forked from selfthinker/dokuwiki_template_writr
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tpl_functions.php
239 lines (218 loc) · 9.3 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
227
228
229
230
231
232
233
234
235
236
237
238
239
<?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();
/**
* Generate the HTML for the Site-Branding Area
*
* @return string
*/
if (!function_exists('tpl_getSiteBranding')) {
function tpl_getSiteBranding()
{
// Retrieve the global variables
global $ID,$conf;
// Initialize the return value
$return = '';
// Initialize the site branding configurations
$logoSize = array();
$logoImages = array();
if(tpl_getConf('doLogoChangesByNamespace')){
$namespace = "";
$namespaces = array();
foreach(explode(':',getNS($ID)) as $ns){
$namespace .= "$ns:";
$namespaces[] = $namespace;
}
foreach(array_reverse($namespaces) as $namespace){
$logoImages[] = ":".trim($namespace,":").":logo.png";
}
}
$logoImages[] = ':logo.png';
$logoImages[] = ':wiki:logo.png';
$logoImages[] = 'images/logo.png';
$logo = tpl_getMediaFile($logoImages, false, $logoSize);
$link = wl();
if(tpl_getConf('doLogoLinkChangesByNamespace')){
$link = str_replace(['/_media','logo.png'],['',$conf['start']],$logo);
}
$title = $conf['title'];
if(tpl_getConf('doTitleChangesByNamespace')){
$nstitle = tpl_include_page('nstitle', 0, 1);
if ($nstitle) {
$title = str_replace(['<p>','</p>',"\n"],'',$nstitle);
}
}
$tagline = $conf['tagline'];
if(tpl_getConf('doTaglineChangesByNamespace')){
$nstagline = tpl_include_page('nstagline', 0, 1);
if ($nstagline) {
$tagline = str_replace(['<p>','</p>',"\n"],'',$nstagline);
}
}
// Initialize the logo
$return .= '<a class="site-logo" href="'.$link.'" title="'.$title.'" rel="home" accesskey="h">';
$return .= '<img src="'.$logo.'" '.$logoSize[3].' class="no-grav header-image" />';
$return .= '</a>';
// Initialize the site branding
$return .= '<div class="site-branding">';
$return .= '<h1 class="site-title"><a href="'.$link.'" rel="home" accesskey="h" title="'.$title.'">'.$title.'</a></h1>';
if($tagline){
$return .= '<h2 class="site-description">'.$tagline.'</h2>';
}
$return .= '</div>';
return $return;
}
}
/**
* Generate the gravatar URL for a given email
*
* @return string
*/
if (!function_exists('tpl_getGravatarURL')) {
function tpl_getGravatarURL($email, $size = 96)
{
return 'https://www.gravatar.com/avatar/'.md5(strtolower(trim($email))).'?s='.$size;
}
}
/**
* Generate the HTML for a menu
*
* @return string
*/
if (!function_exists('tpl_getMenu')) {
function tpl_getMenu($menu)
{
switch($menu){
case 'usermenu':
return tpl_getUserMenu();
break;
case 'sidebarmenu':
return tpl_getSidebarMenu();
break;
}
}
}
/**
* Generate the HTML for the user menu
*
* @return string
*/
if (!function_exists('tpl_getUserMenu')) {
function tpl_getUserMenu()
{
global $lang,$ID,$conf,$INFO;
$return = '';
$items = (new \dokuwiki\Menu\UserMenu())->getItems();
if(isset($INFO['userinfo'])){
$return .= '<div class="tools-menus">';
$return .= '<div class="dropdown user-tools">';
$return .= '<a href="'.wl($ID).'" class="dropdown-toggle" title="'.$lang['user_tools'].'" data-target="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">';
$return .= '<i class="bi bi-person"></i>'.$INFO['userinfo']['name'];
$return .= '</a>';
$return .= '<ul class="dropdown-menu" role="menu">';
$return .= '<li>';
$return .= '<p class="avatar">';
$return .= '<img alt="'.$INFO['userinfo']['name'].'" src="'.tpl_getGravatarURL($INFO['userinfo']['mail']).'" />';
$return .= '</p>';
$return .= '</li>';
foreach($items as $item) {
$return .= '<li>'
.'<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">'
.'<i></i> '
.$item->getLabel()
.'</a></li>';
}
$return .= '</ul>';
$return .= '</div>';
if(tpl_getConf('enableStarredBookmark')){
if (!plugin_isdisabled('sqlite')) {
if (!plugin_isdisabled('starred')) {
$return .= '<div class="dropdown bookmarks">';
$return .= '<a href="#" class="dropdown-toggle starred" title="'.tpl_getLang('Bookmarks').'" data-target="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">';
$return .= '<i class="bi bi-star"></i>'.tpl_getLang('Bookmarks');
$return .= '</a>';
$return .= '<ul class="dropdown-menu" role="menu">';
$instructions = p_get_instructions('{{starred>min}}');
if(count($instructions) > 0) {
$render = p_render('xhtml',$instructions, $info);
// Sanitize the output
$render = preg_replace('/<div class="plugin_starred">/', '', $render);
$render = preg_replace('/<\/div>/', '', $render);
$render = preg_replace('/<div class="li">/', '', $render);
$render = preg_replace('/<\/div>/', '', $render);
$render = preg_replace('/<ul>/', '', $render);
$render = preg_replace('/<\/ul>/', '', $render);
$render = preg_replace('/<li class="level1">/', '<li>', $render);
$return .= $render;
}
$return .= '</ul>';
$return .= '</div>';
}
}
}
$return .= '</div>';
} else {
$return .= '<div class="inline user-tools">';
foreach($items as $item) {
$return .= '<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">'
.'<i></i> '
.$item->getLabel()
.'</a>';
}
$return .= '</div>';
}
return $return;
}
}
/**
* Generate the HTML for the sidebar menus
*
* @return string
*/
if (!function_exists('tpl_getSidebarMenu')) {
function tpl_getSidebarMenu()
{
global $lang,$ID,$conf,$INFO;
$userItems = (new \dokuwiki\Menu\UserMenu())->getItems();
$return = '';
$return .= '<div id="writr__sidebar__tools">';
if(isset($INFO['userinfo'])){
$return .= '<div class="user-tools">';
$return .= '<a href="'.wl($ID).'" class="" title="'.$lang['user_tools'].'" data-target="#user-tools-menu" data-toggle="collapse" role="button" aria-haspopup="true" aria-expanded="false">';
$return .= '<img alt="'.$INFO['userinfo']['name'].'" src="'.tpl_getGravatarURL($INFO['userinfo']['mail'], 32).'" />';
$return .= '<span>'.$INFO['userinfo']['name'].'</span>';
$return .= '</a>';
$return .= '<div id="user-tools-menu" class="collapsed">';
$return .= '<ul class="menu" role="menu">';
foreach($userItems as $item) {
$return .= '<li>'
.'<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">'
.'<i></i> '
.$item->getLabel()
.'</a></li>';
}
$return .= '</ul>';
$return .= '</div>';
$return .= '</div>';
} else {
$return .= '<div class="user-tools">';
foreach($userItems as $item) {
$return .= '<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">'
.'<i></i> '
.$item->getLabel()
.'</a>';
}
$return .= '</div>';
}
$return .= '</div>';
return $return;
}
}