1<?php
2
3require_once dirname(__FILE__) . '/IckeNavigation.php';
4
5function icke_getFile($name) {
6    return file_exists(DOKU_TPLINC . 'local/' . $name) ?
7           'local/' . $name : $name;
8}
9
10function icke_tplPopupPage($id){
11    $page = p_wiki_xhtml($id,'',false);
12    if($page) {
13        icke_tplPopup($page);
14    }
15}
16
17function icke_tplPopup($page) {
18    ?>
19    <div class="sec_level">
20    <span class="a"></span>
21    <span class="b"></span>
22    <div class="popup_content">
23    <?php echo $page; ?>
24    </div>
25    <span class="c"></span>
26    <span class="d"></span>
27    </div>
28    <?php
29}
30
31function icke_tplProjectSteps(){
32    global $ID;
33    global $conf;
34
35    $steps = '';
36    $ns = $ID;
37    do {
38        $ns = getNS($ns);
39        $try = $ns . ':schritt';
40        if(page_exists($try)) {
41            $steps = $try;
42            break;
43        }
44        $try .= ':' . $conf['start'];
45        if(page_exists($try)) {
46            $steps = $try;
47            break;
48        }
49    } while ($ns);
50
51    if (!$steps) return;
52
53    echo '<li class="sideclip">';
54    echo p_wiki_xhtml($steps,'',false);
55    echo '</li>';
56}
57
58
59/**
60 * Return the toolbox popup
61 */
62function icke_toolbox(){
63    $tools  = '';
64    $tools .= '<h1 class="empty"></h1>';
65    $tools .= '<div class="level2">';
66    $tools .= '<ul>';
67    $tools .= (new \dokuwiki\Menu\SiteMenu())->getListItems('dw-menu-item ');
68    $tools .= (new \dokuwiki\Menu\UserMenu())->getListItems('dw-menu-item ');
69    $tools .= '</ul></div>';
70    return $tools;
71}
72
73function icke_toolbox_renderer($action, $text, $pluginName, $pluginType) {
74    if (plugin_load($pluginType, $pluginName) === null) {
75        return '';
76    }
77    global $ID;
78    $url = wl($ID, array('do' => $action));
79    $link =  '<li><div class="li">';
80    $link .= "<a href=\"$url\" class=\"action admin\" rel=\"nofollow\" title=\"$text\">$text</a>";
81    $link .= '</div></li>';
82    return $link;
83}
84
85/**
86 * Print a single navigation item and associated quick popup
87 */
88function icke_navi($link,$name='',$class='',$popup='',$active=false,$sep=false){
89    // active/separator decorations
90    $liclass = '';
91    if($active) $liclass .= ' active';
92    if($sep) $liclass .= ' separator';
93    if($name == 'Settings') $liclass .= ' nomobile';
94    $liclass = trim($liclass);
95    if($liclass) $liclass = ' class="'.$liclass.'"';
96
97    if(!$name && $link)  $name  = p_get_first_heading($link);
98    if(!$class && $link) $class = 'qnav_'.str_replace(':','_',getNS($link));
99    if($link) $link = ' href="'.wl($link).'"';
100
101    // output the item
102    $liHTML  = '<li'.$liclass.'>';
103    $liHTML .= '<a class="qnav_item '.$class.'" '.$link.'>'.hsc($name).'</a>';
104    if($popup){
105        $liHTML .= '<div class="sec_level">';
106        $liHTML .= '<div class="popup_content">';
107        $liHTML .= $popup;
108        $liHTML .= '</div>';
109        $liHTML .= '</div>';
110    }
111    $liHTML .= '</li>';
112    echo $liHTML;
113}
114
115/**
116 * Populate the navigation side bar from the configured navigation links
117 */
118function icke_tplSidebar() {
119    $navigation = icke_getNavigation();
120    $navigation->drawSidebar();
121}
122
123function icke_translatedID($id, $mustExist = true) {
124    $translation =& plugin_load('action', 'translation');
125    if ($translation === null) {
126        return $id;
127    }
128
129    if ($translation->locale === null) {
130        return $id;
131    }
132    $translatedId = $translation->locale . ":$id";
133    if (page_exists($translatedId) || !$mustExist ) {
134        return $translatedId;
135    }
136    return $id;
137}
138
139/**
140 * Include icons CSS for the navigation and fancy search
141 *
142 * Looks in the media namespace (ns:icon_on.png, ns:icon_off.png) first,
143 * then in the template, then uses a fail image.
144 */
145function icke_tplCSS() {
146    $navigation = icke_getNavigation();
147    $navigation->buildPageCss();
148}
149
150function icke_processFancySearchItem($id) {
151    if(!$id) return false;
152    $link = $id;
153    resolve_pageid('',$link,$exists);
154    if (auth_quickaclcheck($link) < AUTH_READ) return false;
155    $ns   = getNS($link);
156    if(!$ns) $ns = $link;
157
158    // try to use translated namespaces for translation plug-in
159    $class = array_shift(explode(':',$ns));
160    $imgClass = $class;
161    if (page_exists($link)) {
162        $class = icke_translatedID($class, false);
163        $class = str_replace(':', '_', $class);
164    }
165    return array('ns' => $ns, 'class' => $class, 'imgClass' => $imgClass);
166}
167
168
169function icke_tplSearch() {
170
171    $fancysearch = plugin_load('action', 'fancysearch');
172    if (is_null($fancysearch)) {
173        tpl_searchform(true, false);
174        return;
175    }
176
177    $navigation = icke_getNavigation();
178    $navi = array();
179    $navi[''] = 'icke';
180    foreach($navigation->navigation as $item){
181        if (!($item instanceof IckeNavigationItem)) continue;
182        if(strstr($item->id,'%USER%') !== false) continue;
183        //$processed = icke_processFancySearchItem($id);
184        //if (!$processed) continue;
185        $ns = rtrim($item->getNamespace(), ':');
186        $class = $item->class;
187
188        $navi[$ns] = $class;
189    }
190
191    $fancysearch->tpl_searchform($navi);
192}
193
194
195