Subversion Repositories oidplus

Rev

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