Rev 635 | Rev 1041 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 635 | Rev 800 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with 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 |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | define('SPACER_PNG', base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=')); |
20 | define('SPACER_PNG', base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=')); |
21 | 21 | ||
22 | // TODO: should we also check security.ini ? |
22 | // TODO: should we also check security.ini ? |
23 | 23 | ||
24 | require_once __DIR__ . '/../../../../includes/functions.inc.php'; |
24 | require_once __DIR__ . '/../../../../includes/functions.inc.php'; |
25 | 25 | ||
26 | //if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPagePublicResources', false)) { |
26 | //if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPagePublicResources', false)) { |
27 | // throw new OIDplusException(_L('This plugin was disabled by the system administrator!')); |
27 | // throw new OIDplusException(_L('This plugin was disabled by the system administrator!')); |
28 | //} |
28 | //} |
29 | 29 | ||
30 | error_reporting(0); |
30 | error_reporting(0); |
31 | 31 | ||
32 | if (!isset($_REQUEST['file'])) { |
32 | if (!isset($_REQUEST['file'])) { |
33 | httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); |
33 | httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); |
34 | die(); |
34 | die(); |
35 | } else { |
35 | } else { |
36 | $file = $_REQUEST['file']; |
36 | $file = $_REQUEST['file']; |
37 | } |
37 | } |
38 | 38 | ||
39 | if (!isset($_REQUEST['mode'])) { |
39 | if (!isset($_REQUEST['mode'])) { |
40 | httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); |
40 | httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); |
41 | die(); |
41 | die(); |
42 | } else { |
42 | } else { |
43 | $mode = $_REQUEST['mode']; |
43 | $mode = $_REQUEST['mode']; |
44 | } |
44 | } |
45 | 45 | ||
46 | if (!isset($_REQUEST['lang'])) { |
46 | if (!isset($_REQUEST['lang'])) { |
47 | $lang = 'enus'; |
47 | $lang = 'enus'; |
48 | } else { |
48 | } else { |
49 | $lang = $_REQUEST['lang']; |
49 | $lang = $_REQUEST['lang']; |
50 | } |
50 | } |
51 | 51 | ||
52 | $candidate1 = __DIR__ . '/../../../../userdata/resources/' . $file; |
52 | $candidate1 = __DIR__ . '/../../../../userdata/resources/' . $file; |
53 | $candidate2 = __DIR__ . '/../../../../res/' . $file; |
53 | $candidate2 = __DIR__ . '/../../../../res/' . $file; |
54 | 54 | ||
55 | if (file_exists($candidate1) || is_dir($candidate1)) { |
55 | if (file_exists($candidate1) || is_dir($candidate1)) { |
56 | // It is a file inside userdata/ (or it is overwritten by userdata) |
56 | // It is a file inside userdata/ (or it is overwritten by userdata) |
57 | $file = $candidate1; |
57 | $file = $candidate1; |
58 | } else { |
58 | } else { |
59 | // It is a file in res/ |
59 | // It is a file in res/ |
60 | $file = $candidate2; |
60 | $file = $candidate2; |
61 | } |
61 | } |
62 | 62 | ||
63 | if (($mode == 'treeicon_folder') || ($mode == 'treeicon_leaf_url') || ($mode == 'treeicon_leaf_doc')) { |
63 | if (($mode == 'leaf_url_icon16') || ($mode == 'leaf_doc_icon16') || ($mode == 'folder_icon16')) { |
64 | 64 | ||
65 | if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'tree', $lang))) { |
65 | if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'tree', $lang))) { |
66 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
66 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
67 | } else if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'tree', ''))) { |
67 | } else if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'tree', ''))) { |
68 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
68 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
69 | } else if (file_exists($icon_candidate = __DIR__.'/'.$mode.'.png')) { // default icon for mode |
69 | } else if (file_exists($icon_candidate = __DIR__.'/img/'.$mode.'.png')) { // default icon for mode |
70 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
70 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
71 | } else { |
71 | } else { |
72 | httpOutWithETag(SPACER_PNG, 'image/png'); // should not happen |
72 | httpOutWithETag(SPACER_PNG, 'image/png'); // should not happen |
73 | } |
73 | } |
74 | 74 | ||
75 | } else if (($mode == 'icon_leaf_url_big') || ($mode == 'icon_leaf_doc_big') || ($mode == 'icon_folder_big')) { |
75 | } else if (($mode == 'leaf_url_icon') || ($mode == 'leaf_doc_icon') || ($mode == 'folder_icon')) { |
76 | 76 | ||
77 | if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'big', $lang))) { |
77 | if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'big', $lang))) { |
78 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
78 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
79 | } else if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'big', ''))) { |
79 | } else if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'big', ''))) { |
80 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
80 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
81 | } else if (file_exists($icon_candidate = __DIR__.'/'.$mode.'.png')) { // default icon for mode |
81 | } else if (file_exists($icon_candidate = __DIR__.'/img/'.$mode.'.png')) { // default icon for mode |
82 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
82 | httpOutWithETag(file_get_contents($icon_candidate), 'image/png', basename($icon_candidate)); |
83 | } else { |
83 | } else { |
84 | httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); // should not happen |
84 | httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); // should not happen |
85 | } |
85 | } |
86 | 86 | ||
87 | } else { |
87 | } else { |
88 | 88 | ||
89 | // Invalid $mode value |
89 | // Invalid $mode value |
90 | httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); // should not happen |
90 | httpOutWithETag(SPACER_PNG, 'image/png', 'spacer.png'); // should not happen |
91 | 91 | ||
92 | } |
92 | } |
93 | 93 | ||
94 | # --- |
94 | # --- |
95 | 95 | ||
96 | function getIconCandidate($file, $picFormat, $treeOrBig, $lang) { |
96 | function getIconCandidate($file, $picFormat, $treeOrBig, $lang) { |
97 | $cnt = 0; |
97 | $cnt = 0; |
98 | if (!empty($lang)) { |
98 | if (!empty($lang)) { |
99 | $appendix = '_'.$treeOrBig.'$'.$lang.'.'.$picFormat; |
99 | $appendix = '_'.$treeOrBig.'$'.$lang.'.'.$picFormat; |
100 | } else { |
100 | } else { |
101 | $appendix = '_'.$treeOrBig.'.'.$picFormat; |
101 | $appendix = '_'.$treeOrBig.'.'.$picFormat; |
102 | } |
102 | } |
103 | $tmp = preg_replace('/\.([^.]+)$/', $appendix, basename($file), -1, $cnt); |
103 | $tmp = preg_replace('/\.([^.]+)$/', $appendix, basename($file), -1, $cnt); |
104 | if ($cnt == 0) $tmp .= $appendix; |
104 | if ($cnt == 0) $tmp .= $appendix; |
105 | return dirname($file).'/'.$tmp; |
105 | return dirname($file).'/'.$tmp; |
106 | } |
106 | } |
107 | 107 |