1<?php 2/** 3 * DokuWiki Plugin struct (Helper Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10use dokuwiki\plugin\struct\meta\StructException; 11 12if(!defined('DOKU_INC')) die(); 13 14 15class remote_plugin_struct extends DokuWiki_Remote_Plugin { 16 /** @var helper_plugin_struct hlp */ 17 protected $hlp; 18 19 /** 20 * remote_plugin_struct constructor. 21 */ 22 public function __construct() { 23 parent::__construct(); 24 25 /** @var helper_plugin_struct hlp */ 26 $this->hlp = plugin_load('helper', 'struct'); 27 } 28 29 /** 30 * Get the structured data of a given page 31 * 32 * @param string $page The page to get data for 33 * @param string $schema The schema to use empty for all 34 * @param int $time A timestamp if you want historic data (0 for now) 35 * @return array ('schema' => ( 'fieldlabel' => 'value', ...)) 36 * @throws RemoteAccessDeniedException 37 * @throws RemoteException 38 */ 39 public function getData($page, $schema, $time) { 40 $page = cleanID($page); 41 42 if(!auth_quickaclcheck($page) < AUTH_READ) { 43 throw new RemoteAccessDeniedException('no permissions to access data of that page'); 44 } 45 46 if(!$schema) $schema = null; 47 48 try { 49 return $this->hlp->getData($page, $schema, $time); 50 } catch (StructException $e) { 51 throw new RemoteException($e->getMessage(), 0, $e); 52 } 53 } 54 55 56 /** 57 * Saves data for a given page (creates a new revision) 58 * 59 * If this call succeeds you can assume your data has either been saved or it was 60 * not necessary to save it because the data already existed in the wanted form or 61 * the given schemas are no longer assigned to that page. 62 * 63 * @param string $page 64 * @param array $data ('schema' => ( 'fieldlabel' => 'value', ...)) 65 * @param string $summary 66 * @return bool returns always true 67 * @throws RemoteAccessDeniedException 68 * @throws RemoteException 69 */ 70 public function saveData($page, $data, $summary) { 71 $page = cleanID($page); 72 73 if(!auth_quickaclcheck($page) < AUTH_EDIT) { 74 throw new RemoteAccessDeniedException('no permissions to save data for that page'); 75 } 76 77 try { 78 $this->hlp->saveData($page, $data, $summary); 79 return true; 80 } catch (StructException $e) { 81 throw new RemoteException($e->getMessage(), 0, $e); 82 } 83 } 84 85 /** 86 * Get info about existing schemas columns 87 * 88 * Returns only current, enabled columns 89 * 90 * @param string $schema the schema to query, empty for all 91 * @return array 92 * @throws RemoteAccessDeniedException 93 * @throws RemoteException 94 */ 95 public function getSchema($schema) { 96 if(!auth_ismanager()) { 97 throw new RemoteAccessDeniedException('you need to be manager to access schema info'); 98 } 99 100 if(!$schema) $schema = null; 101 try { 102 $result = array(); 103 $schemas = $this->hlp->getSchema($schema); 104 foreach($schemas as $name => $schema) { 105 $result[$name] = array(); 106 foreach ($schema->getColumns(false) as $column) { 107 $result[$name][] = array( 108 'name' => $column->getLabel(), 109 'type' => array_pop(explode('\\', get_class($column->getType()))), 110 'ismulti' => $column->isMulti() 111 ); 112 } 113 } 114 return $result; 115 } catch (StructException $e) { 116 throw new RemoteException($e->getMessage(), 0, $e); 117 } 118 } 119} 120