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