Subversion Repositories oidplus

Rev

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