XoopsModules25x /
tdmdownloads
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | /** |
||
| 4 | * TDMDownload |
||
| 5 | * |
||
| 6 | * You may not change or alter any portion of this comment or credits |
||
| 7 | * of supporting developers from this source code or any supporting source code |
||
| 8 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 9 | * This program is distributed in the hope that it will be useful, |
||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 12 | * |
||
| 13 | * @copyright Gregory Mage (Aka Mage) |
||
| 14 | * @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
||
| 15 | * @author Gregory Mage (Aka Mage) |
||
| 16 | */ |
||
| 17 | |||
| 18 | use XoopsModules\Tdmdownloads\{ |
||
| 19 | Helper, |
||
| 20 | Tree}; |
||
| 21 | |||
| 22 | require_once __DIR__ . '/header.php'; |
||
| 23 | |||
| 24 | /** @var \XoopsModules\Tdmdownloads\Helper $helper */ |
||
| 25 | $helper = Helper::getInstance(); |
||
| 26 | |||
| 27 | // template d'affichage |
||
| 28 | $moduleDirName = basename(__DIR__); |
||
| 29 | $GLOBALS['xoopsOption']['template_main'] = 'tdmdownloads_index.tpl'; |
||
| 30 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 31 | /** @var \xos_opal_Theme $xoTheme */ |
||
| 32 | $xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/styles.css', null); |
||
| 33 | // pour les permissions |
||
| 34 | $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); |
||
| 35 | |||
| 36 | //tableau des téléchargements |
||
| 37 | $criteria = new \CriteriaCompo(); |
||
| 38 | $criteria->add(new \Criteria('status', 0, '!=')); |
||
| 39 | $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); |
||
| 40 | $downloadsArray = $downloadsHandler->getAll($criteria); |
||
| 41 | $xoopsTpl->assign('lang_thereare', sprintf(_MD_TDMDOWNLOADS_INDEX_THEREARE, count($downloadsArray))); |
||
| 42 | |||
| 43 | //tableau des catégories |
||
| 44 | $criteria = new \CriteriaCompo(); |
||
| 45 | $criteria->setSort('cat_weight ASC, cat_title'); |
||
| 46 | $criteria->setOrder('ASC'); |
||
| 47 | $criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN')); |
||
| 48 | $downloadscatArray = $categoryHandler->getAll($criteria); |
||
| 49 | $mytree = new Tree($downloadscatArray, 'cat_cid', 'cat_pid'); |
||
| 50 | |||
| 51 | //affichage des catégories |
||
| 52 | $xoopsTpl->assign('nb_catcol', $helper->getConfig('nb_catcol')); |
||
| 53 | $count = 1; |
||
| 54 | $keywords = ''; |
||
| 55 | foreach (array_keys($downloadscatArray) as $i) { |
||
| 56 | /** @var \XoopsModules\Tdmdownloads\Category[] $downloadscatArray */ |
||
| 57 | |||
| 58 | if (0 === $downloadscatArray[$i]->getVar('cat_pid')) { |
||
| 59 | $totaldownloads = $utility->getNumbersOfEntries($mytree, $categories, $downloadsArray, $downloadscatArray[$i]->getVar('cat_cid')); |
||
| 60 | |||
| 61 | $subcategories_arr = $mytree->getFirstChild($downloadscatArray[$i]->getVar('cat_cid')); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 62 | |||
| 63 | $chcount = 0; |
||
| 64 | |||
| 65 | $subcategories = ''; |
||
| 66 | |||
| 67 | //pour les mots clef |
||
| 68 | |||
| 69 | $keywords .= $downloadscatArray[$i]->getVar('cat_title') . ','; |
||
| 70 | |||
| 71 | foreach (array_keys($subcategories_arr) as $j) { |
||
| 72 | /** @var \XoopsModules\Tdmdownloads\Category[] $subcategories_arr */ |
||
| 73 | |||
| 74 | if ($chcount >= $helper->getConfig('nbsouscat')) { |
||
| 75 | $subcategories .= '<li>[<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $downloadscatArray[$i]->getVar('cat_cid') . '">+</a>]</li>'; |
||
| 76 | |||
| 77 | break; |
||
| 78 | } |
||
| 79 | |||
| 80 | $subcategories .= '<li><a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $subcategories_arr[$j]->getVar('cat_cid') . '">' . $subcategories_arr[$j]->getVar('cat_title') . '</a></li>'; |
||
| 81 | |||
| 82 | $keywords .= $downloadscatArray[$i]->getVar('cat_title') . ','; |
||
| 83 | |||
| 84 | ++$chcount; |
||
| 85 | } |
||
| 86 | |||
| 87 | $xoopsTpl->append( |
||
| 88 | 'categories', |
||
| 89 | [ |
||
| 90 | 'image' => $uploadurl . $downloadscatArray[$i]->getVar('cat_imgurl'), |
||
| 91 | 'id' => $downloadscatArray[$i]->getVar('cat_cid'), |
||
| 92 | 'title' => $downloadscatArray[$i]->getVar('cat_title'), |
||
| 93 | 'description_main' => $downloadscatArray[$i]->getVar('cat_description_main'), |
||
| 94 | 'subcategories' => $subcategories, |
||
| 95 | 'countsubs' => count($subcategories_arr), |
||
| 96 | 'totaldownloads' => $totaldownloads, |
||
| 97 | 'count' => $count, |
||
| 98 | ] |
||
| 99 | ); |
||
| 100 | |||
| 101 | ++$count; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | //pour afficher les résumés |
||
| 106 | //---------------------------------------------------------------------------------------------------------------------------------------------------- |
||
| 107 | //téléchargements récents |
||
| 108 | if (1 == $helper->getConfig('bldate')) { |
||
| 109 | $criteria = new \CriteriaCompo(); |
||
| 110 | |||
| 111 | $criteria->add(new \Criteria('status', 0, '!=')); |
||
| 112 | |||
| 113 | $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); |
||
| 114 | |||
| 115 | $criteria->setSort('date'); |
||
| 116 | |||
| 117 | $criteria->setOrder('DESC'); |
||
| 118 | |||
| 119 | $criteria->setLimit($helper->getConfig('nbbl')); |
||
| 120 | |||
| 121 | $downloads_arr_date = $downloadsHandler->getAll($criteria); |
||
| 122 | |||
| 123 | foreach (array_keys($downloads_arr_date) as $i) { |
||
| 124 | /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloads_arr_date */ |
||
| 125 | |||
| 126 | $title = $downloads_arr_date[$i]->getVar('title'); |
||
| 127 | |||
| 128 | if (mb_strlen($title) >= $helper->getConfig('longbl')) { |
||
| 129 | $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...'; |
||
| 130 | } |
||
| 131 | |||
| 132 | $date = formatTimestamp($downloads_arr_date[$i]->getVar('date'), 's'); |
||
| 133 | |||
| 134 | $xoopsTpl->append( |
||
| 135 | 'bl_date', |
||
| 136 | [ |
||
| 137 | 'id' => $downloads_arr_date[$i]->getVar('lid'), |
||
| 138 | 'cid' => $downloads_arr_date[$i]->getVar('cid'), |
||
| 139 | 'date' => $date, |
||
| 140 | 'title' => $title, |
||
| 141 | ] |
||
| 142 | ); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | //plus téléchargés |
||
| 146 | if (1 == $helper->getConfig('blpop')) { |
||
| 147 | $criteria = new \CriteriaCompo(); |
||
| 148 | |||
| 149 | $criteria->add(new \Criteria('status', 0, '!=')); |
||
| 150 | |||
| 151 | $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); |
||
| 152 | |||
| 153 | $criteria->setSort('hits'); |
||
| 154 | |||
| 155 | $criteria->setOrder('DESC'); |
||
| 156 | |||
| 157 | $criteria->setLimit($helper->getConfig('nbbl')); |
||
| 158 | |||
| 159 | $downloads_arr_hits = $downloadsHandler->getAll($criteria); |
||
| 160 | |||
| 161 | foreach (array_keys($downloads_arr_hits) as $i) { |
||
| 162 | /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloads_arr_hits */ |
||
| 163 | |||
| 164 | $title = $downloads_arr_hits[$i]->getVar('title'); |
||
| 165 | |||
| 166 | if (mb_strlen($title) >= $helper->getConfig('longbl')) { |
||
| 167 | $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...'; |
||
| 168 | } |
||
| 169 | |||
| 170 | $xoopsTpl->append( |
||
| 171 | 'bl_pop', |
||
| 172 | [ |
||
| 173 | 'id' => $downloads_arr_hits[$i]->getVar('lid'), |
||
| 174 | 'cid' => $downloads_arr_hits[$i]->getVar('cid'), |
||
| 175 | 'hits' => $downloads_arr_hits[$i]->getVar('hits'), |
||
| 176 | 'title' => $title, |
||
| 177 | ] |
||
| 178 | ); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | //mieux notés |
||
| 182 | if (1 == $helper->getConfig('blrating')) { |
||
| 183 | $criteria = new \CriteriaCompo(); |
||
| 184 | |||
| 185 | $criteria->add(new \Criteria('status', 0, '!=')); |
||
| 186 | |||
| 187 | $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); |
||
| 188 | |||
| 189 | $criteria->setSort('rating'); |
||
| 190 | |||
| 191 | $criteria->setOrder('DESC'); |
||
| 192 | |||
| 193 | $criteria->setLimit($helper->getConfig('nbbl')); |
||
| 194 | |||
| 195 | $downloads_arr_rating = $downloadsHandler->getAll($criteria); |
||
| 196 | |||
| 197 | foreach (array_keys($downloads_arr_rating) as $i) { |
||
| 198 | /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloads_arr_rating */ |
||
| 199 | |||
| 200 | $title = $downloads_arr_rating[$i]->getVar('title'); |
||
| 201 | |||
| 202 | if (mb_strlen($title) >= $helper->getConfig('longbl')) { |
||
| 203 | $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...'; |
||
| 204 | } |
||
| 205 | |||
| 206 | $rating = number_format((float)$downloads_arr_rating[$i]->getVar('rating'), 1); |
||
| 207 | |||
| 208 | $xoopsTpl->append( |
||
| 209 | 'bl_rating', |
||
| 210 | [ |
||
| 211 | 'id' => $downloads_arr_rating[$i]->getVar('lid'), |
||
| 212 | 'cid' => $downloads_arr_rating[$i]->getVar('cid'), |
||
| 213 | 'rating' => $rating, |
||
| 214 | 'title' => $title, |
||
| 215 | ] |
||
| 216 | ); |
||
| 217 | } |
||
| 218 | } |
||
| 219 | $bl_affichage = 1; |
||
| 220 | if (0 === $helper->getConfig('bldate') && 0 === $helper->getConfig('blpop') && 0 === $helper->getConfig('blrating')) { |
||
| 221 | $bl_affichage = 0; |
||
| 222 | } |
||
| 223 | $xoopsTpl->assign('bl_affichage', $bl_affichage); |
||
| 224 | $xoopsTpl->assign('show_latest_files', $helper->getConfig('show_latest_files')); |
||
| 225 | |||
| 226 | //---------------------------------------------------------------------------------------------------------------------------------------------------- |
||
| 227 | |||
| 228 | // affichage des téléchargements |
||
| 229 | if ($helper->getConfig('newdownloads') > 0) { |
||
| 230 | $xoopsTpl->assign('nb_dowcol', $helper->getConfig('nb_dowcol')); |
||
| 231 | |||
| 232 | //Utilisation d'une copie d'écran avec la largeur selon les préférences |
||
| 233 | |||
| 234 | if (1 == $helper->getConfig('useshots')) { |
||
| 235 | $xoopsTpl->assign('shotwidth', $helper->getConfig('shotwidth')); |
||
| 236 | |||
| 237 | $xoopsTpl->assign('show_screenshot', true); |
||
| 238 | |||
| 239 | $xoopsTpl->assign('img_float', $helper->getConfig('img_float')); |
||
| 240 | } |
||
| 241 | |||
| 242 | $criteria = new \CriteriaCompo(); |
||
| 243 | |||
| 244 | $criteria->add(new \Criteria('status', 0, '!=')); |
||
| 245 | |||
| 246 | $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); |
||
| 247 | |||
| 248 | $criteria->setLimit($helper->getConfig('newdownloads')); |
||
| 249 | |||
| 250 | $tblsort = []; |
||
| 251 | |||
| 252 | $tblsort[1] = 'date'; |
||
| 253 | |||
| 254 | $tblsort[2] = 'date'; |
||
| 255 | |||
| 256 | $tblsort[3] = 'hits'; |
||
| 257 | |||
| 258 | $tblsort[4] = 'hits'; |
||
| 259 | |||
| 260 | $tblsort[5] = 'rating'; |
||
| 261 | |||
| 262 | $tblsort[6] = 'rating'; |
||
| 263 | |||
| 264 | $tblsort[7] = 'title'; |
||
| 265 | |||
| 266 | $tblsort[8] = 'title'; |
||
| 267 | |||
| 268 | $tblorder = []; |
||
| 269 | |||
| 270 | $tblorder[1] = 'DESC'; |
||
| 271 | |||
| 272 | $tblorder[2] = 'ASC'; |
||
| 273 | |||
| 274 | $tblorder[3] = 'DESC'; |
||
| 275 | |||
| 276 | $tblorder[4] = 'ASC'; |
||
| 277 | |||
| 278 | $tblorder[5] = 'DESC'; |
||
| 279 | |||
| 280 | $tblorder[6] = 'ASC'; |
||
| 281 | |||
| 282 | $tblorder[7] = 'DESC'; |
||
| 283 | |||
| 284 | $tblorder[8] = 'ASC'; |
||
| 285 | |||
| 286 | $sort = $helper->getConfig('toporder') ?? 1; |
||
| 287 | |||
| 288 | $order = $helper->getConfig('toporder') ?? 1; |
||
| 289 | |||
| 290 | $criteria->setSort($tblsort[$sort]); |
||
| 291 | |||
| 292 | $criteria->setOrder($tblorder[$order]); |
||
| 293 | |||
| 294 | $downloadsArray = $downloadsHandler->getAll($criteria); |
||
| 295 | |||
| 296 | $categories = $utility->getItemIds('tdmdownloads_download', $moduleDirName); |
||
| 297 | |||
| 298 | $item = $utility->getItemIds('tdmdownloads_download_item', $moduleDirName); |
||
| 299 | |||
| 300 | $count = 1; |
||
| 301 | |||
| 302 | foreach (array_keys($downloadsArray) as $i) { |
||
| 303 | /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ |
||
| 304 | |||
| 305 | if ('blank.gif' === $downloadsArray[$i]->getVar('logourl')) { |
||
| 306 | $logourl = ''; |
||
| 307 | } else { |
||
| 308 | $logourl = $downloadsArray[$i]->getVar('logourl'); |
||
| 309 | |||
| 310 | $logourl = $uploadurl_shots . $logourl; |
||
| 311 | } |
||
| 312 | |||
| 313 | $datetime = formatTimestamp($downloadsArray[$i]->getVar('date'), 's'); |
||
| 314 | |||
| 315 | $submitter = \XoopsUser::getUnameFromId($downloadsArray[$i]->getVar('submitter')); |
||
| 316 | |||
| 317 | $description = $downloadsArray[$i]->getVar('description'); |
||
| 318 | |||
| 319 | //permet d'afficher uniquement la description courte |
||
| 320 | |||
| 321 | if (false === mb_strpos($description, '[pagebreak]')) { |
||
| 322 | $descriptionShort = $description; |
||
| 323 | } else { |
||
| 324 | $descriptionShort = mb_substr($description, 0, mb_strpos($description, '[pagebreak]')); |
||
| 325 | } |
||
| 326 | |||
| 327 | // pour les vignettes "new" et "mis à jour" |
||
| 328 | |||
| 329 | $new = $utility->getStatusImage($downloadsArray[$i]->getVar('date'), $downloadsArray[$i]->getVar('status')); |
||
| 330 | |||
| 331 | $pop = $utility->getPopularImage($downloadsArray[$i]->getVar('hits')); |
||
| 332 | |||
| 333 | // Défini si la personne est un admin |
||
| 334 | |||
| 335 | $adminlink = ''; |
||
| 336 | |||
| 337 | if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) { |
||
| 338 | $adminlink = '<a href="' |
||
| 339 | . XOOPS_URL |
||
| 340 | . '/modules/' |
||
| 341 | . $moduleDirName |
||
| 342 | . '/admin/downloads.php?op=view_downloads&downloads_lid=' |
||
| 343 | . $downloadsArray[$i]->getVar('lid') |
||
| 344 | . '" title="' |
||
| 345 | . _MD_TDMDOWNLOADS_EDITTHISDL |
||
| 346 | . '"><img src="' |
||
| 347 | . XOOPS_URL |
||
| 348 | . '/modules/' |
||
| 349 | . $moduleDirName |
||
| 350 | . '/assets/images/icons/16/edit.png" width="16px" height="16px" border="0" alt="' |
||
| 351 | . _MD_TDMDOWNLOADS_EDITTHISDL |
||
| 352 | . '"></a>'; |
||
| 353 | } |
||
| 354 | |||
| 355 | //permission de télécharger |
||
| 356 | |||
| 357 | $downloadPermission = true; |
||
| 358 | |||
| 359 | if (1 === $helper->getConfig('permission_download')) { |
||
| 360 | if (!in_array($downloadsArray[$i]->getVar('cid'), $categories)) { |
||
| 361 | $downloadPermission = false; |
||
| 362 | } |
||
| 363 | } else { |
||
| 364 | if (!in_array($downloadsArray[$i]->getVar('lid'), $item)) { |
||
| 365 | $downloadPermission = false; |
||
| 366 | } |
||
| 367 | } |
||
| 368 | |||
| 369 | $xoopsTpl->append( |
||
| 370 | 'file', |
||
| 371 | [ |
||
| 372 | 'id' => $downloadsArray[$i]->getVar('lid'), |
||
| 373 | 'cid' => $downloadsArray[$i]->getVar('cid'), |
||
| 374 | 'title' => $downloadsArray[$i]->getVar('title'), |
||
| 375 | 'rating' => $downloadsArray[$i]->getVar('rating'), |
||
| 376 | 'hits' => $downloadsArray[$i]->getVar('hits'), |
||
| 377 | 'new' => $new, |
||
| 378 | 'pop' => $pop, |
||
| 379 | 'logourl' => $logourl, |
||
| 380 | 'updated' => $datetime, |
||
| 381 | 'description_short' => $descriptionShort, |
||
| 382 | 'adminlink' => $adminlink, |
||
| 383 | 'submitter' => $submitter, |
||
| 384 | 'perm_download' => $downloadPermission, |
||
| 385 | 'count' => $count, |
||
| 386 | ] |
||
| 387 | ); |
||
| 388 | |||
| 389 | //pour les mots clef |
||
| 390 | |||
| 391 | $keywords .= $downloadsArray[$i]->getVar('title') . ','; |
||
| 392 | |||
| 393 | ++$count; |
||
| 394 | } |
||
| 395 | } |
||
| 396 | // référencement |
||
| 397 | //description |
||
| 398 | $xoTheme->addMeta('meta', 'description', strip_tags($xoopsModule->name())); |
||
| 399 | //keywords |
||
| 400 | $keywords = mb_substr($keywords, 0, -1); |
||
| 401 | $xoTheme->addMeta('meta', 'keywords', $keywords); |
||
| 402 | |||
| 403 | require XOOPS_ROOT_PATH . '/footer.php'; |
||
| 404 |