-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
196 lines (175 loc) · 8.32 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
declare(strict_types=1);
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* wgFileManager module for xoops
*
* @copyright 2021 XOOPS Project (https://xoops.org)
* @license GPL 2.0 or later
* @package wgfilemanager
* @author Goffy - Wedega - Email:webmaster@wedega.com - Website:https://xoops.wedega.com
*/
use Xmf\Request;
use XoopsModules\Wgfilemanager;
use XoopsModules\Wgfilemanager\Constants;
require __DIR__ . '/header.php';
// Get all request values
$op = Request::getCmd('op', 'list');
$dirId = Request::getInt('dir_id', 1);
$start = Request::getInt('start');
$limit = Request::getInt('limit', $helper->getConfig('userpager'));
$GLOBALS['xoopsOption']['template_main'] = 'wgfilemanager_index.tpl';
require_once \XOOPS_ROOT_PATH . '/header.php';
// Define Stylesheet
$GLOBALS['xoTheme']->addStylesheet($style, null);
$GLOBALS['xoTheme']->addStylesheet(\WGFILEMANAGER_URL . '/assets/css/default.css');
// Paths
$GLOBALS['xoopsTpl']->assign('xoops_mpageurl', \WGFILEMANAGER_URL.'/index.php');
$GLOBALS['xoopsTpl']->assign('xoops_icons32_url', \XOOPS_ICONS32_URL);
$GLOBALS['xoopsTpl']->assign('wgfilemanager_icon_bi_url', \WGFILEMANAGER_ICONS_URL . '/bootstrap/');
$GLOBALS['xoopsTpl']->assign('wgfilemanager_url', \WGFILEMANAGER_URL);
$GLOBALS['xoopsTpl']->assign('wgfilemanager_upload_url', \WGFILEMANAGER_UPLOAD_URL);
$GLOBALS['xoopsTpl']->assign('wgfilemanager_upload_url', \WGFILEMANAGER_UPLOAD_URL);
//preferences
$GLOBALS['xoopsTpl']->assign('table_type', $helper->getConfig('table_type'));
$GLOBALS['xoopsTpl']->assign('panel_type', $helper->getConfig('panel_type'));
$indexDirPosition = (string)$helper->getConfig('indexdirposition');
$GLOBALS['xoopsTpl']->assign('indexDirPosLeft', 'left' === $indexDirPosition);
$GLOBALS['xoopsTpl']->assign('indexDirPosTop', 'top' === $indexDirPosition);
$GLOBALS['xoopsTpl']->assign('indexDirPosNone', 'none' === $indexDirPosition);
$GLOBALS['xoopsTpl']->assign('useBroken', (bool)$helper->getConfig('use_broken'));
$iconSet = $helper->getConfig('iconset');
// Keywords
$keywords = [];
//get param list
$params = '&dir_id=' . $dirId;
$params .= '&start=' . $start;
$params .= '&limit=' . $limit;
$GLOBALS['xoopsTpl']->assign('params', $params);
$cookieStyle = $GLOBALS['xoopsConfig']['usercookie'] . '_wgf_indexstyle';
$cookiePreview = $GLOBALS['xoopsConfig']['usercookie'] . '_wgf_indexpreview';
switch ($op) {
case 'list':
default:
// handle cookies
$cookieIndexstyle = Request::getString($cookieStyle, 'none', 'COOKIE');
if ('none' === $cookieIndexstyle) {
$cookieIndexstyle = Constants::COOKIE_STYLE_DEFAULT;
xoops_setcookie($cookieStyle, $cookieIndexstyle, time() + 60 * 60 * 24 * 30);
} else {
$cookieIndexstyle = $_COOKIE[$cookieStyle];
}
$GLOBALS['xoopsTpl']->assign('wgfindexstyle', $cookieIndexstyle);
$GLOBALS['xoopsTpl']->assign('styledefault', Constants::COOKIE_STYLE_DEFAULT);
$GLOBALS['xoopsTpl']->assign('stylegrouped', Constants::COOKIE_STYLE_GROUPED);
$GLOBALS['xoopsTpl']->assign('stylecard', Constants::COOKIE_STYLE_CARD);
$GLOBALS['xoopsTpl']->assign('stylecardbig', Constants::COOKIE_STYLE_CARDBIG);
$cookieIndexPreview = Request::getString($cookiePreview, 'none', 'COOKIE');
if ('none' === $cookieIndexPreview) {
$cookieIndexPreview = Constants::COOKIE_NOPREVIEW;
xoops_setcookie($cookiePreview, $cookieIndexPreview, time() + 60 * 60 * 24 * 30);
} else {
$cookieIndexPreview = $_COOKIE[$cookiePreview];
}
$GLOBALS['xoopsTpl']->assign('wgfindexpreview', (int)$cookieIndexPreview);
// Breadcrumbs
if ($dirId > 1) {
$xoBreadcrumbs[] = ['title' => \_MA_WGFILEMANAGER_INDEX, 'link' => 'index.php'];
$dirArray = $directoryHandler->getDirListBreadcrumb($dirId);
$dirListBreadcrumb = array_reverse($dirArray, true);
foreach ($dirListBreadcrumb as $key => $value) {
if ($key == array_key_last($dirListBreadcrumb)) {
$xoBreadcrumbs[] = ['title' => $value];
} else {
$xoBreadcrumbs[] = ['title' => $value, 'link' => 'index.php?dir_id=' . $key];
}
}
} else {
$xoBreadcrumbs[] = ['title' => \_MA_WGFILEMANAGER_INDEX];
}
//get permissions
$GLOBALS['xoopsTpl']->assign('permCreateDir', $permissionsHandler->getPermSubmitDirectory($dirId));
$GLOBALS['xoopsTpl']->assign('permEditDir', $permissionsHandler->getPermSubmitDirectory($dirId));
$GLOBALS['xoopsTpl']->assign('permEditFile', $permissionsHandler->getPermSubmitDirectory($dirId));
$GLOBALS['xoopsTpl']->assign('permDownloadFileFromDir', $permissionsHandler->getPermDownloadFileFromDir($dirId));
$GLOBALS['xoopsTpl']->assign('permUploadFileToDir', $permissionsHandler->getPermUploadFileToDir($dirId));
$GLOBALS['xoopsTpl']->assign('permViewDirectory', $permissionsHandler->getPermViewDirectory($dirId));
$GLOBALS['xoopsTpl']->assign('showBtnDetails', true);
//get directory list
$dirList = $directoryHandler->getDirList(0, $dirId);
$GLOBALS['xoopsTpl']->assign('dir_list', $dirList);
$GLOBALS['xoopsTpl']->assign('dirId', $dirId);
$indexDirList = $directoryHandler->getSubDirList($dirId);
$GLOBALS['xoopsTpl']->assign('indexDirlist', $indexDirList);
$GLOBALS['xoopsTpl']->assign('indexDirlistIcon', WGFILEMANAGER_ICONS_URL . '/foldericons/folder2.png');
$crFile = new \CriteriaCompo();
$crFile->add(new \Criteria('directory_id', $dirId));
$fileCount = $fileHandler->getCount($crFile);
$fileList = [];
$crFile->setStart($start);
$crFile->setLimit($limit);
$crFile->setSort('name');
$crFile->setOrder('ASC');
if ($fileCount > 0) {
$fileIcons = [];
if ('none' !== $iconSet) {
$fileIcons = $fileHandler->getFileIconCollection($iconSet);
}
$fileAll = $fileHandler->getAll($crFile);
foreach (\array_keys($fileAll) as $i) {
$file = $fileAll[$i]->getValuesFile();
$ext = substr(strrchr($file['name'], '.'), 1);
$fileCategory = isset($fileIcons['files'][$ext]) ? (int)$fileIcons['files'][$ext]['category'] : 0;
$file['category'] = $fileCategory;
$file['icon_url'] = isset($fileIcons['files'][$ext]) ? $fileIcons['files'][$ext]['src'] : $fileIcons['default'];
$file['image'] = false;
$file['image_url'] = '';
$file['pdf'] = false;
$file['pdf_url'] = '';
switch ($fileCategory) {
case 0:
break;
case Constants::MIMETYPE_CAT_IMAGE:
$file['image'] = true;
$file['image_url'] = $file['real_url'];
break;
case Constants::MIMETYPE_CAT_PDF:
$file['pdf'] = true;
$file['pdf_url'] = $file['real_url'];
break;
}
$fileList[$i] = $file;
}
}
$GLOBALS['xoopsTpl']->assign('indexFilelist', $fileList);
// Display Navigation
if ($fileCount > $limit) {
require_once \XOOPS_ROOT_PATH . '/class/pagenav.php';
$pagenav = new \XoopsPageNav($fileCount, $limit, $start, 'start', 'op=list&limit=' . $limit . '&dir_id=' . $dirId);
$GLOBALS['xoopsTpl']->assign('pagenavFile', $pagenav->renderNav());
}
break;
case 'setstyle':
// set cookies and reload
$styleType = Request::getString('style');
xoops_setcookie($cookieStyle, $styleType, time() + 60 * 60 * 24 * 30);
\redirect_header('index.php?op=list' . $params, 0);
break;
case 'preview':
// set cookies and reload
$styleType = Request::getInt('style');
xoops_setcookie($cookiePreview, $styleType, time() + 60 * 60 * 24 * 30);
\redirect_header('index.php?op=list' . $params, 0);
break;
}
// Keywords
wgfilemanagerMetaKeywords($helper->getConfig('keywords') . ', ' . \implode(',', $keywords));
unset($keywords);
require __DIR__ . '/footer.php';