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