-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathupload_single.php
More file actions
129 lines (110 loc) · 4.71 KB
/
upload_single.php
File metadata and controls
129 lines (110 loc) · 4.71 KB
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
<?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
* @author Wedega - Email:<webmaster@wedega.com> - 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');
$albPid = Request::getInt('alb_pid');
// Template
$GLOBALS['xoopsOption']['template_main'] = 'wggallery_upload_single.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, (int)$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());
switch ($op) {
case 'uploadSingle':
// Security Check
if (!$GLOBALS['xoopsSecurity']->check()) {
\redirect_header('images.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
}
$imageNameOpt = (int)$helper->getConfig('image_name');
// Set Var img_name
include_once \XOOPS_ROOT_PATH . '/class/uploader.php';
$filename = $_FILES['img_name']['name'];
$imgMimetype = $_FILES['img_name']['type'];
$imgSize = $_FILES['img_name']['size'];
$imgTitle = Request::getString('img_title');
if ('' === $imgTitle) {
// use file name as title
$imgTitle = substr($filename, 0, strrpos($filename, '.'));
}
$uploaderErrors = '';
$savedFilename = '';
$uploader = new \XoopsMediaUploader(\WGGALLERY_UPLOAD_IMAGE_PATH . '/large/',
$helper->getConfig('mimetypes_image'),
$helper->getConfig('maxsize_image'), null, null);
if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
if (Constants::IMAGENAME_ORIGINAL === $imageNameOpt) {
// use original file name
$imgName = substr($filename, 0, strrpos($filename, '.')) . '_imgl';
} else {
$imgName = \str_replace('.', '_', uniqid('imgl', true));
}
$uploader->setPrefix($imgName);
$uploader->fetchMedia($_POST['xoops_upload_file'][0]);
if (!$uploader->upload()) {
$uploaderErrors = $uploader->getErrors();
} else {
$savedFilename = $uploader->getSavedFileName();
}
} else {
if ($filename > '') {
$uploaderErrors = $uploader->getErrors();
}
}
$imgDesc = Request::getString('img_desc');
$ret = $imagesHandler->handleSingleUpload($savedFilename, $imgTitle, $imgDesc, $imgMimetype, $imgSize, $albId);
if ($ret) {
\redirect_header('images.php?op=list&alb_id=' . $albId . '&alb_pid=' . $albPid, 2, \_CO_WGGALLERY_FORM_OK);
}
// Get Form
$GLOBALS['xoopsTpl']->assign('error', $ret['error']);
break;
case 'default':
default:
if ($albId > 0) {
$formSingleUpload = $imagesHandler->getFormSingleUpload($albId);
$xoopsTpl->assign('formSingleUpload', $formSingleUpload->render());
}
break;
}
// Breadcrumbs
$xoBreadcrumbs[] = ['title' => \_CO_WGGALLERY_IMAGES_UPLOAD];
require __DIR__ . '/footer.php';