xref: /plugin/sectionedit/action.php (revision 68fe61b8d73a593c721c407b01906555a400b933)
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*68fe61b8SGerry Weißbach        global  $ACT,  $INPUT, $QUERY, $ID, $REV, $DATE_AT, $IDX,
38*68fe61b8SGerry Weißbach        $DATE, $RANGE, $HIGH, $TEXT, $PRE, $SUF, $SUM, $INFO, $JSINFO;
39c03f4736SGerry Weißbach
40c03f4736SGerry Weißbach        if ( $event->data != 'sectionedit' ) return false;
41c03f4736SGerry Weißbach        $event->preventDefault();
42c03f4736SGerry Weißbach
43c03f4736SGerry Weißbach        $ACT = act_validate($INPUT->str('do'));
44c03f4736SGerry Weißbach        if ( !in_array($ACT, array('show', 'edit', 'save')) ) return;
45463e69e9SGerry Weißbach        $this->inited = $ACT;
46c03f4736SGerry Weißbach
47c03f4736SGerry Weißbach        // This seems super evil.
48c03f4736SGerry Weißbach        // if we catch all our variables, include the doku.php to do its normal magic.
49c03f4736SGerry Weißbach        // EXCEPT: we will catch the ACT_PREPROCESS in AFTER, outpout the current content and be done with it.
50c03f4736SGerry Weißbach        // This will either: show the current page ('show' or 'save') or the edit form.
51c03f4736SGerry Weißbach        return include_once(DOKU_INC . '/doku.php');
52c03f4736SGerry Weißbach    }
53c03f4736SGerry Weißbach
54c03f4736SGerry Weißbach    function handle_suppress_default_after(Doku_Event &$event, $param) {
55c03f4736SGerry Weißbach
56*68fe61b8SGerry Weißbach        global  $ACT,  $INPUT, $QUERY, $ID, $REV, $DATE_AT, $IDX,
57*68fe61b8SGerry Weißbach        $DATE, $RANGE, $HIGH, $TEXT, $PRE, $SUF, $SUM, $INFO, $JSINFO;
58c03f4736SGerry Weißbach        // If this plugin already ran into the sectionedit action, we will be inited and we can just output the template
59463e69e9SGerry Weißbach        // if the ACT was save, return nothing to John Snow. We need another request for show.
60c03f4736SGerry Weißbach        // hint: super evil. handle with care. experimental.
61463e69e9SGerry Weißbach        if ( is_null($this->inited) || $this->inited == 'save' ) return;
62c03f4736SGerry Weißbach        tpl_content();
63c03f4736SGerry Weißbach        exit;
64c03f4736SGerry Weißbach    }
65c03f4736SGerry Weißbach}
66c03f4736SGerry Weißbach
67c03f4736SGerry Weißbach// vim:ts=4:sw=4:et:
68