Rev 1086 | Rev 1130 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1086 | Rev 1116 | ||
---|---|---|---|
Line 23... | Line 23... | ||
23 | \defined('INSIDE_OIDPLUS') or die; |
23 | \defined('INSIDE_OIDPLUS') or die; |
24 | // phpcs:enable PSR1.Files.SideEffects |
24 | // phpcs:enable PSR1.Files.SideEffects |
25 | 25 | ||
26 | class OIDplusPagePublicResources extends OIDplusPagePluginPublic { |
26 | class OIDplusPagePublicResources extends OIDplusPagePluginPublic { |
27 | 27 | ||
- | 28 | /** |
|
- | 29 | * @return array|mixed|string|string[] |
|
- | 30 | */ |
|
28 | private function getMainTitle() { |
31 | private function getMainTitle() { |
29 | return _L('Documents and Resources'); |
32 | return _L('Documents and Resources'); |
30 | } |
33 | } |
31 | 34 | ||
- | 35 | /** |
|
- | 36 | * @param bool $html |
|
- | 37 | * @return void |
|
- | 38 | * @throws OIDplusException |
|
- | 39 | */ |
|
32 | public function init($html=true) { |
40 | public function init(bool $html=true) { |
33 | 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) { |
41 | 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) { |
34 | if (!is_numeric($value) || ($value < 0)) { |
42 | if (!is_numeric($value) || ($value < 0)) { |
35 | throw new OIDplusException(_L('Please enter a valid value.')); |
43 | throw new OIDplusException(_L('Please enter a valid value.')); |
36 | } |
44 | } |
37 | }); |
45 | }); |
Line 42... | Line 50... | ||
42 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
50 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
43 | } |
51 | } |
44 | }); |
52 | }); |
45 | } |
53 | } |
46 | 54 | ||
- | 55 | /** |
|
- | 56 | * @param $file |
|
- | 57 | * @return string |
|
- | 58 | * @throws OIDplusConfigInitializationException |
|
- | 59 | * @throws OIDplusException |
|
- | 60 | */ |
|
47 | private static function getDocumentContent($file) { |
61 | private static function getDocumentContent($file) { |
48 | $file = self::realname($file); |
62 | $file = self::realname($file); |
49 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
63 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
50 | if (file_exists($file2)) $file = $file2; |
64 | if (file_exists($file2)) $file = $file2; |
51 | 65 | ||
Line 58... | Line 72... | ||
58 | $cont .= stripHtmlComments($html); |
72 | $cont .= stripHtmlComments($html); |
59 | 73 | ||
60 | return $cont; |
74 | return $cont; |
61 | } |
75 | } |
62 | 76 | ||
- | 77 | /** |
|
- | 78 | * @param $file |
|
- | 79 | * @return array|mixed|string |
|
- | 80 | * @throws OIDplusConfigInitializationException |
|
- | 81 | * @throws OIDplusException |
|
- | 82 | */ |
|
63 | private static function getDocumentTitle($file) { |
83 | private static function getDocumentTitle($file) { |
64 | $file = self::realname($file); |
84 | $file = self::realname($file); |
65 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
85 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
66 | if (file_exists($file2)) $file = $file2; |
86 | if (file_exists($file2)) $file = $file2; |
67 | 87 | ||
Line 79... | Line 99... | ||
79 | if (preg_match('@<h5>(.+)</h5>@ismU', $cont, $m)) return $m[1]; |
99 | if (preg_match('@<h5>(.+)</h5>@ismU', $cont, $m)) return $m[1]; |
80 | if (preg_match('@<h6>(.+)</h6>@ismU', $cont, $m)) return $m[1]; |
100 | if (preg_match('@<h6>(.+)</h6>@ismU', $cont, $m)) return $m[1]; |
81 | return pathinfo($file, PATHINFO_FILENAME); // filename without extension |
101 | return pathinfo($file, PATHINFO_FILENAME); // filename without extension |
82 | } |
102 | } |
83 | 103 | ||
- | 104 | /** |
|
- | 105 | * @param $source |
|
- | 106 | * @return bool |
|
- | 107 | * @throws OIDplusException |
|
- | 108 | */ |
|
84 | protected static function mayAccessResource($source) { |
109 | protected static function mayAccessResource($source) { |
85 | if (OIDplus::authUtils()->isAdminLoggedIn()) return true; |
110 | if (OIDplus::authUtils()->isAdminLoggedIn()) return true; |
86 | 111 | ||
87 | $candidates = array( |
112 | $candidates = array( |
88 | OIDplus::localpath().'userdata/resources/security.ini', |
113 | OIDplus::localpath().'userdata/resources/security.ini', |
Line 108... | Line 133... | ||
108 | } |
133 | } |
109 | } |
134 | } |
110 | return true; |
135 | return true; |
111 | } |
136 | } |
112 | 137 | ||
- | 138 | /** |
|
- | 139 | * @param $reldir |
|
- | 140 | * @param $onlydir |
|
- | 141 | * @return array |
|
- | 142 | * @throws OIDplusException |
|
- | 143 | */ |
|
113 | private static function myglob($reldir, $onlydir=false) { |
144 | private static function myglob($reldir, $onlydir=false) { |
114 | $out = array(); |
145 | $out = array(); |
115 | 146 | ||
116 | $root = OIDplus::localpath().'userdata/resources/'; |
147 | $root = OIDplus::localpath().'userdata/resources/'; |
117 | $res = $onlydir ? @glob($root.ltrim($reldir,'/'), GLOB_ONLYDIR) : @glob($root.ltrim($reldir,'/')); |
148 | $res = $onlydir ? @glob($root.ltrim($reldir,'/'), GLOB_ONLYDIR) : @glob($root.ltrim($reldir,'/')); |
Line 134... | Line 165... | ||
134 | return array_filter($out, function($v, $k) { |
165 | return array_filter($out, function($v, $k) { |
135 | return self::mayAccessResource($v); |
166 | return self::mayAccessResource($v); |
136 | }, ARRAY_FILTER_USE_BOTH); |
167 | }, ARRAY_FILTER_USE_BOTH); |
137 | } |
168 | } |
138 | 169 | ||
- | 170 | /** |
|
- | 171 | * @param $rel |
|
- | 172 | * @return string|null |
|
- | 173 | */ |
|
139 | private static function realname($rel) { |
174 | private static function realname($rel) { |
140 | $candidate1 = OIDplus::localpath().'userdata/resources/'.$rel; |
175 | $candidate1 = OIDplus::localpath().'userdata/resources/'.$rel; |
141 | $candidate2 = OIDplus::localpath().'res/'.$rel; |
176 | $candidate2 = OIDplus::localpath().'res/'.$rel; |
142 | if (file_exists($candidate1) || is_dir($candidate1)) return $candidate1; |
177 | if (file_exists($candidate1) || is_dir($candidate1)) return $candidate1; |
143 | if (file_exists($candidate2) || is_dir($candidate2)) return $candidate2; |
178 | if (file_exists($candidate2) || is_dir($candidate2)) return $candidate2; |
144 | return null; |
179 | return null; |
145 | } |
180 | } |
146 | 181 | ||
- | 182 | /** |
|
- | 183 | * @param $source |
|
- | 184 | * @param $target |
|
- | 185 | * @return bool |
|
- | 186 | */ |
|
147 | protected static function checkRedirect($source, &$target): bool { |
187 | protected static function checkRedirect($source, &$target): bool { |
148 | $candidates = array( |
188 | $candidates = array( |
149 | OIDplus::localpath().'userdata/resources/redirect.ini', |
189 | OIDplus::localpath().'userdata/resources/redirect.ini', |
150 | OIDplus::localpath().'res/redirect.ini' |
190 | OIDplus::localpath().'res/redirect.ini' |
151 | ); |
191 | ); |
Line 159... | Line 199... | ||
159 | } |
199 | } |
160 | } |
200 | } |
161 | return false; |
201 | return false; |
162 | } |
202 | } |
163 | 203 | ||
- | 204 | /** |
|
- | 205 | * @param string $id |
|
- | 206 | * @param array $out |
|
- | 207 | * @param bool $handled |
|
- | 208 | * @return void |
|
- | 209 | * @throws OIDplusConfigInitializationException |
|
- | 210 | * @throws OIDplusException |
|
- | 211 | */ |
|
164 | public function gui($id, &$out, &$handled) { |
212 | public function gui(string $id, array &$out, bool &$handled) { |
165 | if (explode('$',$id,2)[0] === 'oidplus:resources') { |
213 | if (explode('$',$id,2)[0] === 'oidplus:resources') { |
166 | $handled = true; |
214 | $handled = true; |
167 | 215 | ||
168 | $tmp = explode('$',$id); |
216 | $tmp = explode('$',$id); |
169 | $file = isset($tmp[1]) ? $tmp[1] : ''; |
217 | $file = isset($tmp[1]) ? $tmp[1] : ''; |
Line 292... | Line 340... | ||
292 | $out['text'] .= self::getDocumentContent($file); |
340 | $out['text'] .= self::getDocumentContent($file); |
293 | } else { |
341 | } else { |
294 | $out['title'] = _L('Unknown file type'); |
342 | $out['title'] = _L('Unknown file type'); |
295 | $out['icon'] = 'img/error.png'; |
343 | $out['icon'] = 'img/error.png'; |
296 | $out['text'] = '<p>'._L('The system does not know how to handle this file type.').'</p>'; |
344 | $out['text'] = '<p>'._L('The system does not know how to handle this file type.').'</p>'; |
297 | return; |
- | |
298 | } |
345 | } |
299 | } else if (is_dir($realfile)) { |
346 | } else if (is_dir($realfile)) { |
300 | $out['title'] = ($file == '') ? $this->getMainTitle() : self::getFolderTitle($realfile); |
347 | $out['title'] = ($file == '') ? $this->getMainTitle() : self::getFolderTitle($realfile); |
301 | 348 | ||
302 | if ($file == '') { |
349 | if ($file == '') { |
Line 400... | Line 447... | ||
400 | $out['text'] = '<p>'._L('This resource doesn\'t exist anymore.').'</p>'; |
447 | $out['text'] = '<p>'._L('This resource doesn\'t exist anymore.').'</p>'; |
401 | } |
448 | } |
402 | } |
449 | } |
403 | } |
450 | } |
404 | 451 | ||
- | 452 | /** |
|
- | 453 | * @param $children |
|
- | 454 | * @param ?string $rootdir |
|
- | 455 | * @param int $depth |
|
- | 456 | * @return void |
|
- | 457 | * @throws OIDplusConfigInitializationException |
|
- | 458 | * @throws OIDplusException |
|
- | 459 | */ |
|
405 | private function tree_rec(&$children, $rootdir=null, $depth=0) { |
460 | private function tree_rec(&$children, string $rootdir=null, int $depth=0)/*: void*/ { |
406 | if (is_null($rootdir)) $rootdir = ''; |
461 | if (is_null($rootdir)) $rootdir = ''; |
407 | if ($depth > 100) return false; // something is wrong! |
462 | if ($depth > 100) return; // something is wrong! |
408 | 463 | ||
409 | $dirs = self::myglob($rootdir.'*'.'/', true); |
464 | $dirs = self::myglob($rootdir.'*'.'/', true); |
410 | natcasesort($dirs); |
465 | natcasesort($dirs); |
411 | foreach ($dirs as $dir) { |
466 | foreach ($dirs as $dir) { |
412 | $tmp = array(); |
467 | $tmp = array(); |
Line 489... | Line 544... | ||
489 | ); |
544 | ); |
490 | } |
545 | } |
491 | } |
546 | } |
492 | } |
547 | } |
493 | 548 | ||
- | 549 | /** |
|
- | 550 | * @param $json |
|
- | 551 | * @param $out |
|
- | 552 | * @return void |
|
- | 553 | */ |
|
494 | private function publicSitemap_rec($json, &$out) { |
554 | private function publicSitemap_rec($json, &$out) { |
495 | foreach ($json as $x) { |
555 | foreach ($json as $x) { |
496 | if (isset($x['id']) && $x['id']) { |
556 | if (isset($x['id']) && $x['id']) { |
497 | $out[] = $x['id']; |
557 | $out[] = $x['id']; |
498 | } |
558 | } |
Line 500... | Line 560... | ||
500 | $this->publicSitemap_rec($x['children'], $out); |
560 | $this->publicSitemap_rec($x['children'], $out); |
501 | } |
561 | } |
502 | } |
562 | } |
503 | } |
563 | } |
504 | 564 | ||
- | 565 | /** |
|
- | 566 | * @param array $out |
|
- | 567 | * @return void |
|
- | 568 | */ |
|
505 | public function publicSitemap(&$out) { |
569 | public function publicSitemap(array &$out) { |
506 | $json = array(); |
570 | $json = array(); |
507 | $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, true/*display all*/); |
571 | $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, "*"/*display all*/); |
508 | $this->publicSitemap_rec($json, $out); |
572 | $this->publicSitemap_rec($json, $out); |
509 | } |
573 | } |
510 | 574 | ||
- | 575 | /** |
|
- | 576 | * @param array $json |
|
- | 577 | * @param string|null $ra_email |
|
- | 578 | * @param bool $nonjs |
|
- | 579 | * @param string $req_goto |
|
- | 580 | * @return bool |
|
- | 581 | * @throws OIDplusConfigInitializationException |
|
- | 582 | * @throws OIDplusException |
|
- | 583 | */ |
|
511 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
584 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
512 | $children = array(); |
585 | $children = array(); |
513 | 586 | ||
514 | $this->tree_rec($children, '/'); |
587 | $this->tree_rec($children, '/'); |
515 | 588 | ||
516 | if (!OIDplus::config()->getValue('resource_plugin_hide_empty_path', true) || (count($children) > 0)) { |
589 | if (!OIDplus::config()->getValue('resource_plugin_hide_empty_path', true) || (count($children) > 0)) { |
Line 530... | Line 603... | ||
530 | } |
603 | } |
531 | 604 | ||
532 | return true; |
605 | return true; |
533 | } |
606 | } |
534 | 607 | ||
- | 608 | /** |
|
- | 609 | * @param string $request |
|
- | 610 | * @return array|false |
|
- | 611 | */ |
|
535 | public function tree_search($request) { |
612 | public function tree_search(string $request) { |
536 | return false; |
613 | return false; |
537 | } |
614 | } |
538 | 615 | ||
- | 616 | /** |
|
- | 617 | * @param $file |
|
- | 618 | * @return array|mixed|string|string[]|null |
|
- | 619 | * @throws OIDplusConfigInitializationException |
|
- | 620 | * @throws OIDplusException |
|
- | 621 | */ |
|
539 | private static function getHyperlinkTitle($file) { |
622 | private static function getHyperlinkTitle($file) { |
540 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
623 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
541 | if (file_exists($file2)) $file = $file2; |
624 | if (file_exists($file2)) $file = $file2; |
542 | 625 | ||
543 | if (substr($file,-4,4) == '.url') { |
626 | if (substr($file,-4,4) == '.url') { |
Line 563... | Line 646... | ||
563 | } else { |
646 | } else { |
564 | throw new OIDplusException(_L('Unexpected file extension for file %1',$file)); |
647 | throw new OIDplusException(_L('Unexpected file extension for file %1',$file)); |
565 | } |
648 | } |
566 | } |
649 | } |
567 | 650 | ||
- | 651 | /** |
|
- | 652 | * @param $file |
|
- | 653 | * @return mixed |
|
- | 654 | * @throws OIDplusConfigInitializationException |
|
- | 655 | * @throws OIDplusException |
|
- | 656 | */ |
|
568 | private static function getHyperlinkURL($file) { |
657 | private static function getHyperlinkURL($file) { |
569 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
658 | $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file); |
570 | if (file_exists($file2)) $file = $file2; |
659 | if (file_exists($file2)) $file = $file2; |
571 | 660 | ||
572 | if (substr($file,-4,4) == '.url') { |
661 | if (substr($file,-4,4) == '.url') { |
Line 608... | Line 697... | ||
608 | throw new OIDplusException(_L('Unexpected file extension for file %1',$file)); |
697 | throw new OIDplusException(_L('Unexpected file extension for file %1',$file)); |
609 | } |
698 | } |
610 | 699 | ||
611 | } |
700 | } |
612 | 701 | ||
- | 702 | /** |
|
- | 703 | * @param $dir |
|
- | 704 | * @return mixed|string |
|
- | 705 | * @throws OIDplusConfigInitializationException |
|
- | 706 | * @throws OIDplusException |
|
- | 707 | */ |
|
613 | private static function getFolderTitle($dir) { |
708 | private static function getFolderTitle($dir) { |
614 | $data = @parse_ini_file("$dir/folder\$".OIDplus::getCurrentLang().".ini", true); |
709 | $data = @parse_ini_file("$dir/folder\$".OIDplus::getCurrentLang().".ini", true); |
615 | if ($data && isset($data['Folder']) && isset($data['Folder']['Title'])) { |
710 | if ($data && isset($data['Folder']) && isset($data['Folder']['Title'])) { |
616 | return $data['Folder']['Title']; |
711 | return $data['Folder']['Title']; |
617 | } |
712 | } |