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