1<?php
2
3/**
4 * Main file of the "mnml-blog" template for DokuWiki
5 *
6 *
7 * LICENSE: This file is open source software (OSS) and may be copied under
8 *          certain conditions. See COPYING file for details or try to contact
9 *          the author(s) of this file in doubt.
10 *
11 * @license GPLv2 (http://www.gnu.org/licenses/gpl2.html)
12 * @author ARSAVA <dokuwiki@dev.arsava.com>
13 * @link https://www.dokuwiki.org/template:mnml-blog
14 * @link https://www.dokuwiki.org/devel:templates
15 * @link https://www.dokuwiki.org/devel:coding_style
16 * @link https://www.dokuwiki.org/devel:environment
17 * @link https://www.dokuwiki.org/devel:action_modes
18 */
19
20
21//check if we are running within the DokuWiki environment
22if (!defined("DOKU_INC")){
23    die();
24}
25
26
27/**
28 * Stores the name the current client used to login
29 *
30 * @var string
31 * @author ARSAVA <dokuwiki@dev.arsava.com>
32 */
33$loginname = "";
34if (!empty($conf["useacl"])){
35    if (isset($_SERVER["REMOTE_USER"]) && //no empty() but isset(): "0" may be a valid username...
36        $_SERVER["REMOTE_USER"] !== ""){
37        $loginname = $_SERVER["REMOTE_USER"]; //$INFO["client"] would not work here (-> e.g. when
38                                              //current IP differs from the one used to login)
39    }
40}
41
42
43//get needed language array
44include DOKU_TPLINC."lang/en/lang.php";
45//overwrite English language values with available translations
46if (!empty($conf["lang"]) &&
47    $conf["lang"] != "en" &&
48    file_exists(DOKU_TPLINC."/lang/".$conf["lang"]."/lang.php")){
49    //get language file (partially translated language files are no problem
50    //cause non translated stuff is still existing as English array value)
51    include DOKU_TPLINC."/lang/".$conf["lang"]."/lang.php";
52}
53
54
55//detect revision
56$rev = (int)$INFO["rev"]; //$INFO comes from the DokuWiki core
57if ($rev < 1){
58    $rev = (int)$INFO["lastmod"];
59}
60
61
62//get boxes config
63if (file_exists(DOKU_TPLINC."/user/boxes.php")){ //user defined
64   include DOKU_TPLINC."/user/boxes.php";
65}
66//add box for QR Code of current page's URL (powered by <http://goqr.me/api/>)
67if (tpl_getConf("mnmlblog_qrcodebox")){
68    $_mnmlblog_boxes["qrcode"]["headline"] = $lang["mnmlblog_qrcodebox_qrcode"];
69    $_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, "&"))."&#38;size=190x190&#38;margin=0&#38;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>";
70}
71
72
73/**
74 * Helper to render the boxes (like a dynamic XHTML snippet)
75 *
76 * @param array The box data to render within the snippet. Each box is
77 *        represented through an subarray:
78 *        $array = array("box-id1" => array("headline" => "hello world!",
79 *                                          "xhtml"    => "I am <i>here</i>."));
80 *        Available keys within the subarrays:
81 *        - "xhtml" (mandatory)
82 *          The content of the Box you want to show as XHTML. Attention: YOU
83 *          HAVE TO TAKE CARE ABOUT FILTER EVENTUALLY USED INPUT/SECURITY. Be
84 *          aware of XSS and stuff.
85 *        - "headline" (optional)
86 *          Headline to show above the box. Leave empty/do not set for none.
87 * @author ARSAVA <dokuwiki@dev.arsava.com>
88 * @link http://www.wikipedia.org/wiki/Nofollow
89 * @link http://www.wikipedia.org/wiki/Cross-site_scripting
90 * @link https://www.dokuwiki.org/devel:coding_style
91 */
92function _mnmlblog_renderBoxes($arr)
93{
94    //is there something useful?
95    if (empty($arr) ||
96        !is_array($arr)){
97        return false; //nope, break operation
98    }
99
100    //array to store the created boxes into
101    $boxes = array();
102
103    //handle the box data
104    foreach($arr as $div_id => $contents){
105        //basic check
106        if (empty($contents) ||
107            !is_array($contents) ||
108            !isset($contents["xhtml"])){
109            continue; //ignore invalid stuff and go on
110        }
111        $interim  = "\n            <div class=\"sidebarbox\" id=\"".hsc($div_id)."\">\n";
112        if (!empty($contents["headline"])){
113            $interim .= "                <h5 class=\"hspec\">".hsc($contents["headline"])."</h5>\n";
114        }
115        $interim .= "                <div class=\"level1\">".$contents["xhtml"]."</div>"
116                   ."\n            </div>\n\n";
117        //store it
118        $boxes[] = $interim;
119    }
120    //show everything created
121    if (!empty($boxes)){
122        foreach ($boxes as $box){
123            echo $box;
124        }
125    }
126
127    return true;
128}
129
130//workaround for the "jumping textarea" IE bug. CSS only fix not possible cause
131//some DokuWiki JavaScript is triggering this bug, too. See the following for
132//info:
133//- <http://blog.andreas-haerter.com/2010/05/28/fix-msie-8-auto-scroll-textarea-css-width-percentage-bug>
134//- <http://msdn.microsoft.com/library/cc817574.aspx>
135if ($ACT === "edit" &&
136    !headers_sent()){
137    header("X-UA-Compatible: IE=EmulateIE7");
138}
139
140?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
141  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
142<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"]); ?>">
143<head>
144<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
145<title><?php tpl_pagetitle(); echo " - ".hsc($conf["title"]); ?></title>
146<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /><![endif]-->
147<?php
148//show meta-tags
149tpl_metaheaders();
150echo "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\" />";
151
152//include default or userdefined favicon
153//
154//note: since 2011-04-22 "Rincewind RC1", there is a core function named
155//      "tpl_getFavicon()". But its functionality is not really fitting the
156//      behaviour of this template, therefore I don't use it here exclusively.
157if (file_exists(DOKU_TPLINC."user/favicon.ico")){
158    //user defined - you might find http://tools.dynamicdrive.com/favicon/
159    //useful to generate one
160    echo "\n<link rel=\"shortcut icon\" href=\"".DOKU_TPL."user/favicon.ico\" />\n";
161}elseif (file_exists(DOKU_TPLINC."user/favicon.png")){
162    //note: I do NOT recommend PNG for favicons (cause it is not supported by
163    //all browsers).
164    echo "\n<link rel=\"shortcut icon\" href=\"".DOKU_TPL."user/favicon.png\" />\n";
165}else{
166    //default
167    echo "\n<link rel=\"shortcut icon\" href=\"".(function_exists("tpl_getFavicon") ? tpl_getFavicon() : DOKU_TPL."images/favicon.ico")."\" />\n";
168}
169
170//include default or userdefined Apple Touch Icon (see <http://j.mp/sx3NMT> for
171//details)
172if (file_exists(DOKU_TPLINC."user/apple-touch-icon.png")){
173    echo "<link rel=\"apple-touch-icon\" href=\"".DOKU_TPL."user/apple-touch-icon.png\" />\n";
174}else{
175    //default
176    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";
177}
178
179//load userdefined js?
180if (tpl_getConf("mnmlblog_loaduserjs") && file_exists(DOKU_TPLINC."user/user.js")){
181    echo "<script type=\"text/javascript\" charset=\"utf-8\" src=\"".DOKU_TPL."user/user.js\"></script>\n";
182}
183?>
184<!--[if lte IE 8]><link rel="stylesheet" media="all" type="text/css" href="<?php echo DOKU_TPL; ?>css/mnml-blog_screen_iehacks.css" /><![endif]-->
185<!--[if lt IE 7]><style type="text/css">img { behavior: url(<?php echo DOKU_TPL; ?>js/iepngfix/iepngfix.htc); }</style><![endif]-->
186</head>
187
188<body>
189<div id="pagewrap"<?php
190    if ($ACT !== "show" && //speed up: check most common action first
191        ($ACT === "admin" ||
192         $ACT === "conflict" ||
193         $ACT === "diff" ||
194         $ACT === "draft" ||
195         $ACT === "edit" ||
196         $ACT === "media" ||
197         $ACT === "preview" ||
198         $ACT === "save")){
199        echo " class=\"admin\"";
200    } ?>>
201
202    <!-- start header -->
203    <div id="tmpl_header">
204        <?php
205        //include userdefined logo or show text-headline
206        echo "<a href=\"".DOKU_BASE."\" name=\"dokuwiki__top\" id=\"dokuwiki__top\" accesskey=\"h\"";
207        if (file_exists(DOKU_TPLINC."user/logo.png")){
208            //user defined PNG
209            echo "><img src=\"".DOKU_TPL."user/logo.png\" id=\"tmpl_header_logo_img\" alt=\"\"/></a>\n";
210        }elseif (file_exists(DOKU_TPLINC."user/logo.gif")){
211            //user defined GIF
212            echo "><img src=\"".DOKU_TPL."user/logo.gif\" id=\"tmpl_header_logo_img\" alt=\"\"/></a>\n";
213        }elseif (file_exists(DOKU_TPLINC."user/logo.jpg")){
214            //user defined JPG
215            echo "><img src=\"".DOKU_TPL."user/logo.jpg\" id=\"tmpl_header_logo_img\" alt=\"\"/></a>\n";
216        }else{
217            //default
218            echo " class=\"tmpl_header_logo_txt\">".hsc($conf["title"])."</a>\n";
219        }
220
221        //show header navigation?
222        if (tpl_getConf("mnmlblog_headernav")){
223            echo "\n       <div id=\"tmpl_header_nav\">\n";
224            //we have to show a custom navigation
225            if (empty($conf["useacl"]) ||
226                auth_quickaclcheck(cleanID(tpl_getConf("mnmlblog_headernav_location")))){ //current user got access?
227                //get the rendered content of the defined wiki article to use as custom navigation
228                $interim = tpl_include_page(tpl_getConf("mnmlblog_headernav_location"), false);
229                if ($interim === "" ||
230                    $interim === false){
231                    //show creation/edit link if the defined page got no content
232                    echo "[&#160;";
233                    tpl_pagelink(tpl_getConf("mnmlblog_headernav_location"), hsc($lang["mnmlblog_fillplaceholder"]." (".tpl_getConf("mnmlblog_headernav_location").")"));
234                    echo "&#160;]<br />";
235                }else{
236                   //show the rendered page content
237                   echo $interim;
238                }
239            }
240            if (tpl_getConf("mnmlblog_search") &&
241                tpl_getConf("mnmlblog_search_pos") === "headernav"){
242                echo "\n            <div id=\"tmpl_header_nav_search\" class=\"dokuwiki\">\n";
243                tpl_searchform();
244                echo "\n            </div>\n";
245            }
246            echo "            <div class=\"clearer\"></div>\n        </div>\n";
247        }
248        ?>
249        <div class="clearer"></div>
250    </div>
251    <!-- end header -->
252
253
254    <!-- start main content area -->
255    <div class="dokuwiki">
256        <?php html_msgarea(); ?>
257
258        <!-- start left col -->
259        <div id="content"<?php echo (($ACT === "media") ? " class=\"mediamanagerfix\"" : ""); ?>>
260            <div class="page">
261
262
263<!-- start rendered page content -->
264<?php
265//send already created content to get a faster page rendering on the client
266tpl_flush();
267//show page content
268tpl_content(false);
269?>
270<!-- end rendered page content -->
271<div class="clearer"></div>
272
273
274            </div>
275        </div>
276        <!-- end left col -->
277        <?php
278        //send already created content to get a faster page rendering on the client
279        tpl_flush();
280        ?>
281
282        <!-- start right col -->
283        <div id="tmpl_sidebar">
284            <?php
285            //show sidebar navigation?
286            if (tpl_getConf("mnmlblog_sidebarnav")){
287                echo "\n            <div class=\"sidebarnav\">\n";
288                //we have to show a custom navigation
289                if (empty($conf["useacl"]) ||
290                    auth_quickaclcheck(cleanID(tpl_getConf("mnmlblog_sidebarnav_location")))){ //current user got access?
291              //get the rendered content of the defined wiki article to use as custom navigation
292                    $interim = tpl_include_page(tpl_getConf("mnmlblog_sidebarnav_location"), false);
293                    if ($interim === "" ||
294                        $interim === false){
295                        //show creation/edit link if the defined page got no content
296                        echo "[&#160;";
297                        tpl_pagelink(tpl_getConf("mnmlblog_sidebarnav_location"), hsc($lang["mnmlblog_fillplaceholder"]." (".tpl_getConf("mnmlblog_sidebarnav_location").")"));
298                        echo "&#160;]<br />";
299                    }else{
300                       //show the rendered page content
301                       echo $interim;
302                    }
303                }
304                echo "            </div>\n";
305            }
306            ?>
307
308
309            <?php
310            if (tpl_getConf("mnmlblog_search") &&
311                tpl_getConf("mnmlblog_search_pos") === "sidebar"){
312                echo  "\n            <div id=\"search\" class=\"sidebarbox\">\n"
313                     ."                <h5 class=\"hspec\">".hsc($lang["mnmlblog_search"])."</h5>\n"
314                     ."                <div class=\"level1\">";
315                tpl_searchform();
316                echo "\n                </div>\n            </div>\n";
317            }?>
318
319            <?php
320            //show boxes, see mnml-blog/user/boxes.php to configure them
321            if (!empty($_mnmlblog_boxes) &&
322                 is_array($_mnmlblog_boxes)){
323                _mnmlblog_renderBoxes($_mnmlblog_boxes);
324            }
325
326            //copyright notice
327            if (tpl_getConf("mnmlblog_copyright")){
328                echo "\n            <div id=\"licenseinfo\">\n                ";
329                if (tpl_getConf("mnmlblog_copyright_default")){
330                    tpl_license(false);
331                }else{
332                    if (empty($conf["useacl"]) ||
333                        auth_quickaclcheck(cleanID(tpl_getConf("mnmlblog_copyright_location")))){ //current user got access?
334                        //get the rendered content of the defined wiki article to use as custom notice
335                        $interim = tpl_include_page(tpl_getConf("mnmlblog_copyright_location"), false);
336                        if ($interim === "" ||
337                            $interim === false){
338                            //show creation/edit link if the defined page got no content
339                            echo "[&#160;";
340                            tpl_pagelink(tpl_getConf("mnmlblog_copyright_location"), hsc($lang["mnmlblog_fillplaceholder"]." (".tpl_getConf("mnmlblog_copyright_location").")"));
341                            echo "&#160;]<br />";
342                        }else{
343                            //show the rendered page content
344                            echo $interim;
345                        }
346                    }
347                }
348                echo "\n            </div>\n\n";
349            }
350            ?>
351
352            <div class="clearer"></div>
353        </div>
354        <!-- end right col -->
355        <div class="clearer"></div>
356
357        <div id="tmpl_footer">
358            <div id="tmpl_footer_actlinksleft">
359                <?php
360                echo "[&#160;";
361                tpl_actionlink("top");
362                if (actionOK("index")){ //check if action is disabled
363                    echo "&#160;|&#160;";
364                    tpl_actionlink("index");
365                }
366                echo "&#160;]";
367                ?>
368            </div>
369            <div id="tmpl_footer_actlinksright">
370                <?php
371                if (!empty($loginname) ||
372                    !tpl_getConf("mnmlblog_hideadminlinksfromanon")){
373                    echo "[&#160;";
374                    tpl_actionlink("login"); //"login" handles both login/logout
375                    if (!empty($INFO["writable"])){ //$INFO comes from DokuWiki core
376                        echo "&#160;|&#160;";
377                        tpl_actionlink("edit"); //"edit" handles edit/create/show
378                    }
379                    if (!empty($INFO["exists"]) &&
380                        actionOK("revisions")){ //check if action is disabled
381                        echo "&#160;|&#160;";
382                        tpl_actionlink("revisions");
383                    }
384                    if (!empty($loginname) &&
385                        $ACT === "show" &&
386                        actionOK("subscribe")){ //check if action is disabled
387                        echo "&#160;|&#160;";
388                        tpl_actionlink("subscribe");
389                    }
390                    if ((!empty($INFO["writable"]) || //$INFO comes from DokuWiki core
391                         !empty($INFO["isadmin"]) || //purpose of this template are "non-wiki" websites, therefore show this link only to users with write permission and admins
392                         !empty($INFO["ismanager"])) &&
393                        actionOK("media") && //check if action is disabled
394                        function_exists("media_managerURL")) { //new media manager is available on DokuWiki releases newer than 2011-05-25a "Rincewind" / since 2011-11-10 "Angua" RC1
395                        echo "&#160;|&#160;";
396                        tpl_actionlink("media");
397                    }
398                    if (!empty($loginname)){
399                        echo  "&#160;|&#160;"
400                             ."<a href=\"".hsc(wl(cleanID(tpl_getConf("mnmlblog_newpostform_location"))))."\" rel=\"nofollow\">".hsc($lang["mnmlblog_lnk_newposting"])."</a>"; //create "new posting"
401                    }else{
402                        echo  "&#160;|&#160;"
403                             ."<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"
404                    }
405                    if (!empty($INFO["isadmin"]) ||  //$INFO comes from DokuWiki core
406                        !empty($INFO["ismanager"])){
407                        echo "&#160;|&#160;";
408                        tpl_actionlink("admin");
409                    }
410                    if (!empty($loginname) &&
411                        actionOK("profile")){ //check if action is disabled
412                        echo "&#160;|&#160;";
413                        tpl_actionlink("profile");
414                    }
415                    echo "&#160;]";
416                }else{
417                    echo "&#160;";
418                }
419                ?>
420            </div>
421            <div class="clearer"></div>
422            <div id="tmpl_footer_metainfo">
423                <?php
424                //Note: Please do NOT remove the following mnml-blog and/or DokuWiki link/notice. Thank you. :-)
425                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";
426                if (!empty($loginname)){
427                    echo " | ";
428                    tpl_pageinfo();
429                    echo " | ";
430                    tpl_userinfo();
431                }
432                ?>
433            </div>
434        </div>
435
436    </div>
437    <!-- end main content area -->
438    <div class="clearer"></div>
439    <?php
440    //provide DokuWiki housekeeping, required in all templates
441    tpl_indexerWebBug();
442    //include web analytics software
443    if (file_exists(DOKU_TPLINC."/user/tracker.php")){
444        include DOKU_TPLINC."/user/tracker.php";
445    }
446    ?>
447
448</div>
449</body>
450</html>
451