1<?php 2 3 4use ComboStrap\MetadataUtility; 5use ComboStrap\PluginUtility; 6 7if (!defined('DOKU_INC')) die(); 8 9require_once (__DIR__.'/../class/MetadataUtility.php'); 10 11/** 12 * Class syntax_plugin_combo_metadata 13 */ 14class syntax_plugin_combo_metadata extends DokuWiki_Syntax_Plugin 15{ 16 17 /** 18 * Syntax Type. 19 * 20 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 21 * @see DokuWiki_Syntax_Plugin::getType() 22 */ 23 function getType() 24 { 25 return 'substition'; 26 } 27 28 /** 29 * How Dokuwiki will add P element 30 * 31 * * 'normal' - The plugin can be used inside paragraphs 32 * * 'block' - Open paragraphs need to be closed before plugin output - block should not be inside paragraphs 33 * * 'stack' - Special case. Plugin wraps other paragraphs. - Stacks can contain paragraphs 34 * 35 * @see DokuWiki_Syntax_Plugin::getPType() 36 */ 37 function getPType() 38 { 39 return 'block'; 40 } 41 42 /** 43 * @return array 44 * Allow which kind of plugin inside 45 * 46 * No one of array('baseonly','container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs') 47 * because we manage self the content and we call self the parser 48 * 49 * Return an array of one or more of the mode types {@link $PARSER_MODES} in Parser.php 50 */ 51 function getAllowedTypes() 52 { 53 return array(); 54 } 55 56 function getSort() 57 { 58 return 201; 59 } 60 61 62 function connectTo($mode) 63 { 64 65 66 $pattern = PluginUtility::getEmptyTagPattern(MetadataUtility::TAG); 67 $this->Lexer->addSpecialPattern($pattern, $mode, PluginUtility::getModeForComponent($this->getPluginComponent())); 68 69 70 } 71 72 /** 73 * 74 * The handle function goal is to parse the matched syntax through the pattern function 75 * and to return the result for use in the renderer 76 * This result is always cached until the page is modified. 77 * @param string $match 78 * @param int $state 79 * @param int $pos 80 * @param Doku_Handler $handler 81 * @return array|bool 82 * @see DokuWiki_Syntax_Plugin::handle() 83 * 84 */ 85 function handle($match, $state, $pos, Doku_Handler $handler) 86 { 87 /** 88 * There is only one state call ie DOKU_LEXER_SPECIAL 89 * because of the connect to 90 */ 91 92 $attributes = PluginUtility::getTagAttributes($match); 93 return $attributes; 94 95 } 96 97 /** 98 * Render the output 99 * @param string $format 100 * @param Doku_Renderer $renderer 101 * @param array $data - what the function handle() return'ed 102 * @return boolean - rendered correctly? (however, returned value is not used at the moment) 103 * @see DokuWiki_Syntax_Plugin::render() 104 * 105 * 106 */ 107 function render($format, Doku_Renderer $renderer, $data) 108 { 109 if ($format == 'xhtml') { 110 111 /** @var Doku_Renderer_xhtml $renderer */ 112 113 $renderer->doc .= MetadataUtility::getHtmlMetadataBox($this, $data); 114 return true; 115 116 } 117 118 // unsupported $mode 119 return false; 120 } 121 122 123} 124 125