1<?php 2/** 3 * DokuWiki Plugin Simplebox (Syntax Component) 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Marc Bulling 7 */ 8 9if (!defined('DOKU_INC')) die(); 10 11class syntax_plugin_simplebox extends DokuWiki_Syntax_Plugin { 12 13 public function getType() { 14 return 'container'; 15 } 16 17 public function getPType() { 18 return 'block'; 19 } 20 21 public function getAllowedTypes() { 22 return array('container', 'formatting', 'substition'); 23 } 24 25 public function getSort() { 26 return 198; 27 } 28 29 public function connectTo($mode) { 30 $this->Lexer->addSpecialPattern('{{simplebox>.*?}}', $mode, 'plugin_simplebox'); 31 $this->Lexer->addSpecialPattern('{{simplebox-linebreak}}', $mode, 'plugin_simplebox'); 32 } 33 34 public function handle($match, $state, $pos, Doku_Handler $handler) { 35 if ($match === '{{simplebox-linebreak}}') { 36 return 'linebreak'; 37 } else { 38 preg_match('/{{simplebox>(.*?)\|size=(\d+)\|content=(.*?)}}/', $match, $matches); 39 return array( 40 'color' => $matches[1], 41 'size' => (int) $matches[2], 42 'content' => $matches[3] 43 ); 44 } 45 } 46 47 public function render($mode, Doku_Renderer $renderer, $data) { 48 if ($mode !== 'xhtml') return false; 49 50 if ($data === 'linebreak') { 51 $renderer->doc .= '<br style="clear:both;" />'; 52 } else { 53 $color = $data['color']; 54 $size = $data['size']; 55 $content = $data['content']; 56 57 $renderer->doc .= '<div class="simplebox" style="background-color: '.$color.'; width: '.$size.'px; height: '.$size.'px; border-radius: 10px; display: inline-flex; justify-content: center; align-items: center; float: left; margin: 5px;"><b>'.$content."</b></div>\n"; 58 } 59 60 return true; 61 } 62} 63