These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ |
||
14 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license |
||
15 | * @package Publisher |
||
16 | * @subpackage Action |
||
17 | * @since 1.0 |
||
18 | * @author trabis <[email protected]> |
||
19 | */ |
||
20 | |||
21 | include_once __DIR__ . '/header.php'; |
||
22 | |||
23 | //getting the values |
||
24 | $rating = XoopsRequest::getInt('rating', 0, 'GET'); |
||
25 | $itemid = XoopsRequest::getInt('itemid', 0, 'GET'); |
||
26 | |||
27 | $groups = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
28 | $gpermHandler = xoops_getModuleHandler('groupperm'); |
||
29 | $hModConfig = xoops_getHandler('config'); |
||
30 | $module_id = $publisher->getModule()->getVar('mid'); |
||
31 | |||
32 | //Checking permissions |
||
33 | View Code Duplication | if (!$publisher->getConfig('perm_rating') || !$gpermHandler->checkRight('global', PublisherConstants::PUBLISHER_RATE, $groups, $module_id)) { |
|
0 ignored issues
–
show
|
|||
34 | redirect_header(PUBLISHER_URL . '/item.php?itemid=' . $itemid, 2, _NOPERM); |
||
35 | // exit(); |
||
36 | } |
||
37 | |||
38 | if ($rating > 5 || $rating < 1) { |
||
39 | redirect_header(PUBLISHER_URL . '/item.php?itemid=' . $itemid, 2, _MD_PUBLISHER_VOTE_BAD); |
||
40 | // exit(); |
||
41 | } |
||
42 | |||
43 | $criteria = new Criteria('itemid', $itemid); |
||
44 | $ratingObjs = $publisher->getHandler('rating')->getObjects($criteria); |
||
45 | |||
46 | $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
||
47 | $count = count($ratingObjs); |
||
48 | $current_rating = 0; |
||
49 | $voted = false; |
||
50 | $ip = getenv('REMOTE_ADDR'); |
||
51 | |||
52 | View Code Duplication | foreach ($ratingObjs as $ratingObj) { |
|
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. ![]() |
|||
53 | $current_rating += $ratingObj->getVar('rate'); |
||
54 | if ($ratingObj->getVar('ip') == $ip || ($uid > 0 && $uid == $ratingObj->getVar('uid'))) { |
||
55 | $voted = true; |
||
56 | } |
||
57 | } |
||
58 | //unset($ratingObj); |
||
59 | |||
60 | if ($voted) { |
||
61 | redirect_header(PUBLISHER_URL . '/item.php?itemid=' . $itemid, 2, _MD_PUBLISHER_VOTE_ALREADY); |
||
62 | // exit(); |
||
63 | } |
||
64 | |||
65 | $newRatingObj = $publisher->getHandler('rating')->create(); |
||
66 | $newRatingObj->setVar('itemid', $itemid); |
||
67 | $newRatingObj->setVar('ip', $ip); |
||
68 | $newRatingObj->setVar('uid', $uid); |
||
69 | $newRatingObj->setVar('rate', $rating); |
||
70 | $newRatingObj->setVar('date', time()); |
||
71 | $publisher->getHandler('rating')->insert($newRatingObj); |
||
72 | |||
73 | $current_rating += $rating; |
||
74 | ++$count; |
||
75 | |||
76 | $publisher->getHandler('item')->updateAll('rating', number_format($current_rating / $count, 4), $criteria, true); |
||
77 | $publisher->getHandler('item')->updateAll('votes', $count, $criteria, true); |
||
78 | |||
79 | redirect_header(PUBLISHER_URL . '/item.php?itemid=' . $itemid, 2, _MD_PUBLISHER_VOTE_THANKS); |
||
80 | //exit(); |
||
81 |
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.