Passed
Push — master ( 978347...893ae4 )
by Michael
02:45
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
use XoopsModules\Adslight\Helper;
27
28
$GLOBALS['xoopsOption']['template_main'] = 'adslight_category.tpl';
29
30
global $xoopsModule;
31
32
require_once __DIR__ . '/header.php';
33
34
$myts      = \MyTextSanitizer::getInstance();
35
$module_id = $xoopsModule->getVar('mid');
36
37
$groups = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
38
39
/** @var \XoopsGroupPermHandler $grouppermHandler */
40
$grouppermHandler = xoops_getHandler('groupperm');
41
42
$perm_itemid = Request::getInt('item_id', 0, 'POST');
43
44
if (!$grouppermHandler->checkRight('adslight_view', $perm_itemid, $groups, $module_id)) {
45
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
46
}
47
48
$prem_perm = (!$grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) ? '0' : '1';
49
50
$mytree = new Adslight\ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
51
52
#  function index
53
#####################################################
54
55
function index()
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', $GLOBALS['xoopsModuleConfig']['adslight_use_index_code']);
85
    $GLOBALS['xoopsTpl']->assign('adslight_use_banner', $GLOBALS['xoopsModuleConfig']['adslight_use_banner']);
86
    $GLOBALS['xoopsTpl']->assign('index_extra_code', $GLOBALS['xoopsModuleConfig']['adslight_index_code']);
87
    $GLOBALS['xoopsTpl']->assign('index_code_place', $GLOBALS['xoopsModuleConfig']['adslight_index_code_place']);
88
    $GLOBALS['xoopsTpl']->assign('category_title2', _ADSLIGHT_ANNONCES);
89
    // adslight 2
90
    $GLOBALS['xoopsTpl']->assign('adslight_active_menu', $GLOBALS['xoopsModuleConfig']['adslight_active_menu']);
91
    $GLOBALS['xoopsTpl']->assign('adslight_active_rss', $GLOBALS['xoopsModuleConfig']['adslight_active_rss']);
92
93
    //    ExpireAd();
94
    Adslight\Utility::expireAd();
95
96
    if ($GLOBALS['xoopsUser']) {
97
        $member_usid = $GLOBALS['xoopsUser']->getVar('uid');
98
        if ($usid = $member_usid) {
0 ignored issues
show
The assignment to $usid is dead and can be removed.
Loading history...
99
            $GLOBALS['xoopsTpl']->assign('istheirs', true);
100
101
            [$show_user] = $xoopsDB->fetchRow($xoopsDB->query('SELECT SQL_CACHE COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE usid=' . $member_usid . ' '));
102
103
            $GLOBALS['xoopsTpl']->assign('show_user', $show_user);
104
            $GLOBALS['xoopsTpl']->assign('show_user_link', 'members.php?usid=' . $member_usid . '');
105
        }
106
    }
107
108
    $sql = 'SELECT COUNT(*)  FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE valid="No"';
109
    $result = $xoopsDB->query($sql);
110
    [$propo] = $xoopsDB->fetchRow($result);
111
112
    if ($propo > 0) {
113
        $GLOBALS['xoopsTpl']->assign('moderated', true);
114
    }
115
    if ($GLOBALS['xoopsUser'] instanceof \XoopsUser) {
116
        if ($GLOBALS['xoopsUser']->isAdmin()) {
117
            $GLOBALS['xoopsTpl']->assign('admin_block', _ADSLIGHT_ADMINCADRE);
118
            if (0 == $propo) {
119
                $GLOBALS['xoopsTpl']->assign('confirm_ads', _ADSLIGHT_NO_CLA);
120
            } else {
121
                $GLOBALS['xoopsTpl']->assign('confirm_ads', _ADSLIGHT_THEREIS . ' ' . $propo . '  ' . _ADSLIGHT_WAIT . '<br><a href="' . XOOPS_URL . '/modules/adslight/admin/validate_ads.php">' . _ADSLIGHT_SEEIT . '</a>');
122
            }
123
        }
124
125
        $categories = Adslight\Utility::getMyItemIds('adslight_submit');
126
        $intro      = (is_array($categories)
127
                       && (count($categories) > 0)) ? _ADSLIGHT_INTRO : '';
128
        $GLOBALS['xoopsTpl']->assign('intro', $intro);
129
    }
130
131
    $sql = 'SELECT SQL_CACHE cid, title, img FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE pid = 0 ';
132
133
    $categories = Adslight\Utility::getMyItemIds('adslight_view');
134
    if (is_array($categories) && count($categories) > 0) {
135
        $sql .= ' AND cid IN (' . implode(',', $categories) . ') ';
136
    } else {
137
        redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
138
    }
139
140
    $sql .= ('cat_order' === $GLOBALS['xoopsModuleConfig']['adslight_csortorder']) ? 'ORDER BY cat_order' : 'ORDER BY title';
141
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 = Adslight\Utility::getTotalItems($myrow['cid'], 1);
157
        $content      .= $title . ' ';
158
159
        $arr = [];
160
        if (in_array($myrow['cid'], $categories)) {
161
            $arr           = $mytree->getFirstChild($myrow['cid'], 'title');
162
            $space         = 0;
163
            $chcount       = 1;
164
            $subcategories = '';
165
            if (1 == $GLOBALS['xoopsModuleConfig']['adslight_souscat']) {
166
                foreach ($arr as $ele) {
167
                    if (in_array($ele['cid'], $categories)) {
168
                        $chtitle = \htmlspecialchars($ele['title'], ENT_QUOTES | ENT_HTML5);
169
                        if ($chcount > $GLOBALS['xoopsModuleConfig']['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
    [$ads] = $xoopsDB->fetchRow($xoopsDB->query('SELECT SQL_CACHE COUNT(*)  FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE valid='Yes' AND status!='1' {$cat_perms}"));
201
202
    [$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...
203
204
    $submit_perms = Adslight\Utility::getMyItemIds('adslight_submit');
0 ignored issues
show
The assignment to $submit_perms is dead and can be removed.
Loading history...
205
206
    if ($GLOBALS['xoopsUser'] instanceof \XoopsUser) {
207
        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULLOK . '<a href="add.php">' . _ADSLIGHT_ADD_LISTING_SUBOK . '</a>';
208
    } else {
209
        $add_listing = '' . _ADSLIGHT_ADD_LISTING_BULL . '<a href="' . XOOPS_URL . '/register.php">' . _ADSLIGHT_ADD_LISTING_SUB . '</a>.';
210
    }
211
212
    $GLOBALS['xoopsTpl']->assign('bullinfotext', _ADSLIGHT_ACTUALY . ' ' . $ads . ' ' . _ADSLIGHT_ADVERTISEMENTS . '<br>' . $add_listing);
213
    $GLOBALS['xoopsTpl']->assign('total_confirm', _ADSLIGHT_AND . " $propo " . _ADSLIGHT_WAIT3);
214
215
    if (1 == $GLOBALS['xoopsModuleConfig']['adslight_newad']) {
216
        $cat_perms = '';
217
        if (is_array($categories) && count($categories) > 0) {
218
            $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') ';
219
        }
220
221
        $sql = 'SELECT  SQL_CACHE  lid, title, status, type, price, typeprice, date, town, country, usid, premium, valid, photo, hits FROM '
222
                                  . $xoopsDB->prefix('adslight_listing')
223
                                  . " WHERE valid='Yes' and status!='1' {$cat_perms} ORDER BY date DESC LIMIT {$GLOBALS['xoopsModuleConfig']['adslight_newcount']}";
224
        $result = $xoopsDB->query($sql);
225
        if ($result) {
226
            $GLOBALS['xoopsTpl']->assign('last_head', _ADSLIGHT_THE . ' ' . $GLOBALS['xoopsModuleConfig']['adslight_newcount'] . ' ' . _ADSLIGHT_LASTADD);
227
            $GLOBALS['xoopsTpl']->assign('last_head_title', _ADSLIGHT_TITLE);
228
            $GLOBALS['xoopsTpl']->assign('last_head_price', _ADSLIGHT_PRICE);
229
            $GLOBALS['xoopsTpl']->assign('last_head_date', _ADSLIGHT_DATE);
230
            $GLOBALS['xoopsTpl']->assign('last_head_local', _ADSLIGHT_LOCAL2);
231
            $GLOBALS['xoopsTpl']->assign('last_head_hits', _ADSLIGHT_VIEW);
232
            $GLOBALS['xoopsTpl']->assign('last_head_photo', _ADSLIGHT_PHOTO);
233
            $rank = 1;
234
235
            while (false !== (list($lid, $title, $status, $type, $price, $typeprice, $date, $town, $country, $usid, $premium, $valid, $photo, $hits) = $xoopsDB->fetchRow($result))) {
236
                $title = \htmlspecialchars($title, ENT_QUOTES | ENT_HTML5);
237
                $type  = \htmlspecialchars($type, ENT_QUOTES | ENT_HTML5);
238
                //                $price     = number_format($price, 2, ',', ' ');
239
                $town      = \htmlspecialchars($town, ENT_QUOTES | ENT_HTML5);
240
                $country   = \htmlspecialchars($country, ENT_QUOTES | ENT_HTML5);
241
                $premium   = \htmlspecialchars($premium, ENT_QUOTES | ENT_HTML5);
242
                $a_item    = [];
243
                $newcount  = $GLOBALS['xoopsModuleConfig']['adslight_countday'];
244
                $startdate = (time() - (86400 * $newcount));
245
246
                if ($startdate < $date) {
247
                    $newitem       = '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/newred.gif" alt="new" >';
248
                    $a_item['new'] = $newitem;
249
                }
250
251
                $useroffset = '';
252
                if ($GLOBALS['xoopsUser'] instanceof \XoopsUser) {
253
                    $timezone   = $GLOBALS['xoopsUser']->timezone();
254
                    $useroffset = !empty($timezone) ? $GLOBALS['xoopsUser']->timezone() : $xoopsConfig['default_TZ'];
255
                    if ($GLOBALS['xoopsUser']->isAdmin()) {
256
                        $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>';
257
                    }
258
                }
259
260
                $date = ($useroffset * 3600) + $date;
261
                $date = formatTimestamp($date, 's');
262
263
                $result7 = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' WHERE id_type=' . (int)$type);
264
                [$nom_type] = $xoopsDB->fetchRow($result7);
265
266
                $a_item['type']  = \htmlspecialchars($nom_type, ENT_QUOTES | ENT_HTML5);
267
                $a_item['title'] = '<a href="' . XOOPS_URL . "/modules/adslight/viewads.php?lid={$lid}\"><strong>{$title}</strong></a>";
268
269
                $result8 = $xoopsDB->query('SELECT nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' WHERE id_price=' . (int)$typeprice);
270
                [$nom_price] = $xoopsDB->fetchRow($result8);
271
272
                if ($price > 0) {
273
                    $a_item['price']           = $price . ' ' . $GLOBALS['xoopsModuleConfig']['adslight_currency_symbol'] . '';
274
                    $a_item['price_typeprice'] = \htmlspecialchars($nom_price, ENT_QUOTES | ENT_HTML5);
275
                } else {
276
                    $a_item['price']           = '';
277
                    $a_item['price_typeprice'] = \htmlspecialchars($nom_price, ENT_QUOTES | ENT_HTML5);
278
                }
279
                $a_item['premium'] = $premium;
280
                $a_item['date']    = $date;
281
                $a_item['local']   = $town ?: '';
282
                $a_item['country'] = $country ?: '';
283
284
                if (2 == $status) {
285
                    $a_item['sold'] = _ADSLIGHT_RESERVEDMEMBER;
286
                }
287
288
                if ($helper->getConfig('active_thumbsindex') > 0) {
289
                    $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>";
290
291
                    $updir = $GLOBALS['xoopsModuleConfig']['adslight_link_upload'];
292
                    $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";
293
294
                    $resultp = $xoopsDB->query($sql);
295
296
                    while (false !== (list($cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($resultp))) {
297
                        if ($photo) {
298
                            $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>";
299
                        }
300
                    }
301
                } else {
302
                    $a_item['no_photo'] = '<img src="' . XOOPS_URL . "/modules/adslight/assets/images/camera_nophoto.png\" align=\"left\" width=\"24px\" alt=\"{$title}\">";
303
                    $updir              = $GLOBALS['xoopsModuleConfig']['adslight_link_upload'];
0 ignored issues
show
The assignment to $updir is dead and can be removed.
Loading history...
304
                    $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";
305
                    $resultp            = $xoopsDB->query($sql);
306
307
                    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...
308
                        if ($photo) {
309
                            $a_item['photo'] = '<img src="' . XOOPS_URL . "/modules/adslight/assets/images/camera_photo.png\" align=\"left\" width=\"24\" alt=\"{$title}\">";
310
                        }
311
                    }
312
                }
313
                $a_item['hits'] = $hits;
314
                ++$rank;
315
                $GLOBALS['xoopsTpl']->append('items', $a_item);
316
            }
317
        }
318
    }
319
}
320
321
#  function categorynewgraphic
322
#####################################################
323
/**
324
 * @param $cid
325
 */
326
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

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