xref: /dokuwiki/inc/template.php (revision af1824345c357da2fbf69f5690b1135b29a14a1a)
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  global $lang;
54
55  switch($ACT){
56    case 'show':
57      html_show();
58      break;
59    case $lang['btn_preview']:
60      html_edit($TEXT);
61      html_show($TEXT);
62      break;
63    case 'edit':
64      html_edit();
65      break;
66    case 'wordblock':
67      html_edit($TEXT,'wordblock');
68      break;
69    case 'search':
70      html_search();
71      break;
72    case 'revisions':
73      html_revisions();
74      break;
75    case 'diff':
76      html_diff();
77      break;
78    case 'recent':
79      html_recent();
80      break;
81    case 'index':
82      html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
83      break;
84    case 'backlink':
85      html_backlinks();
86      break;
87    case 'conflict':
88      html_conflict(con($PRE,$TEXT,$SUF),$SUM);
89      html_diff(con($PRE,$TEXT,$SUF),false);
90      break;
91    case 'locked':
92      html_locked($lockedby);
93      break;
94    case 'login':
95      html_login();
96      break;
97    case 'register':
98      html_register();
99      break;
100    default:
101      print "Uhm... Where am I? This shouldn't happen";
102  }
103}
104
105
106/**
107 * Print the correct HTML meta headers
108 *
109 * This has to go into the head section of your template.
110 *
111 * @author Andreas Gohr <andi@splitbrain.org>
112 */
113function tpl_metaheaders(){
114  global $ID;
115  global $INFO;
116  global $ACT;
117  global $lang;
118  $it=2;
119
120  // the usual stuff
121  ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it);
122  ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it);
123  ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it);
124  ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it);
125  ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&amp;ns='.$INFO['namespace'].'" />',$it);
126  ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.wl($ID,'do=export_html').'" />',$it);
127  ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.wl($ID, 'do=export_raw').'" />',$it);
128  ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'style.css" />',$it);
129
130  // setup robot tags apropriate for different modes
131  if( ($ACT=='show' || $ACT=='export_html') && !$REV){
132    if($INFO['exists']){
133      ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it);
134      //delay indexing:
135      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
136        ptln('<meta name="robots" content="index,follow" />',$it);
137      }else{
138        ptln('<meta name="robots" content="noindex,nofollow" />',$it);
139      }
140    }else{
141      ptln('<meta name="robots" content="noindex,follow" />',$it);
142    }
143  }else{
144    ptln('<meta name="robots" content="noindex,nofollow" />',$it);
145  }
146
147  // include some JavaScript language strings
148  ptln('<script language="JavaScript" type="text/javascript">',$it);
149  ptln("  var alertText   = '".$lang['qb_alert']."'",$it);
150  ptln("  var notSavedYet = '".$lang['notsavedyet']."'",$it);
151  ptln("  var DOKU_BASE   = '".DOKU_BASE."'",$it);
152  ptln('</script>',$it);
153
154  // load the default JavaScript file
155  ptln('<script language="JavaScript" type="text/javascript" src="'.DOKU_BASE.'script.js"></script>',$it);
156
157
158  //FIXME include some default CSS ? IE FIX?
159}
160
161/**
162 * Print a link
163 *
164 * Just builds a link but adds additional JavaScript needed for
165 * the unsaved data check needed in the edit form.
166 *
167 * @author Andreas Gohr <andi@splitbrain.org>
168 */
169function tpl_link($url,$name,$more=''){
170  print '<a href="'.$url.'" onclick="return svchk()" onkeypress="return svchk()"';
171  if ($more) print ' '.$more;
172  print ">$name</a>";
173}
174
175/**
176 * Print one of the buttons
177 *
178 * Available Buttons are
179 *
180 *  edit    - edit/create/show button
181 *  history - old revisions
182 *  recent  - recent changes
183 *  login   - login/logout button - if ACL enabled
184 *  index   - The index
185 *  top     - a back to top button
186 *
187 * @author Andreas Gohr <andi@splitbrain.org>
188 */
189function tpl_button($type){
190  global $ID;
191  global $conf;
192
193  switch($type){
194    case 'edit':
195      print html_editbutton();
196      break;
197    case 'history':
198      print html_btn(revs,$ID,'o',array('do' => 'revisions'));
199      break;
200    case 'recent':
201      print html_btn(recent,'','r',array('do' => 'recent'));
202      break;
203    case 'index':
204      print html_btn(index,$ID,'x',array('do' => 'index'));
205      break;
206    case 'top':
207      print html_topbtn();
208      break;
209    case 'login':
210      if($conf['useacl']){
211        if($_SERVER['REMOTE_USER']){
212          print html_btn('logout',$ID,'',array('do' => 'logout',));
213        }else{
214          print html_btn('login',$ID,'',array('do' => 'login'));
215        }
216      }
217      break;
218  }
219}
220
221/**
222 * Print the search form
223 *
224 * @author Andreas Gohr <andi@splitbrain.org>
225 */
226function tpl_searchform(){
227  global $lang;
228  print '<form action="'.wl().'" accept-charset="utf-8" class="search" onsubmit="return svchk()">';
229  print '<input type="hidden" name="do" value="search" />';
230  print '<input type="text" accesskey="f" name="id" class="edit" />';
231  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />';
232  print '</form>';
233}
234
235/**
236 * Print the breadcrumbs trace
237 *
238 * @todo   add a hierachical breadcrumb function
239 * @author Andreas Gohr <andi@splitbrain.org>
240 */
241function tpl_breadcrumbs(){
242  global $lang;
243  global $conf;
244
245  //check if enabled
246  if(!$conf['breadcrumbs']) return;
247
248  $crumbs = breadcrumbs(); //setup crumb trace
249  print $lang['breadcrumb'].':';
250  foreach ($crumbs as $crumb){
251    print ' &raquo; ';
252    tpl_link(wl($crumb),noNS($crumb),'class="breadcrumbs" title="'.$crumb.'"');
253  }
254}
255
256/**
257 * Print info if the user is logged in
258 *
259 * Could be enhanced with a profile link in future?
260 *
261 * @author Andreas Gohr <andi@splitbrain.org>
262 */
263function tpl_userinfo(){
264  global $lang;
265  if($_SERVER['REMOTE_USER'])
266    print $lang['loggedinas'].': '.$_SERVER['REMOTE_USER'];
267}
268
269/**
270 * Print some info about the current page
271 *
272 * @author Andreas Gohr <andi@splitbrain.org>
273 */
274function tpl_pageinfo(){
275  global $conf;
276  global $lang;
277  global $INFO;
278  global $REV;
279
280  // prepare date and path
281  $fn = $INFO['filepath'];
282  if(!$conf['fullpath']){
283    if($REV){
284      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
285    }else{
286      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
287    }
288  }
289  $date = date($conf['dformat'],$INFO['lastmod']);
290
291  // print it
292  if($INFO['exists']){
293    print $fn;
294    print ' &middot; ';
295    print $lang['lastmod'];
296    print ': ';
297    print $date;
298    if($INFO['editor']){
299      print ' '.$lang['by'].' ';
300      print $INFO['editor'];
301    }
302    if($INFO['locked']){
303      print ' &middot; ';
304      print $lang['lockedby'];
305      print ': ';
306      print $INFO['locked'];
307    }
308  }
309}
310
311?>
312