3 /* Copyright (C) 2002, Lawrence Akka <lakka@users.sourceforge.net>
4 * Copyright (C) 2004,2005,2006 $ThePhpWikiProgrammingTeam
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.
10 global $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString;
11 global $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct;
14 global $xmlrpcerr, $xmlrpcstr;
15 global $xmlrpc_defencoding;
16 global $xmlrpcName, $xmlrpcVersion;
17 global $xmlrpcerruser, $xmlrpcerrxml;
18 global $xmlrpc_backslash;
20 global $_xmlrpcs_debug;
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';
33 // See http://www.jspwiki.org/wiki/WikiRPCInterface for version 1
34 // See http://www.jspwiki.org/wiki/WikiRPCInterface2 for version 2 (we support 80%)
35 define ("WIKI_XMLRPC_VERSION", 1);
38 * Helper functions for encoding/decoding strings.
40 * According to WikiRPC spec, all returned strings take one of either
41 * two forms. Short strings (page names, and authors) are converted to
42 * UTF-8, then rawurlencode()d, and returned as XML-RPC <code>strings</code>.
43 * Long strings (page content) are converted to UTF-8 then returned as
44 * XML-RPC <code>base64</code> binary objects.
48 * Urlencode ASCII control characters.
50 * (And control characters...)
56 function UrlencodeControlCharacters($str)
58 return preg_replace('/([\x00-\x1F])/e', "urlencode('\\1')", $str);
62 * Convert a short string (page name, author) to xmlrpcval.
64 function short_string($str)
66 return new xmlrpcval(UrlencodeControlCharacters(utf8_encode($str)), 'string');
70 * Convert a large string (page content) to xmlrpcval.
72 function long_string($str)
74 return new xmlrpcval(utf8_encode($str), 'base64');
78 * Decode a short string (e.g. page name)
80 function short_string_decode($str)
82 return utf8_decode(urldecode($str));
85 function wiki_xmlrpc_post($method, $args = null, $url = null, $auth = null)
88 //$url = deduce_script_name();
89 $url = DATA_PATH . "/RPC2.php"; // connect to self
92 $server = parse_url($url);
93 if (empty($server['host'])) {
94 $server['host'] = 'localhost';
96 if (!empty($_GET['start_debug'])) {
99 if (DEBUG & _DEBUG_REMOTE) { // xmlrpc remote debugging
101 $server['path'] .= '?start_debug=1';
103 $params = array('method' => $method,
105 'host' => $server['host'],
106 'uri' => $server['path'],
109 //TODO: auth and/or session cookie
110 if (isset($auth['sid']))
111 $params['cookies'] = array(session_name() => $auth['sid']);
112 if (isset($auth['user']))
113 $params['user'] = $auth['user'];
114 if (isset($auth['pass']))
115 $params['pass'] = $auth['pass'];
116 $result = xu_rpc_http_concise($params);
124 // c-hanging-comment-ender-p: nil
125 // indent-tabs-mode: nil