diff options
Diffstat (limited to 'plugins/jetpack/modules/sharedaddy')
-rw-r--r-- | plugins/jetpack/modules/sharedaddy/sharing-sources.php | 257 | ||||
-rw-r--r-- | plugins/jetpack/modules/sharedaddy/sharing.js | 2 | ||||
-rw-r--r-- | plugins/jetpack/modules/sharedaddy/sharing.php | 164 |
3 files changed, 243 insertions, 180 deletions
diff --git a/plugins/jetpack/modules/sharedaddy/sharing-sources.php b/plugins/jetpack/modules/sharedaddy/sharing-sources.php index 73f38553..ec87639d 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing-sources.php +++ b/plugins/jetpack/modules/sharedaddy/sharing-sources.php @@ -1,8 +1,8 @@ <?php abstract class Sharing_Source { - public $button_style; - public $smart; + public $button_style; + public $smart; protected $open_link_in_new; protected $id; @@ -21,11 +21,13 @@ abstract class Sharing_Source { */ $this->open_link_in_new = apply_filters( 'jetpack_open_sharing_in_new_window', true ); - if ( isset( $settings['button_style'] ) ) + if ( isset( $settings['button_style'] ) ) { $this->button_style = $settings['button_style']; + } - if ( isset( $settings['smart'] ) ) + if ( isset( $settings['smart'] ) ) { $this->smart = $settings['smart']; + } } public function http() { @@ -79,17 +81,19 @@ abstract class Sharing_Source { public function get_link( $url, $text, $title, $query = '', $id = false ) { $args = func_get_args(); - $klasses = array( 'share-'.$this->get_class(), 'sd-button' ); + $klasses = array( 'share-' . $this->get_class(), 'sd-button' ); - if ( 'icon' == $this->button_style || 'icon-text' == $this->button_style ) + if ( 'icon' == $this->button_style || 'icon-text' == $this->button_style ) { $klasses[] = 'share-icon'; + } if ( 'icon' == $this->button_style ) { $text = $title; $klasses[] = 'no-text'; - if ( true == $this->open_link_in_new ) + if ( true == $this->open_link_in_new ) { $text .= __( ' (Opens in new window)', 'jetpack' ); + } } /** @@ -144,15 +148,17 @@ abstract class Sharing_Source { */ $query = apply_filters( 'jetpack_sharing_display_query', $query, $this, $id, $args ); - if ( !empty( $query ) ) { - if ( false === stripos( $url, '?' ) ) - $url .= '?'.$query; - else - $url .= '&'.$query; + if ( ! empty( $query ) ) { + if ( false === stripos( $url, '?' ) ) { + $url .= '?' . $query; + } else { + $url .= '&' . $query; + } } - if ( 'text' == $this->button_style ) + if ( 'text' == $this->button_style ) { $klasses[] = 'no-icon'; + } /** * Filter the sharing display classes. @@ -202,7 +208,6 @@ abstract class Sharing_Source { ( true == $this->open_link_in_new ) ? ' target="_blank"' : '', $title, ( 'icon' == $this->button_style ) ? '></span><span class="sharing-screen-reader-text"' : '', - $text ); } @@ -237,20 +242,25 @@ abstract class Sharing_Source { public function display_preview( $echo = true, $force_smart = false, $button_style = null ) { $text = ' '; $button_style = ( ! empty( $button_style ) ) ? $button_style : $this->button_style; - if ( !$this->smart && ! $force_smart ) - if ( $button_style != 'icon' ) + if ( ! $this->smart && ! $force_smart ) { + if ( $button_style != 'icon' ) { $text = $this->get_name(); + } + } - $klasses = array( 'share-'.$this->get_class(), 'sd-button' ); + $klasses = array( 'share-' . $this->get_class(), 'sd-button' ); - if ( $button_style == 'icon' || $button_style == 'icon-text' ) + if ( $button_style == 'icon' || $button_style == 'icon-text' ) { $klasses[] = 'share-icon'; + } - if ( $button_style == 'icon' ) + if ( $button_style == 'icon' ) { $klasses[] = 'no-text'; + } - if ( $button_style == 'text' ) + if ( $button_style == 'text' ) { $klasses[] = 'no-icon'; + } $link = sprintf( '<a rel="nofollow" class="%s" href="javascript:void(0)" title="%s"><span>%s</span></a>', @@ -261,8 +271,9 @@ abstract class Sharing_Source { $smart = ( $this->smart || $force_smart ) ? 'on' : 'off'; $return = "<div class='option option-smart-$smart'>$link</div>"; - if ( $echo ) + if ( $echo ) { echo $return; + } return $return; } @@ -274,24 +285,26 @@ abstract class Sharing_Source { if ( $post == false ) { // get total number of shares for service - return (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s", $blog_id, $name ) ); + return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s', $blog_id, $name ) ); } // get total shares for a post - return (int) $wpdb->get_var( $wpdb->prepare( "SELECT count FROM sharing_stats WHERE blog_id = %d AND post_id = %d AND share_service = %s", $blog_id, $post->ID, $name ) ); + return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT count FROM sharing_stats WHERE blog_id = %d AND post_id = %d AND share_service = %s', $blog_id, $post->ID, $name ) ); } public function get_posts_total() { global $wpdb, $blog_id; $totals = array(); - $name = strtolower( $this->get_id() ); + $name = strtolower( $this->get_id() ); - $my_data = $wpdb->get_results( $wpdb->prepare( "SELECT post_id as id, SUM( count ) as total FROM sharing_stats WHERE blog_id = %d AND share_service = %s GROUP BY post_id ORDER BY count DESC ", $blog_id, $name ) ); + $my_data = $wpdb->get_results( $wpdb->prepare( 'SELECT post_id as id, SUM( count ) as total FROM sharing_stats WHERE blog_id = %d AND share_service = %s GROUP BY post_id ORDER BY count DESC ', $blog_id, $name ) ); - if ( !empty( $my_data ) ) - foreach( $my_data as $row ) + if ( ! empty( $my_data ) ) { + foreach ( $my_data as $row ) { $totals[] = new Sharing_Post_Total( $row->id, $row->total ); + } + } usort( $totals, array( 'Sharing_Post_Total', 'cmp' ) ); @@ -312,18 +325,19 @@ abstract class Sharing_Source { } public function js_dialog( $name, $params = array() ) { - if ( true !== $this->open_link_in_new ) + if ( true !== $this->open_link_in_new ) { return; + } $defaults = array( - 'menubar' => 1, + 'menubar' => 1, 'resizable' => 1, - 'width' => 600, - 'height' => 400, + 'width' => 600, + 'height' => 400, ); $params = array_merge( $defaults, $params ); $opts = array(); - foreach( $params as $key => $val ) { + foreach ( $params as $key => $val ) { $opts[] = "$key=$val"; } $opts = implode( ',', $opts ); @@ -360,10 +374,11 @@ class Share_Email extends Sharing_Source { public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); - if ( 'official' == $this->button_style ) + if ( 'official' == $this->button_style ) { $this->smart = true; - else + } else { $this->smart = false; + } } public function get_name() { @@ -373,16 +388,19 @@ class Share_Email extends Sharing_Source { // Default does nothing public function process_request( $post, array $post_data ) { $ajax = false; - if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) + if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) { $ajax = true; + } $source_email = $target_email = $source_name = false; - if ( isset( $post_data['source_email'] ) && is_email( $post_data['source_email'] ) ) + if ( isset( $post_data['source_email'] ) && is_email( $post_data['source_email'] ) ) { $source_email = $post_data['source_email']; + } - if ( isset( $post_data['target_email'] ) && is_email( $post_data['target_email'] ) ) + if ( isset( $post_data['target_email'] ) && is_email( $post_data['target_email'] ) ) { $target_email = $post_data['target_email']; + } if ( isset( $post_data['source_name'] ) && strlen( $post_data['source_name'] ) < 200 ) { $source_name = $post_data['source_name']; @@ -393,7 +411,7 @@ class Share_Email extends Sharing_Source { } // Test email - $error = 1; // Failure in data + $error = 1; // Failure in data if ( empty( $post_data['source_f_name'] ) && $source_email && $target_email && $source_name ) { /** * Allow plugins to stop the email sharing button from running the shared message through Akismet. @@ -408,10 +426,10 @@ class Share_Email extends Sharing_Source { */ if ( apply_filters( 'sharing_email_check', true, $post, $post_data ) ) { $data = array( - 'post' => $post, + 'post' => $post, 'source' => $source_email, 'target' => $target_email, - 'name' => $source_name + 'name' => $source_name, ); // todo: implement an error message when email doesn't get sent. /** @@ -444,24 +462,25 @@ class Share_Email extends Sharing_Source { ?> <div class="response"> <div class="response-title"><?php _e( 'This post has been shared!', 'jetpack' ); ?></div> - <div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div> - <div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div> + <div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div> + <div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div> </div> <?php + } else { + wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email' ); } - else - wp_safe_redirect( get_permalink( $post->ID ).'?shared=email' ); die(); + } else { + $error = 2; // Email check failed } - else - $error = 2; // Email check failed } - if ( $ajax ) + if ( $ajax ) { echo $error; - else - wp_safe_redirect( get_permalink( $post->ID ).'?shared=email&msg=fail' ); + } else { + wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email&msg=fail' ); + } die(); } @@ -542,10 +561,11 @@ class Share_Twitter extends Sharing_Source { public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); - if ( 'official' == $this->button_style ) + if ( 'official' == $this->button_style ) { $this->smart = true; - else + } else { $this->smart = false; + } } public function get_name() { @@ -570,7 +590,7 @@ class Share_Twitter extends Sharing_Source { * was introduced with the adding of the Twitter cards. * This should be a temporary solution until a better method is setup. */ - if( 'jetpack' == $twitter_site_tag_value ) { + if ( 'jetpack' == $twitter_site_tag_value ) { $twitter_site_tag_value = ''; } @@ -609,8 +629,9 @@ class Share_Twitter extends Sharing_Source { foreach ( $related_accounts as $related_account_username => $related_account_description ) { // Join the description onto the end of the username - if ( $related_account_description ) + if ( $related_account_description ) { $related_account_username .= ':' . $related_account_description; + } $related[] = $related_account_username; } @@ -735,10 +756,11 @@ class Share_Reddit extends Sharing_Source { public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); - if ( 'official' == $this->button_style ) + if ( 'official' == $this->button_style ) { $this->smart = true; - else + } else { $this->smart = false; + } } public function get_name() { @@ -746,10 +768,11 @@ class Share_Reddit extends Sharing_Source { } public function get_display( $post ) { - if ( $this->smart ) + if ( $this->smart ) { return '<div class="reddit_button"><iframe src="' . $this->http() . '://www.reddit.com/static/button/button1.html?newwindow=true&width=120&url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '" height="22" width="120" scrolling="no" frameborder="0"></iframe></div>'; - else + } else { return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Reddit', 'share to', 'jetpack' ), __( 'Click to share on Reddit', 'jetpack' ), 'share=reddit' ); + } } public function process_request( $post, array $post_data ) { @@ -770,10 +793,11 @@ class Share_LinkedIn extends Sharing_Source { public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); - if ( 'official' == $this->button_style ) + if ( 'official' == $this->button_style ) { $this->smart = true; - else + } else { $this->smart = false; + } } public function get_name() { @@ -808,7 +832,6 @@ class Share_LinkedIn extends Sharing_Source { // Using the same URL as the official button, which is *not* LinkedIn's documented sharing link // https://www.linkedin.com/cws/share?url={url}&token=&isFramed=false - $linkedin_url = add_query_arg( array( 'url' => rawurlencode( $post_link ), ), 'https://www.linkedin.com/cws/share?token=&isFramed=false' ); @@ -822,14 +845,14 @@ class Share_LinkedIn extends Sharing_Source { } public function display_footer() { - if ( !$this->smart ) { + if ( ! $this->smart ) { $this->js_dialog( $this->shortname, array( 'width' => 580, 'height' => 450 ) ); } else { ?><script type="text/javascript"> jQuery( document ).ready( function() { - jQuery.getScript( 'https://platform.linkedin.com/in.js?async=true', function success() { - IN.init(); - }); + jQuery.getScript( 'https://platform.linkedin.com/in.js?async=true', function success() { + IN.init(); + }); }); jQuery( document.body ).on( 'post-load', function() { if ( typeof IN != 'undefined' ) @@ -848,13 +871,15 @@ class Share_Facebook extends Sharing_Source { public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); - if ( isset( $settings['share_type'] ) ) + if ( isset( $settings['share_type'] ) ) { $this->share_type = $settings['share_type']; + } - if ( 'official' == $this->button_style ) + if ( 'official' == $this->button_style ) { $this->smart = true; - else + } else { $this->smart = false; + } } public function get_name() { @@ -865,12 +890,12 @@ class Share_Facebook extends Sharing_Source { } function guess_locale_from_lang( $lang ) { - if ( 'en' == $lang || 'en_US' == $lang || !$lang ) { + if ( 'en' == $lang || 'en_US' == $lang || ! $lang ) { return 'en_US'; } - if ( !class_exists( 'GP_Locales' ) ) { - if ( !defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || !file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { + if ( ! class_exists( 'GP_Locales' ) ) { + if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { return false; } @@ -979,10 +1004,11 @@ class Share_Print extends Sharing_Source { public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); - if ( 'official' == $this->button_style ) + if ( 'official' == $this->button_style ) { $this->smart = true; - else + } else { $this->smart = false; + } } public function get_name() { @@ -1000,10 +1026,11 @@ class Share_PressThis extends Sharing_Source { public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); - if ( 'official' == $this->button_style ) + if ( 'official' == $this->button_style ) { $this->smart = true; - else + } else { $this->smart = false; + } } public function get_name() { @@ -1038,10 +1065,11 @@ class Share_PressThis extends Sharing_Source { $blog = current( $blogs ); - $url = $blog->siteurl.'/wp-admin/press-this.php?u='.rawurlencode( $this->get_share_url( $post->ID ) ).'&t='.rawurlencode( $this->get_share_title( $post->ID ) ); + $url = $blog->siteurl . '/wp-admin/press-this.php?u=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&t=' . rawurlencode( $this->get_share_title( $post->ID ) ); - if ( isset( $_GET['sel'] ) ) - $url .= '&s='.rawurlencode( $_GET['sel'] ); + if ( isset( $_GET['sel'] ) ) { + $url .= '&s=' . rawurlencode( $_GET['sel'] ); + } // Record stats parent::process_request( $post, $post_data ); @@ -1064,10 +1092,11 @@ class Share_GooglePlus1 extends Sharing_Source { public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); - if ( 'official' == $this->button_style ) + if ( 'official' == $this->button_style ) { $this->smart = true; - else + } else { $this->smart = false; + } } public function get_name() { @@ -1154,11 +1183,11 @@ class Share_GooglePlus1 extends Sharing_Source { if ( $post == false ) { // get total number of shares for service - return $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s", $blog_id, $name ) ); + return $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s', $blog_id, $name ) ); } - //get total shares for a post - return $wpdb->get_var( $wpdb->prepare( "SELECT count FROM sharing_stats WHERE blog_id = %d AND post_id = %d AND share_service = %s", $blog_id, $post->ID, $name ) ); + // get total shares for a post + return $wpdb->get_var( $wpdb->prepare( 'SELECT count FROM sharing_stats WHERE blog_id = %d AND post_id = %d AND share_service = %s', $blog_id, $post->ID, $name ) ); } } @@ -1200,8 +1229,9 @@ class Share_Custom extends Sharing_Advanced_Source { } } - if ( isset( $settings['url'] ) ) + if ( isset( $settings['url'] ) ) { $this->url = $settings['url']; + } } public function get_name() { @@ -1209,22 +1239,25 @@ class Share_Custom extends Sharing_Advanced_Source { } public function get_display( $post ) { - $str = $this->get_link( $this->get_process_request_url( $post->ID ), esc_html( $this->name ), sprintf( __( 'Click to share on %s', 'jetpack' ), esc_attr( $this->name ) ), 'share='.$this->id ); + $str = $this->get_link( $this->get_process_request_url( $post->ID ), esc_html( $this->name ), sprintf( __( 'Click to share on %s', 'jetpack' ), esc_attr( $this->name ) ), 'share=' . $this->id ); return str_replace( '<span>', '<span style="' . esc_attr( 'background-image:url("' . addcslashes( esc_url_raw( $this->icon ), '"' ) . '");' ) . '">', $str ); } public function process_request( $post, array $post_data ) { $url = str_replace( '&', '&', $this->url ); + $url = str_replace( '%post_id%', rawurlencode( $post->ID ), $url ); $url = str_replace( '%post_url%', rawurlencode( $this->get_share_url( $post->ID ) ), $url ); $url = str_replace( '%post_full_url%', rawurlencode( get_permalink( $post->ID ) ), $url ); $url = str_replace( '%post_title%', rawurlencode( $this->get_share_title( $post->ID ) ), $url ); + $url = str_replace( '%home_url%', rawurlencode( home_url() ), $url ); + $url = str_replace( '%post_slug%', rawurlencode( $post->post_name ), $url ); if ( strpos( $url, '%post_tags%' ) !== false ) { - $tags = get_the_tags( $post->ID ); + $tags = get_the_tags( $post->ID ); $tagged = ''; if ( $tags ) { - foreach ( $tags AS $tag ) { + foreach ( $tags as $tag ) { $tagged[] = rawurlencode( $tag->name ); } @@ -1236,8 +1269,9 @@ class Share_Custom extends Sharing_Advanced_Source { if ( strpos( $url, '%post_excerpt%' ) !== false ) { $url_excerpt = $post->post_excerpt; - if ( empty( $url_excerpt ) ) + if ( empty( $url_excerpt ) ) { $url_excerpt = $post->post_content; + } $url_excerpt = strip_tags( strip_shortcodes( $url_excerpt ) ); $url_excerpt = wp_html_excerpt( $url_excerpt, 100 ); @@ -1291,14 +1325,17 @@ class Share_Custom extends Sharing_Advanced_Source { $url = trim( esc_url_raw( $data['url'] ) ); $icon = trim( esc_url_raw( $data['icon'] ) ); - if ( $name ) + if ( $name ) { $this->name = $name; + } - if ( $url ) - $this->url = $url; + if ( $url ) { + $this->url = $url; + } - if ( $icon ) + if ( $icon ) { $this->icon = $icon; + } } public function get_options() { @@ -1313,22 +1350,26 @@ class Share_Custom extends Sharing_Advanced_Source { $opts = $this->get_options(); $text = ' '; - if ( !$this->smart ) - if ( $this->button_style != 'icon' ) + if ( ! $this->smart ) { + if ( $this->button_style != 'icon' ) { $text = $this->get_name(); + } + } - $klasses = array( 'share-'.$this->shortname ); + $klasses = array( 'share-' . $this->shortname ); - if ( $this->button_style == 'icon' || $this->button_style == 'icon-text' ) + if ( $this->button_style == 'icon' || $this->button_style == 'icon-text' ) { $klasses[] = 'share-icon'; + } if ( $this->button_style == 'icon' ) { $text = ''; $klasses[] = 'no-text'; } - if ( $this->button_style == 'text' ) + if ( $this->button_style == 'text' ) { $klasses[] = 'no-icon'; + } $link = sprintf( '<a rel="nofollow" class="%s" href="javascript:void(0)" title="%s"><span style="background-image:url("%s") !important;background-position:left center;background-repeat:no-repeat;">%s</span></a>', @@ -1349,10 +1390,11 @@ class Share_Tumblr extends Sharing_Source { public $genericon = '\f214'; public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); - if ( 'official' == $this->button_style ) + if ( 'official' == $this->button_style ) { $this->smart = true; - else + } else { $this->smart = false; + } } public function get_name() { @@ -1362,8 +1404,9 @@ class Share_Tumblr extends Sharing_Source { public function get_display( $post ) { if ( $this->smart ) { $target = ''; - if ( true == $this->open_link_in_new ) + if ( true == $this->open_link_in_new ) { $target = '_blank'; + } return '<a target="' . $target . '" href="https://www.tumblr.com/share/link/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&name=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '" title="' . __( 'Share on Tumblr', 'jetpack' ) . '" style="display:inline-block; text-indent:-9999px; overflow:hidden; width:62px; height:20px; background:url(\'https://platform.tumblr.com/v1/share_2.png\') top left no-repeat transparent;">' . __( 'Share on Tumblr', 'jetpack' ) . '</a>'; } else { @@ -1396,10 +1439,11 @@ class Share_Pinterest extends Sharing_Source { public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); - if ( 'official' == $this->button_style ) + if ( 'official' == $this->button_style ) { $this->smart = true; - else + } else { $this->smart = false; + } } public function get_name() { @@ -1481,7 +1525,7 @@ class Share_Pinterest extends Sharing_Source { // Record stats parent::process_request( $post, $post_data ); // If we're triggering the multi-select panel, then we don't need to redirect to Pinterest - if ( !isset( $_GET['js_only'] ) ) { + if ( ! isset( $_GET['js_only'] ) ) { $pinterest_url = esc_url_raw( $this->get_external_url( $post ) ); wp_redirect( $pinterest_url ); } else { @@ -1508,7 +1552,9 @@ class Share_Pinterest extends Sharing_Source { var s = document.createElement("script"); s.type = "text/javascript"; s.async = true; - <?php if ( $jetpack_pinit_over ) echo "s.setAttribute('data-pin-hover', true);"; ?> + <?php if ( $jetpack_pinit_over ) { + echo "s.setAttribute('data-pin-hover', true);"; + } ?> s.src = window.location.protocol + "//assets.pinterest.com/js/pinit.js"; var x = document.getElementsByTagName("script")[0]; x.parentNode.insertBefore(s, x); @@ -1546,10 +1592,11 @@ class Share_Pocket extends Sharing_Source { public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); - if ( 'official' == $this->button_style ) + if ( 'official' == $this->button_style ) { $this->smart = true; - else + } else { $this->smart = false; + } } public function get_name() { diff --git a/plugins/jetpack/modules/sharedaddy/sharing.js b/plugins/jetpack/modules/sharedaddy/sharing.js index dc1777c6..57bf81f9 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing.js +++ b/plugins/jetpack/modules/sharedaddy/sharing.js @@ -357,7 +357,7 @@ var updateLinkedInCount = function( data ) { $( '#sharing_email form a.sharing_cancel' ).show(); // Reset reCATPCHA if exists. - if ( 'object' === typeof grecaptcha && 'function' === typeof grecaptcha.reset ) { + if ( 'object' === typeof grecaptcha && 'function' === typeof grecaptcha.reset && window.___grecaptcha_cfg.count ) { grecaptcha.reset(); } diff --git a/plugins/jetpack/modules/sharedaddy/sharing.php b/plugins/jetpack/modules/sharedaddy/sharing.php index 2f69d5ad..b147b81a 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing.php +++ b/plugins/jetpack/modules/sharedaddy/sharing.php @@ -2,12 +2,12 @@ class Sharing_Admin { public function __construct() { - if ( !defined( 'WP_SHARING_PLUGIN_URL' ) ) { + if ( ! defined( 'WP_SHARING_PLUGIN_URL' ) ) { define( 'WP_SHARING_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'WP_SHARING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); } - require_once WP_SHARING_PLUGIN_DIR.'sharing-service.php'; + require_once WP_SHARING_PLUGIN_DIR . 'sharing-service.php'; add_action( 'admin_init', array( &$this, 'admin_init' ) ); add_action( 'admin_menu', array( &$this, 'subscription_menu' ) ); @@ -33,14 +33,14 @@ class Sharing_Admin { wp_enqueue_style( 'sharing', WP_SHARING_PLUGIN_URL . 'sharing.css', false, JETPACK__VERSION ); wp_enqueue_style( 'social-logos' ); - wp_enqueue_script( 'sharing-js-fe', WP_SHARING_PLUGIN_URL . 'sharing.js', array( ), 4 ); - + wp_enqueue_script( 'sharing-js-fe', WP_SHARING_PLUGIN_URL . 'sharing.js', array(), 4 ); add_thickbox(); } public function admin_init() { - if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'sharing.php' || $_GET['page'] == 'sharing' ) ) + if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'sharing.php' || $_GET['page'] == 'sharing' ) ) { $this->process_requests(); + } } public function process_requests() { @@ -62,10 +62,11 @@ class Sharing_Admin { } public function subscription_menu( $user ) { - if ( !defined( 'IS_WPCOM' ) || !IS_WPCOM ) { + if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) { $active = Jetpack::get_active_modules(); - if ( !in_array( 'publicize', $active ) && !current_user_can( 'manage_options' ) ) + if ( ! in_array( 'publicize', $active ) && ! current_user_can( 'manage_options' ) ) { return; + } } add_submenu_page( 'options-general.php', __( 'Sharing Settings', 'jetpack' ), __( 'Sharing', 'jetpack' ), 'publish_posts', 'sharing', array( &$this, 'management_page' ) ); @@ -98,14 +99,14 @@ class Sharing_Admin { } public function ajax_delete_service() { - if ( isset( $_POST['_wpnonce'] ) && isset( $_POST['service'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options_'.$_POST['service'] ) ) { + if ( isset( $_POST['_wpnonce'] ) && isset( $_POST['service'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options_' . $_POST['service'] ) ) { $sharer = new Sharing_Service(); $sharer->delete_service( $_POST['service'] ); } } public function ajax_save_options() { - if ( isset( $_POST['_wpnonce'] ) && isset( $_POST['service'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options_'.$_POST['service'] ) ) { + if ( isset( $_POST['_wpnonce'] ) && isset( $_POST['service'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options_' . $_POST['service'] ) ) { $sharer = new Sharing_Service(); $service = $sharer->get_service( $_POST['service'] ); @@ -127,14 +128,15 @@ class Sharing_Admin { $klasses = array( 'advanced', 'preview-item' ); if ( $service->button_style != 'text' || $service->has_custom_button_style() ) { - $klasses[] = 'preview-'.$service->get_class(); - $klasses[] = 'share-'.$service->get_class(); + $klasses[] = 'preview-' . $service->get_class(); + $klasses[] = 'share-' . $service->get_class(); - if ( $service->get_class() != $service->get_id() ) - $klasses[] = 'preview-'.$service->get_id(); + if ( $service->get_class() != $service->get_id() ) { + $klasses[] = 'preview-' . $service->get_id(); + } } - echo '<li class="'.implode( ' ', $klasses ).'">'; + echo '<li class="' . implode( ' ', $klasses ) . '">'; $service->display_preview(); echo '</li>'; } @@ -148,7 +150,7 @@ class Sharing_Admin { <form method="post" action="<?php echo admin_url( 'admin-ajax.php' ); ?>"> <input type="hidden" name="action" value="sharing_delete_service" /> <input type="hidden" name="service" value="<?php echo esc_attr( $id ); ?>" /> - <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options_'.$id );?>" /> + <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options_' . $id );?>" /> </form> <?php endif; ?> </li> @@ -156,22 +158,23 @@ class Sharing_Admin { } public function management_page() { - $sharer = new Sharing_Service(); + $sharer = new Sharing_Service(); $enabled = $sharer->get_blog_services(); - $global = $sharer->get_global_options(); + $global = $sharer->get_global_options(); $shows = array_values( get_post_types( array( 'public' => true ) ) ); array_unshift( $shows, 'index' ); if ( false == function_exists( 'mb_stripos' ) ) { echo '<div id="message" class="updated fade"><h3>' . __( 'Warning! Multibyte support missing!', 'jetpack' ) . '</h3>'; - echo "<p>" . sprintf( __( 'This plugin will work without it, but multibyte support is used <a href="%s" target="_blank">if available</a>. You may see minor problems with Tweets and other sharing services.', 'jetpack' ), "http://www.php.net/manual/en/mbstring.installation.php" ) . '</p></div>'; + echo '<p>' . sprintf( __( 'This plugin will work without it, but multibyte support is used <a href="%s" target="_blank">if available</a>. You may see minor problems with Tweets and other sharing services.', 'jetpack' ), 'http://www.php.net/manual/en/mbstring.installation.php' ) . '</p></div>'; } - if ( isset( $_GET['update'] ) && $_GET['update'] == 'saved' ) - echo '<div class="updated"><p>'.__( 'Settings have been saved', 'jetpack' ).'</p></div>'; + if ( isset( $_GET['update'] ) && $_GET['update'] == 'saved' ) { + echo '<div class="updated"><p>' . __( 'Settings have been saved', 'jetpack' ) . '</p></div>'; + } - if( ! isset( $global['sharing_label'] ) ) { + if ( ! isset( $global['sharing_label'] ) ) { $global['sharing_label'] = __( 'Share this:', 'jetpack' ); } ?> @@ -207,16 +210,18 @@ class Sharing_Admin { </td> <td class="services"> <ul class="services-available" style="height: 100px;"> - <?php foreach ( $sharer->get_all_services_blog() AS $id => $service ) : ?> + <?php foreach ( $sharer->get_all_services_blog() as $id => $service ) : ?> <?php - if ( !isset( $enabled['all'][$id] ) ) - $this->output_service( $id, $service ); + if ( ! isset( $enabled['all'][ $id ] ) ) { + $this->output_service( $id, $service ); + } ?> <?php endforeach; ?> </ul> <?php - if ( -1 == get_option( 'blog_public' ) ) - echo '<p><strong>'.__( 'Please note that your services have been restricted because your site is private.', 'jetpack' ).'</strong></p>'; + if ( -1 == get_option( 'blog_public' ) ) { + echo '<p><strong>' . __( 'Please note that your services have been restricted because your site is private.', 'jetpack' ) . '</strong></p>'; + } ?> <br class="clearing" /> </td> @@ -233,7 +238,7 @@ class Sharing_Admin { <p><?php _e( 'Services dragged here will appear individually.', 'jetpack' ); ?></p> </td> <td class="services" id="share-drop-target"> - <h2 id="drag-instructions" <?php if ( count( $enabled['visible'] ) > 0 ) echo ' style="display: none"'; ?>><?php _e( 'Drag and drop available services here.', 'jetpack' ); ?></h2> + <h2 id="drag-instructions" <?php if ( count( $enabled['visible'] ) > 0 ) { echo ' style="display: none"';} ?>><?php _e( 'Drag and drop available services here.', 'jetpack' ); ?></h2> <ul class="services-enabled"> <?php foreach ( $enabled['visible'] as $id => $service ) : ?> @@ -262,7 +267,7 @@ class Sharing_Admin { <h3><?php _e( 'Live Preview', 'jetpack' ); ?></h3> </td> <td class="services"> - <h2<?php if ( count( $enabled['all'] ) > 0 ) echo ' style="display: none"'; ?>><?php _e( 'Sharing is off. Add services above to enable.', 'jetpack' ); ?></h2> + <h2 <?php echo ( count( $enabled['all'] ) > 0 ) ? ' style="display: none"' : ''; ?>><?php _e( 'Sharing is off. Add services above to enable.', 'jetpack' ); ?></h2> <div class="sharedaddy sd-sharing-enabled"> <?php if ( count( $enabled['all'] ) > 0 ) : ?> <h3 class="sd-title"><?php echo esc_html( $global['sharing_label'] ); ?></h3> @@ -281,15 +286,17 @@ class Sharing_Admin { <?php if ( count( $enabled['hidden'] ) > 0 ) : ?> <div class="sharing-hidden"> <div class="inner" style="display: none; <?php echo count( $enabled['hidden'] ) == 1 ? 'width:150px;' : ''; ?>"> - <?php if ( count( $enabled['hidden'] ) == 1 ) : ?> - <ul style="background-image:none;"> - <?php else: ?> - <ul> - <?php endif; ?> - - <?php foreach ( $enabled['hidden'] as $id => $service ) { + <?php if ( count( $enabled['hidden'] ) == 1 ) : ?> + <ul style="background-image:none;"> + <?php else : ?> + <ul> + <?php endif; ?> + + <?php + foreach ( $enabled['hidden'] as $id => $service ) { $this->output_preview( $service ); - }?> + } + ?> </ul> </div> </div> @@ -297,15 +304,16 @@ class Sharing_Admin { <ul class="archive" style="display:none;"> <?php - foreach ( $sharer->get_all_services_blog() as $id => $service ) : - if ( isset( $enabled['visible'][$id] ) ) - $service = $enabled['visible'][$id]; - elseif ( isset( $enabled['hidden'][$id] ) ) - $service = $enabled['hidden'][$id]; - - $service->button_style = 'icon-text'; // The archive needs the full text, which is removed in JS later - $service->smart = false; - $this->output_preview( $service ); + foreach ( $sharer->get_all_services_blog() as $id => $service ) : + if ( isset( $enabled['visible'][ $id ] ) ) { + $service = $enabled['visible'][ $id ]; + } elseif ( isset( $enabled['hidden'][ $id ] ) ) { + $service = $enabled['hidden'][ $id ]; + } + + $service->button_style = 'icon-text'; // The archive needs the full text, which is removed in JS later + $service->smart = false; + $this->output_preview( $service ); endforeach; ?> <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php _e( 'More', 'jetpack' ); ?></span></a></li> </ul> @@ -331,10 +339,10 @@ class Sharing_Admin { <th scope="row"><label><?php _e( 'Button style', 'jetpack' ); ?></label></th> <td> <select name="button_style" id="button_style"> - <option<?php if ( $global['button_style'] == 'icon-text' ) echo ' selected="selected"';?> value="icon-text"><?php _e( 'Icon + text', 'jetpack' ); ?></option> - <option<?php if ( $global['button_style'] == 'icon' ) echo ' selected="selected"';?> value="icon"><?php _e( 'Icon only', 'jetpack' ); ?></option> - <option<?php if ( $global['button_style'] == 'text' ) echo ' selected="selected"';?> value="text"><?php _e( 'Text only', 'jetpack' ); ?></option> - <option<?php if ( $global['button_style'] == 'official' ) echo ' selected="selected"';?> value="official"><?php _e( 'Official buttons', 'jetpack' ); ?></option> + <option<?php echo ( $global['button_style'] == 'icon-text' ) ? ' selected="selected"' : ''; ?> value="icon-text"><?php _e( 'Icon + text', 'jetpack' ); ?></option> + <option<?php echo ( $global['button_style'] == 'icon' ) ? ' selected="selected"' : ''; ?> value="icon"><?php _e( 'Icon only', 'jetpack' ); ?></option> + <option<?php echo ( $global['button_style'] == 'text' ) ? ' selected="selected"' : ''; ?> value="text"><?php _e( 'Text only', 'jetpack' ); ?></option> + <option<?php echo ( $global['button_style'] == 'official' ) ? ' selected="selected"' : ''; ?> value="official"><?php _e( 'Official buttons', 'jetpack' ); ?></option> </select> </td> </tr> @@ -346,31 +354,39 @@ class Sharing_Admin { </tr> <?php /** - * Filters the HTML at the beginning of the "Show button on" row. - * - * @module sharedaddy - * - * @since 2.1.0 - * - * @param string $var Opening HTML tag at the beginning of the "Show button on" row. - */ + * Filters the HTML at the beginning of the "Show button on" row. + * + * @module sharedaddy + * + * @since 2.1.0 + * + * @param string $var Opening HTML tag at the beginning of the "Show button on" row. + */ echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' ); ?> <th scope="row"><label><?php _e( 'Show buttons on', 'jetpack' ); ?></label></th> - <td> - <?php - $br = false; - foreach ( $shows as $show ) : - if ( 'index' == $show ) { - $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' ); - } else { - $post_type_object = get_post_type_object( $show ); - $label = $post_type_object->labels->name; - } - ?> - <?php if ( $br ) echo '<br />'; ?><label><input type="checkbox"<?php checked( in_array( $show, $global['show'] ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label> - <?php $br = true; endforeach; ?> - </td> + <td> + <?php + $br = false; + foreach ( $shows as $show ) : + if ( 'index' == $show ) { + $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' ); + } else { + $post_type_object = get_post_type_object( $show ); + $label = $post_type_object->labels->name; + } + ?> + <?php + if ( $br ) { + echo '<br />'; + } + ?> + <label><input type="checkbox"<?php checked( in_array( $show, $global['show'] ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label> + <?php + $br = true; + endforeach; + ?> + </td> <?php /** * Filters the HTML at the end of the "Show button on" row. @@ -420,7 +436,7 @@ class Sharing_Admin { <input type="text" name="sharing_url" id="new_sharing_url" size="40" /> <p><?php _e( 'You can add the following variables to your service sharing URL:', 'jetpack' ); ?><br/> - <code>%post_title%</code>, <code>%post_url%</code>, <code>%post_full_url%</code>, <code>%post_excerpt%</code>, <code>%post_tags%</code></p> + <code>%post_id%</code>, <code>%post_title%</code>, <code>%post_slug%</code>, <code>%post_url%</code>, <code>%post_full_url%</code>, <code>%post_excerpt%</code>, <code>%post_tags%</code>, <code>%home_url%</code></p> </td> </tr> <tr valign="top"> @@ -445,7 +461,7 @@ class Sharing_Admin { * @module sharedaddy * * @since 1.1.0 - */ + */ do_action( 'sharing_new_service_form' ); ?> </tbody> @@ -478,7 +494,7 @@ class Sharing_Admin { </div> <script type="text/javascript"> - var sharing_loading_icon = '<?php echo esc_js( admin_url( "/images/loading.gif" ) ); ?>'; + var sharing_loading_icon = '<?php echo esc_js( admin_url( '/images/loading.gif' ) ); ?>'; <?php if ( isset( $_GET['create_new_service'] ) && 'true' == $_GET['create_new_service'] ) : ?> jQuery(document).ready(function() { // Prefill new service box and then open it |