1<?php 2 3/** 4 * DokuWiki Plugin struct (Action Component) 5 * 6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7 * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 8 */ 9 10use dokuwiki\plugin\struct\meta\Column; 11use dokuwiki\plugin\struct\types\AbstractBaseType; 12 13class action_plugin_struct_config extends DokuWiki_Action_Plugin 14{ 15 16 /** 17 * Registers a callback function for a given event 18 * 19 * @param Doku_Event_Handler $controller DokuWiki's event controller object 20 * @return void 21 */ 22 public function register(Doku_Event_Handler $controller) 23 { 24 $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjax'); 25 $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'addJsinfo'); 26 } 27 28 /** 29 * Reconfigure config for a given type 30 * 31 * @param Doku_Event $event event object by reference 32 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 33 * handler was registered] 34 */ 35 public function handleAjax(Doku_Event $event, $param) 36 { 37 if ($event->data != 'plugin_struct_config') return; 38 $event->preventDefault(); 39 $event->stopPropagation(); 40 global $INPUT; 41 42 $conf = json_decode($INPUT->str('conf'), true); 43 $typeclasses = Column::allTypes(); 44 $class = $typeclasses[$INPUT->str('type', 'Text')]; 45 /** @var AbstractBaseType $type */ 46 $type = new $class($conf); 47 48 header('Content-Type: text/plain'); // we need the encoded string, not decoded by jQuery 49 echo json_encode($type->getConfig()); 50 } 51 52 /** 53 * Add config options to JSINFO 54 * 55 * @param Doku_Event $event 56 */ 57 public function addJsinfo(Doku_Event $event) 58 { 59 global $JSINFO; 60 $JSINFO['plugins']['struct']['disableDeleteSerial'] = $this->getConf('disableDeleteSerial'); 61 } 62} 63