Issues (496)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

class/RatingHandler.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php namespace XoopsModules\Smartobject;
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    XOOPS Project https://xoops.org/
15
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @package
17
 * @since
18
 * @author     XOOPS Development Team
19
 */
20
21
use XoopsModules\Smartobject;
22
23
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
24
25
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
26
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartplugins.php';
27
28
29
/**
30
 * Class SmartobjectRatingHandler
31
 */
32
class RatingHandler extends Smartobject\PersistableObjectHandler
33
{
34
    public $_rateOptions = [];
35
    public $_moduleList  = false;
36
    public $pluginsObject;
37
38
    /**
39
     * SmartobjectRatingHandler constructor.
40
     * @param \XoopsDatabase $db
41
     */
42
    public function __construct(\XoopsDatabase $db)
43
    {
44
        parent::__construct($db, Rating::class, 'ratingid', 'rate', '', 'smartobject');
45
        $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid';
0 ignored issues
show
Documentation Bug introduced by
The property $generalSQL was declared of type boolean, but 'SELECT * FROM ' . $this...mname . '.uid=user.uid' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
46
47
        $this->_rateOptions[1] = 1;
48
        $this->_rateOptions[2] = 2;
49
        $this->_rateOptions[3] = 3;
50
        $this->_rateOptions[4] = 4;
51
        $this->_rateOptions[5] = 5;
52
53
        $this->pluginsObject = new PluginHandler();
54
    }
55
56
    /**
57
     * @return bool
58
     */
59
    public function getModuleList()
60
    {
61
        if (!$this->_moduleList) {
62
            $moduleArray          = $this->pluginsObject->getPluginsArray();
63
            $this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION;
64
            foreach ($moduleArray as $k => $v) {
65
                $this->_moduleList[$k] = $v;
66
            }
67
        }
68
69
        return $this->_moduleList;
70
    }
71
72
    /**
73
     * @return array
74
     */
75
    public function getRateList()
76
    {
77
        return $this->_rateOptions;
78
    }
79
80
    /**
81
     * @param $itemid
82
     * @param $dirname
83
     * @param $item
84
     * @return int
85
     */
86
    public function getRatingAverageByItemId($itemid, $dirname, $item)
87
    {
88
        $sql    = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid";
89
        $result = $this->db->query($sql);
90
        if (!$result) {
91
            return 0;
92
        }
93
        list($average, $sum) = $this->db->fetchRow($result);
94
        $ret['average'] = isset($average) ? $average : 0;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$ret was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ret = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
95
        $ret['sum']     = isset($sum) ? $sum : 0;
96
97
        return $ret;
98
    }
99
100
    /**
101
     * @param $item
102
     * @param $itemid
103
     * @param $dirname
104
     * @param $uid
105
     * @return bool
106
     */
107
    public function already_rated($item, $itemid, $dirname, $uid)
108
    {
109
        $criteria = new \CriteriaCompo();
110
        $criteria->add(new \Criteria('item', $item));
111
        $criteria->add(new \Criteria('itemid', $itemid));
112
        $criteria->add(new \Criteria('dirname', $dirname));
113
        $criteria->add(new \Criteria('user.uid', $uid));
114
115
        $ret =& $this->getObjects($criteria);
116
117
        if (!$ret) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $ret of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
118
            return false;
119
        } else {
120
            return $ret[0];
121
        }
122
    }
123
}
124