diff -r 2f6f6f7551ca -r 32102edaa81b web/wp-content/plugins/add-to-any/add-to-any.php --- a/web/wp-content/plugins/add-to-any/add-to-any.php Thu Sep 16 15:45:36 2010 +0000 +++ b/web/wp-content/plugins/add-to-any/add-to-any.php Mon Nov 19 18:26:13 2012 +0100 @@ -1,210 +1,377 @@ Settings] -Version: .9.9.4.3 -Author: Add to Any -Author URI: http://www.addtoany.com/contact/ +Plugin Name: Share Buttons by Lockerz / AddToAny +Plugin URI: http://share.lockerz.com/ +Description: Help people share, bookmark, and email your posts & pages using any service, such as Facebook, Twitter, Google, StumbleUpon, LinkedIn and many more. [Settings] +Version: 1.0.3 +Author: micropat +Author URI: http://share.lockerz.com/ */ -if( !isset($A2A_javascript) ) - $A2A_javascript = ''; if( !isset($A2A_locale) ) $A2A_locale = ''; - + // Pre-2.6 compatibility -if ( !defined('WP_CONTENT_URL') ) - define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); +if ( ! defined('WP_CONTENT_URL') ) + define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); if ( ! defined( 'WP_PLUGIN_URL' ) ) - define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' ); + define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); + +$A2A_SHARE_SAVE_plugin_basename = plugin_basename(dirname(__FILE__)); -$A2A_SHARE_SAVE_plugin_basename = plugin_basename(dirname(__FILE__)); -$A2A_SHARE_SAVE_plugin_url_path = WP_PLUGIN_URL.'/'.$A2A_SHARE_SAVE_plugin_basename; // /wp-content/plugins/add-to-any +// WordPress Must-Use? +if ( basename(dirname(__FILE__)) == "mu-plugins" ) { + // __FILE__ expected in /wp-content/mu-plugins (parent directory for auto-execution) + // /wp-content/mu-plugins/add-to-any + $A2A_SHARE_SAVE_plugin_url_path = WPMU_PLUGIN_URL . '/add-to-any'; + $A2A_SHARE_SAVE_plugin_dir = WPMU_PLUGIN_DIR . '/add-to-any'; +} +else { + // /wp-content/plugins/add-to-any + $A2A_SHARE_SAVE_plugin_url_path = WP_PLUGIN_URL . '/' . $A2A_SHARE_SAVE_plugin_basename; + $A2A_SHARE_SAVE_plugin_dir = WP_PLUGIN_DIR . '/' . $A2A_SHARE_SAVE_plugin_basename; +} + -function A2A_SHARE_SAVE_textdomain() { - global $A2A_SHARE_SAVE_plugin_url_path, $A2A_SHARE_SAVE_plugin_basename; +// Fix SSL +if (is_ssl()) + $A2A_SHARE_SAVE_plugin_url_path = str_replace('http:', 'https:', $A2A_SHARE_SAVE_plugin_url_path); + +$A2A_SHARE_SAVE_options = get_option('addtoany_options'); + +function A2A_SHARE_SAVE_init() { + global $A2A_SHARE_SAVE_plugin_url_path, + $A2A_SHARE_SAVE_plugin_basename, + $A2A_SHARE_SAVE_options; + if (get_option('A2A_SHARE_SAVE_button')) { + A2A_SHARE_SAVE_migrate_options(); + $A2A_SHARE_SAVE_options = get_option('addtoany_options'); + } + load_plugin_textdomain('add-to-any', $A2A_SHARE_SAVE_plugin_url_path.'/languages', $A2A_SHARE_SAVE_plugin_basename.'/languages'); + + if ($A2A_SHARE_SAVE_options['display_in_excerpts'] != '-1') { + // Excerpts use strip_tags() for the_content, so cancel if Excerpt and append to the_excerpt instead + add_filter('get_the_excerpt', 'A2A_SHARE_SAVE_remove_from_content', 9); + add_filter('the_excerpt', 'A2A_SHARE_SAVE_add_to_content', 98); + } } -add_action('init', 'A2A_SHARE_SAVE_textdomain'); +add_filter('init', 'A2A_SHARE_SAVE_init'); -function A2A_SHARE_SAVE_link_vars() { +function A2A_SHARE_SAVE_link_vars($linkname = FALSE, $linkurl = FALSE) { global $post; - $linkname = get_the_title($post->ID); - $linkname_enc = rawurlencode( $linkname ); - $linkurl = get_permalink($post->ID); - $linkurl_enc = rawurlencode( $linkurl ); + $linkname = ($linkname) ? $linkname : get_the_title($post->ID); + $linkname_enc = rawurlencode( html_entity_decode($linkname, ENT_QUOTES, 'UTF-8') ); + $linkurl = ($linkurl) ? $linkurl : get_permalink($post->ID); + $linkurl_enc = rawurlencode( $linkurl ); return compact( 'linkname', 'linkname_enc', 'linkurl', 'linkurl_enc' ); } -include_once('services.php'); +include_once($A2A_SHARE_SAVE_plugin_dir . '/services.php'); -function ADDTOANY_SHARE_SAVE_ICONS( $args = false ) { - if( $args ) - extract( $args ); // output_later, html_wrap_open, html_wrap_close - extract(A2A_SHARE_SAVE_link_vars()); // linkname_enc, etc. - - global $A2A_SHARE_SAVE_plugin_url_path, $A2A_SHARE_SAVE_services; +// Combine ADDTOANY_SHARE_SAVE_ICONS and ADDTOANY_SHARE_SAVE_BUTTON +function ADDTOANY_SHARE_SAVE_KIT( $args = false ) { + global $_addtoany_counter; + + $_addtoany_counter++; + + if ( ! isset($args['html_container_open'])) { + $args['html_container_open'] = '
'; + $args['is_kit'] = TRUE; + } + if ( ! isset($args['html_container_close'])) + $args['html_container_close'] = "
"; + // Close container element in ADDTOANY_SHARE_SAVE_BUTTON, not prematurely in ADDTOANY_SHARE_SAVE_ICONS + $html_container_close = $args['html_container_close']; // Cache for _BUTTON + unset($args['html_container_close']); // Avoid passing to ADDTOANY_SHARE_SAVE_ICONS since set in _BUTTON + + if ( ! isset($args['html_wrap_open'])) + $args['html_wrap_open'] = ""; + if ( ! isset($args['html_wrap_close'])) + $args['html_wrap_close'] = ""; + + $kit_html = ADDTOANY_SHARE_SAVE_ICONS($args); + + $args['html_container_close'] = $html_container_close; // Re-set because unset above for _ICONS + unset($args['html_container_open']); // Avoid passing to ADDTOANY_SHARE_SAVE_BUTTON since set in _ICONS + + $kit_html .= ADDTOANY_SHARE_SAVE_BUTTON($args); + + if (isset($args['output_later']) && $args['output_later']) + return $kit_html; + else + echo $kit_html; +} + +function ADDTOANY_SHARE_SAVE_ICONS( $args = array() ) { + // $args array: output_later, html_container_open, html_container_close, html_wrap_open, html_wrap_close, linkname, linkurl + + global $A2A_SHARE_SAVE_plugin_url_path, + $A2A_SHARE_SAVE_services; + + $linkname = (isset($args['linkname'])) ? $args['linkname'] : FALSE; + $linkurl = (isset($args['linkurl'])) ? $args['linkurl'] : FALSE; + + $args = array_merge($args, A2A_SHARE_SAVE_link_vars($linkname, $linkurl)); // linkname_enc, etc. + + $defaults = array( + 'linkname' => '', + 'linkurl' => '', + 'linkname_enc' => '', + 'linkurl_enc' => '', + 'output_later' => FALSE, + 'html_container_open' => '', + 'html_container_close' => '', + 'html_wrap_open' => '', + 'html_wrap_close' => '', + ); + + $args = wp_parse_args( $args, $defaults ); + extract( $args ); // Make available services extensible via plugins, themes (functions.php), etc. $A2A_SHARE_SAVE_services = apply_filters('A2A_SHARE_SAVE_services', $A2A_SHARE_SAVE_services); - $active_services = get_option('A2A_SHARE_SAVE_active_services'); + $service_codes = (is_array($A2A_SHARE_SAVE_services)) ? array_keys($A2A_SHARE_SAVE_services) : Array(); + + // Include Facebook Like and Twitter Tweet etc. + array_unshift($service_codes, 'facebook_like', 'twitter_tweet', 'google_plusone', 'google_plus_share'); - $ind_html = ""; + $options = get_option('addtoany_options'); + + $active_services = $options['active_services']; + + $ind_html = "" . $html_container_open; if( !$active_services ) $active_services = Array(); foreach($active_services as $active_service) { - // Skip unknown - if( !in_array($active_service, array_keys($A2A_SHARE_SAVE_services)) ) + if ( !in_array($active_service, $service_codes) ) continue; - $service = $A2A_SHARE_SAVE_services[$active_service]; - $safe_name = $active_service; - $name = $service['name']; - - if (isset($service['href'])) { - $custom_service = TRUE; - $href = $service['href']; - $href = str_replace('A2A_LINKURL', $linkurl_enc, $href); - $href = str_replace('A2A_LINKNAME', $linkname_enc, $href); - } else { - $custom_service = FALSE; + if ($active_service == 'facebook_like' || $active_service == 'twitter_tweet' || $active_service == 'google_plusone' || $active_service == 'google_plus_share') { + $special_args = $args; + $special_args['output_later'] = TRUE; + $link = ADDTOANY_SHARE_SAVE_SPECIAL($active_service, $special_args); } - - if ( $custom_service && isset($service['icon_url']) ) - $icon = $service['icon_url']; - elseif ( ! isset($service['icon'])) - $icon = 'default'; - else - $icon = $service['icon']; - $width = (isset($service['icon_width'])) ? $service['icon_width'] : '16'; - $height = (isset($service['icon_height'])) ? $service['icon_height'] : '16'; + else { + $service = $A2A_SHARE_SAVE_services[$active_service]; + $safe_name = $active_service; + $name = $service['name']; + + if (isset($service['href'])) { + $custom_service = TRUE; + $href = $service['href']; + if (isset($service['href_js_esc'])) { + $href_linkurl = str_replace("'", "\'", $linkurl); + $href_linkname = str_replace("'", "\'", $linkname); + } else { + $href_linkurl = $linkurl_enc; + $href_linkname = $linkname_enc; + } + $href = str_replace("A2A_LINKURL", $href_linkurl, $href); + $href = str_replace("A2A_LINKNAME", $href_linkname, $href); + $href = str_replace(" ", "%20", $href); + } else { + $custom_service = FALSE; + } + + $icon_url = (isset($service['icon_url'])) ? $service['icon_url'] : FALSE; + $icon = (isset($service['icon'])) ? $service['icon'] : 'default'; // Just the icon filename + $width = (isset($service['icon_width'])) ? $service['icon_width'] : '16'; + $height = (isset($service['icon_height'])) ? $service['icon_height'] : '16'; + + $url = ($custom_service) ? $href : "http://www.addtoany.com/add_to/" . $safe_name . "?linkurl=" . $linkurl_enc . "&linkname=" . $linkname_enc; + $src = ($icon_url) ? $icon_url : $A2A_SHARE_SAVE_plugin_url_path."/icons/".$icon.".png"; + $class_attr = ($custom_service) ? "" : " class=\"a2a_button_$safe_name\""; + + $link = $html_wrap_open.""; + $link .= "\"$name\"/"; + $link .= "".$html_wrap_close; + } - $url = ($custom_service) ? $href : "http://www.addtoany.com/add_to/" . $safe_name . "?linkurl=" . $linkurl_enc . "&linkname=" . $linkname_enc; - $src = ($custom_service) ? $icon : $A2A_SHARE_SAVE_plugin_url_path."/icons/".$icon.".png"; - - $link = $html_wrap_open.""; - $link .= "\"$name\"/"; - $link .= "".$html_wrap_close; - - $ind_html .= apply_filters('addtoany_link', $link); + $ind_html .= $link; } - if($output_later) + $ind_html .= $html_container_close; + + if ( $output_later ) return $ind_html; else echo $ind_html; } -function ADDTOANY_SHARE_SAVE_BUTTON( $args = false ) { +function ADDTOANY_SHARE_SAVE_BUTTON( $args = array() ) { + + // $args array = output_later, html_container_open, html_container_close, html_wrap_open, html_wrap_close, linkname, linkurl - global $A2A_SHARE_SAVE_plugin_url_path, $A2A_SHARE_SAVE_services; + global $A2A_SHARE_SAVE_plugin_url_path, $_addtoany_targets, $_addtoany_counter, $_addtoany_init; - // Make available services extensible via plugins, themes (functions.php), etc. - $A2A_SHARE_SAVE_services = apply_filters('A2A_SHARE_SAVE_services', $A2A_SHARE_SAVE_services); + $linkname = (isset($args['linkname'])) ? $args['linkname'] : FALSE; + $linkurl = (isset($args['linkurl'])) ? $args['linkurl'] : FALSE; + $_addtoany_targets = (isset($_addtoany_targets)) ? $_addtoany_targets : array(); + + $args = array_merge($args, A2A_SHARE_SAVE_link_vars($linkname, $linkurl)); // linkname_enc, etc. - if( $args ) - extract( $args ); // output_later, html_wrap_open, html_wrap_close + $defaults = array( + 'linkname' => '', + 'linkurl' => '', + 'linkname_enc' => '', + 'linkurl_enc' => '', + 'use_current_page' => FALSE, + 'output_later' => FALSE, + 'is_kit' => FALSE, + 'html_container_open' => '', + 'html_container_close' => '', + 'html_wrap_open' => '', + 'html_wrap_close' => '', + ); - extract(A2A_SHARE_SAVE_link_vars()); // linkname_enc, etc. + $args = wp_parse_args( $args, $defaults ); + extract( $args ); - /* Add to Any button */ + // If not enclosed in an AddToAny Kit, count & target this button (instead of Kit) for async loading + if ( ! $args['is_kit']) { + $_addtoany_counter++; + $button_class = ' a2a_target'; + $button_id = ' id="wpa2a_' . $_addtoany_counter . '"'; + } else { + $button_class = ''; + $button_id = ''; + } - $button_target = (get_option('A2A_SHARE_SAVE_button_opens_new_window')=='1' && (get_option('A2A_SHARE_SAVE_onclick')!='1')) ? ' target="_blank"' : ''; + /* AddToAny button */ - if( !get_option('A2A_SHARE_SAVE_button') ) { + $is_feed = is_feed(); + $button_target = ''; + $button_href_querystring = ($is_feed) ? '#url=' . $linkurl_enc . '&title=' . $linkname_enc : ''; + $options = get_option('addtoany_options'); + + if( ! $options['button'] ) { $button_fname = 'share_save_171_16.png'; $button_width = ' width="171"'; $button_height = ' height="16"'; $button_src = $A2A_SHARE_SAVE_plugin_url_path.'/'.$button_fname; - } else if( get_option('A2A_SHARE_SAVE_button') == 'CUSTOM' ) { - $button_src = get_option('A2A_SHARE_SAVE_button_custom'); + } else if( $options['button'] == 'CUSTOM' ) { + $button_src = $options['button_custom']; $button_width = ''; $button_height = ''; - } else if( get_option('A2A_SHARE_SAVE_button') == 'TEXT' ) { - $button_text = stripslashes(get_option('A2A_SHARE_SAVE_button_text')); + } else if( $options['button'] == 'TEXT' ) { + $button_text = stripslashes($options['button_text']); } else { - $button_attrs = explode( '|', get_option('A2A_SHARE_SAVE_button') ); + $button_attrs = explode( '|', $options['button'] ); $button_fname = $button_attrs[0]; $button_width = ' width="'.$button_attrs[1].'"'; $button_height = ' height="'.$button_attrs[2].'"'; $button_src = $A2A_SHARE_SAVE_plugin_url_path.'/'.$button_fname; - $button_text = stripslashes(get_option('A2A_SHARE_SAVE_button_text')); + $button_text = stripslashes($options['button_text']); } - if( $button_fname == 'favicon.png' || $button_fname == 'share_16_16.png' ) { - if( !is_feed() ) { - $style_bg = 'background:url('.$A2A_SHARE_SAVE_plugin_url_path.'/'.$button_fname.') no-repeat scroll 9px 0px'; // padding-left:9 (9=other icons padding) - $style_bg = ';' . $style_bg . ' !important;'; - $style = ' style="'.$style_bg.'padding:0 0 0 30px;display:inline-block;height:16px;line-height:16px;vertical-align:middle;"'; // padding-left:30+9 (9=other icons padding) + $style = ''; + + if( isset($button_fname) && ($button_fname == 'favicon.png' || $button_fname == 'share_16_16.png') ) { + if( ! $is_feed) { + $style_bg = 'background:url('.$A2A_SHARE_SAVE_plugin_url_path.'/'.$button_fname.') no-repeat scroll 9px 0px !important;'; + $style = ' style="'.$style_bg.'padding:0 0 0 30px;display:inline-block;height:16px;line-height:16px;vertical-align:middle"'; // padding-left:30+9 (9=other icons padding) } } - if( $button_text && (!$button_fname || $button_fname == 'favicon.png' || $button_fname == 'share_16_16.png') ) { + if( isset($button_text) && $button_text && ( ! isset($button_fname) || ! $button_fname || $button_fname == 'favicon.png' || $button_fname == 'share_16_16.png') ) { $button = $button_text; } else { $style = ''; - $button = 'Share/Bookmark'; + $button = 'Share'; } - $button_html = $html_wrap_open.''.$button.''.$html_wrap_close; + $button_html = $html_container_open . $html_wrap_open . '' . $button . '' . $html_wrap_close . $html_container_close; // If not a feed - if( !is_feed() ) { - - global $A2A_javascript, $A2A_SHARE_SAVE_external_script_called; - if( $A2A_javascript == '' || !$A2A_SHARE_SAVE_external_script_called ) { - $external_script_call = ''; - $A2A_SHARE_SAVE_external_script_called = true; + if( ! $is_feed ) { + if ($use_current_page) { + $_addtoany_targets[] = "\n{title:document.title," + . "url:location.href}"; + } else { + $_addtoany_targets[] = "\n{title:'". esc_js($linkname) . "'," + . "url:'" . $linkurl . "'}"; + } + + if ( ! $_addtoany_init) { + $javascript_load_early = "\n\n"; } else - $external_script_call = 'a2a_init("page");'; - $A2A_javascript .= '\n"; + + echo $javascript_header; +} + +add_action('wp_head', 'A2A_SHARE_SAVE_head_script'); + +function A2A_SHARE_SAVE_footer_script() { + global $_addtoany_targets; + + if (is_admin()) + return; + + $_addtoany_targets = (isset($_addtoany_targets)) ? $_addtoany_targets : array(); + + $javascript_footer = "\n" . '\n"; + echo $javascript_footer; +} + +add_action('wp_footer', 'A2A_SHARE_SAVE_footer_script'); + + + +function A2A_SHARE_SAVE_theme_hooks_check() { + $template_directory = get_template_directory(); + + // If footer.php exists in the current theme, scan for "wp_footer" + $file = $template_directory . '/footer.php'; + if (is_file($file)) { + $search_string = "wp_footer"; + $file_lines = @file($file); + + foreach ($file_lines as $line) { + $searchCount = substr_count($line, $search_string); + if ($searchCount > 0) { + return true; } - - // wp_footer() not found: - echo "
" . __("Your theme needs to be fixed. To fix your theme, use the Theme Editor to insert <?php wp_footer(); ?> just before the </body> line of your theme's footer.php file.") . "
"; } - } + + // wp_footer() not found: + echo "
" . __("Your theme needs to be fixed. To fix your theme, use the Theme Editor to insert <?php wp_footer(); ?> just before the </body> line of your theme's footer.php file.") . "
"; + } + + // If header.php exists in the current theme, scan for "wp_head" + $file = $template_directory . '/header.php'; + if (is_file($file)) { + $search_string = "wp_head"; + $file_lines = @file($file); + + foreach ($file_lines as $line) { + $searchCount = substr_count($line, $search_string); + if ($searchCount > 0) { + return true; + } + } + + // wp_footer() not found: + echo "
" . __("Your theme needs to be fixed. To fix your theme, use the Theme Editor to insert <?php wp_head(); ?> just before the </head> line of your theme's header.php file.") . "
"; + } +} + +function A2A_SHARE_SAVE_auto_placement($title) { + global $A2A_SHARE_SAVE_auto_placement_ready; + $A2A_SHARE_SAVE_auto_placement_ready = true; + + return $title; } -function A2A_SHARE_SAVE_to_bottom_of_content($content) { +/** + * Remove the_content filter and add it for next time + */ +function A2A_SHARE_SAVE_remove_from_content($content) { + remove_filter('the_content', 'A2A_SHARE_SAVE_add_to_content', 98); + add_filter('the_content', 'A2A_SHARE_SAVE_add_to_content_next_time', 98); + + return $content; +} + +/** + * Apply the_content filter "next time" + */ +function A2A_SHARE_SAVE_add_to_content_next_time($content) { + add_filter('the_content', 'A2A_SHARE_SAVE_add_to_content', 98); + + return $content; +} + + +function A2A_SHARE_SAVE_add_to_content($content) { + global $A2A_SHARE_SAVE_auto_placement_ready; + $is_feed = is_feed(); + $options = get_option('addtoany_options'); + + if( ! $A2A_SHARE_SAVE_auto_placement_ready) + return $content; + + if (get_post_status(get_the_ID()) == 'private') + return $content; if ( ( // Tags - strpos($content, '')===false || // tag - strpos($content, '')!==false // tag - ) && + // tag + strpos($content, '')===false || + // tag + strpos($content, '')!==false + ) && ( // Posts - ( ! is_page() && get_option('A2A_SHARE_SAVE_display_in_posts')=='-1' ) || // All posts - ( is_home() && get_option('A2A_SHARE_SAVE_display_in_posts_on_front_page')=='-1' ) || // Front page posts - ( is_category() && get_option('A2A_SHARE_SAVE_display_in_posts_on_front_page')=='-1' ) || // Category posts (same as Front page option) - ( is_tag() && get_option('A2A_SHARE_SAVE_display_in_posts_on_front_page')=='-1' ) || // Tag Cloud posts (same as Front page option) - ( is_date() && get_option('A2A_SHARE_SAVE_display_in_posts_on_front_page')=='-1' ) || // Date-based archives posts (same as Front page option) - ( is_author() && get_option('A2A_SHARE_SAVE_display_in_posts_on_front_page')=='-1' ) || // Author posts (same as Front page option) - ( is_search() && get_option('A2A_SHARE_SAVE_display_in_posts_on_front_page')=='-1' ) || // Search results posts (same as Front page option) - ( $is_feed && (get_option('A2A_SHARE_SAVE_display_in_feed')=='-1' ) || // Posts in feed + // All posts + ( ! is_page() && $options['display_in_posts']=='-1' ) || + // Front page posts + ( is_home() && $options['display_in_posts_on_front_page']=='-1' ) || + // Archive page posts (Category, Tag, Author and Date pages) + ( is_archive() && $options['display_in_posts_on_archive_pages']=='-1' ) || + // Search results posts (same as Archive page posts option) + ( is_search() && $options['display_in_posts_on_archive_pages']=='-1' ) || + // Posts in feed + ( $is_feed && ($options['display_in_feed']=='-1' ) || // Pages - ( is_page() && get_option('A2A_SHARE_SAVE_display_in_pages')=='-1' ) || // Individual pages - ( (strpos($content, '')!==false) ) // + // Individual pages + ( is_page() && $options['display_in_pages']=='-1' ) || + // + ( (strpos($content, '')!==false) ) ) ) ) return $content; - $icons_args = array( + $kit_args = array( "output_later" => true, - "html_wrap_open" => ($is_feed) ? "" : "
  • ", - "html_wrap_close" => ($is_feed) ? " " : "
  • ", - ); - - $A2A_SHARE_SAVE_options = array( - "output_later" => true, - "html_wrap_open" => ($is_feed) ? "" : "
  • ", - "html_wrap_close" => ($is_feed) ? "" : "
  • ", + "is_kit" => ($is_feed) ? FALSE : TRUE, ); if ( ! $is_feed ) { - $container_wrap_open = '
    '; + $container_wrap_open = '
    '; + $container_wrap_close = '
    '; + } else { // Is feed + $container_wrap_open = '

    '; + $container_wrap_close = '

    '; + $kit_args['html_container_open'] = ''; + $kit_args['html_container_close'] = ''; + $kit_args['html_wrap_open'] = ''; + $kit_args['html_wrap_close'] = ''; } - $content .= $container_wrap_open.ADDTOANY_SHARE_SAVE_ICONS( $icons_args ).ADDTOANY_SHARE_SAVE_BUTTON( $A2A_SHARE_SAVE_options ).$container_wrap_close; + $options['position'] = isset($options['position']) ? $options['position'] : 'bottom'; + + if ($options['position'] == 'both' || $options['position'] == 'top') { + // Prepend to content + $content = $container_wrap_open.ADDTOANY_SHARE_SAVE_KIT($kit_args) . $container_wrap_close . $content; + } + if ( $options['position'] == 'bottom' || $options['position'] == 'both') { + // Append to content + $content .= $container_wrap_open.ADDTOANY_SHARE_SAVE_KIT($kit_args) . $container_wrap_close; + } + return $content; } -add_action('the_content', 'A2A_SHARE_SAVE_to_bottom_of_content', 98); +// Only automatically output button code after the_title has been called - to avoid premature calling from misc. the_content filters (especially meta description) +add_filter('the_title', 'A2A_SHARE_SAVE_auto_placement', 9); +add_filter('the_content', 'A2A_SHARE_SAVE_add_to_content', 98); -function A2A_SHARE_SAVE_button_css() { - ?> +// [addtoany url="http://example.com/page.html" title="Some Example Page"] +function A2A_SHARE_SAVE_shortcode( $attributes ) { + extract( shortcode_atts( array( + 'url' => 'something', + 'title' => 'something else', + ), $attributes ) ); + + $linkname = (isset($attributes['title'])) ? $attributes['title'] : FALSE; + $linkurl = (isset($attributes['url'])) ? $attributes['url'] : FALSE; + $output_later = TRUE; + + return ADDTOANY_SHARE_SAVE_KIT( compact('linkname', 'linkurl', 'output_later') ); +} + +add_shortcode( 'addtoany', 'A2A_SHARE_SAVE_shortcode' ); + + + +function A2A_SHARE_SAVE_button_css_IE() { +/* IE support for opacity: */ ?> + $message ); + } + + if (count($file_urls) > 0) { + for ($i = 0; $i < count($file_urls); $i++) { + // Download files + $file_url = $file_urls[$i]; + $file_name = substr(strrchr($file_url, '/'), 1, 99); + + // Place files in uploads/addtoany directory + wp_get_http($file_url, $upload_dir['basedir'] . '/addtoany/' . $file_name); + } + } +} + +function A2A_SHARE_SAVE_schedule_cache() { + // WP "Cron" requires WP version 2.1 + $timestamp = wp_next_scheduled('A2A_SHARE_SAVE_refresh_cache'); + if ( ! $timestamp) { + // Only schedule if currently unscheduled + wp_schedule_event(time(), 'daily', 'A2A_SHARE_SAVE_refresh_cache'); + } +} + +function A2A_SHARE_SAVE_unschedule_cache() { + $timestamp = wp_next_scheduled('A2A_SHARE_SAVE_refresh_cache'); + wp_unschedule_event($timestamp, 'A2A_SHARE_SAVE_refresh_cache'); +} @@ -360,65 +726,198 @@ ******************************/ +function A2A_SHARE_SAVE_migrate_options() { + + $options = array( + 'inline_css' => '1', // Modernly used for "Use CSS Stylesheet?" + 'cache' => '-1', + 'display_in_posts_on_front_page' => '1', + 'display_in_posts_on_archive_pages' => '1', + 'display_in_posts' => '1', + 'display_in_pages' => '1', + 'display_in_feed' => '1', + 'show_title' => '-1', + 'onclick' => '-1', + 'button' => 'share_save_171_16.png|171|16', + 'button_custom' => '', + 'additional_js_variables' => '', + 'button_text' => 'Share/Bookmark', + 'display_in_excerpts' => '1', + 'active_services' => Array(), + ); + + $namespace = 'A2A_SHARE_SAVE_'; + + foreach ($options as $option_name => $option_value) { + $old_option_name = $namespace . $option_name; + $old_option_value = get_option($old_option_name); + + if($old_option_value === FALSE) { + // Default value + $options[$option_name] = $option_value; + } else { + // Old value + $options[$option_name] = $old_option_value; + } + + delete_option($old_option_name); + } + + update_option('addtoany_options', $options); + + $deprecated_options = array( + 'button_opens_new_window', + 'hide_embeds', + ); + + foreach ($deprecated_options as $option_name) { + delete_option($namespace . $option_name); + } + +} + function A2A_SHARE_SAVE_options_page() { - global $A2A_SHARE_SAVE_plugin_url_path, $A2A_SHARE_SAVE_services; + global $A2A_SHARE_SAVE_plugin_url_path, + $A2A_SHARE_SAVE_services; + // Require admin privs + if ( ! current_user_can('manage_options') ) + return false; + + $new_options = array(); + + $namespace = 'A2A_SHARE_SAVE_'; + // Make available services extensible via plugins, themes (functions.php), etc. $A2A_SHARE_SAVE_services = apply_filters('A2A_SHARE_SAVE_services', $A2A_SHARE_SAVE_services); - if( $_POST[ 'A2A_SHARE_SAVE_submit_hidden' ] == 'Y' ) { + if (isset($_POST['Submit'])) { + + // Nonce verification + check_admin_referer('add-to-any-update-options'); - update_option( 'A2A_SHARE_SAVE_display_in_posts_on_front_page', ($_POST['A2A_SHARE_SAVE_display_in_posts_on_front_page']=='1') ? '1':'-1' ); - update_option( 'A2A_SHARE_SAVE_display_in_posts', ($_POST['A2A_SHARE_SAVE_display_in_posts']=='1') ? '1':'-1' ); - update_option( 'A2A_SHARE_SAVE_display_in_pages', ($_POST['A2A_SHARE_SAVE_display_in_pages']=='1') ? '1':'-1' ); - update_option( 'A2A_SHARE_SAVE_display_in_feed', ($_POST['A2A_SHARE_SAVE_display_in_feed']=='1') ? '1':'-1' ); - update_option( 'A2A_SHARE_SAVE_hide_embeds', ($_POST['A2A_SHARE_SAVE_hide_embeds']=='1') ? '1':'-1' ); - update_option( 'A2A_SHARE_SAVE_show_title', ($_POST['A2A_SHARE_SAVE_show_title']=='1') ? '1':'-1' ); - update_option( 'A2A_SHARE_SAVE_onclick', ($_POST['A2A_SHARE_SAVE_onclick']=='1') ? '1':'-1' ); - update_option( 'A2A_SHARE_SAVE_button_opens_new_window', ($_POST['A2A_SHARE_SAVE_button_opens_new_window']=='1') ? '1':'-1' ); - update_option( 'A2A_SHARE_SAVE_button', $_POST['A2A_SHARE_SAVE_button'] ); - update_option( 'A2A_SHARE_SAVE_button_custom', $_POST['A2A_SHARE_SAVE_button_custom'] ); - update_option( 'A2A_SHARE_SAVE_additional_js_variables', trim($_POST['A2A_SHARE_SAVE_additional_js_variables']) ); + $new_options['position'] = ($_POST['A2A_SHARE_SAVE_position']) ? @$_POST['A2A_SHARE_SAVE_position'] : 'bottom'; + $new_options['display_in_posts_on_front_page'] = (@$_POST['A2A_SHARE_SAVE_display_in_posts_on_front_page']=='1') ? '1':'-1'; + $new_options['display_in_posts_on_archive_pages'] = (@$_POST['A2A_SHARE_SAVE_display_in_posts_on_archive_pages']=='1') ? '1':'-1'; + $new_options['display_in_excerpts'] = (@$_POST['A2A_SHARE_SAVE_display_in_excerpts']=='1') ? '1':'-1'; + $new_options['display_in_posts'] = (@$_POST['A2A_SHARE_SAVE_display_in_posts']=='1') ? '1':'-1'; + $new_options['display_in_pages'] = (@$_POST['A2A_SHARE_SAVE_display_in_pages']=='1') ? '1':'-1'; + $new_options['display_in_feed'] = (@$_POST['A2A_SHARE_SAVE_display_in_feed']=='1') ? '1':'-1'; + $new_options['show_title'] = (@$_POST['A2A_SHARE_SAVE_show_title']=='1') ? '1':'-1'; + $new_options['onclick'] = (@$_POST['A2A_SHARE_SAVE_onclick']=='1') ? '1':'-1'; + $new_options['button'] = @$_POST['A2A_SHARE_SAVE_button']; + $new_options['button_custom'] = @$_POST['A2A_SHARE_SAVE_button_custom']; + $new_options['additional_js_variables'] = trim(@$_POST['A2A_SHARE_SAVE_additional_js_variables']); + $new_options['inline_css'] = (@$_POST['A2A_SHARE_SAVE_inline_css']=='1') ? '1':'-1'; + $new_options['cache'] = (@$_POST['A2A_SHARE_SAVE_cache']=='1') ? '1':'-1'; + + // Schedule cache refresh? + if (@$_POST['A2A_SHARE_SAVE_cache']=='1') { + A2A_SHARE_SAVE_schedule_cache(); + A2A_SHARE_SAVE_refresh_cache(); + } else { + A2A_SHARE_SAVE_unschedule_cache(); + } // Store desired text if 16 x 16px buttons or text-only is chosen: - if( get_option('A2A_SHARE_SAVE_button') == 'favicon.png|16|16' ) - update_option( 'A2A_SHARE_SAVE_button_text', $_POST['A2A_SHARE_SAVE_button_favicon_16_16_text'] ); - elseif( get_option('A2A_SHARE_SAVE_button') == 'share_16_16.png|16|16' ) - update_option( 'A2A_SHARE_SAVE_button_text', $_POST['A2A_SHARE_SAVE_button_share_16_16_text'] ); + if( $new_options['button'] == 'favicon.png|16|16' ) + $new_options['button_text'] = $_POST['A2A_SHARE_SAVE_button_favicon_16_16_text']; + elseif( $new_options['button'] == 'share_16_16.png|16|16' ) + $new_options['button_text'] = $_POST['A2A_SHARE_SAVE_button_share_16_16_text']; else - update_option( 'A2A_SHARE_SAVE_button_text', ( trim($_POST['A2A_SHARE_SAVE_button_text']) != '' ) ? $_POST['A2A_SHARE_SAVE_button_text'] : __('Share/Bookmark','add-to-any') ); + $new_options['button_text'] = ( trim($_POST['A2A_SHARE_SAVE_button_text']) != '' ) ? $_POST['A2A_SHARE_SAVE_button_text'] : __('Share/Bookmark','add-to-any'); // Store chosen individual services to make active $active_services = Array(); - if( !$_POST['A2A_SHARE_SAVE_active_services'] ) + if ( ! isset($_POST['A2A_SHARE_SAVE_active_services'])) $_POST['A2A_SHARE_SAVE_active_services'] = Array(); - foreach( $_POST['A2A_SHARE_SAVE_active_services'] as $dummy=>$sitename ) + foreach ( $_POST['A2A_SHARE_SAVE_active_services'] as $dummy=>$sitename ) $active_services[] = substr($sitename, 7); - update_option('A2A_SHARE_SAVE_active_services', $active_services); - // Delete then re-add to ensure sorting works (re-sorting doesn't effect associated array equality in PHP so update doesn't hit the dB for identical arrays - delete_option('A2A_SHARE_SAVE_active_services', $active_services); - add_option('A2A_SHARE_SAVE_active_services', $active_services); + $new_options['active_services'] = $active_services; + // Store special service options + $new_options['special_facebook_like_options'] = array( + 'verb' => ((@$_POST['addtoany_facebook_like_verb'] == 'recommend') ? 'recommend' : 'like') + ); + $new_options['special_twitter_tweet_options'] = array( + 'show_count' => ((@$_POST['addtoany_twitter_tweet_show_count'] == '1') ? '1' : '-1') + ); + $new_options['special_google_plusone_options'] = array( + 'show_count' => ((@$_POST['addtoany_google_plusone_show_count'] == '1') ? '1' : '-1') + ); + $new_options['special_google_plus_share_options'] = array( + 'show_count' => ((@$_POST['addtoany_google_plus_share_show_count'] == '1') ? '1' : '-1') + ); + + update_option('addtoany_options', $new_options); + ?>

    array( + 'selected' => ('bottom' == $options['position']) ? ' selected="selected"' : '', + 'string' => __('bottom', 'add-to-any') + ), + 'top' => array( + 'selected' => ('top' == $options['position']) ? ' selected="selected"' : '', + 'string' => __('top', 'add-to-any') + ), + 'both' => array( + 'selected' => ('both' == $options['position']) ? ' selected="selected"' : '', + 'string' => __('top & bottom', 'add-to-any') + ) + ); + + if ($option_box) { + $html = ''; + $html .= '