1<?php
2/**
3 * template functions for dokubook template
4 *
5 * @license:    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author:     Michael Klier <chi@chimeric.de>
7 */
8
9if(!defined('DW_LF')) define('DW_LF',"\n");
10
11// load language files
12require_once(DOKU_TPLINC.'lang/en/lang.php');
13if(@file_exists(DOKU_TPLINC.'lang/'.$conf['lang'].'/lang.php')) {
14    require_once(DOKU_TPLINC.'lang/'.$conf['lang'].'/lang.php');
15}
16
17/**
18 * checks if a file called logo.png or logo.jpg exists
19 * and uses it as logo, uses the dokuwiki logo by default
20 *
21 * @author Michael Klier <chi@chimeric.de>
22 */
23function tpl_logo() {
24    global $conf;
25
26    $out = '';
27
28    switch(true) {
29        case(@file_exists(DOKU_TPLINC.'images/logo.jpg')):
30            $logo = DOKU_TPL.'images/logo.jpg';
31            break;
32        case(@file_exists(DOKU_TPLINC.'images/logo.jpeg')):
33            $logo = DOKU_TPL.'images/logo.jpeg';
34            break;
35        case(@file_exists(DOKU_TPLINC.'images/logo.png')):
36            $logo = DOKU_TPL.'images/logo.png';
37            break;
38        default:
39            $logo = DOKU_TPL.'images/dokuwiki-128.png';
40            break;
41    }
42
43    $out .= '<a href="' . DOKU_BASE . '" name="dokuwiki__top" id="dokuwiki__top" accesskey="h" title="[ALT+H]">';
44    $out .= '  <img class="logo" src="' . $logo . '" alt="' . $conf['title'] . '" /></a>' . DW_LF;
45
46    print ($out);
47}
48
49/**
50 * generates the sidebar contents
51 *
52 * @author Michael Klier <chi@chimeric.de>
53 */
54function tpl_sidebar() {
55    global $lang;
56    global $ID;
57    global $INFO;
58
59    $svID  = cleanID($ID);
60    $navpn = tpl_getConf('pagename');
61    $path  = explode(':',$svID);
62    $found = false;
63    $sb    = '';
64
65    if(tpl_getConf('closedwiki') && empty($INFO['userinfo'])) {
66        print '<span class="sb_label">' . $lang['toolbox'] . '</span>' . DW_LF;
67        print '<div id="toolbox" class="sidebar_box">' . DW_LF;
68        tpl_actionlink('login');
69        print '</div>' . DW_LF;
70        return;
71    }
72
73    // main navigation
74    print '<span class="sb_label">' . $lang['navigation'] . '</span>' . DW_LF;
75    print '<div id="navigation" class="sidebar_box">' . DW_LF;
76
77    print ts_sidebar('navigation');
78
79    print '</div>' . DW_LF;
80    print '<span class="sb_label">' . $lang['index'] . '</span>' . DW_LF;
81    print '<div id="index" class="sidebar_box">' . DW_LF;
82
83    print ts_sidebar('index');
84
85    print '</div>' . DW_LF;
86
87    // generate the searchbox
88    print '<span class="sb_label">' . strtolower($lang['btn_search']) . '</span>' . DW_LF;
89    print '<div id="search">' . DW_LF;
90    tpl_searchform();
91    print '</div>' . DW_LF;
92
93    // generate the toolbox
94    print '<span class="sb_label">' . $lang['toolbox'] . '</span>' . DW_LF;
95    print '<div id="toolbox" class="sidebar_box">' . DW_LF;
96    tpl_actionlink('admin');
97    tpl_actionlink('index');
98    tpl_actionlink('recent');
99    tpl_actionlink('backlink');
100    tpl_actionlink('profile');
101    tpl_actionlink('login');
102    print '</div>' . DW_LF;
103}
104
105/**
106 * removes the TOC of the sidebar-pages and shows a edit-button if user has enough rights
107 *
108 * @author Michael Klier <chi@chimeric.de>
109 */
110function p_sidebar_xhtml($sb) {
111    $data = p_wiki_xhtml($sb,'',false);
112    if(auth_quickaclcheck($sb) >= AUTH_EDIT) {
113        $data .= '<div class="secedit">' . html_btn('secedit',$sb,'',array('do'=>'edit','rev'=>'','post')) . '</div>';
114    }
115    return preg_replace('/<div class="toc">.*?(<\/div>\n<\/div>)/s', '', $data);
116}
117
118/**
119 * puts text into our sidebar using lang/en/$ns.txt
120 */
121function ts_sidebar($ns){
122  global $conf;
123
124    $sb_path = 'lang/en';
125  if (@file_exists(DOKU_TPLINC.'lang/'.$conf['lang'].'/'.$ns.'.txt'))
126    $sb_path = '../../../lib/tpl/tribalshout/lang/'.$conf['lang'];
127  elseif (@file_exists(DOKU_TPLINC.'lang/en/'.$ns.'.txt'))
128    $sb_path = '../../../lib/tpl/tribalshout/lang/en';
129
130  print p_locale_xhtml($sb_path.'/'.$ns);
131}
132
133/**
134 * Like the action buttons but links
135 *
136 * Available links are
137 *
138 *  article - links to the main page itself
139 *  discussion - links to Talk:<namespace>
140 *
141 * @author Andreas Gohr <andi@splitbrain.org>
142 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
143 * @see    tpl_button
144 * adapted by davek
145 */
146function ts_tpl_actionlink($type,$pre='',$suf=''){
147  global $ID;
148  global $INFO;
149  global $REV;
150  global $ACT;
151  global $conf;
152  global $lang;
153  global $auth;
154
155  // check disabled actions and fix the badly named ones
156  $ctype = $type;
157  if($type == 'history') $ctype='revisions';
158  if(!actionOK($ctype)) return false;
159
160  switch($type){
161    case 'article':
162	  //$ID = ereg_replace('^talk:','Talk:',$ID);
163      if (ereg('^talk:', $ID))
164      	tpl_link(wl(ereg_replace('^talk:','',$ID)),$pre.$lang['btn_article'].$suf,'class="action article" accesskey="v" rel="nofollow"');
165      else
166      	tpl_link(wl($ID),$pre.$lang['btn_article'].$suf,'class="action article" accesskey="v" rel="nofollow"');
167      return true;
168    case 'discussion':
169      if (ereg('^talk:', $ID)) {
170        tpl_link(wl($ID),$pre.$lang['btn_discussion'].$suf,'class="action discussion" style="margin-right:40px;" accesskey="d" rel="nofollow"');
171      } else {
172        tpl_link(wl('talk:'.$ID),$pre.$lang['btn_discussion'].$suf,'class="action" style="margin-right:40px;" accesskey="d" rel="nofollow"');
173      }
174      return true;
175    default:
176      print '[unknown link type]';
177      return true;
178  }
179}
180