XoopsModules25x /
xoopspartners
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 | You may not change or alter any portion of this comment or credits |
||
| 4 | of supporting developers from this source code or any supporting source code |
||
| 5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 6 | |||
| 7 | This program is distributed in the hope that it will be useful, |
||
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * XOOPS XoopsPartners module |
||
| 14 | * |
||
| 15 | * @category Module |
||
| 16 | * @package xoopspartners |
||
| 17 | * @subpackage include |
||
| 18 | * @author Taiwen Jiang <[email protected]> |
||
| 19 | * @author zyspec <[email protected]> |
||
| 20 | * @author XOOPS Module Development Team |
||
| 21 | * @copyright {@link http://xoops.org 2001-2016 XOOPS Project} |
||
| 22 | * @license {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License} |
||
| 23 | * @link http://xoops.org XOOPS |
||
| 24 | */ |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @internal {Make sure you PROTECT THIS FILE} |
||
| 28 | */ |
||
| 29 | |||
| 30 | if ((!defined('XOOPS_ROOT_PATH')) |
||
| 31 | || !($GLOBALS['xoopsUser'] instanceof XoopsUser) |
||
|
0 ignored issues
–
show
The class
XoopsUser does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. Loading history...
|
|||
| 32 | || !$GLOBALS['xoopsUser']->isAdmin() |
||
| 33 | ) { |
||
| 34 | exit('Restricted access' . PHP_EOL); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * |
||
| 39 | * Verifies XOOPS version meets minimum requirements for this module |
||
| 40 | * @param XoopsModule $module {@link XoopsModule} |
||
| 41 | * |
||
| 42 | * @return bool true if meets requirements, false if not |
||
| 43 | */ |
||
| 44 | function xoopspartnersCheckXoopsVer(XoopsModule $module) |
||
| 45 | { |
||
| 46 | xoops_loadLanguage('admin', $module->dirname()); |
||
| 47 | //check for minimum XOOPS version |
||
| 48 | $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
||
| 49 | $currArray = explode('.', $currentVer); |
||
| 50 | $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
||
| 51 | $reqArray = explode('.', $requiredVer); |
||
| 52 | $success = true; |
||
| 53 | foreach ($reqArray as $k => $v) { |
||
| 54 | if (isset($currArray[$k])) { |
||
| 55 | if ($currArray[$k] > $v) { |
||
| 56 | break; |
||
| 57 | } elseif ($currArray[$k] == $v) { |
||
| 58 | continue; |
||
| 59 | } else { |
||
| 60 | $success = false; |
||
| 61 | break; |
||
| 62 | } |
||
| 63 | } else { |
||
| 64 | if ((int)$v > 0) { // handles things like x.x.x.0_RC2 |
||
| 65 | $success = false; |
||
| 66 | break; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | if (!$success) { |
||
| 72 | $module->setErrors(sprintf(_AM_XPARTNERS_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
||
| 73 | } |
||
| 74 | |||
| 75 | return $success; |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * |
||
| 80 | * Verifies PHP version meets minimum requirements for this module |
||
| 81 | * @param XoopsModule $module {@link XoopsModule} |
||
| 82 | * |
||
| 83 | * @return bool true if meets requirements, false if not |
||
| 84 | */ |
||
| 85 | function xoopspartnersCheckPHPVer(XoopsModule $module) |
||
| 86 | { |
||
| 87 | xoops_loadLanguage('admin', $module->dirname()); |
||
| 88 | // check for minimum PHP version |
||
| 89 | $success = true; |
||
| 90 | $verNum = phpversion(); |
||
| 91 | $reqVer =& $module->getInfo('min_php'); |
||
| 92 | if (false !== $reqVer && '' !== $reqVer) { |
||
| 93 | if (version_compare($verNum, $reqVer, '<')) { |
||
| 94 | $module->setErrors(sprintf(_AM_XPARTNERS_ERROR_BAD_XOOPS, $reqVer, $verNum)); |
||
| 95 | $success = false; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | return $success; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * |
||
| 104 | * Prepares system prior to attempting to install module |
||
| 105 | * @param XoopsModule $module {@link XoopsModule} |
||
| 106 | * |
||
| 107 | * @return bool true if ready to install, false if not |
||
| 108 | */ |
||
| 109 | View Code Duplication | function xoops_module_pre_install_xoopspartners(XoopsModule $module) |
|
|
0 ignored issues
–
show
This function seems to be duplicated in 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. Loading history...
|
|||
| 110 | { |
||
| 111 | //check for minimum XOOPS version |
||
| 112 | if (!xoopspartnersCheckXoopsVer($module)) { |
||
| 113 | return false; |
||
| 114 | } |
||
| 115 | |||
| 116 | // check for minimum PHP version |
||
| 117 | if (!xoopspartnersCheckPHPVer($module)) { |
||
| 118 | return false; |
||
| 119 | } |
||
| 120 | return true; |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * |
||
| 125 | * Performs tasks required during installation of the module |
||
| 126 | * @param XoopsModule $module {@link XoopsModule} |
||
| 127 | * |
||
| 128 | * @return bool true if installation successful, false if not |
||
| 129 | */ |
||
| 130 | function xoops_module_install_xoopspartners(XoopsModule $module) |
||
|
0 ignored issues
–
show
xoops_module_install_xoopspartners 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);
}
}
Loading history...
|
|||
| 131 | { |
||
| 132 | |||
| 133 | $indexFile = $GLOBALS['xoops']->path('/modules/' . $module->dirname() . '/include/index.html'); |
||
| 134 | |||
| 135 | //Create the "uploads" directory for the module |
||
| 136 | $module_uploads = $GLOBALS['xoops']->path('/uploads/' . $module->dirname()); |
||
| 137 | if (!is_dir($module_uploads)) { |
||
| 138 | mkdir($module_uploads, 0777); |
||
| 139 | } |
||
| 140 | chmod($module_uploads, 0777); |
||
| 141 | //now copy the index file to help prevent 'browsing' the directory |
||
| 142 | copy($indexFile, $GLOBALS['xoops']->path('/uploads/' . $module->dirname() . '/index.html')); |
||
| 143 | |||
| 144 | return true; |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * |
||
| 149 | * Prepares system prior to attempting to update module |
||
| 150 | * @param XoopsModule $module {@link XoopsModule} |
||
| 151 | * |
||
| 152 | * @return bool true if successfully ready to update module, false if not |
||
| 153 | */ |
||
| 154 | View Code Duplication | function xoops_module_pre_update_xoopspartners(XoopsModule $module) |
|
|
0 ignored issues
–
show
This function seems to be duplicated in 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. Loading history...
|
|||
| 155 | { |
||
| 156 | //check for minimum XOOPS version |
||
| 157 | if (!xoopspartnersCheckXoopsVer($module)) { |
||
| 158 | return false; |
||
| 159 | } |
||
| 160 | |||
| 161 | // check for minimum PHP version |
||
| 162 | if (!xoopspartnersCheckPHPVer($module)) { |
||
| 163 | return false; |
||
| 164 | } |
||
| 165 | return true; |
||
| 166 | } |
||
| 167 | |||
| 168 | /** |
||
| 169 | * |
||
| 170 | * Functions to upgrade from previous version of the module |
||
| 171 | * |
||
| 172 | * @param XoopsModule $module {@link XoopsModule} |
||
| 173 | * @param int $curr_version version number of module currently installed |
||
|
0 ignored issues
–
show
Should the type for parameter
$curr_version not be integer|null?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. Loading history...
|
|||
| 174 | * |
||
| 175 | * @return bool true if successfully updated module, false if not |
||
| 176 | */ |
||
| 177 | function xoops_module_update_xoopspartners(XoopsModule $module, $curr_version = null) |
||
|
0 ignored issues
–
show
|
|||
| 178 | { |
||
| 179 | return true; |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * |
||
| 184 | * Function to perform before module uninstall |
||
| 185 | * @param XoopsModule $module {@link XoopsModule} |
||
| 186 | * |
||
| 187 | * @return bool true if successfully executed, false if not |
||
| 188 | */ |
||
| 189 | function xoops_module_pre_uninstall_xoopspartners(XoopsModule $module) |
||
|
0 ignored issues
–
show
|
|||
| 190 | { |
||
| 191 | return true; |
||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * |
||
| 196 | * Function to complete upon module uninstall |
||
| 197 | * @param XoopsModule $module {@link XoopsModule} |
||
| 198 | * |
||
| 199 | * @return bool true if successfully executed uninstall of module, false if not |
||
| 200 | */ |
||
| 201 | function xoops_module_uninstall_xoopspartners(XoopsModule $module) |
||
|
0 ignored issues
–
show
|
|||
| 202 | { |
||
| 203 | return true; |
||
| 204 | } |
||
| 205 |
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.