diff options
Diffstat (limited to 'plugins/jetpack/modules')
10 files changed, 348 insertions, 46 deletions
diff --git a/plugins/jetpack/modules/carousel/jetpack-carousel.js b/plugins/jetpack/modules/carousel/jetpack-carousel.js index b32cc843..dbb83150 100644 --- a/plugins/jetpack/modules/carousel/jetpack-carousel.js +++ b/plugins/jetpack/modules/carousel/jetpack-carousel.js @@ -445,6 +445,11 @@ jQuery(document).ready(function($) { return; } + // skip if the container is not a link + if ( 'undefined' === typeof( $( container ).attr( 'href' ) ) ) { + return; + } + var valid = false; // if link points to 'Media File' (ignoring GET parameters) and flag is set allow it diff --git a/plugins/jetpack/modules/markdown.php b/plugins/jetpack/modules/markdown.php index b173ffb1..e572eff3 100644 --- a/plugins/jetpack/modules/markdown.php +++ b/plugins/jetpack/modules/markdown.php @@ -13,3 +13,17 @@ */ include dirname( __FILE__ ) . '/markdown/easy-markdown.php'; + +/** + * Remove checkbox set in modules/markdown/easy-markdown.php. + * We don't just remove the register_setting call there because the checkbox is + * needed on WordPress.com, where the file is sync'ed verbatim. + */ +function jetpack_markdown_posting_always_on() { + // why oh why isn't there a remove_settings_field? + global $wp_settings_fields; + if ( isset( $wp_settings_fields['writing']['default'][ WPCom_Markdown::POST_OPTION ] ) ) { + unset( $wp_settings_fields['writing']['default'][ WPCom_Markdown::POST_OPTION ] ); + } +} +add_action( 'admin_init', 'jetpack_markdown_posting_always_on', 11 ); diff --git a/plugins/jetpack/modules/sharedaddy/sharing-service.php b/plugins/jetpack/modules/sharedaddy/sharing-service.php index f89d8592..a3a3e6d8 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing-service.php +++ b/plugins/jetpack/modules/sharedaddy/sharing-service.php @@ -548,9 +548,6 @@ function sharing_add_footer() { ); wp_localize_script( 'sharing-js', 'sharing_js_options', $sharing_js_options); } -} - -function sharing_add_footer_scripts_inline() { $sharer = new Sharing_Service(); $enabled = $sharer->get_blog_services(); foreach ( array_merge( $enabled['visible'], $enabled['hidden'] ) AS $service ) { @@ -779,9 +776,6 @@ function sharing_display( $text = '', $echo = false ) { // Enqueue scripts for the footer add_action( 'wp_footer', 'sharing_add_footer' ); - - // Print inline scripts that depend on jQuery - add_action( 'wp_footer', 'sharing_add_footer_scripts_inline', 25 ); } } diff --git a/plugins/jetpack/modules/sso.php b/plugins/jetpack/modules/sso.php index 43134477..578e7538 100644 --- a/plugins/jetpack/modules/sso.php +++ b/plugins/jetpack/modules/sso.php @@ -31,8 +31,8 @@ class Jetpack_SSO { add_action( 'init', array( $this, 'maybe_logout_user' ), 5 ); add_action( 'jetpack_modules_loaded', array( $this, 'module_configure_button' ) ); add_action( 'login_form_logout', array( $this, 'store_wpcom_profile_cookies_on_logout' ) ); - add_action( 'wp_login', array( 'Jetpack_SSO', 'clear_wpcom_profile_cookies' ) ); add_action( 'jetpack_unlinked_user', array( $this, 'delete_connection_for_user') ); + add_action( 'wp_login', array( 'Jetpack_SSO', 'clear_cookies_after_login' ) ); // Adding this action so that on login_init, the action won't be sanitized out of the $action global. add_action( 'login_form_jetpack-sso', '__return_true' ); @@ -554,6 +554,44 @@ class Jetpack_SSO { } } + /** + * Clear cookies that are no longer needed once the user has logged in. + * + * @since 4.8.0 + */ + static function clear_cookies_after_login() { + self::clear_wpcom_profile_cookies(); + if ( isset( $_COOKIE[ 'jetpack_sso_nonce' ] ) ) { + setcookie( + 'jetpack_sso_nonce', + ' ', + time() - YEAR_IN_SECONDS, + COOKIEPATH, + COOKIE_DOMAIN + ); + } + + if ( isset( $_COOKIE[ 'jetpack_sso_original_request' ] ) ) { + setcookie( + 'jetpack_sso_original_request', + ' ', + time() - YEAR_IN_SECONDS, + COOKIEPATH, + COOKIE_DOMAIN + ); + } + + if ( isset( $_COOKIE[ 'jetpack_sso_redirect_to' ] ) ) { + setcookie( + 'jetpack_sso_redirect_to', + ' ', + time() - YEAR_IN_SECONDS, + COOKIEPATH, + COOKIE_DOMAIN + ); + } + } + static function delete_connection_for_user( $user_id ) { if ( ! $wpcom_user_id = get_user_meta( $user_id, 'wpcom_user_id', true ) ) { return; @@ -577,17 +615,33 @@ class Jetpack_SSO { } static function request_initial_nonce() { - Jetpack::load_xml_rpc_client(); - $xml = new Jetpack_IXR_Client( array( - 'user_id' => get_current_user_id(), - ) ); - $xml->query( 'jetpack.sso.requestNonce' ); + $nonce = ! empty( $_COOKIE[ 'jetpack_sso_nonce' ] ) + ? $_COOKIE[ 'jetpack_sso_nonce' ] + : false; - if ( $xml->isError() ) { - return new WP_Error( $xml->getErrorCode(), $xml->getErrorMessage() ); + if ( ! $nonce ) { + Jetpack::load_xml_rpc_client(); + $xml = new Jetpack_IXR_Client( array( + 'user_id' => get_current_user_id(), + ) ); + $xml->query( 'jetpack.sso.requestNonce' ); + + if ( $xml->isError() ) { + return new WP_Error( $xml->getErrorCode(), $xml->getErrorMessage() ); + } + + $nonce = $xml->getResponse(); + + setcookie( + 'jetpack_sso_nonce', + $nonce, + time() + ( 10 * MINUTE_IN_SECONDS ), + COOKIEPATH, + COOKIE_DOMAIN + ); } - return $xml->getResponse(); + return sanitize_key( $nonce ); } /** @@ -727,8 +781,6 @@ class Jetpack_SSO { if ( ! empty( $_COOKIE['jetpack_sso_redirect_to'] ) ) { // Set that as the requested redirect to $redirect_to = $_request_redirect_to = esc_url_raw( $_COOKIE['jetpack_sso_redirect_to'] ); - // And then purge it - setcookie( 'jetpack_sso_redirect_to', ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); } $json_api_auth_environment = Jetpack_SSO_Helpers::get_json_api_auth_environment(); diff --git a/plugins/jetpack/modules/videopress/class.videopress-xmlrpc.php b/plugins/jetpack/modules/videopress/class.videopress-xmlrpc.php index 72e88c8f..6537b438 100644 --- a/plugins/jetpack/modules/videopress/class.videopress-xmlrpc.php +++ b/plugins/jetpack/modules/videopress/class.videopress-xmlrpc.php @@ -155,18 +155,21 @@ class VideoPress_XMLRPC { return false; } + // We add ssl => 1 to make sure that the videos.files.wordpress.com domain is parsed as photon. + $poster = apply_filters( 'jetpack_photon_url', $poster, array( 'ssl' => 1 ), 'https' ); + + $meta = wp_get_attachment_metadata( $post_id ); + $meta['videopress']['poster'] = $poster; + wp_update_attachment_metadata( $post_id, $meta ); + // Update the poster in the VideoPress info. $thumbnail_id = videopress_download_poster_image( $poster, $post_id ); - if ( !is_int( $thumbnail_id ) ) { + if ( ! is_int( $thumbnail_id ) ) { return false; } update_post_meta( $post_id, '_thumbnail_id', $thumbnail_id ); - $meta = wp_get_attachment_metadata( $post_id ); - - $meta['videopress']['poster'] = $poster; - wp_update_attachment_metadata( $post_id, $meta ); return true; } diff --git a/plugins/jetpack/modules/videopress/utility-functions.php b/plugins/jetpack/modules/videopress/utility-functions.php index c6903165..e9f597a5 100644 --- a/plugins/jetpack/modules/videopress/utility-functions.php +++ b/plugins/jetpack/modules/videopress/utility-functions.php @@ -558,17 +558,22 @@ function videopress_make_media_upload_path( $blog_id ) { function video_get_info_by_blogpostid( $blog_id, $post_id ) { $post = get_post( $post_id ); + $video_info = new stdClass(); + $video_info->post_id = $post_id; + $video_info->blog_id = $blog_id; + $video_info->guid = null; + $video_info->finish_date_gmt = '0000-00-00 00:00:00'; + if ( is_wp_error( $post ) ) { - return false; + return $video_info; } if ( 'video/videopress' !== $post->post_mime_type ) { - return false; + return $video_info; } - $video_info = new stdClass(); + // Since this is a VideoPress post, lt's fill out the rest of the object. $video_info->guid = get_post_meta( $post_id, 'videopress_guid', true ); - $video_info->finish_date_gmt = '0000-00-00 00:00:00'; if ( videopress_is_finished_processing( $post_id ) ) { $video_info->finish_date_gmt = date( 'Y-m-d H:i:s' ); @@ -576,3 +581,118 @@ function video_get_info_by_blogpostid( $blog_id, $post_id ) { return $video_info; } + + +/** + * Check that a VideoPress video format has finished processing. + * + * This uses the info object, because that is what the WPCOM endpoint + * uses, however we don't have a complete info object in the same way + * WPCOM does, so we pull the meta information out of the post + * options instead. + * + * Note: This mimics the WPCOM function of the same name and helps the media + * API endpoint add all needed VideoPress data. + * + * @param stdClass $info + * @param string $format + * @return bool + */ +function video_format_done( $info, $format ) { + + // Avoids notice when a non-videopress item is found. + if ( ! is_object( $info ) ) { + return false; + } + + $post_id = $info->post_id; + + if ( get_post_mime_type( $post_id ) !== 'video/videopress' ) { + return false; + } + + $post = get_post( $post_id ); + + if ( is_wp_error( $post ) ) { + return false; + } + + $meta = wp_get_attachment_metadata( $post->ID ); + + switch ( $format ) { + case 'fmt_hd': + return isset( $meta['videopress']['files']['hd']['mp4'] ); + break; + + case 'fmt_dvd': + return isset( $meta['videopress']['files']['dvd']['mp4'] ); + break; + + case 'fmt_std': + return isset( $meta['videopress']['files']['std']['mp4'] ); + break; + + case 'fmt_ogg': + return isset( $meta['videopress']['files']['std']['ogg'] ); + break; + } + + return false; +} + +/** + * Get the image URL for the given VideoPress GUID + * + * We look up by GUID, because that is what WPCOM does and this needs to be + * parameter compatible with that. + * + * Note: This mimics the WPCOM function of the same name and helps the media + * API endpoint add all needed VideoPress data. + * + * @param string $guid + * @param string $format + * @return string + */ +function video_image_url_by_guid( $guid, $format ) { + + $post = video_get_post_by_guid( $guid ); + + if ( is_wp_error( $post ) ) { + return null; + } + + $meta = wp_get_attachment_metadata( $post->ID ); + + // We add ssl => 1 to make sure that the videos.files.wordpress.com domain is parsed as photon. + $poster = apply_filters( 'jetpack_photon_url', $meta['videopress']['poster'], array( 'ssl' => 1 ), 'https' ); + + return $poster; +} + +/** + * Using a GUID, find a post. + * + * @param string $guid + * @return WP_Post + */ +function video_get_post_by_guid( $guid ) { + $args = array( + 'post_type' => 'attachment', + 'post_mime_type' => 'video/videopress', + 'post_status' => 'inherit', + 'meta_query' => array( + array( + 'key' => 'videopress_guid', + 'value' => $guid, + 'compare' => '=', + ) + ) + ); + + $query = new WP_Query( $args ); + + $post = $query->next_post(); + + return $post; +} + diff --git a/plugins/jetpack/modules/widget-visibility/widget-conditions.php b/plugins/jetpack/modules/widget-visibility/widget-conditions.php index 9f65b08d..f2492c4c 100644 --- a/plugins/jetpack/modules/widget-visibility/widget-conditions.php +++ b/plugins/jetpack/modules/widget-visibility/widget-conditions.php @@ -91,13 +91,17 @@ class Jetpack_Widget_Conditions { $post_types = get_post_types( array( 'public' => true ), 'objects' ); $widget_conditions_post_types = array(); + $widget_conditions_post_type_archives = array(); foreach ( $post_types as $post_type ) { $widget_conditions_post_types[] = array( 'post_type-' . $post_type->name, $post_type->labels->singular_name ); + $widget_conditions_post_type_archives[] = array( 'post_type_archive-' . $post_type->name, $post_type->labels->name ); } $widget_conditions_data['page'][] = array( __( 'Post type:', 'jetpack' ), $widget_conditions_post_types ); + $widget_conditions_data['page'][] = array( __( 'Post type Archives:', 'jetpack' ), $widget_conditions_post_type_archives ); + $pages_dropdown = preg_replace( '/<\/?select[^>]*?>/i', '', wp_dropdown_pages( array( 'echo' => false ) ) ); preg_match_all( '/value=.([0-9]+).[^>]*>([^<]+)</', $pages_dropdown, $page_ids_and_titles, PREG_SET_ORDER ); @@ -490,6 +494,8 @@ class Jetpack_Widget_Conditions { default: if ( substr( $rule['minor'], 0, 10 ) == 'post_type-' ) { $condition_result = is_singular( substr( $rule['minor'], 10 ) ); + } elseif ( substr( $rule['minor'], 0, 18 ) == 'post_type_archive-' ) { + $condition_result = is_post_type_archive( substr( $rule['minor'], 18 ) ); } elseif ( $rule['minor'] == get_option( 'page_for_posts' ) ) { // If $rule['minor'] is a page ID which is also the posts page $condition_result = $wp_query->is_posts_page; @@ -690,6 +696,76 @@ class Jetpack_Widget_Conditions { return $term_id; } + + /** + * Upgrade routine to go through all widgets and move the Post Type + * setting to its newer location. + * + * @since 4.7.1 + * + */ + static function migrate_post_type_rules() { + global $wp_registered_widgets; + + $sidebars_widgets = get_option( 'sidebars_widgets' ); + + // Going through all sidebars and through inactive and orphaned widgets + foreach ( $sidebars_widgets as $s => $sidebar ) { + if ( ! is_array( $sidebar ) ) { + continue; + } + + foreach ( $sidebar as $w => $widget ) { + // $widget is the id of the widget + if ( empty( $wp_registered_widgets[ $widget ] ) ) { + continue; + } + + $opts = $wp_registered_widgets[ $widget ]; + $instances = get_option( $opts['callback'][0]->option_name ); + + // Going through each instance of the widget + foreach( $instances as $number => $instance ) { + if ( + ! is_array( $instance ) || + empty( $instance['conditions'] ) || + empty( $instance['conditions']['rules'] ) + ) { + continue; + } + + // Going through all visibility rules + foreach( $instance['conditions']['rules'] as $index => $rule ) { + + // We only need Post Type rules + if ( 'post_type' !== $rule['major'] ) { + continue; + } + + $rule_type = false; + + // Post type or type archive rule + if ( 0 === strpos( $rule['minor'], 'post_type_archive' ) ) { + $rule_type = 'post_type_archive'; + } else if ( 0 === strpos( $rule['minor'], 'post_type' ) ) { + $rule_type = 'post_type'; + } + + if ( $rule_type ) { + $post_type = substr( $rule['minor'], strlen( $rule_type ) + 1 ); + $rule['minor'] = $rule_type . '-' . $post_type; + $rule['major'] = 'page'; + + $instances[ $number ]['conditions']['rules'][ $index ] = $rule; + } + } + } + + update_option( $opts['callback'][0]->option_name, $instances ); + } + } + } + } add_action( 'init', array( 'Jetpack_Widget_Conditions', 'init' ) ); diff --git a/plugins/jetpack/modules/widget-visibility/widget-conditions/rtl/widget-conditions-rtl.css b/plugins/jetpack/modules/widget-visibility/widget-conditions/rtl/widget-conditions-rtl.css index 94cf4502..d2770de6 100644 --- a/plugins/jetpack/modules/widget-visibility/widget-conditions/rtl/widget-conditions-rtl.css +++ b/plugins/jetpack/modules/widget-visibility/widget-conditions/rtl/widget-conditions-rtl.css @@ -1,10 +1,7 @@ -/* This file was automatically generated on Jul 14 2014 00:47:30 */ - +/* Do not modify this file directly. It is concatenated from individual module CSS files. */ .wp-customizer .expanded .widget-conditional .widget-conditional-inner { - width: 98%; - -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */ - -moz-box-sizing: border-box; /* Firefox, other Gecko */ - box-sizing: border-box; + width: 98%; /* Safari/Chrome, other WebKit */ /* Firefox, other Gecko */ + box-sizing: border-box; } .wp-customizer .expanded .widget-conditional .form{ @@ -35,9 +32,12 @@ } .widget-conditional .condition { padding-top: 12px; + position: relative; } .widget-conditional .condition select { width: 120px; + position: relative; + z-index: 2; } .widget-conditional .condition-top select { width: auto; @@ -48,22 +48,51 @@ margin-top: -20px; } .widget-conditional .selection { - margin-left: 70px; + margin-left: 50px; + margin-right: 20px; +} +.widget-conditional .conditions-rule-has-children { + display: block; } .widget-conditional .condition .actions { margin-top: -28px; +}.widget-conditional .condition .actions { + margin-top: -28px; } .widget-conditional .condition-control a { text-decoration: none; + position: absolute; + top: 17px; + text-indent: -9999px; + z-index: 1; +} +.widget-conditional .condition-control a:before { + position: absolute; + text-indent: 0; + right: 0; } -.widget-conditional .condition:last-child .condition-conjunction { +.widget-conditional .condition-control .delete-condition { + right: 0; + color: #f11; +} +.widget-conditional .condition-control .add-condition { + left: 0; +} + +.widget-conditional .condition:last-child .condition-conjunction, +.widget-conditional .condition:last-child .condition-intersection { display: none; } -.widget-control-actions .alignright { - text-align: left; - color:#999; + +.widget-conditional.conjunction .condition-intersection { + display: none; +} + +.widget-conditional.intersection .condition-conjunction { + display: none; } + .wp-core-ui .button.display-options { margin-left: 5px; } @@ -76,3 +105,11 @@ max-width: none; height: auto; } +.wp-customizer .widget-conditional .condition-control a { + top: 15px; +} +@media screen and ( max-width: 782px ) { + .widget-conditional .condition-control a { + top: 20px; + } +} diff --git a/plugins/jetpack/modules/widget-visibility/widget-conditions/widget-conditions.js b/plugins/jetpack/modules/widget-visibility/widget-conditions/widget-conditions.js index 9217e67a..658c4270 100644 --- a/plugins/jetpack/modules/widget-visibility/widget-conditions/widget-conditions.js +++ b/plugins/jetpack/modules/widget-visibility/widget-conditions/widget-conditions.js @@ -200,7 +200,10 @@ jQuery( function( $ ) { select = condition.find( '.conditions-rule-minor' ).html( '' ), major = condition.data( 'rule-major' ); - if ( ! major ) { + // Disable the select, if major rule is empty or if it's a `post_type`. + // "Post Type" rule has been removed in Jetpack 4.7, and + // because it breaks all other rules we should `return`. + if ( ! major || 'post_type' === major ) { select.attr( 'disabled', 'disabled' ); return; } diff --git a/plugins/jetpack/modules/widgets/image-widget.php b/plugins/jetpack/modules/widgets/image-widget.php index 82039e7d..10ba8ccd 100644 --- a/plugins/jetpack/modules/widgets/image-widget.php +++ b/plugins/jetpack/modules/widgets/image-widget.php @@ -69,14 +69,7 @@ class Jetpack_Image_Widget extends WP_Widget { if ( '' != $instance['img_url'] ) { - $image_url = Jetpack::is_module_active( 'photon' ) - ? jetpack_photon_url( $instance['img_url'], array( - 'w' => $instance['img_width'], - 'h' => $instance['img_height'], - ) ) - : $instance['img_url']; - - $output = '<img src="' . esc_url( $image_url ) . '" '; + $output = '<img src="' . esc_url( $instance['img_url'] ) . '" '; if ( '' != $instance['alt_text'] ) { $output .= 'alt="' . esc_attr( $instance['alt_text'] ) .'" '; @@ -94,6 +87,11 @@ class Jetpack_Image_Widget extends WP_Widget { $output .= 'height="' . esc_attr( $instance['img_height'] ) .'" '; } $output .= '/>'; + + if ( class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) ) { + $output = Jetpack_Photon::filter_the_content( $output ); + } + if ( '' != $instance['link'] ) { $target = ! empty( $instance['link_target_blank'] ) ? 'target="_blank"' |