Issues (733)

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/offer.php (16 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 37 and the first side effect is on line 31.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
// 
3
// ------------------------------------------------------------------------ //
4
//               XOOPS - PHP Content Management System                      //
5
//                   Copyright (c) 2000-2016 XOOPS.org                           //
6
//                      <http://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
// This program is distributed in the hope that it will be useful,          //
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
20
// GNU General Public License for more details.                             //
21
22
// You should have received a copy of the GNU General Public License        //
23
// along with this program; if not, write to the Free Software              //
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
25
// ------------------------------------------------------------------------ //
26
// URL: http://xoops.org/                                               //
27
// Project: XOOPS Project                                               //
28
// -------------------------------------------------------------------------//
29
30
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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.

Loading history...
31
include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
32
include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjecthandler.php';
33
34
/**
35
 * Class SmartpartnerOffer
36
 */
37
class SmartpartnerOffer extends SmartObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
38
{
39
    /**
40
     * SmartpartnerOffer constructor.
41
     */
42
    public function __construct()
43
    {
44
        $this->initVar('offerid', XOBJ_DTYPE_INT, '', true);
45
        $this->initVar('partnerid', XOBJ_DTYPE_INT, '', true, 255, '', false, _CO_SPARTNER_OFFER_PARTNER, _CO_SPARTNER_OFFER_PARTNER_DSC, true);
46
        $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SPARTNER_OFFER_TITLE, _CO_SPARTNER_OFFER_TITLE_DSC, true);
47
48
        $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SPARTNER_OFFER_DESC, _CO_SPARTNER_OFFER_DESC_DSC);
49
        $this->initVar('url', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SPARTNER_OFFER_URL, _CO_SPARTNER_OFFER_URL_DSC, true);
50
        $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SPARTNER_OFFER_IMAGE, _CO_SPARTNER_OFFER_IMAGE_DSC);
51
52
        $this->initVar('date_sub', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SPARTNER_OFFER_DATESUB, _CO_SPARTNER_OFFER_DATESUB_DSC, true);
53
        $this->initVar('date_pub', XOBJ_DTYPE_INT, time() - 1000, false, null, '', false, _CO_SPARTNER_OFFER_DATE_START, _CO_SPARTNER_OFFER_DATE_START_DSC, true);
54
        $this->initVar('date_end', XOBJ_DTYPE_INT, time() + 30 * 24 * 3600, false, null, '', false, _CO_SPARTNER_OFFER_DATE_END, _CO_SPARTNER_OFFER_DATE_END_DSC, true);
55
56
        $this->initVar('status', XOBJ_DTYPE_INT, _SPARTNER_STATUS_ONLINE, false, null, '', false, _CO_SPARTNER_OFFER_STATUS, _CO_SPARTNER_OFFER_STATUS_DSC, true);
57
        $this->initCommonVar('weight');
58
        $this->initCommonVar('dohtml', false);
59
60
        $this->setControl('image', array('name' => 'image'));
61
62
        $this->setControl('date_sub', array('name' => 'date_time'));
63
        $this->setControl('date_pub', array('name' => 'date_time'));
64
        $this->setControl('date_end', array('name' => 'date_time'));
65
66
        $this->setControl('status', array(
67
            'name'        => false,
68
            'itemHandler' => 'offer',
69
            'method'      => 'getStatus',
70
            'module'      => 'smartpartner'
71
        ));
72
        $this->setControl('partnerid', array(
73
            'itemHandler' => 'partner',
74
            'method'      => 'getList',
75
            'module'      => 'smartpartner'
76
        ));
77
    }
78
79
    /**
80
     * @param  string $key
81
     * @param  string $format
82
     * @return mixed
83
     */
84
    public function getVar($key, $format = 's')
85
    {
86
        if ($format === 's' && in_array($key, array('partnerid', 'status'))) {
87
            //            return call_user_func(array($this, $key));
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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.

Loading history...
88
            return $this->{$key}();
89
        }
90
91
        return parent::getVar($key, $format);
92
    }
93
94
    /**
95
     * @return mixed
96
     */
97
    public function partnerid()
98
    {
99
        global $smartPartnerPartnerHandler;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
100
        if (!$smartPartnerPartnerHandler) {
101
            $smartPartnerPartnerHandler = smartpartner_gethandler('partner');
102
        }
103
        $ret        = $this->getVar('partnerid', 'e');
104
        $partnerObj = $smartPartnerPartnerHandler->get($ret);
105
106
        return $partnerObj->getVar('title');
107
    }
108
109
    /**
110
     * @return mixed
111
     */
112
    public function status()
113
    {
114
        global $statusArray;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
115
        $ret = $this->getVar('status', 'e');
116
117
        return $statusArray [$ret];
118
    }
119
120
    /**
121
     * @param array $notifications
122
     */
123
    public function sendNotifications($notifications = array())
124
    {
125
        global $smartPartnerPartnerHandler;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
126
        $partnerObj  = $smartPartnerPartnerHandler->get($this->getVar('partnerid', 'e'));
127
        $smartModule =& smartpartner_getModuleInfo();
128
        $module_id   = $smartModule->getVar('mid');
0 ignored issues
show
$module_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
129
130
        $myts                = MyTextSanitizer::getInstance();
131
        $notificationHandler = xoops_getHandler('notification');
132
133
        $tags                 = array();
134
        $tags['MODULE_NAME']  = $myts->displayTarea($smartModule->getVar('name'));
135
        $tags['PARTNER_NAME'] = $partnerObj->title(20);
136
        $tags['OFFER_NAME']   = $this->title(20);
137
        foreach ($notifications as $notification) {
138
            switch ($notification) {
139
140
                case _SPARTNER_NOT_OFFER_NEW:
141
                    $tags['OFFER_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/partner.php?id=' . $this->getVar('partnerid', 'e');
142
                    $notificationHandler->triggerEvent('global_partner', 0, 'new_offer', $tags);
143
                    break;
144
                case -1:
145
                default:
146
                    break;
147
            }
148
        }
149
    }
150
151
    /**
152
     * @param  string $format
153
     * @return array
154
     */
155
    public function toArray($format = 's')
156
    {
157
        global $myts;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
158
        if (!$myts) {
159
            $myts = MyTextSanitizer::getInstance();
160
        }
161
        $ret = parent::toArray();
162
        if ($format === 'e') {
163
            $ret['partnerid'] = $this->getVar('partnerid', 'e');
164
        }
165
        $ret['description'] = $myts->undoHtmlSpecialChars($ret['description']);
166
167
        return $ret;
168
    }
169
}
170
171
/**
172
 * Class SmartpartnerOfferHandler
173
 */
174
class SmartpartnerOfferHandler extends SmartPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
175
{
176
    /**
177
     * SmartpartnerOfferHandler constructor.
178
     * @param XoopsDatabase $db
179
     */
180
    public function __construct(XoopsDatabase $db)
181
    {
182
        parent::__construct($db, 'offer', 'offerid', 'title', false, 'smartpartner');
183
    }
184
185
    /**
186
     * @return array
187
     */
188
    public function getStatus()
189
    {
190
        global $statusArray;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
191
192
        return $statusArray;
193
    }
194
195
    /**
196
     * @return array
197
     */
198
    public function getObjectsForUserSide()
199
    {
200
        global $xoopsModuleConfig, $smartPartnerCategoryHandler, $smartPartnerPartnerHandler, $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
201
202
        $criteria = new CriteriaCompo();
203
        $criteria->setSort($xoopsModuleConfig['offer_sort']);
204
        $criteria->setOrder($xoopsModuleConfig['offer_order']);
205
        $criteria->add(new Criteria('date_pub', time(), '<'));
206
        $criteria->add(new Criteria('date_end', time(), '>'));
207
        $criteria->add(new Criteria('status', _SPARTNER_STATUS_ONLINE));
208
209
        $offersObj = $this->getObjects($criteria);
210
        foreach ($offersObj as $offerObj) {
0 ignored issues
show
This foreach statement is empty and can be removed.

This check looks for foreach loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
211
        }
212
        $catsObj     = $smartPartnerCategoryHandler->getObjects(null, true);
213
        $partnersObj = $smartPartnerPartnerHandler->getObjects(null, true);
214
215
        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectpermission.php';
216
        $smartPermissionsHandler = new SmartobjectPermissionHandler($smartPartnerPartnerHandler);
217
        $userGroups              = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
218
        $grantedItems            = $smartPermissionsHandler->getGrantedItems('full_view');
219
        $relevantCat             = array();
220
221
        foreach ($offersObj as $offerObj) {
222
            if (in_array($offerObj->getVar('partnerid', 'e'), $grantedItems)) {
223
                $categId        = $partnersObj[$offerObj->getVar('partnerid', 'e')]->categoryid();
224
                $parentCatArray = explode('|', $categId);
225
                $relevantCat    = array_merge($relevantCat, $parentCatArray);
226
                foreach ($parentCatArray as $p_cat) {
227
                    $parentid = $p_cat;
228
                    while ($catsObj[$parentid]->parentid() != 0) {
229
                        $parentid      = $catsObj[$parentid]->parentid();
230
                        $relevantCat[] = $parentid;
231
                    }
232
                }
233
            }
234
        }
235
        $relevantCat = array_unique($relevantCat);
236
237
        $partnersArray = array();
238
        foreach ($partnersObj as $partnerObj) {
239
            $grantedGroups = $smartPermissionsHandler->getGrantedGroups('full_view', $partnerObj->id());
240
            if (array_intersect($userGroups, $grantedGroups)) {
241
                $partnerArray           = array();
242
                $partnerArray['name']   = $partnerObj->title();
243
                $partnerArray['offers'] = array();
244
                foreach ($offersObj as $offerObj) {
245
                    if ($offerObj->getVar('partnerid', 'e') == $partnerObj->id()) {
246
                        $partnerArray['offers'][] = $offerObj->toArray();
247
                    }
248
                }
249
                $partnersArray[$partnerObj->id()] = $partnerArray;
250
                unset($partnerArray);
251
            }
252
        }
253
254
        $categoriesArray = array();
255
        foreach ($catsObj as $catObj) {
256
            if (in_array($catObj->categoryid(), $relevantCat)) {
257
                $categoryArray               = array();
258
                $categoryArray['parentid']   = $catObj->parentid();
259
                $categoryArray['categoryid'] = $catObj->categoryid();
260
                $categoryArray['name']       = $catObj->name();
261
                $categoryArray['partners']   = array();
262
                foreach ($partnersObj as $partnerObj) {
263
                    $catArray = explode('|', $partnerObj->categoryid());
264
                    if (in_array($catObj->categoryid(), $catArray)) {
265
                        $categoryArray['partners'][$partnerObj->id()] = $partnersArray[$partnerObj->id()];
266
                    }
267
                }
268
                $categoriesArray[] = $categoryArray;
269
                unset($categoryArray);
270
            }
271
        }
272
273
        return $this->hierarchize($categoriesArray);
274
    }
275
276
    /**
277
     * @param        $categoriesArray
278
     * @param  int   $parentid
279
     * @return array
280
     */
281
    public function hierarchize($categoriesArray, $parentid = 0)
282
    {
283
        $hierachizedArray = array();
284
        foreach ($categoriesArray as $cat) {
285
            if ($cat['parentid'] == $parentid) {
286
                $id                               = $cat['categoryid'];
287
                $hierachizedArray[$id]            = $cat;
288
                $hierachizedArray[$id]['subcats'] = $this->hierarchize($categoriesArray, $cat['categoryid']);
289
            }
290
        }
291
292
        return $hierachizedArray;
293
    }
294
295
    /**
296
     * @param $category
297
     * @return bool
298
     */
299
    public function hasOffer($category)
300
    {
301
        $partners = $category['partners'];
302
        $subcats  = $category['subcats'];
303
        $hasoffer = false;
304
        foreach ($partners as $partner) {
305
            if (isset($partner['offers'])) {
306
                $hasoffer = true;
307
            }
308
        }
309
        if ((!$hasoffer || !$partners) && !$subcats) {
310
            return false;
311
        }
312
        foreach ($partners as $partner) {
313
            if ($partner['offers']) {
314
                return true;
315
            }
316
        }
317
        foreach ($subcats as $subcat) {
318
            return hasOffer($subcat);
319
        }
320
    }
321
322
    /**
323
     * @return mixed
324
     */
325
    public function getPartnerList()
326
    {
327
        global $smartPartnerPartnerHandler;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
328
329
        return $smartPartnerPartnerHandler->getList();
330
    }
331
332
    /**
333
     * @return array
334
     */
335
    public function getstatusList()
336
    {
337
        global $statusArray;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
338
339
        return $statusArray;
340
    }
341
}
342