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 | Helper, |
||
| 26 | Utility, |
||
| 27 | ObjectTree |
||
| 28 | }; |
||
| 29 | /** @var Helper $helper */ |
||
| 30 | /** @var Utility $utility */ |
||
| 31 | |||
| 32 | $currentFile = basename(__FILE__); |
||
| 33 | require_once __DIR__ . '/header.php'; |
||
| 34 | |||
| 35 | $lid = Request::getInt('lid', 0); |
||
| 36 | $downloadObj = $helper->getHandler('Download')->get($lid); |
||
| 37 | if (null === $downloadObj) { |
||
| 38 | redirect_header('index.php', 3, _CO_WFDOWNLOADS_ERROR_NODOWNLOAD); |
||
| 39 | } |
||
| 40 | $cid = Request::getInt('cid', $downloadObj->getVar('cid')); |
||
| 41 | $categoryObj = $helper->getHandler('Category')->get($cid); |
||
| 42 | if (null === $categoryObj) { |
||
| 43 | redirect_header('index.php', 3, _CO_WFDOWNLOADS_ERROR_NOCATEGORY); |
||
| 44 | } |
||
| 45 | |||
| 46 | // Download not published, expired or taken offline - redirect |
||
| 47 | if (false === $downloadObj->getVar('published') || $downloadObj->getVar('published') > time() |
||
| 48 | || true === $downloadObj->getVar('offline') |
||
| 49 | || (0 != $downloadObj->getVar('expired') |
||
| 50 | && $downloadObj->getVar('expired') < time())) { |
||
| 51 | redirect_header('index.php', 3, _MD_WFDOWNLOADS_NODOWNLOAD); |
||
| 52 | } |
||
| 53 | |||
| 54 | // Check permissions |
||
| 55 | if (false === $helper->getConfig('enable_ratings') && !Utility::userIsAdmin()) { |
||
| 56 | redirect_header('index.php', 3, _NOPERM); |
||
| 57 | } |
||
| 58 | // Breadcrumb |
||
| 59 | require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
||
| 60 | $categoryObjsTree = new ObjectTree($helper->getHandler('Category')->getObjects(), 'cid', 'pid'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 61 | $breadcrumb = new Common\Breadcrumb(); |
||
| 62 | $breadcrumb->addLink($helper->getModule()->getVar('name'), WFDOWNLOADS_URL); |
||
|
0 ignored issues
–
show
|
|||
| 63 | foreach (array_reverse($categoryObjsTree->getAllParent($cid)) as $parentCategory) { |
||
| 64 | $breadcrumb->addLink($parentCategory->getVar('title'), 'viewcat.php?cid=' . $parentCategory->getVar('cid')); |
||
| 65 | } |
||
| 66 | $breadcrumb->addLink($categoryObj->getVar('title'), "viewcat.php?cid={$cid}"); |
||
| 67 | $breadcrumb->addLink($downloadObj->getVar('title'), "singlefile.php?lid={$lid}"); |
||
| 68 | |||
| 69 | $op = Request::getString('op', 'vote.add'); |
||
| 70 | switch ($op) { |
||
| 71 | case 'vote.add': |
||
| 72 | default: |
||
| 73 | // Get vote poster 'uid' |
||
| 74 | $ratinguserUid = is_object($GLOBALS['xoopsUser']) ? (int)$GLOBALS['xoopsUser']->getVar('uid') : 0; |
||
| 75 | $ratinguserIp = getenv('REMOTE_ADDR'); |
||
| 76 | |||
| 77 | if (Request::hasVar('submit', 'POST')) { |
||
| 78 | $rating = Request::getString('rating', '--', 'POST'); |
||
| 79 | |||
| 80 | // Check if Rating is Null |
||
| 81 | if ('--' === $rating) { |
||
| 82 | redirect_header("?cid={$cid}&lid={$lid}", 4, _MD_WFDOWNLOADS_NORATING); |
||
| 83 | } |
||
| 84 | if (0 != $ratinguserUid) { |
||
| 85 | // Check if Download POSTER is voting (UNLESS Anonymous users allowed to post) |
||
| 86 | if ($downloadObj->getVar('submitter') == $ratinguserUid) { |
||
| 87 | redirect_header(WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&lid={$lid}", 4, _MD_WFDOWNLOADS_CANTVOTEOWN); |
||
| 88 | } |
||
| 89 | // Check if REG user is trying to vote twice. |
||
| 90 | $criteria = new CriteriaCompo(new Criteria('lid', $lid)); |
||
| 91 | $criteria->add(new Criteria('ratinguser', $ratinguserUid)); |
||
| 92 | $ratingsCount = $helper->getHandler('Rating')->getCount($criteria); |
||
| 93 | if ($ratingsCount > 0) { |
||
| 94 | redirect_header("singlefile.php?cid={$cid}&lid={$lid}", 4, _MD_WFDOWNLOADS_VOTEONCE); |
||
| 95 | } |
||
| 96 | } else { |
||
| 97 | // Check if ANONYMOUS user is trying to vote more than once per day (only 1 anonymous from an IP in a single day). |
||
| 98 | $anonymousWaitDays = 1; |
||
| 99 | $yesterday = (time() - (86400 * $anonymousWaitDays)); |
||
| 100 | $criteria = new CriteriaCompo(new Criteria('lid', $lid)); |
||
| 101 | $criteria->add(new Criteria('ratinguser', 0)); |
||
| 102 | $criteria->add(new Criteria('ratinghostname', $ratinguserIp)); |
||
| 103 | $criteria->add(new Criteria('ratingtimestamp', $yesterday, '>')); |
||
| 104 | $anonymousVotesCount = $helper->getHandler('Rating')->getCount($criteria); |
||
| 105 | if ($anonymousVotesCount > 0) { |
||
| 106 | redirect_header("singlefile.php?cid={$cid}&lid={$lid}", 4, _MD_WFDOWNLOADS_VOTEONCE); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | // All is well. Add to Line Item Rate to DB. |
||
| 110 | $ratingObj = $helper->getHandler('Rating')->create(); |
||
| 111 | $ratingObj->setVar('lid', $lid); |
||
| 112 | $ratingObj->setVar('ratinguser', $ratinguserUid); |
||
| 113 | $ratingObj->setVar('rating', (int)$rating); |
||
| 114 | $ratingObj->setVar('ratinghostname', $ratinguserIp); |
||
| 115 | $ratingObj->setVar('ratingtimestamp', time()); |
||
| 116 | if ($helper->getHandler('Rating')->insert($ratingObj)) { |
||
| 117 | // All is well. Calculate Score & Add to Summary (for quick retrieval & sorting) to DB. |
||
| 118 | Utility::updateRating($lid); |
||
| 119 | $thankyouMessage = _MD_WFDOWNLOADS_VOTEAPPRE . '<br>' . sprintf(_MD_WFDOWNLOADS_THANKYOU, $GLOBALS['xoopsConfig']['sitename']); |
||
| 120 | redirect_header("singlefile.php?cid={$cid}&lid={$lid}", 4, $thankyouMessage); |
||
| 121 | } else { |
||
| 122 | echo $ratingObj->getHtmlErrors(); |
||
| 123 | } |
||
| 124 | } else { |
||
| 125 | $GLOBALS['xoopsOption']['template_main'] = "{$helper->getModule()->dirname()}_ratefile.tpl"; |
||
| 126 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 127 | |||
| 128 | $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js'); |
||
| 129 | $xoTheme->addScript(WFDOWNLOADS_URL . '/assets/js/magnific/jquery.magnific-popup.min.js'); |
||
| 130 | $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/js/magnific/magnific-popup.css'); |
||
| 131 | $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/css/module.css'); |
||
| 132 | |||
| 133 | $xoopsTpl->assign('wfdownloads_url', WFDOWNLOADS_URL . '/'); |
||
| 134 | |||
| 135 | // Breadcrumb |
||
| 136 | $breadcrumb->addLink(_MD_WFDOWNLOADS_RATETHISFILE, ''); |
||
| 137 | $xoopsTpl->assign('wfdownloads_breadcrumb', $breadcrumb->render()); |
||
| 138 | |||
| 139 | // Generate form |
||
| 140 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 141 | $sform = new XoopsThemeForm(_MD_WFDOWNLOADS_RATETHISFILE, 'voteform', xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
| 142 | $rating_select = new XoopsFormSelect(_MD_WFDOWNLOADS_REV_RATING, 'rating', '10'); |
||
| 143 | //$rating_select->setDescription(_MD_WFDOWNLOADS_REV_RATING_DESC); |
||
| 144 | $rating_select->addOptionArray( |
||
| 145 | [ |
||
| 146 | '1' => 1, |
||
| 147 | '2' => 2, |
||
| 148 | '3' => 3, |
||
| 149 | '4' => 4, |
||
| 150 | '5' => 5, |
||
| 151 | '6' => 6, |
||
| 152 | '7' => 7, |
||
| 153 | '8' => 8, |
||
| 154 | '9' => 9, |
||
| 155 | '10' => 10, |
||
| 156 | ] |
||
| 157 | ); |
||
| 158 | $sform->addElement($rating_select); |
||
| 159 | $sform->addElement(new XoopsFormHidden('lid', $lid)); |
||
| 160 | $sform->addElement(new XoopsFormHidden('cid', $cid)); |
||
| 161 | $sform->addElement(new XoopsFormHidden('uid', $reviewerUid)); |
||
| 162 | $buttonTray = new XoopsFormElementTray('', ''); |
||
| 163 | $submitButton = new XoopsFormButton('', 'submit', _MD_WFDOWNLOADS_RATEIT, 'submit'); |
||
| 164 | $buttonTray->addElement($submitButton); |
||
| 165 | $cancelButton = new XoopsFormButton('', '', _CANCEL, 'button'); |
||
| 166 | $cancelButton->setExtra('onclick="history.go(-1)"'); |
||
| 167 | $buttonTray->addElement($cancelButton); |
||
| 168 | $sform->addElement($buttonTray); |
||
| 169 | $xoopsTpl->assign('voteform', $sform->render()); |
||
| 170 | $xoopsTpl->assign( |
||
| 171 | 'download', |
||
| 172 | [ |
||
| 173 | 'lid' => $lid, |
||
| 174 | 'cid' => $cid, |
||
| 175 | 'title' => $downloadObj->getVar('title'), |
||
| 176 | 'description' => $downloadObj->getVar('description'), |
||
| 177 | ] |
||
| 178 | ); |
||
| 179 | |||
| 180 | $xoopsTpl->assign( |
||
| 181 | 'file', |
||
| 182 | [ |
||
| 183 | 'id' => $lid, |
||
| 184 | 'lid' => $lid, |
||
| 185 | 'cid' => $cid, |
||
| 186 | 'title' => $downloadObj->getVar('title'), |
||
| 187 | 'imageheader' => Utility::headerImage(), |
||
| 188 | ] |
||
| 189 | ); // this definition is not removed for backward compatibility issues |
||
| 190 | require_once __DIR__ . '/footer.php'; |
||
| 191 | } |
||
| 192 | break; |
||
| 193 | } |
||
| 194 |