1<?php 2/** 3 * DokuWiki Plugin togglewrap (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Jonas Fourquier <jonas@mythtv-fr.org> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11 12class syntax_plugin_togglewrap extends DokuWiki_Syntax_Plugin { 13 14 public function getType() { 15 return 'substition'; 16 } 17 18 public function getPType() { 19 return 'normal'; 20 } 21 22 public function getSort() { 23 return 308; 24 } 25 26 public function connectTo($mode) { 27 $this->Lexer->addSpecialPattern('{{togglewrap>.*?}}',$mode,'plugin_togglewrap'); 28 } 29 30 public function handle($match, $state, $pos, Doku_Handler &$handler){ 31 $match = substr($match, 13, -2); 32 list ($opts,$label) = explode('|',$match, 2); 33 list ($class,$opts) = explode('&', $opts, 2); 34 if (!$label) $label = $class; 35 $opts = explode('&',$opts); 36 return array($class, $label, $pos, $opts); 37 } 38 39 public function render($mode, Doku_Renderer &$renderer, $data) { 40 if($mode != 'xhtml') return false; 41 list($class, $label, $pos, $opts) = $data; 42 $renderer->doc .= '<input id="togglewrap_'.$pos.'" type="checkbox" class="togglewrap" value="'.strtolower($class).'" '.(in_array('checked',$opts) ? 'checked=checked ' : '').' /><label for="togglewrap_'.$pos.'">'.$label.'</label>'; 43 return true; 44 } 45} 46