1<?php 2 3 4// must be run within Dokuwiki 5use ComboStrap\PluginUtility; 6use ComboStrap\TagAttributes; 7 8if (!defined('DOKU_INC')) die(); 9 10 11class syntax_plugin_combo_brand extends DokuWiki_Syntax_Plugin 12{ 13 14 const TAG = "brand"; 15 16 /** 17 * Syntax Type. 18 * 19 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 20 * @see DokuWiki_Syntax_Plugin::getType() 21 */ 22 function getType() 23 { 24 return 'formatting'; 25 } 26 27 /** 28 * How Dokuwiki will add P element 29 * 30 * * 'normal' - The plugin can be used inside paragraphs 31 * * 'block' - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs 32 * * 'stack' - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs 33 * 34 * @see DokuWiki_Syntax_Plugin::getPType() 35 */ 36 function getPType() 37 { 38 return 'normal'; 39 } 40 41 /** 42 * @return array 43 * Allow which kind of plugin inside 44 * 45 * array('container', 'baseonly', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs') 46 * 47 */ 48 function getAllowedTypes() 49 { 50 return array('container', 'baseonly', 'formatting', 'substition', 'protected', 'disabled'); 51 } 52 53 function getSort() 54 { 55 return 201; 56 } 57 58 public function accepts($mode) 59 { 60 return syntax_plugin_combo_preformatted::disablePreformatted($mode); 61 } 62 63 64 /** 65 * Create a pattern that will called this plugin 66 * 67 * @param string $mode 68 * @see Doku_Parser_Mode::connectTo() 69 */ 70 function connectTo($mode) 71 { 72 73 $pattern = PluginUtility::getContainerTagPattern(self::getTag()); 74 $this->Lexer->addEntryPattern($pattern, $mode, 'plugin_' . PluginUtility::PLUGIN_BASE_NAME . '_' . $this->getPluginComponent()); 75 76 } 77 78 function postConnect() 79 { 80 81 $this->Lexer->addExitPattern('</' . self::getTag() . '>', 'plugin_' . PluginUtility::PLUGIN_BASE_NAME . '_' . $this->getPluginComponent()); 82 83 } 84 85 function handle($match, $state, $pos, Doku_Handler $handler) 86 { 87 88 switch ($state) { 89 90 case DOKU_LEXER_ENTER : 91 $defaultParameters = []; 92 global $conf; 93 $title = $conf['title']; 94 if (!empty($title)) { 95 $defaultParameters["title"] = $title; 96 } 97 $parameters = PluginUtility::getTagAttributes($match); 98 $parameters = PluginUtility::mergeAttributes($parameters, $defaultParameters); 99 return array( 100 PluginUtility::STATE => $state, 101 PluginUtility::ATTRIBUTES => $parameters 102 ); 103 104 case DOKU_LEXER_UNMATCHED : 105 return PluginUtility::handleAndReturnUnmatchedData(self::TAG, $match, $handler); 106 107 case DOKU_LEXER_EXIT : 108 109 // Important otherwise we don't get an exit in the render 110 return array( 111 PluginUtility::STATE => $state 112 ); 113 114 115 } 116 return array(); 117 118 } 119 120 /** 121 * Render the output 122 * @param string $format 123 * @param Doku_Renderer $renderer 124 * @param array $data - what the function handle() return'ed 125 * @return boolean - rendered correctly? (however, returned value is not used at the moment) 126 * @see DokuWiki_Syntax_Plugin::render() 127 * 128 * 129 */ 130 function render($format, Doku_Renderer $renderer, $data) 131 { 132 133 if ($format == 'xhtml') { 134 135 /** @var Doku_Renderer_xhtml $renderer */ 136 $state = $data[PluginUtility::STATE]; 137 switch ($state) { 138 case DOKU_LEXER_ENTER : 139 $parameters = $data[PluginUtility::ATTRIBUTES]; 140 $tagAttributes = TagAttributes::createFromCallStackArray($parameters); 141 $tagAttributes->addHtmlAttributeValue("href", wl()); 142 $tagAttributes->addHtmlAttributeValue("accesskey", "h"); 143 $tagAttributes->addClassName("navbar-brand"); 144 145 $renderer->doc .= $tagAttributes->toHtmlEnterTag("a"); 146 break; 147 148 case DOKU_LEXER_UNMATCHED : 149 // What about: 150 // * the title of the website ? $conf['title'] 151 // * the logo ? $logo = tpl_getMediaFile(array(':wiki:logo.png', ':logo.png', 'images/logo.png'), false, $logoSize); 152 $renderer->doc .= PluginUtility::renderUnmatched($data); 153 break; 154 155 case DOKU_LEXER_EXIT : 156 $renderer->doc .= '</a>'; 157 break; 158 } 159 return true; 160 } 161 162 // unsupported $mode 163 return false; 164 } 165 166 public static function getTag() 167 { 168 list(/* $t */, /* $p */, /* $n */, $c) = explode('_', get_called_class(), 4); 169 return (isset($c) ? $c : ''); 170 } 171 172} 173 174