mirror of
https://github.com/YGGverse/Yo.git
synced 2025-01-27 23:14:16 +00:00
add totals placeholder
This commit is contained in:
parent
f55fe2c378
commit
57c137ac49
@ -8,6 +8,13 @@ error_reporting(E_ALL);
|
||||
// Load dependencies
|
||||
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
|
||||
$config = json_decode(
|
||||
file_get_contents(
|
||||
@ -15,7 +22,7 @@ $config = json_decode(
|
||||
)
|
||||
);
|
||||
|
||||
/* @TODO show totals in placeholder
|
||||
// Show totals in placeholder
|
||||
|
||||
// Init
|
||||
$client = new \Manticoresearch\Client(
|
||||
@ -30,7 +37,36 @@ $index = $client->index(
|
||||
$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>
|
||||
<form name="search" method="GET" action="<?php echo $config->webui->url->base; ?>/search.php">
|
||||
<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>
|
||||
</form>
|
||||
</header>
|
||||
|
@ -8,6 +8,13 @@ error_reporting(E_ALL);
|
||||
// Load dependencies
|
||||
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
|
||||
$config = json_decode(
|
||||
file_get_contents(
|
||||
@ -28,6 +35,37 @@ $index = $client->index(
|
||||
$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
|
||||
$q = !empty($_GET['q']) ? $_GET['q'] : '';
|
||||
$p = !empty($_GET['p']) ? (int) $_GET['p'] : 1;
|
||||
@ -214,7 +252,7 @@ $results = $index->search($q)
|
||||
<header>
|
||||
<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>
|
||||
<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>
|
||||
</form>
|
||||
</header>
|
||||
|
Loading…
x
Reference in New Issue
Block a user