Subversion Repositories oidplus

Rev

Rev 294 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
294 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2020 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
 
360 daniel-mar 20
define('SPACER_PNG', base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='));
294 daniel-mar 21
 
22
if (!isset($_REQUEST['file'])) {
360 daniel-mar 23
        header('Content-Type:image/png');
24
        die(SPACER_PNG);
294 daniel-mar 25
} else {
26
        $file = $_REQUEST['file'];
27
}
28
 
29
if (!isset($_REQUEST['mode'])) {
360 daniel-mar 30
        header('Content-Type:image/png');
31
        die(SPACER_PNG);
294 daniel-mar 32
} else {
33
        $mode = $_REQUEST['mode'];
34
}
35
 
360 daniel-mar 36
if (!isset($_REQUEST['lang'])) {
37
        $lang = 'enus';
38
} else {
39
        $lang = $_REQUEST['lang'];
40
}
41
 
294 daniel-mar 42
$candidate1 = __DIR__ . '/../../../userdata/resources/' . $file;
43
$candidate2 = __DIR__ . '/../../../res/' . $file;
44
 
45
if (file_exists($candidate1) || is_dir($candidate1)) {
360 daniel-mar 46
        // It is a file inside userdata/ (or it is overwritten by userdata)
294 daniel-mar 47
        $file = $candidate1;
48
} else {
360 daniel-mar 49
        // It is a file in res/
294 daniel-mar 50
        $file = $candidate2;
51
}
52
 
53
if (($mode == 'treeicon_folder') || ($mode == 'treeicon_leaf_url') || ($mode == 'treeicon_leaf_doc')) {
360 daniel-mar 54
 
55
        if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'tree', $lang))) {
56
                header('Content-Type:image/png');
57
                die(file_get_contents($icon_candidate));
58
        } else if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'tree', ''))) {
59
                header('Content-Type:image/png');
60
                die(file_get_contents($icon_candidate));
61
        } else if (file_exists($icon_candidate = __DIR__.'/'.$mode.'.png')) { // default icon for mode
62
                header('Content-Type:image/png');
63
                die(file_get_contents($icon_candidate));
294 daniel-mar 64
        } else {
360 daniel-mar 65
                header('Content-Type:image/png');
66
                die(SPACER_PNG); // should not happen
294 daniel-mar 67
        }
360 daniel-mar 68
 
294 daniel-mar 69
} else if (($mode == 'icon_leaf_url_big') || ($mode == 'icon_leaf_doc_big') || ($mode == 'icon_folder_big')) {
360 daniel-mar 70
 
71
        if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'big', $lang))) {
72
                header('Content-Type:image/png');
73
                die(file_get_contents($icon_candidate));
74
        } else if (file_exists($icon_candidate = getIconCandidate($file, 'png', 'big', ''))) {
75
                header('Content-Type:image/png');
76
                die(file_get_contents($icon_candidate));
77
        } else if (file_exists($icon_candidate = __DIR__.'/'.$mode.'.png')) { // default icon for mode
78
                header('Content-Type:image/png');
79
                die(file_get_contents($icon_candidate));
294 daniel-mar 80
        } else {
360 daniel-mar 81
                header('Content-Type:image/png');
82
                die(SPACER_PNG); // should not happen
294 daniel-mar 83
        }
360 daniel-mar 84
 
294 daniel-mar 85
} else {
360 daniel-mar 86
 
87
        // Invalid $mode value
88
        header('Content-Type:image/png');
89
        die(SPACER_PNG); // should not happen
90
 
294 daniel-mar 91
}
360 daniel-mar 92
 
93
# ---
94
 
95
function getIconCandidate($file, $picFormat, $treeOrBig, $lang) {
96
        $cnt = 0;
97
        if (!empty($lang)) {
98
                $appendix = '_'.$treeOrBig.'$'.$lang.'.'.$picFormat;
99
        } else {
100
                $appendix = '_'.$treeOrBig.'.'.$picFormat;
101
        }
102
        $tmp = preg_replace('/\.([^.]+)$/', $appendix, basename($file), -1, $cnt);
103
        if ($cnt == 0) $tmp .= $appendix;
104
        return dirname($file).'/'.$tmp;
105
}