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