Subversion Repositories oidplus

Rev

Rev 419 | Rev 429 | 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
 
215 daniel-mar 40
        $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename);
420 daniel-mar 41
        if ($do_minify) {
215 daniel-mar 42
                $minifier = new Minify\CSS($filename);
142 daniel-mar 43
                $cont = $minifier->minify();
44
        } else {
215 daniel-mar 45
                $cont = file_get_contents($filename);
142 daniel-mar 46
        }
368 daniel-mar 47
        $cont = preg_replace('@url\\(\s+@ism', 'url(', $cont);
48
        $cont = str_ireplace('url("data:', 'url###("data:', $cont);
49
        $cont = str_ireplace('url("', 'url###("'.$dir.'/', $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);
142 daniel-mar 54
        $cont = str_ireplace("url###(", "url(", $cont);
261 daniel-mar 55
        return $cont."\n\n";
142 daniel-mar 56
}
112 daniel-mar 57
 
142 daniel-mar 58
# ---
112 daniel-mar 59
 
411 daniel-mar 60
// Third-party products
420 daniel-mar 61
$out .= process_file(__DIR__ . '/3p/jstree/themes/default/style'.($do_minify ? '.min' : '').'.css');
62
$out .= process_file(__DIR__ . '/3p/jquery-ui/jquery-ui'.($do_minify ? '.min' : '').'.css');
63
$out .= process_file(__DIR__ . '/3p/bootstrap4/css/bootstrap'.($do_minify ? '.min' : '').'.css');
411 daniel-mar 64
 
65
// OIDplus basic definitions
364 daniel-mar 66
if (file_exists(__DIR__ . '/userdata/styles/oidplus_base.css')) {
67
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_base.css');
287 daniel-mar 68
} else {
69
        $out .= process_file(__DIR__ . '/oidplus_base.css');
70
}
142 daniel-mar 71
 
411 daniel-mar 72
// Then plugins
307 daniel-mar 73
$manifests = OIDplus::getAllPluginManifests('*Pages', true);
74
foreach ($manifests as $manifest) {
75
        foreach ($manifest->getCSSFiles() as $css_file) {
76
                $out .= process_file($css_file);
277 daniel-mar 77
        }
142 daniel-mar 78
}
79
 
411 daniel-mar 80
// Now user-defined definitions
81
if (file_exists(__DIR__ . '/userdata/styles/oidplus_add.css')) {
82
        $out .= process_file(__DIR__ . '/userdata/styles/oidplus_add.css');
83
}
142 daniel-mar 84
 
85
# ---
86
 
286 daniel-mar 87
$inv = isset($_REQUEST['invert']) ? $_REQUEST['invert'] : 0;
88
if ($inv != 0) {
89
        $out = invertColorsOfCSS($out);
90
}
91
 
142 daniel-mar 92
$hs = isset($_REQUEST['h_shift']) ? $_REQUEST['h_shift'] : 0;
93
$ss = isset($_REQUEST['s_shift']) ? $_REQUEST['s_shift'] : 0;
94
$vs = isset($_REQUEST['v_shift']) ? $_REQUEST['v_shift'] : 0;
286 daniel-mar 95
if (($hs != 0) ||($ss != 0) || ($vs != 0)) {
96
        $out = changeHueOfCSS($out, $hs, $ss, $vs);
97
}
142 daniel-mar 98
 
99
# ---
100
 
379 daniel-mar 101
httpOutWithETag($out, 'text/css', 'oidplus.css');