Subversion Repositories oidplus

Rev

Rev 1050 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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