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