PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 3.6.4
Jetpack – WP Security, Backup, Speed, & Growth v3.6.4
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / functions.compat.php
functions.compat.php
90 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Required for class.media-extractor.php to match expected function naming convention.
5 *
6 * @param $url Can be just the $url or the whole $atts array
7 * @return bool|mixed The Youtube video ID via jetpack_get_youtube_id
8 */
9
10 function jetpack_shortcode_get_youtube_id( $url ) {
11 return jetpack_get_youtube_id( $url );
12 }
13
14 /**
15 * @param $url Can be just the $url or the whole $atts array
16 * @return bool|mixed The Youtube video ID
17 */
18 function jetpack_get_youtube_id( $url ) {
19 // Do we have an $atts array? Get first att
20 if ( is_array( $url ) )
21 $url = $url[0];
22
23 $url = youtube_sanitize_url( $url );
24 $url = parse_url( $url );
25 $id = false;
26
27 if ( ! isset( $url['query'] ) )
28 return false;
29
30 parse_str( $url['query'], $qargs );
31
32 if ( ! isset( $qargs['v'] ) && ! isset( $qargs['list'] ) )
33 return false;
34
35 if ( isset( $qargs['list'] ) )
36 $id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['list'] );
37
38 if ( empty( $id ) )
39 $id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['v'] );
40
41 return $id;
42 }
43
44 if ( !function_exists( 'youtube_sanitize_url' ) ) :
45 /**
46 * Normalizes a YouTube URL to include a v= parameter and a query string free of encoded ampersands.
47 *
48 * @param string $url
49 * @return string The normalized URL
50 */
51 function youtube_sanitize_url( $url ) {
52 $url = trim( $url, ' "' );
53 $url = trim( $url );
54 $url = str_replace( array( 'youtu.be/', '/v/', '#!v=', '&amp;', '&#038;', 'playlist' ), array( 'youtu.be/?v=', '/?v=', '?v=', '&', '&', 'videoseries' ), $url );
55
56 // 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.
57 $query_string_start = strpos( $url, "?" );
58
59 if ( false !== $query_string_start ) {
60 $url = substr( $url, 0, $query_string_start + 1 ) . str_replace( "?", "&", substr( $url, $query_string_start + 1 ) );
61 }
62
63 return $url;
64 }
65 endif;
66
67 /**
68 * Merge in three string helper functions from WPCOM.
69 *
70 * @see WPCOM/wp-content/mu-plugins/string-helpers.php
71 */
72 if ( ! function_exists( 'wp_startswith' ) ) :
73 function wp_startswith( $haystack, $needle ) {
74 return 0 === strpos( $haystack, $needle );
75 }
76 endif;
77
78
79 if ( ! function_exists( 'wp_endswith' ) ) :
80 function wp_endswith( $haystack, $needle ) {
81 return $needle === substr( $haystack, -strlen( $needle ));
82 }
83 endif;
84
85 if ( ! function_exists( 'wp_in' ) ) :
86 function wp_in( $needle, $haystack ) {
87 return false !== strpos( $haystack, $needle );
88 }
89 endif;
90