xref: /plugin/structsection/action.php (revision 9f39a0a1656ce783ca72bb68688bc4549dcfe356)
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     * Registers a callback function for a given event
13     *
14     * @param Doku_Event_Handler $controller DokuWiki's event controller object
15     * @return void
16     */
17    public function register(Doku_Event_Handler $controller) {
18        $controller->register_hook('PARSER_HANDLER_DONE', 'AFTER', $this, 'handle_parser_done');
19        $controller->register_hook('PLUGIN_STRUCT_TYPECLASS_INIT', 'BEFORE', $this, 'handle_init');
20    }
21
22    /**
23     * [Custom event handler which performs action]
24     *
25     * @param Doku_Event $event event object by reference
26     * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
27     *                           handler was registered]
28     * @return void
29     */
30
31    public function handle_parser_done(Doku_Event $event, $param) {
32        /** @var helper_plugin_struct $struct */
33        $struct = plugin_load('helper', 'struct');
34        if (!$struct) {
35            return;
36        }
37
38        global $ACT;
39
40        if (act_clean($ACT) != 'show') {
41            dbglog($ACT, __FILE__ .': '.__LINE__);
42            return;
43        }
44
45        $last = end($event->data->calls);
46        $pos = $last[2];
47
48        $event->data->calls[] = array(
49            'plugin',
50            array(
51                'structsection', array('pos' => $pos), DOKU_LEXER_SPECIAL, '',
52            ),
53            $pos,
54        );
55    }
56
57    public function handle_init(Doku_Event &$event, $param) {
58        $event->data['Section'] = 'dokuwiki\\plugin\\structsection\\types\\Section';
59    }
60
61}
62
63// vim:ts=4:sw=4:et:
64