Subversion Repositories oidplus

Rev

Rev 490 | Rev 532 | 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
511 daniel-mar 5
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
112 daniel-mar 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);
486 daniel-mar 32
@ini_set('display_errors', OIDplus::baseConfig()->getValue('DEBUG') ? 1 : 0);
112 daniel-mar 33
 
142 daniel-mar 34
$out = '';
112 daniel-mar 35
 
142 daniel-mar 36
# ---
112 daniel-mar 37
 
420 daniel-mar 38
$do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true);
39
 
142 daniel-mar 40
function process_file($filename) {
420 daniel-mar 41
        global $do_minify;
42
 
462 daniel-mar 43
        $filename_min = preg_replace('/\.[^.]+$/', '.min.css', $filename);
44
        $filename_full = $filename;
429 daniel-mar 45
 
420 daniel-mar 46
        if ($do_minify) {
462 daniel-mar 47
                if (file_exists($filename_min)) {
48
                        // There is a file which is already minified
49
                        $filename = $filename_min;
50
                        $cont = file_get_contents($filename);
51
                } else if (file_exists($filename_full)) {
52
                        // Otherwise, we minify it ourself
53
                        $filename = $filename_full;
54
                        $minifier = new Minify\CSS($filename);
55
                        $cont = $minifier->minify();
56
                } else {
57
                        return;
58
                }
142 daniel-mar 59
        } else {
462 daniel-mar 60
                if (file_exists($filename_full)) {
61
                        $filename = $filename_full;
62
                        $cont = file_get_contents($filename);
63
                } else if (file_exists($filename_min)) {
64
                        $filename = $filename_min;
65
                        $cont = file_get_contents($filename);
66
                } else {
67
                        return;
68
                }
142 daniel-mar 69
        }
462 daniel-mar 70
 
490 daniel-mar 71
        $thisdir = __DIR__;
72
        $thisdir = str_replace('\\', '/', $thisdir); // change Windows Backslashes into Web-Slashes
73
        $filename = str_replace('\\', '/', $filename); // change Windows Backslashes into Web-Slashes
74
        $dir = dirname((strpos($filename, $thisdir.'/') === 0) ? substr($filename, strlen($thisdir.'/')) : $filename);
75
 
368 daniel-mar 76
        $cont = preg_replace('@url\\(\s+@ism', 'url(', $cont);
77
        $cont = str_ireplace('url("data:', 'url###("data:', $cont);
78
        $cont = str_ireplace('url("', 'url###("'.$dir.'/', $cont);
79
        $cont = str_ireplace("url('data:", "url###('data:", $cont);
80
        $cont = str_ireplace("url('", "url###('".$dir.'/', $cont);
81
        $cont = str_ireplace("url(data:", "url###(data:", $cont);
82
        $cont = str_ireplace("url(", "url###(".$dir.'/', $cont);
142 daniel-mar 83
        $cont = str_ireplace("url###(", "url(", $cont);
261 daniel-mar 84
        return $cont."\n\n";
142 daniel-mar 85
}
112 daniel-mar 86
 
142 daniel-mar 87
# ---
112 daniel-mar 88
 
411 daniel-mar 89
// Third-party products
462 daniel-mar 90
$out .= process_file(__DIR__ . '/3p/jstree/themes/default/style.css');
91
$out .= process_file(__DIR__ . '/3p/jquery-ui/jquery-ui.css');
92
$out .= process_file(__DIR__ . '/3p/bootstrap4/css/bootstrap.css');
411 daniel-mar 93
 
448 daniel-mar 94
// Find out base CSS
95
if (isset($_REQUEST['theme'])) {
96
        $theme = $_REQUEST['theme'];
97
        if (strpos($theme,'/') !== false) $theme = 'default';
98
        if (strpos($theme,'\\') !== false) $theme = 'default';
99
        if (strpos($theme,'..') !== false) $theme = 'default';
100
} else {
101
        $theme = 'default';
102
}
103
 
364 daniel-mar 104
if (file_exists(__DIR__ . '/userdata/styles/oidplus_base.css')) {
473 daniel-mar 105
        // There is a user defined CSS (not recommended, use design plugins instead!)
364 daniel-mar 106
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_base.css');
287 daniel-mar 107
} else {
473 daniel-mar 108
        // Use CSS of the design plugin
109
        OIDplus::registerAllPlugins('design', 'OIDplusDesignPlugin', array('OIDplus','registerDesignPlugin'));
110
        $plugins = OIDplus::getDesignPlugins();
111
        foreach ($plugins as $plugin) {
112
                if ((basename($plugin->getPluginDirectory())) == $theme) {
113
                        $manifest = $plugin->getManifest();
114
                        foreach ($manifest->getCSSFiles() as $css_file) {
115
                                $out .= process_file($css_file);
116
                        }
117
                }
118
        }
287 daniel-mar 119
}
142 daniel-mar 120
 
411 daniel-mar 121
// Then plugins
307 daniel-mar 122
$manifests = OIDplus::getAllPluginManifests('*Pages', true);
123
foreach ($manifests as $manifest) {
124
        foreach ($manifest->getCSSFiles() as $css_file) {
125
                $out .= process_file($css_file);
277 daniel-mar 126
        }
142 daniel-mar 127
}
128
 
474 daniel-mar 129
// Now user-defined (additional) definitions
411 daniel-mar 130
if (file_exists(__DIR__ . '/userdata/styles/oidplus_add.css')) {
131
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_add.css');
132
}
142 daniel-mar 133
 
134
# ---
135
 
286 daniel-mar 136
$inv = isset($_REQUEST['invert']) ? $_REQUEST['invert'] : 0;
137
if ($inv != 0) {
138
        $out = invertColorsOfCSS($out);
139
}
140
 
142 daniel-mar 141
$hs = isset($_REQUEST['h_shift']) ? $_REQUEST['h_shift'] : 0;
142
$ss = isset($_REQUEST['s_shift']) ? $_REQUEST['s_shift'] : 0;
143
$vs = isset($_REQUEST['v_shift']) ? $_REQUEST['v_shift'] : 0;
286 daniel-mar 144
if (($hs != 0) ||($ss != 0) || ($vs != 0)) {
145
        $out = changeHueOfCSS($out, $hs, $ss, $vs);
146
}
142 daniel-mar 147
 
148
# ---
149
 
481 daniel-mar 150
if (OIDplus::baseConfig()->getValue('DEBUG')) {
151
        // In debug mode, we might get PHP error messages (see "error_reporting" above),
152
        // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!)
153
        header('Content-Type:text/css');
154
        echo $out;
155
} else {
156
        httpOutWithETag($out, 'text/css', 'oidplus.css');
157
}