Subversion Repositories oidplus

Rev

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