From c7c227be6f3e61dda3b09b843ce2fc6e4dbff66f Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Thu, 8 Mar 2018 12:34:21 -0500 Subject: [PATCH 1/8] remove AMP_WP_Utils class and tests --- includes/class-amp-autoloader.php | 1 - includes/utils/class-amp-wp-utils.php | 61 --------------------------- tests/test-amp-wp-utils.php | 47 --------------------- 3 files changed, 109 deletions(-) delete mode 100644 includes/utils/class-amp-wp-utils.php delete mode 100644 tests/test-amp-wp-utils.php diff --git a/includes/class-amp-autoloader.php b/includes/class-amp-autoloader.php index 3ec923b7bde..0533b2dd96b 100644 --- a/includes/class-amp-autoloader.php +++ b/includes/class-amp-autoloader.php @@ -86,7 +86,6 @@ class AMP_Autoloader { 'AMP_Image_Dimension_Extractor' => 'includes/utils/class-amp-image-dimension-extractor', 'AMP_Validation_Utils' => 'includes/utils/class-amp-validation-utils', 'AMP_String_Utils' => 'includes/utils/class-amp-string-utils', - 'AMP_WP_Utils' => 'includes/utils/class-amp-wp-utils', 'AMP_Widget_Archives' => 'includes/widgets/class-amp-widget-archives', 'AMP_Widget_Categories' => 'includes/widgets/class-amp-widget-categories', 'AMP_Widget_Media_Video' => 'includes/widgets/class-amp-widget-media-video', diff --git a/includes/utils/class-amp-wp-utils.php b/includes/utils/class-amp-wp-utils.php deleted file mode 100644 index bacb72458af..00000000000 --- a/includes/utils/class-amp-wp-utils.php +++ /dev/null @@ -1,61 +0,0 @@ - 'scheme', - PHP_URL_HOST => 'host', - PHP_URL_PORT => 'port', - PHP_URL_USER => 'user', - PHP_URL_PASS => 'pass', - PHP_URL_PATH => 'path', - PHP_URL_QUERY => 'query', - PHP_URL_FRAGMENT => 'fragment', - ); - - if ( isset( $translation[ $constant ] ) ) { - return $translation[ $constant ]; - } - - return false; - } -} diff --git a/tests/test-amp-wp-utils.php b/tests/test-amp-wp-utils.php deleted file mode 100644 index 43f3b3a572e..00000000000 --- a/tests/test-amp-wp-utils.php +++ /dev/null @@ -1,47 +0,0 @@ - array( - 'https://example.com/path', - array( - 'scheme' => 'https', - 'host' => 'example.com', - 'path' => '/path', - ), - -1, - ), - - 'valid__with_component' => array( - 'https://example.com/path', - 'example.com', - PHP_URL_HOST, - ), - - 'valid__schemaless__no_component' => array( - '//example.com/path', - array( - 'host' => 'example.com', - 'path' => '/path', - ), - -1, - ), - - 'valid__schemaless__with_component' => array( - '//example.com/path', - 'example.com', - PHP_URL_HOST, - ), - ); - } - - /** - * @dataProvider get_test_data - */ - function test__method( $url, $expected, $component ) { - $actual = AMP_WP_Utils::parse_url( $url, $component ); - - $this->assertEquals( $expected, $actual ); - } -} From 65b88f7f24649a2f859624134c455d612eb837ea Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Thu, 8 Mar 2018 12:35:33 -0500 Subject: [PATCH 2/8] replace AMP_WP_Utils::parse_url() with wp_parse_url() --- includes/embeds/class-amp-dailymotion-embed.php | 2 +- includes/embeds/class-amp-soundcloud-embed.php | 2 +- includes/embeds/class-amp-youtube-embed.php | 2 +- includes/sanitizers/class-amp-img-sanitizer.php | 2 +- .../class-amp-tag-and-attribute-sanitizer.php | 10 +++++----- includes/utils/class-amp-image-dimension-extractor.php | 2 +- jetpack-helper.php | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/includes/embeds/class-amp-dailymotion-embed.php b/includes/embeds/class-amp-dailymotion-embed.php index 7c58905948f..0ba6a7ce45c 100644 --- a/includes/embeds/class-amp-dailymotion-embed.php +++ b/includes/embeds/class-amp-dailymotion-embed.php @@ -88,7 +88,7 @@ public function render( $args ) { } private function get_video_id_from_url( $url ) { - $parsed_url = AMP_WP_Utils::parse_url( $url ); + $parsed_url = wp_parse_url( $url ); parse_str( $parsed_url['path'], $path ); $tok = explode( '/', $parsed_url['path'] ); $tok = explode( '_', $tok[2] ); diff --git a/includes/embeds/class-amp-soundcloud-embed.php b/includes/embeds/class-amp-soundcloud-embed.php index bc2a5b83abe..c0c00616e81 100644 --- a/includes/embeds/class-amp-soundcloud-embed.php +++ b/includes/embeds/class-amp-soundcloud-embed.php @@ -178,7 +178,7 @@ private function render_embed_fallback( $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 ); + $parsed_url = wp_parse_url( $url ); if ( ! preg_match( '#tracks/(?P[^/]+)#', $parsed_url['path'], $matches ) ) { return ''; } diff --git a/includes/embeds/class-amp-youtube-embed.php b/includes/embeds/class-amp-youtube-embed.php index a019a6a6334..4d6863827c7 100644 --- a/includes/embeds/class-amp-youtube-embed.php +++ b/includes/embeds/class-amp-youtube-embed.php @@ -89,7 +89,7 @@ public function render( $args ) { private function get_video_id_from_url( $url ) { $video_id = false; - $parsed_url = AMP_WP_Utils::parse_url( $url ); + $parsed_url = wp_parse_url( $url ); if ( self::SHORT_URL_HOST === substr( $parsed_url['host'], -strlen( self::SHORT_URL_HOST ) ) ) { // youtu.be/{id} diff --git a/includes/sanitizers/class-amp-img-sanitizer.php b/includes/sanitizers/class-amp-img-sanitizer.php index 86fe45e2770..5a9bd2f5d7c 100644 --- a/includes/sanitizers/class-amp-img-sanitizer.php +++ b/includes/sanitizers/class-amp-img-sanitizer.php @@ -227,7 +227,7 @@ private function adjust_and_replace_node( $node ) { */ private function is_gif_url( $url ) { $ext = self::$anim_extension; - $path = AMP_WP_Utils::parse_url( $url, PHP_URL_PATH ); + $path = wp_parse_url( $url, PHP_URL_PATH ); return substr( $path, -strlen( $ext ) ) === $ext; } } diff --git a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php index 030c2be8d3b..7f59d1e7d75 100644 --- a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php +++ b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php @@ -1146,7 +1146,7 @@ private function check_attr_spec_rule_allowed_protocol( $node, $attr_name, $attr * This seems to be an acceptable check since the AMP validator * will allow a URL with no protocol to pass validation. */ - $url_scheme = AMP_WP_Utils::parse_url( $url, PHP_URL_SCHEME ); + $url_scheme = wp_parse_url( $url, PHP_URL_SCHEME ); if ( $url_scheme ) { if ( ! in_array( strtolower( $url_scheme ), $attr_spec_rule[ AMP_Rule_Spec::VALUE_URL ][ AMP_Rule_Spec::ALLOWED_PROTOCOL ], true ) ) { return AMP_Rule_Spec::FAIL; @@ -1165,7 +1165,7 @@ private function check_attr_spec_rule_allowed_protocol( $node, $attr_name, $attr * This seems to be an acceptable check since the AMP validator * will allow a URL with no protocol to pass validation. */ - $url_scheme = AMP_WP_Utils::parse_url( $url, PHP_URL_SCHEME ); + $url_scheme = wp_parse_url( $url, PHP_URL_SCHEME ); if ( $url_scheme ) { if ( ! in_array( strtolower( $url_scheme ), $attr_spec_rule[ AMP_Rule_Spec::VALUE_URL ][ AMP_Rule_Spec::ALLOWED_PROTOCOL ], true ) ) { return AMP_Rule_Spec::FAIL; @@ -1200,7 +1200,7 @@ private function check_attr_spec_rule_disallowed_relative( $node, $attr_name, $a $attr_value = preg_replace( '/\s*,\s*/', ',', $attr_value ); $urls_to_test = explode( ',', $attr_value ); foreach ( $urls_to_test as $url ) { - $parsed_url = AMP_WP_Utils::parse_url( $url ); + $parsed_url = wp_parse_url( $url ); /* * The JS AMP validator seems to consider 'relative' to mean @@ -1221,7 +1221,7 @@ private function check_attr_spec_rule_disallowed_relative( $node, $attr_name, $a $attr_value = preg_replace( '/\s*,\s*/', ',', $attr_value ); $urls_to_test = explode( ',', $attr_value ); foreach ( $urls_to_test as $url ) { - $parsed_url = AMP_WP_Utils::parse_url( $url ); + $parsed_url = wp_parse_url( $url ); if ( empty( $parsed_url['scheme'] ) ) { return AMP_Rule_Spec::FAIL; } @@ -1274,7 +1274,7 @@ private function check_attr_spec_rule_disallowed_empty( $node, $attr_name, $attr private function check_attr_spec_rule_disallowed_domain( $node, $attr_name, $attr_spec_rule ) { if ( isset( $attr_spec_rule[ AMP_Rule_Spec::DISALLOWED_DOMAIN ] ) && $node->hasAttribute( $attr_name ) ) { $attr_value = $node->getAttribute( $attr_name ); - $url_domain = AMP_WP_Utils::parse_url( $attr_value, PHP_URL_HOST ); + $url_domain = wp_parse_url( $attr_value, PHP_URL_HOST ); if ( ! empty( $url_domain ) ) { foreach ( $attr_spec_rule[ AMP_Rule_Spec::DISALLOWED_DOMAIN ] as $disallowed_domain ) { if ( strtolower( $url_domain ) === strtolower( $disallowed_domain ) ) { diff --git a/includes/utils/class-amp-image-dimension-extractor.php b/includes/utils/class-amp-image-dimension-extractor.php index e659b4fc860..7c6b7d5875b 100644 --- a/includes/utils/class-amp-image-dimension-extractor.php +++ b/includes/utils/class-amp-image-dimension-extractor.php @@ -51,7 +51,7 @@ public static function normalize_url( $url ) { return set_url_scheme( $url, 'http' ); } - $parsed = AMP_WP_Utils::parse_url( $url ); + $parsed = wp_parse_url( $url ); if ( ! isset( $parsed['host'] ) ) { $path = ''; if ( isset( $parsed['path'] ) ) { diff --git a/jetpack-helper.php b/jetpack-helper.php index 20b4680e7ba..673040da8eb 100644 --- a/jetpack-helper.php +++ b/jetpack-helper.php @@ -56,7 +56,7 @@ function jetpack_amp_build_stats_pixel_url() { $blog = Jetpack_Options::get_option( 'id' ); $tz = get_option( 'gmt_offset' ); $v = 'ext'; - $blog_url = AMP_WP_Utils::parse_url( site_url() ); + $blog_url = wp_parse_url( site_url() ); $srv = $blog_url['host']; $j = sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION ); $post = $wp_the_query->get_queried_object_id(); From 944bbf94733bfa2287c9cf9358fd1ce3df64b3c9 Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Thu, 8 Mar 2018 12:35:45 -0500 Subject: [PATCH 3/8] replace parse_url() with wp_parse_url() --- includes/embeds/class-amp-vimeo-embed.php | 2 +- wpcom-helper.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/embeds/class-amp-vimeo-embed.php b/includes/embeds/class-amp-vimeo-embed.php index 6b334ce6441..7143a65b778 100644 --- a/includes/embeds/class-amp-vimeo-embed.php +++ b/includes/embeds/class-amp-vimeo-embed.php @@ -97,7 +97,7 @@ public function render( $args ) { // Takes the last component of a Vimeo URL // and returns it as the associated video id private function get_video_id_from_url( $url ) { - $parsed_url = parse_url( $url ); + $parsed_url = wp_parse_url( $url ); parse_str( $parsed_url['path'], $path ); $video_id = ""; diff --git a/wpcom-helper.php b/wpcom-helper.php index 37af6a9ee91..eddc6ef2890 100644 --- a/wpcom-helper.php +++ b/wpcom-helper.php @@ -129,12 +129,12 @@ function wpcom_amp_extract_image_dimensions_from_querystring( $dimensions ) { continue; } - $host = parse_url( $url, PHP_URL_HOST ); + $host = wp_parse_url( $url, PHP_URL_HOST ); if ( ! wp_endswith( $host, '.wp.com' ) || ! wp_endswith( $host, '.files.wordpress.com' ) ) { continue; } - parse_str( parse_url( $url, PHP_URL_QUERY ), $query ); + parse_str( wp_parse_url( $url, PHP_URL_QUERY ), $query ); $w = isset( $query['w'] ) ? absint( $query['w'] ) : false; $h = isset( $query['h'] ) ? absint( $query['h'] ) : false; From 0c6bd9318daccd80e797b8cb8d50d43d804d6e7a Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Thu, 8 Mar 2018 12:36:05 -0500 Subject: [PATCH 4/8] bump minimum required version to 4.8 --- readme.md | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 8cdfb6070e5..679bad37973 100644 --- a/readme.md +++ b/readme.md @@ -6,13 +6,13 @@ Enable Accelerated Mobile Pages (AMP) on your WordPress site. **Contributors:** [batmoo](https://profiles.wordpress.org/batmoo), [joen](https://profiles.wordpress.org/joen), [automattic](https://profiles.wordpress.org/automattic), [potatomaster](https://profiles.wordpress.org/potatomaster), [albertomedina](https://profiles.wordpress.org/albertomedina), [google](https://profiles.wordpress.org/google), [xwp](https://profiles.wordpress.org/xwp), [westonruter](https://profiles.wordpress.org/westonruter) **Tags:** [amp](https://wordpress.org/plugins/tags/amp), [mobile](https://wordpress.org/plugins/tags/mobile) -**Requires at least:** 4.7 **Tested up to:** 4.9 **Stable tag:** 0.6.0 **License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) **Requires PHP:** 5.3 [![Build Status](https://travis-ci.org/Automattic/amp-wp.svg?branch=master)](https://travis-ci.org/Automattic/amp-wp) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com) +**Requires at least:** 4.8 ## Description ## diff --git a/readme.txt b/readme.txt index fe723ec86f8..5ea58bce6ff 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ === AMP for WordPress === Contributors: batmoo, joen, automattic, potatomaster, albertomedina, google, xwp, westonruter Tags: amp, mobile -Requires at least: 4.7 +Requires at least: 4.8 Tested up to: 4.9 Stable tag: 0.6.0 License: GPLv2 or later From 59bbbbb8e1f77ae31941c3e7882bdfafee919af8 Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Sun, 18 Mar 2018 12:42:18 -0400 Subject: [PATCH 5/8] Revert "bump minimum required version to 4.8" This reverts commit 0c6bd9318daccd80e797b8cb8d50d43d804d6e7a. --- readme.md | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 679bad37973..8cdfb6070e5 100644 --- a/readme.md +++ b/readme.md @@ -6,13 +6,13 @@ Enable Accelerated Mobile Pages (AMP) on your WordPress site. **Contributors:** [batmoo](https://profiles.wordpress.org/batmoo), [joen](https://profiles.wordpress.org/joen), [automattic](https://profiles.wordpress.org/automattic), [potatomaster](https://profiles.wordpress.org/potatomaster), [albertomedina](https://profiles.wordpress.org/albertomedina), [google](https://profiles.wordpress.org/google), [xwp](https://profiles.wordpress.org/xwp), [westonruter](https://profiles.wordpress.org/westonruter) **Tags:** [amp](https://wordpress.org/plugins/tags/amp), [mobile](https://wordpress.org/plugins/tags/mobile) +**Requires at least:** 4.7 **Tested up to:** 4.9 **Stable tag:** 0.6.0 **License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) **Requires PHP:** 5.3 [![Build Status](https://travis-ci.org/Automattic/amp-wp.svg?branch=master)](https://travis-ci.org/Automattic/amp-wp) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com) -**Requires at least:** 4.8 ## Description ## diff --git a/readme.txt b/readme.txt index 5ea58bce6ff..fe723ec86f8 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ === AMP for WordPress === Contributors: batmoo, joen, automattic, potatomaster, albertomedina, google, xwp, westonruter Tags: amp, mobile -Requires at least: 4.8 +Requires at least: 4.7 Tested up to: 4.9 Stable tag: 0.6.0 License: GPLv2 or later From 745eb87ee900cdb278aeee5355e367e669238cdc Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Sun, 18 Mar 2018 12:42:44 -0400 Subject: [PATCH 6/8] Revert "remove AMP_WP_Utils class and tests" This reverts commit c7c227be6f3e61dda3b09b843ce2fc6e4dbff66f. --- includes/class-amp-autoloader.php | 1 + includes/utils/class-amp-wp-utils.php | 61 +++++++++++++++++++++++++++ tests/test-amp-wp-utils.php | 47 +++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 includes/utils/class-amp-wp-utils.php create mode 100644 tests/test-amp-wp-utils.php diff --git a/includes/class-amp-autoloader.php b/includes/class-amp-autoloader.php index 0533b2dd96b..3ec923b7bde 100644 --- a/includes/class-amp-autoloader.php +++ b/includes/class-amp-autoloader.php @@ -86,6 +86,7 @@ class AMP_Autoloader { 'AMP_Image_Dimension_Extractor' => 'includes/utils/class-amp-image-dimension-extractor', 'AMP_Validation_Utils' => 'includes/utils/class-amp-validation-utils', 'AMP_String_Utils' => 'includes/utils/class-amp-string-utils', + 'AMP_WP_Utils' => 'includes/utils/class-amp-wp-utils', 'AMP_Widget_Archives' => 'includes/widgets/class-amp-widget-archives', 'AMP_Widget_Categories' => 'includes/widgets/class-amp-widget-categories', 'AMP_Widget_Media_Video' => 'includes/widgets/class-amp-widget-media-video', diff --git a/includes/utils/class-amp-wp-utils.php b/includes/utils/class-amp-wp-utils.php new file mode 100644 index 00000000000..bacb72458af --- /dev/null +++ b/includes/utils/class-amp-wp-utils.php @@ -0,0 +1,61 @@ + 'scheme', + PHP_URL_HOST => 'host', + PHP_URL_PORT => 'port', + PHP_URL_USER => 'user', + PHP_URL_PASS => 'pass', + PHP_URL_PATH => 'path', + PHP_URL_QUERY => 'query', + PHP_URL_FRAGMENT => 'fragment', + ); + + if ( isset( $translation[ $constant ] ) ) { + return $translation[ $constant ]; + } + + return false; + } +} diff --git a/tests/test-amp-wp-utils.php b/tests/test-amp-wp-utils.php new file mode 100644 index 00000000000..43f3b3a572e --- /dev/null +++ b/tests/test-amp-wp-utils.php @@ -0,0 +1,47 @@ + array( + 'https://example.com/path', + array( + 'scheme' => 'https', + 'host' => 'example.com', + 'path' => '/path', + ), + -1, + ), + + 'valid__with_component' => array( + 'https://example.com/path', + 'example.com', + PHP_URL_HOST, + ), + + 'valid__schemaless__no_component' => array( + '//example.com/path', + array( + 'host' => 'example.com', + 'path' => '/path', + ), + -1, + ), + + 'valid__schemaless__with_component' => array( + '//example.com/path', + 'example.com', + PHP_URL_HOST, + ), + ); + } + + /** + * @dataProvider get_test_data + */ + function test__method( $url, $expected, $component ) { + $actual = AMP_WP_Utils::parse_url( $url, $component ); + + $this->assertEquals( $expected, $actual ); + } +} From 4f49291b3f16780e8768219f2e57e919f716c344 Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Sun, 18 Mar 2018 13:07:08 -0400 Subject: [PATCH 7/8] mark AMP_WP_Utils::parse_url as deprecated --- includes/utils/class-amp-wp-utils.php | 47 +++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/includes/utils/class-amp-wp-utils.php b/includes/utils/class-amp-wp-utils.php index bacb72458af..924b6a3cdbd 100644 --- a/includes/utils/class-amp-wp-utils.php +++ b/includes/utils/class-amp-wp-utils.php @@ -1,15 +1,39 @@ Date: Mon, 19 Mar 2018 14:43:43 -0700 Subject: [PATCH 8/8] Remove tests for deprecated AMP_WP_Utils class --- tests/test-amp-wp-utils.php | 69 ------------------------------------- 1 file changed, 69 deletions(-) delete mode 100644 tests/test-amp-wp-utils.php diff --git a/tests/test-amp-wp-utils.php b/tests/test-amp-wp-utils.php deleted file mode 100644 index 5ab5d1277ec..00000000000 --- a/tests/test-amp-wp-utils.php +++ /dev/null @@ -1,69 +0,0 @@ - array( - 'https://example.com/path', - array( - 'scheme' => 'https', - 'host' => 'example.com', - 'path' => '/path', - ), - -1, - ), - - 'valid__with_component' => array( - 'https://example.com/path', - 'example.com', - PHP_URL_HOST, - ), - - 'valid__schemaless__no_component' => array( - '//example.com/path', - array( - 'host' => 'example.com', - 'path' => '/path', - ), - -1, - ), - - 'valid__schemaless__with_component' => array( - '//example.com/path', - 'example.com', - PHP_URL_HOST, - ), - ); - } - - /** - * Test URL parsing. - * - * @param string $url The URL. - * @param string $expected Expected value. - * @param string $component Derived value. - * - * @dataProvider get_test_data - */ - public function test__method( $url, $expected, $component ) { - $actual = AMP_WP_Utils::parse_url( $url, $component ); - - $this->assertEquals( $expected, $actual ); - } -}