Passed
Push — master ( 8afea9...0ea5f2 )
by Goffy
03:26
created
Labels
Severity
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 Xmf\Request;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/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 before OtherDir/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:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
25
use XoopsModules\Wgfilemanager;
26
use XoopsModules\Wgfilemanager\Constants;
27
28
require __DIR__ . '/header.php';
29
// Get all request values
30
$op    = Request::getCmd('op', 'list');
31
$dirId = Request::getInt('dir_id', 1);
32
$start = Request::getInt('start');
33
$limit = Request::getInt('limit', $helper->getConfig('userpager'));
34
35
$GLOBALS['xoopsOption']['template_main'] = 'wgfilemanager_index.tpl';
36
require_once \XOOPS_ROOT_PATH . '/header.php';
37
// Define Stylesheet
38
foreach ($styles as $style) {
39
    $GLOBALS['xoTheme']->addStylesheet($style, null);
40
}
41
$GLOBALS['xoTheme']->addStylesheet(\WGFILEMANAGER_URL . '/assets/css/default.css');
42
43
$GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js');
44
// Paths
45
$GLOBALS['xoopsTpl']->assign('xoops_mpageurl', \WGFILEMANAGER_URL.'/index.php');
46
$GLOBALS['xoopsTpl']->assign('xoops_icons32_url', \XOOPS_ICONS32_URL);
47
$GLOBALS['xoopsTpl']->assign('wgfilemanager_icon_bi_url', \WGFILEMANAGER_ICONS_URL . '/bootstrap/');
48
$GLOBALS['xoopsTpl']->assign('wgfilemanager_url', \WGFILEMANAGER_URL);
49
$GLOBALS['xoopsTpl']->assign('wgfilemanager_upload_url', \WGFILEMANAGER_UPLOAD_URL);
50
//preferences
51
$GLOBALS['xoopsTpl']->assign('table_type', $helper->getConfig('table_type'));
52
$GLOBALS['xoopsTpl']->assign('panel_type', $helper->getConfig('panel_type'));
53
$indexDirPosition = (string)$helper->getConfig('indexdirposition');
54
$GLOBALS['xoopsTpl']->assign('indexDirPosLeft', 'left' === $indexDirPosition);
55
$GLOBALS['xoopsTpl']->assign('indexDirPosTop', 'top' === $indexDirPosition);
56
$GLOBALS['xoopsTpl']->assign('indexDirPosNone', 'none' === $indexDirPosition);
57
$GLOBALS['xoopsTpl']->assign('useBroken', (bool)$helper->getConfig('use_broken'));
58
$GLOBALS['xoopsTpl']->assign('useFavorites', (bool)$helper->getConfig('use_favorites'));
59
$iconSet = $helper->getConfig('iconset');
60
// Keywords
61
$keywords = [];
62
//get param list
63
$params = '&amp;dir_id=' . $dirId;
64
$params .= '&amp;start=' . $start;
65
$params .= '&amp;limit=' . $limit;
66
$GLOBALS['xoopsTpl']->assign('params', $params);
67
68
$cookieStyle   = $GLOBALS['xoopsConfig']['usercookie'] . '_wgf_indexstyle';
69
$cookiePreview = $GLOBALS['xoopsConfig']['usercookie'] . '_wgf_indexpreview';
70
$cookieSorting = $GLOBALS['xoopsConfig']['usercookie'] . '_wgf_indexsort';
71
72
switch ($op) {
73
    case 'list':
74
    default:
75
        $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js');
76
        // handle cookies
77
        // cookie style
78
        $cookieIndexstyle = Request::getString($cookieStyle, 'none', 'COOKIE');
79
        if ('none' === $cookieIndexstyle) {
80
            $cookieIndexstyle = Constants::COOKIE_STYLE_DEFAULT;
81
            xoops_setcookie($cookieStyle, $cookieIndexstyle, time() + 60 * 60 * 24 * 30);
82
        } else {
83
            $cookieIndexstyle = $_COOKIE[$cookieStyle];
84
        }
85
        $GLOBALS['xoopsTpl']->assign('wgfindexstyle', $cookieIndexstyle);
86
        $GLOBALS['xoopsTpl']->assign('styledefault', Constants::COOKIE_STYLE_DEFAULT);
87
        $GLOBALS['xoopsTpl']->assign('stylegrouped', Constants::COOKIE_STYLE_GROUPED);
88
        $GLOBALS['xoopsTpl']->assign('stylecard', Constants::COOKIE_STYLE_CARD);
89
        $GLOBALS['xoopsTpl']->assign('stylecardbig', Constants::COOKIE_STYLE_CARDBIG);
90
91
        // cookie preview
92
        $cookieIndexPreview = Request::getString($cookiePreview, 'none', 'COOKIE');
93
        if ('none' === $cookieIndexPreview) {
94
            $cookieIndexPreview = Constants::COOKIE_NOPREVIEW;
95
            xoops_setcookie($cookiePreview, $cookieIndexPreview, time() + 60 * 60 * 24 * 30);
96
        } else {
97
            $cookieIndexPreview = $_COOKIE[$cookiePreview];
98
        }
99
        $GLOBALS['xoopsTpl']->assign('wgfindexpreview', (int)$cookieIndexPreview);
100
        $GLOBALS['xoopsTpl']->assign('previewshow', Constants::COOKIE_PREVIEW);
101
        $GLOBALS['xoopsTpl']->assign('previewhide', Constants::COOKIE_NOPREVIEW);
102
103
        // cookie sorting
104
        $cookieIndexSort = Request::getString($cookieSorting, 'none', 'COOKIE');
105
        if ('none' === $cookieIndexSort) {
106
            $cookieIndexSort = Constants::COOKIE_SORT_NAME_ASC;
107
            xoops_setcookie($cookieSorting, $cookieIndexSort, time() + 60 * 60 * 24 * 30);
108
        } else {
109
            $cookieIndexSort = $_COOKIE[$cookieSorting];
110
        }
111
        $GLOBALS['xoopsTpl']->assign('wgfindexsort', $cookieIndexSort);
112
        $GLOBALS['xoopsTpl']->assign('sortnameasc', Constants::COOKIE_SORT_NAME_ASC);
113
        $GLOBALS['xoopsTpl']->assign('sortnamedesc', Constants::COOKIE_SORT_NAME_DESC);
114
        $GLOBALS['xoopsTpl']->assign('sortctimeasc', Constants::COOKIE_SORT_CTIME_ASC);
115
        $GLOBALS['xoopsTpl']->assign('sortctimedesc', Constants::COOKIE_SORT_CTIME_DESC);
116
        $GLOBALS['xoopsTpl']->assign('sortdatecreateasc', Constants::COOKIE_SORT_DATE_CREATE_ASC);
117
        $GLOBALS['xoopsTpl']->assign('sortdatecreatedesc', Constants::COOKIE_SORT_DATE_CREATE_DESC);
118
        switch ($cookieIndexSort) {
119
            case Constants::COOKIE_SORT_NAME_ASC:
120
            default:
121
                $sortby = 'name';
122
                $sortbyDir = 'name';
123
                $orderby = 'ASC';
124
                break;
125
            case Constants::COOKIE_SORT_NAME_DESC:
126
                $sortby = 'name';
127
                $sortbyDir = 'name';
128
                $orderby = 'DESC';
129
                break;
130
            case Constants::COOKIE_SORT_CTIME_ASC:
131
                $sortby = 'ctime';
132
                $sortbyDir = 'date_created';
133
                $orderby = 'ASC';
134
                break;
135
            case Constants::COOKIE_SORT_CTIME_DESC:
136
                $sortby = 'ctime';
137
                $sortbyDir = 'date_created';
138
                $orderby = 'DESC';
139
                break;
140
            case Constants::COOKIE_SORT_DATE_CREATE_ASC:
141
                $sortby = 'date_created';
142
                $sortbyDir = 'date_created';
143
                $orderby = 'ASC';
144
                break;
145
            case Constants::COOKIE_SORT_DATE_CREATE_DESC:
146
                $sortby = 'date_created';
147
                $sortbyDir = 'date_created';
148
                $orderby = 'DESC';
149
                break;
150
        }
151
152
        // Breadcrumbs
153
        if ($dirId > 1) {
154
            $xoBreadcrumbs[] = ['title' => \_MA_WGFILEMANAGER_INDEX, 'link' => 'index.php'];
155
            $dirArray = $directoryHandler->getDirListBreadcrumb($dirId);
156
            $dirListBreadcrumb = array_reverse($dirArray, true);
157
            foreach ($dirListBreadcrumb as $key => $value) {
158
                if ($key == array_key_last($dirListBreadcrumb)) {
159
                    $xoBreadcrumbs[] = ['title' => $value];
160
                } else {
161
                    $xoBreadcrumbs[] = ['title' => $value, 'link' => 'index.php?dir_id=' . $key];
162
                }
163
            }
164
        } else {
165
            $xoBreadcrumbs[] = ['title' => \_MA_WGFILEMANAGER_INDEX];
166
        }
167
168
        //get permissions
169
        $GLOBALS['xoopsTpl']->assign('permCreateDir', $permissionsHandler->getPermSubmitDirectory($dirId));
170
        $GLOBALS['xoopsTpl']->assign('permEditDir', $permissionsHandler->getPermSubmitDirectory($dirId));
171
        $GLOBALS['xoopsTpl']->assign('permEditFile', $permissionsHandler->getPermSubmitDirectory($dirId));
172
        $GLOBALS['xoopsTpl']->assign('permDownloadFileFromDir', $permissionsHandler->getPermDownloadFileFromDir($dirId));
173
        $GLOBALS['xoopsTpl']->assign('permUploadFileToDir', $permissionsHandler->getPermUploadFileToDir($dirId));
174
        $GLOBALS['xoopsTpl']->assign('permViewDirectory', $permissionsHandler->getPermViewDirectory($dirId));
175
        $GLOBALS['xoopsTpl']->assign('showBtnDetails', true);
176
177
        //get directory list
178
        $dirList = $directoryHandler->getDirList(0, $dirId);
179
        $GLOBALS['xoopsTpl']->assign('dir_list', $dirList);
180
        $GLOBALS['xoopsTpl']->assign('dirId', $dirId);
181
        $indexDirList = $directoryHandler->getSubDirList($dirId, $sortbyDir, $orderby);
182
        $GLOBALS['xoopsTpl']->assign('indexDirlist', $indexDirList);
183
        $GLOBALS['xoopsTpl']->assign('indexDirlistIcon', WGFILEMANAGER_ICONS_URL . '/foldericons/folder2.png');
184
185
        // get files
186
        $crFile = new \CriteriaCompo();
187
        $crFile->add(new \Criteria('directory_id', $dirId));
188
        $fileCount = $fileHandler->getCount($crFile);
189
190
        $fileList = [];
191
        $crFile->setStart($start);
192
        $crFile->setLimit($limit);
193
        $crFile->setSort($sortby);
194
        $crFile->setOrder($orderby);
195
        if ($fileCount > 0) {
196
            $fileIcons = [];
197
            if ('none' !== $iconSet) {
198
                $fileIcons = $fileHandler->getFileIconCollection($iconSet);
199
            }
200
            $fileAll = $fileHandler->getAll($crFile);
201
            foreach (\array_keys($fileAll) as $i) {
202
                $file = $fileAll[$i]->getValuesFile();
203
                $ext = '';
204
                if (strpos($file['name'],'.') > 0) {
205
                    $ext  = substr(strrchr($file['name'], '.'), 1);
206
                }
207
                $fileCategory = isset($fileIcons['files'][$ext]) ? (int)$fileIcons['files'][$ext]['category'] : 0;
208
                $file['category']  = $fileCategory;
209
                $file['icon_url']  = isset($fileIcons['files'][$ext]) ? $fileIcons['files'][$ext]['src'] : $fileIcons['default'];
210
                $file['image']     = false;
211
                $file['image_url'] = '';
212
                $file['pdf']       = false;
213
                $file['pdf_url']   = '';
214
                switch ($fileCategory) {
215
                    case 0:
216
                        break;
217
                    case Constants::MIMETYPE_CAT_IMAGE:
218
                        $file['image'] = true;
219
                        $file['image_url'] = $file['real_url'];
220
                        break;
221
                    case Constants::MIMETYPE_CAT_PDF:
222
                        $file['pdf'] = true;
223
                        $file['pdf_url'] = $file['real_url'];
224
                        break;
225
                }
226
                $fileList[$i]        = $file;
227
            }
228
        }
229
        $GLOBALS['xoopsTpl']->assign('indexFilelist', $fileList);
230
231
        $block['fav_list'] = [];
232
        if ((bool)$helper->getConfig('use_favorites')) {
233
            //get fav list
234
            $favList = [];
235
            //get directory fav list
236
            $favList['dirs'] = $directoryHandler->getFavDirList();
237
            //get directory fav list
238
            $favList['files'] = $fileHandler->getFavFileList();
239
            $GLOBALS['xoopsTpl']->assign('fav_list', $favList);
240
        }
241
        // Display Navigation
242
        if ($fileCount > $limit) {
243
            require_once \XOOPS_ROOT_PATH . '/class/pagenav.php';
244
            $pagenav = new \XoopsPageNav($fileCount, $limit, $start, 'start', 'op=list&amp;limit=' . $limit . '&amp;dir_id=' . $dirId);
245
            $GLOBALS['xoopsTpl']->assign('pagenavFile', $pagenav->renderNav());
246
        }
247
248
        //get current user
249
        $userUid = 0;
250
        if (isset($GLOBALS['xoopsUser']) && \is_object($GLOBALS['xoopsUser'])) {
251
            $userUid = $GLOBALS['xoopsUser']->uid();
252
        }
253
        $GLOBALS['xoopsTpl']->assign('userUid', $userUid);
254
        break;
255
256
    case 'setstyle':
257
        // set cookies and reload
258
        $styleType = Request::getString('style');
259
        xoops_setcookie($cookieStyle, $styleType, time() + 60 * 60 * 24 * 30);
260
        \redirect_header('index.php?op=list' . $params, 0);
261
        break;
262
    case 'setpreview':
263
        // set cookies and reload
264
        $previewType = Request::getInt('preview');
265
        xoops_setcookie($cookiePreview, $previewType, time() + 60 * 60 * 24 * 30);
266
267
        \redirect_header('index.php?op=list' . $params, 0);
268
        break;
269
    case 'setsort':
270
        // set cookies and reload
271
        $sortType = Request::getInt('sort');
272
        xoops_setcookie($cookieSorting, $sortType, time() + 60 * 60 * 24 * 30);
273
274
        \redirect_header('index.php?op=list' . $params, 0);
275
        break;
276
}
277
278
// Keywords
279
wgfilemanagerMetaKeywords($helper->getConfig('keywords') . ', ' . \implode(',', $keywords));
280
unset($keywords);
281
282
require __DIR__ . '/footer.php';
283