summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org>2015-05-01 00:40:49 +0000
committerJorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org>2015-05-01 00:40:49 +0000
commitc64ce3ae8de09092f9570ab88a68fe920b0fd970 (patch)
treea9959002055a8bdff0ee46bf82ca6a2a39bf00cd /plugins/jetpack/json-endpoints/class.wpcom-json-api-render-embed-endpoint.php
parentAdd easy-table plugin, requested by hwoarang (diff)
downloadblogs-gentoo-c64ce3ae8de09092f9570ab88a68fe920b0fd970.tar.gz
blogs-gentoo-c64ce3ae8de09092f9570ab88a68fe920b0fd970.tar.bz2
blogs-gentoo-c64ce3ae8de09092f9570ab88a68fe920b0fd970.zip
Update plugins and themes to the latest versions.
Signed-off-by: Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org>
Diffstat (limited to 'plugins/jetpack/json-endpoints/class.wpcom-json-api-render-embed-endpoint.php')
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-render-embed-endpoint.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-render-embed-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-render-embed-endpoint.php
new file mode 100644
index 00000000..fe4cf85b
--- /dev/null
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-render-embed-endpoint.php
@@ -0,0 +1,61 @@
+<?php
+class WPCOM_JSON_API_Render_Embed_Endpoint extends WPCOM_JSON_API_Render_Endpoint {
+ // /sites/%s/embeds/render -> $blog_id
+ function callback( $path = '', $blog_id = 0 ) {
+ $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
+ if ( is_wp_error( $blog_id ) ) {
+ return $blog_id;
+ }
+
+ if ( ! current_user_can( 'edit_posts' ) ) {
+ return new WP_Error( 'unauthorized', 'Your token must have permission to post on this blog.', 403 );
+ }
+
+ $args = $this->query_args();
+ $embed_url = trim( $args['embed_url'] );
+
+ // quick validation
+ if ( ! preg_match_all( '|^\s*(https?://[^\s"]+)\s*$|im', $embed_url, $matches ) ) {
+ return new WP_Error( 'invalid_embed_url', 'The embed_url parameter must be a valid URL.', 400 );
+ }
+
+ if ( count( $matches[1] ) > 1 ) {
+ return new WP_Error( 'invalid_embed', 'Only one embed can be rendered at a time.', 400 );
+ }
+
+ $embed_url = array_shift( $matches[1] );
+ $parts = parse_url( $embed_url );
+ if ( ! $parts ) {
+ return new WP_Error( 'invalid_embed_url', 'The embed_url parameter must be a valid URL.', 400 );
+ }
+
+ // in order for oEmbed to fire in the `$wp_embed->shortcode` method, we need to set a post as the current post
+ $_posts = get_posts( array( 'posts_per_page' => 1, 'suppress_filters' => false ) );
+ if ( ! empty( $_posts ) ) {
+ global $post;
+ $post = array_shift( $_posts );
+ }
+
+ global $wp_embed;
+ $render = $this->process_render( array( $this, 'do_embed' ), $embed_url );
+
+ // if nothing happened, then the shortcode does not exist.
+ $is_an_embed = ( $embed_url != $render['result'] && $wp_embed->maybe_make_link( $embed_url ) != $render['result'] );
+ if ( ! $is_an_embed ) {
+ return new WP_Error( 'invalid_embed', 'The requested URL is not an embed.', 400 );
+ }
+
+ // our output for this endpoint..
+ $return['embed_url'] = $embed_url;
+ $return['result'] = $render['result'];
+
+ $return = $this->add_assets( $return, $render['loaded_scripts'], $render['loaded_styles'] );
+
+ return $return;
+ }
+
+ function do_embed( $embed_url ) {
+ global $wp_embed;
+ return $wp_embed->shortcode( array(), $embed_url );
+ }
+} \ No newline at end of file