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