summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Chatzimichos <tampakrap@gentoo.org>2013-08-01 08:53:46 +0200
committerTheo Chatzimichos <tampakrap@gentoo.org>2013-08-01 08:53:46 +0200
commitc65f25a29edb6d47fa7d99a69c274f906b61adea (patch)
tree3f85de9f4159f72bb555310a6e4e5da75276a7ff /plugins/jetpack/class.json-api.php
parentbump kde-graffiti (diff)
downloadblogs-gentoo-c65f25a29edb6d47fa7d99a69c274f906b61adea.tar.gz
blogs-gentoo-c65f25a29edb6d47fa7d99a69c274f906b61adea.tar.bz2
blogs-gentoo-c65f25a29edb6d47fa7d99a69c274f906b61adea.zip
Update jetpack, akismet and wordpress-importer
Diffstat (limited to 'plugins/jetpack/class.json-api.php')
-rw-r--r--plugins/jetpack/class.json-api.php81
1 files changed, 67 insertions, 14 deletions
diff --git a/plugins/jetpack/class.json-api.php b/plugins/jetpack/class.json-api.php
index 5a322eb6..b94ce590 100644
--- a/plugins/jetpack/class.json-api.php
+++ b/plugins/jetpack/class.json-api.php
@@ -12,6 +12,7 @@ class WPCOM_JSON_API {
var $method = '';
var $url = '';
var $path = '';
+ var $version = null;
var $query = array();
var $post_body = null;
var $files = null;
@@ -23,6 +24,7 @@ class WPCOM_JSON_API {
var $public_api_scheme = 'https';
var $trapped_error = null;
+ var $did_output = false;
static function init( $method = null, $url = null, $post_body = null ) {
if ( !self::$self ) {
@@ -78,7 +80,7 @@ class WPCOM_JSON_API {
$this->accept = $_SERVER['HTTP_ACCEPT'];
}
- if ( 'POST' == $this->method ) {
+ if ( 'POST' === $this->method ) {
if ( is_null( $post_body ) ) {
$this->post_body = file_get_contents( 'php://input' );
@@ -122,11 +124,17 @@ class WPCOM_JSON_API {
add_filter( 'comment_edit_pre', array( $this, 'comment_edit_pre' ) );
- $this->initialize();
+ $initialization = $this->initialize();
+ if ( is_wp_error( $initialization ) ) {
+ $this->output_error( $initialization );
+ return;
+ }
- // Normalize path
+ // Normalize path and extract API version
$this->path = untrailingslashit( $this->path );
- $this->path = preg_replace( '#^/rest/v1#', '', $this->path );
+ preg_match( '#^/rest/v1(\.\d+)*#', $this->path, $matches );
+ $this->path = substr( $this->path, strlen( $matches[0] ) );
+ $this->version = $matches[1];
$allowed_methods = array( 'GET', 'POST' );
$four_oh_five = false;
@@ -156,7 +164,7 @@ class WPCOM_JSON_API {
$methods = $allowed_methods;
$find_all_matching_endpoints = true;
$four_oh_five = true;
- }
+ }
}
// Find which endpoint to serve
@@ -238,25 +246,37 @@ class WPCOM_JSON_API {
if ( !$response ) {
return $this->output( 500, '', 'text/plain' );
} elseif ( is_wp_error( $response ) ) {
- $status_code = $response->get_error_data();
- if ( !$status_code ) {
- $status_code = 400;
- }
- $response = array(
- 'error' => $response->get_error_code(),
- 'message' => $response->get_error_message(),
- );
- return $this->output( $status_code, $response );
+ return $this->output_error( $response );
}
return $this->output( 200, $response );
}
function process_request( WPCOM_JSON_API_Endpoint $endpoint, $path_pieces ) {
+ $this->endpoint = $endpoint;
return call_user_func_array( array( $endpoint, 'callback' ), $path_pieces );
}
+ function output_early( $status_code, $response = null, $content_type = 'application/json' ) {
+ $exit = $this->exit;
+ $this->exit = false;
+ if ( is_wp_error( $response ) )
+ $this->output_error( $response );
+ else
+ $this->output( $status_code, $response, $content_type );
+ $this->exit = $exit;
+ $this->finish_request();
+ }
+
function output( $status_code, $response = null, $content_type = 'application/json' ) {
+ // In case output() was called before the callback returned
+ if ( $this->did_output ) {
+ if ( $this->exit )
+ exit;
+ return $content_type;
+ }
+ $this->did_output = true;
+
if ( is_null( $response ) ) {
$response = new stdClass;
}
@@ -310,6 +330,22 @@ class WPCOM_JSON_API {
return $content_type;
}
+ function output_error( $error ) {
+ $status_code = $error->get_error_data();
+
+ if ( is_array( $status_code ) )
+ $status_code = $status_code['status_code'];
+
+ if ( !$status_code ) {
+ $status_code = 400;
+ }
+ $response = array(
+ 'error' => $error->get_error_code(),
+ 'message' => $error->get_error_message(),
+ );
+ return $this->output( $status_code, $response );
+ }
+
function ensure_http_scheme_of_home_url( $url, $path, $original_scheme ) {
if ( $original_scheme ) {
return $url;
@@ -352,6 +388,18 @@ class WPCOM_JSON_API {
return 0;
}
+ function is_liked( $blog_id, $post_id ) {
+ return false;
+ }
+
+ function is_reblogged( $blog_id, $post_id ) {
+ return false;
+ }
+
+ function is_following( $blog_id ) {
+ return false;
+ }
+
function get_avatar_url( $email ) {
add_filter( 'pre_option_show_avatars', '__return_true', 999 );
$_SERVER['HTTPS'] = 'off';
@@ -440,4 +488,9 @@ class WPCOM_JSON_API {
'message' => $this->trapped_error['message'],
) );
}
+
+ function finish_request() {
+ if ( function_exists( 'fastcgi_finish_request' ) )
+ return fastcgi_finish_request();
+ }
}