Advertisement
Guest User

modified juiz-social-post-sharer.php

a guest
Feb 24th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.68 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Juiz Social Post Sharer
  4. Plugin URI: http://wordpress.org/extend/plugins/juiz-social-post-sharer/
  5. Description: Add buttons after (or before, or both) your posts to allow visitors share your content (includes no JavaScript mode). You can also use <code>juiz_sps($array)</code> template function or <code>[juiz_sps]</code> shortcode. For more informations see the setting page located in <strong>Settings</strong> submenu.
  6. Author: Geoffrey Crofte
  7. Version: 1.4.2
  8. Author URI: http://geoffrey.crofte.fr
  9. License: GPLv2 or later
  10. Text Domain: juiz-social-post-sharer
  11. Domain Path: /languages
  12.  
  13.  
  14.  
  15. Copyright 2012-2015  Geoffrey Crofte  (email : support@creativejuiz.com)
  16.  
  17.    
  18. This program is free software; you can redistribute it and/or
  19. modify it under the terms of the GNU General Public License
  20. as published by the Free Software Foundation; either version 2
  21. of the License, or (at your option) any later version.
  22.  
  23. This program is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. GNU General Public License for more details.
  27.  
  28. You should have received a copy of the GNU General Public License
  29. along with this program; if not, write to the Free Software
  30. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  31.  
  32. */
  33.  
  34. define( 'JUIZ_SPS_PLUGIN_NAME',  'Juiz Social Post Sharer' );
  35. define( 'JUIZ_SPS_VERSION',      '1.4.2' );
  36. define( 'JUIZ_SPS_FILE',         __FILE__ );
  37. define( 'JUIZ_SPS_DIRNAME',      basename( dirname( __FILE__ ) ) );
  38. define( 'JUIZ_SPS_PLUGIN_URL',   plugin_dir_url( __FILE__ ));
  39. define( 'JUIZ_SPS_SLUG',         'juiz-social-post-sharer' );
  40. define( 'JUIZ_SPS_SETTING_NAME', 'juiz_SPS_settings' );
  41.  
  42.    
  43. // multilingue
  44.  
  45. add_action( 'init', 'make_juiz_sps_multilang' );
  46. function make_juiz_sps_multilang() {
  47.     load_plugin_textdomain( 'juiz-social-post-sharer', false, JUIZ_SPS_DIRNAME.'/languages' );
  48. }
  49.  
  50. if ( is_admin() || ( defined( 'DOING_AJAX' ) && ! DOING_AJAX ) ) {
  51.    
  52.     include('admin/jsps-admin.inc.php');
  53.  
  54. } // end if is_admin
  55.  
  56.  
  57. if ( ! is_admin() ) {
  58.  
  59.     // Enqueue & deregister
  60.     add_action( 'wp_enqueue_scripts', 'juiz_sps_style_and_script');
  61.     if ( ! function_exists( 'juiz_sps_style_and_script' ) ) {
  62.  
  63.         function juiz_sps_style_and_script() {
  64.  
  65.             $juiz_sps_options = get_option( JUIZ_SPS_SETTING_NAME );
  66.  
  67.             if ( is_array( $juiz_sps_options ) ) {
  68.  
  69.                 // TODO future : if(is_numeric($juiz_sps_options['juiz_sps_style'] ) && $juiz_sps_options['juiz_sps_write_css_in_html']==0)
  70.                 if ( is_numeric( $juiz_sps_options['juiz_sps_style'] ) && apply_filters( 'juiz_sps_use_default_css', true ) ) {
  71.  
  72.                     wp_enqueue_style( 'juiz_sps_styles', JUIZ_SPS_PLUGIN_URL . 'css/' . JUIZ_SPS_SLUG . '-' . $juiz_sps_options['juiz_sps_style'] . '.min.css', false, JUIZ_SPS_VERSION, 'all' );
  73.                 }
  74.                 if (
  75.                     ( is_numeric ( $juiz_sps_options['juiz_sps_counter'] ) && $juiz_sps_options['juiz_sps_counter'] == 1 )
  76.                     ||
  77.                     ( isset( $juiz_sps_options['juiz_sps_networks']['print'] ) && $juiz_sps_options['juiz_sps_networks']['print'][0] === 1 )
  78.                     ||
  79.                     ( isset( $juiz_sps_options['juiz_sps_networks']['bookmark'] ) && $juiz_sps_options['juiz_sps_networks']['bookmark'][0] === 1 )
  80.                 ) {
  81.  
  82.                     wp_enqueue_script( 'juiz_sps_scripts', JUIZ_SPS_PLUGIN_URL . 'js/' . JUIZ_SPS_SLUG . '.min.js', array('jquery'), JUIZ_SPS_VERSION, true );
  83.                 }
  84.             }
  85.         }
  86.     }
  87.  
  88.  
  89.     // Thanks to http://boiteaweb.fr/sf_get_current_url-obtenir-url-courante-fonction-semaine-5-6765.html
  90.     if ( ! function_exists( 'sf_get_current_url' ) ) {
  91.         function sf_get_current_url( $mode = 'base' ) {
  92.            
  93.             $url = 'http' . ( is_ssl() ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  94.            
  95.             switch ( $mode ) {
  96.                 case 'raw' :
  97.                     return $url;
  98.                     break;
  99.                 case 'base' :
  100.                     return reset( explode( '?', $url ) );
  101.                     break;
  102.                 case 'uri' :
  103.                     $exp = explode( '?', $url );
  104.                     return trim( str_replace( home_url(), '', reset( $exp ) ), '/' );
  105.                     break;
  106.                 default:
  107.                     return false;
  108.             }
  109.         }
  110.     }
  111.  
  112.  
  113.     // template function
  114.     if ( ! function_exists( 'get_juiz_sps' ) ) {
  115.         function get_juiz_sps( $networks = array(), $counters = 0, $is_current_page_url = 0, $is_shortcode = 0, $url_to_share = NULL ) {
  116.  
  117.             global $post;
  118.  
  119.             $show_me =  ( get_post_meta( $post->ID, '_jsps_metabox_hide_buttons', true) == 'on' ) ? false : true;
  120.             $show_me =  $is_shortcode ? true : $show_me;
  121.  
  122.             // show buttons only if post meta don't ask to hide it, and if it's not a shortcode.
  123.             if ( $show_me ) {
  124.  
  125.                 // url needed by user ?
  126.                 $url_needed_by_user = ( $url_to_share != NULL ) ? $url_to_share : false;
  127.                 if ( in_array( $url_needed_by_user, array( 'permalink', 'siteurl' ) ) ) {
  128.                     switch( $url_needed_by_user ) {
  129.                         case 'permalink' :
  130.                             $url_needed_by_user = get_permalink();
  131.                             break;
  132.                         case 'siteurl' :
  133.                             $url_needed_by_user = get_bloginfo('url');
  134.                             break;
  135.                     }
  136.                 }
  137.                 else {
  138.                     $url_needed_by_user = esc_url( $url_needed_by_user );
  139.                 }
  140.  
  141.                 // texts, URL and image to share
  142.                 $text = wp_strip_all_tags( esc_attr( rawurlencode( $post->post_title ) ) );
  143.                 $url = $post ? get_permalink() : sf_get_current_url( 'raw' );
  144.                 $url = ( $url_needed_by_user == false ) ? $url : $url_needed_by_user;
  145.                 //$url = urlencode(get_permalink());
  146.                 if ( $is_current_page_url &&  $url_needed_by_user == false ) {
  147.                     $url = sf_get_current_url( 'raw' );
  148.                 }
  149.  
  150.                 $url = apply_filters( 'juiz_sps_the_shared_permalink', $url );
  151.                 $image = has_post_thumbnail( $post->ID ) ? wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ) : '';
  152.  
  153.                 // some text filters
  154.                 $total_word = apply_filters( 'juiz_sps_total_count_word', __( 'Total: ', 'juiz-social-post-sharer' ) );
  155.  
  156.                 // some markup filters
  157.                 $hide_intro_phrase          = apply_filters( 'juiz_sps_network_name', false );
  158.                 $share_the_post_sentence    = apply_filters( 'juiz_sps_intro_phrase_text', __('Share the post', 'juiz-social-post-sharer') );
  159.                 $before_the_sps_content     = apply_filters( 'juiz_sps_before_the_sps', '' );
  160.                 $after_the_sps_content      = apply_filters( 'juiz_sps_after_the_sps', '' );
  161.                 $before_the_list            = apply_filters( 'juiz_sps_before_the_list', '' );
  162.                 $after_the_list             = apply_filters( 'juiz_sps_after_the_list', '' );
  163.                 $before_first_i             = apply_filters( 'juiz_sps_before_first_item', '' );
  164.                 $after_last_i               = apply_filters( 'juiz_sps_after_last_item', '' );
  165.                 $container_classes          = apply_filters( 'juiz_sps_container_classes', '' );
  166.                 $rel_nofollow               = apply_filters( 'juiz_sps_links_nofollow', 'rel="nofollow"' );
  167.  
  168.                 // markup filters
  169.                 $div    = apply_filters( 'juiz_sps_container_tag', 'div' );
  170.                 $p      = apply_filters( 'juiz_sps_phrase_tag', 'p' );
  171.                 $ul     = apply_filters( 'juiz_sps_list_container_tag', 'ul' );
  172.                 $li     = apply_filters( 'juiz_sps_list_of_item_tag', 'li' );
  173.  
  174.  
  175.                 // get the plugin options
  176.                 $juiz_sps_options = get_option( JUIZ_SPS_SETTING_NAME );
  177.  
  178.                 // classes and attributes options
  179.                 $juiz_sps_target_link = ( isset( $juiz_sps_options['juiz_sps_target_link'] ) && $juiz_sps_options['juiz_sps_target_link'] == 1 ) ? ' target="_blank"' : '';
  180.                 $juiz_sps_hidden_name_class = ( isset( $juiz_sps_options['juiz_sps_hide_social_name'] ) && $juiz_sps_options['juiz_sps_hide_social_name'] == 1 ) ? ' juiz_sps_hide_name' : '';
  181.                 $container_classes .= ( intval( $counters ) == 1 ) ? ' juiz_sps_counters' : '';
  182.                 $container_classes .= ( isset( $juiz_sps_options['juiz_sps_counter_option'] ) ) ? ' counters_' . $juiz_sps_options['juiz_sps_counter_option'] : ' counters_both';
  183.  
  184.                 // other options
  185.                 $juiz_sps_display_where = isset( $juiz_sps_options['juiz_sps_display_where'] ) ? $juiz_sps_options['juiz_sps_display_where'] : '';
  186.                 $force_pinterest_snif = isset( $juiz_sps_options['juiz_sps_force_pinterest_snif'] ) ? intval( $juiz_sps_options['juiz_sps_force_pinterest_snif'] ) : 0;
  187.  
  188.                 // beginning markup
  189.                 $juiz_sps_content = $before_the_sps_content;
  190.                 $juiz_sps_content .= "\n" . '<' . $div . ' class="juiz_sps_links ' . esc_attr( $container_classes ) . ' juiz_sps_displayed_' . $juiz_sps_display_where . '">';
  191.                 $juiz_sps_content .= $hide_intro_phrase ? '' : "\n" . '<' . $p . ' class="screen-reader-text juiz_sps_maybe_hidden_text">' . $share_the_post_sentence . ' "' . wp_strip_all_tags( get_the_title() ) . '"</' . $p . '>' . "\n";
  192.                 $juiz_sps_content .= $before_the_list;
  193.                 $juiz_sps_content .= "\n\t" . '<' . $ul . ' class="juiz_sps_links_list' . esc_attr( $juiz_sps_hidden_name_class ) . '">';
  194.                 $juiz_sps_content .= $before_first_i;
  195.  
  196.                 // networks to display
  197.                 // 2 differents results by:
  198.                 // -- using hook (options from admin panel)
  199.                 // -- using shortcode/template-function (the array $networks in parameter of this function)
  200.                 $juiz_sps_networks = array();
  201.  
  202.                 if ( ! empty( $networks ) ) {
  203.                     // compare $juiz_sps_options['juiz_sps_networks'] array and $networks array and conserve form the first one all that correspond to the second one's keys
  204.                     $juiz_sps_networks = array();
  205.  
  206.                     foreach( $juiz_sps_options['juiz_sps_networks'] as $k => $v ) {
  207.                         if ( in_array( $k, $networks ) ) {
  208.                             $juiz_sps_networks[ $k ] = $v;
  209.                             $juiz_sps_networks[ $k ][0] = 1; // set its visible value to 1 (visible)
  210.                         }
  211.                     }
  212.  
  213.                 }
  214.                 else {
  215.                     $juiz_sps_networks = $juiz_sps_options['juiz_sps_networks'];
  216.                 }
  217.  
  218.  
  219.                 // each links (come from options or manual array)
  220.                 foreach( $juiz_sps_networks as $k => $v ) {
  221.                     if ( $v[0] == 1 ) {
  222.                         $api_link = $api_text = '';
  223.                         $url  = apply_filters( 'juiz_sps_the_shared_permalink_for_' . $k, $url );
  224.                         $network_name = isset( $v[1] ) ? $v[1] : $k;
  225.                         $network_name = apply_filters( 'juiz_sps_share_name_for_' . $k, $network_name );
  226.  
  227.                         $twitter_user = $juiz_sps_options['juiz_sps_twitter_user'] != '' ? '&amp;related=' . $juiz_sps_options['juiz_sps_twitter_user'] . '&amp;via=' . $juiz_sps_options['juiz_sps_twitter_user'] : '';
  228.  
  229.                         $api_text = apply_filters( 'juiz_sps_share_text_for_' . $k, sprintf( __( 'Share this article on %s', 'juiz-social-post-sharer' ), $network_name ) );
  230.  
  231.                         $more_attr = '';
  232.  
  233.                         switch ( $k ) {
  234.                             case 'twitter' :
  235.                                 $api_link = 'https://twitter.com/intent/tweet?source=webclient&amp;original_referer=' . $url . '%3Futm_source%3Dtwitter%26utm_medium%3Dsocialsharing' .  '&amp;text=' . $text . '&amp;url=' . $url . '%3Futm_source%3Dtwitter%26utm_medium%3Dsocialsharing' . $twitter_user;
  236.                                 break;
  237.  
  238.                             case 'facebook' :
  239.                                 $api_link = 'https://www.facebook.com/sharer/sharer.php?u=' . $url . '%3Futm_source%3Dfacebook%26utm_medium%3Dsocialsharing';
  240.                                 break;
  241.  
  242.                             case 'google' :
  243.                                 $api_link = 'https://plus.google.com/share?url=' . $url . '%3Futm_source%3Dgplus%26utm_medium%3Dsocialsharing';
  244.                                 break;
  245.  
  246.                             case 'pinterest' :
  247.                                 if ( $image != '' && $force_pinterest_snif == 0 ) {
  248.                                     $api_link = 'https://pinterest.com/pin/create/bookmarklet/?media=' . $image[0] . '&amp;url=' . $url . '&amp;title=' . get_the_title() . '&amp;description=' . $post->post_excerpt;
  249.                                 }
  250.                                 else {
  251.                                     $api_link = "javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());";
  252.                                     $juiz_sps_target_link = '';
  253.                                 }
  254.                                 $api_text = apply_filters( 'juiz_sps_share_text_for_' . $k, __( 'Share an image of this article on Pinterest', 'juiz-social-post-sharer' ) );
  255.                                 break;
  256.  
  257.                             case 'viadeo' :
  258.                                 $api_link = 'https://www.viadeo.com/?url=' . $url . '&amp;title=' . $text;
  259.                                 break;
  260.  
  261.                             case 'linkedin':
  262.                                 $api_link = 'https://www.linkedin.com/shareArticle?mini=true&amp;ro=true&amp;trk=JuizSocialPostSharer&amp;title=' . $text . '&amp;url=' . $url;
  263.                                 break;
  264.  
  265.                             case 'digg':
  266.                                 $api_link = 'https://digg.com/submit?phase=2%20&amp;url=' . $url . '&amp;title=' . $text;
  267.                                 break;
  268.  
  269.                             case 'stumbleupon':
  270.                                 $api_link = 'https://www.stumbleupon.com/badge/?url=' . $url;
  271.                                 break;
  272.  
  273.                             case 'tumblr':
  274.                                 $api_link = 'https://www.tumblr.com/widgets/share/tool?canonicalUrl=' . $url;
  275.                                 break;
  276.  
  277.                             case 'reddit':
  278.                                 $api_link = 'https://www.reddit.com/submit?url=' . $url . '%3Futm_source%3Dreddit%26utm_medium%3Dsocialsharing' . '&amp;title=' . $text;
  279.                                 break;
  280.  
  281.                             case 'delicious':
  282.                                 $api_link = 'https://delicious.com/save?v=5&amp;provider=JSPS&amp;url=' . $url . '&amp;title=' . $text;
  283.                                 break;
  284.  
  285.                             case 'weibo':
  286.                                 // title tips by Aili (thank you ;p)
  287.                                 $simplecontent = $text . esc_attr( urlencode( " : " . mb_substr( strip_tags( $post->post_content ), 0, 90, 'utf-8') ) );
  288.                                 $api_link = 'http://service.weibo.com/share/share.php?title=' . $simplecontent . '&amp;url=' . $url;
  289.                                 break;
  290.  
  291.                             case 'vk':
  292.                                 $api_link = 'https://vkontakte.ru/share.php?url=' . $url;
  293.                                 break;
  294.  
  295.                             case 'mail' :
  296.                                 if ( strpos( $juiz_sps_options['juiz_sps_mail_body'], '%%' ) || strpos( $juiz_sps_options['juiz_sps_mail_subject'], '%%' ) ) {
  297.                                     $api_link = 'mailto:?subject=' . $juiz_sps_options['juiz_sps_mail_subject'] . '&amp;body=' . $juiz_sps_options['juiz_sps_mail_body'];
  298.                                     $api_link = preg_replace( array('#%%title%%#', '#%%siteurl%%#', '#%%permalink%%#', '#%%url%%#'), array( get_the_title(), get_site_url(), get_permalink() . '%3Futm_source%3Demail%26utm_medium%3Dsocialsharing', $url ), $api_link );
  299.                                 }
  300.                                 else {
  301.                                     $api_link = 'mailto:?subject=' . $juiz_sps_options['juiz_sps_mail_subject'] . '&amp;body=' . $juiz_sps_options['juiz_sps_mail_body'] . ":" . $url;
  302.                                 }
  303.                                 $api_text = apply_filters( 'juiz_sps_share_text_for_' . $k, __( 'Share this article with a friend (email)', 'juiz-social-post-sharer') );
  304.                                 break;
  305.  
  306.                             case 'bookmark' :
  307.                                 $api_link = $url;
  308.                                 $api_text = apply_filters( 'juiz_sps_share_text_for_' . $k, __( 'Bookmark this article (on your browser)', 'juiz-social-post-sharer') );
  309.                                 $more_attr = ' data-alert="' . esc_attr( __( 'Press %s to bookmark this page.', 'juiz-social-post-sharer' ) ) . '"';
  310.                                 break;
  311.  
  312.                             case 'print' :
  313.                                 $api_link = '#';
  314.                                 $api_text = apply_filters( 'juiz_sps_share_text_for_' . $k, __( 'Print this page', 'juiz-social-post-sharer') );
  315.                                 break;
  316.                         }
  317.  
  318.                         $juiz_sps_content .= '<' . $li . ' class="juiz_sps_item juiz_sps_link_' . esc_attr( $k ) . '"><a href="' . wp_strip_all_tags( esc_attr( $api_link ) ) . '" ' . $rel_nofollow . '' . $more_attr . ' title="' . esc_attr( $api_text ) . '"' . $juiz_sps_target_link . '><span class="juiz_sps_icon jsps-' . esc_attr( $k ) . '"></span><span class="juiz_sps_network_name">' . esc_html( $network_name ) . '</span></a></' . $li . '>';
  319.  
  320.                     }
  321.                 }
  322.  
  323.                 $general_counters = ( isset( $juiz_sps_options['juiz_sps_counter'] ) && $juiz_sps_options['juiz_sps_counter'] == 1 ) ? 1 : 0;
  324.  
  325.                 // no data-* attribute if user markup is not HTML5 :/
  326.                 $hidden_info = '<input type="hidden" class="juiz_sps_info_plugin_url" value="' . JUIZ_SPS_PLUGIN_URL . '" /><input type="hidden" class="juiz_sps_info_permalink" value="' . $url . '" />';
  327.  
  328.                 $juiz_sps_content .= $after_last_i;
  329.  
  330.                 // show total counter only when "both" or "total" is selected
  331.                 if ( isset( $juiz_sps_options['juiz_sps_counter_option'] ) ) {
  332.                     if ( $juiz_sps_options['juiz_sps_counter_option'] == 'both' || $juiz_sps_options['juiz_sps_counter_option'] == 'total' ) {
  333.                         $juiz_sps_content .= (
  334.                                                 ( $general_counters == 1 && intval( $counters ) == 1)
  335.                                                 ||
  336.                                                 ( $general_counters == 0 && intval( $counters ) == 1 )
  337.                                              )
  338.                                              ?
  339.                                              '<' . $li . ' class="juiz_sps_item juiz_sps_totalcount_item"><span class="juiz_sps_totalcount" title="' . esc_attr( $total_word ) . '"><span class="juiz_sps_t_nb"></span></span></' . $li . '>'
  340.                                              : '';
  341.                     }
  342.                 }
  343.                 $juiz_sps_content .= '</' . $ul . '>' . "\n\t";
  344.                 $juiz_sps_content .= $after_the_list;
  345.                 $juiz_sps_content .= ( ( $general_counters == 1 && intval( $counters ) == 1 ) || ( $general_counters == 0 && intval( $counters ) == 1 ) )  ? $hidden_info : '';
  346.                 $juiz_sps_content .= '</' . $div . '>' . "\n\n";
  347.                 $juiz_sps_content .= $after_the_sps_content;
  348.  
  349.  
  350.                 // final markup
  351.  
  352.                 return $juiz_sps_content;
  353.  
  354.             } // end of if post meta hide sharing buttons
  355.  
  356.         } // end of get_juiz_sps()
  357.     } // end of if exists
  358.  
  359.  
  360.     // just a little alias
  361.     if ( ! function_exists( 'juiz_sps' ) ) {
  362.         function juiz_sps( $networks = array(), $counters = 0, $current_page = 0, $is_shortcode = 0, $url_to_share = NULL ) {
  363.             echo get_juiz_sps( $networks, $counters, $current_page, $is_shortcode, $url_to_share );
  364.         }
  365.     }
  366.  
  367.     // write buttons in content
  368.     add_filter( 'the_content', 'juiz_sps_print_links', 10, 1 );
  369.     if ( apply_filters( 'juiz_sps_buttons_in_excerpt', false ) ) {
  370.         add_filter( 'the_excerpt', 'juiz_sps_print_links', 10, 1 );
  371.     }
  372.  
  373.     if ( ! function_exists( 'juiz_sps_print_links' ) ) {
  374.         function juiz_sps_print_links( $content ) {
  375.            
  376.             $juiz_sps_options = get_option( JUIZ_SPS_SETTING_NAME );
  377.  
  378.             if ( isset( $juiz_sps_options['juiz_sps_display_in_types'] ) ) {
  379.  
  380.                 // write buttons only if administrator checked this type
  381.                 $is_all_lists = in_array( 'all_lists', $juiz_sps_options['juiz_sps_display_in_types'] );
  382.                 $singular_options = $juiz_sps_options['juiz_sps_display_in_types'];
  383.                 unset( $singular_options['all_lists'] );
  384.  
  385.                 $is_lists_authorized = ( is_archive() || is_front_page() || is_search() || is_tag() || is_post_type_archive() || is_home()) && $is_all_lists ? true : false;
  386.                 $is_singular = is_singular( $singular_options );
  387.  
  388.                 if ( $is_singular || $is_lists_authorized ) {
  389.  
  390.                     $need_counters = $juiz_sps_options['juiz_sps_counter'] ? 1 : 0;
  391.  
  392.                     $jsps_links = get_juiz_sps( array(), $need_counters );
  393.  
  394.                     $juiz_sps_display_where = isset( $juiz_sps_options['juiz_sps_display_where'] ) ? $juiz_sps_options['juiz_sps_display_where'] : '';
  395.  
  396.                     if ( 'top' == $juiz_sps_display_where || 'both' == $juiz_sps_display_where ) {
  397.                         $content = $jsps_links . $content;
  398.                     }
  399.                     if ( 'bottom' == $juiz_sps_display_where || 'both' == $juiz_sps_display_where ) {
  400.                         $content = $content . $jsps_links;
  401.                     }
  402.  
  403.                     return $content;
  404.                 }
  405.                 else {
  406.                     return $content;
  407.                 }
  408.             }
  409.             else {
  410.                 return $content;
  411.             }
  412.  
  413.         } // end function
  414.     } // end if function exists
  415.  
  416.  
  417.     /*
  418.      * Add shortcode
  419.      */
  420.     if ( ! function_exists( 'sc_4_jsps' ) ) {
  421.  
  422.         function sc_4_jsps( $atts ) {
  423.            
  424.             $atts = shortcode_atts( array(
  425.                 'buttons'   => 'facebook,twitter,mail,google,stumbleupon,linkedin,pinterest,viadeo,digg,weibo',
  426.                 'counters'  => 0,
  427.                 'current'   => 1,
  428.                 'url'       => NULL
  429.             ), $atts );
  430.            
  431.             // buttons become array ("digg,mail", "digg ,mail", "digg, mail", "digg , mail", are right syntaxes)
  432.             $jsps_networks      = preg_split( '#[\s+,\s+]#', $atts['buttons'] );
  433.             $jsps_counters      = intval( $atts['counters'] );
  434.             $jsps_current_page  = intval( $atts['current'] );
  435.             $jsps_url           = $atts['url'];
  436.  
  437.             if ( $jsps_current_page == 1 ) {
  438.                 wp_enqueue_script( 'juiz_sps_scripts', JUIZ_SPS_PLUGIN_URL . 'js/' . JUIZ_SPS_SLUG . '.min.js', array( 'jquery' ), false, true );
  439.             }
  440.            
  441.             ob_start();
  442.             juiz_sps( $jsps_networks, $jsps_counters, $jsps_current_page, 1, $jsps_url ); //do an echo
  443.             $jsps_sc_output = ob_get_contents();
  444.             ob_end_clean();
  445.            
  446.  
  447.             return $jsps_sc_output;
  448.         }
  449.         add_shortcode( 'juiz_social','sc_4_jsps' );
  450.         add_shortcode( 'juiz_sps'   ,'sc_4_jsps' );
  451.     }
  452.  
  453. } // end of if not admin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement