Subversion Repositories oidplus

Rev

Rev 490 | Rev 585 | 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;
21
 
22
require_once __DIR__ . '/../includes/oidplus.inc.php';
462 daniel-mar 23
 
364 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);
486 daniel-mar 31
@ini_set('display_errors', OIDplus::baseConfig()->getValue('DEBUG') ? 1 : 0);
364 daniel-mar 32
 
33
$out = '';
34
 
35
# ---
36
 
429 daniel-mar 37
$do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true);
38
 
364 daniel-mar 39
function process_file($filename) {
429 daniel-mar 40
        global $do_minify;
41
 
42
        if (!file_exists($filename)) return;
43
 
490 daniel-mar 44
        $thisdir = __DIR__;
45
        $thisdir = str_replace('\\', '/', $thisdir); // change Windows Backslashes into Web-Slashes
46
        $filename = str_replace('\\', '/', $filename); // change Windows Backslashes into Web-Slashes
47
        $dir = dirname((strpos($filename, $thisdir.'/') === 0) ? substr($filename, strlen($thisdir.'/')) : $filename);
48
 
429 daniel-mar 49
        if ($do_minify) {
364 daniel-mar 50
                $minifier = new Minify\CSS($filename);
51
                $cont = $minifier->minify();
52
                $cont = str_ireplace("url(data:", "url###(data:", $cont);
53
                $cont = str_ireplace("url(", "url(".$dir.'/', $cont);
54
        } else {
55
                $cont = file_get_contents($filename);
56
                $cont = str_ireplace('url("data:', 'url###("data:', $cont);
57
                $cont = str_ireplace('url("', 'url("'.$dir.'/', $cont);
58
                $cont = str_ireplace("url('data:", "url###('data:", $cont);
59
                $cont = str_ireplace("url('", "url('".$dir.'/', $cont);
60
        }
61
        $cont = str_ireplace("url###(", "url(", $cont);
62
        return $cont."\n\n";
63
}
64
 
65
# ---
66
 
411 daniel-mar 67
// Third-party products
68
// (None)
380 daniel-mar 69
 
411 daniel-mar 70
// OIDplus basic definitions
364 daniel-mar 71
if (file_exists(__DIR__ . '/../userdata/styles/setup_base.css')) {
72
        $out .= process_file(__DIR__ . '/../userdata/styles/setup_base.css');
73
} else {
456 daniel-mar 74
        $out .= process_file(__DIR__ . '/includes/setup_base.css');
364 daniel-mar 75
}
76
 
411 daniel-mar 77
// Then plugins
78
OIDplus::registerAllPlugins('database', 'OIDplusDatabasePlugin', array('OIDplus','registerDatabasePlugin'));
79
$manifests = OIDplus::getAllPluginManifests('database', true);
80
foreach ($manifests as $manifest) {
81
        foreach ($manifest->getCSSFilesSetup() as $css_file) {
82
                $out .= process_file($css_file);
83
        }
84
}
85
 
86
// Now user-defined definitions
366 daniel-mar 87
if (file_exists(__DIR__ . '/userdata/styles/setup_add.css')) {
88
        $out .= process_file(__DIR__ . '/userdata/styles/setup_add.css');
89
}
90
 
364 daniel-mar 91
# ---
92
 
481 daniel-mar 93
if (OIDplus::baseConfig()->getValue('DEBUG')) {
94
        // In debug mode, we might get PHP error messages (see "error_reporting" above),
95
        // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!)
96
        header('Content-Type:text/css');
97
        echo $out;
98
} else {
99
        httpOutWithETag($out, 'text/css', 'oidplus_setup.css');
100
}