These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 (http://xoops.org) |
||
16 | * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
||
17 | * @link http://xoops.org/ |
||
18 | * @since 1.0.6 |
||
19 | */ |
||
20 | |||
21 | include __DIR__ . '/header.php'; |
||
22 | |||
23 | global $xtubemyts, $xoTheme; |
||
0 ignored issues
–
show
|
|||
24 | |||
25 | // Check if videoload POSTER is voting (UNLESS Anonymous users allowed to post) |
||
26 | $lid = XoopsRequest::getInt('lid', XoopsRequest::getInt('lid', '', 'POST'), 'GET'); |
||
27 | |||
28 | $ip = getenv('REMOTE_ADDR'); |
||
29 | $ratinguser = (!is_object($GLOBALS['xoopsUser'])) ? 0 : $GLOBALS['xoopsUser']->getVar('uid'); |
||
30 | |||
31 | if (0 == $GLOBALS['xoopsModuleConfig']['showrating'] || '' === $lid) { |
||
32 | $ratemessage = _MD_XOOPSTUBE_CANTVOTEOWN; |
||
33 | redirect_header('index.php', 4, $ratemessage); |
||
34 | } |
||
35 | |||
36 | if ($ratinguser !== 0) { |
||
37 | $result = $GLOBALS['xoopsDB']->query('SELECT cid, submitter FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' WHERE lid=' . (int)$lid); |
||
38 | View Code Duplication | while (false !== (list($cid, $ratinguserDB) = $GLOBALS['xoopsDB']->fetchRow($result))) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
39 | if ($ratinguserDB === $ratinguser) { |
||
40 | $ratemessage = _MD_XOOPSTUBE_CANTVOTEOWN; |
||
41 | redirect_header('singlevideo.php?cid=' . (int)$cid . '&lid=' . (int)$lid, 4, $ratemessage); |
||
42 | } |
||
43 | } |
||
44 | // Check if REG user is trying to vote twice. |
||
45 | $result = $GLOBALS['xoopsDB']->query('SELECT cid, ratinguser FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_votedata') . ' WHERE lid=' . (int)$lid); |
||
46 | View Code Duplication | while (false !== (list($cid, $ratinguserDB) = $GLOBALS['xoopsDB']->fetchRow($result))) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
47 | if ($ratinguserDB === $ratinguser) { |
||
48 | $ratemessage = _MD_XOOPSTUBE_VOTEONCE; |
||
49 | redirect_header('singlevideo.php?cid=' . (int)$cid . '&lid=' . (int)$lid, 4, $ratemessage); |
||
50 | } |
||
51 | } |
||
52 | } else { |
||
53 | // Check if ANONYMOUS user is trying to vote more than once per day. |
||
54 | $yesterday = (time() - (86400 * $anonwaitdays)); |
||
55 | $result = $GLOBALS['xoopsDB']->query('SELECT COUNT(*) FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_votedata') . ' WHERE lid=' . (int)$lid . ' AND ratinguser=0 AND ratinghostname=' . $ip |
||
56 | . ' AND ratingtimestamp > ' . $yesterday); |
||
57 | list($anonvotecount) = $GLOBALS['xoopsDB']->fetchRow($result); |
||
58 | if ($anonvotecount >= 1) { |
||
59 | $ratemessage = _MD_XOOPSTUBE_VOTEONCE; |
||
60 | redirect_header('singlevideo.php?cid=' . (int)$cid . '&lid=' . (int)$lid, 4, $ratemessage); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | if (!empty(XoopsRequest::getString('submit', ''))) { |
||
65 | $ratinguser = (!is_object($GLOBALS['xoopsUser'])) ? 0 : $GLOBALS['xoopsUser']->getVar('uid'); |
||
66 | // Make sure only 1 anonymous from an IP in a single day. |
||
67 | $anonwaitdays = 1; |
||
68 | $ip = getenv('REMOTE_ADDR'); |
||
69 | $lid = XoopsRequest::getInt('lid', 0, 'POST'); |
||
70 | $cid = XoopsRequest::getInt('cid', 0, 'POST'); |
||
71 | $rating = XoopsRequest::getInt('rating', 0, 'POST'); |
||
72 | // $title = $xtubemyts->addslashes(trim(XoopsRequest::getString('title', '', 'POST'))); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
62% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
73 | $title = XoopsRequest::getString('title', '', 'POST'); |
||
74 | // Check if Rating is Null |
||
75 | if (0 == $rating) { |
||
76 | $ratemessage = _MD_XOOPSTUBE_NORATING; |
||
77 | redirect_header('ratevideo.php?cid=' . (int)$cid . '&lid=' . (int)$lid, 4, $ratemessage); |
||
78 | } |
||
79 | // All is well. Add to Line Item Rate to DB. |
||
80 | $newid = $GLOBALS['xoopsDB']->genId($GLOBALS['xoopsDB']->prefix('xoopstube_votedata') . '_ratingid_seq'); |
||
81 | $datetime = time(); |
||
82 | $sql = |
||
83 | sprintf('INSERT INTO %s (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp, title) VALUES (%u, %u, %u, %u, %s, %u, %s)', $GLOBALS['xoopsDB']->prefix('xoopstube_votedata'), |
||
84 | $newid, (int)$lid, $ratinguser, $rating, $GLOBALS['xoopsDB']->quoteString($ip), $datetime, $GLOBALS['xoopsDB']->quoteString($title)); |
||
85 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
86 | $ratemessage = _MD_XOOPSTUBE_ERROR; |
||
87 | } else { |
||
88 | // All is well. Calculate Score & Add to Summary (for quick retrieval & sorting) to DB. |
||
89 | XoopstubeUtilities::xtubeUpdateRating($lid); |
||
90 | $ratemessage = _MD_XOOPSTUBE_VOTEAPPRE . '<br>' . sprintf(_MD_XOOPSTUBE_THANKYOU, $GLOBALS['xoopsConfig']['sitename']); |
||
91 | } |
||
92 | redirect_header('singlevideo.php?cid=' . (int)$cid . '&lid=' . (int)$lid, 4, $ratemessage); |
||
93 | } else { |
||
94 | //TODO add |
||
95 | $xoopsOption['template_main'] = 'xoopstube_ratevideo.tpl'; |
||
96 | include XOOPS_ROOT_PATH . '/header.php'; |
||
97 | |||
98 | $catarray['imageheader'] = XoopstubeUtilities::xtubeRenderImageHeader(); |
||
99 | $cid = XoopsRequest::getInt('cid', XoopsRequest::getInt('cid', '', 'POST'), 'GET'); |
||
100 | |||
101 | $catarray['imageheader'] = XoopstubeUtilities::xtubeRenderImageHeader(); |
||
102 | $xoopsTpl->assign('catarray', $catarray); |
||
103 | |||
104 | $result = $GLOBALS['xoopsDB']->query('SELECT title FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' WHERE lid=' . (int)$lid); |
||
105 | list($title) = $GLOBALS['xoopsDB']->fetchRow($result); |
||
106 | $xoopsTpl->assign('video', array( |
||
107 | 'id' => (int)$lid, |
||
108 | 'cid' => (int)$cid, |
||
109 | 'title' => $xtubemyts->htmlSpecialCharsStrip($title) |
||
110 | )); |
||
111 | |||
112 | XoopstubeUtilities::xtubeSetNoIndexNoFollow(); |
||
113 | |||
114 | $xoopsTpl->assign('module_dir', $xoopsModule->getVar('dirname')); |
||
115 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
116 | } |
||
117 | |||
118 | XoopstubeUtilities::xtubeSetNoIndexNoFollow(); |
||
119 | |||
120 | $xoopsTpl->assign('module_dir', $xoopsModule->getVar('dirname')); |
||
121 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
122 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state