1<?php
2
3/**
4 * DokuWiki Bootstrap3 Template: Compatibility functions
5 *
6 * @link     http://dokuwiki.org/template:bootstrap3
7 * @author   Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
8 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 */
10
11global $updateVersion;
12$dokuwiki_version = floatval($updateVersion);
13
14define('DOKU_VERSION', $dokuwiki_version);
15define('DOKU_VERSION_HOGFATHER',          51); // 2020-07-29
16define('DOKU_VERSION_GREEBO',             50); // 2018-04-22 (PHP >= 5.6)
17define('DOKU_VERSION_FRUSTERICK_MANNERS', 49); // 2017-02-19 (PHP >= 5.4 ???)
18define('DOKU_VERSION_ELENOR_OF_TSORT',    48); // 2016-06-26
19define('DOKU_VERSION_DETRITUS',           47); // 2015-08-10 (PHP >= 5.3.3)
20
21
22// Load compatibility Menu classes for pre-Greebo releases
23if (DOKU_VERSION > 0 && DOKU_VERSION < DOKU_VERSION_GREEBO) {
24
25    define('DOKU_INC_COMPAT', realpath(dirname(__FILE__) . '/../') . '/');
26
27    require DOKU_INC_COMPAT . "inc/Menu/MenuInterface.php";
28    require DOKU_INC_COMPAT . "inc/Menu/AbstractMenu.php";
29    require DOKU_INC_COMPAT . "inc/Menu/Item/AbstractItem.php";
30
31    require DOKU_INC_COMPAT . "inc/Menu/UserMenu.php";
32    require DOKU_INC_COMPAT . "inc/Menu/MobileMenu.php";
33    require DOKU_INC_COMPAT . "inc/Menu/PageMenu.php";
34    require DOKU_INC_COMPAT . "inc/Menu/SiteMenu.php";
35    require DOKU_INC_COMPAT . "inc/Menu/DetailMenu.php";
36
37    require DOKU_INC_COMPAT . "inc/Menu/Item/ImgBackto.php";
38    require DOKU_INC_COMPAT . "inc/Menu/Item/Top.php";
39    require DOKU_INC_COMPAT . "inc/Menu/Item/Edit.php";
40    require DOKU_INC_COMPAT . "inc/Menu/Item/Profile.php";
41    require DOKU_INC_COMPAT . "inc/Menu/Item/Revisions.php";
42    require DOKU_INC_COMPAT . "inc/Menu/Item/Backlink.php";
43    require DOKU_INC_COMPAT . "inc/Menu/Item/Back.php";
44    require DOKU_INC_COMPAT . "inc/Menu/Item/Login.php";
45    require DOKU_INC_COMPAT . "inc/Menu/Item/Index.php";
46    require DOKU_INC_COMPAT . "inc/Menu/Item/Register.php";
47    require DOKU_INC_COMPAT . "inc/Menu/Item/MediaManager.php";
48    require DOKU_INC_COMPAT . "inc/Menu/Item/Subscribe.php";
49    require DOKU_INC_COMPAT . "inc/Menu/Item/Recent.php";
50    require DOKU_INC_COMPAT . "inc/Menu/Item/Media.php";
51    require DOKU_INC_COMPAT . "inc/Menu/Item/Resendpwd.php";
52    require DOKU_INC_COMPAT . "inc/Menu/Item/Admin.php";
53    require DOKU_INC_COMPAT . "inc/Menu/Item/Revert.php";
54
55}
56
57// Load template class for previous "Frusterick Manners" (2017-02-19) releases
58if (DOKU_VERSION < DOKU_VERSION_FRUSTERICK_MANNERS) {
59
60    $tpl_incdir = tpl_incdir();
61
62    require $tpl_incdir . 'Template.php';
63    require $tpl_incdir . 'SVG.php';
64
65}
66
67/**
68 * copied from core (available since Greebo)
69 */
70if (!function_exists('inlineSVG')) {
71
72    function inlineSVG($file, $maxsize = 2048)
73    {
74        $file = trim($file);
75        if ($file === '') {
76            return false;
77        }
78
79        if (!file_exists($file)) {
80            return false;
81        }
82
83        if (filesize($file) > $maxsize) {
84            return false;
85        }
86
87        if (!is_readable($file)) {
88            return false;
89        }
90
91        $content = file_get_contents($file);
92        $content = preg_replace('/<!--.*?(-->)/s', '', $content); // comments
93        $content = preg_replace('/<\?xml .*?\?>/i', '', $content); // xml header
94        $content = preg_replace('/<!DOCTYPE .*?>/i', '', $content); // doc type
95        $content = preg_replace('/>\s+</s', '><', $content); // newlines between tags
96        $content = trim($content);
97        if (substr($content, 0, 5) !== '<svg ') {
98            return false;
99        }
100
101        return $content;
102    }
103
104}
105
106/**
107 * copied from core (available since Detritus)
108 */
109if (!function_exists('tpl_toolsevent')) {
110
111    function tpl_toolsevent($toolsname, $items, $view = 'main')
112    {
113        $data = array(
114            'view'  => $view,
115            'items' => $items,
116        );
117
118        $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY';
119        $evt  = new Doku_Event($hook, $data);
120
121        if ($evt->advise_before()) {
122            foreach ($evt->data['items'] as $k => $html) {
123                echo $html;
124            }
125        }
126        $evt->advise_after();
127    }
128
129}
130
131/**
132 * copied from core (available since Binky)
133 */
134if (!function_exists('tpl_classes')) {
135
136    function tpl_classes()
137    {
138        global $ACT, $conf, $ID, $INFO;
139
140        $classes = array(
141            'dokuwiki',
142            'mode_' . $ACT,
143            'tpl_' . $conf['template'],
144            !empty($_SERVER['REMOTE_USER']) ? 'loggedIn' : '',
145            $INFO['exists'] ? '' : 'notFound',
146            ($ID == $conf['start']) ? 'home' : '',
147        );
148
149        return join(' ', $classes);
150    }
151
152}
153
154/**
155 * copied from core (available since Detritus)
156 */
157if (!function_exists('plugin_getRequestAdminPlugin')) {
158
159    function plugin_getRequestAdminPlugin()
160    {
161        static $admin_plugin = false;
162        global $ACT, $INPUT, $INFO;
163
164        if ($admin_plugin === false) {
165            if (($ACT == 'admin') && ($page = $INPUT->str('page', '', true)) != '') {
166                $pluginlist = plugin_list('admin');
167                if (in_array($page, $pluginlist)) {
168                    // attempt to load the plugin
169                    /** @var $admin_plugin DokuWiki_Admin_Plugin */
170                    $admin_plugin = plugin_load('admin', $page);
171                    // verify
172                    if ($admin_plugin && $admin_plugin->forAdminOnly() && !$INFO['isadmin']) {
173                        $admin_plugin = null;
174                        $INPUT->remove('page');
175                        msg('For admins only', -1);
176                    }
177                }
178            }
179        }
180
181        return $admin_plugin;
182    }
183
184}
185