diff options
Diffstat (limited to 'plugins/jetpack/modules/sharedaddy')
-rw-r--r-- | plugins/jetpack/modules/sharedaddy/recaptcha.php | 9 | ||||
-rw-r--r-- | plugins/jetpack/modules/sharedaddy/sharing-service.php | 31 | ||||
-rw-r--r-- | plugins/jetpack/modules/sharedaddy/sharing-sources.php | 93 | ||||
-rw-r--r-- | plugins/jetpack/modules/sharedaddy/sharing.js | 12 | ||||
-rw-r--r-- | plugins/jetpack/modules/sharedaddy/sharing.php | 24 |
5 files changed, 111 insertions, 58 deletions
diff --git a/plugins/jetpack/modules/sharedaddy/recaptcha.php b/plugins/jetpack/modules/sharedaddy/recaptcha.php index 3e4fc915..58ae6563 100644 --- a/plugins/jetpack/modules/sharedaddy/recaptcha.php +++ b/plugins/jetpack/modules/sharedaddy/recaptcha.php @@ -61,6 +61,7 @@ class Jetpack_ReCaptcha { 'invalid-input-response' => __( 'The response parameter is invalid or malformed', 'jetpack' ), 'invalid-json' => __( 'Invalid JSON', 'jetpack' ), 'unexpected-response' => __( 'Unexpected response', 'jetpack' ), + 'unexpected-hostname' => __( 'Unexpected hostname', 'jetpack' ), ); } @@ -128,6 +129,14 @@ class Jetpack_ReCaptcha { return new WP_Error( $error_code, $error_message ); } + // Validate the hostname matches expected source + if ( isset( $resp_decoded['hostname'] ) ) { + $url = wp_parse_url( get_home_url() ); + if ( $url['host'] !== $resp_decoded['hostname'] ) { + return new WP_Error( 'unexpected-host', $this->error_codes['unexpected-hostname'] ); + } + } + return true; } diff --git a/plugins/jetpack/modules/sharedaddy/sharing-service.php b/plugins/jetpack/modules/sharedaddy/sharing-service.php index 2a056991..86e3cc20 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing-service.php +++ b/plugins/jetpack/modules/sharedaddy/sharing-service.php @@ -221,8 +221,17 @@ class Sharing_Service { } // Cleanup after any filters that may have produced duplicate services - $enabled['visible'] = array_unique( $enabled['visible'] ); - $enabled['hidden'] = array_unique( $enabled['hidden'] ); + if ( is_array( $enabled['visible'] ) ) { + $enabled['visible'] = array_unique( $enabled['visible'] ); + } else { + $enabled['visible'] = array(); + } + + if ( is_array( $enabled['hidden'] ) ) { + $enabled['hidden'] = array_unique( $enabled['hidden'] ); + } else { + $enabled['hidden'] = array(); + } // Form the enabled services $blog = array( 'visible' => array(), 'hidden' => array() ); @@ -230,7 +239,10 @@ class Sharing_Service { foreach ( $blog AS $area => $stuff ) { foreach ( (array)$enabled[$area] AS $service ) { if ( isset( $services[$service] ) ) { - $blog[$area][$service] = new $services[$service]( $service, array_merge( $global, isset( $options[$service] ) ? $options[$service] : array() ) ); + if ( ! isset( $options[ $service ] ) || ! is_array( $options[ $service ] ) ) { + $options[ $service ] = array(); + } + $blog[ $area ][ $service ] = new $services[ $service ]( $service, array_merge( $global, $options[ $service ] ) ); } } } @@ -339,10 +351,11 @@ class Sharing_Service { if ( $this->global === false ) { $options = get_option( 'sharing-options' ); - if ( is_array( $options ) && isset( $options['global'] ) ) + if ( is_array( $options ) && isset( $options['global'] ) && is_array( $options['global'] ) ) { $this->global = $options['global']; - else + } else { $this->global = $this->set_global_options( $options['global'] ); + } } if ( ! isset( $this->global['show'] ) ) { @@ -676,8 +689,9 @@ function sharing_display( $text = '', $echo = false ) { // Disabled for this post? $switched_status = get_post_meta( $post->ID, 'sharing_disabled', false ); - if ( !empty( $switched_status ) ) + if ( !empty( $switched_status ) ) { $show = false; + } // Private post? $post_status = get_post_status( $post->ID ); @@ -691,6 +705,7 @@ function sharing_display( $text = '', $echo = false ) { $show = true; $sharing_content = ''; + $enabled = false; if ( $show ) { /** @@ -812,10 +827,12 @@ function sharing_display( $text = '', $echo = false ) { * @module sharedaddy * * @since 3.8.0 + * @since 6.2.0 Started sending $enabled as a second parameter. * * @param string $sharing_content Content markup of the Jetpack sharing links + * @param array $enabled Array of Sharing Services currently enabled. */ - $sharing_markup = apply_filters( 'jetpack_sharing_display_markup', $sharing_content ); + $sharing_markup = apply_filters( 'jetpack_sharing_display_markup', $sharing_content, $enabled ); if ( $echo ) echo $text . $sharing_markup; diff --git a/plugins/jetpack/modules/sharedaddy/sharing-sources.php b/plugins/jetpack/modules/sharedaddy/sharing-sources.php index 679449e1..6df9b210 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing-sources.php +++ b/plugins/jetpack/modules/sharedaddy/sharing-sources.php @@ -367,10 +367,9 @@ abstract class Sharing_Advanced_Source extends Sharing_Source { abstract public function get_options(); } - class Share_Email extends Sharing_Source { public $shortname = 'email'; - public $genericon = '\f410'; + public $icon = '\f410'; public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); @@ -554,7 +553,7 @@ class Share_Email extends Sharing_Source { class Share_Twitter extends Sharing_Source { public $shortname = 'twitter'; - public $genericon = '\f202'; + public $icon = '\f202'; // 'https://dev.twitter.com/rest/reference/get/help/configuration' ( 2015/02/06 ) short_url_length is 22, short_url_length_https is 23 public $short_url_length = 24; @@ -572,7 +571,14 @@ class Share_Twitter extends Sharing_Source { return __( 'Twitter', 'jetpack' ); } - function sharing_twitter_via( $post ) { + /** + * Determine the Twitter 'via' value for a post. + * + * @param WP_Post|int $post Post object or post ID. + * @return string Twitter handle without the preceding @. + **/ + public static function sharing_twitter_via( $post ) { + $post = get_post( $post ); /** * Allow third-party plugins to customize the Twitter username used as "twitter:site" Twitter Card Meta Tag. * @@ -611,7 +617,14 @@ class Share_Twitter extends Sharing_Source { return preg_replace( '/[^\da-z_]+/i', '', $twitter_site_tag_value ); } - public function get_related_accounts( $post ) { + /** + * Determine the 'related' Twitter accounts for a post. + * + * @param WP_Post|int $post Post object or post ID. + * @return string Comma-separated list of Twitter handles. + **/ + public static function get_related_accounts( $post ) { + $post = get_post( $post ); /** * Filter the list of related Twitter accounts added to the Twitter sharing button. * @@ -752,7 +765,7 @@ class Share_Twitter extends Sharing_Source { class Share_Reddit extends Sharing_Source { public $shortname = 'reddit'; - public $genericon = '\f222'; + public $icon = '\f222'; public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); @@ -789,7 +802,7 @@ class Share_Reddit extends Sharing_Source { class Share_LinkedIn extends Sharing_Source { public $shortname = 'linkedin'; - public $genericon = '\f207'; + public $icon = '\f207'; public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); @@ -865,7 +878,7 @@ class Share_LinkedIn extends Sharing_Source { class Share_Facebook extends Sharing_Source { public $shortname = 'facebook'; - public $genericon = '\f204'; + public $icon = '\f204'; private $share_type = 'default'; public function __construct( $id, array $settings ) { @@ -1000,7 +1013,7 @@ class Share_Facebook extends Sharing_Source { class Share_Print extends Sharing_Source { public $shortname = 'print'; - public $genericon = '\f469'; + public $icon = '\f469'; public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); @@ -1022,7 +1035,7 @@ class Share_Print extends Sharing_Source { class Share_PressThis extends Sharing_Source { public $shortname = 'pressthis'; - public $genericon = '\f205'; + public $icon = '\f205'; public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); @@ -1098,7 +1111,7 @@ class Share_PressThis extends Sharing_Source { class Share_GooglePlus1 extends Sharing_Source { public $shortname = 'googleplus1'; - public $genericon = '\f218'; + public $icon = '\f218'; private $state = false; public function __construct( $id, array $settings ) { @@ -1269,11 +1282,12 @@ class Share_Custom extends Sharing_Advanced_Source { $tagged = ''; if ( $tags ) { + $tagged_raw = array(); foreach ( $tags as $tag ) { - $tagged[] = rawurlencode( $tag->name ); + $tagged_raw[] = rawurlencode( $tag->name ); } - $tagged = implode( ',', $tagged ); + $tagged = implode( ',', $tagged_raw ); } $url = str_replace( '%post_tags%', $tagged, $url ); @@ -1399,7 +1413,7 @@ class Share_Custom extends Sharing_Advanced_Source { class Share_Tumblr extends Sharing_Source { public $shortname = 'tumblr'; - public $genericon = '\f214'; + public $icon = '\f214'; public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); if ( 'official' == $this->button_style ) { @@ -1447,7 +1461,7 @@ class Share_Tumblr extends Sharing_Source { class Share_Pinterest extends Sharing_Source { public $shortname = 'pinterest'; - public $genericon = '\f209'; + public $icon = '\f209'; public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); @@ -1599,7 +1613,7 @@ class Share_Pinterest extends Sharing_Source { class Share_Pocket extends Sharing_Source { public $shortname = 'pocket'; - public $genericon = '\f224'; + public $icon = '\f224'; public function __construct( $id, array $settings ) { parent::__construct( $id, $settings ); @@ -1699,13 +1713,13 @@ class Jetpack_Share_WhatsApp extends Sharing_Source { } public function get_display( $post ) { - return $this->get_link( 'https://api.whatsapp.com/send?text=' . rawurlencode( $this->get_share_title( $post->ID ) ) . ' ' . rawurlencode( $this->get_share_url( $post->ID ) ), _x( 'WhatsApp', 'share to', 'jetpack' ), __( 'Click to share on WhatsApp', 'jetpack' ) ); + return $this->get_link( 'https://api.whatsapp.com/send?text=' . rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) ), _x( 'WhatsApp', 'share to', 'jetpack' ), __( 'Click to share on WhatsApp', 'jetpack' ) ); } } class Share_Skype extends Sharing_Source { public $shortname = 'skype'; - public $genericon = '\f220'; + public $icon = '\f220'; private $share_type = 'default'; public function __construct( $id, array $settings ) { @@ -1720,6 +1734,7 @@ class Share_Skype extends Sharing_Source { } else { $this->smart = false; } + } public function get_name() { @@ -1741,7 +1756,7 @@ class Share_Skype extends Sharing_Source { sharing_register_post_for_share_counts( $post->ID ); } return $this->get_link( - $this->get_process_request_url( $post->ID ), _x( 'Skype', 'share to', 'jetpack' ), __( 'Share on Skype', 'jetpack' ), 'share=skype', 'sharing-skype-' . $post->ID ); + $this->get_process_request_url( $post->ID ), _x( 'Skype', 'share to', 'jetpack' ), __( 'Click to share on Skype', 'jetpack' ), 'share=skype', 'sharing-skype-' . $post->ID ); } public function process_request( $post, array $post_data ) { @@ -1761,26 +1776,26 @@ class Share_Skype extends Sharing_Source { public function display_footer() { if ( $this->smart ) : - ?> - <script> - (function(r, d, s) { - r.loadSkypeWebSdkAsync = r.loadSkypeWebSdkAsync || function(p) { - var js, sjs = d.getElementsByTagName(s)[0]; - if (d.getElementById(p.id)) { return; } - js = d.createElement(s); - js.id = p.id; - js.src = p.scriptToLoad; - js.onload = p.callback - sjs.parentNode.insertBefore(js, sjs); - }; - var p = { - scriptToLoad: 'https://swx.cdn.skype.com/shared/v/latest/skypewebsdk.js', - id: 'skype_web_sdk' - }; - r.loadSkypeWebSdkAsync(p); - })(window, document, 'script'); - </script> - <?php + ?> + <script> + (function(r, d, s) { + r.loadSkypeWebSdkAsync = r.loadSkypeWebSdkAsync || function(p) { + var js, sjs = d.getElementsByTagName(s)[0]; + if (d.getElementById(p.id)) { return; } + js = d.createElement(s); + js.id = p.id; + js.src = p.scriptToLoad; + js.onload = p.callback + sjs.parentNode.insertBefore(js, sjs); + }; + var p = { + scriptToLoad: 'https://swx.cdn.skype.com/shared/v/latest/skypewebsdk.js', + id: 'skype_web_sdk' + }; + r.loadSkypeWebSdkAsync(p); + })(window, document, 'script'); + </script> + <?php else : $this->js_dialog( $this->shortname, array( 'width' => 305, 'height' => 665 ) ); endif; diff --git a/plugins/jetpack/modules/sharedaddy/sharing.js b/plugins/jetpack/modules/sharedaddy/sharing.js index fd7d47b9..9d8d5c5d 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing.js +++ b/plugins/jetpack/modules/sharedaddy/sharing.js @@ -22,14 +22,14 @@ if ( sharing_js_options && sharing_js_options.counts ) { // Pinterest handles share counts for both http and https pinterest: [ window.location.protocol + - '//api.pinterest.com/v1/urls/count.json?callback=WPCOMSharing.update_pinterest_count&url=' + - encodeURIComponent( url ) + '//api.pinterest.com/v1/urls/count.json?callback=WPCOMSharing.update_pinterest_count&url=' + + encodeURIComponent( url ) ], // Facebook protocol summing has been shown to falsely double counts, so we only request the current URL facebook: [ window.location.protocol + - '//graph.facebook.com/?callback=WPCOMSharing.update_facebook_count&ids=' + - encodeURIComponent( url ) + '//graph.facebook.com/?callback=WPCOMSharing.update_facebook_count&ids=' + + encodeURIComponent( url ) ] }; @@ -333,6 +333,10 @@ if ( sharing_js_options && sharing_js_options.counts ) { // Email button $( 'a.share-email', this ).on( 'click', function() { var url = $( this ).attr( 'href' ); + var currentDomain = window.location.protocol + '//' + window.location.hostname + '/'; + if ( url.indexOf( currentDomain ) !== 0 ) { + return true; + } if ( $sharing_email.is( ':visible' ) ) { $sharing_email.slideUp( 200 ); diff --git a/plugins/jetpack/modules/sharedaddy/sharing.php b/plugins/jetpack/modules/sharedaddy/sharing.php index f6a6bebd..c6f57436 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing.php +++ b/plugins/jetpack/modules/sharedaddy/sharing.php @@ -1,12 +1,11 @@ <?php +if ( ! defined( 'WP_SHARING_PLUGIN_URL' ) ) { + define( 'WP_SHARING_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); + define( 'WP_SHARING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); +} class Sharing_Admin { public function __construct() { - 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'; add_action( 'admin_init', array( &$this, 'admin_init' ) ); @@ -32,7 +31,16 @@ class Sharing_Admin { array( 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-form' ), 2 ); - $postfix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; + + /** + * Filters the switch that if set to true allows Jetpack to use minified assets. Defaults to true + * if the SCRIPT_DEBUG constant is not set or set to false. The filter overrides it. + * + * @since 6.2.0 + * + * @param boolean $var should Jetpack use minified assets. + */ + $postfix = apply_filters( 'jetpack_should_use_minified_assets', true ) ? '.min' : ''; if ( is_rtl() ) { wp_enqueue_style( 'sharing-admin', WP_SHARING_PLUGIN_URL . 'admin-sharing-rtl' . $postfix . '.css', false, JETPACK__VERSION ); } else { @@ -422,7 +430,7 @@ class Sharing_Admin { </table> <p class="submit"> - <input type="submit" name="submit" class="button-primary" value="<?php _e( 'Save Changes', 'jetpack' ); ?>" /> + <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" /> </p> <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options' );?>" /> @@ -457,7 +465,7 @@ class Sharing_Admin { <tr valign="top" width="100"> <th scope="row"></th> <td> - <input type="submit" class="button-primary" value="<?php _e( 'Create Share Button', 'jetpack' ); ?>" /> + <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Create Share Button', 'jetpack' ); ?>" /> <img src="<?php echo admin_url( 'images/loading.gif' ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" /> </td> </tr> |