diff --git a/crontab/crawler.php b/crontab/crawler.php index a390572..99ad76c 100644 --- a/crontab/crawler.php +++ b/crontab/crawler.php @@ -336,7 +336,9 @@ try { if ($lastHostImageDescription = $db->getLastHostImageDescription($queueHostImage->hostImageId)) { $db->setHostImageDescription($queueHostImage->hostImageId, - crc32($hostImageData), + crc32($lastHostImageDescription->alt . + $lastHostImageDescription->title . + $hostImageData), $lastHostImageDescription->alt, $lastHostImageDescription->title, $hostImageData, @@ -618,10 +620,13 @@ try { } // Add/update host image description + $imageAlt = Filter::imageAlt($imageAlt); + $imageTitle = Filter::imageTitle($imageTitle); + $db->setHostImageDescription($hostImageId, - null, // no data, download it in the crawler queue - Filter::imageAlt($imageAlt), - Filter::imageTitle($imageTitle), + crc32($imageAlt . $imageTitle), + $imageAlt, + $imageTitle, null, time()); diff --git a/database/yggo.mwb b/database/yggo.mwb index 7a3cc12..35ee90c 100644 Binary files a/database/yggo.mwb and b/database/yggo.mwb differ diff --git a/library/mysql.php b/library/mysql.php index 9dddd2b..6e12201 100644 --- a/library/mysql.php +++ b/library/mysql.php @@ -259,14 +259,14 @@ class MySQL { } public function setHostImageDescription(int $hostImageId, - mixed $crc32data, + int $crc32id, string $alt, string $title, mixed $data, int $time) { $query = $this->_db->prepare('INSERT INTO `hostImageDescription` (`hostImageId`, - `crc32data`, + `crc32id`, `alt`, `title`, `timeAdded`) VALUES (?, ?, ?, ?, ?) @@ -275,24 +275,24 @@ class MySQL { `title` = ?, `timeUpdated` = ?'); - $query->execute([$hostImageId, $crc32data, $alt, $title, $time, $alt, $title, $time]); + $query->execute([$hostImageId, $crc32id, $alt, $title, $time, $alt, $title, $time]); return $this->_db->lastInsertId(); } public function setHostImageDescriptionData(int $hostImageId, - mixed $crc32data, + int $crc32id, mixed $data, int $time) { $query = $this->_db->prepare('INSERT INTO `hostImageDescription` (`hostImageId`, - `crc32data`, + `crc32id`, `data`, `timeAdded`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE `timeUpdated` = ?'); - $query->execute([$hostImageId, $crc32data, $data, $time, $time]); + $query->execute([$hostImageId, $crc32id, $data, $time, $time]); return $this->_db->lastInsertId(); } diff --git a/public/search.php b/public/search.php index 8567163..639ee80 100644 --- a/public/search.php +++ b/public/search.php @@ -346,7 +346,7 @@ if (!empty($q)) { $hostImage->uri; // Get local image data - if ($lastHostImageDescription = $db->getLastHostImageDescription($hostImage->hostImageId)) { + if ($lastHostImageDescription = $db->getLastHostImageDescription($result->id)) { $hostImageURLencoded = $lastHostImageDescription->data; @@ -359,13 +359,13 @@ if (!empty($q)) { // Skip item render on timeout $hostImageHttpCode = $hostImageCurl->getCode(); - $db->updateHostImageHttpCode($hostImage->hostImageId, (int) $hostImageHttpCode, time()); + $db->updateHostImageHttpCode($result->id, (int) $hostImageHttpCode, time()); if (200 != $hostImageHttpCode) { - $db->updateHostImageHttpCode($hostImage->hostImageId, $hostImageHttpCode, time()); + $db->updateHostImageHttpCode($result->id, $hostImageHttpCode, time()); - $db->updateHostImageTimeBanned($hostImage->hostImageId, time()); + $db->updateHostImageTimeBanned($result->id, time()); continue; } @@ -373,7 +373,7 @@ if (!empty($q)) { // Skip image processing on MIME type not provided if (!$hostImageContentType = $hostImageCurl->getContentType()) { - $db->updateHostImageTimeBanned($hostImage->hostImageId, time()); + $db->updateHostImageTimeBanned($result->id, time()); continue; } @@ -391,9 +391,9 @@ if (!empty($q)) { if ($hostImageBanned) { - $db->updateHostImageMime($hostImage->hostImageId, $hostImageContentType, time()); + $db->updateHostImageMime($result->id, $hostImageContentType, time()); - $hostImagesBanned += $db->updateHostImageTimeBanned($hostImage->hostImageId, time()); + $hostImagesBanned += $db->updateHostImageTimeBanned($result->id, time()); continue; } @@ -401,7 +401,7 @@ if (!empty($q)) { // Skip image processing without returned content if (!$hostImageContent = $hostImageCurl->getContent()) { - $db->updateHostImageTimeBanned($hostImage->hostImageId, time()); + $db->updateHostImageTimeBanned($result->id, time()); continue; } @@ -409,14 +409,14 @@ if (!empty($q)) { // Convert remote image data to base64 string to prevent direct URL call if (!$hostImageExtension = @pathinfo($hostImageURL, PATHINFO_EXTENSION)) { - $db->updateHostImageTimeBanned($hostImage->hostImageId, time()); + $db->updateHostImageTimeBanned($result->id, time()); continue; } if (!$hostImageBase64 = @base64_encode($hostImageContent)) { - $db->updateHostImageTimeBanned($hostImage->hostImageId, time()); + $db->updateHostImageTimeBanned($result->id, time()); continue; } @@ -424,11 +424,11 @@ if (!empty($q)) { $hostImageURLencoded = 'data:image/' . str_replace(['svg'], ['svg+xml'], $hostImageExtension) . ';base64,' . $hostImageBase64; // Save image content on data settings enabled - $db->updateHostImage($hostImage->hostImageId, + $db->updateHostImage($result->id, Filter::mime($hostImageContentType), time()); - $db->setHostImageDescriptionData($hostImage->hostImageId, + $db->setHostImageDescriptionData($result->id, crc32($hostImageURLencoded), $hostImage->crawlMetaOnly ? null : $hostImageURLencoded, time());