1 | <?php |
||||||
2 | |||||||
3 | use XoopsModules\Tag\Tag; |
||||||
4 | use XoopsModules\Tag\TagHandler; |
||||||
5 | |||||||
6 | /** |
||||||
7 | * TDMDownload |
||||||
8 | * |
||||||
9 | * You may not change or alter any portion of this comment or credits |
||||||
10 | * of supporting developers from this source code or any supporting source code |
||||||
11 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||||||
12 | * This program is distributed in the hope that it will be useful, |
||||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
15 | * |
||||||
16 | * @copyright Gregory Mage (Aka Mage) |
||||||
17 | * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
||||||
18 | * @author Gregory Mage (Aka Mage) |
||||||
19 | */ |
||||||
20 | require_once __DIR__ . '/header.php'; |
||||||
21 | $moduleDirName = basename(__DIR__); |
||||||
22 | |||||||
23 | /** @var \XoopsModules\Tdmdownloads\Helper $helper */ |
||||||
24 | $helper = \XoopsModules\Tdmdownloads\Helper::getInstance(); |
||||||
25 | // template d'affichage |
||||||
26 | $GLOBALS['xoopsOption']['template_main'] = 'tdmdownloads_submit.tpl'; |
||||||
27 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||||||
28 | /** @var \xos_opal_Theme $xoTheme */ |
||||||
29 | $xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/styles.css', null); |
||||||
30 | |||||||
31 | //On recupere la valeur de l'argument op dans l'URL$ |
||||||
32 | $op = \Xmf\Request::getString('op', 'list'); |
||||||
33 | $lid = \Xmf\Request::getInt('lid', 0, 'REQUEST'); |
||||||
34 | |||||||
35 | // redirection si pas de droit pour poster |
||||||
36 | if (false === $perm_submit) { |
||||||
37 | redirect_header('index.php', 2, _NOPERM); |
||||||
38 | } |
||||||
39 | // user must have perm to autoapprove if he want to modify, otherwise modfile.php must be used |
||||||
40 | if (false === $perm_autoapprove && $lid > 0) { |
||||||
41 | redirect_header('index.php', 2, _NOPERM); |
||||||
42 | } |
||||||
43 | |||||||
44 | //Les valeurs de op qui vont permettre d'aller dans les differentes parties de la page |
||||||
45 | switch ($op) { |
||||||
46 | // Vue liste |
||||||
47 | case 'list': |
||||||
48 | //navigation |
||||||
49 | $navigation = _MD_TDMDOWNLOADS_SUBMIT_PROPOSER; |
||||||
50 | $xoopsTpl->assign('navigation', $navigation); |
||||||
51 | // référencement |
||||||
52 | // titre de la page |
||||||
53 | $titre = _MD_TDMDOWNLOADS_SUBMIT_PROPOSER . ' - '; |
||||||
54 | $titre .= $xoopsModule->name(); |
||||||
55 | $xoopsTpl->assign('xoops_pagetitle', $titre); |
||||||
56 | //description |
||||||
57 | $xoTheme->addMeta('meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SUBMIT_PROPOSER)); |
||||||
58 | |||||||
59 | //Affichage du formulaire de notation des téléchargements |
||||||
60 | $obj = $downloadsHandler->create(); |
||||||
61 | $form = $obj->getForm($donnee = [], false); |
||||||
62 | $xoopsTpl->assign('themeForm', $form->render()); |
||||||
63 | break; |
||||||
64 | // save |
||||||
65 | case 'save_downloads': |
||||||
66 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||||||
67 | $newUpload = true; |
||||||
68 | if (true === $perm_autoapprove && $lid > 0) { |
||||||
69 | $obj = $downloadsHandler->get($lid); |
||||||
70 | $newUpload = false; |
||||||
71 | } else { |
||||||
72 | $obj = $downloadsHandler->create(); |
||||||
73 | } |
||||||
74 | $erreur = false; |
||||||
75 | $errorMessage = ''; |
||||||
76 | $donnee = []; |
||||||
77 | $obj->setVar('title', \Xmf\Request::getString('title', '', 'POST')); |
||||||
78 | $donnee['title'] = \Xmf\Request::getString('title', '', 'POST'); |
||||||
79 | $obj->setVar('cid', \Xmf\Request::getString('cid', '', 'POST')); |
||||||
80 | $donnee['cid'] = \Xmf\Request::getString('cid', '', 'POST'); |
||||||
81 | $obj->setVar('homepage', formatURL(\Xmf\Request::getString('homepage', '', 'POST'))); |
||||||
82 | $obj->setVar('version', \Xmf\Request::getString('version', '', 'POST')); |
||||||
83 | $obj->setVar('size', \Xmf\Request::getString('size', '', 'POST')); |
||||||
84 | $donnee['type_size'] = \Xmf\Request::getString('type_size', '', 'POST'); |
||||||
85 | $obj->setVar('paypal', \Xmf\Request::getString('paypal', '', 'POST')); |
||||||
86 | if (\Xmf\Request::hasVar('platform', 'POST')) { |
||||||
87 | $obj->setVar('platform', implode('|', \Xmf\Request::getString('platform', '', 'POST'))); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
88 | } |
||||||
89 | $obj->setVar('description', \Xmf\Request::getString('description', '', 'POST')); |
||||||
90 | if (\Xmf\Request::hasVar('submitter', 'POST')) { |
||||||
91 | $obj->setVar('submitter', \Xmf\Request::getString('submitter', '', 'POST')); |
||||||
92 | $donnee['submitter'] = \Xmf\Request::getString('submitter', '', 'POST'); |
||||||
93 | } else { |
||||||
94 | $obj->setVar('submitter', !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0); |
||||||
95 | $donnee['submitter'] = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0; |
||||||
96 | } |
||||||
97 | $obj->setVar('date', time()); |
||||||
98 | if (true === $perm_autoapprove) { |
||||||
99 | $obj->setVar('status', 1); |
||||||
100 | } else { |
||||||
101 | $obj->setVar('status', 0); |
||||||
102 | } |
||||||
103 | if ($xoopsUser) { |
||||||
104 | if ($xoopsUser->isAdmin($xoopsModule->mid())) { |
||||||
105 | if (\Xmf\Request::hasVar('status', 'POST')) { |
||||||
106 | $obj->setVar('status', \Xmf\Request::getInt('status', 0, 'POST')); |
||||||
107 | $donnee['status'] = \Xmf\Request::getInt('status', 0, 'POST'); |
||||||
108 | } else { |
||||||
109 | $obj->setVar('status', 0); |
||||||
110 | $donnee['status'] = 0; |
||||||
111 | } |
||||||
112 | } |
||||||
113 | } |
||||||
114 | $donnee['date_update'] = 0; |
||||||
115 | // erreur si la taille du fichier n'est pas un nombre |
||||||
116 | if (\Xmf\Request::hasVar('size', 'REQUEST')) { |
||||||
117 | if (0 === \Xmf\Request::getInt('size', 0, 'REQUEST')) { |
||||||
118 | $erreur = false; |
||||||
119 | } else { |
||||||
120 | $erreur = true; |
||||||
121 | $errorMessage .= _MD_TDMDOWNLOADS_ERREUR_SIZE . '<br>'; |
||||||
122 | } |
||||||
123 | } |
||||||
124 | // erreur si la catégorie est vide |
||||||
125 | if (\Xmf\Request::hasVar('cid', 'REQUEST')) { |
||||||
126 | if (0 === \Xmf\Request::getInt('cid', 0, 'REQUEST')) { |
||||||
127 | $erreur = true; |
||||||
128 | $errorMessage .= _MD_TDMDOWNLOADS_ERREUR_NOCAT . '<br>'; |
||||||
129 | } |
||||||
130 | } |
||||||
131 | // erreur si le captcha est faux |
||||||
132 | xoops_load('xoopscaptcha'); |
||||||
133 | $xoopsCaptcha = \XoopsCaptcha::getInstance(); |
||||||
134 | if (!$xoopsCaptcha->verify()) { |
||||||
135 | $errorMessage .= $xoopsCaptcha->getMessage() . '<br>'; |
||||||
136 | $erreur = true; |
||||||
137 | } |
||||||
138 | // pour enregistrer temporairement les valeur des champs sup |
||||||
139 | $criteria = new \CriteriaCompo(); |
||||||
140 | $criteria->setSort('weight ASC, title'); |
||||||
141 | $criteria->setOrder('ASC'); |
||||||
142 | $downloads_field = $fieldHandler->getAll($criteria); |
||||||
143 | foreach (array_keys($downloads_field) as $i) { |
||||||
144 | if (0 === $downloads_field[$i]->getVar('status_def')) { |
||||||
145 | $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); |
||||||
146 | $donnee[$fieldName] = \Xmf\Request::getString($fieldName, '', 'POST'); |
||||||
147 | } |
||||||
148 | } |
||||||
149 | // enregistrement temporaire des tags |
||||||
150 | if ((1 == $helper->getConfig('usetag')) && class_exists(Tag::class)) { |
||||||
151 | $donnee['TAG'] = $_POST['tag']; |
||||||
152 | } |
||||||
153 | if (true === $erreur) { |
||||||
154 | $xoopsTpl->assign('message_erreur', $errorMessage); |
||||||
155 | $form = $obj->getForm($donnee, true); |
||||||
156 | $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); |
||||||
157 | break; |
||||||
158 | } |
||||||
159 | $obj->setVar('size', \Xmf\Request::getString('size', '', 'POST') . ' ' . \Xmf\Request::getString('type_size', '', 'POST')); |
||||||
160 | // Pour le fichier |
||||||
161 | if (isset($_POST['xoops_upload_file'][0])) { |
||||||
162 | $uploader = new \XoopsMediaUploader($uploaddir_downloads, $helper->getConfig('mimetype'), $helper->getConfig('maxuploadsize'), null, null); |
||||||
163 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
||||||
164 | if ($helper->getConfig('newnamedownload')) { |
||||||
165 | $uploader->setPrefix($helper->getConfig('prefixdownloads')); |
||||||
166 | } |
||||||
167 | $uploader->fetchMedia($_POST['xoops_upload_file'][0]); |
||||||
168 | if (!$uploader->upload()) { |
||||||
169 | $errors = $uploader->getErrors(); |
||||||
170 | redirect_header('javascript:history.go(-1)', 3, $errors); |
||||||
171 | } else { |
||||||
172 | $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName()); |
||||||
173 | } |
||||||
174 | } else { |
||||||
175 | if ($_FILES['attachedfile']['name'] > '') { |
||||||
176 | // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize |
||||||
177 | $errorMessage .= $uploader->getErrors() . '<br>'; |
||||||
178 | $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); |
||||||
179 | $form = $obj->getForm($donnee, true); |
||||||
180 | $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); |
||||||
181 | break; |
||||||
182 | } |
||||||
183 | $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST')); |
||||||
184 | } |
||||||
185 | } |
||||||
186 | // Pour l'image |
||||||
187 | if (isset($_POST['xoops_upload_file'][1])) { |
||||||
188 | $uploader_2 = new \XoopsMediaUploader($uploaddir_shots, [ |
||||||
189 | 'image/gif', |
||||||
190 | 'image/jpeg', |
||||||
191 | 'image/pjpeg', |
||||||
192 | 'image/x-png', |
||||||
193 | 'image/png', |
||||||
194 | ], $helper->getConfig('maxuploadsize'), null, null); |
||||||
195 | if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) { |
||||||
196 | $uploader_2->setPrefix('downloads_'); |
||||||
197 | $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]); |
||||||
198 | if (!$uploader_2->upload()) { |
||||||
199 | $errors = $uploader_2->getErrors(); |
||||||
200 | redirect_header('javascript:history.go(-1)', 3, $errors); |
||||||
201 | } else { |
||||||
202 | $obj->setVar('logourl', $uploader_2->getSavedFileName()); |
||||||
203 | } |
||||||
204 | } else { |
||||||
205 | if ($_FILES['attachedimage']['name'] > '') { |
||||||
206 | // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize |
||||||
207 | $errorMessage .= $uploader_2->getErrors() . '<br>'; |
||||||
208 | $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); |
||||||
209 | $form = $obj->getForm($donnee, true); |
||||||
210 | $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); |
||||||
211 | break; |
||||||
212 | } |
||||||
213 | $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST')); |
||||||
214 | } |
||||||
215 | } |
||||||
216 | |||||||
217 | if ($downloadsHandler->insert($obj)) { |
||||||
218 | if ($newUpload) { |
||||||
219 | $lidDownloads = $obj->getNewEnreg($db); |
||||||
220 | } else { |
||||||
221 | $lidDownloads = $lid; |
||||||
222 | } |
||||||
223 | //tags |
||||||
224 | if ((1 == $helper->getConfig('usetag')) && class_exists(TagHandler::class)) { |
||||||
225 | /** @var \XoopsModules\Tag\TagHandler $tagHandler */ |
||||||
226 | $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
||||||
227 | $tagHandler->updateByItem($_POST['tag'], $lidDownloads, $moduleDirName, 0); |
||||||
228 | } |
||||||
229 | // Récupération des champs supplémentaires: |
||||||
230 | $criteria = new \CriteriaCompo(); |
||||||
231 | $criteria->setSort('weight ASC, title'); |
||||||
232 | $criteria->setOrder('ASC'); |
||||||
233 | $downloads_field = $fieldHandler->getAll($criteria); |
||||||
234 | foreach (array_keys($downloads_field) as $i) { |
||||||
235 | if (0 === $downloads_field[$i]->getVar('status_def')) { |
||||||
236 | $objdata = $fielddataHandler->create(); |
||||||
237 | $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); |
||||||
238 | $objdata->setVar('data', \Xmf\Request::getString($fieldName, '', 'POST')); |
||||||
239 | $objdata->setVar('lid', $lidDownloads); |
||||||
240 | $objdata->setVar('fid', $downloads_field[$i]->getVar('fid')); |
||||||
241 | $fielddataHandler->insert($objdata) || $objdata->getHtmlErrors(); |
||||||
242 | } |
||||||
243 | } |
||||||
244 | if ($xoopsUser) { |
||||||
245 | if ($xoopsUser->isAdmin($xoopsModule->mid())) { |
||||||
246 | //permission pour télécharger |
||||||
247 | if (1 == $helper->getConfig('permission_download')) { |
||||||
248 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||||||
249 | $grouppermHandler = xoops_getHandler('groupperm'); |
||||||
250 | $criteria = new \CriteriaCompo(); |
||||||
251 | $criteria->add(new \Criteria('gperm_itemid', $lidDownloads, '=')); |
||||||
252 | $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); |
||||||
253 | $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_download_item', '=')); |
||||||
254 | $grouppermHandler->deleteAll($criteria); |
||||||
255 | if (\Xmf\Request::hasVar('item_download', 'POST')) { |
||||||
256 | foreach ($_POST['item_download'] as $onegroup_id) { |
||||||
257 | $grouppermHandler->addRight('tdmdownloads_download_item', $lidDownloads, $onegroup_id, $xoopsModule->getVar('mid')); |
||||||
258 | } |
||||||
259 | } |
||||||
260 | } |
||||||
261 | } |
||||||
262 | } |
||||||
263 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||||||
264 | $notificationHandler = xoops_getHandler('notification'); |
||||||
265 | $tags = []; |
||||||
266 | $tags['FILE_NAME'] = $donnee['title']; |
||||||
267 | $tags['FILE_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $donnee['cid'] . '&lid=' . $lidDownloads; |
||||||
268 | $downloadscat_cat = $categoryHandler->get($donnee['cid']); |
||||||
269 | $tags['CATEGORY_NAME'] = $downloadscat_cat->getVar('cat_title'); |
||||||
270 | $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $donnee['cid']; |
||||||
271 | |||||||
272 | if (true === $perm_autoapprove) { |
||||||
273 | $notificationHandler->triggerEvent('global', 0, 'new_file', $tags); |
||||||
0 ignored issues
–
show
'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
![]() 'new_file' 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
![]() |
|||||||
274 | $notificationHandler->triggerEvent('category', $donnee['cid'], 'new_file', $tags); |
||||||
275 | redirect_header('index.php', 2, _MD_TDMDOWNLOADS_SUBMIT_RECEIVED . '<br>' . _MD_TDMDOWNLOADS_SUBMIT_ISAPPROVED . ''); |
||||||
276 | exit; |
||||||
277 | } |
||||||
278 | $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/admin/index.php?op=listNewDownloads'; |
||||||
279 | $notificationHandler->triggerEvent('global', 0, 'file_submit', $tags); |
||||||
280 | $notificationHandler->triggerEvent('category', $donnee['cid'], 'file_submit', $tags); |
||||||
281 | redirect_header('index.php', 2, _MD_TDMDOWNLOADS_SUBMIT_RECEIVED); |
||||||
282 | exit; |
||||||
283 | } |
||||||
284 | $errors = $obj->getHtmlErrors(); |
||||||
285 | |||||||
286 | $form = $obj->getForm($donnee, true); |
||||||
287 | $xoopsTpl->assign('themeForm', $form->render()); |
||||||
288 | break; |
||||||
289 | } |
||||||
290 | require XOOPS_ROOT_PATH . '/footer.php'; |
||||||
291 |