Subversion Repositories oidplus

Rev

Rev 143 | Rev 277 | 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 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. define('DO_MINIFY', true);
  23.  
  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.  
  30. require_once __DIR__ . '/includes/color_utils.inc.php';
  31.  
  32. error_reporting(E_ALL);
  33.  
  34. $out = '';
  35.  
  36. # ---
  37.  
  38. function process_file($filename) {
  39.         $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename);
  40.         if (DO_MINIFY) {
  41.                 $minifier = new Minify\CSS($filename);
  42.                 $cont = $minifier->minify();
  43.                 $cont = str_ireplace("url(data:", "url###(data:", $cont);
  44.                 $cont = str_ireplace("url(", "url(".$dir.'/', $cont);
  45.         } else {
  46.                 $cont = file_get_contents($filename);
  47.                 $cont = str_ireplace('url("data:', 'url###("data:', $cont);
  48.                 $cont = str_ireplace('url("', 'url("'.$dir.'/', $cont);
  49.                 $cont = str_ireplace("url('data:", "url###('data:", $cont);
  50.                 $cont = str_ireplace("url('", "url('".$dir.'/', $cont);
  51.         }
  52.         $cont = str_ireplace("url###(", "url(", $cont);
  53.         return $cont;
  54. }
  55.  
  56. # ---
  57.  
  58. $out .= process_file(__DIR__ . '/oidplus_base.css')."\n\n";
  59.  
  60. foreach (array('publicPages','adminPages','raPages') as $pudir) {
  61.         $ary = glob(__DIR__ . '/plugins/'.$pudir.'/'.'*'.'/style.css');
  62.         sort($ary);
  63.         foreach ($ary as $a) $out .= process_file($a);
  64. }
  65.  
  66. $out .= process_file(__DIR__ . '/3p/jstree/themes/default/style.css')."\n\n";
  67. $out .= process_file(__DIR__ . '/3p/jquery-ui/jquery-ui.css')."\n\n";
  68. $out .= process_file(__DIR__ . '/3p/bootstrap/css/bootstrap.css')."\n\n";
  69.  
  70. # ---
  71.  
  72. $hs = isset($_REQUEST['h_shift']) ? $_REQUEST['h_shift'] : 0;
  73. $ss = isset($_REQUEST['s_shift']) ? $_REQUEST['s_shift'] : 0;
  74. $vs = isset($_REQUEST['v_shift']) ? $_REQUEST['v_shift'] : 0;
  75. if (($hs != 0) ||($ss != 0) || ($vs != 0))
  76. $out = changeHueOfCSS($out, $hs, $ss, $vs);
  77.  
  78. # ---
  79.  
  80. $etag = md5($out);
  81. header("Etag: $etag");
  82. if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && (trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)) {
  83.         header("HTTP/1.1 304 Not Modified");
  84. } else {
  85.         header('Content-Type:text/css');
  86.         echo $out;
  87. }
  88.