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 | 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 | /** @var \XoopsModules\Tdmdownloads\Downloads $obj */ |
||||
| 80 | $obj = $downloadsHandler->get($lid); |
||||
| 81 | /** @var \XoopsThemeForm $form */ |
||||
| 82 | $form = $obj->getForm($donnee = [], false, 'submit.php'); |
||||
| 83 | } else { |
||||
| 84 | /** @var \XoopsModules\Tdmdownloads\Modified $obj */ |
||||
| 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 | /** @var \XoopsModules\Tdmdownloads\Downloads $obj */ |
||||
| 95 | $obj = $modifiedHandler->create(); |
||||
| 96 | $erreur = false; |
||||
| 97 | $errorMessage = ''; |
||||
| 98 | $donnee = []; |
||||
| 99 | $obj->setVar('title', \Xmf\Request::getString('title', '', 'POST')); //$_POST['title']); |
||||
| 100 | $donnee['title'] = \Xmf\Request::getString('title', '', 'POST'); //$_POST['title']; |
||||
| 101 | $obj->setVar('cid', \Xmf\Request::getInt('cid', 0, 'POST')); //$_POST['cid']); |
||||
| 102 | $donnee['cid'] = \Xmf\Request::getInt('cid', 0, 'POST'); //$_POST['cid']; |
||||
| 103 | $obj->setVar('lid', \Xmf\Request::getInt('lid', 0, 'POST')); //$_POST['lid']); |
||||
| 104 | $obj->setVar('homepage', \Xmf\Request::getString('homepage', '', 'POST')); //formatURL($_POST["homepage"])); |
||||
| 105 | $donnee['homepage'] = \Xmf\Request::getString('homepage', '', 'POST'); //formatURL($_POST["homepage"]); |
||||
| 106 | $obj->setVar('version', \Xmf\Request::getString('version', '', 'POST')); //$_POST["version"]); |
||||
| 107 | $donnee['version'] = \Xmf\Request::getString('version', '', 'POST'); //$_POST["version"]; |
||||
| 108 | if (\Xmf\Request::hasVar('platform', 'POST')) { |
||||
| 109 | $obj->setVar('platform', implode('|', \Xmf\Request::getString('platform', '', 'POST'))); //$_POST['platform'])); |
||||
| 110 | $donnee['platform'] = implode('|', \Xmf\Request::getString('platform', '', 'POST')); //$_POST["platform"]); |
||||
| 111 | } else { |
||||
| 112 | $donnee['platform'] = ''; |
||||
| 113 | } |
||||
| 114 | $obj->setVar('description', \Xmf\Request::getString('description', '', 'POST')); //$_POST["description"]); |
||||
| 115 | $donnee['description'] = \Xmf\Request::getString('description', '', 'POST'); //$_POST["description"]; |
||||
| 116 | $obj->setVar('modifysubmitter', !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0); |
||||
| 117 | |||||
| 118 | // erreur si la catégorie est vide |
||||
| 119 | if (\Xmf\Request::hasVar('cid')) { |
||||
| 120 | if (0 == \Xmf\Request::getInt('cid', 0, 'POST')) { |
||||
| 121 | $erreur = true; |
||||
| 122 | $errorMessage .= _MD_TDMDOWNLOADS_ERREUR_NOCAT . '<br>'; |
||||
| 123 | } |
||||
| 124 | } |
||||
| 125 | // get captcha (members are skipped in class/download.php getForm |
||||
| 126 | if (!$xoopsUser) { |
||||
| 127 | // erreur si le captcha est faux |
||||
| 128 | xoops_load('xoopscaptcha'); |
||||
| 129 | $xoopsCaptcha = \XoopsCaptcha::getInstance(); |
||||
| 130 | if (!$xoopsCaptcha->verify()) { |
||||
| 131 | $errorMessage .= $xoopsCaptcha->getMessage() . '<br>'; |
||||
| 132 | $erreur = true; |
||||
| 133 | } |
||||
| 134 | } |
||||
| 135 | // pour enregistrer temporairement les valeur des champs sup |
||||
| 136 | $criteria = new \CriteriaCompo(); |
||||
| 137 | $criteria->setSort('weight ASC, title'); |
||||
| 138 | $criteria->setOrder('ASC'); |
||||
| 139 | $downloads_field = $fieldHandler->getAll($criteria); |
||||
| 140 | foreach (array_keys($downloads_field) as $i) { |
||||
| 141 | /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ |
||||
| 142 | if (0 == $downloads_field[$i]->getVar('status_def')) { |
||||
| 143 | $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); |
||||
| 144 | $donnee[$fieldName] = \Xmf\Request::getString($fieldName, '', 'POST'); |
||||
| 145 | } |
||||
| 146 | } |
||||
| 147 | if (true === $erreur) { |
||||
| 148 | $xoopsTpl->assign('message_erreur', $errorMessage); |
||||
| 149 | } else { |
||||
| 150 | // Pour le fichier |
||||
| 151 | $mediaSize = 0; |
||||
| 152 | if (isset($_POST['xoops_upload_file'][0])) { |
||||
| 153 | $uploader = new \XoopsMediaUploader($uploaddir_downloads, $helper->getConfig('mimetype'), $helper->getConfig('maxuploadsize'), null, null); |
||||
| 154 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
||||
| 155 | if ($helper->getConfig('newnamedownload')) { |
||||
| 156 | $uploader->setPrefix($helper->getConfig('prefixdownloads')); |
||||
| 157 | } |
||||
| 158 | $uploader->fetchMedia($_POST['xoops_upload_file'][0]); |
||||
| 159 | if (!$uploader->upload()) { |
||||
| 160 | $errors = $uploader->getErrors(); |
||||
| 161 | redirect_header('javascript:history.go(-1)', 3, $errors); |
||||
| 162 | } else { |
||||
| 163 | $mediaSize = $uploader->getMediaSize(); |
||||
| 164 | $obj->setVar('url', $uploadurl_downloads . $uploader->getSavedFileName()); |
||||
| 165 | } |
||||
| 166 | } else { |
||||
| 167 | if ($_FILES['attachedfile']['name'] > '') { |
||||
| 168 | // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize |
||||
| 169 | $errorMessage .= $uploader->getErrors() . '<br>'; |
||||
| 170 | $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); |
||||
| 171 | /** @var \XoopsThemeForm $form */ |
||||
| 172 | $form = $obj->getForm($donnee, true); |
||||
| 173 | $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); |
||||
| 174 | break; |
||||
| 175 | } |
||||
| 176 | $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST')); |
||||
| 177 | } |
||||
| 178 | } else { |
||||
| 179 | $obj->setVar('url', \Xmf\Request::getString('url', '', 'REQUEST')); |
||||
| 180 | } |
||||
| 181 | // Pour l'image |
||||
| 182 | if (isset($_POST['xoops_upload_file'][1])) { |
||||
| 183 | $uploader_2 = new \XoopsMediaUploader($uploaddir_shots, [ |
||||
| 184 | 'image/gif', |
||||
| 185 | 'image/jpeg', |
||||
| 186 | 'image/pjpeg', |
||||
| 187 | 'image/x-png', |
||||
| 188 | 'image/png', |
||||
| 189 | ], $helper->getConfig('maxuploadsize'), null, null); |
||||
| 190 | if ($uploader_2->fetchMedia($_POST['xoops_upload_file'][1])) { |
||||
| 191 | $uploader_2->setPrefix('downloads_'); |
||||
| 192 | $uploader_2->fetchMedia($_POST['xoops_upload_file'][1]); |
||||
| 193 | if (!$uploader_2->upload()) { |
||||
| 194 | $errors = $uploader_2->getErrors(); |
||||
| 195 | redirect_header('javascript:history.go(-1)', 3, $errors); |
||||
| 196 | } else { |
||||
| 197 | $obj->setVar('logourl', $uploader_2->getSavedFileName()); |
||||
| 198 | } |
||||
| 199 | } else { |
||||
| 200 | if ($_FILES['attachedimage']['name'] > '') { |
||||
| 201 | // file name was given, but fetchMedia failed - show error when e.g. file size exceed maxuploadsize |
||||
| 202 | $errorMessage .= $uploader_2->getErrors() . '<br>'; |
||||
| 203 | $GLOBALS['xoopsTpl']->assign('message_erreur', $errorMessage); |
||||
| 204 | $form = $obj->getForm($donnee, true); |
||||
| 205 | $GLOBALS['xoopsTpl']->assign('themeForm', $form->render()); |
||||
| 206 | break; |
||||
| 207 | } |
||||
| 208 | $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST')); |
||||
| 209 | } |
||||
| 210 | } else { |
||||
| 211 | $obj->setVar('logourl', \Xmf\Request::getString('logo_img', '', 'REQUEST')); |
||||
| 212 | } |
||||
| 213 | //Automatic file size |
||||
| 214 | if (Xmf\Request::getString('sizeValue', '') == ''){ |
||||
| 215 | if ($mediaSize == 0) { |
||||
| 216 | $obj->setVar('size', $utility::GetFileSize(Xmf\Request::getUrl('url', ''))); |
||||
| 217 | } else { |
||||
| 218 | $obj->setVar('size', $utility::FileSizeConvert($mediaSize)); |
||||
| 219 | } |
||||
| 220 | } else { |
||||
| 221 | $obj->setVar('size', Xmf\Request::getFloat('sizeValue', 0) . ' ' . Xmf\Request::getString('sizeType', '')); |
||||
| 222 | } |
||||
| 223 | $timeToRedirect = 2; |
||||
| 224 | if ($obj->getVar('size') == 0){ |
||||
| 225 | $obj->setVar('size', ''); |
||||
| 226 | $error_message = _AM_TDMDOWNLOADS_ERREUR_SIZE; |
||||
| 227 | $timeToRedirect = 10; |
||||
| 228 | } |
||||
| 229 | if ($modifiedHandler->insert($obj)) { |
||||
| 230 | $lidDownloads = $obj->getNewEnreg($db); |
||||
| 231 | // Récupération des champs supplémentaires: |
||||
| 232 | $criteria = new \CriteriaCompo(); |
||||
| 233 | $criteria->setSort('weight ASC, title'); |
||||
| 234 | $criteria->setOrder('ASC'); |
||||
| 235 | $downloads_field = $fieldHandler->getAll($criteria); |
||||
| 236 | foreach (array_keys($downloads_field) as $i) { |
||||
| 237 | /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ |
||||
| 238 | if (0 == $downloads_field[$i]->getVar('status_def')) { |
||||
| 239 | //$objdata = $modifiedfielddataHandler->create(); |
||||
| 240 | $objdata = $modifieddataHandler->create(); |
||||
| 241 | $fieldName = 'champ' . $downloads_field[$i]->getVar('fid'); |
||||
| 242 | $objdata->setVar('moddata', \Xmf\Request::getString($fieldName, '', 'POST')); |
||||
| 243 | $objdata->setVar('lid', $lidDownloads); |
||||
| 244 | $objdata->setVar('fid', $downloads_field[$i]->getVar('fid')); |
||||
| 245 | //$modifiedfielddataHandler->insert($objdata) || $objdata->getHtmlErrors(); |
||||
| 246 | $modifieddataHandler->insert($objdata) || $objdata->getHtmlErrors(); |
||||
| 247 | } |
||||
| 248 | } |
||||
| 249 | $tags = []; |
||||
| 250 | $tags['MODIFYREPORTS_URL'] = XOOPS_URL . '/modules/' . $moduleDirName . '/admin/modified.php'; |
||||
| 251 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||||
| 252 | $notificationHandler = xoops_getHandler('notification'); |
||||
| 253 | $notificationHandler->triggerEvent('global', 0, 'file_modify', $tags); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
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
Loading history...
|
|||||
| 254 | redirect_header('singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0, 'REQUEST'), timeToRedirect, _MD_TDMDOWNLOADS_MODFILE_THANKSFORINFO . '<br><br>' . $error_message); |
||||
|
0 ignored issues
–
show
|
|||||
| 255 | } |
||||
| 256 | echo $obj->getHtmlErrors(); |
||||
| 257 | } |
||||
| 258 | //Affichage du formulaire de notation des téléchargements |
||||
| 259 | $form = $obj->getForm(\Xmf\Request::getInt('lid', 0, 'REQUEST'), true, $donnee); |
||||
| 260 | $xoopsTpl->assign('themeForm', $form->render()); |
||||
| 261 | |||||
| 262 | break; |
||||
| 263 | } |
||||
| 264 | require XOOPS_ROOT_PATH . '/footer.php'; |
||||
| 265 |