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