@@ 45-66 (lines=22) @@ | ||
42 | return $id; |
|
43 | } |
|
44 | ||
45 | if ( !function_exists( 'youtube_sanitize_url' ) ) : |
|
46 | /** |
|
47 | * Normalizes a YouTube URL to include a v= parameter and a query string free of encoded ampersands. |
|
48 | * |
|
49 | * @param string $url |
|
50 | * @return string The normalized URL |
|
51 | */ |
|
52 | function youtube_sanitize_url( $url ) { |
|
53 | $url = trim( $url, ' "' ); |
|
54 | $url = trim( $url ); |
|
55 | $url = str_replace( array( 'youtu.be/', '/v/', '#!v=', '&', '&', 'playlist' ), array( 'youtu.be/?v=', '/?v=', '?v=', '&', '&', 'videoseries' ), $url ); |
|
56 | ||
57 | // 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. |
|
58 | $query_string_start = strpos( $url, "?" ); |
|
59 | ||
60 | if ( false !== $query_string_start ) { |
|
61 | $url = substr( $url, 0, $query_string_start + 1 ) . str_replace( "?", "&", substr( $url, $query_string_start + 1 ) ); |
|
62 | } |
|
63 | ||
64 | return $url; |
|
65 | } |
|
66 | endif; |
|
67 | ||
68 | /** |
|
69 | * Merge in three string helper functions from WPCOM. |
@@ 125-140 (lines=16) @@ | ||
122 | * @param string $url |
|
123 | * @return string The normalized URL |
|
124 | */ |
|
125 | if ( ! function_exists( 'youtube_sanitize_url' ) ) : |
|
126 | function youtube_sanitize_url( $url ) { |
|
127 | $url = trim( $url, ' "' ); |
|
128 | $url = trim( $url ); |
|
129 | $url = str_replace( array( 'youtu.be/', '/v/', '#!v=', '&', '&', 'playlist' ), array( 'youtu.be/?v=', '/?v=', '?v=', '&', '&', 'videoseries' ), $url ); |
|
130 | ||
131 | // 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. |
|
132 | $query_string_start = strpos( $url, "?" ); |
|
133 | ||
134 | if ( false !== $query_string_start ) { |
|
135 | $url = substr( $url, 0, $query_string_start + 1 ) . str_replace( "?", "&", substr( $url, $query_string_start + 1 ) ); |
|
136 | } |
|
137 | ||
138 | return $url; |
|
139 | } |
|
140 | endif; |
|
141 | ||
142 | /* |
|
143 | * url can be: |