1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 14:46:56 +02:00

Fixes #4785 - og:image should be only rendered once. Moved all og meta code out of header_default.php and into social plugin.

This commit is contained in:
Cameron
2022-06-03 09:12:12 -07:00
parent 0ffd69a946
commit d672131d86
4 changed files with 69 additions and 48 deletions

View File

@@ -114,8 +114,6 @@ function render_title()
if(!defined('e_PAGETITLE') && ($_PAGE_TITLE = e107::getSingleton('eResponse')->getMetaTitle())) // use e107::title() to set. if(!defined('e_PAGETITLE') && ($_PAGE_TITLE = e107::getSingleton('eResponse')->getMetaTitle())) // use e107::title() to set.
{ {
define('e_PAGETITLE', $_PAGE_TITLE); define('e_PAGETITLE', $_PAGE_TITLE);
e107::meta('og:title', $_PAGE_TITLE); // will only populate if not already defined.
e107::meta('twitter:title', $_PAGE_TITLE);
} }
$arr = []; $arr = [];
@@ -131,12 +129,6 @@ function render_title()
$arr[] = PAGE_NAME; $arr[] = PAGE_NAME;
} }
} }
else // Frontpage
{
e107::meta('og:type', 'website');
e107::meta('og:title', SITENAME);
e107::meta('twitter:title', SITENAME);
}
$arr[] = SITENAME; $arr[] = SITENAME;
@@ -167,18 +159,7 @@ echo "<head>
<meta charset='utf-8' />\n"; <meta charset='utf-8' />\n";
if(!empty($pref['meta_copyright'][e_LANGUAGE])) e107::meta('dcterms.rights',$pref['meta_copyright'][e_LANGUAGE]); if(!empty($pref['meta_copyright'][e_LANGUAGE])) e107::meta('dcterms.rights',$pref['meta_copyright'][e_LANGUAGE]);
if(!empty($pref['meta_author'][e_LANGUAGE])) e107::meta('author',$pref['meta_author'][e_LANGUAGE]); if(!empty($pref['meta_author'][e_LANGUAGE])) e107::meta('author',$pref['meta_author'][e_LANGUAGE]);
if(!empty($pref['sitebutton']))
{
$siteButton = (strpos($pref['sitebutton'],'{e_MEDIA') !== false) ? e107::getParser()->thumbUrl($pref['sitebutton'],'w=800',false, true) : e107::getParser()->replaceConstants($pref['sitebutton'],'full');
e107::meta('og:image',$siteButton);
unset($siteButton);
}
elseif(!empty($pref['sitelogo'])) // fallback to sitelogo
{
$siteLogo = (strpos($pref['sitelogo'],'{e_MEDIA') !== false) ? e107::getParser()->thumbUrl($pref['sitelogo'],'w=800',false, true) : e107::getParser()->replaceConstants($pref['sitelogo'],'full');
e107::meta('og:image',$siteLogo);
unset($siteLogo);
}
if(defined("VIEWPORT")) e107::meta('viewport',VIEWPORT); //BC ONLY if(defined("VIEWPORT")) e107::meta('viewport',VIEWPORT); //BC ONLY

View File

@@ -4106,7 +4106,7 @@ class eResponse
'article:section', 'article:tag', 'article:published_time', 'article:modified_time', 'article:section', 'article:tag', 'article:published_time', 'article:modified_time',
'og:description', 'og:image', 'og:title', 'og:updated_time','og:url', 'og:type' 'og:description', 'og:image', 'og:title', 'og:updated_time','og:url', 'og:type'
); );
protected $_meta_multiple = array('og:image', 'og:image:width','twitter:image'); protected $_meta_multiple = array();
protected $_meta = array(); protected $_meta = array();
protected $_meta_robot_types = array('noindex'=>'NoIndex', 'nofollow'=>'NoFollow','noarchive'=>'NoArchive','noimageindex'=>'NoImageIndex' ); protected $_meta_robot_types = array('noindex'=>'NoIndex', 'nofollow'=>'NoFollow','noarchive'=>'NoArchive','noimageindex'=>'NoImageIndex' );
protected $_title_separator = ' &raquo; '; protected $_title_separator = ' &raquo; ';

View File

@@ -674,29 +674,19 @@ class news_front
} }
// include news-thumbnail/image in meta. - always put this one first. // include news-thumbnail/image in meta. - always put this one first.
$twitterImage = false;
if(!empty($news['news_thumbnail'])) if(!empty($news['news_thumbnail']))
{ {
$iurl = (substr($news['news_thumbnail'],0,3)=="{e_") ? $news['news_thumbnail'] : SITEURL.e_IMAGE."newspost_images/".$news['news_thumbnail']; $iurl = (substr($news['news_thumbnail'],0,3)=="{e_") ? $news['news_thumbnail'] : SITEURL.e_IMAGE."newspost_images/".$news['news_thumbnail'];
$tmp = explode(",", $iurl); $tmp = explode(",", $iurl);
foreach($tmp as $mimg)
if(!empty($tmp[0]) && substr($tmp[0],-8) !== '.youtube')
{ {
if(substr($mimg,-8) == '.youtube' || empty($mimg)) $mimg = $tmp[0];
{
continue;
}
$metaImg = $tp->thumbUrl($mimg,'w=1200',false,true) ; $metaImg = $tp->thumbUrl($mimg,'w=1200',false,true) ;
e107::meta('og:image',$metaImg); e107::meta('og:image',$metaImg);
e107::meta('og:image:width', 1200); e107::meta('og:image:width', 1200);
if(!$twitterImage) e107::meta('twitter:image', $metaImg);
{
e107::meta('twitter:image', $metaImg);
$twitterImage = true;
}
e107::meta('twitter:card', 'summary_large_image'); e107::meta('twitter:card', 'summary_large_image');
} }
} }

View File

@@ -30,7 +30,7 @@ class social_event
$event[] = array( $event[] = array(
'name' => "system_meta_pre", 'name' => "system_meta_pre",
'function' => "og_image_add", 'function' => "addFallbackMeta",
); );
return $event; return $event;
@@ -42,31 +42,81 @@ class social_event
/** /**
* Callback function to add og:image if there is no any * Callback function to add og:image if there is no any
*/ */
function og_image_add($meta) function addFallbackMeta($meta)
{ {
$ogImage = e107::pref('social', 'og_image', false);
if(e_ADMIN_AREA === true)
{
return null;
}
/** @note TITLE */
if($title = e107::getSingleton('eResponse')->getMetaTitle())
{
e107::meta('og:title', $title); // will only populate if not already defined.
e107::meta('twitter:title', $title);
}
elseif(deftrue('e_FRONTPAGE'))
{
e107::meta('og:title', SITENAME);
e107::meta('twitter:title', SITENAME);
}
/** @note TYPE */
if(empty($meta['og:type'])) if(empty($meta['og:type']))
{ {
e107::meta('og:type', 'website'); e107::meta('og:type', 'website');
} }
if(empty($ogImage) || empty($meta) || e_ADMIN_AREA === true) /** @note DESCRIPTION */
if(empty($meta['og:description']))
{ {
return null; $description = e107::getSingleton('eResponse')->getMetaDescription();
}
// check if we have og:image defined if(empty($description) && deftrue('META_DESCRIPTION'))
foreach($meta as $m)
{
if(varset($m['name']) === 'og:image')
{ {
return null; $description = META_DESCRIPTION;
}
else
{
$description = e107::pref('core', 'meta_description');
}
if(!empty($description))
{
e107::meta('og:description', $description);
e107::meta('twitter:description', $description);
} }
} }
e107::meta('og:image', e107::getParser()->thumbUrl($ogImage, 'w=500', false, true)); /** @note IMAGE */
if(!empty($meta['og:image']))
{
// e107::getDebug()->log("Skipping Social plugin og:image fallback");
return null;
}
$pref = e107::getConfig()->getPref();
if($ogImage = e107::pref('social', 'og_image', false))
{
$metaImg = e107::getParser()->thumbUrl($ogImage, 'w=800', false, true);
e107::meta('og:image', $metaImg);
e107::meta('twitter:image', $metaImg);
}
elseif(!empty($pref['sitebutton']))
{
$siteButton = (strpos($pref['sitebutton'],'{e_MEDIA') !== false) ? e107::getParser()->thumbUrl($pref['sitebutton'],'w=800',false, true) : e107::getParser()->replaceConstants($pref['sitebutton'],'full');
e107::meta('og:image',$siteButton);
e107::meta('twitter:image', $siteButton);
}
elseif(!empty($pref['sitelogo'])) // fallback to sitelogo
{
$siteLogo = (strpos($pref['sitelogo'],'{e_MEDIA') !== false) ? e107::getParser()->thumbUrl($pref['sitelogo'],'w=800',false, true) : e107::getParser()->replaceConstants($pref['sitelogo'],'full');
e107::meta('og:image',$siteLogo);
e107::meta('twitter:image', $siteLogo);
}
} }