1<?php
2
3/**
4 * DokuWiki Bootstrap3 Template: CSS Asset Dispatcher
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
11# NOTE Some Linux distributon change the location of DokuWiki core libraries (DOKU_INC)
12#
13#      Bitnami (Docker)         /opt/bitnami/dokuwiki
14#      LinuxServer.io (Docker)  /app/dokuwiki
15#      Arch Linux               /usr/share/webapps/dokuwiki
16#      Debian/Ubuntu            /usr/share/dokuwiki
17#
18# NOTE If DokuWiki core libraries (DOKU_INC) is in another location you can
19#      create a PHP file in bootstrap3 root directory called "doku_inc.php" with
20#      this content:
21#
22#           <?php define('DOKU_INC', '/path/dokuwiki/');
23#
24#      (!) This file will be deleted on every upgrade of template
25
26$doku_inc_dirs = array(
27    '/opt/bitnami/dokuwiki',                      # Bitnami (Docker)
28    '/usr/share/webapps/dokuwiki',                # Arch Linux
29    '/usr/share/dokuwiki',                        # Debian/Ubuntu
30    '/app/dokuwiki',                              # LinuxServer.io (Docker),
31    realpath(dirname(__FILE__) . '/../../../'),   # Default DokuWiki path
32);
33
34# Load doku_inc.php file
35#
36if (file_exists(dirname(__FILE__) . '/doku_inc.php')) {
37    require_once dirname(__FILE__) . '/doku_inc.php';
38}
39
40if (! defined('DOKU_INC')) {
41    foreach ($doku_inc_dirs as $dir) {
42        if (! defined('DOKU_INC') && @file_exists("$dir/inc/init.php")) {
43            define('DOKU_INC', "$dir/");
44        }
45    }
46}
47
48
49// we do not use a session or authentication here (better caching)
50
51if (!defined('NOSESSION')) {
52    define('NOSESSION', true);
53}
54
55if (!defined('NL')) {
56    define('NL', "\n");
57}
58
59// we gzip ourself here
60
61if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) {
62    define('DOKU_DISABLE_GZIP_OUTPUT', 1);
63}
64
65function css_error($error)
66{
67    echo "html:before {
68        content: '$error';
69        background-color: red;
70        display: block;
71        background-color: #fcc;
72        border-color: #ebb;
73        color: #000;
74        padding: 0.5em;
75    }";
76}
77
78// TODO remove this cache-control in future
79header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
80header("Cache-Control: post-check=0, pre-check=0", false);
81header("Pragma: no-cache");
82header('Content-Type: text/css; charset=utf-8');
83
84if (!file_exists(DOKU_INC)) {
85    $error = 'Problem with DOKU_INC directory. Please check your DokuWiki installation directory!';
86    css_error($error);
87    die;
88}
89
90require_once DOKU_INC . 'inc/init.php';
91
92global $INPUT;
93global $conf;
94global $ID;
95
96$ID = cleanID($INPUT->str('id', null));
97
98$bootstrap_theme    = tpl_getConf('bootstrapTheme');
99$bootswatch_theme   = tpl_getConf('bootswatchTheme');
100$custom_theme       = tpl_getConf('customTheme');
101$theme_by_namespace = tpl_getConf('themeByNamespace');
102$tpl_basedir        = tpl_basedir();
103$tpl_incdir         = tpl_incdir();
104$themes_filename    = DOKU_CONF . 'bootstrap3.themes.conf';
105$stylesheets        = array();
106$bootswatch_themes  = array('cerulean', 'cosmo', 'cyborg', 'darkly', 'flatly', 'journal', 'lumen', 'paper', 'readable', 'sandstone', 'simplex', 'solar', 'slate', 'spacelab', 'superhero', 'united', 'yeti');
107
108# Check Theme Switcher
109if (tpl_getConf('showThemeSwitcher')) {
110    if (get_doku_pref('bootswatchTheme', null) !== null && get_doku_pref('bootswatchTheme', null) !== '') {
111        $bootswatch_theme = get_doku_pref('bootswatchTheme', null);
112    }
113
114    if (!in_array($bootswatch_theme, $bootswatch_themes)) {
115        $bootswatch_theme = 'default';
116    }
117}
118
119# Check Theme by Namespace
120if ($theme_by_namespace && file_exists($themes_filename)) {
121    $config = confToHash($themes_filename);
122    krsort($config);
123    $theme_found = false;
124
125    foreach ($config as $page => $theme) {
126        if (preg_match("/^$page/", "$ID")) {
127            list($bootstrap_theme, $bootswatch_theme) = explode('/', $theme);
128
129            if ($bootstrap_theme && in_array($bootstrap_theme, array('default', 'optional', 'custom'))) {
130                $theme_found = true;
131                break;
132            }
133
134            if ($bootstrap_theme == 'bootswatch' && in_array($bootswatch_theme, $bootswatch_themes)) {
135                $theme_found = true;
136                break;
137            }
138        }
139    }
140}
141
142# Check $ID and unload the template
143if ($theme_by_namespace && file_exists($themes_filename) && !$ID) {
144    $bootstrap_theme = 'none';
145}
146
147switch ($bootstrap_theme) {
148    case 'optional':
149        $stylesheets[] = 'assets/bootstrap/default/bootstrap.min.css';
150        $stylesheets[] = 'assets/bootstrap/default/bootstrap-theme.min.css';
151        break;
152
153    case 'custom':
154        $stylesheets[] = $custom_theme;
155        break;
156
157    case 'bootswatch':
158
159        $bootswatch_url = 'assets/bootstrap';
160
161        if (file_exists($tpl_incdir . "assets/fonts/$bootswatch_theme.fonts.css")) {
162            $stylesheets[] = "assets/fonts/$bootswatch_theme.fonts.css";
163        }
164
165        $stylesheets[] = "$bootswatch_url/$bootswatch_theme/bootstrap.min.css";
166        break;
167
168    case 'none':
169        break;
170
171    case 'default':
172    default:
173        $stylesheets[] = 'assets/bootstrap/default/bootstrap.min.css';
174        break;
175}
176
177$content = '';
178
179foreach ($stylesheets as $style) {
180    $content .= "@import url($style);" . NL;
181}
182
183print $content;
184