Subversion Repositories oidplus

Rev

Rev 429 | Rev 462 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 429 Rev 448
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OIDplus 2.0
4
 * OIDplus 2.0
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
6
 *
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with 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
9
 * You may obtain a copy of the License at
10
 *
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
17
 * limitations under the License.
18
 */
18
 */
19
 
19
 
20
use MatthiasMullie\Minify;
20
use MatthiasMullie\Minify;
21
 
21
 
22
require_once __DIR__ . '/includes/oidplus.inc.php';
22
require_once __DIR__ . '/includes/oidplus.inc.php';
23
require_once __DIR__ . '/3p/minify/path-converter/ConverterInterface.php';
23
require_once __DIR__ . '/3p/minify/path-converter/ConverterInterface.php';
24
require_once __DIR__ . '/3p/minify/path-converter/Converter.php';
24
require_once __DIR__ . '/3p/minify/path-converter/Converter.php';
25
require_once __DIR__ . '/3p/minify/src/Minify.php';
25
require_once __DIR__ . '/3p/minify/src/Minify.php';
26
require_once __DIR__ . '/3p/minify/src/CSS.php';
26
require_once __DIR__ . '/3p/minify/src/CSS.php';
27
require_once __DIR__ . '/3p/minify/src/Exception.php';
27
require_once __DIR__ . '/3p/minify/src/Exception.php';
28
 
28
 
29
error_reporting(E_ALL);
29
error_reporting(E_ALL);
30
 
30
 
31
$out = '';
31
$out = '';
32
 
32
 
33
# ---
33
# ---
34
 
34
 
35
$do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true);
35
$do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true);
36
 
36
 
37
function process_file($filename) {
37
function process_file($filename) {
38
        global $do_minify;
38
        global $do_minify;
39
 
39
 
40
        if (!file_exists($filename)) return;
40
        if (!file_exists($filename)) return;
41
 
41
 
42
        $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename);
42
        $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename);
43
        if ($do_minify) {
43
        if ($do_minify) {
44
                $minifier = new Minify\CSS($filename);
44
                $minifier = new Minify\CSS($filename);
45
                $cont = $minifier->minify();
45
                $cont = $minifier->minify();
46
        } else {
46
        } else {
47
                $cont = file_get_contents($filename);
47
                $cont = file_get_contents($filename);
48
        }
48
        }
49
        $cont = preg_replace('@url\\(\s+@ism', 'url(', $cont);
49
        $cont = preg_replace('@url\\(\s+@ism', 'url(', $cont);
50
        $cont = str_ireplace('url("data:', 'url###("data:', $cont);
50
        $cont = str_ireplace('url("data:', 'url###("data:', $cont);
51
        $cont = str_ireplace('url("', 'url###("'.$dir.'/', $cont);
51
        $cont = str_ireplace('url("', 'url###("'.$dir.'/', $cont);
52
        $cont = str_ireplace("url('data:", "url###('data:", $cont);
52
        $cont = str_ireplace("url('data:", "url###('data:", $cont);
53
        $cont = str_ireplace("url('", "url###('".$dir.'/', $cont);
53
        $cont = str_ireplace("url('", "url###('".$dir.'/', $cont);
54
        $cont = str_ireplace("url(data:", "url###(data:", $cont);
54
        $cont = str_ireplace("url(data:", "url###(data:", $cont);
55
        $cont = str_ireplace("url(", "url###(".$dir.'/', $cont);
55
        $cont = str_ireplace("url(", "url###(".$dir.'/', $cont);
56
        $cont = str_ireplace("url###(", "url(", $cont);
56
        $cont = str_ireplace("url###(", "url(", $cont);
57
        return $cont."\n\n";
57
        return $cont."\n\n";
58
}
58
}
59
 
59
 
60
# ---
60
# ---
61
 
61
 
62
// Third-party products
62
// Third-party products
63
$out .= process_file(__DIR__ . '/3p/jstree/themes/default/style'.($do_minify ? '.min' : '').'.css');
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');
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');
65
$out .= process_file(__DIR__ . '/3p/bootstrap4/css/bootstrap'.($do_minify ? '.min' : '').'.css');
66
 
66
 
-
 
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
 
67
// OIDplus basic definitions
79
// OIDplus basic definitions
68
if (file_exists(__DIR__ . '/userdata/styles/oidplus_base.css')) {
80
if (file_exists(__DIR__ . '/userdata/styles/oidplus_base.css')) {
69
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_base.css');
81
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_base.css');
70
} else {
82
} else {
71
        $out .= process_file(__DIR__ . '/oidplus_base.css');
83
        $out .= process_file($base_css);
72
}
84
}
73
 
85
 
74
// Then plugins
86
// Then plugins
75
$manifests = OIDplus::getAllPluginManifests('*Pages', true);
87
$manifests = OIDplus::getAllPluginManifests('*Pages', true);
76
foreach ($manifests as $manifest) {
88
foreach ($manifests as $manifest) {
77
        foreach ($manifest->getCSSFiles() as $css_file) {
89
        foreach ($manifest->getCSSFiles() as $css_file) {
78
                $out .= process_file($css_file);
90
                $out .= process_file($css_file);
79
        }
91
        }
80
}
92
}
81
 
93
 
82
// Now user-defined definitions
94
// Now user-defined definitions
83
if (file_exists(__DIR__ . '/userdata/styles/oidplus_add.css')) {
95
if (file_exists(__DIR__ . '/userdata/styles/oidplus_add.css')) {
84
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_add.css');
96
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_add.css');
85
}
97
}
86
 
98
 
87
# ---
99
# ---
88
 
100
 
89
$inv = isset($_REQUEST['invert']) ? $_REQUEST['invert'] : 0;
101
$inv = isset($_REQUEST['invert']) ? $_REQUEST['invert'] : 0;
90
if ($inv != 0) {
102
if ($inv != 0) {
91
        $out = invertColorsOfCSS($out);
103
        $out = invertColorsOfCSS($out);
92
}
104
}
93
 
105
 
94
$hs = isset($_REQUEST['h_shift']) ? $_REQUEST['h_shift'] : 0;
106
$hs = isset($_REQUEST['h_shift']) ? $_REQUEST['h_shift'] : 0;
95
$ss = isset($_REQUEST['s_shift']) ? $_REQUEST['s_shift'] : 0;
107
$ss = isset($_REQUEST['s_shift']) ? $_REQUEST['s_shift'] : 0;
96
$vs = isset($_REQUEST['v_shift']) ? $_REQUEST['v_shift'] : 0;
108
$vs = isset($_REQUEST['v_shift']) ? $_REQUEST['v_shift'] : 0;
97
if (($hs != 0) ||($ss != 0) || ($vs != 0)) {
109
if (($hs != 0) ||($ss != 0) || ($vs != 0)) {
98
        $out = changeHueOfCSS($out, $hs, $ss, $vs);
110
        $out = changeHueOfCSS($out, $hs, $ss, $vs);
99
}
111
}
100
 
112
 
101
# ---
113
# ---
102
 
114
 
103
httpOutWithETag($out, 'text/css', 'oidplus.css');
115
httpOutWithETag($out, 'text/css', 'oidplus.css');
104
 
116