From 097e7d91b32dd6d27ea47e5d7cd8d6bdcf1e50a2 Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Mon, 18 Apr 2016 11:52:28 -0400 Subject: Update plugin jetpack to 3.9.6 --- .../jetpack/modules/carousel/jetpack-carousel.js | 40 +- plugins/jetpack/modules/comments/comments.php | 11 +- .../modules/contact-form/grunion-contact-form.php | 81 ++- .../modules/contact-form/js/grunion-frontend.js | 4 +- plugins/jetpack/modules/custom-content-types.php | 2 +- plugins/jetpack/modules/custom-css/custom-css.php | 2 +- .../jetpack/modules/custom-post-types/comics.php | 1 + .../modules/custom-post-types/js/many-items.js | 2 +- .../modules/custom-post-types/portfolios.php | 1 + .../modules/custom-post-types/testimonial.php | 1 + .../jetpack/modules/infinite-scroll/infinity.js | 72 ++- .../jetpack/modules/infinite-scroll/infinity.php | 167 +------ plugins/jetpack/modules/latex.php | 17 +- plugins/jetpack/modules/manage/confirm-admin.php | 4 +- plugins/jetpack/modules/minileven.php | 4 +- plugins/jetpack/modules/module-headings.php | 549 ++++++++++++--------- plugins/jetpack/modules/module-info.php | 132 +++-- plugins/jetpack/modules/monitor.php | 20 + plugins/jetpack/modules/post-by-email.php | 2 +- plugins/jetpack/modules/protect.php | 4 +- plugins/jetpack/modules/publicize/ui.php | 6 +- .../related-posts/jetpack-related-posts.php | 16 +- .../jetpack/modules/related-posts/related-posts.js | 3 +- .../modules/sharedaddy/images/smart-twitter.png | Bin 2945 -> 1952 bytes .../modules/sharedaddy/images/smart-twitter@2x.png | Bin 2686 -> 1691 bytes plugins/jetpack/modules/shortcodes/archives.php | 54 +- plugins/jetpack/modules/shortcodes/codepen.php | 10 + plugins/jetpack/modules/shortcodes/dailymotion.php | 2 +- plugins/jetpack/modules/shortcodes/facebook.php | 16 +- plugins/jetpack/modules/shortcodes/flickr.php | 73 +-- plugins/jetpack/modules/shortcodes/gist.php | 82 ++- plugins/jetpack/modules/shortcodes/houzz.php | 29 ++ plugins/jetpack/modules/shortcodes/instagram.php | 51 +- plugins/jetpack/modules/shortcodes/js/facebook.js | 29 -- .../modules/shortcodes/js/slideshow-shortcode.js | 5 + .../jetpack/modules/shortcodes/presentations.php | 237 +++++---- plugins/jetpack/modules/shortcodes/scribd.php | 8 +- plugins/jetpack/modules/shortcodes/slideshare.php | 87 ++-- plugins/jetpack/modules/shortcodes/slideshow.php | 3 +- plugins/jetpack/modules/shortcodes/soundcloud.php | 140 +++--- plugins/jetpack/modules/shortcodes/ted.php | 40 +- .../modules/shortcodes/twitter-timeline.php | 31 +- plugins/jetpack/modules/shortcodes/vimeo.php | 149 ++++-- plugins/jetpack/modules/shortcodes/wufoo.php | 91 ++-- plugins/jetpack/modules/shortcodes/youtube.php | 40 +- plugins/jetpack/modules/sitemaps/sitemap-xsl.php | 11 +- plugins/jetpack/modules/sitemaps/sitemaps.php | 142 +++--- plugins/jetpack/modules/sso.php | 9 +- plugins/jetpack/modules/stats.php | 39 +- .../modules/subscriptions/subscriptions.css | 1 - .../modules/theme-tools/compat/twentyfifteen.php | 2 +- .../modules/theme-tools/compat/twentysixteen.php | 2 +- .../modules/theme-tools/random-redirect.php | 25 +- .../modules/theme-tools/responsive-videos.php | 1 + .../responsive-videos/responsive-videos.js | 2 +- plugins/jetpack/modules/theme-tools/site-logo.php | 8 +- .../theme-tools/site-logo/inc/class-site-logo.php | 5 + .../theme-tools/site-logo/inc/functions.php | 4 +- .../theme-tools/site-logo/js/site-logo-control.js | 9 +- .../tiled-gallery/templates/carousel-container.php | 1 + .../tiled-gallery/templates/partials/item.php | 15 +- plugins/jetpack/modules/videopress/videopress.php | 6 +- .../widget-visibility/widget-conditions.php | 8 +- .../widget-conditions/widget-conditions.js | 14 +- plugins/jetpack/modules/widgets/contact-info.php | 40 +- .../widgets/contact-info/contact-info-map.js | 38 +- .../jetpack/modules/widgets/facebook-likebox.php | 85 +--- .../jetpack/modules/widgets/social-media-icons.php | 7 +- plugins/jetpack/modules/widgets/top-posts.php | 156 +++++- .../jetpack/modules/widgets/twitter-timeline.php | 34 +- .../modules/widgets/wordpress-post-widget.php | 54 +- 71 files changed, 1806 insertions(+), 1230 deletions(-) create mode 100644 plugins/jetpack/modules/shortcodes/codepen.php create mode 100644 plugins/jetpack/modules/shortcodes/houzz.php delete mode 100644 plugins/jetpack/modules/shortcodes/js/facebook.js (limited to 'plugins/jetpack/modules') diff --git a/plugins/jetpack/modules/carousel/jetpack-carousel.js b/plugins/jetpack/modules/carousel/jetpack-carousel.js index 95b6c4b0..a4b6aac4 100644 --- a/plugins/jetpack/modules/carousel/jetpack-carousel.js +++ b/plugins/jetpack/modules/carousel/jetpack-carousel.js @@ -86,7 +86,7 @@ jQuery(document).ready(function($) { buttons = $(''); - caption = $('

'); + caption = $('

'); photo_info = $('').append(caption); imageMeta = $('
') @@ -226,11 +226,14 @@ jQuery(document).ready(function($) { container = $('
') .addClass('jp-carousel-wrap') .addClass( 'jp-carousel-transitions' ); - if ( 'white' === jetpackCarouselStrings.background_color ) { container.addClass('jp-carousel-light'); } + container.attr('itemscope', ''); + + container.attr('itemtype', 'http://schema.org/ImageGallery'); + container.css({ 'position' : 'fixed', 'top' : 0, @@ -902,7 +905,7 @@ jQuery(document).ready(function($) { .css( 'width', '100%' ) .css( 'height', '100%' ); - var slide = $('') + var slide = $('') .hide() .css({ //'position' : 'fixed', @@ -987,7 +990,7 @@ jQuery(document).ready(function($) { if ( medium_width >= args.max_width || medium_height >= args.max_height ) { return args.medium_file; } - + if ( isPhotonUrl ) { // args.orig_file doesn't point to a Photon url, so in this case we use args.large_file // to return the photon url of the original image. @@ -1016,7 +1019,7 @@ jQuery(document).ready(function($) { if ( '9999' === size_parts[0] ) { size_parts[0] = '0'; } - + if ( '9999' === size_parts[1] ) { size_parts[1] = '0'; } @@ -1230,12 +1233,23 @@ jQuery(document).ready(function($) { if(!current || !current.data) { return false; } - var original = current.data('orig-file').replace(/\?.+$/, ''), - origSize = current.data('orig-size').split(','), - permalink = $( ''+gallery.jp_carousel('format', {'text': jetpackCarouselStrings.download_original, 'replacements': origSize})+'' ) - .addClass( 'jp-carousel-image-download' ) - .attr( 'href', original ) - .attr( 'target', '_blank' ); + var original, + origSize = current.data('orig-size').split(',' ), + imageLinkParser = document.createElement( 'a' ); + + imageLinkParser.href = current.data( 'src' ).replace( /\?.+$/, '' ); + + // Is this a Photon URL? + if ( imageLinkParser.hostname.match( /^i[\d]{1}.wp.com$/i ) !== null ) { + original = imageLinkParser.href; + } else { + original = current.data('orig-file').replace(/\?.+$/, ''); + } + + var permalink = $( ''+gallery.jp_carousel('format', {'text': jetpackCarouselStrings.download_original, 'replacements': origSize})+'' ) + .addClass( 'jp-carousel-image-download' ) + .attr( 'href', original ) + .attr( 'target', '_blank' ); // Update (replace) the content of the anchor $( 'div.jp-carousel-image-meta a.jp-carousel-image-download' ).replaceWith( permalink ); @@ -1436,9 +1450,9 @@ jQuery(document).ready(function($) { } ); if ( ! slide.data( 'preview-image' ) || ( slide.data( 'thumb-size' ) && slide.width() > slide.data( 'thumb-size' ).width ) ) { - image.attr( 'src', image.closest( '.jp-carousel-slide' ).data( 'src' ) ); + image.attr( 'src', image.closest( '.jp-carousel-slide' ).data( 'src' ) ).attr('itemprop', 'image'); } else { - image.attr( 'src', slide.data( 'preview-image' ) ); + image.attr( 'src', slide.data( 'preview-image' ) ).attr('itemprop', 'image'); } image.data( 'loaded', 1 ); diff --git a/plugins/jetpack/modules/comments/comments.php b/plugins/jetpack/modules/comments/comments.php index 493c749b..5330cb7a 100644 --- a/plugins/jetpack/modules/comments/comments.php +++ b/plugins/jetpack/modules/comments/comments.php @@ -279,8 +279,7 @@ class Jetpack_Comments extends Highlander_Comments_Base { } $params['sig'] = $signature; - $url_origin = set_url_scheme( 'http://jetpack.wordpress.com' ); - $url = "{$url_origin}/jetpack-comment/?" . http_build_query( $params ); + $url = "https://jetpack.wordpress.com/jetpack-comment/?" . http_build_query( $params ); $url = "{$url}#parent=" . urlencode( set_url_scheme( '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 @@ -295,9 +294,9 @@ class Jetpack_Comments extends Highlander_Comments_Base {

-
- -
+
+ +
@@ -313,7 +312,7 @@ class Jetpack_Comments extends Highlander_Comments_Base { * @since JetpackComments (1.4) */ public function watch_comment_parent() { - $url_origin = set_url_scheme( 'http://jetpack.wordpress.com' ); + $url_origin = 'https://jetpack.wordpress.com'; ?> '; + } $id = ( ! empty( $content ) ) ? $content : $atts[0]; // Parse a URL - if ( ! is_numeric( $id ) ) + if ( ! is_numeric( $id ) ) { $id = preg_replace( '#https?://gist.github.com/([a-zA-Z0-9]+)#', '$1', $id ); + } - if ( ! $id ) + if ( ! $id ) { return ''; + } - if ( ! empty( $atts['file'] ) ) { - $file = '?file=' . urlencode( $atts['file'] ); + wp_enqueue_script( 'jetpack-gist-embed', plugins_url( 'js/gist.js', __FILE__ ), array( 'jquery' ), false, true ); + + if ( false !== strpos( $id, '#file-' ) ) { + // URL points to a specific file in the gist + $id = str_replace( '#file-', '.json?file=', $id ); + $id = preg_replace( '/\-(?!.*\-)/', '.', $id ); } else { - $file = ''; + $file = ( ! empty( $atts['file'] ) ) ? '?file=' . urlencode( $atts['file'] ) : ''; + // URL points to the entire gist + $id .= ".json$file"; } - $embed_url = "{$id}.json" . $file; - // inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables - $return = '' . - '
'; - - if ( isset( $_POST[ 'type' ]) && 'embed' === $_POST[ 'type' ] && - isset( $_POST[ 'action' ] ) && 'parse-embed' === $_POST['action'] ) { + $return = '
'; - return github_gist_simple_embed( $id, $file ); + if ( isset( $_POST[ 'type' ] ) && 'embed' === $_POST[ 'type' ] && + isset( $_POST[ 'action' ] ) && 'parse-embed' === $_POST['action'] ) { + return github_gist_simple_embed( $id ); } - return $return; + return $return; } -function github_gist_simple_embed( $id, $file ) { - $embed_url = $id . '.js' . $file; - - return ''; +/** + * Use script tag to load shortcode in editor. + * + * @since 3.9.0 + * + * @param string $id The ID of the gist. + * + * @return string + */ +function github_gist_simple_embed( $id ) { + $id = str_replace( 'json', 'js', $id ); + return ''; } \ No newline at end of file diff --git a/plugins/jetpack/modules/shortcodes/houzz.php b/plugins/jetpack/modules/shortcodes/houzz.php new file mode 100644 index 00000000..7e31c50e --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/houzz.php @@ -0,0 +1,29 @@ +get_html( $url, $args ); +} +add_shortcode( 'houzz', 'jetpack_houzz_shortcode' ); diff --git a/plugins/jetpack/modules/shortcodes/instagram.php b/plugins/jetpack/modules/shortcodes/instagram.php index 43d7d28a..08c8ceb0 100644 --- a/plugins/jetpack/modules/shortcodes/instagram.php +++ b/plugins/jetpack/modules/shortcodes/instagram.php @@ -8,8 +8,9 @@ * @return (string) the filtered or the original content **/ function jetpack_instagram_embed_reversal( $content ) { - if ( false === stripos( $content, 'instagram.com' ) ) + if ( false === stripos( $content, 'instagram.com' ) ) { return $content; + } /* Sample embed code:
Loading

Balloons

View on Instagram

@@ -31,16 +32,18 @@ function jetpack_instagram_embed_reversal( $content ) { $regexes[] = '#<iframe(?:[^&]|&(?!gt;))+?src="(?:https?:)?//instagram\.com/p/([^"\'/]++)[^"\']*?"(?:[^&]|&(?!gt;))*+>\s*?</iframe>#i'; foreach ( $regexes as $regex ) { - if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) - continue; + if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) { + continue; + } foreach ( $matches as $match ) { - if ( ! preg_match( '#(https?:)?//instagr(\.am|am\.com)/p/([^/]*)#i', $match[2], $url_matches ) ) + if ( ! preg_match( '#(https?:)?//instagr(\.am|am\.com)/p/([^/]*)#i', $match[2], $url_matches ) ) { continue; + } // Since we support Instagram via oEmbed, we simply leave a link on a line by itself. $replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $match[0], '#' ) ); - $url = esc_url( $url_matches[0] ); + $url = esc_url( $url_matches[0] ); $content = preg_replace( $replace_regex, sprintf( "\n\n%s\n\n", $url ), $content ); /** This action is documented in modules/shortcodes/youtube.php */ @@ -50,14 +53,14 @@ function jetpack_instagram_embed_reversal( $content ) { return $content; } -add_filter( 'pre_kses', 'jetpack_instagram_embed_reversal' ); +add_filter( 'pre_kses', 'jetpack_instagram_embed_reversal' ); /** * Instagram */ -wp_oembed_remove_provider( '#http://instagr(\.am|am\.com)/p/.*#i' ); // remove core's oEmbed support so we can override -wp_embed_register_handler( 'jetpack_instagram', '#http(s?)://instagr(\.am|am\.com)/p/([^/]*)#i', 'jetpack_instagram_handler' ); +wp_oembed_remove_provider( '#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i' ); // remove core's oEmbed support so we can override +wp_embed_register_handler( 'jetpack_instagram', '#http(s?)://(www\.)?instagr(\.am|am\.com)/p/([^/]*)#i', 'jetpack_instagram_handler' ); function jetpack_instagram_handler( $matches, $atts, $url ) { global $content_width; @@ -69,19 +72,19 @@ function jetpack_instagram_handler( $matches, $atts, $url ) { $min_width = 320; if ( is_feed() ) { - $media_url = sprintf( 'http://instagr.am/p/%s/media/?size=l', $matches[3] ); + $media_url = sprintf( 'http://instagr.am/p/%s/media/?size=l', $matches[4] ); return sprintf( 'Instagram Photo', esc_url( $url ), esc_attr__( 'View on Instagram', 'jetpack' ), esc_url( $media_url ) ); } $atts = shortcode_atts( array( - 'width' => isset( $content_width ) ? $content_width : $max_width, + 'width' => isset( $content_width ) ? $content_width : $max_width, 'hidecaption' => false, ), $atts ); $atts['width'] = absint( $atts['width'] ); - if ( $atts['width'] > $max_width || $min_width > $atts['width'] ) + if ( $atts['width'] > $max_width || $min_width > $atts['width'] ) { $atts['width'] = $max_width; - + } // remove the modal param from the URL $url = remove_query_arg( 'modal', $url ); @@ -90,11 +93,11 @@ function jetpack_instagram_handler( $matches, $atts, $url ) { $url = str_replace( 'instagr.am', 'instagram.com', $url ); // The oembed endpoint expects HTTP, but HTTP requests 301 to HTTPS - $instagram_http_url = str_replace( 'https://', 'http://', $url ); + $instagram_http_url = str_replace( 'https://', 'http://', $url ); $instagram_https_url = str_replace( 'http://', 'https://', $url ); $url_args = array( - 'url' => $instagram_http_url, + 'url' => $instagram_http_url, 'maxwidth' => $atts['width'], ); @@ -111,17 +114,17 @@ function jetpack_instagram_handler( $matches, $atts, $url ) { * * @module shortcodes * - * @since 3.3.0 + * @since 3.3.0 * - * @param bool false Object caching is off by default. - * @param array $matches Array of Instagram URLs found in the post. - * @param array $atts Instagram Shortcode attributes. + * @param bool false Object caching is off by default. + * @param array $matches Array of Instagram URLs found in the post. + * @param array $atts Instagram Shortcode attributes. * @param string $passed_url Instagram API URL. */ $response_body_use_cache = apply_filters( 'instagram_cache_oembed_api_response_body', false, $matches, $atts, $passed_url ); - $response_body = false; + $response_body = false; if ( $response_body_use_cache ) { - $cache_key = 'oembed_response_body_' . md5( $url ); + $cache_key = 'oembed_response_body_' . md5( $url ); $response_body = wp_cache_get( $cache_key, 'instagram_embeds' ); } @@ -129,7 +132,7 @@ function jetpack_instagram_handler( $matches, $atts, $url ) { // Not using cache (default case) or cache miss $instagram_response = wp_remote_get( $url, array( 'redirection' => 0 ) ); if ( is_wp_error( $instagram_response ) || 200 != $instagram_response['response']['code'] || empty( $instagram_response['body'] ) ) { - return ""; + return ''; } $response_body = json_decode( $instagram_response['body'] ); @@ -143,24 +146,24 @@ function jetpack_instagram_handler( $matches, $atts, $url ) { wp_enqueue_script( 'jetpack-instagram-embed', plugins_url( 'js/instagram.js', __FILE__ ), array( 'jquery' ), false, true ); // there's a script in the response, which we strip on purpose since it's added by this ^ script $ig_embed = preg_replace( '@<(script)[^>]*?>.*?@si', '', $response_body->html ); + return $ig_embed; } return ''; } - // filters instagram's username format to the expected format that matches the embed handler wp_embed_register_handler( 'jetpack_instagram_alternate_format', '#http(s?)://instagr(\.am|am\.com)/([^/]*)/p/([^/]*)#i', 'jetpack_instagram_alternate_format_handler' ); function jetpack_instagram_alternate_format_handler( $matches, $atts, $url ) { - $url = esc_url_raw( 'https://instagram.com/p/' . $matches[4] ); + $url = esc_url_raw( 'https://instagram.com/p/' . $matches[4] ); $matches[0] = $url; $matches[3] = $matches[4]; unset( $matches[4] ); + return jetpack_instagram_handler( $matches, $atts, $url ); } - // [instagram url="http://instagram.com/p/PSbF9sEIGP/"] // [instagram url="http://instagram.com/p/PSbF9sEIGP/" width="300"] add_shortcode( 'instagram', 'jetpack_shortcode_instagram' ); diff --git a/plugins/jetpack/modules/shortcodes/js/facebook.js b/plugins/jetpack/modules/shortcodes/js/facebook.js deleted file mode 100644 index f955effc..00000000 --- a/plugins/jetpack/modules/shortcodes/js/facebook.js +++ /dev/null @@ -1,29 +0,0 @@ -/* global FB, jpfbembed */ -(function( window ) { - var facebookEmbed = function() { - if ( 'undefined' !== typeof FB && FB.XFBML ) { - FB.XFBML.parse(); - } else { - var fbroot = document.createElement( 'div' ); - fbroot.id = 'fb-root'; - document.getElementsByTagName( 'body' )[0].appendChild( fbroot ); - - jQuery.getScript( '//connect.facebook.net/en_US/sdk.js' ); - } - }; - - window.fbAsyncInit = function() { - FB.init( { - appId : jpfbembed.appid, - version: 'v2.3' - } ); - - FB.XFBML.parse(); - }; - - if ( 'undefined' !== typeof infiniteScroll ) { - jQuery( document.body ).on( 'post-load', facebookEmbed ); - } - - facebookEmbed(); -})( this ); diff --git a/plugins/jetpack/modules/shortcodes/js/slideshow-shortcode.js b/plugins/jetpack/modules/shortcodes/js/slideshow-shortcode.js index 38531e0c..d2a04c5e 100644 --- a/plugins/jetpack/modules/shortcodes/js/slideshow-shortcode.js +++ b/plugins/jetpack/modules/shortcodes/js/slideshow-shortcode.js @@ -36,12 +36,17 @@ JetpackSlideshow.prototype.init = function() { img.title = typeof( imageInfo.title ) !== 'undefined' ? imageInfo.title : ''; img.alt = typeof( imageInfo.alt ) !== 'undefined' ? imageInfo.alt : ''; img.align = 'middle'; + img.setAttribute('itemprop','image'); img.nopin = 'nopin'; var caption = document.createElement( 'div' ); caption.className = 'slideshow-slide-caption'; + caption.setAttribute('itemprop','caption description'); caption.innerHTML = imageInfo.caption; var container = document.createElement('div'); container.className = 'slideshow-slide'; + container.setAttribute('itemprop','associatedMedia'); + container.setAttribute('itemscope',''); + container.setAttribute('itemtype','http://schema.org/ImageObject'); // Hide loading image once first image has loaded. if ( i === 0 ) { diff --git a/plugins/jetpack/modules/shortcodes/presentations.php b/plugins/jetpack/modules/shortcodes/presentations.php index aa4f42ee..aac538b7 100644 --- a/plugins/jetpack/modules/shortcodes/presentations.php +++ b/plugins/jetpack/modules/shortcodes/presentations.php @@ -76,7 +76,6 @@ presentation unless overridden by individual slides. */ if ( ! class_exists( 'Presentations' ) ) : - class Presentations { private $presentation_settings; @@ -88,23 +87,24 @@ class Presentations { */ function __construct() { // Bail without 3.0. - if ( ! function_exists( '__return_false' ) ) + if ( ! function_exists( '__return_false' ) ) { return; + } - $this->presentation_initialized = false; + $this->presentation_initialized = false; $this->scripts_and_style_included = false; // Registers shortcodes add_action( 'wp_head', array( &$this, 'add_scripts' ), 1 ); add_shortcode( 'presentation', array( &$this, 'presentation_shortcode' ) ); - add_shortcode( 'slide', array( &$this, 'slide_shortcode' ) ); + add_shortcode( 'slide', array( &$this, 'slide_shortcode' ) ); } function add_scripts() { $this->scripts_and_style_included = false; - if ( empty( $GLOBALS['posts'] ) || !is_array( $GLOBALS['posts'] ) ) { + if ( empty( $GLOBALS['posts'] ) || ! is_array( $GLOBALS['posts'] ) ) { return; } @@ -115,45 +115,40 @@ class Presentations { } } - if ( ! $this->scripts_and_style_included ) + if ( ! $this->scripts_and_style_included ) { return; + } $plugin = plugin_dir_url( __FILE__ ); // Add CSS - wp_enqueue_style('presentations', $plugin . 'css/style.css'); + wp_enqueue_style( 'presentations', $plugin . 'css/style.css' ); // Add JavaScript - wp_enqueue_script('jquery'); - wp_enqueue_script('jmpress', - $plugin . 'js/jmpress.min.js', - array('jquery'), - '0.4.5', - true); - wp_enqueue_script('presentations', - $plugin . 'js/main.js', - array('jquery', 'jmpress'), - false, - true); + wp_enqueue_script( 'jquery' ); + wp_enqueue_script( 'jmpress', $plugin . 'js/jmpress.min.js', array( 'jquery' ), '0.4.5', true ); + wp_enqueue_script( 'presentations', $plugin . 'js/main.js', array( 'jquery', 'jmpress' ), false, true ); } - function presentation_shortcode( $atts, $content='' ) { + function presentation_shortcode( $atts, $content = '' ) { // Mark that we've found a valid [presentation] shortcode $this->presentation_initialized = true; - $atts = shortcode_atts( array( - 'duration' => '', - 'height' => '', - 'width' => '', - 'bgcolor' => '', - 'bgimg' => '', - 'autoplay' => '', - - // Settings - 'transition' => '', - 'scale' => '', - 'rotate' => '', - 'fade' => '', - 'fadebullets' => '', - ), $atts, 'presentation' ); + $atts = shortcode_atts( + array( + 'duration' => '', + 'height' => '', + 'width' => '', + 'bgcolor' => '', + 'bgimg' => '', + 'autoplay' => '', + + // Settings + 'transition' => '', + 'scale' => '', + 'rotate' => '', + 'fade' => '', + 'fadebullets' => '', + ), $atts, 'presentation' + ); $this->presentation_settings = array( 'transition' => 'down', @@ -162,51 +157,60 @@ class Presentations { 'fade' => 'on', 'fadebullets' => 0, 'last' => array( - 'x' => 0, - 'y' => 0, - 'scale' => 1, - 'rotate' => 0, + 'x' => 0, + 'y' => 0, + 'scale' => 1, + 'rotate' => 0, ), ); // Set the presentation-wide settings - if ( '' != trim( $atts['transition'] ) ) + if ( '' != trim( $atts['transition'] ) ) { $this->presentation_settings['transition'] = $atts['transition']; + } - if ( '' != trim( $atts['scale'] ) ) + if ( '' != trim( $atts['scale'] ) ) { $this->presentation_settings['scale'] = floatval( $atts['scale'] ); + } - if ( '' != trim( $atts['rotate'] ) ) + if ( '' != trim( $atts['rotate'] ) ) { $this->presentation_settings['rotate'] = floatval( $atts['rotate'] ); + } - if ( '' != trim( $atts['fade'] ) ) + if ( '' != trim( $atts['fade'] ) ) { $this->presentation_settings['fade'] = $atts['fade']; + } - if ( '' != trim( $atts['fadebullets'] ) ) + if ( '' != trim( $atts['fadebullets'] ) ) { $this->presentation_settings['fadebullets'] = $atts['fadebullets']; + } // Set any settings the slides don't care about - if ( '' != trim( $atts['duration'] ) ) + if ( '' != trim( $atts['duration'] ) ) { $duration = floatval( $atts['duration'] ) . 's'; - else + } else { $duration = '1s'; + } // Autoplay durations are set in milliseconds - if ( '' != trim( $atts['autoplay'] ) ) + if ( '' != trim( $atts['autoplay'] ) ) { $autoplay = floatval( $atts['autoplay'] ) * 1000; - else - $autoplay = 0; // No autoplay + } else { + $autoplay = 0; + } // No autoplay // Set the presentation size as specified or with some nicely sized dimensions - if ( '' != trim( $atts['width'] ) ) + if ( '' != trim( $atts['width'] ) ) { $this->presentation_settings['width'] = intval( $atts['width'] ); - else + } else { $this->presentation_settings['width'] = 480; + } - if ( '' != trim( $atts['height'] ) ) + if ( '' != trim( $atts['height'] ) ) { $this->presentation_settings['height'] = intval( $atts['height'] ); - else + } else { $this->presentation_settings['height'] = 370; + } // Hide the content by default in case the scripts fail $style = 'display: none; width: ' . $this->presentation_settings['width'] . 'px; height: ' . $this->presentation_settings['height'] . 'px;'; @@ -223,99 +227,115 @@ class Presentations { // Not supported message style is inlined incase the style sheet doesn't get included $out = "
"; - $out.= "

"; - $out.= __( 'This slideshow could not be started. Try refreshing the page or viewing it in another browser.' , 'jetpack' ) . '

'; + $out .= "

"; + $out .= __( 'This slideshow could not be started. Try refreshing the page or viewing it in another browser.', 'jetpack' ) . '

'; // Bail out unless the scripts were added if ( $this->scripts_and_style_included ) { - $out.= sprintf( + $out .= sprintf( '
', esc_attr( $duration ), esc_attr( $autoplay ), esc_attr( $style ) ); - $out.= ""; - $out.= ""; - $out.= ""; + $out .= ""; + $out .= ""; + $out .= ""; if ( $autoplay ) { - $out.= ""; + $out .= ''; } - $out.= do_shortcode( $content ); + $out .= do_shortcode( $content ); } - $out.= "
"; + $out .= ''; $this->presentation_initialized = false; + return $out; } function slide_shortcode( $atts, $content = '' ) { // Bail out unless wrapped by a [presentation] shortcode - if ( ! $this->presentation_initialized ) + if ( ! $this->presentation_initialized ) { return $content; + } - $atts = shortcode_atts( array( - 'transition' => '', - 'scale' => '', - 'rotate' => '', - 'fade' => '', - 'fadebullets'=> '', - 'bgcolor' => '', - 'bgimg' => '', - ), $atts, 'slide' ); + $atts = shortcode_atts( + array( + 'transition' => '', + 'scale' => '', + 'rotate' => '', + 'fade' => '', + 'fadebullets' => '', + 'bgcolor' => '', + 'bgimg' => '', + ), $atts, 'slide' + ); // Determine positioning based on transition - if ( '' == trim( $atts['transition'] ) ) + if ( '' == trim( $atts['transition'] ) ) { $atts['transition'] = $this->presentation_settings['transition']; + } // Setting the content scale - if ( '' == trim( $atts['scale'] ) ) + if ( '' == trim( $atts['scale'] ) ) { $atts['scale'] = $this->presentation_settings['scale']; + } - if( '' == trim( $atts['scale'] ) ) + if ( '' == trim( $atts['scale'] ) ) { $scale = 1; - else + } else { $scale = floatval( $atts['scale'] ); + } - if ( $scale < 0 ) + if ( $scale < 0 ) { $scale *= -1; + } // Setting the content rotation - if ( '' == trim( $atts['rotate'] ) ) + if ( '' == trim( $atts['rotate'] ) ) { $atts['rotate'] = $this->presentation_settings['rotate']; + } - if( '' == trim( $atts['rotate'] ) ) + if ( '' == trim( $atts['rotate'] ) ) { $rotate = 0; - else + } else { $rotate = floatval( $atts['rotate'] ); + } // Setting if the content should fade - if ( '' == trim( $atts['fade'] ) ) + if ( '' == trim( $atts['fade'] ) ) { $atts['fade'] = $this->presentation_settings['fade']; + } - if ( 'on' == $atts['fade'] || 'true' == $atts['fade'] ) + if ( 'on' == $atts['fade'] || 'true' == $atts['fade'] ) { $fade = 'fade'; - else + } else { $fade = ''; + } // Setting if bullets should fade on step changes - if ( '' == trim( $atts['fadebullets'] ) ) + if ( '' == trim( $atts['fadebullets'] ) ) { $atts['fadebullets'] = $this->presentation_settings['fadebullets']; + } - if ( 'on' == $atts['fadebullets'] || 'true' == $atts['fadebullets'] ) + if ( 'on' == $atts['fadebullets'] || 'true' == $atts['fadebullets'] ) { $fadebullets = 'fadebullets'; - else + } else { $fadebullets = ''; + } - $coords = $this->get_coords( array( - 'transition' => $atts['transition'], - 'scale' => $scale, - 'rotate' => $rotate, - )); + $coords = $this->get_coords( + array( + 'transition' => $atts['transition'], + 'scale' => $scale, + 'rotate' => $rotate, + ) + ); $x = $coords['x']; $y = $coords['y']; @@ -342,31 +362,33 @@ class Presentations { esc_attr( $style ) ); - $out.= "
"; - $out.= do_shortcode( $content ); - $out.= "
"; + $out .= '
'; + $out .= do_shortcode( $content ); + $out .= '
'; + return $out; } /** * Determines the position of the next slide based on the position and scaling of the previous slide. * - * @param array $args: an array with the following key-value pairs - * string $transition: the transition name, "up", "down", "left", or "right" - * float $scale: the scale of the next slide (used to determine the position of the slide after that) + * @param array $args : an array with the following key-value pairs + * string $transition: the transition name, "up", "down", "left", or "right" + * float $scale: the scale of the next slide (used to determine the position of the slide after that) * * @return array with the 'x' and 'y' coordinates of the slide */ function get_coords( $args ) { - if ( 0 == $args['scale'] ) + if ( 0 == $args['scale'] ) { $args['scale'] = 1; + } $width = $this->presentation_settings['width']; $height = $this->presentation_settings['height']; $last = $this->presentation_settings['last']; $scale = $last['scale']; - $next = array( + $next = array( 'x' => $last['x'], 'y' => $last['y'], 'scale' => $args['scale'], @@ -375,7 +397,7 @@ class Presentations { // All angles are measured from the vertical axis, so everything is backwards! $diagAngle = atan2( $width, $height ); - $diagonal = sqrt( pow( $width, 2 ) + pow( $height, 2 ) ); + $diagonal = sqrt( pow( $width, 2 ) + pow( $height, 2 ) ); // We offset the angles by the angle formed by the diagonal so that // we can multiply the sines directly against the diagonal length @@ -383,21 +405,21 @@ class Presentations { $phi = deg2rad( $next['rotate'] ) - $diagAngle; // We start by displacing by the slide dimensions - $totalHorizDisp = $width * $scale; + $totalHorizDisp = $width * $scale; $totalVertDisp = $height * $scale; // If the previous slide was rotated, we add the incremental offset from the rotation // Namely the difference between the regular dimension (no rotation) and the component // of the diagonal for that angle - $totalHorizDisp += ( ( ( abs( sin( $theta ) ) * $diagonal) - $width ) / 2) * $scale; - $totalVertDisp += ( ( ( abs( cos( $theta ) ) * $diagonal) - $height) / 2) * $scale; + $totalHorizDisp += ( ( ( abs( sin( $theta ) ) * $diagonal ) - $width ) / 2 ) * $scale; + $totalVertDisp += ( ( ( abs( cos( $theta ) ) * $diagonal ) - $height ) / 2 ) * $scale; // Similarly, we check if the current slide has been rotated and add whatever additional // offset has been added. This is so that two rotated corners don't clash with each other. // Note: we are checking the raw angle relative to the vertical axis, NOT the diagonal angle. - if ( $next['rotate'] % 180 != 0 ){ - $totalHorizDisp += ( abs( ( sin( $phi ) * $diagonal ) - $width ) / 2) * $next['scale']; - $totalVertDisp += ( abs( ( cos( $phi ) * $diagonal ) - $height ) / 2) * $next['scale']; + if ( 0 !== $next['rotate'] % 180 ) { + $totalHorizDisp += ( abs( ( sin( $phi ) * $diagonal ) - $width ) / 2 ) * $next['scale']; + $totalVertDisp += ( abs( ( cos( $phi ) * $diagonal ) - $height ) / 2 ) * $next['scale']; } switch ( trim( $args['transition'] ) ) { @@ -423,6 +445,7 @@ class Presentations { } $this->presentation_settings['last'] = $next; + return $next; } } diff --git a/plugins/jetpack/modules/shortcodes/scribd.php b/plugins/jetpack/modules/shortcodes/scribd.php index a334fd55..7a278ea1 100644 --- a/plugins/jetpack/modules/shortcodes/scribd.php +++ b/plugins/jetpack/modules/shortcodes/scribd.php @@ -15,7 +15,7 @@ function scribd_shortcode_handler( $atts ) { $atts = shortcode_atts( array( 'id' => 0, 'key' => 0, - 'mode' => "", + 'mode' => '', ), $atts, 'scribd' ); $modes = array( 'list', 'book', 'slide', 'slideshow', 'tile' ); @@ -24,8 +24,9 @@ function scribd_shortcode_handler( $atts ) { if ( preg_match( '/^[A-Za-z0-9-]+$/', $atts['key'], $m ) ) { $atts['key'] = $m[0]; - if ( !in_array( $atts['mode'], $modes ) ) + if ( ! in_array( $atts['mode'], $modes ) ) { $atts['mode'] = ''; + } return scribd_shortcode_markup( $atts ); } else { @@ -41,6 +42,7 @@ EOD; return $markup; } + add_shortcode( 'scribd', 'scribd_shortcode_handler' ); // Scribd supports HTTPS, so use that endpoint to get HTTPS-compatible embeds @@ -48,6 +50,8 @@ function scribd_https_oembed( $providers ) { if ( isset( $providers['#https?://(www\.)?scribd\.com/doc/.*#i'] ) ) { $providers['#https?://(www\.)?scribd\.com/doc/.*#i'][0] = 'https://www.scribd.com/services/oembed'; } + return $providers; } + add_filter( 'oembed_providers', 'scribd_https_oembed' ); diff --git a/plugins/jetpack/modules/shortcodes/slideshare.php b/plugins/jetpack/modules/shortcodes/slideshare.php index 6b452039..f2278935 100644 --- a/plugins/jetpack/modules/shortcodes/slideshare.php +++ b/plugins/jetpack/modules/shortcodes/slideshare.php @@ -10,13 +10,15 @@ wp_oembed_add_provider( '#https?://(www\.)?slideshare\.net/.*#i', 'https://www.s * New style: [slideshare id=5342235&w=300&h=200&fb=0&mw=0&mh=0&sc=no] * * Legend: - * id = Document ID provided by Slideshare - * w = Width of iFrame (int) - * h = Height of iFrame (int) - * fb = iFrame frameborder (int) - * mw = iFrame marginwidth (int) - * mh = iFrame marginheight (int) - * sc = iFrame Scrollbar (yes/no) + * id = Document ID provided by Slideshare + * w = Width of iFrame (int) + * h = Height of iFrame (int) + * fb = iFrame frameborder (int) + * mw = iFrame marginwidth (int) + * mh = iFrame marginheight (int) + * sc = iFrame Scrollbar (yes/no) + * pro = Slideshare Pro (yes/no) + * style = Inline CSS (string) **/ add_shortcode( 'slideshare', 'slideshare_shortcode' ); @@ -27,60 +29,85 @@ function slideshare_shortcode( $atts ) { $params = shortcode_new_to_old_params( $atts ); parse_str( $params, $arguments ); - if ( empty( $arguments ) ) + if ( empty( $arguments ) ) { return ''; + } - extract( $arguments ); + $attr = shortcode_atts( + array( + 'id' => '', + 'w' => '', + 'h' => '', + 'fb' => '', + 'mw' => '', + 'mh' => '', + 'sc' => '', + 'pro' => '', + 'style' => '', + ), $arguments + ); // check that the Slideshare ID contains letters, numbers and query strings $pattern = '/[^-_a-zA-Z0-9?=&]/'; - if ( empty( $id ) || preg_match( $pattern, $id ) ) + if ( empty( $attr['id'] ) || preg_match( $pattern, $attr['id'] ) ) { return ''; + } // check the width/height - if ( empty( $w ) && ! empty( $content_width ) ) + $w = $attr['w']; + if ( empty( $w ) && ! empty( $content_width ) ) { $w = intval( $content_width ); - elseif ( ! ( $w = intval( $w ) ) || $w < 300 || $w > 1600 ) + } elseif ( ! ( $w = intval( $w ) ) || $w < 300 || $w > 1600 ) { $w = 425; - else + } else { $w = intval( $w ); + } - $h = ceil( $w * 348 / 425 ); + $h = ceil( $w * 348 / 425 ); // Note: user-supplied height is ignored. - if ( isset( $pro ) ) { - $source = "https://www.slideshare.net/slidesharepro/$id"; + if ( isset( $attr['pro'] ) && $attr['pro'] ) { + $source = 'https://www.slideshare.net/slidesharepro/' . $attr['id']; } else { - $source = "https://www.slideshare.net/slideshow/embed_code/$id"; + $source = 'https://www.slideshare.net/slideshow/embed_code/' . $attr['id']; } - if ( isset( $rel ) ) + if ( isset( $rel ) ) { $source = add_query_arg( 'rel', intval( $rel ), $source ); + } - if ( isset( $startSlide ) ) + if ( isset( $startSlide ) ) { $source = add_query_arg( 'startSlide', intval( $startSlide ), $source ); + } $player = sprintf( "', $width, $height, $url ); } /** * Legacy Flash widget embed code - * @param {array} $options Parameters - * @return {string} Flash embed code + * + * @param array $options Parameters + * + * @return string Flash embed code */ function soundcloud_flash_widget( $options ) { - // Build URL - $url = set_url_scheme( 'https://player.soundcloud.com/player.swf?' . http_build_query($options['params']) ); + $url = set_url_scheme( 'https://player.soundcloud.com/player.swf?' . http_build_query( $options['params'] ) ); // Set default width if not defined $width = isset( $options['width'] ) && $options['width'] !== 0 ? $options['width'] : '100%'; // Set default height if not defined - $height = isset( $options['height'] ) && $options['height'] !== 0 ? $options['height'] : ( soundcloud_url_has_tracklist( $options['url'] ) ? '255' : '81'); - - return preg_replace( '/\s\s+/', "", sprintf( ' - - - - ', $width, $height, $url, $width, $height, $url ) ); + $height = isset( $options['height'] ) && $options['height'] !== 0 ? $options['height'] : ( soundcloud_url_has_tracklist( $options['url'] ) ? '255' : '81' ); + + return preg_replace( + '/\s\s+/', '', sprintf( + ' + + + + ', $width, $height, $url, $width, $height, $url + ) + ); } - /** * SoundCloud Embed Reversal * * Converts a generic HTML embed code from SoundClound into a * WordPress.com-compatibly shortcode. + * + * @param string $content HTML content. + * + * @return string Parsed content. */ function jetpack_soundcloud_embed_reversal( $content ) { - if ( false === stripos( $content, 'w.soundcloud.com/player' ) ) + if ( false === stripos( $content, 'w.soundcloud.com/player' ) ) { return $content; + } /* Sample embed code: @@ -236,8 +263,9 @@ function jetpack_soundcloud_embed_reversal( $content ) { $regexes[] = '#<iframe(?:[^&]|&(?!gt;))+?src="((?:https?:)?//w\.soundcloud\.com/player/[^"\']++)"(?:[^&]|&(?!gt;))*+>\s*?</iframe>#i'; foreach ( $regexes as $regex ) { - if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) + if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) { continue; + } foreach ( $matches as $match ) { @@ -247,13 +275,14 @@ function jetpack_soundcloud_embed_reversal( $content ) { $args = parse_url( html_entity_decode( $match[1] ), PHP_URL_QUERY ); $args = wp_parse_args( $args ); - if ( ! preg_match( '#^(?:https?:)?//api\.soundcloud\.com/.+$#i', $args['url'], $url_matches ) ) + if ( ! preg_match( '#^(?:https?:)?//api\.soundcloud\.com/.+$#i', $args['url'], $url_matches ) ) { continue; + } if ( ! preg_match( '#height="(\d+)"#i', $match[0], $hmatch ) ) { $height = ''; } else { - $height = " height='" . intval( $hmatch[1] ) . "'"; + $height = ' height="' . intval( $hmatch[1] ) . '"'; } unset( $args['url'] ); @@ -269,7 +298,7 @@ function jetpack_soundcloud_embed_reversal( $content ) { $shortcode = '[soundcloud url="' . esc_url( $url_matches[0] ) . '" ' . $params . ' width="100%"' . $height . ' iframe="true" /]'; $replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $match[0], '#' ) ); - $content = preg_replace( $replace_regex, sprintf( "\n\n%s\n\n", $shortcode ), $content ); + $content = preg_replace( $replace_regex, sprintf( "\n\n%s\n\n", $shortcode ), $content ); /** This action is documented in modules/shortcodes/youtube.php */ do_action( 'jetpack_embed_to_shortcode', 'soundcloud', $url_matches[0] ); } @@ -278,5 +307,4 @@ function jetpack_soundcloud_embed_reversal( $content ) { return $content; } - add_filter( 'pre_kses', 'jetpack_soundcloud_embed_reversal' ); diff --git a/plugins/jetpack/modules/shortcodes/ted.php b/plugins/jetpack/modules/shortcodes/ted.php index f49184ef..d5386109 100644 --- a/plugins/jetpack/modules/shortcodes/ted.php +++ b/plugins/jetpack/modules/shortcodes/ted.php @@ -18,42 +18,47 @@ function jetpack_shortcode_get_ted_id( $atts ) { } add_shortcode( 'ted', 'shortcode_ted' ); -function shortcode_ted( $atts, $content = '' ) { +function shortcode_ted( $atts ) { global $wp_embed; $defaults = array( - 'id' => '', - 'width' => '', - 'height' => '', - 'lang' => 'en', - ); - $atts = shortcode_atts( $defaults, $atts, 'ted' ); + 'id' => '', + 'width' => '', + 'height' => '', + 'lang' => 'en', + ); + $atts = shortcode_atts( $defaults, $atts, 'ted' ); - if ( empty( $atts['id'] ) ) + if ( empty( $atts['id'] ) ) { return ''; + } - if ( preg_match( "#^[\d]+$#", $atts['id'], $matches ) ) + $url = ''; + if ( preg_match( '#^[\d]+$#', $atts['id'], $matches ) ) { $url = 'http://ted.com/talks/view/id/' . $matches[0]; - elseif ( preg_match( "#^https?://(www\.)?ted\.com/talks/view/id/[0-9]+$#", $atts['id'], $matches ) ) + } elseif ( preg_match( '#^https?://(www\.)?ted\.com/talks/view/id/[0-9]+$#', $atts['id'], $matches ) ) { $url = $matches[0]; + } unset( $atts['id'] ); $args = array(); - if ( is_numeric( $atts['width'] ) ) + if ( is_numeric( $atts['width'] ) ) { $args['width'] = $atts['width']; - else if ( $embed_size_w = get_option( 'embed_size_w' ) ) + } else if ( $embed_size_w = get_option( 'embed_size_w' ) ) { $args['width'] = $embed_size_w; - else if ( ! empty( $GLOBALS['content_width'] ) ) - $args['width'] = (int)$GLOBALS['content_width']; - else + } else if ( ! empty( $GLOBALS['content_width'] ) ) { + $args['width'] = (int) $GLOBALS['content_width']; + } else { $args['width'] = 500; + } // Default to a 16x9 aspect ratio if there's no height set - if ( is_numeric( $atts['height'] ) ) + if ( is_numeric( $atts['height'] ) ) { $args['height'] = $atts['height']; - else + } else { $args['height'] = $args['width'] * 0.5625; + } if ( ! empty( $atts['lang'] ) ) { $args['lang'] = sanitize_key( $atts['lang'] ); @@ -61,6 +66,7 @@ function shortcode_ted( $atts, $content = '' ) { } $retval = $wp_embed->shortcode( $args, $url ); remove_filter( 'oembed_fetch_url', 'ted_filter_oembed_fetch_url', 10 ); + return $retval; } diff --git a/plugins/jetpack/modules/shortcodes/twitter-timeline.php b/plugins/jetpack/modules/shortcodes/twitter-timeline.php index 4f12d067..adde0367 100644 --- a/plugins/jetpack/modules/shortcodes/twitter-timeline.php +++ b/plugins/jetpack/modules/shortcodes/twitter-timeline.php @@ -4,28 +4,35 @@ add_shortcode( 'twitter-timeline', 'twitter_timeline_shortcode' ); function twitter_timeline_shortcode( $attr ) { $default_atts = array( - 'username' => '', - 'id' => '', - 'height' => 282, - 'width' => 450, - + 'username' => '', + 'id' => '', + 'height' => '282', + 'width' => '450', ); $attr = shortcode_atts( $default_atts, $attr, 'twitter-timeline' ); - if ( $attr['username'] != preg_replace( '/[^A-Za-z0-9_]+/', '', $attr['username'] ) ) - return ''; + $attr['username'] = preg_replace( '/[^A-Za-z0-9_]+/', '', $attr['username'] ); + + if ( empty( $attr['username'] ) ) { + return ''; + } - if ( ! is_numeric( $attr['id'] ) ) - return ''; + if ( ! is_numeric( $attr['id'] ) ) { + return ''; + } $tweets_by = sprintf( __( 'Tweets by @%s', 'jetpack' ), $attr['username'] ); - $output = '' . esc_html( $tweets_by ) . ''; - add_action( 'wp_footer', 'twitter_timeline_js' ); + $output = '' . esc_html( $tweets_by ) . ''; + + wp_enqueue_script( 'jetpack-twitter-timeline' ); return $output; } function twitter_timeline_js() { - echo ''; + if ( is_customize_preview() ) { + wp_enqueue_script( 'jetpack-twitter-timeline' ); + } } +add_action( 'wp_enqueue_scripts', 'twitter_timeline_js' ); diff --git a/plugins/jetpack/modules/shortcodes/vimeo.php b/plugins/jetpack/modules/shortcodes/vimeo.php index 64869111..f63367d8 100644 --- a/plugins/jetpack/modules/shortcodes/vimeo.php +++ b/plugins/jetpack/modules/shortcodes/vimeo.php @@ -11,16 +11,19 @@ function jetpack_shortcode_get_vimeo_id( $atts ) { if ( isset( $atts[0] ) ) { - $atts[0] = trim( $atts[0] , '=' ); - $id = false; - if ( is_numeric( $atts[0] ) ) + $atts[0] = trim( $atts[0], '=' ); + $id = false; + if ( is_numeric( $atts[0] ) ) { $id = (int) $atts[0]; - elseif ( preg_match( '|vimeo\.com/(\d+)/?$|i', $atts[0], $match ) ) + } elseif ( preg_match( '|vimeo\.com/(\d+)/?$|i', $atts[0], $match ) ) { $id = (int) $match[1]; - elseif ( preg_match( '|player\.vimeo\.com/video/(\d+)/?$|i', $atts[0], $match ) ) + } elseif ( preg_match( '|player\.vimeo\.com/video/(\d+)/?$|i', $atts[0], $match ) ) { $id = (int) $match[1]; + } + return $id; } + return 0; } @@ -28,41 +31,53 @@ function jetpack_shortcode_get_vimeo_id( $atts ) { * Convert a Vimeo shortcode into an embed code. * * @param array $atts An array of shortcode attributes. + * * @return string The embed code for the Vimeo video. */ function vimeo_shortcode( $atts ) { global $content_width; - extract( array_map( 'intval', shortcode_atts( array( - 'id' => 0, - 'width' => 400, - 'height' => 300, - 'autoplay' => 0, - 'loop' => 0, - ), $atts, 'vimeo' ) ) ); + $attr = array_map( + 'intval', + shortcode_atts( + array( + 'id' => 0, + 'width' => 0, + 'height' => 0, + 'autoplay' => 0, + 'loop' => 0, + ), $atts + ) + ); if ( isset( $atts[0] ) ) { - $id = jetpack_shortcode_get_vimeo_id( $atts ); + $attr['id'] = jetpack_shortcode_get_vimeo_id( $atts ); } - if ( ! $id ) return ""; + if ( ! $attr['id'] ) { + return ''; + } // [vimeo 141358 h=500&w=350] $params = shortcode_new_to_old_params( $atts ); // h=500&w=350 $params = str_replace( array( '&', '&' ), '&', $params ); parse_str( $params, $args ); - if ( isset( $args['w'] ) ) { - $width = (int) $args['w']; + $width = intval( $attr['width'] ); + $height = intval( $attr['height'] ); + + // Support w and h argument as fallback. + if ( empty( $width ) && isset( $args['w'] ) ) { + $width = intval( $args['w'] ); - if ( ! isset( $args['h'] ) ) { + if ( empty( $height ) && ! isset( $args['h'] ) ) { // The case where w=300 is specified without h=200, otherwise $height // will always equal the default of 300, no matter what w was set to. $height = round( ( $width / 640 ) * 360 ); } } - if ( isset( $args['h'] ) ) { + if ( empty( $height ) && isset( $args['h'] ) ) { $height = (int) $args['h']; if ( ! isset( $args['w'] ) ) { @@ -70,10 +85,15 @@ function vimeo_shortcode( $atts ) { } } - if ( ! $width ) { + if ( ! $width && ! empty( $content_width ) ) { $width = absint( $content_width ); } + // If setting the width with content_width has failed, defaulting + if ( ! $width ) { + $width = 640; + } + if ( ! $height ) { $height = round( ( $width / 640 ) * 360 ); } @@ -100,20 +120,31 @@ function vimeo_shortcode( $atts ) { */ $height = (int) apply_filters( 'vimeo_height', $height ); - $url = esc_url( "https://player.vimeo.com/video/$id" ); + $url = esc_url( 'https://player.vimeo.com/video/' . $attr['id'] ); - // $args['autoplay'] is parsed from the embedded url. - // $autoplay is parsed from shortcode arguments. - // in_array( 'autoplay', $atts ) catches the argument passed without a value. - if ( ! empty( $args['autoplay'] ) || ! empty( $autoplay ) || in_array( 'autoplay', $atts ) ) { + // Handle autoplay and loop arguments. + if ( + isset( $args['autoplay'] ) && '1' === $args['autoplay'] // Parsed from the embedded URL. + || $attr['autoplay'] // Parsed from shortcode arguments. + || in_array( 'autoplay', $atts ) // Catch the argument passed without a value. + ) { $url = add_query_arg( 'autoplay', 1, $url ); } - if ( ! empty( $args['loop'] ) || ! empty( $loop ) || in_array( 'loop', $atts ) ) { + if ( + isset( $args['loop'] ) && '1' === $args['loop'] // Parsed from the embedded URL. + || $attr['loop'] // Parsed from shortcode arguments. + || in_array( 'loop', $atts ) // Catch the argument passed without a value. + ) { $url = add_query_arg( 'loop', 1, $url ); } - $html = sprintf( '
', esc_url( $url ), $width, $height ); + $html = sprintf( + '
', + esc_url( $url ), + esc_attr( $width ), + esc_attr( $height ) + ); /** * Filter the Vimeo player HTML. @@ -162,35 +193,39 @@ function wpcom_vimeo_embed_url_init() { add_action( 'init', 'wpcom_vimeo_embed_url_init' ); function vimeo_embed_to_shortcode( $content ) { - if ( false === stripos( $content, 'player.vimeo.com/video/' ) ) + if ( false === stripos( $content, 'player.vimeo.com/video/' ) ) { return $content; + } - $regexp = '!!i'; + $regexp = '!!i'; $regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) ); foreach ( array( 'regexp', '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 ) { $id = (int) $match[2]; $params = $match[3]; - if ( 'regexp_ent' == $reg ) + if ( 'regexp_ent' == $reg ) { $params = html_entity_decode( $params ); + } $params = wp_kses_hair( $params, array( 'http' ) ); - $width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0; + $width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0; $height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0; $wh = ''; - if ( $width && $height ) + if ( $width && $height ) { $wh = ' w=' . $width . ' h=' . $height; + } $shortcode = '[vimeo ' . $id . $wh . ']'; - $content = str_replace( $match[0], $shortcode, $content ); + $content = str_replace( $match[0], $shortcode, $content ); } } @@ -200,15 +235,44 @@ function vimeo_embed_to_shortcode( $content ) { add_filter( 'pre_kses', 'vimeo_embed_to_shortcode' ); /** - * Replaces plain-text links to Vimeo videos with Vimeo embeds. + * Replaces shortcodes and plain-text URLs to Vimeo videos with Vimeo embeds. + * Covers shortcode usage [vimeo 1234] | [vimeo https://vimeo.com/1234] | [vimeo http://vimeo.com/1234] + * Or plain text URLs https://vimeo.com/1234 | vimeo.com/1234 | //vimeo.com/1234 + * Links are left intact. * * @since 3.7.0 + * @since 3.9.5 One regular expression matches shortcodes and plain URLs. * * @param string $content HTML content * @return string The content with embeds instead of URLs */ function vimeo_link( $content ) { - return preg_replace_callback( '#https://vimeo.com/\d*#', 'vimeo_link_callback', $content ); + /** + * [vimeo 12345] + * [vimeo http://vimeo.com/12345] + */ + $shortcode = "(?:\[vimeo\s+[^0-9]*)([0-9]+)(?:\])"; + + /** + * http://vimeo.com/12345 + * https://vimeo.com/12345 + * //vimeo.com/12345 + * vimeo.com/some/descender/12345 + * + * Should not capture inside HTML attributes + * [Not] Cool Video + * [Not] vimeo.com/12345 + * + * Could erroneously capture: + * This video (vimeo.com/12345) is teh cat's meow! + */ + $plain_url = "(?:[^'\">]?\/?(?:https?:\/\/)?vimeo\.com[^0-9]+)([0-9]+)(?:[^'\"0-9<]|$)"; + + return preg_replace_callback( + sprintf( '#%s|%s#i', $shortcode, $plain_url ), + 'vimeo_link_callback', + $content + ); } /** @@ -217,19 +281,14 @@ function vimeo_link( $content ) { * @since 3.7.0 * * @param array $matches An array containing a Vimeo URL. - * @return string THe Vimeo HTML embed code. + * @return string The Vimeo HTML embed code. */ function vimeo_link_callback( $matches ) { - // Grab the Vimeo ID from the URL - if ( preg_match( '|vimeo\.com/(\d+)/?$|i', $matches[0], $match ) ) { - $id = (int) $match[1]; - } - - // Pass that ID to the Vimeo shortcode function. - if ( $id ) { - $atts = array( 'id' => $id ); + $id = isset( $matches[ 2 ] ) ? $matches[ 2 ] : $matches[ 1 ]; + if ( isset( $id ) && ctype_digit( $id ) ) { + return "\n" . vimeo_shortcode( array( 'id' => $id ) ) . "\n"; } - return "\n" . vimeo_shortcode( $atts ) . "\n"; + return $matches[ 0 ]; } /** This filter is documented in modules/shortcodes/youtube.php */ diff --git a/plugins/jetpack/modules/shortcodes/wufoo.php b/plugins/jetpack/modules/shortcodes/wufoo.php index fb8cce6d..4020c5ea 100644 --- a/plugins/jetpack/modules/shortcodes/wufoo.php +++ b/plugins/jetpack/modules/shortcodes/wufoo.php @@ -10,72 +10,73 @@ http://wufoo.com/docs/code-manager/wordpress-shortcode-plugin/ function wufoo_shortcode( $atts ) { - extract( shortcode_atts( array( - 'username' => '', - 'formhash' => '', - 'autoresize' => true, - 'height' => '500', - 'header' => 'show', - 'ssl' => '' - ), $atts ) ); + $attr = shortcode_atts( + array( + 'username' => '', + 'formhash' => '', + 'autoresize' => true, + 'height' => '500', + 'header' => 'show', + 'ssl' => '', + ), $atts + ); - //Check username and formhash to ensure they only have alphanumeric characters or underscores, and aren't empty - if ( !preg_match( "/^[a-zA-Z0-9_]+$/", $username) || !preg_match( "/^[a-zA-Z0-9_]+$/", $formhash ) ) { + // Check username and formhash to ensure they only have alphanumeric characters or underscores, and aren't empty. + if ( ! preg_match( '/^[a-zA-Z0-9_]+$/', $attr['username'] ) || ! preg_match( '/^[a-zA-Z0-9_]+$/', $attr['formhash'] ) ) { - /** - * Return an error to the users with instructions if one of these params is invalid - * They don't have default values because they are user/form-specific - */ - $return_error = sprintf( __( 'Something is wrong with your Wufoo shortcode. If you copy and paste it from the %sWufoo Code Manager%s, you should be golden.', 'jetpack' ), "", "" ); + /** + * Return an error to the users with instructions if one of these params is invalid + * They don't have default values because they are user/form-specific + */ + $return_error = sprintf( __( 'Something is wrong with your Wufoo shortcode. If you copy and paste it from the %sWufoo Code Manager%s, you should be golden.', 'jetpack' ), '', '' ); - return " -
+ return ' +

Uh oh!

-

$return_error

-
"; +

' . $return_error . '

+
'; } /** - * Required parameters are present - * An error will be returned inside the form if they are invalid - */ - + * Required parameters are present. + * An error will be returned inside the form if they are invalid. + */ $js_embed = ''; $js_embed .= ""; + * Only output SSL value if passes as param. + * Lower tier plans don't show this param (don't offer SSL). + */ + $js_embed .= ( $attr['ssl'] ) ? ",'ssl':" . (bool) $attr['ssl'] : ''; + $js_embed .= '});'; + $js_embed .= 'wufoo_' . $attr['formhash'] . '.display();'; + $js_embed .= ''; /** - * iframe embed, loaded inside