1<?php 2/** 3 * DokuWiki Syntax Plugin Combostrap. 4 * 5 */ 6 7use ComboStrap\LogUtility; 8use ComboStrap\PluginUtility; 9 10if (!defined('DOKU_INC')) { 11 die(); 12} 13 14require_once(__DIR__ . '/../class/PluginUtility.php'); 15 16/** 17 * 18 * The name of the class must follow a pattern (don't change it) 19 * ie: 20 * syntax_plugin_PluginName_ComponentName 21 * 22 * @deprecated used {@link syntax_plugin_combo_panel} instead (since version 1.12) 23 */ 24class syntax_plugin_combo_tab extends DokuWiki_Syntax_Plugin 25{ 26 27 const TAG = 'tab'; 28 29 30 /** 31 * Syntax Type. 32 * 33 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 34 * @see DokuWiki_Syntax_Plugin::getType() 35 */ 36 function getType() 37 { 38 return 'container'; 39 } 40 41 /** 42 * @return array 43 * Allow which kind of plugin inside 44 * All 45 */ 46 public function getAllowedTypes() 47 { 48 return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 49 } 50 51 /** 52 * How Dokuwiki will add P element 53 * 54 * * 'normal' - The plugin can be used inside paragraphs 55 * * 'block' - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs 56 * * 'stack' - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs 57 * 58 * @see DokuWiki_Syntax_Plugin::getPType() 59 */ 60 function getPType() 61 { 62 return 'block'; 63 } 64 65 /** 66 * @see Doku_Parser_Mode::getSort() 67 * 68 * the mode with the lowest sort number will win out 69 * the container (parent) must then have a lower number than the child 70 */ 71 function getSort() 72 { 73 return 100; 74 } 75 76 /** 77 * Create a pattern that will called this plugin 78 * 79 * @param string $mode 80 * @see Doku_Parser_Mode::connectTo() 81 */ 82 function connectTo($mode) 83 { 84 85 if ($mode = PluginUtility::getModeForComponent(syntax_plugin_combo_tabs::TAG)) { 86 $pattern = PluginUtility::getContainerTagPattern(self::TAG); 87 $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeForComponent($this->getPluginComponent())); 88 } 89 90 } 91 92 public function postConnect() 93 { 94 95 $this->Lexer->addExitPattern('</' . self::TAG . '>', PluginUtility::getModeForComponent($this->getPluginComponent())); 96 97 } 98 99 /** 100 * 101 * The handle function goal is to parse the matched syntax through the pattern function 102 * and to return the result for use in the renderer 103 * This result is always cached until the page is modified. 104 * @param string $match 105 * @param int $state 106 * @param int $pos 107 * @param Doku_Handler $handler 108 * @return array|bool 109 * @see DokuWiki_Syntax_Plugin::handle() 110 * 111 */ 112 function handle($match, $state, $pos, Doku_Handler $handler) 113 { 114 115 switch ($state) { 116 117 case DOKU_LEXER_ENTER: 118 119 $tagAttributes = PluginUtility::getTagAttributes($match); 120 121 return array( 122 PluginUtility::STATE => $state, 123 PluginUtility::ATTRIBUTES => $tagAttributes 124 ); 125 126 case DOKU_LEXER_UNMATCHED: 127 128 return array( 129 PluginUtility::STATE => $state, 130 PluginUtility::PAYLOAD => $match 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::escape($data[PluginUtility::PAYLOAD]) . DOKU_LF; 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