Passed
Push — master ( be43a3...3139c5 )
by Michael
06:12 queued 01:07
created

index.php (7 issues)

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
use Xmf\Request;
24
use XoopsModules\Adslight;
25
26
$GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
27
28
global $xoopsModule;
29
30
require_once __DIR__ . '/header.php';
31
32
$myts      = \MyTextSanitizer::getInstance();
33
$module_id = $xoopsModule->getVar('mid');
34
35
$groups = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
36
37
/** @var \XoopsGroupPermHandler $grouppermHandler */
38
$grouppermHandler = xoops_getHandler('groupperm');
39
40
$perm_itemid = Request::getInt('item_id', 0, 'POST');
41
42
if (!$grouppermHandler->checkRight('adslight_view', $perm_itemid, $groups, $module_id)) {
43
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
44
}
45
46
$prem_perm = (!$grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) ? '0' : '1';
47
48
$mytree = new Adslight\ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
49
50
#  function index
51
#####################################################
52
53
function index()
54
{
55
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $mytree, $meta, $mid, $prem_perm;
56
    $pathIcon16 = \Xmf\Module\Admin::iconUrl('', 16);
57
    $moduleDirName = basename(__DIR__);
58
59
    /** @var \XoopsModules\Adslight\Helper $helper */
60
    $helper = \XoopsModules\Adslight\Helper::getInstance();
61
62
    if (!isset($GLOBALS['xoopsTpl']) || !($GLOBALS['xoopsTpl'] instanceof XoopsTpl)) {
63
        require_once $GLOBALS['xoops']->path('class/template.php');
64
        $GLOBALS['xoopsTpl'] = new \XoopsTpl();
65
    }
66
67
    //    $GLOBALS['xoopsOption']['template_main'] = 'adslight_index.tpl';
68
69
    require_once XOOPS_ROOT_PATH . '/header.php';
70
71
    $GLOBALS['xoopsTpl']->assign('xmid', $xoopsModule->getVar('mid'));
72
    $GLOBALS['xoopsTpl']->assign('add_from', _ADSLIGHT_ADDFROM . ' ' . $xoopsConfig['sitename']);
73
    $GLOBALS['xoopsTpl']->assign('add_from_title', _ADSLIGHT_ADDFROM);
74
    $GLOBALS['xoopsTpl']->assign('add_from_sitename', $xoopsConfig['sitename']);
75
    $GLOBALS['xoopsTpl']->assign('only_pix', _ADSLIGHT_ONLYPIX);
76
    $GLOBALS['xoopsTpl']->assign('adslight_logolink', _ADSLIGHT_LOGOLINK);
77
    $GLOBALS['xoopsTpl']->assign('permit', $prem_perm);
78
79
    $GLOBALS['xoopsTpl']->assign('xoops_module_header', '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/assets/css/adslight.css" type="text/css" media="all" >');
80
81
    $banner = xoops_getbanner();
82
    $GLOBALS['xoopsTpl']->assign('banner', $banner);
83
    $GLOBALS['xoopsTpl']->assign('use_extra_code', $GLOBALS['xoopsModuleConfig']['adslight_use_index_code']);
84
    $GLOBALS['xoopsTpl']->assign('adslight_use_banner', $GLOBALS['xoopsModuleConfig']['adslight_use_banner']);
85
    $GLOBALS['xoopsTpl']->assign('index_extra_code', $GLOBALS['xoopsModuleConfig']['adslight_index_code']);
86
    $GLOBALS['xoopsTpl']->assign('index_code_place', $GLOBALS['xoopsModuleConfig']['adslight_index_code_place']);
87
    $GLOBALS['xoopsTpl']->assign('category_title2', _ADSLIGHT_ANNONCES);
88
    // adslight 2
89
    $GLOBALS['xoopsTpl']->assign('adslight_active_menu', $GLOBALS['xoopsModuleConfig']['adslight_active_menu']);
90
    $GLOBALS['xoopsTpl']->assign('adslight_active_rss', $GLOBALS['xoopsModuleConfig']['adslight_active_rss']);
91
92
    //    ExpireAd();
93
    Adslight\Utility::expireAd();
94
95
    if ($GLOBALS['xoopsUser']) {
96
        $member_usid = $GLOBALS['xoopsUser']->getVar('uid');
97
        if ($usid = $member_usid) {
0 ignored issues
show
The assignment to $usid is dead and can be removed.
Loading history...
98
            $GLOBALS['xoopsTpl']->assign('istheirs', true);
99
100
            list($show_user) = $xoopsDB->fetchRow($xoopsDB->query('SELECT SQL_CACHE COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE usid=' . $member_usid . ' '));
101
102
            $GLOBALS['xoopsTpl']->assign('show_user', $show_user);
103
            $GLOBALS['xoopsTpl']->assign('show_user_link', 'members.php?usid=' . $member_usid . '');
104
        }
105
    }
106
107
    $sql = 'SELECT COUNT(*)  FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE valid="No"';
108
    $result = $xoopsDB->query($sql);
109
    list($propo) = $xoopsDB->fetchRow($result);
110
111
    if ($propo > 0) {
112
        $GLOBALS['xoopsTpl']->assign('moderated', true);
113
    }
114
    if ($GLOBALS['xoopsUser'] instanceof \XoopsUser) {
115
        if ($GLOBALS['xoopsUser']->isAdmin()) {
116
            $GLOBALS['xoopsTpl']->assign('admin_block', _ADSLIGHT_ADMINCADRE);
117
            if (0 == $propo) {
118
                $GLOBALS['xoopsTpl']->assign('confirm_ads', _ADSLIGHT_NO_CLA);
119
            } else {
120
                $GLOBALS['xoopsTpl']->assign('confirm_ads', _ADSLIGHT_THEREIS . ' ' . $propo . '  ' . _ADSLIGHT_WAIT . '<br><a href="' . XOOPS_URL . '/modules/adslight/admin/validate_ads.php">' . _ADSLIGHT_SEEIT . '</a>');
121
            }
122
        }
123
124
        $categories = Adslight\Utility::getMyItemIds('adslight_submit');
125
        $intro      = (is_array($categories)
126
                       && (count($categories) > 0)) ? _ADSLIGHT_INTRO : '';
127
        $GLOBALS['xoopsTpl']->assign('intro', $intro);
128
    }
129
130
    $sql = 'SELECT SQL_CACHE cid, title, img FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE pid = 0 ';
131
132
    $categories = Adslight\Utility::getMyItemIds('adslight_view');
133
    if (is_array($categories) && count($categories) > 0) {
134
        $sql .= ' AND cid IN (' . implode(',', $categories) . ') ';
135
    } else {
136
        redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
137
    }
138
139
    $sql .= ('cat_order' === $GLOBALS['xoopsModuleConfig']['adslight_csortorder']) ? 'ORDER BY cat_order' : 'ORDER BY title';
140
141
    $result = $xoopsDB->query($sql);
142
143
    $count   = 1;
144
    $content = '';
145
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
146
        $title = $myts->htmlSpecialChars($myrow['title']);
147
148
        if ($myrow['img'] && 'http://' !== $myrow['img']) {
149
            $cat_img = $myts->htmlSpecialChars($myrow['img']);
150
            $img     = "<a href=\"viewcats.php?cid={$myrow['cid']}\"><img src=\"" . XOOPS_URL . "/modules/adslight/assets/images/img_cat/{$cat_img}\" align=\"middle\" alt=\"{$title}\"></a>";
151
        } else {
152
            $img = '';
153
        }
154
155
        $totallisting = Adslight\Utility::getTotalItems($myrow['cid'], 1);
156
        $content      .= $title . ' ';
157
158
        $arr = [];
159
        if (in_array($myrow['cid'], $categories)) {
160
            $arr           = $mytree->getFirstChild($myrow['cid'], 'title');
161
            $space         = 0;
162
            $chcount       = 1;
163
            $subcategories = '';
164
            if (1 == $GLOBALS['xoopsModuleConfig']['adslight_souscat']) {
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
            $GLOBALS['xoopsTpl']->append('categories', [
183
                'image'         => $img,
184
                'id'            => $myrow['cid'],
185
                'title'         => $myts->htmlSpecialChars($myrow['title']),
186
                'new'           => categorynewgraphic($myrow['cid']),
0 ignored issues
show
Are you sure the usage of categorynewgraphic($myrow['cid']) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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")));
0 ignored issues
show
Comprehensibility Best Practice introduced by
This list assign is not used and could be removed.
Loading history...
202
203
    $submit_perms = Adslight\Utility::getMyItemIds('adslight_submit');
0 ignored issues
show
The assignment to $submit_perms is dead and can be removed.
Loading history...
204
205
    if ($GLOBALS['xoopsUser'] instanceof \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
    $GLOBALS['xoopsTpl']->assign('bullinfotext', _ADSLIGHT_ACTUALY . ' ' . $ads . ' ' . _ADSLIGHT_ADVERTISEMENTS . '<br>' . $add_listing);
212
    $GLOBALS['xoopsTpl']->assign('total_confirm', _ADSLIGHT_AND . " $propo " . _ADSLIGHT_WAIT3);
213
214
    if (1 == $GLOBALS['xoopsModuleConfig']['adslight_newad']) {
215
        $cat_perms = '';
216
        if (is_array($categories) && count($categories) > 0) {
217
            $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
218
        }
219
220
        $sql = '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 {$GLOBALS['xoopsModuleConfig']['adslight_newcount']}";
223
        $result = $xoopsDB->query($sql);
224
        if ($result) {
225
            $GLOBALS['xoopsTpl']->assign('last_head', _ADSLIGHT_THE . ' ' . $GLOBALS['xoopsModuleConfig']['adslight_newcount'] . ' ' . _ADSLIGHT_LASTADD);
226
            $GLOBALS['xoopsTpl']->assign('last_head_title', _ADSLIGHT_TITLE);
227
            $GLOBALS['xoopsTpl']->assign('last_head_price', _ADSLIGHT_PRICE);
228
            $GLOBALS['xoopsTpl']->assign('last_head_date', _ADSLIGHT_DATE);
229
            $GLOBALS['xoopsTpl']->assign('last_head_local', _ADSLIGHT_LOCAL2);
230
            $GLOBALS['xoopsTpl']->assign('last_head_hits', _ADSLIGHT_VIEW);
231
            $GLOBALS['xoopsTpl']->assign('last_head_photo', _ADSLIGHT_PHOTO);
232
            $rank = 1;
233
234
            while (false !== (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    = [];
242
                $newcount  = $GLOBALS['xoopsModuleConfig']['adslight_countday'];
243
                $startdate = (time() - (86400 * $newcount));
244
245
                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'] instanceof \XoopsUser) {
252
                    $timezone   = $GLOBALS['xoopsUser']->timezone();
253
                    $useroffset = !empty($timezone) ? $GLOBALS['xoopsUser']->timezone() : $xoopsConfig['default_TZ'];
254
                    if ($GLOBALS['xoopsUser']->isAdmin()) {
255
                        $a_item['admin'] = '<a href="' . XOOPS_URL . "/modules/adslight/admin/validate_ads.php?op=modifyAds&amp;lid={$lid}\"><img src=\"{$pathIcon16}/edit.png\" border=\"0\" alt=\"" . _ADSLIGHT_MODADMIN . '"></a>';
256
                    }
257
                }
258
259
                $date = ($useroffset * 3600) + $date;
260
                $date = formatTimestamp($date, 's');
261
262
                $result7 = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' WHERE id_type=' . (int)$type);
263
                list($nom_type) = $xoopsDB->fetchRow($result7);
264
265
                $a_item['type']  = $myts->htmlSpecialChars($nom_type);
266
                $a_item['title'] = '<a href="' . XOOPS_URL . "/modules/adslight/viewads.php?lid={$lid}\"><strong>{$title}</strong></a>";
267
268
                $result8 = $xoopsDB->query('SELECT nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' WHERE id_price=' . (int)$typeprice);
269
                list($nom_price) = $xoopsDB->fetchRow($result8);
270
271
                if ($price > 0) {
272
                    $a_item['price']           = $price . ' ' . $GLOBALS['xoopsModuleConfig']['adslight_currency_symbol'] . '';
273
                    $a_item['price_typeprice'] = $myts->htmlSpecialChars($nom_price);
274
                } else {
275
                    $a_item['price']           = '';
276
                    $a_item['price_typeprice'] = $myts->htmlSpecialChars($nom_price);
277
                }
278
                $a_item['premium'] = $premium;
279
                $a_item['date']    = $date;
280
                $a_item['local']   = $town ?: '';
281
                $a_item['country'] = $country ?: '';
282
283
                if (2 == $status) {
284
                    $a_item['sold'] = _ADSLIGHT_RESERVEDMEMBER;
285
                }
286
287
                if ($helper->getConfig('active_thumbsindex') > 0) {
288
                    $a_item['no_photo'] = '<a href="' . XOOPS_URL . "/modules/adslight/viewads.php?lid={$lid}\"><img class=\"thumb\" src=\"" . XOOPS_URL . "/modules/adslight/assets/images/nophoto.jpg\" align=\"left\" width=\"100px\" alt=\"{$title}\"></a>";
289
290
                    $updir = $GLOBALS['xoopsModuleConfig']['adslight_link_upload'];
291
                    $sql   = 'SELECT cod_img, lid, uid_owner, url FROM ' . $xoopsDB->prefix('adslight_pictures') . ' WHERE  uid_owner=' . (int)$usid . " AND lid={$lid} ORDER BY date_added ASC LIMIT 1";
292
293
                    $resultp = $xoopsDB->query($sql);
294
295
                    while (false !== (list($cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($resultp))) {
296
                        if ($photo) {
297
                            $a_item['photo'] = '<a href="' . XOOPS_URL . "/modules/adslight/viewads.php?lid={$lid}\"><img class=\"thumb\" src=\"{$updir}/thumbs/thumb_{$url}\" align=\"left\" width=\"100px\" alt=\"{$title}\"></a>";
298
                        }
299
                    }
300
                } else {
301
                    $a_item['no_photo'] = '<img src="' . XOOPS_URL . "/modules/adslight/assets/images/camera_nophoto.png\" align=\"left\" width=\"24px\" alt=\"{$title}\">";
302
                    $updir              = $GLOBALS['xoopsModuleConfig']['adslight_link_upload'];
0 ignored issues
show
The assignment to $updir is dead and can be removed.
Loading history...
303
                    $sql                = 'SELECT cod_img, lid, uid_owner, url FROM ' . $xoopsDB->prefix('adslight_pictures') . ' WHERE uid_owner=' . (int)$usid . " AND lid={$lid} ORDER BY date_added ASC LIMIT 1";
304
                    $resultp            = $xoopsDB->query($sql);
305
306
                    while (false !== (list($cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($resultp))) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
This list assign is not used and could be removed.
Loading history...
307
                        if ($photo) {
308
                            $a_item['photo'] = '<img src="' . XOOPS_URL . "/modules/adslight/assets/images/camera_photo.png\" align=\"left\" width=\"24\" alt=\"{$title}\">";
309
                        }
310
                    }
311
                }
312
                $a_item['hits'] = $hits;
313
                ++$rank;
314
                $GLOBALS['xoopsTpl']->append('items', $a_item);
315
            }
316
        }
317
    }
318
}
319
320
#  function categorynewgraphic
321
#####################################################
322
/**
323
 * @param $cid
324
 */
325
function categorynewgraphic($cid)
0 ignored issues
show
The parameter $cid is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

325
function categorynewgraphic(/** @scrutinizer ignore-unused */ $cid)

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

Loading history...
326
{
327
    global $xoopsDB;
328
}
329
330
######################################################
331
332
$pa      = Request::getInt('pa', null, 'GET');
333
$lid     = Request::getInt('lid', null, 'GET');
334
$cid     = Request::getInt('cid', null, 'GET');
335
$usid    = Request::getString('usid', '', 'GET');
336
$min     = Request::getInt('min', null, 'GET');
337
$show    = Request::getInt('show', null, 'GET');
338
$orderby = Request::getInt('orderby', null, 'GET');
339
340
switch ($pa) {
341
    case 'adsview':
342
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
343
        adsView($cid, $min, $orderby, $show);
344
        break;
345
    case 'viewads':
346
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_item.tpl';
347
        viewAds($lid);
348
        break;
349
    default:
350
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_index.tpl';
351
//        $GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
352
        index();
353
        break;
354
}
355
356
require_once XOOPS_ROOT_PATH . '/footer.php';
357