mirror of
https://github.com/e107inc/e107.git
synced 2025-08-21 21:57:34 +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:
@@ -30,7 +30,7 @@ class social_event
|
||||
|
||||
$event[] = array(
|
||||
'name' => "system_meta_pre",
|
||||
'function' => "og_image_add",
|
||||
'function' => "addFallbackMeta",
|
||||
);
|
||||
|
||||
return $event;
|
||||
@@ -42,31 +42,81 @@ class social_event
|
||||
/**
|
||||
* 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']))
|
||||
{
|
||||
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
|
||||
|
||||
foreach($meta as $m)
|
||||
{
|
||||
if(varset($m['name']) === 'og:image')
|
||||
if(empty($description) && deftrue('META_DESCRIPTION'))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user