Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistently use wp_parse_url(); deprecate AMP_WP_Utils #995

Merged
merged 9 commits into from Mar 19, 2018
1 change: 0 additions & 1 deletion includes/class-amp-autoloader.php
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion includes/embeds/class-amp-dailymotion-embed.php
Expand Up @@ -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] );
Expand Down
2 changes: 1 addition & 1 deletion includes/embeds/class-amp-soundcloud-embed.php
Expand Up @@ -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<track_id>[^/]+)#', $parsed_url['path'], $matches ) ) {
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion includes/embeds/class-amp-vimeo-embed.php
Expand Up @@ -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 = "";
Expand Down
2 changes: 1 addition & 1 deletion includes/embeds/class-amp-youtube-embed.php
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion includes/sanitizers/class-amp-img-sanitizer.php
Expand Up @@ -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;
}
}
10 changes: 5 additions & 5 deletions includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 ) ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/utils/class-amp-image-dimension-extractor.php
Expand Up @@ -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'] ) ) {
Expand Down
61 changes: 0 additions & 61 deletions includes/utils/class-amp-wp-utils.php

This file was deleted.

2 changes: 1 addition & 1 deletion jetpack-helper.php
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -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 ##

Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
47 changes: 0 additions & 47 deletions tests/test-amp-wp-utils.php

This file was deleted.

4 changes: 2 additions & 2 deletions wpcom-helper.php
Expand Up @@ -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;

Expand Down