18824339dSAndreas Gohr<?php 28824339dSAndreas Gohr/** 38824339dSAndreas Gohr * DokuWiki Plugin struct (Action Component) 48824339dSAndreas Gohr * 58824339dSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 68824339dSAndreas Gohr * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 78824339dSAndreas Gohr */ 88824339dSAndreas Gohr 98824339dSAndreas Gohr// must be run within Dokuwiki 10*18902e76SMichael Großeuse dokuwiki\plugin\struct\meta\Column; 118824339dSAndreas Gohruse dokuwiki\plugin\struct\types\AbstractBaseType; 128824339dSAndreas Gohr 138824339dSAndreas Gohrif(!defined('DOKU_INC')) die(); 148824339dSAndreas Gohr 158824339dSAndreas Gohrclass action_plugin_struct_config extends DokuWiki_Action_Plugin { 168824339dSAndreas Gohr 178824339dSAndreas Gohr /** 188824339dSAndreas Gohr * Registers a callback function for a given event 198824339dSAndreas Gohr * 208824339dSAndreas Gohr * @param Doku_Event_Handler $controller DokuWiki's event controller object 218824339dSAndreas Gohr * @return void 228824339dSAndreas Gohr */ 238824339dSAndreas Gohr public function register(Doku_Event_Handler $controller) { 248824339dSAndreas Gohr $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax'); 258824339dSAndreas Gohr } 268824339dSAndreas Gohr 278824339dSAndreas Gohr /** 288824339dSAndreas Gohr * Reconfigure config for a given type 298824339dSAndreas Gohr * 308824339dSAndreas Gohr * @param Doku_Event $event event object by reference 318824339dSAndreas Gohr * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 328824339dSAndreas Gohr * handler was registered] 338824339dSAndreas Gohr */ 348824339dSAndreas Gohr public function handle_ajax(Doku_Event $event, $param) { 358824339dSAndreas Gohr if($event->data != 'plugin_struct_config') return; 368824339dSAndreas Gohr $event->preventDefault(); 378824339dSAndreas Gohr $event->stopPropagation(); 388824339dSAndreas Gohr global $INPUT; 398824339dSAndreas Gohr 408824339dSAndreas Gohr $conf = json_decode($INPUT->str('conf'), true); 41*18902e76SMichael Große $typeclasses = Column::allTypes(); 42*18902e76SMichael Große $class = $typeclasses[$INPUT->str('type', 'Text')]; 438824339dSAndreas Gohr /** @var AbstractBaseType $type */ 448824339dSAndreas Gohr $type = new $class($conf); 458824339dSAndreas Gohr 468824339dSAndreas Gohr header('Content-Type: text/plain'); // we need the encoded string, not decoded by jQuery 478824339dSAndreas Gohr echo json_encode($type->getConfig()); 488824339dSAndreas Gohr } 498824339dSAndreas Gohr 508824339dSAndreas Gohr} 51