Completed
Push — master ( 67bb37...e20777 )
by Michael
02:35
created

index.php (4 issues)

Upgrade to new PHP Analysis Engine

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

1
<?php
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($GLOBALS['xoopsUser']) ? $groups = $GLOBALS['xoopsUser']->getGroups() : $groups = XOOPS_GROUP_ANONYMOUS;
30
31
$gpermHandler = xoops_getHandler('groupperm');
32
33
$perm_itemid = XoopsRequest::getInt('item_id', 0, 'POST');
34
35 View Code Duplication
if (!$gpermHandler->checkRight('adslight_view', $perm_itemid, $groups, $module_id)) {
36
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
37
}
38
39
(!$gpermHandler->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/class/utilities.php';
43
$mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
44
45
#  function index
46
#####################################################
47
function index()
1 ignored issue
show
index 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...
48
{
49
    global $xoopsDB, $xoopsConfig, $xoopsModule, $xoopsTpl, $myts, $mytree, $meta, $mid, $moduleDirName, $main_lang, $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...
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/assets/css/adslight.css" type="text/css" media="all" />');
65
66
    $banner = xoops_getbanner();
67
    $xoopsTpl->assign('banner', $banner);
68
    $xoopsTpl->assign('use_extra_code', $GLOBALS['xoopsModuleConfig']['adslight_use_index_code']);
69
    $xoopsTpl->assign('adslight_use_banner', $GLOBALS['xoopsModuleConfig']['adslight_use_banner']);
70
    $xoopsTpl->assign('index_extra_code', $GLOBALS['xoopsModuleConfig']['adslight_index_code']);
71
    $xoopsTpl->assign('index_code_place', $GLOBALS['xoopsModuleConfig']['adslight_index_code_place']);
72
    $xoopsTpl->assign('category_title2', _ADSLIGHT_ANNONCES);
73
    // adslight 2
74
    $xoopsTpl->assign('adslight_active_menu', $GLOBALS['xoopsModuleConfig']['adslight_active_menu']);
75
    $xoopsTpl->assign('adslight_active_rss', $GLOBALS['xoopsModuleConfig']['adslight_active_rss']);
76
77
    //    ExpireAd();
78
    AdslightUtilities::expireAd();
79
80
    if ($GLOBALS['xoopsUser']) {
81
        $member_usid = $GLOBALS['xoopsUser']->getVar('uid');
82
        if ($usid = $member_usid) {
83
            $xoopsTpl->assign('istheirs', true);
84
85
            list($show_user) = $xoopsDB->fetchRow($xoopsDB->query('SELECT SQL_CACHE COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE usid='" . $member_usid . "'"));
86
87
            $xoopsTpl->assign('show_user', $show_user);
88
            $xoopsTpl->assign('show_user_link', 'members.php?usid=' . $member_usid);
89
        }
90
    }
91
92
    $result = $xoopsDB->query('SELECT SQL_CACHE COUNT(*)  FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE valid="No"');
93
    list($propo) = $xoopsDB->fetchRow($result);
94
95
    if ($propo > 0) {
96
        $xoopsTpl->assign('moderated', true);
97
    }
98
    if ($GLOBALS['xoopsUser']) {
99
        if ($GLOBALS['xoopsUser']->isAdmin()) {
100
            $xoopsTpl->assign('admin_block', _ADSLIGHT_ADMINCADRE);
101
            if ($propo == 0) {
102
                $xoopsTpl->assign('confirm_ads', _ADSLIGHT_NO_CLA);
103
            } else {
104
                $xoopsTpl->assign('confirm_ads',
105
                                  _ADSLIGHT_THEREIS . ' ' . $propo . '  ' . _ADSLIGHT_WAIT . '<br><a href="' . XOOPS_URL . '/modules/adslight/admin/validate_ads.php">' . _ADSLIGHT_SEEIT . '</a>');
106
            }
107
        }
108
109
        $categories = AdslightUtilities::getMyItemIds('adslight_submit');
110
        if (is_array($categories) && count($categories) > 0) {
111
            $intro = _ADSLIGHT_INTRO;
112
        } else {
113
            $intro = '';
114
        }
115
        $xoopsTpl->assign('intro', $intro);
116
    }
117
118
    $sql = 'SELECT SQL_CACHE cid, title, img FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE pid = 0 ';
119
120
    $categories = AdslightUtilities::getMyItemIds('adslight_view');
121
    if (is_array($categories) && count($categories) > 0) {
122
        $sql .= ' AND cid IN (' . implode(',', $categories) . ') ';
123
    } else {
124
        redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
125
    }
126
127
    if ($GLOBALS['xoopsModuleConfig']['adslight_csortorder'] === 'ordre') {
128
        $sql .= 'ORDER BY ordre';
129
    } else {
130
        $sql .= 'ORDER BY title';
131
    }
132
133
    $result = $xoopsDB->query($sql);
134
135
    $count   = 1;
136
    $content = '';
137
    while ($myrow = $xoopsDB->fetchArray($result)) {
138
        $title = $myts->htmlSpecialChars($myrow['title']);
139
140
        if ($myrow['img'] && $myrow['img'] !== 'http://') {
141
            $cat_img = $myts->htmlSpecialChars($myrow['img']);
142
            $img     = '<a href="viewcats.php?cid='
143
                       . $myrow['cid']
144
                       . '"><img src="'
145
                       . XOOPS_URL
146
                       . '/modules/adslight/assets/images/img_cat/'
147
                       . $cat_img
148
                       . '" align="middle" alt="'
149
                       . $title
150
                       . '" /></a>';
151
        } else {
152
            $img = '';
153
        }
154
155
        $totallisting = AdslightUtilities::getTotalItems($myrow['cid'], 1);
156
        $content .= $title . ' ';
157
158
        $arr = array();
159
        if (in_array($myrow['cid'], $categories)) {
160
            $arr           = $mytree->getFirstChild($myrow['cid'], 'title');
161
            $space         = 0;
162
            $chcount       = 1;
163
            $subcategories = '';
164
            if ($GLOBALS['xoopsModuleConfig']['adslight_souscat'] == 1) {
165
                foreach ($arr as $ele) {
166
                    if (in_array($ele['cid'], $categories)) {
167
                        $chtitle = $myts->htmlSpecialChars($ele['title']);
168
                        if ($chcount > $GLOBALS['xoopsModuleConfig']['adslight_nbsouscat']) {
169
                            $subcategories .= '<a href="viewcats.php?cid=' . $myrow['cid'] . '">' . _ADSLIGHT_CATPLUS . '</a>';
170
                            break;
171
                        }
172
                        if ($space > 0) {
173
                            $subcategories .= '<br>';
174
                        }
175
                        $subcategories .= '-&nbsp;<a href="' . XOOPS_URL . '/modules/adslight/viewcats.php?cid=' . $ele['cid'] . '">' . $chtitle . '</a>';
176
                        ++$space;
177
                        ++$chcount;
178
                        $content .= $ele['title'] . ' ';
179
                    }
180
                }
181
            }
182
            $xoopsTpl->append('categories', array(
183
                'image'         => $img,
184
                'id'            => $myrow['cid'],
185
                'title'         => $myts->htmlSpecialChars($myrow['title']),
186
                'new'           => categorynewgraphic($myrow['cid']),
187
                'subcategories' => $subcategories,
188
                'totallisting'  => $totallisting,
189
                'count'         => $count
190
            ));
191
            ++$count;
192
        }
193
    }
194
    $cat_perms = '';
195
    if (is_array($categories) && count($categories) > 0) {
196
        $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
197
    }
198
199
    list($ads) = $xoopsDB->fetchRow($xoopsDB->query('SELECT SQL_CACHE COUNT(*)  FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='Yes' AND status!='1' $cat_perms"));
200
201
    list($catt) = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*)  FROM ' . $xoopsDB->prefix('' . $moduleDirName . '_categories') . ''));
202
203
    $submit_perms = AdslightUtilities::getMyItemIds('adslight_submit');
204
205
    if ($GLOBALS['xoopsUser']) {
206
        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULLOK . '<a href="add.php">' . _ADSLIGHT_ADD_LISTING_SUBOK . '</a>';
207
    } else {
208
        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULL . '<a href="' . XOOPS_URL . '/register.php">' . _ADSLIGHT_ADD_LISTING_SUB . '</a>.';
209
    }
210
211
    $xoopsTpl->assign('bullinfotext', _ADSLIGHT_ACTUALY . ' ' . $ads . ' ' . _ADSLIGHT_ADVERTISEMENTS . '<br>' . $add_listing);
212
    $xoopsTpl->assign('total_confirm', _ADSLIGHT_AND . " $propo " . _ADSLIGHT_WAIT3);
213
214
    if ($GLOBALS['xoopsModuleConfig']['adslight_newad'] == 1) {
215
        $cat_perms = '';
216
        if (is_array($categories) && count($categories) > 0) {
217
            $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
218
        }
219
220
        $result = $xoopsDB->query('SELECT SQL_CACHE lid, title, status, type, price, typeprice, date, town, country, usid, premium, valid, photo, hits FROM '
221
                                  . $xoopsDB->prefix('adslight_listing')
222
                                  . " WHERE valid='Yes' AND status!='1' $cat_perms ORDER BY date DESC LIMIT "
223
                                  . $GLOBALS['xoopsModuleConfig']['adslight_newcount']);
224
        if ($result) {
225
            $xoopsTpl->assign('last_head', _ADSLIGHT_THE . ' ' . $GLOBALS['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  = $GLOBALS['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
                if ($GLOBALS['xoopsUser']) {
252
                    $timezone = $GLOBALS['xoopsUser']->timezone();
253
                    if (isset($timezone)) {
254
                        $useroffset = $GLOBALS['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 ($GLOBALS['xoopsUser']) {
1 ignored issue
show
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...
263
                    if ($GLOBALS['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 . ' ' . $GLOBALS['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 ($GLOBALS['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   = $GLOBALS['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              = $GLOBALS['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;
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...
378
}
379
380
######################################################
381
382
$pa      = XoopsRequest::getInt('pa', null, 'GET');
383
$lid     = XoopsRequest::getInt('lid', null, 'GET');
384
$cid     = XoopsRequest::getInt('cid', null, 'GET');
385
$usid    = XoopsRequest::getString('usid', '', 'GET');
386
$min     = XoopsRequest::getInt('min', null, 'GET');
387
$show    = XoopsRequest::getInt('show', null, 'GET');
388
$orderby = XoopsRequest::getInt('orderby', null, 'GET');
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