Subversion Repositories oidplus

Rev

Rev 1116 | Rev 1143 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1116 Rev 1130
Line 51... Line 51...
51
                        }
51
                        }
52
                });
52
                });
53
        }
53
        }
54
 
54
 
55
        /**
55
        /**
56
         * @param $file
56
         * @param string $file
57
         * @return string
57
         * @return string
58
         * @throws OIDplusConfigInitializationException
58
         * @throws OIDplusConfigInitializationException|OIDplusException
59
         * @throws OIDplusException
-
 
60
         */
59
         */
61
        private static function getDocumentContent($file) {
60
        private static function getDocumentContent(string $file): string {
62
                $file = self::realname($file);
61
                $file = self::realname($file);
63
                $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file);
62
                $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file);
64
                if (file_exists($file2)) $file = $file2;
63
                if (file_exists($file2)) $file = $file2;
65
 
64
 
66
                $cont = file_get_contents($file);
65
                $cont = file_get_contents($file);
Line 73... Line 72...
73
 
72
 
74
                return $cont;
73
                return $cont;
75
        }
74
        }
76
 
75
 
77
        /**
76
        /**
78
         * @param $file
77
         * @param string $file
79
         * @return array|mixed|string
78
         * @return array|mixed|string
80
         * @throws OIDplusConfigInitializationException
79
         * @throws OIDplusConfigInitializationException
81
         * @throws OIDplusException
80
         * @throws OIDplusException
82
         */
81
         */
83
        private static function getDocumentTitle($file) {
82
        private static function getDocumentTitle(string $file) {
84
                $file = self::realname($file);
83
                $file = self::realname($file);
85
                $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file);
84
                $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file);
86
                if (file_exists($file2)) $file = $file2;
85
                if (file_exists($file2)) $file = $file2;
87
 
86
 
88
                $cont = file_get_contents($file);
87
                $cont = file_get_contents($file);
Line 100... Line 99...
100
                if (preg_match('@<h6>(.+)</h6>@ismU', $cont, $m)) return $m[1];
99
                if (preg_match('@<h6>(.+)</h6>@ismU', $cont, $m)) return $m[1];
101
                return pathinfo($file, PATHINFO_FILENAME); // filename without extension
100
                return pathinfo($file, PATHINFO_FILENAME); // filename without extension
102
        }
101
        }
103
 
102
 
104
        /**
103
        /**
105
         * @param $source
104
         * @param string $source
106
         * @return bool
105
         * @return bool
107
         * @throws OIDplusException
106
         * @throws OIDplusException
108
         */
107
         */
109
        protected static function mayAccessResource($source) {
108
        protected static function mayAccessResource(string $source): bool {
110
                if (OIDplus::authUtils()->isAdminLoggedIn()) return true;
109
                if (OIDplus::authUtils()->isAdminLoggedIn()) return true;
111
 
110
 
112
                $candidates = array(
111
                $candidates = array(
113
                        OIDplus::localpath().'userdata/resources/security.ini',
112
                        OIDplus::localpath().'userdata/resources/security.ini',
114
                        OIDplus::localpath().'res/security.ini'
113
                        OIDplus::localpath().'res/security.ini'
Line 134... Line 133...
134
                }
133
                }
135
                return true;
134
                return true;
136
        }
135
        }
137
 
136
 
138
        /**
137
        /**
139
         * @param $reldir
138
         * @param string $reldir
140
         * @param $onlydir
139
         * @param bool $onlydir
141
         * @return array
140
         * @return array
142
         * @throws OIDplusException
141
         * @throws OIDplusException
143
         */
142
         */
144
        private static function myglob($reldir, $onlydir=false) {
143
        private static function myglob(string $reldir, bool $onlydir=false): array {
145
                $out = array();
144
                $out = array();
146
 
145
 
147
                $root = OIDplus::localpath().'userdata/resources/';
146
                $root = OIDplus::localpath().'userdata/resources/';
148
                $res = $onlydir ? @glob($root.ltrim($reldir,'/'), GLOB_ONLYDIR) : @glob($root.ltrim($reldir,'/'));
147
                $res = $onlydir ? @glob($root.ltrim($reldir,'/'), GLOB_ONLYDIR) : @glob($root.ltrim($reldir,'/'));
149
                if ($res) foreach ($res as &$x) {
148
                if ($res) foreach ($res as &$x) {
Line 166... Line 165...
166
                        return self::mayAccessResource($v);
165
                        return self::mayAccessResource($v);
167
                }, ARRAY_FILTER_USE_BOTH);
166
                }, ARRAY_FILTER_USE_BOTH);
168
        }
167
        }
169
 
168
 
170
        /**
169
        /**
171
         * @param $rel
170
         * @param string $rel
172
         * @return string|null
171
         * @return string|null
173
         */
172
         */
174
        private static function realname($rel) {
173
        private static function realname(string $rel) {
175
                $candidate1 = OIDplus::localpath().'userdata/resources/'.$rel;
174
                $candidate1 = OIDplus::localpath().'userdata/resources/'.$rel;
176
                $candidate2 = OIDplus::localpath().'res/'.$rel;
175
                $candidate2 = OIDplus::localpath().'res/'.$rel;
177
                if (file_exists($candidate1) || is_dir($candidate1)) return $candidate1;
176
                if (file_exists($candidate1) || is_dir($candidate1)) return $candidate1;
178
                if (file_exists($candidate2) || is_dir($candidate2)) return $candidate2;
177
                if (file_exists($candidate2) || is_dir($candidate2)) return $candidate2;
179
                return null;
178
                return null;
180
        }
179
        }
181
 
180
 
182
        /**
181
        /**
183
         * @param $source
182
         * @param string $source
184
         * @param $target
183
         * @param string $target
185
         * @return bool
184
         * @return bool
186
         */
185
         */
187
        protected static function checkRedirect($source, &$target): bool {
186
        protected static function checkRedirect(string $source, string &$target): bool {
188
                $candidates = array(
187
                $candidates = array(
189
                        OIDplus::localpath().'userdata/resources/redirect.ini',
188
                        OIDplus::localpath().'userdata/resources/redirect.ini',
190
                        OIDplus::localpath().'res/redirect.ini'
189
                        OIDplus::localpath().'res/redirect.ini'
191
                );
190
                );
192
                foreach ($candidates as $ini_file) {
191
                foreach ($candidates as $ini_file) {
Line 212... Line 211...
212
        public function gui(string $id, array &$out, bool &$handled) {
211
        public function gui(string $id, array &$out, bool &$handled) {
213
                if (explode('$',$id,2)[0] === 'oidplus:resources') {
212
                if (explode('$',$id,2)[0] === 'oidplus:resources') {
214
                        $handled = true;
213
                        $handled = true;
215
 
214
 
216
                        $tmp = explode('$',$id);
215
                        $tmp = explode('$',$id);
217
                        $file = isset($tmp[1]) ? $tmp[1] : '';
216
                        $file = $tmp[1] ?? '';
218
                        unset($tmp);
217
                        unset($tmp);
219
 
218
 
220
                        // Security checks
219
                        // Security checks
221
 
220
 
222
                        if (
221
                        if (
Line 251... Line 250...
251
                        }
250
                        }
252
 
251
 
253
                        // Redirections
252
                        // Redirections
254
 
253
 
255
                        if ($file != '') {
254
                        if ($file != '') {
256
                                $target = null;
255
                                $target = '';
257
                                if (self::checkRedirect($file, $target)) {
256
                                if (self::checkRedirect($file, $target)) {
258
                                        $out['title'] = _L('Please wait...');
257
                                        $out['title'] = _L('Please wait...');
259
                                        $out['text'] = '<p>'._L('You are being redirected...').'</p><script>window.location.href = '.js_escape($target).';</script>';
258
                                        $out['text'] = '<p>'._L('You are being redirected...').'</p><script>window.location.href = '.js_escape($target).';</script>';
260
                                        return;
259
                                        return;
261
                                }
260
                                }
Line 448... Line 447...
448
                        }
447
                        }
449
                }
448
                }
450
        }
449
        }
451
 
450
 
452
        /**
451
        /**
453
         * @param $children
452
         * @param array $children
454
         * @param ?string $rootdir
453
         * @param string|null $rootdir
455
         * @param int $depth
454
         * @param int $depth
456
         * @return void
455
         * @return void
457
         * @throws OIDplusConfigInitializationException
456
         * @throws OIDplusConfigInitializationException
458
         * @throws OIDplusException
457
         * @throws OIDplusException
459
         */
458
         */
460
        private function tree_rec(&$children, string $rootdir=null, int $depth=0)/*: void*/ {
459
        private function tree_rec(array &$children, string $rootdir=null, int $depth=0)/*: void*/ {
461
                if (is_null($rootdir)) $rootdir = '';
460
                if (is_null($rootdir)) $rootdir = '';
462
                if ($depth > 100) return; // something is wrong!
461
                if ($depth > 100) return; // something is wrong!
463
 
462
 
464
                $dirs = self::myglob($rootdir.'*'.'/', true);
463
                $dirs = self::myglob($rootdir.'*'.'/', true);
465
                natcasesort($dirs);
464
                natcasesort($dirs);
Line 545... Line 544...
545
                        }
544
                        }
546
                }
545
                }
547
        }
546
        }
548
 
547
 
549
        /**
548
        /**
550
         * @param $json
549
         * @param array $json
551
         * @param $out
550
         * @param array $out
552
         * @return void
551
         * @return void
553
         */
552
         */
554
        private function publicSitemap_rec($json, &$out) {
553
        private function publicSitemap_rec(array $json, array &$out) {
555
                foreach ($json as $x) {
554
                foreach ($json as $x) {
556
                        if (isset($x['id']) && $x['id']) {
555
                        if (isset($x['id']) && $x['id']) {
557
                                $out[] = $x['id'];
556
                                $out[] = $x['id'];
558
                        }
557
                        }
559
                        if (isset($x['children'])) {
558
                        if (isset($x['children'])) {
Line 612... Line 611...
612
        public function tree_search(string $request) {
611
        public function tree_search(string $request) {
613
                return false;
612
                return false;
614
        }
613
        }
615
 
614
 
616
        /**
615
        /**
617
         * @param $file
616
         * @param string $file
618
         * @return array|mixed|string|string[]|null
617
         * @return array|mixed|string|string[]|null
619
         * @throws OIDplusConfigInitializationException
618
         * @throws OIDplusConfigInitializationException
620
         * @throws OIDplusException
619
         * @throws OIDplusException
621
         */
620
         */
622
        private static function getHyperlinkTitle($file) {
621
        private static function getHyperlinkTitle(string $file) {
623
                $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file);
622
                $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file);
624
                if (file_exists($file2)) $file = $file2;
623
                if (file_exists($file2)) $file = $file2;
625
 
624
 
626
                if (substr($file,-4,4) == '.url') {
625
                if (substr($file,-4,4) == '.url') {
627
                        return preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($file));
626
                        return preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($file));
Line 647... Line 646...
647
                        throw new OIDplusException(_L('Unexpected file extension for file %1',$file));
646
                        throw new OIDplusException(_L('Unexpected file extension for file %1',$file));
648
                }
647
                }
649
        }
648
        }
650
 
649
 
651
        /**
650
        /**
652
         * @param $file
651
         * @param string $file
653
         * @return mixed
652
         * @return mixed
654
         * @throws OIDplusConfigInitializationException
653
         * @throws OIDplusConfigInitializationException
655
         * @throws OIDplusException
654
         * @throws OIDplusException
656
         */
655
         */
657
        private static function getHyperlinkURL($file) {
656
        private static function getHyperlinkURL(string $file) {
658
                $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file);
657
                $file2 = preg_replace('/\.([^.]+)$/', '$'.OIDplus::getCurrentLang().'.\1', $file);
659
                if (file_exists($file2)) $file = $file2;
658
                if (file_exists($file2)) $file = $file2;
660
 
659
 
661
                if (substr($file,-4,4) == '.url') {
660
                if (substr($file,-4,4) == '.url') {
662
                        /*
661
                        /*
Line 698... Line 697...
698
                }
697
                }
699
 
698
 
700
        }
699
        }
701
 
700
 
702
        /**
701
        /**
703
         * @param $dir
702
         * @param string $dir
704
         * @return mixed|string
703
         * @return mixed|string
705
         * @throws OIDplusConfigInitializationException
704
         * @throws OIDplusConfigInitializationException
706
         * @throws OIDplusException
705
         * @throws OIDplusException
707
         */
706
         */
708
        private static function getFolderTitle($dir) {
707
        private static function getFolderTitle(string $dir) {
709
                $data = @parse_ini_file("$dir/folder\$".OIDplus::getCurrentLang().".ini", true);
708
                $data = @parse_ini_file("$dir/folder\$".OIDplus::getCurrentLang().".ini", true);
710
                if ($data && isset($data['Folder']) && isset($data['Folder']['Title'])) {
709
                if ($data && isset($data['Folder']) && isset($data['Folder']['Title'])) {
711
                        return $data['Folder']['Title'];
710
                        return $data['Folder']['Title'];
712
                }
711
                }
713
 
712