These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
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 | |||
26 | $myts = MyTextSanitizer::getInstance(); |
||
27 | $module_id = $xoopsModule->getVar('mid'); |
||
28 | |||
29 | if (is_object($xoopsUser)) { |
||
30 | $groups = $xoopsUser->getGroups(); |
||
31 | } else { |
||
32 | $groups = XOOPS_GROUP_ANONYMOUS; |
||
33 | } |
||
34 | $gperm_handler = xoops_getHandler('groupperm'); |
||
35 | if (isset($_POST['item_id'])) { |
||
36 | $perm_itemid = (int)$_POST['item_id']; |
||
37 | } else { |
||
38 | $perm_itemid = 0; |
||
39 | } |
||
40 | //If no access |
||
41 | View Code Duplication | if (!$gperm_handler->checkRight('adslight_view', $perm_itemid, $groups, $module_id)) { |
|
1 ignored issue
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
42 | redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM); |
||
43 | } |
||
44 | if (!$gperm_handler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id)) { |
||
45 | $prem_perm = '0'; |
||
46 | } else { |
||
47 | $prem_perm = '1'; |
||
48 | } |
||
49 | |||
50 | # function adslightMaps |
||
51 | ##################################################### |
||
52 | function adslightMaps() |
||
1 ignored issue
–
show
adslightMaps 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);
}
}
![]() |
|||
53 | { |
||
54 | global $xoopsDB, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsUser, $xoopsTpl, $myts, $mytree, $meta, $mid, $moduleDirName, $main_lang, $prem_perm; |
||
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
}
}
![]() |
|||
55 | |||
56 | $GLOBALS['xoopsOption']['template_main'] = 'adslight_maps.tpl'; |
||
57 | |||
58 | include XOOPS_ROOT_PATH . '/header.php'; |
||
59 | |||
60 | $xoopsTpl->assign('xmid', $xoopsModule->getVar('mid')); |
||
61 | $xoopsTpl->assign('add_from', _ADSLIGHT_ADDFROM . ' ' . $xoopsConfig['sitename']); |
||
62 | $xoopsTpl->assign('add_from_title', _ADSLIGHT_ADDFROM); |
||
63 | $xoopsTpl->assign('add_from_sitename', $xoopsConfig['sitename']); |
||
64 | $xoopsTpl->assign('search_listings', _ADSLIGHT_SEARCH_LISTINGS); |
||
65 | $xoopsTpl->assign('all_words', _ADSLIGHT_ALL_WORDS); |
||
66 | $xoopsTpl->assign('any_words', _ADSLIGHT_ANY_WORDS); |
||
67 | $xoopsTpl->assign('exact_match', _ADSLIGHT_EXACT_MATCH); |
||
68 | $xoopsTpl->assign('only_pix', _ADSLIGHT_ONLYPIX); |
||
69 | $xoopsTpl->assign('search', _ADSLIGHT_SEARCH); |
||
70 | $xoopsTpl->assign('permit', $prem_perm); |
||
71 | $xoopsTpl->assign('imgscss', XOOPS_URL . '/modules/adslight/assets/css/adslight.css'); |
||
72 | $xoopsTpl->assign('adslight_logolink', _ADSLIGHT_LOGOLINK); |
||
73 | |||
74 | $xoTheme->addMeta('meta', 'robots', 'noindex, nofollow'); |
||
0 ignored issues
–
show
|
|||
75 | |||
76 | $header_cssadslight = '<link rel="stylesheet" href="' . XOOPS_URL . '/modules/adslight/assets/css/adslight.css" type="text/css" media="all" />'; |
||
77 | |||
78 | $xoopsTpl->assign('xoops_module_header', $header_cssadslight); |
||
79 | |||
80 | $maps_name = $xoopsModuleConfig['adslight_maps_set']; |
||
81 | $maps_width = $xoopsModuleConfig['adslight_maps_width']; |
||
82 | $maps_height = $xoopsModuleConfig['adslight_maps_height']; |
||
83 | |||
84 | $xoopsTpl->assign('maps_name', $maps_name); |
||
85 | $xoopsTpl->assign('maps_width', $maps_width); |
||
86 | $xoopsTpl->assign('maps_height', $maps_height); |
||
87 | |||
88 | $xoopsTpl->assign('adlight_maps_title', _ADSLIGHT_MAPS_TITLE); |
||
89 | $xoopsTpl->assign('bullinfotext', _ADSLIGHT_MAPS_TEXT); |
||
90 | |||
91 | // adslight 2 |
||
92 | $xoopsTpl->assign('adslight_active_menu', $xoopsModuleConfig['adslight_active_menu']); |
||
93 | $xoopsTpl->assign('adslight_active_rss', $xoopsModuleConfig['adslight_active_rss']); |
||
94 | |||
95 | View Code Duplication | if ($xoopsUser) { |
|
1 ignored issue
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
96 | $member_usid = $xoopsUser->getVar('uid'); |
||
97 | if ($usid = $member_usid) { |
||
0 ignored issues
–
show
$usid is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
98 | $xoopsTpl->assign('istheirs', true); |
||
99 | |||
100 | list($show_user) = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE usid=$member_usid")); |
||
101 | |||
102 | $xoopsTpl->assign('show_user', $show_user); |
||
103 | $xoopsTpl->assign('show_user_link', "members.php?usid=$member_usid"); |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | |||
108 | ###################################################### |
||
109 | |||
110 | $pa = !isset($_GET['pa']) ? null : $_GET['pa']; |
||
111 | |||
112 | switch ($pa) { |
||
113 | default: |
||
114 | $GLOBALS['xoopsOption']['template_main'] = 'adslight_maps.tpl'; |
||
115 | adslightMaps(); |
||
116 | break; |
||
117 | } |
||
118 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
119 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.