From a6fda64e4ae1427ade6567c92f620b9b10bcc3c1 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 12 Dec 2017 07:43:18 -0800 Subject: [PATCH 01/21] Add skeleton for create-embed-test-post script --- .dev-lib | 4 ++ bin/create-embed-test-post.php | 77 ++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 bin/create-embed-test-post.php diff --git a/.dev-lib b/.dev-lib index ac8f8ff8bb4..0c899920d65 100644 --- a/.dev-lib +++ b/.dev-lib @@ -1,2 +1,6 @@ SYNC_README_MD=0 PATH_EXCLUDES_PATTERN=includes/lib/* + +if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]]; then + PATH_EXCLUDES_PATTERN="$PATH_EXCLUDES_PATTERN,bin/create-embed-test-post.php" +fi diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php new file mode 100644 index 00000000000..5fcfb05ae37 --- /dev/null +++ b/bin/create-embed-test-post.php @@ -0,0 +1,77 @@ + 'amp_test_prepare_image_attachments', + 'heading' => 'Media Gallery', + 'content' => function( $data ) { + return sprintf( '[gallery ids="%s"]', implode( ',', $data['ids'] ) ); + }, + ), +); + +/** + * Prepare test by ensuring attachments exist. + * + * @param array $data Entry data. + * @return array Data. + */ +function amp_test_prepare_image_attachments( $data ) { + $attachments = get_children( array( + 'post_parent' => 0, + 'post_status' => 'inherit', + 'post_type' => 'attachment', + 'post_mime_type' => 'image', + ) ); + $data['ids'] = wp_list_pluck( $attachments, 'ID' ); + + // @todo Add some attachments if count( $data['ids'] ) < 5. + return $data; +} + +// Run the script. +$page = get_page_by_path( '/amp-test-embeds/' ); +if ( $page ) { + $page_id = $page->ID; +} else { + $page_id = wp_insert_post( array( + 'post_name' => 'amp-test-embeds', + 'post_title' => 'AMP Test Embeds', + 'post_type' => 'page', + ) ); +} + +$content = ''; +foreach ( $data_entries as $data_entry ) { + if ( isset( $data_entry['prepare'] ) ) { + $data_entry = array_merge( + $data_entry, + call_user_func( $data_entry['prepare'], $data_entry ) + ); + } + + $content .= sprintf( "

%s

\n", $data_entry['heading'] ); + if ( is_callable( $data_entry['content'] ) ) { + $content .= call_user_func( $data_entry['content'], $data_entry ); + } else { + $content .= $data_entry['content']; + } + $content .= "\n\n"; +} + +wp_update_post( wp_slash( array( + 'ID' => $page_id, + 'post_content' => $content, +) ) ); + +WP_CLI::success( sprintf( 'Please take a look at: %s', get_permalink( $page_id ) ) ); From 6ef976873279cdb1e95861be8c943d55db1ba428 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 12 Dec 2017 12:22:40 -0800 Subject: [PATCH 02/21] Fix syntax of PATH_EXCLUDES_PATTERN and add PHPCS exclude-pattern --- .dev-lib | 4 ++-- phpcs.xml | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.dev-lib b/.dev-lib index 0c899920d65..42b445e66cc 100644 --- a/.dev-lib +++ b/.dev-lib @@ -1,6 +1,6 @@ SYNC_README_MD=0 -PATH_EXCLUDES_PATTERN=includes/lib/* +PATH_EXCLUDES_PATTERN=includes/lib/ if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]]; then - PATH_EXCLUDES_PATTERN="$PATH_EXCLUDES_PATTERN,bin/create-embed-test-post.php" + PATH_EXCLUDES_PATTERN="$PATH_EXCLUDES_PATTERN|bin/create-embed-test-post\.php" fi diff --git a/phpcs.xml b/phpcs.xml index a61014f926d..ac2ddd22f33 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -37,5 +37,6 @@ */dev-lib/* */node_modules/* */vendor/* - */includes/sanitizers/class-amp-allowed-tags-generated.php + includes/lib/* + includes/sanitizers/class-amp-allowed-tags-generated.php From 550ed6574e9bfebdca4ad5e28077cc0d4684253c Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Tue, 12 Dec 2017 19:49:49 -0600 Subject: [PATCH 03/21] Issue 806 : Add media and embeds to test page. Use Weston's wp-cli script to create a test post. Add media items to the post content. And add several embeds. Several embeds are still not rendering, Even on a standard, non-AMP page. --- bin/create-embed-test-post.php | 229 ++++++++++++++++++++++++++++++++- 1 file changed, 228 insertions(+), 1 deletion(-) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 5fcfb05ae37..745fa616df8 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -18,6 +18,180 @@ return sprintf( '[gallery ids="%s"]', implode( ',', $data['ids'] ) ); }, ), + array( + 'heading' => 'Media Image', + 'content' => amp_image_markup(), + ), + array( + 'heading' => 'Media Caption', + 'content' => '[caption width=150]' . amp_image_markup() . 'Example image caption[/caption]', + ), + array( + 'heading' => 'Media Video', + 'content' => '[video src=https://videos.files.wordpress.com/DK5mLrbr/video-ca6dc0ab4a_hd.mp4]', + ), + array( + 'heading' => 'Media Audio', + 'content' => '[audio src=https://wptavern.com/wp-content/uploads/2017/11/EPISODE-296-Gutenberg-Telemetry-Calypso-and-More-With-Matt-Mullenweg.mp3]', + ), + array( + 'prepare' => 'amp_test_prepare_video_attachments', + 'heading' => 'Video Playlist', + 'content' => function( $data ) { + return isset( $data['ids'] ) ? sprintf( '[playlist type="video" ids="%s"]', implode( ',', $data['ids'] ) ) : 'There are no videos, so no playlist is expected'; + }, + ), + array( + 'prepare' => 'amp_test_prepare_audio_attachments', + 'heading' => 'Audio Playlist', + 'content' => function( $data ) { + return isset( $data['ids'] ) ? sprintf( '[playlist ids="%s"]', implode( ',', $data['ids'] ) ) : 'There audio files, so no playlist is expected'; + }, + ), + array( + 'heading' => 'CloudUp Image Embed', + 'content' => 'https://cloudup.com/iWn3EIpgjev', + ), + array( + 'heading' => 'CloudUp Video Embed', + 'content' => 'https://cloudup.com/ioyW8a_Tjme', + ), + array( + 'heading' => 'CloudUp Gallery Embed', + 'content' => 'https://cloudup.com/cQNdYtQLO5U', + ), + array( + 'heading' => 'CollegeHumor Embed', + 'content' => 'http://www.collegehumor.com/video/40002823/how-to-actually-finish-something-for-once', + ), + array( + 'heading' => 'DailyMotion Embed', + 'content' => 'http://www.dailymotion.com/embed/video/x6bacgf', + ), + array( + 'heading' => 'Facebook Post Embed', + 'content' => 'https://www.facebook.com/WordPress/posts/10155651799877911', + ), + array( + 'heading' => 'Facebook Video Embed', + 'content' => 'https://www.facebook.com/WordPress/videos/10154702401472911/', + ), + array( + 'heading' => 'Flickr Image Embed', + 'content' => 'https://www.flickr.com/photos/sylvainmessier/38089894895/in/explore-2017-12-11/', + ), + array( + 'heading' => 'Flickr Video Embed', + 'content' => 'https://flic.kr/p/5TPDWa', + ), + array( + 'heading' => 'Funny Or Die Video Embed', + 'content' => 'http://FunnyOrDie.com/m/b1dn', + ), + array( + 'heading' => 'Hulu Embed', + 'content' => 'https://www.hulu.com/watch/807443', + ), + array( + 'heading' => 'Imgur Embed', + 'content' => '
Takeoff
', + ), + array( + 'heading' => 'Instagram Embed', + 'content' => 'https://www.instagram.com/p/bNd86MSFv6/', + ), + array( + 'heading' => 'Isuu Embed', + 'content' => 'https://issuu.com/ajcwfu/docs/seatatthetablefinal', + ), + array( + 'heading' => 'Kickstarter Embed', + 'content' => 'https://www.kickstarter.com/projects/iananderson/save-froots-magazine', + ), + array( + 'heading' => 'Meetup Embed', + 'content' => 'https://www.meetup.com/WordPress-Mexico', + ), + array( + 'heading' => 'Mixcloud Embed', + 'content' => 'https://www.mixcloud.com/TheWireMagazine/adventures-in-sound-and-music-hosted-by-derek-walmsley-7-december-2017/', + ), + array( + 'heading' => 'Photobucket Embed', + 'content' => 'http://s1284.photobucket.com/user/adonchin/media/20171116_181841_zpsrjuop6u7.jpg.html', + ), + array( + 'heading' => 'Polldaddy Embed', + 'content' => 'https://polldaddy.com/poll/7012505/', + ), + array( + 'heading' => 'Reddit Embed', + 'content' => 'https://www.reddit.com/r/Android/comments/7jbkub/google_maps_will_soon_tell_you_when_its_time_to/?ref=share&ref_source=link', + ), + array( + 'heading' => 'Reverb Nation Embed', + 'content' => 'https://www.reverbnation.com/fernandotorresleiva/song/28755694-breve-amor-new-version', + ), + array( + 'heading' => 'Scribd Embed', + 'content' => '[scribd id=124550852 key=key-1hh4hsgsvzz8jdl28w3v mode=scroll]', + ), + array( + 'heading' => 'SlideShare Embed', + 'content' => 'https://www.slideshare.net/slideshow/embed_code/key/u6WNbsR5worSzC', + ), + array( + 'heading' => 'SmugMug Embed', + 'content' => 'https://stuckincustoms.smugmug.com/Portfolio/i-GnwtS8R/A', + ), + array( + 'heading' => 'Soundcloud Embed', + 'content' => 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor', + ), + array( + 'heading' => 'Speaker Deck Embed', + 'content' => 'https://speakerdeck.com/caitiem20/distributed-sagas-a-protocol-for-coordinating-microservices', + ), + array( + 'heading' => 'Spotify Embed', + 'content' => 'https://open.spotify.com/track/2XULDEvijLgHttFgLzzpM5', + ), + array( + 'heading' => 'Ted Embed', + 'content' => 'https://www.ted.com/talks/derek_sivers_how_to_start_a_movement', + ), + array( + 'heading' => 'Tumblr Post Embed', + 'content' => 'https://embed.tumblr.com/embed/post/CHB7nLkCLl-ODZ7tdPU9SQ/168290317795', + ), + array( + 'heading' => 'Twitter Embed', + 'content' => 'https://twitter.com/WordPress/status/936550699336437760', + ), + array( + 'heading' => 'VideoPress Embed', + 'content' => 'https://videopress.com/v/kUJmAcSf', + ), + array( + 'heading' => 'Vimeo Embed', + 'content' => 'https://vimeo.com/59172123', + ), + array( + 'heading' => 'Vine Embed', + 'content' => '[vine url="https://vine.co/v/bEIHZpD2JWz"]', + ), + array( + 'heading' => 'WordPress Plugin Directory Embed', + 'content' => 'https://wordpress.org/plugins/amp/', + ), + array( + 'heading' => 'WordPress TV Embed', + 'content' => 'https://videopress.com/v/DK5mLrbr', + ), + array( + 'heading' => 'YouTube Embed', + 'content' => 'https://www.youtube.com/watch?v=XOY3ZUO6P0k', + ), ); /** @@ -35,10 +209,63 @@ function amp_test_prepare_image_attachments( $data ) { ) ); $data['ids'] = wp_list_pluck( $attachments, 'ID' ); - // @todo Add some attachments if count( $data['ids'] ) < 5. + $image_count_needed = 5; + if ( count( $data['ids'] ) < $image_count_needed ) { + $data['ids'] = wp_list_pluck( amp_get_media_items( 'image', $image_count_needed ), 'ID' ); + } + return $data; +} + +/** + * Get the markup for an image. + * + * @return string $image Markup for the image. + */ +function amp_image_markup() { + $image_posts = amp_get_media_items( 'image', 1 ); + $image = reset( $image_posts ); + return isset( $image->ID ) ? wp_get_attachment_image( $image->ID ) : null; +} + +/** + * Get video IDs to test a video playlist. + * + * @param array $data Entry data. + * @return array $data Entry data, with video IDs. + */ +function amp_test_prepare_video_attachments( $data ) { + $data['ids'] = wp_list_pluck( amp_get_media_items( 'video' ), 'ID' ); + return $data; +} + +/** + * Get audio IDs to test an audio playlist. + * + * @param array $data Entry data. + * @return array $data Data, with video IDs. + */ +function amp_test_prepare_audio_attachments( $data ) { + $data['ids'] = wp_list_pluck( amp_get_media_items( 'audio' ), 'ID' ); return $data; } +/** + * Get media items, using a \WP_Query. + * + * @param integer $type The post_mime_type of the media item. + * @param integer $image_count The number of images for which to query. + * @return array $media_items The media items from the query. + */ +function amp_get_media_items( $type, $image_count = 10 ) { + $query = new \WP_Query( array( + 'post_type' => 'attachment', + 'post_mime_type' => $type, + 'post_status' => 'inherit', + 'posts_per_page' => $image_count, + ) ); + return $query->get_posts(); +} + // Run the script. $page = get_page_by_path( '/amp-test-embeds/' ); if ( $page ) { From 7c777528f8642d93c4502eca355ef4dd759968de Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Tue, 12 Dec 2017 20:17:43 -0600 Subject: [PATCH 04/21] Issue 806 : Align equals signs vertically. Before, the equals sign alignment caused a PHPCS warning. Fix this, to enable the Travis build to succeed. --- bin/create-embed-test-post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 745fa616df8..5e0b5628e7b 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -223,7 +223,7 @@ function amp_test_prepare_image_attachments( $data ) { */ function amp_image_markup() { $image_posts = amp_get_media_items( 'image', 1 ); - $image = reset( $image_posts ); + $image = reset( $image_posts ); return isset( $image->ID ) ? wp_get_attachment_image( $image->ID ) : null; } From 128836c706d506c3596cf8c3a4f82243f1354732 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Tue, 12 Dec 2017 21:17:31 -0600 Subject: [PATCH 05/21] Issue 804 : Test WordPress post embeds. create-embed-test-post.php needs to test all post content. As Weston mentioned, embedded posts are part of this. --- bin/create-embed-test-post.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 5e0b5628e7b..d042a538d92 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -48,6 +48,10 @@ return isset( $data['ids'] ) ? sprintf( '[playlist ids="%s"]', implode( ',', $data['ids'] ) ) : 'There audio files, so no playlist is expected'; }, ), + array( + 'heading' => 'WordPress Post Embed', + 'content' => 'https://make.wordpress.org/core/2017/12/11/whats-new-in-gutenberg-11th-december/', + ), array( 'heading' => 'CloudUp Image Embed', 'content' => 'https://cloudup.com/iWn3EIpgjev', @@ -101,7 +105,7 @@ 'content' => 'https://www.instagram.com/p/bNd86MSFv6/', ), array( - 'heading' => 'Isuu Embed', + 'heading' => 'Issuu Embed', 'content' => 'https://issuu.com/ajcwfu/docs/seatatthetablefinal', ), array( From b8ba8369d07234c753f5fe7a801a09708b4fc9ed Mon Sep 17 00:00:00 2001 From: ThierryA Date: Wed, 13 Dec 2017 11:13:38 +0100 Subject: [PATCH 06/21] Issue 806 : code improvement --- .dev-lib | 4 - bin/create-embed-test-post.php | 130 ++++++++++----------------------- 2 files changed, 40 insertions(+), 94 deletions(-) diff --git a/.dev-lib b/.dev-lib index 42b445e66cc..7a14e274790 100644 --- a/.dev-lib +++ b/.dev-lib @@ -1,6 +1,2 @@ SYNC_README_MD=0 PATH_EXCLUDES_PATTERN=includes/lib/ - -if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]]; then - PATH_EXCLUDES_PATTERN="$PATH_EXCLUDES_PATTERN|bin/create-embed-test-post\.php" -fi diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index d042a538d92..6ab7d887790 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -12,19 +12,16 @@ $data_entries = array( array( - 'prepare' => 'amp_test_prepare_image_attachments', 'heading' => 'Media Gallery', - 'content' => function( $data ) { - return sprintf( '[gallery ids="%s"]', implode( ',', $data['ids'] ) ); - }, + 'content' => sprintf( '[gallery ids="%s"]', amp_get_media_items_ids( 'image' ) ), ), array( 'heading' => 'Media Image', - 'content' => amp_image_markup(), + 'content' => wp_get_attachment_image( amp_get_media_items_ids( 'image', 1 ) ), ), array( 'heading' => 'Media Caption', - 'content' => '[caption width=150]' . amp_image_markup() . 'Example image caption[/caption]', + 'content' => sprintf( '[caption width=150]%sExample image caption[/caption]', wp_get_attachment_image( amp_get_media_items_ids( 'image', 1 ) ) ), ), array( 'heading' => 'Media Video', @@ -35,18 +32,12 @@ 'content' => '[audio src=https://wptavern.com/wp-content/uploads/2017/11/EPISODE-296-Gutenberg-Telemetry-Calypso-and-More-With-Matt-Mullenweg.mp3]', ), array( - 'prepare' => 'amp_test_prepare_video_attachments', 'heading' => 'Video Playlist', - 'content' => function( $data ) { - return isset( $data['ids'] ) ? sprintf( '[playlist type="video" ids="%s"]', implode( ',', $data['ids'] ) ) : 'There are no videos, so no playlist is expected'; - }, + 'content' => sprintf( '[playlist type="video" ids="%s"]', amp_get_media_items_ids( 'video' ) ), ), array( - 'prepare' => 'amp_test_prepare_audio_attachments', 'heading' => 'Audio Playlist', - 'content' => function( $data ) { - return isset( $data['ids'] ) ? sprintf( '[playlist ids="%s"]', implode( ',', $data['ids'] ) ) : 'There audio files, so no playlist is expected'; - }, + 'content' => sprintf( '[playlist ids="%s"]', amp_get_media_items_ids( 'audio' ) ), ), array( 'heading' => 'WordPress Post Embed', @@ -199,75 +190,32 @@ ); /** - * Prepare test by ensuring attachments exist. - * - * @param array $data Entry data. - * @return array Data. - */ -function amp_test_prepare_image_attachments( $data ) { - $attachments = get_children( array( - 'post_parent' => 0, - 'post_status' => 'inherit', - 'post_type' => 'attachment', - 'post_mime_type' => 'image', - ) ); - $data['ids'] = wp_list_pluck( $attachments, 'ID' ); - - $image_count_needed = 5; - if ( count( $data['ids'] ) < $image_count_needed ) { - $data['ids'] = wp_list_pluck( amp_get_media_items( 'image', $image_count_needed ), 'ID' ); - } - return $data; -} - -/** - * Get the markup for an image. - * - * @return string $image Markup for the image. - */ -function amp_image_markup() { - $image_posts = amp_get_media_items( 'image', 1 ); - $image = reset( $image_posts ); - return isset( $image->ID ) ? wp_get_attachment_image( $image->ID ) : null; -} - -/** - * Get video IDs to test a video playlist. - * - * @param array $data Entry data. - * @return array $data Entry data, with video IDs. - */ -function amp_test_prepare_video_attachments( $data ) { - $data['ids'] = wp_list_pluck( amp_get_media_items( 'video' ), 'ID' ); - return $data; -} - -/** - * Get audio IDs to test an audio playlist. - * - * @param array $data Entry data. - * @return array $data Data, with video IDs. - */ -function amp_test_prepare_audio_attachments( $data ) { - $data['ids'] = wp_list_pluck( amp_get_media_items( 'audio' ), 'ID' ); - return $data; -} - -/** - * Get media items, using a \WP_Query. + * Get media item ids, using a \WP_Query. * * @param integer $type The post_mime_type of the media item. * @param integer $image_count The number of images for which to query. - * @return array $media_items The media items from the query. + * @return string|WP_CLI::error The media item ids separated by comma on success; error otherwise. */ -function amp_get_media_items( $type, $image_count = 10 ) { +function amp_get_media_items_ids( $type, $image_count = 3 ) { $query = new \WP_Query( array( 'post_type' => 'attachment', 'post_mime_type' => $type, 'post_status' => 'inherit', 'posts_per_page' => $image_count, + 'fields' => 'ids', ) ); - return $query->get_posts(); + + $posts = $query->get_posts(); + $posts_count = count( $posts ); + if ( $posts_count < $image_count ) { + WP_CLI::error( sprintf( + '%1$s "2$s" expected, %3$s found. Please make sure at least %1$s "2$s" are accessible and run this script again.', + $image_count, + $type, + $posts_count + ) ); + } + return implode( ',', $posts ); } // Run the script. @@ -276,33 +224,35 @@ function amp_get_media_items( $type, $image_count = 10 ) { $page_id = $page->ID; } else { $page_id = wp_insert_post( array( - 'post_name' => 'amp-test-embeds', + 'post_name' => 'amp-test-embeds', 'post_title' => 'AMP Test Embeds', - 'post_type' => 'page', + 'post_type' => 'page', ) ); + + if ( ! $page_id || is_wp_error( $page_id ) ) { + WP_CLI::error( 'The test page could not be added, please try again.' ); + } } +// Build and update content. $content = ''; -foreach ( $data_entries as $data_entry ) { - if ( isset( $data_entry['prepare'] ) ) { - $data_entry = array_merge( - $data_entry, - call_user_func( $data_entry['prepare'], $data_entry ) +foreach ( $data_entries as $entry ) { + if ( isset( $entry['heading'], $entry['content'] ) ) { + $content .= sprintf( + "

%s

\n%s\n\n", + $entry['heading'], + $entry['content'] ); } - - $content .= sprintf( "

%s

\n", $data_entry['heading'] ); - if ( is_callable( $data_entry['content'] ) ) { - $content .= call_user_func( $data_entry['content'], $data_entry ); - } else { - $content .= $data_entry['content']; - } - $content .= "\n\n"; } -wp_update_post( wp_slash( array( - 'ID' => $page_id, +$update = wp_update_post( wp_slash( array( + 'ID' => $page_id, 'post_content' => $content, ) ) ); +if ( ! $update ) { + WP_CLI::error( 'The test page could not be updated, please try again.' ); +} + WP_CLI::success( sprintf( 'Please take a look at: %s', get_permalink( $page_id ) ) ); From 0b729b1a728fbfd0faa9a7842ec757d1b8a5b4bd Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 13 Dec 2017 18:00:27 -0800 Subject: [PATCH 07/21] Fix rendering of SoundCloud embeds and correct parameters for soundcloud shortcode * Hook into oEmbed filters for rewriting SoundCloud embeds as AMP components. * Ensure Jetpack is active while unit tests are run. * Explicitly install and activate Jetpack during unit tests. * Fix error message in create-embed-test-post.php * Fix phpcs for Soundcloud code. --- .dev-lib | 5 + bin/create-embed-test-post.php | 8 +- .../embeds/class-amp-soundcloud-embed.php | 165 +++++++++++++++--- phpunit.xml | 3 + tests/test-amp-soundcloud-embed.php | 89 ++++++++-- 5 files changed, 224 insertions(+), 46 deletions(-) diff --git a/.dev-lib b/.dev-lib index 7a14e274790..247d573cc36 100644 --- a/.dev-lib +++ b/.dev-lib @@ -1,2 +1,7 @@ SYNC_README_MD=0 PATH_EXCLUDES_PATTERN=includes/lib/ + +function after_wp_install { + echo "Installing REST API..." + svn export -q https://plugins.svn.wordpress.org/jetpack/trunk/ "$WP_CORE_DIR/src/wp-content/plugins/jetpack" +} \ No newline at end of file diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 6ab7d887790..cc221773a0e 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -140,9 +140,13 @@ 'content' => 'https://stuckincustoms.smugmug.com/Portfolio/i-GnwtS8R/A', ), array( - 'heading' => 'Soundcloud Embed', + 'heading' => 'SoundCloud Embed', 'content' => 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor', ), + array( + 'heading' => 'SoundCloud Shortcode', + 'content' => '[soundcloud url="https://api.soundcloud.com/tracks/89299804"]', + ), array( 'heading' => 'Speaker Deck Embed', 'content' => 'https://speakerdeck.com/caitiem20/distributed-sagas-a-protocol-for-coordinating-microservices', @@ -209,7 +213,7 @@ function amp_get_media_items_ids( $type, $image_count = 3 ) { $posts_count = count( $posts ); if ( $posts_count < $image_count ) { WP_CLI::error( sprintf( - '%1$s "2$s" expected, %3$s found. Please make sure at least %1$s "2$s" are accessible and run this script again.', + 'Please make sure at least %1$s "%2$s" attachments are accessible and run this script again.', $image_count, $type, $posts_count diff --git a/includes/embeds/class-amp-soundcloud-embed.php b/includes/embeds/class-amp-soundcloud-embed.php index 4e8b757e235..5e56594c238 100644 --- a/includes/embeds/class-amp-soundcloud-embed.php +++ b/includes/embeds/class-amp-soundcloud-embed.php @@ -9,22 +9,49 @@ * Class AMP_SoundCloud_Embed_Handler */ class AMP_SoundCloud_Embed_Handler extends AMP_Base_Embed_Handler { - const URL_PATTERN = '#https?://api\.soundcloud\.com/tracks/.*#i'; + + /** + * Default height. + * + * @var int + */ protected $DEFAULT_HEIGHT = 200; + /** + * Script slug. + * + * @var string + */ private static $script_slug = 'amp-soundcloud'; + + /** + * Script source. + * + * @var string + */ private static $script_src = 'https://cdn.ampproject.org/v0/amp-soundcloud-0.1.js'; + /** + * Register embed. + */ public function register_embed() { - wp_embed_register_handler( 'amp-soundcloud', self::URL_PATTERN, array( $this, 'oembed' ), -1 ); add_shortcode( 'soundcloud', array( $this, 'shortcode' ) ); + add_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10, 2 ); } + /** + * Unregister embed. + */ public function unregister_embed() { - wp_embed_unregister_handler( 'amp-soundcloud', -1 ); remove_shortcode( 'soundcloud' ); + remove_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10 ); } + /** + * Get scripts needed by component. + * + * @return array Scripts. + */ public function get_scripts() { if ( ! $this->did_convert_elements ) { return array(); @@ -33,21 +60,81 @@ public function get_scripts() { return array( self::$script_slug => self::$script_src ); } - public function oembed( $matches, $attr, $url, $rawattr ) { + /** + * Render oEmbed. + * + * @see \WP_Embed::shortcode() + * + * @deprecated Core's oEmbed handler is now used instead, with embed_oembed_html filter used to convert to AMP. + * @param array $matches URL pattern matches. + * @param array $attr Shortcode attribues. + * @param string $url URL. + * @return string Rendered oEmbed. + */ + public function oembed( $matches, $attr, $url ) { + _deprecated_function( __METHOD__, '0.6.0' ); + unset( $matches, $attr ); $track_id = $this->get_track_id_from_url( $url ); - return $this->render( array( - 'track_id' => $track_id, - ) ); + return $this->render( compact( 'track_id' ) ); } - public function shortcode( $attr ) { + /** + * Filter oEmbed HTML for SoundCloud to convert to AMP. + * + * @param string $cache Cache for oEmbed. + * @param string $url Embed URL. Optional. + * @return string Embed. + */ + public function filter_embed_oembed_html( $cache, $url = null ) { + $parsed_url = wp_parse_url( $url ); + if ( $url && false === strpos( $parsed_url['host'], 'soundcloud.com' ) ) { + return $cache; + } + return $this->parse_amp_component_from_iframe( $cache ); + } - $track_id = false; + /** + * Parse AMP component from iframe. + * + * @param string $html HTML. + * @return string AMP component or empty if unable to determine SoundCloud ID. + */ + private function parse_amp_component_from_iframe( $html ) { + $embed = ''; + if ( preg_match( '#.+?)".*>#', $html, $matches ) ) { + $src = html_entity_decode( $matches['url'], ENT_QUOTES ); + $query = array(); + parse_str( wp_parse_url( $src, PHP_URL_QUERY ), $query ); + if ( ! empty( $query['url'] ) ) { + $embed = $this->render( array( + 'track_id' => $this->get_track_id_from_url( $query['url'] ), + ) ); + } + } + return $embed; + } - if ( isset( $attr['id'] ) ) { - $track_id = $attr['id']; + /** + * Render shortcode. + * + * @param array $attr Shortcode attributes. + * @param string $content Shortcode content. + * @return string Rendered shortcode. + */ + public function shortcode( $attr, $content = null ) { + $output = ''; + if ( function_exists( 'soundcloud_shortcode' ) ) { + if ( empty( $attr['url'] ) && ! empty( $attr['id'] ) ) { + $attr['url'] = 'https://api.soundcloud.com/tracks/' . intval( $attr['id'] ); + } + $output = soundcloud_shortcode( $attr, $content ); + $output = $this->parse_amp_component_from_iframe( $output ); } else { - $url = false; + $url = null; + if ( isset( $attr['id'] ) ) { + $url = 'https://w.soundcloud.com/player/?url=https%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F' . intval( $attr['id'] ); + } + if ( isset( $attr['url'] ) ) { $url = $attr['url']; } elseif ( isset( $attr[0] ) ) { @@ -56,27 +143,28 @@ public function shortcode( $attr ) { $url = shortcode_new_to_old_params( $attr ); } - if ( ! empty( $url ) ) { - $track_id = $this->get_track_id_from_url( $url ); + if ( $url ) { + $output = $this->render_embed_fallback( $url ); } } - - if ( empty( $track_id ) ) { - return ''; - } - - return $this->render( array( - 'track_id' => $track_id, - ) ); + return $output; } + /** + * Render embed. + * + * @param array $args Args. + * @return string Rendered embed. + * @global WP_Embed $wp_embed + */ public function render( $args ) { $args = wp_parse_args( $args, array( 'track_id' => false, + 'url' => null, ) ); if ( empty( $args['track_id'] ) ) { - return AMP_HTML_Utils::build_tag( 'a', array( 'href' => esc_url( $args['url'] ), 'class' => 'amp-wp-embed-fallback' ), esc_html( $args['url'] ) ); + return $this->render_embed_fallback( $args['url'] ); } $this->did_convert_elements = true; @@ -91,11 +179,34 @@ public function render( $args ) { ); } + /** + * Render embed fallback. + * + * @param string $url URL. + * @returns string + */ + private function render_embed_fallback( $url ) { + return AMP_HTML_Utils::build_tag( 'a', + array( + 'href' => esc_url( $url ), + 'class' => 'amp-wp-embed-fallback', + ), + esc_html( $url ) + ); + } + + /** + * Get track_id from URL. + * + * @param string $url URL. + * + * @return string Track ID or empty string if none matched. + */ private function get_track_id_from_url( $url ) { $parsed_url = AMP_WP_Utils::parse_url( $url ); - $tok = explode( '/', $parsed_url['path'] ); - $track_id = $tok[2]; - - return $track_id; + if ( ! preg_match( '#tracks/(?P[^/]+)#', $parsed_url['path'], $matches ) ) { + return ''; + } + return $matches['track_id']; } } diff --git a/phpunit.xml b/phpunit.xml index 1d5d523cffa..a234bdc120d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,6 +6,9 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" > + + + ./tests/ diff --git a/tests/test-amp-soundcloud-embed.php b/tests/test-amp-soundcloud-embed.php index 85490eabea9..b3202b8e2f3 100644 --- a/tests/test-amp-soundcloud-embed.php +++ b/tests/test-amp-soundcloud-embed.php @@ -1,38 +1,82 @@ array( '

Hello world.

', '

Hello world.

' . PHP_EOL, ), 'url_simple' => array( - 'https://api.soundcloud.com/tracks/89299804' . PHP_EOL, - '

' . PHP_EOL, + 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor' . PHP_EOL, + '

' . PHP_EOL, ), + ); - 'shortcode_unnamed_attr_as_url' => array( - '[soundcloud https://api.soundcloud.com/tracks/89299804]' . PHP_EOL, - '' . PHP_EOL, - ), + if ( defined( 'JETPACK__PLUGIN_DIR' ) ) { + require_once JETPACK__PLUGIN_DIR . 'modules/shortcodes/soundcloud.php'; + } - 'shortcode_named_attr_url' => array( - '[soundcloud url=https://api.soundcloud.com/tracks/89299804]' . PHP_EOL, - '' . PHP_EOL, - ), + if ( function_exists( 'soundcloud_shortcode' ) ) { + $data = array_merge( + $data, + array( + // This is supported by Jetpack. + 'shortcode_unnamed_attr_as_url' => array( + '[soundcloud url=https://api.soundcloud.com/tracks/89299804]' . PHP_EOL, + '' . PHP_EOL, + ), - 'shortcode_named_attr_url' => array( - '[soundcloud id=89299804]' . PHP_EOL, - '' . PHP_EOL, - ), + // This apparently only works on WordPress.com. + 'shortcode_with_id' => array( + '[soundcloud id=89299804]' . PHP_EOL, + '' . PHP_EOL, + ), + ) + ); + } - ); + return $data; } /** + * Test conversion. + * + * @covers AMP_SoundCloud_Embed_Handler::filter_embed_oembed_html() + * @covers AMP_SoundCloud_Embed_Handler::shortcode() + * @covers AMP_SoundCloud_Embed_Handler::render() * @dataProvider get_conversion_data + * + * @param string $source Source. + * @param string $expected Expected. */ public function test__conversion( $source, $expected ) { $embed = new AMP_SoundCloud_Embed_Handler(); @@ -42,6 +86,11 @@ public function test__conversion( $source, $expected ) { $this->assertEquals( $expected, $filtered_content ); } + /** + * Get scripts data. + * + * @return array Scripts data. + */ public function get_scripts_data() { return array( 'not_converted' => array( @@ -49,14 +98,20 @@ public function get_scripts_data() { array(), ), 'converted' => array( - 'https://api.soundcloud.com/tracks/89299804' . PHP_EOL, + 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor' . PHP_EOL, array( 'amp-soundcloud' => 'https://cdn.ampproject.org/v0/amp-soundcloud-0.1.js' ), ), ); } /** + * Test get scripts. + * + * @covers AMP_SoundCloud_Embed_Handler::get_scripts() * @dataProvider get_scripts_data + * + * @param string $source Source. + * @param string $expected Expected. */ public function test__get_scripts( $source, $expected ) { $embed = new AMP_SoundCloud_Embed_Handler(); From 938be7247edf20a12f97f88ec7bb778153040446 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 13 Dec 2017 20:07:38 -0800 Subject: [PATCH 08/21] Fix phpunit tests in WP<4.9 due to oEmbeds formerly requiring post context --- tests/test-amp-soundcloud-embed.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test-amp-soundcloud-embed.php b/tests/test-amp-soundcloud-embed.php index b3202b8e2f3..4d6d9ca9e6e 100644 --- a/tests/test-amp-soundcloud-embed.php +++ b/tests/test-amp-soundcloud-embed.php @@ -14,10 +14,23 @@ class AMP_SoundCloud_Embed_Test extends WP_UnitTestCase { /** * Set up. + * + * @global WP_Post $post */ public function setUp() { + global $post; parent::setUp(); + /* + * As #34115 in 4.9 a post is not needed for context to run oEmbeds. Prior ot 4.9, the WP_Embed::shortcode() + * method would short-circuit when this is the case: + * https://github.com/WordPress/wordpress-develop/blob/4.8.4/src/wp-includes/class-wp-embed.php#L192-L193 + * So on WP<4.9 we set a post global to ensure oEmbeds get processed. + */ + if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.9', '<' ) ) { + $post = get_post( $this->factory()->post->create() ); + } + if ( function_exists( 'soundcloud_shortcode' ) ) { add_shortcode( 'soundcloud', 'soundcloud_shortcode' ); } From 45c538cab3884f08f8f72fdb553790c53bb71ae4 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 13 Dec 2017 21:35:44 -0800 Subject: [PATCH 09/21] Fix handling of polldaddy oEmbeds in AMP * Use noscript response from oEmbed as default content. * Include WPCOM_AMP_Polldaddy_Embed by default even when not on WordPress.com; deprecate wpcom/shortcodes.php. * Fix DailyMotion and FunnyOrDie test URLs. * Clean phpcs for class-amp-polldaddy-embed.php --- bin/create-embed-test-post.php | 18 +++- includes/class-amp-autoloader.php | 2 +- .../embeds/class-amp-soundcloud-embed.php | 4 +- .../templates/class-amp-post-template.php | 1 + wpcom-helper.php | 8 +- wpcom/class-amp-polldaddy-embed.php | 86 +++++++++++++++++-- wpcom/shortcodes.php | 10 +-- 7 files changed, 109 insertions(+), 20 deletions(-) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index cc221773a0e..90fdbdb5e7a 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -61,7 +61,7 @@ ), array( 'heading' => 'DailyMotion Embed', - 'content' => 'http://www.dailymotion.com/embed/video/x6bacgf', + 'content' => 'http://www.dailymotion.com/video/x6bacgf', ), array( 'heading' => 'Facebook Post Embed', @@ -81,7 +81,7 @@ ), array( 'heading' => 'Funny Or Die Video Embed', - 'content' => 'http://FunnyOrDie.com/m/b1dn', + 'content' => 'http://www.funnyordie.com/videos/2977012a20/i-still-haven-t-found-the-droids-i-m-looking-for', ), array( 'heading' => 'Hulu Embed', @@ -116,9 +116,21 @@ 'content' => 'http://s1284.photobucket.com/user/adonchin/media/20171116_181841_zpsrjuop6u7.jpg.html', ), array( - 'heading' => 'Polldaddy Embed', + 'heading' => 'Polldaddy Poll oEmbed', 'content' => 'https://polldaddy.com/poll/7012505/', ), + array( + 'heading' => 'Polldaddy Survey oEmbed', + 'content' => 'https://polldaddy.com/s/689f136963604d4f', + ), + array( + 'heading' => 'Polldaddy Poll Shortcode', + 'content' => '[polldaddy poll=7012505 title="Custom poll title"]', + ), + array( + 'heading' => 'Polldaddy Survey Shortcode', + 'content' => '[polldaddy survey=689f136963604d4f title="Custom survey title"]', + ), array( 'heading' => 'Reddit Embed', 'content' => 'https://www.reddit.com/r/Android/comments/7jbkub/google_maps_will_soon_tell_you_when_its_time_to/?ref=share&ref_source=link', diff --git a/includes/class-amp-autoloader.php b/includes/class-amp-autoloader.php index 74cdc586523..37d943f499a 100644 --- a/includes/class-amp-autoloader.php +++ b/includes/class-amp-autoloader.php @@ -80,7 +80,7 @@ class AMP_Autoloader { 'AMP_Image_Dimension_Extractor' => 'includes/utils/class-amp-image-dimension-extractor', 'AMP_String_Utils' => 'includes/utils/class-amp-string-utils', 'AMP_WP_Utils' => 'includes/utils/class-amp-wp-utils', - 'WPCOM_AMP_Polldaddy_Embed' => 'includes/wpcom/class-amp-polldaddy-embed', + 'WPCOM_AMP_Polldaddy_Embed' => 'wpcom/class-amp-polldaddy-embed', 'AMP_Test_Stub_Sanitizer' => 'tests/stubs', 'AMP_Test_World_Sanitizer' => 'tests/stubs', ); diff --git a/includes/embeds/class-amp-soundcloud-embed.php b/includes/embeds/class-amp-soundcloud-embed.php index 5e56594c238..114a4fbaa56 100644 --- a/includes/embeds/class-amp-soundcloud-embed.php +++ b/includes/embeds/class-amp-soundcloud-embed.php @@ -82,10 +82,10 @@ public function oembed( $matches, $attr, $url ) { * Filter oEmbed HTML for SoundCloud to convert to AMP. * * @param string $cache Cache for oEmbed. - * @param string $url Embed URL. Optional. + * @param string $url Embed URL. * @return string Embed. */ - public function filter_embed_oembed_html( $cache, $url = null ) { + public function filter_embed_oembed_html( $cache, $url ) { $parsed_url = wp_parse_url( $url ); if ( $url && false === strpos( $parsed_url['host'], 'soundcloud.com' ) ) { return $cache; diff --git a/includes/templates/class-amp-post-template.php b/includes/templates/class-amp-post-template.php index e1c5cd3ea82..497146a7a65 100644 --- a/includes/templates/class-amp-post-template.php +++ b/includes/templates/class-amp-post-template.php @@ -362,6 +362,7 @@ private function build_post_content() { 'AMP_Facebook_Embed_Handler' => array(), 'AMP_Pinterest_Embed_Handler' => array(), 'AMP_Gallery_Embed_Handler' => array(), + 'WPCOM_AMP_Polldaddy_Embed' => array(), ), $this->post ), apply_filters( 'amp_content_sanitizers', array( 'AMP_Style_Sanitizer' => array(), diff --git a/wpcom-helper.php b/wpcom-helper.php index 7bf66c55412..37af6a9ee91 100644 --- a/wpcom-helper.php +++ b/wpcom-helper.php @@ -6,10 +6,12 @@ // Disable admin menu add_filter( 'amp_options_menu_is_enabled', '__return_false', 9999 ); +/** + * Disable the_content filters for Jetpack. + * + * @param int $post_id Post ID. + */ function jetpack_amp_disable_the_content_filters( $post_id ) { - // Shortcode overrides. - require_once( dirname( __FILE__ ) . '/wpcom/shortcodes.php' ); - add_filter( 'post_flair_disable', '__return_true', 99 ); add_filter( 'videopress_show_2015_player', '__return_true' ); add_filter( 'protected_embeds_use_form_post', '__return_false' ); diff --git a/wpcom/class-amp-polldaddy-embed.php b/wpcom/class-amp-polldaddy-embed.php index f48c4e8da5b..784fcc0eb4e 100644 --- a/wpcom/class-amp-polldaddy-embed.php +++ b/wpcom/class-amp-polldaddy-embed.php @@ -1,26 +1,100 @@ ' . esc_html( $name ) . '

'; + if ( ! empty( $attr['title'] ) ) { + $output = $this->render_link( $url, $attr['title'] ); + } elseif ( $url ) { + $output = $wp_embed->shortcode( $attr, $url ); + } + + return $output; + } + + /** + * Filter oEmbed HTML for PollDaddy to for AMP output. + * + * @param string $cache Cache for oEmbed. + * @param string $url Embed URL. + * @param array $attr Shortcode attributes. + * @return string Embed. + */ + public function filter_embed_oembed_html( $cache, $url, $attr ) { + $parsed_url = wp_parse_url( $url ); + if ( $url && false === strpos( $parsed_url['host'], 'polldaddy.com' ) ) { + return $cache; + } + + $output = ''; + + // Poll oEmbed responses include noscript. + if ( preg_match( '##', $cache, $matches ) ) { + $output = $matches[1]; + } + + if ( empty( $output ) ) { + if ( ! empty( $attr['title'] ) ) { + $name = $attr['title']; + } elseif ( false !== strpos( $url, 'polldaddy.com/s' ) ) { + $name = __( 'View Survey', 'amp' ); + } else { + $name = __( 'View Poll', 'amp' ); + } + $output = $this->render_link( $url, $name ); + } + + return $output; + } + + /** + * Render poll/survey link. + * + * @param string $url Link URL. + * @param string $title Link Text. + * @return string Link. + */ + private function render_link( $url, $title ) { + return sprintf( '

' . esc_html( $title ) . '

' ); } } diff --git a/wpcom/shortcodes.php b/wpcom/shortcodes.php index e50402b4c24..977bc280eb3 100644 --- a/wpcom/shortcodes.php +++ b/wpcom/shortcodes.php @@ -5,16 +5,16 @@ * @package AMP */ -add_filter( 'amp_content_embed_handlers', 'wpcom_amp_add_custom_embeds', 10, 2 ); +_deprecated_file( __FILE__, '0.6.0' ); /** * Add custom embeds for WordPress.com. * - * @param array $embed_handler_classes Embed handler classes. - * @param WP_Post $post Post. + * @deprecated Now PollDaddy is supported in core AMP. + * @param array $embed_handler_classes Embed handler classes. * @return mixed */ -function wpcom_amp_add_custom_embeds( $embed_handler_classes, $post ) { - $embed_handler_classes['WPCOM_AMP_Polldaddy_Embed'] = array(); +function wpcom_amp_add_custom_embeds( $embed_handler_classes ) { + _deprecated_function( __FUNCTION__, '0.6.0' ); return $embed_handler_classes; } From 52b306ba1944d101792f7dccd96628a6b93a793d Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Thu, 14 Dec 2017 11:43:18 -0600 Subject: [PATCH 10/21] Issue 806 : Add instructions for using the wp-cli test page script. Add steps to contributing.md to use create-embed-test-post.php. Include a step that this should be inside an environment like VVV. --- contributing.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contributing.md b/contributing.md index 42a970837ef..83a92dddf1e 100644 --- a/contributing.md +++ b/contributing.md @@ -15,6 +15,15 @@ To update that file: 2. run `bash bin/amphtml-update.sh` That script is intended for a Linux environment like [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV). +### Testing Media And Embed Support + +The following script creates a post in order to test support for WordPress media and embeds. +To run it: +1. `ssh` into an environment like [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV) +2. `cd` to the root of this plugin +3. run `wp eval-file bin/create-embed-test-post.php` +4. go to the URL that is output in the command line + ### PHPUnit Testing Please run these tests in an environment with WordPress unit tests installed, like [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV). From eaf51573fd27e936c887b875db4396678bccb487 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Thu, 14 Dec 2017 12:34:26 -0600 Subject: [PATCH 11/21] Issue 804 : Add Amazon, Animoto, and Speakerdeck URLs Add these URLs to test oEmbed. Use the Amazon testing URLs in: https://core.trac.wordpress.org/ticket/38181 Props @jsepia for these URLs. --- bin/create-embed-test-post.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 90fdbdb5e7a..9331f6fba9e 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -43,6 +43,22 @@ 'heading' => 'WordPress Post Embed', 'content' => 'https://make.wordpress.org/core/2017/12/11/whats-new-in-gutenberg-11th-december/', ), + array( + 'heading' => 'Amazon Com Smile Embed', + 'content' => 'https://smile.amazon.com/dp/B00DPM7TIG', + ), + array( + 'heading' => 'Amazon Co Smile Embed', + 'content' => 'https://smile.amazon.co.uk/dp/B00DPM7TIG', + ), + array( + 'heading' => 'Amazon Read CN Embed', + 'content' => 'https://read.amazon.cn/kp/embed?asin=B00DPM7TIG', + ), + array( + 'heading' => 'Animoto Embed', + 'content' => 'https://animoto.com/play/TDfViXkPqIwYj5EjamYjnw', + ), array( 'heading' => 'CloudUp Image Embed', 'content' => 'https://cloudup.com/iWn3EIpgjev', @@ -161,7 +177,7 @@ ), array( 'heading' => 'Speaker Deck Embed', - 'content' => 'https://speakerdeck.com/caitiem20/distributed-sagas-a-protocol-for-coordinating-microservices', + 'content' => 'https://speakerdeck.com/wallat/why-backbone', ), array( 'heading' => 'Spotify Embed', From 8e34745ddc1749f93b4bcea540288f33fc4c0df5 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Thu, 14 Dec 2017 12:44:25 -0600 Subject: [PATCH 12/21] Issue 804 : Update the Scribd URL. Use the URL from @wonderboymusic in: https://core.trac.wordpress.org/ticket/28379. --- bin/create-embed-test-post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 9331f6fba9e..8dab7946189 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -157,7 +157,7 @@ ), array( 'heading' => 'Scribd Embed', - 'content' => '[scribd id=124550852 key=key-1hh4hsgsvzz8jdl28w3v mode=scroll]', + 'content' => 'http://www.scribd.com/doc/110799637/Synthesis-of-Knowledge-Effects-of-Fire-and-Thinning-Treatments-on-Understory-Vegetation-in-Dry-U-S-Forests', ), array( 'heading' => 'SlideShare Embed', From b22e12a3d98795e5b22bd6ba135a2fd19d9d8f75 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 14 Dec 2017 10:26:16 -0800 Subject: [PATCH 13/21] Restore required attachment count in create-embed-test-post; refactor into functions --- .dev-lib | 2 +- bin/create-embed-test-post.php | 526 +++++++++++++++++---------------- 2 files changed, 275 insertions(+), 253 deletions(-) diff --git a/.dev-lib b/.dev-lib index 247d573cc36..3ea07fa9ab8 100644 --- a/.dev-lib +++ b/.dev-lib @@ -4,4 +4,4 @@ PATH_EXCLUDES_PATTERN=includes/lib/ function after_wp_install { echo "Installing REST API..." svn export -q https://plugins.svn.wordpress.org/jetpack/trunk/ "$WP_CORE_DIR/src/wp-content/plugins/jetpack" -} \ No newline at end of file +} diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 8dab7946189..6d70316fa43 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -5,225 +5,229 @@ * @package AMP */ -if ( ! defined( 'WP_CLI' ) ) { - echo "Must be run in WP-CLI via: wp eval-file bin/create-embed-test-post.php\n"; - exit( 1 ); +/** + * Get test data entries. + * + * @throws Exception When there is not enough data in DB. + * @return array Data entries. + */ +function amp_get_test_data_entries() { + return array( + array( + 'heading' => 'Media Gallery', + 'content' => sprintf( '[gallery ids="%s"]', amp_get_media_items_ids( 'image' ) ), + ), + array( + 'heading' => 'Media Image', + 'content' => wp_get_attachment_image( amp_get_media_items_ids( 'image', 1 ) ), + ), + array( + 'heading' => 'Media Caption', + 'content' => sprintf( '[caption width=150]%sExample image caption[/caption]', wp_get_attachment_image( amp_get_media_items_ids( 'image', 1 ) ) ), + ), + array( + 'heading' => 'Media Video', + 'content' => '[video src=https://videos.files.wordpress.com/DK5mLrbr/video-ca6dc0ab4a_hd.mp4]', + ), + array( + 'heading' => 'Media Audio', + 'content' => '[audio src=https://wptavern.com/wp-content/uploads/2017/11/EPISODE-296-Gutenberg-Telemetry-Calypso-and-More-With-Matt-Mullenweg.mp3]', + ), + array( + 'heading' => 'Video Playlist', + 'content' => sprintf( '[playlist type="video" ids="%s"]', amp_get_media_items_ids( 'video' ) ), + ), + array( + 'heading' => 'Audio Playlist', + 'content' => sprintf( '[playlist ids="%s"]', amp_get_media_items_ids( 'audio' ) ), + ), + array( + 'heading' => 'WordPress Post Embed', + 'content' => 'https://make.wordpress.org/core/2017/12/11/whats-new-in-gutenberg-11th-december/', + ), + array( + 'heading' => 'Amazon Com Smile Embed', + 'content' => 'https://smile.amazon.com/dp/B00DPM7TIG', + ), + array( + 'heading' => 'Amazon Co Smile Embed', + 'content' => 'https://smile.amazon.co.uk/dp/B00DPM7TIG', + ), + array( + 'heading' => 'Amazon Read CN Embed', + 'content' => 'https://read.amazon.cn/kp/embed?asin=B00DPM7TIG', + ), + array( + 'heading' => 'Animoto Embed', + 'content' => 'https://animoto.com/play/TDfViXkPqIwYj5EjamYjnw', + ), + array( + 'heading' => 'CloudUp Image Embed', + 'content' => 'https://cloudup.com/iWn3EIpgjev', + ), + array( + 'heading' => 'CloudUp Video Embed', + 'content' => 'https://cloudup.com/ioyW8a_Tjme', + ), + array( + 'heading' => 'CloudUp Gallery Embed', + 'content' => 'https://cloudup.com/cQNdYtQLO5U', + ), + array( + 'heading' => 'CollegeHumor Embed', + 'content' => 'http://www.collegehumor.com/video/40002823/how-to-actually-finish-something-for-once', + ), + array( + 'heading' => 'DailyMotion Embed', + 'content' => 'http://www.dailymotion.com/video/x6bacgf', + ), + array( + 'heading' => 'Facebook Post Embed', + 'content' => 'https://www.facebook.com/WordPress/posts/10155651799877911', + ), + array( + 'heading' => 'Facebook Video Embed', + 'content' => 'https://www.facebook.com/WordPress/videos/10154702401472911/', + ), + array( + 'heading' => 'Flickr Image Embed', + 'content' => 'https://www.flickr.com/photos/sylvainmessier/38089894895/in/explore-2017-12-11/', + ), + array( + 'heading' => 'Flickr Video Embed', + 'content' => 'https://flic.kr/p/5TPDWa', + ), + array( + 'heading' => 'Funny Or Die Video Embed', + 'content' => 'http://www.funnyordie.com/videos/2977012a20/i-still-haven-t-found-the-droids-i-m-looking-for', + ), + array( + 'heading' => 'Hulu Embed', + 'content' => 'https://www.hulu.com/watch/807443', + ), + array( + 'heading' => 'Imgur Embed', + 'content' => '
Takeoff
', + ), + array( + 'heading' => 'Instagram Embed', + 'content' => 'https://www.instagram.com/p/bNd86MSFv6/', + ), + array( + 'heading' => 'Issuu Embed', + 'content' => 'https://issuu.com/ajcwfu/docs/seatatthetablefinal', + ), + array( + 'heading' => 'Kickstarter Embed', + 'content' => 'https://www.kickstarter.com/projects/iananderson/save-froots-magazine', + ), + array( + 'heading' => 'Meetup Embed', + 'content' => 'https://www.meetup.com/WordPress-Mexico', + ), + array( + 'heading' => 'Mixcloud Embed', + 'content' => 'https://www.mixcloud.com/TheWireMagazine/adventures-in-sound-and-music-hosted-by-derek-walmsley-7-december-2017/', + ), + array( + 'heading' => 'Photobucket Embed', + 'content' => 'http://s1284.photobucket.com/user/adonchin/media/20171116_181841_zpsrjuop6u7.jpg.html', + ), + array( + 'heading' => 'Polldaddy Poll oEmbed', + 'content' => 'https://polldaddy.com/poll/7012505/', + ), + array( + 'heading' => 'Polldaddy Survey oEmbed', + 'content' => 'https://polldaddy.com/s/689f136963604d4f', + ), + array( + 'heading' => 'Polldaddy Poll Shortcode', + 'content' => '[polldaddy poll=7012505 title="Custom poll title"]', + ), + array( + 'heading' => 'Polldaddy Survey Shortcode', + 'content' => '[polldaddy survey=689f136963604d4f title="Custom survey title"]', + ), + array( + 'heading' => 'Reddit Embed', + 'content' => 'https://www.reddit.com/r/Android/comments/7jbkub/google_maps_will_soon_tell_you_when_its_time_to/?ref=share&ref_source=link', + ), + array( + 'heading' => 'Reverb Nation Embed', + 'content' => 'https://www.reverbnation.com/fernandotorresleiva/song/28755694-breve-amor-new-version', + ), + array( + 'heading' => 'Scribd Embed', + 'content' => 'http://www.scribd.com/doc/110799637/Synthesis-of-Knowledge-Effects-of-Fire-and-Thinning-Treatments-on-Understory-Vegetation-in-Dry-U-S-Forests', + ), + array( + 'heading' => 'SlideShare Embed', + 'content' => 'https://www.slideshare.net/slideshow/embed_code/key/u6WNbsR5worSzC', + ), + array( + 'heading' => 'SmugMug Embed', + 'content' => 'https://stuckincustoms.smugmug.com/Portfolio/i-GnwtS8R/A', + ), + array( + 'heading' => 'SoundCloud Embed', + 'content' => 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor', + ), + array( + 'heading' => 'SoundCloud Shortcode', + 'content' => '[soundcloud url="https://api.soundcloud.com/tracks/89299804"]', + ), + array( + 'heading' => 'Speaker Deck Embed', + 'content' => 'https://speakerdeck.com/wallat/why-backbone', + ), + array( + 'heading' => 'Spotify Embed', + 'content' => 'https://open.spotify.com/track/2XULDEvijLgHttFgLzzpM5', + ), + array( + 'heading' => 'Ted Embed', + 'content' => 'https://www.ted.com/talks/derek_sivers_how_to_start_a_movement', + ), + array( + 'heading' => 'Tumblr Post Embed', + 'content' => 'https://embed.tumblr.com/embed/post/CHB7nLkCLl-ODZ7tdPU9SQ/168290317795', + ), + array( + 'heading' => 'Twitter Embed', + 'content' => 'https://twitter.com/WordPress/status/936550699336437760', + ), + array( + 'heading' => 'VideoPress Embed', + 'content' => 'https://videopress.com/v/kUJmAcSf', + ), + array( + 'heading' => 'Vimeo Embed', + 'content' => 'https://vimeo.com/59172123', + ), + array( + 'heading' => 'Vine Embed', + 'content' => '[vine url="https://vine.co/v/bEIHZpD2JWz"]', + ), + array( + 'heading' => 'WordPress Plugin Directory Embed', + 'content' => 'https://wordpress.org/plugins/amp/', + ), + array( + 'heading' => 'WordPress TV Embed', + 'content' => 'https://videopress.com/v/DK5mLrbr', + ), + array( + 'heading' => 'YouTube Embed', + 'content' => 'https://www.youtube.com/watch?v=XOY3ZUO6P0k', + ), + ); } -$data_entries = array( - array( - 'heading' => 'Media Gallery', - 'content' => sprintf( '[gallery ids="%s"]', amp_get_media_items_ids( 'image' ) ), - ), - array( - 'heading' => 'Media Image', - 'content' => wp_get_attachment_image( amp_get_media_items_ids( 'image', 1 ) ), - ), - array( - 'heading' => 'Media Caption', - 'content' => sprintf( '[caption width=150]%sExample image caption[/caption]', wp_get_attachment_image( amp_get_media_items_ids( 'image', 1 ) ) ), - ), - array( - 'heading' => 'Media Video', - 'content' => '[video src=https://videos.files.wordpress.com/DK5mLrbr/video-ca6dc0ab4a_hd.mp4]', - ), - array( - 'heading' => 'Media Audio', - 'content' => '[audio src=https://wptavern.com/wp-content/uploads/2017/11/EPISODE-296-Gutenberg-Telemetry-Calypso-and-More-With-Matt-Mullenweg.mp3]', - ), - array( - 'heading' => 'Video Playlist', - 'content' => sprintf( '[playlist type="video" ids="%s"]', amp_get_media_items_ids( 'video' ) ), - ), - array( - 'heading' => 'Audio Playlist', - 'content' => sprintf( '[playlist ids="%s"]', amp_get_media_items_ids( 'audio' ) ), - ), - array( - 'heading' => 'WordPress Post Embed', - 'content' => 'https://make.wordpress.org/core/2017/12/11/whats-new-in-gutenberg-11th-december/', - ), - array( - 'heading' => 'Amazon Com Smile Embed', - 'content' => 'https://smile.amazon.com/dp/B00DPM7TIG', - ), - array( - 'heading' => 'Amazon Co Smile Embed', - 'content' => 'https://smile.amazon.co.uk/dp/B00DPM7TIG', - ), - array( - 'heading' => 'Amazon Read CN Embed', - 'content' => 'https://read.amazon.cn/kp/embed?asin=B00DPM7TIG', - ), - array( - 'heading' => 'Animoto Embed', - 'content' => 'https://animoto.com/play/TDfViXkPqIwYj5EjamYjnw', - ), - array( - 'heading' => 'CloudUp Image Embed', - 'content' => 'https://cloudup.com/iWn3EIpgjev', - ), - array( - 'heading' => 'CloudUp Video Embed', - 'content' => 'https://cloudup.com/ioyW8a_Tjme', - ), - array( - 'heading' => 'CloudUp Gallery Embed', - 'content' => 'https://cloudup.com/cQNdYtQLO5U', - ), - array( - 'heading' => 'CollegeHumor Embed', - 'content' => 'http://www.collegehumor.com/video/40002823/how-to-actually-finish-something-for-once', - ), - array( - 'heading' => 'DailyMotion Embed', - 'content' => 'http://www.dailymotion.com/video/x6bacgf', - ), - array( - 'heading' => 'Facebook Post Embed', - 'content' => 'https://www.facebook.com/WordPress/posts/10155651799877911', - ), - array( - 'heading' => 'Facebook Video Embed', - 'content' => 'https://www.facebook.com/WordPress/videos/10154702401472911/', - ), - array( - 'heading' => 'Flickr Image Embed', - 'content' => 'https://www.flickr.com/photos/sylvainmessier/38089894895/in/explore-2017-12-11/', - ), - array( - 'heading' => 'Flickr Video Embed', - 'content' => 'https://flic.kr/p/5TPDWa', - ), - array( - 'heading' => 'Funny Or Die Video Embed', - 'content' => 'http://www.funnyordie.com/videos/2977012a20/i-still-haven-t-found-the-droids-i-m-looking-for', - ), - array( - 'heading' => 'Hulu Embed', - 'content' => 'https://www.hulu.com/watch/807443', - ), - array( - 'heading' => 'Imgur Embed', - 'content' => '
Takeoff
', - ), - array( - 'heading' => 'Instagram Embed', - 'content' => 'https://www.instagram.com/p/bNd86MSFv6/', - ), - array( - 'heading' => 'Issuu Embed', - 'content' => 'https://issuu.com/ajcwfu/docs/seatatthetablefinal', - ), - array( - 'heading' => 'Kickstarter Embed', - 'content' => 'https://www.kickstarter.com/projects/iananderson/save-froots-magazine', - ), - array( - 'heading' => 'Meetup Embed', - 'content' => 'https://www.meetup.com/WordPress-Mexico', - ), - array( - 'heading' => 'Mixcloud Embed', - 'content' => 'https://www.mixcloud.com/TheWireMagazine/adventures-in-sound-and-music-hosted-by-derek-walmsley-7-december-2017/', - ), - array( - 'heading' => 'Photobucket Embed', - 'content' => 'http://s1284.photobucket.com/user/adonchin/media/20171116_181841_zpsrjuop6u7.jpg.html', - ), - array( - 'heading' => 'Polldaddy Poll oEmbed', - 'content' => 'https://polldaddy.com/poll/7012505/', - ), - array( - 'heading' => 'Polldaddy Survey oEmbed', - 'content' => 'https://polldaddy.com/s/689f136963604d4f', - ), - array( - 'heading' => 'Polldaddy Poll Shortcode', - 'content' => '[polldaddy poll=7012505 title="Custom poll title"]', - ), - array( - 'heading' => 'Polldaddy Survey Shortcode', - 'content' => '[polldaddy survey=689f136963604d4f title="Custom survey title"]', - ), - array( - 'heading' => 'Reddit Embed', - 'content' => 'https://www.reddit.com/r/Android/comments/7jbkub/google_maps_will_soon_tell_you_when_its_time_to/?ref=share&ref_source=link', - ), - array( - 'heading' => 'Reverb Nation Embed', - 'content' => 'https://www.reverbnation.com/fernandotorresleiva/song/28755694-breve-amor-new-version', - ), - array( - 'heading' => 'Scribd Embed', - 'content' => 'http://www.scribd.com/doc/110799637/Synthesis-of-Knowledge-Effects-of-Fire-and-Thinning-Treatments-on-Understory-Vegetation-in-Dry-U-S-Forests', - ), - array( - 'heading' => 'SlideShare Embed', - 'content' => 'https://www.slideshare.net/slideshow/embed_code/key/u6WNbsR5worSzC', - ), - array( - 'heading' => 'SmugMug Embed', - 'content' => 'https://stuckincustoms.smugmug.com/Portfolio/i-GnwtS8R/A', - ), - array( - 'heading' => 'SoundCloud Embed', - 'content' => 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor', - ), - array( - 'heading' => 'SoundCloud Shortcode', - 'content' => '[soundcloud url="https://api.soundcloud.com/tracks/89299804"]', - ), - array( - 'heading' => 'Speaker Deck Embed', - 'content' => 'https://speakerdeck.com/wallat/why-backbone', - ), - array( - 'heading' => 'Spotify Embed', - 'content' => 'https://open.spotify.com/track/2XULDEvijLgHttFgLzzpM5', - ), - array( - 'heading' => 'Ted Embed', - 'content' => 'https://www.ted.com/talks/derek_sivers_how_to_start_a_movement', - ), - array( - 'heading' => 'Tumblr Post Embed', - 'content' => 'https://embed.tumblr.com/embed/post/CHB7nLkCLl-ODZ7tdPU9SQ/168290317795', - ), - array( - 'heading' => 'Twitter Embed', - 'content' => 'https://twitter.com/WordPress/status/936550699336437760', - ), - array( - 'heading' => 'VideoPress Embed', - 'content' => 'https://videopress.com/v/kUJmAcSf', - ), - array( - 'heading' => 'Vimeo Embed', - 'content' => 'https://vimeo.com/59172123', - ), - array( - 'heading' => 'Vine Embed', - 'content' => '[vine url="https://vine.co/v/bEIHZpD2JWz"]', - ), - array( - 'heading' => 'WordPress Plugin Directory Embed', - 'content' => 'https://wordpress.org/plugins/amp/', - ), - array( - 'heading' => 'WordPress TV Embed', - 'content' => 'https://videopress.com/v/DK5mLrbr', - ), - array( - 'heading' => 'YouTube Embed', - 'content' => 'https://www.youtube.com/watch?v=XOY3ZUO6P0k', - ), -); - /** * Get media item ids, using a \WP_Query. * + * @throws Exception When there are not enough posts. * @param integer $type The post_mime_type of the media item. * @param integer $image_count The number of images for which to query. * @return string|WP_CLI::error The media item ids separated by comma on success; error otherwise. @@ -236,55 +240,73 @@ function amp_get_media_items_ids( $type, $image_count = 3 ) { 'posts_per_page' => $image_count, 'fields' => 'ids', ) ); - - $posts = $query->get_posts(); - $posts_count = count( $posts ); - if ( $posts_count < $image_count ) { - WP_CLI::error( sprintf( - 'Please make sure at least %1$s "%2$s" attachments are accessible and run this script again.', + if ( $query->post_count < $image_count ) { + throw new Exception( sprintf( + 'Please make sure at least %1$s "%2$s" attachments are accessible and run this script again. There are currently only %3$s.', $image_count, $type, - $posts_count + $query->found_posts ) ); } - return implode( ',', $posts ); + return implode( ',', $query->get_posts() ); } -// Run the script. -$page = get_page_by_path( '/amp-test-embeds/' ); -if ( $page ) { - $page_id = $page->ID; -} else { - $page_id = wp_insert_post( array( - 'post_name' => 'amp-test-embeds', - 'post_title' => 'AMP Test Embeds', - 'post_type' => 'page', - ) ); +/** + * Create embed test post (page). + * + * @param array $data_entries Data. + * + * @throws Exception But when database doesn't have enough attachments or in case of error. + * @return int Page ID. + */ +function amp_create_embed_test_post( $data_entries ) { + $page = get_page_by_path( '/amp-test-embeds/' ); + if ( $page ) { + $page_id = $page->ID; + } else { + $page_id = wp_insert_post( array( + 'post_name' => 'amp-test-embeds', + 'post_title' => 'AMP Test Embeds', + 'post_type' => 'page', + ) ); - if ( ! $page_id || is_wp_error( $page_id ) ) { - WP_CLI::error( 'The test page could not be added, please try again.' ); + if ( ! $page_id || is_wp_error( $page_id ) ) { + throw new Exception( 'The test page could not be added, please try again.' ); + } } -} -// Build and update content. -$content = ''; -foreach ( $data_entries as $entry ) { - if ( isset( $entry['heading'], $entry['content'] ) ) { - $content .= sprintf( - "

%s

\n%s\n\n", - $entry['heading'], - $entry['content'] - ); + // Build and update content. + $content = ''; + foreach ( $data_entries as $entry ) { + if ( isset( $entry['heading'], $entry['content'] ) ) { + $content .= sprintf( + "

%s

\n%s\n\n", + $entry['heading'], + $entry['content'] + ); + } } -} -$update = wp_update_post( wp_slash( array( - 'ID' => $page_id, - 'post_content' => $content, -) ) ); + $update = wp_update_post( wp_slash( array( + 'ID' => $page_id, + 'post_content' => $content, + ) ) ); -if ( ! $update ) { - WP_CLI::error( 'The test page could not be updated, please try again.' ); + if ( ! $update ) { + throw new Exception( 'The test page could not be updated, please try again.' ); + } + return $update; } -WP_CLI::success( sprintf( 'Please take a look at: %s', get_permalink( $page_id ) ) ); +// Bootstrap. +if ( defined( 'WP_CLI' ) ) { + try { + $post_id = amp_create_embed_test_post( amp_get_test_data_entries() ); + WP_CLI::success( sprintf( 'Please take a look at: %s', get_permalink( $post_id ) ) ); + } catch ( Exception $e ) { + WP_CLI::error( $e->getMessage() ); + } +} else { + echo "Must be run in WP-CLI via: wp eval-file bin/create-embed-test-post.php\n"; + exit( 1 ); +} From f1ee3de14c1202719b5b16f62a38075256fbe5fa Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 14 Dec 2017 10:37:44 -0800 Subject: [PATCH 14/21] Remove DoubleArrowNotAligned PHPCS suppression * Add missing since tag * Update filter_embed_oembed_html calls since $url is required * Add DEFAULT_BASE_BRANCH=develop * Use create_and_get in test --- .dev-lib | 1 + includes/class-amp-autoloader.php | 108 +++++++-------- .../embeds/class-amp-soundcloud-embed.php | 12 +- .../templates/class-amp-post-template.php | 129 ++++++++++-------- phpcs.xml | 3 - tests/test-amp-soundcloud-embed.php | 8 +- wpcom/class-amp-polldaddy-embed.php | 2 +- 7 files changed, 138 insertions(+), 125 deletions(-) diff --git a/.dev-lib b/.dev-lib index 3ea07fa9ab8..9a5b610e301 100644 --- a/.dev-lib +++ b/.dev-lib @@ -1,5 +1,6 @@ SYNC_README_MD=0 PATH_EXCLUDES_PATTERN=includes/lib/ +DEFAULT_BASE_BRANCH=develop function after_wp_install { echo "Installing REST API..." diff --git a/includes/class-amp-autoloader.php b/includes/class-amp-autoloader.php index 37d943f499a..a8edb14b7ff 100644 --- a/includes/class-amp-autoloader.php +++ b/includes/class-amp-autoloader.php @@ -29,60 +29,60 @@ class AMP_Autoloader { * @var string[] */ private static $_classmap = array( - 'AMP_Actions' => 'includes/actions/class-amp-actions', - 'AMP_Frontend_Actions' => 'includes/actions/class-amp-frontend-actions', - 'AMP_Paired_Post_Actions' => 'includes/actions/class-amp-paired-post-actions', - 'AMP_Template_Customizer' => 'includes/admin/class-amp-customizer', - 'AMP_Post_Meta_Box' => 'includes/admin/class-amp-post-meta-box', - 'AMP_Post_Type_Support' => 'includes/class-amp-post-type-support', - 'AMP_Base_Embed_Handler' => 'includes/embeds/class-amp-base-embed-handler', - 'AMP_DailyMotion_Embed_Handler' => 'includes/embeds/class-amp-dailymotion-embed', - 'AMP_Facebook_Embed_Handler' => 'includes/embeds/class-amp-facebook-embed', - 'AMP_Gallery_Embed_Handler' => 'includes/embeds/class-amp-gallery-embed', - 'AMP_Instagram_Embed_Handler' => 'includes/embeds/class-amp-instagram-embed', - 'AMP_Pinterest_Embed_Handler' => 'includes/embeds/class-amp-pinterest-embed', - 'AMP_SoundCloud_Embed_Handler' => 'includes/embeds/class-amp-soundcloud-embed', - 'AMP_Twitter_Embed_Handler' => 'includes/embeds/class-amp-twitter-embed', - 'AMP_Vimeo_Embed_Handler' => 'includes/embeds/class-amp-vimeo-embed', - 'AMP_Vine_Embed_Handler' => 'includes/embeds/class-amp-vine-embed', - 'AMP_YouTube_Embed_Handler' => 'includes/embeds/class-amp-youtube-embed', - 'FastImage' => 'includes/lib/fastimage/class-fastimage', - 'WillWashburn\\Stream\\Exception\\StreamBufferTooSmallException' => 'includes/lib/fasterimage/Stream/Exception/StreamBufferTooSmallException', - 'WillWashburn\\Stream\\StreamableInterface' => 'includes/lib/fasterimage/Stream/StreamableInterface', - 'WillWashburn\\Stream\\Stream' => 'includes/lib/fasterimage/Stream/Stream', - 'FasterImage\\Exception\\InvalidImageException' => 'includes/lib/fasterimage/Exception/InvalidImageException', - 'FasterImage\\ExifParser' => 'includes/lib/fasterimage/ExifParser', - 'FasterImage\\ImageParser' => 'includes/lib/fasterimage/ImageParser', - 'FasterImage\\FasterImage' => 'includes/lib/fasterimage/FasterImage', - 'AMP_Analytics_Options_Submenu' => 'includes/options/class-amp-analytics-options-submenu', - 'AMP_Options_Menu' => 'includes/options/class-amp-options-menu', - 'AMP_Options_Manager' => 'includes/options/class-amp-options-manager', - 'AMP_Analytics_Options_Submenu_Page' => 'includes/options/views/class-amp-analytics-options-submenu-page', - 'AMP_Options_Menu_Page' => 'includes/options/views/class-amp-options-menu-page', - 'AMP_Rule_Spec' => 'includes/sanitizers/class-amp-rule-spec', - 'AMP_Allowed_Tags_Generated' => 'includes/sanitizers/class-amp-allowed-tags-generated', - 'AMP_Audio_Sanitizer' => 'includes/sanitizers/class-amp-audio-sanitizer', - 'AMP_Base_Sanitizer' => 'includes/sanitizers/class-amp-base-sanitizer', - 'AMP_Blacklist_Sanitizer' => 'includes/sanitizers/class-amp-blacklist-sanitizer', - 'AMP_Iframe_Sanitizer' => 'includes/sanitizers/class-amp-iframe-sanitizer', - 'AMP_Img_Sanitizer' => 'includes/sanitizers/class-amp-img-sanitizer', - 'AMP_Playbuzz_Sanitizer' => 'includes/sanitizers/class-amp-playbuzz-sanitizer', - 'AMP_Style_Sanitizer' => 'includes/sanitizers/class-amp-style-sanitizer', - 'AMP_Tag_And_Attribute_Sanitizer' => 'includes/sanitizers/class-amp-tag-and-attribute-sanitizer', - 'AMP_Video_Sanitizer' => 'includes/sanitizers/class-amp-video-sanitizer', - 'AMP_Customizer_Design_Settings' => 'includes/settings/class-amp-customizer-design-settings', - 'AMP_Customizer_Settings' => 'includes/settings/class-amp-customizer-settings', - 'AMP_Content' => 'includes/templates/class-amp-content', - 'AMP_Content_Sanitizer' => 'includes/templates/class-amp-content-sanitizer', - 'AMP_Post_Template' => 'includes/templates/class-amp-post-template', - 'AMP_DOM_Utils' => 'includes/utils/class-amp-dom-utils', - 'AMP_HTML_Utils' => 'includes/utils/class-amp-html-utils', - 'AMP_Image_Dimension_Extractor' => 'includes/utils/class-amp-image-dimension-extractor', - 'AMP_String_Utils' => 'includes/utils/class-amp-string-utils', - 'AMP_WP_Utils' => 'includes/utils/class-amp-wp-utils', - 'WPCOM_AMP_Polldaddy_Embed' => 'wpcom/class-amp-polldaddy-embed', - 'AMP_Test_Stub_Sanitizer' => 'tests/stubs', - 'AMP_Test_World_Sanitizer' => 'tests/stubs', + 'AMP_Actions' => 'includes/actions/class-amp-actions', + 'AMP_Frontend_Actions' => 'includes/actions/class-amp-frontend-actions', + 'AMP_Paired_Post_Actions' => 'includes/actions/class-amp-paired-post-actions', + 'AMP_Template_Customizer' => 'includes/admin/class-amp-customizer', + 'AMP_Post_Meta_Box' => 'includes/admin/class-amp-post-meta-box', + 'AMP_Post_Type_Support' => 'includes/class-amp-post-type-support', + 'AMP_Base_Embed_Handler' => 'includes/embeds/class-amp-base-embed-handler', + 'AMP_DailyMotion_Embed_Handler' => 'includes/embeds/class-amp-dailymotion-embed', + 'AMP_Facebook_Embed_Handler' => 'includes/embeds/class-amp-facebook-embed', + 'AMP_Gallery_Embed_Handler' => 'includes/embeds/class-amp-gallery-embed', + 'AMP_Instagram_Embed_Handler' => 'includes/embeds/class-amp-instagram-embed', + 'AMP_Pinterest_Embed_Handler' => 'includes/embeds/class-amp-pinterest-embed', + 'AMP_SoundCloud_Embed_Handler' => 'includes/embeds/class-amp-soundcloud-embed', + 'AMP_Twitter_Embed_Handler' => 'includes/embeds/class-amp-twitter-embed', + 'AMP_Vimeo_Embed_Handler' => 'includes/embeds/class-amp-vimeo-embed', + 'AMP_Vine_Embed_Handler' => 'includes/embeds/class-amp-vine-embed', + 'AMP_YouTube_Embed_Handler' => 'includes/embeds/class-amp-youtube-embed', + 'FastImage' => 'includes/lib/fastimage/class-fastimage', + 'WillWashburn\Stream\Exception\StreamBufferTooSmallException' => 'includes/lib/fasterimage/Stream/Exception/StreamBufferTooSmallException', + 'WillWashburn\Stream\StreamableInterface' => 'includes/lib/fasterimage/Stream/StreamableInterface', + 'WillWashburn\Stream\Stream' => 'includes/lib/fasterimage/Stream/Stream', + 'FasterImage\Exception\InvalidImageException' => 'includes/lib/fasterimage/Exception/InvalidImageException', + 'FasterImage\ExifParser' => 'includes/lib/fasterimage/ExifParser', + 'FasterImage\ImageParser' => 'includes/lib/fasterimage/ImageParser', + 'FasterImage\FasterImage' => 'includes/lib/fasterimage/FasterImage', + 'AMP_Analytics_Options_Submenu' => 'includes/options/class-amp-analytics-options-submenu', + 'AMP_Options_Menu' => 'includes/options/class-amp-options-menu', + 'AMP_Options_Manager' => 'includes/options/class-amp-options-manager', + 'AMP_Analytics_Options_Submenu_Page' => 'includes/options/views/class-amp-analytics-options-submenu-page', + 'AMP_Options_Menu_Page' => 'includes/options/views/class-amp-options-menu-page', + 'AMP_Rule_Spec' => 'includes/sanitizers/class-amp-rule-spec', + 'AMP_Allowed_Tags_Generated' => 'includes/sanitizers/class-amp-allowed-tags-generated', + 'AMP_Audio_Sanitizer' => 'includes/sanitizers/class-amp-audio-sanitizer', + 'AMP_Base_Sanitizer' => 'includes/sanitizers/class-amp-base-sanitizer', + 'AMP_Blacklist_Sanitizer' => 'includes/sanitizers/class-amp-blacklist-sanitizer', + 'AMP_Iframe_Sanitizer' => 'includes/sanitizers/class-amp-iframe-sanitizer', + 'AMP_Img_Sanitizer' => 'includes/sanitizers/class-amp-img-sanitizer', + 'AMP_Playbuzz_Sanitizer' => 'includes/sanitizers/class-amp-playbuzz-sanitizer', + 'AMP_Style_Sanitizer' => 'includes/sanitizers/class-amp-style-sanitizer', + 'AMP_Tag_And_Attribute_Sanitizer' => 'includes/sanitizers/class-amp-tag-and-attribute-sanitizer', + 'AMP_Video_Sanitizer' => 'includes/sanitizers/class-amp-video-sanitizer', + 'AMP_Customizer_Design_Settings' => 'includes/settings/class-amp-customizer-design-settings', + 'AMP_Customizer_Settings' => 'includes/settings/class-amp-customizer-settings', + 'AMP_Content' => 'includes/templates/class-amp-content', + 'AMP_Content_Sanitizer' => 'includes/templates/class-amp-content-sanitizer', + 'AMP_Post_Template' => 'includes/templates/class-amp-post-template', + 'AMP_DOM_Utils' => 'includes/utils/class-amp-dom-utils', + 'AMP_HTML_Utils' => 'includes/utils/class-amp-html-utils', + 'AMP_Image_Dimension_Extractor' => 'includes/utils/class-amp-image-dimension-extractor', + 'AMP_String_Utils' => 'includes/utils/class-amp-string-utils', + 'AMP_WP_Utils' => 'includes/utils/class-amp-wp-utils', + 'WPCOM_AMP_Polldaddy_Embed' => 'wpcom/class-amp-polldaddy-embed', + 'AMP_Test_Stub_Sanitizer' => 'tests/stubs', + 'AMP_Test_World_Sanitizer' => 'tests/stubs', ); /** diff --git a/includes/embeds/class-amp-soundcloud-embed.php b/includes/embeds/class-amp-soundcloud-embed.php index 114a4fbaa56..03d269a9484 100644 --- a/includes/embeds/class-amp-soundcloud-embed.php +++ b/includes/embeds/class-amp-soundcloud-embed.php @@ -7,6 +7,8 @@ /** * Class AMP_SoundCloud_Embed_Handler + * + * @since 0.5 */ class AMP_SoundCloud_Embed_Handler extends AMP_Base_Embed_Handler { @@ -87,7 +89,7 @@ public function oembed( $matches, $attr, $url ) { */ public function filter_embed_oembed_html( $cache, $url ) { $parsed_url = wp_parse_url( $url ); - if ( $url && false === strpos( $parsed_url['host'], 'soundcloud.com' ) ) { + if ( false === strpos( $parsed_url['host'], 'soundcloud.com' ) ) { return $cache; } return $this->parse_amp_component_from_iframe( $cache ); @@ -160,7 +162,7 @@ public function shortcode( $attr, $content = null ) { public function render( $args ) { $args = wp_parse_args( $args, array( 'track_id' => false, - 'url' => null, + 'url' => null, ) ); if ( empty( $args['track_id'] ) ) { @@ -173,8 +175,8 @@ public function render( $args ) { 'amp-soundcloud', array( 'data-trackid' => $args['track_id'], - 'layout' => 'fixed-height', - 'height' => $this->args['height'], + 'layout' => 'fixed-height', + 'height' => $this->args['height'], ) ); } @@ -188,7 +190,7 @@ public function render( $args ) { private function render_embed_fallback( $url ) { return AMP_HTML_Utils::build_tag( 'a', array( - 'href' => esc_url( $url ), + 'href' => esc_url( $url ), 'class' => 'amp-wp-embed-fallback', ), esc_html( $url ) diff --git a/includes/templates/class-amp-post-template.php b/includes/templates/class-amp-post-template.php index 497146a7a65..ae6453fd3c9 100644 --- a/includes/templates/class-amp-post-template.php +++ b/includes/templates/class-amp-post-template.php @@ -142,7 +142,7 @@ public function __construct( $post ) { * @param array $analytics An associative array of the analytics entries we want to output. Each array entry must have a unique key, and the value should be an array with the following keys: `type`, `attributes`, `script_data`. See readme for more details. * @param WP_Post $post The current post. */ - 'amp_analytics' => apply_filters( 'amp_post_template_analytics', array(), $this->post ), + 'amp_analytics' => apply_filters( 'amp_post_template_analytics', array(), $this->post ), ); $this->build_post_content(); @@ -270,14 +270,16 @@ private function build_post_data() { $post_modified_timestamp = get_post_modified_time( 'U', false, $this->post ); $post_author = get_userdata( $this->post->post_author ); - $this->add_data( array( - 'post' => $this->post, - 'post_id' => $this->ID, - 'post_title' => $post_title, - 'post_publish_timestamp' => $post_publish_timestamp, - 'post_modified_timestamp' => $post_modified_timestamp, - 'post_author' => $post_author, - ) ); + $this->add_data( + array( + 'post' => $this->post, + 'post_id' => $this->ID, + 'post_title' => $post_title, + 'post_publish_timestamp' => $post_publish_timestamp, + 'post_modified_timestamp' => $post_modified_timestamp, + 'post_author' => $post_author, + ) + ); $metadata = array( '@context' => 'http://schema.org', @@ -301,10 +303,10 @@ private function build_post_data() { $site_icon_url = $this->get( 'site_icon_url' ); if ( $site_icon_url ) { $metadata['publisher']['logo'] = array( - '@type' => 'ImageObject', - 'url' => $site_icon_url, + '@type' => 'ImageObject', + 'url' => $site_icon_url, 'height' => self::SITE_ICON_SIZE, - 'width' => self::SITE_ICON_SIZE, + 'width' => self::SITE_ICON_SIZE, ); } @@ -340,41 +342,48 @@ private function build_post_commments_data() { ? __( 'Leave a Comment', 'amp' ) : __( 'View Comments', 'amp' ); - $this->add_data( array( - 'comments_link_url' => $comments_link_url, - 'comments_link_text' => $comments_link_text, - ) ); + $this->add_data( + array( + 'comments_link_url' => $comments_link_url, + 'comments_link_text' => $comments_link_text, + ) + ); } /** * Build post content. */ private function build_post_content() { - $amp_content = new AMP_Content( $this->post->post_content, - apply_filters( 'amp_content_embed_handlers', array( - 'AMP_Twitter_Embed_Handler' => array(), - 'AMP_YouTube_Embed_Handler' => array(), - 'AMP_DailyMotion_Embed_Handler' => array(), - 'AMP_Vimeo_Embed_Handler' => array(), - 'AMP_SoundCloud_Embed_Handler' => array(), - 'AMP_Instagram_Embed_Handler' => array(), - 'AMP_Vine_Embed_Handler' => array(), - 'AMP_Facebook_Embed_Handler' => array(), - 'AMP_Pinterest_Embed_Handler' => array(), - 'AMP_Gallery_Embed_Handler' => array(), - 'WPCOM_AMP_Polldaddy_Embed' => array(), - ), $this->post ), - apply_filters( 'amp_content_sanitizers', array( - 'AMP_Style_Sanitizer' => array(), - 'AMP_Img_Sanitizer' => array(), - 'AMP_Video_Sanitizer' => array(), - 'AMP_Audio_Sanitizer' => array(), - 'AMP_Playbuzz_Sanitizer' => array(), - 'AMP_Tag_And_Attribute_Sanitizer' => array(), - 'AMP_Iframe_Sanitizer' => array( - 'add_placeholder' => true, - ), - ), $this->post ), + $amp_content = new AMP_Content( + $this->post->post_content, + apply_filters( + 'amp_content_embed_handlers', array( + 'AMP_Twitter_Embed_Handler' => array(), + 'AMP_YouTube_Embed_Handler' => array(), + 'AMP_DailyMotion_Embed_Handler' => array(), + 'AMP_Vimeo_Embed_Handler' => array(), + 'AMP_SoundCloud_Embed_Handler' => array(), + 'AMP_Instagram_Embed_Handler' => array(), + 'AMP_Vine_Embed_Handler' => array(), + 'AMP_Facebook_Embed_Handler' => array(), + 'AMP_Pinterest_Embed_Handler' => array(), + 'AMP_Gallery_Embed_Handler' => array(), + 'WPCOM_AMP_Polldaddy_Embed' => array(), + ), $this->post + ), + apply_filters( + 'amp_content_sanitizers', array( + 'AMP_Style_Sanitizer' => array(), + 'AMP_Img_Sanitizer' => array(), + 'AMP_Video_Sanitizer' => array(), + 'AMP_Audio_Sanitizer' => array(), + 'AMP_Playbuzz_Sanitizer' => array(), + 'AMP_Tag_And_Attribute_Sanitizer' => array(), + 'AMP_Iframe_Sanitizer' => array( + 'add_placeholder' => true, + ), + ), $this->post + ), array( 'content_max_width' => $this->get( 'content_max_width' ), ) @@ -418,10 +427,12 @@ private function build_post_featured_image() { ) ); - $this->add_data_by_key( 'featured_image', array( - 'amp_html' => $sanitized_html, - 'caption' => $featured_image->post_excerpt, - ) ); + $this->add_data_by_key( + 'featured_image', array( + 'amp_html' => $sanitized_html, + 'caption' => $featured_image->post_excerpt, + ) + ); if ( $featured_scripts ) { $this->merge_data_for_key( 'amp_component_scripts', $featured_scripts ); @@ -467,16 +478,18 @@ private function get_post_image_metadata() { if ( has_post_thumbnail( $this->ID ) ) { $post_image_id = get_post_thumbnail_id( $this->ID ); } else { - $attached_image_ids = get_posts( array( - 'post_parent' => $this->ID, - 'post_type' => 'attachment', - 'post_mime_type' => 'image', - 'posts_per_page' => 1, - 'orderby' => 'menu_order', - 'order' => 'ASC', - 'fields' => 'ids', - 'suppress_filters' => false, - ) ); + $attached_image_ids = get_posts( + array( + 'post_parent' => $this->ID, + 'post_type' => 'attachment', + 'post_mime_type' => 'image', + 'posts_per_page' => 1, + 'orderby' => 'menu_order', + 'order' => 'ASC', + 'fields' => 'ids', + 'suppress_filters' => false, + ) + ); if ( ! empty( $attached_image_ids ) ) { $post_image_id = array_shift( $attached_image_ids ); @@ -491,9 +504,9 @@ private function get_post_image_metadata() { if ( is_array( $post_image_src ) ) { $post_image_meta = array( - '@type' => 'ImageObject', - 'url' => $post_image_src[0], - 'width' => $post_image_src[1], + '@type' => 'ImageObject', + 'url' => $post_image_src[0], + 'width' => $post_image_src[1], 'height' => $post_image_src[2], ); } diff --git a/phpcs.xml b/phpcs.xml index ac2ddd22f33..8783262c975 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -17,9 +17,6 @@ tests/test-tag-and-attribute-sanitizer.php - - 0 - includes/actions/class-amp-paired-post-actions.php diff --git a/tests/test-amp-soundcloud-embed.php b/tests/test-amp-soundcloud-embed.php index 4d6d9ca9e6e..a4156cc4493 100644 --- a/tests/test-amp-soundcloud-embed.php +++ b/tests/test-amp-soundcloud-embed.php @@ -28,7 +28,7 @@ public function setUp() { * So on WP<4.9 we set a post global to ensure oEmbeds get processed. */ if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.9', '<' ) ) { - $post = get_post( $this->factory()->post->create() ); + $post = $this->factory()->post->create_and_get(); } if ( function_exists( 'soundcloud_shortcode' ) ) { @@ -43,7 +43,7 @@ public function setUp() { */ public function get_conversion_data() { $data = array( - 'no_embed' => array( + 'no_embed' => array( '

Hello world.

', '

Hello world.

' . PHP_EOL, ), @@ -69,7 +69,7 @@ public function get_conversion_data() { ), // This apparently only works on WordPress.com. - 'shortcode_with_id' => array( + 'shortcode_with_id' => array( '[soundcloud id=89299804]' . PHP_EOL, '' . PHP_EOL, ), @@ -110,7 +110,7 @@ public function get_scripts_data() { '

Hello World.

', array(), ), - 'converted' => array( + 'converted' => array( 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor' . PHP_EOL, array( 'amp-soundcloud' => 'https://cdn.ampproject.org/v0/amp-soundcloud-0.1.js' ), ), diff --git a/wpcom/class-amp-polldaddy-embed.php b/wpcom/class-amp-polldaddy-embed.php index 784fcc0eb4e..812605d50df 100644 --- a/wpcom/class-amp-polldaddy-embed.php +++ b/wpcom/class-amp-polldaddy-embed.php @@ -62,7 +62,7 @@ public function shortcode( $attr ) { */ public function filter_embed_oembed_html( $cache, $url, $attr ) { $parsed_url = wp_parse_url( $url ); - if ( $url && false === strpos( $parsed_url['host'], 'polldaddy.com' ) ) { + if ( false === strpos( $parsed_url['host'], 'polldaddy.com' ) ) { return $cache; } From a91d7adb729e4bcdcb1b8763f2bb709e7509a0b6 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 14 Dec 2017 11:02:15 -0800 Subject: [PATCH 15/21] Fix order of sanitizers to ensure whitelist applies at end, after iframe sanitizer has run Issue introduced in 575ac66a73c5f3ab24df014f0ba00c1b653d83e9 --- bin/create-embed-test-post.php | 2 +- includes/templates/class-amp-post-template.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 6d70316fa43..195dbcb64b8 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -302,7 +302,7 @@ function amp_create_embed_test_post( $data_entries ) { if ( defined( 'WP_CLI' ) ) { try { $post_id = amp_create_embed_test_post( amp_get_test_data_entries() ); - WP_CLI::success( sprintf( 'Please take a look at: %s', get_permalink( $post_id ) ) ); + WP_CLI::success( sprintf( 'Please take a look at: %s', amp_get_permalink( $post_id ) ) ); } catch ( Exception $e ) { WP_CLI::error( $e->getMessage() ); } diff --git a/includes/templates/class-amp-post-template.php b/includes/templates/class-amp-post-template.php index ae6453fd3c9..2f88c6545f4 100644 --- a/includes/templates/class-amp-post-template.php +++ b/includes/templates/class-amp-post-template.php @@ -378,10 +378,10 @@ private function build_post_content() { 'AMP_Video_Sanitizer' => array(), 'AMP_Audio_Sanitizer' => array(), 'AMP_Playbuzz_Sanitizer' => array(), - 'AMP_Tag_And_Attribute_Sanitizer' => array(), 'AMP_Iframe_Sanitizer' => array( 'add_placeholder' => true, ), + 'AMP_Tag_And_Attribute_Sanitizer' => array(), // Note: This whitelist sanitizer must come at the end to clean up any remaining issues the other sanitizers didn't catch. ), $this->post ), array( From 499e58050c375fe613fa603b19dc6dcea5eddafc Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Thu, 14 Dec 2017 12:44:25 -0600 Subject: [PATCH 16/21] Issue 806 : Update the Photobucket and Scribd URLs. Thanks to ohthenoes for the Photobucket link in: https://core.trac.wordpress.org/ticket/13754 And thanks to @wonderboymusic for the Scribd URL from: https://core.trac.wordpress.org/ticket/28379. --- bin/create-embed-test-post.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 9331f6fba9e..a931c14f9cd 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -129,7 +129,7 @@ ), array( 'heading' => 'Photobucket Embed', - 'content' => 'http://s1284.photobucket.com/user/adonchin/media/20171116_181841_zpsrjuop6u7.jpg.html', + 'content' => 'http://i69.photobucket.com/albums/i70/apheli0n/quick%20uploads/addsiteerror.jpg', ), array( 'heading' => 'Polldaddy Poll oEmbed', @@ -157,7 +157,7 @@ ), array( 'heading' => 'Scribd Embed', - 'content' => '[scribd id=124550852 key=key-1hh4hsgsvzz8jdl28w3v mode=scroll]', + 'content' => 'http://www.scribd.com/doc/110799637/Synthesis-of-Knowledge-Effects-of-Fire-and-Thinning-Treatments-on-Understory-Vegetation-in-Dry-U-S-Forests', ), array( 'heading' => 'SlideShare Embed', From d2dd0325c0ed5f29dc712e11ceabcd8cb0d6472f Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Thu, 14 Dec 2017 13:31:06 -0600 Subject: [PATCH 17/21] Issue 806 : Remove Vine embed, add Screencast embed. Add a Screencast embed, thanks to designsimply's URL in: https://core.trac.wordpress.org/ticket/24660 Because Vine isn't supported anymore, remove its test URL. @see wordpress-develop/src/wp-includes/class-oembed.php --- bin/create-embed-test-post.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 195dbcb64b8..8c1f3853ef8 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -131,7 +131,7 @@ function amp_get_test_data_entries() { ), array( 'heading' => 'Photobucket Embed', - 'content' => 'http://s1284.photobucket.com/user/adonchin/media/20171116_181841_zpsrjuop6u7.jpg.html', + 'content' => 'http://i69.photobucket.com/albums/i70/apheli0n/quick%20uploads/addsiteerror.jpg', ), array( 'heading' => 'Polldaddy Poll oEmbed', @@ -157,6 +157,10 @@ function amp_get_test_data_entries() { 'heading' => 'Reverb Nation Embed', 'content' => 'https://www.reverbnation.com/fernandotorresleiva/song/28755694-breve-amor-new-version', ), + array( + 'heading' => 'Screencast Embed', + 'content' => 'http://screencast.com/t/nMCYr3N3uF', + ), array( 'heading' => 'Scribd Embed', 'content' => 'http://www.scribd.com/doc/110799637/Synthesis-of-Knowledge-Effects-of-Fire-and-Thinning-Treatments-on-Understory-Vegetation-in-Dry-U-S-Forests', @@ -205,10 +209,6 @@ function amp_get_test_data_entries() { 'heading' => 'Vimeo Embed', 'content' => 'https://vimeo.com/59172123', ), - array( - 'heading' => 'Vine Embed', - 'content' => '[vine url="https://vine.co/v/bEIHZpD2JWz"]', - ), array( 'heading' => 'WordPress Plugin Directory Embed', 'content' => 'https://wordpress.org/plugins/amp/', From 8732936a4ce06897c2bf86166f1eb2f8ef2f1406 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Thu, 14 Dec 2017 13:42:50 -0600 Subject: [PATCH 18/21] Issue 806 : Add tests for Someecards. Both the full URL, and the short URL ending with the TLD .ly. They both render well in AMP. --- bin/create-embed-test-post.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 8c1f3853ef8..25188c7a65e 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -173,6 +173,14 @@ function amp_get_test_data_entries() { 'heading' => 'SmugMug Embed', 'content' => 'https://stuckincustoms.smugmug.com/Portfolio/i-GnwtS8R/A', ), + array( + 'heading' => 'Someecards Embed', + 'content' => 'https://www.someecards.com/usercards/viewcard/mjaxmi1jmgy2y2exm2m2ngu2ntfi/?tagSlug=christmas', + ), + array( + 'heading' => 'Someecards Short URL Embed', + 'content' => 'https://some.ly/V3RZUq/', + ), array( 'heading' => 'SoundCloud Embed', 'content' => 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor', From 5bce94fbadde0511e501637b05ca884abef68e75 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 14 Dec 2017 11:42:12 -0800 Subject: [PATCH 19/21] Fix phpcs issues in class-amp-rule-spec.php --- includes/sanitizers/class-amp-rule-spec.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/sanitizers/class-amp-rule-spec.php b/includes/sanitizers/class-amp-rule-spec.php index 19320fd2262..694b7dcf7df 100644 --- a/includes/sanitizers/class-amp-rule-spec.php +++ b/includes/sanitizers/class-amp-rule-spec.php @@ -92,20 +92,20 @@ abstract class AMP_Rule_Spec { */ 'amp-share-tracking' => array( 'attr_spec_list' => array(), - 'tag_spec' => array(), + 'tag_spec' => array(), ), /** * Needed for some tags such as analytics */ - 'script' => array( + 'script' => array( 'attr_spec_list' => array( 'type' => array( - 'mandatory' => true, + 'mandatory' => true, 'value_casei' => 'text/javascript', ), ), - 'tag_spec' => array(), + 'tag_spec' => array(), ), ); } From e885b7a3c70c8d30080ad8e38683f443744f5dd4 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Thu, 14 Dec 2017 16:33:23 -0600 Subject: [PATCH 20/21] Issue 806 : Correct embeds, including Imgur, Polldaddy, Screencast. Change the URLs for most of these. And remove the soundcloud shortcode. This isn't supported natively. --- bin/create-embed-test-post.php | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 25188c7a65e..0f230c95d80 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -107,7 +107,7 @@ function amp_get_test_data_entries() { ), array( 'heading' => 'Imgur Embed', - 'content' => '
Takeoff
', + 'content' => 'https://imgur.com/HNQ2WRt', ), array( 'heading' => 'Instagram Embed', @@ -134,20 +134,12 @@ function amp_get_test_data_entries() { 'content' => 'http://i69.photobucket.com/albums/i70/apheli0n/quick%20uploads/addsiteerror.jpg', ), array( - 'heading' => 'Polldaddy Poll oEmbed', + 'heading' => 'Polldaddy Poll Embed', 'content' => 'https://polldaddy.com/poll/7012505/', ), array( - 'heading' => 'Polldaddy Survey oEmbed', - 'content' => 'https://polldaddy.com/s/689f136963604d4f', - ), - array( - 'heading' => 'Polldaddy Poll Shortcode', - 'content' => '[polldaddy poll=7012505 title="Custom poll title"]', - ), - array( - 'heading' => 'Polldaddy Survey Shortcode', - 'content' => '[polldaddy survey=689f136963604d4f title="Custom survey title"]', + 'heading' => 'Polldaddy Survey Embed', + 'content' => 'https://rydk.polldaddy.com/s/test-survey', ), array( 'heading' => 'Reddit Embed', @@ -159,7 +151,7 @@ function amp_get_test_data_entries() { ), array( 'heading' => 'Screencast Embed', - 'content' => 'http://screencast.com/t/nMCYr3N3uF', + 'content' => 'http://www.screencast.com/t/nMCYr3N3uF', ), array( 'heading' => 'Scribd Embed', @@ -185,10 +177,6 @@ function amp_get_test_data_entries() { 'heading' => 'SoundCloud Embed', 'content' => 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor', ), - array( - 'heading' => 'SoundCloud Shortcode', - 'content' => '[soundcloud url="https://api.soundcloud.com/tracks/89299804"]', - ), array( 'heading' => 'Speaker Deck Embed', 'content' => 'https://speakerdeck.com/wallat/why-backbone', From ed6088dcb818459ac45318f3ccda26faa5791691 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Thu, 14 Dec 2017 17:01:20 -0600 Subject: [PATCH 21/21] Issue 806 : Update Photobucket, Tumblr, remove Imgur. Use mrdenn1s's image from his Trac ticket: https://core.trac.wordpress.org/ticket/28345 It looks like Imgur oEmbeds no longer work in WordPress. @see https://core.trac.wordpress.org/ticket/42247 --- bin/create-embed-test-post.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 0f230c95d80..e66857e7085 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -105,10 +105,6 @@ function amp_get_test_data_entries() { 'heading' => 'Hulu Embed', 'content' => 'https://www.hulu.com/watch/807443', ), - array( - 'heading' => 'Imgur Embed', - 'content' => 'https://imgur.com/HNQ2WRt', - ), array( 'heading' => 'Instagram Embed', 'content' => 'https://www.instagram.com/p/bNd86MSFv6/', @@ -131,7 +127,7 @@ function amp_get_test_data_entries() { ), array( 'heading' => 'Photobucket Embed', - 'content' => 'http://i69.photobucket.com/albums/i70/apheli0n/quick%20uploads/addsiteerror.jpg', + 'content' => 'http://i1259.photobucket.com/albums/ii543/iamnotpeterpan/EditPostlsaquoDennisDoesCricketmdashWordPress_zpsf72cc13d.png', ), array( 'heading' => 'Polldaddy Poll Embed', @@ -191,7 +187,7 @@ function amp_get_test_data_entries() { ), array( 'heading' => 'Tumblr Post Embed', - 'content' => 'https://embed.tumblr.com/embed/post/CHB7nLkCLl-ODZ7tdPU9SQ/168290317795', + 'content' => 'http://ifpaintingscouldtext.tumblr.com/post/92003045635/grant-wood-american-gothic-1930', ), array( 'heading' => 'Twitter Embed',