Passed
Push — master ( 89b06b...05ee30 )
by Michael
02:40
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\Module\Admin;
24
use Xmf\Request;
25
use XoopsModules\Adslight\{
26
    ClassifiedsTree,
27
    Helper,
28
    Utility
29
};
30
31
32
$GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
33
34
global $xoopsModule;
35
36
require_once __DIR__ . '/header.php';
37
38
$myts      = \MyTextSanitizer::getInstance();
39
$module_id = $xoopsModule->getVar('mid');
40
41
$groups = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
42
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, $module_id)) {
49
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
50
}
51
52
$prem_perm = (!$grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) ? '0' : '1';
53
54
$mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
55
56
#  function index
57
#####################################################
58
59
function index()
60
{
61
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $mytree, $meta, $mid, $prem_perm;
62
    $pathIcon16 = Admin::iconUrl('', 16);
63
    $moduleDirName = basename(__DIR__);
64
65
    $helper = Helper::getInstance();
66
67
    if (!isset($GLOBALS['xoopsTpl']) || !($GLOBALS['xoopsTpl'] instanceof XoopsTpl)) {
68
        require_once $GLOBALS['xoops']->path('class/template.php');
69
        $GLOBALS['xoopsTpl'] = new \XoopsTpl();
70
    }
71
72
    //    $GLOBALS['xoopsOption']['template_main'] = 'adslight_index.tpl';
73
74
    require_once XOOPS_ROOT_PATH . '/header.php';
75
76
    $GLOBALS['xoopsTpl']->assign('xmid', $xoopsModule->getVar('mid'));
77
    $GLOBALS['xoopsTpl']->assign('add_from', _ADSLIGHT_ADDFROM . ' ' . $xoopsConfig['sitename']);
78
    $GLOBALS['xoopsTpl']->assign('add_from_title', _ADSLIGHT_ADDFROM);
79
    $GLOBALS['xoopsTpl']->assign('add_from_sitename', $xoopsConfig['sitename']);
80
    $GLOBALS['xoopsTpl']->assign('only_pix', _ADSLIGHT_ONLYPIX);
81
    $GLOBALS['xoopsTpl']->assign('adslight_logolink', _ADSLIGHT_LOGOLINK);
82
    $GLOBALS['xoopsTpl']->assign('permit', $prem_perm);
83
84
    $GLOBALS['xoopsTpl']->assign('xoops_module_header', '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/assets/css/adslight.css" type="text/css" media="all" >');
85
86
    $banner = xoops_getbanner();
87
    $GLOBALS['xoopsTpl']->assign('banner', $banner);
88
    $GLOBALS['xoopsTpl']->assign('use_extra_code', $GLOBALS['xoopsModuleConfig']['adslight_use_index_code']);
89
    $GLOBALS['xoopsTpl']->assign('adslight_use_banner', $GLOBALS['xoopsModuleConfig']['adslight_use_banner']);
90
    $GLOBALS['xoopsTpl']->assign('index_extra_code', $GLOBALS['xoopsModuleConfig']['adslight_index_code']);
91
    $GLOBALS['xoopsTpl']->assign('index_code_place', $GLOBALS['xoopsModuleConfig']['adslight_index_code_place']);
92
    $GLOBALS['xoopsTpl']->assign('category_title2', _ADSLIGHT_ANNONCES);
93
    // adslight 2
94
    $GLOBALS['xoopsTpl']->assign('adslight_active_menu', $GLOBALS['xoopsModuleConfig']['adslight_active_menu']);
95
    $GLOBALS['xoopsTpl']->assign('adslight_active_rss', $GLOBALS['xoopsModuleConfig']['adslight_active_rss']);
96
97
    //    ExpireAd();
98
    Utility::expireAd();
99
100
    if ($GLOBALS['xoopsUser']) {
101
        $member_usid = $GLOBALS['xoopsUser']->getVar('uid');
102
        if ($usid = $member_usid) {
0 ignored issues
show
The assignment to $usid is dead and can be removed.
Loading history...
103
            $GLOBALS['xoopsTpl']->assign('istheirs', true);
104
105
            [$show_user] = $xoopsDB->fetchRow($xoopsDB->query('SELECT SQL_CACHE COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE usid=' . $member_usid . ' '));
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
144
    $sql .= ('cat_order' === $GLOBALS['xoopsModuleConfig']['adslight_csortorder']) ? 'ORDER BY cat_order' : 'ORDER BY title';
145
146
    $result = $xoopsDB->query($sql);
147
148
    $count   = 1;
149
    $content = '';
150
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
151
        $title = \htmlspecialchars($myrow['title'], ENT_QUOTES | ENT_HTML5);
152
153
        if ($myrow['img'] && 'http://' !== $myrow['img']) {
154
            $cat_img = \htmlspecialchars($myrow['img'], ENT_QUOTES | ENT_HTML5);
155
            $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>";
156
        } else {
157
            $img = '';
158
        }
159
160
        $totallisting = Utility::getTotalItems($myrow['cid'], 1);
161
        $content      .= $title . ' ';
162
163
        $arr = [];
164
        if (in_array($myrow['cid'], $categories)) {
165
            $arr           = $mytree->getFirstChild($myrow['cid'], 'title');
166
            $space         = 0;
167
            $chcount       = 1;
168
            $subcategories = '';
169
            if (1 == $GLOBALS['xoopsModuleConfig']['adslight_souscat']) {
170
                foreach ($arr as $ele) {
171
                    if (in_array($ele['cid'], $categories)) {
172
                        $chtitle = \htmlspecialchars($ele['title'], ENT_QUOTES | ENT_HTML5);
173
                        if ($chcount > $GLOBALS['xoopsModuleConfig']['adslight_nbsouscat']) {
174
                            $subcategories .= "<a href=\"viewcats.php?cid={$myrow['cid']}\">" . _ADSLIGHT_CATPLUS . '</a>';
175
                            break;
176
                        }
177
                        if ($space > 0) {
178
                            $subcategories .= '<br>';
179
                        }
180
                        $subcategories .= '-&nbsp;<a href="' . XOOPS_URL . "/modules/adslight/viewcats.php?cid={$ele['cid']}\">{$chtitle}</a>";
181
                        ++$space;
182
                        ++$chcount;
183
                        $content .= $ele['title'] . ' ';
184
                    }
185
                }
186
            }
187
            $GLOBALS['xoopsTpl']->append('categories', [
188
                'image'         => $img,
189
                'id'            => $myrow['cid'],
190
                'title'         => htmlspecialchars($myrow['title'], ENT_QUOTES | ENT_HTML5),
191
                '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...
192
                'subcategories' => $subcategories,
193
                'totallisting'  => $totallisting,
194
                'count'         => $count,
195
            ]);
196
            ++$count;
197
        }
198
    }
199
    $cat_perms = '';
200
    if (is_array($categories) && count($categories) > 0) {
201
        $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
202
    }
203
204
    [$ads] = $xoopsDB->fetchRow($xoopsDB->query('SELECT SQL_CACHE COUNT(*)  FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='Yes' AND status!='1' {$cat_perms}"));
205
206
    [$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...
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
214
    } else {
215
        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULL . '<a href="' . XOOPS_URL . '/register.php">' . _ADSLIGHT_ADD_LISTING_SUB . '</a>.';
216
    }
217
218
    $GLOBALS['xoopsTpl']->assign('bullinfotext', _ADSLIGHT_ACTUALY . ' ' . $ads . ' ' . _ADSLIGHT_ADVERTISEMENTS . '<br>' . $add_listing);
219
    $GLOBALS['xoopsTpl']->assign('total_confirm', _ADSLIGHT_AND . " $propo " . _ADSLIGHT_WAIT3);
220
221
    if (1 == $GLOBALS['xoopsModuleConfig']['adslight_newad']) {
222
        $cat_perms = '';
223
        if (is_array($categories) && count($categories) > 0) {
224
            $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
225
        }
226
227
        $sql = 'SELECT  SQL_CACHE  lid, title, status, type, price, typeprice, date, town, country, usid, premium, valid, photo, hits FROM '
228
                                  . $xoopsDB->prefix('adslight_listing')
229
                                  . " WHERE valid='Yes' and status!='1' {$cat_perms} ORDER BY date DESC LIMIT {$GLOBALS['xoopsModuleConfig']['adslight_newcount']}";
230
        $result = $xoopsDB->query($sql);
231
        if ($result) {
232
            $GLOBALS['xoopsTpl']->assign('last_head', _ADSLIGHT_THE . ' ' . $GLOBALS['xoopsModuleConfig']['adslight_newcount'] . ' ' . _ADSLIGHT_LASTADD);
233
            $GLOBALS['xoopsTpl']->assign('last_head_title', _ADSLIGHT_TITLE);
234
            $GLOBALS['xoopsTpl']->assign('last_head_price', _ADSLIGHT_PRICE);
235
            $GLOBALS['xoopsTpl']->assign('last_head_date', _ADSLIGHT_DATE);
236
            $GLOBALS['xoopsTpl']->assign('last_head_local', _ADSLIGHT_LOCAL2);
237
            $GLOBALS['xoopsTpl']->assign('last_head_hits', _ADSLIGHT_VIEW);
238
            $GLOBALS['xoopsTpl']->assign('last_head_photo', _ADSLIGHT_PHOTO);
239
            $rank = 1;
240
241
            while (false !== (list($lid, $title, $status, $type, $price, $typeprice, $date, $town, $country, $usid, $premium, $valid, $photo, $hits) = $xoopsDB->fetchRow($result))) {
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  = $GLOBALS['xoopsModuleConfig']['adslight_countday'];
250
                $startdate = (time() - (86400 * $newcount));
251
252
                if ($startdate < $date) {
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 = ($useroffset * 3600) + $date;
267
                $date = formatTimestamp($date, 's');
268
269
                $result7 = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' WHERE id_type=' . (int)$type);
270
                [$nom_type] = $xoopsDB->fetchRow($result7);
271
272
                $a_item['type']  = \htmlspecialchars($nom_type, ENT_QUOTES | ENT_HTML5);
273
                $a_item['title'] = '<a href="' . XOOPS_URL . "/modules/adslight/viewads.php?lid={$lid}\"><strong>{$title}</strong></a>";
274
275
                $result8 = $xoopsDB->query('SELECT nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' WHERE id_price=' . (int)$typeprice);
276
                [$nom_price] = $xoopsDB->fetchRow($result8);
277
278
                if ($price > 0) {
279
//                    $a_item['price']           = $price . ' ' . $GLOBALS['xoopsModuleConfig']['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']    = $date;
296
                $a_item['local']   = $town ?: '';
297
                $a_item['country'] = $country ?: '';
298
299
                if (2 == $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 = $GLOBALS['xoopsModuleConfig']['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_added ASC LIMIT 1";
308
309
                    $resultp = $xoopsDB->query($sql);
310
311
                    while (false !== (list($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              = $GLOBALS['xoopsModuleConfig']['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_added ASC LIMIT 1";
320
                    $resultp            = $xoopsDB->query($sql);
321
322
                    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...
323
                        if ($photo) {
324
                            $a_item['photo'] = '<img src="' . XOOPS_URL . "/modules/adslight/assets/images/camera_photo.png\" align=\"left\" width=\"24\" alt=\"{$title}\">";
325
                        }
326
                    }
327
                }
328
                $a_item['hits'] = $hits;
329
                ++$rank;
330
                $GLOBALS['xoopsTpl']->append('items', $a_item);
331
            }
332
        }
333
    }
334
}
335
336
#  function categorynewgraphic
337
#####################################################
338
/**
339
 * @param $cid
340
 */
341
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

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