Subversion Repositories oidplus

Rev

Rev 462 | Rev 474 | 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
} else {
95
        $theme = 'default';
96
}
97
 
364 daniel-mar 98
if (file_exists(__DIR__ . '/userdata/styles/oidplus_base.css')) {
473 daniel-mar 99
        // There is a user defined CSS (not recommended, use design plugins instead!)
364 daniel-mar 100
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_base.css');
287 daniel-mar 101
} else {
473 daniel-mar 102
        // Use CSS of the design plugin
103
        OIDplus::registerAllPlugins('design', 'OIDplusDesignPlugin', array('OIDplus','registerDesignPlugin'));
104
        $plugins = OIDplus::getDesignPlugins();
105
        foreach ($plugins as $plugin) {
106
                if ((basename($plugin->getPluginDirectory())) == $theme) {
107
                        $manifest = $plugin->getManifest();
108
                        foreach ($manifest->getCSSFiles() as $css_file) {
109
                                $out .= process_file($css_file);
110
                        }
111
                }
112
        }
287 daniel-mar 113
}
142 daniel-mar 114
 
411 daniel-mar 115
// Then plugins
307 daniel-mar 116
$manifests = OIDplus::getAllPluginManifests('*Pages', true);
117
foreach ($manifests as $manifest) {
118
        foreach ($manifest->getCSSFiles() as $css_file) {
119
                $out .= process_file($css_file);
277 daniel-mar 120
        }
142 daniel-mar 121
}
122
 
411 daniel-mar 123
// Now user-defined definitions
124
if (file_exists(__DIR__ . '/userdata/styles/oidplus_add.css')) {
125
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_add.css');
126
}
142 daniel-mar 127
 
128
# ---
129
 
286 daniel-mar 130
$inv = isset($_REQUEST['invert']) ? $_REQUEST['invert'] : 0;
131
if ($inv != 0) {
132
        $out = invertColorsOfCSS($out);
133
}
134
 
142 daniel-mar 135
$hs = isset($_REQUEST['h_shift']) ? $_REQUEST['h_shift'] : 0;
136
$ss = isset($_REQUEST['s_shift']) ? $_REQUEST['s_shift'] : 0;
137
$vs = isset($_REQUEST['v_shift']) ? $_REQUEST['v_shift'] : 0;
286 daniel-mar 138
if (($hs != 0) ||($ss != 0) || ($vs != 0)) {
139
        $out = changeHueOfCSS($out, $hs, $ss, $vs);
140
}
142 daniel-mar 141
 
142
# ---
143
 
379 daniel-mar 144
httpOutWithETag($out, 'text/css', 'oidplus.css');