1797c0d11SAndreas Gohr<?php 27aec69d1SGuy Brandif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); 3797c0d11SAndreas Gohr 4797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php'); 5797c0d11SAndreas Gohrsession_write_close(); //close session 6593bf8f6SMichael Klier 7*2a9d6d65SFlorian Rathgeberif(!$conf['remote']) die((new IXR_Error(-32605, "XML-RPC server not enabled."))->getXml()); 8593bf8f6SMichael Klier 9797c0d11SAndreas Gohr/** 10797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available 11797c0d11SAndreas Gohr * XMLRPC functions. 12797c0d11SAndreas Gohr */ 133a13cfe7SDominik Eckelmannclass dokuwiki_xmlrpc_server extends IXR_Server { 1442a6fba0SGerrit Uitslag protected $remote; 153ee5b583SAndreas Gohr 163ee5b583SAndreas Gohr /** 17797c0d11SAndreas Gohr * Constructor. Register methods and run Server 18797c0d11SAndreas Gohr */ 1942a6fba0SGerrit Uitslag public function __construct(){ 203f3bb97fSDominik Eckelmann $this->remote = new RemoteAPI(); 21f9501785SDominik Eckelmann $this->remote->setDateTransformation(array($this, 'toDate')); 22f9501785SDominik Eckelmann $this->remote->setFileTransformation(array($this, 'toFile')); 230c43e719SGerrit Uitslag parent::__construct(); 24797c0d11SAndreas Gohr } 25797c0d11SAndreas Gohr 267e8500eeSGerrit Uitslag /** 277e8500eeSGerrit Uitslag * @param string $methodname 287e8500eeSGerrit Uitslag * @param array $args 297e8500eeSGerrit Uitslag * @return IXR_Error|mixed 307e8500eeSGerrit Uitslag */ 3142a6fba0SGerrit Uitslag public function call($methodname, $args){ 323f3bb97fSDominik Eckelmann try { 333a13cfe7SDominik Eckelmann $result = $this->remote->call($methodname, $args); 343a13cfe7SDominik Eckelmann return $result; 35e61127e4SDominik Eckelmann } catch (RemoteAccessDeniedException $e) { 363a13cfe7SDominik Eckelmann if (!isset($_SERVER['REMOTE_USER'])) { 379d2e1be6SAndreas Gohr http_status(401); 38b2a3342aSTim Roes return new IXR_Error(-32603, "server error. not authorized to call method $methodname"); 39f71f4f53SAndreas Gohr } else { 409d2e1be6SAndreas Gohr http_status(403); 41b2a3342aSTim Roes return new IXR_Error(-32604, "server error. forbidden to call the method $methodname"); 42f71f4f53SAndreas Gohr } 433a13cfe7SDominik Eckelmann } catch (RemoteException $e) { 443a13cfe7SDominik Eckelmann return new IXR_Error($e->getCode(), $e->getMessage()); 4526bec61eSMichael Klier } 4626bec61eSMichael Klier } 4726bec61eSMichael Klier 4842ea7f44SGerrit Uitslag /** 4942ea7f44SGerrit Uitslag * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp 5042ea7f44SGerrit Uitslag * @return IXR_Date 5142ea7f44SGerrit Uitslag */ 5242a6fba0SGerrit Uitslag public function toDate($data) { 53f9501785SDominik Eckelmann return new IXR_Date($data); 54f9501785SDominik Eckelmann } 55f9501785SDominik Eckelmann 5642ea7f44SGerrit Uitslag /** 5742ea7f44SGerrit Uitslag * @param string $data 5842ea7f44SGerrit Uitslag * @return IXR_Base64 5942ea7f44SGerrit Uitslag */ 6042a6fba0SGerrit Uitslag public function toFile($data) { 61f9501785SDominik Eckelmann return new IXR_Base64($data); 62f9501785SDominik Eckelmann } 63797c0d11SAndreas Gohr} 64797c0d11SAndreas Gohr 65797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server(); 66797c0d11SAndreas Gohr 67e3776c06SMichael Hamann// vim:ts=4:sw=4:et: 68