summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury German <blueknight@gentoo.org>2019-05-22 01:01:36 -0400
committerYury German <blueknight@gentoo.org>2019-05-22 01:01:36 -0400
commit0914c92da22824025992c368c745546e41fbeb84 (patch)
tree965f6adf3b725e56d559fe4a93eff02281499dcc /plugins/jetpack/class.jetpack-ixr-client.php
parentDeleting plugins for update (diff)
downloadblogs-gentoo-0914c92da22824025992c368c745546e41fbeb84.tar.gz
blogs-gentoo-0914c92da22824025992c368c745546e41fbeb84.tar.bz2
blogs-gentoo-0914c92da22824025992c368c745546e41fbeb84.zip
Adding Plugins
Updating the following akismet.4.1.2, google-authenticator.0.52, jetpack.7.3.1 Signed-off-by: Yury German <blueknight@gentoo.org>
Diffstat (limited to 'plugins/jetpack/class.jetpack-ixr-client.php')
-rw-r--r--plugins/jetpack/class.jetpack-ixr-client.php135
1 files changed, 135 insertions, 0 deletions
diff --git a/plugins/jetpack/class.jetpack-ixr-client.php b/plugins/jetpack/class.jetpack-ixr-client.php
new file mode 100644
index 00000000..5d2f7516
--- /dev/null
+++ b/plugins/jetpack/class.jetpack-ixr-client.php
@@ -0,0 +1,135 @@
+<?php
+
+defined( 'ABSPATH' ) or die( 'No direct access, please.' );
+
+require_once( ABSPATH . WPINC . '/class-IXR.php' );
+
+/**
+ * IXR_Client
+ *
+ * @package IXR
+ * @since 1.5
+ *
+ */
+class Jetpack_IXR_Client extends IXR_Client {
+ public $jetpack_args = null;
+
+ function __construct( $args = array(), $path = false, $port = 80, $timeout = 15 ) {
+ $defaults = array(
+ 'url' => Jetpack::xmlrpc_api_url(),
+ 'user_id' => 0,
+ );
+
+ $args = wp_parse_args( $args, $defaults );
+
+ $this->jetpack_args = $args;
+
+ $this->IXR_Client( $args['url'], $path, $port, $timeout );
+ }
+
+ function query() {
+ $args = func_get_args();
+ $method = array_shift( $args );
+ $request = new IXR_Request( $method, $args );
+ $xml = trim( $request->getXml() );
+
+ $response = Jetpack_Client::remote_request( $this->jetpack_args, $xml );
+
+ if ( is_wp_error( $response ) ) {
+ $this->error = new IXR_Error( -10520, sprintf( 'Jetpack: [%s] %s', $response->get_error_code(), $response->get_error_message() ) );
+ return false;
+ }
+
+ if ( !$response ) {
+ $this->error = new IXR_Error( -10520, 'Jetpack: Unknown Error' );
+ return false;
+ }
+
+ if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
+ $this->error = new IXR_Error( -32300, 'transport error - HTTP status code was not 200' );
+ return false;
+ }
+
+ $content = wp_remote_retrieve_body( $response );
+
+ // Now parse what we've got back
+ $this->message = new IXR_Message( $content );
+ if ( !$this->message->parse() ) {
+ // XML error
+ $this->error = new IXR_Error( -32700, 'parse error. not well formed' );
+ return false;
+ }
+
+ // Is the message a fault?
+ if ( $this->message->messageType == 'fault' ) {
+ $this->error = new IXR_Error( $this->message->faultCode, $this->message->faultString );
+ return false;
+ }
+
+ // Message must be OK
+ return true;
+ }
+
+ function get_jetpack_error( $fault_code = null, $fault_string = null ) {
+ if ( is_null( $fault_code ) ) {
+ $fault_code = $this->error->code;
+ }
+
+ if ( is_null( $fault_string ) ) {
+ $fault_string = $this->error->message;
+ }
+
+ if ( preg_match( '#jetpack:\s+\[(\w+)\]\s*(.*)?$#i', $fault_string, $match ) ) {
+ $code = $match[1];
+ $message = $match[2];
+ $status = $fault_code;
+ return new Jetpack_Error( $code, $message, $status );
+ }
+
+ return new Jetpack_Error( "IXR_{$fault_code}", $fault_string );
+ }
+}
+
+/**
+ * IXR_ClientMulticall
+ *
+ * @package IXR
+ * @since 1.5
+ */
+class Jetpack_IXR_ClientMulticall extends Jetpack_IXR_Client {
+ public $calls = array();
+
+ function __construct( $args = array(), $path = false, $port = 80, $timeout = 15 ) {
+ parent::__construct( $args, $path, $port, $timeout );
+ }
+
+ function addCall() {
+ $args = func_get_args();
+ $methodName = array_shift( $args );
+ $struct = array(
+ 'methodName' => $methodName,
+ 'params' => $args
+ );
+ $this->calls[] = $struct;
+ }
+
+ function query() {
+ usort( $this->calls, array( $this, 'sort_calls' ) );
+
+ // Prepare multicall, then call the parent::query() method
+ return parent::query( 'system.multicall', $this->calls );
+ }
+
+ // Make sure syncs are always done first
+ function sort_calls( $a, $b ) {
+ if ( 'jetpack.syncContent' == $a['methodName'] ) {
+ return -1;
+ }
+
+ if ( 'jetpack.syncContent' == $b['methodName'] ) {
+ return 1;
+ }
+
+ return 0;
+ }
+}