-
Notifications
You must be signed in to change notification settings - Fork 8
/
upload.php
140 lines (134 loc) · 5.78 KB
/
upload.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
<?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.
*/
/**
* @copyright XOOPS Project https://xoops.org/
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
* @link https://xoops.org/
* @min_xoops 2.5.9
* @author Wedega - Email:<[email protected]> - Website:<https://wedega.com>
*/
use Xmf\Jwt\TokenFactory;
use Xmf\Module\Admin;
use Xmf\Request;
use XoopsModules\Tdmdownloads\{
CategoryHandler,
Form\UploadForm
};
/** @var \Xmf\Module\Helper\Permission $permHelper */
require_once __DIR__ . '/header.php';
$moduleDirName = basename(__DIR__);
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
// It recovered the value of argument op in URL$
$op = Request::getString('op', 'form');
$catId = Request::getInt('cat_cid', 0);
// Template
$GLOBALS['xoopsOption']['template_main'] = $moduleDirName . '_upload.tpl';
require_once XOOPS_ROOT_PATH . '/header.php';
$pathIcon16 = Admin::iconUrl('', '16');
$GLOBALS['xoopsTpl']->assign('pathIcon16', $pathIcon16);
$categoryHandler = new CategoryHandler();
// Form Create
if (isset($catId)) {
$categoryObj = $categoryHandler->get($catId);
} else {
$categoryObj = $categoryHandler->create();
}
$catId = 1; //for testing, comment out later
$xoopsTpl->assign('multiupload', true);
$form = new UploadForm($categoryObj);
$form->setExtra('enctype="multipart/form-data"');
$GLOBALS['xoopsTpl']->assign('form', $form->render());
$permHelper->checkPermissionRedirect('tdmdownloads_submit', $catId, 'index.php', 3, 'You are not allowed to submit a file', false);
$permissionUpload = $permHelper->checkPermission('tdmdownloads_submit', $catId, false);
if ($permissionUpload) {
if ($catId > 0) {
$GLOBALS['xoopsTpl']->assign('catId', $catId);
$categoryObj = $categoryHandler->get($catId);
// get config for file type/extenstion
$fileextions = $helper->getConfig('mimetypes');
$mimetypes = [];
foreach ($fileextions as $fe) {
switch ($fe) {
case 'jpg':
case 'jpeg':
case 'jpe':
$mimetypes['image/jpeg'] = 'image/jpeg';
break;
case 'gif':
$mimetypes['image/gif'] = 'image/gif';
break;
case 'png':
$mimetypes['image/png'] = 'image/png';
break;
case 'bmp':
$mimetypes['image/bmp'] = 'image/bmp';
break;
case 'tiff':
case 'tif':
$mimetypes['image/tiff'] = 'image/tiff';
break;
case 'zip':
$mimetypes['application/zip'] = 'application/zip';
break;
case 'else':
default:
break;
}
}
$allowedfileext = implode("', '", $fileextions);
if ('' !== $allowedfileext) {
$allowedfileext = "'" . $allowedfileext . "'";
}
$allowedmimetypes = implode("', '", $mimetypes);
if ('' !== $allowedmimetypes) {
$allowedmimetypes = "'" . $allowedmimetypes . "'";
}
// Define Stylesheet
/** @var xos_opal_Theme $xoTheme */
$xoTheme->addStylesheet(XOOPS_URL . '/media/fine-uploader/fine-uploader-new.css');
$xoTheme->addStylesheet(XOOPS_URL . '/media/fine-uploader/ManuallyTriggerUploads.css');
$xoTheme->addStylesheet(XOOPS_URL . '/media/font-awesome/css/font-awesome.min.css');
$xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
// Define scripts
$xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
$xoTheme->addScript('modules/system/js/admin.js');
$xoTheme->addScript('media/fine-uploader/fine-uploader.js');
// Define Breadcrumb and tips
$xoopsTpl->assign('multiupload', true);
// echo $helper->getConfig('mimetypes');
$xoopsTpl->assign('file_maxsize', $helper->getConfig('maxuploadsize'));
$xoopsTpl->assign('img_maxwidth', $helper->getConfig('imageWidth'));
$xoopsTpl->assign('img_maxheight', $helper->getConfig('imageHeight'));
$xoopsTpl->assign('categoryname', $categoryObj->getVar('cat_title'));
$xoopsTpl->assign('allowedfileext', $categoryObj->getVar('allowedfileext'));
$xoopsTpl->assign('allowedmimetypes', $categoryObj->getVar('allowedmimetypes'));
$payload = [
'aud' => 'ajaxfineupload.php',
'cat' => $catId,
'uid' => $xoopsUser instanceof \XoopsUser ? $xoopsUser->id() : 0,
'handler' => '\XoopsModules\\' . ucfirst($moduleDirName) . '\Common\FineimpuploadHandler',
'moddir' => $moduleDirName,
];
$jwt = TokenFactory::build('fineuploader', $payload, 60 * 30); // token good for 30 minutes
$xoopsTpl->assign('jwt', $jwt);
setcookie('jwt', $jwt);
$fineup_debug = 'false';
if (($xoopsUser instanceof \XoopsUser ? $xoopsUser->isAdmin() : false)
&& isset($_REQUEST['FINEUPLOADER_DEBUG'])) {
$fineup_debug = 'true';
}
$xoopsTpl->assign('fineup_debug', $fineup_debug);
}
}
// Breadcrumbs
$xoBreadcrumbs[] = ['title' => constant('CO_' . $moduleDirNameUpper . '_IMAGES_UPLOAD')];
//require __DIR__ . '/footer.php';
require_once XOOPS_ROOT_PATH . '/footer.php';