Subversion Repositories oidplus

Rev

Rev 448 | Rev 473 | 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';
26
require_once __DIR__ . '/3p/minify/src/Minify.php';
27
require_once __DIR__ . '/3p/minify/src/CSS.php';
28
require_once __DIR__ . '/3p/minify/src/Exception.php';
29
 
462 daniel-mar 30
error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0);
112 daniel-mar 31
 
142 daniel-mar 32
$out = '';
112 daniel-mar 33
 
142 daniel-mar 34
# ---
112 daniel-mar 35
 
420 daniel-mar 36
$do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true);
37
 
142 daniel-mar 38
function process_file($filename) {
420 daniel-mar 39
        global $do_minify;
40
 
462 daniel-mar 41
        $filename_min = preg_replace('/\.[^.]+$/', '.min.css', $filename);
42
        $filename_full = $filename;
429 daniel-mar 43
 
420 daniel-mar 44
        if ($do_minify) {
462 daniel-mar 45
                if (file_exists($filename_min)) {
46
                        // There is a file which is already minified
47
                        $filename = $filename_min;
48
                        $cont = file_get_contents($filename);
49
                } else if (file_exists($filename_full)) {
50
                        // Otherwise, we minify it ourself
51
                        $filename = $filename_full;
52
                        $minifier = new Minify\CSS($filename);
53
                        $cont = $minifier->minify();
54
                } else {
55
                        return;
56
                }
142 daniel-mar 57
        } else {
462 daniel-mar 58
                if (file_exists($filename_full)) {
59
                        $filename = $filename_full;
60
                        $cont = file_get_contents($filename);
61
                } else if (file_exists($filename_min)) {
62
                        $filename = $filename_min;
63
                        $cont = file_get_contents($filename);
64
                } else {
65
                        return;
66
                }
142 daniel-mar 67
        }
462 daniel-mar 68
 
69
        $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename);
368 daniel-mar 70
        $cont = preg_replace('@url\\(\s+@ism', 'url(', $cont);
71
        $cont = str_ireplace('url("data:', 'url###("data:', $cont);
72
        $cont = str_ireplace('url("', 'url###("'.$dir.'/', $cont);
73
        $cont = str_ireplace("url('data:", "url###('data:", $cont);
74
        $cont = str_ireplace("url('", "url###('".$dir.'/', $cont);
75
        $cont = str_ireplace("url(data:", "url###(data:", $cont);
76
        $cont = str_ireplace("url(", "url###(".$dir.'/', $cont);
142 daniel-mar 77
        $cont = str_ireplace("url###(", "url(", $cont);
261 daniel-mar 78
        return $cont."\n\n";
142 daniel-mar 79
}
112 daniel-mar 80
 
142 daniel-mar 81
# ---
112 daniel-mar 82
 
411 daniel-mar 83
// Third-party products
462 daniel-mar 84
$out .= process_file(__DIR__ . '/3p/jstree/themes/default/style.css');
85
$out .= process_file(__DIR__ . '/3p/jquery-ui/jquery-ui.css');
86
$out .= process_file(__DIR__ . '/3p/bootstrap4/css/bootstrap.css');
411 daniel-mar 87
 
448 daniel-mar 88
// Find out base CSS
89
if (isset($_REQUEST['theme'])) {
90
        $theme = $_REQUEST['theme'];
91
        if (strpos($theme,'/') !== false) $theme = 'default';
92
        if (strpos($theme,'\\') !== false) $theme = 'default';
93
        if (strpos($theme,'..') !== false) $theme = 'default';
94
        if (!is_dir(__DIR__.'/plugins/design/'.$theme)) $theme = 'default';
95
} else {
96
        $theme = 'default';
97
}
98
$base_css = __DIR__ . '/plugins/design/'.$theme.'/oidplus_base.css';
99
 
411 daniel-mar 100
// OIDplus basic definitions
364 daniel-mar 101
if (file_exists(__DIR__ . '/userdata/styles/oidplus_base.css')) {
102
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_base.css');
287 daniel-mar 103
} else {
448 daniel-mar 104
        $out .= process_file($base_css);
287 daniel-mar 105
}
142 daniel-mar 106
 
411 daniel-mar 107
// Then plugins
307 daniel-mar 108
$manifests = OIDplus::getAllPluginManifests('*Pages', true);
109
foreach ($manifests as $manifest) {
110
        foreach ($manifest->getCSSFiles() as $css_file) {
111
                $out .= process_file($css_file);
277 daniel-mar 112
        }
142 daniel-mar 113
}
114
 
411 daniel-mar 115
// Now user-defined definitions
116
if (file_exists(__DIR__ . '/userdata/styles/oidplus_add.css')) {
117
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_add.css');
118
}
142 daniel-mar 119
 
120
# ---
121
 
286 daniel-mar 122
$inv = isset($_REQUEST['invert']) ? $_REQUEST['invert'] : 0;
123
if ($inv != 0) {
124
        $out = invertColorsOfCSS($out);
125
}
126
 
142 daniel-mar 127
$hs = isset($_REQUEST['h_shift']) ? $_REQUEST['h_shift'] : 0;
128
$ss = isset($_REQUEST['s_shift']) ? $_REQUEST['s_shift'] : 0;
129
$vs = isset($_REQUEST['v_shift']) ? $_REQUEST['v_shift'] : 0;
286 daniel-mar 130
if (($hs != 0) ||($ss != 0) || ($vs != 0)) {
131
        $out = changeHueOfCSS($out, $hs, $ss, $vs);
132
}
142 daniel-mar 133
 
134
# ---
135
 
379 daniel-mar 136
httpOutWithETag($out, 'text/css', 'oidplus.css');