XoopsModules25x /
wfdownloads
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||
| 2 | /* |
||
| 3 | You may not change or alter any portion of this comment or credits |
||
| 4 | of supporting developers from this source code or any supporting source code |
||
| 5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 6 | |||
| 7 | This program is distributed in the hope that it will be useful, |
||
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Wfdownloads module |
||
| 14 | * |
||
| 15 | * @copyright XOOPS Project (https://xoops.org) |
||
| 16 | * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
| 17 | * @package wfdownload |
||
| 18 | * @since 3.23 |
||
| 19 | * @author Xoops Development Team |
||
| 20 | */ |
||
| 21 | |||
| 22 | use Xmf\Request; |
||
| 23 | use XoopsModules\Wfdownloads\{ |
||
| 24 | Common, |
||
| 25 | Common\LetterChoice, |
||
| 26 | Helper, |
||
| 27 | Utility, |
||
| 28 | DownloadHandler, |
||
| 29 | ObjectTree |
||
| 30 | }; |
||
| 31 | |||
| 32 | /** @var Helper $helper */ |
||
| 33 | /** @var Utility $utility */ |
||
| 34 | |||
| 35 | $currentFile = basename(__FILE__); |
||
| 36 | require_once __DIR__ . '/header.php'; |
||
| 37 | |||
| 38 | $GLOBALS['xoopsOption']['template_main'] = "{$helper->getModule()->dirname()}_topten.tpl"; |
||
| 39 | |||
| 40 | // Check permissions |
||
| 41 | if ('rate' === Request::getString('list', '', 'GET') |
||
| 42 | && false === $helper->getConfig('enable_ratings') && !Utility::userIsAdmin()) { |
||
| 43 | redirect_header('index.php', 3, _NOPERM); |
||
| 44 | } |
||
| 45 | $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS]; |
||
| 46 | |||
| 47 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 48 | |||
| 49 | $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js'); |
||
| 50 | $xoTheme->addScript(WFDOWNLOADS_URL . '/assets/js/magnific/jquery.magnific-popup.min.js'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 51 | $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/js/magnific/magnific-popup.css'); |
||
| 52 | $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/css/module.css'); |
||
| 53 | |||
| 54 | $xoopsTpl->assign('wfdownloads_url', WFDOWNLOADS_URL . '/'); |
||
| 55 | |||
| 56 | $action_array = ['hit' => 0, 'rate' => 1]; |
||
| 57 | $list_array = ['hits', 'rating']; |
||
| 58 | $lang_array = [_MD_WFDOWNLOADS_HITS, _MD_WFDOWNLOADS_RATING]; |
||
| 59 | |||
| 60 | $sort = (isset($_GET['list']) && in_array($_GET['list'], $action_array)) ? $_GET['list'] : 'hit'; |
||
| 61 | $thisselected = $action_array[$sort]; |
||
| 62 | $sortDB = $list_array[$thisselected]; |
||
| 63 | |||
| 64 | $catarray['imageheader'] = Utility::headerImage(); |
||
| 65 | //$catarray['letters'] = Utility::lettersChoice(); |
||
| 66 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 67 | $objHandler = new DownloadHandler($db); |
||
| 68 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 69 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 70 | $choicebyletter = new LetterChoice($objHandler, null, null, range('a', 'z'), 'letter'); |
||
| 71 | $catarray['letters'] = $choicebyletter->render(); |
||
| 72 | |||
| 73 | $catarray['toolbar'] = Utility::toolbar(); |
||
| 74 | |||
| 75 | $xoopsTpl->assign('catarray', $catarray); |
||
| 76 | |||
| 77 | $arr = []; |
||
| 78 | |||
| 79 | $categoryObjs = $helper->getHandler('Category')->getObjects(); |
||
| 80 | |||
| 81 | $categoryObjsTree = new ObjectTree($categoryObjs, 'cid', 'pid'); |
||
| 82 | $mainCategoryObjs = $categoryObjsTree->getFirstChild(0); |
||
| 83 | $allowedCategoriesIds = $grouppermHandler->getItemIds('WFDownCatPerm', $groups, $helper->getModule()->mid()); |
||
| 84 | |||
| 85 | $e = 0; |
||
| 86 | $rankings = []; |
||
| 87 | foreach ($mainCategoryObjs as $mainCategoryObj) { |
||
| 88 | $cid = (int)$mainCategoryObj->getVar('cid'); |
||
| 89 | if (in_array($cid, $allowedCategoriesIds)) { |
||
| 90 | $allSubCategoryObjs = $categoryObjsTree->getAllChild($cid); |
||
| 91 | $cids = []; //initialise array |
||
| 92 | if (count($allSubCategoryObjs) > 0) { |
||
| 93 | foreach ($allSubCategoryObjs as $allSubCategoryObj) { |
||
| 94 | $cids[] = $allSubCategoryObj->getVar('cid'); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | $cids[] = $cid; |
||
| 98 | |||
| 99 | $criteria = new CriteriaCompo(new Criteria('cid', '(' . implode(',', $cids) . ')', 'IN')); |
||
| 100 | $criteria->setSort($sortDB); |
||
| 101 | $criteria->setOrder('DESC'); |
||
| 102 | $criteria->setLimit(10); |
||
| 103 | $downloadObjs = $helper->getHandler('Download')->getActiveDownloads($criteria); |
||
| 104 | $filecount = count($downloadObjs); |
||
| 105 | |||
| 106 | if ($filecount > 0) { |
||
| 107 | $rankings[$e]['title'] = $mainCategoryObj->getVar('title'); |
||
| 108 | $rank = 1; |
||
| 109 | |||
| 110 | foreach (array_keys($downloadObjs) as $k) { |
||
| 111 | $parentCategory_titles = []; |
||
| 112 | $parentCategoryObjs = $categoryObjsTree->getAllParent($downloadObjs[$k]->getVar('cid')); |
||
| 113 | if (count($parentCategoryObjs) > 0) { |
||
| 114 | foreach ($parentCategoryObjs as $parentCategoryObj) { |
||
| 115 | $parentCategory_titles[] = $parentCategoryObj->getVar('title'); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | $thisCategoryObj = &$categoryObjsTree->getByKey($downloadObjs[$k]->getVar('cid')); |
||
| 119 | $parentCategory_titles[] = $thisCategoryObj->getVar('title'); |
||
| 120 | |||
| 121 | $rankings[$e]['file'][] = [ |
||
| 122 | 'id' => (int)$downloadObjs[$k]->getVar('lid'), |
||
| 123 | 'cid' => (int)$downloadObjs[$k]->getVar('cid'), |
||
| 124 | 'rank' => $rank, |
||
| 125 | 'title' => $downloadObjs[$k]->getVar('title'), |
||
| 126 | 'category' => implode('/', $parentCategory_titles), |
||
| 127 | 'hits' => $downloadObjs[$k]->getVar('hits'), |
||
| 128 | 'rating' => number_format($downloadObjs[$k]->getVar('rating'), 2), |
||
| 129 | 'votes' => $downloadObjs[$k]->getVar('votes'), |
||
| 130 | ]; |
||
| 131 | ++$rank; |
||
| 132 | } |
||
| 133 | ++$e; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | $xoopsTpl->assign('lang_sortby', $lang_array[$thisselected]); |
||
| 139 | $xoopsTpl->assign('rankings', $rankings); |
||
| 140 | |||
| 141 | // Breadcrumb |
||
| 142 | $breadcrumb = new Common\Breadcrumb(); |
||
| 143 | $breadcrumb->addLink($helper->getModule()->getVar('name'), WFDOWNLOADS_URL); |
||
| 144 | $breadcrumb->addLink($lang_array[$thisselected], ''); |
||
| 145 | $xoopsTpl->assign('wfdownloads_breadcrumb', $breadcrumb->render()); |
||
| 146 | |||
| 147 | if ('rate' === Request::getString('list', '', 'GET')) { |
||
| 148 | $xoopsTpl->assign('categoryPath', _MD_WFDOWNLOADS_DOWNLOAD_MOST_RATED); |
||
| 149 | } else { |
||
| 150 | $xoopsTpl->assign('categoryPath', _MD_WFDOWNLOADS_DOWNLOAD_MOST_POPULAR); |
||
| 151 | } |
||
| 152 | |||
| 153 | $xoopsTpl->assign('module_home', Utility::moduleHome(true)); |
||
| 154 | |||
| 155 | require_once __DIR__ . '/footer.php'; |
||
| 156 |