Subversion Repositories oidplus

Rev

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

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