Passed
Push — master ( 222087...05cb95 )
by Michael
03:24 queued 10s
created

index.php (1 issue)

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