1<?php 2/** 3 * Plugin Toursprung: Allow display your Toursprung-Infos. 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Juergen A. Lamers <jaloma.ac@googlemail.com> 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'syntax.php'); 12/** 13 * All DokuWiki plugins to extend the parser/rendering mechanism 14 * need to inherit from this class 15 */ 16class syntax_plugin_toursprung extends DokuWiki_Syntax_Plugin { 17 18//<iframe width='145' height='385' src='http://www.runmap.net/user/jaloma/user_info_widget' border='0' frameborder='0' marginheight='0' marginwidth='0' scrolling='no'></iframe> 19 20 var $dflt = array( 21 'user' => '', 22 'site' => 'bikemap' 23 ); 24 25 /** 26 * return some info 27 */ 28 function getInfo(){ 29 return array( 30 'author' => 'Jürgen A. Lamers', 31 'email' => 'jaloma.ac@googlemail.com', 32 'date' => '2008-10-18', 33 'name' => 'Toursprung Plugin', 34 'desc' => 'Add your ToursprungInfos to your wiki 35 Syntax: <toursprung site="" user=""/>', 36 'url' => 'http://jaloma.ac.googlepages.com/plugin:toursprung' 37 ); 38 } 39 40 /** 41 * What kind of syntax are we? 42 */ 43 function getType() { return 'substition'; } 44 function getPType() { return 'block'; } 45 /** 46 * Where to sort in to parse? 47 */ 48 function getSort() { return 899; } 49 50 /** 51 * Connect pattern to lexer 52 */ 53 function connectTo($mode) { // 1234567890123 54 // <reliwa 55 $this->Lexer->addSpecialPattern('<toursprung ?[^>\n]*/>',$mode,'plugin_toursprung'); 56 } 57 58 /* 59 function postConnect() { 60 $this->Lexer->addExitPattern('</toursprung>','plugin_toursprung'); 61 }*/ 62 63 /** 64 * Handle the match 65 */ 66 function handle($match, $state, $pos, &$handler){ 67 // break matched cdata into its components 68 // 1234567890 69 // toursprung 70 list($str_params,$str_points) = explode('>',substr($match,11,-9),2); 71 $gmap = $this->_extract_params($str_params); 72 return array($gmap); 73 } 74 75 /** 76 * Create output 77 */ 78 function render($mode, &$renderer, $data) { 79 if ($mode == 'xhtml') { 80 list($param) = $data; 81 82//<iframe width='145' height='385' src='http://www.runmap.net/user/jaloma/user_info_widget' border='0' frameborder='0' marginheight='0' marginwidth='0' scrolling='no'></iframe> 83 $txt = ""; 84 $txt .= '<span>'; 85 $txt .= '<iframe'; 86 $txt .= ' width="145"'; 87 $txt .= ' height="385"'; 88 $txt .= ' src="http://www.'.$param['site'].'.net/user/'; 89 $uname = $param['user']; 90 if ($uname == '') { 91 $uname = $this->getConf('user'); 92 } 93 $txt .= $uname.'/user_info_widget"'; 94 $txt .= ' border="0"'; 95 $txt .= ' frameborder="0"'; 96 $txt .= ' marginheight="0"'; 97 $txt .= ' marginwidth="0"'; 98 $txt .= ' scrolling="no">'; 99 $txt .= '</iframe>'; 100 $txt .= '</span>'; 101 $renderer->doc .= $txt; 102 } 103 return false; 104 } 105 106 /** 107 * extract parameters for the googlemap from the parameter string 108 * 109 * @param string $str_params string of key="value" pairs 110 * @return array associative array of parameters key=>value 111 */ 112 function _extract_params($str_params) { 113 $param = array(); 114 preg_match_all('/(\w*)="(.*?)"/us',$str_params,$param,PREG_SET_ORDER); 115 if (sizeof($param) == 0) { 116 preg_match_all("/(\w*)='(.*?)'/us",$str_params,$param,PREG_SET_ORDER); 117 } 118 // parse match for instructions, break into key value pairs 119 $gmap = $this->dflt; 120 foreach($param as $kvpair) { 121 list($match,$key,$val) = $kvpair; 122 $key = strtolower($key); 123 if (isset($gmap[$key])) $gmap[$key] = $val; 124 } 125 return $gmap; 126 } 127} /* CLASS */ 128?>