xref: /dokuwiki/lib/exe/xmlrpc.php (revision f95017850a515969190f54df3d57a00449245bb9)
1797c0d11SAndreas Gohr<?php
27aec69d1SGuy Brandif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
3797c0d11SAndreas Gohr
4797c0d11SAndreas Gohr// fix when '< ?xml' isn't on the very first line
5797c0d11SAndreas Gohrif(isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
6797c0d11SAndreas Gohr
7445e8084SAndreas Gohr/**
8445e8084SAndreas Gohr * Increased whenever the API is changed
9445e8084SAndreas Gohr */
1080d6fbc3SAdrian Langdefine('DOKU_XMLRPC_API_VERSION', 6);
11797c0d11SAndreas Gohr
12797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php');
133a13cfe7SDominik Eckelmannrequire_once(DOKU_INC.'inc/remote.php');
14797c0d11SAndreas Gohrsession_write_close();  //close session
15593bf8f6SMichael Klier
163ee5b583SAndreas Gohrif(!$conf['xmlrpc']) die('XML-RPC server not enabled.');
17593bf8f6SMichael Klier
18797c0d11SAndreas Gohr/**
19797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available
20797c0d11SAndreas Gohr * XMLRPC functions.
21797c0d11SAndreas Gohr */
223a13cfe7SDominik Eckelmannclass dokuwiki_xmlrpc_server extends IXR_Server {
233f3bb97fSDominik Eckelmann    var $remote;
243ee5b583SAndreas Gohr
253ee5b583SAndreas Gohr    /**
26797c0d11SAndreas Gohr     * Constructor. Register methods and run Server
27797c0d11SAndreas Gohr     */
28797c0d11SAndreas Gohr    function dokuwiki_xmlrpc_server(){
293f3bb97fSDominik Eckelmann        $this->remote = new RemoteAPI();
30*f9501785SDominik Eckelmann        $this->remote->setDateTransformation(array($this, 'toDate'));
31*f9501785SDominik Eckelmann        $this->remote->setFileTransformation(array($this, 'toFile'));
323a13cfe7SDominik Eckelmann        $this->IXR_Server();
33797c0d11SAndreas Gohr    }
34797c0d11SAndreas Gohr
353a13cfe7SDominik Eckelmann    function call($methodname, $args){
363f3bb97fSDominik Eckelmann        try {
373a13cfe7SDominik Eckelmann            //print 'a';
383a13cfe7SDominik Eckelmann            $result = $this->remote->call($methodname, $args);
393a13cfe7SDominik Eckelmann            return $result;
403f3bb97fSDominik Eckelmann        } catch (RemoteAccessDenied $e) {
413a13cfe7SDominik Eckelmann            if (!isset($_SERVER['REMOTE_USER'])) {
423a13cfe7SDominik Eckelmann                header('HTTP/1.1 401 Unauthorized');
43f71f4f53SAndreas Gohr            } else {
443a13cfe7SDominik Eckelmann                header('HTTP/1.1 403 Forbidden');
45f71f4f53SAndreas Gohr            }
463a13cfe7SDominik Eckelmann            return new IXR_Error(-32603, 'server error. not authorized to call method');
473a13cfe7SDominik Eckelmann        } catch (RemoteException $e) {
483a13cfe7SDominik Eckelmann            return new IXR_Error($e->getCode(), $e->getMessage());
4926bec61eSMichael Klier        }
5026bec61eSMichael Klier    }
5126bec61eSMichael Klier
52*f9501785SDominik Eckelmann    function toDate($data) {
53*f9501785SDominik Eckelmann        return new IXR_Date($data);
54*f9501785SDominik Eckelmann    }
55*f9501785SDominik Eckelmann
56*f9501785SDominik Eckelmann    function toFile($data) {
57*f9501785SDominik Eckelmann        return new IXR_Base64($data);
58*f9501785SDominik Eckelmann    }
59*f9501785SDominik Eckelmann
60797c0d11SAndreas Gohr}
61797c0d11SAndreas Gohr
62797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server();
63797c0d11SAndreas Gohr
64e3776c06SMichael Hamann// vim:ts=4:sw=4:et:
65