xref: /plugin/combo/syntax/tabpanels.php (revision 32b85071e019dd3646a67c17fac4051338e495eb)
1<?php
2/**
3 * DokuWiki Syntax Plugin Combostrap.
4 *
5 */
6
7use ComboStrap\PluginUtility;
8
9if (!defined('DOKU_INC')) {
10    die();
11}
12
13require_once(__DIR__ . '/../class/PluginUtility.php');
14
15/**
16 *
17 * The name of the class must follow a pattern (don't change it)
18 * ie:
19 *    syntax_plugin_PluginName_ComponentName
20 * @deprecated for {@link syntax_plugin_combo_tabs} in version 1.12
21 */
22class syntax_plugin_combo_tabpanels extends DokuWiki_Syntax_Plugin
23{
24
25    const TAG = 'tabpanels';
26
27
28    /**
29     * Syntax Type.
30     *
31     * Needs to return one of the mode types defined in $PARSER_MODES in parser.php
32     * @see DokuWiki_Syntax_Plugin::getType()
33     */
34    function getType()
35    {
36        return 'container';
37    }
38
39    /**
40     * @return array
41     * Allow which kind of plugin inside
42     * All
43     */
44    public function getAllowedTypes()
45    {
46        return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs');
47    }
48
49    /**
50     * How Dokuwiki will add P element
51     *
52     *  * 'normal' - The plugin can be used inside paragraphs
53     *  * 'block'  - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs
54     *  * 'stack'  - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs
55     *
56     * @see DokuWiki_Syntax_Plugin::getPType()
57     */
58    function getPType()
59    {
60        return 'stack';
61    }
62
63    /**
64     * @see Doku_Parser_Mode::getSort()
65     *
66     * the mode with the lowest sort number will win out
67     * the container (parent) must then have a lower number than the child
68     */
69    function getSort()
70    {
71        return 100;
72    }
73
74    /**
75     * Create a pattern that will called this plugin
76     *
77     * @param string $mode
78     * @see Doku_Parser_Mode::connectTo()
79     */
80    function connectTo($mode)
81    {
82
83        $pattern = PluginUtility::getContainerTagPattern(self::TAG);
84        $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeForComponent($this->getPluginComponent()));
85
86    }
87
88    public function postConnect()
89    {
90
91        $this->Lexer->addExitPattern('</' . self::TAG . '>', PluginUtility::getModeForComponent($this->getPluginComponent()));
92
93    }
94
95    /**
96     *
97     * The handle function goal is to parse the matched syntax through the pattern function
98     * and to return the result for use in the renderer
99     * This result is always cached until the page is modified.
100     * @param string $match
101     * @param int $state
102     * @param int $pos
103     * @param Doku_Handler $handler
104     * @return array|bool
105     * @see DokuWiki_Syntax_Plugin::handle()
106     *
107     */
108    function handle($match, $state, $pos, Doku_Handler $handler)
109    {
110
111        switch ($state) {
112
113            case DOKU_LEXER_ENTER:
114
115                $tagAttributes = PluginUtility::getTagAttributes($match);
116
117                return array(
118                    PluginUtility::STATE => $state,
119                    PluginUtility::ATTRIBUTES => $tagAttributes
120                );
121
122            case DOKU_LEXER_UNMATCHED:
123
124                // We should never get there but yeah ...
125                return PluginUtility::handleAndReturnUnmatchedData(self::TAG,$match,$handler);
126
127
128            case DOKU_LEXER_EXIT :
129
130                return array(
131                    PluginUtility::STATE => $state
132                );
133
134
135        }
136
137        return array();
138
139    }
140
141    /**
142     * Render the output
143     * @param string $format
144     * @param Doku_Renderer $renderer
145     * @param array $data - what the function handle() return'ed
146     * @return boolean - rendered correctly? (however, returned value is not used at the moment)
147     * @see DokuWiki_Syntax_Plugin::render()
148     *
149     *
150     */
151    function render($format, Doku_Renderer $renderer, $data)
152    {
153
154        if ($format == 'xhtml') {
155
156            /** @var Doku_Renderer_xhtml $renderer */
157            $state = $data[PluginUtility::STATE];
158            $attributes = array();
159            switch ($state) {
160
161                case DOKU_LEXER_ENTER :
162                    $renderer->doc .= syntax_plugin_combo_tabs::openTabPanelsElement($attributes);
163                    break;
164                case DOKU_LEXER_EXIT :
165                    $renderer->doc .= syntax_plugin_combo_tabs::closeTabPanelsElement($attributes);
166                    break;
167                case DOKU_LEXER_UNMATCHED:
168                    $renderer->doc .= PluginUtility::renderUnmatched($data);
169                    break;
170            }
171            return true;
172        }
173        return false;
174    }
175
176
177}
178