Completed
Branch master (a25b3b)
by Michael
03:43 queued 01:22
created

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
isset($_POST['item_id']) ? $perm_itemid = (int)$_POST['item_id'] : $perm_itemid = 0;
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()
48
{
49
    global $xoopsDB, $xoopsConfig, $xoopsModule, $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/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 View Code Duplication
    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
                                  . '');
225
        if ($result) {
226
            $xoopsTpl->assign('last_head', _ADSLIGHT_THE . ' ' . $GLOBALS['xoopsModuleConfig']['adslight_newcount'] . ' ' . _ADSLIGHT_LASTADD);
227
            $xoopsTpl->assign('last_head_title', _ADSLIGHT_TITLE);
228
            $xoopsTpl->assign('last_head_price', _ADSLIGHT_PRICE);
229
            $xoopsTpl->assign('last_head_date', _ADSLIGHT_DATE);
230
            $xoopsTpl->assign('last_head_local', _ADSLIGHT_LOCAL2);
231
            $xoopsTpl->assign('last_head_hits', _ADSLIGHT_VIEW);
232
            $xoopsTpl->assign('last_head_photo', _ADSLIGHT_PHOTO);
233
            $rank = 1;
234
235
            while (list($lid, $title, $status, $type, $price, $typeprice, $date, $town, $country, $usid, $premium, $valid, $photo, $hits) = $xoopsDB->fetchRow($result)) {
236
                $title     = $myts->htmlSpecialChars($title);
237
                $type      = $myts->htmlSpecialChars($type);
238
                $price     = number_format($price, 2, ',', ' ');
239
                $town      = $myts->htmlSpecialChars($town);
240
                $country   = $myts->htmlSpecialChars($country);
241
                $premium   = $myts->htmlSpecialChars($premium);
242
                $a_item    = array();
243
                $newcount  = $GLOBALS['xoopsModuleConfig']['adslight_countday'];
244
                $startdate = (time() - (86400 * $newcount));
245
246 View Code Duplication
                if ($startdate < $date) {
247
                    $newitem       = '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/newred.gif" alt="new" />';
248
                    $a_item['new'] = $newitem;
249
                }
250
251
                $useroffset = '';
252
                if ($GLOBALS['xoopsUser']) {
253
                    $timezone = $GLOBALS['xoopsUser']->timezone();
254
                    if (isset($timezone)) {
255
                        $useroffset = $GLOBALS['xoopsUser']->timezone();
256
                    } else {
257
                        $useroffset = $xoopsConfig['default_TZ'];
258
                    }
259
                }
260
261
                $date = ($useroffset * 3600) + $date;
262
                $date = formatTimestamp($date, 's');
263 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...
264
                    if ($GLOBALS['xoopsUser']->isAdmin()) {
265
                        $a_item['admin'] = '<a href="'
266
                                           . XOOPS_URL
267
                                           . '/modules/adslight/admin/validate_ads.php?op=ModifyAds&amp;lid='
268
                                           . $lid
269
                                           . '"><img src="'
270
                                           . $pathIcon16
271
                                           . '/edit.png'
272
                                           . '" border=0 alt="'
273
                                           . _ADSLIGHT_MODADMIN
274
                                           . '" /></a>';
275
                    }
276
                }
277
278
                $result7 = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' WHERE id_type=' . $xoopsDB->escape($type) . '');
279
                list($nom_type) = $xoopsDB->fetchRow($result7);
280
281
                $a_item['type']  = $myts->htmlSpecialChars($nom_type);
282
                $a_item['title'] = '<a href="' . XOOPS_URL . '/modules/adslight/viewads.php?lid=' . $lid . '"><strong>' . $title . '</strong></a>';
283
284
                $result8 = $xoopsDB->query('SELECT nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' WHERE id_price=' . $xoopsDB->escape($typeprice) . '');
285
                list($nom_price) = $xoopsDB->fetchRow($result8);
286
287
                if ($price > 0) {
288
                    $a_item['price']           = $price . ' ' . $GLOBALS['xoopsModuleConfig']['adslight_money'] . '';
289
                    $a_item['price_typeprice'] = $myts->htmlSpecialChars($nom_price);
290
                } else {
291
                    $a_item['price']           = '';
292
                    $a_item['price_typeprice'] = $myts->htmlSpecialChars($nom_price);
293
                }
294
                $a_item['premium'] = $premium;
295
                $a_item['date']    = $date;
296
                $a_item['local']   = '';
297
                if ($town) {
298
                    $a_item['local'] .= $town;
299
                }
300
                $a_item['country'] = '';
301
                if ($country) {
302
                    $a_item['country'] = $country;
303
                }
304
305
                if ($status == 2) {
306
                    $a_item['sold'] = _ADSLIGHT_RESERVEDMEMBER;
307
                }
308
309 View Code Duplication
                if ($GLOBALS['xoopsModuleConfig']['active_thumbsindex'] > 0) {
310
                    $a_item['no_photo'] = '<a href="'
311
                                          . XOOPS_URL
312
                                          . '/modules/adslight/viewads.php?lid='
313
                                          . $lid
314
                                          . '"><img class="thumb" src="'
315
                                          . XOOPS_URL
316
                                          . '/modules/adslight/assets/images/nophoto.jpg" align="left" width="100px" alt="'
317
                                          . $title
318
                                          . '" /></a>';
319
320
                    $updir   = $GLOBALS['xoopsModuleConfig']['adslight_link_upload'];
321
                    $sql     = 'SELECT cod_img, lid, uid_owner, url FROM '
322
                               . $xoopsDB->prefix('adslight_pictures')
323
                               . ' WHERE  uid_owner='
324
                               . $xoopsDB->escape($usid)
325
                               . ' AND lid='
326
                               . $xoopsDB->escape($lid)
327
                               . ' ORDER BY date_added ASC limit 1';
328
                    $resultp = $xoopsDB->query($sql);
329
330
                    while (list($cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($resultp)) {
331
                        if ($photo) {
332
                            $a_item['photo'] = '<a href="'
333
                                               . XOOPS_URL
334
                                               . '/modules/adslight/viewads.php?lid='
335
                                               . $lid
336
                                               . '"><img class="thumb" src="'
337
                                               . $updir
338
                                               . '/thumbs/thumb_'
339
                                               . $url
340
                                               . '" align="left" width="100px" alt="'
341
                                               . $title
342
                                               . '" /></a>';
343
                        }
344
                    }
345
                } else {
346
                    $a_item['no_photo'] = '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/camera_nophoto.png" align="left" width="24" alt="' . $title . '" />';
347
                    $updir              = $GLOBALS['xoopsModuleConfig']['adslight_link_upload'];
348
                    $sql                = 'SELECT cod_img, lid, uid_owner, url FROM '
349
                                          . $xoopsDB->prefix('adslight_pictures')
350
                                          . ' WHERE  uid_owner='
351
                                          . $xoopsDB->escape($usid)
352
                                          . ' AND lid='
353
                                          . $xoopsDB->escape($lid)
354
                                          . ' ORDER BY date_added ASC limit 1';
355
                    $resultp            = $xoopsDB->query($sql);
356
357
                    while (list($cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($resultp)) {
358
                        if ($photo) {
359
                            $a_item['photo'] = '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/camera_photo.png" align="left" width="24" alt="' . $title . '" />';
360
                        }
361
                    }
362
                }
363
                $a_item['hits'] = $hits;
364
                ++$rank;
365
                $xoopsTpl->append('items', $a_item);
366
            }
367
        }
368
    }
369
}
370
371
#  function categorynewgraphic
372
#####################################################
373
/**
374
 * @param $cid
375
 */
376
function categorynewgraphic($cid)
377
{
378
    global $xoopsDB;
379
}
380
381
######################################################
382
383
$pa      = !isset($_GET['pa']) ? null : $_GET['pa'];
384
$lid     = !isset($_GET['lid']) ? null : $_GET['lid'];
385
$cid     = !isset($_GET['cid']) ? null : $_GET['cid'];
386
$usid    = isset($_GET['usid']) ? $_GET['usid'] : '';
387
$min     = !isset($_GET['min']) ? null : $_GET['min'];
388
$show    = !isset($_GET['show']) ? null : $_GET['show'];
389
$orderby = !isset($_GET['orderby']) ? null : $_GET['orderby'];
390
391
switch ($pa) {
392
    case 'Adsview':
393
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
394
        adsView($cid, $min, $orderby, $show);
395
        break;
396
    case 'viewads':
397
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_item.tpl';
398
        viewAds($lid);
399
        break;
400
    default:
401
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_index.tpl';
402
        index();
403
        break;
404
}
405
include XOOPS_ROOT_PATH . '/footer.php';
406