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