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; 14use ComboStrap\TagAttributes; 15 16if (!defined('DOKU_INC')) { 17 die(); 18} 19 20require_once(__DIR__ . '/../class/PluginUtility.php'); 21 22/** 23 * Implementation of the footer 24 * 25 * @see https:/combostrap.com/footer 26 * 27 * 28 * The name of the class must follow a pattern (don't change it) 29 * ie: 30 * syntax_plugin_PluginName_ComponentName 31 * 32 * This is the HTML footer element 33 * It's is also added automatically to wrap a {@link syntax_plugin_combo_cite} 34 * in a blockquote 35 */ 36class syntax_plugin_combo_footer extends DokuWiki_Syntax_Plugin 37{ 38 const TAG = "footer"; 39 40 41 /** 42 * Syntax Type. 43 * 44 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 45 * @see DokuWiki_Syntax_Plugin::getType() 46 */ 47 function getType() 48 { 49 return 'container'; 50 } 51 52 /** 53 * @return array 54 * Allow which kind of plugin inside 55 * All 56 */ 57 public function getAllowedTypes() 58 { 59 return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 60 } 61 62 /** 63 * How Dokuwiki will add P element 64 * 65 * * 'normal' - The plugin can be used inside paragraphs 66 * * 'block' - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs 67 * * 'stack' - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs 68 * 69 * @see DokuWiki_Syntax_Plugin::getPType() 70 */ 71 function getPType() 72 { 73 return 'stack'; 74 } 75 76 /** 77 * @see Doku_Parser_Mode::getSort() 78 * 79 * the mode with the lowest sort number will win out 80 * the container (parent) must then have a lower number than the child 81 */ 82 function getSort() 83 { 84 return 100; 85 } 86 87 /** 88 * Create a pattern that will called this plugin 89 * 90 * @param string $mode 91 * @see Doku_Parser_Mode::connectTo() 92 */ 93 function connectTo($mode) 94 { 95 96 $pattern = PluginUtility::getContainerTagPattern(self::TAG); 97 $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeForComponent($this->getPluginComponent())); 98 99 } 100 101 public function postConnect() 102 { 103 104 $this->Lexer->addExitPattern('</' . self::TAG . '>', PluginUtility::getModeForComponent($this->getPluginComponent())); 105 106 } 107 108 /** 109 * 110 * The handle function goal is to parse the matched syntax through the pattern function 111 * and to return the result for use in the renderer 112 * This result is always cached until the page is modified. 113 * @param string $match 114 * @param int $state 115 * @param int $pos 116 * @param Doku_Handler $handler 117 * @return array|bool 118 * @see DokuWiki_Syntax_Plugin::handle() 119 * 120 */ 121 function handle($match, $state, $pos, Doku_Handler $handler) 122 { 123 124 switch ($state) { 125 126 case DOKU_LEXER_ENTER: 127 128 $tagAttributes = PluginUtility::getTagAttributes($match); 129 return array( 130 PluginUtility::STATE => $state, 131 PluginUtility::ATTRIBUTES => $tagAttributes 132 ); 133 134 case DOKU_LEXER_UNMATCHED: 135 return PluginUtility::handleAndReturnUnmatchedData(self::TAG, $match, $handler); 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 switch ($state) { 168 169 case DOKU_LEXER_ENTER : 170 $attributes = $data[PluginUtility::ATTRIBUTES]; 171 $tagAttributes = TagAttributes::createFromCallStackArray($attributes, self::TAG); 172 $renderer->doc .= $tagAttributes->toHtmlEnterTag("footer"); 173 break; 174 175 case DOKU_LEXER_UNMATCHED : 176 177 $renderer->doc .= PluginUtility::renderUnmatched($data); 178 break; 179 180 case DOKU_LEXER_EXIT : 181 182 $renderer->doc .= '</footer>' . DOKU_LF; 183 break; 184 } 185 return true; 186 } 187 return false; 188 } 189 190 191} 192