XoopsModules25x /
tdmdownloads
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | use Xmf\Metagen; |
||
| 4 | use XoopsModules\Tag\Tag; |
||
| 5 | use XoopsModules\Tdmdownloads\{ |
||
| 6 | Helper, |
||
| 7 | Tree}; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * TDMDownload |
||
| 11 | * |
||
| 12 | * You may not change or alter any portion of this comment or credits |
||
| 13 | * of supporting developers from this source code or any supporting source code |
||
| 14 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 15 | * This program is distributed in the hope that it will be useful, |
||
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 18 | * |
||
| 19 | * @copyright Gregory Mage (Aka Mage) |
||
| 20 | * @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
||
| 21 | * @author Gregory Mage (Aka Mage) |
||
| 22 | */ |
||
| 23 | require_once __DIR__ . '/header.php'; |
||
| 24 | |||
| 25 | /** @var \XoopsModules\Tdmdownloads\Helper $helper */ |
||
| 26 | $helper = Helper::getInstance(); |
||
| 27 | |||
| 28 | $moduleDirName = basename(__DIR__); |
||
| 29 | // template d'affichage |
||
| 30 | $GLOBALS['xoopsOption']['template_main'] = 'tdmdownloads_singlefile.tpl'; |
||
| 31 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 32 | /** @var \xos_opal_Theme $xoTheme */ |
||
| 33 | $xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/styles.css', null); |
||
| 34 | $xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/blocks.css', null); |
||
| 35 | |||
| 36 | $lid = \Xmf\Request::getInt('lid', 0, 'REQUEST'); |
||
| 37 | |||
| 38 | //information du téléchargement |
||
| 39 | $viewDownloads = $downloadsHandler->get($lid); |
||
| 40 | |||
| 41 | // redirection si le téléchargement n'existe pas ou n'est pas activé |
||
| 42 | if ((is_array($viewDownloads) && 0 == count($viewDownloads)) || 0 == $viewDownloads->getVar('status')) { |
||
| 43 | redirect_header('index.php', 3, _MD_TDMDOWNLOADS_SINGLEFILE_NONEXISTENT); |
||
| 44 | } |
||
| 45 | |||
| 46 | // pour les permissions |
||
| 47 | $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); |
||
| 48 | if (!in_array($viewDownloads->getVar('cid'), $categories)) { |
||
| 49 | redirect_header(XOOPS_URL, 2, _NOPERM); |
||
| 50 | } |
||
| 51 | |||
| 52 | //tableau des catégories |
||
| 53 | $criteria = new \CriteriaCompo(); |
||
| 54 | $criteria->setSort('cat_weight ASC, cat_title'); |
||
| 55 | $criteria->setOrder('ASC'); |
||
| 56 | $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); |
||
| 57 | $downloadscatArray = $categoryHandler->getAll($criteria); |
||
| 58 | $mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); |
||
| 59 | |||
| 60 | //navigation |
||
| 61 | $navigation = $utility::getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ', true, 'ASC', true); |
||
| 62 | $navigation .= ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ' . $viewDownloads->getVar('title'); |
||
| 63 | $xoopsTpl->assign('navigation', $navigation); |
||
| 64 | |||
| 65 | // sortie des informations |
||
| 66 | //Utilisation d'une copie d'écran avec la largeur selon les préférences |
||
| 67 | if (1 == $helper->getConfig('useshots')) { |
||
| 68 | $xoopsTpl->assign('shotwidth', $helper->getConfig('shotwidth')); |
||
| 69 | |||
| 70 | $xoopsTpl->assign('show_screenshot', true); |
||
| 71 | |||
| 72 | $xoopsTpl->assign('img_float', $helper->getConfig('img_float')); |
||
| 73 | } |
||
| 74 | |||
| 75 | if ('ltr' === $helper->getConfig('download_float')) { |
||
| 76 | $xoopsTpl->assign('textfloat', 'floatleft'); |
||
| 77 | |||
| 78 | $xoopsTpl->assign('infofloat', 'floatright'); |
||
| 79 | } else { |
||
| 80 | $xoopsTpl->assign('textfloat', 'floatright'); |
||
| 81 | |||
| 82 | $xoopsTpl->assign('infofloat', 'floatleft'); |
||
| 83 | } |
||
| 84 | |||
| 85 | // sortie des informations |
||
| 86 | if ('blank.gif' === $viewDownloads->getVar('logourl')) { |
||
| 87 | $logourl = ''; |
||
| 88 | } else { |
||
| 89 | $logourl = $viewDownloads->getVar('logourl'); |
||
| 90 | |||
| 91 | $logourl = $uploadurl_shots . $logourl; |
||
| 92 | } |
||
| 93 | // Défini si la personne est un admin |
||
| 94 | $adminlink = ''; |
||
| 95 | if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) { |
||
| 96 | $adminlink = '<a href="' |
||
| 97 | . XOOPS_URL |
||
| 98 | . '/modules/' |
||
| 99 | . $moduleDirName |
||
| 100 | . '/admin/downloads.php?op=view_downloads&downloads_lid=' |
||
| 101 | . \Xmf\Request::getInt('lid', 0, 'REQUEST') |
||
| 102 | . '" title="' |
||
| 103 | . _MD_TDMDOWNLOADS_EDITTHISDL |
||
| 104 | . '"><img src="' |
||
| 105 | . XOOPS_URL |
||
| 106 | . '/modules/' |
||
| 107 | . $moduleDirName |
||
| 108 | . '/assets/images/icons/16/edit.png" width="16px" height="16px" border="0" alt="' |
||
| 109 | . _MD_TDMDOWNLOADS_EDITTHISDL |
||
| 110 | . '"></a>'; |
||
| 111 | } |
||
| 112 | |||
| 113 | $description = $viewDownloads->getVar('description'); |
||
| 114 | $xoopsTpl->assign('description', str_replace('[pagebreak]', '', $description)); |
||
| 115 | $xoopsTpl->assign('lid', $lid); |
||
| 116 | $xoopsTpl->assign('cid', $viewDownloads->getVar('cid')); |
||
| 117 | $xoopsTpl->assign('logourl', $logourl); |
||
| 118 | // pour les vignettes "new" et "mis à jour" |
||
| 119 | $new = $utility->getStatusImage($viewDownloads->getVar('date'), $viewDownloads->getVar('status')); |
||
| 120 | $pop = $utility->getPopularImage($viewDownloads->getVar('hits')); |
||
| 121 | $xoopsTpl->assign('title', $viewDownloads->getVar('title')); |
||
| 122 | $xoopsTpl->assign('new', $new); |
||
| 123 | $xoopsTpl->assign('pop', $pop); |
||
| 124 | $xoopsTpl->assign('adminlink', $adminlink); |
||
| 125 | $xoopsTpl->assign('date', formatTimestamp($viewDownloads->getVar('date'), 's')); |
||
| 126 | $xoopsTpl->assign('author', \XoopsUser::getUnameFromId($viewDownloads->getVar('submitter'))); |
||
| 127 | $xoopsTpl->assign('hits', sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_NBTELECH, $viewDownloads->getVar('hits'))); |
||
| 128 | $xoopsTpl->assign('rating', number_format((float)$viewDownloads->getVar('rating'), 1)); |
||
| 129 | $xoopsTpl->assign('votes', sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_VOTES, $viewDownloads->getVar('votes'))); |
||
| 130 | $xoopsTpl->assign('nb_comments', sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_COMMENTS, $viewDownloads->getVar('comments'))); |
||
| 131 | $xoopsTpl->assign('show_bookmark', $helper->getConfig('show_bookmark')); |
||
| 132 | $xoopsTpl->assign('show_social', $helper->getConfig('show_social')); |
||
| 133 | |||
| 134 | //paypal |
||
| 135 | $paypal = false; |
||
| 136 | if (true === $helper->getConfig('use_paypal') && '' !== $viewDownloads->getVar('paypal')) { |
||
| 137 | $paypal = '<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> |
||
| 138 | <input type="hidden" name="cmd" value="_xclick"> |
||
| 139 | <input type="hidden" name="business" value="' . $viewDownloads->getVar('paypal') . '"> |
||
| 140 | <input type="hidden" name="item_name" value="' . sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_PAYPAL, $viewDownloads->getVar('title')) . ' (' . \XoopsUser::getUnameFromId(!empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0) . ')"> |
||
| 141 | <input type="hidden" name="currency_code" value="' . $helper->getConfig('currency_paypal') . '"> |
||
| 142 | <input type="image" src="' . $helper->getConfig('image_paypal') . '" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!"> |
||
| 143 | </form>'; |
||
| 144 | } |
||
| 145 | $xoopsTpl->assign('paypal', $paypal); |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @param $k |
||
| 149 | * @return string |
||
| 150 | */ |
||
| 151 | function getXfieldKey($k) |
||
| 152 | { |
||
| 153 | return \mb_strtolower( |
||
| 154 | str_replace( |
||
| 155 | ['Ü', 'ü', 'Ş', 'ş', 'I', 'ı', 'Ç', 'ç', 'Ğ', 'ğ', 'Ö', 'ö'], |
||
| 156 | ['u', 'u', 's', 's', 'i', 'i', 'c', 'c', 'g', 'g', 'o', 'o'], |
||
| 157 | $k |
||
| 158 | ) |
||
| 159 | ); |
||
| 160 | } |
||
| 161 | |||
| 162 | // pour les champs supplémentaires |
||
| 163 | $criteria = new \CriteriaCompo(); |
||
| 164 | $criteria->setSort('weight ASC, title'); |
||
| 165 | $criteria->setOrder('ASC'); |
||
| 166 | $criteria->add(new \Criteria('status', 1)); |
||
| 167 | /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ |
||
| 168 | $downloads_field = $fieldHandler->getAll($criteria); |
||
| 169 | $nb_champ = count($downloads_field); |
||
| 170 | $champ_sup = ''; |
||
| 171 | $champ_sup_vide = 0; |
||
| 172 | $xfields = []; |
||
| 173 | foreach (array_keys($downloads_field) as $i) { |
||
| 174 | /** @var \XoopsModules\Tdmdownloads\Field[] $downloads_field */ |
||
| 175 | |||
| 176 | if (1 == $downloads_field[$i]->getVar('status_def')) { |
||
| 177 | if (1 == $downloads_field[$i]->getVar('fid')) { |
||
| 178 | //page d'accueil |
||
| 179 | |||
| 180 | if ('' != $viewDownloads->getVar('homepage')) { |
||
| 181 | $champ_sup = ' ' . _AM_TDMDOWNLOADS_FORMHOMEPAGE . ': <a href="' . $viewDownloads->getVar('homepage') . '">' . _MD_TDMDOWNLOADS_SINGLEFILE_ICI . '</a>'; |
||
| 182 | |||
| 183 | ++$champ_sup_vide; |
||
| 184 | |||
| 185 | $xfields['homepage'] = $champ_sup; |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | if (2 == $downloads_field[$i]->getVar('fid')) { |
||
| 190 | //version |
||
| 191 | |||
| 192 | if ('' != $viewDownloads->getVar('version')) { |
||
| 193 | $champ_sup = ' ' . _AM_TDMDOWNLOADS_FORMVERSION . ': ' . $viewDownloads->getVar('version'); |
||
| 194 | |||
| 195 | ++$champ_sup_vide; |
||
| 196 | |||
| 197 | $xfields['version'] = $champ_sup; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | if (3 == $downloads_field[$i]->getVar('fid')) { |
||
| 202 | //taille du fichier |
||
| 203 | |||
| 204 | $size_value_arr = explode(' ', $viewDownloads->getVar('size')); |
||
| 205 | |||
| 206 | if ('' != $size_value_arr[0]) { |
||
| 207 | $champ_sup = ' ' . _AM_TDMDOWNLOADS_FORMSIZE . ': ' . $utility::convertSizeToString($viewDownloads->getVar('size')); |
||
| 208 | |||
| 209 | ++$champ_sup_vide; |
||
| 210 | |||
| 211 | $xfields['size'] = $champ_sup; |
||
| 212 | } |
||
| 213 | } |
||
| 214 | |||
| 215 | if (4 == $downloads_field[$i]->getVar('fid')) { |
||
| 216 | //plateforme |
||
| 217 | |||
| 218 | if ('' != $viewDownloads->getVar('platform')) { |
||
| 219 | $champ_sup = ' ' . _AM_TDMDOWNLOADS_FORMPLATFORM . $viewDownloads->getVar('platform'); |
||
| 220 | |||
| 221 | ++$champ_sup_vide; |
||
| 222 | |||
| 223 | $xfields['platform'] = $champ_sup; |
||
| 224 | } |
||
| 225 | } |
||
| 226 | } else { |
||
| 227 | $view_data = $fielddataHandler->get(); |
||
| 228 | |||
| 229 | $criteria = new \CriteriaCompo(); |
||
| 230 | |||
| 231 | $criteria->add(new \Criteria('lid', \Xmf\Request::getInt('lid', 0, 'REQUEST'))); |
||
| 232 | |||
| 233 | $criteria->add(new \Criteria('fid', $downloads_field[$i]->getVar('fid'))); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 234 | |||
| 235 | $downloadsfielddata = $fielddataHandler->getAll($criteria); |
||
| 236 | |||
| 237 | $contenu = ''; |
||
| 238 | |||
| 239 | foreach (array_keys($downloadsfielddata) as $j) { |
||
| 240 | /** @var \XoopsModules\Tdmdownloads\Fielddata[] $downloadsfielddata */ |
||
| 241 | |||
| 242 | $contenu = $downloadsfielddata[$j]->getVar('data', 'n'); |
||
| 243 | } |
||
| 244 | |||
| 245 | if ('' != $contenu) { |
||
| 246 | $champ_sup = ' ' . $downloads_field[$i]->getVar('title') . ': ' . $contenu; |
||
| 247 | |||
| 248 | ++$champ_sup_vide; |
||
| 249 | |||
| 250 | $xfieldKey = getXfieldKey($downloads_field[$i]->getVar('title')); |
||
| 251 | |||
| 252 | $xfields[$xfieldKey] = $contenu; |
||
| 253 | } |
||
| 254 | } |
||
| 255 | |||
| 256 | if ('' != $champ_sup) { |
||
| 257 | $xoopsTpl->append( |
||
| 258 | 'champ_sup', |
||
| 259 | [ |
||
| 260 | 'image' => $uploadurl_field . $downloads_field[$i]->getVar('img'), |
||
| 261 | 'data' => $champ_sup, |
||
| 262 | ] |
||
| 263 | ); |
||
| 264 | } |
||
| 265 | |||
| 266 | $champ_sup = ''; |
||
| 267 | } |
||
| 268 | |||
| 269 | $xoopsTpl->assign('xfields', $xfields); |
||
| 270 | if ($nb_champ > 0 && $champ_sup_vide > 0) { |
||
| 271 | $xoopsTpl->assign('sup_aff', true); |
||
| 272 | } else { |
||
| 273 | $xoopsTpl->assign('sup_aff', false); |
||
| 274 | } |
||
| 275 | //permission |
||
| 276 | $xoopsTpl->assign('perm_vote', $perm_vote); |
||
| 277 | $xoopsTpl->assign('perm_modif', $perm_modif); |
||
| 278 | $categories = $utility->getItemIds('tdmdownloads_download', $moduleDirName); |
||
| 279 | $item = $utility->getItemIds('tdmdownloads_download_item', $moduleDirName); |
||
| 280 | if (1 == $helper->getConfig('permission_download')) { |
||
| 281 | if (!in_array($viewDownloads->getVar('cid'), $categories)) { |
||
| 282 | $xoopsTpl->assign('perm_download', false); |
||
| 283 | } else { |
||
| 284 | $xoopsTpl->assign('perm_download', true); |
||
| 285 | } |
||
| 286 | } else { |
||
| 287 | if (!in_array($viewDownloads->getVar('lid'), $item)) { |
||
| 288 | $xoopsTpl->assign('perm_download', false); |
||
| 289 | } else { |
||
| 290 | $xoopsTpl->assign('perm_download', true); |
||
| 291 | } |
||
| 292 | } |
||
| 293 | |||
| 294 | // pour utiliser tellafriend. |
||
| 295 | if (1 == $helper->getConfig('usetellafriend') && is_dir('../tellafriend')) { |
||
| 296 | $string = sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_INTFILEFOUND, $xoopsConfig['sitename'] . ': ' . XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0, 'REQUEST')); |
||
| 297 | |||
| 298 | $subject = sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_INTFILEFOUND, $xoopsConfig['sitename']); |
||
| 299 | |||
| 300 | if (false !== mb_strpos($subject, '%')) { |
||
| 301 | $subject = rawurldecode($subject); |
||
| 302 | } |
||
| 303 | |||
| 304 | if (false !== mb_stripos($string, '%3F')) { |
||
| 305 | $string = rawurldecode($string); |
||
| 306 | } |
||
| 307 | |||
| 308 | if (preg_match('/(' . preg_quote(XOOPS_URL, '/') . '.*)$/i', $string, $matches)) { |
||
| 309 | $targetUri = str_replace('&', '&', $matches[1]); |
||
| 310 | } else { |
||
| 311 | $targetUri = XOOPS_URL . $_SERVER['REQUEST_URI']; |
||
| 312 | } |
||
| 313 | |||
| 314 | $tellafriendText = '<a target="_top" href="' . XOOPS_URL . '/modules/tellafriend/index.php?target_uri=' . rawurlencode($targetUri) . '&subject=' . rawurlencode($subject) . '">' . _MD_TDMDOWNLOADS_SINGLEFILE_TELLAFRIEND . '</a>'; |
||
| 315 | } else { |
||
| 316 | $tellafriendText = '<a target="_top" href="mailto:?subject=' . rawurlencode(sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_INTFILEFOUND, $xoopsConfig['sitename'])) . '&body=' . rawurlencode( |
||
| 317 | sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_INTFILEFOUND, $xoopsConfig['sitename']) . ': ' . XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?lid=' . \Xmf\Request::getInt('lid', 0, 'REQUEST') |
||
| 318 | ) . '">' . _MD_TDMDOWNLOADS_SINGLEFILE_TELLAFRIEND . '</a>'; |
||
| 319 | } |
||
| 320 | $xoopsTpl->assign('tellafriend_texte', $tellafriendText); |
||
| 321 | |||
| 322 | // référencement |
||
| 323 | // tags |
||
| 324 | if (1 == $helper->getConfig('usetag') && class_exists(Tag::class)) { |
||
| 325 | require_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php'; |
||
| 326 | |||
| 327 | $xoopsTpl->assign('tags', true); |
||
| 328 | |||
| 329 | $xoopsTpl->assign('tagbar', tagBar(\Xmf\Request::getInt('lid', 0, 'REQUEST'), 0)); |
||
| 330 | } else { |
||
| 331 | $xoopsTpl->assign('tags', false); |
||
| 332 | } |
||
| 333 | |||
| 334 | // titre de la page |
||
| 335 | $pagetitle = $viewDownloads->getVar('title') . ' - '; |
||
| 336 | $pagetitle .= $utility::getPathTreeUrl($mytree, $viewDownloads->getVar('cid'), $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC', true); |
||
| 337 | $xoopsTpl->assign('xoops_pagetitle', $pagetitle); |
||
| 338 | //version for title |
||
| 339 | $xoopsTpl->assign('version', $viewDownloads->getVar('version')); |
||
| 340 | //description |
||
| 341 | if (false === mb_strpos($description, '[pagebreak]')) { |
||
| 342 | $descriptionShort = mb_substr($description, 0, 400); |
||
| 343 | } else { |
||
| 344 | $descriptionShort = mb_substr($description, 0, mb_strpos($description, '[pagebreak]')); |
||
| 345 | } |
||
| 346 | $xoTheme->addMeta('meta', 'description', strip_tags($descriptionShort)); |
||
| 347 | //keywords |
||
| 348 | $keywords = Metagen::generateKeywords($viewDownloads->getVar('description'), 10); |
||
| 349 | $xoTheme->addMeta('meta', 'keywords', implode(', ', $keywords)); |
||
| 350 | /*$keywords = substr($keywords,0,-1); |
||
| 351 | $xoTheme->addMeta( 'meta', 'keywords', $keywords);*/ |
||
| 352 | require XOOPS_ROOT_PATH . '/include/comment_view.php'; |
||
| 353 | require XOOPS_ROOT_PATH . '/footer.php'; |
||
| 354 |