コード例 #1
0
ファイル: xmlrpcserver.php プロジェクト: habari/system
 /**
  * Handle all incoming XMLRPC requests.
  */
 public function act_xmlrpc_call()
 {
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $exception = new XMLRPCException(1);
         $exception->output_fault_xml();
         // dies here
     }
     $input = file_get_contents('php://input');
     $xml = new \SimpleXMLElement($input);
     $function = $xml->methodName;
     $params = array();
     $found_params = $xml->xpath('//params/param/value');
     if (is_array($found_params)) {
         foreach ($found_params as $param) {
             $params[] = XMLRPCUtils::decode_args($param);
         }
     }
     $returnvalue = false;
     Plugins::register(array($this, 'system_listMethods'), 'xmlrpc', 'system.listMethods');
     $returnvalue = Plugins::xmlrpc("{$function}", $returnvalue, $params, $this);
     $response = new \SimpleXMLElement('<?xml version="1.0"?' . '><methodResponse><params><param></param></params></methodResponse>');
     XMLRPCUtils::encode_arg($response->params->param, $returnvalue);
     ob_end_clean();
     header('Content-Type: text/xml;charset=utf-8');
     echo trim($response->asXML());
     exit;
 }
コード例 #2
0
ファイル: xmlrpcclient.php プロジェクト: psaintlaurent/Habari
 /**
  * Allow method overloading for this class.
  * This method allows any method name to be called on this object.  The method
  * called is the method called via RPC, within the scope defined in $this->scope.
  *
  * @param string $fname The function name to call
  * @param array $args An array of arguments that were called with the function
  * @return array The result array
  */
 public function __call($fname, $args)
 {
     if ($this->scope != '') {
         $rpc_method = "{$this->scope}.{$fname}";
     } else {
         $rpc_method = $fname;
     }
     $rpx = new SimpleXMLElement('<methodCall/>');
     $rpx->addChild('methodName', $rpc_method);
     if (count($args) > 0) {
         $params = $rpx->addchild('params');
         foreach ($args as $arg) {
             $param = $params->addchild('param');
             XMLRPCUtils::encode_arg($param, $arg);
         }
     }
     $request = new RemoteRequest($this->entrypoint, 'POST');
     $request->add_header('Content-Type: text/xml;charset=utf-8');
     $request->set_body($rpx->asXML());
     $request->execute();
     if ($request->executed()) {
         $response = $request->get_response_body();
         $enc = mb_detect_encoding($response);
         $responseutf8 = mb_convert_encoding($response, 'UTF-8', $enc);
         try {
             $bit = ini_get('error_reporting');
             error_reporting($bit && !E_WARNING);
             $responsexml = new SimpleXMLElement($responseutf8);
             error_reporting($bit);
             $tmp = $responsexml->xpath('//params/param/value');
             if (!($responsestruct = reset($tmp))) {
                 $tmp = $responsexml->xpath('//fault/value');
                 if (!($responsestruct = reset($tmp))) {
                     throw new Exception(_t('Invalid XML response.'));
                 }
             }
             return XMLRPCUtils::decode_args($responsestruct);
         } catch (Exception $e) {
             //Utils::debug($response, $e);
             error_reporting($bit);
             return false;
         }
     }
 }
コード例 #3
0
ファイル: xmlrpcclient.php プロジェクト: habari/system
 /**
  * Allow method overloading for this class.
  * This method allows any method name to be called on this object.  The method
  * called is the method called via RPC, within the scope defined in $this->scope.
  *
  * @param string $fname The function name to call
  * @param array $args An array of arguments that were called with the function
  * @return array The result array
  */
 public function __call($fname, $args)
 {
     if ($this->scope != '') {
         $rpc_method = "{$this->scope}.{$fname}";
     } else {
         $rpc_method = $fname;
     }
     $rpx = new \SimpleXMLElement('<methodCall/>');
     $rpx->addChild('methodName', $rpc_method);
     if (count($args) > 0) {
         $params = $rpx->addchild('params');
         foreach ($args as $arg) {
             $param = $params->addchild('param');
             XMLRPCUtils::encode_arg($param, $arg);
         }
     }
     $request = new RemoteRequest($this->entrypoint, 'POST');
     $request->add_header('Content-Type: text/xml;charset=utf-8');
     $request->set_body($rpx->asXML());
     $request->execute();
     if ($request->executed()) {
         $response = $request->get_response_body();
         // @todo this should use the MultiByte class, not directly call mb_string functions
         $enc = mb_detect_encoding($response);
         $responseutf8 = mb_convert_encoding($response, 'UTF-8', $enc);
         try {
             // @todo this should use libxml_use_internal_errors() instead of trying to hide the PHP warning see the plugin info parsing code for an example
             $bit = ini_get('error_reporting');
             error_reporting($bit && !E_WARNING);
             $responsexml = new \SimpleXMLElement($responseutf8);
             error_reporting($bit);
             $tmp = $responsexml->xpath('//params/param/value');
             if (!($responsestruct = reset($tmp))) {
                 $tmp = $responsexml->xpath('//fault/value');
                 if (!($responsestruct = reset($tmp))) {
                     throw new \Exception(_t('Invalid XML response.'));
                 }
             }
             return XMLRPCUtils::decode_args($responsestruct);
         } catch (\Exception $e) {
             error_reporting($bit);
             return false;
         }
     }
 }