Passed
Push — master ( e8b784...3aca22 )
by Michael
15:11 queued 10:10
created

index.php (7 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
-------------------------------------------------------------------------
7
                     ADSLIGHT 2 : Module for Xoops
8
9
        Redesigned and ameliorate By iluc user at www.frxoops.org
10
        Started with the Classifieds module and made MANY changes
11
        Website : http://www.limonads.com
12
        Contact : [email protected]
13
-------------------------------------------------------------------------
14
             Original credits below Version History
15
##########################################################################
16
#                    Classified Module for Xoops                         #
17
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
18
#      Started with the MyAds module and made MANY changes               #
19
##########################################################################
20
 Original Author: Pascal Le Boustouller
21
 Author Website : [email protected]
22
 Licence Type   : GPL
23
-------------------------------------------------------------------------
24
*/
25
26
use Xmf\Module\Admin;
27
use Xmf\Request;
28
use XoopsModules\Adslight\{
29
    Tree,
30
    Helper,
31
    Utility
32
};
33
34
$GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
35
36
global $xoopsModule;
37
38
require_once __DIR__ . '/header.php';
39
40
$myts      = \MyTextSanitizer::getInstance();
41
$module_id = $xoopsModule->getVar('mid');
42
43
$groups = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
44
45
/** @var \XoopsGroupPermHandler $grouppermHandler */
46
$grouppermHandler = xoops_getHandler('groupperm');
47
48
$perm_itemid = Request::getInt('item_id', 0, 'POST');
49
50
if (!$grouppermHandler->checkRight('adslight_view', $perm_itemid, $groups, $module_id)) {
51
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
52
}
53
54
$prem_perm = (!$grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) ? '0' : '1';
55
56
$mytree = new Tree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
57
58
#  function index
59
#####################################################
60
61
function index()
62
{
63
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $mytree, $meta, $mid, $prem_perm;
64
    $pathIcon16    = Admin::iconUrl('', 16);
65
    $moduleDirName = \basename(__DIR__);
66
67
    $helper = Helper::getInstance();
68
69
    if (!isset($GLOBALS['xoopsTpl']) || !($GLOBALS['xoopsTpl'] instanceof XoopsTpl)) {
70
        require_once $GLOBALS['xoops']->path('class/template.php');
71
        $GLOBALS['xoopsTpl'] = new \XoopsTpl();
72
    }
73
74
    //    $GLOBALS['xoopsOption']['template_main'] = 'adslight_index.tpl';
75
76
    require_once XOOPS_ROOT_PATH . '/header.php';
77
78
    $GLOBALS['xoopsTpl']->assign('xmid', $xoopsModule->getVar('mid'));
79
    $GLOBALS['xoopsTpl']->assign('add_from', _ADSLIGHT_ADDFROM . ' ' . $xoopsConfig['sitename']);
80
    $GLOBALS['xoopsTpl']->assign('add_from_title', _ADSLIGHT_ADDFROM);
81
    $GLOBALS['xoopsTpl']->assign('add_from_sitename', $xoopsConfig['sitename']);
82
    $GLOBALS['xoopsTpl']->assign('only_pix', _ADSLIGHT_ONLYPIX);
83
    $GLOBALS['xoopsTpl']->assign('adslight_logolink', _ADSLIGHT_LOGOLINK);
84
    $GLOBALS['xoopsTpl']->assign('permit', $prem_perm);
85
86
    $GLOBALS['xoopsTpl']->assign('xoops_module_header', '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/assets/css/adslight.css" type="text/css" media="all" >');
87
88
    $banner = xoops_getbanner();
89
    $GLOBALS['xoopsTpl']->assign('banner', $banner);
90
    $GLOBALS['xoopsTpl']->assign('use_extra_code', $GLOBALS['xoopsModuleConfig']['adslight_use_index_code']);
91
    $GLOBALS['xoopsTpl']->assign('adslight_use_banner', $GLOBALS['xoopsModuleConfig']['adslight_use_banner']);
92
    $GLOBALS['xoopsTpl']->assign('index_extra_code', $GLOBALS['xoopsModuleConfig']['adslight_index_code']);
93
    $GLOBALS['xoopsTpl']->assign('index_code_place', $GLOBALS['xoopsModuleConfig']['adslight_index_code_place']);
94
    $GLOBALS['xoopsTpl']->assign('category_title2', _ADSLIGHT_ANNONCES);
95
    // adslight 2
96
    $GLOBALS['xoopsTpl']->assign('adslight_active_menu', $GLOBALS['xoopsModuleConfig']['adslight_active_menu']);
97
    $GLOBALS['xoopsTpl']->assign('adslight_active_rss', $GLOBALS['xoopsModuleConfig']['adslight_active_rss']);
98
99
    //    ExpireAd();
100
    Utility::expireAd();
101
102
    if ($GLOBALS['xoopsUser']) {
103
        $member_usid = $GLOBALS['xoopsUser']->getVar('uid');
104
        if ($usid = $member_usid) {
0 ignored issues
show
The assignment to $usid is dead and can be removed.
Loading history...
105
            $GLOBALS['xoopsTpl']->assign('istheirs', true);
106
107
            [$show_user] = $xoopsDB->fetchRow($xoopsDB->query('SELECT SQL_CACHE COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE usid=' . $member_usid . ' '));
108
109
            $GLOBALS['xoopsTpl']->assign('show_user', $show_user);
110
            $GLOBALS['xoopsTpl']->assign('show_user_link', 'members.php?usid=' . $member_usid . '');
111
        }
112
    }
113
114
    $sql    = 'SELECT COUNT(*)  FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE valid="No"';
115
    $result = $xoopsDB->query($sql);
116
    [$propo] = $xoopsDB->fetchRow($result);
117
118
    if ($propo > 0) {
119
        $GLOBALS['xoopsTpl']->assign('moderated', true);
120
    }
121
    if ($GLOBALS['xoopsUser'] instanceof \XoopsUser) {
122
        if ($GLOBALS['xoopsUser']->isAdmin()) {
123
            $GLOBALS['xoopsTpl']->assign('admin_block', _ADSLIGHT_ADMINCADRE);
124
            if (0 == $propo) {
125
                $GLOBALS['xoopsTpl']->assign('confirm_ads', _ADSLIGHT_NO_CLA);
126
            } else {
127
                $GLOBALS['xoopsTpl']->assign('confirm_ads', _ADSLIGHT_THEREIS . ' ' . $propo . '  ' . _ADSLIGHT_WAIT . '<br><a href="' . XOOPS_URL . '/modules/adslight/admin/validate_ads.php">' . _ADSLIGHT_SEEIT . '</a>');
128
            }
129
        }
130
131
        $categories = Utility::getMyItemIds('adslight_submit');
132
        $intro      = (is_array($categories)
133
                       && (count($categories) > 0)) ? _ADSLIGHT_INTRO : '';
134
        $GLOBALS['xoopsTpl']->assign('intro', $intro);
135
    }
136
137
    $sql = 'SELECT SQL_CACHE cid, title, img FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE pid = 0 ';
138
139
    $categories = Utility::getMyItemIds('adslight_view');
140
    if (is_array($categories) && count($categories) > 0) {
141
        $sql .= ' AND cid IN (' . implode(',', $categories) . ') ';
142
    } else {
143
        redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
144
    }
145
146
    $sql .= ('cat_order' === $GLOBALS['xoopsModuleConfig']['adslight_csortorder']) ? 'ORDER BY cat_order' : 'ORDER BY title';
147
148
    $result = $xoopsDB->query($sql);
149
150
    $count   = 1;
151
    $content = '';
152
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
153
        $title = \htmlspecialchars($myrow['title'], ENT_QUOTES | ENT_HTML5);
154
155
        if ($myrow['img'] && 'http://' !== $myrow['img']) {
156
            $cat_img = \htmlspecialchars($myrow['img'], ENT_QUOTES | ENT_HTML5);
157
            $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>";
158
        } else {
159
            $img = '';
160
        }
161
162
        $totallisting = Utility::getTotalItems($myrow['cid'], 1);
163
        $content      .= $title . ' ';
164
165
        $arr = [];
166
        if (in_array($myrow['cid'], $categories)) {
167
            $arr           = $mytree->getFirstChild($myrow['cid'], 'title');
168
            $space         = 0;
169
            $chcount       = 1;
170
            $subcategories = '';
171
            if (1 == $GLOBALS['xoopsModuleConfig']['adslight_souscat']) {
172
                foreach ($arr as $ele) {
173
                    if (in_array($ele['cid'], $categories)) {
174
                        $chtitle = \htmlspecialchars($ele['title'], ENT_QUOTES | ENT_HTML5);
175
                        if ($chcount > $GLOBALS['xoopsModuleConfig']['adslight_nbsouscat']) {
176
                            $subcategories .= "<a href=\"viewcats.php?cid={$myrow['cid']}\">" . _ADSLIGHT_CATPLUS . '</a>';
177
                            break;
178
                        }
179
                        if ($space > 0) {
180
                            $subcategories .= '<br>';
181
                        }
182
                        $subcategories .= '-&nbsp;<a href="' . XOOPS_URL . "/modules/adslight/viewcats.php?cid={$ele['cid']}\">{$chtitle}</a>";
183
                        ++$space;
184
                        ++$chcount;
185
                        $content .= $ele['title'] . ' ';
186
                    }
187
                }
188
            }
189
            $GLOBALS['xoopsTpl']->append('categories', [
190
                'image'         => $img,
191
                'id'            => $myrow['cid'],
192
                'title'         => htmlspecialchars($myrow['title'], ENT_QUOTES | ENT_HTML5),
193
                '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...
194
                'subcategories' => $subcategories,
195
                'totallisting'  => $totallisting,
196
                'count'         => $count,
197
            ]);
198
            ++$count;
199
        }
200
    }
201
    $cat_perms = '';
202
    if (is_array($categories) && count($categories) > 0) {
203
        $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
204
    }
205
206
    [$ads] = $xoopsDB->fetchRow($xoopsDB->query('SELECT SQL_CACHE COUNT(*)  FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='Yes' AND status!='1' {$cat_perms}"));
207
208
    [$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...
209
210
    $submit_perms = Utility::getMyItemIds('adslight_submit');
0 ignored issues
show
The assignment to $submit_perms is dead and can be removed.
Loading history...
211
212
    if ($GLOBALS['xoopsUser'] instanceof \XoopsUser) {
213
        //        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULLOK . '<a href="add.php">' . _ADSLIGHT_ADD_LISTING_SUBOK . '</a>';
214
        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULLOK . '<a rel="nofollow" class="btn btn-success text-right"  title="submit your ad" href="add.php">' . _ADSLIGHT_ADD_LISTING_SUBOK . '</a>';
215
    } else {
216
        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULL . '<a href="' . XOOPS_URL . '/register.php">' . _ADSLIGHT_ADD_LISTING_SUB . '</a>.';
217
    }
218
219
    $GLOBALS['xoopsTpl']->assign('bullinfotext', _ADSLIGHT_ACTUALY . ' ' . $ads . ' ' . _ADSLIGHT_ADVERTISEMENTS . '<br>' . $add_listing);
220
    $GLOBALS['xoopsTpl']->assign('total_confirm', _ADSLIGHT_AND . " $propo " . _ADSLIGHT_WAIT3);
221
222
    if (1 == $GLOBALS['xoopsModuleConfig']['adslight_newad']) {
223
        $cat_perms = '';
224
        if (is_array($categories) && count($categories) > 0) {
225
            $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
226
        }
227
228
        $sql    = 'SELECT  SQL_CACHE  lid, title, status, type, price, typeprice, date_created, town, country, usid, premium, valid, photo, hits FROM '
229
                  . $xoopsDB->prefix('adslight_listing')
230
                  . " WHERE valid='Yes' and status!='1' {$cat_perms} ORDER BY date_created DESC LIMIT {$GLOBALS['xoopsModuleConfig']['adslight_newcount']}";
231
        $result = $xoopsDB->query($sql);
232
        if ($result) {
233
            $GLOBALS['xoopsTpl']->assign('last_head', _ADSLIGHT_THE . ' ' . $GLOBALS['xoopsModuleConfig']['adslight_newcount'] . ' ' . _ADSLIGHT_LASTADD);
234
            $GLOBALS['xoopsTpl']->assign('last_head_title', _ADSLIGHT_TITLE);
235
            $GLOBALS['xoopsTpl']->assign('last_head_price', _ADSLIGHT_PRICE);
236
            $GLOBALS['xoopsTpl']->assign('last_head_date', _ADSLIGHT_DATE);
237
            $GLOBALS['xoopsTpl']->assign('last_head_local', _ADSLIGHT_LOCAL2);
238
            $GLOBALS['xoopsTpl']->assign('last_head_hits', _ADSLIGHT_VIEW);
239
            $GLOBALS['xoopsTpl']->assign('last_head_photo', _ADSLIGHT_PHOTO);
240
            $rank = 1;
241
242
            while (false !== (list($lid, $title, $status, $type, $price, $typeprice, $date_created, $town, $country, $usid, $premium, $valid, $photo, $hits) = $xoopsDB->fetchRow($result))) {
243
                $title = \htmlspecialchars($title, ENT_QUOTES | ENT_HTML5);
244
                $type  = \htmlspecialchars($type, ENT_QUOTES | ENT_HTML5);
245
                //                $price     = number_format($price, 2, ',', ' ');
246
                $town      = \htmlspecialchars($town, ENT_QUOTES | ENT_HTML5);
247
                $country   = \htmlspecialchars($country, ENT_QUOTES | ENT_HTML5);
248
                $premium   = \htmlspecialchars($premium, ENT_QUOTES | ENT_HTML5);
249
                $a_item    = [];
250
                $newcount  = $GLOBALS['xoopsModuleConfig']['adslight_countday'];
251
                $startdate = (time() - (86400 * $newcount));
252
253
                if ($startdate < $date_created) {
254
                    $newitem       = '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/newred.gif" alt="new" >';
255
                    $a_item['new'] = $newitem;
256
                }
257
258
                $useroffset = '';
259
                if ($GLOBALS['xoopsUser'] instanceof \XoopsUser) {
260
                    $timezone   = $GLOBALS['xoopsUser']->timezone();
261
                    $useroffset = !empty($timezone) ? $GLOBALS['xoopsUser']->timezone() : $xoopsConfig['default_TZ'];
262
                    if ($GLOBALS['xoopsUser']->isAdmin()) {
263
                        $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>';
264
                    }
265
                }
266
267
                $date_created = ($useroffset * 3600) + $date_created;
268
                $date_created = formatTimestamp($date_created, 's');
269
270
                $result7 = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' WHERE id_type=' . (int)$type);
271
                [$nom_type] = $xoopsDB->fetchRow($result7);
272
273
                $a_item['type']  = \htmlspecialchars($nom_type, ENT_QUOTES | ENT_HTML5);
274
                $a_item['title'] = '<a href="' . XOOPS_URL . "/modules/adslight/viewads.php?lid={$lid}\"><strong>{$title}</strong></a>";
275
276
                $result8 = $xoopsDB->query('SELECT nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' WHERE id_price=' . (int)$typeprice);
277
                [$nom_price] = $xoopsDB->fetchRow($result8);
278
279
                if ($price > 0) {
280
                    //                    $a_item['price']           = $price . ' ' . $GLOBALS['xoopsModuleConfig']['adslight_currency_symbol'] . '';
281
                    $currencyCode                 = $helper->getConfig('adslight_currency_code');
282
                    $currencySymbol               = $helper->getConfig('adslight_currency_symbol');
283
                    $currencyPosition             = $helper->getConfig('currency_position');
284
                    $formattedCurrencyUtilityTemp = Utility::formatCurrencyTemp($price, $currencyCode, $currencySymbol, $currencyPosition);
285
286
                    $priceHtml       = '<strong>' . _ADSLIGHT_PRICE2 . '</strong>' . $formattedCurrencyUtilityTemp . ' - ' . $nom_price;
287
                    $a_item['price'] = $priceHtml;
288
289
                    $a_item['price_typeprice'] = \htmlspecialchars($nom_price, ENT_QUOTES | ENT_HTML5);
290
                } else {
291
                    $a_item['price']           = '';
292
                    $a_item['price_typeprice'] = \htmlspecialchars($nom_price, ENT_QUOTES | ENT_HTML5);
293
                }
294
295
                $a_item['premium'] = $premium;
296
                $a_item['date_created']    = $date_created;
297
                $a_item['local']   = $town ?: '';
298
                $a_item['country'] = $country ?: '';
299
300
                if (2 == $status) {
301
                    $a_item['sold'] = _ADSLIGHT_RESERVEDMEMBER;
302
                }
303
304
                if ($helper->getConfig('active_thumbsindex') > 0) {
305
                    $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>";
306
307
                    $updir = $GLOBALS['xoopsModuleConfig']['adslight_link_upload'];
308
                    $sql   = 'SELECT cod_img, lid, uid_owner, url FROM ' . $xoopsDB->prefix('adslight_pictures') . ' WHERE  uid_owner=' . (int)$usid . " AND lid={$lid} ORDER BY date_created ASC LIMIT 1";
309
310
                    $resultp = $xoopsDB->query($sql);
311
312
                    while (false !== (list($cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($resultp))) {
313
                        if ($photo) {
314
                            $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>";
315
                        }
316
                    }
317
                } else {
318
                    $a_item['no_photo'] = '<img src="' . XOOPS_URL . "/modules/adslight/assets/images/camera_nophoto.png\" align=\"left\" width=\"24px\" alt=\"{$title}\">";
319
                    $updir              = $GLOBALS['xoopsModuleConfig']['adslight_link_upload'];
0 ignored issues
show
The assignment to $updir is dead and can be removed.
Loading history...
320
                    $sql                = 'SELECT cod_img, lid, uid_owner, url FROM ' . $xoopsDB->prefix('adslight_pictures') . ' WHERE uid_owner=' . (int)$usid . " AND lid={$lid} ORDER BY date_created ASC LIMIT 1";
321
                    $resultp            = $xoopsDB->query($sql);
322
323
                    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...
324
                        if ($photo) {
325
                            $a_item['photo'] = '<img src="' . XOOPS_URL . "/modules/adslight/assets/images/camera_photo.png\" align=\"left\" width=\"24\" alt=\"{$title}\">";
326
                        }
327
                    }
328
                }
329
                $a_item['hits'] = $hits;
330
                ++$rank;
331
                $GLOBALS['xoopsTpl']->append('items', $a_item);
332
            }
333
        }
334
    }
335
}
336
337
#  function categorynewgraphic
338
#####################################################
339
/**
340
 * @param $cid
341
 */
342
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

342
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...
343
{
344
    global $xoopsDB;
345
}
346
347
######################################################
348
349
$pa      = Request::getInt('pa', null, 'GET');
350
$lid     = Request::getInt('lid', null, 'GET');
351
$cid     = Request::getInt('cid', null, 'GET');
352
$usid    = Request::getString('usid', '', 'GET');
353
$min     = Request::getInt('min', null, 'GET');
354
$show    = Request::getInt('show', null, 'GET');
355
$orderby = Request::getInt('orderby', null, 'GET');
356
357
switch ($pa) {
358
    case 'adsview':
359
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
360
        adsView($cid, $min, $orderby, $show);
361
        break;
362
    case 'viewads':
363
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_item.tpl';
364
        viewAds($lid);
365
        break;
366
    default:
367
        $GLOBALS['xoopsOption']['template_main'] = 'adslight_index.tpl';
368
        //        $GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
369
        index();
370
        break;
371
}
372
373
require_once XOOPS_ROOT_PATH . '/footer.php';
374