|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
14
|
|
|
* @license https://www.fsf.org/copyleft/gpl.html GNU public license |
|
15
|
|
|
* @since 1.0 |
|
16
|
|
|
* @author trabis <[email protected]> |
|
17
|
|
|
* @author The SmartFactory <www.smartfactory.ca> |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
use Xmf\Request; |
|
21
|
|
|
use XoopsModules\Publisher; |
|
22
|
|
|
use XoopsModules\Publisher\Utility; |
|
23
|
|
|
|
|
24
|
|
|
require_once __DIR__ . '/header.php'; |
|
25
|
|
|
|
|
26
|
|
|
$helper->loadLanguage('admin'); |
|
27
|
|
|
//xoops_loadLanguage('admin', PUBLISHER_DIRNAME); |
|
28
|
|
|
|
|
29
|
|
|
$op = Request::getString('op', Request::getString('op', '', 'GET'), 'POST'); |
|
30
|
|
|
$fileid = Request::getInt('fileid', Request::getInt('fileid', 0, 'GET'), 'POST'); |
|
31
|
|
|
|
|
32
|
|
|
if (0 == $fileid) { |
|
33
|
|
|
redirect_header('index.php', 2, _MD_PUBLISHER_NOITEMSELECTED); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$fileObj = $helper->getHandler('File') |
|
37
|
|
|
->get($fileid); |
|
38
|
|
|
|
|
39
|
|
|
// if the selected item was not found, exit |
|
40
|
|
|
if (!$fileObj) { |
|
41
|
|
|
redirect_header('index.php', 1, _NOPERM); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$itemObj = $helper->getHandler('Item') |
|
45
|
|
|
->get($fileObj->getVar('itemid')); |
|
46
|
|
|
|
|
47
|
|
|
// if the user does not have permission to modify this file, exit |
|
48
|
|
|
if (!(Utility::userIsAdmin() || Utility::userIsModerator($itemObj) || (is_object($GLOBALS['xoopsUser']) && $fileObj->getVar('uid') == $GLOBALS['xoopsUser']->getVar('uid')))) { |
|
49
|
|
|
redirect_header('index.php', 1, _NOPERM); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/* -- Available operations -- */ |
|
53
|
|
|
switch ($op) { |
|
54
|
|
|
case 'default': |
|
55
|
|
|
case 'mod': |
|
56
|
|
|
require_once XOOPS_ROOT_PATH . '/header.php'; |
|
57
|
|
|
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
|
58
|
|
|
|
|
59
|
|
|
// FILES UPLOAD FORM |
|
60
|
|
|
$uploadForm = $fileObj->getForm(); |
|
61
|
|
|
$uploadForm->display(); |
|
62
|
|
|
break; |
|
63
|
|
|
case 'modify': |
|
64
|
|
|
$fileid = Request::getInt('fileid', 0, 'POST'); |
|
65
|
|
|
|
|
66
|
|
|
// Creating the file object |
|
67
|
|
|
if (0 != $fileid) { |
|
68
|
|
|
$fileObj = $helper->getHandler('File') |
|
69
|
|
|
->get($fileid); |
|
70
|
|
|
} else { |
|
71
|
|
|
redirect_header('index.php', 1, _NOPERM); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
// Putting the values in the file object |
|
75
|
|
|
$fileObj->setVar('name', Request::getString('name')); |
|
76
|
|
|
$fileObj->setVar('description', Request::getString('description')); |
|
77
|
|
|
$fileObj->setVar('status', Request::getInt('file_status', 0, 'GET')); |
|
78
|
|
|
|
|
79
|
|
|
// attach file if any |
|
80
|
|
|
|
|
81
|
|
|
if ('' != Request::getString('item_upload_file', '', 'FILES')) { |
|
82
|
|
|
$oldfile = $fileObj->getFilePath(); |
|
83
|
|
|
|
|
84
|
|
|
// Get available mimetypes for file uploading |
|
85
|
|
|
$allowedMimetypes = $helper->getHandler('Mimetype') |
|
86
|
|
|
->getArrayByType(); |
|
87
|
|
|
// TODO : display the available mimetypes to the user |
|
88
|
|
|
$errors = []; |
|
89
|
|
|
|
|
90
|
|
|
// if ($helper->getConfig('perm_upload') && is_uploaded_file(Request::getArray('item_upload_file', array(), 'FILES')['tmp_name'])) { |
|
91
|
|
|
$temp = Request::getArray('item_upload_file', [], 'FILES'); |
|
92
|
|
|
if ($helper->getConfig('perm_upload') && is_uploaded_file($temp['tmp_name'])) { |
|
93
|
|
|
if ($fileObj->checkUpload('item_upload_file', $allowedMimetypes, $errors)) { |
|
94
|
|
|
if ($fileObj->storeUpload('item_upload_file', $allowedMimetypes, $errors)) { |
|
95
|
|
|
unlink($oldfile); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
if (!$helper->getHandler('File') |
|
102
|
|
|
->insert($fileObj)) { |
|
103
|
|
|
redirect_header('item.php?itemid=' . $fileObj->itemid(), 3, _AM_PUBLISHER_FILE_EDITING_ERROR . Utility::formatErrors($fileObj->getErrors())); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, _AM_PUBLISHER_FILE_EDITING_SUCCESS); |
|
107
|
|
|
break; |
|
108
|
|
|
case 'clear': |
|
109
|
|
|
//mb echo 'my time is now ' . now; |
|
110
|
|
|
break; |
|
111
|
|
|
case 'del': |
|
112
|
|
|
$confirm = Request::getInt('confirm', '', 'POST'); |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
if ($confirm) { |
|
115
|
|
|
if (!$helper->getHandler('File') |
|
116
|
|
|
->delete($fileObj)) { |
|
117
|
|
|
redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, _AM_PUBLISHER_FILE_DELETE_ERROR); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, sprintf(_AM_PUBLISHER_FILEISDELETED, $fileObj->name())); |
|
121
|
|
|
} else { |
|
122
|
|
|
// no confirm: show deletion condition |
|
123
|
|
|
|
|
124
|
|
|
require_once XOOPS_ROOT_PATH . '/header.php'; |
|
125
|
|
|
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); |
|
126
|
|
|
require_once XOOPS_ROOT_PATH . '/footer.php'; |
|
127
|
|
|
} |
|
128
|
|
|
exit(); |
|
129
|
|
|
} |
|
130
|
|
|
require_once XOOPS_ROOT_PATH . '/footer.php'; |
|
131
|
|
|
|