From f95017850a515969190f54df3d57a00449245bb9 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 8 Jan 2012 18:37:59 +0100 Subject: delegate file and date transformation to remote library --- inc/RemoteAPICore.php | 26 ++++++++++++++++---------- inc/remote.php | 33 +++++++++++++++++++++++++++++---- lib/exe/xmlrpc.php | 10 ++++++++++ 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/inc/RemoteAPICore.php b/inc/RemoteAPICore.php index a19c1b84e..639aa4536 100644 --- a/inc/RemoteAPICore.php +++ b/inc/RemoteAPICore.php @@ -2,6 +2,12 @@ class RemoteAPICore { + private $api; + + public function __construct(RemoteAPI $api) { + $this->api = $api; + } + function __getRemoteInfo() { return array( 'dokuwiki.getVersion' => array( @@ -217,7 +223,7 @@ class RemoteAPICore { } $data = io_readFile($file, false); - return new RemoteFile($data); + return $this->api->toFile($data); } /** @@ -228,13 +234,13 @@ class RemoteAPICore { function getAttachmentInfo($id){ $id = cleanID($id); $info = array( - 'lastModified' => new RemoteDate(0), + 'lastModified' => $this->api->toDate(0), 'size' => 0, ); $file = mediaFN($id); if ((auth_quickaclcheck(getNS($id).':*') >= AUTH_READ) && file_exists($file)){ - $info['lastModified'] = new RemoteDate(filemtime($file)); + $info['lastModified'] = $this->api->toDate(filemtime($file)); $info['size'] = filesize($file); } @@ -269,7 +275,7 @@ class RemoteAPICore { $page['id'] = trim($pages[$idx]); $page['perms'] = $perm; $page['size'] = @filesize(wikiFN($pages[$idx])); - $page['lastModified'] = new RemoteDate(@filemtime(wikiFN($pages[$idx]))); + $page['lastModified'] = $this->api->toDate(@filemtime(wikiFN($pages[$idx]))); $list[] = $page; } @@ -362,7 +368,7 @@ class RemoteAPICore { for($i=0; $i<$len; $i++) { unset($data[$i]['meta']); - $data[$i]['lastModified'] = new RemoteDate($data[$i]['mtime']); + $data[$i]['lastModified'] = $this->api->toDate($data[$i]['mtime']); } return $data; } else { @@ -395,7 +401,7 @@ class RemoteAPICore { $data = array( 'name' => $id, - 'lastModified' => new RemoteDate($time), + 'lastModified' => $this->api->toDate($time), 'author' => (($info['user']) ? $info['user'] : $info['ip']), 'version' => $time ); @@ -477,7 +483,7 @@ class RemoteAPICore { * * Michael Klier */ - function putAttachment($id, RemoteFile $file, $params) { + function putAttachment($id, $file, $params) { $id = cleanID($id); $auth = auth_quickaclcheck(getNS($id).':*'); @@ -596,7 +602,7 @@ class RemoteAPICore { foreach ($recents as $recent) { $change = array(); $change['name'] = $recent['id']; - $change['lastModified'] = new RemoteDate($recent['date']); + $change['lastModified'] = $this->api->toDate($recent['date']); $change['author'] = $recent['user']; $change['version'] = $recent['date']; $change['perms'] = $recent['perms']; @@ -629,7 +635,7 @@ class RemoteAPICore { foreach ($recents as $recent) { $change = array(); $change['name'] = $recent['id']; - $change['lastModified'] = new RemoteDate($recent['date']); + $change['lastModified'] = $this->api->toDate($recent['date']); $change['author'] = $recent['user']; $change['version'] = $recent['date']; $change['perms'] = $recent['perms']; @@ -693,7 +699,7 @@ class RemoteAPICore { $data['ip'] = $info['ip']; $data['type'] = $info['type']; $data['sum'] = $info['sum']; - $data['modified'] = new RemoteDate($info['date']); + $data['modified'] = $this->api->toDate($info['date']); $data['version'] = $info['date']; array_push($versions, $data); } diff --git a/inc/remote.php b/inc/remote.php index c18cb3713..71ceb97b5 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -18,9 +18,6 @@ abstract class RemoteDataType { } } -class RemoteDate extends RemoteDataType {} -class RemoteFile extends RemoteDataType {} - /** * This class provides information about remote access to the wiki. * @@ -66,6 +63,14 @@ class RemoteAPI { */ private $pluginMethods = null; + private $dateTransformation; + private $fileTransformation; + + public function __construct() { + $this->dateTransformation = array($this, 'dummyTransformation'); + $this->fileTransformation = array($this, 'dummyTransformation'); + } + /** * Get all available methods with remote access. * @@ -191,11 +196,31 @@ class RemoteAPI { public function getCoreMethods($apiCore = null) { if ($this->coreMethods === null) { if ($apiCore === null) { - $this->coreMethods = new RemoteAPICore(); + $this->coreMethods = new RemoteAPICore($this); } else { $this->coreMethods = $apiCore; } } return $this->coreMethods->__getRemoteInfo(); } + + public function toFile($data) { + return call_user_func($this->fileTransformation, $data); + } + + public function toDate($data) { + return call_user_func($this->dateTransformation, $data); + } + + public function dummyTransformation($data) { + return $data; + } + + public function setDateTransformation($dateTransformation) { + $this->dateTransformation = $dateTransformation; + } + + public function setFileTransformation($fileTransformation) { + $this->fileTransformation = $fileTransformation; + } } \ No newline at end of file diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php index 9888c9a61..44b4ba7a0 100644 --- a/lib/exe/xmlrpc.php +++ b/lib/exe/xmlrpc.php @@ -27,6 +27,8 @@ class dokuwiki_xmlrpc_server extends IXR_Server { */ function dokuwiki_xmlrpc_server(){ $this->remote = new RemoteAPI(); + $this->remote->setDateTransformation(array($this, 'toDate')); + $this->remote->setFileTransformation(array($this, 'toFile')); $this->IXR_Server(); } @@ -47,6 +49,14 @@ class dokuwiki_xmlrpc_server extends IXR_Server { } } + function toDate($data) { + return new IXR_Date($data); + } + + function toFile($data) { + return new IXR_Base64($data); + } + } $server = new dokuwiki_xmlrpc_server(); -- cgit v1.2.3