1<?php 2/** 3 * DokuWiki Plugin floatdiv (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Tinkerghost <geek@rentedgeek.com> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11 12if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 15 16require_once DOKU_PLUGIN.'syntax.php'; 17 18class syntax_plugin_floatdiv_float extends DokuWiki_Syntax_Plugin { 19 public function getType() { 20 return 'container'; 21 } 22 23 public function getPType() { 24 return 'stack'; 25 } 26 27 public function getSort() { 28 return 500; 29 } 30 31 public function getAllowedTypes() { 32// return array('formatting','substitution','protected','disabled','paragraphs'); 33 return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); 34 } 35 36 public function connectTo($mode) { 37// $this->Lexer->addSpecialPattern('\[float*\]',$mode,'plugin_floatdiv_float'); 38 $this->Lexer->addEntryPattern('\[float.*?\]',$mode,'plugin_floatdiv_float'); 39 } 40 41 public function postConnect() { 42 $this->Lexer->addExitPattern('\[/float\]','plugin_floatdiv_float'); 43 } 44 45 46 public function handle($match, $state, $pos, &$handler){ 47 $data = array(); 48 switch ($state){ 49 case DOKU_LEXER_ENTER : 50 $matches = preg_split('/\]/u',$match,2); 51 if (trim($matches[0]) == ''){ 52 $matches[0]=NULL; 53 } 54 else{ 55 $matches[0] = trim($matches[0]); 56 } 57 //** Parsing Parameters ** 58 preg_match('/(right|left)/i', $matches[0],$side); 59 preg_match('/width=([0-9]+)/i', $matches[0],$width); 60 preg_match('/size=([0-9]+)/i', $matches[0], $size); 61 preg_match('/background=#([0-9a-fA-F]{6})/i', $matches[0], $background); 62 return array ($state,$side[1],$width[1],$size[1],$background[1]); 63 case DOKU_LEXER_UNMATCHED : return array($state, $match); 64 case DOKU_LEXER_EXIT : return array($state, ''); 65 } 66 return array(); 67 68 } 69 70 public function render($mode, &$renderer, $data) { 71 if($mode != 'xhtml') return false; 72 list($state,$match) = $data; 73 74 switch($state) { 75 case DOKU_LEXER_ENTER : 76 list($state, $side,$width,$size,$background) = $data; 77 $style = ''; 78 if ($side){$style .= "float: $side;";} 79 if ($width){ 80 if ($width < 50){$style .= "width: 50px;";} 81 elseif ($width > 500){$style .= "width: 500px;";} 82 else{$style .= "width: ".$width."px;";} 83 } 84 if ($size){ 85 if ($size<8){$style .= "font-size: 8px;";} 86 elseif ($size >20){$style .= "font-size: 20px;";} 87 else {$style .= "font-size: ".$size."px;";} 88 } 89 if ($background) {$style .= "background-color:#$background;";} 90 $renderer->doc .="<div class='floatpane' style='$style'>"; 91 break; 92 case DOKU_LEXER_UNMATCHED : 93 $renderer->doc .= $renderer->_xmlEntities($match); break; 94 case DOKU_LEXER_EXIT : $renderer->doc .= "</div>"; break; 95 } 96 97 return true; 98 } 99} 100 101// vim:ts=4:sw=4:et: 102