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

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