Fix #1254 use cover image first when extracting images for SEO

This commit is contained in:
Kijin Sung 2020-03-20 01:24:54 +09:00
parent 6a43274826
commit 8e593a9d60
2 changed files with 14 additions and 15 deletions

View file

@ -489,32 +489,28 @@ class HTMLDisplayHandler
$document_images = array();
if ($oDocument->hasUploadedFiles())
{
foreach ($oDocument->getUploadedFiles() as $file)
$document_files = $oDocument->getUploadedFiles();
usort($document_files, function($a, $b) {
return ord($b->cover_image) - ord($a->cover_image);
});
foreach ($document_files as $file)
{
if ($file->isvalid !== 'Y' || !preg_match('/\.(?:bmp|gif|jpe?g|png)$/i', $file->uploaded_filename))
{
continue;
}
list($width, $height) = @getimagesize($file->uploaded_filename);
if ($width < 100 && $height < 100)
{
continue;
}
$image = array('filepath' => $file->uploaded_filename, 'width' => $width, 'height' => $height);
if ($file->cover_image === 'Y')
{
array_unshift($document_images, $image);
}
else
{
$document_images[] = $image;
}
if (count($document_images) >= 1)
{
$document_images[] = array('filepath' => $file->uploaded_filename, 'width' => $width, 'height' => $height);
break;
}
}
}
Rhymix\Framework\Cache::set("seo:document_images:$document_srl", $document_images);
}
}
@ -525,7 +521,7 @@ class HTMLDisplayHandler
if ($document_images)
{
$first_image = reset($document_images);
$first_image = array_first($document_images);
$first_image['filepath'] = preg_replace('/^.\\/files\\//', \RX_BASEURL . 'files/', $first_image['filepath']);
Context::addOpenGraphData('og:image', Rhymix\Framework\URL::getCurrentDomainURL($first_image['filepath']));
Context::addOpenGraphData('og:image:width', $first_image['width']);

View file

@ -970,6 +970,7 @@ class documentController extends document
//remove from cache
Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($obj->document_srl) . $obj->document_srl);
Rhymix\Framework\Cache::delete('seo:document_images:' . $obj->document_srl);
return $output;
}
@ -1100,6 +1101,7 @@ class documentController extends document
//remove from cache
Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($document_srl) . $document_srl);
Rhymix\Framework\Cache::delete('seo:document_images:' . $document_srl);
unset($GLOBALS['XE_DOCUMENT_LIST'][$document_srl]);
unset($GLOBALS['XE_EXTRA_VARS'][$document_srl]);
return $output;
@ -1256,6 +1258,7 @@ class documentController extends document
// Clear cache
Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($oDocument->document_srl) . $oDocument->document_srl);
Rhymix\Framework\Cache::delete('seo:document_images:' . $oDocument->document_srl);
return $output;
}