Passed
Branch master (d2b70f)
by Michael
12:26
created
Labels
Severity
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       The XUUPS Project https://sourceforge.net/projects/xuups/
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')->get($fileid);
37
38
// if the selected item was not found, exit
39
if (!$fileObj) {
40
    redirect_header('index.php', 1, _NOPERM);
41
}
42
43
$itemObj = $helper->getHandler('Item')->get($fileObj->getVar('itemid'));
44
45
// if the user does not have permission to modify this file, exit
46
if (!(Utility::userIsAdmin() || Utility::userIsModerator($itemObj) || (is_object($GLOBALS['xoopsUser']) && $fileObj->getVar('uid') == $GLOBALS['xoopsUser']->getVar('uid')))) {
47
    redirect_header('index.php', 1, _NOPERM);
48
}
49
50
/* -- Available operations -- */
51
switch ($op) {
52
    case 'default':
53
    case 'mod':
54
        require_once $GLOBALS['xoops']->path('header.php');
55
        require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
56
57
        // FILES UPLOAD FORM
58
        $uploadForm = $fileObj->getForm();
59
        $uploadForm->display();
60
        break;
61
    case 'modify':
62
        $fileid = Request::getInt('fileid', 0, 'POST');
63
64
        // Creating the file object
65
        if (0 != $fileid) {
66
            $fileObj = $helper->getHandler('File')->get($fileid);
67
        } else {
68
            redirect_header('index.php', 1, _NOPERM);
69
        }
70
71
        // Putting the values in the file object
72
        $fileObj->setVar('name', Request::getString('name'));
73
        $fileObj->setVar('description', Request::getString('description'));
74
        $fileObj->setVar('status', Request::getInt('file_status', 0, 'GET'));
75
76
        // attach file if any
77
78
        if ('' != Request::getString('item_upload_file', '', 'FILES')) {
79
            $oldfile = $fileObj->getFilePath();
80
81
            // Get available mimetypes for file uploading
82
            $allowedMimetypes = $helper->getHandler('Mimetype')->getArrayByType();
83
            // TODO : display the available mimetypes to the user
84
            $errors = [];
85
86
            //            if ($helper->getConfig('perm_upload') && is_uploaded_file(Request::getArray('item_upload_file', array(), 'FILES')['tmp_name'])) {
87
            $temp = Request::getArray('item_upload_file', [], 'FILES');
88
            if ($helper->getConfig('perm_upload') && is_uploaded_file($temp['tmp_name'])) {
89
                if ($fileObj->checkUpload('item_upload_file', $allowedMimetypes, $errors)) {
90
                    if ($fileObj->storeUpload('item_upload_file', $allowedMimetypes, $errors)) {
91
                        unlink($oldfile);
92
                    }
93
                }
94
            }
95
        }
96
97
        if (!$helper->getHandler('File')->insert($fileObj)) {
98
            redirect_header('item.php?itemid=' . $fileObj->itemid(), 3, _AM_PUBLISHER_FILE_EDITING_ERROR . Utility::formatErrors($fileObj->getErrors()));
99
        }
100
101
        redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, _AM_PUBLISHER_FILE_EDITING_SUCCESS);
102
        break;
103
    case 'clear':
104
        //mb        echo 'my time is now ' . now;
105
        break;
106
    case 'del':
107
        $confirm = Request::getInt('confirm', '', 'POST');
0 ignored issues
show
'' of type string is incompatible with the type integer expected by parameter $default of Xmf\Request::getInt(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

107
        $confirm = Request::getInt('confirm', /** @scrutinizer ignore-type */ '', 'POST');
Loading history...
108
109
        if ($confirm) {
110
            if (!$helper->getHandler('File')->delete($fileObj)) {
111
                redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, _AM_PUBLISHER_FILE_DELETE_ERROR);
112
            }
113
114
            redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, sprintf(_AM_PUBLISHER_FILEISDELETED, $fileObj->name()));
115
        } else {
116
            // no confirm: show deletion condition
117
118
            require_once $GLOBALS['xoops']->path('header.php');
119
            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);
120
            require_once $GLOBALS['xoops']->path('footer.php');
121
        }
122
        exit();
123
}
124
require_once $GLOBALS['xoops']->path('footer.php');
125