' . __( 'Loading…' ) . '
' . __('This widget requires JavaScript.') . '
';
}
add_action('wp_ajax_at_save_transient', 'addthis_save_transient');
function addthis_save_transient() {
global $wpdb; // this is how you get access to the database
parse_str($_POST['value'], $values);
// verify nonce (or die).
$nonce = $values['_wpnonce'];
if (! wp_verify_nonce($nonce, 'addthis-options') ) die('Security check');
// Parse Post data
$option_array = addthis_parse_options($values);
// Set Transient
if (false !== get_transient('addthis_settings'))
delete_transient('addthis_settings');
$eh = set_transient('addthis_settings', $option_array, 120);
print_r($option_array);
die();
}
function addthis_save_settings($input)
{
$options_array = addthis_parse_options($input);
return $options_array;
}
/**
* goes through all the options, sanitizing, verifying and returning for storage what needs to be there
*/
function addthis_parse_options($data)
{
require_once('addthis_settings_functions.php');
global $addthis_styles, $addthis_new_styles;
$styles = array_merge($addthis_styles, $addthis_new_styles);
$below_custom_styles = $above_custom_styles = '';
$options = array();
// Sanitize profile, username and password
if ( isset($data['addthis_username']) )
$options['username'] = sanitize_text_field($data['addthis_username']);
if ( isset($data['addthis_profile']) )
$options['profile'] = sanitize_text_field($data['addthis_profile']);
if ( isset($data['addthis_password']) )
$options['password'] = sanitize_text_field($data['addthis_password']);
if ( isset($data['username']) )
$options['username'] = sanitize_text_field($data['username']);
if ( isset($data['profile']) )
$options['profile'] = sanitize_text_field($data['profile']);
if ( isset($data['password']) )
$options['password'] = sanitize_text_field($data['password']);
if ( isset($data['wpfooter']))
$options['wpfooter'] = (bool) $data['wpfooter'];
if ( isset ($data['show_above']) )
$options['above'] = 'none';
elseif ( isset($styles[$data['above']]) )
$options['above'] = $data['above'];
elseif ($data['above'] == 'disable')
$options['above'] = $data['above'];
elseif ($data['above'] == 'none')
{
$options['above'] = 'none';
}
elseif ($data['above'] == 'custom')
{
$options['above_do_custom_services'] = isset($data['above_do_custom_services']) ;
$options['above_do_custom_preferred'] = isset($data['above_do_custom_preferred']) ;
$options['above'] = 'custom';
$options['above_custom_size'] = ( $data['above_custom_size'] == '16' || $data['above_custom_size'] == 32 ) ? $data['above_custom_size'] : '' ;
$options['above_custom_services'] = sanitize_text_field( $data['above_custom_services'] );
$options['above_custom_preferred'] = (int) $data['above_custom_preferred'] ;
$options['above_custom_more'] = isset($data['above_custom_more']);
}
elseif ($data['above'] == 'custom_string')
{
$options['above'] = 'custom_string';
if (strpos($data['above_custom_string'], "style=") != false) {
$custom_style = explode('style=', $data['above_custom_string']);
$custom_style = explode('>', $custom_style[1]);
$custom_style = explode(' ', $custom_style[0]);
$above_custom_styles = " style=$custom_style[0]";
}
$options['above_custom_string'] = addthis_kses($data['above_custom_string'], $above_custom_styles);
}
if ( isset ($data['show_below']) )
$options['below'] = 'none';
elseif ( isset($styles[$data['below']]) )
$options['below'] = $data['below'];
elseif ($data['below'] == 'disable')
$options['below'] = $data['below'];
elseif ($data['below'] == 'none')
{
$options['below'] = 'none';
}
elseif ($data['below'] == 'custom')
{
$options['below_do_custom_services'] = isset($data['below_do_custom_services']) ;
$options['below_do_custom_preferred'] = isset($data['below_do_custom_preferred']) ;
$options['below'] = 'custom';
$options['below_custom_size'] = ( $data['below_custom_size'] == '16' || $data['below_custom_size'] == 32 ) ? $data['below_custom_size'] : '' ;
$options['below_custom_services'] = sanitize_text_field( $data['below_custom_services'] );
$options['below_custom_preferred'] = sanitize_text_field( $data['below_custom_preferred'] );
$options['below_custom_more'] = isset($data['below_custom_more']);
}
elseif ($data['below'] == 'custom_string')
{
$options['below'] = 'custom_string';
if (strpos($data['below_custom_string'], "style=") != false) {
$custom_style = explode('style=', $data['below_custom_string']);
$custom_style = explode('>', $custom_style[1]);
$custom_style = explode(' ', $custom_style[0]);
$below_custom_styles = " style=$custom_style[0]";
}
$options['below_custom_string'] = addthis_kses($data['below_custom_string'], $below_custom_styles);
}
if (isset($data['addthis_copytrackingremove']) && $data['addthis_copytrackingremove'] == true)
unset($data['addthis_copytracking1']);
// All the checkbox fields
foreach (array('addthis_show_stats', 'addthis_asynchronous_loading','addthis_append_data', 'addthis_showonhome', 'addthis_showonpages', 'addthis_showonarchives', 'addthis_showoncats', 'addthis_showonexcerpts', 'addthis_aftertitle' , 'addthis_beforecomments', 'addthis_addressbar','addthis_508','addthis_copytracking2' ) as $field)
{
if ( isset($data[$field]) && $data[$field] == true)
$options[$field] = true;
else
$options[$field] = false;
}
if ( isset ($data['data_ga_property']) && strlen($data['data_ga_property']) != 0)
$options['data_ga_property'] = sanitize_text_field($data['data_ga_property']);
//[addthis_twitter_template]
if ( isset ($data['addthis_twitter_template']) && strlen($data['addthis_twitter_template']) != 0 ) {
//Parse the first twitter username to be used with via
$options['addthis_twitter_template'] = get_first_twitter_username(sanitize_text_field($data['addthis_twitter_template']));
}
if (isset ($data['addthis_bitly_login']) && strlen($data['addthis_bitly_login']) != 0 )
$options['addthis_bitly_login'] = sanitize_text_field($data['addthis_bitly_login']);
if (isset ($data['addthis_bitly_key']) && strlen($data['addthis_bitly_key']) != 0 )
$options['addthis_bitly_key'] = sanitize_text_field($data['addthis_bitly_key']);
//[addthis_brand] =>
if ( isset ($data['addthis_brand']) && strlen($data['addthis_brand']) != 0 )
$options['addthis_brand'] = sanitize_text_field($data['addthis_brand']);
//[addthis_options] =>
if ( isset ($data['addthis_options']) && strlen($data['addthis_options']) != 0 )
$options['addthis_options'] = str_replace(' ', '', esc_js( strtolower( $data['addthis_options'] ) ));
//[addthis_language] =>
if ( isset ($data['addthis_language']))
$options['addthis_language'] = sanitize_text_field($data['addthis_language']);
//[atversion]=>
if ( isset ($data['atversion']))
$options['atversion'] = sanitize_text_field($data['atversion']);
//[atversion_update_status]=>
if ( isset ($data['atversion_update_status']))
$options['atversion_update_status'] = sanitize_text_field($data['atversion_update_status']);
if ( isset ($data['credential_validation_status']))
$options['credential_validation_status'] = sanitize_text_field($data['credential_validation_status']);
if ( isset ($data['addthis_header_background']) && strlen($data['addthis_header_background']) != 0 )
{
if (! strpos($data['addthis_header_background'], '#') === 0)
$options['addthis_header_background'] = '#' . sanitize_text_field($data['addthis_header_background']);
else
$options['addthis_header_background'] = sanitize_text_field($data['addthis_header_background']);
}
if ( isset ($data['addthis_header_color']) && strlen($data['addthis_header_color']) != 0 )
{
if (! strpos($data['addthis_header_color'], '#') === 0)
$options['addthis_header_color'] = '#' . sanitize_text_field($data['addthis_header_color']);
else
$options['addthis_header_color'] = sanitize_text_field($data['addthis_header_color']);
}
if (isset ($data['addthis_config_json']) && strlen($data['addthis_config_json']) != 0 )
{
$options['addthis_config_json'] = sanitize_text_field($data['addthis_config_json']);
}
if (isset ($data['addthis_share_json']) && strlen($data['addthis_share_json']) != 0 )
{
$options['addthis_share_json'] = sanitize_text_field($data['addthis_share_json']);
}
if (isset ($data['above_chosen_list']) && strlen($data['above_chosen_list']) != 0)
{
$options['above_chosen_list'] = sanitize_text_field($data['above_chosen_list']);
}
else {
$options['above_chosen_list'] = "";
}
if (isset ($data['below_chosen_list']) && strlen($data['below_chosen_list']) != 0)
{
$options['below_chosen_list'] = sanitize_text_field($data['below_chosen_list']);
}
else {
$options['below_chosen_list'] = "";
}
return $options;
}
/**
* Formally registers AddThis settings. Only called in WP 2.7+.
*/
function register_addthis_settings() {
register_setting('addthis', 'addthis_settings', 'addthis_save_settings');
}
/*
* Used to make sure excerpts above the head aren't displayed wrong
*/
function addthis_add_content_filters()
{
global $addthis_did_filters_added;
$addthis_did_filters_added = true;
if ( isset($_GET['preview']) && $_GET['preview'] == 1 && $options = get_transient('addthis_settings') )
$preview = true;
else
$options = get_option('addthis_settings');
if ( ! empty( $options) ){
if ( isset($options['addthis_showonexcerpts']) && $options['addthis_showonexcerpts'] == true )
add_filter('get_the_excerpt', 'addthis_display_social_widget_excerpt', 11);
if ( isset($options['addthis_aftertitle']) && $options['addthis_aftertitle'] == true)
add_filter('the_title', 'addthis_display_after_title', 11);
add_filter('the_content', 'addthis_display_social_widget', 15);
}
}
/**
* Adds WP filter so we can append the AddThis button to post content.
*/
function addthis_init()
{
global $addthis_settings;
add_action( 'wp_head', 'addthis_add_content_filters');
if (addthis_get_wp_version() >= 2.7 || apply_filters('at_assume_latest', __return_false() ) || apply_filters('addthis_assume_latest', __return_false() ) ) {
if ( is_admin() ) {
add_action( 'admin_init', 'register_addthis_settings' );
}
}
$options = get_option('addthis_settings');
$script_location = apply_filters( 'at_files_uri', plugins_url( '', basename(dirname(__FILE__)) ) ) . '/addthis/js/addthis.js' ;
$script_location = apply_filters( 'addthis_files_uri', plugins_url( '', basename(dirname(__FILE__)) ) ) . '/addthis/js/addthis.js' ;
$style_location = apply_filters( 'at_files_uri', plugins_url( '', basename(dirname(__FILE__)) ) ) .'/addthis/css/addthis.css' ;
$style_location = apply_filters( 'addthis_files_uri', plugins_url( '', basename(dirname(__FILE__)) ) ) .'/addthis/css/addthis.css' ;
wp_register_style( 'addthis', $style_location );
wp_register_script( 'addthis', $script_location , array('jquery-ui-tabs') );
add_action('admin_print_styles-index.php', 'addthis_print_style');
add_action('admin_print_scripts-index.php', 'addthis_print_script');
add_filter('admin_menu', 'addthis_admin_menu');
if ( apply_filters( 'at_do_options_upgrades', '__return_true') || apply_filters( 'addthis_do_options_upgrades', '__return_true') )
{
if ( get_option('addthis_product') !== false && ! is_array( $options ) )
addthis_options_200();
// Upgrade to 210 from 200
if ( isset($options['username']) && ! isset($options['profile']) )
addthis_options_210();
// Upgrade to 240 and add at 300
if ( ! isset($options['atversion']) )
addthis_options_240();
}
add_action( 'addthis_widget', 'addthis_print_widget', 10, 3);
}
/**
* Places our options into a global associative array.
* @refactor
*/
function addthis_set_addthis_settings()
{
global $addthis_settings;
$product = get_option('addthis_product');
$style = get_option('addthis_style');
if (strlen($style) == 0) $style = 'share';
$addthis_settings['style'] = $style;
$addthis_settings['menu_type'] = get_option('addthis_menu_type');
$addthis_settings['username'] = get_option('addthis_username');
$addthis_settings['fallback_username'] = get_option('addthis_fallback_username');
$addthis_settings['password'] = get_option('addthis_password');
$language = get_option('addthis_language');
$addthis_settings['language'] = $language;
$atversion = get_option('atversion');
$addthis_settings['atversion'] = $atversion;
$advopts = array('brand', 'append_data', 'language', 'header_background', 'header_color');
$addthis_settings['customization'] = '';
for ($i = 0; $i < count($advopts); $i++)
{
$opt = $advopts[$i];
$val = get_option("addthis_$opt");
if (isset($val) && strlen($val)) $addthis_settings['customization'] .= "var addthis_$opt = '$val';";
}
$addthis_settings['options'] = get_option('addthis_options');
}
add_action('wp_dashboard_setup', 'addthis_dashboard_init' );
add_action('widgets_init', 'addthis_widget_init');
function addthis_widget_init()
{
require_once('addthis_settings_functions.php');
require_once('addthis_sidebar_widget.php');
//require_once('addthis_content_feed_widget.php');
register_widget('AddThisSidebarWidget');
//register_widget('AddThisContentFeedWidget');
}
function addthis_sidebar_widget($args)
{
extract($args);
echo $before_widget;
echo $before_title . $after_title . addthis_social_widget('', true);
echo $after_widget;
}
// essentially replace wp_trim_excerpt until we have something better to use here
function addthis_remove_tag($content, $text = '')
{
if ( isset($_GET['preview']) && $_GET['preview'] == 1 && $options = get_transient('addthis_settings') )
$preview = true;
else
$options = get_option('addthis_settings');
$raw_excerpt = $text;
if ( '' == $text ) {
$text = get_the_content('');
$text = strip_shortcodes( $text );
remove_filter('the_content', 'addthis_display_social_widget', 15);
$text = apply_filters('the_content', $text);
add_filter('the_content', 'addthis_display_social_widget', 15);
$text = str_replace(']]>', ']]>', $text);
// 3.3 and earlier
if (! function_exists('wp_trim_words'))
$text = strip_tags($text);
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
// 3.3 and later
if (function_exists('wp_trim_words'))
{
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
else
{
$words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(' ', $words);
$text = $text . $excerpt_more;
} else {
$text = implode(' ', $words);
}
}
if ($options['addthis_showonexcerpts'] == false)
return $text;
return addthis_display_social_widget($text, false, false);
}
else
{
return $content;
}
}
/**
* so named because it is added "later then the standard filter and all the WP internal filters"
*/
function addthis_late_widget($link_text)
{
remove_filter('get_the_excerpt', 'addthis_late_widget');
if ( isset($_GET['preview']) && $_GET['preview'] == 1 && $options = get_transient('addthis_settings') )
$preview = true;
else
$options = get_option('addthis_settings');
if ($options['addthis_showonexcerpts'] == false)
return $link_text;
global $addthis_styles, $addthis_new_styles;
$styles = array_merge($addthis_styles, $addthis_new_styles);
$url = get_permalink();
$title = get_the_title();
$url_above = '';
$url_below = '';
if ( isset($_GET['preview']) && $_GET['preview'] == 1 && $options = get_transient('addthis_settings') )
$preview = true;
else
$options = get_option('addthis_settings');
$url_below = "addthis:url='$url' ";
$url_below .= "addthis:title='". esc_attr( $title) ." '";
if (has_excerpt() && ! is_attachment() && isset($options['below']) && $options['below'] == 'custom')
{
$belowOptions['size'] = $options['below_custom_size'];
if ($options['below_do_custom_services'])
$belowOptions['services'] = $options['below_custom_services'];
if ($options['below_do_custom_preferred'])
$belowOptions['preferred'] = $options['below_custom_preferred'];
$belowOptions['more'] = $options['below_custom_more'];
return $link_text . apply_filters('addthis_below_content', addthis_custom_toolbox($belowOptions, $url, $title) );
}
elseif ( isset ($styles[$options['below']]) && has_excerpt() && ! is_attachment() )
{
$below = apply_filters('addthis_below_content', $styles[$options['below']]['src']);
}
else
{
$below = apply_filters('addthis_below_content','' );
}
return $link_text . sprintf($below, $url_below);
}
function addthis_display_social_widget_excerpt($content)
{
if ( isset($_GET['preview']) && $_GET['preview'] == 1 && $options = get_transient('addthis_settings') )
$preview = true;
else
$options = get_option('addthis_settings');
// I don't think has_excerpt() is always necessarily true when calling "get_the_excerpt()",
// but since this function is only as a get_the_excerpt() filter, we should probably
// not care whether or not an excerpt is there since the caller obviously wants one.
// needs testing/understanding.
if ( has_excerpt() && $options['addthis_showonexcerpts'] == true ) {
return addthis_display_social_widget($content, true, true);
} else
return $content;
}
function addthis_display_widget_above($styles, $url, $title, $options) {
$above = '';
if (isset($styles[$options['above']])) {
if (isset($options['above_chosen_list']) && strlen($options['above_chosen_list']) != 0) {
if (isset($options['above']) && $options['above'] == 'large_toolbox') {
$aboveOptions['size'] = '32';
} elseif (isset($options['above']) && $options['above'] == 'small_toolbox') {
$aboveOptions['size'] = '16';
}
$aboveOptions['type'] = $options['above'];
$aboveOptions['services'] = $options['above_chosen_list'];
if(isset($options['addthis_options']))
$aboveOptions['addthis_options'] = $options['addthis_options'];
else
$aboveOptions['addthis_options'] = '';
$above = apply_filters('addthis_above_content', addthis_custom_toolbox($aboveOptions, $url, $title));
} else {
$above = apply_filters('addthis_above_content', $styles[$options['above']]['src']);
}
} elseif ($options['above'] == 'custom') {
$aboveOptions['size'] = $options['above_custom_size'];
if ($options['above_do_custom_services'])
$aboveOptions['services'] = $options['above_custom_services'];
if ($options['above_do_custom_preferred'])
$aboveOptions['preferred'] = $options['above_custom_preferred'];
$aboveOptions['more'] = $options['above_custom_more'];
$aboveOptions['addthis_options'] = $options['addthis_options'];
$above = apply_filters('addthis_above_content', addthis_custom_toolbox($aboveOptions, $url, $title));
} elseif ($options['above'] == 'custom_string') {
$custom = preg_replace('/<\s*div\s*/', 'post_content, '') != false) {
$display = false;
}
else {
$display = true;
}
}
}
else {
if (isset($options['addthis_showonexcerpts']) && $options['addthis_showonexcerpts'] == true ) {
if( strpos($post->post_content, '') != false) {
$display = true;
}
else {
$display = false;
}
}
else {
$display = false;
}
}
}
elseif ( is_archive() && ! is_category() )
$display = (isset($options['addthis_showonarchives']) && $options['addthis_showonarchives'] == true ) ? true : false;
// Cat
elseif ( is_category() )
$display = (isset($options['addthis_showoncats']) && $options['addthis_showoncats'] == true ) ? true : false;
// Pages
elseif ( is_page($post->ID) )
$display = (isset($options['addthis_showonpages']) && $options['addthis_showonpages'] == true) ? true: false;
// Single pages (true by default and design)
elseif ( is_single() )
$display = true;
else
$display = false;
$custom_fields = get_post_custom($post->ID);
if (isset ($custom_fields['addthis_exclude']) && $custom_fields['addthis_exclude'][0] == 'true')
$display = false;
$display = apply_filters('addthis_post_exclude', $display);
remove_filter('wp_trim_excerpt', 'addthis_remove_tag', 9, 2);
remove_filter('get_the_excerpt', 'addthis_late_widget');
$url = get_permalink();
$title = get_the_title();
$url_above = "addthis:url='$url' ";
$url_above .= "addthis:title='". esc_attr( $title) ." '";
$url_below = "addthis:url='$url' ";
$url_below .= "addthis:title='". esc_attr( $title) ." '";
$above = '';
$below = '';
// Still here? Well let's add some social goodness
if ( isset( $options['above'] ) && $options['above'] != 'none' && $options['above'] != 'disable' && $display )
{
$above = addthis_display_widget_above($styles, $url, $title, $options);
}
elseif ($display)
$above = apply_filters('addthis_above_content','' );
else
$above = '';
if ( isset( $options['below'] ) && $options['below'] != 'none' && $options['below'] != 'disable' && $display && ! $below_excerpt )
{
$below = addthis_display_widget_below($styles, $url, $title, $options);
}
elseif ($below_excerpt && $display && $options['below'] != 'none' )
{
$below = apply_filters('addthis_below_content','' );
if ($options['addthis_showonexcerpts'] == true )
add_filter('get_the_excerpt', 'addthis_late_widget', 14);
}
elseif ($display)
$below = apply_filters('addthis_below_content','' );
else
$below = '';
if ($display)
{
if ( isset($above) )
{
$content = sprintf($above, $url_above) . $content;
}
if ( isset($below) )
{
$content = $content . sprintf($below, $url_below);
}
if ($filtered == true)
add_filter('wp_trim_excerpt', 'addthis_remove_tag', 11, 2);
}
return $content;
}
add_action('init', 'addthis_register_script_in_addjs', 20);
function addthis_register_script_in_addjs(){
global $addthis_addjs;
$script = addthis_output_script(true, true);
$addthis_addjs->addToScript($script);
}
//add_action('wp_footer', 'addthis_output_script');
/**
* Check to see if our Javascript has been outputted yet. If it hasn't, return it. Else, return false.
*
* @return mixed
*/
function addthis_output_script($return = false, $justConfig = false )
{
global $addthis_settings;
wp_enqueue_style( 'output', plugins_url('css/output.css', __FILE__) );
if ( isset($_GET['preview']) && $_GET['preview'] == 1 && $options = get_transient('addthis_settings') )
$preview = true;
else
$options = get_option('addthis_settings');
$script = "\n\n"
.'';
$script .= '';
if ( ! is_admin() && ! is_feed() )
echo $script;
elseif ($return == true && ! is_admin() && ! is_feed() )
return $script;
}
add_action('wp_ajax_validate_addthis_api_credentials', 'validate_addthis_api_credentials');
/**
* AJAX action to test the AddThis credentials
*/
function validate_addthis_api_credentials()
{
$ajax_response = array('profileerror' => 'true', 'profilemessage' => '',
'credentialerror' => 'true', 'credentialmessage' => '');
if ($_POST['addthis_username'] && $_POST['addthis_password'] && $_POST['addthis_profile']) {
$url = 'https://api.addthis.com/analytics/1.0/pub/shares.json?'.
'username=' . urlencode($_POST['addthis_username']).
'&password=' . urlencode($_POST['addthis_password']).
'&pubid=' . urlencode($_POST['addthis_profile']);
$response = wp_remote_get($url);
$credential_error = '✖ The username, password, and profile combination you entered is invalid.';
$profile_error = '✖ Invalid AddThis profile ID';
if (!is_wp_error($response)) {
if ($response['response']['code'] == 200) {
$ajax_response['profileerror'] = 'false';
$ajax_response['credentialerror'] = 'false';
} else {
if ($response['response']['code'] != 401) {
$ajax_response['credentialerror'] = 'false';
if (strpos($response['body'], '"invalidParameterName":"pubid"') === FALSE) {
$ajax_response['profileerror'] = 'false';
} else {
$ajax_response['profilemessage'] = $profile_error;
}
} else {
$ajax_response['credentialmessage'] = $credential_error;
}
}
} else {
$ajax_response['credentialmessage'] = 'error';
}
}
die('{"profileerror":"' . $ajax_response['profileerror'] . '","profilemessage":"' . $ajax_response['profilemessage'] . '",
"credentialerror":"' . $ajax_response['credentialerror'] . '","credentialmessage":"' . $ajax_response['credentialmessage'] . '"}');
}
/*
* Merge the Add this settings with that given using JSON format
* @param String $appendString - The string to build and return the script
* @param array $addthis_config - The setting array for add this config
* @param String $addthis_json_config - The JSON String
* @return String $appendString - The string to build and return the script
*/
function merge_config_with_json_config($append_string, $addthis_config, $addthis_json_config) {
if ( isset( $addthis_json_config ) && trim($addthis_json_config) != '') {
$addthis_config_json_list = json_decode($addthis_json_config, true);
if (! empty ($addthis_config_json_list) && ! empty ($addthis_config)) {
foreach($addthis_config_json_list as $key_json => $json_config_value) {
$addthis_config[$key_json] = $json_config_value;
}
}
}
if (! empty ($addthis_config) )
$append_string .= 'var addthis_config = '. json_encode($addthis_config) .';';
return $append_string;
}
/*
* Merge the Add this settings with that given using JSON format
* @param String $appendString - The string to build and return the script
* @param array $addthis_share - The setting array for add this share
* @param String $addthis_json_share - The JSON String
* @return String $appendString - The string to build and return the script
*/
function merge_share_with_json_share($addthis_share, $addthis_json_share) {
$append_string = '';
if ( isset( $addthis_json_share ) && trim($addthis_json_share) != '') {
$addthis_share_json_list = json_decode($addthis_json_share, true);
if (! empty ($addthis_share_json_list) && ! empty ($addthis_share)) {
foreach($addthis_share_json_list as $key_json => $json_share_value) {
$addthis_share[$key_json] = $json_share_value;
}
}
}
if (! empty ($addthis_share) )
$append_string = 'if (typeof(addthis_share) == "undefined"){ addthis_share = '. json_encode($addthis_share) .';}';
return $append_string;
}
/**
* Appends AddThis button to post content.
*/
function addthis_social_widget($content, $onSidebar = false, $url = null, $title = null)
{
addthis_set_addthis_settings();
global $addthis_settings;
// add nothing to RSS feed or search results; control adding to static/archive/category pages
if (!$onSidebar)
{
if ($addthis_settings['sidebar_only'] == 'true') return $content;
else if (is_feed()) return $content;
else if (is_search()) return $content;
else if (is_home() && !$addthis_settings['showonhome']) return $content;
else if (is_page() && !$addthis_settings['showonpages']) return $content;
else if (is_archive() && !$addthis_settings['showonarchives']) return $content;
else if (is_category() && !$addthis_settings['showoncats']) return $content;
}
$pub = ($addthis_settings['username']);
if (!$pub) {
$pub = 'wp-'.cuid();
}
$pub = urlencode($pub);
$link = !is_null($url) ? $url : ($onSidebar ? get_bloginfo('url') : get_permalink());
$title = !is_null($title) ? $title : ($onSidebar ? get_bloginfo('title') : the_title('', '', false));
$addthis_options = $addthis_settings['options'];
$content .= "\n\n"
.'
';
}
else if ($addthis_settings['menu_type'] === 'toolbox')
{
$content .= "\n//-->\n\n";
$content .= <<
Share|
EOF;
if (!strlen($addthis_options)) $addthis_options = 'email,favorites,print,facebook,twitter';
$addthis_options = split(',', $addthis_options);
foreach ($addthis_options as $option) {
$option = trim($option);
if ($option != 'more') {
$content .= '';
}
}
$content .= ' ';
}
else
{
$link = urlencode($link);
$title = urlencode($title);
$content .= <<