1<?php 2/** 3 * DokuWiki template functions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 10 require_once(DOKU_INC.'conf/dokuwiki.php'); 11 12/** 13 * Wrapper around htmlspecialchars() 14 * 15 * @author Andreas Gohr <andi@splitbrain.org> 16 * @see htmlspecialchars() 17 */ 18function hsc($string){ 19 return htmlspecialchars($string); 20} 21 22/** 23 * print a newline terminated string 24 * 25 * You can give an indention as optional parameter 26 * 27 * @author Andreas Gohr <andi@splitbrain.org> 28 */ 29function ptln($string,$intend=0){ 30 for($i=0; $i<$intend; $i++) print ' '; 31 print"$string\n"; 32} 33 34/** 35 * Print the content 36 * 37 * This function is used for printing all the usual content 38 * (defined by the global $ACT var) by calling the appropriate 39 * outputfunction(s) from html.php 40 * 41 * Everything that doesn't use the default template isn't 42 * handled by this function. ACL stuff is not done either. 43 * 44 * @author Andreas Gohr <andi@splitbrain.org> 45 */ 46function tpl_content(){ 47 global $ACT; 48 global $TEXT; 49 global $PRE; 50 global $SUF; 51 global $SUM; 52 global $IDX; 53 54 switch($ACT){ 55 case 'show': 56 html_show(); 57 break; 58 case 'preview': 59 html_edit($TEXT); 60 html_show($TEXT); 61 break; 62 case 'edit': 63 html_edit(); 64 break; 65 case 'wordblock': 66 html_edit($TEXT,'wordblock'); 67 break; 68 case 'search': 69 html_search(); 70 break; 71 case 'revisions': 72 html_revisions(); 73 break; 74 case 'diff': 75 html_diff(); 76 break; 77 case 'recent': 78 html_recent(); 79 break; 80 case 'index': 81 html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 82 break; 83 case 'backlink': 84 html_backlinks(); 85 break; 86 case 'conflict': 87 html_conflict(con($PRE,$TEXT,$SUF),$SUM); 88 html_diff(con($PRE,$TEXT,$SUF),false); 89 break; 90 case 'locked': 91 html_locked($lockedby); 92 break; 93 case 'login': 94 html_login(); 95 break; 96 case 'register': 97 html_register(); 98 break; 99 case 'denied': 100 print parsedLocale('denied'); 101 break; 102 default: 103 msg("Failed to handle command: ".hsc($ACT),-1); 104 } 105} 106 107 108/** 109 * Print the correct HTML meta headers 110 * 111 * This has to go into the head section of your template. 112 * 113 * @author Andreas Gohr <andi@splitbrain.org> 114 */ 115function tpl_metaheaders(){ 116 global $ID; 117 global $INFO; 118 global $ACT; 119 global $lang; 120 $it=2; 121 122 // the usual stuff 123 ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it); 124 ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it); 125 ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it); 126 ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it); 127 ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'].'" />',$it); 128 ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.wl($ID,'do=export_html').'" />',$it); 129 ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.wl($ID, 'do=export_raw').'" />',$it); 130 ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'style.css" />',$it); 131 132 // setup robot tags apropriate for different modes 133 if( ($ACT=='show' || $ACT=='export_html') && !$REV){ 134 if($INFO['exists']){ 135 ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it); 136 //delay indexing: 137 if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ 138 ptln('<meta name="robots" content="index,follow" />',$it); 139 }else{ 140 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 141 } 142 }else{ 143 ptln('<meta name="robots" content="noindex,follow" />',$it); 144 } 145 }else{ 146 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 147 } 148 149 // include some JavaScript language strings 150 ptln('<script language="JavaScript" type="text/javascript">',$it); 151 ptln(" var alertText = '".$lang['qb_alert']."'",$it); 152 ptln(" var notSavedYet = '".$lang['notsavedyet']."'",$it); 153 ptln(" var DOKU_BASE = '".DOKU_BASE."'",$it); 154 ptln('</script>',$it); 155 156 // load the default JavaScript file 157 ptln('<script language="JavaScript" type="text/javascript" src="'.DOKU_BASE.'script.js"></script>',$it); 158 159 160 //FIXME include some default CSS ? IE FIX? 161} 162 163/** 164 * Print a link 165 * 166 * Just builds a link but adds additional JavaScript needed for 167 * the unsaved data check needed in the edit form. 168 * 169 * @author Andreas Gohr <andi@splitbrain.org> 170 */ 171function tpl_link($url,$name,$more=''){ 172 print '<a href="'.$url.'" onclick="return svchk()" onkeypress="return svchk()"'; 173 if ($more) print ' '.$more; 174 print ">$name</a>"; 175} 176 177/** 178 * Print one of the buttons 179 * 180 * Available Buttons are 181 * 182 * edit - edit/create/show button 183 * history - old revisions 184 * recent - recent changes 185 * login - login/logout button - if ACL enabled 186 * index - The index 187 * top - a back to top button 188 * 189 * @author Andreas Gohr <andi@splitbrain.org> 190 */ 191function tpl_button($type){ 192 global $ID; 193 global $conf; 194 195 switch($type){ 196 case 'edit': 197 print html_editbutton(); 198 break; 199 case 'history': 200 print html_btn(revs,$ID,'o',array('do' => 'revisions')); 201 break; 202 case 'recent': 203 print html_btn(recent,'','r',array('do' => 'recent')); 204 break; 205 case 'index': 206 print html_btn(index,$ID,'x',array('do' => 'index')); 207 break; 208 case 'top': 209 print html_topbtn(); 210 break; 211 case 'login': 212 if($conf['useacl']){ 213 if($_SERVER['REMOTE_USER']){ 214 print html_btn('logout',$ID,'',array('do' => 'logout',)); 215 }else{ 216 print html_btn('login',$ID,'',array('do' => 'login')); 217 } 218 } 219 break; 220 } 221} 222 223/** 224 * Print the search form 225 * 226 * @author Andreas Gohr <andi@splitbrain.org> 227 */ 228function tpl_searchform(){ 229 global $lang; 230 print '<form action="'.wl().'" accept-charset="utf-8" class="search" onsubmit="return svchk()">'; 231 print '<input type="hidden" name="do" value="search" />'; 232 print '<input type="text" accesskey="f" name="id" class="edit" />'; 233 print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />'; 234 print '</form>'; 235} 236 237/** 238 * Print the breadcrumbs trace 239 * 240 * @todo add a hierachical breadcrumb function 241 * @author Andreas Gohr <andi@splitbrain.org> 242 */ 243function tpl_breadcrumbs(){ 244 global $lang; 245 global $conf; 246 247 //check if enabled 248 if(!$conf['breadcrumbs']) return; 249 250 $crumbs = breadcrumbs(); //setup crumb trace 251 print $lang['breadcrumb'].':'; 252 foreach ($crumbs as $crumb){ 253 print ' » '; 254 tpl_link(wl($crumb),noNS($crumb),'class="breadcrumbs" title="'.$crumb.'"'); 255 } 256} 257 258/** 259 * Print info if the user is logged in 260 * 261 * Could be enhanced with a profile link in future? 262 * 263 * @author Andreas Gohr <andi@splitbrain.org> 264 */ 265function tpl_userinfo(){ 266 global $lang; 267 if($_SERVER['REMOTE_USER']) 268 print $lang['loggedinas'].': '.$_SERVER['REMOTE_USER']; 269} 270 271/** 272 * Print some info about the current page 273 * 274 * @author Andreas Gohr <andi@splitbrain.org> 275 */ 276function tpl_pageinfo(){ 277 global $conf; 278 global $lang; 279 global $INFO; 280 global $REV; 281 282 // prepare date and path 283 $fn = $INFO['filepath']; 284 if(!$conf['fullpath']){ 285 if($REV){ 286 $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn); 287 }else{ 288 $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn); 289 } 290 } 291 $date = date($conf['dformat'],$INFO['lastmod']); 292 293 // print it 294 if($INFO['exists']){ 295 print $fn; 296 print ' · '; 297 print $lang['lastmod']; 298 print ': '; 299 print $date; 300 if($INFO['editor']){ 301 print ' '.$lang['by'].' '; 302 print $INFO['editor']; 303 } 304 if($INFO['locked']){ 305 print ' · '; 306 print $lang['lockedby']; 307 print ': '; 308 print $INFO['locked']; 309 } 310 } 311} 312 313/** 314 * Print a list of namespaces containing media files 315 * 316 * @author Andreas Gohr <andi@splitbrain.org> 317 */ 318function tpl_medianamespaces(){ 319 global $conf; 320 321 $data = array(); 322 search($data,$conf['mediadir'],'search_namespaces',array()); 323 print html_buildlist($data,'idx',media_html_list_namespaces); 324} 325 326/** 327 * Print a list of mediafiles in the current namespace 328 * 329 * @author Andreas Gohr <andi@splitbrain.org> 330 */ 331function tpl_mediafilelist(){ 332 global $conf; 333 global $lang; 334 global $NS; 335 $dir = utf8_encodeFN(str_replace(':','/',$NS)); 336 337 $data = array(); 338 search($data,$conf['mediadir'],'search_media',array(),$dir); 339 340 if(!count($data)){ 341 ptln('<div class="nothing">'.$lang['nothingfound'].'<div>'); 342 return; 343 } 344 345 ptln('<ul>',2); 346 foreach($data as $item){ 347 ptln('<li>',4); 348 ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'. 349 utf8_decodeFN($item['file']). 350 '</a>',6); 351 if($item['isimg']){ 352 ptln('('.$item['info'][0].'×'.$item['info'][1]. 353 ' '.filesize_h($item['size']).')<br />',6); 354 355 # build thumbnail 356 $link=array(); 357 $link['name']=$item['id']; 358 if($item['info'][0]>120) $link['name'] .= '?120'; 359 $link = format_link_media($link); 360 ptln($link['name'],6); 361 362 }else{ 363 ptln ('('.filesize_h($item['size']).')',6); 364 } 365 ptln('</li>',4); 366 } 367 ptln('</ul>',2); 368} 369 370/** 371 * Print the media upload form if permissions are correct 372 * 373 * @author Andreas Gohr <andi@splitbrain.org> 374 */ 375function tpl_mediauploadform(){ 376 global $NS; 377 global $UPLOADOK; 378 global $lang; 379 380 if(!$UPLOADOK) return; 381 382 ptln('<form action="'.$_SERVER['PHP_SELF'].'" name="upload"'. 383 ' method="post" enctype="multipart/form-data">',2); 384 ptln($lang['txt_upload'].':<br />',4); 385 ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4); 386 ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4); 387 ptln($lang['txt_filename'].'<br />',4); 388 ptln('<input type="text" name="id" class="edit" />',4); 389 ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4); 390 ptln('</form>',2); 391} 392 393?> 394