Subversion Repositories oidplus

Rev

Rev 429 | Rev 462 | 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. require_once __DIR__ . '/includes/oidplus.inc.php';
  23. require_once __DIR__ . '/3p/minify/path-converter/ConverterInterface.php';
  24. require_once __DIR__ . '/3p/minify/path-converter/Converter.php';
  25. require_once __DIR__ . '/3p/minify/src/Minify.php';
  26. require_once __DIR__ . '/3p/minify/src/CSS.php';
  27. require_once __DIR__ . '/3p/minify/src/Exception.php';
  28.  
  29. error_reporting(E_ALL);
  30.  
  31. $out = '';
  32.  
  33. # ---
  34.  
  35. $do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true);
  36.  
  37. function process_file($filename) {
  38.         global $do_minify;
  39.  
  40.         if (!file_exists($filename)) return;
  41.  
  42.         $dir = dirname((strpos($filename, __DIR__.'/') === 0) ? substr($filename, strlen(__DIR__.'/')) : $filename);
  43.         if ($do_minify) {
  44.                 $minifier = new Minify\CSS($filename);
  45.                 $cont = $minifier->minify();
  46.         } else {
  47.                 $cont = file_get_contents($filename);
  48.         }
  49.         $cont = preg_replace('@url\\(\s+@ism', 'url(', $cont);
  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.         $cont = str_ireplace("url(data:", "url###(data:", $cont);
  55.         $cont = str_ireplace("url(", "url###(".$dir.'/', $cont);
  56.         $cont = str_ireplace("url###(", "url(", $cont);
  57.         return $cont."\n\n";
  58. }
  59.  
  60. # ---
  61.  
  62. // Third-party products
  63. $out .= process_file(__DIR__ . '/3p/jstree/themes/default/style'.($do_minify ? '.min' : '').'.css');
  64. $out .= process_file(__DIR__ . '/3p/jquery-ui/jquery-ui'.($do_minify ? '.min' : '').'.css');
  65. $out .= process_file(__DIR__ . '/3p/bootstrap4/css/bootstrap'.($do_minify ? '.min' : '').'.css');
  66.  
  67. // Find out base CSS
  68. if (isset($_REQUEST['theme'])) {
  69.         $theme = $_REQUEST['theme'];
  70.         if (strpos($theme,'/') !== false) $theme = 'default';
  71.         if (strpos($theme,'\\') !== false) $theme = 'default';
  72.         if (strpos($theme,'..') !== false) $theme = 'default';
  73.         if (!is_dir(__DIR__.'/plugins/design/'.$theme)) $theme = 'default';
  74. } else {
  75.         $theme = 'default';
  76. }
  77. $base_css = __DIR__ . '/plugins/design/'.$theme.'/oidplus_base.css';
  78.  
  79. // OIDplus basic definitions
  80. if (file_exists(__DIR__ . '/userdata/styles/oidplus_base.css')) {
  81.         $out .= process_file(__DIR__ . '/userdata/styles/oidplus_base.css');
  82. } else {
  83.         $out .= process_file($base_css);
  84. }
  85.  
  86. // Then plugins
  87. $manifests = OIDplus::getAllPluginManifests('*Pages', true);
  88. foreach ($manifests as $manifest) {
  89.         foreach ($manifest->getCSSFiles() as $css_file) {
  90.                 $out .= process_file($css_file);
  91.         }
  92. }
  93.  
  94. // Now user-defined definitions
  95. if (file_exists(__DIR__ . '/userdata/styles/oidplus_add.css')) {
  96.         $out .= process_file(__DIR__ . '/userdata/styles/oidplus_add.css');
  97. }
  98.  
  99. # ---
  100.  
  101. $inv = isset($_REQUEST['invert']) ? $_REQUEST['invert'] : 0;
  102. if ($inv != 0) {
  103.         $out = invertColorsOfCSS($out);
  104. }
  105.  
  106. $hs = isset($_REQUEST['h_shift']) ? $_REQUEST['h_shift'] : 0;
  107. $ss = isset($_REQUEST['s_shift']) ? $_REQUEST['s_shift'] : 0;
  108. $vs = isset($_REQUEST['v_shift']) ? $_REQUEST['v_shift'] : 0;
  109. if (($hs != 0) ||($ss != 0) || ($vs != 0)) {
  110.         $out = changeHueOfCSS($out, $hs, $ss, $vs);
  111. }
  112.  
  113. # ---
  114.  
  115. httpOutWithETag($out, 'text/css', 'oidplus.css');
  116.