array('http://wordpress.org/extend/plugins/addthis/', 'Share') ,
'AddThis Follow Widget' => array('http://wordpress.org/extend/plugins/addthis-follow/', 'Follow'),
// 'AddThis Trending Content Widget' => array('http://wordpress.org/extend/plugins/addthis-trending', 'Trending' ),
'AddThis Welcome Bar' => array('http://wordpress.org/extend/plugins/addthis-welcome/', 'Welcome'),
'AddThis Social Sign In' => array('http://wordpress.org/extend/plugins/addthis-social-sign-in/', 'SSI'),
);
private $_atInstalled = array();
var $pubid;
var $jsToAdd;
var $jsAfterAdd;
var $atversion;
var $productCode;
const addjs_version = 1;
/**
*
*/
public function __construct ($options){
if ( did_action('addthis_addjs_created') !== 0){
_doing_it_wrong( 'addthis_addjs', 'Only one instance of this class should be initialized. Look for the $addthis_addjs global first',1 );
}
$this->productCode = ADDTHIS_PRODUCT_VERSION;
// We haven't added our JS yet. Or at least better not have.
$this->_js_added = false;
$this->_options = $options;
// Version of AddThis code to use
if (is_array($options)) {
$this->atversion = array_key_exists('atversion_update_status', $options) && $options['atversion_update_status'] == ADDTHIS_ATVERSION_REVERTED ? $options['atversion'] : ADDTHIS_ATVERSION;
}
// set the cuid
$base = get_option('home');
$cuid = hash_hmac('md5', $base, 'addthis');
$this->_cuid = $cuid;
// If the footer option isn't set, check for it
if (! isset($this->_options['wpfooter']) && current_user_can('manage_options'))
{
add_action('admin_init',array($this, 'update_wpfooter'));
}
$this->pubid = $this->getProfileId();
// on theme swich, check for footer again
add_action('switch_theme', array($this, 'switch_theme'),15);
// In order for our wp_footer magic to work, we need to sometimes add our stuff
add_action('init', array($this, 'maybe_add_footer_comment'));
// Footer
if ( isset($this->_options['wpfooter']) && $this->_options['wpfooter'])
add_action('wp_footer', array($this, 'output_script') );
else
add_filter('the_content', array($this, 'output_script_filter') );
do_action('addthis_addjs_created');
}
function switch_theme(){
$footer = $this->check_for_footer();
$this->_options['wpfooter'] = $footer;
update_option( 'addthis_settings', $this->_options);
}
function output_script(){
if ($this->_js_added != true)
{
$this->wrapJs();
$this->addWidgetToJs();
$this->addAfterToJs();
echo $this->jsToAdd;
$this->_js_added = true;
$this->jsToAdd = false;
} else {
$this->addAfterToJs();
echo $this->jsToAdd;
$this->jsToAdd = false;
}
}
function output_script_filter($content){
if ($this->_js_added != true && ! is_admin() && ! is_feed() )
{
$this->wrapJs();
$this->addWidgetToJs();
$this->addAfterToJs();
$content = $content . $this->jsToAdd;
$this->_js_added = true;
}
return $content;
}
function wrapJs(){
$this->jsToAdd .= "var addthis_product = '".$this->productCode."';\n";
$this->jsToAdd = '';
}
/* testing for wp_footer in a theme stuff */
function update_wpfooter(){
$footer = $this->check_for_footer();
$options = $this->_options;
$options['wpfooter'] = $footer;
update_option( 'addthis_settings', $options);
$this->_options = $options;
}
function check_for_footer(){
$url = home_url();
$response = wp_remote_get( $url, array( 'sslverify' => false ) );
$code = (int) wp_remote_retrieve_response_code( $response );
if ( $code == 200 ) {
$html = preg_replace( '/[
s]/', '', wp_remote_retrieve_body( $response ) );
return (bool)( strstr( $html, '' ) );
}
}
function maybe_add_footer_comment(){
add_action( 'wp_footer', array($this, 'test_footer' ), 99999 ); // Some obscene priority, make sure we run last
}
function test_footer(){
echo '';
}
/* END testing for wp_footer in a theme stuff */
function addToScript($newData){
$this->jsToAdd .= $newData;
}
function addAfterScript($newData){
if ( $this->_js_added != true )
{
$this->jsAfterAdd .= $newData;
} else {
$this->jsAfterAdd = $newData;
}
}
function addWidgetToJs(){
$addthis_settings_options = get_option('addthis_settings');
$addthis_asynchronous_loading = (isset($addthis_settings_options['addthis_asynchronous_loading']))?$addthis_settings_options['addthis_asynchronous_loading']:false;
if(isset($addthis_asynchronous_loading) && $addthis_asynchronous_loading) {
$this->jsToAdd .= '';
$this->jsToAdd .= '';
} else {
$this->jsToAdd .= '';
}
}
function addAfterToJs(){
if (! empty($this->jsAfterAdd)) {
$this->jsToAdd .= '';
$this->jsAfterAdd = NULL;
}
}
/* User name and other shared resources */
function getUsername(){
return (isset($this->_options['username']))? $this->_options['username'] : false;
}
function setUsername($username){
$this->_options['username'] = sanitize_text_field($username);
update_option( 'addthis_settings', $options);
}
function getProfileId(){
return( isset( $this->_options['profile'] ) && ! empty($this->_options['profile']) )? $this->_options['profile'] : $this->_cuid;
}
function setProfileId($profile){
$this->_options['profile'] = sanitize_text_field($profile);
update_option( 'addthis_settings', $this->_options);
}
function getPassword(){
return (isset($this->_options['password']))? $this->_options['password'] : $this->_cuid;
}
function setPassword($password){
$this->_options['password'] = sanitize_text_field($password);
update_option( 'addthis_settings', $options);
}
function getAtPluginPromoText(){
if (! did_action('admin_init') && ! current_filter('admin_init'))
{
_doing_it_wrong('getAtPluginPromoText', 'This function should only be called on an admin page load and no earlier the admin_init', 1);
return null;
}
return null;
}
}