Completed
Push — master ( 38bf19...25ce06 )
by Michael
02:36
created
Severity

Upgrade to new PHP Analysis Engine

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

1
<?php
2
/*
3
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By iluc user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.limonads.com
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
26
$myts      = MyTextSanitizer::getInstance();
27
$module_id = $xoopsModule->getVar('mid');
28
29
is_object($xoopsUser) ? $groups = $xoopsUser->getGroups() : $groups = XOOPS_GROUP_ANONYMOUS;
30
31
$gperm_handler = xoops_getHandler('groupperm');
32
33
isset($_POST['item_id']) ? $perm_itemid = (int)$_POST['item_id'] : $perm_itemid = 0;
34
35 View Code Duplication
if (!$gperm_handler->checkRight('adslight_view', $perm_itemid, $groups, $module_id)) {
36
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
37
}
38
39
(!$gperm_handler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) ? $prem_perm = '0' : $prem_perm = '1';
40
41
include XOOPS_ROOT_PATH . '/modules/adslight/class/classifiedstree.php';
42
include XOOPS_ROOT_PATH . '/modules/adslight/include/functions.php';
43
$mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
44
45
#  function index
46
#####################################################
47
function index()
48
{
49
    global $xoopsDB, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsUser, $xoopsTpl, $myts, $mytree, $meta, $mid, $moduleDirName, $main_lang, $prem_perm, $xoopsModule;
50
    $pathIcon16 = $xoopsModule->getInfo('icons16');
51
52
    $GLOBALS['xoopsOption']['template_main'] = 'adslight_index.tpl';
53
54
    include XOOPS_ROOT_PATH . '/header.php';
55
56
    $xoopsTpl->assign('xmid', $xoopsModule->getVar('mid'));
57
    $xoopsTpl->assign('add_from', _ADSLIGHT_ADDFROM . ' ' . $xoopsConfig['sitename']);
58
    $xoopsTpl->assign('add_from_title', _ADSLIGHT_ADDFROM);
59
    $xoopsTpl->assign('add_from_sitename', $xoopsConfig['sitename']);
60
    $xoopsTpl->assign('only_pix', _ADSLIGHT_ONLYPIX);
61
    $xoopsTpl->assign('adslight_logolink', _ADSLIGHT_LOGOLINK);
62
    $xoopsTpl->assign('permit', $prem_perm);
63
64
    $xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/style/adslight.css" type="text/css" media="all" />');
65
66
    $banner = xoops_getbanner();
67
    $xoopsTpl->assign('banner', $banner);
68
    $xoopsTpl->assign('use_extra_code', $xoopsModuleConfig['adslight_use_index_code']);
69
    $xoopsTpl->assign('adslight_use_banner', $xoopsModuleConfig['adslight_use_banner']);
70
    $xoopsTpl->assign('index_extra_code', $xoopsModuleConfig['adslight_index_code']);
71
    $xoopsTpl->assign('index_code_place', $xoopsModuleConfig['adslight_index_code_place']);
72
    $xoopsTpl->assign('category_title2', _ADSLIGHT_ANNONCES);
73
    // adslight 2
74
    $xoopsTpl->assign('adslight_active_menu', $xoopsModuleConfig['adslight_active_menu']);
75
    $xoopsTpl->assign('adslight_active_rss', $xoopsModuleConfig['adslight_active_rss']);
76
77
    ExpireAd();
78
79 View Code Duplication
    if ($xoopsUser) {
80
        $member_usid = $xoopsUser->getVar('uid');
81
        if ($usid = $member_usid) {
82
            $xoopsTpl->assign('istheirs', true);
83
84
            list($show_user) = $xoopsDB->fetchRow($xoopsDB->query('SELECT SQL_CACHE COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE usid=' . $member_usid . ''));
85
86
            $xoopsTpl->assign('show_user', $show_user);
87
            $xoopsTpl->assign('show_user_link', 'members.php?usid=' . $member_usid . '');
88
        }
89
    }
90
91
    $result = $xoopsDB->query('SELECT SQL_CACHE COUNT(*)  FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE valid="No"');
92
    list($propo) = $xoopsDB->fetchRow($result);
93
94
    if ($propo > 0) {
95
        $xoopsTpl->assign('moderated', true);
96
    }
97
    if ($xoopsUser) {
98
        if ($xoopsUser->isAdmin()) {
99
            $xoopsTpl->assign('admin_block', _ADSLIGHT_ADMINCADRE);
100
            if ($propo == 0) {
101
                $xoopsTpl->assign('confirm_ads', _ADSLIGHT_NO_CLA);
102
            } else {
103
                $xoopsTpl->assign('confirm_ads',
104
                                  _ADSLIGHT_THEREIS . ' ' . $propo . '  ' . _ADSLIGHT_WAIT . '<br><a href="' . XOOPS_URL . '/modules/adslight/admin/validate_ads.php">' . _ADSLIGHT_SEEIT . '</a>');
105
            }
106
        }
107
108
        $categories = adslight_MygetItemIds('adslight_submit');
109
        if (is_array($categories) && count($categories) > 0) {
110
            $intro = _ADSLIGHT_INTRO;
111
        } else {
112
            $intro = '';
113
        }
114
        $xoopsTpl->assign('intro', $intro);
115
    }
116
117
    $sql = 'SELECT SQL_CACHE cid, title, img FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE pid = 0 ';
118
119
    $categories = adslight_MygetItemIds('adslight_view');
120
    if (is_array($categories) && count($categories) > 0) {
121
        $sql .= ' AND cid IN (' . implode(',', $categories) . ') ';
122
    } else {
123
        redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
124
    }
125
126
    if ($xoopsModuleConfig['adslight_csortorder'] === 'ordre') {
127
        $sql .= 'ORDER BY ordre';
128
    } else {
129
        $sql .= 'ORDER BY title';
130
    }
131
132
    $result = $xoopsDB->query($sql);
133
134
    $count   = 1;
135
    $content = '';
136
    while ($myrow = $xoopsDB->fetchArray($result)) {
137
        $title = $myts->htmlSpecialChars($myrow['title']);
138
139
        if ($myrow['img'] && $myrow['img'] !== 'http://') {
140
            $cat_img = $myts->htmlSpecialChars($myrow['img']);
141
            $img     = '<a href="viewcats.php?cid='
142
                       . $myrow['cid']
143
                       . '"><img src="'
144
                       . XOOPS_URL
145
                       . '/modules/adslight/assets/images/img_cat/'
146
                       . $cat_img
147
                       . '" align="middle" alt="'
148
                       . $title
149
                       . '" /></a>';
150
        } else {
151
            $img = '';
152
        }
153
154
        $totallisting = adslight_getTotalItems($myrow['cid'], 1);
155
        $content .= $title . ' ';
156
157
        $arr = array();
158
        if (in_array($myrow['cid'], $categories)) {
159
            $arr           = $mytree->getFirstChild($myrow['cid'], 'title');
160
            $space         = 0;
161
            $chcount       = 1;
162
            $subcategories = '';
163
            if ($xoopsModuleConfig['adslight_souscat'] == 1) {
164
                foreach ($arr as $ele) {
165
                    if (in_array($ele['cid'], $categories)) {
166
                        $chtitle = $myts->htmlSpecialChars($ele['title']);
167
                        if ($chcount > $xoopsModuleConfig['adslight_nbsouscat']) {
168
                            $subcategories .= '<a href="viewcats.php?cid=' . $myrow['cid'] . '">' . _ADSLIGHT_CATPLUS . '</a>';
169
                            break;
170
                        }
171
                        if ($space > 0) {
172
                            $subcategories .= '<br>';
173
                        }
174
                        $subcategories .= '-&nbsp;<a href="' . XOOPS_URL . '/modules/adslight/viewcats.php?cid=' . $ele['cid'] . '">' . $chtitle . '</a>';
175
                        ++$space;
176
                        ++$chcount;
177
                        $content .= $ele['title'] . ' ';
178
                    }
179
                }
180
            }
181
            $xoopsTpl->append('categories', array(
182
                'image'         => $img,
183
                'id'            => $myrow['cid'],
184
                'title'         => $myts->htmlSpecialChars($myrow['title']),
185
                'new'           => categorynewgraphic($myrow['cid']),
186
                'subcategories' => $subcategories,
187
                'totallisting'  => $totallisting,
188
                'count'         => $count
189
            ));
190
            ++$count;
191
        }
192
    }
193
    $cat_perms = '';
194
    if (is_array($categories) && count($categories) > 0) {
195
        $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
196
    }
197
198
    list($ads) = $xoopsDB->fetchRow($xoopsDB->query('SELECT SQL_CACHE COUNT(*)  FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='Yes' AND status!='1' $cat_perms"));
199
200
    list($catt) = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*)  FROM ' . $xoopsDB->prefix('' . $moduleDirName . '_categories') . ''));
201
202
    $submit_perms = adslight_MygetItemIds('adslight_submit');
0 ignored issues
show
$submit_perms 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...
203
204
    if ($xoopsUser) {
205
        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULLOK . '<a href="add.php">' . _ADSLIGHT_ADD_LISTING_SUBOK . '</a>';
206
    } else {
207
        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULL . '<a href="' . XOOPS_URL . '/register.php">' . _ADSLIGHT_ADD_LISTING_SUB . '</a>.';
208
    }
209
210
    $xoopsTpl->assign('bullinfotext', _ADSLIGHT_ACTUALY . ' ' . $ads . ' ' . _ADSLIGHT_ADVERTISEMENTS . '<br>' . $add_listing);
211
    $xoopsTpl->assign('total_confirm', _ADSLIGHT_AND . " $propo " . _ADSLIGHT_WAIT3);
212
213
    if ($xoopsModuleConfig['adslight_newad'] == 1) {
214
        $cat_perms = '';
215
        if (is_array($categories) && count($categories) > 0) {
216
            $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
217
        }
218
219
        $result = $xoopsDB->query('SELECT SQL_CACHE lid, title, status, type, price, typeprice, date, town, country, usid, premium, valid, photo, hits FROM '
220
                                  . $xoopsDB->prefix('adslight_listing')
221
                                  . " WHERE valid='Yes' AND status!='1' $cat_perms ORDER BY date DESC LIMIT "
222
                                  . $xoopsModuleConfig['adslight_newcount']
223
                                  . '');
224
        if ($result) {
225
            $xoopsTpl->assign('last_head', _ADSLIGHT_THE . ' ' . $xoopsModuleConfig['adslight_newcount'] . ' ' . _ADSLIGHT_LASTADD);
226
            $xoopsTpl->assign('last_head_title', _ADSLIGHT_TITLE);
227
            $xoopsTpl->assign('last_head_price', _ADSLIGHT_PRICE);
228
            $xoopsTpl->assign('last_head_date', _ADSLIGHT_DATE);
229
            $xoopsTpl->assign('last_head_local', _ADSLIGHT_LOCAL2);
230
            $xoopsTpl->assign('last_head_hits', _ADSLIGHT_VIEW);
231
            $xoopsTpl->assign('last_head_photo', _ADSLIGHT_PHOTO);
232
            $rank = 1;
233
234
            while (list($lid, $title, $status, $type, $price, $typeprice, $date, $town, $country, $usid, $premium, $valid, $photo, $hits) = $xoopsDB->fetchRow($result)) {
235
                $title     = $myts->htmlSpecialChars($title);
236
                $type      = $myts->htmlSpecialChars($type);
237
                $price     = number_format($price, 2, ',', ' ');
238
                $town      = $myts->htmlSpecialChars($town);
239
                $country   = $myts->htmlSpecialChars($country);
240
                $premium   = $myts->htmlSpecialChars($premium);
241
                $a_item    = array();
242
                $newcount  = $xoopsModuleConfig['adslight_countday'];
243
                $startdate = (time() - (86400 * $newcount));
244
245 View Code Duplication
                if ($startdate < $date) {
246
                    $newitem       = '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/newred.gif" alt="new" />';
247
                    $a_item['new'] = $newitem;
248
                }
249
250
                $useroffset = '';
251 View Code Duplication
                if ($xoopsUser) {
252
                    $timezone = $xoopsUser->timezone();
253
                    if (isset($timezone)) {
254
                        $useroffset = $xoopsUser->timezone();
255
                    } else {
256
                        $useroffset = $xoopsConfig['default_TZ'];
257
                    }
258
                }
259
260
                $date = ($useroffset * 3600) + $date;
261
                $date = formatTimestamp($date, 's');
262 View Code Duplication
                if ($xoopsUser) {
263
                    if ($xoopsUser->isAdmin()) {
264
                        $a_item['admin'] = '<a href="'
265
                                           . XOOPS_URL
266
                                           . '/modules/adslight/admin/validate_ads.php?op=ModifyAds&amp;lid='
267
                                           . $lid
268
                                           . '"><img src="'
269
                                           . $pathIcon16
270
                                           . '/edit.png'
271
                                           . '" border=0 alt="'
272
                                           . _ADSLIGHT_MODADMIN
273
                                           . '" /></a>';
274
                    }
275
                }
276
277
                $result7 = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' WHERE id_type=' . $xoopsDB->escape($type) . '');
278
                list($nom_type) = $xoopsDB->fetchRow($result7);
279
280
                $a_item['type']  = $myts->htmlSpecialChars($nom_type);
281
                $a_item['title'] = '<a href="' . XOOPS_URL . '/modules/adslight/viewads.php?lid=' . $lid . '"><strong>' . $title . '</strong></a>';
282
283
                $result8 = $xoopsDB->query('SELECT nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' WHERE id_price=' . $xoopsDB->escape($typeprice) . '');
284
                list($nom_price) = $xoopsDB->fetchRow($result8);
285
286
                if ($price > 0) {
287
                    $a_item['price']           = $price . ' ' . $xoopsModuleConfig['adslight_money'] . '';
288
                    $a_item['price_typeprice'] = $myts->htmlSpecialChars($nom_price);
289
                } else {
290
                    $a_item['price']           = '';
291
                    $a_item['price_typeprice'] = $myts->htmlSpecialChars($nom_price);
292
                }
293
                $a_item['premium'] = $premium;
294
                $a_item['date']    = $date;
295
                $a_item['local']   = '';
296
                if ($town) {
297
                    $a_item['local'] .= $town;
298
                }
299
                $a_item['country'] = '';
300
                if ($country) {
301
                    $a_item['country'] = $country;
302
                }
303
304
                if ($status == 2) {
305
                    $a_item['sold'] = _ADSLIGHT_RESERVEDMEMBER;
306
                }
307
308 View Code Duplication
                if ($xoopsModuleConfig['active_thumbsindex'] > 0) {
309
                    $a_item['no_photo'] = '<a href="'
310
                                          . XOOPS_URL
311
                                          . '/modules/adslight/viewads.php?lid='
312
                                          . $lid
313
                                          . '"><img class="thumb" src="'
314
                                          . XOOPS_URL
315
                                          . '/modules/adslight/assets/images/nophoto.jpg" align="left" width="100px" alt="'
316
                                          . $title
317
                                          . '" /></a>';
318
319
                    $updir   = $xoopsModuleConfig['adslight_link_upload'];
320
                    $sql     = 'SELECT cod_img, lid, uid_owner, url FROM '
321
                               . $xoopsDB->prefix('adslight_pictures')
322
                               . ' WHERE  uid_owner='
323
                               . $xoopsDB->escape($usid)
324
                               . ' AND lid='
325
                               . $xoopsDB->escape($lid)
326
                               . ' ORDER BY date_added ASC limit 1';
327
                    $resultp = $xoopsDB->query($sql);
328
329
                    while (list($cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($resultp)) {
330
                        if ($photo) {
331
                            $a_item['photo'] = '<a href="'
332
                                               . XOOPS_URL
333
                                               . '/modules/adslight/viewads.php?lid='
334
                                               . $lid
335
                                               . '"><img class="thumb" src="'
336
                                               . $updir
337
                                               . '/thumbs/thumb_'
338
                                               . $url
339
                                               . '" align="left" width="100px" alt="'
340
                                               . $title
341
                                               . '" /></a>';
342
                        }
343
                    }
344
                } else {
345
                    $a_item['no_photo'] = '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/camera_nophoto.png" align="left" width="24" alt="' . $title . '" />';
346
                    $updir              = $xoopsModuleConfig['adslight_link_upload'];
347
                    $sql                = 'SELECT cod_img, lid, uid_owner, url FROM '
348
                                          . $xoopsDB->prefix('adslight_pictures')
349
                                          . ' WHERE  uid_owner='
350
                                          . $xoopsDB->escape($usid)
351
                                          . ' AND lid='
352
                                          . $xoopsDB->escape($lid)
353
                                          . ' ORDER BY date_added ASC limit 1';
354
                    $resultp            = $xoopsDB->query($sql);
355
356
                    while (list($cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($resultp)) {
357
                        if ($photo) {
358
                            $a_item['photo'] = '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/camera_photo.png" align="left" width="24" alt="' . $title . '" />';
359
                        }
360
                    }
361
                }
362
                $a_item['hits'] = $hits;
363
                ++$rank;
364
                $xoopsTpl->append('items', $a_item);
365
            }
366
        }
367
    }
368
}
369
370
#  function categorynewgraphic
371
#####################################################
372
/**
373
 * @param $cid
374
 */
375
function categorynewgraphic($cid)
376
{
377
    global $xoopsDB, $xoopsModuleConfig;
378
}
379
380
######################################################
381
382
$pa      = !isset($_GET['pa']) ? null : $_GET['pa'];
383
$lid     = !isset($_GET['lid']) ? null : $_GET['lid'];
384
$cid     = !isset($_GET['cid']) ? null : $_GET['cid'];
385
$usid    = isset($_GET['usid']) ? $_GET['usid'] : '';
386
$min     = !isset($_GET['min']) ? null : $_GET['min'];
387
$show    = !isset($_GET['show']) ? null : $_GET['show'];
388
$orderby = !isset($_GET['orderby']) ? null : $_GET['orderby'];
389
390
switch ($pa) {
391
    case 'Adsview':
392
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
393
        adsView($cid, $min, $orderby, $show);
394
        break;
395
    case 'viewads':
396
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_item.tpl';
397
        viewAds($lid);
398
        break;
399
    default:
400
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_index.tpl';
401
        index();
402
        break;
403
}
404
include XOOPS_ROOT_PATH . '/footer.php';
405