server_url = $url; $this->api_key = $key; $this->local_url = $local_url; } /** * PHP magic function for handling the calling of services * * @param string $name Name of function called * @param array $args Arguments passed */ public function __call($name, $args){ $postdata = array( 'key' => $this->api_key, 'url' => $this->local_url, 'service' => $name, 'args' => serialize($args) ); if(function_exists('wp_remote_request')){ $result = wp_remote_request($this->server_url, array( 'timeout' => 20,'method' => 'POST', 'body' => array("c" => base64_encode(serialize($postdata))))); if ( is_fontserv_error($result) ) { $response = array('msg' => $result->getMessage()); } else { $response = unserialize(base64_decode(($result['body']))); if (false === $response) $response = array('msg' => __('

An unknown HTTP error occurred.

Please contact support and include the following details:

')); } if ($response instanceof fontservException) { throw $response; } } else { $response = array('msg' => __('

An unknown HTTP error occurred.

Please contact support and include the following details:

')); } return $response; } } /** * An RPC Exception class, used for handling, surprisingly, * errors. */ class fontservException extends Exception{} function is_fontserv_error($thing) { if ( is_object($thing) && is_a($thing, 'WP_Error') ) return true; return false; } ?>