1<?php 2/** 3 * DokuWiki Plugin blextra (Helper Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Bernard Ladenthin <bernard@ladenthin.net> 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 16class helper_plugin_blextra extends DokuWiki_Plugin { 17 18 function getInfo() { 19 return array('author' => 'Bernard Ladenthin (SystemhouseSoftware)', 20 'email' => 'bernard@ladenthin.net', 21 'date' => '2012-05-26', 22 'name' => 'blextra Plugin', 23 'desc' => 'Provide functions for simple template creation', 24 'url' => 'http://www.dokuwiki.org/plugin:blextra'); 25 } 26 27 /** 28 * Constructor. 29 */ 30 function helper_plugin_blextra() { 31 } 32 33 /** 34 * Return namespacepart of a wiki ID exploded as array 35 */ 36 function getNSArray($id) { 37 $result = getNS($id); 38 if($result) { 39 $result = @explode(':',$result); 40 } 41 return $result; 42 } 43 44 /** 45 * Array of available menu items, especially for the function tpl_actionlink_array 46 * Change the order to change the order of the menu 47 */ 48 public $available_actions = array( 49 array( 50 'type' => 'login', 51 'pre' => '', 52 'suf' => '', 53 'inner' => '' 54 ), 55 array( 56 'type' => 'edit', 57 'pre' => '', 58 'suf' => '', 59 'inner' => '' 60 ), 61 array( 62 'type' => 'history', 63 'pre' => '', 64 'suf' => '', 65 'inner' => '' 66 ), 67 array( 68 'type' => 'recent', 69 'pre' => '', 70 'suf' => '', 71 'inner' => '' 72 ), 73 array( 74 'type' => 'profile', 75 'pre' => '', 76 'suf' => '', 77 'inner' => '' 78 ), 79 array( 80 'type' => 'index', 81 'pre' => '', 82 'suf' => '', 83 'inner' => '' 84 ), 85 array( 86 'type' => 'admin', 87 'pre' => '', 88 'suf' => '', 89 'inner' => '' 90 ), 91 array( 92 'type' => 'top', 93 'pre' => '', 94 'suf' => '', 95 'inner' => '' 96 ), 97 array( 98 'type' => 'back', 99 'pre' => '', 100 'suf' => '', 101 'inner' => '' 102 ), 103 array( 104 'type' => 'backlink', 105 'pre' => '', 106 'suf' => '', 107 'inner' => '' 108 ), 109 array( 110 'type' => 'subscribe', 111 'pre' => '', 112 'suf' => '', 113 'inner' => '' 114 ) 115 ); 116 117 /** 118 * Return the menu as string ($return = true) or 119 * return each return value from the tpl_actionlink call as array ($return = false), 120 * an example with $available_actions (from this class): 121 * array(11) { 122 * ["edit"]=> 123 * bool(true) 124 * ["history"]=> 125 * bool(true) 126 * ["recent"]=> 127 * bool(true) 128 * ["login"]=> 129 * bool(true) 130 * ["profile"]=> 131 * bool(true) 132 * ["index"]=> 133 * bool(true) 134 * ["admin"]=> 135 * bool(true) 136 * ["top"]=> 137 * bool(true) 138 * ["back"]=> 139 * bool(false) 140 * ["backlink"]=> 141 * bool(true) 142 * ["subscribe"]=> 143 * bool(false) 144 * } 145 */ 146 function tpl_actionlink_array($types,$array_pre='',$array_after='',$return=false) { 147 $out = ''; 148 if (!$return) { 149 $out = array(); 150 } 151 152 foreach($types as $key => $type) { 153 $_type = htmlspecialchars($type['type']); 154 $_pre = htmlspecialchars($type['pre']); 155 $_suf = htmlspecialchars($type['suf']); 156 $_inner = htmlspecialchars($type['inner']); 157 158 if ($return) { 159 $out .= 160 $array_pre. 161 tpl_actionlink($_type,$_pre,$_suf,$_inner,$return). 162 $array_after; 163 } 164 else { 165 echo $array_pre; 166 $out[$type['type']] = tpl_actionlink($_type,$_pre,$_suf,$_inner,$return); 167 echo $array_after; 168 } 169 } 170 171 return $out; 172 } 173 /** 174 * Return the links as string ($return = true) or 175 * return each return value from the tpl_link call as array ($return = false) 176 * 177 * an example: 178 * 179 * input: 180 * array(2) { 181 * [0]=> 182 * array(3) { 183 * ["url"]=> 184 * string(5) "start" 185 * ["name"]=> 186 * string(5) "Start" 187 * ["more"]=> 188 * string(22) "id='head_menu_1_start'" 189 * } 190 * [1]=> 191 * array(3) { 192 * ["url"]=> 193 * string(3) "end" 194 * ["name"]=> 195 * string(14) "Thats the end!" 196 * ["more"]=> 197 * string(20) "id='head_menu_1_end'" 198 * } 199 * } 200 * 201 * 202 * result: 203 * array(2) { 204 * [0]=> 205 * bool(true) 206 * [1]=> 207 * bool(true) 208 * } 209 * 210 */ 211 function tpl_link_array($urls,$array_pre='',$array_after='',$return=false) { 212 global $ID; 213 $out = $linktarget = ''; 214 if (!$return) { 215 $out = array(); 216 } 217 218 foreach($urls as $key => $url) { 219 $_url = htmlspecialchars($url['url']); 220 $_name = htmlspecialchars($url['name']); 221 $_more = htmlspecialchars($url['more']); 222 $_linktarget = wl(cleanID($_url),$params); 223 224 if ($return) { 225 $out .= 226 $array_pre. 227 tpl_link($_linktarget,$_name,$_more,$return). 228 $array_after; 229 } 230 else { 231 echo $array_pre; 232 $out[] = tpl_link($_linktarget,$_name,$_more,$return); 233 echo $array_after; 234 } 235 } 236 237 return $out; 238 } 239 240 function getMethods(){ 241 $result = array(); 242 243 $result[] = array( 244 'name' => 'getNSArray', 245 'desc' => 'Return namespacepart of a wiki ID exploded as array', 246 'params' => array(), 247 'return' => array('id' => 'string') 248 ); 249 250 $result[] = array( 251 'name' => 'tpl_actionlink_array', 252 'desc' => 'Return action links as array', 253 'params' => array( 254 'types' => 'array', 255 'array_pre (optional)' => 'string', 256 'array_after (optional)' => 'string', 257 'return (optional)' => 'bool' 258 ), 259 'return' => array('out' => 'mixed') //string or array 260 ); 261 262 $result[] = array( 263 'name' => 'tpl_link_array', 264 'desc' => 'Return action links as array', 265 'params' => array( 266 'urls' => 'array', 267 'array_pre (optional)' => 'string', 268 'array_after (optional)' => 'string', 269 'return (optional)' => 'bool' 270 ), 271 'return' => array('out' => 'mixed') //string or array 272 ); 273 274 return $result; 275 } 276 277} 278 279// vim:ts=4:sw=4:et: 280 281