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