diff --git a/classes/display/HTMLDisplayHandler.php b/classes/display/HTMLDisplayHandler.php
index cf5838c00..8023f74fa 100644
--- a/classes/display/HTMLDisplayHandler.php
+++ b/classes/display/HTMLDisplayHandler.php
@@ -489,30 +489,26 @@ 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)
- {
- break;
- }
+
+ $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']);
diff --git a/modules/document/document.controller.php b/modules/document/document.controller.php
index 3b552ac0d..41ee5674a 100644
--- a/modules/document/document.controller.php
+++ b/modules/document/document.controller.php
@@ -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;
}