1<?php 2 3 4use ComboStrap\PluginUtility; 5use ComboStrap\TagAttributes; 6use ComboStrap\XmlTagProcessing; 7 8require_once(__DIR__ . '/../vendor/autoload.php'); 9 10/** 11 * 12 * backgrounds is an element that holds more than one background 13 * We can set then parallax effect for instance 14 * 15 */ 16class syntax_plugin_combo_backgrounds extends DokuWiki_Syntax_Plugin 17{ 18 19 const TAG = "backgrounds"; 20 21 22 /** 23 * Syntax Type. 24 * 25 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 26 * @see DokuWiki_Syntax_Plugin::getType() 27 */ 28 function getType() 29 { 30 return 'container'; 31 } 32 33 /** 34 * How Dokuwiki will add P element 35 * 36 * * 'normal' - Inline 37 * * 'block' - Block (p are not created inside) 38 * * 'stack' - Block (p can be created inside) 39 * 40 * @see DokuWiki_Syntax_Plugin::getPType() 41 */ 42 function getPType() 43 { 44 /** 45 * normal (and not block) is important to not create p_open calls 46 */ 47 return 'normal'; 48 } 49 50 /** 51 * @return array 52 * Allow which kind of plugin inside 53 * 54 * Array('baseonly','container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs') 55 * 56 * Return an array of one or more of the mode types {@link $PARSER_MODES} in Parser.php 57 */ 58 function getAllowedTypes() 59 { 60 return array('baseonly', 'container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 61 } 62 63 public function accepts($mode) 64 { 65 66 return syntax_plugin_combo_preformatted::disablePreformatted($mode); 67 68 } 69 70 function getSort() 71 { 72 return 201; 73 } 74 75 76 function connectTo($mode) 77 { 78 79 $pattern = XmlTagProcessing::getContainerTagPattern(self::TAG); 80 $this->Lexer->addEntryPattern($pattern, $mode, PluginUtility::getModeFromTag($this->getPluginComponent())); 81 82 } 83 84 85 function postConnect() 86 { 87 88 $this->Lexer->addExitPattern('</' . self::TAG . '>', PluginUtility::getModeFromTag($this->getPluginComponent())); 89 90 91 } 92 93 function handle($match, $state, $pos, Doku_Handler $handler) 94 { 95 96 switch ($state) { 97 98 case DOKU_LEXER_ENTER : 99 $tagAttributes = TagAttributes::createFromTagMatch($match); 100 return array( 101 PluginUtility::STATE => $state, 102 PluginUtility::ATTRIBUTES => $tagAttributes->toCallStackArray() 103 ); 104 105 case DOKU_LEXER_UNMATCHED : 106 /** 107 * We should not have anything here 108 * but in any case, we send the data for feedback 109 */ 110 return PluginUtility::handleAndReturnUnmatchedData(self::TAG, $match, $handler); 111 112 case DOKU_LEXER_EXIT : 113 114 /** 115 * Return state to keep the call stack structure 116 * and print the closing tag 117 */ 118 return array( 119 PluginUtility::STATE => $state 120 ); 121 122 123 } 124 return array(); 125 126 } 127 128 /** 129 * Render the output 130 * @param string $format 131 * @param Doku_Renderer $renderer 132 * @param array $data - what the function handle() return'ed 133 * @return boolean - rendered correctly? (however, returned value is not used at the moment) 134 * @see DokuWiki_Syntax_Plugin::render() 135 * 136 * 137 */ 138 function render($format, Doku_Renderer $renderer, $data) 139 { 140 if ($format == 'xhtml') { 141 142 /** @var Doku_Renderer_xhtml $renderer */ 143 $state = $data[PluginUtility::STATE]; 144 switch ($state) { 145 146 case DOKU_LEXER_ENTER: 147 $tagAttributes = TagAttributes::createFromCallStackArray($data[PluginUtility::ATTRIBUTES]); 148 $tagAttributes->addClassName(self::TAG); 149 $renderer->doc .= $tagAttributes->toHtmlEnterTag("div"); 150 break; 151 case DOKU_LEXER_EXIT: 152 $renderer->doc .= "</div>"; 153 break; 154 case DOKU_LEXER_UNMATCHED: 155 /** 156 * In case anyone put text where it should not 157 */ 158 $renderer->doc .= PluginUtility::renderUnmatched($data); 159 break; 160 161 } 162 return true; 163 } 164 165 // unsupported $mode 166 return false; 167 } 168 169 170} 171 172