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