This repository has been archived by the owner on Jan 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tpl_functions.php
161 lines (139 loc) · 4.64 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
<?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 discussion page and back
*
* @author Anika Henke <[email protected]>
*/
function _tpl_discussion($discussionPage, $title, $backTitle, $link=0, $wrapper=0) {
global $ID;
$discussPage = str_replace('@ID@', $ID, $discussionPage);
$discussPageRaw = str_replace('@ID@', '', $discussionPage);
$isDiscussPage = strpos($ID, $discussPageRaw) !== false;
$backID = ':'.str_replace($discussPageRaw, '', $ID);
if ($wrapper) echo "<$wrapper>";
if ($isDiscussPage) {
if ($link)
tpl_pagelink($backID, $backTitle);
else
echo html_btn('back2article', $backID, '', array(), 'get', 0, $backTitle);
} else {
if ($link)
tpl_pagelink($discussPage, $title);
else
echo html_btn('discussion', $discussPage, '', array(), 'get', 0, $title);
}
if ($wrapper) echo "</$wrapper>";
}
/**
* Create link/button to user page
*
* @author Anika Henke <[email protected]>
*/
function _tpl_userpage($userPage, $title, $link=0, $wrapper=0) {
if (empty($_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 'discussion':
if (tpl_getConf('discussionPage')) {
_tpl_discussion(tpl_getConf('discussionPage'), tpl_getLang('discussion'), tpl_getLang('back_to_article'), $link, $wrapper);
}
break;
case 'userpage':
if (tpl_getConf('userPage')) {
_tpl_userpage(tpl_getConf('userPage'), tpl_getLang('userpage'), $link, $wrapper);
}
break;
}
}
/**
* Create event for tools menues
*
* @author Anika Henke <[email protected]>
*/
function _tpl_toolsevent($toolsname, $items, $view='main') {
$data = array(
'view' => $view,
'items' => $items
);
$hook = 'TEMPLATE_'.strtoupper($toolsname).'_DISPLAY';
$evt = new Doku_Event($hook, $data);
if($evt->advise_before()){
foreach($evt->data['items'] as $k => $html) echo $html;
}
$evt->advise_after();
}
/**
* copied from core (available since Binky)
*/
if (!function_exists('tpl_classes')) {
function tpl_classes() {
global $ACT, $conf, $ID, $INFO;
$classes = array(
'dokuwiki',
'mode_'.$ACT,
'tpl_'.$conf['template'],
!empty($_SERVER['REMOTE_USER']) ? 'loggedIn' : '',
$INFO['exists'] ? '' : 'notFound',
($ID == $conf['start']) ? 'home' : '',
);
return join(' ', $classes);
}
}
/**
* Special Functions for this template
*
* @author Florian Wehner <[email protected]>
*
*/
// If output exists, put the content of $before and $after around it
function _tpl_check_if_output_and_amend($before="", $tpl_function="", $after="") {
ob_start();
eval($tpl_function.";");
$function_output = ob_get_clean();
if(strlen($function_output)==0) return false;
print $before;
print $function_output;
print $after;
return true;
}
// Copied and adjusted from core for navbar search form
function _tpl_draw_searchform($ajax = true, $autocomplete = true) {
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" role="search"><div class="field">';
print '<input type="hidden" name="do" value="search" />';
print '<input type="search" ';
if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
if(!$autocomplete) print 'autocomplete="off" ';
print 'id="qsearch__in" accesskey="f" name="id" class="search input" title="[F]" placeholder="'.$lang['btn_search'].'"/>';
if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
print '</div></form>';
return true;
}