xref: /dokuwiki/inc/template.php (revision 6b13307fb447795714d01cdc029d6ed7ac087cf3)
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      #FIXME check for $conf['openregister']) needs to be done first!!
99      html_register();
100      break;
101    default:
102      print "Uhm... Where am I? This shouldn't happen";
103  }
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&amp;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 * @todo   svcheck missing
227 * @author Andreas Gohr <andi@splitbrain.org>
228 */
229function tpl_searchform(){
230  global $lang;
231  print '<form action="'.wl().'" accept-charset="utf-8" class="search">';
232  print '<input type="hidden" name="do" value="search" />';
233  print '<input type="text" accesskey="f" name="id" class="edit" />';
234  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />';
235  print '</form>';
236}
237
238/**
239 * Print the breadcrumbs trace
240 *
241 * @todo   add a hierachical breadcrumb function
242 * @author Andreas Gohr <andi@splitbrain.org>
243 */
244function tpl_breadcrumbs(){
245  global $lang;
246  global $conf;
247
248  //check if enabled
249  if(!$conf['breadcrumbs']) return;
250
251  $crumbs = breadcrumbs(); //setup crumb trace
252  print $lang['breadcrumb'].':';
253  foreach ($crumbs as $crumb){
254    print ' &raquo; ';
255    tpl_link(wl($crumb),noNS($crumb),'class="breadcrumbs" title="'.$crumb.'"');
256  }
257}
258
259/**
260 * Print info if the user is logged in
261 *
262 * Could be enhanced with a profile link in future?
263 *
264 * @author Andreas Gohr <andi@splitbrain.org>
265 */
266function tpl_userinfo(){
267  global $lang;
268  if($_SERVER['REMOTE_USER'])
269    print $lang['loggedinas'].': '.$_SERVER['REMOTE_USER'];
270}
271
272/**
273 * Print some info about the current page
274 *
275 * @author Andreas Gohr <andi@splitbrain.org>
276 */
277function tpl_pageinfo(){
278  global $conf;
279  global $lang;
280  global $INFO;
281  global $REV;
282
283  // prepare date and path
284  $fn = $INFO['filepath'];
285  if(!$conf['fullpath']){
286    if($REV){
287      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
288    }else{
289      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
290    }
291  }
292  $date = date($conf['dformat'],$INFO['lastmod']);
293
294  // print it
295  if($INFO['exists']){
296    print $fn;
297    print ' &middot; ';
298    print $lang['lastmod'];
299    print ': ';
300    print $date;
301    if($INFO['editor']){
302      print ' '.$lang['by'].' ';
303      print $INFO['editor'];
304    }
305    if($INFO['locked']){
306      print ' &middot; ';
307      print $lang['lockedby'];
308      print ': ';
309      print $INFO['locked'];
310    }
311  }
312}
313
314?>
315