xref: /plugin/structsection/action.php (revision adc87508697492918d4a7b7ee1db4e7939294965)
19d2d02ffSMichael Große<?php
2eadb8fe2SMichael 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
10eadb8fe2SMichael Großeclass action_plugin_structsection extends \DokuWiki_Action_Plugin
1115756b07SMichael Große{
129d2d02ffSMichael Große    /**
139d2d02ffSMichael Große     * Registers a callback function for a given event
149d2d02ffSMichael Große     *
15eadb8fe2SMichael Große     * @param \Doku_Event_Handler $controller DokuWiki's event controller object
169d2d02ffSMichael Große     * @return void
179d2d02ffSMichael Große     */
18eadb8fe2SMichael Große    public function register(\Doku_Event_Handler $controller)
1915756b07SMichael Große    {
20*cb058b5aSMichael Große        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'addPageRevisionToJSINFO');
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
25*cb058b5aSMichael Große    public function addPageRevisionToJSINFO(\Doku_Event $event, $param)
26*cb058b5aSMichael Große    {
27*cb058b5aSMichael Große        global $ACT;
28*cb058b5aSMichael Große
29*cb058b5aSMichael Große        if (act_clean($ACT) !== 'show') {
30*cb058b5aSMichael Große            return;
31*cb058b5aSMichael Große        }
32*cb058b5aSMichael Große        global $JSINFO, $INFO;
33*cb058b5aSMichael Große        $JSINFO['plugin_structsection'] = [
34*cb058b5aSMichael Große            'rev' => $INFO['currentrev'],
35*cb058b5aSMichael Große        ];
36*cb058b5aSMichael Große    }
37*cb058b5aSMichael Große
389d2d02ffSMichael Große    /**
3915756b07SMichael Große     * Event handler for PARSER_HANDLER_DONE
409d2d02ffSMichael Große     *
41eadb8fe2SMichael Große     * @param \Doku_Event $event event object by reference
429d2d02ffSMichael Große     * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
439d2d02ffSMichael Große     *                           handler was registered]
449d2d02ffSMichael Große     * @return void
459d2d02ffSMichael Große     */
46eadb8fe2SMichael Große    final public function appendPluginOutputToPage(\Doku_Event $event, $param)
4715756b07SMichael Große    {
481d58a283SMichael Große        static $instructionsAdded = false;
491d58a283SMichael Große
50eadb8fe2SMichael Große        /** @var \helper_plugin_struct $struct */
516b380169SMichael Große        $struct = plugin_load('helper', 'struct');
526b380169SMichael Große        if (!$struct) {
536b380169SMichael Große            return;
546b380169SMichael Große        }
556b380169SMichael Große
566b380169SMichael Große        global $ACT;
576b380169SMichael Große
586b380169SMichael Große        if (act_clean($ACT) != 'show') {
596b380169SMichael Große            return;
606b380169SMichael Große        }
616b380169SMichael Große
621d58a283SMichael Große        if ($instructionsAdded) {
631d58a283SMichael Große            return;
641d58a283SMichael Große        }
651d58a283SMichael Große
661d58a283SMichael Große        $instructionsAdded = true;
671d58a283SMichael Große
686b380169SMichael Große        $last = end($event->data->calls);
6978317c4bSMichael Große
7078317c4bSMichael Große        $INSTRUCTION_POSITION_INDEX = 2;
7178317c4bSMichael Große        $pos = $last[$INSTRUCTION_POSITION_INDEX];
726b380169SMichael Große
736b380169SMichael Große        $event->data->calls[] = array(
746b380169SMichael Große            'plugin',
756b380169SMichael Große            array(
76284f9fc3SMichael Große                'structsection', array('pos' => $pos), DOKU_LEXER_SPECIAL, '',
776b380169SMichael Große            ),
786b380169SMichael Große            $pos,
796b380169SMichael Große        );
806b380169SMichael Große    }
816b380169SMichael Große
8215756b07SMichael Große    /**
8315756b07SMichael Große     * Event handler for PLUGIN_STRUCT_TYPECLASS_INIT
8415756b07SMichael Große     *
85eadb8fe2SMichael Große     * @param \Doku_Event $event
8615756b07SMichael Große     * @param            $param
8715756b07SMichael Große     */
88eadb8fe2SMichael Große    final public function registerTypeWithStructPlugin(\Doku_Event $event, $param)
8915756b07SMichael Große    {
90284f9fc3SMichael Große        $event->data['Section'] = 'dokuwiki\\plugin\\structsection\\types\\Section';
919d2d02ffSMichael Große    }
929d2d02ffSMichael Große}
939d2d02ffSMichael Große
949d2d02ffSMichael Große// vim:ts=4:sw=4:et:
95