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