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 | use XoopsModules\Tdmdownloads; |
||||||
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 = $utility->cleanVars($_REQUEST, 'op', 'list', 'string'); |
||||||
33 | |||||||
34 | // redirection si pas de droit pour poster |
||||||
35 | if (false === $perm_submit) { |
||||||
36 | redirect_header('index.php', 2, _NOPERM); |
||||||
37 | } |
||||||
38 | |||||||
39 | //Les valeurs de op qui vont permettre d'aller dans les differentes parties de la page |
||||||
40 | switch ($op) { |
||||||
41 | // Vue liste |
||||||
42 | case 'list': |
||||||
43 | //navigation |
||||||
44 | $navigation = _MD_TDMDOWNLOADS_SUBMIT_PROPOSER; |
||||||
45 | $xoopsTpl->assign('navigation', $navigation); |
||||||
46 | // référencement |
||||||
47 | // titre de la page |
||||||
48 | $titre = _MD_TDMDOWNLOADS_SUBMIT_PROPOSER . ' - '; |
||||||
49 | $titre .= $xoopsModule->name(); |
||||||
50 | $xoopsTpl->assign('xoops_pagetitle', $titre); |
||||||
51 | //description |
||||||
52 | $xoTheme->addMeta('meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SUBMIT_PROPOSER)); |
||||||
53 | |||||||
54 | //Affichage du formulaire de notation des téléchargements |
||||||
55 | $obj = $downloadsHandler->create(); |
||||||
56 | $form = $obj->getForm($donnee = [], false); |
||||||
57 | $xoopsTpl->assign('themeForm', $form->render()); |
||||||
58 | break; |
||||||
59 | // save |
||||||
60 | case 'save_downloads': |
||||||
61 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||||||
62 | $obj = $downloadsHandler->create(); |
||||||
63 | $erreur = false; |
||||||
64 | $message_erreur = ''; |
||||||
65 | $donnee = []; |
||||||
66 | $obj->setVar('title', \Xmf\Request::getString('title', '', 'POST')); |
||||||
67 | $donnee['title'] = \Xmf\Request::getString('title', '', 'POST'); |
||||||
68 | $obj->setVar('cid', \Xmf\Request::getString('cid', '', 'POST')); |
||||||
69 | $donnee['cid'] = \Xmf\Request::getString('cid', '', 'POST'); |
||||||
70 | $obj->setVar('homepage', formatURL(\Xmf\Request::getString('homepage', '', 'POST'))); |
||||||
71 | $obj->setVar('version', \Xmf\Request::getString('version', '', 'POST')); |
||||||
72 | $obj->setVar('size', \Xmf\Request::getString('size', '', 'POST')); |
||||||
73 | $donnee['type_size'] = \Xmf\Request::getString('type_size', '', 'POST'); |
||||||
74 | $obj->setVar('paypal', \Xmf\Request::getString('paypal', '', 'POST')); |
||||||
75 | if (\Xmf\Request::hasVar('platform', 'POST')) { |
||||||
76 | $obj->setVar('platform', implode('|', \Xmf\Request::getString('platform', '', 'POST'))); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
77 | } |
||||||
78 | $obj->setVar('description', \Xmf\Request::getString('description', '', 'POST')); |
||||||
79 | if (\Xmf\Request::hasVar('submitter', 'POST')) { |
||||||
80 | $obj->setVar('submitter', \Xmf\Request::getString('submitter', '', 'POST')); |
||||||
81 | $donnee['submitter'] = \Xmf\Request::getString('submitter', '', 'POST'); |
||||||
82 | } else { |
||||||
83 | $obj->setVar('submitter', !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0); |
||||||
84 | $donnee['submitter'] = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0; |
||||||
85 | } |
||||||
86 | $obj->setVar('date', time()); |
||||||
87 | if (true === $perm_autoapprove) { |
||||||
88 | $obj->setVar('status', 1); |
||||||
89 | } else { |
||||||
90 | $obj->setVar('status', 0); |
||||||
91 | } |
||||||
92 | if ($xoopsUser) { |
||||||
93 | if ($xoopsUser->isAdmin($xoopsModule->mid())) { |
||||||
94 | if (\Xmf\Request::hasVar('status', 'POST')) { |
||||||
95 | $obj->setVar('status', $_POST['status']); |
||||||
96 | $donnee['status'] = $_POST['status']; |
||||||
97 | } else { |
||||||
98 | $obj->setVar('status', 0); |
||||||
99 | $donnee['status'] = 0; |
||||||
100 | } |
||||||
101 | } |
||||||
102 | } |
||||||
103 | $donnee['date_update'] = 0; |
||||||
104 | // erreur si la taille du fichier n'est pas un nombre |
||||||
105 | if (\Xmf\Request::hasVar('size', 'REQUEST')) { |
||||||
106 | if ('0' === $_REQUEST['size'] || '' === $_REQUEST['size']) { |
||||||
107 | $erreur = false; |
||||||
108 | } else { |
||||||
109 | $erreur = true; |
||||||
110 | $message_erreur .= _MD_TDMDOWNLOADS_ERREUR_SIZE . '<br>'; |
||||||
111 | } |
||||||
112 | } |
||||||
113 | // erreur si la catégorie est vide |
||||||
114 | if (\Xmf\Request::hasVar('cid', 'REQUEST')) { |
||||||
115 | if (0 == $_REQUEST['cid']) { |
||||||
116 | $erreur = true; |
||||||
117 | $message_erreur .= _MD_TDMDOWNLOADS_ERREUR_NOCAT . '<br>'; |
||||||
118 | } |
||||||
119 | } |
||||||
120 | // erreur si le captcha est faux |
||||||
121 | xoops_load('xoopscaptcha'); |
||||||
122 | $xoopsCaptcha = \XoopsCaptcha::getInstance(); |
||||||
123 | if (!$xoopsCaptcha->verify()) { |
||||||
124 | $message_erreur .= $xoopsCaptcha->getMessage() . '<br>'; |
||||||
125 | $erreur = true; |
||||||
126 | } |
||||||
127 | // pour enregistrer temporairement les valeur des champs sup |
||||||
128 | $criteria = new \CriteriaCompo(); |
||||||
129 | $criteria->setSort('weight ASC, title'); |
||||||
130 | $criteria->setOrder('ASC'); |
||||||
131 | $downloads_field = $fieldHandler->getAll($criteria); |
||||||
132 | foreach (array_keys($downloads_field) as $i) { |
||||||
133 | if (0 === $downloads_field[$i]->getVar('status_def')) { |
||||||
134 | $nom_champ = 'champ' . $downloads_field[$i]->getVar('fid'); |
||||||
135 | $donnee[$nom_champ] = $_POST[$nom_champ]; |
||||||
136 | } |
||||||
137 | } |
||||||
138 | // enregistrement temporaire des tags |
||||||
139 | if ((1 === $helper->getConfig('usetag')) && is_dir('../tag')) { |
||||||
140 | $donnee['TAG'] = $_POST['tag']; |
||||||
141 | } |
||||||
142 | if (true === $erreur) { |
||||||
143 | $xoopsTpl->assign('message_erreur', $message_erreur); |
||||||
144 | } else { |
||||||
145 | $obj->setVar('size', $_POST['size'] . ' ' . $_POST['type_size']); |
||||||
146 | // Pour le fichier |
||||||
147 | if (isset($_POST['xoops_upload_file'][0])) { |
||||||
148 | $uploader = new \XoopsMediaUploader($uploaddir_downloads, explode('|', $helper->getConfig('mimetype')), $helper->getConfig('maxuploadsize'), null, null); |
||||||
149 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
||||||
150 | if ($helper->getConfig('newnamedownload')) { |
||||||
151 | $uploader->setPrefix($helper->getConfig('prefixdownloads')); |
||||||
152 | } |
||||||
153 | $uploader->fetchMedia($_POST['xoops_upload_file'][0]); |
||||||
154 | if (!$uploader->upload()) { |
||||||
155 | $errors = $uploader->getErrors(); |
||||||
156 | redirect_header('javascript:history.go(-1)', 3, $errors); |
||||||
157 | } else { |
||||||
158 | $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName()); |
||||||
159 | } |
||||||
160 | } else { |
||||||
161 | $obj->setVar('url', $_REQUEST['url']); |
||||||
162 | } |
||||||
163 | } |
||||||
164 | // Pour l'image |
||||||
165 | if (isset($_POST['xoops_upload_file'][1])) { |
||||||
166 | $uploader_2 = new \XoopsMediaUploader($uploaddir_shots, [ |
||||||
167 | 'image/gif', |
||||||
168 | 'image/jpeg', |
||||||
169 | 'image/pjpeg', |
||||||
170 | 'image/x-png', |
||||||
171 | 'image/png', |
||||||
172 | ], $helper->getConfig('maxuploadsize'), null, null); |
||||||
173 | if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) { |
||||||
174 | $uploader_2->setPrefix('downloads_'); |
||||||
175 | $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]); |
||||||
176 | if (!$uploader_2->upload()) { |
||||||
177 | $errors = $uploader_2->getErrors(); |
||||||
178 | redirect_header('javascript:history.go(-1)', 3, $errors); |
||||||
179 | } else { |
||||||
180 | $obj->setVar('logourl', $uploader_2->getSavedFileName()); |
||||||
181 | } |
||||||
182 | } else { |
||||||
183 | $obj->setVar('logourl', $_REQUEST['logo_img']); |
||||||
184 | } |
||||||
185 | } |
||||||
186 | |||||||
187 | if ($downloadsHandler->insert($obj)) { |
||||||
188 | $lidDownloads = $obj->getNewEnreg($db); |
||||||
189 | //tags |
||||||
190 | if ((1 === $helper->getConfig('usetag')) && is_dir('../tag')) { |
||||||
191 | /** @var \XoopsModules\Tag\TagHandler $tagHandler */ |
||||||
192 | $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
||||||
193 | $tagHandler->updateByItem($_POST['tag'], $lidDownloads, $moduleDirName, 0); |
||||||
194 | } |
||||||
195 | // Récupération des champs supplémentaires: |
||||||
196 | $criteria = new \CriteriaCompo(); |
||||||
197 | $criteria->setSort('weight ASC, title'); |
||||||
198 | $criteria->setOrder('ASC'); |
||||||
199 | $downloads_field = $fieldHandler->getAll($criteria); |
||||||
200 | foreach (array_keys($downloads_field) as $i) { |
||||||
201 | if (0 === $downloads_field[$i]->getVar('status_def')) { |
||||||
202 | $objdata = $fielddataHandler->create(); |
||||||
203 | $nom_champ = 'champ' . $downloads_field[$i]->getVar('fid'); |
||||||
204 | $objdata->setVar('data', $_POST[$nom_champ]); |
||||||
205 | $objdata->setVar('lid', $lidDownloads); |
||||||
206 | $objdata->setVar('fid', $downloads_field[$i]->getVar('fid')); |
||||||
207 | $fielddataHandler->insert($objdata) || $objdata->getHtmlErrors(); |
||||||
208 | } |
||||||
209 | } |
||||||
210 | if ($xoopsUser) { |
||||||
211 | if ($xoopsUser->isAdmin($xoopsModule->mid())) { |
||||||
212 | //permission pour télécharger |
||||||
213 | if (1 == $helper->getConfig('permission_download')) { |
||||||
214 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||||||
215 | $grouppermHandler = xoops_getHandler('groupperm'); |
||||||
216 | $criteria = new \CriteriaCompo(); |
||||||
217 | $criteria->add(new \Criteria('gperm_itemid', $lidDownloads, '=')); |
||||||
218 | $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '=')); |
||||||
219 | $criteria->add(new \Criteria('gperm_name', 'tdmdownloads_download_item', '=')); |
||||||
220 | $grouppermHandler->deleteAll($criteria); |
||||||
221 | if (\Xmf\Request::hasVar('item_download', 'POST')) { |
||||||
222 | foreach ($_POST['item_download'] as $onegroup_id) { |
||||||
223 | $grouppermHandler->addRight('tdmdownloads_download_item', $lidDownloads, $onegroup_id, $xoopsModule->getVar('mid')); |
||||||
224 | } |
||||||
225 | } |
||||||
226 | } |
||||||
227 | } |
||||||
228 | } |
||||||
229 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||||||
230 | $notificationHandler = xoops_getHandler('notification'); |
||||||
231 | $tags = []; |
||||||
232 | $tags['FILE_NAME'] = $donnee['title']; |
||||||
233 | $tags['FILE_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $donnee['cid'] . '&lid=' . $lidDownloads; |
||||||
234 | $downloadscat_cat = $categoryHandler->get($donnee['cid']); |
||||||
235 | $tags['CATEGORY_NAME'] = $downloadscat_cat->getVar('cat_title'); |
||||||
236 | $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $donnee['cid']; |
||||||
237 | |||||||
238 | if (true === $perm_autoapprove) { |
||||||
239 | $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
![]() |
|||||||
240 | $notificationHandler->triggerEvent('category', $donnee['cid'], 'new_file', $tags); |
||||||
241 | redirect_header('index.php', 2, _MD_TDMDOWNLOADS_SUBMIT_RECEIVED . '<br>' . _MD_TDMDOWNLOADS_SUBMIT_ISAPPROVED . ''); |
||||||
242 | exit; |
||||||
243 | } |
||||||
244 | $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/admin/index.php?op=listNewDownloads'; |
||||||
245 | $notificationHandler->triggerEvent('global', 0, 'file_submit', $tags); |
||||||
246 | $notificationHandler->triggerEvent('category', $donnee['cid'], 'file_submit', $tags); |
||||||
247 | redirect_header('index.php', 2, _MD_TDMDOWNLOADS_SUBMIT_RECEIVED); |
||||||
248 | exit; |
||||||
249 | } |
||||||
250 | echo $obj->getHtmlErrors(); |
||||||
251 | } |
||||||
252 | $form = $obj->getForm($donnee, true); |
||||||
253 | $xoopsTpl->assign('themeForm', $form->render()); |
||||||
254 | |||||||
255 | break; |
||||||
256 | } |
||||||
257 | require XOOPS_ROOT_PATH . '/footer.php'; |
||||||
258 |