Subversion Repositories oidplus

Rev

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