addThisConfigs = $addThisConfigs;
// Save async load settings via ajax request
add_action( 'wp_ajax_at_async_loading', array($this, 'addthisAsyncLoading'));
$this->_upgrade = $upgrade;
$this->_getVariables = $_GET;
$this->_postVariables = $_POST;
$this->_options = $this->addThisConfigs->getConfigs();
$this->_pubid = null;
if ( isset($this->_options)
&& isset($this->_options['addthis_profile'])
&& !empty($this->_options['addthis_profile'])
) {
$this->_pubid = $this->_options['addthis_profile'];
}
include_once 'addthis-toolbox.php';
new Addthis_ToolBox;
add_action('admin_menu', array($this, 'addthisWordpressMenu'));
// Deactivation
register_deactivation_hook(
ADDTHIS_PLUGIN_FILE,
array($this, 'pluginDeactivation')
);
// Settings link in plugins page
$plugin = 'addthis/addthis_social_widget.php';
add_filter(
"plugin_action_links_$plugin",
array($this, 'addSettingsLink')
);
}
/*
* Function to add settings link in plugins page
*
* @return null
*/
public function addSettingsLink($links)
{
$settingsLink = 'Settings';
array_push($links, $settingsLink);
return $links;
}
/**
* Functions to execute on plugin deactivation
*
* @return null
*/
public function pluginDeactivation()
{
if (get_option('addthis_run_once')) {
delete_option('addthis_run_once');
}
}
/**
* Adds sub menu page to the WP settings menu
*
* @return null
*/
public function addthisWordpressMenu()
{
add_options_page(
'AddThis Sharing Buttons',
'AddThis Sharing Buttons',
'manage_options',
ADDTHIS_SETTINGS_PAGE_ID,
array($this, 'addthisWordpressOptions')
);
}
/**
* Manages the WP settings page
*
* @return null
*/
public function addthisWordpressOptions()
{
if (!current_user_can('manage_options')) {
wp_die(
__('You do not have sufficient permissions to access this page.')
);
}
$updateResult = null;
if ($this->_checkAddPubid()) {
$updateResult = $this->updateSettings($this->_postVariables);
}
wp_enqueue_script(
'addThisScript',
plugins_url(ADDTHIS_JS_PATH, __FILE__)
);
wp_enqueue_script('atTabs',plugins_url('js/options-page.32.js', __FILE__));
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_style(
'addThisStylesheet',
plugins_url(ADDTHIS_CSS_PATH, __FILE__)
);
wp_enqueue_style('attabStyles',plugins_url('css/options-page.css', __FILE__));
echo $this->_getHTML($updateResult);
}
/**
* Updates addthis profile id
*
* @param string $pubId Addthis public id
*
* @return string
*/
public function updateSettings($settings)
{
if(isset($settings['pubid'])){
$this->_options['addthis_profile'] = sanitize_key($settings['pubid']);
}
if(isset($settings['addthis_settings']['addthis_environment'])){
$this->_options['addthis_environment'] = sanitize_key($settings['addthis_settings']['addthis_environment']);
}
if( isset($settings['addthis_plugin_controls'])
&& $settings['addthis_plugin_controls'] == "WordPress"
) {
$this->_options['addthis_plugin_controls'] = $settings['addthis_plugin_controls'];
}
if(isset($settings['async_loading'])){
$this->_options['addthis_asynchronous_loading'] = intval($settings['async_loading']);
}
$this->_options = $this->addThisConfigs->saveConfigs($this->_options);
$this->_pubid = $this->_options['addthis_profile'];
return "
".
"AddThis Profile Settings updated successfully!!!".
"
";
}
/**
* Get addthis profile id
*
* @return string
*/
public static function getPubid()
{
global $addThisConfigs;
$settings = $addThisConfigs->getConfigs();
if (!empty($settings['addthis_profile'])) {
return $settings['addthis_profile'];
} else {
return null;
}
}
/**
* Get referer url
*
* @return string
*/
private function _getReferelUrl()
{
$referer = '';
if (isset($_SERVER['HTTP_REFERER'])) {
$parse = parse_url($_SERVER['HTTP_REFERER']);
$referer = $parse['host'];
}
// return $referer;
return self::ADDTHIS_REFERER;
}
/**
* Check if there is an addthis profile id return from addthis.com
*
* @return boolean
*/
private function _checkPubidFromAddThis()
{
$referer = $this->_getReferelUrl();
$successReturn = isset ($this->_getVariables['pubid']) &&
isset ($this->_getVariables['complete']) &&
$this->_getVariables['complete'] == 'true' &&
$referer == self::ADDTHIS_REFERER;
return $successReturn;
}
/**
* Check if there is request to add addthis profile id
*
* @return boolean
*/
private function _checkAddPubid()
{
$successReturn = isset ($this->_postVariables['pubid'])
&& isset ($this->_postVariables['submit'])
&& isset( $this->_postVariables['pubid_nonce'] )
&& wp_verify_nonce( $this->_postVariables['pubid_nonce'], 'update_pubid' );
return $successReturn;
}
/**
* Check if there is request to update async loading
*
* @return boolean
*/
private function _checkAsyncLoading()
{
$successReturn = isset ($this->_postVariables['async_loading']);
return $successReturn;
}
public function addthisAsyncLoading()
{
if (current_user_can( 'manage_options' ) && $this->_checkAsyncLoading()) {
$updateResult = $this->updateSettings($this->_postVariables);
}
die; //exit from the ajax request
}
/**
* Check pubid from addthis failure
*
* @return boolean
*/
private function _checkAddPubidFailure()
{
$referer = $this->_getReferelUrl();
$successReturn = (isset ($this->_getVariables['complete']) &&
$this->_getVariables['complete'] != 'true') ||
(isset ($this->_getVariables['complete']) &&
$referer !== self::ADDTHIS_REFERER);
return $successReturn;
}
/**
* Get the HTML for addthis settings page
*
* @param string $updateResult Updated message
*
* @return string
*/
private function _getHTML($updateResult)
{
$html = '
';
}
return $html;
}
/**
* Get pubid failure message
*
* @return
*/
private static function _getPubIdFromAddthisFailureMessage()
{
return "".
"Failed to add AddThis Profile ID".
"
";
}
/**
* Get Update Success Message when updating from old plugin
*
* @return null
*/
private function _getupdateSuccessMessage()
{
return "".
"Click on the link below to finish setting up your AddThis tools.".
"
";
}
/**
* Get Link to addthis site
*
* @return string
*/
private function _getAddThisLinkButton()
{
$noPubIdDescription = 'To configure sharing tools for your site, use the button below to set up an AddThis account at addthis.com, create a profile for your site and begin adding sharing tools. This process will require an email address.';
$noPubIdButtonText = "AddThis profile setup";
$noPubIdCardTitle = 'You\'re almost done!';
$pubIdDescription = 'To configure sharing tools for your site, use the button below. It will take you to Tools on addthis.com';
$pubIdCardTitle = 'Setup AddThis Tools';
$pubIdButtonText = "Configure AddThis Tools";
if (empty($this->_pubid)) {
// if they don't have a profile yet, default to setup
$tabOrder = array(
'tabs-1' => 'Setup',
'tabs-2' => 'Advanced Options',
);
$sharingToolsCardTitle = $noPubIdCardTitle;
$sharingToolsDescription = $noPubIdDescription;
$sharingToolsButtonUrl = _addthis_profile_setup_url();
$sharingToolsButtonText = $noPubIdButtonText;
$target = '';
} else {
// else default to profile
$tabOrder = array(
'tabs-1' => 'Sharing Tools',
'tabs-2' => 'Advanced Options',
);
$sharingToolsCardTitle = $pubIdCardTitle;
$sharingToolsDescription = $pubIdDescription;
$sharingToolsButtonUrl = _addthis_tools_url();
$sharingToolsButtonText = $pubIdButtonText;
$target = 'target="_blank"';
}
$tabsHtml = '';
foreach ($tabOrder as $href => $title) {
$tabsHtml .= '' . $title . '';
}
$html = '
' . $sharingToolsCardTitle . '
Beautiful simple website tools designed to help you get likes, get shares, get follows and get discovered.
' . $sharingToolsDescription . '
' . $sharingToolsButtonText . ' →
If you don\'t see your tools after configuring them in the dashboard, please contact
AddThis Support
' . _addthis_profile_id_card() . '
' . _addthis_mode_card() . '
';
return $html;
}
/**
* Get the plugin's settings page url
*
* @return string
*/
public static function getSettingsPageUrl()
{
return admin_url("options-general.php?page=" . ADDTHIS_SETTINGS_PAGE_ID);
}
/**
* Get the wp domain
*
* @return string
*/
public static function getDomain()
{
$url = get_option('siteurl');
$urlobj = parse_url($url);
$domain = $urlobj['host'];
return $domain;
}
}
// Setup our shared resources early
// addthis_addjs.php is a standard class shared by the various AddThis plugins
// to make it easy for us to include our bootstrapping JavaScript only once.
// Priority should be lowest for Share plugin.
add_action('init', 'Addthis_Wordpress_early', 0);
/**
* Include addthis js widget
*
* @global AddThis_addjs $addthis_addjs
* @return null
*/
function Addthis_Wordpress_early()
{
global $addthis_addjs;
global $addThisConfigs;
if (!isset($addthis_addjs)) {
include 'includes/addthis_addjs_new.php';
$addthis_addjs = new AddThis_addjs($addThisConfigs);
}
}