Passed
Push — master ( 0405fd...a3f27c )
by Michael
02:30
created

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

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