2013-03-03 21:44:31 -08:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* e107 website system
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008-2013 e107 Inc (e107.org)
|
|
|
|
* Released under the terms and conditions of the
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
2015-02-09 12:57:42 -08:00
|
|
|
* XXX HIGHLY EXPERIMENTAL AND SUBJECT TO CHANGE WITHOUT NOTICE.
|
2013-03-03 21:44:31 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('e107_INIT')) { exit; }
|
|
|
|
|
|
|
|
|
2016-04-07 11:43:28 -07:00
|
|
|
class social_event
|
2013-03-03 21:44:31 -08:00
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* constructor
|
|
|
|
*/
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-07 11:43:28 -07:00
|
|
|
function config()
|
|
|
|
{
|
2017-12-09 15:47:23 +02:00
|
|
|
$event = array();
|
|
|
|
|
|
|
|
$event[] = array(
|
|
|
|
'name' => "system_meta_pre",
|
2022-06-03 09:12:12 -07:00
|
|
|
'function' => "addFallbackMeta",
|
2017-12-09 15:47:23 +02:00
|
|
|
);
|
2016-04-07 11:43:28 -07:00
|
|
|
|
2017-12-09 15:47:23 +02:00
|
|
|
return $event;
|
|
|
|
|
|
|
|
}
|
2017-12-09 10:36:00 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-09 15:47:23 +02:00
|
|
|
/**
|
|
|
|
* Callback function to add og:image if there is no any
|
|
|
|
*/
|
2022-06-03 09:12:12 -07:00
|
|
|
function addFallbackMeta($meta)
|
2017-12-09 15:47:23 +02:00
|
|
|
{
|
2017-12-09 10:36:00 -08:00
|
|
|
|
2022-06-03 09:12:12 -07:00
|
|
|
if(e_ADMIN_AREA === true)
|
2021-10-01 08:47:18 -07:00
|
|
|
{
|
2022-06-03 09:12:12 -07:00
|
|
|
return null;
|
2021-10-01 08:47:18 -07:00
|
|
|
}
|
|
|
|
|
2022-06-03 09:12:12 -07:00
|
|
|
/** @note TITLE */
|
|
|
|
if($title = e107::getSingleton('eResponse')->getMetaTitle())
|
2017-12-09 10:36:00 -08:00
|
|
|
{
|
2022-06-03 09:12:12 -07:00
|
|
|
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);
|
2017-12-09 10:36:00 -08:00
|
|
|
}
|
|
|
|
|
2022-06-03 09:12:12 -07:00
|
|
|
/** @note TYPE */
|
|
|
|
if(empty($meta['og:type']))
|
|
|
|
{
|
|
|
|
e107::meta('og:type', 'website');
|
|
|
|
}
|
2021-10-01 08:47:18 -07:00
|
|
|
|
2022-06-03 09:12:12 -07:00
|
|
|
/** @note DESCRIPTION */
|
|
|
|
if(empty($meta['og:description']))
|
2017-12-09 10:36:00 -08:00
|
|
|
{
|
2022-06-03 09:12:12 -07:00
|
|
|
$description = e107::getSingleton('eResponse')->getMetaDescription();
|
|
|
|
|
2022-06-03 10:19:32 -07:00
|
|
|
if(empty($description))
|
2022-06-03 09:12:12 -07:00
|
|
|
{
|
2022-06-03 10:19:32 -07:00
|
|
|
if(deftrue('META_DESCRIPTION'))
|
|
|
|
{
|
|
|
|
$description = META_DESCRIPTION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$tmp = e107::pref('core', 'meta_description');
|
|
|
|
if(!empty($tmp[e_LANGUAGE]))
|
|
|
|
{
|
|
|
|
$description = $tmp[e_LANGUAGE];
|
|
|
|
}
|
|
|
|
}
|
2022-06-03 09:12:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($description))
|
2017-12-09 10:36:00 -08:00
|
|
|
{
|
2022-06-03 09:12:12 -07:00
|
|
|
e107::meta('og:description', $description);
|
|
|
|
e107::meta('twitter:description', $description);
|
2017-12-09 15:47:23 +02:00
|
|
|
}
|
2017-12-09 10:36:00 -08:00
|
|
|
}
|
|
|
|
|
2022-06-03 09:12:12 -07:00
|
|
|
/** @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);
|
|
|
|
}
|
2017-12-09 10:36:00 -08:00
|
|
|
|
2016-04-07 11:43:28 -07:00
|
|
|
}
|
|
|
|
|
2013-03-03 21:44:31 -08:00
|
|
|
} //end class
|
|
|
|
|
2017-12-09 10:36:00 -08:00
|
|
|
|
|
|
|
|