diff options
author | Theo Chatzimichos <tampakrap@gentoo.org> | 2012-07-07 12:47:25 +0200 |
---|---|---|
committer | Theo Chatzimichos <tampakrap@gentoo.org> | 2012-07-07 12:47:25 +0200 |
commit | 0f7f96bbe0a5de9b8b88c846369e0f5395bb99bd (patch) | |
tree | 8b304e08e4636ff29b721adb4c1a2ccf1e886cb7 /plugins/jetpack/modules | |
parent | New module jetpack, replacement of wp-stats (diff) | |
download | blogs-gentoo-0f7f96bbe0a5de9b8b88c846369e0f5395bb99bd.tar.gz blogs-gentoo-0f7f96bbe0a5de9b8b88c846369e0f5395bb99bd.tar.bz2 blogs-gentoo-0f7f96bbe0a5de9b8b88c846369e0f5395bb99bd.zip |
Update jetpack
Diffstat (limited to 'plugins/jetpack/modules')
28 files changed, 1691 insertions, 437 deletions
diff --git a/plugins/jetpack/modules/after-the-deadline.php b/plugins/jetpack/modules/after-the-deadline.php index f634be02..31feef26 100644 --- a/plugins/jetpack/modules/after-the-deadline.php +++ b/plugins/jetpack/modules/after-the-deadline.php @@ -2,7 +2,7 @@ /** * Module Name: Spelling and Grammar * Module Description: Improve your spelling, style, and grammar with the <a href="http://www.afterthedeadline.com/">After the Deadline</a> Proofreading service. - * Sort Order: 1 + * Sort Order: 7 * First Introduced: 1.1 */ diff --git a/plugins/jetpack/modules/after-the-deadline/atd-autoproofread.js b/plugins/jetpack/modules/after-the-deadline/atd-autoproofread.js index 4a135bdf..b76a757c 100644 --- a/plugins/jetpack/modules/after-the-deadline/atd-autoproofread.js +++ b/plugins/jetpack/modules/after-the-deadline/atd-autoproofread.js @@ -8,10 +8,11 @@ function AtD_submit_check( e ) { return; /* Let's not submit the form, shall we? */ + e.stopImmediatePropagation(); e.preventDefault(); /* We'll call the AtD function based on which editor is currently active */ - if (typeof(tinyMCE) != 'undefined' && tinyMCE.activeEditor != null && tinyMCE.activeEditor.isHidden() == false) { + if ( typeof(tinyMCE) != 'undefined' && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden() ) { /* Woo! We're running tinyMCE! */ tinyMCE.activeEditor.execCommand('mceWritingImprovementTool', AtD_submit_check_callback); } else { @@ -23,6 +24,7 @@ function AtD_submit_check( e ) { /* This is the callback function that runs after the publish/update button is pressed */ function AtD_submit_check_callback(count) { + count = count || 0; AtD_unbind_proofreader_listeners(); if ( 0 == count || 1 < AtD_proofread_click_count ) { @@ -57,33 +59,26 @@ function AtD_submit_check_callback(count) { /* Stop the proofreader from doing its auto proofread thing (activated when the proofread button is clicked) */ function AtD_kill_autoproofread() { - jQuery('#publish').unbind('click', AtD_submit_check); + jQuery('#publish').unbind('click.AtD_submit_check'); } /* a function to force the post to be submitted */ function AtD_update_post() { - if ( typeof(tinyMCE) == 'undefined' || tinyMCE.activeEditor == null || tinyMCE.activeEditor.isHidden() ) + if ( typeof(tinyMCE) == 'undefined' || !tinyMCE.activeEditor || tinyMCE.activeEditor.isHidden() ) AtD_restore_if_proofreading(); - jQuery('#publish') - .unbind('click', AtD_submit_check) - .click() // we're using click() because doing a form submit causes posts to not publish. I couldn't trace back the the cause :/ - ; + jQuery('#publish').unbind('click.AtD_submit_check').click(); } /* init the autoproofread options */ -function atd_auto_proofread_init() { - var original_post_status = jQuery('#original_post_status').val(); +jQuery( document ).ready( function($){ + var orig_status = $('#original_post_status').val(); - /* check if auto-check is enabled && if #content exists */ - if ( typeof AtD_check_when != 'undefined' && ((original_post_status != 'publish' && AtD_check_when.onpublish) || ((original_post_status == 'publish' || original_post_status == 'schedule') && AtD_check_when.onupdate)) && jQuery('#content').length != 0 ) - jQuery('#publish').click( AtD_submit_check ); -} - -/* document.ready() does not execute in IE6 unless it's at the bottom of the page. oi! */ -if (navigator.appName == 'Microsoft Internet Explorer') - setTimeout( atd_auto_proofread_init, 2500 ); -else - jQuery( document ).ready( atd_auto_proofread_init ); + /* check if auto-check is enabled && if #content exists */ + if ( typeof AtD_check_when != 'undefined' && $('#content').length + && ( ( orig_status != 'publish' && AtD_check_when.onpublish ) + || ( ( orig_status == 'publish' || orig_status == 'schedule' ) && AtD_check_when.onupdate ) ) ) + $('#publish').bind( 'click.AtD_submit_check', AtD_submit_check ); +}); diff --git a/plugins/jetpack/modules/after-the-deadline/atd-nonvis-editor-plugin.js b/plugins/jetpack/modules/after-the-deadline/atd-nonvis-editor-plugin.js index dde4eab2..5d84497d 100644 --- a/plugins/jetpack/modules/after-the-deadline/atd-nonvis-editor-plugin.js +++ b/plugins/jetpack/modules/after-the-deadline/atd-nonvis-editor-plugin.js @@ -6,27 +6,26 @@ function AtD_restore_text_area() AtD.remove('content'); /* swap the preview div for the textarea, notice how I have to restore the appropriate class/id/style attributes */ + var content = jQuery('#content').html(); - var content; - - if (navigator.appName == 'Microsoft Internet Explorer') - content = jQuery('#content').html().replace(/<BR.*?class.*?atd_remove_me.*?>/gi, "\n"); - else - content = jQuery('#content').html(); + if ( navigator.appName == 'Microsoft Internet Explorer' ) + content = content.replace(/<BR.*?class.*?atd_remove_me.*?>/gi, "\n"); jQuery('#content').replaceWith( AtD.content_canvas ); jQuery('#content').val( content.replace(/\<\;/g, '<').replace(/\>\;/g, '>').replace(/\&/g, '&') ); jQuery('#content').height(AtD.height); - /* change the link text back to its original label */ - jQuery(AtD_qtbutton).val( AtD.getLang('button_proofread', 'proofread') ); - jQuery(AtD_qtbutton).css({ 'color' : '#464646' }); + if ( AtD_qtbutton ) { + /* change the link text back to its original label */ + jQuery(AtD_qtbutton).val( AtD.getLang('button_proofread', 'proofread') ); + jQuery(AtD_qtbutton).css({ 'color' : '#464646' }); - /* enable the toolbar buttons */ - jQuery( AtD_qtbutton ).siblings('input').andSelf().attr( 'disabled', false ); + /* enable the toolbar buttons */ + jQuery( AtD_qtbutton ).siblings('input').andSelf().attr( 'disabled', false ); + } /* restore autosave */ - if (AtD.autosave != undefined) + if ( AtD.autosave != undefined ) autosave = AtD.autosave; }; @@ -43,7 +42,7 @@ if ( typeof(QTags) != 'undefined' && QTags.addButton ) { } function AtD_restore_if_proofreading() { - if (jQuery(AtD_qtbutton).val() == AtD.getLang('button_edit_text', 'edit text')) + if ( AtD_qtbutton && jQuery(AtD_qtbutton).val() == AtD.getLang('button_edit_text', 'edit text') ) AtD_restore_text_area(); } diff --git a/plugins/jetpack/modules/comments.php b/plugins/jetpack/modules/comments.php new file mode 100644 index 00000000..b30ccd73 --- /dev/null +++ b/plugins/jetpack/modules/comments.php @@ -0,0 +1,26 @@ +<?php + +/** + * Module Name: Jetpack Comments + * Module Description: A new comment system that has integrated social media login options. + * First Introduced: 1.4 + * Sort Order: 2 + */ + +require dirname( __FILE__ ) . '/comments/comments.php'; + +if ( is_admin() ) { + require dirname( __FILE__ ) . '/comments/admin.php'; +} + +function jetpack_comments_load() { + Jetpack::enable_module_configurable( __FILE__ ); + Jetpack::module_configuration_load( __FILE__, 'jetpack_comments_configuration_load' ); +} + +function jetpack_comments_configuration_load() { + wp_safe_redirect( admin_url( 'options-discussion.php#jetpack-comments-settings' ) ); + exit; +} + +add_action( 'jetpack_modules_loaded', 'jetpack_comments_load' ); diff --git a/plugins/jetpack/modules/comments/admin.php b/plugins/jetpack/modules/comments/admin.php new file mode 100644 index 00000000..342b7f64 --- /dev/null +++ b/plugins/jetpack/modules/comments/admin.php @@ -0,0 +1,208 @@ +<?php + +class Jetpack_Comments_Settings { + + /** Variables *************************************************************/ + + /** + * The Jetpack Coments singleton + */ + var $jetpack_comments; + + /** + * The default comment form greeting + * @var string + */ + var $default_greeting = ''; // Set in constructor + + /** + * The default comment form color scheme + * @var string + */ + var $color_schemes = array(); + + public static function init() { + static $instance = false; + + if ( !$instance ) { + $instance = new Jetpack_Comments_Settings( Jetpack_Comments::init() ); + } + + return $instance; + } + + public function __construct( Highlander_Comments_Base $jetpack_comments ) { + $this->jetpack_comments = $jetpack_comments; + + // Setup settings + add_action( 'admin_init', array( $this, 'add_settings' ) ); + $this->setup_globals(); + } + + /** Private Methods *******************************************************/ + + /** + * Set any global variables or class variables + * @since JetpackComments (1.4) + */ + protected function setup_globals() { + // Default option values + $this->default_greeting = __( 'Leave a Reply', 'jetpack' ); + + // Possible color schemes + $this->color_schemes = array( + 'light' => __( 'Light', 'jetpack' ), + 'dark' => __( 'Dark', 'jetpack' ), + 'transparent' => __( 'Transparent', 'jetpack' ), + ); + } + + /** Settings **************************************************************/ + + /** + * Add the Jetpack settings to WordPress's discussions page + * + * @since JetpackComments (1.4) + */ + public function add_settings() { + + // Create the section + add_settings_section( + 'jetpack_comment_form', + __( 'Jetpack Comments', 'jetpack' ), + array( $this, 'comment_form_settings_section' ), + 'discussion' + ); + + /** Clever Greeting ***************************************************/ + + add_settings_field( + 'highlander_comment_form_prompt', + __( 'Greeting Text', 'jetpack' ), + array( $this, 'comment_form_greeting_setting' ), + 'discussion', + 'jetpack_comment_form' + ); + + register_setting( + 'discussion', + 'highlander_comment_form_prompt', + array( $this, 'comment_form_greeting_sanitize' ) + ); + + /** Color Scheme ******************************************************/ + + add_settings_field( + 'jetpack_comment_form_color_scheme', + __( 'Color Scheme', 'jetpack' ), + array( $this, 'comment_form_color_scheme_setting' ), + 'discussion', + 'jetpack_comment_form' + ); + + register_setting( + 'discussion', + 'jetpack_comment_form_color_scheme', + array( $this, 'comment_form_color_scheme_sanitize' ) + ); + } + + /** + * Discussions setting section blurb + * + * @since JetpackComments (1.4) + */ + public function comment_form_settings_section() { + ?> + + <p id="jetpack-comments-settings"><?php _e( 'Adjust your Jetpack Comments form with a clever greeting and color-scheme.', 'jetpack' ); ?></p> + + <?php + } + + /** + * Custom Comment Greeting Text + * + * @since JetpackComments (1.4) + */ + public function comment_form_greeting_setting() { + + // The greeting + $greeting = get_option( 'highlander_comment_form_prompt', $this->default_greeting ); ?> + + <input type="text" name="highlander_comment_form_prompt" id="jetpack-comment-form-greeting" value="<?php echo esc_attr( $greeting ); ?>" class="regular-text"> + <p class="description"><?php _e( 'A few catchy words to motivate your readers to comment', 'jetpack' ); ?></p> + + <?php + } + + /** + * Sanitize the clever comment greeting + * + * @since JetpackComments (1.4) + * @param type $val + * @return string + */ + function comment_form_greeting_sanitize( $val ) { + + // Delete if empty or the default + if ( empty( $val ) || ( $this->default_greeting == $val ) ) { + delete_option( 'highlander_comment_form_prompt' ); + return false; + } + + return wp_kses( $val, array() ); + } + + /** + * Color Scheme Setting + * + * @since JetpackComments (1.4) + */ + public function comment_form_color_scheme_setting() { + + // The color scheme + $scheme = get_option( 'jetpack_comment_form_color_scheme', $this->jetpack_comments->default_color_scheme ); ?> + + <fieldset> + <legend class="screen-reader-text"><?php _e( 'Color Scheme', 'jetpack' ); ?></legend> + + <?php foreach( $this->color_schemes as $key => $label ) : ?> + + <label> + <input type="radio" name="jetpack_comment_form_color_scheme" id="jetpack-comment-form-color-scheme" value="<?php echo $key; ?>" <?php checked( $scheme, $key ); ?>> + <?php echo $label; ?> + </label> + <br /> + + <?php endforeach; ?> + + </fieldset> + + <?php + } + + /** + * Sanitize the color scheme + * + * @since JetpackComments (1.4) + * @param type $val + * @return string + */ + public function comment_form_color_scheme_sanitize( $val ) { + + // Delete the option if it's... + if ( + empty( $val ) || !in_array( $val, array_keys( $this->color_schemes ) ) // ... unknown + || + $val == $this->jetpack_comments->default_color_scheme // ... or the default + ) { + delete_option( 'jetpack_comment_form_color_scheme' ); + return false; + } + + return $val; + } +} + +Jetpack_Comments_Settings::init(); diff --git a/plugins/jetpack/modules/comments/base.php b/plugins/jetpack/modules/comments/base.php new file mode 100644 index 00000000..2835313f --- /dev/null +++ b/plugins/jetpack/modules/comments/base.php @@ -0,0 +1,328 @@ +<?php + +/** + * All the code shared between WP.com Highlander and Jetpack Highlander + */ +class Highlander_Comments_Base { + function __construct() { + $this->setup_globals(); + $this->setup_actions(); + $this->setup_filters(); + } + + /** + * Set any global variables or class variables + * @since JetpackComments (1.4) + */ + protected function setup_globals() {} + + /** + * Setup actions for methods in this class + * @since JetpackComments (1.4) + */ + protected function setup_actions() { + // Before a comment is posted + add_action( 'pre_comment_on_post', array( $this, 'allow_logged_out_user_to_comment_as_external' ) ); + + // After a comment is posted + add_action( 'comment_post', array( $this, 'set_comment_cookies' ) ); + } + + /** + * Setup filters for methods in this class + * @since JetpackComments (1.4) + */ + protected function setup_filters() { + add_filter( 'comments_array', array( $this, 'comments_array' ) ); + add_filter( 'preprocess_comment', array( $this, 'allow_logged_in_user_to_comment_as_guest' ), 0 ); + add_filter( 'get_avatar', array( $this, 'get_avatar' ), 10, 4 ); + } + + /** + * Is this a Highlander POST request? + * Optionally restrict to one or more credentials slug (facebook, twitter, ...) + * + * @param string Comment credentials slug + * @param ... + * @return false|string false if it's not a Highlander POST request. The matching credentials slug if it is. + */ + function is_highlander_comment_post() { + if ( empty( $_POST['hc_post_as'] ) ) { + return false; + } + + if ( func_num_args() ) { + foreach ( func_get_args() as $id_source ) { + if ( $id_source === $_POST['hc_post_as'] ) { + return $id_source; + } + } + return false; + } + + return is_string( $_POST['hc_post_as'] ) && in_array( $_POST['hc_post_as'], $this->id_sources ) ? $_POST['hc_post_as'] : false; + } + + /** + * Signs an array of scalars with the self-hosted blog's Jetpack Token + * + * @param array $parameters + * @param string $key + * @return string HMAC + */ + static function sign_remote_comment_parameters( $parameters, $key ) { + unset( + $parameters['sig'], // Don't sign the signature + $parameters['replytocom'] // This parameter is unsigned - it changes dynamically as the comment form moves from parent comment to parent comment + ); + + ksort( $parameters ); + + $signing = array(); + foreach ( $parameters as $k => $v ) { + if ( !is_scalar( $v ) ) { + return new WP_Error( 'invalid_input', __( 'Invalid request', 'jetpack' ) ); + } + + $signing[] = "{$k}={$v}"; + } + + return hash_hmac( 'sha1', implode( ':', $signing ), $key ); + } + + /* + * After commenting as a guest while logged in, the user needs to see both: + * + * ( user_id = blah AND comment_approved = 0 ) + * and + * ( comment_author_email = blah AND comment_approved = 0 ) + * + * Core only does the first since the user is logged in. + * + * Add the second to the comments array. + */ + function comments_array( $comments ) { + global $wpdb, $post; + + $commenter = $this->get_current_commenter(); + + if ( !$commenter['user_id'] ) + return $comments; + + if ( !$commenter['comment_author'] ) + return $comments; + + $in_moderation_comments = $wpdb->get_results( $wpdb->prepare( + "SELECT * FROM `$wpdb->comments` WHERE `comment_post_ID` = %d AND `user_id` = 0 AND `comment_author` = %s AND `comment_author_email` = %s AND `comment_approved` = '0' ORDER BY `comment_date_gmt` /* Highlander_Comments_Base::comments_array() */", + $post->ID, + wp_specialchars_decode( $commenter['comment_author'], ENT_QUOTES ), + $commenter['comment_author_email'] + ) ); + + if ( !$in_moderation_comments ) + return $comments; + + // @todo ZOMG this is a bad idea + $comments = array_merge( $comments, $in_moderation_comments ); + usort( $comments, array( $this, 'sort_comments_by_comment_date_gmt' ) ); + + return $comments; + } + + /** + * Comment sort comparator: comment_date_gmt + * + * @since JetpackComments (1.4) + * @param object $a + * @param object $b + * @return int + */ + public function sort_comments_by_comment_date_gmt( $a, $b ) { + if ( $a->comment_date_gmt == $b->comment_date_gmt ) { + return 0; + } + + return $a->comment_date_gmt < $b->comment_date_gmt ? -1 : 1; + } + + /** + * Get the current commenter's information from their cookie + * + * @since JetpackComments (1.4) + * @return array Commenters information from cookie + */ + protected function get_current_commenter() { + // Defaults + $user_id = 0; + $comment_author = ''; + $comment_author_email = ''; + $comment_author_url = ''; + + if ( isset( $_COOKIE['comment_author_' . COOKIEHASH] ) ) { + $comment_author = $_COOKIE['comment_author_' . COOKIEHASH]; + } + + if ( isset( $_COOKIE['comment_author_email_' . COOKIEHASH] ) ) { + $comment_author_email = $_COOKIE['comment_author_email_' . COOKIEHASH]; + } + + if ( isset( $_COOKIE['comment_author_url_' . COOKIEHASH] ) ) { + $comment_author_url = $_COOKIE['comment_author_url_' . COOKIEHASH]; + } + + if ( is_user_logged_in() ) { + $user = wp_get_current_user(); + $user_id = $user->ID; + } + + return compact( 'comment_author', 'comment_author_email', 'comment_author_url', 'user_id' ); + } + + /** + * Allows a logged out user to leave a comment as a facebook or twitter credentialed user. + * Overrides WordPress' core comment_registration option to treat these commenters as "registered" (verified) users. + * + * @since JetpackComments (1.4) + * @return If no + */ + function allow_logged_out_user_to_comment_as_external() { + if ( !$this->is_highlander_comment_post( 'facebook', 'twitter' ) ) { + return; + } + + add_filter( 'pre_option_comment_registration', '__return_zero' ); + } + + /** + * Allow a logged in user to post as a guest, FB, or twitter credentialed request. + * Bypasses WordPress' core overrides that force a logged in user to comment as that user. + * Respects comment_registration option. + * + * @since JetpackComments (1.4) + * @param array $comment_data + * @return int + */ + function allow_logged_in_user_to_comment_as_guest( $comment_data ) { + // Bail if user registration is allowed + if ( get_option( 'comment_registration' ) ) { + return $comment_data; + } + + // Bail if user is not logged in or not a post request + if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) || !is_user_logged_in() ) { + return $comment_data; + } + + // Bail if this is not a guest or external service credentialed request + if ( !$this->is_highlander_comment_post( 'guest', 'facebook', 'twitter' ) ) { + return $comment_data; + } + + $user = wp_get_current_user(); + + foreach ( array( 'comment_author' => 'display_name', 'comment_author_email' => 'user_email', 'comment_author_url' => 'user_url' ) as $comment_field => $user_field ) { + if ( $comment_data[$comment_field] != addslashes( $user->$user_field ) ) { + return $comment_data; // some other plugin already did something funky + } + } + + if ( get_option( 'require_name_email' ) ) { + if ( 6 > strlen( $_POST['email'] ) || empty( $_POST['author'] ) ) { + wp_die( __( 'Error: please fill the required fields (name, email).', 'jetpack' ) ); + } elseif ( ! is_email( $_POST['email'] ) ) { + wp_die( __( 'Error: please enter a valid email address.', 'jetpack' ) ); + } + } + + foreach ( array( 'comment_author' => 'author', 'comment_author_email' => 'email', 'comment_author_url' => 'url' ) as $comment_field => $post_field ) { + $comment_data[$comment_field] = $_POST[$post_field]; + } + + // Mark as guest comment + $comment_data['user_id'] = $comment_data['user_ID'] = 0; + + return $comment_data; + } + + /** + * Set the comment cookies or bail if comment is invalid + * + * @since JetpackComments (1.4) + * @param type $comment_id + * @return If comment is invalid + */ + public function set_comment_cookies( $comment_id ) { + // Get comment and bail if it's invalid somehow + $comment = get_comment( $comment_id ); + if ( empty( $comment ) || is_wp_error( $comment ) ) { + return; + } + + $id_source = $this->is_highlander_comment_post(); + if ( empty( $id_source ) ) { + return; + } + + // Set comment author cookies + if ( ( 'wordpress' != $id_source ) && is_user_logged_in() ) { + $comment_cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 ); + setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN ); + setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN ); + setcookie( 'comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN ); + } + } + + /** + * Get the comment avatar from Gravatar, Twitter, or Facebook + * + * @since JetpackComments (1.4) + * @param string $avatar Current avatar URL + * @param string $comment Comment for the avatar + * @param int $size Size of the avatar + * @param string $default Not used + * @return string New avatar + */ + public function get_avatar( $avatar, $comment, $size, $default ) { + if ( ! isset( $comment->comment_post_ID ) || ! isset( $comment->comment_ID ) ) { + // it's not a comment - bail + return $avatar; + } + + if ( false === strpos( $comment->comment_author_url, '/www.facebook.com/' ) && false === strpos( $comment->comment_author_url, '/twitter.com/' ) ) { + // It's neither FB nor Twitter - bail + return $avatar; + } + + // It's a FB or Twitter avatar + $foreign_avatar = get_comment_meta( $comment->comment_ID, 'hc_avatar', true ); + if ( empty( $foreign_avatar ) ) { + // Can't find the avatar details - bail + return $avatar; + } + + // Return the FB or Twitter avatar + return preg_replace( '#src=([\'"])[^\'"]+\\1#', 'src=\\1' . esc_url( $this->imgpress_avatar( $foreign_avatar, $size ) ) . '\\1', $avatar ); + } + + /** + * Get an avatar from Imgpress + * + * @since JetpackComments (1.4) + * @param string $url + * @param int $size + * @return string + */ + protected function imgpress_avatar( $url, $size ) { + $size = (int) $size; + + $args = urlencode_deep( array( + 'url' => $url, + 'resize' => "$size,$size", + ) ); + + $url = apply_filters( 'jetpack_static_url', ( is_ssl() ? 'https://s-ssl.wordpress.com' : 'http://s.wordpress.com' ) . '/imgpress' ); + $url = add_query_arg( $args, $url ); + + return $url; + } +} diff --git a/plugins/jetpack/modules/comments/comments.php b/plugins/jetpack/modules/comments/comments.php new file mode 100644 index 00000000..965769d6 --- /dev/null +++ b/plugins/jetpack/modules/comments/comments.php @@ -0,0 +1,377 @@ +<?php + +require dirname( __FILE__ ) . '/base.php'; + +/** + * Main Jetpack Comments class + * + * @package JetpackComments + * @version 1.4 + * @since 1.4 + */ +class Jetpack_Comments extends Highlander_Comments_Base { + + /** Variables *************************************************************/ + + /** + * Possible comment form sources + * @var array + */ + var $id_sources = array(); + + /** + * URL + * @var string + */ + var $signed_url = ''; + + /** + * The default comment form color scheme + * @var string + * @see ::set_default_color_theme_based_on_theme_settings() + */ + var $default_color_scheme = 'light'; + + /** Methods ***************************************************************/ + + public static function init() { + static $instance = false; + + if ( !$instance ) { + $instance = new Jetpack_Comments; + } + + return $instance; + } + + /** + * Main constructor for Jetpack Comments + * + * @since JetpackComments (1.4) + */ + public function __construct() { + parent::__construct(); + + // Jetpack Comments is loaded + do_action_ref_array( 'jetpack_comments_loaded', array( $this ) ); + add_action( 'after_setup_theme', array( $this, 'set_default_color_theme_based_on_theme_settings' ), 100 ); + } + + public function set_default_color_theme_based_on_theme_settings() { + if ( function_exists( 'twentyeleven_get_theme_options' ) ) { + $theme_options = twentyeleven_get_theme_options(); + $theme_color_scheme = isset( $theme_options['color_scheme'] ) ? $theme_options['color_scheme'] : 'transparent'; + } else { + $theme_color_scheme = get_theme_mod( 'color_scheme', 'transparent' ); + } + // Default for $theme_color_scheme is 'transparent' just so it doesn't match 'light' or 'dark' + // The default for Jetpack's color scheme is still defined above as 'light' + + if ( false !== stripos( $theme_color_scheme, 'light' ) ) { + $this->default_color_scheme = 'light'; + } elseif ( false !== stripos( $theme_color_scheme, 'dark' ) ) { + $this->default_color_scheme = 'dark'; + } + } + + /** Private Methods *******************************************************/ + + /** + * Set any global variables or class variables + * @since JetpackComments (1.4) + */ + protected function setup_globals() { + parent::setup_globals(); + + // Sources + $this->id_sources = array( + 'guest', + 'jetpack', + 'wordpress', + 'twitter', + 'facebook' + ); + } + + /** + * Setup actions for methods in this class + * @since JetpackComments (1.4) + */ + protected function setup_actions() { + parent::setup_actions(); + + // Selfishly remove everything from the existing comment form + remove_all_actions( 'comment_form_before' ); + remove_all_actions( 'comment_form_after' ); + + // Selfishly add only our actions back to the comment form + add_action( 'comment_form_before', array( $this, 'comment_form_before' ) ); + add_action( 'comment_form_after', array( $this, 'comment_form_after' ) ); + + // Before a comment is posted + add_action( 'pre_comment_on_post', array( $this, 'pre_comment_on_post' ), 1 ); + + // After a comment is posted + add_action( 'comment_post', array( $this, 'add_comment_meta' ) ); + } + + /** Output Methods ********************************************************/ + + /** + * Start capturing the core comment_form() output + * @since JetpackComments (1.4) + */ + public function comment_form_before() { + // Add some JS to the footer + add_action( 'wp_footer', array( $this, 'watch_comment_parent' ), 100 ); + + ob_start(); + } + + /** + * Noop teh default comment form output, get some options, and output our + * tricked out totally radical comment form. + * + * @since JetpackComments (1.4) + */ + public function comment_form_after() { + + // Throw it all out and drop in our replacement + ob_end_clean(); + + // If users are required to be logged in, and they're not, then we don't need to do anything else + if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) { + echo '<p id="must-log-in-to-comment">' . sprintf( apply_filters( 'jetpack_must_log_in_to_comment', __( 'You must <a href="%s">log in</a> to post a comment.', 'jetpack' ) ), wp_login_url( get_permalink() . '#respond' ) ) . '</p>'; + return; + } + + if ( in_array( 'subscriptions', Jetpack::get_active_modules() ) ) { + $stb_enabled = get_option( 'stb_enabled', 1 ); + $stb_enabled = empty( $stb_enabled ) ? 0 : 1; + + $stc_enabled = get_option( 'stc_enabled', 1 ); + $stc_enabled = empty( $stc_enabled ) ? 0 : 1; + } else { + $stb_enabled = 0; + $stc_enabled = 0; + } + + $params = array( + 'blogid' => Jetpack::get_option( 'id' ), + 'postid' => get_the_ID(), + 'comment_registration' => ( get_option( 'comment_registration' ) ? '1' : '0' ), // Need to explicitly send a '1' or a '0' for these + 'require_name_email' => ( get_option( 'require_name_email' ) ? '1' : '0' ), + 'stc_enabled' => $stc_enabled, + 'stb_enabled' => $stb_enabled, + 'show_avatars' => ( get_option( 'show_avatars' ) ? '1' : '0' ), + 'avatar_default' => get_option( 'avatar_default' ), + 'greeting' => get_option( 'highlander_comment_form_prompt', __( 'Leave a Reply', 'jetpack' ) ), + 'color_scheme' => get_option( 'jetpack_comment_form_color_scheme', $this->default_color_scheme ), + 'lang' => get_bloginfo( 'language' ), + ); + + // Extra parameters for logged in user + if ( is_user_logged_in() ) { + $current_user = wp_get_current_user(); + $params['hc_post_as'] = 'jetpack'; + $params['hc_userid'] = $current_user->ID; + $params['hc_username'] = $current_user->display_name; + $params['hc_userurl'] = $current_user->user_url; + $params['hc_useremail'] = md5( strtolower( trim( $current_user->user_email ) ) ); + if ( current_user_can( 'unfiltered_html' ) ) + $params['_wp_unfiltered_html_comment'] = wp_create_nonce( 'unfiltered-html-comment_' . get_the_ID() ); + } + + $signature = Jetpack_Comments::sign_remote_comment_parameters( $params, Jetpack::get_option( 'blog_token' ) ); + if ( is_wp_error( $signature ) ) { + $signature = 'error'; + } + + $params['sig'] = $signature; + $url_origin = ( is_ssl() ? 'https' : 'http' ) . '://jetpack.wordpress.com'; + $url = "{$url_origin}/jetpack-comment/?" . http_build_query( $params ); + $url = "{$url}#parent=" . urlencode( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); + $this->signed_url = $url; + $height = $params['comment_registration'] || is_user_logged_in() ? '315' : '430'; // Iframe can be shorter if we're not allowing guest commenting + $transparent = ( $params['color_scheme'] == 'transparent' ) ? 'true' : 'false'; + + if ( isset( $_GET['replytocom'] ) ) { + $url .= '&replytocom=' . (int) $_GET['replytocom']; + } + + // The actual iframe (loads comment form from Jetpack server) + ?> + + <div id="respond"> + <div id="cancel-comment-reply-link" style="display:none; float:right;"><a href="#"><?php echo esc_html( __( 'Cancel Reply', 'jetpack' ) ); ?></a></div> + <iframe src="<?php echo esc_url( $url ); ?>" allowtransparency="<?php echo $transparent; ?>" style="width:100%; height: <?php echo $height; ?>px;border:0px;" frameBorder="0" scrolling="no" name="jetpack_remote_comment" id="jetpack_remote_comment"></iframe> + </div> + + <?php // Below is required for comment reply JS to work ?> + + <input type="hidden" name="comment_parent" id="comment_parent" value="" /> + + <?php + } + + /** + * Add some JS to wp_footer to watch for hierarchical reply parent change + * + * @since JetpackComments (1.4) + */ + public function watch_comment_parent() { + $url_origin = ( is_ssl() ? 'https' : 'http' ) . '://jetpack.wordpress.com'; + ?> + + <script type="text/javascript"> + var comm_par = document.getElementById( 'comment_parent' ).value, + frame = document.getElementById( 'jetpack_remote_comment' ), + tellFrameNewParent; + + tellFrameNewParent = function() { + if ( comm_par ) { + frame.src = <?php echo json_encode( esc_url_raw( $this->signed_url ) ); ?> + '&replytocom=' + parseInt( comm_par, 10 ).toString(); + } else { + frame.src = <?php echo json_encode( esc_url_raw( $this->signed_url ) ); ?>; + } + }; + + addComment._Jetpack_moveForm = addComment.moveForm; + + addComment.moveForm = function( commId, parentId, respondId, postId ) { + var returnValue = addComment._Jetpack_moveForm( commId, parentId, respondId, postId ), cancelClick, cancel; + + if ( false === returnValue ) { + cancel = document.getElementById( 'cancel-comment-reply-link' ); + cancelClick = cancel.onclick; + cancel.onclick = function() { + var cancelReturn = cancelClick.call( this ); + if ( false !== cancelReturn ) { + return cancelReturn; + } + + if ( !comm_par ) { + return cancelReturn; + } + + comm_par = 0; + + tellFrameNewParent(); + + return cancelReturn; + }; + } + + if ( comm_par == parentId ) { + return returnValue; + } + + comm_par = parentId; + + tellFrameNewParent(); + + return returnValue; + }; + + if ( window.postMessage ) { + if ( document.addEventListener ) { + window.addEventListener( 'message', function( event ) { + if ( <?php echo json_encode( esc_url_raw( $url_origin ) ); ?> !== event.origin ) { + return; + } + + jQuery( frame ).height( event.data ); + } ); + } else if ( document.attachEvent ) { + window.attachEvent( 'message', function( event ) { + if ( <?php echo json_encode( esc_url_raw( $url_origin ) ); ?> !== event.origin ) { + return; + } + + jQuery( frame ).height( event.data ); + } ); + } + } + </script> + + <?php + } + + /** + * Verify the hash included in remote comments. + * + * @since JetpackComments (1.4) + * @param type $comment Not used + */ + public function pre_comment_on_post( $comment ) { + $post_array = stripslashes_deep( $_POST ); + + // Bail if missing the Jetpack token + if ( ! isset( $post_array['sig'] ) ) { + unset( $_POST['hc_post_as'] ); + return; + } + + if ( FALSE !== strpos( $post_array['hc_avatar'], '.gravatar.com' ) ) + $post_array['hc_avatar'] = htmlentities( $post_array['hc_avatar'] ); + + $check = Jetpack_Comments::sign_remote_comment_parameters( $post_array, Jetpack::get_option( 'blog_token' ) ); + if ( is_wp_error( $check ) ) { + wp_die( $check ); + } + + // Bail if token is expired or not valid + if ( $check !== $post_array['sig'] ) + wp_die( __( 'Invalid security token.', 'jetpack' ) ); + } + + /** Capabilities **********************************************************/ + + /** + * Add some additional comment meta after comment is saved about what + * service the comment is from, the avatar, user_id, etc... + * + * @since JetpackComments (1.4) + * @param type $comment_id + */ + public function add_comment_meta( $comment_id ) { + $comment_meta = array(); + + switch( $this->is_highlander_comment_post() ) { + case 'facebook' : + $comment_meta['hc_post_as'] = 'facebook'; + $comment_meta['hc_avatar'] = stripslashes( $_POST['hc_avatar'] ); + $comment_meta['hc_foreign_user_id'] = stripslashes( $_POST['hc_userid'] ); + break; + + case 'twitter' : + $comment_meta['hc_post_as'] = 'twitter'; + $comment_meta['hc_avatar'] = stripslashes( $_POST['hc_avatar'] ); + $comment_meta['hc_foreign_user_id'] = stripslashes( $_POST['hc_userid'] ); + break; + + case 'wordpress' : + $comment_meta['hc_post_as'] = 'wordpress'; + $comment_meta['hc_avatar'] = stripslashes( $_POST['hc_avatar'] ); + $comment_meta['hc_foreign_user_id'] = stripslashes( $_POST['hc_userid'] ); + break; + + case 'jetpack' : + $comment_meta['hc_post_as'] = 'jetpack'; + $comment_meta['hc_avatar'] = stripslashes( $_POST['hc_avatar'] ); + $comment_meta['hc_foreign_user_id'] = stripslashes( $_POST['hc_userid'] ); + break; + + } + + // Bail if no extra comment meta + if ( empty( $comment_meta ) ) + return; + + // Loop through extra meta and add values + foreach ( $comment_meta as $key => $value ) + add_comment_meta( $comment_id, $key, $value, true ); + } +} + +Jetpack_Comments::init(); diff --git a/plugins/jetpack/modules/contact-form.php b/plugins/jetpack/modules/contact-form.php index bff13e26..ac44d0d3 100644 --- a/plugins/jetpack/modules/contact-form.php +++ b/plugins/jetpack/modules/contact-form.php @@ -2,7 +2,7 @@ /** * Module Name: Contact Form * Module Description: Easily insert a contact form any where on your site. - * Sort Order: 5 + * Sort Order: 6 * First Introduced: 1.3 */ diff --git a/plugins/jetpack/modules/gravatar-hovercards.php b/plugins/jetpack/modules/gravatar-hovercards.php index e3e8e66e..3678837f 100644 --- a/plugins/jetpack/modules/gravatar-hovercards.php +++ b/plugins/jetpack/modules/gravatar-hovercards.php @@ -2,7 +2,7 @@ /** * Module Name: Gravatar Hovercards * Module Description: Show a pop-up business card of your users' gravatar profiles in comments. - * Sort Order: 5 + * Sort Order: 8 * First Introduced: 1.1 */ diff --git a/plugins/jetpack/modules/latex.php b/plugins/jetpack/modules/latex.php index fe20647d..4e4d9db2 100644 --- a/plugins/jetpack/modules/latex.php +++ b/plugins/jetpack/modules/latex.php @@ -2,7 +2,7 @@ /** * Module Name: Beautiful Math * Module Description: Mark up your posts with the <img src="http://l.wordpress.com/latex.php?latex=%5CLaTeX&bg=transparent&fg=000&s=-2" alt="LaTeX logo" title="LaTeX" style="vertical-align: -25%" /> markup language, perfect for complex mathematical equations and other über-geekery. - * Sort Order: 15 + * Sort Order: 12 * First Introduced: 1.1 */ diff --git a/plugins/jetpack/modules/module-info.php b/plugins/jetpack/modules/module-info.php index e6140161..885b3fd2 100644 --- a/plugins/jetpack/modules/module-info.php +++ b/plugins/jetpack/modules/module-info.php @@ -124,9 +124,7 @@ function jetpack_shortcodes_more_info_connected() { ?> 'polldaddy' => 'http://support.polldaddy.com/wordpress-shortcodes/', ); - if ( version_compare( PHP_VERSION, 5, '>=' ) ) { - $codes['wpvideo (VideoPress)'] = 'http://en.support.wordpress.com/videopress/'; - } + $codes['wpvideo (VideoPress)'] = 'http://en.support.wordpress.com/videopress/'; $available = ''; foreach ( $codes as $code => $url ) { @@ -430,3 +428,34 @@ add_action( 'jetpack_learn_more_button_contact-form', 'jetpack_contact_form_lear add_action( 'jetpack_module_more_info_contact-form', 'jetpack_contact_form_more_info' ); add_action( 'jetpack_module_more_info_connected_contact-form', 'jetpack_contact_form_more_info' ); // Contact Form: STOP + +// Jetpack Comments + +function jetpack_comments_learn_more_button() { + echo '<a class="button more-info-link" href="#">' . __( 'Learn More', 'jetpack' ) . '</a>'; +} + +function jetpack_comments_more_info() { +?> + <div class="jp-info-img"> + <img class="jp-info-img" src="<?php echo plugins_url( basename( dirname( dirname( __FILE__ ) ) ) . '/_inc/images/comments.png' ) ?>" alt="<?php esc_attr_e( 'Jetpack Comments Screenshot', 'jetpack' ) ?>" width="320" height="205" /> + </div> + + <h4><?php esc_html_e( 'Jetpack Comments', 'jetpack' ); ?></h4> + + <p><?php esc_html_e( 'Jetpack Comments enables your visitors to use their WordPress.com, Twitter, or Facebook accounts when commenting on your site.', 'jetpack' ); ?></p> + +<?php if ( 'jetpack_module_more_info_connected_comments' == current_filter() ) : ?> + + <p><?php printf( + __( "Jetpack tries to match your site's color scheme automatically, but you can make manual adjustments at the bottom of the <a href='%s'>Discussion Settings</a> page.", 'jetpack' ), + admin_url( 'options-discussion.php#jetpack-comments-settings' ) + ); ?></p> + +<?php endif; ?> +<?php +} + +add_action( 'jetpack_learn_more_button_comments', 'jetpack_comments_learn_more_button' ); +add_action( 'jetpack_module_more_info_comments', 'jetpack_comments_more_info' ); +add_action( 'jetpack_module_more_info_connected_comments', 'jetpack_comments_more_info' ); diff --git a/plugins/jetpack/modules/sharedaddy.php b/plugins/jetpack/modules/sharedaddy.php index 97f359c5..45eeb0c8 100644 --- a/plugins/jetpack/modules/sharedaddy.php +++ b/plugins/jetpack/modules/sharedaddy.php @@ -2,7 +2,7 @@ /** * Module Name: Sharing * Module Description: The most super duper sharing tool on the interwebs. Share content with Facebook, Twitter, and many more. - * Sort Order: 1 + * Sort Order: 4 * First Introduced: 1.1 * Major Changes In: 1.2 */ diff --git a/plugins/jetpack/modules/sharedaddy/images/linkedin.png b/plugins/jetpack/modules/sharedaddy/images/linkedin.png Binary files differindex a5e0340e..0d727c2c 100644 --- a/plugins/jetpack/modules/sharedaddy/images/linkedin.png +++ b/plugins/jetpack/modules/sharedaddy/images/linkedin.png diff --git a/plugins/jetpack/modules/sharedaddy/sharing-service.php b/plugins/jetpack/modules/sharedaddy/sharing-service.php index 073044d4..1b765cb6 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing-service.php +++ b/plugins/jetpack/modules/sharedaddy/sharing-service.php @@ -205,8 +205,15 @@ class Sharing_Service { if ( isset( $data['button_style'] ) && in_array( $data['button_style'], array( 'icon-text', 'icon', 'text' ) ) ) $options['global']['button_style'] = $data['button_style']; - if ( isset( $data['sharing_label'] ) ) - $options['global']['sharing_label'] = trim( wp_kses( stripslashes( $data['sharing_label'] ), array() ) ); + if ( isset( $data['sharing_label'] ) ) { + $new_label = trim( wp_kses( stripslashes( $data['sharing_label'] ), array() ) ); + + if ( 0 === strcmp( $new_label, $options['global']['sharing_label'] ) ) { + $options['global']['sharing_label'] = FALSE; + } else { + $options['global']['sharing_label'] = $new_label; + } + } if ( isset( $data['open_links'] ) && in_array( $data['open_links'], array( 'new', 'same' ) ) ) $options['global']['open_links'] = $data['open_links']; @@ -466,8 +473,12 @@ function sharing_display( $text = '' ) { } $parts = array(); - if ( $global['sharing_label'] != '' ) - $parts[] = '<li class="sharing_label">'.$global['sharing_label'].'</li>'; + + if ( FALSE === $global['sharing_label'] ) { + $parts[] = '<li class="sharing_label">' . __( 'Share this:', 'jetpack' ) . '</li>'; + } elseif ( '' != $global['sharing_label'] ) { + $parts[] = '<li class="sharing_label">' . esc_html( $global['sharing_label'] ) . '</li>'; + } $parts[] = $visible; if ( count( $enabled['hidden'] ) > 0 ) diff --git a/plugins/jetpack/modules/sharedaddy/sharing-sources.php b/plugins/jetpack/modules/sharedaddy/sharing-sources.php index 1eb18722..2734d820 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing-sources.php +++ b/plugins/jetpack/modules/sharedaddy/sharing-sources.php @@ -729,14 +729,22 @@ class Share_Facebook extends Sharing_Advanced_Source { } function guess_locale_from_lang( $lang ) { - $lang = strtolower( str_replace( '-', '_', $lang ) ); - if ( 5 == strlen( $lang ) ) - $lang = substr( $lang, 0, 3 ) . strtoupper( substr( $lang, 3, 2 ) ); // Already in xx_xx, just make sure it's uppered - else if ( 3 == strlen( $lang ) ) - $lang = $lang; // Don't know what to do with these - else - $lang = $lang . '_' . strtoupper( $lang ); // Sometimes this gives a workable locale - return $lang; + if ( 'en' == $lang || 'en_US' == $lang || !$lang ) { + return 'en_US'; + } + + if ( !class_exists( 'GP_Locales' ) ) { + require JETPACK__PLUGIN_DIR . 'locales.php'; + } + + // Jetpack: get_locale() returns 'it_IT'; + $locale = GP_Locales::by_field( 'wp_locale', $lang ); + + if ( !$locale || empty( $locale->facebook_locale ) ) { + return false; + } + + return $locale->facebook_locale; } public function get_display( $post ) { @@ -747,28 +755,33 @@ class Share_Facebook extends Sharing_Advanced_Source { // Default widths to suit English $inner_w = 90; - + // Locale-specific widths/overrides $widths = array( - 'de' => array( 'width' => 100, 'locale' => 'de_DE' ), - 'da' => array( 'width' => 120, 'locale' => 'da_DK' ), - 'fi' => array( 'width' => 100, 'locale' => 'fi_FI' ), + 'bg_BG' => 120, + 'de_DE' => 100, + 'da_DK' => 120, + 'es_ES' => 100, + 'es_LA' => 100, + 'fi_FI' => 100, + 'it_IT' => 100, + 'ja_JP' => 100, + 'ru_RU' => 128, ); $widths = apply_filters( 'sharing_facebook_like_widths', $widths ); // Fix the button to the blogs locale and then adjust the width - $locale = str_replace( '-', '_', get_locale() ); + $locale = $this->guess_locale_from_lang( get_locale() ); + if ( $locale ) { + if ( 'en_US' != $locale ) { + $url .= '&locale=' . $locale; + } - if ( isset( $widths[substr( $locale, 0, 2 )] ) ) { - $inner_w = $widths[substr( $locale, 0, 2 )]['width']; - $locale = $widths[substr( $locale, 0, 2 )]['locale']; - } else { - $locale = $this->guess_locale_from_lang( get_locale() ); + if ( isset( $widths[$locale] ) ) { + $inner_w = $widths[$locale]; + } } - - if ( $locale && 'en_US' != $locale ) - $url .= '&locale=' . $locale; $url .= '&width='.$inner_w; return '<div class="like_button"><iframe src="'.$url.'" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:'.( $inner_w + 6 ).'px; height:21px;" allowTransparency="true"></iframe></div>'; diff --git a/plugins/jetpack/modules/sharedaddy/sharing.js b/plugins/jetpack/modules/sharedaddy/sharing.js index 90b19e8e..9a288457 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing.js +++ b/plugins/jetpack/modules/sharedaddy/sharing.js @@ -4,9 +4,11 @@ return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test( this.val() ); } } ); - - $( document ).ready(function() { - $( '.sharing a.sharing-anchor' ).click( function() { + + $( document ).on( 'ready post-load', function() { + var $more_sharing_buttons = $( '.sharing a.sharing-anchor' ); + + $more_sharing_buttons.click( function() { return false; } ); @@ -14,92 +16,126 @@ if ( $( this ).attr( 'href' ) && $( this ).attr( 'href' ).indexOf( 'share=' ) != -1 ) $( this ).attr( 'href', $( this ).attr( 'href' ) + '&nb=1' ); } ); - + // Show hidden buttons - $( '.sharing a.sharing-anchor' ).hover( function() { - if ( $( this ).data( 'hasappeared' ) !== true ) { - var item = $( this ).parents( 'div:first' ).find( '.inner' ); - var original = $( this ); - - // Create a timer to make the area appear if the mouse hovers for a period - var timer = setTimeout( function() { - $( '#sharing_email' ).slideUp( 200 ); - $( item ).css( { - left: $( original ).position().left + 'px', - top: $( original ).position().top + $( original ).height() + 3 + 'px' - } ).slideDown( 200, function() { - // Mark the item as have being appeared by the hover - $( original ).data( 'hasappeared', true ).data( 'hasoriginal', true ).data( 'hasitem', false ); - - // Remove all special handlers - $( item ).mouseleave( handler_item_leave ).mouseenter( handler_item_enter ); - $( original ).mouseleave( handler_original_leave ).mouseenter( handler_original_enter ); - - // Add a special handler to quickly close the item - $( original ).click( close_it ); - } ); - - // The following handlers take care of the mouseenter/mouseleave for the share button and the share area - if both are left then we close the share area - var handler_item_leave = function() { - $( original ).data( 'hasitem', false ); - - if ( $( original ).data( 'hasoriginal' ) === false ) { - var timer = setTimeout( close_it, 800 ); - $( original ).data( 'timer2', timer ); - } - }; - - var handler_item_enter = function() { - $( original ).data( 'hasitem', true ); - clearTimeout( $( original ).data( 'timer2' ) ); - } - - var handler_original_leave = function() { - $( original ).data( 'hasoriginal', false ); - - if ( $( original ).data( 'hasitem' ) === false ) { - var timer = setTimeout( close_it, 800 ); - $( original ).data( 'timer2', timer ); - } - }; - - var handler_original_enter = function() { - $( original ).data( 'hasoriginal', true ); - clearTimeout( $( original ).data( 'timer2' ) ); - }; - - var close_it = function() { - item.slideUp( 200 ); - - // Clear all hooks - $( original ).unbind( 'mouseleave', handler_original_leave ).unbind( 'mouseenter', handler_original_enter ); - $( item ).unbind( 'mouseleave', handler_item_leave ).unbind( 'mouseenter', handler_item_leave ); - $( original ).data( 'hasappeared', false ); - $( original ).unbind( 'click', close_it ); - return false; - }; - }, 200 ); - - // Remember the timer so we can detect it on the mouseout - $( this ).data( 'timer', timer ); + // Touchscreen device: use click. + // Non-touchscreen device: use click if not already appearing due to a hover event + $more_sharing_buttons.click( function() { + var $more_sharing_button = $( this ), + $more_sharing_pane = $more_sharing_button.parents( 'div:first' ).find( '.inner' ); + + if ( $more_sharing_pane.is( ':animated' ) ) { + // We're in the middle of some other event's animation + return; + } + + if ( true === $more_sharing_pane.data( 'justSlid' ) ) { + // We just finished some other event's animation - don't process click event so that slow-to-react-clickers don't get confused + return; } - }, function() { - // Mouse out - remove any timer - clearTimeout( $( this ).data( 'timer' ) ); - $( this ).data( 'timer', false ); + + $( '#sharing_email' ).slideUp( 200 ); + + $more_sharing_pane.css( { + left: $more_sharing_button.position().left + 'px', + top: $more_sharing_button.position().top + $more_sharing_button.height() + 3 + 'px' + } ).slideToggle( 200 ); } ); - + + if ( document.ontouchstart === undefined ) { + // Non-touchscreen device: use hover/mouseout with delay + $more_sharing_buttons.hover( function() { + var $more_sharing_button = $( this ), + $more_sharing_pane = $more_sharing_button.parents( 'div:first' ).find( '.inner' ); + + if ( !$more_sharing_pane.is( ':animated' ) ) { + // Create a timer to make the area appear if the mouse hovers for a period + var timer = setTimeout( function() { + $( '#sharing_email' ).slideUp( 200 ); + + $more_sharing_pane.data( 'justSlid', true ); + $more_sharing_pane.css( { + left: $more_sharing_button.position().left + 'px', + top: $more_sharing_button.position().top + $more_sharing_button.height() + 3 + 'px' + } ).slideDown( 200, function() { + // Mark the item as have being appeared by the hover + $more_sharing_button.data( 'hasoriginal', true ).data( 'hasitem', false ); + + // Remove all special handlers + $more_sharing_pane.mouseleave( handler_item_leave ).mouseenter( handler_item_enter ); + $more_sharing_button.mouseleave( handler_original_leave ).mouseenter( handler_original_enter ); + setTimeout( function() { + $more_sharing_pane.data( 'justSlid', false ); + }, 300 ); + } ); + + // The following handlers take care of the mouseenter/mouseleave for the share button and the share area - if both are left then we close the share area + var handler_item_leave = function() { + $more_sharing_button.data( 'hasitem', false ); + + if ( $more_sharing_button.data( 'hasoriginal' ) === false ) { + var timer = setTimeout( close_it, 800 ); + $more_sharing_button.data( 'timer2', timer ); + } + }; + + var handler_item_enter = function() { + $more_sharing_button.data( 'hasitem', true ); + clearTimeout( $more_sharing_button.data( 'timer2' ) ); + } + + var handler_original_leave = function() { + $more_sharing_button.data( 'hasoriginal', false ); + + if ( $more_sharing_button.data( 'hasitem' ) === false ) { + var timer = setTimeout( close_it, 800 ); + $more_sharing_button.data( 'timer2', timer ); + } + }; + + var handler_original_enter = function() { + $more_sharing_button.data( 'hasoriginal', true ); + clearTimeout( $more_sharing_button.data( 'timer2' ) ); + }; + + var close_it = function() { + $more_sharing_pane.data( 'justSlid', true ); + $more_sharing_pane.slideUp( 200, function() { + setTimeout( function() { + $more_sharing_pane.data( 'justSlid', false ); + }, 300 ); + } ); + + // Clear all hooks + $more_sharing_button.unbind( 'mouseleave', handler_original_leave ).unbind( 'mouseenter', handler_original_enter ); + $more_sharing_pane.unbind( 'mouseleave', handler_item_leave ).unbind( 'mouseenter', handler_item_leave ); + return false; + }; + }, 200 ); + + // Remember the timer so we can detect it on the mouseout + $more_sharing_button.data( 'timer', timer ); + } + }, function() { + // Mouse out - remove any timer + $more_sharing_buttons.each( function() { + clearTimeout( $( this ).data( 'timer' ) ); + } ); + $more_sharing_buttons.data( 'timer', false ); + } ); + } + // Add click functionality $( '.sharing ul' ).each( function( item ) { printUrl = function ( uniqueId, urlToPrint ) { $( 'body:first' ).append( '<iframe style="position:fixed;top:100;left:100;height:1px;width:1px;border:none;" id="printFrame-' + uniqueId + '" name="printFrame-' + uniqueId + '" src="' + urlToPrint + '" onload="frames[\'printFrame-' + uniqueId + '\'].focus();frames[\'printFrame-' + uniqueId + '\'].print();"></iframe>' ) }; - + // Print button $( this ).find( '.share-print a' ).click( function() { ref = $( this ).attr( 'href' ); - + var do_print = function() { if ( ref.indexOf( '#print' ) == -1 ) { uid = new Date().getTime(); @@ -108,7 +144,7 @@ else print(); } - + // Is the button in a dropdown? if ( $( this ).parents( '.sharing-hidden' ).length > 0 ) { $( this ).parents( '.inner' ).slideUp( 0, function() { @@ -120,11 +156,11 @@ return false; } ); - + // Press This button $( this ).find( '.share-press-this a' ).click( function() { var s = ''; - + if ( window.getSelection ) s = window.getSelection(); else if( document.getSelection ) @@ -135,7 +171,7 @@ if ( s ) $( this ).attr( 'href', $( this ).attr( 'href' ) + '&sel=' + encodeURI( s ) ); - if ( !window.open( $( this ).attr( 'href' ), 't', 'toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570' ) ) + if ( !window.open( $( this ).attr( 'href' ), 't', 'toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570' ) ) document.location.href = $( this ).attr( 'href' ); return false; @@ -144,7 +180,7 @@ // Email button $( this ).find( '.share-email a' ).click( function() { var url = $( this ).attr( 'href' ); - + if ( $( '#sharing_email' ).is( ':visible' ) ) $( '#sharing_email' ).slideUp( 200 ); else { @@ -160,7 +196,7 @@ left: $( this ).offset().left + 'px', top: $( this ).offset().top + $( this ).height() + 'px' } ).slideDown( 200 ); - + // Hook up other buttons $( '#sharing_email a.sharing_cancel' ).unbind( 'click' ).click( function() { $( '#sharing_email .errors' ).hide(); @@ -168,25 +204,25 @@ $( '#sharing_background' ).fadeOut(); return false; } ); - + // Submit validation $( '#sharing_email input[type=submit]' ).unbind( 'click' ).click( function() { var form = $( this ).parents( 'form' ); - + // Disable buttons + enable loading icon $( this ).attr( 'disabled', 'disabled' ); form.find( 'a.sharing_cancel' ).hide(); form.find( 'img.loading' ).show(); - + $( '#sharing_email .errors' ).hide(); $( '#sharing_email .error' ).removeClass( 'error' ); - + if ( $( '#sharing_email input[name=source_email]' ).share_is_email() == false ) $( '#sharing_email input[name=source_email]' ).addClass( 'error' ); - + if ( $( '#sharing_email input[name=target_email]' ).share_is_email() == false ) $( '#sharing_email input[name=target_email]' ).addClass( 'error' ); - + if ( $( '#sharing_email .error' ).length == 0 ) { // AJAX send the form $.ajax( { @@ -212,10 +248,10 @@ } } } ); - + return false; } - + form.find( 'img.loading' ).hide(); form.find( 'input[type=submit]' ).removeAttr( 'disabled' ); form.find( 'a.sharing_cancel' ).show(); @@ -224,11 +260,11 @@ return false; } ); } - + return false; } ); } ); - + $( 'li.share-email, li.share-custom a.sharing-anchor' ).addClass( 'share-service-visible' ); } ); })( jQuery ); diff --git a/plugins/jetpack/modules/sharedaddy/sharing.php b/plugins/jetpack/modules/sharedaddy/sharing.php index 26422edc..48f30767 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing.php +++ b/plugins/jetpack/modules/sharedaddy/sharing.php @@ -312,7 +312,7 @@ class Sharing_Admin { <tr valign="top"> <th scope="row"><label><?php _e( 'Sharing label', 'jetpack' ); ?></label></th> <td> - <input type="text" name="sharing_label" value="<?php echo esc_attr( $global['sharing_label'] ); ?>" /> + <input type="text" name="sharing_label" value="<?php echo ( FALSE === $global['sharing_label'] ) ? __( 'Share this:', 'jetpack' ) : $global['sharing_label']; ?>" /> </td> </tr> <tr valign="top"> diff --git a/plugins/jetpack/modules/shortcodes.php b/plugins/jetpack/modules/shortcodes.php index 614658c2..e10805ca 100644 --- a/plugins/jetpack/modules/shortcodes.php +++ b/plugins/jetpack/modules/shortcodes.php @@ -3,6 +3,7 @@ /** * Module Name: Shortcode Embeds * Module Description: Easily embed videos and more from sites like YouTube, Vimeo, and SlideShare. + * Sort Order: 11 * First Introduced: 1.1 * Major Changes In: 1.2 */ @@ -34,16 +35,7 @@ function shortcode_new_to_old_params( $params, $old_format_support = false ) { } function jetpack_load_shortcodes() { - if ( version_compare( PHP_VERSION, 5, '<' ) ) { - $php5_only = array( 'videopress.php' => true ); - } else { - $php5_only = array(); - } - foreach ( Jetpack::glob_php( dirname( __FILE__ ) . '/shortcodes' ) as $file ) { - if ( isset( $php5_only[basename( $file )] ) ) { - continue; - } include $file; } } diff --git a/plugins/jetpack/modules/shortcodes/audio.php b/plugins/jetpack/modules/shortcodes/audio.php index ec50436a..55e8b984 100644 --- a/plugins/jetpack/modules/shortcodes/audio.php +++ b/plugins/jetpack/modules/shortcodes/audio.php @@ -1,71 +1,353 @@ <?php /** - * Shortcode for audio - * [audio http://wpcom.files.wordpress.com/2007/01/mattmullenweg-interview.mp3|width=180|titles=1|artists=2] - * - * The important question here is whether the shortcode applies to widget_text: - * add_filter('widget_text', 'do_shortcode'); - * */ +* Class wrapper for audio shortcode +*/ +class AudioShortcode { -function audio_shortcode( $atts ) { - global $ap_playerID; + static $add_script = false; + + /** + * Add all the actions & resgister the shortcode + */ + function __construct() { + add_shortcode( 'audio', array( $this, 'audio_shortcode' ) ); + add_action( 'wp_enqueue_scripts', array( $this, 'check_infinite' ) ); + add_action( 'infinite_scroll_render', array( $this, 'audio_shortcode_infinite' ), 11 ); + } - if ( ! isset( $atts[0] ) ) - return ''; + /** + * Shortcode for audio + * [audio http://wpcom.files.wordpress.com/2007/01/mattmullenweg-interview.mp3|width=180|titles=1|artists=2] + * + * The important question here is whether the shortcode applies to widget_text: + * add_filter('widget_text', 'do_shortcode'); + * */ + function audio_shortcode( $atts ) { + global $ap_playerID; + global $post; + if ( ! is_array( $atts ) ) { + return '<!-- Audio shortcode passed invalid attributes -->'; + } - if ( count( $atts ) ) - $atts[0] = strip_tags( join( ' ', $atts ) ); + if ( ! isset( $atts[0] ) ) { + return '<!-- Audio shortcode source not set -->'; + } - $src = ltrim( $atts[0], '=' ); + // add the special .js + wp_enqueue_script( + 'audio-shortcode', + plugins_url( 'js/audio-shortcode.js', __FILE__ ), + array( 'jquery' ), + '1.1', + true); - $ap_options = apply_filters( 'audio_player_default_colors', array( "bg" => "0xf8f8f8", "leftbg" => "0xeeeeee", "lefticon" => "0x666666", "rightbg" => "0xcccccc", "rightbghover" => "0x999999", "righticon" => "0x666666", "righticonhover" => "0xffffff", "text" => "0x666666", "slider" => "0x666666", "track" => "0xFFFFFF", "border" => "0x666666", "loader" => "0x9FFFB8" ) ); + // alert the infinite scroll renderer that it should try to load the script + self::$add_script = true; + $atts[0] = strip_tags( join( ' ', $atts ) ); + $src = ltrim( $atts[0], '=' ); + $ap_options = apply_filters( + 'audio_player_default_colors', + array( + "bg" => "0xF8F8F8", + "leftbg" => "0xEEEEEE", + "lefticon" => "0x666666", + "rightbg" => "0xCCCCCC", + "rightbghover" => "0x999999", + "righticon" => "0x666666", + "righticonhover" => "0xFFFFFF", + "text" => "0x666666", + "slider" => "0x666666", + "track" => "0xFFFFFF", + "border" => "0x666666", + "loader" => "0x9FFFB8" + ) ); - if ( isset( $ap_playerID ) == false ) - $ap_playerID = 1; - else - $ap_playerID++; + if ( ! isset( $ap_playerID ) ) { + $ap_playerID = 1; + } else { + $ap_playerID++; + } - $src = trim( $src, ' "' ); + if ( ! isset( $load_audio_script ) ) { + $load_audio_script = true; + } - if ( strpos( '|', $src ) ) - $options = explode( '|', $src ); - else + // prep the audio files + $src = trim( $src, ' "' ); $options = array(); + $data = preg_split( "/\|/", $src ); + $sound_file = $data[0]; + $sound_files = explode( ',', $sound_file ); + $sound_files = array_map( 'trim', $sound_files ); + $sound_files = array_map( array( $this, 'unbreak_spacey_url' ), $sound_files ); + $sound_files = array_map( 'esc_url_raw', $sound_files ); // Ensure each is a valid URL + $num_files = count( $sound_files ); + $sound_types = array( + 'mp3' => 'mpeg', + 'wav' => 'wav', + 'ogg' => 'ogg', + 'oga' => 'ogg', + 'm4a' => 'mp4', + 'aac' => 'mp4', + 'webm' => 'webm' + ); - $data = preg_split( "/[\|]/", $src ); - $flashvars = "playerID={$ap_playerID}"; + for ( $i = 1; $i < count( $data ); $i++ ) { + $pair = explode( "=", $data[$i] ); + if ( strtolower( $pair[0] ) != 'autostart' ) { + $options[$pair[0]] = $pair[1]; + } + } - for ( $i = 1; $i < count( $data ); $i++ ) { - $pair = explode( "=", $data[$i] ); - if( strtolower( $pair[0] ) != 'autostart' ) - $options[$pair[0]] = $pair[1]; - } + // Merge runtime options to default colour options + // (runtime options overwrite default options) + foreach ( $ap_options as $key => $default ) { + if ( isset( $options[$key] ) ) { + if ( preg_match( '/^0x[a-f0-9]{6}$/i', $default ) && !preg_match( '/^0x[a-f0-9]{6}$/i', $options[$key] ) ) { + // Default is a hex color, but input is not + $options[$key] = $default; + } + } else { + $options[$key] = $default; + } + } + $options['soundFile'] = join( ',', $sound_files ); // Rebuild the option with our now sanitized data + $flash_vars = array(); + foreach ( $options as $key => $value ) { + $flash_vars[] = rawurlencode( $key ) . '=' . rawurlencode( $value ); + } + $flash_vars = implode( '&', $flash_vars ); + $flash_vars = esc_attr( $flash_vars ); - // Merge runtime options to default colour options (runtime options overwrite default options) - $options = array_merge( $ap_options, $options ); - $options['soundFile'] = $data[0]; - $flash_vars = ''; - foreach ( $options as $key => $value ) { - $flash_vars .= '&' . rawurlencode( $key ) . '=' . rawurlencode( $value ); - } - $flash_vars = esc_attr( $flash_vars ); + // extract some of the options to insert into the markup + if ( isset( $options['bgcolor'] ) && preg_match( '/^0x[a-f0-9]{6}$/i', $options['bgcolor'] ) ) { + $bgcolor = preg_replace( '/^0x/', '#', $options['bgcolor'] ); + $bgcolor = esc_attr( $bgcolor ); + } else { + $bgcolor = '#FFFFFF'; + } + + if ( isset( $options['width'] ) ) { + $width = intval( $options['width'] ); + } else { + $width = 290; + } + + $loop = ''; + $script_loop = 'false'; + if ( isset( $options['loop'] ) && 'yes' == $options['loop'] ) { + $script_loop = 'true'; + if ( 1 == $num_files ) { + $loop = 'loop'; + } + } + + $volume = 0.6; + if ( isset( $options['initialvolume'] ) && + 0.0 < floatval( $options['initialvolume'] ) && + 100.0 >= floatval( $options['initialvolume'] ) ) { + + $volume = floatval( $options['initialvolume'] )/100.0; + } + + $file_artists = array_pad( array(), $num_files, '' ); + if ( isset( $options['artists'] ) ) { + $artists = preg_split( '/,/', $options['artists'] ); + foreach ( $artists as $i => $artist ) { + $file_artists[$i] = esc_html( $artist ) . ' - '; + } + } + + // generate default titles + $file_titles = array(); + for ( $i = 0; $i < $num_files; $i++ ) { + $file_titles[] = 'Track #' . ($i+1); + } + + // replace with real titles if they exist + if ( isset( $options['titles'] ) ) { + $titles = preg_split( '/,/', $options['titles'] ); + foreach ( $titles as $i => $title ) { + $file_titles[$i] = esc_html( $title ); + } + } + + // fallback for the fallback, just a download link + $not_supported = ''; + foreach ( $sound_files as $sfile ) { + $not_supported .= sprintf( + __( 'Download: <a href="%s">%s</a><br />', 'jetpack' ), + esc_url( $sfile ), + esc_html( basename( $sfile ) ) ); + } + + // HTML5 audio tag + $html5_audio = ''; + $all_mp3 = true; + $add_audio = true; + $num_good = 0; + $to_remove = array(); + foreach ( $sound_files as $i => $sfile ) { + $file_extension = pathinfo( $sfile, PATHINFO_EXTENSION ); + if ( ! preg_match( '/^(mp3|wav|ogg|oga|m4a|aac|webm)$/', $file_extension ) ) { + $html5_audio .= '<!-- Audio shortcode unsupported audio format -->'; + if ( 1 == $num_files ) { + $html5_audio .= $not_supported; + } - if ( isset( $options['bgcolor'] ) ) - $bgcolor = esc_attr( $options['bgcolor'] ); - else - $bgcolor = '#FFFFFF'; + $to_remove[] = $i; // make a note of the bad files + $all_mp3 = false; + continue; + } elseif ( ! preg_match( '/^mp3$/', $file_extension ) ) { + $all_mp3 = false; + } - if ( isset( $options['width'] ) ) - $width = intval( $options['width'] ); - else - $width = 290; + if ( 0 == $i ) { // only need one player + $html5_audio .= <<<AUDIO + <span id="wp-as-{$post->ID}_{$ap_playerID}-container"> + <audio id='wp-as-{$post->ID}_{$ap_playerID}' controls preload='none' $loop style='background-color:$bgcolor;width:{$width}px;'> + <span id="wp-as-{$post->ID}_{$ap_playerID}-nope">$not_supported</span> + </audio> + </span> + <br /> +AUDIO; + } + $num_good++; + } - $swfurl = apply_filters( 'jetpack_static_url', 'http://en.wordpress.com/wp-content/plugins/audio-player/player.swf' ); + // player controls, if needed + if ( 1 < $num_files ) { + $html5_audio .= <<<CONTROLS + <span id='wp-as-{$post->ID}_{$ap_playerID}-controls' style='display:none;'> + <a id='wp-as-{$post->ID}_{$ap_playerID}-prev' + href='javascript:audioshortcode.prev_track( "{$post->ID}_{$ap_playerID}" );' + style='font-size:1.5em;'>«</a> + | + <a id='wp-as-{$post->ID}_{$ap_playerID}-next' + href='javascript:audioshortcode.next_track( "{$post->ID}_{$ap_playerID}", true, $script_loop );' + style='font-size:1.5em;'>»</a> + </span> +CONTROLS; + } + $html5_audio .= "<span id='wp-as-{$post->ID}_{$ap_playerID}-playing'></span>"; - $obj = "<p><object type='application/x-shockwave-flash' data='$swfurl' width='$width' height='24' id='audioplayer1'><param name='movie' value='$swfurl' /><param name='FlashVars' value='{$flash_vars}' /><param name='quality' value='high' /><param name='menu' value='false' /><param name='bgcolor' value='$bgcolor' /><param name='wmode' value='opaque' /></object></p>"; + $swfurl = apply_filters( + 'jetpack_static_url', + 'http://en.wordpress.com/wp-content/plugins/audio-player/player.swf' ); - return "<span style='text-align:left;display:block;'>$obj</span>"; + // process regular flash player, inserting HTML5 tags into object as fallback + if ( $all_mp3 ) { + $audio_tags = <<<FLASH + <object id='wp-as-{$post->ID}_{$ap_playerID}-flash' type='application/x-shockwave-flash' data='$swfurl' width='$width' height='24'> + <param name='movie' value='$swfurl' /> + <param name='FlashVars' value='{$flash_vars}' /> + <param name='quality' value='high' /> + <param name='menu' value='false' /> + <param name='bgcolor' value='$bgcolor' /> + <param name='wmode' value='opaque' /> + $html5_audio + </object> +FLASH; + } else { // just HTML5 for non-mp3 versions + $audio_tags = $html5_audio; + } + + // strip out all the bad files before it reaches .js + foreach ( $to_remove as $i ) { + array_splice( $sound_files, $i, 1 ); + array_splice( $file_artists, $i, 1 ); + array_splice( $file_titles, $i, 1 ); + } + + // mashup the artist/titles for the script + $script_titles = array(); + for ( $i = 0; $i < $num_files; $i++ ) { + $script_titles[] = $file_artists[$i] . $file_titles[$i]; + + } + + // javacript to control audio + $script_files = json_encode( $sound_files ); + $script_titles = json_encode( $script_titles ); + $script = <<<SCRIPT + <script type='text/javascript'> + //<![CDATA[ + jQuery(document).on( 'ready as-script-load', function($) { + if ( typeof window.audioshortcode != 'undefined' ) { + audioshortcode.prep( + '{$post->ID}_{$ap_playerID}', + $script_files, + $script_titles, + $volume, + $script_loop ); + } + } ); + //]]> + </script> +SCRIPT; + + // add the special javascript, if needed + if ( 0 < $num_good ) { + $audio_tags .= $script; + } + return "<span style='text-align:left;display:block;'><p>$audio_tags</p></span>"; + } + + /** + * If the theme uses infinite scroll, include jquery at the start + */ + function check_infinite() { + if ( current_theme_supports( 'infinite-scroll' ) ) { + wp_enqueue_script( 'jquery' ); + } + } + + /** + * Dynamically load the .js, if needed + * + * This hooks in late (priority 11) to infinite_scroll_render to determine + * a posteriori if a shortcode has been called. + */ + function audio_shortcode_infinite() { + // only try to load if a shortcode has been called + if( self::$add_script ) { + $script_url = json_encode( esc_url_raw( plugins_url( 'js/audio-shortcode.js', __FILE__ ) ) ); + + // if the script hasn't been loaded, load it + // if the script loads successfully, fire an 'as-script-load' event + echo <<<SCRIPT + <script type='text/javascript'> + //<![CDATA[ + if ( typeof window.audioshortcode === 'undefined' ) { + var wp_as_js = document.createElement( 'script' ); + wp_as_js.type = 'text/javascript'; + wp_as_js.src = $script_url; + wp_as_js.async = true; + wp_as_js.onload = function() { + jQuery( document.body ).trigger( 'as-script-load' ); + }; + document.getElementsByTagName( 'head' )[0].appendChild( wp_as_js ); + } else { + jQuery( document.body ).trigger( 'as-script-load' ); + } + //]]> + </script> +SCRIPT; + } + } + + /** + * Fixes URLs that have been pasted with spaces: + * [audio http://example.com/Some Cool Music.mp3] + * + * @param string $url + * @return string + */ + function unbreak_spacey_url( $url ) { + return str_replace( ' ', rawurlencode( ' ' ), $url ); + } } -add_shortcode( 'audio', 'audio_shortcode' ); +// kick it all off +new AudioShortcode(); diff --git a/plugins/jetpack/modules/shortcodes/googlemaps.php b/plugins/jetpack/modules/shortcodes/googlemaps.php index deadac38..b7ee9c30 100644 --- a/plugins/jetpack/modules/shortcodes/googlemaps.php +++ b/plugins/jetpack/modules/shortcodes/googlemaps.php @@ -10,20 +10,33 @@ function jetpack_googlemaps_embed_to_short_code( $content ) { return $content; // IE and TinyMCE format things differently + // <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="<a href="https://maps.google.co.uk/maps/ms?msa=0&amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;hl=en&amp;ie=UTF8&amp;t=m&amp;ll=50.91917,-1.398808&amp;spn=0.013225,0.011794&amp;output=embed"></iframe><br">https://maps.google.co.uk/maps/ms?msa=0&amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;hl=en&amp;ie=UTF8&amp;t=m&amp;ll=50.91917,-1.398808&amp;spn=0.013225,0.011794&amp;output=embed"></iframe><br</a> /><small>View <a href="<a href="https://maps.google.co.uk/maps/ms?msa=0&amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;hl=en&amp;ie=UTF8&amp;t=m&amp;ll=50.91917,-1.398808&amp;spn=0.013225,0.011794&amp;source=embed">https://maps.google.co.uk/maps/ms?msa=0&amp;msid=206216869547772496318.0004bf5f0ff25aea47bd9&amp;hl=en&amp;ie=UTF8&amp;t=m&amp;ll=50.91917,-1.398808&amp;spn=0.013225,0.011794&amp;source=embed</a>" style="color:#0000FF;text-align:left">OARA Membership Discount Map</a> in a larger map</small> if ( strpos( $content, 'src="<a href="' ) !== false ) { - $content = preg_replace_callback( '!<iframe width="(\d+)" height="(\d+)" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="<a href="http://.*\.google\.(.*)/(.*)\?(.+)"></iframe><br">http://.*\.google\..*/(.*)\?(.+)"></iframe><br</a> /><small>(.*)</small>!i', 'jetpack_googlemaps_embed_to_short_code_callback', $content ); + $content = preg_replace_callback( '#<iframe\s[^&]*?(?:&(?!gt;)[^&]*?)*?src="<a href="https?://.*?\.google\.(.*?)/(.*?)\?(.+?)"[^&]*?(?:&(?!gt;)[^&]*?)*?>\s*</iframe><br">[^"]*?">\s*</iframe><br</a>\s*/>\s*<small>.*?</small>#i', 'jetpack_googlemaps_embed_to_short_code_callback', $content ); return $content; } - $content = preg_replace_callback( '!\<iframe width="(\d+)" height="(\d+)" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://.*\.google\.(.*)/(.*)\?(.+)"\>\</iframe\>\<br /\>\<small\>(.*)\</small\>!i', 'jetpack_googlemaps_embed_to_short_code_callback', $content ); + $content = preg_replace_callback( '!\<iframe\s[^>]*?src="https?://.*?\.google\.(.*?)/(.*?)\?(.+?)"[^>]*?\>\s*\</iframe\>\s*(?:\<br\s*/?\>)?\s*\<small\>.*?\</small\>!i', 'jetpack_googlemaps_embed_to_short_code_callback', $content ); - $content = preg_replace_callback( '!<iframe width="(\d+)" height="(\d+)" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://.*\.google\.(.*)/(.*)\?(.+)"></iframe><br /><small>(.*)</small>!i', 'jetpack_googlemaps_embed_to_short_code_callback', $content ); + $content = preg_replace_callback( '#<iframe\s[^&]*?(?:&(?!gt;)[^&]*?)*?src="https?://.*?\.google\.(.*?)/(.*?)\?(.+?)"[^&]*?(?:&(?!gt;)[^&]*?)*?>\s*</iframe>\s*(?:<br\s*/?>)?\s*<small>.*?</small>#i', 'jetpack_googlemaps_embed_to_short_code_callback', $content ); return $content; } function jetpack_googlemaps_embed_to_short_code_callback( $match ) { - $url = "http://maps.google.{$match[3]}/{$match[4]}?{$match[5]}&w={$match[1]}&h={$match[2]}"; + if ( preg_match( '/\bwidth=[\'"](\d+)/', $match[0], $width ) ) { + $width = (int) $width[1]; + } else { + $width = 425; + } + + if ( preg_match( '/\bheight=[\'"](\d+)/', $match[0], $height ) ) { + $height = (int) $height[1]; + } else { + $height = 350; + } + + $url = "https://maps.google.{$match[1]}/{$match[2]}?{$match[3]}&w={$width}&h={$height}"; do_action( 'jetpack_embed_to_shortcode', 'googlemaps', $url ); @@ -41,7 +54,7 @@ function jetpack_googlemaps_shortcode( $atts ) { $width = 425; $height = 350; - if ( preg_match( '!^http://maps\.google(\.co|\.com)?(\.[a-z]+)?/.*?(\?.+)!i', $params, $match ) ) { + if ( preg_match( '!^https?://maps\.google(\.co|\.com)?(\.[a-z]+)?/.*?(\?.+)!i', $params, $match ) ) { $params = str_replace( '&amp;', '&', $params ); $params = str_replace( '&', '&', $params ); parse_str( $params, $arg ); diff --git a/plugins/jetpack/modules/shortcodes/slide.php b/plugins/jetpack/modules/shortcodes/slide.php deleted file mode 100644 index ea668de2..00000000 --- a/plugins/jetpack/modules/shortcodes/slide.php +++ /dev/null @@ -1,121 +0,0 @@ -<?php - -/** - * slideshow and slideguest shortcodes for slide.com - * [slideshow id=2233785415202545677&w=426&h=320] - */ -function jetpack_slide_embed_to_short_code( $content ) { - global $content_width; - - if ( false === strpos( $content, 'slide.com/widgets' ) ) - return $content; - - $regexp = '!<div><embed((?:\s+\w+="[^"]*")*)\s+src="http://widget[^"]+slide\.com/widgets/slideticker\.swf"((?:\s+\w+="[^"]*")*)\s*(?:/?>|>\s*</embed>)\s*<div(?:\s+[^>]+).*?slide\.com/p1/.*?slide\.com/p2.*?</div>\s*</div>!i'; - $regexp_ent = htmlspecialchars( $regexp, ENT_NOQUOTES ); - - foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) { - if ( !preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) - continue; - - foreach ( $matches as $match ) { - $params = $match[1] . $match[2]; - if ( 'regexp_ent' == $reg ) - $params = html_entity_decode( $params ); - - $params = wp_kses_hair( $params, array( 'http' ) ); - if ( !isset( $params['type'] ) || 'application/x-shockwave-flash' != $params['type']['value'] || !isset( $params['flashvars'] ) ) - continue; - - wp_parse_str( html_entity_decode( $params['flashvars']['value'] ), $flashvars ); - - if ( empty( $flashvars['channel'] ) ) - continue; - - $id = $flashvars['channel']; - - $width = 400; - if ( ! empty( $params['width']['value'] ) ) - $width = (int) $params['width']['value']; - elseif ( ! empty( $params['style']['value'] ) && preg_match( '/width\s*:\s*(\d+)/i', $params['style']['value'], $width_match ) ) - $width = (int) $width_match[1]; - - $height = 300; - if ( ! empty( $params['height']['value'] ) ) - $height = (int) $params['height']['value']; - elseif ( ! empty( $params['style']['value'] ) && preg_match( '/height\s*:\s*(\d+)/i', $params['style']['value'], $height_match ) ) - $height = (int) $height_match[1]; - - if ( $content_width && $width > $content_width ) { - $height = intval( $height * $content_width / $width ); - $width = $content_width; - } - - $content = str_replace( $match[0], "[slideshow id={$id}&w={$width}&h={$height}]", $content ); - - do_action( 'jetpack_embed_to_shortcode', 'slideshow', $id ); - } - } - - return $content; -} -add_filter( 'pre_kses', 'jetpack_slide_embed_to_short_code' ); - -function jetpack_slideshow_shortcode( $atts, $content, $shortcode ) { - if ( - 'slideshow' == $shortcode - && - ( empty( $atts['id'] ) || false === strpos( $atts['id'], '&' ) ) - && - ( $previous_slideshow_shortcode = jetpack_slide_shortcodes( true ) ) - && - is_callable( $previous_slideshow_shortcode ) - ) { - return call_user_func( $previous_slideshow_shortcode, $atts, $content, $shortcode ); - } - - return jetpack_slide_embed( $shortcode, $atts ); -} - -function jetpack_slide_embed( $type, $atts ) { - $param = shortcode_new_to_old_params( $atts ); - - if ( ctype_digit( $param ) ) { - $id = $param; - $w = 426; - $h = 320; - } else { - parse_str( $param, $params ); - if ( count( $params ) != 3 || !isset( $params['id'] ) || !isset( $params['w'] ) || !isset( $params['h'] ) ) - return '<!-- Slide.com error: provide id, w, h -->'; - - extract( $params ); - if ( !ctype_digit( $id ) || !ctype_digit( $w ) || !ctype_digit( $h ) ) - return '<!-- Slide.com error: provide integers -->'; - } - - $partition = sprintf( '%02x', $id % 256 ); - - if ( 'slideshow' == $type ) - return "<div><embed src='http://widget-$partition.slide.com/widgets/slideticker.swf' type='application/x-shockwave-flash' quality='high' scale='noscale' salign='l' wmode='transparent' flashvars='site=widget-$partition.slide.com&channel=$id&cy=wp&il=1' width='$w' height='$h' name='flashticker' align='middle' /><div style='width: {$w}px;text-align:left;'><a href='http://www.slide.com/pivot?ad=0&tt=0&sk=0&cy=wp&th=0&id=$id&map=1' target='_blank'><img src='http://widget-$partition.slide.com/p1/$id/wp_t000_v000_a000_f00/images/xslide1.gif' border='0' ismap='ismap' /></a> <a href='http://www.slide.com/pivot?ad=0&tt=0&sk=0&cy=wp&th=0&id=$id&map=2' target='_blank'><img src='http://widget-$partition.slide.com/p2/$id/wp_t000_v000_a000_f00/images/xslide2.gif' border='0' ismap='ismap' /></a></div></div>"; - else - return "<div><embed src='http://widget-$partition.slide.com/widgets/slidemap.swf' type='application/x-shockwave-flash' quality='high' scale='noscale' salign='l' wmode='transparent' flashvars='site=widget-$partition.slide.com&channel=$id&cy=wp&il=1' width='$w' height='$h' name='flashticker' align='middle' /><div style='width:{$w}px;text-align:left;'><a href='http://www.slide.com/pivot?ad=0&tt=0&sk=0&cy=wp&th=0&id=$id&map=5' target='_blank'><img src='http://widget-$partition.slide.com/c1/$id/wp_t000_v000_a000_f00/images/xslide1.gif' border='0' ismap='ismap' /></a> <a href='http://www.slide.com/pivot?ad=0&tt=0&sk=0&cy=wp&th=0&id=$id&map=6' target='_blank'><img src='http://widget-$partition.slide.com/c2/$id/wp_t000_v000_a000_f00/images/xslide6.gif' border='0' ismap='ismap' /></a></div></div>"; - -} - -function jetpack_slide_shortcodes( $get_previous = false ) { - global $shortcode_tags; - static $previous = false; - - if ( $get_previous ) { - return $previous; - } - - if ( isset( $shortcode_tags['slideshow'] ) ) { - $previous = $shortcode_tags['slideshow']; - } - - add_shortcode( 'slideguest', 'jetpack_slideshow_shortcode' ); - add_shortcode( 'slideshow', 'jetpack_slideshow_shortcode' ); -} - -jetpack_slide_shortcodes(); diff --git a/plugins/jetpack/modules/shortcodes/videopress.php b/plugins/jetpack/modules/shortcodes/videopress.php index aa87fbd5..912ab4cf 100644 --- a/plugins/jetpack/modules/shortcodes/videopress.php +++ b/plugins/jetpack/modules/shortcodes/videopress.php @@ -561,14 +561,7 @@ class VideoPress_Video { // PHP 5.3.3 or newer can throw a warning on a bad input URI. catch that occurance just in case try { - // use the component parameter of parse_url if current version of PHP supports - if ( version_compare(PHP_VERSION, '5.1.2', '>=') ) { - return parse_url( $url, PHP_URL_HOST ); - } else { - $url_parts = parse_url( $url ); - if ( $url_parts !== false && isset( $url_parts['host'] ) ) - return $url_parts['host']; - } + return parse_url( $url, PHP_URL_HOST ); } catch (Exception $e){} return false; } diff --git a/plugins/jetpack/modules/shortcodes/youtube.php b/plugins/jetpack/modules/shortcodes/youtube.php index 139fd9e3..8417a82e 100644 --- a/plugins/jetpack/modules/shortcodes/youtube.php +++ b/plugins/jetpack/modules/shortcodes/youtube.php @@ -2,13 +2,13 @@ /** * youtube shortcode - * - * Contains shortcode + some improvements over the Embeds syntax @ + * + * Contains shortcode + some improvements over the Embeds syntax @ * http://codex.wordpress.org/Embeds - * + * * @example [youtube=http://www.youtube.com/watch?v=wq0rXGLs0YM&fs=1&hl=bg_BG] - */ - + */ + /** * Replaces YouTube embeds with YouTube shortcodes. * @@ -42,7 +42,7 @@ function youtube_embed_to_short_code( $content ) { $ifr_regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $ifr_regexp, ENT_NOQUOTES ) ); foreach ( array( 'regexp', 'regexp_ent', 'old_regexp', 'old_regexp_ent', 'ifr_regexp', 'ifr_regexp_ent' ) as $reg ) { - if ( !preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) + if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) continue; foreach ( $matches as $match ) { @@ -51,13 +51,13 @@ function youtube_embed_to_short_code( $content ) { // if it is present // YouTube changed their embed code. // Example of how it is now: -//<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object> - // As shown at the start of function, previous YouTube didn't '?' + // <object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/aP9AaD4tgBY?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object> + // As shown at the start of function, previous YouTube didn't '?' // the 1st field-value pair. if ( in_array ( $reg, array( 'ifr_regexp', 'ifr_regexp_ent' ) ) ) { $params = $match[1]; - if ( 'ifr_regexp_ent' == $reg ) + if ( 'ifr_regexp_ent' == $reg ) $params = html_entity_decode( $params ); $params = wp_kses_hair( $params, array( 'http' ) ); @@ -65,13 +65,14 @@ function youtube_embed_to_short_code( $content ) { $width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0; $height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0; $wh = ''; + if ( $width && $height ) $wh = "&w=$width&h=$height"; - + $url = esc_url_raw( "http://www.youtube.com/watch?v={$match[2]}{$wh}" ); } else { $match[1] = str_replace( '?', '&', $match[1] ); - + $url = esc_url_raw( 'http://www.youtube.com/watch?v=' . html_entity_decode( $match[1] ) ); } @@ -83,11 +84,12 @@ function youtube_embed_to_short_code( $content ) { return $content; } + add_filter('pre_kses', 'youtube_embed_to_short_code'); /** * Replaces plain-text links to YouTube videos with YouTube embeds. - * + * * @param string $content HTML content * @return string The content with embeds instead of URLs */ @@ -113,14 +115,14 @@ function youtube_sanitize_url( $url ) { $url = trim( $url, ' "' ); $url = trim( $url ); $url = str_replace( array( 'youtu.be/', '/v/', '#!v=', '&', '&' ), array( 'youtu.be/?v=', '/?v=', '?v=', '&', '&' ), $url ); - + // Replace any extra question marks with ampersands - the result of a URL like "http://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US" being passed in. $query_string_start = strpos( $url, "?" ); - + if ( false !== $query_string_start ) { $url = substr( $url, 0, $query_string_start + 1 ) . str_replace( "?", "&", substr( $url, $query_string_start + 1 ) ); } - + return $url; } @@ -133,17 +135,17 @@ function youtube_sanitize_url( $url ) { * http://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US * http://youtu.be/Rrohlqeir5E */ - + function get_youtube_id( $url ) { $url = youtube_sanitize_url( $url ); $url = parse_url( $url ); - if ( !isset( $url['query'] ) ) + if ( ! isset( $url['query'] ) ) return false; parse_str( $url['query'], $qargs ); - if ( !isset( $qargs['v'] ) ) + if ( ! isset( $qargs['v'] ) ) return false; $id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['v'] ); @@ -158,13 +160,13 @@ function youtube_id( $url ) { if ( apply_filters( 'jetpack_bail_on_shortcode', false, 'youtube' ) ) return ''; - if ( !$id = get_youtube_id( $url ) ) + if ( ! $id = get_youtube_id( $url ) ) return '<!--YouTube Error: bad URL entered-->'; $url = youtube_sanitize_url( $url ); $url = parse_url( $url ); - if ( !isset( $url['query'] ) ) + if ( ! isset( $url['query'] ) ) return false; parse_str( $url['query'], $qargs ); @@ -172,73 +174,60 @@ function youtube_id( $url ) { $agent = $_SERVER['HTTP_USER_AGENT']; // Bloglines & Google Reader handle YouTube well now, instead of // big blank space of yester year, so they can skip this treatment - if ( is_feed() && !preg_match( '#' . apply_filters( 'jetpack_shortcode_youtube_whitelist_user_agents', 'Bloglines|FeedFetcher-Google|feedburner' ) . '#i', $agent ) ) + if ( is_feed() && ! preg_match( '#' . apply_filters( 'jetpack_shortcode_youtube_whitelist_user_agents', 'Bloglines|FeedFetcher-Google|feedburner' ) . '#i', $agent ) ) return '<span style="text-align:center; display: block;"><a href="' . get_permalink() . '"><img src="http://img.youtube.com/vi/' . $id . '/2.jpg" alt="" /></a></span>'; - // calculate the width and height, taken content_width into consideration + // calculate the width and height, taking content_width into consideration global $content_width; $input_w = ( isset( $qargs['w'] ) && intval( $qargs['w'] ) ) ? intval( $qargs['w'] ) : 0; $input_h = ( isset( $qargs['h'] ) && intval( $qargs['h'] ) ) ? intval( $qargs['h'] ) : 0; - $default_width = 640; + $default_width = get_option('embed_size_w'); + + if ( empty( $default_width ) ) { + if ( ! empty( $content_width ) ) { + $default_width = $content_width; + } else { + $default_width = 640; + } + } if ( $input_w > 0 && $input_h > 0 ) { $w = $input_w; $h = $input_h; } elseif ( 0 == $input_w && 0 == $input_h ) { - if ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) - $w = ( !empty( $content_width ) ? min( $content_width, 480 ) : 480 ); - else - $w = ( !empty( $content_width ) ? min( $content_width, $default_width ) : $default_width ); - - $h = ceil( ( $w / 16 ) * 9 ) + 30; + if ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) { + $w = ( ! empty( $content_width ) ? min( $content_width, 480 ) : 480 ); + } else { + $w = ( ! empty( $content_width ) ? min( $content_width, $default_width ) : $default_width ); + $h = ceil( ( $w / 16 ) * 9 ) + 30; + } } elseif ( $input_w > 0 ) { $w = $input_w; $h = ceil( ( $w / 16 ) * 9 ) + 30; } else { - if ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) - $w = ( !empty( $content_width ) ? min( $content_width, 480 ) : 480 ); - else - $w = ( !empty( $content_width ) ? min( $content_width, $default_width ) : $default_width ); - - $h = $input_h; + if ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) { + $w = ( ! empty( $content_width ) ? min( $content_width, 480 ) : 480 ); + } else { + $w = ( ! empty( $content_width ) ? min( $content_width, $default_width ) : $default_width ); + $h = $input_h; + } } $w = (int) apply_filters( 'youtube_width', $w ); $h = (int) apply_filters( 'youtube_height', $h ); - $fmt = ''; - if ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) - $fmt = '&fmt=' . (int) $qargs['fmt']; - - if ( isset( $qargs['rel'] ) && 0 == $qargs['rel'] ) - $rel = 0; - else - $rel = 1; + $rel = ( isset( $qargs['rel'] ) && 0 == $qargs['rel'] ) ? 0 : 1; + $search = ( isset( $qargs['showsearch'] ) && 1 == $qargs['showsearch'] ) ? 1 : 0; + $info = ( isset( $qargs['showinfo'] ) && 0 == $qargs['showinfo'] ) ? 0 : 1; + $iv = ( isset( $qargs['iv_load_policy'] ) && 3 == $qargs['iv_load_policy'] ) ? 3 : 1; - if ( isset( $qargs['showsearch'] ) && 1 == $qargs['showsearch'] ) - $search = 1; - else - $search = 0; + $fmt = ( isset( $qargs['fmt'] ) && intval( $qargs['fmt'] ) ) ? '&fmt=' . (int) $qargs['fmt'] : ''; + $start = ( isset( $qargs['start'] ) && intval( $qargs['start'] ) ) ? '&start=' . (int) $qargs['start'] : ''; + $hd = ( isset( $qargs['hd'] ) && intval( $qargs['hd'] ) ) ? '&hd=' . (int) $qargs['hd'] : ''; - if ( isset( $qargs['showinfo'] ) && 0 == $qargs['showinfo'] ) - $info = 0; - else - $info = 1; - - if ( isset( $qargs['iv_load_policy'] ) && 3 == $qargs['iv_load_policy'] ) - $iv = 3; - else - $iv = 1; - - $start = ''; - if ( isset( $qargs['start'] ) && intval( $qargs['start'] ) ) - $start = '&start=' . (int) $qargs['start']; - - $hd = ''; - if ( isset( $qargs['hd'] ) && intval( $qargs['hd'] ) ) - $hd = '&hd=' . (int) $qargs['hd']; + $wmode = ( isset( $qargs['wmode'] ) && in_array( strtolower( $qargs['wmode'] ), array( 'opaque', 'window', 'transparent' ) ) ) ? $qargs['wmode'] : 'transparent'; $alignmentcss = 'text-align:center;'; if ( isset( $qargs['align'] ) ) { @@ -251,25 +240,17 @@ function youtube_id( $url ) { break; } } - - if ( isset( $qargs['wmode'] ) && in_array( strtolower( $qargs['wmode'] ), array( 'opaque', 'window', 'transparent' ) ) ) - $wmode = $qargs['wmode']; - else - $wmode = 'transparent'; - $html = "<span class='embed-youtube' style='$alignmentcss display: block;'><iframe class='youtube-player' type='text/html' width='$w' height='$h' src='" . esc_attr( "http://www.youtube.com/embed/$id?version=3&rel=$rel&fs=1$fmt&showsearch=$search&showinfo=$info&iv_load_policy=$iv$start$hd&wmode=$wmode" ) . "' frameborder='0'></iframe></span>"; + $html = "<span class='embed-youtube' style='$alignmentcss display: block;'><iframe class='youtube-player' type='text/html' width='$w' height='$h' src='" . esc_url( "http://www.youtube.com/embed/$id?version=3&rel=$rel&fs=1$fmt&showsearch=$search&showinfo=$info&iv_load_policy=$iv$start$hd&wmode=$wmode" ) . "' frameborder='0'></iframe></span>"; $html = apply_filters( 'video_embed_html', $html ); + return $html; } function youtube_shortcode( $atts ) { - if ( isset ( $atts[0] ) ) - $src = ltrim( $atts[0] , '=' ); - else - $src = shortcode_new_to_old_params( $atts ); - - return youtube_id( $src ); + return youtube_id( ( isset ( $atts[0] ) ) ? ltrim( $atts[0] , '=' ) : shortcode_new_to_old_params( $atts ) ); } + add_shortcode( 'youtube', 'youtube_shortcode' ); /** @@ -283,6 +264,7 @@ function wpcom_youtube_embed_crazy_url( $matches, $attr, $url ) { function wpcom_youtube_embed_crazy_url_init() { wp_embed_register_handler( 'wpcom_youtube_embed_crazy_url', '#http://(?:www\.)?(?:youtube.com/(?:v/|watch[/\#?])|youtu\.be/).*#i', 'wpcom_youtube_embed_crazy_url' ); } + add_action( 'init', 'wpcom_youtube_embed_crazy_url_init' ); // higher priority because we need it before auto-link and autop get to it diff --git a/plugins/jetpack/modules/shortlinks.php b/plugins/jetpack/modules/shortlinks.php index 72c336b9..98ec743d 100644 --- a/plugins/jetpack/modules/shortlinks.php +++ b/plugins/jetpack/modules/shortlinks.php @@ -2,7 +2,7 @@ /** * Module Name: WP.me Shortlinks * Module Description: Enable WP.me-powered shortlinks for all of your Posts and Pages for easier sharing. - * Sort Order 1 + * Sort Order: 10 * First Introduced: 1.1 */ diff --git a/plugins/jetpack/modules/stats.php b/plugins/jetpack/modules/stats.php index fa1feb32..32e01189 100644 --- a/plugins/jetpack/modules/stats.php +++ b/plugins/jetpack/modules/stats.php @@ -502,7 +502,6 @@ function stats_configuration_head() { } function stats_configuration_screen() { - global $wp_version; $options = stats_get_options(); $options['reg_users'] = empty( $options['reg_users'] ) ? false : true; ?> @@ -512,10 +511,8 @@ function stats_configuration_screen() { <input type='hidden' name='action' value='save_options' /> <?php wp_nonce_field( 'stats' ); ?> <table id="menu" class="form-table"> - <?php if ( version_compare( $wp_version, '3.1-RC', '>=' ) ) : ?> <tr valign="top"><th scope="row"><label for="admin_bar"><?php _e( 'Admin bar' , 'jetpack' ); ?></label></th> <td><label><input type='checkbox'<?php checked( $options['admin_bar'] ); ?> name='admin_bar' id='admin_bar' /> <?php _e( "Put a chart showing 48 hours of views in the admin bar.", 'jetpack' ); ?></label></td></tr> - <?php endif; ?> <tr valign="top"><th scope="row"><label for="reg_users"><?php _e( 'Registered users', 'jetpack' ); ?></label></th> <td><label><input type='checkbox'<?php checked( $options['reg_users'] ); ?> name='reg_users' id='reg_users' /> <?php _e( "Count the page views of registered users who are logged in.", 'jetpack' ); ?></label></td></tr> <tr valign="top"><th scope="row"><?php _e( 'Smiley' , 'jetpack' ); ?></th> diff --git a/plugins/jetpack/modules/subscriptions.php b/plugins/jetpack/modules/subscriptions.php index f1ca95e6..2355867e 100644 --- a/plugins/jetpack/modules/subscriptions.php +++ b/plugins/jetpack/modules/subscriptions.php @@ -2,9 +2,21 @@ /** * Module Name: Subscriptions * Module Description: Allow users to subscribe to your posts and comments to receive a notification via email. - * Sort Order: 1 + * Sort Order: 3 * First Introduced: 1.2 */ + +add_action( 'jetpack_modules_loaded', 'jetpack_subscriptions_load' ); + +function jetpack_subscriptions_load() { + Jetpack::enable_module_configurable( __FILE__ ); + Jetpack::module_configuration_load( __FILE__, 'jetpack_subscriptions_configuration_load' ); +} + +function jetpack_subscriptions_configuration_load() { + wp_safe_redirect( admin_url( 'options-discussion.php#jetpack-subscriptions-settings' ) ); + exit; +} class Jetpack_Subscriptions { var $jetpack = false; @@ -12,7 +24,7 @@ class Jetpack_Subscriptions { * Singleton * @static */ - function &init() { + function init() { static $instance = false; if ( !$instance ) { @@ -28,6 +40,9 @@ class Jetpack_Subscriptions { add_filter( 'jetpack_xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); // @todo remove sync from subscriptions and move elsewhere... + + // Add Configuration Page + add_action( 'admin_init', array( $this, 'configure' ) ); // Handle Posts add_action( 'transition_post_status', array( $this, 'transition_post_status' ), 10, 3 ); @@ -151,8 +166,87 @@ class Jetpack_Subscriptions { * * Jetpack Subscriptions configuration screen. */ - function configure() { - echo '<p>This is the configuration page for the Subscriptions Module.</p>'; + function configure() { + // Create the section + add_settings_section( + 'jetpack_subscriptions', + __( 'Jetpack Subscriptions Settings', 'jetpack' ), + array( $this, 'subscriptions_settings_section' ), + 'discussion' + ); + + /** Subscribe to Posts ***************************************************/ + + add_settings_field( + 'jetpack_subscriptions_post_subscribe', + __( 'Follow Blog', 'jetpack' ), + array( $this, 'subscription_post_subscribe_setting' ), + 'discussion', + 'jetpack_subscriptions' + ); + + register_setting( + 'discussion', + 'stb_enabled' + ); + + /** Subscribe to Comments ******************************************************/ + + add_settings_field( + 'jetpack_subscriptions_comment_subscribe', + __( 'Follow Comments', 'jetpack' ), + array( $this, 'subscription_comment_subscribe_setting' ), + 'discussion', + 'jetpack_subscriptions' + ); + + register_setting( + 'discussion', + 'stc_enabled' + ); + } + + /** + * Discussions setting section blurb + * + */ + function subscriptions_settings_section() { + ?> + + <p id="jetpack-subscriptions-settings"><?php _e( 'Change whether your visitors can subscribe to your posts or comments or both.', 'jetpack' ); ?></p> + + <?php + } + + /** + * Post Subscriptions Toggle + * + */ + function subscription_post_subscribe_setting() { + + $stb_enabled = get_option( 'stb_enabled', 1 ); ?> + + <p class="description"> + <input type="checkbox" name="stb_enabled" id="jetpack-post-subscribe" value="1" <?php checked( $stb_enabled, 1 ); ?> /> + <?php _e( "Show a <em>'follow blog'</em> option in the comment form", 'jetpack' ); ?> + </p> + <?php + } + + /** + * Comments Subscriptions Toggle + * + */ + function subscription_comment_subscribe_setting() { + + $stc_enabled = get_option( 'stc_enabled', 1 ); ?> + + <p class="description"> + <input type="checkbox" name="stc_enabled" id="jetpack-comment-subscribe" value="1" <?php checked( $stc_enabled, 1 ); ?> /> + <?php _e( "Show a <em>'follow comments'</em> option in the comment form", 'jetpack' ); ?> + </p> + + <?php } /** diff --git a/plugins/jetpack/modules/vaultpress.php b/plugins/jetpack/modules/vaultpress.php index 4b6b70e1..7df1913a 100644 --- a/plugins/jetpack/modules/vaultpress.php +++ b/plugins/jetpack/modules/vaultpress.php @@ -3,7 +3,7 @@ * Module Name: VaultPress * Module Description: Realtime backup and security scanning for your WordPress site. * First Introduced: 0:1.2 - * Sort Order: 2 + * Sort Order: 5 * Deactivate: false * Free: false */ diff --git a/plugins/jetpack/modules/widgets.php b/plugins/jetpack/modules/widgets.php index d12c8b67..43793864 100644 --- a/plugins/jetpack/modules/widgets.php +++ b/plugins/jetpack/modules/widgets.php @@ -2,7 +2,7 @@ /** * Module Name: Extra Sidebar Widgets * Module Description: Easily add images, Twitter updates, and your site's RSS links to your theme's sidebar. - * Sort Order: 20 + * Sort Order: 9 * First Introduced: 1.2 */ |