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 /** 67 * @see Doku_Parser_Mode::getSort() 68 * 69 * the mode with the lowest sort number will win out 70 * the container (parent) must then have a lower number than the child 71 */ 72 function getSort() 73 { 74 return 100; 75 } 76 77 /** 78 * Create a pattern that will called this plugin 79 * 80 * @param string $mode 81 * @see Doku_Parser_Mode::connectTo() 82 */ 83 function connectTo($mode) 84 { 85 86 if ($mode = PluginUtility::getModeForComponent(syntax_plugin_combo_tabs::TAG)) { 87 $pattern = PluginUtility::getContainerTagPattern(self::TAG); 88 $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeForComponent($this->getPluginComponent())); 89 } 90 91 } 92 93 public function postConnect() 94 { 95 96 $this->Lexer->addExitPattern('</' . self::TAG . '>', PluginUtility::getModeForComponent($this->getPluginComponent())); 97 98 } 99 100 /** 101 * 102 * The handle function goal is to parse the matched syntax through the pattern function 103 * and to return the result for use in the renderer 104 * This result is always cached until the page is modified. 105 * @param string $match 106 * @param int $state 107 * @param int $pos 108 * @param Doku_Handler $handler 109 * @return array|bool 110 * @see DokuWiki_Syntax_Plugin::handle() 111 * 112 */ 113 function handle($match, $state, $pos, Doku_Handler $handler) 114 { 115 116 switch ($state) { 117 118 case DOKU_LEXER_ENTER: 119 120 $tagAttributes = PluginUtility::getTagAttributes($match); 121 122 return array( 123 PluginUtility::STATE => $state, 124 PluginUtility::ATTRIBUTES => $tagAttributes 125 ); 126 127 case DOKU_LEXER_UNMATCHED: 128 129 return PluginUtility::handleAndReturnUnmatchedData(self::TAG,$match, $handler); 130 131 132 133 134 case DOKU_LEXER_EXIT : 135 136 return array( 137 PluginUtility::STATE => $state 138 ); 139 140 141 } 142 143 return array(); 144 145 } 146 147 /** 148 * Render the output 149 * @param string $format 150 * @param Doku_Renderer $renderer 151 * @param array $data - what the function handle() return'ed 152 * @return boolean - rendered correctly? (however, returned value is not used at the moment) 153 * @see DokuWiki_Syntax_Plugin::render() 154 * 155 * 156 */ 157 function render($format, Doku_Renderer $renderer, $data) 158 { 159 160 if ($format == 'xhtml') { 161 162 /** @var Doku_Renderer_xhtml $renderer */ 163 $state = $data[PluginUtility::STATE]; 164 switch ($state) { 165 166 case DOKU_LEXER_ENTER : 167 $attributes = $data[PluginUtility::ATTRIBUTES]; 168 $renderer->doc .= syntax_plugin_combo_tabs::openNavigationalTabElement($attributes); 169 break; 170 case DOKU_LEXER_UNMATCHED: 171 $renderer->doc .= PluginUtility::renderUnmatched($data); 172 break; 173 case DOKU_LEXER_EXIT : 174 $renderer->doc .= syntax_plugin_combo_tabs::closeNavigationalTabElement(); 175 break; 176 } 177 return true; 178 } 179 return false; 180 } 181 182 183} 184