jetpack
Last commit date
3rd-party
6 years ago
_inc
6 years ago
bin
6 years ago
css
6 years ago
extensions
6 years ago
images
6 years ago
json-endpoints
6 years ago
languages
6 years ago
modules
5 years ago
sal
6 years ago
src
6 years ago
vendor
6 years ago
views
6 years ago
.svnignore
12 years ago
CODE-OF-CONDUCT.md
9 years ago
changelog.txt
6 years ago
class-jetpack-wizard-banner.php
6 years ago
class.frame-nonce-preview.php
6 years ago
class.jetpack-admin.php
6 years ago
class.jetpack-affiliate.php
6 years ago
class.jetpack-autoupdate.php
6 years ago
class.jetpack-bbpress-json-api.compat.php
6 years ago
class.jetpack-cli.php
6 years ago
class.jetpack-client-server.php
6 years ago
class.jetpack-connection-banner.php
6 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
6 years ago
class.jetpack-heartbeat.php
6 years ago
class.jetpack-idc.php
6 years ago
class.jetpack-ixr-client.php
6 years ago
class.jetpack-modules-list-table.php
6 years ago
class.jetpack-network-sites-list-table.php
6 years ago
class.jetpack-network.php
6 years ago
class.jetpack-plan.php
6 years ago
class.jetpack-post-images.php
6 years ago
class.jetpack-twitter-cards.php
6 years ago
class.jetpack-user-agent.php
6 years ago
class.jetpack-xmlrpc-server.php
6 years ago
class.jetpack.php
6 years ago
class.json-api-endpoints.php
6 years ago
class.json-api.php
6 years ago
class.photon.php
6 years ago
composer.json
6 years ago
functions.compat.php
6 years ago
functions.cookies.php
6 years ago
functions.gallery.php
6 years ago
functions.global.php
6 years ago
functions.opengraph.php
6 years ago
functions.photon.php
6 years ago
jest.config.js
6 years ago
jetpack.php
5 years ago
json-api-config.php
10 years ago
json-endpoints.php
7 years ago
load-jetpack.php
6 years ago
locales.php
7 years ago
readme.txt
5 years ago
require-lib.php
6 years ago
uninstall.php
6 years ago
wpml-config.xml
10 years ago
functions.compat.php
101 lines
| 1 | <?php |
| 2 | |
| 3 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 4 | |
| 5 | /** |
| 6 | * Required for class.media-extractor.php to match expected function naming convention. |
| 7 | * |
| 8 | * @param $url Can be just the $url or the whole $atts array |
| 9 | * @return bool|mixed The Youtube video ID via jetpack_get_youtube_id |
| 10 | */ |
| 11 | |
| 12 | function jetpack_shortcode_get_youtube_id( $url ) { |
| 13 | return jetpack_get_youtube_id( $url ); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * @param $url Can be just the $url or the whole $atts array |
| 18 | * @return bool|mixed The Youtube video ID |
| 19 | */ |
| 20 | function jetpack_get_youtube_id( $url ) { |
| 21 | // Do we have an $atts array? Get first att |
| 22 | if ( is_array( $url ) ) { |
| 23 | $url = reset( $url ); |
| 24 | } |
| 25 | |
| 26 | $url = youtube_sanitize_url( $url ); |
| 27 | $url = wp_parse_url( $url ); |
| 28 | $id = false; |
| 29 | |
| 30 | if ( ! isset( $url['query'] ) ) |
| 31 | return false; |
| 32 | |
| 33 | parse_str( $url['query'], $qargs ); |
| 34 | |
| 35 | if ( ! isset( $qargs['v'] ) && ! isset( $qargs['list'] ) ) |
| 36 | return false; |
| 37 | |
| 38 | if ( isset( $qargs['list'] ) ) |
| 39 | $id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['list'] ); |
| 40 | |
| 41 | if ( empty( $id ) ) |
| 42 | $id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['v'] ); |
| 43 | |
| 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. |
| 72 | * |
| 73 | * @see WPCOM/wp-content/mu-plugins/string-helpers.php |
| 74 | */ |
| 75 | if ( ! function_exists( 'wp_startswith' ) ) : |
| 76 | function wp_startswith( $haystack, $needle ) { |
| 77 | return 0 === strpos( $haystack, $needle ); |
| 78 | } |
| 79 | endif; |
| 80 | |
| 81 | |
| 82 | if ( ! function_exists( 'wp_endswith' ) ) : |
| 83 | function wp_endswith( $haystack, $needle ) { |
| 84 | return $needle === substr( $haystack, -strlen( $needle )); |
| 85 | } |
| 86 | endif; |
| 87 | |
| 88 | if ( ! function_exists( 'wp_in' ) ) : |
| 89 | function wp_in( $needle, $haystack ) { |
| 90 | return false !== strpos( $haystack, $needle ); |
| 91 | } |
| 92 | endif; |
| 93 | |
| 94 | /** |
| 95 | * @deprecated 7.5 Use Connection_Manager instead. |
| 96 | */ |
| 97 | function jetpack_sha1_base64( $text ) { |
| 98 | $connection = new Connection_Manager(); |
| 99 | return $connection->sha1_base64( $text ); |
| 100 | } |
| 101 |