1<?php 2 3 4if (!defined('DOKU_INC'))define('DOKU_INC', realpath(dirname( __FILE__ ).'/../../').'/'); 5if (!defined('DOKU_PLUGIN'))define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); 6require_once (DOKU_PLUGIN.'syntax.php'); 7 8 9class syntax_plugin_jalbum_jalbumbadge extends DokuWiki_Syntax_Plugin 10{ 11 /** 12 * default parameters of the jalbum tag 13 */ 14 var $dflt = array ( 15 'user'=>'jaloma', 16 'layout'=>'5', 17 'header'=>'My JAlbums', 18 'width'=>'off', 19 'height'=>'off', 20 'simple_footer_lnks'=>'1', 21 ); 22 23 24 var $layoutmapping = array ( 25 "Light"=>1, 26 "Dark"=>2, 27 "Blue"=>3, 28 "Pink"=>4, 29 "Green"=>5, 30 "Brown"=>6, 31 "light"=>1, 32 "dark"=>2, 33 "blue"=>3, 34 "pink"=>4, 35 "green"=>5, 36 "brown"=>6, 37 ); 38 39 /** 40 * return some info 41 */ 42 function getInfo() 43 { 44 return array ( 45 'author'=>'Juergen A.Lamers', 46 'email'=>'jaloma.ac@googlemail.com', 47 'date'=>@file_get_contents(DOKU_PLUGIN.'jalbum/VERSION'), 48 'name'=>'jalbumbadge', 49 'desc'=>'Einfacher Zugriff auf das Badge von JAlbum-Net', 50 'url'=>'http://wiki.dokuwiki.org/plugin:jalbum' 51 ); 52 } 53 54 /** 55 * What kind of syntax are we? 56 */ 57 function getType() 58 { 59 return 'substition'; 60 } 61 62 function getSort() 63 { 64 return 999; 65 } 66 67 function connectTo($mode) 68 { 69 $this->Lexer->addSpecialPattern('<jalbumbadge.*?/>', $mode, 'plugin_jalbum_jalbumbadge'); 70 } 71 72 function matchLength() 73 { 74 return strlen('<jalbumbadge'); 75 } 76 77 /** 78 * Handle the match 79 */ 80 function handle($match, $state, $pos, & $handler) 81 { 82 $match = html_entity_decode(substr($match, $this->matchLength(), -2)); 83 $thumb = $this->_extract_params($match); 84 return array ($thumb); 85 } 86 87 /** 88 * Create output 89 * <script type="text/javascript" charset="utf-8"> 90 _ja_badge_header = "My Jalbums"; 91 _ja_badge_look = 5; 92 93 _ja_badge_width = 200; 94 _ja_badge_simple_footer_lnks = 1; 95 96 </script> 97 <script src="http://jalbum.net/badge/load.js?u=jaloma&v=1" type="text/javascript" charset="utf-8"></script> 98 */ 99 function render($mode, & $renderer, $data) 100 { 101 global $conf; 102 if ($mode == 'xhtml') 103 { 104 list ($param) = $data; 105 if ( isset ($param['user'])) 106 { 107 $title = $param['header']; 108 $user = $param['user']; 109 $layout = $param['layout']; 110 if (array_key_exists($layout,$this->layoutmapping)) { 111 $layout = $this->layoutmapping[$layout]; 112 } 113 $width = $param['width']; 114 $height = $param['height']; 115// echo $layout."<br/>"; 116 $simple_footer_lnks = $param['simple_footer_lnks']; 117// $txt .= '<p>'; 118 $txt .= '<p style="clear:none;">'; 119 //<![CDATA[Inhalt]]]]><![CDATA[>Inhalt]]> 120 $txt .= '<script type="text/javascript" charset="utf-8">'."\n"; 121 if ( isset ($height) && $height != 'off') 122 { 123 $txt .= '_ja_badge_height = '.$height.";\n"; 124 } 125 //'// <![CDATA['."\n". 126 127 if ( isset ($width) && $width != 'off') 128 { 129 $txt .= '_ja_badge_width = '.$width.";\n"; 130 } 131 $txt .= '_ja_badge_simple_footer_lnks = '.$simple_footer_lnks.";\n"; 132 $txt .= '_ja_badge_look = '.$layout.';'."\n"; 133 $txt .= '_ja_badge_header = "'.$title.'";'."\n"; 134 $txt .= ''. 135 //'//]]>'."\n". 136 '</script>'."\n". 137 //.' 138 '<script src="http://jalbum.net/badge/load.js?u='.$user.'&v=1" type="text/javascript" charset="utf-8"></script>'."\n"; 139 140 $txt .= '</p>'; 141// $txt .= '<h3> </h3>'; 142// $txt .= '</p>'; 143 $renderer->doc .= $txt; 144 } else 145 { 146 return false; 147 } 148 } 149 return true; 150 } 151 152 /** 153 * extract parameters for jalbum from the parameter string 154 * 155 * @param string $str_params string of key="value" or key='value' pairs 156 * @return array associative array of parameters key=>value 157 */ 158 function _extract_params($str_params) 159 { 160 $param = array (); 161 preg_match_all('/(\w*)="(.*?)"/us', $str_params, $param, PREG_SET_ORDER); 162 if (sizeof($param) == 0) 163 { 164 preg_match_all("/(\w*)='(.*?)'/us", $str_params, $param, PREG_SET_ORDER); 165 } 166 // parse match for instructions, break into key value pairs 167 $thumb = $this->dflt; 168 foreach ($param as $kvpair) 169 { 170 list ($match, $key, $val) = $kvpair; 171 // $key = strtolower($key); 172 if ( isset ($thumb[$key]))$thumb[$key] = $val; 173 } 174 return $thumb; 175 } 176 177} // class 178 179?> 180