Completed
Push — master ( 923121...f83415 )
by Michael
02:52
created

functions.php ➔ money_format()   F

Complexity

Conditions 30
Paths > 20000

Size

Total Lines 82
Code Lines 63

Duplication

Lines 12
Ratio 14.63 %

Importance

Changes 0
Metric Value
cc 30
eloc 63
nc 172034
nop 2
dl 12
loc 82
rs 2.2956
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 29 and the first side effect is on line 23.

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
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
$moduleDirName = basename(dirname(__DIR__));
24
$main_lang     = '_' . strtoupper($moduleDirName);
25
require_once XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php';
26
include_once XOOPS_ROOT_PATH . '/class/xoopstree.php';
27
$myts = MyTextSanitizer::getInstance();
28
29
function ExpireAd()
30
{
31
    global $xoopsDB, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $myts, $meta, $moduleDirName, $main_lang;
1 ignored issue
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...
32
33
    $datenow = time();
34
35
    $result5 = $xoopsDB->query('SELECT lid, title, expire, type, desctext, date, email, submitter, photo, valid, hits, comments, remind FROM '
36
                               . $xoopsDB->prefix('adslight_listing')
37
                               . " WHERE valid='Yes'");
38
39
    while (list($lids, $title, $expire, $type, $desctext, $dateann, $email, $submitter, $photo, $valid, $hits, $comments, $remind) = $xoopsDB->fetchRow($result5)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $comments is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
40
        $title     = $myts->htmlSpecialChars($title);
41
        $expire    = $myts->htmlSpecialChars($expire);
42
        $type      = $myts->htmlSpecialChars($type);
43
        $desctext  = $myts->displayTarea($desctext, 1, 1, 1, 1, 1);
44
        $submitter = $myts->htmlSpecialChars($submitter);
45
        $remind    = $myts->htmlSpecialChars($remind);
46
        $supprdate = $dateann + ($expire * 86400);
47
        $almost    = $xoopsModuleConfig['adslight_almost'];
48
49
        // give warning that add is about to expire
50
51
        if ($almost > 0 && ($supprdate - $almost * 86400) < $datenow && $valid === 'Yes' && $remind == 0) {
52
            $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET remind='1' WHERE lid=$lids");
53
54 View Code Duplication
            if ($email) {
1 ignored issue
show
Duplication introduced by
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.

Loading history...
55
                $tags               = array();
56
                $subject            = '' . _ADSLIGHT_ALMOST . '';
57
                $tags['TITLE']      = $title;
58
                $tags['HELLO']      = '' . _ADSLIGHT_HELLO . '';
59
                $tags['YOUR_AD_ON'] = '' . _ADSLIGHT_YOUR_AD_ON . '';
60
                $tags['VEDIT_AD']   = '' . _ADSLIGHT_VEDIT_AD . '';
61
                $tags['YOUR_AD']    = '' . _ADSLIGHT_YOUR_AD . '';
62
                $tags['SOON']       = '' . _ADSLIGHT_SOON . '';
63
                $tags['VIEWED']     = '' . _ADSLIGHT_VU . '';
64
                $tags['TIMES']      = '' . _ADSLIGHT_TIMES . '';
65
                $tags['WEBMASTER']  = '' . _ADSLIGHT_WEBMASTER . '';
66
                $tags['THANKS']     = '' . _ADSLIGHT_THANKS . '';
67
                $tags['TYPE']       = adslight_NameType($type);
68
                $tags['DESCTEXT']   = $desctext;
69
                $tags['HITS']       = $hits;
70
                $tags['META_TITLE'] = $meta['title'];
71
                $tags['SUBMITTER']  = $submitter;
72
                $tags['DURATION']   = $expire;
73
                $tags['LINK_URL']   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewads.php?' . '&lid=' . $lids;
74
                $mail               =& getMailer();
75
                $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/');
76
                $mail->setTemplate('listing_expires.tpl');
77
                $mail->useMail();
78
                $mail->multimailer->isHTML(true);
79
                $mail->setFromName($meta['title']);
80
                $mail->setFromEmail($xoopsConfig['adminmail']);
81
                $mail->setToEmails($email);
82
                $mail->setSubject($subject);
83
                $mail->assign($tags);
84
                $mail->send();
85
                echo $mail->getErrors();
86
            }
87
        }
88
89
        // expire ad
90
91
        if ($supprdate < $datenow) {
92
            if ($photo != 0) {
93
                $result2 = $xoopsDB->query('SELECT url FROM ' . $xoopsDB->prefix('adslight_pictures') . ' WHERE lid=' . $xoopsDB->escape($lids) . '');
94
95
                while (list($url) = $xoopsDB->fetchRow($result2)) {
96
                    $destination  = XOOPS_ROOT_PATH . '/uploads/AdsLight';
97
                    $destination2 = XOOPS_ROOT_PATH . '/uploads/AdsLight/thumbs';
98
                    $destination3 = XOOPS_ROOT_PATH . '/uploads/AdsLight/midsize';
99
                    if (file_exists("$destination/$url")) {
100
                        unlink("$destination/$url");
101
                    }
102
                    if (file_exists("$destination2/thumb_$url")) {
103
                        unlink("$destination2/thumb_$url");
104
                    }
105
                    if (file_exists("$destination3/resized_$url")) {
106
                        unlink("$destination3/resized_$url");
107
                    }
108
                }
109
            }
110
111
            $xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lids) . '');
112
113
            //  Specification for Japan:
114
            //  $message = ""._ADS_HELLO." $submitter,\n\n"._ADS_STOP2."\n $type : $title\n $desctext\n"._ADS_STOP3."\n\n"._ADS_VU." $lu "._ADS_VU2."\n\n"._ADS_OTHER." ".XOOPS_URL."/modules/myAds\n\n"._ADS_THANK."\n\n"._ADS_TEAM." ".$meta['title']."\n".XOOPS_URL."";
115 View Code Duplication
            if ($email) {
1 ignored issue
show
Duplication introduced by
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.

Loading history...
116
                $tags               = array();
117
                $subject            = '' . _ADSLIGHT_STOP . '';
118
                $tags['TITLE']      = $title;
119
                $tags['HELLO']      = '' . _ADSLIGHT_HELLO . '';
120
                $tags['TYPE']       = adslight_NameType($type);
121
                $tags['DESCTEXT']   = $desctext;
122
                $tags['HITS']       = $hits;
123
                $tags['META_TITLE'] = $meta['title'];
124
                $tags['SUBMITTER']  = $submitter;
125
                $tags['YOUR_AD_ON'] = '' . _ADSLIGHT_YOUR_AD_ON . '';
126
                $tags['EXPIRED']    = '' . _ADSLIGHT_EXPIRED . '';
127
                $tags['MESSTEXT']   = stripslashes($message);
0 ignored issues
show
Bug introduced by
The variable $message does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
128
                $tags['OTHER']      = '' . _ADSLIGHT_OTHER . '';
129
                $tags['WEBMASTER']  = '' . _ADSLIGHT_WEBMASTER . '';
130
                $tags['THANKS']     = '' . _ADSLIGHT_THANKS . '';
131
                $tags['VIEWED']     = '' . _ADSLIGHT_VU . '';
132
                $tags['TIMES']      = '' . _ADSLIGHT_TIMES . '';
133
                $tags['TEAM']       = '' . _ADSLIGHT_TEAM . '';
134
                $tags['DURATION']   = $expire;
135
                $tags['LINK_URL']   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewads.php?' . '&lid=' . $lids;
136
                $mail               =& getMailer();
137
                $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/');
138
                $mail->setTemplate('listing_expired.tpl');
139
                $mail->useMail();
140
                $mail->multimailer->isHTML(true);
141
                $mail->setFromName($meta['title']);
142
                $mail->setFromEmail($xoopsConfig['adminmail']);
143
                $mail->setToEmails($email);
144
                $mail->setSubject($subject);
145
                $mail->assign($tags);
146
                $mail->send();
147
                echo $mail->getErrors();
148
            }
149
        }
150
    }
151
}
152
153
//updates rating data in itemtable for a given user
154
/**
155
 * @param $sel_id
156
 */
157 View Code Duplication
function updateUrating($sel_id)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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.

Loading history...
Coding Style introduced by
updateUrating uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
158
{
159
    global $xoopsDB, $xoopsUser, $moduleDirName, $main_lang;
1 ignored issue
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...
160
161
    if (isset($_GET['usid'])) {
162
        $usid = (int)$_GET['usid'];
0 ignored issues
show
Unused Code introduced by
$usid 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...
163
    } else {
164
        $usid = 0;
0 ignored issues
show
Unused Code introduced by
$usid 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...
165
    }
166
    $query = 'SELECT rating FROM ' . $xoopsDB->prefix('adslight_user_votedata') . ' WHERE usid=' . $xoopsDB->escape($sel_id) . '';
167
    //echo $query;
168
    $voteresult  = $xoopsDB->query($query);
169
    $votesDB     = $xoopsDB->getRowsNum($voteresult);
170
    $totalrating = 0;
171
    while (list($rating) = $xoopsDB->fetchRow($voteresult)) {
172
        $totalrating += $rating;
173
    }
174
    $finalrating = $totalrating / $votesDB;
175
    $finalrating = number_format($finalrating, 4);
176
    $query       = 'UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET user_rating=$finalrating, user_votes=$votesDB WHERE usid=" . $xoopsDB->escape($sel_id) . '';
177
    //echo $query;
178
    $xoopsDB->query($query) || exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function updateUrating() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
179
}
180
181
//updates rating data in itemtable for a given user
182
/**
183
 * @param $sel_id
184
 */
185 View Code Duplication
function updateIrating($sel_id)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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.

Loading history...
Coding Style introduced by
updateIrating uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
186
{
187
    global $xoopsDB, $xoopsUser, $moduleDirName, $main_lang;
1 ignored issue
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...
188
189
    if (isset($_GET['lid'])) {
190
        $lid = (int)$_GET['lid'];
0 ignored issues
show
Unused Code introduced by
$lid 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...
191
    } else {
192
        $lid = 0;
0 ignored issues
show
Unused Code introduced by
$lid 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...
193
    }
194
    $query = 'SELECT rating FROM ' . $xoopsDB->prefix('adslight_item_votedata') . ' WHERE lid=' . $xoopsDB->escape($sel_id) . '';
195
    //echo $query;
196
    $voteresult  = $xoopsDB->query($query);
197
    $votesDB     = $xoopsDB->getRowsNum($voteresult);
198
    $totalrating = 0;
199
    while (list($rating) = $xoopsDB->fetchRow($voteresult)) {
200
        $totalrating += $rating;
201
    }
202
    $finalrating = $totalrating / $votesDB;
203
    $finalrating = number_format($finalrating, 4);
204
    $query       = 'UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET item_rating=$finalrating, item_votes=$votesDB WHERE lid=" . $xoopsDB->escape($sel_id) . '';
205
    //echo $query;
206
    $xoopsDB->query($query) || exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function updateIrating() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
207
}
208
209
/**
210
 * @param        $sel_id
211
 * @param string $status
212
 *
213
 * @return int
214
 */
215
function adslight_getTotalItems($sel_id, $status = '')
0 ignored issues
show
Unused Code introduced by
The parameter $status is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
216
{
217
    global $xoopsDB, $mytree, $moduleDirName;
1 ignored issue
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...
218
    $categories = adslight_MygetItemIds('adslight_view');
219
    $count      = 0;
220
    $arr        = array();
0 ignored issues
show
Unused Code introduced by
$arr 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...
221
    if (in_array($sel_id, $categories)) {
222
        $query = 'SELECT SQL_CACHE count(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE cid=' . (int)$sel_id . " and valid='Yes' AND status!='1'";
223
224
        $result = $xoopsDB->query($query);
225
        list($thing) = $xoopsDB->fetchRow($result);
226
        $count = $thing;
227
        $arr   = $mytree->getAllChildId($sel_id);
228
        $size  = count($arr);
229
        for ($i = 0; $i < $size; ++$i) {
230
            if (in_array($arr[$i], $categories)) {
231
                $query2 = 'SELECT SQL_CACHE count(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE cid=' . (int)$arr[$i] . " and valid='Yes' AND status!='1'";
232
233
                $result2 = $xoopsDB->query($query2);
234
                list($thing) = $xoopsDB->fetchRow($result2);
235
                $count += $thing;
236
            }
237
        }
238
    }
239
240
    return $count;
241
}
242
243
/**
244
 * @param $permtype
245
 *
246
 * @return mixed
247
 */
248
function adslight_MygetItemIds($permtype)
249
{
250
    global $xoopsUser, $moduleDirName;
1 ignored issue
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...
251
    static $permissions = array();
252
    if (is_array($permissions) && array_key_exists($permtype, $permissions)) {
253
        return $permissions[$permtype];
254
    }
255
256
    /** @var XoopsModuleHandler $moduleHandler */
257
    $moduleHandler          = xoops_getHandler('module');
258
    $myModule               = $moduleHandler->getByDirname('adslight');
259
    $groups                 = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
260
    $gperm_handler          = xoops_getHandler('groupperm');
261
    $categories             = $gperm_handler->getItemIds($permtype, $groups, $myModule->getVar('mid'));
262
    $permissions[$permtype] = $categories;
263
264
    return $categories;
265
}
266
267
/**
268
 * @param        $option
269
 * @param string $repmodule
270
 *
271
 * @return bool
272
 */
273
function adslight_getmoduleoption($option, $repmodule = 'adslight')
1 ignored issue
show
Coding Style introduced by
adslight_getmoduleoption uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
274
{
275
    global $xoopsModuleConfig, $xoopsModule;
1 ignored issue
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...
276
    static $tbloptions = array();
277
    if (is_array($tbloptions) && array_key_exists($option, $tbloptions)) {
278
        return $tbloptions[$option];
279
    }
280
281
    $retval = false;
282
    if (isset($xoopsModuleConfig)
283
        && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule
284
            && $xoopsModule->getVar('isactive'))
285
    ) {
286
        if (isset($xoopsModuleConfig[$option])) {
287
            $retval = $xoopsModuleConfig[$option];
288
        }
289
    } else {
290
        /** @var XoopsModuleHandler $moduleHandler */
291
        $moduleHandler  = xoops_getHandler('module');
292
        $module         = $moduleHandler->getByDirname($repmodule);
293
        $config_handler = xoops_getHandler('config');
294
        if ($module) {
295
            $moduleConfig =& $config_handler->getConfigsByCat(0, $GLOBALS['xoopsModule']->getVar('mid'));
296
            if (isset($moduleConfig[$option])) {
297
                $retval = $moduleConfig[$option];
298
            }
299
        }
300
    }
301
    $tbloptions[$option] = $retval;
302
303
    return $retval;
304
}
305
306
function ShowImg()
307
{
308
    global $moduleDirName;
1 ignored issue
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...
309
    echo "<script type=\"text/javascript\">\n";
310
    echo "<!--\n\n";
311
    echo "function showimage() {\n";
312
    echo "if (!document.images)\n";
313
    echo "return\n";
314
    echo "document.images.avatar.src=\n";
315
    echo "'" . XOOPS_URL . "/modules/adslight/assets/images/img_cat/' + document.imcat.img.options[document.imcat.img.selectedIndex].value\n";
316
    echo "}\n\n";
317
    echo "//-->\n";
318
    echo "</script>\n";
319
}
320
321
//Reusable Link Sorting Functions
322
/**
323
 * @param $orderby
324
 *
325
 * @return string
326
 */
327
function adslight_convertorderbyin($orderby)
328
{
329
    switch (trim($orderby)) {
330
        case 'titleA':
331
            $orderby = 'title ASC';
332
            break;
333
        case 'dateA':
334
            $orderby = 'date ASC';
335
            break;
336
        case 'hitsA':
337
            $orderby = 'hits ASC';
338
            break;
339
        case 'priceA':
340
            $orderby = 'price ASC';
341
            break;
342
        case 'titleD':
343
            $orderby = 'title DESC';
344
            break;
345
        case 'hitsD':
346
            $orderby = 'hits DESC';
347
            break;
348
        case 'priceD':
349
            $orderby = 'price DESC';
350
            break;
351
        case'dateD':
0 ignored issues
show
Coding Style introduced by
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
352
        default:
353
            $orderby = 'date DESC';
354
            break;
355
    }
356
357
    return $orderby;
358
}
359
360
/**
361
 * @param $orderby
362
 *
363
 * @return string
364
 */
365
function adslight_convertorderbytrans($orderby)
366
{
367
    global $main_lang;
1 ignored issue
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...
368
369
    if ($orderby === 'hits ASC') {
370
        $orderbyTrans = '' . _ADSLIGHT_POPULARITYLTOM . '';
371
    }
372
    if ($orderby === 'hits DESC') {
373
        $orderbyTrans = '' . _ADSLIGHT_POPULARITYMTOL . '';
374
    }
375
    if ($orderby === 'title ASC') {
376
        $orderbyTrans = '' . _ADSLIGHT_TITLEATOZ . '';
377
    }
378
    if ($orderby === 'title DESC') {
379
        $orderbyTrans = '' . _ADSLIGHT_TITLEZTOA . '';
380
    }
381
    if ($orderby === 'date ASC') {
382
        $orderbyTrans = '' . _ADSLIGHT_DATEOLD . '';
383
    }
384
    if ($orderby === 'date DESC') {
385
        $orderbyTrans = '' . _ADSLIGHT_DATENEW . '';
386
    }
387
    if ($orderby === 'price ASC') {
388
        $orderbyTrans = _ADSLIGHT_PRICELTOH;
389
    }
390
    if ($orderby === 'price DESC') {
391
        $orderbyTrans = '' . _ADSLIGHT_PRICEHTOL . '';
392
    }
393
394
    return $orderbyTrans;
0 ignored issues
show
Bug introduced by
The variable $orderbyTrans does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
395
}
396
397
/**
398
 * @param $orderby
399
 *
400
 * @return string
401
 */
402
function adslight_convertorderbyout($orderby)
403
{
404
    if ($orderby === 'title ASC') {
405
        $orderby = 'titleA';
406
    }
407
    if ($orderby === 'date ASC') {
408
        $orderby = 'dateA';
409
    }
410
    if ($orderby === 'hits ASC') {
411
        $orderby = 'hitsA';
412
    }
413
    if ($orderby === 'price ASC') {
414
        $orderby = 'priceA';
415
    }
416
    if ($orderby === 'title DESC') {
417
        $orderby = 'titleD';
418
    }
419
    if ($orderby === 'date DESC') {
420
        $orderby = 'dateD';
421
    }
422
    if ($orderby === 'hits DESC') {
423
        $orderby = 'hitsD';
424
    }
425
    if ($orderby === 'price DESC') {
426
        $orderby = 'priceD';
427
    }
428
429
    return $orderby;
430
}
431
432
/**
433
 * @param        $caption
434
 * @param        $name
435
 * @param string $value
436
 * @param string $width
437
 * @param string $height
438
 * @param string $supplemental
439
 *
440
 * @return bool|XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinymce
0 ignored issues
show
Documentation introduced by
Should the return type not be XoopsFormTinymce|XoopsFo...sFormKoivi|FormTextArea?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
441
 */
442 View Code Duplication
function adslight_getEditor($caption, $name, $value = '', $width = '100%', $height = '300px', $supplemental = '')
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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.

Loading history...
443
{
444
    global $xoopsModuleConfig, $moduleDirName;
1 ignored issue
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...
445
    $editor = false;
0 ignored issues
show
Unused Code introduced by
$editor 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...
446
    $x22    = false;
447
    $xv     = str_replace('XOOPS ', '', XOOPS_VERSION);
448
    if (substr($xv, 2, 1) == '2') {
449
        $x22 = true;
450
    }
451
    $editor_configs           = array();
452
    $editor_configs['name']   = $name;
453
    $editor_configs['value']  = $value;
454
    $editor_configs['rows']   = 25;
455
    $editor_configs['cols']   = 80;
456
    $editor_configs['width']  = '100%';
457
    $editor_configs['height'] = '300px';
458
459
    switch (strtolower($xoopsModuleConfig['adslight_form_options'])) {
460
461
        case 'tinymce' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
462
            if (!$x22) {
463
                if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinymce/formtinymce.php')) {
464
                    include_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinymce/formtinymce.php';
465
                    $editor = new XoopsFormTinymce(array(
466
                                                       'caption' => $caption,
467
                                                       'name'    => $name,
468
                                                       'value'   => $value,
469
                                                       'width'   => '100%',
470
                                                       'height'  => '300px'
471
                                                   ));
472
                } else {
473
                    if ($dhtml) {
0 ignored issues
show
Bug introduced by
The variable $dhtml does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
474
                        $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
475
                    } else {
476
                        $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
477
                    }
478
                }
479
            } else {
480
                $editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs);
481
            }
482
            break;
483
484
        case 'fckeditor' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
485
            if (!$x22) {
486
                if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) {
487
                    include_once XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php';
488
                    $editor = new XoopsFormFckeditor($editor_configs, true);
489
                } else {
490
                    if ($dhtml) {
491
                        $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
492
                    } else {
493
                        $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
494
                    }
495
                }
496
            } else {
497
                $editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs);
498
            }
499
            break;
500
501
        case 'koivi' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
502
            if (!$x22) {
503
                if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/koivi/formkoivi.php')) {
504
                    include_once XOOPS_ROOT_PATH . '/class/xoopseditor/koivi/formkoivi.php';
505
                    include_once XOOPS_ROOT_PATH . '/class/xoopseditor/koivi/language/english.php';
506
                    $editor = new XoopsFormKoivi($editor_configs, true);
507
                } else {
508
                    if ($dhtml) {
509
                        $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
510
                    } else {
511
                        $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
512
                    }
513
                }
514
            } else {
515
                $editor = new XoopsFormEditor($caption, 'koivi', $editor_configs);
516
            }
517
            break;
518
519
        case 'textarea':
520
            if (!$x22) {
521
                if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/textarea/textarea.php')) {
522
                    include_once XOOPS_ROOT_PATH . '/class/xoopseditor/textarea/textarea.php';
523
                    $editor = new FormTextArea($caption, $name, $value);
524
                } else {
525
                    if ($dhtml) {
526
                        $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
527
                    } else {
528
                        $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
529
                    }
530
                }
531
            } else {
532
                $editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs);
533
            }
534
            break;
535
536
        default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
537
            //        if ($dhtml) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
538
            include_once XOOPS_ROOT_PATH . '/class/xoopseditor/dhtmltextarea/dhtmltextarea.php';
539
            $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 40, $supplemental);
540
            //       } else {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
541
            //           $editor = new XoopsFormEditor($caption, 'dhtmltextarea', $editor_configs);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
542
            //       }
543
544
            break;
545
    }
546
547
    return $editor;
548
}
549
550
/**
551
 * @param        $caption
552
 * @param        $name
553
 * @param string $value
554
 * @param string $width
555
 * @param string $height
556
 * @param string $supplemental
557
 *
558
 * @return bool|XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinymce
0 ignored issues
show
Documentation introduced by
Should the return type not be XoopsFormTinymce|XoopsFo...sFormKoivi|FormTextArea?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
559
 */
560 View Code Duplication
function adslight_adminEditor($caption, $name, $value = '', $width = '100%', $height = '300px', $supplemental = '')
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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.

Loading history...
561
{
562
    global $xoopsModuleConfig, $moduleDirName;
1 ignored issue
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...
563
    $editor = false;
0 ignored issues
show
Unused Code introduced by
$editor 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...
564
    $x22    = false;
565
    $xv     = str_replace('XOOPS ', '', XOOPS_VERSION);
566
    if (substr($xv, 2, 1) == '2') {
567
        $x22 = true;
568
    }
569
    $editor_configs           = array();
570
    $editor_configs['name']   = $name;
571
    $editor_configs['value']  = $value;
572
    $editor_configs['rows']   = 35;
573
    $editor_configs['cols']   = 60;
574
    $editor_configs['width']  = '100%';
575
    $editor_configs['height'] = '300px';
576
577
    switch (strtolower($xoopsModuleConfig['adslight_admin_editor'])) {
578
579
        case 'tinymce' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
580
            if (!$x22) {
581
                if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinymce/formtinymce.php')) {
582
                    include_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinymce/formtinymce.php';
583
                    $editor = new XoopsFormTinymce(array(
584
                                                       'caption' => $caption,
585
                                                       'name'    => $name,
586
                                                       'value'   => $value,
587
                                                       'width'   => '100%',
588
                                                       'height'  => '300px'
589
                                                   ));
590
                } else {
591
                    if ($dhtml) {
0 ignored issues
show
Bug introduced by
The variable $dhtml does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
592
                        $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
593
                    } else {
594
                        $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
595
                    }
596
                }
597
            } else {
598
                $editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs);
599
            }
600
            break;
601
602
        case 'fckeditor' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
603
            if (!$x22) {
604
                if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) {
605
                    include_once XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php';
606
                    $editor = new XoopsFormFckeditor($editor_configs, true);
607
                } else {
608
                    if ($dhtml) {
609
                        $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
610
                    } else {
611
                        $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
612
                    }
613
                }
614
            } else {
615
                $editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs);
616
            }
617
            break;
618
619
        case 'koivi' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
620
            if (!$x22) {
621
                if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/koivi/formkoivi.php')) {
622
                    include_once XOOPS_ROOT_PATH . '/class/xoopseditor/koivi/formkoivi.php';
623
                    include_once XOOPS_ROOT_PATH . '/class/xoopseditor/koivi/language/english.php';
624
                    $editor = new XoopsFormKoivi($editor_configs, true);
625
                } else {
626
                    if ($dhtml) {
627
                        $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
628
                    } else {
629
                        $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
630
                    }
631
                }
632
            } else {
633
                $editor = new XoopsFormEditor($caption, 'koivi', $editor_configs);
634
            }
635
            break;
636
637
        case 'textarea':
638
            if (!$x22) {
639
                if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/textarea/textarea.php')) {
640
                    include_once XOOPS_ROOT_PATH . '/class/xoopseditor/textarea/textarea.php';
641
                    $editor = new FormTextArea($caption, $name, $value);
642
                } else {
643
                    if ($dhtml) {
644
                        $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
645
                    } else {
646
                        $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
647
                    }
648
                }
649
            } else {
650
                $editor = new XoopsFormEditor($caption, 'textarea', $editor_configs);
651
            }
652
            break;
653
654
        default :
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
655
656
            include_once XOOPS_ROOT_PATH . '/class/xoopseditor/dhtmltextarea/dhtmltextarea.php';
657
            $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 40, $supplemental);
658
659
            break;
660
    }
661
662
    return $editor;
663
}
664
665
/**
666
 * @param $tablename
667
 *
668
 * @return bool
669
 */
670
function jlm_ads_TableExists($tablename)
671
{
672
    global $xoopsDB;
1 ignored issue
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...
673
    $result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'");
674
675
    return ($xoopsDB->getRowsNum($result) > 0);
676
}
677
678
/**
679
 * @param $fieldname
680
 * @param $table
681
 *
682
 * @return bool
683
 */
684
function jlm_ads_FieldExists($fieldname, $table)
685
{
686
    global $xoopsDB;
1 ignored issue
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...
687
    $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'");
688
689
    return ($xoopsDB->getRowsNum($result) > 0);
690
}
691
692
/**
693
 * @param $field
694
 * @param $table
695
 *
696
 * @return mixed
697
 */
698
function jlm_ads_AddField($field, $table)
699
{
700
    global $xoopsDB;
1 ignored issue
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...
701
    $result = $xoopsDB->queryF('ALTER TABLE ' . $table . " ADD $field;");
702
703
    return $result;
704
}
705
706
/**
707
 * @param $cid
708
 *
709
 * @return bool
710
 */
711
function adslight_getCatNameFromId($cid)
712
{
713
    global $xoopsDB, $xoopsConfig, $myts, $xoopsUser, $moduleDirName;
1 ignored issue
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...
714
715
    $sql = 'SELECT SQL_CACHE title FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid = '$cid'";
716
717
    if (!$result = $xoopsDB->query($sql)) {
718
        return false;
719
    }
720
721
    if (!$arr = $xoopsDB->fetchArray($result)) {
722
        return false;
723
    }
724
725
    $title = $arr['title'];
726
727
    return $title;
728
}
729
730
/**
731
 * @return mixed
732
 */
733 View Code Duplication
function adslight_gocategory()
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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.

Loading history...
734
{
735
    global $xoopsDB;
1 ignored issue
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...
736
737
    $xt   = new XoopsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
738
    $jump = XOOPS_URL . '/modules/adslight/viewcats.php?cid=';
739
    ob_start();
740
    $xt->makeMySelBox('title', 'title', 0, 1, 'pid', "location=\"" . $jump . "\"+this.options[this.selectedIndex].value");
741
    $block['selectbox'] = ob_get_contents();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$block was never initialized. Although not strictly required by PHP, it is generally a good practice to add $block = 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...
742
    ob_end_clean();
743
744
    return $block;
745
}
746
747
// ADSLIGHT Version 2 //
748
// Fonction rss.php RSS par categories
749
/**
750
 * @return array
751
 */
752
function returnAllAdsRss()
0 ignored issues
show
Coding Style introduced by
returnAllAdsRss uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
753
{
754
    global $xoopsDB, $xoopsModuleConfig, $xoopsUser;
1 ignored issue
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...
755
756
    $cid = !isset($_GET['cid']) ? null : $_GET['cid'];
757
758
    $result = array();
759
760
    $sql = 'SELECT lid, title, price, date, town FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='yes' AND cid=" . $xoopsDB->escape($cid) . ' ORDER BY date DESC';
761
762
    $resultValues = $xoopsDB->query($sql);
763
    while (($resultTemp = $xoopsDB->fetchBoth($resultValues)) !== false) {
764
        array_push($result, $resultTemp);
765
    }
766
767
    return $result;
768
}
769
770
// Fonction fluxrss.php RSS Global
771
/**
772
 * @return array
773
 */
774
function returnAllAdsFluxRss()
775
{
776
    global $xoopsDB, $xoopsModuleConfig, $xoopsUser;
1 ignored issue
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...
777
778
    $result = array();
779
780
    $sql = 'SELECT lid, title, price, desctext, date, town FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='yes' ORDER BY date DESC LIMIT 0,15";
781
782
    $resultValues = $xoopsDB->query($sql);
783
    while (($resultTemp = $xoopsDB->fetchBoth($resultValues)) !== false) {
784
        array_push($result, $resultTemp);
785
    }
786
787
    return $result;
788
}
789
790
/**
791
 * @param $type
792
 *
793
 * @return mixed
794
 */
795
function adslight_NameType($type)
796
{
797
    global $xoopsDB;
1 ignored issue
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...
798
    $sql = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' WHERE id_type=' . $xoopsDB->escape($type) . '');
799
    list($nom_type) = $xoopsDB->fetchRow($sql);
800
801
    return $nom_type;
802
}
803
804
/**
805
 * @param $format
806
 * @param $number
807
 *
808
 * @return mixed
809
 */
810
function money_format($format, $number)
811
{
812
    $regex = '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?' . '(?:#([0-9]+))?(?:\.([0-9]+))?([in%])/';
813
    if (setlocale(LC_MONETARY, 0) === 'C') {
814
        setlocale(LC_MONETARY, '');
815
    }
816
817
    setlocale(LC_ALL, 'en_US');
818
    $locale = localeconv();
819
    preg_match_all($regex, $format, $matches, PREG_SET_ORDER);
820
    foreach ($matches as $fmatch) {
0 ignored issues
show
Bug introduced by
The expression $matches of type null|array<integer,array<integer,string>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
821
        $value      = (float)$number;
822
        $flags      = array(
823
            'fillchar'  => preg_match('/\=(.)/', $fmatch[1], $match) ? $match[1] : ' ',
824
            'nogroup'   => preg_match('/\^/', $fmatch[1]) > 0,
825
            'usesignal' => preg_match('/\+|\(/', $fmatch[1], $match) ? $match[0] : '+',
826
            'nosimbol'  => preg_match('/\!/', $fmatch[1]) > 0,
827
            'isleft'    => preg_match('/\-/', $fmatch[1]) > 0
828
        );
829
        $width      = trim($fmatch[2]) ? (int)$fmatch[2] : 0;
830
        $left       = trim($fmatch[3]) ? (int)$fmatch[3] : 0;
831
        $right      = trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits'];
832
        $conversion = $fmatch[5];
833
834
        $positive = true;
835
        if ($value < 0) {
836
            $positive = false;
837
            $value *= -1;
838
        }
839
        $letter = $positive ? 'p' : 'n';
840
841
        $prefix = $suffix = $cprefix = $csuffix = $signal = '';
0 ignored issues
show
Unused Code introduced by
$signal 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...
842
843
        $signal = $positive ? $locale['positive_sign'] : $locale['negative_sign'];
844
        switch (true) {
845 View Code Duplication
            case $locale["{$letter}_sign_posn"] == 1 && $flags['usesignal'] == '+':
1 ignored issue
show
Duplication introduced by
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.

Loading history...
846
                $prefix = $signal;
847
                break;
848 View Code Duplication
            case $locale["{$letter}_sign_posn"] == 2 && $flags['usesignal'] == '+':
1 ignored issue
show
Duplication introduced by
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.

Loading history...
849
                $suffix = $signal;
850
                break;
851 View Code Duplication
            case $locale["{$letter}_sign_posn"] == 3 && $flags['usesignal'] == '+':
1 ignored issue
show
Duplication introduced by
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.

Loading history...
852
                $cprefix = $signal;
853
                break;
854 View Code Duplication
            case $locale["{$letter}_sign_posn"] == 4 && $flags['usesignal'] == '+':
1 ignored issue
show
Duplication introduced by
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.

Loading history...
855
                $csuffix = $signal;
856
                break;
857
            case $flags['usesignal'] === '(':
858
            case $locale["{$letter}_sign_posn"] == 0:
859
                $prefix = '(';
860
                $suffix = ')';
861
                break;
862
        }
863
        if (!$flags['nosimbol']) {
864
            $currency = $cprefix . ($conversion === 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']) . $csuffix;
865
        } else {
866
            $currency = '';
867
        }
868
        $space = $locale["{$letter}_sep_by_space"] ? ' ' : '';
869
870
        $value = number_format($value, $right, $locale['mon_decimal_point'], $flags['nogroup'] ? '' : $locale['mon_thousands_sep']);
871
        $value = @explode($locale['mon_decimal_point'], $value);
872
873
        $n = strlen($prefix) + strlen($currency) + strlen($value[0]);
874
        if ($left > 0 && $left > $n) {
875
            $value[0] = str_repeat($flags['fillchar'], $left - $n) . $value[0];
876
        }
877
        $value = implode($locale['mon_decimal_point'], $value);
878
        if ($locale["{$letter}_cs_precedes"]) {
879
            $value = $prefix . $currency . $space . $value . $suffix;
880
        } else {
881
            $value = $prefix . $value . $space . $currency . $suffix;
882
        }
883
        if ($width > 0) {
884
            $value = str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ? STR_PAD_RIGHT : STR_PAD_LEFT);
885
        }
886
887
        $format = str_replace($fmatch[0], $value, $format);
888
    }
889
890
    return $format;
891
}
892