forked from arsava/dokuwiki-template-mnml-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.php
450 lines (410 loc) · 19.1 KB
/
main.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<?php
/**
* Main file of the "mnml-blog" template for DokuWiki
*
*
* LICENSE: This file is open source software (OSS) and may be copied under
* certain conditions. See COPYING file for details or try to contact
* the author(s) of this file in doubt.
*
* @license GPLv2 (http://www.gnu.org/licenses/gpl2.html)
* @author ARSAVA <[email protected]>
* @link https://www.dokuwiki.org/template:mnml-blog
* @link https://www.dokuwiki.org/devel:templates
* @link https://www.dokuwiki.org/devel:coding_style
* @link https://www.dokuwiki.org/devel:environment
* @link https://www.dokuwiki.org/devel:action_modes
*/
//check if we are running within the DokuWiki environment
if (!defined("DOKU_INC")){
die();
}
/**
* Stores the name the current client used to login
*
* @var string
* @author ARSAVA <[email protected]>
*/
$loginname = "";
if (!empty($conf["useacl"])){
if (isset($_SERVER["REMOTE_USER"]) && //no empty() but isset(): "0" may be a valid username...
$_SERVER["REMOTE_USER"] !== ""){
$loginname = $_SERVER["REMOTE_USER"]; //$INFO["client"] would not work here (-> e.g. when
//current IP differs from the one used to login)
}
}
//get needed language array
include DOKU_TPLINC."lang/en/lang.php";
//overwrite English language values with available translations
if (!empty($conf["lang"]) &&
$conf["lang"] != "en" &&
file_exists(DOKU_TPLINC."/lang/".$conf["lang"]."/lang.php")){
//get language file (partially translated language files are no problem
//cause non translated stuff is still existing as English array value)
include DOKU_TPLINC."/lang/".$conf["lang"]."/lang.php";
}
//detect revision
$rev = (int)$INFO["rev"]; //$INFO comes from the DokuWiki core
if ($rev < 1){
$rev = (int)$INFO["lastmod"];
}
//get boxes config
if (file_exists(DOKU_TPLINC."/user/boxes.php")){ //user defined
include DOKU_TPLINC."/user/boxes.php";
}
//add box for QR Code of current page's URL (powered by <http://goqr.me/api/>)
if (tpl_getConf("mnmlblog_qrcodebox")){
$_mnmlblog_boxes["qrcode"]["headline"] = $lang["mnmlblog_qrcodebox_qrcode"];
$_mnmlblog_boxes["qrcode"]["xhtml"] = "<span class=\"qrcode\">".((cleanID(getID()) === "start") ? "<a href=\"http://".(($conf["lang"] !== "de") ? "goqr.me" : "goqr.me/de")."/\" target=\"_blank\">" : "")."<img src=\"".((!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === "on") ? "https" : "http")."://api.qrserver.com/v1/create-qr-code/?data=".urlencode(wl(cleanID(getId()), false, true, "&"))."&size=190x190&margin=0&bgcolor=ffffff\" alt=\"".hsc($lang["mnmlblog_qrcodebox_qrcode"])." ".hsc(tpl_pagetitle(null, true))." (".hsc($lang["mnmlblog_qrcodebox_genforcurrentpage"]).")\" title=\"".hsc($lang["mnmlblog_qrcodebox_urlofcurrentpage"])."\" />".((cleanID(getID()) === "start") ? "</a>" : "")."</span>";
}
/**
* Helper to render the boxes (like a dynamic XHTML snippet)
*
* @param array The box data to render within the snippet. Each box is
* represented through an subarray:
* $array = array("box-id1" => array("headline" => "hello world!",
* "xhtml" => "I am <i>here</i>."));
* Available keys within the subarrays:
* - "xhtml" (mandatory)
* The content of the Box you want to show as XHTML. Attention: YOU
* HAVE TO TAKE CARE ABOUT FILTER EVENTUALLY USED INPUT/SECURITY. Be
* aware of XSS and stuff.
* - "headline" (optional)
* Headline to show above the box. Leave empty/do not set for none.
* @author ARSAVA <[email protected]>
* @link http://www.wikipedia.org/wiki/Nofollow
* @link http://www.wikipedia.org/wiki/Cross-site_scripting
* @link https://www.dokuwiki.org/devel:coding_style
*/
function _mnmlblog_renderBoxes($arr)
{
//is there something useful?
if (empty($arr) ||
!is_array($arr)){
return false; //nope, break operation
}
//array to store the created boxes into
$boxes = array();
//handle the box data
foreach($arr as $div_id => $contents){
//basic check
if (empty($contents) ||
!is_array($contents) ||
!isset($contents["xhtml"])){
continue; //ignore invalid stuff and go on
}
$interim = "\n <div class=\"sidebarbox\" id=\"".hsc($div_id)."\">\n";
if (!empty($contents["headline"])){
$interim .= " <h5 class=\"hspec\">".hsc($contents["headline"])."</h5>\n";
}
$interim .= " <div class=\"level1\">".$contents["xhtml"]."</div>"
."\n </div>\n\n";
//store it
$boxes[] = $interim;
}
//show everything created
if (!empty($boxes)){
foreach ($boxes as $box){
echo $box;
}
}
return true;
}
//workaround for the "jumping textarea" IE bug. CSS only fix not possible cause
//some DokuWiki JavaScript is triggering this bug, too. See the following for
//info:
//- <http://blog.andreas-haerter.com/2010/05/28/fix-msie-8-auto-scroll-textarea-css-width-percentage-bug>
//- <http://msdn.microsoft.com/library/cc817574.aspx>
if ($ACT === "edit" &&
!headers_sent()){
header("X-UA-Compatible: IE=EmulateIE7");
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo hsc($conf["lang"]); ?>" lang="<?php echo hsc($conf["lang"]); ?>" dir="<?php echo hsc($lang["direction"]); ?>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php tpl_pagetitle(); echo " - ".hsc($conf["title"]); ?></title>
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /><![endif]-->
<?php
//show meta-tags
tpl_metaheaders();
echo "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\" />";
//include default or userdefined favicon
//
//note: since 2011-04-22 "Rincewind RC1", there is a core function named
// "tpl_getFavicon()". But its functionality is not really fitting the
// behaviour of this template, therefore I don't use it here exclusively.
if (file_exists(DOKU_TPLINC."user/favicon.ico")){
//user defined - you might find http://tools.dynamicdrive.com/favicon/
//useful to generate one
echo "\n<link rel=\"shortcut icon\" href=\"".DOKU_TPL."user/favicon.ico\" />\n";
}elseif (file_exists(DOKU_TPLINC."user/favicon.png")){
//note: I do NOT recommend PNG for favicons (cause it is not supported by
//all browsers).
echo "\n<link rel=\"shortcut icon\" href=\"".DOKU_TPL."user/favicon.png\" />\n";
}else{
//default
echo "\n<link rel=\"shortcut icon\" href=\"".(function_exists("tpl_getFavicon") ? tpl_getFavicon() : DOKU_TPL."images/favicon.ico")."\" />\n";
}
//include default or userdefined Apple Touch Icon (see <http://j.mp/sx3NMT> for
//details)
if (file_exists(DOKU_TPLINC."user/apple-touch-icon.png")){
echo "<link rel=\"apple-touch-icon\" href=\"".DOKU_TPL."user/apple-touch-icon.png\" />\n";
}else{
//default
echo "<link rel=\"apple-touch-icon\" href=\"".(function_exists("tpl_getFavicon") ? tpl_getFavicon(false, "apple-touch-icon.png") : DOKU_TPL."images/apple-touch-icon.png")."\" />\n";
}
//load userdefined js?
if (tpl_getConf("mnmlblog_loaduserjs") && file_exists(DOKU_TPLINC."user/user.js")){
echo "<script type=\"text/javascript\" charset=\"utf-8\" src=\"".DOKU_TPL."user/user.js\"></script>\n";
}
?>
<!--[if lte IE 8]><link rel="stylesheet" media="all" type="text/css" href="<?php echo DOKU_TPL; ?>css/mnml-blog_screen_iehacks.css" /><![endif]-->
<!--[if lt IE 7]><style type="text/css">img { behavior: url(<?php echo DOKU_TPL; ?>js/iepngfix/iepngfix.htc); }</style><![endif]-->
</head>
<body>
<div id="pagewrap"<?php
if ($ACT !== "show" && //speed up: check most common action first
($ACT === "admin" ||
$ACT === "conflict" ||
$ACT === "diff" ||
$ACT === "draft" ||
$ACT === "edit" ||
$ACT === "media" ||
$ACT === "preview" ||
$ACT === "save")){
echo " class=\"admin\"";
} ?>>
<!-- start header -->
<div id="tmpl_header">
<?php
//include userdefined logo or show text-headline
echo "<a href=\"".DOKU_BASE."\" name=\"dokuwiki__top\" id=\"dokuwiki__top\" accesskey=\"h\"";
if (file_exists(DOKU_TPLINC."user/logo.png")){
//user defined PNG
echo "><img src=\"".DOKU_TPL."user/logo.png\" id=\"tmpl_header_logo_img\" alt=\"\"/></a>\n";
}elseif (file_exists(DOKU_TPLINC."user/logo.gif")){
//user defined GIF
echo "><img src=\"".DOKU_TPL."user/logo.gif\" id=\"tmpl_header_logo_img\" alt=\"\"/></a>\n";
}elseif (file_exists(DOKU_TPLINC."user/logo.jpg")){
//user defined JPG
echo "><img src=\"".DOKU_TPL."user/logo.jpg\" id=\"tmpl_header_logo_img\" alt=\"\"/></a>\n";
}else{
//default
echo " class=\"tmpl_header_logo_txt\">".hsc($conf["title"])."</a>\n";
}
//show header navigation?
if (tpl_getConf("mnmlblog_headernav")){
echo "\n <div id=\"tmpl_header_nav\">\n";
//we have to show a custom navigation
if (empty($conf["useacl"]) ||
auth_quickaclcheck(cleanID(tpl_getConf("mnmlblog_headernav_location")))){ //current user got access?
//get the rendered content of the defined wiki article to use as custom navigation
$interim = tpl_include_page(tpl_getConf("mnmlblog_headernav_location"), false);
if ($interim === "" ||
$interim === false){
//show creation/edit link if the defined page got no content
echo "[ ";
tpl_pagelink(tpl_getConf("mnmlblog_headernav_location"), hsc($lang["mnmlblog_fillplaceholder"]." (".tpl_getConf("mnmlblog_headernav_location").")"));
echo " ]<br />";
}else{
//show the rendered page content
echo $interim;
}
}
if (tpl_getConf("mnmlblog_search") &&
tpl_getConf("mnmlblog_search_pos") === "headernav"){
echo "\n <div id=\"tmpl_header_nav_search\" class=\"dokuwiki\">\n";
tpl_searchform();
echo "\n </div>\n";
}
echo " <div class=\"clearer\"></div>\n </div>\n";
}
?>
<div class="clearer"></div>
</div>
<!-- end header -->
<!-- start main content area -->
<div class="dokuwiki">
<?php html_msgarea(); ?>
<!-- start left col -->
<div id="content"<?php echo (($ACT === "media") ? " class=\"mediamanagerfix\"" : ""); ?>>
<div class="page">
<!-- start rendered page content -->
<?php
//send already created content to get a faster page rendering on the client
tpl_flush();
//show page content
tpl_content(false);
?>
<!-- end rendered page content -->
<div class="clearer"></div>
</div>
</div>
<!-- end left col -->
<?php
//send already created content to get a faster page rendering on the client
tpl_flush();
?>
<!-- start right col -->
<div id="tmpl_sidebar">
<?php
//show sidebar navigation?
if (tpl_getConf("mnmlblog_sidebarnav")){
echo "\n <div class=\"sidebarnav\">\n";
//we have to show a custom navigation
if (empty($conf["useacl"]) ||
auth_quickaclcheck(cleanID(tpl_getConf("mnmlblog_sidebarnav_location")))){ //current user got access?
//get the rendered content of the defined wiki article to use as custom navigation
$interim = tpl_include_page(tpl_getConf("mnmlblog_sidebarnav_location"), false);
if ($interim === "" ||
$interim === false){
//show creation/edit link if the defined page got no content
echo "[ ";
tpl_pagelink(tpl_getConf("mnmlblog_sidebarnav_location"), hsc($lang["mnmlblog_fillplaceholder"]." (".tpl_getConf("mnmlblog_sidebarnav_location").")"));
echo " ]<br />";
}else{
//show the rendered page content
echo $interim;
}
}
echo " </div>\n";
}
?>
<?php
if (tpl_getConf("mnmlblog_search") &&
tpl_getConf("mnmlblog_search_pos") === "sidebar"){
echo "\n <div id=\"search\" class=\"sidebarbox\">\n"
." <h5 class=\"hspec\">".hsc($lang["mnmlblog_search"])."</h5>\n"
." <div class=\"level1\">";
tpl_searchform();
echo "\n </div>\n </div>\n";
}?>
<?php
//show boxes, see mnml-blog/user/boxes.php to configure them
if (!empty($_mnmlblog_boxes) &&
is_array($_mnmlblog_boxes)){
_mnmlblog_renderBoxes($_mnmlblog_boxes);
}
//copyright notice
if (tpl_getConf("mnmlblog_copyright")){
echo "\n <div id=\"licenseinfo\">\n ";
if (tpl_getConf("mnmlblog_copyright_default")){
tpl_license(false);
}else{
if (empty($conf["useacl"]) ||
auth_quickaclcheck(cleanID(tpl_getConf("mnmlblog_copyright_location")))){ //current user got access?
//get the rendered content of the defined wiki article to use as custom notice
$interim = tpl_include_page(tpl_getConf("mnmlblog_copyright_location"), false);
if ($interim === "" ||
$interim === false){
//show creation/edit link if the defined page got no content
echo "[ ";
tpl_pagelink(tpl_getConf("mnmlblog_copyright_location"), hsc($lang["mnmlblog_fillplaceholder"]." (".tpl_getConf("mnmlblog_copyright_location").")"));
echo " ]<br />";
}else{
//show the rendered page content
echo $interim;
}
}
}
echo "\n </div>\n\n";
}
?>
<div class="clearer"></div>
</div>
<!-- end right col -->
<div class="clearer"></div>
<div id="tmpl_footer">
<div id="tmpl_footer_actlinksleft">
<?php
echo "[ ";
tpl_actionlink("top");
if (actionOK("index")){ //check if action is disabled
echo " | ";
tpl_actionlink("index");
}
echo " ]";
?>
</div>
<div id="tmpl_footer_actlinksright">
<?php
if (!empty($loginname) ||
!tpl_getConf("mnmlblog_hideadminlinksfromanon")){
echo "[ ";
tpl_actionlink("login"); //"login" handles both login/logout
if (!empty($INFO["writable"])){ //$INFO comes from DokuWiki core
echo " | ";
tpl_actionlink("edit"); //"edit" handles edit/create/show
}
if (!empty($INFO["exists"]) &&
actionOK("revisions")){ //check if action is disabled
echo " | ";
tpl_actionlink("revisions");
}
if (!empty($loginname) &&
$ACT === "show" &&
actionOK("subscribe")){ //check if action is disabled
echo " | ";
tpl_actionlink("subscribe");
}
if ((!empty($INFO["writable"]) || //$INFO comes from DokuWiki core
!empty($INFO["isadmin"]) || //purpose of this template are "non-wiki" websites, therefore show this link only to users with write permission and admins
!empty($INFO["ismanager"])) &&
actionOK("media") && //check if action is disabled
function_exists("media_managerURL")) { //new media manager is available on DokuWiki releases newer than 2011-05-25a "Rincewind" / since 2011-11-10 "Angua" RC1
echo " | ";
tpl_actionlink("media");
}
if (!empty($loginname)){
echo " | "
."<a href=\"".hsc(wl(cleanID(tpl_getConf("mnmlblog_newpostform_location"))))."\" rel=\"nofollow\">".hsc($lang["mnmlblog_lnk_newposting"])."</a>"; //create "new posting"
}else{
echo " | "
."<a href=\"".hsc(wl(cleanID(tpl_getConf("mnmlblog_newpostform_location")), array("do" => "login")))."\" rel=\"nofollow\">".hsc($lang["mnmlblog_lnk_newposting"])."</a>"; //show needed login before create "new posting"
}
if (!empty($INFO["isadmin"]) || //$INFO comes from DokuWiki core
!empty($INFO["ismanager"])){
echo " | ";
tpl_actionlink("admin");
}
if (!empty($loginname) &&
actionOK("profile")){ //check if action is disabled
echo " | ";
tpl_actionlink("profile");
}
echo " ]";
}else{
echo " ";
}
?>
</div>
<div class="clearer"></div>
<div id="tmpl_footer_metainfo">
<?php
//Note: Please do NOT remove the following mnml-blog and/or DokuWiki link/notice. Thank you. :-)
echo "<a href=\"https://www.dokuwiki.org/template:mnml-blog\" target=\"_blank\"".((cleanID(getID()) === "start") ? "" : " rel=\"nofollow\"").">mnml-blog on DW</a> under the hood\n";
if (!empty($loginname)){
echo " | ";
tpl_pageinfo();
echo " | ";
tpl_userinfo();
}
?>
</div>
</div>
</div>
<!-- end main content area -->
<div class="clearer"></div>
<?php
//provide DokuWiki housekeeping, required in all templates
tpl_indexerWebBug();
//include web analytics software
if (file_exists(DOKU_TPLINC."/user/tracker.php")){
include DOKU_TPLINC."/user/tracker.php";
}
?>
</div>
</body>
</html>