jetpack
Last commit date
3rd-party
7 years ago
_inc
6 years ago
bin
6 years ago
css
7 years ago
extensions
6 years ago
images
7 years ago
json-endpoints
7 years ago
languages
6 years ago
logs
9 years ago
modules
6 years ago
sal
7 years ago
scss
7 years ago
sync
7 years ago
vendor
6 years ago
views
7 years ago
wp-cli-templates
7 years ago
.svnignore
12 years ago
CODE-OF-CONDUCT.md
9 years ago
changelog.txt
6 years ago
class.frame-nonce-preview.php
9 years ago
class.jetpack-admin.php
7 years ago
class.jetpack-affiliate.php
7 years ago
class.jetpack-autoupdate.php
7 years ago
class.jetpack-bbpress-json-api-compat.php
9 years ago
class.jetpack-cli.php
7 years ago
class.jetpack-client-server.php
8 years ago
class.jetpack-client.php
7 years ago
class.jetpack-connection-banner.php
7 years ago
class.jetpack-constants.php
8 years ago
class.jetpack-data.php
6 years ago
class.jetpack-debugger.php
7 years ago
class.jetpack-error.php
10 years ago
class.jetpack-gutenberg.php
7 years ago
class.jetpack-heartbeat.php
7 years ago
class.jetpack-idc.php
7 years ago
class.jetpack-ixr-client.php
10 years ago
class.jetpack-jitm.php
7 years ago
class.jetpack-modules-list-table.php
7 years ago
class.jetpack-network-sites-list-table.php
9 years ago
class.jetpack-network.php
7 years ago
class.jetpack-options.php
7 years ago
class.jetpack-plan.php
7 years ago
class.jetpack-post-images.php
7 years ago
class.jetpack-signature.php
7 years ago
class.jetpack-tracks.php
7 years ago
class.jetpack-twitter-cards.php
7 years ago
class.jetpack-user-agent.php
7 years ago
class.jetpack-xmlrpc-server.php
7 years ago
class.jetpack.php
6 years ago
class.json-api-endpoints.php
7 years ago
class.json-api.php
7 years ago
class.photon.php
7 years ago
composer.json
6 years ago
functions.compat.php
7 years ago
functions.gallery.php
8 years ago
functions.global.php
7 years ago
functions.opengraph.php
7 years ago
functions.photon.php
7 years ago
jest.config.js
7 years ago
jetpack.php
6 years ago
json-api-config.php
10 years ago
json-endpoints.php
7 years ago
locales.php
7 years ago
readme.txt
6 years ago
require-lib.php
7 years ago
uninstall.php
7 years ago
wpml-config.xml
10 years ago
functions.compat.php
91 lines
| 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 = reset( $url ); |
| 22 | } |
| 23 | |
| 24 | $url = youtube_sanitize_url( $url ); |
| 25 | $url = parse_url( $url ); |
| 26 | $id = false; |
| 27 | |
| 28 | if ( ! isset( $url['query'] ) ) |
| 29 | return false; |
| 30 | |
| 31 | parse_str( $url['query'], $qargs ); |
| 32 | |
| 33 | if ( ! isset( $qargs['v'] ) && ! isset( $qargs['list'] ) ) |
| 34 | return false; |
| 35 | |
| 36 | if ( isset( $qargs['list'] ) ) |
| 37 | $id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['list'] ); |
| 38 | |
| 39 | if ( empty( $id ) ) |
| 40 | $id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['v'] ); |
| 41 | |
| 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. |
| 70 | * |
| 71 | * @see WPCOM/wp-content/mu-plugins/string-helpers.php |
| 72 | */ |
| 73 | if ( ! function_exists( 'wp_startswith' ) ) : |
| 74 | function wp_startswith( $haystack, $needle ) { |
| 75 | return 0 === strpos( $haystack, $needle ); |
| 76 | } |
| 77 | endif; |
| 78 | |
| 79 | |
| 80 | if ( ! function_exists( 'wp_endswith' ) ) : |
| 81 | function wp_endswith( $haystack, $needle ) { |
| 82 | return $needle === substr( $haystack, -strlen( $needle )); |
| 83 | } |
| 84 | endif; |
| 85 | |
| 86 | if ( ! function_exists( 'wp_in' ) ) : |
| 87 | function wp_in( $needle, $haystack ) { |
| 88 | return false !== strpos( $haystack, $needle ); |
| 89 | } |
| 90 | endif; |
| 91 |