xref: /plugin/combo/syntax/footer.php (revision 5f891b7e09648e05e78f5882f3fdde1e9df9b0f1)
1<?php
2/**
3 * Copyright (c) 2020. ComboStrap, Inc. and its affiliates. All Rights Reserved.
4 *
5 * This source code is licensed under the GPL license found in the
6 * COPYING  file in the root directory of this source tree.
7 *
8 * @license  GPL 3 (https://www.gnu.org/licenses/gpl-3.0.en.html)
9 * @author   ComboStrap <support@combostrap.com>
10 *
11 */
12
13use ComboStrap\PluginUtility;
14
15if (!defined('DOKU_INC')) {
16    die();
17}
18
19require_once(__DIR__ . '/../class/PluginUtility.php');
20
21/**
22 * Implementation of the {@link https:/combostrap.com/footer}
23 *
24 *
25 * The name of the class must follow a pattern (don't change it)
26 * ie:
27 *    syntax_plugin_PluginName_ComponentName
28 */
29class syntax_plugin_combo_footer extends DokuWiki_Syntax_Plugin
30{
31    const TAG = "footer";
32
33
34    /**
35     * Syntax Type.
36     *
37     * Needs to return one of the mode types defined in $PARSER_MODES in parser.php
38     * @see DokuWiki_Syntax_Plugin::getType()
39     */
40    function getType()
41    {
42        return 'container';
43    }
44
45    /**
46     * @return array
47     * Allow which kind of plugin inside
48     * All
49     */
50    public function getAllowedTypes()
51    {
52        return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs');
53    }
54
55    /**
56     * How Dokuwiki will add P element
57     *
58     * * 'normal' - The plugin can be used inside paragraphs
59     *  * 'block'  - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs
60     *  * 'stack'  - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs
61     *
62     * @see DokuWiki_Syntax_Plugin::getPType()
63     */
64    function getPType()
65    {
66        return 'block';
67    }
68
69    /**
70     * @see Doku_Parser_Mode::getSort()
71     *
72     * the mode with the lowest sort number will win out
73     * the container (parent) must then have a lower number than the child
74     */
75    function getSort()
76    {
77        return 100;
78    }
79
80    /**
81     * Create a pattern that will called this plugin
82     *
83     * @param string $mode
84     * @see Doku_Parser_Mode::connectTo()
85     */
86    function connectTo($mode)
87    {
88
89        $pattern = PluginUtility::getContainerTagPattern(self::TAG);
90        $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeForComponent($this->getPluginComponent()));
91
92    }
93
94    public function postConnect()
95    {
96
97        $this->Lexer->addExitPattern('</' . self::TAG . '>', PluginUtility::getModeForComponent($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                // Suppress the component name
122
123                $tagAttributes = PluginUtility::getTagAttributes($match);
124                return array($state, $tagAttributes);
125
126            case DOKU_LEXER_UNMATCHED:
127                return array($state, $match);
128
129            case DOKU_LEXER_EXIT :
130
131                return array($state, '');
132
133
134        }
135
136        return array();
137
138    }
139
140    /**
141     * Render the output
142     * @param string $format
143     * @param Doku_Renderer $renderer
144     * @param array $data - what the function handle() return'ed
145     * @return boolean - rendered correctly? (however, returned value is not used at the moment)
146     * @see DokuWiki_Syntax_Plugin::render()
147     *
148     *
149     */
150    function render($format, Doku_Renderer $renderer, $data)
151    {
152
153        if ($format == 'xhtml') {
154
155            /** @var Doku_Renderer_xhtml $renderer */
156            list($state, $payload) = $data;
157            switch ($state) {
158
159                case DOKU_LEXER_ENTER :
160                    $attributes = $payload;
161                    if (array_key_exists("class", $attributes)) {
162                        $attributes["class"] .= " " . self::TAG;
163                    } else {
164                        $attributes["class"] .= self::TAG;
165                    }
166                    $inlineAttributes = PluginUtility::array2HTMLAttributes($attributes);
167                    $renderer->doc .= "<footer $inlineAttributes>" . DOKU_LF;
168                    break;
169
170                case DOKU_LEXER_UNMATCHED :
171
172                    $renderer->doc .= PluginUtility::escape($payload);;
173                    break;
174
175                case DOKU_LEXER_EXIT :
176
177                    $renderer->doc .= '</footer>' . DOKU_LF;
178                    break;
179            }
180            return true;
181        }
182        return false;
183    }
184
185
186}
187