diff options
Diffstat (limited to 'plugins/jetpack/modules/sharedaddy')
7 files changed, 72 insertions, 44 deletions
diff --git a/plugins/jetpack/modules/sharedaddy/admin-sharing.js b/plugins/jetpack/modules/sharedaddy/admin-sharing.js index 741931d1..e4834772 100644 --- a/plugins/jetpack/modules/sharedaddy/admin-sharing.js +++ b/plugins/jetpack/modules/sharedaddy/admin-sharing.js @@ -1,4 +1,3 @@ -/* jshint onevar: false, smarttabs: true */ /* global sharing_loading_icon */ ( function( $ ) { diff --git a/plugins/jetpack/modules/sharedaddy/sharedaddy.php b/plugins/jetpack/modules/sharedaddy/sharedaddy.php index 1e5de22c..82fe7af2 100644 --- a/plugins/jetpack/modules/sharedaddy/sharedaddy.php +++ b/plugins/jetpack/modules/sharedaddy/sharedaddy.php @@ -4,8 +4,8 @@ Plugin Name: Sharedaddy Description: The most super duper sharing tool on the interwebs. Version: 0.3.1 Author: Automattic, Inc. -Author URI: http://automattic.com/ -Plugin URI: http://en.blog.wordpress.com/2010/08/24/more-ways-to-share/ +Author URI: https://automattic.com/ +Plugin URI: https://en.blog.wordpress.com/2010/08/24/more-ways-to-share/ */ require_once plugin_dir_path( __FILE__ ).'sharing.php'; @@ -222,7 +222,7 @@ function sharing_plugin_settings( $links ) { function sharing_add_plugin_settings($links, $file) { if ( $file == basename( dirname( __FILE__ ) ).'/'.basename( __FILE__ ) ) { $links[] = '<a href="options-general.php?page=sharing.php">' . __( 'Settings', 'jetpack' ) . '</a>'; - $links[] = '<a href="http://support.wordpress.com/sharing/" rel="noopener noreferrer" target="_blank">' . __( 'Support', 'jetpack' ) . '</a>'; + $links[] = '<a href="https://support.wordpress.com/sharing/" rel="noopener noreferrer" target="_blank">' . __( 'Support', 'jetpack' ) . '</a>'; } return $links; diff --git a/plugins/jetpack/modules/sharedaddy/sharing-service.php b/plugins/jetpack/modules/sharedaddy/sharing-service.php index 7e453262..823dd94d 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing-service.php +++ b/plugins/jetpack/modules/sharedaddy/sharing-service.php @@ -1,5 +1,8 @@ <?php +use Automattic\Jetpack\Assets; +use Automattic\Jetpack\Sync\Settings; + include_once dirname( __FILE__ ) . '/sharing-sources.php'; define( 'WP_SHARING_PLUGIN_VERSION', JETPACK__VERSION ); @@ -219,7 +222,10 @@ class Sharing_Service { // Default services if ( ! is_array( $enabled ) ) { $enabled = array( - 'visible' => array(), + 'visible' => array( + 'twitter', + 'facebook', + ), 'hidden' => array(), ); @@ -303,17 +309,17 @@ class Sharing_Service { public function set_global_options( $data ) { $options = get_option( 'sharing-options' ); - // No options yet + // No options yet. if ( ! is_array( $options ) ) { $options = array(); } - // Defaults + // Defaults. $options['global'] = array( 'button_style' => 'icon-text', 'sharing_label' => $this->default_sharing_label, 'open_links' => 'same', - 'show' => array(), + 'show' => ! isset( $options['global'] ) ? array( 'post', 'page' ) : array(), 'custom' => isset( $options['global']['custom'] ) ? $options['global']['custom'] : array(), ); @@ -378,7 +384,7 @@ class Sharing_Service { if ( is_array( $options ) && isset( $options['global'] ) && is_array( $options['global'] ) ) { $this->global = $options['global']; } else { - $this->global = $this->set_global_options( $options['global'] ); + $this->global = $this->set_global_options( $options ); } } @@ -663,11 +669,18 @@ function sharing_process_requests() { } add_action( 'template_redirect', 'sharing_process_requests', 9 ); +/** + * Append sharing links to text. + * + * @param string $text The original text to append sharing links onto. + * @param bool $echo Where to echo the text or return. + * + * @return string The original $text with, if conditions are met, the sharing links. + */ function sharing_display( $text = '', $echo = false ) { global $post, $wp_current_filter; - require_once JETPACK__PLUGIN_DIR . '/sync/class.jetpack-sync-settings.php'; - if ( Jetpack_Sync_Settings::is_syncing() ) { + if ( Settings::is_syncing() ) { return $text; } @@ -679,15 +692,15 @@ function sharing_display( $text = '', $echo = false ) { return $text; } - // Don't output flair on excerpts - if ( in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) { + // Don't output flair on excerpts. + if ( in_array( 'get_the_excerpt', (array) $wp_current_filter, true ) ) { return $text; } - // Don't allow flair to be added to the_content more than once (prevent infinite loops) + // Don't allow flair to be added to the_content more than once (prevent infinite loops). $done = false; foreach ( $wp_current_filter as $filter ) { - if ( 'the_content' == $filter ) { + if ( 'the_content' === $filter ) { if ( $done ) { return $text; } else { @@ -696,15 +709,19 @@ function sharing_display( $text = '', $echo = false ) { } } - // check whether we are viewing the front page and whether the front page option is checked + // check whether we are viewing the front page and whether the front page option is checked. $options = get_option( 'sharing-options' ); - $display_options = $options['global']['show']; + $display_options = null; - if ( is_front_page() && ( is_array( $display_options ) && ! in_array( 'index', $display_options ) ) ) { + if ( is_array( $options ) ) { + $display_options = $options['global']['show']; + } + + if ( is_front_page() && ( is_array( $display_options ) && ! in_array( 'index', $display_options, true ) ) ) { return $text; } - if ( is_attachment() && in_array( 'the_excerpt', (array) $wp_current_filter ) ) { + if ( is_attachment() && in_array( 'the_excerpt', (array) $wp_current_filter, true ) ) { // Many themes run the_excerpt() conditionally on an attachment page, then run the_content(). // We only want to output the sharing buttons once. Let's stick with the_content(). return $text; @@ -715,9 +732,9 @@ function sharing_display( $text = '', $echo = false ) { $show = false; if ( ! is_feed() ) { - if ( is_singular() && in_array( get_post_type(), $global['show'] ) ) { + if ( is_singular() && in_array( get_post_type(), $global['show'], true ) ) { $show = true; - } elseif ( in_array( 'index', $global['show'] ) && ( is_home() || is_front_page() || is_archive() || is_search() || in_array( get_post_type(), $global['show'] ) ) ) { + } elseif ( in_array( 'index', $global['show'], true ) && ( is_home() || is_front_page() || is_archive() || is_search() || in_array( get_post_type(), $global['show'], true ) ) ) { $show = true; } } @@ -741,7 +758,7 @@ function sharing_display( $text = '', $echo = false ) { $show = false; } - // Private post? + // Is the post private? $post_status = get_post_status( $post->ID ); if ( 'private' === $post_status ) { @@ -786,13 +803,11 @@ function sharing_display( $text = '', $echo = false ) { $enabled = apply_filters( 'sharing_enabled', $sharer->get_blog_services() ); if ( count( $enabled['all'] ) > 0 ) { - global $post; - $dir = get_option( 'text_direction' ); - // Wrapper + // Wrapper. $sharing_content .= '<div class="sharedaddy sd-sharing-enabled"><div class="robots-nocontent sd-block sd-social sd-social-' . $global['button_style'] . ' sd-sharing">'; - if ( $global['sharing_label'] != '' ) { + if ( '' !== $global['sharing_label'] ) { $sharing_content .= sprintf( /** * Filter the sharing buttons' headline structure. @@ -811,7 +826,7 @@ function sharing_display( $text = '', $echo = false ) { } $sharing_content .= '<div class="sd-content"><ul>'; - // Visible items + // Visible items. $visible = ''; foreach ( $enabled['visible'] as $id => $service ) { $klasses = array( 'share-' . $service->get_class() ); @@ -821,7 +836,7 @@ function sharing_display( $text = '', $echo = false ) { } $klasses[] = 'share-deprecated'; } - // Individual HTML for sharing service + // Individual HTML for sharing service. $visible .= '<li class="' . implode( ' ', $klasses ) . '">' . $service->get_display( $post ) . '</li>'; } @@ -836,7 +851,7 @@ function sharing_display( $text = '', $echo = false ) { $parts[] = '<li><a href="#" class="sharing-anchor sd-button share-more"><span>' . $expand . '</span></a></li>'; } - if ( $dir == 'rtl' ) { + if ( 'rtl' === $dir ) { $parts = array_reverse( $parts ); } @@ -846,13 +861,13 @@ function sharing_display( $text = '', $echo = false ) { if ( count( $enabled['hidden'] ) > 0 ) { $sharing_content .= '<div class="sharing-hidden"><div class="inner" style="display: none;'; - if ( count( $enabled['hidden'] ) == 1 ) { + if ( count( $enabled['hidden'] ) === 1 ) { $sharing_content .= 'width:150px;'; } $sharing_content .= '">'; - if ( count( $enabled['hidden'] ) == 1 ) { + if ( count( $enabled['hidden'] ) === 1 ) { $sharing_content .= '<ul style="background-image:none;">'; } else { $sharing_content .= '<ul>'; @@ -860,7 +875,7 @@ function sharing_display( $text = '', $echo = false ) { $count = 1; foreach ( $enabled['hidden'] as $id => $service ) { - // Individual HTML for sharing service + // Individual HTML for sharing service. $klasses = array( 'share-' . $service->get_class() ); if ( $service->is_deprecated() ) { if ( ! current_user_can( 'manage_options' ) ) { @@ -872,36 +887,39 @@ function sharing_display( $text = '', $echo = false ) { $sharing_content .= $service->get_display( $post ); $sharing_content .= '</li>'; - if ( ( $count % 2 ) == 0 ) { + if ( ( $count % 2 ) === 0 ) { $sharing_content .= '<li class="share-end"></li>'; } $count ++; } - // End of wrapper + // End of wrapper. $sharing_content .= '<li class="share-end"></li></ul></div></div>'; } $sharing_content .= '</div></div></div>'; - // Register our JS + // Register our JS. if ( defined( 'JETPACK__VERSION' ) ) { $ver = JETPACK__VERSION; } else { $ver = '20141212'; } + + // @todo: Investigate if we can load this JS in the footer instead. wp_register_script( 'sharing-js', - Jetpack::get_file_url_for_environment( + Assets::get_file_url_for_environment( '_inc/build/sharedaddy/sharing.min.js', 'modules/sharedaddy/sharing.js' ), array( 'jquery' ), - $ver + $ver, + false ); - // Enqueue scripts for the footer + // Enqueue scripts for the footer. add_action( 'wp_footer', 'sharing_add_footer' ); } } diff --git a/plugins/jetpack/modules/sharedaddy/sharing-sources.php b/plugins/jetpack/modules/sharedaddy/sharing-sources.php index 0cc0ec59..d9954a96 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing-sources.php +++ b/plugins/jetpack/modules/sharedaddy/sharing-sources.php @@ -1701,7 +1701,15 @@ class Jetpack_Share_WhatsApp extends Sharing_Source { public function process_request( $post, array $post_data ) { // Record stats parent::process_request( $post, $post_data ); - $url = 'https://api.whatsapp.com/send?text=' . rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) ); + + // Firefox for desktop doesn't handle the "api.whatsapp.com" URL properly, so use "web.whatsapp.com" + if ( Jetpack_User_Agent_Info::is_firefox_desktop() ) { + $url = 'https://web.whatsapp.com/send?text='; + } else { + $url = 'https://api.whatsapp.com/send?text='; + } + + $url .= rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) ); wp_redirect( $url ); exit; } diff --git a/plugins/jetpack/modules/sharedaddy/sharing.css b/plugins/jetpack/modules/sharedaddy/sharing.css index 7481f416..2ada890d 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing.css +++ b/plugins/jetpack/modules/sharedaddy/sharing.css @@ -89,7 +89,7 @@ body.highlander-dark h3.sd-title:before { font-family: "Open Sans", sans-serif; font-weight: normal; border-radius: 3px; - color: #545454 !important; + color: #656565 !important; background: #f8f8f8; border: 1px solid #cccccc; box-shadow: 0 1px 0 rgba(0,0,0,.08); @@ -599,7 +599,7 @@ body .sd-social-icon .sd-content li.share-custom a span { } .sd-social-icon .sd-content ul li[class*='share-'].share-facebook a.sd-button { - background: #3b5998; + background: #1877F2; color: #fff !important; } diff --git a/plugins/jetpack/modules/sharedaddy/sharing.js b/plugins/jetpack/modules/sharedaddy/sharing.js index dcaf0f11..bd027e9e 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing.js +++ b/plugins/jetpack/modules/sharedaddy/sharing.js @@ -1,5 +1,4 @@ /* global WPCOM_sharing_counts, grecaptcha */ -/* jshint unused:false */ var sharing_js_options; if ( sharing_js_options && sharing_js_options.counts ) { var WPCOMSharing = { diff --git a/plugins/jetpack/modules/sharedaddy/sharing.php b/plugins/jetpack/modules/sharedaddy/sharing.php index 49df892b..805dc172 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing.php +++ b/plugins/jetpack/modules/sharedaddy/sharing.php @@ -1,10 +1,14 @@ <?php + +use Automattic\Jetpack\Assets; + 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() { require_once WP_SHARING_PLUGIN_DIR . 'sharing-service.php'; @@ -24,7 +28,7 @@ class Sharing_Admin { public function sharing_head() { wp_enqueue_script( 'sharing-js', - Jetpack::get_file_url_for_environment( + Assets::get_file_url_for_environment( '_inc/build/sharedaddy/admin-sharing.min.js', 'modules/sharedaddy/admin-sharing.js' ), @@ -210,7 +214,7 @@ class Sharing_Admin { 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" rel="noopener noreferrer" 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" rel="noopener noreferrer" target="_blank">if available</a>. You may see minor problems with Tweets and other sharing services.', 'jetpack' ), 'https://www.php.net/manual/en/mbstring.installation.php' ) . '</p></div>'; } if ( isset( $_GET['update'] ) && $_GET['update'] == 'saved' ) { |