Code Duplication    Length = 16-22 lines in 2 locations

projects/plugins/jetpack/functions.compat.php 1 location

@@ 47-68 (lines=22) @@
44
	return $id;
45
}
46
47
if ( !function_exists( 'youtube_sanitize_url' ) ) :
48
/**
49
* Normalizes a YouTube URL to include a v= parameter and a query string free of encoded ampersands.
50
*
51
* @param string $url
52
* @return string The normalized URL
53
*/
54
function youtube_sanitize_url( $url ) {
55
	$url = trim( $url, ' "' );
56
	$url = trim( $url );
57
	$url = str_replace( array( 'youtu.be/', '/v/', '#!v=', '&', '&', 'playlist' ), array( 'youtu.be/?v=', '/?v=', '?v=', '&', '&', 'videoseries' ), $url );
58
59
	// Replace any extra question marks with ampersands - the result of a URL like "https://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US" being passed in.
60
	$query_string_start = strpos( $url, "?" );
61
62
	if ( false !== $query_string_start ) {
63
		$url = substr( $url, 0, $query_string_start + 1 ) . str_replace( "?", "&", substr( $url, $query_string_start + 1 ) );
64
	}
65
66
	return $url;
67
}
68
endif;
69
70
/**
71
 * Merge in three string helper functions from WPCOM.

projects/plugins/jetpack/modules/shortcodes/youtube.php 1 location

@@ 138-153 (lines=16) @@
135
 * @param string $url
136
 * @return string The normalized URL
137
 */
138
if ( ! function_exists( 'youtube_sanitize_url' ) ) :
139
	/**
140
	 * Clean up Youtube URL to match a single format.
141
	 *
142
	 * @param string $url Youtube URL.
143
	 */
144
	function youtube_sanitize_url( $url ) {
145
		$url = trim( $url, ' "' );
146
		$url = trim( $url );
147
		$url = str_replace( array( 'youtu.be/', '/v/', '#!v=', '&', '&', 'playlist' ), array( 'youtu.be/?v=', '/?v=', '?v=', '&', '&', 'videoseries' ), $url );
148
149
		// Replace any extra question marks with ampersands - the result of a URL like "http://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US" being passed in.
150
		$query_string_start = strpos( $url, '?' );
151
152
		if ( false !== $query_string_start ) {
153
			$url = substr( $url, 0, $query_string_start + 1 ) . str_replace( '?', '&', substr( $url, $query_string_start + 1 ) );
154
		}
155
156
		return $url;