xref: /plugin/struct/action/output.php (revision 33e429a8d9965918d4772b31235df1e31b85d4ef)
1<?php
2/**
3 * DokuWiki Plugin struct (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12/**
13 * Class action_plugin_struct_output
14 *
15 * This action component handles the automatic output of all schema data that has been assigned
16 * to the current page by appending the appropriate instruction to the handler calls.
17 *
18 * The real output creation is done within the syntax component
19 * @see syntax_plugin_struct_output
20 */
21class action_plugin_struct_output extends DokuWiki_Action_Plugin {
22
23    /**
24     * Registers a callback function for a given event
25     *
26     * @param Doku_Event_Handler $controller DokuWiki's event controller object
27     * @return void
28     */
29    public function register(Doku_Event_Handler $controller) {
30        $controller->register_hook('PARSER_HANDLER_DONE', 'AFTER', $this, 'handle_output');
31
32    }
33
34    /**
35     * Appends the instruction to render our syntax output component to each page
36     *
37     * @param Doku_Event $event
38     * @param $param
39     */
40    public function handle_output(Doku_Event &$event, $param) {
41        global $ACT;
42        global $ID;
43        // blank $ACT happens when instructions are rendered in indexer
44        if(!blank($ACT) &&  $ACT != 'show') return; //FIXME what about export_*?
45        if(!page_exists($ID)) return;
46
47        $pos = filesize(wikiFN($ID))+1;
48
49        $event->data->calls[] = array(
50            'plugin',
51            array(
52                'struct_output', array('pos'=>$pos), DOKU_LEXER_SPECIAL, ''
53            ),
54            $pos
55        );
56    }
57
58}
59
60// vim:ts=4:sw=4:et:
61