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

viewcats.php ➔ Adsview()   F

Complexity

Conditions 56
Paths > 20000

Size

Total Lines 404
Code Lines 293

Duplication

Lines 88
Ratio 21.78 %

Importance

Changes 0
Metric Value
cc 56
eloc 293
nc 387072
nop 4
dl 88
loc 404
rs 2
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 62 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
include_once __DIR__ . '/header.php';
24
require XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php';
25
xoops_load('XoopsLocal');
26
$myts      = MyTextSanitizer::getInstance();
27
$module_id = $xoopsModule->getVar('mid');
28
29
if (is_object($xoopsUser)) {
30
    $groups = $xoopsUser->getGroups();
31
} else {
32
    $groups = XOOPS_GROUP_ANONYMOUS;
33
}
34
$gperm_handler = xoops_getHandler('groupperm');
35
if (isset($_POST['item_id'])) {
36
    $perm_itemid = (int)$_POST['item_id'];
37
} else {
38
    $perm_itemid = 0;
39
}
40
41 View Code Duplication
if (!$gperm_handler->checkRight('adslight_view', $perm_itemid, $groups, $module_id)) {
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...
42
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
43
}
44
if (!$gperm_handler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) {
45
    $prem_perm = '0';
46
} else {
47
    $prem_perm = '1';
48
}
49
50
include XOOPS_ROOT_PATH . '/modules/adslight/class/classifiedstree.php';
51
include XOOPS_ROOT_PATH . '/modules/adslight/include/functions.php';
52
$mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
53
54
#  function view (categories)
55
#####################################################
56
/**
57
 * @param int $cid
58
 * @param int $min
59
 * @param     $orderby
60
 * @param int $show
61
 */
62
function Adsview($cid = 0, $min = 0, $orderby, $show = 0)
1 ignored issue
show
Coding Style introduced by
Adsview 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...
63
{
64
    global $xoopsDB, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsModuleConfig, $myts, $mytree, $imagecat, $meta, $moduleDirName, $main_lang, $xoopsUser, $mid, $prem_perm, $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...
65
    $pathIcon16 = $xoopsModule->getInfo('icons16');
66
67
    $GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
68
    include XOOPS_ROOT_PATH . '/header.php';
69
70
    $xoopsTpl->assign('xmid', $xoopsModule->getVar('mid'));
71
    $xoopsTpl->assign('add_from', _ADSLIGHT_ADDFROM . ' ' . $xoopsConfig['sitename']);
72
    $xoopsTpl->assign('add_from_title', _ADSLIGHT_ADDFROM);
73
    $xoopsTpl->assign('add_from_sitename', $xoopsConfig['sitename']);
74
    $xoopsTpl->assign('only_pix', _ADSLIGHT_ONLYPIX);
75
    $xoopsTpl->assign('adslight_logolink', _ADSLIGHT_LOGOLINK);
76
    $xoopsTpl->assign('permit', $prem_perm);
77
78
    $xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/style/adslight.css" type="text/css" media="all" />');
79
80
    // $adslight_use_catscode = $xoopsModuleConfig['adslight_use_catscode'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
81
    // $adslight_cats_code = $xoopsModuleConfig['adslight_cats_code'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
82
83
    $xoopsTpl->assign('adslight_use_catscode', $xoopsModuleConfig['adslight_use_catscode']);
84
    $xoopsTpl->assign('adslight_cats_code', $xoopsModuleConfig['adslight_cats_code']);
85
86
    $banner = xoops_getbanner();
87
    $xoopsTpl->assign('banner', $banner);
88
    // $index_code_place = $xoopsModuleConfig['adslight_index_code_place'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
89
    // $use_extra_code = $xoopsModuleConfig['adslight_use_index_code'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
90
    // $adslight_use_banner = $xoopsModuleConfig['adslight_use_banner'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
91
    // $index_extra_code = $xoopsModuleConfig['adslight_index_code'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
92
93
    $xoopsTpl->assign('use_extra_code', $xoopsModuleConfig['adslight_use_index_code']);
94
    $xoopsTpl->assign('adslight_use_banner', $xoopsModuleConfig['adslight_use_banner']);
95
    $xoopsTpl->assign('index_extra_code', $xoopsModuleConfig['adslight_index_code']);
96
    $xoopsTpl->assign('index_code_place', $xoopsModuleConfig['adslight_index_code_place']);
97
98
    // adslight 2
99
    $xoopsTpl->assign('adslight_active_menu', $xoopsModuleConfig['adslight_active_menu']);
100
    $xoopsTpl->assign('adslight_active_rss', $xoopsModuleConfig['adslight_active_rss']);
101
102
    /// No Adds in this Cat ///
103
    $submit_perms = adslight_MygetItemIds('adslight_submit');
104
105
    if ($xoopsUser && is_array($submit_perms) && count($submit_perms) > 0) {
106
        $xoopsTpl->assign('not_adds_in_this_cat',
107
                          '' . _ADSLIGHT_ADD_LISTING_NOTADDSINTHISCAT . '<a href="addlisting.php?cid=' . addslashes($cid) . '">' . _ADSLIGHT_ADD_LISTING_NOTADDSSUBMIT . '</a>');
108
    } else {
109
        $xoopsTpl->assign('not_adds_in_this_cat',
110
                          '' . _ADSLIGHT_ADD_LISTING_NOTADDSINTHISCAT . '<br>' . _ADSLIGHT_ADD_LISTING_BULL . '<a href="' . XOOPS_URL . '/register.php">' . _ADSLIGHT_ADD_LISTING_SUB . '</a>.');
111
    }
112
113
    $xoopsTpl->assign('Feed_RSS_cat', '&nbsp;&nbsp;&nbsp;<a href="rss.php?cid=' . addslashes($cid) . '"><img border="0" alt="Feed RSS" src="assets/images/rssfeed_buttons.png" /></a>');
114
115 View Code Duplication
    if ($xoopsUser) {
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
        $member_usid = $xoopsUser->getVar('uid');
117
        if ($usid = $member_usid) {
118
            $xoopsTpl->assign('istheirs', true);
119
120
            list($show_user) = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE usid=' . $member_usid . ''));
121
122
            $xoopsTpl->assign('show_user', $show_user);
123
            $xoopsTpl->assign('show_user_link', 'members.php?usid=' . $member_usid . '');
124
        }
125
    }
126
127
    $default_sort = $xoopsModuleConfig['adslight_lsort_order'];
128
129
    $cid     = ((int)$cid > 0) ? (int)$cid : 0;
130
    $min     = ((int)$min > 0) ? (int)$min : 0;
131
    $show    = ((int)$show > 0) ? (int)$show : $xoopsModuleConfig['adslight_perpage'];
132
    $max     = $min + $show;
133
    $orderby = isset($orderby) ? adslight_convertorderbyin($orderby) : $default_sort;
134
135
    $updir = $xoopsModuleConfig['adslight_link_upload'];
0 ignored issues
show
Unused Code introduced by
$updir 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...
136
    $xoopsTpl->assign('add_from', _ADSLIGHT_ADDFROM . ' ' . $xoopsConfig['sitename']);
137
    $xoopsTpl->assign('add_from_title', _ADSLIGHT_ADDFROM);
138
    $xoopsTpl->assign('add_from_sitename', $xoopsConfig['sitename']);
139
    $xoopsTpl->assign('subcat_title2', _ADSLIGHT_ANNONCES);
140
141
    $categories = adslight_MygetItemIds('adslight_view');
142 View Code Duplication
    if (is_array($categories) && count($categories) > 0) {
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...
143
        if (!in_array($cid, $categories)) {
144
            redirect_header(XOOPS_URL . '/modules/adslight/index.php', 3, _NOPERM);
145
        }
146
    } else {    // User can't see any category
147
        redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
148
    }
149
150
    $arrow = '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/arrow.gif" alt="&raquo;" />';
0 ignored issues
show
Unused Code introduced by
$arrow 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...
151
152
    $pathstring = '<a href="index.php">' . _ADSLIGHT_MAIN . '</a>';
153
    $pathstring .= $mytree->getNicePathFromId($cid, 'title', 'viewcats.php?');
154
    $xoopsTpl->assign('module_name', $xoopsModule->getVar('name'));
155
    $xoopsTpl->assign('category_path', $pathstring);
156
    $xoopsTpl->assign('category_id', $cid);
157
158
    $countresult = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE  cid=' . $xoopsDB->escape($cid) . ' AND valid="Yes" AND status!="1"');
159
    list($trow) = $xoopsDB->fetchRow($countresult);
160
    $trows = $trow;
161
162
    $cat_perms = '';
163
    if (is_array($categories) && count($categories) > 0) {
164
        $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
165
    }
166
167
    $result = $xoopsDB->query('SELECT cid, pid, title, cat_desc, cat_keywords FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . $xoopsDB->escape($cid) . ' ' . $cat_perms . '');
168
    list($cid, $pid, $title, $cat_desc, $cat_keywords) = $xoopsDB->fetchRow($result);
169
170
    $xoopsTpl->assign('cat_desc', $cat_desc);
171
    $xoopsTpl->assign('cat_title', _ADSLIGHT_ANNONCES . ' ' . $title);
172
    $xoopsTpl->assign('cat_keywords', $cat_keywords);
173
    $xoopsTpl->assign('xoops_pagetitle', $title);
174
175
    if ($cat_desc > '0') {
176
        // meta description & keywords tags for categories
177
        $cat_desc_clean     = strip_tags($cat_desc, '<font><img><strong><i><u>');
178
        $cat_keywords_clean = strip_tags($cat_keywords, '<font><img><strong><i><u><br><li>');
179
180
        $xoTheme->addMeta('meta', 'description', '' . substr($cat_desc_clean, 0, 200));
0 ignored issues
show
Bug introduced by
The variable $xoTheme 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...
181
        $xoTheme->addMeta('meta', 'keywords', '' . substr($cat_keywords_clean, 0, 1000));
182
    }
183
184
    $submit_perms = adslight_MygetItemIds('adslight_submit');
185
    if ($xoopsUser && is_array($submit_perms) && count($submit_perms) > 0) {
186
        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULLCATS . '<a href="addlisting.php?cid=' . addslashes($cid) . '">' . _ADSLIGHT_ADD_LISTING_SUBOK . '</a>
187
';
188
    } else {    // User can't see any category
189
        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULLCATSOK . '<a href="' . XOOPS_URL . '/register.php">' . _ADSLIGHT_ADD_LISTING_SUB . '</a>.
190
';
191
    }
192
193
    if ($xoopsModuleConfig['adslight_main_cat'] == 1 || $pid != 0) {
194
        $xoopsTpl->assign('bullinfotext', $add_listing);
195
    }
196
197
    $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...
198
    $arr = $mytree->getFirstChild($cid, 'title');
199
200
    if (count($arr) > 0) {
201
        $scount = 1;
202
        foreach ($arr as $ele) {
203
            if (in_array($ele['cid'], $categories)) {
204
                $sub_arr         = array();
0 ignored issues
show
Unused Code introduced by
$sub_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...
205
                $sub_arr         = $mytree->getFirstChild($ele['cid'], 'title');
206
                $space           = 0;
207
                $chcount         = 0;
208
                $infercategories = '';
209
                $totallisting    = adslight_getTotalItems($ele['cid'], 1);
210
                foreach ($sub_arr as $sub_ele) {
211
                    if (in_array($sub_ele['cid'], $categories)) {
212
                        $chtitle = $myts->htmlSpecialChars($sub_ele['title']);
213
214
                        if ($chcount > 5) {
215
                            $infercategories .= '...';
216
                            break;
217
                        }
218
                        if ($space > 0) {
219
                            $infercategories .= ', ';
220
                        }
221
                        $infercategories .= '<a href="' . XOOPS_URL . '/modules/adslight/viewcats.php?cid=' . $sub_ele['cid'] . '">' . $chtitle . '</a>';
222
223
                        $infercategories .= '&nbsp;(' . adslight_getTotalItems($sub_ele['cid']) . ')';
224
                        $infercategories .= '&nbsp;' . categorynewgraphic($sub_ele['cid']) . '';
225
                        ++$space;
226
                        ++$chcount;
227
                    }
228
                }
229
230
                $xoopsTpl->append('subcategories', array(
231
                    'title'           => $myts->htmlSpecialChars($ele['title']),
232
                    'id'              => $ele['cid'],
233
                    'infercategories' => $infercategories,
234
                    'totallisting'    => $totallisting,
235
                    ''
236
                ));
237
238
                ++$scount;
239
                $xoopsTpl->assign('lang_subcat', _ADSLIGHT_AVAILAB);
240
            }
241
        }
242
    }
243
244
    $pagenav = '';
245
    if ($trows > '0') {
246
        $xoopsTpl->assign('last_head', _ADSLIGHT_THE . ' ' . $xoopsModuleConfig['adslight_newcount'] . ' ' . _ADSLIGHT_LASTADD);
247
        $xoopsTpl->assign('last_head_title', _ADSLIGHT_TITLE);
248
        $xoopsTpl->assign('last_head_price', _ADSLIGHT_PRICE);
249
        $xoopsTpl->assign('last_head_date', _ADSLIGHT_DATE);
250
        $xoopsTpl->assign('last_head_local', _ADSLIGHT_LOCAL2);
251
        $xoopsTpl->assign('last_head_hits', _ADSLIGHT_VIEW);
252
        $xoopsTpl->assign('last_head_photo', _ADSLIGHT_PHOTO);
253
        $xoopsTpl->assign('cat', $cid);
254
        $xoopsTpl->assign('min', $min);
255
        $rank = 1;
256
257
        $cat_perms = '';
258
        if (is_array($categories) && count($categories) > 0) {
259
            $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
260
        }
261
262
        $sql     = 'SELECT lid, title, status, type, price, typeprice, date, town, country, contactby, usid, premium, valid, photo, hits FROM '
263
                   . $xoopsDB->prefix('adslight_listing')
264
                   . ' WHERE valid="Yes" and cid='
265
                   . $xoopsDB->escape($cid)
266
                   . ' AND status!="1" '
267
                   . $cat_perms
268
                   . ' ORDER BY '
269
                   . $orderby
270
                   . '';
271
        $result1 = $xoopsDB->query($sql, $show, $min);
272
        if ($trows > '1') {
273
            $xoopsTpl->assign('show_nav', true);
274
            $orderbyTrans = adslight_convertorderbytrans($orderby);
0 ignored issues
show
Unused Code introduced by
$orderbyTrans 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...
275
            $xoopsTpl->assign('lang_sortby', _ADSLIGHT_SORTBY);
276
            $xoopsTpl->assign('lang_title', _ADSLIGHT_TITLE);
277
            $xoopsTpl->assign('lang_titleatoz', _ADSLIGHT_TITLEATOZ);
278
            $xoopsTpl->assign('lang_titleztoa', _ADSLIGHT_TITLEZTOA);
279
            $xoopsTpl->assign('lang_date', _ADSLIGHT_DATE);
280
            $xoopsTpl->assign('lang_dateold', _ADSLIGHT_DATEOLD);
281
            $xoopsTpl->assign('lang_datenew', _ADSLIGHT_DATENEW);
282
            $xoopsTpl->assign('lang_price', _ADSLIGHT_PRICE);
283
            $xoopsTpl->assign('lang_priceltoh', '' . _ADSLIGHT_PRICELTOH . '');
284
            $xoopsTpl->assign('lang_pricehtol', '' . _ADSLIGHT_PRICEHTOL . '');
285
            $xoopsTpl->assign('lang_popularity', _ADSLIGHT_POPULARITY);
286
            $xoopsTpl->assign('lang_popularityleast', _ADSLIGHT_POPULARITYLTOM);
287
            $xoopsTpl->assign('lang_popularitymost', _ADSLIGHT_POPULARITYMTOL);
288
            $xoopsTpl->assign('lang_cursortedby', sprintf(_ADSLIGHT_CURSORTEDBY, adslight_convertorderbytrans($orderby)));
289
        }
290
291
        while (list($lid, $title, $status, $type, $price, $typeprice, $date, $town, $country, $contactby, $usid, $premium, $valid, $photo, $hits) = $xoopsDB->fetchRow($result1)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $premium 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...
Unused Code introduced by
The assignment to $valid 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...
292
            $a_item = array();
293
            $title  = $myts->htmlSpecialChars($title);
294
            $type   = $myts->htmlSpecialChars($type);
295
            //      $price = number_format($price, 2, ',', ' ');
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
296
            $town       = $myts->htmlSpecialChars($town);
297
            $country    = $myts->htmlSpecialChars($country);
298
            $contactby  = $myts->htmlSpecialChars($contactby);
299
            $useroffset = '';
300
301
            $newcount  = $xoopsModuleConfig['adslight_countday'];
302
            $startdate = (time() - (86400 * $newcount));
303 View Code Duplication
            if ($startdate < $date) {
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...
304
                $newitem       = '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/newred.gif" />';
305
                $a_item['new'] = $newitem;
306
            }
307 View Code Duplication
            if ($xoopsUser) {
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...
308
                $timezone = $xoopsUser->timezone();
309
                if (isset($timezone)) {
310
                    $useroffset = $xoopsUser->timezone();
311
                } else {
312
                    $useroffset = $xoopsConfig['default_TZ'];
313
                }
314
            }
315
            $date = ($useroffset * 3600) + $date;
316
            $date = formatTimestamp($date, 's');
317 View Code Duplication
            if ($xoopsUser) {
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...
318
                if ($xoopsUser->isAdmin()) {
319
                    $a_item['admin'] = '<a href="'
320
                                       . XOOPS_URL
321
                                       . '/modules/adslight/admin/validate_ads.php?op=ModifyAds&amp;lid='
322
                                       . $lid
323
                                       . '"><img src="'
324
                                       . $pathIcon16
325
                                       . '/edit.png'
326
                                       . '" border=0 alt="'
327
                                       . _ADSLIGHT_MODADMIN
328
                                       . '" title="'
329
                                       . _ADSLIGHT_MODADMIN
330
                                       . '"/></a>';
331
                }
332
            }
333
334
            $result7 = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' WHERE id_type=' . $xoopsDB->escape($type) . '');
335
            list($nom_type) = $xoopsDB->fetchRow($result7);
336
337
            $result8 = $xoopsDB->query('SELECT nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' WHERE id_price=' . $xoopsDB->escape($typeprice) . '');
338
            list($nom_price) = $xoopsDB->fetchRow($result8);
339
340
            $a_item['type']   = $myts->htmlSpecialChars($nom_type);
341
            $a_item['title']  = '<a href="viewads.php?lid=' . $lid . '"><strong>' . $title . '</strong></a>';
342
            $a_item['status'] = $status;
343
            if ($price > 0) {
344
345
                //          $a_item['price'] = $price. ' '. $xoopsModuleConfig['adslight_money'].'';
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
346
                $a_item['price']           = XoopsLocal::money_format('%.2n', $price);
347
                $a_item['price_typeprice'] = $myts->htmlSpecialChars($nom_price);
348
            }
349
            $a_item['date']  = $date;
350
            $a_item['local'] = '';
351
            if ($town) {
352
                $a_item['local'] .= $town;
353
            }
354
            $a_item['country'] = '';
355
            if ($country) {
356
                $a_item['country'] = $country;
357
            }
358
359
            $cat = addslashes($cid);
0 ignored issues
show
Unused Code introduced by
$cat 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...
360
            if ($status == 2) {
361
                $a_item['sold'] = _ADSLIGHT_RESERVEDMEMBER;
362
            }
363
364 View Code Duplication
            if ($xoopsModuleConfig['active_thumbscats'] > 0) {
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...
365
                $a_item['no_photo'] = '<a href="'
366
                                      . XOOPS_URL
367
                                      . '/modules/adslight/viewads.php?lid='
368
                                      . $lid
369
                                      . '"><img class="thumb" src="'
370
                                      . XOOPS_URL
371
                                      . '/modules/adslight/assets/images/nophoto.jpg" align="left" width="100px" alt="'
372
                                      . $title
373
                                      . '" /></a>';
374
375
                $updir   = $xoopsModuleConfig['adslight_link_upload'];
376
                $sql     = 'SELECT cod_img, lid, uid_owner, url FROM '
377
                           . $xoopsDB->prefix('adslight_pictures')
378
                           . ' WHERE  uid_owner='
379
                           . $xoopsDB->escape($usid)
380
                           . ' AND lid='
381
                           . $xoopsDB->escape($lid)
382
                           . ' ORDER BY date_added ASC limit 1';
383
                $resultp = $xoopsDB->query($sql);
384
385
                while (list($cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($resultp)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $cod_img 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...
Unused Code introduced by
The assignment to $pic_lid 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...
Unused Code introduced by
The assignment to $uid_owner 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...
386
                    if ($photo) {
387
                        $a_item['photo'] = '<a href="'
388
                                           . XOOPS_URL
389
                                           . '/modules/adslight/viewads.php?lid='
390
                                           . $lid
391
                                           . '"><img class="thumb" src="'
392
                                           . $updir
393
                                           . '/thumbs/thumb_'
394
                                           . $url
395
                                           . '" align="left" width="100px" alt="'
396
                                           . $title
397
                                           . '" /></a>';
398
                    }
399
                }
400
            } else {
401
                $a_item['no_photo'] = '<p><img src="' . XOOPS_URL . '/modules/adslight/assets/images/camera_nophoto.png" align="left" width="24" alt="' . $title . '" /></p>';
402
                $updir              = $xoopsModuleConfig['adslight_link_upload'];
0 ignored issues
show
Unused Code introduced by
$updir 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...
403
                $sql                = 'SELECT cod_img, lid, uid_owner, url FROM '
404
                                      . $xoopsDB->prefix('adslight_pictures')
405
                                      . ' WHERE  uid_owner='
406
                                      . $xoopsDB->escape($usid)
407
                                      . ' AND lid='
408
                                      . $xoopsDB->escape($lid)
409
                                      . ' ORDER BY date_added ASC limit 1';
410
                $resultp            = $xoopsDB->query($sql);
411
                while (list($cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($resultp)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $cod_img 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...
Unused Code introduced by
The assignment to $pic_lid 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...
Unused Code introduced by
The assignment to $uid_owner 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...
412
                    if ($photo) {
413
                        $a_item['photo'] = '<p><img src="' . XOOPS_URL . '/modules/adslight/assets/images/camera_photo.png" align="left" width="24" alt="' . $title . '" /></p>';
414
                    }
415
                }
416
            }
417
418
            $a_item['hits'] = $hits;
419
            ++$rank;
420
            $xoopsTpl->append('items', $a_item);
421
        }
422
423
        $cid = ((int)$cid > 0) ? (int)$cid : 0;
424
425
        $orderby   = adslight_convertorderbyout($orderby);
426
        $linkpages = ceil($trows / $show);
427
428
        //Page Numbering
429
        if ($linkpages != 1 && $linkpages != 0) {
430
            $prev = $min - $show;
431
            if ($prev >= 0) {
432
                $pagenav .= "<a href='viewcats.php?cid=$cid&min=$prev&orderby=$orderby&show=$show'><strong><u>&laquo;</u></strong></a> ";
433
            }
434
            $counter     = 1;
435
            $currentpage = ($max / $show);
436
            while ($counter <= $linkpages) {
437
                $mintemp = ($show * $counter) - $show;
438
                if ($counter == $currentpage) {
439
                    $pagenav .= "<strong>($counter)</strong> ";
440
                } else {
441
                    $pagenav .= "<a href='viewcats.php?cid=$cid&min=$mintemp&orderby=$orderby&show=$show'>$counter</a> ";
442
                }
443
                ++$counter;
444
            }
445
            if ($trows > $max) {
446
                $pagenav .= "<a href='viewcats.php?cid=$cid&min=$max&orderby=$orderby&show=$show'>";
447
                $pagenav .= '<strong><u>&raquo;</u></strong></a>';
448
            }
449
        }
450
    }
451
452
    $xoopsTpl->assign('nav_page', $pagenav);
453
454
    if (!$xoopsUser || $xoopsUser) {
455
        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...
456
457
        $xt   = new XoopsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
458
        $jump = XOOPS_URL . '/modules/adslight/viewcats.php?cid=';
459
        ob_start();
460
        $xt->makeMySelBox('title', 'title', $cid, 1, 'pid', "location=\"" . $jump . "\"+this.options[this.selectedIndex].value");
461
        $select_go_cats = ob_get_contents();
462
        ob_end_clean();
463
        $xoopsTpl->assign('select_go_cats', $select_go_cats);
464
    }
465
}
466
467
#  function categorynewgraphic
468
#####################################################
469
/**
470
 * @param $cid
471
 */
472
function categorynewgraphic($cid)
0 ignored issues
show
Unused Code introduced by
The parameter $cid 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...
Best Practice introduced by
The function categorynewgraphic() has been defined more than once; this definition is ignored, only the first definition in index.php (L375-378) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
473
{
474
    global $xoopsDB, $xoopsModuleConfig;
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...
475
}
476
477
######################################################
478
479
$pa      = !isset($_GET['pa']) ? null : $_GET['pa'];
480
$lid     = !isset($_GET['lid']) ? null : $_GET['lid'];
481
$cid     = !isset($_GET['cid']) ? null : $_GET['cid'];
482
$usid    = isset($_GET['usid']) ? $_GET['usid'] : '';
483
$min     = !isset($_GET['min']) ? null : $_GET['min'];
484
$show    = !isset($_GET['show']) ? null : $_GET['show'];
485
$orderby = !isset($_GET['orderby']) ? null : $_GET['orderby'];
486
487
switch ($pa) {
488
    default:
489
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
490
        Adsview($cid, $min, $orderby, $show);
491
        break;
492
}
493
include XOOPS_ROOT_PATH . '/footer.php';
494