Browse Source

fix image search page errors

main
ghost 2 years ago
parent
commit
ef4de6b245
  1. 18
      library/mysql.php
  2. 31
      public/search.php

18
library/mysql.php

@ -282,6 +282,23 @@ class MySQL {
return $this->_db->lastInsertId(); 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) { public function deleteHostImageDescription(int $hostImageId) {
$query = $this->_db->prepare('DELETE FROM `hostImageDescription` WHERE `hostImageId` = ?'); $query = $this->_db->prepare('DELETE FROM `hostImageDescription` WHERE `hostImageId` = ?');
@ -446,7 +463,6 @@ class MySQL {
$query = $this->_db->prepare('SELECT `hostImage`.`hostImageId`, $query = $this->_db->prepare('SELECT `hostImage`.`hostImageId`,
`hostImage`.`uri`, `hostImage`.`uri`,
`hostImage`.`data`,
`hostImage`.`rank`, `hostImage`.`rank`,
`host`.`scheme`, `host`.`scheme`,
`host`.`name`, `host`.`name`,

31
public/search.php

@ -342,8 +342,13 @@ if (!empty($q)) {
($hostImage->port ? ':' . $hostImage->port : false) . ($hostImage->port ? ':' . $hostImage->port : false) .
$hostImage->uri; $hostImage->uri;
// Get remote image data // Get local image data
if (empty($hostImage->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 // Init image request
$hostImageCurl = new Curl($hostImageURL, PROXY_CURLOPT_USERAGENT); $hostImageCurl = new Curl($hostImageURL, PROXY_CURLOPT_USERAGENT);
@ -420,29 +425,15 @@ if (!empty($q)) {
Filter::mime($hostImageContentType), Filter::mime($hostImageContentType),
time()); time());
// Set host image description $db->setHostImageDescriptionData($hostImage->hostImageId,
// On link collection we knew meta but data, crc32($hostImageURLencoded),
// this step use latest description slice and insert the data received by curl request $hostImage->crawlMetaOnly ? null : $hostImageURLencoded,
if ($lastHostImageDescription = $db->getLastHostImageDescription($hostImage->hostImageId)) {
$db->setHostImageDescription($hostImage->hostImageId,
crc32($hostImageData),
$lastHostImageDescription->alt,
$lastHostImageDescription->title,
$hostImage->crawlMetaOnly ? null : $hostImageData,
time()); time());
} }
// Local image data exists
} else {
$hostImageURLencoded = $hostImage->data;
}
?> ?>
<div> <div>
<a href="<?php echo $hostImageURL ?>"> <a href="<?php echo $hostImageURL ?>">
<img src="<?php echo $hostImageURLencoded ?>" alt="<?php echo htmlentities($hostImage->description) ?>" title="<?php echo htmlentities($hostImageURL) ?>" class="image" /> <img src="<?php echo $hostImageURLencoded ?>" alt="<?php echo htmlentities($hostImageURL) ?>" title="<?php echo htmlentities($hostImageURL) ?>" class="image" />
</a> </a>
<?php $hostImageHostPagesTotal = $db->getHostImageHostPagesTotal($result->id) ?> <?php $hostImageHostPagesTotal = $db->getHostImageHostPagesTotal($result->id) ?>
<?php foreach ((array) $db->getHostImageHostPages($result->id, WEBSITE_SEARCH_IMAGE_RELATED_PAGE_RESULTS_LIMIT) as $hostPage) { ?> <?php foreach ((array) $db->getHostImageHostPages($result->id, WEBSITE_SEARCH_IMAGE_RELATED_PAGE_RESULTS_LIMIT) as $hostPage) { ?>

Loading…
Cancel
Save