1<?php
2/**
3 * Template Functions
4 *
5 * This file provides template specific custom functions that are
6 * not provided by the DokuWiki core.
7 * It is common practice to start each function with an underscore
8 * to make sure it won't interfere with future core functions.
9 *
10 * @author Andreas Gohr <andi@splitbrain.org>
11 * @author Anika Henke <anika@selfthinker.org>
12 * @author Klaus Vormweg <klaus.vormweg@gmx.de>
13 *
14 */
15
16// must be run from within DokuWiki
17if (!defined('DOKU_INC')) die();
18
19/**
20 * prints the menu
21 *
22 * @param void
23 * @return void
24*/
25function _tpl_mainmenu() {
26  require_once(DOKU_INC.'inc/search.php');
27  global $conf;
28
29  /* options for search() function */
30  $opts = array(
31   'depth' => 0,
32   'listfiles' => true,
33   'listdirs'  => true,
34   'pagesonly' => true,
35   'firsthead' => true,
36   'sneakyacl' => true
37  );
38
39  if(isset($conf['start'])) {
40    $start = $conf['start'];
41  } else {
42    $start = 'start';
43  }
44
45  $data = array();
46  search($data,$conf['datadir'],'search_universal',$opts);
47  $i = 0;
48  $data2 = array();
49  foreach($data as $item) {
50    if(strpos($item['id'],'playground') !== false) {
51      continue;
52    }
53    if(isset($conf['sidebar']) and $conf['sidebar']
54        and strpos($item['id'], $conf['sidebar']) !== false) {
55      continue;
56    }
57    ## unset()!!!
58    if($item['id'] == $start or preg_match('/:'.$start.'$/',$item['id'])
59       or preg_match('/(\w+):\1$/',$item['id'])) {
60      continue;
61    }
62    if(array_key_exists($item['id'], $data2)) {
63      $data2[$item['id']]['type'] = 'd';
64      $data2[$item['id']]['ns'] = $item['id'];
65      continue;
66    }
67    $data2[$item['id']] = $item;
68    $i++;
69  }
70  usort($data2,"_tpl_sort_index");
71  echo html_buildlist($data2,'idx','_tpl_list_index','_tpl_html_li_index');
72}
73
74/**
75 * Index item formatter
76 * Callback function for html_buildlist()
77 *
78 * @param array $item
79 * @return string html
80*/
81function _tpl_list_index($item) {
82  global $conf;
83  $ret = '';
84  if($item['type'] == 'd') {
85    if(@file_exists(wikiFN($item['id'].':'.$conf['start']))) {
86      $ret .= html_wikilink($item['id'].':'.$conf['start'], $item['title']);
87    } elseif(@file_exists(wikiFN($item['id'].':'.$item['id']))) {
88      $ret .= html_wikilink($item['id'].':'.$item['id'], $item['title']);
89    } else {
90      $ret .= html_wikilink($item['id'].':', $conf['start']);
91    }
92  } else {
93    $ret .= html_wikilink(':'.$item['id'], $item['title']);
94  }
95  return $ret;
96}
97
98/**
99 * Index List item
100 *
101 * Callback function for html_buildlist to build the
102 * <li> tags for namespaces when displaying the page index
103 *
104 * @param array $item
105 * @return string html
106 */
107function _tpl_html_li_index($item) {
108  global $INFO;
109
110  $class = '';
111  $id = '';
112
113  if($item['type'] == "f") {
114    return '<li class="level'.$item['level'].$class.'" '.$id.'>';
115  } else {
116    return '<li class="closed level'.$item['level'].$class.'">';
117  }
118}
119
120/**
121 * Returns <link> tag for various icon types (favicon|mobile)
122 *
123 * @param  array $types - list of icon types to display (favicon|mobile)
124 * @return string
125 */
126function _tpl_favicon($types = array('favicon','mobile')) {
127
128  $return = '';
129
130  $typearr = array();
131  foreach($types as $type) {
132    switch($type) {
133      case 'favicon':
134        $typearr['shortcut icon'] = 'favicon.ico';
135      case 'mobile':
136        $typearr['apple-touch-icon'] = 'apple-touch-icon.png';
137    }
138  }
139  foreach($typearr as $type => $fname) {
140    $look = array(':wiki:'.$fname, ':'.$fname, 'images/'.$fname);
141    $i = 0;
142    while($look[$i] and strpos($look[$i],'images') === FALSE) {
143      if(!auth_quickaclcheck($look[$i])) {
144        unset($look[$i]);
145      }
146      $i++;
147    }
148    $return .= '<link rel="'.$type.'" href="'.tpl_getMediaFile($look).'" />'.NL;
149  }
150  return $return;
151}
152
153
154/**
155 * Checks if a media file is readable by the current user
156 *
157 * @param string $id
158 * @return bool
159*/
160function _tpl_media_isreadable($id) {
161  $id = cleanID($id);
162  if(auth_quickaclcheck($id)) {
163    return true;
164  } else {
165    return false;
166  }
167}
168
169/**
170 * Callback function for usort
171*/
172function _tpl_sort_index($a, $b) {
173  return strcmp($a['id'],$b['id']);
174}
175