Configuration options are here. Questions on configuration, etc.? Make sure to read the README. Version: 5.3 Author: ShareThis,next2manu, Manu Mukerji Author URI: http://sharethis.com */ load_plugin_textdomain('sharethis'); $_stversion=5.0; function install_ShareThis(){ $publisher_id = get_option('st_pubid'); //pub key value $widget = get_option('st_widget'); //entire script tag $newUser=false; if (get_option('st_version') == '') { update_option('st_version', '5x'); } if(empty($publisher_id)){ if(!empty($widget)){ $newPkey=getKeyFromTag(); if($newPkey==false){ $newUser=true; update_option('st_pubid',trim(makePkey())); }else{ update_option('st_pubid',$newPkey); //pkey found set old key } }else{ $newUser=true; update_option('st_pubid',trim(makePkey())); } } if($widget==false || !preg_match('/stLight.options/',$widget)){ $pkey2=get_option('st_pubid'); $widget =""; $widget.=""; $widget.=""; update_option('st_widget',$widget); } $st_sent=get_option('st_sent'); $st_upgrade_five=get_option('st_upgrade_five'); if(empty($st_sent)){ update_option('st_sent','true'); update_option('st_upgrade_five', '5x'); $st_sent=get_option('st_sent'); //confirm if value has been set if(!(empty($st_sent))){ sendWelcomeEmail($newUser); } $st_upgrade_five=get_option('st_upgrade_five'); } else if (empty($st_upgrade_five)) { update_option('st_upgrade_five', '5x'); $st_upgrade_five=get_option('st_upgrade_five'); //confirm if value has been set if(!(empty($st_upgrade_five))){ sendUpgradeEmail(); } } if (get_option('st_add_to_content') == '') { update_option('st_add_to_content', 'yes'); } if (get_option('st_add_to_page') == '') { update_option('st_add_to_page', 'yes'); } } function getKeyFromTag(){ $widget = get_option('st_widget'); $pattern = "/publisher\=([^\&\"]*)/"; preg_match($pattern, $widget, $matches); $pkey = $matches[1]; if(empty($pkey)){ return false; } else{ return $pkey; } } function getNewTag($oldTag){ $pattern = '/(http\:\/\/*.*)[(\')|(\")]/'; preg_match($pattern, $oldTag, $matches); $url=$matches[1]; $pattern = '/(type=)/'; preg_match($pattern, $url, $matches); if(empty($matches)){ $url.="&type=wordpress".get_bloginfo('version'); } $qs=parse_url($url); if($qs['query']){ $qs=$qs['query']; $newUrl="http://w.sharethis.com/button/sharethis.js#$qs"; } else{ $newUrl=$url; } return $newTag=''; } if (isset($_GET['activate']) && $_GET['activate'] == 'true') { install_ShareThis(); } function st_widget_head() { $widget = get_option('st_widget'); if ($widget == '') { } else{ //$widget = st_widget_add_wp_version($widget); $widget = st_widget_fix_domain($widget); $widget = preg_replace("/\&/", "&", $widget); } print($widget); } function sendWelcomeEmail($newUser){ $to=get_option('admin_email'); $updatePage=get_option('siteurl'); $updatePage.="/wp-admin/options-general.php?page=sharethis.php"; $body = "The ShareThis plugin on your website has been activated on ".get_option('siteurl')."\n\n" ."If you would like to customize the look of your widget, go to the ShareThis Options page in your WordPress administration area. $updatePage\n\n" ."Get more information on customization options at http://help.sharethis.com/integration/wordpress." ."To get reporting on share data login to your account at http://sharethis.com/account and choose options in the Analytics section\n\n" ."If you have any additional questions or need help please email us at support@sharethis.com\n\n--The ShareThis Team"; $subject = "ShareThis WordPress Plugin"; if(empty($to)){ return false; } if($newUser){ $subject = "ShareThis WordPress Plugin Activation"; $body ="Thanks for installing the ShareThis plugin on your blog.\n\n" ."If you would like to customize the look of your widget, go to the ShareThis Options page in your WordPress administration area. $updatePage\n\n" ."Get more information on customization options at http://help.sharethis.com/integration/wordpress.\n\n" ."If you have any additional questions or need help please email us at support@sharethis.com\n\n--The ShareThis Team"; } $headers = "From: ShareThis Support \r\n" ."X-Mailer: php"; update_option('st_sent','true'); mail($to, $subject, $body, $headers); } function sendUpgradeEmail() { $to=get_option('admin_email'); $updatePage=get_option('siteurl'); $updatePage.="/wp-admin/options-general.php?page=sharethis.php"; $body = "The ShareThis plugin on your website has been updated!\n\n" ."If you would like to customize the look of your widget, go to the ShareThis Options page in your WordPress administration area. $updatePage\n\n" ."Get more information on customization options at http://help.sharethis.com/integration/wordpress." ."To get reporting on share data login to your account at http://sharethis.com/account and choose options in the Analytics section\n\n" ."If you have any additional questions or need help please email us at support@sharethis.com\n\n--The ShareThis Team"; $subject = "ShareThis WordPress Plugin Updated"; if(empty($to)){ return false; } $headers = "From: ShareThis Support \r\n" ."X-Mailer: php"; update_option('st_sent','true'); mail($to, $subject, $body, $headers); } function st_link() { global $post; $sharethis = '

ShareThis

'; return $sharethis; } function sharethis_button() { echo st_makeEntries(); } function st_remove_st_add_link($content) { remove_action('the_content', 'st_add_link'); remove_action('the_content', 'st_add_widget'); return $content; } function st_add_widget($content) { if ((is_page() && get_option('st_add_to_page') != 'no') || (!is_page() && get_option('st_add_to_content') != 'no')) { if (!is_feed()) { return $content.'

'.st_makeEntries().'

'; } } return $content; } // 2006-06-02 Renamed function from st_add_st_link() to st_add_feed_link() function st_add_feed_link($content) { if (is_feed()) { $content .= st_link(); } return $content; } // 2006-06-02 Filters to Add Sharethis widget on content and/or link on RSS // 2006-06-02 Expected behavior is that the feed link will show up if an option is not 'no' if (get_option('st_add_to_content') != 'no' || get_option('st_add_to_page') != 'no') { add_filter('the_content', 'st_add_widget'); // 2008-08-15 Excerpts don't play nice due to strip_tags(). add_filter('get_the_excerpt', 'st_remove_st_add_link',9); add_filter('the_excerpt', 'st_add_widget'); } function st_widget_fix_domain($widget) { return preg_replace( "/\]*)src\=\"http\:\/\/sharethis/" , "", $widget); $widget = preg_replace("/widget\/\&wp\=/", "widget/?wp=", $widget); } else { $widget = preg_replace("/([\&\?])wp\=([^\&\"]*)/", "$1wp=".get_bloginfo('version'), $widget); } return $widget; } if (!function_exists('ak_can_update_options')) { function ak_can_update_options() { if (function_exists('current_user_can')) { if (current_user_can('manage_options')) { return true; } } else { global $user_level; get_currentuserinfo(); if ($user_level >= 8) { return true; } } return false; } } function st_request_handler() { if (!empty($_REQUEST['st_action'])) { switch ($_REQUEST['st_action']) { case 'st_update_settings': if (ak_can_update_options()) { if (!empty($_POST['st_widget'])) { // have widget $widget = stripslashes($_POST['st_widget']); $widget = preg_replace("/\&/", "&", $widget); if(!preg_match('/buttons.js/',$widget)){ $pattern = "/publisher\=([^\&\"]*)/"; preg_match($pattern, $widget, $matches); if ($matches[0] == "") { // widget does not have publisher parameter at all $publisher_id = get_option('st_pubid'); if ($publisher_id != "") { $widget = preg_replace("/\"\>\s*\<\/\s*script\s*\>/", "&publisher=".$publisher_id."\">", $widget); $widget = preg_replace("/widget\/\&publisher\=/", "widget/?publisher=", $widget); } } elseif ($matches[1] == "") { // widget does not have pubid in publisher parameter $publisher_id = get_option('st_pubid'); if ($publisher_id != "") { $widget = preg_replace("/([\&\?])publisher\=/", "$1publisher=".$publisher_id, $widget); } else { $widget = preg_replace("/([\&\?])publisher\=/", "$1publisher=".$publisher_id, $widget); } } else { // widget has pubid in publisher parameter $publisher_id = get_option('st_pubid'); if ($publisher_id != "") { if ($publisher_id != $matches[1]) { $publisher_id = $matches[1]; } } else { $publisher_id = $matches[1]; } } }else{ $publisher_id = get_option('st_pubid'); $pkeyUpdated=false; if(!empty($_POST['st_pkey']) && $publisher_id!==$_POST['st_pkey'] && preg_match('/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/',$_POST['st_pkey'])){ update_option('st_pubid', $_POST['st_pkey']); $publisher_id=$_POST['st_pkey']; $pkeyUpdated=true; } else{ if(substr($_POST['st_pkey_hidden'], 0, 3) == "wp." && $publisher_id!==$_POST['st_pkey_hidden'] && preg_match('/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/',$_POST['st_pkey_hidden'])) { update_option('st_pubid', $_POST['st_pkey_hidden']); $publisher_id=$_POST['st_pkey_hidden']; $pkeyUpdated=true; } else{ // Re-generate new random publisher key $publisher_id=trim(makePkey()); update_option('st_pubid',$publisher_id); $pkeyUpdated=true; } } if (preg_match("/publisher:['\"]\w{8}-\w{4}-\w{4}-\w{4}-\w{12}['\"]/",$widget) || preg_match("/publisher:['\"]wp\.\w{8}-\w{4}-\w{4}-\w{4}-\w{12}['\"]/",$widget)) { $pkeyUpdated=false; } if(!preg_match('/stLight.options/',$widget) || $pkeyUpdated==true){ $widgetTemp=""; $widgetTemp.=""; // In case of button style = sharethis (4/7) default. // Remove FBLike, Google+,Pinterest from hoverbar services $defaultServices = '"facebook","twitter","linkedin","email","sharethis"'; $st_services_values = ''; if($_POST["st_current_type"] == 'classic') { $st_services_values = $defaultServices; } else{ // Adding double quotes for each service separated by comma $chickletServicesArray = explode(',', trim($_POST['st_services'])); $newchickletServicesArray = array(); for($i=0; $i"; $widgetTemp.=""; $widgetTemp.=""; } else if (preg_match('/serviceWidget/',$widget)) { $widgetTemp.=""; $widgetTemp.=""; } else if (preg_match('/hoverbuttons/',$widget)) { $widgetTemp.=""; $widgetTemp.=""; } update_option('st_widget',$widgetTemp); $widget = stripslashes(get_option('st_widget')); } } } else { // does not have widget $publisher_id = get_option('st_pubid'); if(empty($publisher_id)) { // Re-generate new random publisher key $publisher_id=trim(makePkey()); } } preg_match("/\]*charset\=\"utf\-8\"[^\>]*/", $widget, $matches); if ($matches[0] == "") { preg_match("/\]*charset\=\"[^\"]*\"[^\>]*/", $widget, $matches); if ($matches[0] == "") { $widget = preg_replace("/\]*type\=\"text\/javascript\"[^\>]*/", $widget, $matches); if ($matches[0] == "") { preg_match("/\]*type\=\"[^\"]*\"[^\>]*/", $widget, $matches); if ($matches[0] == "") { $widget = preg_replace("/\var switchTo5x=true;" . $widget; } } elseif (($_POST['st_version']) == '4x') { $widget = preg_replace("/switchTo5x=true/", "switchTo5x=false", $widget); } } // note: do not convert & to & or append WP version here $widget = st_widget_fix_domain($widget); update_option('st_pubid', $publisher_id); update_option('st_widget', $widget); if(!empty($_POST['st_pkey'])){ update_option('st_pubid', $_POST['st_pkey']); } else { if(substr($_POST['st_pkey_hidden'], 0, 3) == "wp.") { update_option('st_pubid', $_POST['st_pkey_hidden']); } else{ $publisher_id=trim(makePkey()); update_option('st_pubid',$publisher_id); } } if(!empty($_POST['st_tags'])){ $tagsin=$_POST['st_tags']; $tagsin=preg_replace("/\\n|\\t/","", $tagsin); $tagsin=preg_replace("/\\\'/","'", $tagsin); //$tagsin=htmlspecialchars_decode($tagsin); $tagsin=trim($tagsin); update_option('st_tags',$tagsin); } if(!empty($_POST['st_services'])){ update_option('st_services', trim($_POST['st_services'],",") ); } if(!empty($_POST['st_current_type'])){ update_option('st_current_type', trim($_POST['st_current_type'],",") ); } $options = array( 'st_add_to_content' , 'st_add_to_page' ); foreach ($options as $option) { if (isset($_POST[$option]) && in_array($_POST[$option], array('yes', 'no'))) { update_option($option, $_POST[$option]); } } header('Location: '.get_bloginfo('wpurl').'/wp-admin/options-general.php?page=sharethis.php&updated=true'); die(); } break; } } } function st_options_form() { $plugin_location=WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); $publisher_id = get_option('st_pubid'); $services = get_option('st_services'); $tags = get_option('st_tags'); $st_current_type=get_option('st_current_type'); $st_widget_version = get_option('st_version'); $st_prompt = get_option('st_prompt'); if(empty($st_current_type)){ $st_current_type="_buttons"; } if(empty($services)){ $services="facebook,twitter,linkedin,email,sharethis"; } if(empty($st_prompt)){ $services.=",fblike,plusone,pinterest"; update_option('st_prompt', 'true'); } if(empty($tags)){ foreach(explode(',',$services) as $svc){ $tags.=""; } } if(empty($st_widget_version)){ $st_widget_version="4x"; } $fourCheck = $st_widget_version == "4x" ? 'checked="checked"' : ""; $fiveCheck = $st_widget_version == "5x" ? 'checked="checked"' : ""; $fourTag = $st_widget_version == "4x" ? 'versionSelect' : ""; $fiveTag = $st_widget_version == "5x" ? 'versionSelect' : ""; $wImage = $fiveTag == "" ? 'Image_Classic-1.png' : 'Image_Multi_Post-1.png'; if(empty($publisher_id)){ $toShow=""; } else{ $toShow=get_option('st_widget'); } $hidden_input_feild = ''; if(substr($publisher_id, 0, 3) == "wp."){ $hidden_input_feild = ''; $publisher_id = ""; } print('

'.__('ShareThis Options', 'sharethis').'


Include Facebook Like, Google +1 and Pinterest.

                       

Choose which version of the widget you would like to use:

        

[+] Click to change order of social buttons or modify list of buttons. (?)


[+] Click to view/modify the HTML tags.

[+]  Click to modify other widget options.

[+] Want Analytics?

To get detailed sharing analytics, you need to register with ShareThis. You also get:
  • Must-have live metrics: shares, clicks, social response, influencer reports & more
  • Monthly tips and tricks newsletter to improve your site\'s share-ability
  • Weekly sharing summary delivered via email (and available online)

  • And it takes just two minutes! Click here to Register.

    At the end of the flow, you will be given a publisher key. Please paste it in the textbox below.
    '.$hidden_input_feild.'
    '); $opt_js_location=$plugin_location."wp_st_opt.js"; print(""); $options = array( 'st_add_to_content' => __('Automatically add ShareThis to your posts?*', 'sharethis') , 'st_add_to_page' => __('Automatically add ShareThis to your pages?*', 'sharethis') ); foreach ($options as $option => $description) { $$option = get_option($option); if (empty($$option) || $$option == 'yes') { $yes = ' selected="selected"'; $no = ''; } else { $yes = ''; $no = ' selected="selected"'; } print('

    '); } print('
    CopyNShare Beta (?)

    This feature can be enabled only once you register. Click here to Register.

    CopyNShare is the new ShareThis widget feature in open beta that enables you to track the shares that occur when a user copies and pastes your website\'s URL or content. ShareThis adds a special #hashtag at the end of your address bar URL to keep track of where your content is being shared on the web, from Facebook, Twitter to emails, etc. When a user copies text within your site, a "See more: yourURL.com#SThashtag" will appear after the pasted text. Enable CopyNShare for your widget! FAQ.

    '); print('
    Hovering Bar (?)

     

    Would you like your sharing buttons to be persistent and remain on the page as the user scrolls? Well, then Hovering Bar is for you. It shows the sharing services on the left side to present a non-intrusive yet always available experience.



    Note: If you enable ShareNow below, then the hovering bar is automatically moved to right side of the page for optimal experience. You can manually change the code
    above for it to also appear on the left side if you like.

    '); print('
    ShareNow (?)

     

    ShareNow is the first-to-market social tool that allows any publisher to leverage frictionless sharing without having to invest in and create their own custom solution. ShareNow allows publishers to put users in control over how they share content to their social networking timelines by allowing them to either continually share or click-to-share content with a simple 'on' and 'off' switch.

    Why choose ShareNow?

    • Increase Social Activity and Page Views
      Always present next to content so users can easily share leading to more click-backs to the publisher's website
    • Power More Content Distribution
      Allows users to continually share content while browsing the publisher's website
    • Put Users in Control
      Users can share, delete and re-share without having to navigate away from the publisher's website

    Pick a style


    '); echo '

    To learn more about other sharing features and available options, visit our help center.

    '; print('

    '); } function st_menu_items() { if (ak_can_update_options()) { add_options_page( __('ShareThis Options', 'sharethis') , __('ShareThis', 'sharethis') , 'manage_options' , basename(__FILE__) , 'st_options_form' ); } } function st_makeEntries(){ global $post; //$st_json='{"type":"vcount","services":"sharethis,facebook,twitter,email"}'; $out=""; $widget=get_option('st_widget'); $tags=get_option('st_tags'); if(!empty($widget)){ if(preg_match('/buttons.js/',$widget)){ if(!empty($tags)){ $tags=preg_replace("/\\\'/","'", $tags); $tags=preg_replace("/<\?php the_permalink\(\); \?>/",get_permalink($post->ID), $tags); $tags=preg_replace("/<\?php the_title\(\); \?>/",strip_tags(get_the_title()), $tags); $tags=preg_replace("/{URL}/",get_permalink($post->ID), $tags); $tags=preg_replace("/{TITLE}/",strip_tags(get_the_title()), $tags); }else{ $tags=""; $tags=""; $tags=preg_replace("/<\?php the_permalink\(\); \?>/",get_permalink($post->ID), $tags); $tags=preg_replace("/<\?php the_title\(\); \?>/",strip_tags(get_the_title()), $tags); } $out=$tags; }else{ $out = ''; } } return $out; } function makePkey(){ return "wp.".sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),mt_rand( 0, 0x0fff ) | 0x4000,mt_rand( 0, 0x3fff ) | 0x8000,mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) ); // return "paste-your-publisher-key-here"; } add_action('wp_head', 'st_widget_head'); add_action('init', 'st_request_handler', 9999); add_action('admin_menu', 'st_menu_items'); ?>