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