1*1cdd0090SAndreas Gohr<?php 2*1cdd0090SAndreas Gohr 3*1cdd0090SAndreas Gohrnamespace dokuwiki\Remote; 4*1cdd0090SAndreas Gohr 5*1cdd0090SAndreas Gohr/** 6*1cdd0090SAndreas Gohr * Contains needed wrapper functions and registers all available XMLRPC functions. 7*1cdd0090SAndreas Gohr */ 8*1cdd0090SAndreas Gohrclass XmlRpcServer extends \IXR_Server 9*1cdd0090SAndreas Gohr{ 10*1cdd0090SAndreas Gohr protected $remote; 11*1cdd0090SAndreas Gohr 12*1cdd0090SAndreas Gohr /** 13*1cdd0090SAndreas Gohr * Constructor. Register methods and run Server 14*1cdd0090SAndreas Gohr */ 15*1cdd0090SAndreas Gohr public function __construct() 16*1cdd0090SAndreas Gohr { 17*1cdd0090SAndreas Gohr $this->remote = new Api(); 18*1cdd0090SAndreas Gohr $this->remote->setDateTransformation(array($this, 'toDate')); 19*1cdd0090SAndreas Gohr $this->remote->setFileTransformation(array($this, 'toFile')); 20*1cdd0090SAndreas Gohr parent::__construct(); 21*1cdd0090SAndreas Gohr } 22*1cdd0090SAndreas Gohr 23*1cdd0090SAndreas Gohr /** 24*1cdd0090SAndreas Gohr * @inheritdoc 25*1cdd0090SAndreas Gohr */ 26*1cdd0090SAndreas Gohr public function call($methodname, $args) 27*1cdd0090SAndreas Gohr { 28*1cdd0090SAndreas Gohr try { 29*1cdd0090SAndreas Gohr $result = $this->remote->call($methodname, $args); 30*1cdd0090SAndreas Gohr return $result; 31*1cdd0090SAndreas Gohr } /** @noinspection PhpRedundantCatchClauseInspection */ catch (AccessDeniedException $e) { 32*1cdd0090SAndreas Gohr if (!isset($_SERVER['REMOTE_USER'])) { 33*1cdd0090SAndreas Gohr http_status(401); 34*1cdd0090SAndreas Gohr return new \IXR_Error(-32603, "server error. not authorized to call method $methodname"); 35*1cdd0090SAndreas Gohr } else { 36*1cdd0090SAndreas Gohr http_status(403); 37*1cdd0090SAndreas Gohr return new \IXR_Error(-32604, "server error. forbidden to call the method $methodname"); 38*1cdd0090SAndreas Gohr } 39*1cdd0090SAndreas Gohr } catch (RemoteException $e) { 40*1cdd0090SAndreas Gohr return new \IXR_Error($e->getCode(), $e->getMessage()); 41*1cdd0090SAndreas Gohr } 42*1cdd0090SAndreas Gohr } 43*1cdd0090SAndreas Gohr 44*1cdd0090SAndreas Gohr /** 45*1cdd0090SAndreas Gohr * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp 46*1cdd0090SAndreas Gohr * @return \IXR_Date 47*1cdd0090SAndreas Gohr */ 48*1cdd0090SAndreas Gohr public function toDate($data) 49*1cdd0090SAndreas Gohr { 50*1cdd0090SAndreas Gohr return new \IXR_Date($data); 51*1cdd0090SAndreas Gohr } 52*1cdd0090SAndreas Gohr 53*1cdd0090SAndreas Gohr /** 54*1cdd0090SAndreas Gohr * @param string $data 55*1cdd0090SAndreas Gohr * @return \IXR_Base64 56*1cdd0090SAndreas Gohr */ 57*1cdd0090SAndreas Gohr public function toFile($data) 58*1cdd0090SAndreas Gohr { 59*1cdd0090SAndreas Gohr return new \IXR_Base64($data); 60*1cdd0090SAndreas Gohr } 61*1cdd0090SAndreas Gohr} 62