XoopsModules25x /
mylinks
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | // $Id: ratelink.php 11819 2013-07-09 18:21:40Z zyspec $ |
||
| 3 | // ------------------------------------------------------------------------ // |
||
| 4 | // XOOPS - PHP Content Management System // |
||
| 5 | // Copyright (c) 2000 XOOPS.org // |
||
| 6 | // <http://www.xoops.org/> // |
||
| 7 | // ------------------------------------------------------------------------- // |
||
| 8 | // This program is free software; you can redistribute it and/or modify // |
||
| 9 | // it under the terms of the GNU General Public License as published by // |
||
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
||
| 11 | // (at your option) any later version. // |
||
| 12 | // // |
||
| 13 | // You may not change or alter any portion of this comment or credits // |
||
| 14 | // of supporting developers from this source code or any supporting // |
||
| 15 | // source code which is considered copyrighted (c) material of the // |
||
| 16 | // original comment or credit authors. // |
||
| 17 | // // |
||
| 18 | // This program is distributed in the hope that it will be useful, // |
||
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
| 21 | // GNU General Public License for more details. // |
||
| 22 | // // |
||
| 23 | // You should have received a copy of the GNU General Public License // |
||
| 24 | // along with this program; if not, write to the Free Software // |
||
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
| 26 | // ------------------------------------------------------------------------ // |
||
| 27 | include __DIR__ . '/header.php'; |
||
| 28 | //include_once XOOPS_ROOT_PATH . '/class/module.errorhandler.php'; |
||
| 29 | $myts = MyTextSanitizer::getInstance(); // MyTextSanitizer object |
||
| 30 | include_once __DIR__ . '/class/utility.php'; |
||
| 31 | //xoops_load('utility', $xoopsModule->getVar('dirname')); |
||
| 32 | |||
| 33 | if (!empty($_POST['submit'])) { |
||
| 34 | global $xoopsDB; |
||
| 35 | |||
| 36 | $ip = getenv('REMOTE_ADDR'); |
||
| 37 | $lid = MylinksUtility::mylinks_cleanVars($_POST, 'lid', 0, 'int', array('min' => 0)); |
||
| 38 | $cid = MylinksUtility::mylinks_cleanVars($_POST, 'cid', 0, 'int', array('min' => 0)); |
||
| 39 | $rating = MylinksUtility::mylinks_cleanVars($_POST, 'rating', 0, 'int', array('min' => 0)); |
||
| 40 | |||
| 41 | // make sure listing is active |
||
| 42 | $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mylinks_links') . " WHERE lid={$lid} AND status>0"); |
||
| 43 | if (!$xoopsDB->fetchRow($result)) { |
||
| 44 | redirect_header($_SERVER['PHP_SELF'], 3, _MD_MYLINKS_NORECORDFOUND); |
||
| 45 | exit(); |
||
| 46 | } |
||
| 47 | |||
| 48 | // $eh = new ErrorHandler; //ErrorHandler object |
||
| 49 | $ratinguser = empty($xoopsUser) ? 0 : $xoopsUser->getVar('uid'); |
||
| 50 | |||
| 51 | //Make sure only 1 anonymous from an IP in a single day. |
||
| 52 | $anonwaitdays = 1; |
||
| 53 | |||
| 54 | // Check if Rating is Null |
||
| 55 | // if ( '--' == $rating ) { //bugfix since rating is an int from input filtering |
||
|
0 ignored issues
–
show
|
|||
| 56 | if ($rating <= 0) { |
||
| 57 | redirect_header("ratelink.php?cid={$cid}&lid={$lid}", 4, _MD_MYLINKS_NORATING); |
||
| 58 | exit(); |
||
| 59 | } elseif ($rating > 10) { |
||
| 60 | $rating = 10; |
||
| 61 | } |
||
| 62 | |||
| 63 | // Check if Link POSTER is voting (UNLESS Anonymous users allowed to post) |
||
| 64 | if ($ratinguser != 0) { |
||
| 65 | $result = $xoopsDB->query('SELECT submitter FROM ' . $xoopsDB->prefix('mylinks_links') . " WHERE lid={$lid}"); |
||
| 66 | View Code Duplication | while (list($ratinguserDB) = $xoopsDB->fetchRow($result)) { |
|
| 67 | if ($ratinguserDB == $ratinguser) { |
||
| 68 | redirect_header('index.php', 4, _MD_MYLINKS_CANTVOTEOWN); |
||
| 69 | exit(); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | // Check if REG user is trying to vote twice. |
||
| 74 | $result = $xoopsDB->query('SELECT ratinguser FROM ' . $xoopsDB->prefix('mylinks_votedata') . " WHERE lid={$lid}"); |
||
| 75 | View Code Duplication | while (list($ratinguserDB) = $xoopsDB->fetchRow($result)) { |
|
| 76 | if ($ratinguserDB == $ratinguser) { |
||
| 77 | redirect_header('index.php', 4, _MD_MYLINKS_VOTEONCE2); |
||
| 78 | exit(); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } else { |
||
| 82 | |||
| 83 | // Check if ANONYMOUS user is trying to vote more than once per day. |
||
| 84 | $yesterday = (time() - (86400 * $anonwaitdays)); |
||
| 85 | $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mylinks_votedata') . " WHERE lid={$lid} AND ratinguser=0 AND ratinghostname = '{$ip}' AND ratingtimestamp > {$yesterday}"); |
||
| 86 | list($anonvotecount) = $xoopsDB->fetchRow($result); |
||
| 87 | if ($anonvotecount > 0) { |
||
| 88 | redirect_header('index.php', 4, _MD_MYLINKS_VOTEONCE2); |
||
| 89 | exit(); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | /* |
||
| 93 | if($rating > 10){ |
||
| 94 | $rating = 10; |
||
| 95 | } |
||
| 96 | */ |
||
| 97 | //All is well. Add to Line Item Rate to DB. |
||
| 98 | $newid = $xoopsDB->genId($xoopsDB->prefix('mylinks_votedata') . '_ratingid_seq'); |
||
| 99 | $datetime = time(); |
||
| 100 | $sql = sprintf("INSERT INTO %s (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp) VALUES (%u, %u, %u, %u, '%s', %u)", $xoopsDB->prefix('mylinks_votedata'), $newid, $lid, $ratinguser, $rating, $ip, $datetime); |
||
| 101 | $result = $xoopsDB->query($sql); |
||
| 102 | if (!$result) { |
||
| 103 | MylinksUtility::show_message(_MD_MYLINKS_DBNOTUPDATED); |
||
|
0 ignored issues
–
show
|
|||
| 104 | exit(); |
||
| 105 | } |
||
| 106 | |||
| 107 | //All is well. Calculate Score & Add to Summary (for quick retrieval & sorting) to DB. |
||
| 108 | updaterating($lid); |
||
|
0 ignored issues
–
show
It seems like
$lid defined by \MylinksUtility::mylinks...nt', array('min' => 0)) on line 37 can also be of type double; however, updaterating() does only seem to accept integer, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 109 | $ratemessage = _MD_MYLINKS_VOTEAPPRE . '<br>' . sprintf(_MD_MYLINKS_THANKURATE, htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)); |
||
| 110 | redirect_header('index.php', 2, $ratemessage); |
||
| 111 | exit(); |
||
| 112 | } else { |
||
| 113 | $xoopsOption['template_main'] = 'mylinks_ratelink.tpl'; |
||
| 114 | include XOOPS_ROOT_PATH . '/header.php'; |
||
| 115 | |||
| 116 | //wanikoo |
||
| 117 | $xoTheme->addStylesheet('browse.php?' . mylinksGetStylePath('mylinks.css', 'include')); |
||
| 118 | $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js'); |
||
| 119 | $xoTheme->addScript('browse.php?' . mylinksGetStylePath('mylinks.js', 'include')); |
||
| 120 | |||
| 121 | $lid = MylinksUtility::mylinks_cleanVars($_GET, 'lid', 0, 'int', array('min' => 0)); |
||
| 122 | $cid = MylinksUtility::mylinks_cleanVars($_GET, 'cid', 0, 'int', array('min' => 0)); |
||
| 123 | $result = $xoopsDB->query('SELECT title FROM ' . $xoopsDB->prefix('mylinks_links') . " WHERE lid={$lid}"); |
||
| 124 | //TODO: need error checking here in case invalid lid |
||
| 125 | list($title) = $xoopsDB->fetchRow($result); |
||
| 126 | $xoopsTpl->assign('link', array( |
||
| 127 | 'id' => $lid, |
||
| 128 | 'cid' => $cid, |
||
| 129 | 'title' => $myts->htmlSpecialChars($myts->stripSlashesGPC($title)) |
||
| 130 | )); |
||
| 131 | $xoopsTpl->assign('lang_voteonce', _MD_MYLINKS_VOTEONCE); |
||
| 132 | $xoopsTpl->assign('lang_ratingscale', _MD_MYLINKS_RATINGSCALE); |
||
| 133 | $xoopsTpl->assign('lang_beobjective', _MD_MYLINKS_BEOBJECTIVE); |
||
| 134 | $xoopsTpl->assign('lang_donotvote', _MD_MYLINKS_DONOTVOTE); |
||
| 135 | $xoopsTpl->assign('lang_rateit', _MD_MYLINKS_RATEIT); |
||
| 136 | $xoopsTpl->assign('lang_cancel', _CANCEL); |
||
| 137 | |||
| 138 | //wanikoo theme changer |
||
| 139 | $xoopsTpl->assign('lang_themechanger', _MD_MYLINKS_THEMECHANGER); |
||
| 140 | $mymylinkstheme_options = ''; |
||
| 141 | |||
| 142 | View Code Duplication | foreach ($GLOBALS['mylinks_allowed_theme'] as $mymylinkstheme) { |
|
| 143 | $mymylinkstheme_options .= "<option value='{$mymylinkstheme}'"; |
||
| 144 | if ($mymylinkstheme == $GLOBALS['mylinks_theme']) { |
||
| 145 | $mymylinkstheme_options .= " selected='selected'"; |
||
| 146 | } |
||
| 147 | $mymylinkstheme_options .= ">{$mymylinkstheme}</option>"; |
||
| 148 | } |
||
| 149 | |||
| 150 | $mylinkstheme_select = "<select name='mylinks_theme_select' onchange='submit();' size='1'>{$mymylinkstheme_options}</select>"; |
||
| 151 | |||
| 152 | $xoopsTpl->assign('mylinksthemeoption', $mylinkstheme_select); |
||
| 153 | |||
| 154 | //wanikoo search |
||
| 155 | View Code Duplication | if (file_exists(XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/search.php')) { |
|
| 156 | include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/search.php'; |
||
| 157 | } else { |
||
| 158 | include_once XOOPS_ROOT_PATH . '/language/english/search.php'; |
||
| 159 | } |
||
| 160 | $xoopsTpl->assign('lang_all', _SR_ALL); |
||
| 161 | $xoopsTpl->assign('lang_any', _SR_ANY); |
||
| 162 | $xoopsTpl->assign('lang_exact', _SR_EXACT); |
||
| 163 | $xoopsTpl->assign('lang_search', _SR_SEARCH); |
||
| 164 | $xoopsTpl->assign('module_id', $xoopsModule->getVar('mid')); |
||
| 165 | //category head |
||
| 166 | $catarray = array(); |
||
| 167 | if ($mylinks_show_letters) { |
||
| 168 | $catarray['letters'] = ml_wfd_letters(); |
||
| 169 | } |
||
| 170 | if ($mylinks_show_toolbar) { |
||
| 171 | $catarray['toolbar'] = ml_wfd_toolbar(); |
||
| 172 | } |
||
| 173 | $xoopsTpl->assign('catarray', $catarray); |
||
| 174 | |||
| 175 | include_once XOOPSMYLINKPATH . '/footer.php'; |
||
| 176 | } |
||
| 177 |
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.