Passed
Push — master ( 1a0aae...3beb71 )
by Michael
03:11
created

index.php (6 issues)

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

340
function categorynewgraphic(/** @scrutinizer ignore-unused */ $cid): void

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