xref: /plugin/structsection/action.php (revision eadb8fe2a375710293a0ead93a9189831bcc2dfe)
19d2d02ffSMichael Große<?php
2*eadb8fe2SMichael Große
39d2d02ffSMichael Große/**
4284f9fc3SMichael Große * DokuWiki Plugin structsection (Action Component)
59d2d02ffSMichael Große *
69d2d02ffSMichael Große * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
79d2d02ffSMichael Große * @author  Michael Große <mic.grosse@googlemail.com>
89d2d02ffSMichael Große */
99d2d02ffSMichael Große
10*eadb8fe2SMichael Großeclass action_plugin_structsection extends \DokuWiki_Action_Plugin
1115756b07SMichael Große{
129d2d02ffSMichael Große
139d2d02ffSMichael Große    /**
149d2d02ffSMichael Große     * Registers a callback function for a given event
159d2d02ffSMichael Große     *
16*eadb8fe2SMichael Große     * @param \Doku_Event_Handler $controller DokuWiki's event controller object
179d2d02ffSMichael Große     * @return void
189d2d02ffSMichael Große     */
19*eadb8fe2SMichael Große    public function register(\Doku_Event_Handler $controller)
2015756b07SMichael Große    {
2115756b07SMichael Große        $controller->register_hook('PARSER_HANDLER_DONE', 'AFTER', $this, 'appendPluginOutputToPage');
2215756b07SMichael Große        $controller->register_hook('PLUGIN_STRUCT_TYPECLASS_INIT', 'BEFORE', $this, 'registerTypeWithStructPlugin');
239d2d02ffSMichael Große    }
249d2d02ffSMichael Große
259d2d02ffSMichael Große    /**
2615756b07SMichael Große     * Event handler for PARSER_HANDLER_DONE
279d2d02ffSMichael Große     *
28*eadb8fe2SMichael Große     * @param \Doku_Event $event event object by reference
299d2d02ffSMichael Große     * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
309d2d02ffSMichael Große     *                           handler was registered]
319d2d02ffSMichael Große     * @return void
329d2d02ffSMichael Große     */
33*eadb8fe2SMichael Große    final public function appendPluginOutputToPage(\Doku_Event $event, $param)
3415756b07SMichael Große    {
351d58a283SMichael Große        static $instructionsAdded = false;
361d58a283SMichael Große
37*eadb8fe2SMichael Große        /** @var \helper_plugin_struct $struct */
386b380169SMichael Große        $struct = plugin_load('helper', 'struct');
396b380169SMichael Große        if (!$struct) {
406b380169SMichael Große            return;
416b380169SMichael Große        }
426b380169SMichael Große
436b380169SMichael Große        global $ACT;
446b380169SMichael Große
456b380169SMichael Große        if (act_clean($ACT) != 'show') {
466b380169SMichael Große            dbglog($ACT, __FILE__ . ': ' . __LINE__);
476b380169SMichael Große            return;
486b380169SMichael Große        }
496b380169SMichael Große
501d58a283SMichael Große        if ($instructionsAdded) {
511d58a283SMichael Große            return;
521d58a283SMichael Große        }
531d58a283SMichael Große
541d58a283SMichael Große        $instructionsAdded = true;
551d58a283SMichael Große
566b380169SMichael Große        $last = end($event->data->calls);
5778317c4bSMichael Große
5878317c4bSMichael Große        $INSTRUCTION_POSITION_INDEX = 2;
5978317c4bSMichael Große        $pos = $last[$INSTRUCTION_POSITION_INDEX];
606b380169SMichael Große
616b380169SMichael Große        $event->data->calls[] = array(
626b380169SMichael Große            'plugin',
636b380169SMichael Große            array(
64284f9fc3SMichael Große                'structsection', array('pos' => $pos), DOKU_LEXER_SPECIAL, '',
656b380169SMichael Große            ),
666b380169SMichael Große            $pos,
676b380169SMichael Große        );
686b380169SMichael Große    }
696b380169SMichael Große
7015756b07SMichael Große    /**
7115756b07SMichael Große     * Event handler for PLUGIN_STRUCT_TYPECLASS_INIT
7215756b07SMichael Große     *
73*eadb8fe2SMichael Große     * @param \Doku_Event $event
7415756b07SMichael Große     * @param            $param
7515756b07SMichael Große     */
76*eadb8fe2SMichael Große    final public function registerTypeWithStructPlugin(\Doku_Event $event, $param)
7715756b07SMichael Große    {
78284f9fc3SMichael Große        $event->data['Section'] = 'dokuwiki\\plugin\\structsection\\types\\Section';
799d2d02ffSMichael Große    }
809d2d02ffSMichael Große}
819d2d02ffSMichael Große
829d2d02ffSMichael Große// vim:ts=4:sw=4:et:
83