-
Notifications
You must be signed in to change notification settings - Fork 15
/
tpl_functions.php
229 lines (176 loc) · 5.96 KB
/
tpl_functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
/**
* Template Functions
*
* This file provides template specific custom functions that are
* not provided by the DokuWiki core.
* It is common practice to start each function with an underscore
* to make sure it won't interfere with future core functions.
*/
// must be run from within DokuWiki
if (!defined('DOKU_INC')) die();
/**
* Create link/button to user page
*
* @author Anika Henke <[email protected]>
*/
function _tpl_userpage($userPage, $title, $link=0, $wrapper=0) {
if (!$_SERVER['REMOTE_USER']) return;
global $conf;
$userPage = str_replace('@USER@', $_SERVER['REMOTE_USER'], $userPage);
if ($wrapper) echo "<$wrapper>";
if ($link)
tpl_pagelink($userPage, $title);
else
echo html_btn('userpage', $userPage, '', array(), 'get', 0, $title);
if ($wrapper) echo "</$wrapper>";
}
/**
* Wrapper around custom template actions
*
* @author Anika Henke <[email protected]>
*/
function _tpl_action($type, $link=0, $wrapper=0) {
switch ($type) {
case 'userpage':
if (tpl_getConf('userPage')) {
_tpl_userpage(tpl_getConf('userPage'), tpl_getLang('userpage'), $link, $wrapper);
}
break;
}
}
/* dokubootstrap-yeti related functions
********************************************************************/
function _tpl_toc_to_twitter_bootstrap_event_hander_dump_level($data, $firstlevel=false) {
if (count($data) == 0) {
return '';
}
//dw($data);
$out = '<div class="bs-sidebar" role="navigation">';
//$out .= '<ul class="nav nav-pills nav-stacked affix">';
$out .= '<ul class="nav">';
$li_open = false;
$level = $data[0]['level'];
//Only supports top level links for now.
foreach($data as $heading) {
// link or reference?
isset($heading['hid']) ? $href = '#'.$heading['hid'] : $href = $heading['link'];
if ($heading['level'] == $level) {
// Close previous open li.
if($li_open) {
$out .= '</li>';
$li_open = false;
}else{
$out .= '';
}
$out .= '<li><a href="' . $href . '">'. $heading['title'] . '</a>';
$li_open = true;
}else if($heading['level'] > $level) {
$out .= '<ul class="nav">';
$out .= '<li><a href="' . $href . '">'. $heading['title'] . '</a>';
$li_open = true;
}else if($heading['level'] < $level) {
// Close previous open li.
if($li_open) {
for ($i=0; $i < $level - $heading['level'] - 1; ++$i) {
$out .= '</li>';
$out .= '</ul>';
}
$out .= '</li>';
$li_open = false;
}else{
$out .= '';
}
$out .= '</ul>';
$out .= '<li><a href="' . $href . '">'. $heading['title'] . '</a>';
}
$level = $heading['level'];
}
// Close previous open li.
if($li_open) {
$out .= '</li>';
}
$out .= '</ul>';
$out .= '</div>';
return $out;
}
function _tpl_toc_to_twitter_bootstrap_event_hander(&$event, $param)
{
global $conf;
//This is tied to the specific format of the DokuWiki TOC.
echo _tpl_toc_to_twitter_bootstrap_event_hander_dump_level($event->data, true);
}
function _tpl_toc_to_twitter_bootstrap()
{
//Force generation of TOC, request that the TOC is returned as HTML, but then ignore the returned string. The hook will instead dump out the TOC.
global $EVENT_HANDLER;
$EVENT_HANDLER->register_hook('TPL_TOC_RENDER', 'AFTER', NULL, '_tpl_toc_to_twitter_bootstrap_event_hander');
tpl_toc(true);
}
function _tpl_output_page_tools($showTools = true, $element = 'li'){
global $lang;
if ($showTools) {
echo '<ul class="dropdown-menu">';
tpl_action('edit', 1, $element);
tpl_action('revisions', 1, $element);
tpl_action('backlink', 1, $element);
tpl_action('subscribe', 1, $element);
tpl_action('revert', $textonly, $element);
echo '<li class="divider"></li>';
tpl_action('recent', 1, 'li');
tpl_action('media', 1, 'li');
tpl_action('index', 1, 'li');
echo '</ul>';
}
}
function _tpl_output_search_bar()
{
//Modified from the official tpl_searchform function.
global $lang;
global $ACT;
global $QUERY;
// don't print the search form if search action has been disabled
if(!actionOk('search')) return false;
print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get"><div class="no">';
print '<input type="hidden" name="do" value="search" />';
print '<input class="" type="text" placeholder="'.$lang['btn_search'].'" ';
if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
if(!$autocomplete) print 'autocomplete="off" ';
print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';
print '<button type="submit" value="" class="btn btn-default" title="'.$lang['btn_search'].'">';
print '<i class="glyphicon glyphicon-search"></i></button>';
if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
print '</div></form>';
return true;
}
/**
* Define how the user related content is shown.
* When not logged in, login / register is shown
* When logged in the user's name is printed with a dropdown of user related options
*
* @author Paul in 't Hout <[email protected]>
**/
function _tpl_userinfo($element='li') {
global $INFO;
if(isset($_SERVER['REMOTE_USER'])) {
echo '<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">'.hsc($INFO['userinfo']['name']).'<b class="caret"></b></a>';
echo '<ul class="dropdown-menu">';
tpl_action('admin', 1, $element);
tpl_action('profile', 1, $element);
tpl_action('login', 1, $element);
echo '</ul>';
echo '</li>';
}else{
tpl_action('login', 1, $element, 0, '', '', 'Login / Register');
}
}
// debug web
function dw($message) {
print "<pre>";
if (is_array($message)) {
print_r($message);
}else{
print $message;
}
print "<pre>";
}