XoopsModules25x /
xoopstube
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Module: XoopsTube |
||
| 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 | * |
||
| 10 | * PHP version 5 |
||
| 11 | * |
||
| 12 | * @category Module |
||
| 13 | * @package Xoopstube |
||
| 14 | * @author XOOPS Development Team |
||
| 15 | * @copyright 2001-2016 XOOPS Project (https://xoops.org) |
||
| 16 | * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
| 17 | * @link https://xoops.org/ |
||
| 18 | * @since 1.0.6 |
||
| 19 | */ |
||
| 20 | |||
| 21 | use Xmf\Request; |
||
| 22 | use XoopsModules\Xoopstube\{Utility |
||
| 23 | }; |
||
| 24 | $GLOBALS['xoopsOption']['template_main'] = 'xoopstube_ratevideo.tpl'; |
||
| 25 | require_once __DIR__ . '/header.php'; |
||
| 26 | |||
| 27 | global $myts, $xoTheme; |
||
| 28 | |||
| 29 | // Check if videoload POSTER is voting (UNLESS Anonymous users allowed to post) |
||
| 30 | $lid = Request::getInt('lid', Request::getInt('lid', '', 'POST'), 'GET'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 31 | |||
| 32 | $ip = getenv('REMOTE_ADDR'); |
||
| 33 | $ratinguser = (!is_object($GLOBALS['xoopsUser'])) ? 0 : $GLOBALS['xoopsUser']->getVar('uid'); |
||
| 34 | |||
| 35 | if (0 == $GLOBALS['xoopsModuleConfig']['showrating'] || '' == $lid) { |
||
| 36 | $ratemessage = _MD_XOOPSTUBE_CANTVOTEOWN; |
||
| 37 | redirect_header('index.php', 4, $ratemessage); |
||
| 38 | } |
||
| 39 | |||
| 40 | if (0 !== $ratinguser) { |
||
| 41 | $sql = 'SELECT cid, submitter FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' WHERE lid=' . $lid; |
||
| 42 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 43 | while (list($cid, $ratinguserDB) = $GLOBALS['xoopsDB']->fetchRow($result)) { |
||
| 44 | if ($ratinguserDB === $ratinguser) { |
||
| 45 | $ratemessage = _MD_XOOPSTUBE_CANTVOTEOWN; |
||
| 46 | redirect_header('singlevideo.php?cid=' . (int)$cid . '&lid=' . $lid, 4, $ratemessage); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | // Check if REG user is trying to vote twice. |
||
| 50 | $sql = 'SELECT cid, ratinguser FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_votedata') . ' WHERE lid=' . $lid; |
||
| 51 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 52 | if ($result) { |
||
| 53 | while (list($cid, $ratinguserDB) = $GLOBALS['xoopsDB']->fetchRow($result)) { |
||
| 54 | if ($ratinguserDB === $ratinguser) { |
||
| 55 | $ratemessage = _MD_XOOPSTUBE_VOTEONCE; |
||
| 56 | redirect_header('singlevideo.php?cid=' . (int)$cid . '&lid=' . $lid, 4, $ratemessage); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | } else { |
||
| 62 | // Check if ANONYMOUS user is trying to vote more than once per day. |
||
| 63 | $yesterday = (time() - (86400 * $anonwaitdays)); |
||
| 64 | $sql = 'SELECT COUNT(*) FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_votedata') . ' WHERE lid=' . $lid . ' AND ratinguser=0 AND ratinghostname=' . $ip . ' AND ratingtimestamp > ' . $yesterday; |
||
| 65 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 66 | [$anonvotecount] = $GLOBALS['xoopsDB']->fetchRow($result); |
||
| 67 | if ($anonvotecount >= 1) { |
||
| 68 | $ratemessage = _MD_XOOPSTUBE_VOTEONCE; |
||
| 69 | redirect_header('singlevideo.php?cid=' . (int)$cid . '&lid=' . $lid, 4, $ratemessage); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | if (!empty(Request::getString('submit', ''))) { |
||
| 74 | $ratinguser = (!is_object($GLOBALS['xoopsUser'])) ? 0 : $GLOBALS['xoopsUser']->getVar('uid'); |
||
| 75 | // Make sure only 1 anonymous from an IP in a single day. |
||
| 76 | $anonwaitdays = 1; |
||
| 77 | $ip = getenv('REMOTE_ADDR'); |
||
| 78 | $lid = Request::getInt('lid', 0, 'POST'); |
||
| 79 | $cid = Request::getInt('cid', 0, 'POST'); |
||
| 80 | $rating = Request::getInt('rating', 0, 'POST'); |
||
| 81 | // $title = $myts->addslashes(trim(Request::getString('title', '', 'POST'))); |
||
| 82 | $title = Request::getString('title', '', 'POST'); |
||
| 83 | // Check if Rating is Null |
||
| 84 | if (0 == $rating) { |
||
| 85 | $ratemessage = _MD_XOOPSTUBE_NORATING; |
||
| 86 | redirect_header('ratevideo.php?cid=' . $cid . '&lid=' . $lid, 4, $ratemessage); |
||
| 87 | } |
||
| 88 | // All is well. Add to Line Item Rate to DB. |
||
| 89 | $newid = $GLOBALS['xoopsDB']->genId($GLOBALS['xoopsDB']->prefix('xoopstube_votedata') . '_ratingid_seq'); |
||
| 90 | $datetime = time(); |
||
| 91 | $sql = sprintf( |
||
| 92 | 'INSERT INTO `%s` (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp, title) VALUES (%u, %u, %u, %u, %s, %u, %s)', |
||
| 93 | $GLOBALS['xoopsDB']->prefix('xoopstube_votedata'), |
||
| 94 | $newid, |
||
| 95 | $lid, |
||
| 96 | $ratinguser, |
||
| 97 | $rating, |
||
| 98 | $GLOBALS['xoopsDB']->quoteString($ip), |
||
| 99 | $datetime, |
||
| 100 | $GLOBALS['xoopsDB']->quoteString($title) |
||
| 101 | ); |
||
| 102 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
| 103 | $ratemessage = _MD_XOOPSTUBE_ERROR; |
||
| 104 | } else { |
||
| 105 | // All is well. Calculate Score & Add to Summary (for quick retrieval & sorting) to DB. |
||
| 106 | Utility::updateRating($lid); |
||
| 107 | $ratemessage = _MD_XOOPSTUBE_VOTEAPPRE . '<br>' . sprintf(_MD_XOOPSTUBE_THANKYOU, $GLOBALS['xoopsConfig']['sitename']); |
||
| 108 | } |
||
| 109 | redirect_header('singlevideo.php?cid=' . $cid . '&lid=' . $lid, 4, $ratemessage); |
||
| 110 | } else { |
||
| 111 | //TODO add |
||
| 112 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 113 | |||
| 114 | $catarray['imageheader'] = Utility::renderImageHeader(); |
||
| 115 | $cid = Request::getInt('cid', Request::getInt('cid', '', 'POST'), 'GET'); |
||
| 116 | |||
| 117 | $catarray['imageheader'] = Utility::renderImageHeader(); |
||
| 118 | $xoopsTpl->assign('catarray', $catarray); |
||
| 119 | $xoopsTpl->assign('mod_url', XOOPS_URL . '/modules/' . $moduleDirName); |
||
| 120 | |||
| 121 | $result = $GLOBALS['xoopsDB']->query('SELECT title FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' WHERE lid=' . $lid); |
||
| 122 | [$title] = $GLOBALS['xoopsDB']->fetchRow($result); |
||
| 123 | $xoopsTpl->assign( |
||
| 124 | 'video', |
||
| 125 | [ |
||
| 126 | 'id' => $lid, |
||
| 127 | 'cid' => $cid, |
||
| 128 | 'title' => htmlspecialchars($title), |
||
| 129 | ] |
||
| 130 | ); |
||
| 131 | |||
| 132 | Utility::setNoIndexNoFollow(); |
||
| 133 | |||
| 134 | $xoopsTpl->assign('module_dir', $xoopsModule->getVar('dirname')); |
||
| 135 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
| 136 | } |
||
| 137 | |||
| 138 | Utility::setNoIndexNoFollow(); |
||
| 139 | |||
| 140 | $xoopsTpl->assign('module_dir', $xoopsModule->getVar('dirname')); |
||
| 141 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
| 142 |