Rev 635 | Rev 1041 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 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 | die(); |
||
35 | } else { |
||
36 | $file = $_REQUEST['file']; |
||
37 | } |
||
38 | |||
39 | if (!isset($_REQUEST['mode'])) { |
||
40 | httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); |
||
41 | die(); |
||
42 | } else { |
||
43 | $mode = $_REQUEST['mode']; |
||
44 | } |
||
45 | |||
46 | if (!isset($_REQUEST['lang'])) { |
||
47 | $lang = 'enus'; |
||
48 | } else { |
||
49 | $lang = $_REQUEST['lang']; |
||
50 | } |
||
51 | |||
52 | $candidate1 = __DIR__ . '/../../../../userdata/resources/' . $file; |
||
53 | $candidate2 = __DIR__ . '/../../../../res/' . $file; |
||
54 | |||
55 | if (file_exists($candidate1) || is_dir($candidate1)) { |
||
56 | // It is a file inside userdata/ (or it is overwritten by userdata) |
||
57 | $file = $candidate1; |
||
58 | } else { |
||
59 | // It is a file in res/ |
||
60 | $file = $candidate2; |
||
61 | } |
||
62 | |||
800 | daniel-mar | 63 | if (($mode == 'leaf_url_icon16') || ($mode == 'leaf_doc_icon16') || ($mode == 'folder_icon16')) { |
635 | daniel-mar | 64 | |
65 | if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'tree', $lang))) { |
||
66 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
||
67 | } else if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'tree', ''))) { |
||
68 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
||
800 | daniel-mar | 69 | } else if (file_exists($icon_candidate = __DIR__.'/img/'.$mode.'.png')) { // default icon for mode |
635 | daniel-mar | 70 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
71 | } else { |
||
72 | httpOutWithETag(SPACER_PNG, 'image/png'); // should not happen |
||
73 | } |
||
74 | |||
800 | daniel-mar | 75 | } else if (($mode == 'leaf_url_icon') || ($mode == 'leaf_doc_icon') || ($mode == 'folder_icon')) { |
635 | daniel-mar | 76 | |
77 | if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'big', $lang))) { |
||
78 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
||
79 | } else if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'big', ''))) { |
||
80 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
||
800 | daniel-mar | 81 | } else if (file_exists($icon_candidate = __DIR__.'/img/'.$mode.'.png')) { // default icon for mode |
635 | daniel-mar | 82 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
83 | } else { |
||
84 | httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); // should not happen |
||
85 | } |
||
86 | |||
87 | } else { |
||
88 | |||
89 | // Invalid $mode value |
||
90 | httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); // should not happen |
||
91 | |||
92 | } |
||
93 | |||
94 | # --- |
||
95 | |||
96 | function getIconCandidate($file, $picFormat, $treeOrBig, $lang) { |
||
97 | $cnt = 0; |
||
98 | if (!empty($lang)) { |
||
99 | $appendix = '_'.$treeOrBig.'$'.$lang.'.'.$picFormat; |
||
100 | } else { |
||
101 | $appendix = '_'.$treeOrBig.'.'.$picFormat; |
||
102 | } |
||
103 | $tmp = preg_replace('/\.([^.]+)$/', $appendix, basename($file), -1, $cnt); |
||
104 | if ($cnt == 0) $tmp .= $appendix; |
||
105 | return dirname($file).'/'.$tmp; |
||
106 | } |