public/wordpress/wp-content/plugins/backupbuddy/destinations/stash2/init.php
/* stashAPI()
	 *
	 * Communicate with the Stash API.
	 *
	 * @param	array 			$settings			Destination settings array.
	 * @param	string			$action				API verb/action to call.
	 * @param	bool			$passthru_errors	When false, we will handle parsing errors here, returning a string error message. When true, pass back the entire array from the server.
	 * @return	array|string						Array with response data on success. String with error message if something went wrong. Auto-logs all errors to status log.
	 */
stashAPI()
Communicate with the Stash API.

@param       array                   $settings                       Destination settings array.
@param       string                  $action                         API verb/action to call.
@param       bool                    $passthru_errors        When false, we will handle parsing errors here, returning a string error message. When true, pass back the entire array from the server.
@return      array|string                                            Array with response data on success. String with error message if something went wrong. Auto-logs all errors to status log.
stashAPI () Communicate with the Stash API . @param array $settings Destination settings array . @param string $action API verb / action to call . @param bool $passthru_errors When false we will handle parsing errors here returning a string error message . When true pass back the entire array from the server . @return array|string Array with response data on success . String with error message if something went wrong . Auto - logs all errors to status log .
public static function stashAPI( $settings, $action, $additionalParams = array(), $blocking = true, $passthru_errors = false, $timeout = 25 ) {
		global $wp_version;
		$url_params = array(
			'action'    => $action,
			'user'      => $settings['itxapi_username'],
			'wp'        => $wp_version,
			'bb'		=> pb_backupbuddy::settings( 'version' ),
			'site'      => str_replace( 'www.', '', site_url() ),
			'home'      => str_replace( 'www.', '', home_url() ),
			'timestamp' => time()
		);
		$params = array();
		if ( isset( $settings['itxapi_password' ] ) ) { 
			$params['auth_token'] = $settings['itxapi_password']; 
		}
		if ( isset( $settings['itxapi_token' ] ) ) { 
			$params['token'] = $settings['itxapi_token']; 
		}
		$params = array_merge( $params, $additionalParams );
		$post_url = self::API_URL . '/?' . http_build_query( $url_params, null, '&' );
		$http_data = array(
			'method' => 'POST',
			'timeout' => $timeout,
			'redirection' => 5,
			'httpversion' => '1.0',
			'blocking' => $blocking,
			'body' => array( 'request' => json_encode( $params ) ),
			'cookies' => array()
		);
		$response = wp_remote_post(
			$post_url,
			$http_data
		);
		if ( false === $blocking ) {
			return true;
		}
		if ( is_wp_error( $response ) ) {
			$error = 'Error #3892774: `' . $response->get_error_message() . '` connecting to `' . $post_url . '`.';
			self::_error( $error );
			if ( 'live' == $settings['type'] ) {
			}
			return $error;
		} else { 
			if ( null !== ( $response_decoded = json_decode( $response['body'], true  ) ) ) {
				if ( ( false === $passthru_errors ) && ( isset( $response_decoded['error'] ) ) ) {
					if ( isset( $response_decoded['error']['message'] ) ) {
						$error = 'Error #39752893b. Server reported an error performing action `' . $action . '` with additional params: `' . print_r( $additionalParams, true ) . '`. Body Details: `' . print_r( $response_decoded['error'], true ) . '`. Response Details: `' . print_r( $response['response'], true ) . '`.';
						self::_error( $error );
						return $response_decoded['error']['message'];
					} else {
						$error = 'Error #3823973. Received Stash API error but no message found. Details: `' . print_r( $response_decoded, true ) . '`.';
						self::_error( $error );
						return $error;
					}
				} else {
					return $response_decoded;
				}
			} else {
				$error = 'Error #8393833: Unexpected server response: `' . htmlentities( $response['body'] ) . '` calling action `' . $action . '`. Full response: `' . print_r( $response, true ) . '`.';
				self::_error( $error );
				return $error;
			}
		} 
	}
public static function stashAPI ( $ settings , $ action , $ additionalParams = array ( ) , $ blocking = true , $ passthru_errors = false , $ timeout = 25 ) { global $ wp_version ; $ url_params = array ( 'action' => $ action , 'user' => $ settings [ 'itxapi_username' ] , 'wp' => $ wp_version , 'bb' => pb_backupbuddy :: settings ( 'version' ) , 'site' => str_replace ( 'www.' , '' , site_url ( ) ) , 'home' => str_replace ( 'www.' , '' , home_url ( ) ) , 'timestamp' => time ( ) ) ; $ params = array ( ) ; if ( isset ( $ settings [ 'itxapi_password' ] ) ) { $ params [ 'auth_token' ] = $ settings [ 'itxapi_password' ] ; } if ( isset ( $ settings [ 'itxapi_token' ] ) ) { $ params [ 'token' ] = $ settings [ 'itxapi_token' ] ; } $ params = array_merge ( $ params , $ additionalParams ) ; $ post_url = self :: API_URL . '/?' . http_build_query ( $ url_params , null , '&' ) ; $ http_data = array ( 'method' => 'POST' , 'timeout' => $ timeout , 'redirection' => 5 , 'httpversion' => '1.0' , 'blocking' => $ blocking , 'body' => array ( 'request' => json_encode ( $ params ) ) , 'cookies' => array ( ) ) ; $ response = wp_remote_post ( $ post_url , $ http_data ) ; if ( false === $ blocking ) { return true ; } if ( is_wp_error ( $ response ) ) { $ error = 'Error #3892774: `' . $ response -> get_error_message ( ) . '` connecting to `' . $ post_url . '`.' ; self :: _error ( $ error ) ; if ( 'live' == $ settings [ 'type' ] ) { } return $ error ; } else { if ( null !== ( $ response_decoded = json_decode ( $ response [ 'body' ] , true ) ) ) { if ( ( false === $ passthru_errors ) && ( isset ( $ response_decoded [ 'error' ] ) ) ) { if ( isset ( $ response_decoded [ 'error' ] [ 'message' ] ) ) { $ error = 'Error #39752893b. Server reported an error performing action `' . $ action . '` with additional params: `' . print_r ( $ additionalParams , true ) . '`. Body Details: `' . print_r ( $ response_decoded [ 'error' ] , true ) . '`. Response Details: `' . print_r ( $ response [ 'response' ] , true ) . '`.' ; self :: _error ( $ error ) ; return $ response_decoded [ 'error' ] [ 'message' ] ; } else { $ error = 'Error #3823973. Received Stash API error but no message found. Details: `' . print_r ( $ response_decoded , true ) . '`.' ; self :: _error ( $ error ) ; return $ error ; } } else { return $ response_decoded ; } } else { $ error = 'Error #8393833: Unexpected server response: `' . htmlentities ( $ response [ 'body' ] ) . '` calling action `' . $ action . '`. Full response: `' . print_r ( $ response , true ) . '`.' ; self :: _error ( $ error ) ; return $ error ; } } }
stashAPI()
 Communicate with the Stash API.
stashAPI () Communicate with the Stash API .
// Used on initital connection to   // itxapi_password is a HASH of user's password. // Used on initital connection to   // itxapi_password is a HASH of user's password. /*
			$error = 'BackupBuddy Error #438923983: No valid token (itxapi_token) or hashed password (itxapi_password) specified. This should not happen.';
			self::_error( $error );
			trigger_error( $error, E_USER_NOTICE );
			return $error;
		}
		*/ //print_r( $params ); //backupbuddy_core::addNotification( 'live_error', 'BackupBuddy Stash Live Error', $error ); // Not error. // end not error.