show images total instead of pages in placeholder on image search page

This commit is contained in:
ghost 2023-05-05 01:42:44 +03:00
parent 5297e6e918
commit f0b2eb1613
2 changed files with 33 additions and 8 deletions

View File

@ -94,6 +94,15 @@ class MySQL {
}
// Images
public function getTotalImages() {
$query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `hostImage`');
$query->execute();
return $query->fetch()->total;
}
public function getTotalHostImages(int $hostId) {
$query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `hostImage` WHERE `hostId` = ?');

View File

@ -15,20 +15,36 @@ $sphinx = new SphinxQL(SPHINX_HOST, SPHINX_PORT);
// Connect database
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
// Define page basics
$totalPages = $db->getTotalPages();
$placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the new one...'), $totalPages),
sprintf(_('Over %s pages or enter the new one...'), $totalPages),
sprintf(_('Over %s pages or enter the new one...'), $totalPages),
]);
// Filter request data
$t = !empty($_GET['t']) ? Filter::url($_GET['t']) : 'page';
$m = !empty($_GET['m']) ? Filter::url($_GET['m']) : 'default';
$q = !empty($_GET['q']) ? Filter::url($_GET['q']) : '';
$p = !empty($_GET['p']) ? (int) $_GET['p'] : 1;
// Define page basics
switch ($t) {
case 'image':
$totalPages = $db->getTotalImages();
$placeholder = Filter::plural($totalPages, [sprintf(_('Over %s image or enter the new one...'), $totalPages),
sprintf(_('Over %s images or enter the new one...'), $totalPages),
sprintf(_('Over %s images or enter the new one...'), $totalPages),
]);
break;
default:
$totalPages = $db->getTotalPages();
$placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the new one...'), $totalPages),
sprintf(_('Over %s pages or enter the new one...'), $totalPages),
sprintf(_('Over %s pages or enter the new one...'), $totalPages),
]);
}
// Crawl request
if (filter_var($q, FILTER_VALIDATE_URL) && preg_match(CRAWL_URL_REGEXP, $q)) {