1c03f4736SGerry Weißbach<?php 2c03f4736SGerry Weißbach/** 3c03f4736SGerry Weißbach * DokuWiki Plugin ajax (Action Component) 4c03f4736SGerry Weißbach * 5c03f4736SGerry Weißbach * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6c03f4736SGerry Weißbach * @author i-net software <tools@inetsoftware.de> 7c03f4736SGerry Weißbach */ 8c03f4736SGerry Weißbach 9c03f4736SGerry Weißbach// must be run within Dokuwiki 10c03f4736SGerry Weißbachif(!defined('DOKU_INC')) die(); 11c03f4736SGerry Weißbach 12c03f4736SGerry Weißbachclass action_plugin_sectionedit extends DokuWiki_Action_Plugin { 13c03f4736SGerry Weißbach 14c03f4736SGerry Weißbach private $inited = null; 15c03f4736SGerry Weißbach 16c03f4736SGerry Weißbach /** 17c03f4736SGerry Weißbach * Registers a callback function for a given event 18c03f4736SGerry Weißbach * 19c03f4736SGerry Weißbach * @param Doku_Event_Handler $controller DokuWiki's event controller object 20c03f4736SGerry Weißbach * @return void 21c03f4736SGerry Weißbach */ 22c03f4736SGerry Weißbach public function register(Doku_Event_Handler $controller) { 23c03f4736SGerry Weißbach $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call'); 24c03f4736SGerry Weißbach $controller->register_hook('ACTION_ACT_PREPROCESS', 'AFTER', $this, 'handle_suppress_default_after'); 25c03f4736SGerry Weißbach } 26c03f4736SGerry Weißbach 27c03f4736SGerry Weißbach /** 28c03f4736SGerry Weißbach * [Custom event handler which performs action] 29c03f4736SGerry Weißbach * 30c03f4736SGerry Weißbach * @param Doku_Event $event event object by reference 31c03f4736SGerry Weißbach * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 32c03f4736SGerry Weißbach * handler was registered] 33c03f4736SGerry Weißbach * @return void 34c03f4736SGerry Weißbach */ 35c03f4736SGerry Weißbach public function handle_ajax_call(Doku_Event &$event, $param) { 36c03f4736SGerry Weißbach 37*463e69e9SGerry Weißbach global $INPUT, $ACT; 38c03f4736SGerry Weißbach 39c03f4736SGerry Weißbach if ( $event->data != 'sectionedit' ) return false; 40c03f4736SGerry Weißbach $event->preventDefault(); 41c03f4736SGerry Weißbach 42c03f4736SGerry Weißbach $ACT = act_validate($INPUT->str('do')); 43c03f4736SGerry Weißbach if ( !in_array($ACT, array('show', 'edit', 'save')) ) return; 44*463e69e9SGerry Weißbach $this->inited = $ACT; 45c03f4736SGerry Weißbach 46c03f4736SGerry Weißbach // This seems super evil. 47c03f4736SGerry Weißbach // if we catch all our variables, include the doku.php to do its normal magic. 48c03f4736SGerry Weißbach // EXCEPT: we will catch the ACT_PREPROCESS in AFTER, outpout the current content and be done with it. 49c03f4736SGerry Weißbach // This will either: show the current page ('show' or 'save') or the edit form. 50c03f4736SGerry Weißbach return include_once(DOKU_INC . '/doku.php'); 51c03f4736SGerry Weißbach } 52c03f4736SGerry Weißbach 53c03f4736SGerry Weißbach function handle_suppress_default_after(Doku_Event &$event, $param) { 54c03f4736SGerry Weißbach 55*463e69e9SGerry Weißbach global $ACT, $ID, $RANGE; 56c03f4736SGerry Weißbach // If this plugin already ran into the sectionedit action, we will be inited and we can just output the template 57*463e69e9SGerry Weißbach // if the ACT was save, return nothing to John Snow. We need another request for show. 58c03f4736SGerry Weißbach // hint: super evil. handle with care. experimental. 59*463e69e9SGerry Weißbach if ( is_null($this->inited) || $this->inited == 'save' ) return; 60c03f4736SGerry Weißbach tpl_content(); 61c03f4736SGerry Weißbach exit; 62c03f4736SGerry Weißbach } 63c03f4736SGerry Weißbach} 64c03f4736SGerry Weißbach 65c03f4736SGerry Weißbach// vim:ts=4:sw=4:et: 66