Activate on your Accelerated Mobile Pages (AMP)';
const ADMIN_NOTICE_ENABLED_KEY = 'admin_amp_notice_enabled';
const ADMIN_NOTICE_ENABLED_MESSAGE = 'AddThis Plugin is enabled on your site including Accelerated Mobile Pages (AMP)';
const ADMIN_NOTICE_ANON_KEY = 'admin_amp_notice_anon';
const ADMIN_NOTICE_ANON_MESSAGE = 'AddThis Plugin is enabled. Accelerated Mobile Pages are not currently available in anonymous WordPress mode, register for free on';
const ADMIN_NOTICE_ANON_LINK = 'AddThis.com';
protected static $floatingInserted = false;
/**
* Enqueued notice callback for outputting the admin notice message when in anonymous mode
*
* @return null
*/
public static function adminNoticeAnonCallback() {
AddThisAdminUtilities::showNotice(
AddThisAmp::ADMIN_NOTICE_ANON_MESSAGE,
AddThisAmp::ADMIN_NOTICE_ANON_KEY,
AddThisAmp::ADMIN_NOTICE_ANON_LINK
);
}
/**
* Enqueued notice callback for outputting the admin notice message when AMP is enabled
*
* @return null
*/
public static function adminNoticeEnabledCallback() {
AddThisAdminUtilities::showNotice(
AddThisAmp::ADMIN_NOTICE_ENABLED_MESSAGE,
AddThisAmp::ADMIN_NOTICE_ENABLED_KEY
);
}
/**
* Enqueued notice callback for outputting the admin notice message when AMP is not enabled
*
* @return null
*/
public static function adminNoticeNoAmpCallback() {
AddThisAdminUtilities::showNotice(
AddThisAmp::ADMIN_NOTICE_NOAMP_MESSAGE,
AddThisAmp::ADMIN_NOTICE_NOAMP_KEY,
AddThisAmp::ADMIN_NOTICE_NOAMP_LINK
);
}
/**
* Determines if the current context is an AMP page
*
* @return boolean
*/
public static function inAmpMode() {
if (function_exists('is_amp_endpoint')) {
return is_amp_endpoint();
}
return false;
}
/**
* Determines if the AMP plugin is enabled
*
* @return boolean
*/
public static function isAmpPluginEnabled() {
return did_action('amp_init');
}
/**
* Callback for admin_init hook
*
* @return null
*/
public static function initAdmin() {
if (AddThisAdminUtilities::isAdminInterface() && AddThisAdminUtilities::userHasCapabilities()) {
if (self::isAmpPluginEnabled()) {
// AMP is enabled, messaging dependent upon anonymous mode
if (AddThisAdminUtilities::isAnonMode()) {
AddThisAdminUtilities::enqueueNotice(AddThisAmp::ADMIN_NOTICE_ANON_KEY, array(__CLASS__, 'adminNoticeAnonCallback'));
} else {
AddThisAdminUtilities::enqueueNotice(AddThisAmp::ADMIN_NOTICE_ENABLED_KEY, array(__CLASS__, 'adminNoticeEnabledCallback'));
}
} else {
// AMP is not enabled
AddThisAdminUtilities::enqueueNotice(AddThisAmp::ADMIN_NOTICE_NOAMP_KEY, array(__CLASS__, 'adminNoticeNoAmpCallback'));
}
}
}
/**
* Generates the AMP-specific tag using the AMP plugin's helper if available.
*
* @param string $profileId Pub ID
* @param string $widgetId ID of the widget
* @param string $widgetType the type of widget
* @param string $class CSS class for the tag
* @param integer $width width of element
* @param integer $height height of element
*
* @return string
*/
public static function getAmpHtml($profileId, $widgetId, $widgetType = 'shin', $class = null, $width = 320, $height = 65) {
$params = array(
'width' => $width,
'height' => $height,
'data-pub-id' => $profileId
);
if (!empty($widgetId)) {
$params['data-widget-id'] = $widgetId;
} else if (!empty($widgetType)) {
$params['data-product-code'] = $widgetType;
}
if ($widgetType == 'shfs') {
$params['layout'] = 'responsive';
}
if (!empty($class)) {
$params['data-class-name'] = $class;
}
if (class_exists('AMP_HTML_Utils')) {
return AMP_HTML_Utils::build_tag('amp-addthis', $params);
} else {
$html = ' $value) {
$html .= ' ' . $key . '="' . $value . '"';
}
$html .= '>';
return $html;
}
}
/**
* Generates the AMP-specific tag for a floating share tool, only once
*
* @param string $profileId Pub ID
*
* @return string
*/
public static function getFloatingHtml($profileId) {
if (!self::$floatingInserted) {
self::$floatingInserted = true;
return self::getAmpHtml($profileId, null, 'shfs', null, 48, 48);
}
}
}
if (AddThisAdminUtilities::isAdminInterface()) {
add_action('admin_init', array('AddThisAmp', 'initAdmin'));
}
}