Passed
Pull Request — master (#44)
by Michael
05:13 queued 01:49
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
17
use Xmf\Request;
18
19
require_once __DIR__ . '/header.php';
20
21
/** @var \XoopsModules\Tdmdownloads\Helper $helper */
22
$helper = \XoopsModules\Tdmdownloads\Helper::getInstance();
23
24
// template d'affichage
25
$GLOBALS['xoopsOption']['template_main'] = 'tdmdownloads_modfile.tpl';
26
require_once XOOPS_ROOT_PATH . '/header.php';
27
$moduleDirName = basename(__DIR__);
28
29
/** @var \xos_opal_Theme $xoTheme */
30
$xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/styles.css', null);
31
32
//On recupere la valeur de l'argument op dans l'URL$
33
$op = \Xmf\Request::getString('op', 'list');
34
35
// redirection si pas de droit pour poster
36
if (false === $perm_modif) {
37
    redirect_header('index.php', 2, _NOPERM);
38
}
39
40
$lid = \Xmf\Request::getInt('lid', 0, 'REQUEST');
41
42
//information du téléchargement
43
$viewDownloads = $downloadsHandler->get($lid);
44
45
// redirection si le téléchargement n'existe pas ou n'est pas activé
46
if (!is_object($viewDownloads) || 0 == $viewDownloads->getVar('status')) {
47
    redirect_header('index.php', 3, _MD_TDMDOWNLOADS_SINGLEFILE_NONEXISTENT);
48
}
49
50
//Les valeurs de op qui vont permettre d'aller dans les differentes parties de la page
51
switch ($op) {
52
    // Vue liste
53
    case 'list':
54
        //navigation
55
        $view_category = $categoryHandler->get($viewDownloads->getVar('cid'));
56
        $categories    = $utility->getItemIds('tdmdownloads_view', $moduleDirName);
57
        if (!in_array($viewDownloads->getVar('cid'), $categories, true)) {
58
            redirect_header('index.php', 2, _NOPERM);
59
        }
60
        //tableau des catégories
61
        $criteria = new \CriteriaCompo();
62
        $criteria->setSort('cat_weight ASC, cat_title');
63
        $criteria->setOrder('ASC');
64
        $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN'));
65
        $downloadscatArray = $categoryHandler->getAll($criteria);
66
        $mytree            = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid');
67
        //navigation
68
        $navigation = $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ', true, 'ASC', true);
69
        $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>';
70
        $navigation .= ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ' . _MD_TDMDOWNLOADS_SINGLEFILE_MODIFY;
71
        $xoopsTpl->assign('navigation', $navigation);
72
        // référencement
73
        // titre de la page
74
        $pagetitle = _MD_TDMDOWNLOADS_SINGLEFILE_MODIFY . ' - ' . $viewDownloads->getVar('title') . ' - ';
75
        $pagetitle .= $utility->getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true);
76
        $xoopsTpl->assign('xoops_pagetitle', $pagetitle);
77
        //description
78
        $xoTheme->addMeta('meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SINGLEFILE_MODIFY . ' (' . $viewDownloads->getVar('title') . ')'));
79
80
        //Affichage du formulaire de notation des téléchargements
81
        if ( $perm_autoapprove ) {
82
            $obj  = $downloadsHandler->get($lid);
83
            $form = $obj->getForm($donnee = [], false, 'submit.php');
84
        } else {
85
            $obj  = $modifiedHandler->create();
86
            $form = $obj->getForm($lid, false, $donnee = []);
87
        }
88
        $xoopsTpl->assign('themeForm', $form->render());
89
        $xoopsTpl->assign('message_erreur', false);
90
        break;
91
    // save
92
    case 'save':
93
        require_once XOOPS_ROOT_PATH . '/class/uploader.php';
94
        $obj            = $modifiedHandler->create();
95
        $erreur         = false;
96
        $errorMessage = '';
97
        $donnee         = [];
98
        $obj->setVar('title', \Xmf\Request::getString('title', '', 'POST')); //$_POST['title']);
99
        $donnee['title'] = \Xmf\Request::getString('title', '', 'POST'); //$_POST['title'];
100
        $obj->setVar('cid', \Xmf\Request::getInt('cid', 0, 'POST')); //$_POST['cid']);
101
        $donnee['cid'] = \Xmf\Request::getInt('cid', 0, 'POST'); //$_POST['cid'];
102
        $obj->setVar('lid', \Xmf\Request::getInt('lid', 0, 'POST')); //$_POST['lid']);
103
        $obj->setVar('homepage', \Xmf\Request::getString('homepage', '', 'POST')); //formatURL($_POST["homepage"]));
104
        $donnee['homepage'] = \Xmf\Request::getString('homepage', '', 'POST'); //formatURL($_POST["homepage"]);
105
        $obj->setVar('version', \Xmf\Request::getString('version', '', 'POST')); //$_POST["version"]);
106
        $donnee['version'] = \Xmf\Request::getString('version', '', 'POST'); //$_POST["version"];
107
        $obj->setVar('size', \Xmf\Request::getString('size', '', 'POST')); //$_POST["size"]);
108
        $donnee['size']      = \Xmf\Request::getString('size', '', 'POST'); //$_POST["size"];
109
        $donnee['type_size'] = \Xmf\Request::getString('type_size', '', 'POST'); //$_POST['type_size'];
110
        if (\Xmf\Request::hasVar('platform', 'POST')) {
111
            $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

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

242
                $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

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