Rev 1116 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
364 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
364 | 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; |
||
1050 | daniel-mar | 21 | use ViaThinkSoft\OIDplus\OIDplus; |
364 | daniel-mar | 22 | |
23 | require_once __DIR__ . '/../includes/oidplus.inc.php'; |
||
462 | daniel-mar | 24 | |
25 | error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0); |
||
585 | daniel-mar | 26 | @ini_set('display_errors', OIDplus::baseConfig()->getValue('DEBUG') ? '1' : '0'); |
364 | daniel-mar | 27 | |
28 | $out = ''; |
||
29 | |||
30 | # --- |
||
31 | |||
429 | daniel-mar | 32 | $do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true); |
33 | |||
1130 | daniel-mar | 34 | /** |
35 | * @param string $filename |
||
36 | * @return string |
||
37 | */ |
||
38 | function process_file(string $filename): string { |
||
429 | daniel-mar | 39 | global $do_minify; |
40 | |||
1116 | daniel-mar | 41 | if (!file_exists($filename)) return ""; |
429 | daniel-mar | 42 | |
490 | daniel-mar | 43 | $thisdir = __DIR__; |
44 | $thisdir = str_replace('\\', '/', $thisdir); // change Windows Backslashes into Web-Slashes |
||
45 | $filename = str_replace('\\', '/', $filename); // change Windows Backslashes into Web-Slashes |
||
46 | $dir = dirname((strpos($filename, $thisdir.'/') === 0) ? substr($filename, strlen($thisdir.'/')) : $filename); |
||
47 | |||
429 | daniel-mar | 48 | if ($do_minify) { |
364 | daniel-mar | 49 | $minifier = new Minify\CSS($filename); |
50 | $cont = $minifier->minify(); |
||
51 | $cont = str_ireplace("url(data:", "url###(data:", $cont); |
||
52 | $cont = str_ireplace("url(", "url(".$dir.'/', $cont); |
||
53 | } else { |
||
54 | $cont = file_get_contents($filename); |
||
55 | $cont = str_ireplace('url("data:', 'url###("data:', $cont); |
||
56 | $cont = str_ireplace('url("', 'url("'.$dir.'/', $cont); |
||
57 | $cont = str_ireplace("url('data:", "url###('data:", $cont); |
||
58 | $cont = str_ireplace("url('", "url('".$dir.'/', $cont); |
||
59 | } |
||
60 | $cont = str_ireplace("url###(", "url(", $cont); |
||
61 | return $cont."\n\n"; |
||
62 | } |
||
63 | |||
64 | # --- |
||
65 | |||
411 | daniel-mar | 66 | // Third-party products |
67 | // (None) |
||
380 | daniel-mar | 68 | |
411 | daniel-mar | 69 | // OIDplus basic definitions |
364 | daniel-mar | 70 | if (file_exists(__DIR__ . '/../userdata/styles/setup_base.css')) { |
71 | $out .= process_file(__DIR__ . '/../userdata/styles/setup_base.css'); |
||
72 | } else { |
||
456 | daniel-mar | 73 | $out .= process_file(__DIR__ . '/includes/setup_base.css'); |
364 | daniel-mar | 74 | } |
75 | |||
411 | daniel-mar | 76 | // Then plugins |
702 | daniel-mar | 77 | $manifests = OIDplus::getAllPluginManifests('database,captcha', true); |
411 | daniel-mar | 78 | foreach ($manifests as $manifest) { |
79 | foreach ($manifest->getCSSFilesSetup() as $css_file) { |
||
80 | $out .= process_file($css_file); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | // Now user-defined definitions |
||
366 | daniel-mar | 85 | if (file_exists(__DIR__ . '/userdata/styles/setup_add.css')) { |
86 | $out .= process_file(__DIR__ . '/userdata/styles/setup_add.css'); |
||
87 | } |
||
88 | |||
364 | daniel-mar | 89 | # --- |
90 | |||
481 | daniel-mar | 91 | if (OIDplus::baseConfig()->getValue('DEBUG')) { |
92 | // In debug mode, we might get PHP error messages (see "error_reporting" above), |
||
93 | // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!) |
||
94 | header('Content-Type:text/css'); |
||
95 | echo $out; |
||
96 | } else { |
||
97 | httpOutWithETag($out, 'text/css', 'oidplus_setup.css'); |
||
98 | } |