Passed
Pull Request — master (#47)
by Goffy
02:02
created

modfile.php (3 issues)

Labels
Severity
1
<?php
2
/**
3
 * TDMDownload
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   Gregory Mage (Aka Mage)
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Gregory Mage (Aka Mage)
15
 */
16
require_once __DIR__ . '/header.php';
17
18
/** @var \XoopsModules\Tdmdownloads\Helper $helper */
19
$helper = \XoopsModules\Tdmdownloads\Helper::getInstance();
20
21
// template d'affichage
22
$GLOBALS['xoopsOption']['template_main'] = 'tdmdownloads_modfile.tpl';
23
require_once XOOPS_ROOT_PATH . '/header.php';
24
$moduleDirName = basename(__DIR__);
25
26
/** @var \xos_opal_Theme $xoTheme */
27
$xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/styles.css', null);
28
29
//On recupere la valeur de l'argument op dans l'URL$
30
$op = \Xmf\Request::getString('op', 'list');
31
32
// redirection si pas de droit pour poster
33
if (false === $perm_modif) {
34
    redirect_header('index.php', 2, _NOPERM);
35
}
36
37
$lid = \Xmf\Request::getInt('lid', 0, 'REQUEST');
38
39
//information du téléchargement
40
$viewDownloads = $downloadsHandler->get($lid);
41
42
// redirection si le téléchargement n'existe pas ou n'est pas activé
43
if (!is_object($viewDownloads) || 0 == $viewDownloads->getVar('status')) {
44
    redirect_header('index.php', 3, _MD_TDMDOWNLOADS_SINGLEFILE_NONEXISTENT);
45
}
46
47
//Les valeurs de op qui vont permettre d'aller dans les differentes parties de la page
48
switch ($op) {
49
    // Vue liste
50
    case 'list':
51
        //navigation
52
        $view_category = $categoryHandler->get($viewDownloads->getVar('cid'));
53
        $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName);
54
        if (!in_array($viewDownloads->getVar('cid'), $categories, true)) {
55
            redirect_header('index.php', 2, _NOPERM);
56
        }
57
        //tableau des catégories
58
        $criteria = new \CriteriaCompo();
59
        $criteria->setSort('cat_weight ASC, cat_title');
60
        $criteria->setOrder('ASC');
61
        $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN'));
62
        $downloadscatArray = $categoryHandler->getAll($criteria);
63
        $mytree = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid');
64
        //navigation
65
        $navigation = $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ', true, 'ASC', true);
66
        $navigation .= ' <img src="assets/images/deco/arrow.gif" alt="arrow"> <a title="' . $viewDownloads->getVar('title') . '" href="singlefile.php?lid=' . $viewDownloads->getVar('lid') . '">' . $viewDownloads->getVar('title') . '</a>';
67
        $navigation .= ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ' . _MD_TDMDOWNLOADS_SINGLEFILE_MODIFY;
68
        $xoopsTpl->assign('navigation', $navigation);
69
        // référencement
70
        // titre de la page
71
        $pagetitle = _MD_TDMDOWNLOADS_SINGLEFILE_MODIFY . ' - ' . $viewDownloads->getVar('title') . ' - ';
72
        $pagetitle .= $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true);
73
        $xoopsTpl->assign('xoops_pagetitle', $pagetitle);
74
        //description
75
        $xoTheme->addMeta('meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SINGLEFILE_MODIFY . ' (' . $viewDownloads->getVar('title') . ')'));
76
77
        //Affichage du formulaire de notation des téléchargements
78
        if ($perm_autoapprove) {
79
            $obj = $downloadsHandler->get($lid);
80
            $form = $obj->getForm($donnee = [], false, 'submit.php');
81
        } else {
82
            $obj = $modifiedHandler->create();
83
            $form = $obj->getForm($lid, false, $donnee = []);
84
        }
85
        $xoopsTpl->assign('themeForm', $form->render());
86
        $xoopsTpl->assign('message_erreur', false);
87
        break;
88
    // save
89
    case 'save':
90
        require_once XOOPS_ROOT_PATH . '/class/uploader.php';
91
        $obj = $modifiedHandler->create();
92
        $erreur = false;
93
        $errorMessage = '';
94
        $donnee = [];
95
        $obj->setVar('title', \Xmf\Request::getString('title', '', 'POST')); //$_POST['title']);
96
        $donnee['title'] = \Xmf\Request::getString('title', '', 'POST'); //$_POST['title'];
97
        $obj->setVar('cid', \Xmf\Request::getInt('cid', 0, 'POST')); //$_POST['cid']);
98
        $donnee['cid'] = \Xmf\Request::getInt('cid', 0, 'POST'); //$_POST['cid'];
99
        $obj->setVar('lid', \Xmf\Request::getInt('lid', 0, 'POST')); //$_POST['lid']);
100
        $obj->setVar('homepage', \Xmf\Request::getString('homepage', '', 'POST')); //formatURL($_POST["homepage"]));
101
        $donnee['homepage'] = \Xmf\Request::getString('homepage', '', 'POST'); //formatURL($_POST["homepage"]);
102
        $obj->setVar('version', \Xmf\Request::getString('version', '', 'POST')); //$_POST["version"]);
103
        $donnee['version'] = \Xmf\Request::getString('version', '', 'POST'); //$_POST["version"];
104
        $obj->setVar('size', \Xmf\Request::getString('size', '', 'POST')); //$_POST["size"]);
105
        $donnee['size'] = \Xmf\Request::getString('size', '', 'POST'); //$_POST["size"];
106
        $donnee['type_size'] = \Xmf\Request::getString('type_size', '', 'POST'); //$_POST['type_size'];
107
        if (\Xmf\Request::hasVar('platform', 'POST')) {
108
            $obj->setVar('platform', implode('|', \Xmf\Request::getString('platform', '', 'POST'))); //$_POST['platform']));
0 ignored issues
show
Xmf\Request::getString('platform', '', 'POST') of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

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

108
            $obj->setVar('platform', implode('|', /** @scrutinizer ignore-type */ \Xmf\Request::getString('platform', '', 'POST'))); //$_POST['platform']));
Loading history...
109
            $donnee['platform'] = implode('|', \Xmf\Request::getString('platform', '', 'POST')); //$_POST["platform"]);
110
        } else {
111
            $donnee['platform'] = '';
112
        }
113
        $obj->setVar('description', \Xmf\Request::getString('description', '', 'POST')); //$_POST["description"]);
114
        $donnee['description'] = \Xmf\Request::getString('description', '', 'POST'); //$_POST["description"];
115
        $obj->setVar('modifysubmitter', !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0);
116
117
        // erreur si la taille du fichier n'est pas un nombre
118
        if (\Xmf\Request::hasVar('size') && 0 == \Xmf\Request::getInt('size')) {
119
            if ('0' == \Xmf\Request::getString('size', '', 'POST')
120
                || '' === \Xmf\Request::getString('size', '', 'POST')) {
121
                $erreur = false;
122
            } else {
123
                $erreur = true;
124
                $errorMessage .= _MD_TDMDOWNLOADS_ERREUR_SIZE . '<br>';
125
            }
126
        }
127
        // erreur si la catégorie est vide
128
        if (\Xmf\Request::hasVar('cid')) {
129
            if (0 == \Xmf\Request::getInt('cid', 0, 'POST')) {
130
                $erreur = true;
131
                $errorMessage .= _MD_TDMDOWNLOADS_ERREUR_NOCAT . '<br>';
132
            }
133
        }
134
        // get captcha (members are skipped in class/download.php getForm
135
        if (!$xoopsUser) {
136
            // erreur si le captcha est faux
137
            xoops_load('xoopscaptcha');
138
            $xoopsCaptcha = \XoopsCaptcha::getInstance();
139
            if (!$xoopsCaptcha->verify()) {
140
                $errorMessage .= $xoopsCaptcha->getMessage() . '<br>';
141
                $erreur = true;
142
            }
143
        }
144
        // pour enregistrer temporairement les valeur des champs sup
145
        $criteria = new \CriteriaCompo();
146
        $criteria->setSort('weight ASC, title');
147
        $criteria->setOrder('ASC');
148
        $downloads_field = $fieldHandler->getAll($criteria);
149
        foreach (array_keys($downloads_field) as $i) {
150
            if (0 == $downloads_field[$i]->getVar('status_def')) {
151
                $fieldName = 'champ' . $downloads_field[$i]->getVar('fid');
152
                $donnee[$fieldName] = \Xmf\Request::getString($fieldName, '', 'POST');
153
            }
154
        }
155
        if (true === $erreur) {
156
            $xoopsTpl->assign('message_erreur', $errorMessage);
157
        } else {
158
            $obj->setVar('size', \Xmf\Request::getInt('size', 0, 'POST') . ' ' . \Xmf\Request::getString('type_size', '', 'POST'));
159
            // Pour le fichier
160
            if (isset($_POST['xoops_upload_file'][0])) {
161
                $uploader = new \XoopsMediaUploader($uploaddir_downloads, $helper->getConfig('mimetype'), $helper->getConfig('maxuploadsize'), null, null);
162
                if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
163
                    if ($helper->getConfig('newnamedownload')) {
164
                        $uploader->setPrefix($helper->getConfig('prefixdownloads'));
165
                    }
166
                    $uploader->fetchMedia($_POST['xoops_upload_file'][0]);
167
                    if (!$uploader->upload()) {
168
                        $errors = $uploader->getErrors();
169
                        redirect_header('javascript:history.go(-1)', 3, $errors);
170
                    } else {
171
                        $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName());
172
                    }
173
                } else {
174
                    if ($_FILES['attachedfile']['name'] > '') {
175
                        // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize
176
                        $errorMessage .= $uploader->getErrors() . '<br>';
177
                        $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage);
178
                        $form = $obj->getForm($donnee, true);
179
                        $GLOBALS['xoopsTpl']->assign('themeForm', $form->render());
180
                        break;
181
                    }
182
                    $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST'));
183
                }
184
            }
185
            // Pour l'image
186
            if (isset($_POST['xoops_upload_file'][1])) {
187
                $uploader_2 = new \XoopsMediaUploader($uploaddir_shots, [
188
                    'image/gif',
189
                    'image/jpeg',
190
                    'image/pjpeg',
191
                    'image/x-png',
192
                    'image/png',
193
                ], $helper->getConfig('maxuploadsize'), null, null);
194
                if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) {
195
                    $uploader_2->setPrefix('downloads_');
196
                    $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]);
197
                    if (!$uploader_2->upload()) {
198
                        $errors = $uploader_2->getErrors();
199
                        redirect_header('javascript:history.go(-1)', 3, $errors);
200
                    } else {
201
                        $obj->setVar('logourl', $uploader_2->getSavedFileName());
202
                    }
203
                } else {
204
                    if ($_FILES['attachedimage']['name'] > '') {
205
                        // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize
206
                        $errorMessage .= $uploader_2->getErrors() . '<br>';
207
                        $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage);
208
                        $form = $obj->getForm($donnee, true);
209
                        $GLOBALS['xoopsTpl']->assign('themeForm', $form->render());
210
                        break;
211
                    }
212
                    $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST'));
213
                }
214
            }
215
216
            if ($modifiedHandler->insert($obj)) {
217
                $lidDownloads = $obj->getNewEnreg($db);
218
                // Récupération des champs supplémentaires:
219
                $criteria = new \CriteriaCompo();
220
                $criteria->setSort('weight ASC, title');
221
                $criteria->setOrder('ASC');
222
                $downloads_field = $fieldHandler->getAll($criteria);
223
                foreach (array_keys($downloads_field) as $i) {
224
                    if (0 == $downloads_field[$i]->getVar('status_def')) {
225
                        //$objdata = $modifiedfielddataHandler->create();
226
                        $objdata = $modifieddataHandler->create();
227
                        $fieldName = 'champ' . $downloads_field[$i]->getVar('fid');
228
                        $objdata->setVar('moddata', \Xmf\Request::getString($fieldName, '', 'POST'));
229
                        $objdata->setVar('lid', $lidDownloads);
230
                        $objdata->setVar('fid', $downloads_field[$i]->getVar('fid'));
231
                        //$modifiedfielddataHandler->insert($objdata) || $objdata->getHtmlErrors();
232
                        $modifieddataHandler->insert($objdata) || $objdata->getHtmlErrors();
233
                    }
234
                }
235
                $tags = [];
236
                $tags['MODIFYREPORTS_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/admin/modified.php';
237
                /** @var \XoopsNotificationHandler $notificationHandler */
238
                $notificationHandler = xoops_getHandler('notification');
239
                $notificationHandler->triggerEvent('global', 0, 'file_modify', $tags);
0 ignored issues
show
'file_modify' of type string is incompatible with the type integer expected by parameter $event of XoopsNotificationHandler::triggerEvent(). ( Ignorable by Annotation )

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

239
                $notificationHandler->triggerEvent('global', 0, /** @scrutinizer ignore-type */ 'file_modify', $tags);
Loading history...
'global' of type string is incompatible with the type integer expected by parameter $category of XoopsNotificationHandler::triggerEvent(). ( Ignorable by Annotation )

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

239
                $notificationHandler->triggerEvent(/** @scrutinizer ignore-type */ 'global', 0, 'file_modify', $tags);
Loading history...
240
                redirect_header('singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0, 'REQUEST'), 1, _MD_TDMDOWNLOADS_MODFILE_THANKSFORINFO);
241
            }
242
            echo $obj->getHtmlErrors();
243
        }
244
        //Affichage du formulaire de notation des téléchargements
245
        $form = $obj->getForm(\Xmf\Request::getInt('lid', 0, 'REQUEST'), true, $donnee);
246
        $xoopsTpl->assign('themeForm', $form->render());
247
248
        break;
249
}
250
require XOOPS_ROOT_PATH . '/footer.php';
251