xref: /plugin/combo/syntax/metadata.php (revision 9337a630db122fdba0294f47d72bdf5433c2bf10)
1<?php
2
3
4use ComboStrap\MetadataUtility;
5use ComboStrap\PluginUtility;
6
7if (!defined('DOKU_INC')) die();
8
9require_once (__DIR__.'/../class/MetadataUtility.php');
10
11/**
12 * Class syntax_plugin_combo_metadata
13 * Add the metadata box
14 */
15class syntax_plugin_combo_metadata extends DokuWiki_Syntax_Plugin
16{
17
18    /**
19     * Syntax Type.
20     *
21     * Needs to return one of the mode types defined in $PARSER_MODES in parser.php
22     * @see DokuWiki_Syntax_Plugin::getType()
23     */
24    function getType()
25    {
26        return 'substition';
27    }
28
29    /**
30     * How Dokuwiki will add P element
31     *
32     * * 'normal' - The plugin can be used inside paragraphs
33     *  * 'block'  - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs
34     *  * 'stack'  - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs
35     *
36     * @see DokuWiki_Syntax_Plugin::getPType()
37     */
38    function getPType()
39    {
40        return 'block';
41    }
42
43    /**
44     * @return array
45     * Allow which kind of plugin inside
46     *
47     * No one of array('baseonly','container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs')
48     * because we manage self the content and we call self the parser
49     *
50     * Return an array of one or more of the mode types {@link $PARSER_MODES} in Parser.php
51     */
52    function getAllowedTypes()
53    {
54        return array();
55    }
56
57    function getSort()
58    {
59        return 201;
60    }
61
62
63    function connectTo($mode)
64    {
65
66
67        $pattern = PluginUtility::getEmptyTagPattern(MetadataUtility::TAG);
68        $this->Lexer->addSpecialPattern($pattern, $mode, PluginUtility::getModeFromTag($this->getPluginComponent()));
69
70
71    }
72
73    /**
74     *
75     * The handle function goal is to parse the matched syntax through the pattern function
76     * and to return the result for use in the renderer
77     * This result is always cached until the page is modified.
78     * @param string $match
79     * @param int $state
80     * @param int $pos
81     * @param Doku_Handler $handler
82     * @return array|bool
83     * @see DokuWiki_Syntax_Plugin::handle()
84     *
85     */
86    function handle($match, $state, $pos, Doku_Handler $handler)
87    {
88        /**
89         * There is only one state call ie DOKU_LEXER_SPECIAL
90         * because of the connect to
91         */
92
93        return PluginUtility::getTagAttributes($match);
94
95    }
96
97    /**
98     * Render the output
99     * @param string $format
100     * @param Doku_Renderer $renderer
101     * @param array $data - what the function handle() return'ed
102     * @return boolean - rendered correctly? (however, returned value is not used at the moment)
103     * @see DokuWiki_Syntax_Plugin::render()
104     *
105     *
106     */
107    function render($format, Doku_Renderer $renderer, $data)
108    {
109        if ($format == 'xhtml') {
110
111            /** @var Doku_Renderer_xhtml $renderer */
112
113            $renderer->doc .= MetadataUtility::getHtmlMetadataBox($this, $data);
114            return true;
115
116        }
117
118        // unsupported $mode
119        return false;
120    }
121
122
123}
124
125