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