-
Notifications
You must be signed in to change notification settings - Fork 25
/
file.php
126 lines (101 loc) · 4.88 KB
/
file.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
<?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 The XUUPS Project http://sourceforge.net/projects/xuups/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @since 1.0
* @author trabis <[email protected]>
* @author The SmartFactory <www.smartfactory.ca>
*/
use Xmf\Request;
use XoopsModules\Publisher;
use XoopsModules\Publisher\Utility;
require_once __DIR__ . '/header.php';
$helper->loadLanguage('admin');
//xoops_loadLanguage('admin', PUBLISHER_DIRNAME);
$op = Request::getString('op', Request::getString('op', '', 'GET'), 'POST');
$fileid = Request::getInt('fileid', Request::getInt('fileid', 0, 'GET'), 'POST');
if (0 == $fileid) {
redirect_header('index.php', 2, _MD_PUBLISHER_NOITEMSELECTED);
}
$fileObj = $helper->getHandler('File')->get($fileid);
// if the selected item was not found, exit
if (!$fileObj) {
redirect_header('index.php', 1, _NOPERM);
}
$itemObj = $helper->getHandler('Item')->get($fileObj->getVar('itemid'));
// if the user does not have permission to modify this file, exit
if (!(Utility::userIsAdmin() || Utility::userIsModerator($itemObj) || (is_object($GLOBALS['xoopsUser']) && $fileObj->getVar('uid') == $GLOBALS['xoopsUser']->getVar('uid')))) {
redirect_header('index.php', 1, _NOPERM);
}
/* -- Available operations -- */
switch ($op) {
case 'default':
case 'mod':
require_once $GLOBALS['xoops']->path('header.php');
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
// FILES UPLOAD FORM
$uploadForm = $fileObj->getForm();
$uploadForm->display();
break;
case 'modify':
$fileid = Request::getInt('fileid', 0, 'POST');
// Creating the file object
if (0 != $fileid) {
$fileObj = $helper->getHandler('File')->get($fileid);
} else {
redirect_header('index.php', 1, _NOPERM);
}
// Putting the values in the file object
$fileObj->setVar('name', Request::getString('name'));
$fileObj->setVar('description', Request::getString('description'));
$fileObj->setVar('status', Request::getInt('file_status', 0, 'GET'));
// attach file if any
if ('' != Request::getString('item_upload_file', '', 'FILES')) {
$oldfile = $fileObj->getFilePath();
// Get available mimetypes for file uploading
$allowedMimetypes = $helper->getHandler('Mimetype')->getArrayByType();
// TODO : display the available mimetypes to the user
$errors = [];
// if ($helper->getConfig('perm_upload') && is_uploaded_file(Request::getArray('item_upload_file', array(), 'FILES')['tmp_name'])) {
$temp = Request::getArray('item_upload_file', [], 'FILES');
if ($helper->getConfig('perm_upload') && is_uploaded_file($temp['tmp_name'])) {
if ($fileObj->checkUpload('item_upload_file', $allowedMimetypes, $errors)) {
if ($fileObj->storeUpload('item_upload_file', $allowedMimetypes, $errors)) {
unlink($oldfile);
}
}
}
}
if (!$helper->getHandler('File')->insert($fileObj)) {
redirect_header('item.php?itemid=' . $fileObj->itemid(), 3, _AM_PUBLISHER_FILE_EDITING_ERROR . Utility::formatErrors($fileObj->getErrors()));
}
redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, _AM_PUBLISHER_FILE_EDITING_SUCCESS);
break;
case 'clear':
//mb echo 'my time is now ' . now;
break;
case 'del':
$confirm = Request::getInt('confirm', '', 'POST');
if ($confirm) {
if (!$helper->getHandler('File')->delete($fileObj)) {
redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, _AM_PUBLISHER_FILE_DELETE_ERROR);
}
redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, sprintf(_AM_PUBLISHER_FILEISDELETED, $fileObj->name()));
} else {
// no confirm: show deletion condition
require_once $GLOBALS['xoops']->path('header.php');
xoops_confirm(['op' => 'del', 'fileid' => $fileObj->fileid(), 'confirm' => 1, 'name' => $fileObj->name()], 'file.php', _AM_PUBLISHER_DELETETHISFILE . ' <br>' . $fileObj->name() . ' <br> <br>', _AM_PUBLISHER_DELETE);
require_once $GLOBALS['xoops']->path('footer.php');
}
exit();
}
require_once $GLOBALS['xoops']->path('footer.php');