Rev 368 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 368 | Rev 386 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2020 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2020 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 | class OIDplusPagePublicResources extends OIDplusPagePluginPublic { |
20 | class OIDplusPagePublicResources extends OIDplusPagePluginPublic { |
21 | 21 | ||
22 | private function getMainTitle() { |
22 | private function getMainTitle() { |
23 | return _L('Documents and Resources'); |
23 | return _L('Documents and Resources'); |
24 | } |
24 | } |
25 | 25 | ||
26 | public function init($html=true) { |
26 | public function init($html=true) { |
27 | OIDplus::config()->prepareConfigKey('resource_plugin_autoopen_level', 'Resource plugin: How many levels should be open in the treeview when OIDplus is loaded?', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
27 | OIDplus::config()->prepareConfigKey('resource_plugin_autoopen_level', 'Resource plugin: How many levels should be open in the treeview when OIDplus is loaded?', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
28 | if (!is_numeric($value) || ($value < 0)) { |
28 | if (!is_numeric($value) || ($value < 0)) { |
29 | throw new OIDplusException(_L('Please enter a valid value.')); |
29 | throw new OIDplusException(_L('Please enter a valid value.')); |
30 | } |
30 | } |
31 | }); |
31 | }); |
32 | OIDplus::config()->deleteConfigKey('resource_plugin_title'); |
32 | OIDplus::config()->deleteConfigKey('resource_plugin_title'); |
33 | OIDplus::config()->deleteConfigKey('resource_plugin_path'); |
33 | OIDplus::config()->deleteConfigKey('resource_plugin_path'); |
34 | OIDplus::config()->prepareConfigKey('resource_plugin_hide_empty_path','Resource plugin: Hide empty paths? (0=no, 1=yes)', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
34 | OIDplus::config()->prepareConfigKey('resource_plugin_hide_empty_path','Resource plugin: Hide empty paths? (0=no, 1=yes)', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
35 | if (!is_numeric($value) || (($value != 0) && ($value != 1))) { |
35 | if (!is_numeric($value) || (($value != 0) && ($value != 1))) { |
36 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
36 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
37 | } |
37 | } |
38 | }); |
38 | }); |
39 | } |
39 | } |
40 | 40 | ||
41 | private static function getDocumentContent($file) { |
41 | private static function getDocumentContent($file) { |
42 | $file = rtrim(OIDplus::basePath(),'/').'/'.self::realname($file); |
42 | $file = rtrim(OIDplus::basePath(),'/').'/'.self::realname($file); |
43 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
43 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
44 | if (file_exists($file2)) $file = $file2; |
44 | if (file_exists($file2)) $file = $file2; |
45 | 45 | ||
46 | $cont = file_get_contents($file); |
46 | $cont = file_get_contents($file); |
47 | 47 | ||
48 | // make sure the program works even if the user provided HTML is not UTF-8 |
48 | list($html, $js, $css) = extractHtmlContents($cont); |
49 | $cont = iconv(mb_detect_encoding($cont, mb_detect_order(), true), 'UTF-8//IGNORE', $cont); |
- | |
50 | $bom = pack('H*','EFBBBF'); |
49 | $cont = ''; |
51 | $cont = preg_replace("/^$bom/", '', $cont); |
- | |
52 | - | ||
53 | $cont = preg_replace('@^(.+)<body[^>]*>@isU', '', $cont); |
50 | if (!empty($js)) $cont .= "<script>\n$js\n</script>"; |
54 | $cont = preg_replace('@</body>.+$@isU', '', $cont); |
- | |
55 | $cont = preg_replace('@<title>.+</title>@isU', '', $cont); |
51 | if (!empty($css)) $cont .= "<style>\n$css\n</style>"; |
56 | $cont = preg_replace('@<h1>.+</h1>@isU', '', $cont, 1); |
52 | $cont .= $html; |
57 | 53 | ||
58 | return $cont; |
54 | return $cont; |
59 | } |
55 | } |
60 | 56 | ||
61 | private static function getDocumentTitle($file) { |
57 | private static function getDocumentTitle($file) { |
62 | $file = rtrim(OIDplus::basePath(),'/').'/'.self::realname($file); |
58 | $file = rtrim(OIDplus::basePath(),'/').'/'.self::realname($file); |
63 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
59 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
64 | if (file_exists($file2)) $file = $file2; |
60 | if (file_exists($file2)) $file = $file2; |
65 | 61 | ||
66 | $cont = file_get_contents($file); |
62 | $cont = file_get_contents($file); |
67 | 63 | ||
68 | // make sure the program works even if the user provided HTML is not UTF-8 |
64 | // make sure the program works even if the user provided HTML is not UTF-8 |
69 | $cont = iconv(mb_detect_encoding($cont, mb_detect_order(), true), 'UTF-8//IGNORE', $cont); |
65 | $cont = iconv(mb_detect_encoding($cont, mb_detect_order(), true), 'UTF-8//IGNORE', $cont); |
70 | $bom = pack('H*','EFBBBF'); |
66 | $bom = pack('H*','EFBBBF'); |
71 | $cont = preg_replace("/^$bom/", '', $cont); |
67 | $cont = preg_replace("/^$bom/", '', $cont); |
72 | 68 | ||
- | 69 | $m = array(); |
|
73 | if (preg_match('@<title>(.+)</title>@ismU', $cont, $m)) return $m[1]; |
70 | if (preg_match('@<title>(.+)</title>@ismU', $cont, $m)) return $m[1]; |
74 | if (preg_match('@<h1>(.+)</h1>@ismU', $cont, $m)) return $m[1]; |
71 | if (preg_match('@<h1>(.+)</h1>@ismU', $cont, $m)) return $m[1]; |
75 | if (preg_match('@<h2>(.+)</h2>@ismU', $cont, $m)) return $m[1]; |
72 | if (preg_match('@<h2>(.+)</h2>@ismU', $cont, $m)) return $m[1]; |
76 | if (preg_match('@<h3>(.+)</h3>@ismU', $cont, $m)) return $m[1]; |
73 | if (preg_match('@<h3>(.+)</h3>@ismU', $cont, $m)) return $m[1]; |
77 | if (preg_match('@<h4>(.+)</h4>@ismU', $cont, $m)) return $m[1]; |
74 | if (preg_match('@<h4>(.+)</h4>@ismU', $cont, $m)) return $m[1]; |
78 | if (preg_match('@<h5>(.+)</h5>@ismU', $cont, $m)) return $m[1]; |
75 | if (preg_match('@<h5>(.+)</h5>@ismU', $cont, $m)) return $m[1]; |
79 | if (preg_match('@<h6>(.+)</h6>@ismU', $cont, $m)) return $m[1]; |
76 | if (preg_match('@<h6>(.+)</h6>@ismU', $cont, $m)) return $m[1]; |
80 | return pathinfo($file, PATHINFO_FILENAME); // filename without extension |
77 | return pathinfo($file, PATHINFO_FILENAME); // filename without extension |
81 | } |
78 | } |
82 | 79 | ||
83 | private static function myglob($reldir, $onlydir=false) { |
80 | private static function myglob($reldir, $onlydir=false) { |
84 | $out = array(); |
81 | $out = array(); |
85 | 82 | ||
86 | $root = OIDplus::basePath().'/userdata/resources/'; |
83 | $root = OIDplus::basePath().'/userdata/resources/'; |
87 | $res = $onlydir ? glob($root.ltrim($reldir,'/'), GLOB_ONLYDIR) : glob($root.ltrim($reldir,'/')); |
84 | $res = $onlydir ? glob($root.ltrim($reldir,'/'), GLOB_ONLYDIR) : glob($root.ltrim($reldir,'/')); |
88 | foreach ($res as &$x) { |
85 | foreach ($res as &$x) { |
89 | $x = substr($x, strlen($root)); |
86 | $x = substr($x, strlen($root)); |
90 | if (strpos($x,'$') !== false) continue; |
87 | if (strpos($x,'$') !== false) continue; |
91 | $out[] = $x; |
88 | $out[] = $x; |
92 | } |
89 | } |
93 | 90 | ||
94 | $root = OIDplus::basePath().'/res/'; |
91 | $root = OIDplus::basePath().'/res/'; |
95 | $res = $onlydir ? glob($root.ltrim($reldir,'/'), GLOB_ONLYDIR) : glob($root.ltrim($reldir,'/')); |
92 | $res = $onlydir ? glob($root.ltrim($reldir,'/'), GLOB_ONLYDIR) : glob($root.ltrim($reldir,'/')); |
96 | foreach ($res as $x) { |
93 | foreach ($res as $x) { |
97 | $x = substr($x, strlen($root)); |
94 | $x = substr($x, strlen($root)); |
98 | if (strpos($x,'$') !== false) continue; |
95 | if (strpos($x,'$') !== false) continue; |
99 | $out[] = $x; |
96 | $out[] = $x; |
100 | } |
97 | } |
101 | 98 | ||
102 | return array_unique($out); |
99 | return array_unique($out); |
103 | } |
100 | } |
104 | 101 | ||
105 | private static function realname($rel) { |
102 | private static function realname($rel) { |
106 | $candidate1 = OIDplus::basePath().'/userdata/resources/'.$rel; |
103 | $candidate1 = OIDplus::basePath().'/userdata/resources/'.$rel; |
107 | $candidate2 = OIDplus::basePath().'/res/'.$rel; |
104 | $candidate2 = OIDplus::basePath().'/res/'.$rel; |
108 | if (file_exists($candidate1) || is_dir($candidate1)) return "userdata/resources/$rel"; |
105 | if (file_exists($candidate1) || is_dir($candidate1)) return "userdata/resources/$rel"; |
109 | if (file_exists($candidate2) || is_dir($candidate2)) return "res/$rel"; |
106 | if (file_exists($candidate2) || is_dir($candidate2)) return "res/$rel"; |
110 | } |
107 | } |
111 | 108 | ||
112 | public function gui($id, &$out, &$handled) { |
109 | public function gui($id, &$out, &$handled) { |
113 | if (explode('$',$id,2)[0] === 'oidplus:resources') { |
110 | if (explode('$',$id,2)[0] === 'oidplus:resources') { |
114 | $handled = true; |
111 | $handled = true; |
115 | 112 | ||
116 | $file = @explode('$',$id)[1]; |
113 | $file = @explode('$',$id)[1]; |
117 | 114 | ||
118 | // Security checks |
115 | // Security checks |
119 | 116 | ||
120 | if ( |
117 | if ( |
121 | ($file != '') && ( |
118 | ($file != '') && ( |
122 | (strpos($file, chr(0)) !== false) || // Directory traversal (LFI,RFI) helper |
119 | (strpos($file, chr(0)) !== false) || // Directory traversal (LFI,RFI) helper |
123 | (strpos($file, '../') !== false) || ($file[0] == '/') || ($file[0] == '~') || // <-- Local File Injection (LFI) |
120 | (strpos($file, '../') !== false) || ($file[0] == '/') || ($file[0] == '~') || // <-- Local File Injection (LFI) |
124 | ($file[0] == '.') || (strpos($file, '/.') !== false) || // <-- Calling hidden files e.g. ".htpasswd" |
121 | ($file[0] == '.') || (strpos($file, '/.') !== false) || // <-- Calling hidden files e.g. ".htpasswd" |
125 | (strpos($file, '://') !== false) // <-- Remote File Injection (RFI) |
122 | (strpos($file, '://') !== false) // <-- Remote File Injection (RFI) |
126 | )) { |
123 | )) { |
127 | if (strpos($file, chr(0)) !== false) { |
124 | if (strpos($file, chr(0)) !== false) { |
128 | $file = str_replace(chr(0), '[NUL]', $file); |
125 | $file = str_replace(chr(0), '[NUL]', $file); |
129 | } |
126 | } |
130 | OIDplus::logger()->log("[WARN]A!", "LFI/RFI attack blocked (requested file '$file')"); |
127 | OIDplus::logger()->log("[WARN]A!", "LFI/RFI attack blocked (requested file '$file')"); |
131 | $out['title'] = _L('Access denied'); |
128 | $out['title'] = _L('Access denied'); |
132 | $out['icon'] = 'img/error_big.png'; |
129 | $out['icon'] = 'img/error_big.png'; |
133 | $out['text'] = '<p>'._L('This request is invalid').'</p>'; |
130 | $out['text'] = '<p>'._L('This request is invalid').'</p>'; |
134 | return; |
131 | return; |
135 | } |
132 | } |
136 | 133 | ||
137 | $out['text'] = ''; |
134 | $out['text'] = ''; |
138 | 135 | ||
139 | // First, "Go back to" line |
136 | // First, "Go back to" line |
140 | 137 | ||
141 | if ($file != '') { |
138 | if ($file != '') { |
142 | $dir = dirname($file); |
139 | $dir = dirname($file); |
143 | 140 | ||
144 | if ($dir == '.') { |
141 | if ($dir == '.') { |
145 | if (file_exists(__DIR__.'/treeicon.png')) { |
142 | if (file_exists(__DIR__.'/treeicon.png')) { |
146 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
143 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
147 | } else { |
144 | } else { |
148 | $tree_icon = null; // default icon (folder) |
145 | $tree_icon = null; // default icon (folder) |
149 | } |
146 | } |
150 | 147 | ||
151 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
148 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
152 | 149 | ||
153 | $lng_gobackto = _L('Go back to').':'; |
150 | $lng_gobackto = _L('Go back to').':'; |
154 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:resources').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '.$lng_gobackto.' '.$ic.' '.htmlentities($this->getMainTitle()).'</a></p>'; |
151 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:resources').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '.$lng_gobackto.' '.$ic.' '.htmlentities($this->getMainTitle()).'</a></p>'; |
155 | } else { |
152 | } else { |
156 | $realdir = self::realname($dir); |
153 | $realdir = self::realname($dir); |
157 | 154 | ||
158 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_folder&lang='.OIDplus::getCurrentLang().'&file='.urlencode($dir); |
155 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_folder&lang='.OIDplus::getCurrentLang().'&file='.urlencode($dir); |
159 | /* |
156 | /* |
160 | $icon_candidate = pathinfo($realdir)['dirname'].'/'.pathinfo($realdir)['filename'].'_tree.png'; |
157 | $icon_candidate = pathinfo($realdir)['dirname'].'/'.pathinfo($realdir)['filename'].'_tree.png'; |
161 | if (file_exists($icon_candidate)) { |
158 | if (file_exists($icon_candidate)) { |
162 | $tree_icon = $icon_candidate; |
159 | $tree_icon = $icon_candidate; |
163 | } else if (file_exists(__DIR__.'/treeicon_folder.png')) { |
160 | } else if (file_exists(__DIR__.'/treeicon_folder.png')) { |
164 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_folder.png'; |
161 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_folder.png'; |
165 | } else { |
162 | } else { |
166 | $tree_icon = null; // no icon |
163 | $tree_icon = null; // no icon |
167 | } |
164 | } |
168 | */ |
165 | */ |
169 | 166 | ||
170 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
167 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
171 | 168 | ||
172 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:resources$'.rtrim($dir,'/').'/').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Go back to').': '.$ic.' '.htmlentities(self::getFolderTitle($realdir)).'</a></p><br>'; |
169 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:resources$'.rtrim($dir,'/').'/').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Go back to').': '.$ic.' '.htmlentities(self::getFolderTitle($realdir)).'</a></p><br>'; |
173 | } |
170 | } |
174 | } |
171 | } |
175 | 172 | ||
176 | // Then the content |
173 | // Then the content |
177 | 174 | ||
178 | $realfile = self::realname($file); |
175 | $realfile = self::realname($file); |
179 | // $realfile2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $realfile); |
176 | // $realfile2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $realfile); |
180 | // if (file_exists($realfile2)) $realfile = $realfile2; |
177 | // if (file_exists($realfile2)) $realfile = $realfile2; |
181 | 178 | ||
182 | if (file_exists($realfile) && (!is_dir($realfile))) { |
179 | if (file_exists($realfile) && (!is_dir($realfile))) { |
183 | if ((substr($file,-4,4) == '.url') || (substr($file,-5,5) == '.link')) { |
180 | if ((substr($file,-4,4) == '.url') || (substr($file,-5,5) == '.link')) { |
184 | $out['title'] = $this->getHyperlinkTitle($realfile); |
181 | $out['title'] = $this->getHyperlinkTitle($realfile); |
185 | 182 | ||
186 | $out['icon'] = OIDplus::webpath(__DIR__).'show_icon.php?mode=icon_leaf_url_big&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
183 | $out['icon'] = OIDplus::webpath(__DIR__).'show_icon.php?mode=icon_leaf_url_big&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
187 | /* |
184 | /* |
188 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_big.png'; |
185 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_big.png'; |
189 | if (file_exists($icon_candidate)) { |
186 | if (file_exists($icon_candidate)) { |
190 | $out['icon'] = $icon_candidate; |
187 | $out['icon'] = $icon_candidate; |
191 | } else if (file_exists(__DIR__.'/icon_leaf_url_big.png')) { |
188 | } else if (file_exists(__DIR__.'/icon_leaf_url_big.png')) { |
192 | $out['icon'] = OIDplus::webpath(__DIR__).'icon_leaf_url_big.png'; |
189 | $out['icon'] = OIDplus::webpath(__DIR__).'icon_leaf_url_big.png'; |
193 | } else { |
190 | } else { |
194 | $out['icon'] = ''; |
191 | $out['icon'] = ''; |
195 | } |
192 | } |
196 | */ |
193 | */ |
197 | 194 | ||
198 | // Should not happen though, due to conditionalselect |
195 | // Should not happen though, due to conditionalselect |
199 | $out['text'] .= '<a href="'.htmlentities(self::getHyperlinkURL($realfile)).'" target="_blank">'._L('Open in new window').'</a>'; |
196 | $out['text'] .= '<a href="'.htmlentities(self::getHyperlinkURL($realfile)).'" target="_blank">'._L('Open in new window').'</a>'; |
200 | } else if ((substr($file,-4,4) == '.htm') || (substr($file,-5,5) == '.html')) { |
197 | } else if ((substr($file,-4,4) == '.htm') || (substr($file,-5,5) == '.html')) { |
201 | $out['title'] = $this->getDocumentTitle($file); |
198 | $out['title'] = $this->getDocumentTitle($file); |
202 | 199 | ||
203 | $out['icon'] = OIDplus::webpath(__DIR__).'show_icon.php?mode=icon_leaf_doc_big&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
200 | $out['icon'] = OIDplus::webpath(__DIR__).'show_icon.php?mode=icon_leaf_doc_big&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
204 | /* |
201 | /* |
205 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_big.png'; |
202 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_big.png'; |
206 | if (file_exists($icon_candidate)) { |
203 | if (file_exists($icon_candidate)) { |
207 | $out['icon'] = $icon_candidate; |
204 | $out['icon'] = $icon_candidate; |
208 | } else if (file_exists(__DIR__.'/icon_leaf_doc_big.png')) { |
205 | } else if (file_exists(__DIR__.'/icon_leaf_doc_big.png')) { |
209 | $out['icon'] = OIDplus::webpath(__DIR__).'icon_leaf_doc_big.png'; |
206 | $out['icon'] = OIDplus::webpath(__DIR__).'icon_leaf_doc_big.png'; |
210 | } else { |
207 | } else { |
211 | $out['icon'] = ''; |
208 | $out['icon'] = ''; |
212 | } |
209 | } |
213 | */ |
210 | */ |
214 | 211 | ||
215 | $out['text'] .= self::getDocumentContent($file); |
212 | $out['text'] .= self::getDocumentContent($file); |
216 | } else { |
213 | } else { |
217 | $out['title'] = _L('Unknown file type'); |
214 | $out['title'] = _L('Unknown file type'); |
218 | $out['icon'] = 'img/error_big.png'; |
215 | $out['icon'] = 'img/error_big.png'; |
219 | $out['text'] = '<p>'._L('The system does not know how to handle this file type.').'</p>'; |
216 | $out['text'] = '<p>'._L('The system does not know how to handle this file type.').'</p>'; |
220 | return; |
217 | return; |
221 | } |
218 | } |
222 | } else if (is_dir($realfile)) { |
219 | } else if (is_dir($realfile)) { |
223 | $out['title'] = ($file == '') ? $this->getMainTitle() : self::getFolderTitle($realfile); |
220 | $out['title'] = ($file == '') ? $this->getMainTitle() : self::getFolderTitle($realfile); |
224 | 221 | ||
225 | if ($file == '') { |
222 | if ($file == '') { |
226 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : ''; |
223 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : ''; |
227 | } else { |
224 | } else { |
228 | $out['icon'] = OIDplus::webpath(__DIR__).'show_icon.php?mode=icon_folder_big&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
225 | $out['icon'] = OIDplus::webpath(__DIR__).'show_icon.php?mode=icon_folder_big&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
229 | /* |
226 | /* |
230 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_big.png'; |
227 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_big.png'; |
231 | if (file_exists($icon_candidate)) { |
228 | if (file_exists($icon_candidate)) { |
232 | $out['icon'] = $icon_candidate; |
229 | $out['icon'] = $icon_candidate; |
233 | } else if (file_exists(__DIR__.'/icon_folder_big.png')) { |
230 | } else if (file_exists(__DIR__.'/icon_folder_big.png')) { |
234 | $out['icon'] = OIDplus::webpath(__DIR__).'icon_folder_big.png'; |
231 | $out['icon'] = OIDplus::webpath(__DIR__).'icon_folder_big.png'; |
235 | } else { |
232 | } else { |
236 | $out['icon'] = null; // no icon |
233 | $out['icon'] = null; // no icon |
237 | } |
234 | } |
238 | */ |
235 | */ |
239 | } |
236 | } |
240 | 237 | ||
241 | if (file_exists(__DIR__.'/treeicon.png')) { |
238 | if (file_exists(__DIR__.'/treeicon.png')) { |
242 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
239 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
243 | } else { |
240 | } else { |
244 | $tree_icon = null; // default icon (folder) |
241 | $tree_icon = null; // default icon (folder) |
245 | } |
242 | } |
246 | 243 | ||
247 | $count = 0; |
244 | $count = 0; |
248 | 245 | ||
249 | $dirs = self::myglob(rtrim($file,'/').'/'.'*', true); |
246 | $dirs = self::myglob(rtrim($file,'/').'/'.'*', true); |
250 | natcasesort($dirs); |
247 | natcasesort($dirs); |
251 | foreach ($dirs as $dir) { |
248 | foreach ($dirs as $dir) { |
252 | $realdir = self::realname($dir); |
249 | $realdir = self::realname($dir); |
253 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_folder&lang='.OIDplus::getCurrentLang().'&file='.urlencode($dir); |
250 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_folder&lang='.OIDplus::getCurrentLang().'&file='.urlencode($dir); |
254 | /* |
251 | /* |
255 | $icon_candidate = pathinfo($realdir)['dirname'].'/'.pathinfo($realdir)['filename'].'_tree.png'; |
252 | $icon_candidate = pathinfo($realdir)['dirname'].'/'.pathinfo($realdir)['filename'].'_tree.png'; |
256 | if (file_exists($icon_candidate)) { |
253 | if (file_exists($icon_candidate)) { |
257 | $tree_icon = $icon_candidate; |
254 | $tree_icon = $icon_candidate; |
258 | } else if (file_exists(__DIR__.'/treeicon_folder.png')) { |
255 | } else if (file_exists(__DIR__.'/treeicon_folder.png')) { |
259 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_folder.png'; |
256 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_folder.png'; |
260 | } else { |
257 | } else { |
261 | $tree_icon = null; // no icon |
258 | $tree_icon = null; // no icon |
262 | } |
259 | } |
263 | */ |
260 | */ |
264 | 261 | ||
265 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
262 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
266 | 263 | ||
267 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:resources$'.rtrim($dir,'/').'/').'>'.$ic.' '.htmlentities(self::getFolderTitle($realdir)).'</a></p>'; |
264 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:resources$'.rtrim($dir,'/').'/').'>'.$ic.' '.htmlentities(self::getFolderTitle($realdir)).'</a></p>'; |
268 | $count++; |
265 | $count++; |
269 | } |
266 | } |
270 | 267 | ||
271 | $files = array_merge( |
268 | $files = array_merge( |
272 | self::myglob(rtrim($file,'/').'/'.'*.htm'), // TODO: also PHP? |
269 | self::myglob(rtrim($file,'/').'/'.'*.htm'), // TODO: also PHP? |
273 | self::myglob(rtrim($file,'/').'/'.'*.html'), |
270 | self::myglob(rtrim($file,'/').'/'.'*.html'), |
274 | self::myglob(rtrim($file,'/').'/'.'*.url'), |
271 | self::myglob(rtrim($file,'/').'/'.'*.url'), |
275 | self::myglob(rtrim($file,'/').'/'.'*.link') |
272 | self::myglob(rtrim($file,'/').'/'.'*.link') |
276 | ); |
273 | ); |
277 | natcasesort($files); |
274 | natcasesort($files); |
278 | foreach ($files as $file) { |
275 | foreach ($files as $file) { |
279 | $realfile = self::realname($file); |
276 | $realfile = self::realname($file); |
280 | if ((substr($file,-4,4) == '.url') || (substr($file,-5,5) == '.link')) { |
277 | if ((substr($file,-4,4) == '.url') || (substr($file,-5,5) == '.link')) { |
281 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_leaf_url&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
278 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_leaf_url&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
282 | /* |
279 | /* |
283 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_tree.png'; |
280 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_tree.png'; |
284 | if (file_exists($icon_candidate)) { |
281 | if (file_exists($icon_candidate)) { |
285 | $tree_icon = $icon_candidate; |
282 | $tree_icon = $icon_candidate; |
286 | } else if (file_exists(__DIR__.'/treeicon_leaf_url.png')) { |
283 | } else if (file_exists(__DIR__.'/treeicon_leaf_url.png')) { |
287 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_leaf_url.png'; |
284 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_leaf_url.png'; |
288 | } else { |
285 | } else { |
289 | $tree_icon = null; // default icon (folder) |
286 | $tree_icon = null; // default icon (folder) |
290 | } |
287 | } |
291 | */ |
288 | */ |
292 | 289 | ||
293 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
290 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
294 | 291 | ||
295 | $hyperlink_pic = ' <img src="'.OIDplus::webpath(__DIR__).'hyperlink.png" widht="13" height="13" alt="Hyperlink" style="top:-3px;position:relative">'; |
292 | $hyperlink_pic = ' <img src="'.OIDplus::webpath(__DIR__).'hyperlink.png" widht="13" height="13" alt="Hyperlink" style="top:-3px;position:relative">'; |
296 | 293 | ||
297 | $out['text'] .= '<p><a href="'.htmlentities(self::getHyperlinkURL($realfile)).'" target="_blank">'.$ic.' '.htmlentities($this->getHyperlinkTitle($realfile)).' '.$hyperlink_pic.'</a></p>'; |
294 | $out['text'] .= '<p><a href="'.htmlentities(self::getHyperlinkURL($realfile)).'" target="_blank">'.$ic.' '.htmlentities($this->getHyperlinkTitle($realfile)).' '.$hyperlink_pic.'</a></p>'; |
298 | $count++; |
295 | $count++; |
299 | } else { |
296 | } else { |
300 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_leaf_doc&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
297 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_leaf_doc&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
301 | /* |
298 | /* |
302 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_tree.png'; |
299 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_tree.png'; |
303 | if (file_exists($icon_candidate)) { |
300 | if (file_exists($icon_candidate)) { |
304 | $tree_icon = $icon_candidate; |
301 | $tree_icon = $icon_candidate; |
305 | } else if (file_exists(__DIR__.'/treeicon_leaf_doc.png')) { |
302 | } else if (file_exists(__DIR__.'/treeicon_leaf_doc.png')) { |
306 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_leaf_doc.png'; |
303 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_leaf_doc.png'; |
307 | } else { |
304 | } else { |
308 | $tree_icon = null; // default icon (folder) |
305 | $tree_icon = null; // default icon (folder) |
309 | } |
306 | } |
310 | */ |
307 | */ |
311 | 308 | ||
312 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
309 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
313 | 310 | ||
314 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:resources$'.$file).'>'.$ic.' '.htmlentities($this->getDocumentTitle($file)).'</a></p>'; |
311 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:resources$'.$file).'>'.$ic.' '.htmlentities($this->getDocumentTitle($file)).'</a></p>'; |
315 | $count++; |
312 | $count++; |
316 | } |
313 | } |
317 | } |
314 | } |
318 | 315 | ||
319 | if ($count == 0) { |
316 | if ($count == 0) { |
320 | $out['text'] .= '<p>'._L('This folder does not contain any elements').'</p>'; |
317 | $out['text'] .= '<p>'._L('This folder does not contain any elements').'</p>'; |
321 | } |
318 | } |
322 | } else { |
319 | } else { |
323 | $out['title'] = _L('Not found'); |
320 | $out['title'] = _L('Not found'); |
324 | $out['icon'] = 'img/error_big.png'; |
321 | $out['icon'] = 'img/error_big.png'; |
325 | $out['text'] = '<p>'._L('This resource doesn\'t exist anymore.').'</p>'; |
322 | $out['text'] = '<p>'._L('This resource doesn\'t exist anymore.').'</p>'; |
326 | } |
323 | } |
327 | } |
324 | } |
328 | } |
325 | } |
329 | 326 | ||
330 | private function tree_rec(&$children, $rootdir=null, $depth=0) { |
327 | private function tree_rec(&$children, $rootdir=null, $depth=0) { |
331 | if (is_null($rootdir)) $rootdir = ''; |
328 | if (is_null($rootdir)) $rootdir = ''; |
332 | if ($depth > 100) return false; // something is wrong! |
329 | if ($depth > 100) return false; // something is wrong! |
333 | 330 | ||
334 | $dirs = self::myglob($rootdir.'*'.'/', true); |
331 | $dirs = self::myglob($rootdir.'*'.'/', true); |
335 | natcasesort($dirs); |
332 | natcasesort($dirs); |
336 | foreach ($dirs as $dir) { |
333 | foreach ($dirs as $dir) { |
337 | $tmp = array(); |
334 | $tmp = array(); |
338 | 335 | ||
339 | $this->tree_rec($tmp, $dir, $depth+1); |
336 | $this->tree_rec($tmp, $dir, $depth+1); |
340 | 337 | ||
341 | $realdir = self::realname($dir); |
338 | $realdir = self::realname($dir); |
342 | 339 | ||
343 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_folder&lang='.OIDplus::getCurrentLang().'&file='.urlencode($dir); |
340 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_folder&lang='.OIDplus::getCurrentLang().'&file='.urlencode($dir); |
344 | /* |
341 | /* |
345 | $icon_candidate = pathinfo($realdir)['dirname'].'/'.pathinfo($realdir)['filename'].'_tree.png'; |
342 | $icon_candidate = pathinfo($realdir)['dirname'].'/'.pathinfo($realdir)['filename'].'_tree.png'; |
346 | if (file_exists($icon_candidate)) { |
343 | if (file_exists($icon_candidate)) { |
347 | $tree_icon = $icon_candidate; |
344 | $tree_icon = $icon_candidate; |
348 | } else if (file_exists(__DIR__.'/treeicon_folder.png')) { |
345 | } else if (file_exists(__DIR__.'/treeicon_folder.png')) { |
349 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_folder.png'; |
346 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_folder.png'; |
350 | } else { |
347 | } else { |
351 | $tree_icon = null; // default icon (folder) |
348 | $tree_icon = null; // default icon (folder) |
352 | } |
349 | } |
353 | */ |
350 | */ |
354 | 351 | ||
355 | $children[] = array( |
352 | $children[] = array( |
356 | 'id' => 'oidplus:resources$'.$dir, |
353 | 'id' => 'oidplus:resources$'.$dir, |
357 | 'icon' => $tree_icon, |
354 | 'icon' => $tree_icon, |
358 | 'text' => self::getFolderTitle($realdir), |
355 | 'text' => self::getFolderTitle($realdir), |
359 | 'children' => $tmp, |
356 | 'children' => $tmp, |
360 | 'state' => array("opened" => $depth <= OIDplus::config()->getValue('resource_plugin_autoopen_level', 1)-1) |
357 | 'state' => array("opened" => $depth <= OIDplus::config()->getValue('resource_plugin_autoopen_level', 1)-1) |
361 | ); |
358 | ); |
362 | } |
359 | } |
363 | 360 | ||
364 | $files = array_merge( |
361 | $files = array_merge( |
365 | self::myglob($rootdir.'*.htm'), // TODO: Also PHP? |
362 | self::myglob($rootdir.'*.htm'), // TODO: Also PHP? |
366 | self::myglob($rootdir.'*.html'), |
363 | self::myglob($rootdir.'*.html'), |
367 | self::myglob($rootdir.'*.url'), |
364 | self::myglob($rootdir.'*.url'), |
368 | self::myglob($rootdir.'*.link') |
365 | self::myglob($rootdir.'*.link') |
369 | ); |
366 | ); |
370 | natcasesort($files); |
367 | natcasesort($files); |
371 | foreach ($files as $file) { |
368 | foreach ($files as $file) { |
372 | $realfile = self::realname($file); |
369 | $realfile = self::realname($file); |
373 | if ((substr($file,-4,4) == '.url') || (substr($file,-5,5) == '.link')) { |
370 | if ((substr($file,-4,4) == '.url') || (substr($file,-5,5) == '.link')) { |
374 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_leaf_url&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
371 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_leaf_url&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
375 | /* |
372 | /* |
376 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_tree.png'; |
373 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_tree.png'; |
377 | if (file_exists($icon_candidate)) { |
374 | if (file_exists($icon_candidate)) { |
378 | $tree_icon = $icon_candidate; |
375 | $tree_icon = $icon_candidate; |
379 | } else if (file_exists(__DIR__.'/treeicon_leaf_url.png')) { |
376 | } else if (file_exists(__DIR__.'/treeicon_leaf_url.png')) { |
380 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_leaf_url.png'; |
377 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_leaf_url.png'; |
381 | } else { |
378 | } else { |
382 | $tree_icon = null; // default icon (folder) |
379 | $tree_icon = null; // default icon (folder) |
383 | } |
380 | } |
384 | */ |
381 | */ |
385 | 382 | ||
386 | $hyperlink_pic = ' <img src="'.OIDplus::webpath(__DIR__).'hyperlink.png" widht="13" height="13" alt="Hyperlink" style="top:-3px;position:relative">'; |
383 | $hyperlink_pic = ' <img src="'.OIDplus::webpath(__DIR__).'hyperlink.png" widht="13" height="13" alt="Hyperlink" style="top:-3px;position:relative">'; |
387 | 384 | ||
388 | $children[] = array( |
385 | $children[] = array( |
389 | 'id' => 'oidplus:resources$'.$file, |
386 | 'id' => 'oidplus:resources$'.$file, |
390 | 'conditionalselect' => 'window.open('.js_escape(self::getHyperlinkURL($realfile)).'); false;', |
387 | 'conditionalselect' => 'window.open('.js_escape(self::getHyperlinkURL($realfile)).'); false;', |
391 | 'icon' => $tree_icon, |
388 | 'icon' => $tree_icon, |
392 | 'text' => $this->getHyperlinkTitle($realfile).' '.$hyperlink_pic, |
389 | 'text' => $this->getHyperlinkTitle($realfile).' '.$hyperlink_pic, |
393 | 'state' => array("opened" => $depth <= OIDplus::config()->getValue('resource_plugin_autoopen_level', 1)-1) |
390 | 'state' => array("opened" => $depth <= OIDplus::config()->getValue('resource_plugin_autoopen_level', 1)-1) |
394 | ); |
391 | ); |
395 | } else { |
392 | } else { |
396 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_leaf_doc&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
393 | $tree_icon = OIDplus::webpath(__DIR__).'show_icon.php?mode=treeicon_leaf_doc&lang='.OIDplus::getCurrentLang().'&file='.urlencode($file); |
397 | /* |
394 | /* |
398 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_tree.png'; |
395 | $icon_candidate = pathinfo($realfile)['dirname'].'/'.pathinfo($realfile)['filename'].'_tree.png'; |
399 | if (file_exists($icon_candidate)) { |
396 | if (file_exists($icon_candidate)) { |
400 | $tree_icon = $icon_candidate; |
397 | $tree_icon = $icon_candidate; |
401 | } else if (file_exists(__DIR__.'/treeicon_leaf_doc.png')) { |
398 | } else if (file_exists(__DIR__.'/treeicon_leaf_doc.png')) { |
402 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_leaf_doc.png'; |
399 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon_leaf_doc.png'; |
403 | } else { |
400 | } else { |
404 | $tree_icon = null; // default icon (folder) |
401 | $tree_icon = null; // default icon (folder) |
405 | } |
402 | } |
406 | */ |
403 | */ |
407 | $children[] = array( |
404 | $children[] = array( |
408 | 'id' => 'oidplus:resources$'.$file, |
405 | 'id' => 'oidplus:resources$'.$file, |
409 | 'icon' => $tree_icon, |
406 | 'icon' => $tree_icon, |
410 | 'text' => $this->getDocumentTitle($file), |
407 | 'text' => $this->getDocumentTitle($file), |
411 | 'state' => array("opened" => $depth <= OIDplus::config()->getValue('resource_plugin_autoopen_level', 1)-1) |
408 | 'state' => array("opened" => $depth <= OIDplus::config()->getValue('resource_plugin_autoopen_level', 1)-1) |
412 | ); |
409 | ); |
413 | } |
410 | } |
414 | } |
411 | } |
415 | } |
412 | } |
416 | 413 | ||
417 | private function publicSitemap_rec($json, &$out) { |
414 | private function publicSitemap_rec($json, &$out) { |
418 | foreach ($json as $x) { |
415 | foreach ($json as $x) { |
419 | if (isset($x['id']) && $x['id']) { |
416 | if (isset($x['id']) && $x['id']) { |
420 | $out[] = $x['id']; |
417 | $out[] = $x['id']; |
421 | } |
418 | } |
422 | if (isset($x['children'])) { |
419 | if (isset($x['children'])) { |
423 | $this->publicSitemap_rec($x['children'], $out); |
420 | $this->publicSitemap_rec($x['children'], $out); |
424 | } |
421 | } |
425 | } |
422 | } |
426 | } |
423 | } |
427 | 424 | ||
428 | public function publicSitemap(&$out) { |
425 | public function publicSitemap(&$out) { |
429 | $json = array(); |
426 | $json = array(); |
430 | $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, true/*display all*/); |
427 | $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, true/*display all*/); |
431 | $this->publicSitemap_rec($json, $out); |
428 | $this->publicSitemap_rec($json, $out); |
432 | } |
429 | } |
433 | 430 | ||
434 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
431 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
435 | $children = array(); |
432 | $children = array(); |
436 | 433 | ||
437 | $this->tree_rec($children, '/'); |
434 | $this->tree_rec($children, '/'); |
438 | 435 | ||
439 | if (!OIDplus::config()->getValue('resource_plugin_hide_empty_path', true) || (count($children) > 0)) { |
436 | if (!OIDplus::config()->getValue('resource_plugin_hide_empty_path', true) || (count($children) > 0)) { |
440 | if (file_exists(__DIR__.'/treeicon.png')) { |
437 | if (file_exists(__DIR__.'/treeicon.png')) { |
441 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
438 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
442 | } else { |
439 | } else { |
443 | $tree_icon = null; // default icon (folder) |
440 | $tree_icon = null; // default icon (folder) |
444 | } |
441 | } |
445 | 442 | ||
446 | $json[] = array( |
443 | $json[] = array( |
447 | 'id' => 'oidplus:resources', |
444 | 'id' => 'oidplus:resources', |
448 | 'icon' => $tree_icon, |
445 | 'icon' => $tree_icon, |
449 | 'state' => array("opened" => true), |
446 | 'state' => array("opened" => true), |
450 | 'text' => $this->getMainTitle(), |
447 | 'text' => $this->getMainTitle(), |
451 | 'children' => $children |
448 | 'children' => $children |
452 | ); |
449 | ); |
453 | } |
450 | } |
454 | 451 | ||
455 | return true; |
452 | return true; |
456 | } |
453 | } |
457 | 454 | ||
458 | public function tree_search($request) { |
455 | public function tree_search($request) { |
459 | return false; |
456 | return false; |
460 | } |
457 | } |
461 | 458 | ||
462 | private static function getHyperlinkTitle($file) { |
459 | private static function getHyperlinkTitle($file) { |
463 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
460 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
464 | if (file_exists($file2)) $file = $file2; |
461 | if (file_exists($file2)) $file = $file2; |
465 | 462 | ||
466 | if (substr($file,-4,4) == '.url') { |
463 | if (substr($file,-4,4) == '.url') { |
467 | return preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($file)); |
464 | return preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($file)); |
468 | } else if (substr($file,-5,5) == '.link') { |
465 | } else if (substr($file,-5,5) == '.link') { |
469 | /* |
466 | /* |
470 | [Link] |
467 | [Link] |
471 | Title=Report a bug |
468 | Title=Report a bug |
472 | URL=https://www.viathinksoft.com/thinkbug/thinkbug.php?id=97 |
469 | URL=https://www.viathinksoft.com/thinkbug/thinkbug.php?id=97 |
473 | */ |
470 | */ |
474 | 471 | ||
475 | $data = @parse_ini_file($file, true); |
472 | $data = @parse_ini_file($file, true); |
476 | if (!$data) { |
473 | if (!$data) { |
477 | throw new OIDplusException(_L('File %1 has an invalid INI format!',$file)); |
474 | throw new OIDplusException(_L('File %1 has an invalid INI format!',$file)); |
478 | } |
475 | } |
479 | if (!isset($data['Link'])) { |
476 | if (!isset($data['Link'])) { |
480 | throw new OIDplusException(_L('Could not find "%1" section at %2','Link',$file)); |
477 | throw new OIDplusException(_L('Could not find "%1" section at %2','Link',$file)); |
481 | } |
478 | } |
482 | if (!isset($data['Link']['Title'])) { |
479 | if (!isset($data['Link']['Title'])) { |
483 | throw new OIDplusException(_L('"%1" is missing in %2','Title',$file)); |
480 | throw new OIDplusException(_L('"%1" is missing in %2','Title',$file)); |
484 | } |
481 | } |
485 | return $data['Link']['Title']; |
482 | return $data['Link']['Title']; |
486 | } else { |
483 | } else { |
487 | throw new OIDplusException(_L('Unexpected file extension for file %1',$file)); |
484 | throw new OIDplusException(_L('Unexpected file extension for file %1',$file)); |
488 | } |
485 | } |
489 | } |
486 | } |
490 | 487 | ||
491 | private static function getHyperlinkURL($file) { |
488 | private static function getHyperlinkURL($file) { |
492 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
489 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
493 | if (file_exists($file2)) $file = $file2; |
490 | if (file_exists($file2)) $file = $file2; |
494 | 491 | ||
495 | if (substr($file,-4,4) == '.url') { |
492 | if (substr($file,-4,4) == '.url') { |
496 | /* |
493 | /* |
497 | [{000214A0-0000-0000-C000-000000000046}] |
494 | [{000214A0-0000-0000-C000-000000000046}] |
498 | Prop3=19,2 |
495 | Prop3=19,2 |
499 | [InternetShortcut] |
496 | [InternetShortcut] |
500 | URL=http://www.example.com/ |
497 | URL=http://www.example.com/ |
501 | IDList= |
498 | IDList= |
502 | */ |
499 | */ |
503 | 500 | ||
504 | $data = @parse_ini_file($file, true); |
501 | $data = @parse_ini_file($file, true); |
505 | if (!$data) { |
502 | if (!$data) { |
506 | throw new OIDplusException(_L('File %1 has an invalid INI format!',$file)); |
503 | throw new OIDplusException(_L('File %1 has an invalid INI format!',$file)); |
507 | } |
504 | } |
508 | if (!isset($data['InternetShortcut'])) { |
505 | if (!isset($data['InternetShortcut'])) { |
509 | throw new OIDplusException(_L('Could not find "%1" section at %2','InternetShortcut',$file)); |
506 | throw new OIDplusException(_L('Could not find "%1" section at %2','InternetShortcut',$file)); |
510 | } |
507 | } |
511 | if (!isset($data['InternetShortcut']['URL'])) { |
508 | if (!isset($data['InternetShortcut']['URL'])) { |
512 | throw new OIDplusException(_L('"%1" is missing in %2','URL',$file)); |
509 | throw new OIDplusException(_L('"%1" is missing in %2','URL',$file)); |
513 | } |
510 | } |
514 | return $data['InternetShortcut']['URL']; |
511 | return $data['InternetShortcut']['URL']; |
515 | } else if (substr($file,-5,5) == '.link') { |
512 | } else if (substr($file,-5,5) == '.link') { |
516 | /* |
513 | /* |
517 | [Link] |
514 | [Link] |
518 | Title=Report a bug |
515 | Title=Report a bug |
519 | URL=https://www.viathinksoft.com/thinkbug/thinkbug.php?id=97 |
516 | URL=https://www.viathinksoft.com/thinkbug/thinkbug.php?id=97 |
520 | */ |
517 | */ |
521 | 518 | ||
522 | $data = @parse_ini_file($file, true); |
519 | $data = @parse_ini_file($file, true); |
523 | if (!$data) { |
520 | if (!$data) { |
524 | throw new OIDplusException(_L('File %1 has an invalid INI format!',$file)); |
521 | throw new OIDplusException(_L('File %1 has an invalid INI format!',$file)); |
525 | } |
522 | } |
526 | if (!isset($data['Link'])) { |
523 | if (!isset($data['Link'])) { |
527 | throw new OIDplusException(_L('Could not find "%1" section at %2','Link',$file)); |
524 | throw new OIDplusException(_L('Could not find "%1" section at %2','Link',$file)); |
528 | } |
525 | } |
529 | if (!isset($data['Link']['URL'])) { |
526 | if (!isset($data['Link']['URL'])) { |
530 | throw new OIDplusException(_L('"%1" is missing in %2','URL',$file)); |
527 | throw new OIDplusException(_L('"%1" is missing in %2','URL',$file)); |
531 | } |
528 | } |
532 | return $data['Link']['URL']; |
529 | return $data['Link']['URL']; |
533 | } else { |
530 | } else { |
534 | throw new OIDplusException(_L('Unexpected file extension for file %1',$file)); |
531 | throw new OIDplusException(_L('Unexpected file extension for file %1',$file)); |
535 | } |
532 | } |
536 | 533 | ||
537 | } |
534 | } |
538 | 535 | ||
539 | private static function getFolderTitle($dir) { |
536 | private static function getFolderTitle($dir) { |
540 | $data = @parse_ini_file("$dir/folder\$".OIDplus::getCurrentLang().".ini", true); |
537 | $data = @parse_ini_file("$dir/folder\$".OIDplus::getCurrentLang().".ini", true); |
541 | if ($data && isset($data['Folder']) && isset($data['Folder']['Title'])) { |
538 | if ($data && isset($data['Folder']) && isset($data['Folder']['Title'])) { |
542 | return $data['Folder']['Title']; |
539 | return $data['Folder']['Title']; |
543 | } |
540 | } |
544 | 541 | ||
545 | $data = @parse_ini_file("$dir/folder.ini", true); |
542 | $data = @parse_ini_file("$dir/folder.ini", true); |
546 | if ($data && isset($data['Folder']) && isset($data['Folder']['Title'])) { |
543 | if ($data && isset($data['Folder']) && isset($data['Folder']['Title'])) { |
547 | return $data['Folder']['Title']; |
544 | return $data['Folder']['Title']; |
548 | } |
545 | } |
549 | 546 | ||
550 | return basename($dir); |
547 | return basename($dir); |
551 | } |
548 | } |
552 | } |
549 | } |
553 | 550 |