Subversion Repositories oidplus

Rev

Rev 511 | Go to most recent revision | Blame | 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. define('SPACER_PNG', base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='));
  21.  
  22. // TODO: should we also check security.ini ?
  23.  
  24. require_once __DIR__ . '/../../../includes/functions.inc.php';
  25.  
  26. //if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPagePublicResources', false)) {
  27. //      throw new OIDplusException(_L('This plugin was disabled by the system administrator!'));
  28. //}
  29.  
  30. error_reporting(0);
  31.  
  32. if (!isset($_REQUEST['file'])) {
  33.         httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png');
  34. } else {
  35.         $file = $_REQUEST['file'];
  36. }
  37.  
  38. if (!isset($_REQUEST['mode'])) {
  39.         httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png');
  40. } else {
  41.         $mode = $_REQUEST['mode'];
  42. }
  43.  
  44. if (!isset($_REQUEST['lang'])) {
  45.         $lang = 'enus';
  46. } else {
  47.         $lang = $_REQUEST['lang'];
  48. }
  49.  
  50. $candidate1 = __DIR__ . '/../../../userdata/resources/' . $file;
  51. $candidate2 = __DIR__ . '/../../../res/' . $file;
  52.  
  53. if (file_exists($candidate1) || is_dir($candidate1)) {
  54.         // It is a file inside userdata/ (or it is overwritten by userdata)
  55.         $file = $candidate1;
  56. } else {
  57.         // It is a file in res/
  58.         $file = $candidate2;
  59. }
  60.  
  61. if (($mode == 'treeicon_folder') || ($mode == 'treeicon_leaf_url') || ($mode == 'treeicon_leaf_doc')) {
  62.  
  63.         if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'tree', $lang))) {
  64.                 httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate));
  65.         } else if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'tree', ''))) {
  66.                 httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate));
  67.         } else if (file_exists($icon_candidate = __DIR__.'/'.$mode.'.png')) { // default icon for mode
  68.                 httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate));
  69.         } else {
  70.                 httpOutWithETag(SPACER_PNG, 'image/png'); // should not happen
  71.         }
  72.  
  73. } else if (($mode == 'icon_leaf_url_big') || ($mode == 'icon_leaf_doc_big') || ($mode == 'icon_folder_big')) {
  74.  
  75.         if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'big', $lang))) {
  76.                 httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate));
  77.         } else if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'big', ''))) {
  78.                 httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate));
  79.         } else if (file_exists($icon_candidate = __DIR__.'/'.$mode.'.png')) { // default icon for mode
  80.                 httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate));
  81.         } else {
  82.                 httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); // should not happen
  83.         }
  84.  
  85. } else {
  86.  
  87.         // Invalid $mode value
  88.         httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); // should not happen
  89.  
  90. }
  91.  
  92. # ---
  93.  
  94. function getIconCandidate($file, $picFormat, $treeOrBig, $lang) {
  95.         $cnt = 0;
  96.         if (!empty($lang)) {
  97.                 $appendix = '_'.$treeOrBig.'$'.$lang.'.'.$picFormat;
  98.         } else {
  99.                 $appendix = '_'.$treeOrBig.'.'.$picFormat;
  100.         }
  101.         $tmp = preg_replace('/\.([^.]+)$/', $appendix, basename($file), -1, $cnt);
  102.         if ($cnt == 0) $tmp .= $appendix;
  103.         return dirname($file).'/'.$tmp;
  104. }
  105.