mirror of
https://github.com/YGGverse/Yo.git
synced 2025-02-05 11:24:20 +00:00
add totals placeholder
This commit is contained in:
parent
f55fe2c378
commit
57c137ac49
@ -8,6 +8,13 @@ error_reporting(E_ALL);
|
|||||||
// Load dependencies
|
// Load dependencies
|
||||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||||
|
|
||||||
|
function plural(int $number, array $texts)
|
||||||
|
{
|
||||||
|
$cases = [2, 0, 1, 1, 1, 2];
|
||||||
|
|
||||||
|
return $texts[(($number % 100) > 4 && ($number % 100) < 20) ? 2 : $cases[min($number % 10, 5)]];
|
||||||
|
}
|
||||||
|
|
||||||
// Init config
|
// Init config
|
||||||
$config = json_decode(
|
$config = json_decode(
|
||||||
file_get_contents(
|
file_get_contents(
|
||||||
@ -15,7 +22,7 @@ $config = json_decode(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/* @TODO show totals in placeholder
|
// Show totals in placeholder
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
$client = new \Manticoresearch\Client(
|
$client = new \Manticoresearch\Client(
|
||||||
@ -30,7 +37,36 @@ $index = $client->index(
|
|||||||
$config->manticore->index->document
|
$config->manticore->index->document
|
||||||
);
|
);
|
||||||
|
|
||||||
*/
|
// Get totals
|
||||||
|
$total = $index->search('')
|
||||||
|
->option('cutoff', 0)
|
||||||
|
->limit(0)
|
||||||
|
->get()
|
||||||
|
->getTotal();
|
||||||
|
|
||||||
|
$placeholder = plural(
|
||||||
|
$total,
|
||||||
|
[
|
||||||
|
sprintf(
|
||||||
|
_('Over %s page or enter the new one...'),
|
||||||
|
number_format(
|
||||||
|
$total
|
||||||
|
)
|
||||||
|
),
|
||||||
|
sprintf(
|
||||||
|
_('Over %s pages or enter the new one...'),
|
||||||
|
number_format(
|
||||||
|
$total
|
||||||
|
)
|
||||||
|
),
|
||||||
|
sprintf(
|
||||||
|
_('Over %s pages or enter the new one...'),
|
||||||
|
number_format(
|
||||||
|
$total
|
||||||
|
)
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
@ -261,7 +297,7 @@ $index = $client->index(
|
|||||||
<header>
|
<header>
|
||||||
<form name="search" method="GET" action="<?php echo $config->webui->url->base; ?>/search.php">
|
<form name="search" method="GET" action="<?php echo $config->webui->url->base; ?>/search.php">
|
||||||
<h1><?php echo _('Yo!') ?></h1>
|
<h1><?php echo _('Yo!') ?></h1>
|
||||||
<input type="text" name="q" placeholder="<?php echo ('request something...') ?>" value="" />
|
<input type="text" name="q" placeholder="<?php echo $placeholder ?>" value="" />
|
||||||
<button type="submit"><?php echo _('search') ?></button>
|
<button type="submit"><?php echo _('search') ?></button>
|
||||||
</form>
|
</form>
|
||||||
</header>
|
</header>
|
||||||
|
@ -8,6 +8,13 @@ error_reporting(E_ALL);
|
|||||||
// Load dependencies
|
// Load dependencies
|
||||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||||
|
|
||||||
|
function plural(int $number, array $texts)
|
||||||
|
{
|
||||||
|
$cases = [2, 0, 1, 1, 1, 2];
|
||||||
|
|
||||||
|
return $texts[(($number % 100) > 4 && ($number % 100) < 20) ? 2 : $cases[min($number % 10, 5)]];
|
||||||
|
}
|
||||||
|
|
||||||
// Init config
|
// Init config
|
||||||
$config = json_decode(
|
$config = json_decode(
|
||||||
file_get_contents(
|
file_get_contents(
|
||||||
@ -28,6 +35,37 @@ $index = $client->index(
|
|||||||
$config->manticore->index->document
|
$config->manticore->index->document
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Get totals
|
||||||
|
$total = $index->search('')
|
||||||
|
->option('cutoff', 0)
|
||||||
|
->limit(0)
|
||||||
|
->get()
|
||||||
|
->getTotal();
|
||||||
|
|
||||||
|
$placeholder = plural(
|
||||||
|
$total,
|
||||||
|
[
|
||||||
|
sprintf(
|
||||||
|
_('Over %s page or enter the new one...'),
|
||||||
|
number_format(
|
||||||
|
$total
|
||||||
|
)
|
||||||
|
),
|
||||||
|
sprintf(
|
||||||
|
_('Over %s pages or enter the new one...'),
|
||||||
|
number_format(
|
||||||
|
$total
|
||||||
|
)
|
||||||
|
),
|
||||||
|
sprintf(
|
||||||
|
_('Over %s pages or enter the new one...'),
|
||||||
|
number_format(
|
||||||
|
$total
|
||||||
|
)
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
// Request
|
// Request
|
||||||
$q = !empty($_GET['q']) ? $_GET['q'] : '';
|
$q = !empty($_GET['q']) ? $_GET['q'] : '';
|
||||||
$p = !empty($_GET['p']) ? (int) $_GET['p'] : 1;
|
$p = !empty($_GET['p']) ? (int) $_GET['p'] : 1;
|
||||||
@ -214,7 +252,7 @@ $results = $index->search($q)
|
|||||||
<header>
|
<header>
|
||||||
<form name="search" method="GET" action="<?php echo $config->webui->url->base; ?>/search.php">
|
<form name="search" method="GET" action="<?php echo $config->webui->url->base; ?>/search.php">
|
||||||
<h1><a href="<?php echo $config->webui->url->base; ?>"><?php echo _('Yo!') ?></a></h1>
|
<h1><a href="<?php echo $config->webui->url->base; ?>"><?php echo _('Yo!') ?></a></h1>
|
||||||
<input type="text" name="q" placeholder="<?php echo _('request something...') ?>" value="<?php echo htmlentities($q) ?>" />
|
<input type="text" name="q" placeholder="<?php echo $placeholder ?>" value="<?php echo htmlentities($q) ?>" />
|
||||||
<button type="submit"><?php echo _('search'); ?></button>
|
<button type="submit"><?php echo _('search'); ?></button>
|
||||||
</form>
|
</form>
|
||||||
</header>
|
</header>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user