From ef4de6b245da653a4b7f0dc620cf5739cdec650b Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 9 May 2023 08:53:33 +0300 Subject: [PATCH] fix image search page errors --- library/mysql.php | 18 +++++++++++++++++- public/search.php | 33 ++++++++++++--------------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/library/mysql.php b/library/mysql.php index d6545ec..0e4def9 100644 --- a/library/mysql.php +++ b/library/mysql.php @@ -282,6 +282,23 @@ class MySQL { return $this->_db->lastInsertId(); } + public function setHostImageDescriptionData(int $hostImageId, + mixed $crc32data, + mixed $data, + int $time) { + + $query = $this->_db->prepare('INSERT INTO `hostImageDescription` (`hostImageId`, + `crc32data`, + `data`, + `timeAdded`) VALUES (?, ?, ?, ?) + + ON DUPLICATE KEY UPDATE `timeUpdated` = ?'); + + $query->execute([$hostImageId, $crc32data, $data, $time, $time]); + + return $this->_db->lastInsertId(); + } + public function deleteHostImageDescription(int $hostImageId) { $query = $this->_db->prepare('DELETE FROM `hostImageDescription` WHERE `hostImageId` = ?'); @@ -446,7 +463,6 @@ class MySQL { $query = $this->_db->prepare('SELECT `hostImage`.`hostImageId`, `hostImage`.`uri`, - `hostImage`.`data`, `hostImage`.`rank`, `host`.`scheme`, `host`.`name`, diff --git a/public/search.php b/public/search.php index cd6fb98..b801fab 100644 --- a/public/search.php +++ b/public/search.php @@ -342,8 +342,13 @@ if (!empty($q)) { ($hostImage->port ? ':' . $hostImage->port : false) . $hostImage->uri; - // Get remote image data - if (empty($hostImage->data)) { + // Get local image data + if ($lastHostImageDescription = $db->getLastHostImageDescription($hostImage->hostImageId)) { + + $hostImageURLencoded = $lastHostImageDescription->data; + + // Get remote if local index not found or CRAWL_HOST_DEFAULT_META_ONLY enabled + } else { // Init image request $hostImageCurl = new Curl($hostImageURL, PROXY_CURLOPT_USERAGENT); @@ -420,29 +425,15 @@ if (!empty($q)) { Filter::mime($hostImageContentType), time()); - // Set host image description - // On link collection we knew meta but data, - // this step use latest description slice and insert the data received by curl request - if ($lastHostImageDescription = $db->getLastHostImageDescription($hostImage->hostImageId)) { - - $db->setHostImageDescription($hostImage->hostImageId, - crc32($hostImageData), - $lastHostImageDescription->alt, - $lastHostImageDescription->title, - $hostImage->crawlMetaOnly ? null : $hostImageData, - time()); - } - - // Local image data exists - } else { - - $hostImageURLencoded = $hostImage->data; + $db->setHostImageDescriptionData($hostImage->hostImageId, + crc32($hostImageURLencoded), + $hostImage->crawlMetaOnly ? null : $hostImageURLencoded, + time()); } - ?>
- <?php echo htmlentities($hostImage->description) ?> + <?php echo htmlentities($hostImageURL) ?> getHostImageHostPagesTotal($result->id) ?> getHostImageHostPages($result->id, WEBSITE_SEARCH_IMAGE_RELATED_PAGE_RESULTS_LIMIT) as $hostPage) { ?>