1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* wgFileManager module for xoops |
17
|
|
|
* |
18
|
|
|
* @copyright 2021 XOOPS Project (https://xoops.org) |
19
|
|
|
* @license GPL 2.0 or later |
20
|
|
|
* @package wgfilemanager |
21
|
|
|
* @author Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
//use XoopsModules\Wgfilemanager; |
25
|
|
|
use XoopsModules\Wgfilemanager\Helper; |
26
|
|
|
//use XoopsModules\Wgfilemanager\Constants; |
27
|
|
|
use Xmf\Request; |
|
|
|
|
28
|
|
|
|
29
|
|
|
require_once \XOOPS_ROOT_PATH . '/modules/wgfilemanager/include/common.php'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Function show block |
33
|
|
|
* @param $options |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
function b_wgfilemanager_dirfavlist_show($options) |
37
|
|
|
{ |
38
|
|
|
global $xoopsModule; |
39
|
|
|
|
40
|
|
|
$helper = Helper::getInstance(); |
41
|
|
|
$directoryHandler = $helper->getHandler('Directory'); |
42
|
|
|
$fileHandler = $helper->getHandler('File'); |
43
|
|
|
|
44
|
|
|
$typeBlock = $options[0]; |
45
|
|
|
$lengthName = $options[1]; |
|
|
|
|
46
|
|
|
if (isset($options[2])) { |
47
|
|
|
$typeList = (int)$options[2]; |
48
|
|
|
} |
49
|
|
|
$GLOBALS['xoopsTpl']->assign('wgfilemanager_typeblock', $typeBlock); |
50
|
|
|
$GLOBALS['xoTheme']->addStylesheet(\WGFILEMANAGER_URL . '/assets/css/default.css'); |
51
|
|
|
|
52
|
|
|
$block = []; |
53
|
|
|
|
54
|
|
|
$dirId = Request::getInt('dir_id', 0); |
55
|
|
|
if ((!empty($xoopsModule))) { |
56
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
57
|
|
|
/* echo "<br>xoopsModule:".$moduleDirName. " " . $xoopsModule->getByDirname($moduleDirName)->getVar('mid'); |
58
|
|
|
echo "<br>xoopsModule:".$xoopsModule->getVar('mid');*/ |
59
|
|
|
if ($xoopsModule->getByDirname($moduleDirName)->getVar('mid') === $xoopsModule->getVar('mid')) { |
60
|
|
|
$dirId = Request::getInt('dir_id', 1); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
$collapseFav = false; |
64
|
|
|
$collapseDir = false; |
65
|
|
|
if ('collapsable' === (string)$options[0]) { |
66
|
|
|
switch ($typeList) { |
|
|
|
|
67
|
|
|
case 1: |
68
|
|
|
$collapseFav = true; |
69
|
|
|
$collapseDir = false; |
70
|
|
|
break; |
71
|
|
|
case 2: |
72
|
|
|
$collapseFav = false; |
73
|
|
|
$collapseDir = true; |
74
|
|
|
break; |
75
|
|
|
case 0: |
76
|
|
|
default: |
77
|
|
|
$collapseFav = true; |
78
|
|
|
$collapseDir = true; |
79
|
|
|
break; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
$GLOBALS['xoopsTpl']->assign('collapseFav', $collapseFav); |
83
|
|
|
$GLOBALS['xoopsTpl']->assign('collapseDir', $collapseDir); |
84
|
|
|
|
85
|
|
|
//get directory list |
86
|
|
|
$block['dir_list'] = $directoryHandler->getDirList(0, $dirId); |
87
|
|
|
|
88
|
|
|
$block['fav_list'] = []; |
89
|
|
|
if ((bool)$helper->getConfig('use_favorites')) { |
90
|
|
|
//get fav list |
91
|
|
|
$favList = []; |
92
|
|
|
//get directory fav list |
93
|
|
|
$favList['dirs'] = $directoryHandler->getFavDirList(); |
94
|
|
|
//get directory fav list |
95
|
|
|
$favList['files'] = $fileHandler->getFavFileList(); |
96
|
|
|
$block['fav_list'] = $favList; |
97
|
|
|
} |
98
|
|
|
$GLOBALS['xoopsTpl']->assign('countFavlist', count($favList['dirs']) + count($favList['files'])); |
|
|
|
|
99
|
|
|
$GLOBALS['xoopsTpl']->assign('wgfilemanager_url', \WGFILEMANAGER_URL); |
100
|
|
|
$GLOBALS['xoopsTpl']->assign('wgfilemanager_icon_bi_url', \WGFILEMANAGER_ICONS_URL . '/bootstrap/'); |
101
|
|
|
return $block; |
102
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Function edit block |
107
|
|
|
* @param $options |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
function b_wgfilemanager_dirfavlist_edit($options) |
111
|
|
|
{ |
112
|
|
|
$GLOBALS['xoopsTpl']->assign('wgfilemanager_upload_url', \WGFILEMANAGER_UPLOAD_URL); |
113
|
|
|
$form = "<input type='hidden' name='options[0]' value='".$options[0]."' >"; |
114
|
|
|
$form .= \_MB_WGFILEMANAGER_NAME_LENGTH . " : <input type='text' name='options[1]' size='5' maxlength='255' value='" . $options[1] . "' ><br><br>"; |
115
|
|
|
if ('collapsable' === (string)$options[0]) { |
116
|
|
|
$form .= \_MB_WGFILEMANAGER_DIRFAV_COL_TYPE . ": <select name='options[2]' size='3'>"; |
117
|
|
|
$form .= "<option value='0' " . (0 === (int)$options[2] ? "selected='selected'" : '') . '>' . \_MB_WGFILEMANAGER_DIRFAV_COL_TYPE_0 . '</option>'; |
118
|
|
|
$form .= "<option value='1' " . (1 === (int)$options[2] ? "selected='selected'" : '') . '>' . \_MB_WGFILEMANAGER_DIRFAV_COL_TYPE_1 . '</option>'; |
119
|
|
|
$form .= "<option value='2' " . (2 === (int)$options[2] ? "selected='selected'" : '') . '>' . \_MB_WGFILEMANAGER_DIRFAV_COL_TYPE_2 . '</option>'; |
120
|
|
|
$form .= '</select><br>'; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $form; |
124
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: