Subversion Repositories oidplus

Rev

Rev 1212 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 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 ViaThinkSoft\OIDplus\OIDplus;
  21. use ViaThinkSoft\OIDplus\OIDplusDesignPlugin;
  22. use MatthiasMullie\Minify;
  23.  
  24. require_once __DIR__ . '/includes/oidplus.inc.php';
  25.  
  26. error_reporting(OIDplus::baseConfig()->getValue('DEBUG') ? E_ALL : 0);
  27. @ini_set('display_errors', OIDplus::baseConfig()->getValue('DEBUG') ? '1' : '0');
  28.  
  29. $out = '';
  30.  
  31. # ---
  32.  
  33. $do_minify = OIDplus::baseConfig()->getValue('MINIFY_CSS', true);
  34.  
  35. /**
  36. * @param string $filename
  37. * @return string
  38.  */
  39. function process_file(string $filename): string {
  40.         global $do_minify;
  41.  
  42.         $filename_min = preg_replace('/\.[^.]+$/', '.min.css', $filename);
  43.         $filename_full = $filename;
  44.  
  45.         if ($do_minify) {
  46.                 if (file_exists($filename_min)) {
  47.                         // There is a file which is already minified
  48.                         $filename = $filename_min;
  49.                         $cont = file_get_contents($filename);
  50.                 } else if (file_exists($filename_full)) {
  51.                         // Otherwise, we minify it ourself
  52.                         $filename = $filename_full;
  53.                         $minifier = new Minify\CSS($filename);
  54.                         $cont = $minifier->minify();
  55.                 } else {
  56.                         return '';
  57.                 }
  58.         } else {
  59.                 if (file_exists($filename_full)) {
  60.                         $filename = $filename_full;
  61.                         $cont = file_get_contents($filename);
  62.                 } else if (file_exists($filename_min)) {
  63.                         $filename = $filename_min;
  64.                         $cont = file_get_contents($filename);
  65.                 } else {
  66.                         return '';
  67.                 }
  68.         }
  69.  
  70.         $thisdir = __DIR__;
  71.         $thisdir = str_replace('\\', '/', $thisdir); // change Windows Backslashes into Web-Slashes
  72.         $filename = str_replace('\\', '/', $filename); // change Windows Backslashes into Web-Slashes
  73.         $dir = dirname((strpos($filename, $thisdir.'/') === 0) ? substr($filename, strlen($thisdir.'/')) : $filename);
  74.  
  75.         $cont = preg_replace('@url\\(\s+@im', 'url(', $cont);
  76.         $cont = str_ireplace('url("data:', 'url###("data:', $cont);
  77.         $cont = str_ireplace('url("', 'url###("'.$dir.'/', $cont);
  78.         $cont = str_ireplace("url('data:", "url###('data:", $cont);
  79.         $cont = str_ireplace("url('", "url###('".$dir.'/', $cont);
  80.         $cont = str_ireplace("url(data:", "url###(data:", $cont);
  81.         $cont = str_ireplace("url(", "url###(".$dir.'/', $cont);
  82.         $cont = str_ireplace("url###(", "url(", $cont);
  83.         return $cont."\n\n";
  84. }
  85.  
  86. # ---
  87.  
  88. // Third-party products
  89. $out .= process_file(__DIR__ . '/vendor/vakata/jstree/dist/themes/default/style.css');
  90. $out .= process_file(__DIR__ . '/vendor/components/jqueryui/themes/base/jquery-ui.css');
  91. $out .= process_file(__DIR__ . '/vendor/twbs/bootstrap/dist/css/bootstrap.css');
  92. $out .= process_file(__DIR__ . '/vendor/gedmarc/layout/dist/layout-default.css');
  93. $out .= process_file(__DIR__ . '/includes/loading.css');
  94.  
  95. // Find out base CSS
  96. if (isset($_GET['theme'])) {
  97.         $theme = $_GET['theme'];
  98.         if (strpos($theme,'/') !== false) $theme = 'default';
  99.         if (strpos($theme,'\\') !== false) $theme = 'default';
  100.         if (strpos($theme,'..') !== false) $theme = 'default';
  101. } else {
  102.         $theme = 'default';
  103. }
  104.  
  105. if (file_exists(__DIR__ . '/userdata/styles/oidplus_base.css')) {
  106.         // There is a user defined CSS (not recommended, use design plugins instead!)
  107.         $out .= process_file(__DIR__ . '/userdata/styles/oidplus_base.css');
  108. } else {
  109.         // Use CSS of the design plugin
  110.         OIDplus::registerAllPlugins('design', OIDplusDesignPlugin::class, array(OIDplus::class,'registerDesignPlugin'));
  111.         $plugins = OIDplus::getDesignPlugins();
  112.         foreach ($plugins as $plugin) {
  113.                 if ($plugin->id() == $theme) {
  114.                         $manifest = $plugin->getManifest();
  115.                         foreach ($manifest->getCSSFiles() as $css_file) {
  116.                                 $out .= process_file($css_file);
  117.                         }
  118.                 }
  119.         }
  120. }
  121.  
  122. // Then plugins
  123. $manifests = OIDplus::getAllPluginManifests(implode(',',OIDplus::INTERACTIVE_PLUGIN_TYPES), true); // due to interface gridGeneratorLinks (INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6) this plugin type can also have CSS
  124. foreach ($manifests as $manifest) {
  125.         foreach ($manifest->getCSSFiles() as $css_file) {
  126.                 $out .= process_file($css_file);
  127.         }
  128. }
  129.  
  130. // Now user-defined (additional) definitions
  131. if (file_exists(__DIR__ . '/userdata/styles/oidplus_add.css')) {
  132.         $out .= process_file(__DIR__ . '/userdata/styles/oidplus_add.css');
  133. }
  134.  
  135. # ---
  136.  
  137. $inv = $_GET['invert'] ?? 0;
  138. if ($inv != 0) {
  139.         $out = invertColorsOfCSS($out);
  140. }
  141.  
  142. $hs = $_GET['h_shift'] ?? 0;
  143. $ss = $_GET['s_shift'] ?? 0;
  144. $vs = $_GET['v_shift'] ?? 0;
  145. if (($hs != 0) ||($ss != 0) || ($vs != 0)) {
  146.         $out = changeHueOfCSS($out, $hs, $ss, $vs);
  147. }
  148.  
  149. # ---
  150.  
  151. if (OIDplus::baseConfig()->getValue('DEBUG')) {
  152.         // In debug mode, we might get PHP error messages (see "error_reporting" above),
  153.         // so it would be severe if we would allow ETAG! (since $out does not contain the PHP error messages!)
  154.         header('Content-Type:text/css');
  155.         echo $out;
  156. } else {
  157.         httpOutWithETag($out, 'text/css', 'oidplus.css');
  158. }
  159.