Passed
Push — master ( 2aaf26...f22b21 )
by Michael
03:06
created

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