xref: /plugin/structsection/action.php (revision 1d58a2837394e89b4a78b1239216ff27d5678569)
19d2d02ffSMichael Große<?php
29d2d02ffSMichael Große/**
3284f9fc3SMichael Große * DokuWiki Plugin structsection (Action Component)
49d2d02ffSMichael Große *
59d2d02ffSMichael Große * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
69d2d02ffSMichael Große * @author  Michael Große <mic.grosse@googlemail.com>
79d2d02ffSMichael Große */
89d2d02ffSMichael Große
915756b07SMichael Großeclass action_plugin_structsection extends DokuWiki_Action_Plugin
1015756b07SMichael Große{
119d2d02ffSMichael Große
129d2d02ffSMichael Große    /**
139d2d02ffSMichael Große     * Registers a callback function for a given event
149d2d02ffSMichael Große     *
159d2d02ffSMichael Große     * @param Doku_Event_Handler $controller DokuWiki's event controller object
169d2d02ffSMichael Große     * @return void
179d2d02ffSMichael Große     */
1815756b07SMichael Große    public function register(Doku_Event_Handler $controller)
1915756b07SMichael Große    {
2015756b07SMichael Große        $controller->register_hook('PARSER_HANDLER_DONE', 'AFTER', $this, 'appendPluginOutputToPage');
2115756b07SMichael Große        $controller->register_hook('PLUGIN_STRUCT_TYPECLASS_INIT', 'BEFORE', $this, 'registerTypeWithStructPlugin');
229d2d02ffSMichael Große    }
239d2d02ffSMichael Große
249d2d02ffSMichael Große    /**
2515756b07SMichael Große     * Event handler for PARSER_HANDLER_DONE
269d2d02ffSMichael Große     *
279d2d02ffSMichael Große     * @param Doku_Event $event event object by reference
289d2d02ffSMichael Große     * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
299d2d02ffSMichael Große     *                           handler was registered]
309d2d02ffSMichael Große     * @return void
319d2d02ffSMichael Große     */
3215756b07SMichael Große    final public function appendPluginOutputToPage(Doku_Event $event, $param)
3315756b07SMichael Große    {
34*1d58a283SMichael Große        static $instructionsAdded = false;
35*1d58a283SMichael Große
366b380169SMichael Große        /** @var helper_plugin_struct $struct */
376b380169SMichael Große        $struct = plugin_load('helper', 'struct');
386b380169SMichael Große        if (!$struct) {
396b380169SMichael Große            return;
406b380169SMichael Große        }
416b380169SMichael Große
426b380169SMichael Große        global $ACT;
436b380169SMichael Große
446b380169SMichael Große        if (act_clean($ACT) != 'show') {
456b380169SMichael Große            dbglog($ACT, __FILE__ .': '.__LINE__);
466b380169SMichael Große            return;
476b380169SMichael Große        }
486b380169SMichael Große
49*1d58a283SMichael Große        if ($instructionsAdded) {
50*1d58a283SMichael Große            return;
51*1d58a283SMichael Große        }
52*1d58a283SMichael Große
53*1d58a283SMichael Große        $instructionsAdded = true;
54*1d58a283SMichael Große
556b380169SMichael Große        $last = end($event->data->calls);
566b380169SMichael Große        $pos = $last[2];
576b380169SMichael Große
586b380169SMichael Große        $event->data->calls[] = array(
596b380169SMichael Große            'plugin',
606b380169SMichael Große            array(
61284f9fc3SMichael Große                'structsection', array('pos' => $pos), DOKU_LEXER_SPECIAL, '',
626b380169SMichael Große            ),
636b380169SMichael Große            $pos,
646b380169SMichael Große        );
656b380169SMichael Große    }
666b380169SMichael Große
6715756b07SMichael Große    /**
6815756b07SMichael Große     * Event handler for PLUGIN_STRUCT_TYPECLASS_INIT
6915756b07SMichael Große     *
7015756b07SMichael Große     * @param Doku_Event $event
7115756b07SMichael Große     * @param            $param
7215756b07SMichael Große     */
7315756b07SMichael Große    final public function registerTypeWithStructPlugin(Doku_Event $event, $param)
7415756b07SMichael Große    {
75284f9fc3SMichael Große        $event->data['Section'] = 'dokuwiki\\plugin\\structsection\\types\\Section';
769d2d02ffSMichael Große    }
779d2d02ffSMichael Große
789d2d02ffSMichael Große}
799d2d02ffSMichael Große
809d2d02ffSMichael Große// vim:ts=4:sw=4:et:
81