xref: /plugin/combo/syntax/footer.php (revision 32b85071e019dd3646a67c17fac4051338e495eb)
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                $tagAttributes = PluginUtility::getTagAttributes($match);
122                return array(
123                    PluginUtility::STATE => $state,
124                    PluginUtility::ATTRIBUTES => $tagAttributes
125                );
126
127            case DOKU_LEXER_UNMATCHED:
128                return PluginUtility::handleAndReturnUnmatchedData(self::TAG, $match, $handler);
129
130            case DOKU_LEXER_EXIT :
131
132                return array(
133                    PluginUtility::STATE => $state
134                );
135
136
137        }
138
139        return array();
140
141    }
142
143    /**
144     * Render the output
145     * @param string $format
146     * @param Doku_Renderer $renderer
147     * @param array $data - what the function handle() return'ed
148     * @return boolean - rendered correctly? (however, returned value is not used at the moment)
149     * @see DokuWiki_Syntax_Plugin::render()
150     *
151     *
152     */
153    function render($format, Doku_Renderer $renderer, $data)
154    {
155
156        if ($format == 'xhtml') {
157
158            /** @var Doku_Renderer_xhtml $renderer */
159            $state = $data[PluginUtility::STATE];
160            switch ($state) {
161
162                case DOKU_LEXER_ENTER :
163                    $attributes = $data[PluginUtility::ATTRIBUTES];
164                    if (array_key_exists("class", $attributes)) {
165                        $attributes["class"] .= " " . self::TAG;
166                    } else {
167                        $attributes["class"] .= self::TAG;
168                    }
169                    $inlineAttributes = PluginUtility::array2HTMLAttributes($attributes);
170                    $renderer->doc .= "<footer $inlineAttributes>" . DOKU_LF;
171                    break;
172
173                case DOKU_LEXER_UNMATCHED :
174
175                    $renderer->doc .= PluginUtility::renderUnmatched($data);
176                    break;
177
178                case DOKU_LEXER_EXIT :
179
180                    $renderer->doc .= '</footer>' . DOKU_LF;
181                    break;
182            }
183            return true;
184        }
185        return false;
186    }
187
188
189}
190