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// must be run within DokuWiki
9if(!defined('DOKU_INC')) die();
10if(!defined('DOKU_LF')) define('DOKU_LF', "\n");
11
12// load language files
13require_once(DOKU_TPLINC.'lang/en/lang.php');
14if(@file_exists(DOKU_TPLINC.'lang/'.$conf['lang'].'/lang.php')) {
15    require_once(DOKU_TPLINC.'lang/'.$conf['lang'].'/lang.php');
16}
17
18function html_list_index_navigation($item){
19    global $ID;
20    $ret = '';
21    $base = ':'.$item['id'];
22    $base = substr($base,strrpos($base,':')+1);
23    if($item['type']=='d'){
24        $ret .= '<a href="'.wl($item['id']).'/" class="idx_dir"><strong>';
25        $ret .= $base;
26        $ret .= '</strong></a>';
27    }else{
28        $ret .= html_wikilink(':'.$item['id']);
29    }
30    return $ret;
31}
32
33
34/**
35 * checks if a file called logo.png or logo.jpg exists
36 * and uses it as logo, uses the dokuwiki logo by default
37 *
38 * @author Michael Klier <chi@chimeric.de>
39 */
40function dokubook_tpl_logo() {
41    global $conf;
42
43    $out = '';
44
45    switch(true) {
46        case(tpl_getConf('logo')):
47            $logo = tpl_getConf('logo');
48            // check if configured logo is a media file
49            if(file_exists(mediaFN($logo))) {
50                $logo = ml($logo, array('w' => 128));
51            }
52            break;
53        case(@file_exists(tpl_incdir().'images/logo.jpg')):
54            $logo = tpl_basedir().'images/logo.jpg';
55            break;
56        case(@file_exists(tpl_incdir().'images/logo.jpeg')):
57            $logo = tpl_basedir().'images/logo.jpeg';
58            break;
59        case(@file_exists(tpl_incdir().'images/logo.png')):
60            $logo = tpl_basedir().'images/logo.png';
61            break;
62        default:
63            $logo = tpl_basedir().'images/dokuwiki-128.png';
64            break;
65    }
66
67    $out .= '<a href="' . DOKU_BASE . '">';
68		if( $logo ) {
69				$out .= '  <img class="logo" src="' . $logo . '" alt="' . $conf['title'] . '" />' . DOKU_LF;
70		}
71		$out .= '</a>' . DOKU_LF;
72
73    print ($out);
74}
75
76/**
77 * generates the sidebar contents
78 *
79 * @author Michael Klier <chi@chimeric.de>
80 */
81function dokubook_tpl_sidebar() {
82    global $lang;
83    global $ID;
84    global $INFO;
85
86    $svID  = cleanID($ID);
87    $navpn = tpl_getConf('sb_pagename');
88    $path  = explode(':',$svID);
89    $found = false;
90    $sb    = '';
91
92    if(tpl_getConf('closedwiki') && empty($INFO['userinfo'])) {
93        print '<span class="sb_label">' . $lang['toolbox'] . '</span>' . DOKU_LF;
94        print '<aside id="toolbox" class="sidebar_box">' . DOKU_LF;
95        tpl_actionlink('login');
96        print '</aside>' . DOKU_LF;
97        return;
98    }
99
100    // main navigation
101    print '<span class="sb_label">' . $lang['navigation'] . '</span>' . DOKU_LF;
102    print '<aside id="navigation" class="sidebar_box">' . DOKU_LF;
103
104    while(!$found && count($path) > 0) {
105        $sb = implode(':', $path) . ':' . $navpn;
106        $found =  @file_exists(wikiFN($sb));
107        array_pop($path);
108    }
109
110    if(!$found && @file_exists(wikiFN($navpn))) $sb = $navpn;
111
112    if(@file_exists(wikiFN($sb)) && auth_quickaclcheck($sb) >= AUTH_READ) {
113        print p_dokubook_xhtml($sb);
114    } else {
115        print p_index_xhtml(cleanID($svID));
116    }
117
118    print '</aside>' . DOKU_LF;
119
120    // generate the searchbox
121    print '<span class="sb_label">' . strtolower($lang['btn_search']) . '</span>' . DOKU_LF;
122    print '<div id="search">' . DOKU_LF;
123    tpl_searchform();
124    print '</div>' . DOKU_LF;
125
126    // generate the toolbox
127    print '<span class="sb_label">' . $lang['toolbox'] . '</span>' . DOKU_LF;
128    print '<aside id="toolbox" class="sidebar_box">' . DOKU_LF;
129    tpl_actionlink('admin');
130    tpl_actionlink('index');
131    tpl_actionlink('media');
132    tpl_actionlink('recent');
133    tpl_actionlink('backlink');
134    tpl_actionlink('profile');
135    tpl_actionlink('login');
136    print '</aside>' . DOKU_LF;
137
138    // restore ID just in case
139    $ID = $svID;
140}
141
142/**
143 * prints a custom page footer
144 *
145 * @author Michael Klier <chi@chimeric.de>
146 */
147function dokubook_tpl_footer() {
148    global $ID;
149
150    $svID  = $ID;
151    $ftpn  = tpl_getConf('ft_pagename');
152    $path  = explode(':',$svID);
153    $found = false;
154    $ft    = '';
155
156    while(!$found && count($path) > 0) {
157        $ft = implode(':', $path) . ':' . $ftpn;
158        $found =  @file_exists(wikiFN($ft));
159        array_pop($path);
160    }
161
162    if(!$found && @file_exists(wikiFN($ftpn))) $ft = $ftpn;
163
164    if(@file_exists(wikiFN($ft)) && auth_quickaclcheck($ft) >= AUTH_READ) {
165        print '<div id="footer">' . DOKU_LF;
166        print p_dokubook_xhtml($ft);
167        print '</div>' . DOKU_LF;
168    }
169
170    // restore ID just in case
171    $ID = $svID;
172}
173
174/**
175 * removes the TOC of the sidebar-pages and shows
176 * a edit-button if user has enough rights
177 *
178 * @author Michael Klier <chi@chimeric.de>
179 */
180function p_dokubook_xhtml($wp) {
181    $data = p_wiki_xhtml($wp,'',false);
182    if(auth_quickaclcheck($wp) >= AUTH_EDIT) {
183        $data .= '<div class="secedit">' . html_btn('secedit',$wp,'',array('do'=>'edit','rev'=>'','post')) . '</div>';
184    }
185    // strip TOC
186    $data = preg_replace('/<div class="toc">.*?(<\/div>\n<\/div>)/s', '', $data);
187    // replace headline ids for XHTML compliance
188    $data = preg_replace('/(<h.*?><a.*?name=")(.*?)(".*?id=")(.*?)(">.*?<\/a><\/h.*?>)/','\1sb_\2\3sb_\4\5', $data);
189    return ($data);
190}
191
192/**
193 * Renders the Index
194 *
195 * copy of html_index located in /inc/html.php
196 *
197 * @author Andreas Gohr <andi@splitbrain.org>
198 * @author Michael Klier <chi@chimeric.de>
199 */
200function p_index_xhtml($ns) {
201  require_once(DOKU_INC.'inc/search.php');
202  global $conf;
203  global $ID;
204  $dir = $conf['datadir'];
205  $ns  = cleanID($ns);
206  #fixme use appropriate function
207  if(empty($ns)){
208    $ns = dirname(str_replace(':','/',$ID));
209    if($ns == '.') $ns ='';
210  }
211  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
212
213  // only extract headline
214  preg_match('/<h1>.*?<\/h1>/', p_locale_xhtml('index'), $match);
215  print $match[0];
216
217  $data = array();
218  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
219
220  print '<div id="sb__index__tree">' . DOKU_LF;
221  print html_buildlist($data,'idx','html_list_index','html_li_index');
222  print '</div>' . DOKU_LF;
223}
224
225// vim:ts=2:sw=2:enc=utf-8:
226