]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/XmlRpcClient.php
Harmonize file footer
[SourceForge/phpwiki.git] / lib / XmlRpcClient.php
1 <?php // -*- php -*-
2 // $Id$
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 // 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);
36
37 /*
38  * Helper functions for encoding/decoding strings.
39  *
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.
45  */
46
47 /**
48  * Urlencode ASCII control characters.
49  *
50  * (And control characters...)
51  *
52  * @param string $str
53  * @return string
54  * @see urlencode
55  */
56 function UrlencodeControlCharacters($str) {
57     return preg_replace('/([\x00-\x1F])/e', "urlencode('\\1')", $str);
58 }
59
60 /**
61  * Convert a short string (page name, author) to xmlrpcval.
62  */
63 function short_string ($str) {
64     return new xmlrpcval(UrlencodeControlCharacters(utf8_encode($str)), 'string');
65 }
66
67 /**
68  * Convert a large string (page content) to xmlrpcval.
69  */
70 function long_string ($str) {
71     return new xmlrpcval(utf8_encode($str), 'base64');
72 }
73
74 /**
75  * Decode a short string (e.g. page name)
76  */
77 function short_string_decode ($str) {
78     return utf8_decode(urldecode($str));
79 }
80
81 function wiki_xmlrpc_post($method, $args = null, $url = null, $auth = null) {
82     if (is_null($url)) {
83         //$url = deduce_script_name();
84         $url = DATA_PATH . "/RPC2.php"; // connect to self
85     }
86     $debug = 0;
87     $server = parse_url($url);
88     if (empty($server['host'])) {
89         $server['host'] = 'localhost';
90     }
91     if (!empty($_GET['start_debug'])) {
92         $debug = 2;
93     }
94     if (DEBUG & _DEBUG_REMOTE) {  // xmlrpc remote debugging
95         $debug = 2;
96         $server['path'] .= '?start_debug=1';
97     }
98     $params = array('method' => $method,
99                     'args'   => $args,
100                     'host'   => $server['host'],
101                     'uri'    => $server['path'],
102                     'debug'  => $debug,
103                     'output' => null);
104     //TODO: auth and/or session cookie
105     if (isset($auth['sid']))
106         $params['cookies'] = array(session_name() => $auth['sid']);
107     if (isset($auth['user']))
108         $params['user'] = $auth['user'];
109     if (isset($auth['pass']))
110         $params['pass'] = $auth['pass'];
111     $result = xu_rpc_http_concise($params);
112     return $result;
113 }
114
115 // Local Variables:
116 // mode: php
117 // tab-width: 8
118 // c-basic-offset: 4
119 // c-hanging-comment-ender-p: nil
120 // indent-tabs-mode: nil
121 // End: 
122 ?>