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