diff options
Diffstat (limited to 'plugins/jetpack/modules/likes.php')
-rw-r--r-- | plugins/jetpack/modules/likes.php | 523 |
1 files changed, 234 insertions, 289 deletions
diff --git a/plugins/jetpack/modules/likes.php b/plugins/jetpack/modules/likes.php index 24e83ae2..e9bd71c5 100644 --- a/plugins/jetpack/modules/likes.php +++ b/plugins/jetpack/modules/likes.php @@ -1,14 +1,24 @@ <?php /** * Module Name: Likes - * Module Description: Likes are a way for people to show their appreciation for content you have written. It’s also a way for you to show the world how popular your content has become. + * Module Description: Give visitors an easy way to show their appreciation for your content. * First Introduced: 2.2 - * Sort Order: 4 + * Sort Order: 23 * Requires Connection: Yes * Auto Activate: No + * Module Tags: Social */ + +Jetpack::dns_prefetch( array( + '//widgets.wp.com', + '//s0.wp.com', + '//0.gravatar.com', + '//1.gravatar.com', + '//2.gravatar.com', +) ); + class Jetpack_Likes { - var $version = '20130620a'; + var $version = '20141028'; public static function init() { static $instance = NULL; @@ -27,6 +37,7 @@ class Jetpack_Likes { add_action( 'admin_init', array( $this, 'admin_init' ) ); if ( $this->in_jetpack ) { + add_action( 'jetpack_activate_module_likes', array( $this, 'maybe_sync_content' ) ); add_action( 'jetpack_activate_module_likes', array( $this, 'module_toggle' ) ); add_action( 'jetpack_deactivate_module_likes', array( $this, 'module_toggle' ) ); @@ -60,6 +71,7 @@ class Jetpack_Likes { Jetpack_Sync::sync_options( __FILE__, 'social_notifications_like' ); } else { // wpcom + add_action( 'wpmu_new_blog', array( $this, 'enable_comment_likes' ), 10, 1 ); add_action( 'admin_init', array( $this, 'add_meta_box' ) ); add_action( 'end_likes_meta_box_content', array( $this, 'sharing_meta_box_content' ) ); add_filter( 'likes_meta_box_title', array( $this, 'add_likes_to_sharing_meta_box_title' ) ); @@ -69,11 +81,20 @@ class Jetpack_Likes { add_action( 'admin_bar_menu', array( $this, 'admin_bar_likes' ), 60 ); + add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_register_scripts' ) ); + add_action( 'save_post', array( $this, 'meta_box_save' ) ); + add_action( 'edit_attachment', array( $this, 'meta_box_save' ) ); add_action( 'sharing_global_options', array( $this, 'admin_settings_init' ), 20 ); add_action( 'sharing_admin_update', array( $this, 'admin_settings_callback' ), 20 ); } + function maybe_sync_content() { + if ( Jetpack::init()->sync->reindex_needed() ) { + Jetpack::init()->sync->reindex_trigger(); + } + } + function module_toggle() { $jetpack = Jetpack::init(); $jetpack->sync->register( 'noop' ); @@ -91,7 +112,19 @@ class Jetpack_Likes { * Loads Jetpack's CSS on the sharing page so we can use .jetpack-targetable */ function load_jp_css() { - Jetpack::init()->admin_styles(); + // Do we really need `admin_styles`? With the new admin UI, it's breaking some bits. + // Jetpack::init()->admin_styles(); + } + /** + * Load style on the front end. + * @return null + */ + function load_styles_register_scripts() { + + wp_enqueue_style( 'jetpack_likes', plugins_url( 'likes/style.css', __FILE__ ), array(), JETPACK__VERSION ); + if( $this->in_jetpack ) { + $this->register_scripts(); + } } /** @@ -130,10 +163,13 @@ class Jetpack_Likes { if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; + if ( empty( $_POST['wpl_like_status_hidden'] ) ) + return $post_id; + // Record sharing disable. Only needs to be done for WPCOM if ( ! $this->in_jetpack ) { - if ( isset( $_POST['post_type'] ) && ( 'post' == $_POST['post_type'] || 'page' == $_POST['post_type'] ) ) { - if ( isset( $_POST['wpl_sharing_status_hidden'] ) && !isset( $_POST['wpl_enable_post_sharing'] ) ) { + if ( isset( $_POST['post_type'] ) && in_array( $_POST['post_type'], get_post_types( array( 'public' => true ) ) ) ) { + if ( ! isset( $_POST['wpl_enable_post_sharing'] ) ) { update_post_meta( $post_id, 'sharing_disabled', 1 ); } else { delete_post_meta( $post_id, 'sharing_disabled' ); @@ -141,9 +177,6 @@ class Jetpack_Likes { } } - if ( empty( $_POST['wpl_like_status_hidden'] ) ) - return $post_id; - if ( 'post' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_post', $post_id ) ) { return $post_id; @@ -154,7 +187,7 @@ class Jetpack_Likes { // site like setting. if ( ( $this->is_enabled_sitewide() && empty( $_POST['wpl_enable_post_likes'] ) ) || ( ! $this->is_enabled_sitewide() && !empty( $_POST['wpl_enable_post_likes'] ) ) ) { update_post_meta( $post_id, 'switch_like_status', 1 ); - //$g_gif = file_get_contents( 'http://stats.wordpress.com/g.gif?v=wpcom-no-pv&x_likes=switched_post_like_status' ); @todo stat + //$g_gif = file_get_contents( 'http://pixel.wp.com/g.gif?v=wpcom-no-pv&x_likes=switched_post_like_status' ); @todo stat } else { delete_post_meta( $post_id, 'switch_like_status' ); } @@ -237,9 +270,9 @@ class Jetpack_Likes { function admin_likes_get_option( $option ) { if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { - $option_setting = get_blog_option( get_current_blog_id(), $option ); + $option_setting = get_blog_option( get_current_blog_id(), $option, 'on' ); } else { - $option_setting = get_option( $option ); + $option_setting = get_option( $option, 'on' ); } return intval( 'on' == $option_setting ); @@ -283,20 +316,41 @@ class Jetpack_Likes { </label> <div> </td> - </tr> <?php /* + </tr> + <?php if ( ! $this->in_jetpack ) : ?> + <tr> + <th scope="row"> + <label><?php esc_html_e( 'WordPress.com Reblog Button', 'jetpack' ); ?></label> + </th> + <td> + <div> + <label> + <input type="radio" class="code" name="jetpack_reblogs_enabled" value="on" <?php checked( $this->reblogs_enabled_sitewide(), true ); ?> /> + <?php esc_html_e( 'Show the Reblog button on posts', 'jetpack' ); ?> + </label> + </div> + <div> + <label> + <input type="radio" class="code" name="jetpack_reblogs_enabled" value="off" <?php checked( $this->reblogs_enabled_sitewide(), false ); ?> /> + <?php esc_html_e( 'Don\'t show the Reblog button on posts', 'jetpack' ); ?> + </label> + <div> + </td> + </tr> <tr> <th scope="row"> - <label><?php esc_html_e( 'Comment Likes', 'jetpack' ); ?></label> + <label><?php esc_html_e( 'Comment Likes are', 'jetpack' ); ?></label> </th> <td> <div> <label> <input type="checkbox" class="code" name="jetpack_comment_likes_enabled" value="1" <?php checked( $this->is_comments_enabled(), true ); ?> /> - <?php esc_html_e( 'Allow people to like comments', 'jetpack' ); ?> + <?php esc_html_e( 'On for all comments', 'jetpack' ); ?> </label> </div> </td> - </tr> */ ?> + </tr> + <?php endif; ?> </tbody> <?php // closes the tbody attached to sharing_show_buttons_on_row_start... ?> <?php } @@ -370,6 +424,7 @@ class Jetpack_Likes { function process_update_requests_if_sharedaddy_not_loaded() { if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'sharing.php' || $_GET['page'] == 'sharing' ) ) { if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options' ) ) { + /** This action is documented in modules/sharedaddy/sharing.php */ do_action( 'sharing_admin_update' ); wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) ); die(); @@ -386,25 +441,42 @@ class Jetpack_Likes { $new_state = !empty( $_POST['wpl_default'] ) ? $_POST['wpl_default'] : 'on'; $db_state = $this->is_enabled_sitewide(); + $reblogs_new_state = !empty( $_POST['jetpack_reblogs_enabled'] ) ? $_POST['jetpack_reblogs_enabled'] : 'on'; + $reblogs_db_state = $this->reblogs_enabled_sitewide(); /** Default State *********************************************************/ // Checked (enabled) switch( $new_state ) { case 'off' : if ( true == $db_state && ! $this->in_jetpack ) { - $g_gif = file_get_contents( 'http://stats.wordpress.com/g.gif?v=wpcom-no-pv&x_likes=disabled_likes' ); + $g_gif = file_get_contents( 'http://pixel.wp.com/g.gif?v=wpcom-no-pv&x_likes=disabled_likes' ); } update_option( 'disabled_likes', 1 ); break; case 'on' : default: if ( false == $db_state && ! $this->in_jetpack ) { - $g_gif = file_get_contents( 'http://stats.wordpress.com/g.gif?v=wpcom-no-pv&x_likes=reenabled_likes' ); + $g_gif = file_get_contents( 'http://pixel.wp.com/g.gif?v=wpcom-no-pv&x_likes=reenabled_likes' ); } delete_option( 'disabled_likes' ); break; } + switch( $reblogs_new_state ) { + case 'off' : + if ( true == $reblogs_db_state && ! $this->in_jetpack ) { + $g_gif = file_get_contents( 'http://pixel.wp.com/g.gif?v=wpcom-no-pv&x_reblogs=disabled_reblogs' ); + } + update_option( 'disabled_reblogs', 1 ); + break; + case 'on' : + default: + if ( false == $reblogs_db_state && ! $this->in_jetpack ) { + $g_gif = file_get_contents( 'http://pixel.wp.com/g.gif?v=wpcom-no-pv&x_reblogs=reenabled_reblogs' ); + } + delete_option( 'disabled_reblogs' ); + break; + } // comment setting $new_comments_state = !empty( $_POST['jetpack_comment_likes_enabled'] ) ? $_POST['jetpack_comment_likes_enabled'] : false; @@ -420,6 +492,16 @@ class Jetpack_Likes { } /** + * Force comment likes on for a blog + * Used when a new blog is created + */ + function enable_comment_likes( $blog_id ) { + switch_to_blog( $blog_id ); + update_option( 'jetpack_comment_likes_enabled', 1 ); + restore_current_blog(); + } + + /** * Adds the 'sharing' menu to the settings menu. * Only ran if sharedaddy and publicize are not already active. */ @@ -458,7 +540,10 @@ class Jetpack_Likes { <form method="post" action=""> <table class="form-table"> <tbody> - <?php do_action( 'sharing_global_options' ); ?> + <?php + /** This action is documented in modules/sharedaddy/sharing.php */ + do_action( 'sharing_global_options' ); + ?> </tbody> </table> @@ -477,28 +562,31 @@ class Jetpack_Likes { add_action( 'manage_pages_custom_column', array( $this, 'likes_edit_column' ), 10, 2 ); add_action( 'admin_print_styles-edit.php', array( $this, 'load_admin_css' ) ); add_action( "admin_print_scripts-edit.php", array( $this, 'enqueue_admin_scripts' ) ); + + if ( $this->in_jetpack ) { + Jetpack_Sync::sync_posts( __FILE__ ); + } } function action_init() { - if ( is_admin() ) + if ( is_admin() ) { return; + } if ( ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) || ( defined( 'APP_REQUEST' ) && APP_REQUEST ) || ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) || ( defined( 'COOKIE_AUTH_REQUEST' ) && COOKIE_AUTH_REQUEST ) || - ( defined( 'JABBER_SERVER' ) && JABBER_SERVER ) ) + ( defined( 'JABBER_SERVER' ) && JABBER_SERVER ) ) { return; + } // Comment Likes widget has been disabled, pending performance improvements. // add_filter( 'comment_text', array( &$this, 'comment_likes' ), 10, 2 ); if ( $this->in_jetpack ) { add_filter( 'the_content', array( &$this, 'post_likes' ), 30, 1 ); - wp_enqueue_script( 'postmessage', plugins_url( '_inc/postmessage.js', dirname(__FILE__) ), array( 'jquery' ), JETPACK__VERSION, false ); - wp_enqueue_script( 'jquery_inview', plugins_url( '_inc/jquery.inview.js', dirname(__FILE__) ), array( 'jquery' ), JETPACK__VERSION, false ); - wp_enqueue_script( 'jetpack_resize', plugins_url( '_inc/jquery.jetpack-resize.js' , dirname(__FILE__) ), array( 'jquery' ), JETPACK__VERSION, false ); - wp_enqueue_style( 'jetpack_likes', plugins_url( 'likes/style.css', __FILE__ ), array(), JETPACK__VERSION ); + add_filter( 'the_excerpt', array( &$this, 'post_likes' ), 30, 1 ); } else { add_filter( 'post_flair', array( &$this, 'post_likes' ), 30, 1 ); @@ -507,26 +595,55 @@ class Jetpack_Likes { wp_enqueue_script( 'postmessage', '/wp-content/js/postmessage.js', array( 'jquery' ), JETPACK__VERSION, false ); wp_enqueue_script( 'jquery_inview', '/wp-content/js/jquery/jquery.inview.js', array( 'jquery' ), JETPACK__VERSION, false ); wp_enqueue_script( 'jetpack_resize', '/wp-content/js/jquery/jquery.jetpack-resize.js', array( 'jquery' ), JETPACK__VERSION, false ); - wp_enqueue_style( 'jetpack_likes', plugins_url( 'jetpack-likes.css', __FILE__ ), array(), JETPACK__VERSION ); + + + // @todo: Remove this opt-out filter in the future + if ( apply_filters( 'wpl_sharing_2014_1', true ) ) { + wp_enqueue_style( 'jetpack_likes', plugins_url( 'jetpack-likes.css', __FILE__ ), array(), JETPACK__VERSION ); + } else { + wp_enqueue_style( 'jetpack_likes', plugins_url( 'jetpack-likes-legacy.css', __FILE__ ), array(), JETPACK__VERSION ); + } } } /** + * Register scripts + */ + function register_scripts() { + // Lets register all the sciprts + wp_register_script( 'postmessage', plugins_url( '_inc/postmessage.js', dirname(__FILE__) ), array( 'jquery' ), JETPACK__VERSION, false ); + wp_register_script( 'jquery_inview', plugins_url( '_inc/jquery.inview.js', dirname(__FILE__) ), array( 'jquery' ), JETPACK__VERSION, false ); + wp_register_script( 'jetpack_resize', plugins_url( '_inc/jquery.jetpack-resize.js' , dirname(__FILE__) ), array( 'jquery' ), JETPACK__VERSION, false ); + wp_register_script( 'jetpack_likes_queuehandler', plugins_url( 'likes/queuehandler.js' , __FILE__ ), array( 'jquery', 'postmessage', 'jetpack_resize', 'jquery_inview' ), JETPACK__VERSION, true ); + } + + /** * Load the CSS needed for the wp-admin area. */ - function load_admin_css() { ?> + function load_admin_css() { + ?> <style type="text/css"> .fixed .column-likes { width: 5em; padding-top: 8px; text-align: center !important; } .fixed .column-stats { width: 5em; } .fixed .column-likes .post-com-count { background-image: none; } - .fixed .column-likes .comment-count { background-color: #888; } - .fixed .column-likes .comment-count:hover { background-color: #D54E21; } - .mp6 .fixed .column-likes .post-com-count::after { border: none !important; } - .mp6 .fixed .column-likes .comment-count { background-color: #bbb; } - .mp6 .fixed .column-likes .comment-count:hover { background-color: #2ea2cc; } - .mp6 .fixed .column-likes .vers img { display: none; } - .mp6 .fixed .column-likes .vers:before {font:20px/1 dashicons;content: '\f155';-webkit-font-smoothing:antialiased;} - </style> <?php + .fixed .column-likes .post-com-count::after { border: none !important; } + .fixed .column-likes .comment-count { background-color: #bbb; } + .fixed .column-likes .comment-count:hover { background-color: #2ea2cc; } + .fixed .column-likes .vers img { display: none; } + .fixed .column-likes .vers:before { + font: normal 20px/1 dashicons; + content: '\f155'; + speak: none; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + } + @media screen and (max-width: 782px) { + .fixed .column-likes { + display: none; + } + } + </style> + <?php } /** @@ -600,8 +717,8 @@ class Jetpack_Likes { $url_parts = parse_url( $url ); $domain = $url_parts['host']; } - - add_filter( 'wp_footer', array( $this, 'likes_master' ) ); + // make sure to include the scripts before the iframe otherwise weird things happen + add_action( 'wp_footer', array( $this, 'likes_master' ), 21 ); /** * if the same post appears more then once on a page the page goes crazy @@ -614,10 +731,13 @@ class Jetpack_Likes { $wrapper = sprintf( 'like-post-wrapper-%1$d-%2$d-%3$s', $blog_id, $post->ID, $uniqid ); $html = "<div class='sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='$wrapper' data-src='$src' data-name='$name'><h3 class='sd-title'>" . esc_html__( 'Like this:', 'jetpack' ) . '</h3>'; - $html .= "<div class='post-likes-widget-placeholder' style='height:55px'><span class='button'><span>" . esc_html__( 'Like', 'jetpack' ) . '</span></span> <span class="loading">' . esc_html__( 'Loading...', 'jetpack' ) . '</span></div>'; + $html .= "<div class='likes-widget-placeholder post-likes-widget-placeholder' style='height:55px'><span class='button'><span>" . esc_html__( 'Like', 'jetpack' ) . '</span></span> <span class="loading">' . esc_html__( 'Loading...', 'jetpack' ) . '</span></div>'; $html .= "<span class='sd-text-color'></span><a class='sd-link-color'></a>"; $html .= '</div>'; + // Lets make sure that the script is enqued + wp_enqueue_script( 'jetpack_likes_queuehandler' ); + return $content . $html; } @@ -642,8 +762,8 @@ class Jetpack_Likes { $url_parts = parse_url( $url ); $domain = $url_parts['host']; } - - add_filter( 'wp_footer', array( $this, 'likes_master' ) ); + // make sure to include the scripts before the iframe otherwise weird things happen + add_action( 'wp_footer', array( $this, 'likes_master' ), 21 ); $src = sprintf( '%1$s://widgets.wp.com/likes/#blog_id=%2$d&comment_id=%3$d&origin=%1$s://%4$s', $protocol, $blog_id, $comment->comment_ID, $domain ); $name = sprintf( 'like-comment-frame-%1$d-%2$d', $blog_id, $comment->comment_ID ); @@ -681,9 +801,9 @@ class Jetpack_Likes { $url_parts = parse_url( $url ); $domain = $url_parts['host']; } + // make sure to include the scripts before the iframe otherwise weird things happen + add_action( 'wp_footer', array( $this, 'likes_master' ), 21 ); - add_filter( 'wp_footer', array( $this, 'likes_master' ) ); - $src = sprintf( '%1$s://widgets.wp.com/likes/#blog_id=%2$d&post_id=%3$d&origin=%1$s://%4$s', $protocol, $blog_id, $post->ID, $domain ); $html = "<iframe class='admin-bar-likes-widget jetpack-likes-widget' scrolling='no' frameBorder='0' name='admin-bar-likes-widget' src='$src'></iframe>"; @@ -698,233 +818,47 @@ class Jetpack_Likes { $wp_admin_bar->add_node( $node ); } + /** + * This function needs to get loaded after the scripts get added to the page. + * + */ function likes_master() { $protocol = 'http'; if ( is_ssl() ) $protocol = 'https'; - $locale = ( '' == get_locale() || 'en' == get_locale() ) ? '' : '&lang=' . strtolower( substr( get_locale(), 0, 2 ) ); - $src = sprintf( '%1$s://widgets.wp.com/likes/master.html?ver=%2$s#ver=%2$s%3$s&mp6=%4$d', $protocol, $this->version, $locale, apply_filters( 'mp6_enabled', 0 ) ); - - $likersText = wp_kses( __( '<span>%d</span> bloggers like this:', 'jetpack' ), array( 'span' => array() ) ); -?> - <iframe src='<?php echo $src; ?>' scrolling='no' id='likes-master' name='likes-master' style='display:none;'></iframe> - <div id='likes-other-gravatars'><div class="likes-text"><?php echo $likersText; ?></div><ul class="wpl-avatars sd-like-gravatars"></ul></div> - <script type="text/javascript"> - //<![CDATA[ - var jetpackLikesWidgetQueue = []; - var jetpackLikesMasterReady = false; - - function JetpackLikespostMessage( message, target ) { - if ( "string" === typeof message ){ - try{ - message = JSON.parse( message ); - } - catch(e) { - return; - } - } - - pm( { - target: target, - type: 'likesMessage', - data: message, - origin: '*' - } ); - } - - function JetpackLikesMessageListener( event ) { - if ( "undefined" == typeof event.event ) - return; - - if ( 'masterReady' == event.event ) { - jQuery( document ).ready( function() { - jetpackLikesMasterReady = true; - - var stylesData = { - event: 'injectStyles' - }; - - if ( jQuery( 'iframe.admin-bar-likes-widget' ).length > 0 ) { - JetpackLikespostMessage( { event: 'adminBarEnabled' }, window.frames[ 'likes-master' ] ); - - stylesData.adminBarStyles = { - background: jQuery( '#wpadminbar .quicklinks li#wp-admin-bar-wpl-like > a' ).css( 'background' ) - }; - } - - if ( !window.addEventListener ) - jQuery( '#wp-admin-bar-admin-bar-likes-widget' ).hide(); - - stylesData.textStyles = { - color: jQuery( '.sd-text-color').css( 'color' ), - fontFamily: jQuery( '.sd-text-color' ).css( 'font-family' ), - fontSize: jQuery( '.sd-text-color' ).css( 'font-size' ), - direction: jQuery( '.sd-text-color' ).css( 'direction' ), - fontWeight: jQuery( '.sd-text-color' ).css( 'font-weight' ), - fontStyle: jQuery( '.sd-text-color' ).css( 'font-style' ), - textDecoration: jQuery( '.sd-text-color' ).css('text-decoration') - }; - - stylesData.linkStyles = { - color: jQuery( '.sd-link-color' ).css('color'), - fontFamily: jQuery( '.sd-link-color' ).css('font-family'), - fontSize: jQuery( '.sd-link-color' ).css('font-size'), - textDecoration: jQuery( '.sd-link-color' ).css('text-decoration'), - fontWeight: jQuery( '.sd-link-color' ).css( 'font-weight' ), - fontStyle: jQuery( '.sd-link-color' ).css( 'font-style' ) - }; - - JetpackLikespostMessage( stylesData, window.frames[ 'likes-master' ] ); - - var requests = []; - jQuery( '.jetpack-likes-widget-wrapper' ).each( function( i ) { - var regex = /like-(post|comment)-wrapper-(\d+)-(\d+)-(\w+)/; - var match = regex.exec( this.id ); - if ( ! match || match.length != 5 ) - return; - - var info = { - blog_id: match[2], - width: this.width - }; - - if ( 'post' == match[1] ) { - info.post_id = match[3]; - } else if ( 'comment' == match[1] ) { - info.comment_id = match[3]; - } - - info.obj_id = match[4]; - - requests.push( info ); - }); - - JetpackLikespostMessage( { event: 'initialBatch', requests: requests }, window.frames['likes-master'] ); - - jQuery( document ).on( 'inview', 'div.jetpack-likes-widget-unloaded', function() { - jetpackLikesWidgetQueue.push( this.id ); - }); - }); - } - - if ( 'showLikeWidget' == event.event ) { - setTimeout( JetpackLikesWidgetQueueHandler, 10 ); - jQuery( '#' + event.id + ' .post-likes-widget-placeholder' ).fadeOut( 'fast', function() { - jQuery( '#' + event.id + ' .post-likes-widget' ).fadeIn( 'fast', function() { - JetpackLikespostMessage( { event: 'likeWidgetDisplayed', blog_id: event.blog_id, post_id: event.post_id, obj_id: event.obj_id }, window.frames['likes-master'] ); - }); - }); - } - - if ( 'showOtherGravatars' == event.event ) { - var $container = jQuery( '#likes-other-gravatars' ); - var $list = $container.find( 'ul' ); - - $container.hide(); - $list.html( '' ); - - $container.find( '.likes-text span' ).text( event.total ); - - jQuery.each( event.likers, function( i, liker ) { - $list.append( '<li class="' + liker.css_class + '"><a href="' + liker.profile_URL + '" class="wpl-liker" rel="nofollow" target="_parent"><img src="' + liker.avatar_URL + '" alt="' + liker.name + '" width="30" height="30" style="padding-right: 3px;" /></a></li>'); - } ); - - var offset = jQuery( "[name='" + event.parent + "']" ).offset(); - - $container.css( 'left', offset.left + event.position.left - 10 + 'px' ); - $container.css( 'top', offset.top + event.position.top - 33 + 'px' ); - - var rowLength = Math.floor( event.width / 37 ); - var height = ( Math.ceil( event.likers.length / rowLength ) * 37 ) + 13; - if ( height > 204 ) { - height = 204; - } - - $container.css( 'height', height + 'px' ); - $container.css( 'width', rowLength * 37 - 7 + 'px' ); - - $list.css( 'width', rowLength * 37 + 'px' ); + if ( version_compare( $GLOBALS['wp_version'], '3.8-alpha', '>=' ) ) { + add_filter( 'mp6_enabled', '__return_true', 97 ); + } - $container.fadeIn( 'slow' ); + $_locale = get_locale(); - var scrollbarWidth = $list[0].offsetWidth - $list[0].clientWidth; - if ( scrollbarWidth > 0 ) { - $container.width( $container.width() + scrollbarWidth ); - $list.width( $list.width() + scrollbarWidth ); - } - } + // We have to account for WP.org vs WP.com locale divergence + if ( $this->in_jetpack ) { + if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { + return false; } - pm.bind( 'likesMessage', function(e) { JetpackLikesMessageListener(e); } ); - - jQuery( document ).click( function( e ) { - var $container = jQuery( '#likes-other-gravatars' ); - - if ( $container.has( e.target ).length === 0 ) { - $container.fadeOut( 'slow' ); - } - }); - - function JetpackLikesWidgetQueueHandler() { - var wrapperID; - if ( ! jetpackLikesMasterReady ) { - setTimeout( JetpackLikesWidgetQueueHandler, 500 ); - return; - } + require_once JETPACK__GLOTPRESS_LOCALES_PATH; - if ( jetpackLikesWidgetQueue.length > 0 ) { - // We may have a widget that needs creating now - var found = false; - while( jetpackLikesWidgetQueue.length > 0 ) { - // Grab the first member of the queue that isn't already loading. - wrapperID = jetpackLikesWidgetQueue.splice( 0, 1 )[0]; - if ( jQuery( '#' + wrapperID ).hasClass( 'jetpack-likes-widget-unloaded' ) ) { - found = true; - break; - } - } - if ( ! found ) { - setTimeout( JetpackLikesWidgetQueueHandler, 500 ); - return; - } - } else if ( jQuery( 'div.jetpack-likes-widget-unloaded' ).length > 0 ) { - // Get the next unloaded widget - wrapperID = jQuery( 'div.jetpack-likes-widget-unloaded' ).first()[0].id; - if ( ! wrapperID ) { - // Everything is currently loaded - setTimeout( JetpackLikesWidgetQueueHandler, 500 ); - return; - } - } - - var $wrapper = jQuery( '#' + wrapperID ); - $wrapper.find( 'iframe' ).remove(); - - if ( $wrapper.hasClass( 'slim-likes-widget' ) ) { - $wrapper.find( '.post-likes-widget-placeholder' ).after( "<iframe class='post-likes-widget jetpack-likes-widget' name='" + $wrapper.data( 'name' ) + "' height='22px' width='68px' frameBorder='0' scrolling='no' src='" + $wrapper.data( 'src' ) + "'></iframe>" ); - } else { - $wrapper.find( '.post-likes-widget-placeholder' ).after( "<iframe class='post-likes-widget jetpack-likes-widget' name='" + $wrapper.data( 'name' ) + "' height='55px' width='100%' frameBorder='0' src='" + $wrapper.data( 'src' ) + "'></iframe>" ); - } - - $wrapper.removeClass( 'jetpack-likes-widget-unloaded' ).addClass( 'jetpack-likes-widget-loading' ); + $gp_locale = GP_Locales::by_field( 'wp_locale', $_locale ); + $_locale = isset( $gp_locale->slug ) ? $gp_locale->slug : ''; + } - $wrapper.find( 'iframe' ).load( function( e ) { - var $iframe = jQuery( e.target ); - $wrapper.removeClass( 'jetpack-likes-widget-loading' ).addClass( 'jetpack-likes-widget-loaded' ); + $likes_locale = ( '' == $_locale || 'en' == $_locale ) ? '' : '&lang=' . strtolower( $_locale ); - JetpackLikespostMessage( { event: 'loadLikeWidget', name: $iframe.attr( 'name' ), width: $iframe.width() }, window.frames[ 'likes-master' ] ); + // @todo: Remove this opt-out filter in the future + if ( apply_filters( 'wpl_sharing_2014_1', true ) ) { + $src = sprintf( '%1$s://widgets.wp.com/likes/master.html?ver=%2$s#ver=%2$s%3$s&mp6=%4$d', $protocol, $this->version, $likes_locale, apply_filters( 'mp6_enabled', 0 ) ); + } else { + $src = sprintf( '%1$s://widgets.wp.com/likes/master-legacy.html?ver=%2$s#ver=%2$s%3$s&mp6=%4$d', $protocol, $this->version, $likes_locale, apply_filters( 'mp6_enabled', 0 ) ); + } - if ( $wrapper.hasClass( 'slim-likes-widget' ) ) { - $wrapper.find( 'iframe' ).Jetpack( 'resizeable' ); - } - }); - setTimeout( JetpackLikesWidgetQueueHandler, 250 ); - } - JetpackLikesWidgetQueueHandler(); - //]]> - </script> -<?php + $likersText = wp_kses( __( '<span>%d</span> bloggers like this:', 'jetpack' ), array( 'span' => array() ) ); + ?> + <iframe src='<?php echo $src; ?>' scrolling='no' id='likes-master' name='likes-master' style='display:none;'></iframe> + <div id='likes-other-gravatars'><div class="likes-text"><?php echo $likersText; ?></div><ul class="wpl-avatars sd-like-gravatars"></ul></div> + <?php } /** @@ -972,7 +906,6 @@ class Jetpack_Likes { */ function is_likes_visible() { - global $wp_current_filter; // Used to check 'get_the_excerpt' filter global $post; // Used to apply 'sharing_show' filter // Never show on feeds or previews @@ -993,45 +926,46 @@ class Jetpack_Likes { if ( post_password_required() ) $enabled = false; - /** Other Checks ******************************************************/ - - // Do not show on excerpts - if ( in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) { - $enabled = false; - // Sharing Setting Overrides **************************************** - } else { - // Single post - if ( is_singular( 'post' ) ) { - if ( ! $this->is_single_post_enabled() ) { - $enabled = false; - } - // Single page - } elseif ( is_page() ) { - if ( ! $this->is_single_page_enabled() ) { - $enabled = false; - } + // Single post including custom post types + if ( is_single() ) { + if ( ! $this->is_single_post_enabled( $post->post_type ) ) { + $enabled = false; + } - // Attachment - } elseif ( is_attachment() ) { - if ( ! $this->is_attachment_enabled() ) { - $enabled = false; - } + // Single page + } elseif ( is_page() ) { + if ( ! $this->is_single_page_enabled() ) { + $enabled = false; + } - // All other loops - } elseif ( ! $this->is_index_enabled() ) { + // Attachment + } elseif ( is_attachment() ) { + if ( ! $this->is_attachment_enabled() ) { $enabled = false; } + + // All other loops + } elseif ( ! $this->is_index_enabled() ) { + $enabled = false; } } - // Check that the post is a public, published post. - if ( 'publish' != $post->post_status ) { - $enabled = false; + if( is_object( $post ) ) { + // Check that the post is a public, published post. + if ( 'attachment' == $post->post_type ) { + $post_status = get_post_status( $post->post_parent ); + } else { + $post_status = $post->post_status; + } + if ( 'publish' != $post_status ) { + $enabled = false; + } } // Run through the sharing filters + /** This filter is documented in modules/sharedaddy/sharing-service.php */ $enabled = apply_filters( 'sharing_show', $enabled, $post ); return (bool) apply_filters( 'wpl_is_likes_visible', $enabled ); @@ -1046,12 +980,20 @@ class Jetpack_Likes { } /** - * Returns if comment likes are enabled. Defaults to 'on' + * Returns the current state of the "WordPress.com Reblogs are" option. + * @return boolean true if enabled sitewide, false if not + */ + function reblogs_enabled_sitewide() { + return (bool) apply_filters( 'wpl_reblogging_enabled_sitewide', ! get_option( 'disabled_reblogs' ) ); + } + + /** + * Returns if comment likes are enabled. Defaults to 'off' * @todo decide what the default should be * @return boolean true if we should show comment likes, false if not */ function is_comments_enabled() { - return (bool) apply_filters( 'jetpack_comment_likes_enabled', get_option( 'jetpack_comment_likes_enabled', true ) ); + return (bool) apply_filters( 'jetpack_comment_likes_enabled', get_option( 'jetpack_comment_likes_enabled', false ) ); } function is_admin_bar_button_visible() { @@ -1108,11 +1050,15 @@ class Jetpack_Likes { /** * Are Post Likes enabled on single posts? * + * @param String $post_type custom post type identifier * @return bool */ - function is_single_post_enabled() { + function is_single_post_enabled( $post_type = 'post' ) { $options = $this->get_options(); - return (bool) apply_filters( 'wpl_is_single_post_disabled', (bool) in_array( 'post', $options['show'] ) ); + return (bool) apply_filters( + "wpl_is_single_{$post_type}_disabled", + (bool) in_array( $post_type, $options['show'] ) + ); } /** @@ -1134,7 +1080,6 @@ class Jetpack_Likes { $options = $this->get_options(); return (bool) apply_filters( 'wpl_is_attachment_disabled', (bool) in_array( 'attachment', $options['show'] ) ); } - } Jetpack_Likes::init(); |