Rev 256 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 256 | Rev 261 | ||
---|---|---|---|
Line 17... | Line 17... | ||
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | if (!defined('IN_OIDPLUS')) die(); |
20 | if (!defined('IN_OIDPLUS')) die(); |
21 | 21 | ||
22 | define('CFG_RESOURCE_PLUGIN_AUTOOPEN_LEVEL', 1); |
- | |
23 | define('CFG_RESOURCE_PLUGIN_TITLE', 'Documents and resources'); |
- | |
24 | define('CFG_RESOURCE_PLUGIN_PATH', 'res/'); |
- | |
25 | define('CFG_RESOURCE_PLUGIN_HIDE_EMPTY_PATH', true); |
- | |
26 | - | ||
27 | class OIDplusPagePublicResources extends OIDplusPagePluginPublic { |
22 | class OIDplusPagePublicResources extends OIDplusPagePluginPublic { |
28 | 23 | ||
29 | public static function getPluginInformation() { |
24 | public static function getPluginInformation() { |
30 | $out = array(); |
25 | $out = array(); |
31 | $out['name'] = 'Resources'; |
26 | $out['name'] = 'Resources'; |
Line 42... | Line 37... | ||
42 | public function action(&$handled) { |
37 | public function action(&$handled) { |
43 | // Nothing |
38 | // Nothing |
44 | } |
39 | } |
45 | 40 | ||
46 | public function init($html=true) { |
41 | public function init($html=true) { |
47 | // Nothing |
- | |
- | 42 | OIDplus::config()->prepareConfigKey('resource_plugin_autoopen_level', 'Resource plugin: How many levels should be open in the treeview when OIDplus is loaded?', 1, 0, 1); |
|
- | 43 | OIDplus::config()->prepareConfigKey('resource_plugin_title', 'Resource plugin: Title of the resource section?', 'Documents and resources', 0, 1); |
|
- | 44 | OIDplus::config()->prepareConfigKey('resource_plugin_path', 'Resource plugin: Path that contains the documents?', 'res/', 0, 1); |
|
- | 45 | OIDplus::config()->prepareConfigKey('resource_plugin_hide_empty_path','Resource plugin: Hide empty paths? 1=on, 0=off', 1, 0, 1); |
|
48 | } |
46 | } |
49 | 47 | ||
50 | public function cfgSetValue($name, $value) { |
48 | public function cfgSetValue($name, $value) { |
- | 49 | if ($name == 'resource_plugin_autoopen_level') { |
|
- | 50 | if (!is_numeric($value) || ($value < 0)) { |
|
- | 51 | throw new OIDplusException("Please enter a valid value."); |
|
- | 52 | } |
|
- | 53 | } |
|
- | 54 | ||
- | 55 | if ($name == 'resource_plugin_path') { |
|
51 | // Nothing |
56 | // TODO: check if path exists |
- | 57 | } |
|
- | 58 | ||
- | 59 | if ($name == 'resource_plugin_hide_empty_path') { |
|
- | 60 | if (!is_numeric($value) || (($value != 0) && ($value != 1))) { |
|
- | 61 | throw new OIDplusException("Please enter a valid value (0=off, 1=on)."); |
|
- | 62 | } |
|
- | 63 | } |
|
52 | } |
64 | } |
53 | 65 | ||
54 | private static function getDocumentTitle($file) { |
66 | private static function getDocumentTitle($file) { |
55 | $cont = file_get_contents($file); |
67 | $cont = file_get_contents($file); |
56 | if (preg_match('@<title>(.+)</title>@ismU', $cont, $m)) return $m[1]; |
68 | if (preg_match('@<title>(.+)</title>@ismU', $cont, $m)) return $m[1]; |
Line 75... | Line 87... | ||
75 | $out['icon'] = 'img/error_big.png'; |
87 | $out['icon'] = 'img/error_big.png'; |
76 | $out['text'] = '<p>Invalid authentication token</p>'; |
88 | $out['text'] = '<p>Invalid authentication token</p>'; |
77 | return $out; |
89 | return $out; |
78 | } |
90 | } |
79 | 91 | ||
80 | if (strpos($file, CFG_RESOURCE_PLUGIN_PATH) !== 0) { |
92 | if (strpos($file, OIDplus::config()->getValue('resource_plugin_path', 'res/')) !== 0) { |
81 | $out['title'] = 'Access denied'; |
93 | $out['title'] = 'Access denied'; |
82 | $out['icon'] = 'img/error_big.png'; |
94 | $out['icon'] = 'img/error_big.png'; |
83 | $out['text'] = '<p>Security breach A</p>'; |
95 | $out['text'] = '<p>Security breach A</p>'; |
84 | return $out; |
96 | return $out; |
85 | } |
97 | } |
86 | 98 | ||
87 | if (strpos($file, '..') !== false) { |
99 | if (strpos($file, '..') !== false) { |
88 | $out['title'] = 'Access denied'; |
100 | $out['title'] = 'Access denied'; |
89 | $out['icon'] = 'img/error_big.png'; |
101 | $out['icon'] = 'img/error_big.png'; |
90 | $out['text'] = '<p>Security breach A</p>'; |
102 | $out['text'] = '<p>Security breach B</p>'; |
91 | return $out; |
103 | return $out; |
92 | } |
104 | } |
93 | 105 | ||
94 | $out['text'] = ''; |
106 | $out['text'] = ''; |
95 | 107 | ||
96 | if ($file != CFG_RESOURCE_PLUGIN_PATH) { |
108 | if ($file != OIDplus::config()->getValue('resource_plugin_path', 'res/')) { |
97 | $dir = dirname($file).'/'; |
109 | $dir = dirname($file).'/'; |
98 | 110 | ||
99 | if ($dir == CFG_RESOURCE_PLUGIN_PATH) { |
111 | if ($dir == OIDplus::config()->getValue('resource_plugin_path', 'res/')) { |
100 | if (file_exists(__DIR__.'/treeicon.png')) { |
112 | if (file_exists(__DIR__.'/treeicon.png')) { |
101 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
113 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
102 | } else { |
114 | } else { |
103 | $tree_icon = null; // default icon (folder) |
115 | $tree_icon = null; // default icon (folder) |
104 | } |
116 | } |
105 | 117 | ||
106 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
118 | $ic = empty($tree_icon) ? '' : '<img src="'.$tree_icon.'" alt="">'; |
107 | 119 | ||
108 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:resources$'.CFG_RESOURCE_PLUGIN_PATH.'$'.OIDplus::authUtils()::makeAuthKey("resources;".CFG_RESOURCE_PLUGIN_PATH)).'><img src="img/arrow_back.png" width="16"> Go back to: '.$ic.' '.htmlentities(CFG_RESOURCE_PLUGIN_TITLE).'</a></p>'; |
120 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:resources$'.OIDplus::config()->getValue('resource_plugin_path', 'res/').'$'.OIDplus::authUtils()::makeAuthKey("resources;".OIDplus::config()->getValue('resource_plugin_path', 'res/'))).'><img src="img/arrow_back.png" width="16"> Go back to: '.$ic.' '.htmlentities(OIDplus::config()->getValue('resource_plugin_title', 'Documents and resources')).'</a></p>'; |
109 | } else { |
121 | } else { |
110 | $icon_candidate = pathinfo($dir)['dirname'].'/'.pathinfo($dir)['filename'].'_tree.png'; |
122 | $icon_candidate = pathinfo($dir)['dirname'].'/'.pathinfo($dir)['filename'].'_tree.png'; |
111 | if (file_exists($icon_candidate)) { |
123 | if (file_exists($icon_candidate)) { |
112 | $tree_icon = $icon_candidate; |
124 | $tree_icon = $icon_candidate; |
113 | } else if (file_exists(__DIR__.'/treeicon_folder.png')) { |
125 | } else if (file_exists(__DIR__.'/treeicon_folder.png')) { |
Line 161... | Line 173... | ||
161 | $out['icon'] = 'img/error_big.png'; |
173 | $out['icon'] = 'img/error_big.png'; |
162 | $out['text'] = '<p>The system does not know how to handle this file type.</p>'; |
174 | $out['text'] = '<p>The system does not know how to handle this file type.</p>'; |
163 | return $out; |
175 | return $out; |
164 | } |
176 | } |
165 | } else if (is_dir($file)) { |
177 | } else if (is_dir($file)) { |
166 | $out['title'] = ($file == CFG_RESOURCE_PLUGIN_PATH) ? CFG_RESOURCE_PLUGIN_TITLE : basename($file); |
178 | $out['title'] = ($file == OIDplus::config()->getValue('resource_plugin_path', 'res/')) ? OIDplus::config()->getValue('resource_plugin_title', 'Documents and resources') : basename($file); |
167 | 179 | ||
168 | if ($file == CFG_RESOURCE_PLUGIN_PATH) { |
180 | if ($file == OIDplus::config()->getValue('resource_plugin_path', 'res/')) { |
169 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : ''; |
181 | $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : ''; |
170 | } else { |
182 | } else { |
171 | $icon_candidate = pathinfo($file)['dirname'].'/'.pathinfo($file)['filename'].'_big.png'; |
183 | $icon_candidate = pathinfo($file)['dirname'].'/'.pathinfo($file)['filename'].'_big.png'; |
172 | if (file_exists($icon_candidate)) { |
184 | if (file_exists($icon_candidate)) { |
173 | $out['icon'] = $icon_candidate; |
185 | $out['icon'] = $icon_candidate; |
Line 251... | Line 263... | ||
251 | return $out; |
263 | return $out; |
252 | } |
264 | } |
253 | } |
265 | } |
254 | } |
266 | } |
255 | 267 | ||
256 | private function tree_rec(&$children, $rootdir=CFG_RESOURCE_PLUGIN_PATH, $depth=0) { |
268 | private function tree_rec(&$children, $rootdir=null, $depth=0) { |
- | 269 | if (is_null($rootdir)) $rootdir = OIDplus::config()->getValue('resource_plugin_path', 'res/'); |
|
257 | if ($depth > 100) return false; // something is wrong! |
270 | if ($depth > 100) return false; // something is wrong! |
258 | 271 | ||
259 | $dirs = glob($rootdir.'*'.'/', GLOB_ONLYDIR); |
272 | $dirs = glob($rootdir.'*'.'/', GLOB_ONLYDIR); |
260 | natcasesort($dirs); |
273 | natcasesort($dirs); |
261 | foreach ($dirs as $dir) { |
274 | foreach ($dirs as $dir) { |
Line 274... | Line 287... | ||
274 | $children[] = array( |
287 | $children[] = array( |
275 | 'id' => 'oidplus:resources$'.$dir.'$'.OIDplus::authUtils()::makeAuthKey("resources;$dir"), |
288 | 'id' => 'oidplus:resources$'.$dir.'$'.OIDplus::authUtils()::makeAuthKey("resources;$dir"), |
276 | 'icon' => $tree_icon, |
289 | 'icon' => $tree_icon, |
277 | 'text' => basename($dir), |
290 | 'text' => basename($dir), |
278 | 'children' => $tmp, |
291 | 'children' => $tmp, |
279 | 'state' => array("opened" => $depth <= CFG_RESOURCE_PLUGIN_AUTOOPEN_LEVEL-1) |
292 | 'state' => array("opened" => $depth <= OIDplus::config()->getValue('resource_plugin_autoopen_level', 1)-1) |
280 | ); |
293 | ); |
281 | } |
294 | } |
282 | 295 | ||
283 | $files = array_merge( |
296 | $files = array_merge( |
284 | glob($rootdir.'*.htm*'), // TODO: Also PHP? |
297 | glob($rootdir.'*.htm*'), // TODO: Also PHP? |
Line 302... | Line 315... | ||
302 | $children[] = array( |
315 | $children[] = array( |
303 | 'id' => 'oidplus:resources$'.$file.'$'.OIDplus::authUtils()::makeAuthKey("resources;$file"), |
316 | 'id' => 'oidplus:resources$'.$file.'$'.OIDplus::authUtils()::makeAuthKey("resources;$file"), |
304 | 'conditionalselect' => 'window.open('.js_escape(self::getHyperlinkURL($file)).'); false;', |
317 | 'conditionalselect' => 'window.open('.js_escape(self::getHyperlinkURL($file)).'); false;', |
305 | 'icon' => $tree_icon, |
318 | 'icon' => $tree_icon, |
306 | 'text' => $this->getHyperlinkTitle($file).' '.$hyperlink_pic, |
319 | 'text' => $this->getHyperlinkTitle($file).' '.$hyperlink_pic, |
307 | 'state' => array("opened" => $depth <= CFG_RESOURCE_PLUGIN_AUTOOPEN_LEVEL-1) |
320 | 'state' => array("opened" => $depth <= OIDplus::config()->getValue('resource_plugin_autoopen_level', 1)-1) |
308 | ); |
321 | ); |
309 | 322 | ||
310 | } else { |
323 | } else { |
311 | $icon_candidate = pathinfo($file)['dirname'].'/'.pathinfo($file)['filename'].'_tree.png'; |
324 | $icon_candidate = pathinfo($file)['dirname'].'/'.pathinfo($file)['filename'].'_tree.png'; |
312 | if (file_exists($icon_candidate)) { |
325 | if (file_exists($icon_candidate)) { |
Line 318... | Line 331... | ||
318 | } |
331 | } |
319 | $children[] = array( |
332 | $children[] = array( |
320 | 'id' => 'oidplus:resources$'.$file.'$'.OIDplus::authUtils()::makeAuthKey("resources;$file"), |
333 | 'id' => 'oidplus:resources$'.$file.'$'.OIDplus::authUtils()::makeAuthKey("resources;$file"), |
321 | 'icon' => $tree_icon, |
334 | 'icon' => $tree_icon, |
322 | 'text' => $this->getDocumentTitle($file), |
335 | 'text' => $this->getDocumentTitle($file), |
323 | 'state' => array("opened" => $depth <= CFG_RESOURCE_PLUGIN_AUTOOPEN_LEVEL-1) |
336 | 'state' => array("opened" => $depth <= OIDplus::config()->getValue('resource_plugin_autoopen_level', 1)-1) |
324 | ); |
337 | ); |
325 | } |
338 | } |
326 | } |
339 | } |
327 | } |
340 | } |
328 | 341 | ||
329 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
342 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
330 | $children = array(); |
343 | $children = array(); |
331 | 344 | ||
332 | $this->tree_rec($children, CFG_RESOURCE_PLUGIN_PATH); |
345 | $this->tree_rec($children, OIDplus::config()->getValue('resource_plugin_path', 'res/')); |
333 | 346 | ||
334 | if (!CFG_RESOURCE_PLUGIN_HIDE_EMPTY_PATH || (count($children) > 0)) { |
347 | if (!OIDplus::config()->getValue('resource_plugin_hide_empty_path', true) || (count($children) > 0)) { |
335 | if (file_exists(__DIR__.'/treeicon.png')) { |
348 | if (file_exists(__DIR__.'/treeicon.png')) { |
336 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
349 | $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png'; |
337 | } else { |
350 | } else { |
338 | $tree_icon = null; // default icon (folder) |
351 | $tree_icon = null; // default icon (folder) |
339 | } |
352 | } |
340 | 353 | ||
341 | $json[] = array( |
354 | $json[] = array( |
342 | 'id' => 'oidplus:resources$'.CFG_RESOURCE_PLUGIN_PATH.'$'.OIDplus::authUtils()::makeAuthKey("resources;".CFG_RESOURCE_PLUGIN_PATH), |
355 | 'id' => 'oidplus:resources$'.OIDplus::config()->getValue('resource_plugin_path', 'res/').'$'.OIDplus::authUtils()::makeAuthKey("resources;".OIDplus::config()->getValue('resource_plugin_path', 'res/')), |
343 | 'icon' => $tree_icon, |
356 | 'icon' => $tree_icon, |
344 | 'state' => array("opened" => true), |
357 | 'state' => array("opened" => true), |
345 | 'text' => CFG_RESOURCE_PLUGIN_TITLE, |
358 | 'text' => OIDplus::config()->getValue('resource_plugin_title', 'Documents and resources'), |
346 | 'children' => $children |
359 | 'children' => $children |
347 | ); |
360 | ); |
348 | } |
361 | } |
349 | 362 | ||
350 | return true; |
363 | return true; |