These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | ------------------------------------------------------------------------- |
||
4 | ADSLIGHT 2 : Module for Xoops |
||
5 | |||
6 | Redesigned and ameliorate By Luc Bizet user at www.frxoops.org |
||
7 | Started with the Classifieds module and made MANY changes |
||
8 | Website : http://www.luc-bizet.fr |
||
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 | include_once __DIR__ . '/header.php'; |
||
24 | require_once XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php'; |
||
25 | xoops_load('XoopsLocal'); |
||
26 | |||
27 | $myts = MyTextSanitizer::getInstance(); |
||
28 | $module_id = $xoopsModule->getVar('mid'); |
||
29 | |||
30 | View Code Duplication | if (is_object($GLOBALS['xoopsUser'])) { |
|
31 | $groups = $GLOBALS['xoopsUser']->getGroups(); |
||
32 | } else { |
||
33 | $groups = XOOPS_GROUP_ANONYMOUS; |
||
34 | } |
||
35 | $gpermHandler = xoops_getHandler('groupperm'); |
||
36 | $perm_itemid = XoopsRequest::getInt('item_id', 0, 'POST'); |
||
37 | //If no access |
||
38 | View Code Duplication | if (!$gpermHandler->checkRight('adslight_view', $perm_itemid, $groups, $module_id)) { |
|
39 | redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM); |
||
40 | } |
||
41 | if (!$gpermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) { |
||
42 | $prem_perm = '0'; |
||
43 | } else { |
||
44 | $prem_perm = '1'; |
||
45 | } |
||
46 | |||
47 | include XOOPS_ROOT_PATH . '/modules/adslight/class/classifiedstree.php'; |
||
48 | //include XOOPS_ROOT_PATH . '/modules/adslight/class/utilities.php'; |
||
49 | $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid'); |
||
50 | |||
51 | # function viewads |
||
52 | ##################################################### |
||
53 | /** |
||
54 | * @param int $lid |
||
55 | */ |
||
56 | function viewAds($lid = 0) |
||
1 ignored issue
–
show
|
|||
57 | { |
||
58 | global $xoopsDB, $xoopsConfig, $xoopsModule, $xoopsTpl, $myts, $meta, $moduleDirName, $main_lang, $prem_perm, $xoopsModule; |
||
1 ignored issue
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
59 | global $xoopsModuleConfig, $xoopsUser; |
||
1 ignored issue
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
60 | $pathIcon16 = $xoopsModule->getInfo('icons16'); |
||
61 | |||
62 | $tempXoopsLocal = new XoopsLocal; |
||
63 | $GLOBALS['xoopsOption']['template_main'] = 'adslight_item.tpl'; |
||
64 | include XOOPS_ROOT_PATH . '/header.php'; |
||
65 | include XOOPS_ROOT_PATH . '/include/comment_view.php'; |
||
66 | $lid = ((int)$lid > 0) ? (int)$lid : 0; |
||
67 | $rate = ($GLOBALS['xoopsModuleConfig']['adslight_rate_item'] == '1') ? '1' : '0'; |
||
68 | $xoopsTpl->assign('rate', $rate); |
||
69 | $xoopsTpl->assign('xmid', $xoopsModule->getVar('mid')); |
||
70 | $xoopsTpl->assign('adslight_logolink', _ADSLIGHT_LOGOLINK); |
||
71 | |||
72 | // Hack redirection erreur 404 si lid=null |
||
73 | View Code Duplication | if ($lid == '') { |
|
74 | header('Status: 301 Moved Permanently', false, 301); |
||
75 | // header('Location: '.XOOPS_URL.'/modules/adslight/404.php'); |
||
76 | // exit(); |
||
77 | redirect_header(XOOPS_URL . '/modules/adslight/404.php', 1); |
||
78 | } |
||
79 | |||
80 | $xoopsTpl->assign('adslight_active_bookmark', $GLOBALS['xoopsModuleConfig']['adslight_active_bookmark']); |
||
81 | $xoopsTpl->assign('adslight_style_bookmark', $GLOBALS['xoopsModuleConfig']['adslight_style_bookmark']); |
||
82 | $xoopsTpl->assign('adslight_active_xpayement', $GLOBALS['xoopsModuleConfig']['adslight_active_xpayment']); |
||
83 | |||
84 | // adslight 2 |
||
85 | $xoopsTpl->assign('adslight_active_menu', $GLOBALS['xoopsModuleConfig']['adslight_active_menu']); |
||
86 | $xoopsTpl->assign('adslight_active_rss', $GLOBALS['xoopsModuleConfig']['adslight_active_rss']); |
||
87 | |||
88 | if ($GLOBALS['xoopsUser']) { |
||
89 | $member_usid = $GLOBALS['xoopsUser']->getVar('uid'); |
||
90 | if ($usid = $member_usid) { |
||
91 | $xoopsTpl->assign('istheirs', true); |
||
92 | |||
93 | if (strlen($GLOBALS['xoopsUser']->getVar('name'))) { |
||
94 | $xoopsTpl->assign('user_name', $GLOBALS['xoopsUser']->getVar('name') . ' (' . $GLOBALS['xoopsUser']->getVar('uname') . ')'); |
||
95 | } else { |
||
96 | $xoopsTpl->assign('user_name', $GLOBALS['xoopsUser']->getVar('uname')); |
||
97 | } |
||
98 | |||
99 | $xoopsTpl->assign('user_email', $GLOBALS['xoopsUser']->getVar('email')); |
||
100 | |||
101 | list($show_user) = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE usid=$member_usid")); |
||
102 | |||
103 | $xoopsTpl->assign('show_user', $show_user); |
||
104 | $xoopsTpl->assign('show_user_link', 'members.php?usid=' . $member_usid); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | if ($GLOBALS['xoopsUser']) { |
||
109 | $currentid = $GLOBALS['xoopsUser']->getVar('uid', 'E'); |
||
110 | } |
||
111 | |||
112 | $cat_perms = ''; |
||
113 | $categories = AdslightUtilities::getMyItemIds('adslight_view'); |
||
114 | if (is_array($categories) && count($categories) > 0) { |
||
115 | $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') '; |
||
116 | } |
||
117 | |||
118 | $result = $xoopsDB->query('SELECT l.lid, l.cid, l.title, l.status, l.expire, l.type, l.desctext, l.tel, l.price, l.typeprice, l.typeusure, l.date, l.email, l.submitter, l.usid, l.town, l.country, l.contactby, l.premium, l.valid, l.photo, l.hits, l.item_rating, l.item_votes, l.user_rating, l.user_votes, l.comments, p.cod_img, p.lid, p.uid_owner, p.url FROM ' |
||
119 | . $xoopsDB->prefix('adslight_listing') |
||
120 | . ' l LEFT JOIN ' |
||
121 | . $xoopsDB->prefix('adslight_pictures') |
||
122 | . " p ON l.lid=p.lid WHERE l.valid='Yes' AND l.lid = " |
||
123 | . $xoopsDB->escape($lid) |
||
124 | . " and l.status!='1' $cat_perms"); |
||
125 | $recordexist = $xoopsDB->getRowsNum($result); |
||
126 | |||
127 | // Hack redirection erreur 404 si recordexist=null |
||
128 | View Code Duplication | if ($recordexist == '') { |
|
129 | header('Status: 301 Moved Permanently', false, 301); |
||
130 | // header('Location: '.XOOPS_URL.'/modules/adslight/404.php'); |
||
131 | // exit(); |
||
132 | redirect_header(XOOPS_URL . '/modules/adslight/404.php', 1); |
||
133 | } |
||
134 | |||
135 | if ($recordexist) { |
||
136 | list($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $usid, $town, $country, $contactby, $premium, $valid, $photo, $hits, $item_rating, $item_votes, $user_rating, $user_votes, $comments, $cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($result); |
||
137 | |||
138 | $newcount = $GLOBALS['xoopsModuleConfig']['adslight_countday']; |
||
139 | $startdate = (time() - (86400 * $newcount)); |
||
140 | if ($startdate < $date) { |
||
141 | $newitem = '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/newred.gif" alt="new" />'; |
||
142 | $xoopsTpl->assign('new', $newitem); |
||
143 | } |
||
144 | |||
145 | $updir = $GLOBALS['xoopsModuleConfig']['adslight_link_upload']; |
||
146 | $xoopsTpl->assign('add_from', _ADSLIGHT_ADDFROM . ' ' . $xoopsConfig['sitename']); |
||
147 | $xoopsTpl->assign('add_from_title', _ADSLIGHT_ADDFROM); |
||
148 | $xoopsTpl->assign('add_from_sitename', $xoopsConfig['sitename']); |
||
149 | $xoopsTpl->assign('ad_exists', $recordexist); |
||
150 | $xoopsTpl->assign('mydirname', $moduleDirName); |
||
151 | |||
152 | $count = 0; |
||
153 | $x = 0; |
||
154 | $i = 0; |
||
155 | |||
156 | $result3 = $xoopsDB->query('SELECT cid, pid, title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . $xoopsDB->escape($cid)); |
||
157 | list($ccid, $pid, $ctitle) = $xoopsDB->fetchRow($result3); |
||
158 | |||
159 | $xoopsTpl->assign('category_title', $ctitle); |
||
160 | |||
161 | $module_id = $xoopsModule->getVar('mid'); |
||
162 | View Code Duplication | if (is_object($GLOBALS['xoopsUser'])) { |
|
163 | $groups = $GLOBALS['xoopsUser']->getGroups(); |
||
164 | } else { |
||
165 | $groups = XOOPS_GROUP_ANONYMOUS; |
||
166 | } |
||
167 | $gpermHandler = xoops_getHandler('groupperm'); |
||
168 | $xoopsTpl->assign('purchasable', $gpermHandler->checkRight('adslight_purchase', $cid, $groups, $module_id)); |
||
169 | |||
170 | $ctitle = $myts->htmlSpecialChars($ctitle); |
||
171 | $varid[$x] = $ccid; |
||
172 | $varnom[$x] = $ctitle; |
||
173 | |||
174 | list($nbe) = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE valid="Yes" AND cid=' . $xoopsDB->escape($cid) . ' AND status!="1"')); |
||
175 | |||
176 | if ($pid != 0) { |
||
177 | $x = 1; |
||
178 | while ($pid != 0) { |
||
179 | $result4 = $xoopsDB->query('SELECT cid, pid, title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . $xoopsDB->escape($pid)); |
||
180 | list($ccid, $pid, $ctitle) = $xoopsDB->fetchRow($result4); |
||
181 | |||
182 | $ctitle = $myts->htmlSpecialChars($ctitle); |
||
183 | $varid[$x] = $ccid; |
||
184 | $varnom[$x] = $ctitle; |
||
185 | ++$x; |
||
186 | } |
||
187 | --$x; |
||
188 | } |
||
189 | $subcats = ''; |
||
190 | $arrow = ' <img src="' . XOOPS_URL . '/modules/adslight/assets/images/arrow.gif" alt="»" />'; |
||
191 | while ($x != -1) { |
||
192 | $subcats .= ' ' . $arrow . ' <a href="viewcats.php?cid=' . $varid[$x] . '">' . $varnom[$x] . '</a>'; |
||
193 | --$x; |
||
194 | } |
||
195 | $xoopsTpl->assign('nav_main', '<a href="index.php">' . _ADSLIGHT_MAIN . '</a>'); |
||
196 | $xoopsTpl->assign('nav_sub', $subcats); |
||
197 | $xoopsTpl->assign('nav_subcount', $nbe); |
||
198 | $viewcount_judge = true; |
||
199 | $useroffset = ''; |
||
200 | if ($GLOBALS['xoopsUser']) { |
||
201 | $timezone = $GLOBALS['xoopsUser']->timezone(); |
||
202 | if (isset($timezone)) { |
||
203 | $useroffset = $GLOBALS['xoopsUser']->timezone(); |
||
204 | } else { |
||
205 | $useroffset = $xoopsConfig['default_TZ']; |
||
206 | } |
||
207 | if ($GLOBALS['xoopsUser']->isAdmin()) { |
||
208 | $adslight_admin = true; |
||
209 | } else { |
||
210 | $adslight_admin = false; |
||
211 | } |
||
212 | |||
213 | if (($adslight_admin = true) || ($GLOBALS['xoopsUser']->getVar('uid') == $usid)) { |
||
214 | $viewcount_judge = false; |
||
215 | } |
||
216 | |||
217 | $contact_pm = '<a href="' . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . addslashes($usid) . '"> ' . _ADSLIGHT_CONTACT_BY_PM . '</a>'; |
||
218 | } |
||
219 | if (true === $viewcount_judge) { |
||
220 | $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_listing') . ' SET hits=hits+1 WHERE lid = ' . $xoopsDB->escape($lid)); |
||
221 | } |
||
222 | if ($item_votes == 1) { |
||
223 | $votestring = _ADSLIGHT_ONEVOTE; |
||
224 | } else { |
||
225 | $votestring = sprintf(_ADSLIGHT_NUMVOTES, $item_votes); |
||
226 | } |
||
227 | $date = ($useroffset * 3600) + $date; |
||
228 | $date2 = $date + ($expire * 86400); |
||
229 | $date = formatTimestamp($date, 's'); |
||
230 | $date2 = formatTimestamp($date2, 's'); |
||
231 | $title = $myts->htmlSpecialChars($title); |
||
232 | $status = $myts->htmlSpecialChars($status); |
||
233 | $expire = $myts->htmlSpecialChars($expire); |
||
234 | $type = $myts->htmlSpecialChars($type); |
||
235 | $desctext = $myts->displayTarea($desctext, 1, 1, 1); |
||
236 | $tel = $myts->htmlSpecialChars($tel); |
||
237 | // $price = XoopsLocal::number_format($price, 2, ',', ' '); |
||
238 | $typeprice = $myts->htmlSpecialChars($typeprice); |
||
239 | $typeusure = $myts->htmlSpecialChars($typeusure); |
||
240 | $submitter = $myts->htmlSpecialChars($submitter); |
||
241 | $usid = $myts->htmlSpecialChars($usid); |
||
242 | $town = $myts->htmlSpecialChars($town); |
||
243 | $country = $myts->htmlSpecialChars($country); |
||
244 | $contactby = $myts->htmlSpecialChars($contactby); |
||
245 | $premium = $myts->htmlSpecialChars($premium); |
||
246 | |||
247 | if ($status == 2) { |
||
248 | $sold = _ADSLIGHT_RESERVED; |
||
249 | } else { |
||
250 | $sold = ''; |
||
251 | } |
||
252 | |||
253 | $xoopsTpl->assign('printA', '<a href="print.php?op=PrintAd&lid=' . $lid . '" ><img src="assets/images/print.gif" border=0 alt="' . _ADSLIGHT_PRINT . '" /></a> '); |
||
254 | |||
255 | if ($usid > 0) { |
||
256 | $xoopsTpl->assign('submitter', '<img src="assets/images/lesannonces.png" border="0" alt="' |
||
257 | . _ADSLIGHT_VIEW_MY_ADS |
||
258 | . '" /> <a href="members.php?usid=' |
||
259 | . addslashes($usid) |
||
260 | . '" />' |
||
261 | . _ADSLIGHT_VIEW_MY_ADS |
||
262 | . ' ' |
||
263 | . $submitter |
||
264 | . '</a>'); |
||
265 | } else { |
||
266 | $xoopsTpl->assign('submitter', _ADSLIGHT_VIEW_MY_ADS . ' $submitter'); |
||
267 | } |
||
268 | $xoopsTpl->assign('lid', $lid); |
||
269 | $xoopsTpl->assign('read', "$hits " . _ADSLIGHT_VIEW2); |
||
270 | $xoopsTpl->assign('rating', $tempXoopsLocal->number_format($item_rating, 2)); |
||
271 | $xoopsTpl->assign('votes', $votestring); |
||
272 | $xoopsTpl->assign('lang_rating', _ADSLIGHT_RATINGC); |
||
273 | $xoopsTpl->assign('lang_ratethisitem', _ADSLIGHT_RATETHISITEM); |
||
274 | $xoopsTpl->assign('xoop_user', false); |
||
275 | $isOwner = ''; |
||
276 | if ($GLOBALS['xoopsUser']) { |
||
277 | $xoopsTpl->assign('xoop_user', true); |
||
278 | $currentid = $GLOBALS['xoopsUser']->getVar('uid', 'E'); |
||
279 | if ($usid == $currentid) { |
||
280 | $xoopsTpl->assign('modifyads', '<img src=' |
||
281 | . $pathIcon16 |
||
282 | . '/edit.png border="0" alt="' |
||
283 | . _ADSLIGHT_MODIFANN |
||
284 | . '" /> <a href="modify.php?op=ModAd&lid=' |
||
285 | . $lid |
||
286 | . '">' |
||
287 | . _ADSLIGHT_MODIFANN |
||
288 | . '</a>'); |
||
289 | $xoopsTpl->assign('deleteads', '<img src=' |
||
290 | . $pathIcon16 |
||
291 | . '/delete.png border="0" alt="' |
||
292 | . _ADSLIGHT_SUPPRANN |
||
293 | . '" /> <a href="modify.php?op=ListingDel&lid=' |
||
294 | . $lid |
||
295 | . '">' |
||
296 | . _ADSLIGHT_SUPPRANN |
||
297 | . '</a>'); |
||
298 | $xoopsTpl->assign('add_photos', '<img src="assets/images/shape_square_add.png" border="0" alt="' |
||
299 | . _ADSLIGHT_SUPPRANN |
||
300 | . '" /> <a href="view_photos.php?lid=' |
||
301 | . $lid |
||
302 | . '&uid=' |
||
303 | . $usid |
||
304 | . '">' |
||
305 | . _ADSLIGHT_ADD_PHOTOS |
||
306 | . '</a>'); |
||
307 | |||
308 | $isOwner = true; |
||
309 | $xoopsTpl->assign('isOwner', $isOwner); |
||
310 | } |
||
311 | if ($GLOBALS['xoopsUser']->isAdmin()) { |
||
312 | $xoopsTpl->assign('admin', '<a href="' |
||
313 | . XOOPS_URL |
||
314 | . '/modules/adslight/admin/modify_ads.php?op=ModifyAds&lid=' |
||
315 | . $lid |
||
316 | . '"><img src=' |
||
317 | . $pathIcon16 |
||
318 | . '/edit.png border=0 alt="' |
||
319 | . _ADSLIGHT_MODADMIN |
||
320 | . '" /></a>'); |
||
321 | } |
||
322 | } |
||
323 | |||
324 | $result7 = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . " WHERE id_type='" . $xoopsDB->escape($type) . "'"); |
||
325 | list($nom_type) = $xoopsDB->fetchRow($result7); |
||
326 | |||
327 | $result8 = $xoopsDB->query('SELECT nom_price FROM ' . $xoopsDB->prefix('adslight_price') . " WHERE id_price='" . $xoopsDB->escape($typeprice) . "'"); |
||
328 | list($nom_price) = $xoopsDB->fetchRow($result8); |
||
329 | |||
330 | $result9 = $xoopsDB->query('SELECT nom_usure FROM ' . $xoopsDB->prefix('adslight_usure') . " WHERE id_usure='" . $xoopsDB->escape($typeusure) . "'"); |
||
331 | list($nom_usure) = $xoopsDB->fetchRow($result9); |
||
332 | |||
333 | $xoopsTpl->assign('type', $myts->htmlSpecialChars($nom_type)); |
||
334 | $xoopsTpl->assign('title', $title); |
||
335 | $xoopsTpl->assign('status', $status); |
||
336 | $xoopsTpl->assign('desctext', $desctext); |
||
337 | $xoopsTpl->assign('xoops_pagetitle', $title . ' - ' . $town . ': ' . $country . ' - ' . $ctitle); |
||
338 | |||
339 | // meta description tags for ads |
||
340 | $desctextclean = strip_tags($desctext, '<font><img><strong><i><u>'); |
||
341 | $xoTheme->addMeta('meta', 'description', "$title - " . substr($desctextclean, 0, 150)); |
||
0 ignored issues
–
show
|
|||
342 | |||
343 | if ($price > 0) { |
||
344 | $xoopsTpl->assign('price', '<strong>' . _ADSLIGHT_PRICE2 . '</strong>' . $price . ' ' . $GLOBALS['xoopsModuleConfig']['adslight_money'] . ' - ' . $typeprice); |
||
345 | $xoopsTpl->assign('price_head', _ADSLIGHT_PRICE2); |
||
346 | // $xoopsTpl->assign('price_price', $price.' '.$GLOBALS['xoopsModuleConfig']['adslight_money'].' '); |
||
347 | |||
348 | $xoopsTpl->assign('price_price', AdslightUtilities::getMoneyFormat('%.2n', $price)); |
||
349 | |||
350 | $xoopsTpl->assign('price_typeprice', $myts->htmlSpecialChars($nom_price)); |
||
351 | $xoopsTpl->assign('price_currency', $GLOBALS['xoopsModuleConfig']['adslight_currency']); |
||
352 | $xoopsTpl->assign('price_amount', $price); |
||
353 | } |
||
354 | |||
355 | $xoopsTpl->assign('usure_typeusure', $nom_usure); |
||
356 | $xoopsTpl->assign('premium', $premium); |
||
357 | |||
358 | // $xoopsTpl->assign('mustlogin', _ADSLIGHT_MUSTLOGIN); |
||
359 | $xoopsTpl->assign('redirect', '' . '?xoops_redirect=/modules/adslight/index.php'); |
||
360 | |||
361 | if ($town) { |
||
362 | $xoopsTpl->assign('local_town', $town); |
||
363 | } |
||
364 | if ($GLOBALS['xoopsModuleConfig']['adslight_use_country'] == 1) { |
||
365 | if ($country) { |
||
366 | $xoopsTpl->assign('local_country', $country); |
||
367 | $xoopsTpl->assign('country_head', '<img src="assets/images/world_go.png" border="0" alt="country" /> ' . _ADSLIGHT_COUNTRY); |
||
368 | } |
||
369 | } |
||
370 | |||
371 | $tphon = ''; |
||
372 | if ($tel) { |
||
373 | $tphon = '<br>' . _ADSLIGHT_ORBY . ' <strong>' . _ADSLIGHT_TEL . '</strong> ' . $tel; |
||
374 | } |
||
375 | |||
376 | if ($contactby == 1) { |
||
377 | $contact = '<a rel="nofollow" href="contact.php?lid=' . $lid . '">' . _ADSLIGHT_BYMAIL2 . '</a>' . $tphon . ''; |
||
378 | } |
||
379 | if ($contactby == 2) { |
||
380 | $contact = $contact_pm . '' . $tphon; |
||
0 ignored issues
–
show
The variable
$contact_pm does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
381 | } |
||
382 | if ($contactby == 3) { |
||
383 | $contact = '<a rel="nofollow" href="contact.php?lid=' . $lid . '">' . _ADSLIGHT_BYMAIL2 . '</a>' . $tphon . '<br>' . _ADSLIGHT_ORBY . '' . $contact_pm; |
||
384 | } |
||
385 | if ($contactby == 4) { |
||
386 | $contact = '<br><strong>' . _ADSLIGHT_TEL . '</strong> ' . $tel; |
||
387 | } |
||
388 | // $xoopsTpl->assign('contact', $contact); |
||
389 | $xoopsTpl->assign('local_head', '<img src="assets/images/house.png" border="0" alt="local_head" /> ' . _ADSLIGHT_LOCAL); |
||
390 | |||
391 | if ($lid) { |
||
392 | if ($sold) { |
||
393 | $xoopsTpl->assign('bullinfotext', $sold); |
||
394 | } else { |
||
395 | if ($GLOBALS['xoopsUser']) { |
||
396 | $xoopsTpl->assign('bullinfotext', _ADSLIGHT_CONTACT_SUBMITTER . ' ' . $submitter . ' ' . _ADSLIGHT_CONTACTBY2 . ' ' . $contact); |
||
0 ignored issues
–
show
The variable
$contact does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
397 | } else { |
||
398 | $xoopsTpl->assign('bullinfotext', '<span style="color: #de090e;"><b>' . _ADSLIGHT_MUSTLOGIN . '</b></span>'); |
||
399 | } |
||
400 | } |
||
401 | } |
||
402 | |||
403 | $user_profile = XoopsUser::getUnameFromId($usid); |
||
404 | $xoopsTpl->assign('user_profile', '<img src="assets/images/profil.png" border="0" alt="' |
||
405 | . _ADSLIGHT_PROFILE |
||
406 | . '" /> <a rel="nofollow" href="' |
||
407 | . XOOPS_URL |
||
408 | . '/user.php?usid=' |
||
409 | . addslashes($usid) |
||
410 | . '">' |
||
411 | . _ADSLIGHT_PROFILE |
||
412 | . ' ' |
||
413 | . $user_profile |
||
414 | . '</a>'); |
||
415 | |||
416 | if ($photo != '') { |
||
417 | include_once __DIR__ . '/class/pictures.php'; |
||
418 | |||
419 | $criteria_lid = new criteria('lid', $lid); |
||
420 | $criteria_uid = new criteria('uid', $usid); |
||
421 | $album_factory = new Xoopsjlm_picturesHandler($xoopsDB); |
||
422 | $pictures_object_array =& $album_factory->getObjects($criteria_lid, $criteria_uid); |
||
423 | $pictures_number = $album_factory->getCount($criteria_lid, $criteria_uid); |
||
424 | View Code Duplication | if ($pictures_number == 0) { |
|
425 | $nopicturesyet = _ADSLIGHT_NOTHINGYET; |
||
426 | $xoopsTpl->assign('lang_nopicyet', $nopicturesyet); |
||
427 | } else { |
||
428 | |||
429 | /** |
||
430 | * Lets populate an array with the data from the pictures |
||
431 | */ |
||
432 | $i = 0; |
||
433 | foreach ($pictures_object_array as $picture) { |
||
434 | $pictures_array[$i]['url'] = $picture->getVar('url', 's'); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$pictures_array was never initialized. Although not strictly required by PHP, it is generally a good practice to add $pictures_array = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
435 | $pictures_array[$i]['desc'] = $picture->getVar('title', 's'); |
||
0 ignored issues
–
show
The variable
$pictures_array does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
436 | $pictures_array[$i]['cod_img'] = $picture->getVar('cod_img', 's'); |
||
437 | $pictures_array[$i]['lid'] = $picture->getVar('lid', 's'); |
||
438 | $xoopsTpl->assign('pics_array', $pictures_array); |
||
439 | |||
440 | ++$i; |
||
441 | } |
||
442 | } |
||
443 | $owner = new XoopsUser(); |
||
444 | $identifier = $owner->getUnameFromId($usid); |
||
445 | if ($GLOBALS['xoopsModuleConfig']['adslight_lightbox'] == 1) { |
||
446 | $header_lightbox = '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/assets/css/adslight.css" type="text/css" media="all" /> |
||
447 | <script type="text/javascript" src="assets/lightbox/js/jquery-1.7.2.min.js"></script> |
||
448 | <script type="text/javascript" src="assets/lightbox/js/jquery-ui-1.8.18.custom.min"></script> |
||
449 | <script type="text/javascript" src="assets/lightbox/js/jquery.smooth-scroll.min.js"></script> |
||
450 | <script type="text/javascript" src="assets/lightbox/js/lightbox.js"></script> |
||
451 | <link rel="stylesheet" href="assets/css/galery.css" type="text/css" media="screen" /> |
||
452 | <link rel="stylesheet" type="text/css" media="screen" href="assets/lightbox/css/lightbox.css"></link>'; |
||
453 | } else { |
||
454 | $header_lightbox = '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/assets/css/adslight.css" type="text/css" media="all" /> |
||
455 | <link rel="stylesheet" href="assets/css/galery.css" type="text/css" media="screen" />'; |
||
456 | } |
||
457 | |||
458 | $xoopsTpl->assign('path_uploads', $GLOBALS['xoopsModuleConfig']['adslight_link_upload']); |
||
459 | |||
460 | $xoopsTpl->assign('permit', $prem_perm); |
||
461 | |||
462 | if ($GLOBALS['xoopsModuleConfig']['active_rewriteurl'] > 0) { |
||
463 | /* ici le meta Canonicale pour le Rewrite */ |
||
464 | $xoopsTpl->assign('xoops_module_header', $header_lightbox); |
||
465 | } else { |
||
466 | $xoopsTpl->assign('xoops_module_header', $header_lightbox); |
||
467 | } |
||
468 | $xoopsTpl->assign('photo', $photo); |
||
469 | $xoopsTpl->assign('pic_lid', $pic_lid); |
||
470 | $xoopsTpl->assign('pic_owner', $uid_owner); |
||
471 | } else { |
||
472 | $xoopsTpl->assign('photo', ''); |
||
473 | } |
||
474 | $xoopsTpl->assign('date', '<img alt="date" border="0" src="assets/images/date.png" /> <strong>' |
||
475 | . _ADSLIGHT_DATE2 |
||
476 | . ':</strong> ' |
||
477 | . $date |
||
478 | . '<br><img alt="date_error" border="0" src="assets/images/date_error.png" /> <strong>' |
||
479 | . _ADSLIGHT_DISPO |
||
480 | . ':</strong> ' |
||
481 | . $date2); |
||
482 | } else { |
||
483 | $xoopsTpl->assign('no_ad', _ADSLIGHT_NOCLAS); |
||
484 | } |
||
485 | $result8 = $xoopsDB->query('SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . $xoopsDB->escape($cid)); |
||
0 ignored issues
–
show
The variable
$cid does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
486 | |||
487 | list($ctitle) = $xoopsDB->fetchRow($result8); |
||
488 | $xoopsTpl->assign('friend', '<img src="assets/images/friend.gif" border="0" alt="' |
||
489 | . _ADSLIGHT_SENDFRIENDS |
||
490 | . '" /> <a rel="nofollow" href="sendfriend.php?op=SendFriend&lid=' |
||
491 | . $lid |
||
492 | . '">' |
||
493 | . _ADSLIGHT_SENDFRIENDS |
||
494 | . '</a>'); |
||
495 | |||
496 | $xoopsTpl->assign('alerteabus', '<img src="assets/images/error.png" border="0" alt="' |
||
497 | . _ADSLIGHT_ALERTEABUS |
||
498 | . '" /> <a rel="nofollow" href="report-abuse.php?op=ReportAbuse&lid=' |
||
499 | . $lid |
||
500 | . '">' |
||
501 | . _ADSLIGHT_ALERTEABUS |
||
502 | . '</a>'); |
||
503 | |||
504 | $xoopsTpl->assign('link_main', '<a href="../adslight/">' . _ADSLIGHT_MAIN . '</a>'); |
||
505 | $xoopsTpl->assign('link_cat', '<a href="viewcats.php?cid=' . addslashes($cid) . '">' . _ADSLIGHT_GORUB . ' ' . $ctitle . '</a>'); |
||
506 | |||
507 | $xoopsTpl->assign('printA', '<img src="assets/images/print.gif" border="0" alt="' |
||
508 | . _ADSLIGHT_PRINT |
||
509 | . '" /> <a rel="nofollow" href="print.php?op=PrintAd&lid=' |
||
510 | . $lid |
||
511 | . '">' |
||
512 | . _ADSLIGHT_PRINT |
||
513 | . '</a>'); |
||
514 | } |
||
515 | |||
516 | # function categorynewgraphic |
||
517 | ##################################################### |
||
518 | /** |
||
519 | * @param $cid |
||
520 | * |
||
521 | * @return string |
||
522 | */ |
||
523 | function categorynewgraphic($cid) |
||
1 ignored issue
–
show
categorynewgraphic uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
524 | { |
||
525 | global $xoopsDB; |
||
1 ignored issue
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
526 | |||
527 | $cat_perms = ''; |
||
528 | $categories = AdslightUtilities::getMyItemIds('adslight_view'); |
||
529 | if (is_array($categories) && count($categories) > 0) { |
||
530 | $cat_perms .= ' AND cid IN (' . implode(',', $categories) . ') '; |
||
531 | } |
||
532 | |||
533 | $newresult = $xoopsDB->query('SELECT date FROM ' |
||
534 | . $xoopsDB->prefix('adslight_listing') |
||
535 | . ' WHERE cid=' |
||
536 | . $xoopsDB->escape($cid) |
||
537 | . ' AND valid = "Yes" ' |
||
538 | . $cat_perms |
||
539 | . ' ORDER BY date desc limit 1'); |
||
540 | list($date) = $xoopsDB->fetchRow($newresult); |
||
541 | |||
542 | $newcount = $GLOBALS['xoopsModuleConfig']['adslight_countday']; |
||
543 | $startdate = (time() - (86400 * $newcount)); |
||
544 | if ($startdate < $date) { |
||
545 | return '<img src="' . XOOPS_URL . '/modules/adslight/assets/images/newred.gif" alt="new" />'; |
||
546 | } |
||
547 | } |
||
548 | |||
549 | ###################################################### |
||
550 | |||
551 | $pa = XoopsRequest::getInt('pa', null, 'GET'); |
||
552 | $lid = XoopsRequest::getInt('lid', null, 'GET'); |
||
553 | $cid = XoopsRequest::getInt('cid', null, 'GET'); |
||
554 | $usid = XoopsRequest::getString('usid', '', 'GET'); |
||
555 | $min = XoopsRequest::getInt('min', null, 'GET'); |
||
556 | $show = XoopsRequest::getInt('show', null, 'GET'); |
||
557 | $orderby = XoopsRequest::getInt('orderby', null, 'GET'); |
||
558 | |||
559 | switch ($pa) { |
||
560 | |||
561 | default: |
||
562 | $GLOBALS['xoopsOption']['template_main'] = 'adslight_item.tpl'; |
||
563 | |||
564 | viewAds($lid); |
||
565 | break; |
||
566 | } |
||
567 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
568 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: