Subversion Repositories oidplus

Rev

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