-
Notifications
You must be signed in to change notification settings - Fork 6
/
upload.php
143 lines (128 loc) · 5.58 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
141
142
143
<?php
/*
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.
*/
use Xmf\Request;
/**
* wgGallery module for xoops
*
* @copyright module for xoops
* @license GPL 2.0 or later
* @package wggallery
* @since 1.0
* @min_xoops 2.5.11
* @author Wedega - Email:<[email protected]> - Website:<https://wedega.com>
* @version $Id: 1.0 upload.php 1 Sat 2018-03-17 09:55:45Z XOOPS Project (www.xoops.org) $
*/
use XoopsModules\Wggallery;
use XoopsModules\Wggallery\Constants;
use XoopsModules\Wggallery\Common\FineimpuploadHandler;
require_once __DIR__ . '/header.php';
// \xoops_loadLanguage('admin', 'wggallery');
// It recovered the value of argument op in URL$
$op = Request::getString('op', 'form');
$albId = Request::getInt('alb_id');
// Template
$GLOBALS['xoopsOption']['template_main'] = 'wggallery_upload.tpl';
require_once \XOOPS_ROOT_PATH . '/header.php';
$GLOBALS['xoopsTpl']->assign('wggallery_icon_url_16', \WGGALLERY_ICONS_URL . '16/');
$GLOBALS['xoopsTpl']->assign('show_breadcrumbs', $helper->getConfig('show_breadcrumbs'));
$GLOBALS['xoopsTpl']->assign('displayButtonText', $helper->getConfig('displayButtonText'));
// check permissions
if ($albId > 0) {
$albumsObj = $albumsHandler->get($albId);
if (!$permissionsHandler->permAlbumEdit($albId, $albumsObj->getVar('alb_submitter'))) {
\redirect_header('albums.php', 3, _NOPERM);
}
$xoBreadcrumbs[] = ['title' => $albumsObj->getVar('alb_name'), 'link' => \WGGALLERY_URL . '/images.php?op=list&alb_id=' . $albId];
} else {
if (!$permissionsHandler->permGlobalSubmit()) {
\redirect_header('albums.php', 3, _NOPERM);
}
$albumsObj = $albumsHandler->create();
}
// show form
$form = $albumsObj->getFormUploadToAlbum();
$GLOBALS['xoopsTpl']->assign('form', $form->render());
if ($albId > 0) {
$GLOBALS['xoopsTpl']->assign('albId', $albId);
$albumObj = $albumsHandler->get($albId);
// get config for file type/extenstion
$fileextions = $helper->getConfig('fileext');
$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 'else':
default:
break;
}
}
$allowedfileext = \implode("', '", $fileextions);
if ('' !== $allowedfileext) {
$allowedfileext = "'" . $allowedfileext . "'";
}
$allowedmimetypes = \implode("', '", $mimetypes);
if ('' !== $allowedmimetypes) {
$allowedmimetypes = "'" . $allowedmimetypes . "'";
}
$maxSizeMB = ((int)$helper->getConfig('maxsize') / 1048576) . ' ' . \_CO_WGGALLERY_MB . ' (' . $helper->getConfig('maxsize') . ')';
$GLOBALS['xoopsTpl']->assign('img_maxsizeMB', $maxSizeMB);
$GLOBALS['xoopsTpl']->assign('img_maxsize', $helper->getConfig('maxsize'));
$GLOBALS['xoopsTpl']->assign('img_maxwidth', $helper->getConfig('maxwidth'));
$GLOBALS['xoopsTpl']->assign('img_maxheight', $helper->getConfig('maxheight'));
$GLOBALS['xoopsTpl']->assign('img_albname', $albumObj->getVar('alb_name'));
$GLOBALS['xoopsTpl']->assign('allowedfileext', $albumObj->getVar('allowedfileext'));
$GLOBALS['xoopsTpl']->assign('allowedmimetypes', $albumObj->getVar('allowedmimetypes'));
$GLOBALS['xoopsTpl']->assign('multiupload', true);
// Define Stylesheet
$GLOBALS['xoTheme']->addStylesheet(\XOOPS_URL . '/media/fine-uploader/fine-uploader-new.css');
$GLOBALS['xoTheme']->addStylesheet(\XOOPS_URL . '/media/fine-uploader/ManuallyTriggerUploads.css');
$GLOBALS['xoTheme']->addStylesheet(\XOOPS_URL . '/media/font-awesome/css/font-awesome.min.css');
$GLOBALS['xoTheme']->addStylesheet(\XOOPS_URL . '/modules/system/css/admin.css');
// Define scripts
$GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js');
$GLOBALS['xoTheme']->addScript('modules/system/js/admin.js');
$GLOBALS['xoTheme']->addScript('media/fine-uploader/fine-uploader.js');
$payload = [
'aud' => 'ajaxfineupload.php',
'cat' => $albId,
'uid' => $xoopsUser instanceof \XoopsUser ? $xoopsUser->id() : 0,
'handler' => FineimpuploadHandler::class,
'moddir' => 'wggallery',
];
$jwt = \Xmf\Jwt\TokenFactory::build('fineuploader', $payload, 60 * 30); // token good for 30 minutes
$GLOBALS['xoopsTpl']->assign('jwt', $jwt);
setcookie('jwt', $jwt);
$fineup_debug = 'false';
if (($xoopsUser instanceof \XoopsUser ? $xoopsUser->isAdmin() : false)
&& isset($_REQUEST['FINEUPLOADER_DEBUG'])) {
$fineup_debug = 'true';
}
$GLOBALS['xoopsTpl']->assign('fineup_debug', $fineup_debug);
}
// Breadcrumbs
$xoBreadcrumbs[] = ['title' => \_CO_WGGALLERY_IMAGES_UPLOAD];
require __DIR__ . '/footer.php';