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