xref: /plugin/combo/syntax/tabpanels.php (revision 5f891b7e09648e05e78f5882f3fdde1e9df9b0f1)
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
126                    array(
127                        PluginUtility::STATE => $state,
128                        PluginUtility::PAYLOAD => PluginUtility::escape($match)
129                    );
130
131
132            case DOKU_LEXER_EXIT :
133
134                return array(
135                    PluginUtility::STATE => $state
136                );
137
138
139        }
140
141        return array();
142
143    }
144
145    /**
146     * Render the output
147     * @param string $format
148     * @param Doku_Renderer $renderer
149     * @param array $data - what the function handle() return'ed
150     * @return boolean - rendered correctly? (however, returned value is not used at the moment)
151     * @see DokuWiki_Syntax_Plugin::render()
152     *
153     *
154     */
155    function render($format, Doku_Renderer $renderer, $data)
156    {
157
158        if ($format == 'xhtml') {
159
160            /** @var Doku_Renderer_xhtml $renderer */
161            $state = $data[PluginUtility::STATE];
162            $attributes = array();
163            switch ($state) {
164
165                case DOKU_LEXER_ENTER :
166                    $renderer->doc .= syntax_plugin_combo_tabs::openTabPanelsElement($attributes);
167                    break;
168                case DOKU_LEXER_EXIT :
169                    $renderer->doc .= syntax_plugin_combo_tabs::closeTabPanelsElement($attributes);
170                    break;
171                case DOKU_LEXER_UNMATCHED:
172                    $renderer->doc .= $data[PluginUtility::PAYLOAD];
173                    break;
174            }
175            return true;
176        }
177        return false;
178    }
179
180
181}
182