a damn cool xml-rpc-client class
authorx2000habouzit <x2000habouzit>
Tue, 7 Sep 2004 20:05:17 +0000 (20:05 +0000)
committerx2000habouzit <x2000habouzit>
Tue, 7 Sep 2004 20:05:17 +0000 (20:05 +0000)
taken from http://fr2.php.net/xml-rpc

AUTHORS
include/xml-rpc-client.inc.php [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
index cde6ce0..6ae2585 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -6,9 +6,12 @@ Polytechnique.org TEAM :
     Jean Sébastien Bedo     <jean-sebastien.bedo@m4x.org>
     Jeremy Lainé            <jeremy.laine@m4x.org>
     Sophie Charbonnier      <sophie.charbonnier@m4x.org>
-    Vincent Palatin        <vicent.palatin@m4x.org>
+    Vincent Palatin         <vicent.palatin@m4x.org>
     Yann Chevalier          <yann.chevalier@m4x.org>
 
 include/xml-rpc.inc.php :
-    Dan Libby              <dan@libby.com>                 http://xmlrpc-epi.sourceforge.net/
+    Dan Libby               <dan@libby.com>                 http://xmlrpc-epi.sourceforge.net/
+
+include/xml-rpc-client.inc.php:
+    Marc Boeren             <mboeren@php.net>               http://fr2.php.net/xml-rpc
 
diff --git a/include/xml-rpc-client.inc.php b/include/xml-rpc-client.inc.php
new file mode 100644 (file)
index 0000000..6978218
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************
+        $Id: xml-rpc-client.inc.php,v 1.1 2004-09-07 20:05:17 x2000habouzit Exp $
+ ***************************************************************************/
+
+require_once('xml-rpc.inc.php');
+
+/* taken from : http://fr2.php.net/xml-rpc
+ * Author mboeren@php.net
+ *
+ * Usage:
+ * $client = new xmlrpc_client("http://localhost:7080");
+ * print $client->echo('x')."\n";
+ * print $client->add(1, 3)."\n";
+ */
+
+class xmlrpc_client
+{
+    var $url;
+    var $urlparts;
+
+    function xmlrpc_client($url)
+    {
+        $this->url = $url;
+        $this->urlparts = parse_url($this->url);
+        foreach(array('scheme', 'host', 'user', 'pass', 'path', 'query', 'fragment') as $part) {
+            if (!isset($this->urlparts[$part])) { 
+                $this->urlparts[$part] = NULL;
+            }
+        }
+    }
+
+    function __call($function, $arguments, &$return)
+    {
+        $requestprms['host'] = $this->urlparts['host'];
+        $requestprms['port'] = $this->urlparts['port'];
+        $requestprms['uri'] = $this->urlparts['path'];
+        $requestprms['method'] = $function;
+        $requestprms['args'] = $arguments;
+        $requestprms['debug'] = 0;
+        $requestprms['timeout'] = 0;
+        $requestprms['user'] = NULL;
+        $requestprms['pass'] = NULL;
+        $requestprms['secure'] = 0;
+
+        $result = xu_rpc_http_concise($requestprms);
+        if (is_array($result) && isset($result['faultCode'])) {
+            print('Error in xmlrpc call \''.$function.'\''."\n");
+            print('  code  : '.$result['faultCode']."\n");
+            print('  message: '.$result['faultString']."\n");
+            return false;
+        }
+        $return = $result;
+        return true;
+    }
+
+}
+
+overload('xmlrpc_client');
+
+// vim:set et sw=4 sts=4 sws=4:
+?>