]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/XmlRpcClient.php
use explicit RPC2 url because of still unresolved dba problem.
[SourceForge/phpwiki.git] / lib / XmlRpcClient.php
1 <?php // -*- php -*-
2 // $Id: XmlRpcClient.php,v 1.2 2007-01-03 21:25:43 rurban Exp $
3 /* Copyright (C) 2002, Lawrence Akka <lakka@users.sourceforge.net>
4  * Copyright (C) 2004,2005,2006 $ThePhpWikiProgrammingTeam
5  */
6 // All these global declarations that this file
7 // XmlRpcClient.php can be included within a function body
8 // (not in global scope), and things will still work.
9
10 global $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString;
11 global $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct;
12 global $xmlrpcTypes;
13 global $xmlEntities;
14 global $xmlrpcerr, $xmlrpcstr;
15 global $xmlrpc_defencoding;
16 global $xmlrpcName, $xmlrpcVersion;
17 global $xmlrpcerruser, $xmlrpcerrxml;
18 global $xmlrpc_backslash;
19 global $_xh;
20 global $_xmlrpcs_debug;
21
22 define('XMLRPC_EXT_LOADED', true);
23 if (loadPhpExtension('xmlrpc')) { // fast c lib
24     global $xmlrpc_util_path;
25     $xmlrpc_util_path = dirname(__FILE__)."/XMLRPC/";
26     include_once("lib/XMLRPC/xmlrpc_emu.inc"); 
27  } else { // slow php lib
28     // Include the php XML-RPC library
29     include_once("lib/XMLRPC/xmlrpc.inc");
30 }
31
32 //  API version
33 define ("WIKI_XMLRPC_VERSION", 2);
34
35 /*
36  * Helper functions for encoding/decoding strings.
37  *
38  * According to WikiRPC spec, all returned strings take one of either
39  * two forms.  Short strings (page names, and authors) are converted to
40  * UTF-8, then rawurlencode()d, and returned as XML-RPC <code>strings</code>.
41  * Long strings (page content) are converted to UTF-8 then returned as
42  * XML-RPC <code>base64</code> binary objects.
43  */
44
45 /**
46  * Urlencode ASCII control characters.
47  *
48  * (And control characters...)
49  *
50  * @param string $str
51  * @return string
52  * @see urlencode
53  */
54 function UrlencodeControlCharacters($str) {
55     return preg_replace('/([\x00-\x1F])/e', "urlencode('\\1')", $str);
56 }
57
58 /**
59  * Convert a short string (page name, author) to xmlrpcval.
60  */
61 function short_string ($str) {
62     return new xmlrpcval(UrlencodeControlCharacters(utf8_encode($str)), 'string');
63 }
64
65 /**
66  * Convert a large string (page content) to xmlrpcval.
67  */
68 function long_string ($str) {
69     return new xmlrpcval(utf8_encode($str), 'base64');
70 }
71
72 /**
73  * Decode a short string (e.g. page name)
74  */
75 function short_string_decode ($str) {
76     return utf8_decode(urldecode($str));
77 }
78
79 function wiki_xmlrpc_post($method, $args = null, $url = null) {
80     if (is_null($url)) {
81         //$url = deduce_script_name();
82         $url = DATA_PATH . "/RPC2.php";
83     }
84     $debug = 0;
85     $server = parse_url($url);
86     if (empty($server['host'])) $server['host'] = 'localhost';
87     // xmlrpc remote debugging
88     if ((DEBUG & _DEBUG_REMOTE) and !empty($_GET['start_debug'])) { 
89         $debug = 2;
90         $server['path'] .= '?start_debug=1';
91     }
92     $result = xu_rpc_http_concise(array('method' => $method,
93                                         'args'   => $args, 
94                                         'host'   => $server['host'], 
95                                         'uri'    => $server['path'], 
96                                         'debug'  => $debug,
97                                         'output' => null));
98     return $result;
99 }
100
101 /*
102  $Log: not supported by cvs2svn $
103  Revision 1.1  2007/01/02 13:21:12  rurban
104  split client from server
105
106  */
107
108 // (c-file-style: "gnu")
109 // Local Variables:
110 // mode: php
111 // tab-width: 8
112 // c-basic-offset: 4
113 // c-hanging-comment-ender-p: nil
114 // indent-tabs-mode: nil
115 // End:   
116 ?>