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 (0 == $downloadObj->getVar('published') || $downloadObj->getVar('published') > time() |
||
| 48 | || 1 === $downloadObj->getVar('offline') |
||
| 49 | || (1 === $downloadObj->getVar('expired') |
||
| 50 | && $downloadObj->getVar('expired') < time()) |
||
| 51 | || _WFDOWNLOADS_STATUS_WAITING == $downloadObj->getVar('status')) { |
||
| 52 | redirect_header('index.php', 3, _MD_WFDOWNLOADS_NODOWNLOAD); |
||
| 53 | } |
||
| 54 | |||
| 55 | // Check permissions |
||
| 56 | if (false === $helper->getConfig('enable_brokenreports') && !Utility::userIsAdmin()) { |
||
| 57 | redirect_header('index.php', 3, _NOPERM); |
||
| 58 | } |
||
| 59 | |||
| 60 | // Breadcrumb |
||
| 61 | //require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
||
| 62 | $categoryObjArray = $helper->getHandler('Category')->getObjects(); |
||
| 63 | $categoryObjsTree = new ObjectTree($categoryObjArray, 'cid', 'pid'); |
||
| 64 | $breadcrumb = new Common\Breadcrumb(); |
||
| 65 | $breadcrumb->addLink($helper->getModule()->getVar('name'), WFDOWNLOADS_URL); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 66 | foreach (array_reverse($categoryObjsTree->getAllParent($cid)) as $parentCategory) { |
||
| 67 | $breadcrumb->addLink($parentCategory->getVar('title'), 'viewcat.php?cid=' . $parentCategory->getVar('cid')); |
||
| 68 | } |
||
| 69 | $breadcrumb->addLink($categoryObj->getVar('title'), "viewcat.php?cid={$cid}"); |
||
| 70 | $breadcrumb->addLink($downloadObj->getVar('title'), "singlefile.php?lid={$lid}"); |
||
| 71 | |||
| 72 | $op = Request::getString('op', 'report.add'); |
||
| 73 | switch ($op) { |
||
| 74 | case 'report.add': |
||
| 75 | default: |
||
| 76 | // Get report sender 'uid' |
||
| 77 | $senderUid = is_object($GLOBALS['xoopsUser']) ? (int)$GLOBALS['xoopsUser']->getVar('uid') : 0; |
||
| 78 | $senderIp = getenv('REMOTE_ADDR'); |
||
| 79 | |||
| 80 | if (Request::hasVar('submit', 'POST')) { |
||
| 81 | // Check if REG user is trying to report twice |
||
| 82 | $criteria = new Criteria('lid', $lid); |
||
| 83 | $reportCount = $helper->getHandler('Report')->getCount($criteria); |
||
| 84 | if ($reportCount > 0) { |
||
| 85 | redirect_header('index.php', 2, _MD_WFDOWNLOADS_ALREADYREPORTED); |
||
| 86 | } else { |
||
| 87 | $reportObj = $helper->getHandler('Report')->create(); |
||
| 88 | $reportObj->setVar('lid', $lid); |
||
| 89 | $reportObj->setVar('sender', $senderUid); |
||
| 90 | $reportObj->setVar('ip', $senderIp); |
||
| 91 | $reportObj->setVar('date', time()); |
||
| 92 | $reportObj->setVar('confirmed', 0); |
||
| 93 | $reportObj->setVar('acknowledged', 0); |
||
| 94 | if ($helper->getHandler('Report')->insert($reportObj)) { |
||
| 95 | // All is well |
||
| 96 | // Send notification |
||
| 97 | $tags = []; |
||
| 98 | $tags['BROKENREPORTS_URL'] = WFDOWNLOADS_URL . '/admin/reportsmodifications.php?op=reports.modifications.list'; |
||
| 99 | $notificationHandler->triggerEvent('global', 0, 'file_broken', $tags); |
||
| 100 | |||
| 101 | // Send email to the owner of the download stating that it is broken |
||
| 102 | $user = $memberHandler->getUser($downloadObj->getVar('submitter')); |
||
| 103 | $subdate = formatTimestamp($downloadObj->getVar('published'), $helper->getConfig('dateformat')); |
||
| 104 | $cid = $downloadObj->getVar('cid'); |
||
| 105 | $title = $downloadObj->getVar('title'); |
||
| 106 | $subject = _MD_WFDOWNLOADS_BROKENREPORTED; |
||
| 107 | |||
| 108 | $xoopsMailer = xoops_getMailer(); |
||
| 109 | $xoopsMailer->useMail(); |
||
| 110 | $template_dir = WFDOWNLOADS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/mail_template'; |
||
|
0 ignored issues
–
show
|
|||
| 111 | |||
| 112 | $xoopsMailer->setTemplateDir($template_dir); |
||
| 113 | $xoopsMailer->setTemplate('filebroken_notify.tpl'); |
||
| 114 | $xoopsMailer->setToEmails($user->email()); |
||
| 115 | $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']); |
||
| 116 | $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']); |
||
| 117 | $xoopsMailer->assign('X_UNAME', $user->uname()); |
||
| 118 | $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']); |
||
| 119 | $xoopsMailer->assign('X_ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']); |
||
| 120 | $xoopsMailer->assign('X_SITEURL', XOOPS_URL . '/'); |
||
| 121 | $xoopsMailer->assign('X_TITLE', $title); |
||
| 122 | $xoopsMailer->assign('X_SUB_DATE', $subdate); |
||
| 123 | $xoopsMailer->assign('X_DOWNLOAD', WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&lid={$lid}"); |
||
| 124 | $xoopsMailer->setSubject($subject); |
||
| 125 | $xoopsMailer->send(); |
||
| 126 | redirect_header('index.php', 2, _MD_WFDOWNLOADS_BROKENREPORTED); |
||
| 127 | } else { |
||
| 128 | echo $reportObj->getHtmlErrors(); |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } else { |
||
| 132 | $GLOBALS['xoopsOption']['template_main'] = "{$helper->getModule()->dirname()}_brokenfile.tpl"; |
||
| 133 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 134 | $catarray = []; |
||
| 135 | |||
| 136 | // Begin Main page Heading etc |
||
| 137 | $catarray['imageheader'] = Utility::headerImage(); |
||
| 138 | $xoopsTpl->assign('catarray', $catarray); |
||
| 139 | |||
| 140 | $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js'); |
||
| 141 | $xoTheme->addScript(WFDOWNLOADS_URL . '/assets/js/magnific/jquery.magnific-popup.min.js'); |
||
| 142 | $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/js/magnific/magnific-popup.css'); |
||
| 143 | $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/css/module.css'); |
||
| 144 | |||
| 145 | $xoopsTpl->assign('wfdownloads_url', WFDOWNLOADS_URL . '/'); |
||
| 146 | |||
| 147 | // Breadcrumb |
||
| 148 | $breadcrumb->addLink(_MD_WFDOWNLOADS_REPORTBROKEN, ''); |
||
| 149 | $xoopsTpl->assign('wfdownloads_breadcrumb', $breadcrumb->render()); |
||
| 150 | |||
| 151 | // Generate form |
||
| 152 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 153 | $sform = new XoopsThemeForm(_MD_WFDOWNLOADS_RATETHISFILE, 'reportform', xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
| 154 | $sform->addElement(new XoopsFormHidden('lid', $lid)); |
||
| 155 | $sform->addElement(new XoopsFormHidden('cid', $cid)); |
||
| 156 | $sform->addElement(new XoopsFormHidden('uid', $senderUid)); |
||
| 157 | $buttonTray = new XoopsFormElementTray('', ''); |
||
| 158 | $submitButton = new XoopsFormButton('', 'submit', _MD_WFDOWNLOADS_SUBMITBROKEN, 'submit'); |
||
| 159 | $buttonTray->addElement($submitButton); |
||
| 160 | $cancelButton = new XoopsFormButton('', '', _CANCEL, 'button'); |
||
| 161 | $cancelButton->setExtra('onclick="history.go(-1)"'); |
||
| 162 | $buttonTray->addElement($cancelButton); |
||
| 163 | $sform->addElement($buttonTray); |
||
| 164 | $xoopsTpl->assign('reportform', $sform->render()); |
||
| 165 | $xoopsTpl->assign( |
||
| 166 | 'download', |
||
| 167 | [ |
||
| 168 | 'lid' => $lid, |
||
| 169 | 'cid' => $cid, |
||
| 170 | 'title' => $downloadObj->getVar('title'), |
||
| 171 | 'description' => $downloadObj->getVar('description'), |
||
| 172 | ] |
||
| 173 | ); |
||
| 174 | |||
| 175 | $criteria = new Criteria('lid', $lid); |
||
| 176 | |||
| 177 | $reportObjs = $helper->getHandler('Report')->getObjects($criteria); |
||
| 178 | |||
| 179 | if (count($reportObjs) > 0) { |
||
| 180 | $reportObj = $reportObjs[0]; |
||
| 181 | |||
| 182 | $broken['title'] = trim($downloadObj->getVar('title')); |
||
| 183 | $broken['id'] = $reportObj->getVar('reportid'); |
||
| 184 | $broken['reporter'] = XoopsUserUtility::getUnameFromId((int)$reportObj->getVar('sender')); |
||
| 185 | $broken['date'] = formatTimestamp($reportObj->getVar('published'), $helper->getConfig('dateformat')); |
||
| 186 | $broken['acknowledged'] = (1 == $reportObj->getVar('acknowledged')) ? _YES : _NO; |
||
| 187 | $broken['confirmed'] = (1 == $reportObj->getVar('confirmed')) ? _YES : _NO; |
||
| 188 | |||
| 189 | $xoopsTpl->assign('brokenreportexists', true); |
||
| 190 | $xoopsTpl->assign('broken', $broken); |
||
| 191 | $xoopsTpl->assign('brokenreport', true); // this definition is not removed for backward compatibility issues |
||
| 192 | } else { |
||
| 193 | // file info |
||
| 194 | $down['title'] = trim($downloadObj->getVar('title')); |
||
| 195 | $temp = formatURL(trim($downloadObj->getVar('homepage'))); |
||
| 196 | $down['homepage'] = $myts->makeClickable($temp); |
||
| 197 | $time = (0 !== $downloadObj->getVar('updated')) ? $downloadObj->getVar('updated') : $downloadObj->getVar('published'); |
||
| 198 | $down['updated'] = formatTimestamp($time, $helper->getConfig('dateformat')); |
||
| 199 | $is_updated = (0 !== $downloadObj->getVar('updated')) ? _MD_WFDOWNLOADS_UPDATEDON : _MD_WFDOWNLOADS_SUBMITDATE; |
||
| 200 | $down['publisher'] = \XoopsUserUtility::getUnameFromId((int)$downloadObj->getVar('submitter')); |
||
| 201 | |||
| 202 | $xoopsTpl->assign('brokenreportexists', false); |
||
| 203 | $xoopsTpl->assign('file_id', $lid); |
||
| 204 | $xoopsTpl->assign('lang_subdate', $is_updated); |
||
| 205 | $xoopsTpl->assign('is_updated', $downloadObj->getVar('updated')); |
||
| 206 | $xoopsTpl->assign('lid', $lid); |
||
| 207 | $xoopsTpl->assign('down', $down); |
||
| 208 | } |
||
| 209 | require_once __DIR__ . '/footer.php'; |
||
| 210 | } |
||
| 211 | break; |
||
| 212 | } |
||
| 213 |