Skip to content

Commit

Permalink
Replace parse_url with wp_parse_url (#13707)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftbj authored Oct 14, 2019
1 parent 3d70ae6 commit 792b26b
Show file tree
Hide file tree
Showing 38 changed files with 165 additions and 167 deletions.
2 changes: 1 addition & 1 deletion _inc/jetpack-server-sandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
function jetpack_server_sandbox_request_parameters( $sandbox, $url, $headers ) {
$host = '';

$url_host = parse_url( $url, PHP_URL_HOST );
$url_host = wp_parse_url( $url, PHP_URL_HOST );

switch ( $url_host ) {
case 'public-api.wordpress.com' :
Expand Down
8 changes: 4 additions & 4 deletions _inc/lib/class.media-extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static public function extract_from_content( $content, $what_to_extract = self::
if ( preg_match_all( '#(?:^|\s|"|\')(https?://([^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))))#', $content, $matches ) ) {

foreach ( $matches[1] as $link_raw ) {
$url = parse_url( $link_raw );
$url = wp_parse_url( $link_raw );

// Data URI links
if ( isset( $url['scheme'] ) && 'data' === $url['scheme'] )
Expand Down Expand Up @@ -286,7 +286,7 @@ static public function extract_from_content( $content, $what_to_extract = self::
$embeds = array();

foreach ( $matches[1] as $link_raw ) {
$url = parse_url( $link_raw );
$url = wp_parse_url( $link_raw );

list( $proto, $link_all_but_proto ) = explode( '://', $link_raw );

Expand Down Expand Up @@ -402,11 +402,11 @@ public static function get_images_from_html( $html, $images_already_extracted )
if ( !empty( $from_html ) ) {
$srcs = wp_list_pluck( $from_html, 'src' );
foreach( $srcs as $image_url ) {
if ( ( $src = parse_url( $image_url ) ) && isset( $src['scheme'], $src['host'], $src['path'] ) ) {
if ( ( $src = wp_parse_url( $image_url ) ) && isset( $src['scheme'], $src['host'], $src['path'] ) ) {
// Rebuild the URL without the query string
$queryless = $src['scheme'] . '://' . $src['host'] . $src['path'];
} elseif ( $length = strpos( $image_url, '?' ) ) {
// If parse_url() didn't work, strip off the query string the old fashioned way
// If wp_parse_url() didn't work, strip off the query string the old fashioned way
$queryless = substr( $image_url, 0, $length );
} else {
// Failing that, there was no spoon! Err ... query string!
Expand Down
12 changes: 6 additions & 6 deletions _inc/lib/class.media-summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static function get( $post_id, $blog_id = 0, $args = array() ) {
$poster_image = get_post_meta( $post_id, 'vimeo_poster_image', true );
if ( !empty( $poster_image ) ) {
$return['image'] = $poster_image;
$poster_url_parts = parse_url( $poster_image );
$poster_url_parts = wp_parse_url( $poster_image );
$return['secure']['image'] = 'https://secure-a.vimeocdn.com' . $poster_url_parts['path'];
}
}
Expand Down Expand Up @@ -162,12 +162,12 @@ static function get( $post_id, $blog_id = 0, $args = array() ) {
$poster_image = get_post_meta( $post_id, 'vimeo_poster_image', true );
if ( !empty( $poster_image ) ) {
$return['image'] = $poster_image;
$poster_url_parts = parse_url( $poster_image );
$poster_url_parts = wp_parse_url( $poster_image );
$return['secure']['image'] = 'https://secure-a.vimeocdn.com' . $poster_url_parts['path'];
}
} else if ( false !== strpos( $embed, 'dailymotion' ) ) {
$return['image'] = str_replace( 'dailymotion.com/video/','dailymotion.com/thumbnail/video/', $embed );
$return['image'] = parse_url( $return['image'], PHP_URL_SCHEME ) === null ? 'http://' . $return['image'] : $return['image'];
$return['image'] = wp_parse_url( $return['image'], PHP_URL_SCHEME ) === null ? 'http://' . $return['image'] : $return['image'];
$return['secure']['image'] = self::https( $return['image'] );
}

Expand Down Expand Up @@ -348,8 +348,8 @@ static function get_excerpt( $post_content, $post_excerpt, $max_words = 16, $max
static function split_content_in_words( $text ) {
$words = preg_split( '/[\s!?;,.]+/', $text, null, PREG_SPLIT_NO_EMPTY );

// Return an empty array if the split above fails.
return $words ? $words : array();
// Return an empty array if the split above fails.
return $words ? $words : array();
}

static function get_word_count( $post_content ) {
Expand All @@ -358,7 +358,7 @@ static function get_word_count( $post_content ) {

static function get_word_remaining_count( $post_content, $excerpt_content ) {
$content_word_count = count( self::split_content_in_words( self::clean_text( $post_content ) ) );
$excerpt_word_count = count( self::split_content_in_words( self::clean_text( $excerpt_content ) ) );
$excerpt_word_count = count( self::split_content_in_words( self::clean_text( $excerpt_content ) ) );

return (int) $content_word_count - $excerpt_word_count;
}
Expand Down
2 changes: 1 addition & 1 deletion class.jetpack-client-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function authorize( $data = array() ) {
Jetpack::invalidate_onboarding_token();

// If redirect_uri is SSO, ensure SSO module is enabled
parse_str( parse_url( $data['redirect_uri'], PHP_URL_QUERY ), $redirect_options );
parse_str( wp_parse_url( $data['redirect_uri'], PHP_URL_QUERY ), $redirect_options );

/** This filter is documented in class.jetpack-cli.php */
$jetpack_start_enable_sso = apply_filters( 'jetpack_start_enable_sso', true );
Expand Down
2 changes: 1 addition & 1 deletion class.jetpack-connection-banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static function enqueue_connect_button_scripts() {
)
);

$jetpackApiUrl = parse_url( Jetpack::connection()->api_url( '' ) );
$jetpackApiUrl = wp_parse_url( Jetpack::connection()->api_url( '' ) );

// Due to the limitation in how 3rd party cookies are handled in Safari,
// we're falling back to the original flow on Safari desktop and mobile.
Expand Down
4 changes: 2 additions & 2 deletions class.jetpack-post-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ static function from_attachment( $post_id, $width = 200, $height = 200 ) {
$inserted_images = array();

foreach ( $html_images as $html_image ) {
$src = parse_url( $html_image['src'] );
$src = wp_parse_url( $html_image['src'] );
// strip off any query strings from src
if ( ! empty( $src['scheme'] ) && ! empty( $src['host'] ) ) {
$inserted_images[] = $src['scheme'] . '://' . $src['host'] . $src['path'];
Expand Down Expand Up @@ -713,7 +713,7 @@ static function fit_image_url( $src, $width, $height ) {
}

// If WPCOM hosted image use native transformations
$img_host = parse_url( $src, PHP_URL_HOST );
$img_host = wp_parse_url( $src, PHP_URL_HOST );
if ( '.files.wordpress.com' == substr( $img_host, -20 ) ) {
return add_query_arg(
array(
Expand Down
16 changes: 8 additions & 8 deletions class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -3141,7 +3141,7 @@ public static function get_activation_source( $referer_url ) {
return array( 'wp-cli', null );
}

$referer = parse_url( $referer_url );
$referer = wp_parse_url( $referer_url );

$source_type = 'unknown';
$source_query = null;
Expand All @@ -3150,8 +3150,8 @@ public static function get_activation_source( $referer_url ) {
return array( $source_type, $source_query );
}

$plugins_path = parse_url( admin_url( 'plugins.php' ), PHP_URL_PATH );
$plugins_install_path = parse_url( admin_url( 'plugin-install.php' ), PHP_URL_PATH );// /wp-admin/plugin-install.php
$plugins_path = wp_parse_url( admin_url( 'plugins.php' ), PHP_URL_PATH );
$plugins_install_path = wp_parse_url( admin_url( 'plugin-install.php' ), PHP_URL_PATH );// /wp-admin/plugin-install.php

if ( isset( $referer['query'] ) ) {
parse_str( $referer['query'], $query_parts );
Expand Down Expand Up @@ -3331,8 +3331,8 @@ public static function try_registration() {
// Before attempting to connect, let's make sure that the domains are viable.
$domains_to_check = array_unique(
array(
'siteurl' => parse_url( get_site_url(), PHP_URL_HOST ),
'homeurl' => parse_url( get_home_url(), PHP_URL_HOST ),
'siteurl' => wp_parse_url( get_site_url(), PHP_URL_HOST ),
'homeurl' => wp_parse_url( get_home_url(), PHP_URL_HOST ),
)
);
foreach ( $domains_to_check as $domain ) {
Expand Down Expand Up @@ -5583,7 +5583,7 @@ public static function xmlrpc_async_call() {
public static function staticize_subdomain( $url ) {

// Extract hostname from URL
$host = parse_url( $url, PHP_URL_HOST );
$host = wp_parse_url( $url, PHP_URL_HOST );

// Explode hostname on '.'
$exploded_host = explode( '.', $host );
Expand Down Expand Up @@ -5637,7 +5637,7 @@ function post_login_form_to_signed_url( $url, $path, $scheme ) {
return $url;
}

$parsed_url = parse_url( $url );
$parsed_url = wp_parse_url( $url );
$url = strtok( $url, '?' );
$url = "$url?{$_SERVER['QUERY_STRING']}";
if ( ! empty( $parsed_url['query'] ) ) {
Expand Down Expand Up @@ -6350,7 +6350,7 @@ public function deprecated_hooks() {
public static function absolutize_css_urls( $css, $css_file_url ) {
$pattern = '#url\((?P<path>[^)]*)\)#i';
$css_dir = dirname( $css_file_url );
$p = parse_url( $css_dir );
$p = wp_parse_url( $css_dir );
$domain = sprintf(
'%1$s//%2$s%3$s%4$s',
isset( $p['scheme'] ) ? "{$p['scheme']}:" : '',
Expand Down
4 changes: 2 additions & 2 deletions class.json-api-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ function handle_media_sideload( $url, $parent_post_id = 0, $type = 'any' ) {
}

// if we didn't get a URL, let's bail
$parsed = @parse_url( $url );
$parsed = wp_parse_url( $url );
if ( empty( $parsed ) ) {
return false;
}
Expand All @@ -1942,7 +1942,7 @@ function handle_media_sideload( $url, $parent_post_id = 0, $type = 'any' ) {

// emulate a $_FILES entry
$file_array = array(
'name' => basename( parse_url( $url, PHP_URL_PATH ) ),
'name' => basename( wp_parse_url( $url, PHP_URL_PATH ) ),
'tmp_name' => $tmp,
);

Expand Down
2 changes: 1 addition & 1 deletion class.json-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function setup_inputs( $method = null, $url = null, $post_body = null ) {
$this->url = $url;
}

$parsed = parse_url( $this->url );
$parsed = wp_parse_url( $this->url );
if ( ! empty( $parsed['path'] ) ) {
$this->path = $parsed['path'];
}
Expand Down
4 changes: 2 additions & 2 deletions class.photon.php
Original file line number Diff line number Diff line change
Expand Up @@ -1019,13 +1019,13 @@ public function filter_sizes( $sizes, $size ) {
* @return bool
*/
protected static function validate_image_url( $url ) {
$parsed_url = @parse_url( $url );
$parsed_url = wp_parse_url( $url );

if ( ! $parsed_url ) {
return false;
}

// Parse URL and ensure needed keys exist, since the array returned by `parse_url` only includes the URL components it finds.
// Parse URL and ensure needed keys exist, since the array returned by `wp_parse_url` only includes the URL components it finds.
$url_info = wp_parse_args(
$parsed_url,
array(
Expand Down
Loading

0 comments on commit 792b26b

Please sign in to comment.