1<?php 2/** 3 * DokuWiki Syntax Plugin Combostrap. 4 * 5 */ 6 7use ComboStrap\ButtonTag; 8use ComboStrap\DateTag; 9use ComboStrap\DropDownTag; 10use ComboStrap\IconTag; 11use ComboStrap\NoteTag; 12use ComboStrap\PermalinkTag; 13use ComboStrap\PipelineTag; 14use ComboStrap\PluginUtility; 15use ComboStrap\Tag\FollowTag; 16use ComboStrap\Tag\ShareTag; 17use ComboStrap\XmlTagProcessing; 18 19 20require_once(__DIR__ . '/../vendor/autoload.php'); 21 22 23/** 24 * All DokuWiki plugins to extend the parser/rendering mechanism 25 * need to inherit from this class 26 * 27 * The name of the class must follow a pattern (don't change it) 28 * ie: 29 * syntax_plugin_PluginName_ComponentName 30 * 31 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 32 * !!!!!!!!!!! The component name must be the name of the php file !!! 33 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 34 * 35 */ 36class syntax_plugin_combo_xmlinlinetag extends DokuWiki_Syntax_Plugin 37{ 38 39 /** 40 * @return array inline non-protected 41 */ 42 private static function getInlineTags(): array 43 { 44 $array = ButtonTag::getTags(); 45 $array[] = DropDownTag::TAG; 46 $array[] = NoteTag::TAG_INOTE; 47 $array[] = PermalinkTag::TAG; 48 $array[] = DateTag::TAG; 49 $array[] = IconTag::TAG; 50 $array[] = PipelineTag::TAG; 51 $array[] = FollowTag::MARKUP; 52 $array[] = ShareTag::MARKUP; 53 return $array; 54 } 55 56 57 /** 58 * Syntax Type. 59 * 60 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 61 * @see DokuWiki_Syntax_Plugin::getType() 62 */ 63 function getType(): string 64 { 65 return 'formatting'; 66 } 67 68 /** 69 * @return array 70 * Allow which kind of plugin inside 71 * 72 * No one of array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs') 73 * because we manage self the content and we call self the parser 74 */ 75 public function getAllowedTypes(): array 76 { 77 return array('container', 'formatting', 'substition', 'protected', 'disabled'); 78 } 79 80 public function accepts($mode): bool 81 { 82 83 return syntax_plugin_combo_preformatted::disablePreformatted($mode); 84 85 } 86 87 /** 88 * How Dokuwiki will add P element 89 * 90 * * 'normal' - The plugin can be used inside paragraphs 91 * * 'block' - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs 92 * * 'stack' - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs 93 * 94 * @see DokuWiki_Syntax_Plugin::getPType() 95 */ 96 function getPType(): string 97 { 98 return 'normal'; 99 } 100 101 /** 102 * @see Doku_Parser_Mode::getSort() 103 * the mode with the lowest sort number will win out 104 * the lowest in the tree must have the lowest sort number 105 * No idea why it must be low but inside a teaser, it will work 106 * https://www.dokuwiki.org/devel:parser#order_of_adding_modes_important 107 */ 108 function getSort(): int 109 { 110 return 10; 111 } 112 113 /** 114 * Create a pattern that will called this plugin 115 * 116 * @param string $mode 117 * @see Doku_Parser_Mode::connectTo() 118 */ 119 function connectTo($mode) 120 { 121 122 foreach (self::getInlineTags() as $tag) { 123 124 $pattern = XmlTagProcessing::getContainerTagPattern($tag); 125 $this->Lexer->addEntryPattern($pattern, $mode, 'plugin_' . PluginUtility::PLUGIN_BASE_NAME . '_' . $this->getPluginComponent()); 126 127 } 128 129 } 130 131 public function postConnect() 132 { 133 134 foreach (self::getInlineTags() as $tag) { 135 $this->Lexer->addExitPattern('</' . $tag . '>', 'plugin_' . PluginUtility::PLUGIN_BASE_NAME . '_' . $this->getPluginComponent()); 136 } 137 138 } 139 140 /** 141 * 142 * The handle function goal is to parse the matched syntax through the pattern function 143 * and to return the result for use in the renderer 144 * This result is always cached until the page is modified. 145 * @param string $match 146 * @param int $state 147 * @param int $pos 148 * @param Doku_Handler $handler 149 * @return array|bool 150 * @throws Exception 151 * @see DokuWiki_Syntax_Plugin::handle() 152 * 153 */ 154 function handle($match, $state, $pos, Doku_Handler $handler) 155 { 156 157 return XmlTagProcessing::handleStatic($match, $state, $pos, $handler, $this); 158 159 } 160 161 /** 162 * Render the output 163 * @param string $format 164 * @param Doku_Renderer $renderer 165 * @param array $data - what the function handle() return'ed 166 * @return boolean - rendered correctly? (however, returned value is not used at the moment) 167 * @see DokuWiki_Syntax_Plugin::render() 168 * 169 * 170 */ 171 function render($format, Doku_Renderer $renderer, $data): bool 172 { 173 174 return XmlTagProcessing::renderStatic($format, $renderer, $data, $this); 175 176 } 177 178 179} 180