getConfigs();
require_once('addthis_settings_functions.php');
/**
* Show Plugin activation notice on first installation*
*/
function pluginActivationNotice()
{
$run_once = get_option('addthis_run_once');
global $cmsConnector;
if (!$run_once) {
wp_enqueue_style(
'addThisStylesheet',
plugins_url('css/style.css', __FILE__)
);
$html = '
';
if (isset($options['services']) ) {
$services = explode(',', $options['services']);
foreach ($services as $service)
{
$service = trim($service);
if ($service == 'more' || $service == 'compact') {
if (isset($options['type']) && $options['type'] != 'fb_tw_p1_sc') {
$button .= '
';
}
}
else if ($service == 'counter') {
if (isset($options['type']) && $options['type'] == 'fb_tw_p1_sc') {
$button .= '
';
}
else {
$button .= '
';
}
}
else if ($service == 'google_plusone') {
$button .= '
';
}
else
$button .= '
';
}
}
if (isset($options['preferred']) && is_numeric($options['preferred']))
{
for ($a = 1; $a <= $options['preferred']; $a++)
{
$button .= '
';
}
}
if (isset($options['more']) && $options['more'] == true)
{
$button .= '
';
}
if (isset($options['counter']) && ($options['counter'] != "") && ($options['counter'] !== false))
{
if ($options['counter'] === true)
{ //no style was specified
$button .= '
';
}
else
{ //a specific style was specified such as pill_style or bubble_style
$button .= '
';
}
}
$button .= '
';
}
return $button;
}
/**
* Adds AddThis CSS to page. Only used for admin dashboard in WP 2.7 and higher.
*/
function addthis_print_style() {
wp_enqueue_style( 'addthis' );
}
/**
* Adds AddThis script to page. Only used for admin dashboard in WP 2.7 and higher.
*/
function addthis_print_script() {
wp_enqueue_script( 'addthis' );
}
add_action('admin_notices', 'addthis_admin_notices');
function addthis_admin_notices(){
if (! current_user_can('manage_options') ||( defined('ADDTHIS_NO_NOTICES') && ADDTHIS_NO_NOTICES == true ) )
return;
global $cmsConnector;
global $current_user ;
$user_id = $current_user->ID;
$options = get_option('addthis_settings');
if (!$options && ! get_user_meta($user_id, 'addthis_ignore_notices')) {
echo '' . __( '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 (get_transient('addthis_settings') !== false) {
delete_transient('addthis_settings');
}
$eh = set_transient('addthis_settings', $option_array, 120);
print_r($option_array);
die();
}
function addthis_save_settings($input)
{
global $addThisConfigs;
$options_array = $addThisConfigs->getConfigs();
// if special, do special, else
if ( isset($input['addthis_csr_confirmation'])
&& $input['addthis_csr_confirmation'] == 'true'
) {
if ( isset($input['addthis_profile'])
&& wp_verify_nonce($_POST['pubid_nonce'], 'update_pubid')
) {
$options_array['addthis_profile'] = $input['addthis_profile'];
}
} else {
$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)
{
global $addthis_styles, $addthis_new_styles;
global $addThisConfigs;
$styles = array_merge($addthis_styles, $addthis_new_styles);
$below_custom_styles = $above_custom_styles = '';
$options = $addThisConfigs->getConfigs();
if ( isset($data['above_sharing']))
$options['above_sharing'] = $data['above_sharing'];
if ( isset($data['below_sharing']))
$options['below_sharing'] = $data['below_sharing'];
if ( isset ($data['show_below']) )
$options['below'] = 'none';
elseif (isset($data['below'], $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['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')
{
//[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']));
}
$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['addthis_profile'])) {
$options['addthis_profile'] = sanitize_text_field($data['addthis_profile']);
}
if ( isset($data['above_sharing']))
$options['above_sharing'] = $data['above_sharing'];
if ( isset($data['below_sharing']))
$options['below_sharing'] = $data['below_sharing'];
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);
}
// All the checkbox fields
$checkboxFields = array(
'addthis_508',
'addthis_above_enabled',
'addthis_addressbar',
'addthis_aftertitle' ,
'addthis_append_data',
'addthis_append_data',
'addthis_asynchronous_loading',
'addthis_beforecomments',
'addthis_below_enabled',
'addthis_bitly',
'addthis_sidebar_enabled',
);
// add all share button location template settings to list of checkbox fields
$locationTemplateFields = $addThisConfigs->getFieldsForContentTypeSharingLocations();
foreach ($locationTemplateFields as $field) {
$optionName = $field['fieldName'];
$checkboxFields[] = $optionName;
}
foreach ($checkboxFields as $field)
{
if (isset($data[$field]) && $data[$field]) {
$options[$field] = true;
} else {
$options[$field] = false;
}
}
if (isset($data['data_ga_property'])) {
$options['data_ga_property'] = sanitize_text_field($data['data_ga_property']);
}
//[addthis_twitter_template]
if ( isset ($data['addthis_twitter_template'])) {
//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']) && strlen($data['addthis_bitly']) != 0 )
$options['addthis_bitly'] = sanitize_text_field($data['addthis_bitly']);
//[addthis_brand] =>
if ( isset ($data['addthis_brand']) && strlen($data['addthis_brand']) != 0 )
$options['addthis_brand'] = sanitize_text_field($data['addthis_brand']);
//[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'])) {
$options['addthis_config_json'] = sanitize_text_field($data['addthis_config_json']);
}
if (isset($data['addthis_share_json'])) {
$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'] = "";
}
if(isset ($data['addthis_sidebar_position'])){
$options['addthis_sidebar_position'] = $data['addthis_sidebar_position'];
}
if(isset ($data['addthis_sidebar_count'])){
$options['addthis_sidebar_count'] = $data['addthis_sidebar_count'];
}
if(isset ($data['addthis_sidebar_theme'])){
$options['addthis_sidebar_theme'] = $data['addthis_sidebar_theme'];
}
if(isset($data['addthis_environment'])){
$options['addthis_environment'] = $data['addthis_environment'];
}
if(isset ($data['addthis_plugin_controls'])){
$options['addthis_plugin_controls'] = $data['addthis_plugin_controls'];
}
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;
global $addThisConfigs;
$addthis_did_filters_added = true;
$options = $addThisConfigs->getConfigs();
if ( ! empty( $options) ){
if (_addthis_excerpt_buttons_enabled()) {
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 $addThisConfigs;
global $cmsConnector;
$options = $addThisConfigs->getConfigs();
add_action('wp_head', 'addthis_add_content_filters');
if ( ( $cmsConnector->getCmsMinorVersion() >= 2.7
|| $cmsConnector->assumeLatest())
&& is_admin()
) {
add_action('admin_init', 'register_addthis_settings');
}
add_action('admin_print_styles-index.php', 'addthis_print_style');
add_action('admin_print_scripts-index.php', 'addthis_print_script');
add_filter('admin_menu', 'addToWordpressMenu');
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 240 and add at 300
if (!isset($options['atversion']) || empty($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');
$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';";
}
}
add_action('widgets_init', 'addthis_widget_init');
function addthis_widget_init()
{
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 = '')
{
global $addThisConfigs;
$options = $addThisConfigs->getConfigs();
$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 (!_addthis_excerpt_buttons_enabled()) {
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)
{
global $addThisConfigs;
remove_filter('get_the_excerpt', 'addthis_late_widget');
$options = $addThisConfigs->getConfigs();
if (!_addthis_excerpt_buttons_enabled()) {
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 = "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)
{
// 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() && _addthis_excerpt_buttons_enabled()) {
return addthis_display_social_widget($content, true, true);
} else {
return $content;
}
}
function addthis_display_widget_above($styles, $url, $title, $options) {
$above = '';
if ($options['addthis_above_enabled'] == true){
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'];
$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'];
$above = apply_filters('addthis_above_content', addthis_custom_toolbox($aboveOptions, $url, $title));
} elseif ($options['above'] == 'custom_string') {
$custom = preg_replace('/<\s*div\s*/', 'getConfigs();
$templateType = _addthis_determine_template_type();
// get configs for this template type
if (is_string($templateType)) {
$fieldList = $addThisConfigs->getFieldsForContentTypeSharingLocations($templateType);
foreach ($fieldList as $key => $field) {
$fieldList[$field['location']] = $field;
unset($fieldList[$key]);
}
$aboveFieldName = $fieldList['above']['fieldName'];
$belowFieldName = $fieldList['below']['fieldName'];
$displayAbove = (isset($options[$aboveFieldName]) && $options[$aboveFieldName] == true ) ? true : false;
$displayBelow = (isset($options[$belowFieldName]) && $options[$belowFieldName] == true ) ? true : false;
} else {
$displayAbove = false;
$displayBelow = false;
}
if ( $templateType === 'home' ) {
$templateIsAnExcerpt = (boolean)(strpos($post->post_content, '') != false);
if ($templateIsAnExcerpt) {
if ($displayAbove && !_addthis_excerpt_buttons_enabled_above()) {
$displayAbove = false;
}
if ($displayBelow && !_addthis_excerpt_buttons_enabled_below()) {
$displayBelow = false;
}
}
}
$custom_fields = get_post_custom($post->ID);
if ( isset($custom_fields['addthis_exclude'])
&& $custom_fields['addthis_exclude'][0] == 'true'
) {
$displayAbove = false;
$displayBelow = false;
}
$displayAbove = apply_filters('addthis_post_exclude', $displayAbove);
$displayBelow = apply_filters('addthis_post_exclude', $displayBelow);
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) ." '";
// Still here? Well let's add some social goodness
if ( isset($options['above'])
&& $options['above'] != 'none'
&& $options['above'] != 'disable'
&& $displayAbove
) {
$above = addthis_display_widget_above($styles, $url, $title, $options);
} elseif ($displayAbove) {
$above = apply_filters('addthis_above_content', '');
} else {
$above = '';
}
if ( isset($options['below'])
&& $options['below'] != 'none'
&& $options['below'] != 'disable'
&& $displayBelow
&& ! $below_excerpt
) {
$below = addthis_display_widget_below($styles, $url, $title, $options);
} elseif ( $below_excerpt
&& $displayBelow
&& $options['below'] != 'none'
) {
$below = apply_filters('addthis_below_content','' );
if (_addthis_excerpt_buttons_enabled()) {
add_filter('get_the_excerpt', 'addthis_late_widget', 14);
}
} elseif ($displayBelow) {
$below = apply_filters('addthis_below_content', '');
} else {
$below = '';
}
$at_flag = get_post_meta( $post->ID, '_at_widget', TRUE );
if ($at_flag !== '0') {
if ($displayAbove && isset($above)) {
$content = sprintf($above, $url_above) . $content;
}
if ($displayBelow && isset($below)) {
$content = $content . sprintf($below, $url_below);
}
}
if (($displayAbove || $displayBelow) && $filtered) {
add_filter('wp_trim_excerpt', 'addthis_remove_tag', 11, 2);
}
return $content;
}
add_action('wp_head', '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);
$addthis_sidebar = addthis_sidebar_script();
$addthis_addjs->addAfterScript($addthis_sidebar);
}
//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 $addThisConfigs;
$options = $addThisConfigs->getConfigs();
$script = "\n\n"
.'';
$script .= '';
if ( ! is_admin() && ! is_feed() )
echo $script;
elseif ($return == true && ! is_admin() && ! is_feed() )
return $script;
}
function addthis_sidebar_script(){
global $addThisConfigs;
$options = $addThisConfigs->getConfigs();
$return = '';
if ($options['addthis_sidebar_enabled'] != true) {
return $return;
}
$templateType = _addthis_determine_template_type();
if (is_string($templateType)) {
$fieldList = $addThisConfigs->getFieldsForContentTypeSharingLocations($templateType, 'sidebar');
$fieldName = $fieldList[0]['fieldName'];
$display = (isset($options[$fieldName]) && $options[$fieldName]) ? true : false;
} else {
echo "templateType wasn't a string :-(
\n";
$display = false;
}
if (!$display) {
return $return;
}
$return .= "
(function() {
var at_interval = setInterval(function () {
if(window.addthis) {
clearInterval(at_interval);
addthis.layers(
{
'theme' : '".strtolower($options['addthis_sidebar_theme'])."',
'share' : {
'position' : '".$options['addthis_sidebar_position']."',
'numPreferredServices' : ".$options['addthis_sidebar_count']."
}
}
);
}
},1000)
}());";
return $return;
}
/*
* Merge the AddThis 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 AddThis 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 AddThis 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 AddThis 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;
global $addThisConfigs;
// add nothing to RSS feed or search results; control adding to static/archive/category pages
if (!$onSidebar)
{
if ( $addthis_settings['sidebar_only']
|| is_feed()
|| is_search()
|| is_home()
|| is_page()
|| is_archive()
|| is_category()
) {
return $content;
}
}
$pub = urlencode($addThisConfigs->getUsableProfileId());
$link = !is_null($url) ? $url : ($onSidebar ? get_bloginfo('url') : get_permalink());
$title = !is_null($title) ? $title : ($onSidebar ? get_bloginfo('title') : the_title('', '', false));
$content .= "\n\n"
.'
';
}
else if ($addthis_settings['menu_type'] === 'toolbox')
{
$content .= "\n//-->\n\n";
$content .= <<
Share|
EOF;
$content .= ' ';
}
else
{
$link = urlencode($link);
$title = urlencode($title);
$content .= <<