Subversion Repositories oidplus

Rev

Rev 474 | Rev 486 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
112 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
20
use MatthiasMullie\Minify;
21
 
261 daniel-mar 22
require_once __DIR__ . '/includes/oidplus.inc.php';
462 daniel-mar 23
 
112 daniel-mar 24
require_once __DIR__ . '/3p/minify/path-converter/ConverterInterface.php';
25
require_once __DIR__ . '/3p/minify/path-converter/Converter.php';
474 daniel-mar 26
require_once __DIR__ . '/3p/minify/php-fig-cache/CacheItemInterface.php';
112 daniel-mar 27
require_once __DIR__ . '/3p/minify/src/Minify.php';
28
require_once __DIR__ . '/3p/minify/src/CSS.php';
29
require_once __DIR__ . '/3p/minify/src/Exception.php';
30
 
462 daniel-mar 31
error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0);
112 daniel-mar 32
 
142 daniel-mar 33
$out = '';
112 daniel-mar 34
 
142 daniel-mar 35
# ---
112 daniel-mar 36
 
420 daniel-mar 37
$do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true);
38
 
142 daniel-mar 39
function process_file($filename) {
420 daniel-mar 40
        global $do_minify;
41
 
462 daniel-mar 42
        $filename_min = preg_replace('/\.[^.]+$/', '.min.css', $filename);
43
        $filename_full = $filename;
429 daniel-mar 44
 
420 daniel-mar 45
        if ($do_minify) {
462 daniel-mar 46
                if (file_exists($filename_min)) {
47
                        // There is a file which is already minified
48
                        $filename = $filename_min;
49
                        $cont = file_get_contents($filename);
50
                } else if (file_exists($filename_full)) {
51
                        // Otherwise, we minify it ourself
52
                        $filename = $filename_full;
53
                        $minifier = new Minify\CSS($filename);
54
                        $cont = $minifier->minify();
55
                } else {
56
                        return;
57
                }
142 daniel-mar 58
        } else {
462 daniel-mar 59
                if (file_exists($filename_full)) {
60
                        $filename = $filename_full;
61
                        $cont = file_get_contents($filename);
62
                } else if (file_exists($filename_min)) {
63
                        $filename = $filename_min;
64
                        $cont = file_get_contents($filename);
65
                } else {
66
                        return;
67
                }
142 daniel-mar 68
        }
462 daniel-mar 69
 
70
        $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename);
368 daniel-mar 71
        $cont = preg_replace('@url\\(\s+@ism', 'url(', $cont);
72
        $cont = str_ireplace('url("data:', 'url###("data:', $cont);
73
        $cont = str_ireplace('url("', 'url###("'.$dir.'/', $cont);
74
        $cont = str_ireplace("url('data:", "url###('data:", $cont);
75
        $cont = str_ireplace("url('", "url###('".$dir.'/', $cont);
76
        $cont = str_ireplace("url(data:", "url###(data:", $cont);
77
        $cont = str_ireplace("url(", "url###(".$dir.'/', $cont);
142 daniel-mar 78
        $cont = str_ireplace("url###(", "url(", $cont);
261 daniel-mar 79
        return $cont."\n\n";
142 daniel-mar 80
}
112 daniel-mar 81
 
142 daniel-mar 82
# ---
112 daniel-mar 83
 
411 daniel-mar 84
// Third-party products
462 daniel-mar 85
$out .= process_file(__DIR__ . '/3p/jstree/themes/default/style.css');
86
$out .= process_file(__DIR__ . '/3p/jquery-ui/jquery-ui.css');
87
$out .= process_file(__DIR__ . '/3p/bootstrap4/css/bootstrap.css');
411 daniel-mar 88
 
448 daniel-mar 89
// Find out base CSS
90
if (isset($_REQUEST['theme'])) {
91
        $theme = $_REQUEST['theme'];
92
        if (strpos($theme,'/') !== false) $theme = 'default';
93
        if (strpos($theme,'\\') !== false) $theme = 'default';
94
        if (strpos($theme,'..') !== false) $theme = 'default';
95
} else {
96
        $theme = 'default';
97
}
98
 
364 daniel-mar 99
if (file_exists(__DIR__ . '/userdata/styles/oidplus_base.css')) {
473 daniel-mar 100
        // There is a user defined CSS (not recommended, use design plugins instead!)
364 daniel-mar 101
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_base.css');
287 daniel-mar 102
} else {
473 daniel-mar 103
        // Use CSS of the design plugin
104
        OIDplus::registerAllPlugins('design', 'OIDplusDesignPlugin', array('OIDplus','registerDesignPlugin'));
105
        $plugins = OIDplus::getDesignPlugins();
106
        foreach ($plugins as $plugin) {
107
                if ((basename($plugin->getPluginDirectory())) == $theme) {
108
                        $manifest = $plugin->getManifest();
109
                        foreach ($manifest->getCSSFiles() as $css_file) {
110
                                $out .= process_file($css_file);
111
                        }
112
                }
113
        }
287 daniel-mar 114
}
142 daniel-mar 115
 
411 daniel-mar 116
// Then plugins
307 daniel-mar 117
$manifests = OIDplus::getAllPluginManifests('*Pages', true);
118
foreach ($manifests as $manifest) {
119
        foreach ($manifest->getCSSFiles() as $css_file) {
120
                $out .= process_file($css_file);
277 daniel-mar 121
        }
142 daniel-mar 122
}
123
 
474 daniel-mar 124
// Now user-defined (additional) definitions
411 daniel-mar 125
if (file_exists(__DIR__ . '/userdata/styles/oidplus_add.css')) {
126
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_add.css');
127
}
142 daniel-mar 128
 
129
# ---
130
 
286 daniel-mar 131
$inv = isset($_REQUEST['invert']) ? $_REQUEST['invert'] : 0;
132
if ($inv != 0) {
133
        $out = invertColorsOfCSS($out);
134
}
135
 
142 daniel-mar 136
$hs = isset($_REQUEST['h_shift']) ? $_REQUEST['h_shift'] : 0;
137
$ss = isset($_REQUEST['s_shift']) ? $_REQUEST['s_shift'] : 0;
138
$vs = isset($_REQUEST['v_shift']) ? $_REQUEST['v_shift'] : 0;
286 daniel-mar 139
if (($hs != 0) ||($ss != 0) || ($vs != 0)) {
140
        $out = changeHueOfCSS($out, $hs, $ss, $vs);
141
}
142 daniel-mar 142
 
143
# ---
144
 
481 daniel-mar 145
if (OIDplus::baseConfig()->getValue('DEBUG')) {
146
        // In debug mode, we might get PHP error messages (see "error_reporting" above),
147
        // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!)
148
        header('Content-Type:text/css');
149
        echo $out;
150
} else {
151
        httpOutWithETag($out, 'text/css', 'oidplus.css');
152
}