1*8824339dSAndreas Gohr<?php 2*8824339dSAndreas Gohr/** 3*8824339dSAndreas Gohr * DokuWiki Plugin struct (Action Component) 4*8824339dSAndreas Gohr * 5*8824339dSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6*8824339dSAndreas Gohr * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 7*8824339dSAndreas Gohr */ 8*8824339dSAndreas Gohr 9*8824339dSAndreas Gohr// must be run within Dokuwiki 10*8824339dSAndreas Gohruse dokuwiki\plugin\struct\types\AbstractBaseType; 11*8824339dSAndreas Gohr 12*8824339dSAndreas Gohrif(!defined('DOKU_INC')) die(); 13*8824339dSAndreas Gohr 14*8824339dSAndreas Gohrclass action_plugin_struct_config extends DokuWiki_Action_Plugin { 15*8824339dSAndreas Gohr 16*8824339dSAndreas Gohr /** 17*8824339dSAndreas Gohr * Registers a callback function for a given event 18*8824339dSAndreas Gohr * 19*8824339dSAndreas Gohr * @param Doku_Event_Handler $controller DokuWiki's event controller object 20*8824339dSAndreas Gohr * @return void 21*8824339dSAndreas Gohr */ 22*8824339dSAndreas Gohr public function register(Doku_Event_Handler $controller) { 23*8824339dSAndreas Gohr $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax'); 24*8824339dSAndreas Gohr } 25*8824339dSAndreas Gohr 26*8824339dSAndreas Gohr /** 27*8824339dSAndreas Gohr * Reconfigure config for a given type 28*8824339dSAndreas Gohr * 29*8824339dSAndreas Gohr * @param Doku_Event $event event object by reference 30*8824339dSAndreas Gohr * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 31*8824339dSAndreas Gohr * handler was registered] 32*8824339dSAndreas Gohr */ 33*8824339dSAndreas Gohr public function handle_ajax(Doku_Event $event, $param) { 34*8824339dSAndreas Gohr if($event->data != 'plugin_struct_config') return; 35*8824339dSAndreas Gohr $event->preventDefault(); 36*8824339dSAndreas Gohr $event->stopPropagation(); 37*8824339dSAndreas Gohr global $INPUT; 38*8824339dSAndreas Gohr 39*8824339dSAndreas Gohr $conf = json_decode($INPUT->str('conf'), true); 40*8824339dSAndreas Gohr /** @var AbstractBaseType $type */ 41*8824339dSAndreas Gohr $class = 'dokuwiki\\plugin\\struct\\types\\' . $INPUT->str('type', 'Text'); 42*8824339dSAndreas Gohr $type = new $class($conf); 43*8824339dSAndreas Gohr 44*8824339dSAndreas Gohr header('Content-Type: text/plain'); // we need the encoded string, not decoded by jQuery 45*8824339dSAndreas Gohr echo json_encode($type->getConfig()); 46*8824339dSAndreas Gohr } 47*8824339dSAndreas Gohr 48*8824339dSAndreas Gohr} 49