1<?php 2/** 3 * EasyVar Plugin: allows to insert your own variables 4 * 5 * Syntax : @variable@ will be replaced with valeurVariable 6 * 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 * @author Joel Dare <joel@joeldare.com> 9 * 10 * Based on KixoVar by Kixo SARL <infos@kixo.fr>. Adds two improvements. First, 11 * variables can be any length (KixoVar is limited to 2 to 5 characters). 12 * Second, you can use wiki syntax and HTML inside the variables. 13 */ 14 15if(!defined('DOKU_INC')) die('Error'); 16if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 17require_once(DOKU_PLUGIN.'syntax.php'); 18 19class syntax_plugin_easyVar extends DokuWiki_Syntax_Plugin { 20 21 function getInfo(){ 22 return array( 23 'author' => 'Joel Dare', 24 'email' => 'joel@joeldare.com', 25 'date' => '2009-12-28', 26 'name' => 'easyVar', 27 'desc' => 'Insert your own variables', 28 'url' => 'http://www.joeldare.com' 29 ); 30 } 31 32 function getType(){ return 'formatting'; } 33 function getSort(){ return 999; } 34 function connectTo($mode) { $this->Lexer->addSpecialPattern('@\w*@', $mode, 'plugin_easyVar'); } 35 36 function handle($match, $state, $pos, &$handler){ 37 $match = substr($match, 1, -1); // strip markup 38 return array($match); 39 } 40 41 function render($mode, &$renderer, $data) { 42 43 $var=$this->getConf('var'); 44 45 $meta = $data[0]; 46 $nocache = false; 47 $xhtml = $meta; 48 49 if($mode=='xhtml' and sizeof($var)>0){ 50 foreach($var as $key=>$value){ 51 if($key==$meta){ 52 $xhtml=$value; 53 } 54 } 55 56 //$renderer->doc .= hsc($xhtml); 57 $renderer->doc .= $xhtml; 58 return true; 59 } 60 return false; 61 } 62} 63