summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2016-11-30 16:22:57 -0500
committerAnthony G. Basile <blueness@gentoo.org>2016-11-30 16:22:57 -0500
commitfbf8cf39f7ec35489332158cb2f73ea535279e5b (patch)
treeb8025a3b964e60077492449c0e35bf675bcd6939 /plugins/jetpack/class.jetpack-client.php
parentUpdate plugin openid to 3.4.2 (diff)
downloadblogs-gentoo-fbf8cf39f7ec35489332158cb2f73ea535279e5b.tar.gz
blogs-gentoo-fbf8cf39f7ec35489332158cb2f73ea535279e5b.tar.bz2
blogs-gentoo-fbf8cf39f7ec35489332158cb2f73ea535279e5b.zip
Update plugin jetpack to 4.4.1
Diffstat (limited to 'plugins/jetpack/class.jetpack-client.php')
-rw-r--r--plugins/jetpack/class.jetpack-client.php59
1 files changed, 56 insertions, 3 deletions
diff --git a/plugins/jetpack/class.jetpack-client.php b/plugins/jetpack/class.jetpack-client.php
index 8eafd6cf..1846ff98 100644
--- a/plugins/jetpack/class.jetpack-client.php
+++ b/plugins/jetpack/class.jetpack-client.php
@@ -18,6 +18,8 @@ class Jetpack_Client {
'timeout' => 10,
'redirection' => 0,
'headers' => array(),
+ 'stream' => false,
+ 'filename' => null,
);
$args = wp_parse_args( $args, $defaults );
@@ -38,8 +40,10 @@ class Jetpack_Client {
$timeout = intval( $args['timeout'] );
$redirection = $args['redirection'];
+ $stream = $args['stream'];
+ $filename = $args['filename'];
- $request = compact( 'method', 'body', 'timeout', 'redirection' );
+ $request = compact( 'method', 'body', 'timeout', 'redirection', 'stream', 'filename' );
@list( $token_key, $secret ) = explode( '.', $token->secret );
if ( empty( $token ) || empty( $secret ) ) {
@@ -64,11 +68,26 @@ class Jetpack_Client {
// Kind of annoying. Maybe refactor Jetpack_Signature to handle body-hashing
if ( is_null( $body ) ) {
$body_hash = '';
+
} else {
- if ( !is_string( $body ) ) {
+ // Allow arrays to be used in passing data.
+ $body_to_hash = $body;
+
+ if ( is_array( $body ) ) {
+ // We cast this to a new variable, because the array form of $body needs to be
+ // maintained so it can be passed into the request later on in the code.
+ if ( count( $body ) > 0 ) {
+ $body_to_hash = json_encode( self::_stringify_data( $body ) );
+ } else {
+ $body_to_hash = '';
+ }
+ }
+
+ if ( ! is_string( $body_to_hash ) ) {
return new Jetpack_Error( 'invalid_body', 'Body is malformed.' );
}
- $body_hash = jetpack_sha1_base64( $body );
+
+ $body_hash = jetpack_sha1_base64( $body_to_hash );
}
$auth = array(
@@ -255,6 +274,8 @@ class Jetpack_Client {
'method' => 'string',
'timeout' => 'int',
'redirection' => 'int',
+ 'stream' => 'boolean',
+ 'filename' => 'string',
) );
/**
@@ -285,4 +306,36 @@ class Jetpack_Client {
return Jetpack_Client::remote_request( $validated_args, $body );
}
+ /**
+ * Takes an array or similar structure and recursively turns all values into strings. This is used to
+ * make sure that body hashes are made ith the string version, which is what will be seen after a
+ * server pulls up the data in the $_POST array.
+ *
+ * @param array|mixed $data
+ *
+ * @return array|string
+ */
+ public static function _stringify_data( $data ) {
+
+ // Booleans are special, lets just makes them and explicit 1/0 instead of the 0 being an empty string.
+ if ( is_bool( $data ) ) {
+ return $data ? "1" : "0";
+ }
+
+ // Cast objects into arrays.
+ if ( is_object( $data ) ) {
+ $data = (array) $data;
+ }
+
+ // Non arrays at this point should be just converted to strings.
+ if ( ! is_array( $data ) ) {
+ return (string)$data;
+ }
+
+ foreach ( $data as $key => &$value ) {
+ $value = self::_stringify_data( $value );
+ }
+
+ return $data;
+ }
}