xref: /plugin/structsection/action.php (revision 284f9fc3fe87c819811b9293950be7ba46307b04)
19d2d02ffSMichael Große<?php
29d2d02ffSMichael Große/**
3*284f9fc3SMichael 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
99d2d02ffSMichael Große// must be run within Dokuwiki
109d2d02ffSMichael Großeif (!defined('DOKU_INC')) die();
119d2d02ffSMichael Große
12*284f9fc3SMichael Großeclass action_plugin_structsection extends DokuWiki_Action_Plugin {
139d2d02ffSMichael Große
149d2d02ffSMichael Große    /**
159d2d02ffSMichael Große     * Registers a callback function for a given event
169d2d02ffSMichael Große     *
179d2d02ffSMichael Große     * @param Doku_Event_Handler $controller DokuWiki's event controller object
189d2d02ffSMichael Große     * @return void
199d2d02ffSMichael Große     */
209d2d02ffSMichael Große    public function register(Doku_Event_Handler $controller) {
216b380169SMichael Große        $controller->register_hook('PARSER_HANDLER_DONE', 'AFTER', $this, 'handle_parser_done');
226b380169SMichael Große        $controller->register_hook('PLUGIN_STRUCT_TYPECLASS_INIT', 'BEFORE', $this, 'handle_init');
239d2d02ffSMichael Große    }
249d2d02ffSMichael Große
259d2d02ffSMichael Große    /**
269d2d02ffSMichael Große     * [Custom event handler which performs action]
279d2d02ffSMichael Große     *
289d2d02ffSMichael 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     */
339d2d02ffSMichael Große
346b380169SMichael Große    public function handle_parser_done(Doku_Event $event, $param) {
356b380169SMichael Große        /** @var helper_plugin_struct $struct */
366b380169SMichael Große        $struct = plugin_load('helper', 'struct');
376b380169SMichael Große        if (!$struct) {
386b380169SMichael Große            return;
396b380169SMichael Große        }
406b380169SMichael Große
416b380169SMichael Große        global $ACT;
426b380169SMichael Große
436b380169SMichael Große        if (act_clean($ACT) != 'show') {
446b380169SMichael Große            dbglog($ACT, __FILE__ .': '.__LINE__);
456b380169SMichael Große            return;
466b380169SMichael Große        }
476b380169SMichael Große
486b380169SMichael Große        $last = end($event->data->calls);
496b380169SMichael Große        $pos = $last[2];
506b380169SMichael Große
516b380169SMichael Große        $event->data->calls[] = array(
526b380169SMichael Große            'plugin',
536b380169SMichael Große            array(
54*284f9fc3SMichael Große                'structsection', array('pos' => $pos), DOKU_LEXER_SPECIAL, '',
556b380169SMichael Große            ),
566b380169SMichael Große            $pos,
576b380169SMichael Große        );
586b380169SMichael Große    }
596b380169SMichael Große
606b380169SMichael Große    public function handle_init(Doku_Event &$event, $param) {
61*284f9fc3SMichael Große        $event->data['Section'] = 'dokuwiki\\plugin\\structsection\\types\\Section';
629d2d02ffSMichael Große    }
639d2d02ffSMichael Große
649d2d02ffSMichael Große}
659d2d02ffSMichael Große
669d2d02ffSMichael Große// vim:ts=4:sw=4:et:
67