11cdd0090SAndreas Gohr<?php 21cdd0090SAndreas Gohr 31cdd0090SAndreas Gohrnamespace dokuwiki\Remote; 41cdd0090SAndreas Gohr 57f8f2456SAndreas Gohruse IXR\DataType\Base64; 67f8f2456SAndreas Gohruse IXR\DataType\Date; 77f8f2456SAndreas Gohruse IXR\Exception\ServerException; 87f8f2456SAndreas Gohruse IXR\Server\Server; 97f8f2456SAndreas Gohr 101cdd0090SAndreas Gohr/** 111cdd0090SAndreas Gohr * Contains needed wrapper functions and registers all available XMLRPC functions. 121cdd0090SAndreas Gohr */ 137f8f2456SAndreas Gohrclass XmlRpcServer extends Server 141cdd0090SAndreas Gohr{ 151cdd0090SAndreas Gohr protected $remote; 161cdd0090SAndreas Gohr 171cdd0090SAndreas Gohr /** 181cdd0090SAndreas Gohr * Constructor. Register methods and run Server 191cdd0090SAndreas Gohr */ 20fe52a7caSMark Janssen public function __construct($wait=false) 211cdd0090SAndreas Gohr { 221cdd0090SAndreas Gohr $this->remote = new Api(); 231cdd0090SAndreas Gohr $this->remote->setDateTransformation(array($this, 'toDate')); 241cdd0090SAndreas Gohr $this->remote->setFileTransformation(array($this, 'toFile')); 25fe52a7caSMark Janssen parent::__construct(false, false, $wait); 261cdd0090SAndreas Gohr } 271cdd0090SAndreas Gohr 28*1498ac42SAndreas Gohr /** @inheritdoc */ 29*1498ac42SAndreas Gohr public function serve($data = false) 30*1498ac42SAndreas Gohr { 31*1498ac42SAndreas Gohr global $conf; 32*1498ac42SAndreas Gohr if (!$conf['remote']) { 33*1498ac42SAndreas Gohr throw new ServerException("XML-RPC server not enabled.", -32605); 34*1498ac42SAndreas Gohr } 35*1498ac42SAndreas Gohr parent::serve($data); 36*1498ac42SAndreas Gohr } 37*1498ac42SAndreas Gohr 381cdd0090SAndreas Gohr /** 391cdd0090SAndreas Gohr * @inheritdoc 401cdd0090SAndreas Gohr */ 411cdd0090SAndreas Gohr public function call($methodname, $args) 421cdd0090SAndreas Gohr { 431cdd0090SAndreas Gohr try { 441cdd0090SAndreas Gohr $result = $this->remote->call($methodname, $args); 451cdd0090SAndreas Gohr return $result; 467f8f2456SAndreas Gohr } catch (AccessDeniedException $e) { 471cdd0090SAndreas Gohr if (!isset($_SERVER['REMOTE_USER'])) { 481cdd0090SAndreas Gohr http_status(401); 497f8f2456SAndreas Gohr return new ServerException("server error. not authorized to call method $methodname", -32603); 501cdd0090SAndreas Gohr } else { 511cdd0090SAndreas Gohr http_status(403); 527f8f2456SAndreas Gohr return new ServerException("server error. forbidden to call the method $methodname", -32604); 531cdd0090SAndreas Gohr } 541cdd0090SAndreas Gohr } catch (RemoteException $e) { 557f8f2456SAndreas Gohr return new ServerException($e->getMessage(), $e->getCode()); 561cdd0090SAndreas Gohr } 571cdd0090SAndreas Gohr } 581cdd0090SAndreas Gohr 591cdd0090SAndreas Gohr /** 601cdd0090SAndreas Gohr * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp 617f8f2456SAndreas Gohr * @return Date 621cdd0090SAndreas Gohr */ 631cdd0090SAndreas Gohr public function toDate($data) 641cdd0090SAndreas Gohr { 657f8f2456SAndreas Gohr return new Date($data); 661cdd0090SAndreas Gohr } 671cdd0090SAndreas Gohr 681cdd0090SAndreas Gohr /** 691cdd0090SAndreas Gohr * @param string $data 707f8f2456SAndreas Gohr * @return Base64 711cdd0090SAndreas Gohr */ 721cdd0090SAndreas Gohr public function toFile($data) 731cdd0090SAndreas Gohr { 747f8f2456SAndreas Gohr return new Base64($data); 751cdd0090SAndreas Gohr } 761cdd0090SAndreas Gohr} 77