xref: /plugin/structsection/action.php (revision 78317c4b615dccf604992db17edb3e7c3ce324db)
1<?php
2/**
3 * DokuWiki Plugin structsection (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Michael Große <mic.grosse@googlemail.com>
7 */
8
9class action_plugin_structsection extends DokuWiki_Action_Plugin
10{
11
12    /**
13     * Registers a callback function for a given event
14     *
15     * @param Doku_Event_Handler $controller DokuWiki's event controller object
16     * @return void
17     */
18    public function register(Doku_Event_Handler $controller)
19    {
20        $controller->register_hook('PARSER_HANDLER_DONE', 'AFTER', $this, 'appendPluginOutputToPage');
21        $controller->register_hook('PLUGIN_STRUCT_TYPECLASS_INIT', 'BEFORE', $this, 'registerTypeWithStructPlugin');
22    }
23
24    /**
25     * Event handler for PARSER_HANDLER_DONE
26     *
27     * @param Doku_Event $event event object by reference
28     * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
29     *                           handler was registered]
30     * @return void
31     */
32    final public function appendPluginOutputToPage(Doku_Event $event, $param)
33    {
34        static $instructionsAdded = false;
35
36        /** @var helper_plugin_struct $struct */
37        $struct = plugin_load('helper', 'struct');
38        if (!$struct) {
39            return;
40        }
41
42        global $ACT;
43
44        if (act_clean($ACT) != 'show') {
45            dbglog($ACT, __FILE__ .': '.__LINE__);
46            return;
47        }
48
49        if ($instructionsAdded) {
50            return;
51        }
52
53        $instructionsAdded = true;
54
55        $last = end($event->data->calls);
56
57        $INSTRUCTION_POSITION_INDEX = 2;
58        $pos = $last[$INSTRUCTION_POSITION_INDEX];
59
60        $event->data->calls[] = array(
61            'plugin',
62            array(
63                'structsection', array('pos' => $pos), DOKU_LEXER_SPECIAL, '',
64            ),
65            $pos,
66        );
67    }
68
69    /**
70     * Event handler for PLUGIN_STRUCT_TYPECLASS_INIT
71     *
72     * @param Doku_Event $event
73     * @param            $param
74     */
75    final public function registerTypeWithStructPlugin(Doku_Event $event, $param)
76    {
77        $event->data['Section'] = 'dokuwiki\\plugin\\structsection\\types\\Section';
78    }
79
80}
81
82// vim:ts=4:sw=4:et:
83