XoopsModules25x /
oledrion
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 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 | * oledrion |
||
| 14 | * |
||
| 15 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 16 | * @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
||
| 17 | * @author Hervé Thouzard (http://www.herve-thouzard.com/) |
||
| 18 | */ |
||
| 19 | |||
| 20 | /** |
||
| 21 | * A set of useful and common functions |
||
| 22 | * |
||
| 23 | * @package oledrion |
||
| 24 | * @author Hervé Thouzard - Instant Zero (http://xoops.instant-zero.com) |
||
| 25 | * @copyright (c) Instant Zero |
||
| 26 | * |
||
| 27 | * Note: You should be able to use it without the need to instanciate it. |
||
| 28 | * |
||
| 29 | */ |
||
| 30 | |||
| 31 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
||
| 32 | |||
| 33 | use WideImage\WideImage; |
||
| 34 | |||
| 35 | class OledrionUtility extends XoopsObject |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||
| 36 | { |
||
| 37 | const MODULE_NAME = 'oledrion'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
||
| 41 | * |
||
| 42 | * @param string $folder The full path of the directory to check |
||
| 43 | * |
||
| 44 | * @return void |
||
| 45 | */ |
||
| 46 | public static function createFolder($folder) |
||
| 47 | { |
||
| 48 | // try { |
||
| 49 | // if (!mkdir($folder) && !is_dir($folder)) { |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
65% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 50 | // throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 51 | // } else { |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 52 | // file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 53 | // } |
||
| 54 | // } |
||
| 55 | // catch (Exception $e) { |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 56 | // echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 57 | // } |
||
| 58 | try { |
||
| 59 | if (!file_exists($folder)) { |
||
| 60 | if (!mkdir($folder) && !is_dir($folder)) { |
||
| 61 | throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
||
| 62 | } else { |
||
| 63 | file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | catch (Exception $e) { |
||
| 68 | echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param $file |
||
| 74 | * @param $folder |
||
| 75 | * @return bool |
||
| 76 | */ |
||
| 77 | public static function copyFile($file, $folder) |
||
| 78 | { |
||
| 79 | return copy($file, $folder); |
||
| 80 | // try { |
||
| 81 | // if (!is_dir($folder)) { |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 82 | // throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder)); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 83 | // } else { |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 84 | // return copy($file, $folder); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
64% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 85 | // } |
||
| 86 | // } catch (Exception $e) { |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 87 | // echo 'Caught exception: ', $e->getMessage(), "\n", "<br>"; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 88 | // } |
||
| 89 | // return false; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @param $src |
||
| 94 | * @param $dst |
||
| 95 | */ |
||
| 96 | public static function recurseCopy($src, $dst) |
||
| 97 | { |
||
| 98 | $dir = opendir($src); |
||
| 99 | // @mkdir($dst); |
||
| 100 | while (false !== ($file = readdir($dir))) { |
||
| 101 | if (($file !== '.') && ($file !== '..')) { |
||
| 102 | if (is_dir($src . '/' . $file)) { |
||
| 103 | self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
||
|
0 ignored issues
–
show
The method
recurseCopy() does not seem to exist on object<OledrionUtility>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 104 | } else { |
||
| 105 | copy($src . '/' . $file, $dst . '/' . $file); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | } |
||
| 109 | closedir($dir); |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * |
||
| 114 | * Verifies XOOPS version meets minimum requirements for this module |
||
| 115 | * @static |
||
| 116 | * @param XoopsModule $module |
||
| 117 | * |
||
| 118 | * @param null|string $requiredVer |
||
| 119 | * @return bool true if meets requirements, false if not |
||
| 120 | */ |
||
| 121 | public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null) |
||
| 122 | { |
||
| 123 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 124 | if (null === $module) { |
||
| 125 | $module = XoopsModule::getByDirname($moduleDirName); |
||
| 126 | } |
||
| 127 | xoops_loadLanguage('admin', $moduleDirName); |
||
| 128 | //check for minimum XOOPS version |
||
| 129 | $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
||
| 130 | $currArray = explode('.', $currentVer); |
||
| 131 | if (null === $requiredVer) { |
||
| 132 | $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
||
| 133 | } |
||
| 134 | $reqArray = explode('.', $requiredVer); |
||
| 135 | $success = true; |
||
| 136 | foreach ($reqArray as $k => $v) { |
||
| 137 | if (isset($currArray[$k])) { |
||
| 138 | if ($currArray[$k] > $v) { |
||
| 139 | break; |
||
| 140 | } elseif ($currArray[$k] == $v) { |
||
| 141 | continue; |
||
| 142 | } else { |
||
| 143 | $success = false; |
||
| 144 | break; |
||
| 145 | } |
||
| 146 | } else { |
||
| 147 | if ((int)$v > 0) { // handles things like x.x.x.0_RC2 |
||
| 148 | $success = false; |
||
| 149 | break; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | if (!$success) { |
||
| 155 | $module->setErrors(sprintf(_AM_OLEDRION_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
||
| 156 | } |
||
| 157 | |||
| 158 | return $success; |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * |
||
| 163 | * Verifies PHP version meets minimum requirements for this module |
||
| 164 | * @static |
||
| 165 | * @param XoopsModule $module |
||
| 166 | * |
||
| 167 | * @return bool true if meets requirements, false if not |
||
| 168 | */ |
||
| 169 | public static function checkVerPhp(XoopsModule $module) |
||
| 170 | { |
||
| 171 | xoops_loadLanguage('admin', $module->dirname()); |
||
| 172 | // check for minimum PHP version |
||
| 173 | $success = true; |
||
| 174 | $verNum = PHP_VERSION; |
||
| 175 | $reqVer = $module->getInfo('min_php'); |
||
| 176 | if (false !== $reqVer && '' !== $reqVer) { |
||
| 177 | if (version_compare($verNum, $reqVer, '<')) { |
||
| 178 | $module->setErrors(sprintf(_AM_OLEDRION_ERROR_BAD_PHP, $reqVer, $verNum)); |
||
| 179 | $success = false; |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | return $success; |
||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Access the only instance of this class |
||
| 188 | * |
||
| 189 | * @return object |
||
| 190 | * |
||
| 191 | * @static |
||
| 192 | * @staticvar object |
||
| 193 | */ |
||
| 194 | public static function getInstance() |
||
| 195 | { |
||
| 196 | static $instance; |
||
| 197 | if (null === $instance) { |
||
| 198 | $instance = new static(); |
||
| 199 | } |
||
| 200 | |||
| 201 | return $instance; |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Returns a module's option (with cache) |
||
| 206 | * |
||
| 207 | * @param string $option module option's name |
||
| 208 | * @param boolean $withCache Do we have to use some cache ? |
||
| 209 | * @return mixed option's value |
||
| 210 | */ |
||
| 211 | View Code Duplication | public static function getModuleOption($option, $withCache = true) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 212 | { |
||
| 213 | global $xoopsModuleConfig, $xoopsModule; |
||
|
0 ignored issues
–
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
}
}
Loading history...
|
|||
| 214 | $repmodule = self::MODULE_NAME; |
||
| 215 | static $options = array(); |
||
| 216 | if (is_array($options) && array_key_exists($option, $options) && $withCache) { |
||
| 217 | return $options[$option]; |
||
| 218 | } |
||
| 219 | |||
| 220 | $retval = false; |
||
| 221 | if (isset($xoopsModuleConfig) |
||
| 222 | && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule |
||
| 223 | && $xoopsModule->getVar('isactive'))) { |
||
| 224 | if (isset($xoopsModuleConfig[$option])) { |
||
| 225 | $retval = $xoopsModuleConfig[$option]; |
||
| 226 | } |
||
| 227 | } else { |
||
| 228 | /** @var XoopsModuleHandler $moduleHandler */ |
||
| 229 | $moduleHandler = xoops_getHandler('module'); |
||
| 230 | $module = $moduleHandler->getByDirname($repmodule); |
||
| 231 | $configHandler = xoops_getHandler('config'); |
||
| 232 | if ($module) { |
||
| 233 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 234 | if (isset($moduleConfig[$option])) { |
||
| 235 | $retval = $moduleConfig[$option]; |
||
| 236 | } |
||
| 237 | } |
||
| 238 | } |
||
| 239 | $options[$option] = $retval; |
||
| 240 | |||
| 241 | return $retval; |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Is Xoops 2.3.x ? |
||
| 246 | * |
||
| 247 | * @return boolean |
||
| 248 | */ |
||
| 249 | View Code Duplication | public static function isX23() |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 250 | { |
||
| 251 | $x23 = false; |
||
| 252 | $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
||
| 253 | if ((int)substr($xv, 2, 1) >= 3) { |
||
| 254 | $x23 = true; |
||
| 255 | } |
||
| 256 | |||
| 257 | return $x23; |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Is Xoops 2.0.x ? |
||
| 262 | * |
||
| 263 | * @return boolean |
||
| 264 | */ |
||
| 265 | View Code Duplication | public static function isX20() |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 266 | { |
||
| 267 | $x20 = false; |
||
| 268 | $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
||
| 269 | if (substr($xv, 2, 1) == '0') { |
||
| 270 | $x20 = true; |
||
| 271 | } |
||
| 272 | |||
| 273 | return $x20; |
||
| 274 | } |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Retreive an editor according to the module's option "form_options" |
||
| 278 | * |
||
| 279 | * @param string $caption Caption to give to the editor |
||
| 280 | * @param string $name Editor's name |
||
| 281 | * @param string $value Editor's value |
||
| 282 | * @param string $width Editor's width |
||
| 283 | * @param string $height Editor's height |
||
| 284 | * @param string $supplemental |
||
| 285 | * @return object The editor to use |
||
|
0 ignored issues
–
show
|
|||
| 286 | */ |
||
| 287 | View Code Duplication | public static function getWysiwygForm( |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 288 | $caption, |
||
| 289 | $name, |
||
| 290 | $value = '', |
||
| 291 | $width = '100%', |
||
| 292 | $height = '400px', |
||
| 293 | $supplemental = '') |
||
| 294 | { |
||
| 295 | $editor = false; |
||
| 296 | $editor_configs = array(); |
||
| 297 | $editor_configs['name'] = $name; |
||
| 298 | $editor_configs['value'] = $value; |
||
| 299 | $editor_configs['rows'] = 35; |
||
| 300 | $editor_configs['cols'] = 60; |
||
| 301 | $editor_configs['width'] = '100%'; |
||
| 302 | $editor_configs['height'] = '400px'; |
||
| 303 | |||
| 304 | $editor_option = strtolower(self::getModuleOption('bl_form_options')); |
||
| 305 | |||
| 306 | if (self::isX23()) { |
||
| 307 | $editor = new XoopsFormEditor($caption, $editor_option, $editor_configs); |
||
| 308 | |||
| 309 | return $editor; |
||
| 310 | } |
||
| 311 | |||
| 312 | // Only for Xoops 2.0.x |
||
| 313 | switch ($editor_option) { |
||
| 314 | case 'fckeditor': |
||
| 315 | if (is_readable(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php')) { |
||
| 316 | require_once XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php'; |
||
| 317 | $editor = new XoopsFormFckeditor($caption, $name, $value); |
||
| 318 | } |
||
| 319 | break; |
||
| 320 | |||
| 321 | case 'htmlarea': |
||
| 322 | if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
||
| 323 | require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'; |
||
| 324 | $editor = new XoopsFormHtmlarea($caption, $name, $value); |
||
| 325 | } |
||
| 326 | break; |
||
| 327 | |||
| 328 | case 'dhtmltextarea': |
||
| 329 | $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental); |
||
| 330 | break; |
||
| 331 | |||
| 332 | case 'textarea': |
||
| 333 | $editor = new XoopsFormTextArea($caption, $name, $value); |
||
| 334 | break; |
||
| 335 | |||
| 336 | case 'tinyeditor': |
||
| 337 | case 'tinymce': |
||
| 338 | if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) { |
||
| 339 | require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php'; |
||
| 340 | $editor = new XoopsFormTinyeditorTextArea(array( |
||
| 341 | 'caption' => $caption, |
||
| 342 | 'name' => $name, |
||
| 343 | 'value' => $value, |
||
| 344 | 'width' => '100%', |
||
| 345 | 'height' => '400px' |
||
| 346 | )); |
||
| 347 | } |
||
| 348 | break; |
||
| 349 | |||
| 350 | case 'koivi': |
||
| 351 | if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
||
| 352 | require_once XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'; |
||
| 353 | $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, ''); |
||
| 354 | } |
||
| 355 | break; |
||
| 356 | } |
||
| 357 | |||
| 358 | return $editor; |
||
| 359 | } |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Create (in a link) a javascript confirmation's box |
||
| 363 | * |
||
| 364 | * @param string $message Message to display |
||
| 365 | * @param boolean $form Is this a confirmation for a form ? |
||
| 366 | * @return string the javascript code to insert in the link (or in the form) |
||
| 367 | */ |
||
| 368 | View Code Duplication | public static function javascriptLinkConfirm($message, $form = false) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 369 | { |
||
| 370 | if (!$form) { |
||
| 371 | return "onclick=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
||
| 372 | } else { |
||
| 373 | return "onSubmit=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
||
| 374 | } |
||
| 375 | } |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Get current user IP |
||
| 379 | * |
||
| 380 | * @return string IP address (format Ipv4) |
||
| 381 | */ |
||
| 382 | View Code Duplication | public static function IP() |
|
|
0 ignored issues
–
show
This method 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...
IP uses the super-global variable $_SERVER 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...
|
|||
| 383 | { |
||
| 384 | $proxy_ip = ''; |
||
| 385 | if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
||
| 386 | $proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
||
| 387 | } elseif (!empty($_SERVER['HTTP_X_FORWARDED'])) { |
||
| 388 | $proxy_ip = $_SERVER['HTTP_X_FORWARDED']; |
||
| 389 | } elseif (!empty($_SERVER['HTTP_FORWARDED_FOR'])) { |
||
| 390 | $proxy_ip = $_SERVER['HTTP_FORWARDED_FOR']; |
||
| 391 | } elseif (!empty($_SERVER['HTTP_FORWARDED'])) { |
||
| 392 | $proxy_ip = $_SERVER['HTTP_FORWARDED']; |
||
| 393 | } elseif (!empty($_SERVER['HTTP_VIA'])) { |
||
| 394 | $proxy_ip = $_SERVER['HTTP_VIA']; |
||
| 395 | } elseif (!empty($_SERVER['HTTP_X_COMING_FROM'])) { |
||
| 396 | $proxy_ip = $_SERVER['HTTP_X_COMING_FROM']; |
||
| 397 | } elseif (!empty($_SERVER['HTTP_COMING_FROM'])) { |
||
| 398 | $proxy_ip = $_SERVER['HTTP_COMING_FROM']; |
||
| 399 | } |
||
| 400 | $regs = array(); |
||
| 401 | //if (!empty($proxy_ip) && $is_ip = ereg('^([0-9]{1,3}\.){3,3}[0-9]{1,3}', $proxy_ip, $regs) && count($regs) > 0) { |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
59% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 402 | if (!empty($proxy_ip) && filter_var($proxy_ip, FILTER_VALIDATE_IP) && count($regs) > 0) { |
||
| 403 | $the_IP = $regs[0]; |
||
| 404 | } else { |
||
| 405 | $the_IP = $_SERVER['REMOTE_ADDR']; |
||
| 406 | } |
||
| 407 | |||
| 408 | return $the_IP; |
||
| 409 | } |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Set the page's title, meta description and meta keywords |
||
| 413 | * Datas are supposed to be sanitized |
||
| 414 | * |
||
| 415 | * @param string $pageTitle Page's Title |
||
| 416 | * @param string $metaDescription Page's meta description |
||
| 417 | * @param string $metaKeywords Page's meta keywords |
||
| 418 | * @return void |
||
| 419 | */ |
||
| 420 | View Code Duplication | public static function setMetas($pageTitle = '', $metaDescription = '', $metaKeywords = '') |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 421 | { |
||
| 422 | global $xoTheme, $xoTheme, $xoopsTpl; |
||
|
0 ignored issues
–
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
}
}
Loading history...
|
|||
| 423 | $xoopsTpl->assign('xoops_pagetitle', $pageTitle); |
||
| 424 | if (isset($xoTheme) && is_object($xoTheme)) { |
||
| 425 | if (!empty($metaKeywords)) { |
||
| 426 | $xoTheme->addMeta('meta', 'keywords', $metaKeywords); |
||
| 427 | } |
||
| 428 | if (!empty($metaDescription)) { |
||
| 429 | $xoTheme->addMeta('meta', 'description', $metaDescription); |
||
| 430 | } |
||
| 431 | } elseif (isset($xoopsTpl) && is_object($xoopsTpl)) { // Compatibility for old Xoops versions |
||
| 432 | if (!empty($metaKeywords)) { |
||
| 433 | $xoopsTpl->assign('xoops_meta_keywords', $metaKeywords); |
||
| 434 | } |
||
| 435 | if (!empty($metaDescription)) { |
||
| 436 | $xoopsTpl->assign('xoops_meta_description', $metaDescription); |
||
| 437 | } |
||
| 438 | } |
||
| 439 | } |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Send an email from a template to a list of recipients |
||
| 443 | * |
||
| 444 | * @param $tplName |
||
| 445 | * @param array $recipients List of recipients |
||
| 446 | * @param string $subject Email's subject |
||
| 447 | * @param array $variables Varirables to give to the template |
||
| 448 | * @return bool Result of the send |
||
| 449 | * @internal param string $tpl_name Template's name |
||
| 450 | */ |
||
| 451 | View Code Duplication | public static function sendEmailFromTpl($tplName, $recipients, $subject, $variables) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 452 | { |
||
| 453 | global $xoopsConfig; |
||
|
0 ignored issues
–
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
}
}
Loading history...
|
|||
| 454 | require_once XOOPS_ROOT_PATH . '/class/xoopsmailer.php'; |
||
| 455 | if (!is_array($recipients)) { |
||
| 456 | if (trim($recipients) == '') { |
||
| 457 | return false; |
||
| 458 | } |
||
| 459 | } else { |
||
| 460 | if (count($recipients) == 0) { |
||
| 461 | return false; |
||
| 462 | } |
||
| 463 | } |
||
| 464 | if (function_exists('xoops_getMailer')) { |
||
| 465 | $xoopsMailer = xoops_getMailer(); |
||
| 466 | } else { |
||
| 467 | $xoopsMailer = xoops_getMailer(); |
||
| 468 | } |
||
| 469 | |||
| 470 | $xoopsMailer->useMail(); |
||
| 471 | $templateDir = XOOPS_ROOT_PATH . '/modules/' . self::MODULE_NAME . '/language/' . $xoopsConfig['language'] . '/mail_template'; |
||
| 472 | if (!is_dir($templateDir)) { |
||
| 473 | $templateDir = XOOPS_ROOT_PATH . '/modules/' . self::MODULE_NAME . '/language/english/mail_template'; |
||
| 474 | } |
||
| 475 | $xoopsMailer->setTemplateDir($templateDir); |
||
| 476 | $xoopsMailer->setTemplate($tplName); |
||
| 477 | $xoopsMailer->setToEmails($recipients); |
||
| 478 | // TODO: Change ! |
||
| 479 | // $xoopsMailer->setFromEmail('[email protected]'); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
75% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 480 | //$xoopsMailer->setFromName('MonSite'); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
86% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 481 | $xoopsMailer->setSubject($subject); |
||
| 482 | foreach ($variables as $key => $value) { |
||
| 483 | $xoopsMailer->assign($key, $value); |
||
| 484 | } |
||
| 485 | $res = $xoopsMailer->send(); |
||
| 486 | unset($xoopsMailer); |
||
| 487 | $filename = XOOPS_UPLOAD_PATH . '/logmail_' . self::MODULE_NAME . '.php'; |
||
| 488 | if (!file_exists($filename)) { |
||
| 489 | $fp = @fopen($filename, 'a'); |
||
| 490 | if ($fp) { |
||
| 491 | fwrite($fp, "<?php exit(); ?>\n"); |
||
| 492 | fclose($fp); |
||
| 493 | } |
||
| 494 | } |
||
| 495 | $fp = @fopen($filename, 'a'); |
||
| 496 | |||
| 497 | if ($fp) { |
||
| 498 | fwrite($fp, str_repeat('-', 120) . "\n"); |
||
| 499 | fwrite($fp, date('d/m/Y H:i:s') . "\n"); |
||
| 500 | fwrite($fp, 'Template name : ' . $tplName . "\n"); |
||
| 501 | fwrite($fp, 'Email subject : ' . $subject . "\n"); |
||
| 502 | if (is_array($recipients)) { |
||
| 503 | fwrite($fp, 'Recipient(s) : ' . implode(',', $recipients) . "\n"); |
||
| 504 | } else { |
||
| 505 | fwrite($fp, 'Recipient(s) : ' . $recipients . "\n"); |
||
| 506 | } |
||
| 507 | fwrite($fp, 'Transmited variables : ' . implode(',', $variables) . "\n"); |
||
| 508 | fclose($fp); |
||
| 509 | } |
||
| 510 | |||
| 511 | return $res; |
||
| 512 | } |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Remove module's cache |
||
| 516 | */ |
||
| 517 | View Code Duplication | public static function updateCache() |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 518 | { |
||
| 519 | global $xoopsModule; |
||
| 520 | $folder = $xoopsModule->getVar('dirname'); |
||
| 521 | $tpllist = array(); |
||
|
0 ignored issues
–
show
$tpllist 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 Loading history...
|
|||
| 522 | require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
||
| 523 | require_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 524 | $tplfileHandler = xoops_getHandler('tplfile'); |
||
| 525 | $tpllist = $tplfileHandler->find(null, null, null, $folder); |
||
| 526 | xoops_template_clear_module_cache($xoopsModule->getVar('mid')); // Clear module's blocks cache |
||
| 527 | |||
| 528 | foreach ($tpllist as $onetemplate) { // Remove cache for each page. |
||
| 529 | if ($onetemplate->getVar('tpl_type') === 'module') { |
||
| 530 | // Note, I've been testing all the other methods (like the one of Smarty) and none of them run, that's why I have used this code |
||
| 531 | $files_del = array(); |
||
|
0 ignored issues
–
show
$files_del 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 Loading history...
|
|||
| 532 | $files_del = glob(XOOPS_CACHE_PATH . '/*' . $onetemplate->getVar('tpl_file') . '*'); |
||
| 533 | if (count($files_del) > 0 && is_array($files_del)) { |
||
| 534 | foreach ($files_del as $one_file) { |
||
| 535 | if (is_file($one_file)) { |
||
| 536 | unlink($one_file); |
||
| 537 | } |
||
| 538 | } |
||
| 539 | } |
||
| 540 | } |
||
| 541 | } |
||
| 542 | } |
||
| 543 | |||
| 544 | /** |
||
| 545 | * Redirect user with a message |
||
| 546 | * |
||
| 547 | * @param string $message message to display |
||
| 548 | * @param string $url The place where to go |
||
| 549 | * @param integer timeout Time to wait before to redirect |
||
| 550 | */ |
||
| 551 | public static function redirect($message = '', $url = 'index.php', $time = 2) |
||
| 552 | { |
||
| 553 | redirect_header($url, $time, $message); |
||
| 554 | } |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Internal function used to get the handler of the current module |
||
| 558 | * |
||
| 559 | * @return object The module |
||
| 560 | */ |
||
| 561 | View Code Duplication | protected static function _getModule() |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 562 | { |
||
| 563 | static $mymodule; |
||
| 564 | if (!isset($mymodule)) { |
||
| 565 | global $xoopsModule; |
||
| 566 | if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == OLEDRION_DIRNAME) { |
||
| 567 | $mymodule = $xoopsModule; |
||
| 568 | } else { |
||
| 569 | $hModule = xoops_getHandler('module'); |
||
| 570 | $mymodule = $hModule->getByDirname(OLEDRION_DIRNAME); |
||
| 571 | } |
||
| 572 | } |
||
| 573 | |||
| 574 | return $mymodule; |
||
| 575 | } |
||
| 576 | |||
| 577 | /** |
||
| 578 | * Returns the module's name (as defined by the user in the module manager) with cache |
||
| 579 | * @return string Module's name |
||
| 580 | */ |
||
| 581 | View Code Duplication | public static function getModuleName() |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 582 | { |
||
| 583 | static $moduleName; |
||
| 584 | if (!isset($moduleName)) { |
||
| 585 | $mymodule = static::_getModule(); |
||
| 586 | $moduleName = $mymodule->getVar('name'); |
||
| 587 | } |
||
| 588 | |||
| 589 | return $moduleName; |
||
| 590 | } |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Create a title for the href tags inside html links |
||
| 594 | * |
||
| 595 | * @param string $title Text to use |
||
| 596 | * @return string Formated text |
||
| 597 | */ |
||
| 598 | public static function makeHrefTitle($title) |
||
| 599 | { |
||
| 600 | $s = "\"'"; |
||
| 601 | $r = ' '; |
||
| 602 | |||
| 603 | return strtr($title, $s, $r); |
||
| 604 | } |
||
| 605 | |||
| 606 | /** |
||
| 607 | * Retourne la liste des utilisateurs appartenants à un groupe |
||
| 608 | * |
||
| 609 | * @param int $groupId Searched group |
||
| 610 | * @return array Array of XoopsUsers |
||
| 611 | */ |
||
| 612 | View Code Duplication | public static function getUsersFromGroup($groupId) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 613 | { |
||
| 614 | $users = array(); |
||
|
0 ignored issues
–
show
$users 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 Loading history...
|
|||
| 615 | $memberHandler = xoops_getHandler('member'); |
||
| 616 | $users = $memberHandler->getUsersByGroup($groupId, true); |
||
| 617 | |||
| 618 | return $users; |
||
| 619 | } |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Retourne la liste des emails des utilisateurs membres d'un groupe |
||
| 623 | * |
||
| 624 | * @param $groupId |
||
| 625 | * @return array Emails list |
||
| 626 | * @internal param int $group_id Group's number |
||
| 627 | */ |
||
| 628 | View Code Duplication | public static function getEmailsFromGroup($groupId) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 629 | { |
||
| 630 | $ret = array(); |
||
| 631 | $users = self::getUsersFromGroup($groupId); |
||
| 632 | foreach ($users as $user) { |
||
| 633 | $ret[] = $user->getVar('email'); |
||
| 634 | } |
||
| 635 | |||
| 636 | return $ret; |
||
| 637 | } |
||
| 638 | |||
| 639 | /** |
||
| 640 | * Vérifie que l'utilisateur courant fait partie du groupe des administrateurs |
||
| 641 | * |
||
| 642 | * @return booleean Admin or not |
||
|
0 ignored issues
–
show
|
|||
| 643 | */ |
||
| 644 | View Code Duplication | public static function isAdmin() |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 645 | { |
||
| 646 | global $xoopsUser, $xoopsModule; |
||
|
0 ignored issues
–
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
}
}
Loading history...
|
|||
| 647 | if (is_object($xoopsUser)) { |
||
| 648 | if (in_array(XOOPS_GROUP_ADMIN, $xoopsUser->getGroups())) { |
||
| 649 | return true; |
||
| 650 | } elseif (isset($xoopsModule) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) { |
||
| 651 | return true; |
||
| 652 | } |
||
| 653 | } |
||
| 654 | |||
| 655 | return false; |
||
| 656 | } |
||
| 657 | |||
| 658 | /** |
||
| 659 | * Returns the current date in the Mysql format |
||
| 660 | * |
||
| 661 | * @return string Date in the Mysql format |
||
| 662 | */ |
||
| 663 | public static function getCurrentSQLDate() |
||
| 664 | { |
||
| 665 | return date('Y-m-d'); // 2007-05-02 |
||
| 666 | } |
||
| 667 | |||
| 668 | /** |
||
| 669 | * @return bool|string |
||
| 670 | */ |
||
| 671 | public static function getCurrentSQLDateTime() |
||
| 672 | { |
||
| 673 | return date('Y-m-d H:i:s'); // 2007-05-02 |
||
| 674 | } |
||
| 675 | |||
| 676 | /** |
||
| 677 | * Convert a Mysql date to the human's format |
||
| 678 | * |
||
| 679 | * @param string $date The date to convert |
||
| 680 | * @param string $format |
||
| 681 | * @return string The date in a human form |
||
| 682 | */ |
||
| 683 | View Code Duplication | public static function SQLDateToHuman($date, $format = 'l') |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 684 | { |
||
| 685 | if ($date != '0000-00-00' && xoops_trim($date) != '') { |
||
| 686 | return formatTimestamp(strtotime($date), $format); |
||
| 687 | } else { |
||
| 688 | return ''; |
||
| 689 | } |
||
| 690 | } |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Convert a timestamp to a Mysql date |
||
| 694 | * |
||
| 695 | * @param integer $timestamp The timestamp to use |
||
| 696 | * @return string The date in the Mysql format |
||
| 697 | */ |
||
| 698 | public static function timestampToMysqlDate($timestamp) |
||
| 699 | { |
||
| 700 | return date('Y-m-d', (int)$timestamp); |
||
| 701 | } |
||
| 702 | |||
| 703 | /** |
||
| 704 | * Conversion d'un dateTime Mysql en date lisible en français |
||
| 705 | * @param $dateTime |
||
| 706 | * @return bool|string |
||
| 707 | */ |
||
| 708 | public static function sqlDateTimeToFrench($dateTime) |
||
| 709 | { |
||
| 710 | return date('d/m/Y H:i:s', strtotime($dateTime)); |
||
| 711 | } |
||
| 712 | |||
| 713 | /** |
||
| 714 | * Convert a timestamp to a Mysql datetime form |
||
| 715 | * @param integer $timestamp The timestamp to use |
||
| 716 | * @return string The date and time in the Mysql format |
||
| 717 | */ |
||
| 718 | public static function timestampToMysqlDateTime($timestamp) |
||
| 719 | { |
||
| 720 | return date('Y-m-d H:i:s', $timestamp); |
||
| 721 | } |
||
| 722 | |||
| 723 | /** |
||
| 724 | * This function indicates if the current Xoops version needs to add asterisks to required fields in forms |
||
| 725 | * |
||
| 726 | * @return boolean Yes = we need to add them, false = no |
||
| 727 | */ |
||
| 728 | View Code Duplication | public static function needsAsterisk() |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 729 | { |
||
| 730 | if (self::isX23()) { |
||
| 731 | return false; |
||
| 732 | } |
||
| 733 | if (strpos(strtolower(XOOPS_VERSION), 'impresscms') !== false) { |
||
| 734 | return false; |
||
| 735 | } |
||
| 736 | if (strpos(strtolower(XOOPS_VERSION), 'legacy') === false) { |
||
| 737 | $xv = xoops_trim(str_replace('XOOPS ', '', XOOPS_VERSION)); |
||
| 738 | if ((int)substr($xv, 4, 2) >= 17) { |
||
| 739 | return false; |
||
| 740 | } |
||
| 741 | } |
||
| 742 | |||
| 743 | return true; |
||
| 744 | } |
||
| 745 | |||
| 746 | /** |
||
| 747 | * Mark the mandatory fields of a form with a star |
||
| 748 | * |
||
| 749 | * @param object $sform The form to modify |
||
| 750 | * @return object The modified form |
||
| 751 | * @internal param string $caracter The character to use to mark fields |
||
| 752 | */ |
||
| 753 | View Code Duplication | public static function &formMarkRequiredFields(&$sform) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 754 | { |
||
| 755 | if (self::needsAsterisk()) { |
||
| 756 | $required = array(); |
||
| 757 | foreach ($sform->getRequired() as $item) { |
||
| 758 | $required[] = $item->_name; |
||
| 759 | } |
||
| 760 | $elements = array(); |
||
|
0 ignored issues
–
show
$elements 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 Loading history...
|
|||
| 761 | $elements = $sform->getElements(); |
||
| 762 | $cnt = count($elements); |
||
| 763 | for ($i = 0; $i < $cnt; ++$i) { |
||
| 764 | if (is_object($elements[$i]) && in_array($elements[$i]->_name, $required)) { |
||
| 765 | $elements[$i]->_caption .= ' *'; |
||
| 766 | } |
||
| 767 | } |
||
| 768 | } |
||
| 769 | |||
| 770 | return $sform; |
||
| 771 | } |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Create an html heading (from h1 to h6) |
||
| 775 | * |
||
| 776 | * @param string $title The text to use |
||
| 777 | * @param integer $level Level to return |
||
| 778 | * @return string The heading |
||
|
0 ignored issues
–
show
|
|||
| 779 | */ |
||
| 780 | public static function htitle($title = '', $level = 1) |
||
| 781 | { |
||
| 782 | printf('<h%01d>%s</h%01d>', $level, $title, $level); |
||
| 783 | } |
||
| 784 | |||
| 785 | /** |
||
| 786 | * Create a unique upload filename |
||
| 787 | * |
||
| 788 | * @param string $folder The folder where the file will be saved |
||
| 789 | * @param string $fileName Original filename (coming from the user) |
||
| 790 | * @param boolean $trimName Do we need to create a "short" unique name ? |
||
| 791 | * @return string The unique filename to use (with its extension) |
||
| 792 | */ |
||
| 793 | View Code Duplication | public static function createUploadName($folder, $fileName, $trimName = false) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 794 | { |
||
| 795 | $workingfolder = $folder; |
||
| 796 | if (xoops_substr($workingfolder, strlen($workingfolder) - 1, 1) != '/') { |
||
| 797 | $workingfolder .= '/'; |
||
| 798 | } |
||
| 799 | $ext = basename($fileName); |
||
| 800 | $ext = explode('.', $ext); |
||
| 801 | $ext = '.' . $ext[count($ext) - 1]; |
||
| 802 | $true = true; |
||
| 803 | while ($true) { |
||
| 804 | $ipbits = explode('.', $_SERVER['REMOTE_ADDR']); |
||
| 805 | list($usec, $sec) = explode(' ', microtime()); |
||
| 806 | $usec = (integer)($usec * 65536); |
||
| 807 | $sec = ((integer)$sec) & 0xFFFF; |
||
| 808 | |||
| 809 | if ($trimName) { |
||
| 810 | $uid = sprintf('%06x%04x%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
||
| 811 | } else { |
||
| 812 | $uid = sprintf('%08x-%04x-%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
||
| 813 | } |
||
| 814 | if (!file_exists($workingfolder . $uid . $ext)) { |
||
| 815 | $true = false; |
||
| 816 | } |
||
| 817 | } |
||
| 818 | |||
| 819 | return $uid . $ext; |
||
|
0 ignored issues
–
show
The variable
$uid 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
Loading history...
|
|||
| 820 | } |
||
| 821 | |||
| 822 | /** |
||
| 823 | * Replace html entities with their ASCII equivalent |
||
| 824 | * |
||
| 825 | * @param string $chaine The string undecode |
||
| 826 | * @return string The undecoded string |
||
| 827 | */ |
||
| 828 | View Code Duplication | public static function unhtml($chaine) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 829 | { |
||
| 830 | $search = $replace = array(); |
||
| 831 | $chaine = html_entity_decode($chaine); |
||
| 832 | |||
| 833 | for ($i = 0; $i <= 255; ++$i) { |
||
| 834 | $search[] = '&#' . $i . ';'; |
||
| 835 | $replace[] = chr($i); |
||
| 836 | } |
||
| 837 | $replace[] = '...'; |
||
| 838 | $search[] = ' '; |
||
| 839 | $replace[] = "'"; |
||
| 840 | $search[] = ''; |
||
| 841 | $replace[] = "'"; |
||
| 842 | $search[] = ''; |
||
| 843 | $replace[] = '-'; |
||
| 844 | $search[] = '•'; // $replace[] = ''; |
||
| 845 | $replace[] = ''; |
||
| 846 | $search[] = '—'; |
||
| 847 | $replace[] = '-'; |
||
| 848 | $search[] = '–'; |
||
| 849 | $replace[] = '-'; |
||
| 850 | $search[] = '­'; |
||
| 851 | $replace[] = '"'; |
||
| 852 | $search[] = '"'; |
||
| 853 | $replace[] = '&'; |
||
| 854 | $search[] = '&'; |
||
| 855 | $replace[] = ''; |
||
| 856 | $search[] = 'ˆ'; |
||
| 857 | $replace[] = '¡'; |
||
| 858 | $search[] = '¡'; |
||
| 859 | $replace[] = '¦'; |
||
| 860 | $search[] = '¦'; |
||
| 861 | $replace[] = '¨'; |
||
| 862 | $search[] = '¨'; |
||
| 863 | $replace[] = '¯'; |
||
| 864 | $search[] = '¯'; |
||
| 865 | $replace[] = '´'; |
||
| 866 | $search[] = '´'; |
||
| 867 | $replace[] = '¸'; |
||
| 868 | $search[] = '¸'; |
||
| 869 | $replace[] = '¿'; |
||
| 870 | $search[] = '¿'; |
||
| 871 | $replace[] = ''; |
||
| 872 | $search[] = '˜'; |
||
| 873 | $replace[] = "'"; |
||
| 874 | $search[] = '‘'; // $replace[]=''; |
||
| 875 | $replace[] = "'"; |
||
| 876 | $search[] = '’'; // $replace[]=''; |
||
| 877 | $replace[] = ''; |
||
| 878 | $search[] = '‚'; |
||
| 879 | $replace[] = "'"; |
||
| 880 | $search[] = '“'; // $replace[]=''; |
||
| 881 | $replace[] = "'"; |
||
| 882 | $search[] = '”'; // $replace[]=''; |
||
| 883 | $replace[] = ''; |
||
| 884 | $search[] = '„'; |
||
| 885 | $replace[] = ''; |
||
| 886 | $search[] = '‹'; |
||
| 887 | $replace[] = ''; |
||
| 888 | $search[] = '›'; |
||
| 889 | $replace[] = '<'; |
||
| 890 | $search[] = '<'; |
||
| 891 | $replace[] = '>'; |
||
| 892 | $search[] = '>'; |
||
| 893 | $replace[] = '±'; |
||
| 894 | $search[] = '±'; |
||
| 895 | $replace[] = '«'; |
||
| 896 | $search[] = '«'; |
||
| 897 | $replace[] = '»'; |
||
| 898 | $search[] = '»'; |
||
| 899 | $replace[] = '×'; |
||
| 900 | $search[] = '×'; |
||
| 901 | $replace[] = '÷'; |
||
| 902 | $search[] = '÷'; |
||
| 903 | $replace[] = '¢'; |
||
| 904 | $search[] = '¢'; |
||
| 905 | $replace[] = '£'; |
||
| 906 | $search[] = '£'; |
||
| 907 | $replace[] = '¤'; |
||
| 908 | $search[] = '¤'; |
||
| 909 | $replace[] = '¥'; |
||
| 910 | $search[] = '¥'; |
||
| 911 | $replace[] = '§'; |
||
| 912 | $search[] = '§'; |
||
| 913 | $replace[] = '©'; |
||
| 914 | $search[] = '©'; |
||
| 915 | $replace[] = '¬'; |
||
| 916 | $search[] = '¬'; |
||
| 917 | $replace[] = '®'; |
||
| 918 | $search[] = '®'; |
||
| 919 | $replace[] = '°'; |
||
| 920 | $search[] = '°'; |
||
| 921 | $replace[] = 'µ'; |
||
| 922 | $search[] = 'µ'; |
||
| 923 | $replace[] = '¶'; |
||
| 924 | $search[] = '¶'; |
||
| 925 | $replace[] = '·'; |
||
| 926 | $search[] = '·'; |
||
| 927 | $replace[] = ''; |
||
| 928 | $search[] = '†'; |
||
| 929 | $replace[] = ''; |
||
| 930 | $search[] = '‡'; |
||
| 931 | $replace[] = ''; |
||
| 932 | $search[] = '‰'; |
||
| 933 | $replace[] = 'Euro'; |
||
| 934 | $search[] = '€'; // $replace[]='' |
||
| 935 | $replace[] = '¼'; |
||
| 936 | $search[] = '¼'; |
||
| 937 | $replace[] = '½'; |
||
| 938 | $search[] = '½'; |
||
| 939 | $replace[] = '¾'; |
||
| 940 | $search[] = '¾'; |
||
| 941 | $replace[] = '¹'; |
||
| 942 | $search[] = '¹'; |
||
| 943 | $replace[] = '²'; |
||
| 944 | $search[] = '²'; |
||
| 945 | $replace[] = '³'; |
||
| 946 | $search[] = '³'; |
||
| 947 | $replace[] = 'á'; |
||
| 948 | $search[] = 'á'; |
||
| 949 | $replace[] = 'Á'; |
||
| 950 | $search[] = 'Á'; |
||
| 951 | $replace[] = 'â'; |
||
| 952 | $search[] = 'â'; |
||
| 953 | $replace[] = 'Â'; |
||
| 954 | $search[] = 'Â'; |
||
| 955 | $replace[] = 'à'; |
||
| 956 | $search[] = 'à'; |
||
| 957 | $replace[] = 'À'; |
||
| 958 | $search[] = 'À'; |
||
| 959 | $replace[] = 'å'; |
||
| 960 | $search[] = 'å'; |
||
| 961 | $replace[] = 'Å'; |
||
| 962 | $search[] = 'Å'; |
||
| 963 | $replace[] = 'ã'; |
||
| 964 | $search[] = 'ã'; |
||
| 965 | $replace[] = 'Ã'; |
||
| 966 | $search[] = 'Ã'; |
||
| 967 | $replace[] = 'ä'; |
||
| 968 | $search[] = 'ä'; |
||
| 969 | $replace[] = 'Ä'; |
||
| 970 | $search[] = 'Ä'; |
||
| 971 | $replace[] = 'ª'; |
||
| 972 | $search[] = 'ª'; |
||
| 973 | $replace[] = 'æ'; |
||
| 974 | $search[] = 'æ'; |
||
| 975 | $replace[] = 'Æ'; |
||
| 976 | $search[] = 'Æ'; |
||
| 977 | $replace[] = 'ç'; |
||
| 978 | $search[] = 'ç'; |
||
| 979 | $replace[] = 'Ç'; |
||
| 980 | $search[] = 'Ç'; |
||
| 981 | $replace[] = 'ð'; |
||
| 982 | $search[] = 'ð'; |
||
| 983 | $replace[] = 'Ð'; |
||
| 984 | $search[] = 'Ð'; |
||
| 985 | $replace[] = 'é'; |
||
| 986 | $search[] = 'é'; |
||
| 987 | $replace[] = 'É'; |
||
| 988 | $search[] = 'É'; |
||
| 989 | $replace[] = 'ê'; |
||
| 990 | $search[] = 'ê'; |
||
| 991 | $replace[] = 'Ê'; |
||
| 992 | $search[] = 'Ê'; |
||
| 993 | $replace[] = 'è'; |
||
| 994 | $search[] = 'è'; |
||
| 995 | $replace[] = 'È'; |
||
| 996 | $search[] = 'È'; |
||
| 997 | $replace[] = 'ë'; |
||
| 998 | $search[] = 'ë'; |
||
| 999 | $replace[] = 'Ë'; |
||
| 1000 | $search[] = 'Ë'; |
||
| 1001 | $replace[] = ''; |
||
| 1002 | $search[] = 'ƒ'; |
||
| 1003 | $replace[] = 'í'; |
||
| 1004 | $search[] = 'í'; |
||
| 1005 | $replace[] = 'Í'; |
||
| 1006 | $search[] = 'Í'; |
||
| 1007 | $replace[] = 'î'; |
||
| 1008 | $search[] = 'î'; |
||
| 1009 | $replace[] = 'Î'; |
||
| 1010 | $search[] = 'Î'; |
||
| 1011 | $replace[] = 'ì'; |
||
| 1012 | $search[] = 'ì'; |
||
| 1013 | $replace[] = 'Ì'; |
||
| 1014 | $search[] = 'Ì'; |
||
| 1015 | $replace[] = 'ï'; |
||
| 1016 | $search[] = 'ï'; |
||
| 1017 | $replace[] = 'Ï'; |
||
| 1018 | $search[] = 'Ï'; |
||
| 1019 | $replace[] = 'ñ'; |
||
| 1020 | $search[] = 'ñ'; |
||
| 1021 | $replace[] = 'Ñ'; |
||
| 1022 | $search[] = 'Ñ'; |
||
| 1023 | $replace[] = 'ó'; |
||
| 1024 | $search[] = 'ó'; |
||
| 1025 | $replace[] = 'Ó'; |
||
| 1026 | $search[] = 'Ó'; |
||
| 1027 | $replace[] = 'ô'; |
||
| 1028 | $search[] = 'ô'; |
||
| 1029 | $replace[] = 'Ô'; |
||
| 1030 | $search[] = 'Ô'; |
||
| 1031 | $replace[] = 'ò'; |
||
| 1032 | $search[] = 'ò'; |
||
| 1033 | $replace[] = 'Ò'; |
||
| 1034 | $search[] = 'Ò'; |
||
| 1035 | $replace[] = 'º'; |
||
| 1036 | $search[] = 'º'; |
||
| 1037 | $replace[] = 'ø'; |
||
| 1038 | $search[] = 'ø'; |
||
| 1039 | $replace[] = 'Ø'; |
||
| 1040 | $search[] = 'Ø'; |
||
| 1041 | $replace[] = 'õ'; |
||
| 1042 | $search[] = 'õ'; |
||
| 1043 | $replace[] = 'Õ'; |
||
| 1044 | $search[] = 'Õ'; |
||
| 1045 | $replace[] = 'ö'; |
||
| 1046 | $search[] = 'ö'; |
||
| 1047 | $replace[] = 'Ö'; |
||
| 1048 | $search[] = 'Ö'; |
||
| 1049 | $replace[] = ''; |
||
| 1050 | $search[] = 'œ'; |
||
| 1051 | $replace[] = ''; |
||
| 1052 | $search[] = 'Œ'; |
||
| 1053 | $replace[] = ''; |
||
| 1054 | $search[] = 'š'; |
||
| 1055 | $replace[] = ''; |
||
| 1056 | $search[] = 'Š'; |
||
| 1057 | $replace[] = 'ß'; |
||
| 1058 | $search[] = 'ß'; |
||
| 1059 | $replace[] = 'þ'; |
||
| 1060 | $search[] = 'þ'; |
||
| 1061 | $replace[] = 'Þ'; |
||
| 1062 | $search[] = 'Þ'; |
||
| 1063 | $replace[] = 'ú'; |
||
| 1064 | $search[] = 'ú'; |
||
| 1065 | $replace[] = 'Ú'; |
||
| 1066 | $search[] = 'Ú'; |
||
| 1067 | $replace[] = 'û'; |
||
| 1068 | $search[] = 'û'; |
||
| 1069 | $replace[] = 'Û'; |
||
| 1070 | $search[] = 'Û'; |
||
| 1071 | $replace[] = 'ù'; |
||
| 1072 | $search[] = 'ù'; |
||
| 1073 | $replace[] = 'Ù'; |
||
| 1074 | $search[] = 'Ù'; |
||
| 1075 | $replace[] = 'ü'; |
||
| 1076 | $search[] = 'ü'; |
||
| 1077 | $replace[] = 'Ü'; |
||
| 1078 | $search[] = 'Ü'; |
||
| 1079 | $replace[] = 'ý'; |
||
| 1080 | $search[] = 'ý'; |
||
| 1081 | $replace[] = 'Ý'; |
||
| 1082 | $search[] = 'Ý'; |
||
| 1083 | $replace[] = 'ÿ'; |
||
| 1084 | $search[] = 'ÿ'; |
||
| 1085 | $replace[] = ''; |
||
| 1086 | $search[] = 'Ÿ'; |
||
| 1087 | $chaine = str_replace($search, $replace, $chaine); |
||
| 1088 | |||
| 1089 | return $chaine; |
||
| 1090 | } |
||
| 1091 | |||
| 1092 | /** |
||
| 1093 | * Création d'une titre pour être utilisé par l'url rewriting |
||
| 1094 | * |
||
| 1095 | * @param string $content Le texte à utiliser pour créer l'url |
||
| 1096 | * @param integer $urw La limite basse pour créer les mots |
||
| 1097 | * @return string Le texte à utiliser pour l'url |
||
| 1098 | * Note, some parts are from Solo's code |
||
| 1099 | */ |
||
| 1100 | View Code Duplication | public static function makeSeoUrl($content, $urw = 1) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1101 | { |
||
| 1102 | $s = "ÀÁÂÃÄÅÒÓÔÕÖØÈÉÊËÇÌÍÎÏÙÚÛÜÑàáâãäåòóôõöøèéêëçìíîïùúûüÿñ '()"; |
||
| 1103 | $r = 'AAAAAAOOOOOOEEEECIIIIUUUUYNaaaaaaooooooeeeeciiiiuuuuyn----'; |
||
| 1104 | $content = self::unhtml($content); // First, remove html entities |
||
| 1105 | $content = strtr($content, $s, $r); |
||
| 1106 | $content = strip_tags($content); |
||
| 1107 | $content = strtolower($content); |
||
| 1108 | $content = htmlentities($content); // TODO: Vérifier |
||
| 1109 | $content = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/', '$1', $content); |
||
| 1110 | $content = html_entity_decode($content); |
||
| 1111 | $content = preg_replace('/quot/i', ' ', $content); |
||
| 1112 | $content = preg_replace("/'/i", ' ', $content); |
||
| 1113 | $content = preg_replace('/-/i', ' ', $content); |
||
| 1114 | $content = preg_replace('/[[:punct:]]/i', '', $content); |
||
| 1115 | |||
| 1116 | // Selon option mais attention au fichier .htaccess ! |
||
| 1117 | // $content = eregi_replace('[[:digit:]]','', $content); |
||
| 1118 | $content = preg_replace('/[^a-z|A-Z|0-9]/', '-', $content); |
||
| 1119 | |||
| 1120 | $words = explode(' ', $content); |
||
| 1121 | $keywords = ''; |
||
| 1122 | foreach ($words as $word) { |
||
| 1123 | if (strlen($word) >= $urw) { |
||
| 1124 | $keywords .= '-' . trim($word); |
||
| 1125 | } |
||
| 1126 | } |
||
| 1127 | if (!$keywords) { |
||
| 1128 | $keywords = '-'; |
||
| 1129 | } |
||
| 1130 | // Supprime les tirets en double |
||
| 1131 | $keywords = str_replace('---', '-', $keywords); |
||
| 1132 | $keywords = str_replace('--', '-', $keywords); |
||
| 1133 | // Supprime un éventuel tiret à la fin de la chaine |
||
| 1134 | if (substr($keywords, strlen($keywords) - 1, 1) == '-') { |
||
| 1135 | $keywords = substr($keywords, 0, strlen($keywords) - 1); |
||
| 1136 | } |
||
| 1137 | |||
| 1138 | return $keywords; |
||
| 1139 | } |
||
| 1140 | |||
| 1141 | /** |
||
| 1142 | * Create the meta keywords based on the content |
||
| 1143 | * |
||
| 1144 | * @param string $content Content from which we have to create metakeywords |
||
| 1145 | * @return string The list of meta keywords |
||
| 1146 | */ |
||
| 1147 | View Code Duplication | public static function createMetaKeywords($content) |
|
|
0 ignored issues
–
show
This method 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...
createMetaKeywords uses the super-global variable $_SESSION 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...
|
|||
| 1148 | { |
||
| 1149 | $keywordscount = self::getModuleOption('metagen_maxwords'); |
||
| 1150 | $keywordsorder = self::getModuleOption('metagen_order'); |
||
| 1151 | |||
| 1152 | $tmp = array(); |
||
| 1153 | // Search for the "Minimum keyword length" |
||
| 1154 | if (isset($_SESSION['oledrion_keywords_limit'])) { |
||
| 1155 | $limit = $_SESSION['oledrion_keywords_limit']; |
||
| 1156 | } else { |
||
| 1157 | $configHandler = xoops_getHandler('config'); |
||
| 1158 | $xoopsConfigSearch = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH); |
||
| 1159 | $limit = $xoopsConfigSearch['keyword_min']; |
||
| 1160 | $_SESSION['oledrion_keywords_limit'] = $limit; |
||
| 1161 | } |
||
| 1162 | $myts = MyTextSanitizer::getInstance(); |
||
| 1163 | $content = str_replace('<br>', ' ', $content); |
||
| 1164 | $content = $myts->undoHtmlSpecialChars($content); |
||
| 1165 | $content = strip_tags($content); |
||
| 1166 | $content = strtolower($content); |
||
| 1167 | $search_pattern = array( |
||
| 1168 | ' ', |
||
| 1169 | "\t", |
||
| 1170 | "\r\n", |
||
| 1171 | "\r", |
||
| 1172 | "\n", |
||
| 1173 | ',', |
||
| 1174 | '.', |
||
| 1175 | "'", |
||
| 1176 | ';', |
||
| 1177 | ':', |
||
| 1178 | ')', |
||
| 1179 | '(', |
||
| 1180 | '"', |
||
| 1181 | '?', |
||
| 1182 | '!', |
||
| 1183 | '{', |
||
| 1184 | '}', |
||
| 1185 | '[', |
||
| 1186 | ']', |
||
| 1187 | '<', |
||
| 1188 | '>', |
||
| 1189 | '/', |
||
| 1190 | '+', |
||
| 1191 | '-', |
||
| 1192 | '_', |
||
| 1193 | '\\', |
||
| 1194 | '*' |
||
| 1195 | ); |
||
| 1196 | $replace_pattern = array( |
||
| 1197 | ' ', |
||
| 1198 | ' ', |
||
| 1199 | ' ', |
||
| 1200 | ' ', |
||
| 1201 | ' ', |
||
| 1202 | ' ', |
||
| 1203 | ' ', |
||
| 1204 | ' ', |
||
| 1205 | '', |
||
| 1206 | '', |
||
| 1207 | '', |
||
| 1208 | '', |
||
| 1209 | '', |
||
| 1210 | '', |
||
| 1211 | '', |
||
| 1212 | '', |
||
| 1213 | '', |
||
| 1214 | '', |
||
| 1215 | '', |
||
| 1216 | '', |
||
| 1217 | '', |
||
| 1218 | '', |
||
| 1219 | '', |
||
| 1220 | '', |
||
| 1221 | '', |
||
| 1222 | '', |
||
| 1223 | '' |
||
| 1224 | ); |
||
| 1225 | $content = str_replace($search_pattern, $replace_pattern, $content); |
||
| 1226 | $keywords = explode(' ', $content); |
||
| 1227 | switch ($keywordsorder) { |
||
| 1228 | case 0: // Ordre d'apparition dans le texte |
||
| 1229 | $keywords = array_unique($keywords); |
||
| 1230 | break; |
||
| 1231 | case 1: // Ordre de fréquence des mots |
||
| 1232 | $keywords = array_count_values($keywords); |
||
| 1233 | asort($keywords); |
||
| 1234 | $keywords = array_keys($keywords); |
||
| 1235 | break; |
||
| 1236 | case 2: // Ordre inverse de la fréquence des mots |
||
| 1237 | $keywords = array_count_values($keywords); |
||
| 1238 | arsort($keywords); |
||
| 1239 | $keywords = array_keys($keywords); |
||
| 1240 | break; |
||
| 1241 | } |
||
| 1242 | // Remove black listed words |
||
| 1243 | if (xoops_trim(self::getModuleOption('metagen_blacklist')) != '') { |
||
| 1244 | $metagen_blacklist = str_replace("\r", '', self::getModuleOption('metagen_blacklist')); |
||
| 1245 | $metablack = explode("\n", $metagen_blacklist); |
||
| 1246 | array_walk($metablack, 'trim'); |
||
| 1247 | $keywords = array_diff($keywords, $metablack); |
||
| 1248 | } |
||
| 1249 | |||
| 1250 | foreach ($keywords as $keyword) { |
||
| 1251 | if (strlen($keyword) >= $limit && !is_numeric($keyword)) { |
||
| 1252 | $tmp[] = $keyword; |
||
| 1253 | } |
||
| 1254 | } |
||
| 1255 | $tmp = array_slice($tmp, 0, $keywordscount); |
||
| 1256 | if (count($tmp) > 0) { |
||
| 1257 | return implode(',', $tmp); |
||
| 1258 | } else { |
||
| 1259 | if (!isset($configHandler) || !is_object($configHandler)) { |
||
| 1260 | $configHandler = xoops_getHandler('config'); |
||
| 1261 | } |
||
| 1262 | $xoopsConfigMetaFooter = $configHandler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
||
| 1263 | if (isset($xoopsConfigMetaFooter['meta_keywords'])) { |
||
| 1264 | return $xoopsConfigMetaFooter['meta_keywords']; |
||
| 1265 | } else { |
||
| 1266 | return ''; |
||
| 1267 | } |
||
| 1268 | } |
||
| 1269 | } |
||
| 1270 | |||
| 1271 | /** |
||
| 1272 | * Fonction chargée de gérer l'upload |
||
| 1273 | * |
||
| 1274 | * @param integer $indice L'indice du fichier à télécharger |
||
| 1275 | * @param string $dstpath |
||
| 1276 | * @param null $mimeTypes |
||
| 1277 | * @param null $uploadMaxSize |
||
| 1278 | * @param null $maxWidth |
||
| 1279 | * @param null $maxHeight |
||
| 1280 | * @return mixed True si l'upload s'est bien déroulé sinon le message d'erreur correspondant |
||
| 1281 | */ |
||
| 1282 | View Code Duplication | public static function uploadFile( |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1283 | $indice, |
||
| 1284 | $dstpath = XOOPS_UPLOAD_PATH, |
||
| 1285 | $mimeTypes = null, |
||
| 1286 | $uploadMaxSize = null, |
||
| 1287 | $maxWidth = null, |
||
| 1288 | $maxHeight = null) |
||
| 1289 | { |
||
| 1290 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
| 1291 | global $destname; |
||
| 1292 | if (isset($_POST['xoops_upload_file'])) { |
||
| 1293 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
| 1294 | $fldname = ''; |
||
|
0 ignored issues
–
show
$fldname 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 Loading history...
|
|||
| 1295 | $fldname = $_FILES[$_POST['xoops_upload_file'][$indice]]; |
||
| 1296 | $fldname = get_magic_quotes_gpc() ? stripslashes($fldname['name']) : $fldname['name']; |
||
| 1297 | if (xoops_trim($fldname != '')) { |
||
| 1298 | $destname = self::createUploadName($dstpath, $fldname, true); |
||
| 1299 | if ($mimeTypes === null) { |
||
| 1300 | $permittedtypes = explode("\n", str_replace("\r", '', self::getModuleOption('mimetypes'))); |
||
| 1301 | array_walk($permittedtypes, 'trim'); |
||
| 1302 | } else { |
||
| 1303 | $permittedtypes = $mimeTypes; |
||
| 1304 | } |
||
| 1305 | if ($uploadMaxSize === null) { |
||
| 1306 | $uploadSize = self::getModuleOption('maxuploadsize'); |
||
| 1307 | } else { |
||
| 1308 | $uploadSize = $uploadMaxSize; |
||
| 1309 | } |
||
| 1310 | $uploader = new XoopsMediaUploader($dstpath, $permittedtypes, $uploadSize, $maxWidth, $maxHeight); |
||
| 1311 | //$uploader->allowUnknownTypes = true; |
||
| 1312 | $uploader->setTargetFileName($destname); |
||
| 1313 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][$indice])) { |
||
| 1314 | if ($uploader->upload()) { |
||
| 1315 | return true; |
||
| 1316 | } else { |
||
| 1317 | return _ERRORS . ' ' . htmlentities($uploader->getErrors()); |
||
| 1318 | } |
||
| 1319 | } else { |
||
| 1320 | return htmlentities($uploader->getErrors()); |
||
| 1321 | } |
||
| 1322 | } else { |
||
| 1323 | return false; |
||
| 1324 | } |
||
| 1325 | } else { |
||
| 1326 | return false; |
||
| 1327 | } |
||
| 1328 | } |
||
| 1329 | |||
| 1330 | /** |
||
| 1331 | * Resize a Picture to some given dimensions (using the wideImage library) |
||
| 1332 | * |
||
| 1333 | * @param string $src_path Picture's source |
||
| 1334 | * @param string $dst_path Picture's destination |
||
| 1335 | * @param integer $param_width Maximum picture's width |
||
| 1336 | * @param integer $param_height Maximum picture's height |
||
| 1337 | * @param boolean $keep_original Do we have to keep the original picture ? |
||
| 1338 | * @param string $fit Resize mode (see the wideImage library for more information) |
||
| 1339 | * @return bool |
||
| 1340 | */ |
||
| 1341 | View Code Duplication | public static function resizePicture( |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1342 | $src_path, |
||
| 1343 | $dst_path, |
||
| 1344 | $param_width, |
||
| 1345 | $param_height, |
||
| 1346 | $keep_original = false, |
||
| 1347 | $fit = 'inside') |
||
| 1348 | { |
||
| 1349 | // require_once OLEDRION_PATH . 'class/wideimage/WideImage.inc.php'; |
||
| 1350 | $resize = true; |
||
| 1351 | if (OLEDRION_DONT_RESIZE_IF_SMALLER) { |
||
| 1352 | $pictureDimensions = getimagesize($src_path); |
||
| 1353 | if (is_array($pictureDimensions)) { |
||
| 1354 | $width = $pictureDimensions[0]; |
||
| 1355 | $height = $pictureDimensions[1]; |
||
| 1356 | if ($width < $param_width && $height < $param_height) { |
||
| 1357 | $resize = false; |
||
| 1358 | } |
||
| 1359 | } |
||
| 1360 | } |
||
| 1361 | |||
| 1362 | $img = WideImage::load($src_path); |
||
| 1363 | if ($resize) { |
||
| 1364 | $result = $img->resize($param_width, $param_height, $fit); |
||
| 1365 | $result->saveToFile($dst_path); |
||
| 1366 | } else { |
||
| 1367 | @copy($src_path, $dst_path); |
||
|
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
|
|||
| 1368 | } |
||
| 1369 | |||
| 1370 | if (!$keep_original) { |
||
| 1371 | @unlink($src_path); |
||
|
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
|
|||
| 1372 | } |
||
| 1373 | |||
| 1374 | return true; |
||
| 1375 | } |
||
| 1376 | |||
| 1377 | /** |
||
| 1378 | * Déclenchement d'une alerte Xoops suite à un évènement |
||
| 1379 | * |
||
| 1380 | * @param string $category La catégorie de l'évènement |
||
| 1381 | * @param integer $itemId L'ID de l'élément (trop général pour être décris précisément) |
||
| 1382 | * @param unknown_type $event L'évènement qui est déclencé |
||
| 1383 | * @param unknown_type $tags Les variables à passer au template |
||
| 1384 | */ |
||
| 1385 | public static function notify($category, $itemId, $event, $tags) |
||
| 1386 | { |
||
| 1387 | $notificationHandler = xoops_getHandler('notification'); |
||
| 1388 | $tags['X_MODULE_URL'] = OLEDRION_URL; |
||
| 1389 | $notificationHandler->triggerEvent($category, $itemId, $event, $tags); |
||
| 1390 | } |
||
| 1391 | |||
| 1392 | /** |
||
| 1393 | * Ajoute des jours à une date et retourne la nouvelle date au format Date de Mysql |
||
| 1394 | * |
||
| 1395 | * @param int $duration |
||
| 1396 | * @param integer $startingDate Date de départ (timestamp) |
||
| 1397 | * @return bool|string |
||
| 1398 | * @internal param int $durations Durée en jours |
||
| 1399 | */ |
||
| 1400 | View Code Duplication | public static function addDaysToDate($duration = 1, $startingDate = 0) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1401 | { |
||
| 1402 | if ($startingDate == 0) { |
||
| 1403 | $startingDate = time(); |
||
| 1404 | } |
||
| 1405 | $endingDate = $startingDate + ($duration * 86400); |
||
| 1406 | |||
| 1407 | return date('Y-m-d', $endingDate); |
||
| 1408 | } |
||
| 1409 | |||
| 1410 | /** |
||
| 1411 | * Retourne un breadcrumb en fonction des paramètres passés et en partant (d'office) de la racine du module |
||
| 1412 | * |
||
| 1413 | * @param array $path Le chemin complet (excepté la racine) du breadcrumb sous la forme clé=url valeur=titre |
||
| 1414 | * @param string $raquo Le séparateur par défaut à utiliser |
||
| 1415 | * @return string le breadcrumb |
||
| 1416 | */ |
||
| 1417 | View Code Duplication | public static function breadcrumb($path, $raquo = ' » ') |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1418 | { |
||
| 1419 | $breadcrumb = ''; |
||
| 1420 | $workingBreadcrumb = array(); |
||
| 1421 | if (is_array($path)) { |
||
| 1422 | $moduleName = self::getModuleName(); |
||
| 1423 | $workingBreadcrumb[] = "<a href='" . OLEDRION_URL . "' title='" . self::makeHrefTitle($moduleName) . "'>" . $moduleName . '</a>'; |
||
| 1424 | foreach ($path as $url => $title) { |
||
| 1425 | $workingBreadcrumb[] = "<a href='" . $url . "'>" . $title . '</a>'; |
||
| 1426 | } |
||
| 1427 | $cnt = count($workingBreadcrumb); |
||
| 1428 | for ($i = 0; $i < $cnt; ++$i) { |
||
| 1429 | if ($i == $cnt - 1) { |
||
| 1430 | $workingBreadcrumb[$i] = strip_tags($workingBreadcrumb[$i]); |
||
| 1431 | } |
||
| 1432 | } |
||
| 1433 | $breadcrumb = implode($raquo, $workingBreadcrumb); |
||
| 1434 | } |
||
| 1435 | |||
| 1436 | return $breadcrumb; |
||
| 1437 | } |
||
| 1438 | |||
| 1439 | /** |
||
| 1440 | * @param $string |
||
| 1441 | * @return string |
||
| 1442 | */ |
||
| 1443 | View Code Duplication | public static function close_tags($string) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1444 | { |
||
| 1445 | // match opened tags |
||
| 1446 | if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) { |
||
| 1447 | $start_tags = $start_tags[1]; |
||
| 1448 | |||
| 1449 | // match closed tags |
||
| 1450 | if (preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) { |
||
| 1451 | $complete_tags = array(); |
||
| 1452 | $end_tags = $end_tags[1]; |
||
| 1453 | |||
| 1454 | foreach ($start_tags as $key => $val) { |
||
| 1455 | $posb = array_search($val, $end_tags); |
||
| 1456 | if (is_int($posb)) { |
||
| 1457 | unset($end_tags[$posb]); |
||
| 1458 | } else { |
||
| 1459 | $complete_tags[] = $val; |
||
| 1460 | } |
||
| 1461 | } |
||
| 1462 | } else { |
||
| 1463 | $complete_tags = $start_tags; |
||
| 1464 | } |
||
| 1465 | |||
| 1466 | $complete_tags = array_reverse($complete_tags); |
||
| 1467 | for ($i = 0, $iMax = count($complete_tags); $i < $iMax; ++$i) { |
||
| 1468 | $string .= '</' . $complete_tags[$i] . '>'; |
||
| 1469 | } |
||
| 1470 | } |
||
| 1471 | |||
| 1472 | return $string; |
||
| 1473 | } |
||
| 1474 | |||
| 1475 | /** |
||
| 1476 | * @param $string |
||
| 1477 | * @param int $length |
||
| 1478 | * @param string $etc |
||
| 1479 | * @param bool $break_words |
||
| 1480 | * @return mixed|string |
||
| 1481 | */ |
||
| 1482 | View Code Duplication | public static function truncate_tagsafe($string, $length = 80, $etc = '...', $break_words = false) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1483 | { |
||
| 1484 | if ($length == 0) { |
||
| 1485 | return ''; |
||
| 1486 | } |
||
| 1487 | |||
| 1488 | if (strlen($string) > $length) { |
||
| 1489 | $length -= strlen($etc); |
||
| 1490 | if (!$break_words) { |
||
| 1491 | $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1)); |
||
| 1492 | $string = preg_replace('/<[^>]*$/', '', $string); |
||
| 1493 | $string = self::close_tags($string); |
||
| 1494 | } |
||
| 1495 | |||
| 1496 | return $string . $etc; |
||
| 1497 | } else { |
||
| 1498 | return $string; |
||
| 1499 | } |
||
| 1500 | } |
||
| 1501 | |||
| 1502 | /** |
||
| 1503 | * Create an infotip |
||
| 1504 | * @param $text |
||
| 1505 | * @return string |
||
| 1506 | */ |
||
| 1507 | View Code Duplication | public static function makeInfotips($text) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1508 | { |
||
| 1509 | $ret = ''; |
||
| 1510 | $infotips = self::getModuleOption('infotips'); |
||
| 1511 | if ($infotips > 0) { |
||
| 1512 | $myts = MyTextSanitizer::getInstance(); |
||
| 1513 | $ret = $myts->htmlSpecialChars(xoops_substr(strip_tags($text), 0, $infotips)); |
||
| 1514 | } |
||
| 1515 | |||
| 1516 | return $ret; |
||
| 1517 | } |
||
| 1518 | |||
| 1519 | /** |
||
| 1520 | * Mise en place de l'appel à la feuille de style du module dans le template |
||
| 1521 | * @param string $url |
||
| 1522 | */ |
||
| 1523 | View Code Duplication | public static function setCSS($url = '') |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1524 | { |
||
| 1525 | global $xoopsTpl, $xoTheme; |
||
| 1526 | if ($url == '') { |
||
| 1527 | $url = OLEDRION_URL . 'assets/css/oledrion.css'; |
||
| 1528 | } |
||
| 1529 | |||
| 1530 | if (!is_object($xoTheme)) { |
||
| 1531 | $xoopsTpl->assign('xoops_module_header', $xoopsTpl->get_template_vars('xoops_module_header') . "<link rel=\"stylesheet\" type=\"text/css\" href=\"$url\">"); |
||
| 1532 | } else { |
||
| 1533 | $xoTheme->addStylesheet($url); |
||
| 1534 | } |
||
| 1535 | } |
||
| 1536 | |||
| 1537 | /** |
||
| 1538 | * Mise en place de l'appel à la feuille de style du module dans le template |
||
| 1539 | * @param string $language |
||
| 1540 | */ |
||
| 1541 | View Code Duplication | public static function setLocalCSS($language = 'english') |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1542 | { |
||
| 1543 | global $xoopsTpl, $xoTheme; |
||
| 1544 | |||
| 1545 | $localcss = OLEDRION_URL . 'language/' . $language . '/style.css'; |
||
| 1546 | |||
| 1547 | if (!is_object($xoTheme)) { |
||
| 1548 | $xoopsTpl->assign('xoops_module_header', $xoopsTpl->get_template_vars('xoops_module_header') . "<link rel=\"stylesheet\" type=\"text/css\" href=\"$localcss\">"); |
||
| 1549 | } else { |
||
| 1550 | $xoTheme->addStylesheet($localcss); |
||
| 1551 | } |
||
| 1552 | } |
||
| 1553 | |||
| 1554 | /** |
||
| 1555 | * Calcul du TTC à partir du HT et de la TVA |
||
| 1556 | * |
||
| 1557 | * @param float $ht Montant HT |
||
| 1558 | * @param float $vat Taux de TVA |
||
| 1559 | * @param boolean $edit Si faux alors le montant est formaté pour affichage sinon il reste tel quel |
||
| 1560 | * @param string $format Format d'affichage du résultat (long ou court) |
||
| 1561 | * @return mixed Soit une chaine soit un flottant |
||
| 1562 | */ |
||
| 1563 | View Code Duplication | public static function getTTC($ht, $vat, $edit = false, $format = 's') |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1564 | { |
||
| 1565 | $oledrion_Currency = Oledrion_Currency::getInstance(); |
||
| 1566 | $ttc = $ht * (1 + ($vat / 100)); |
||
| 1567 | if (!$edit) { |
||
| 1568 | return $oledrion_Currency->amountForDisplay($ttc, $format); |
||
| 1569 | } else { |
||
| 1570 | return $ttc; |
||
| 1571 | } |
||
| 1572 | } |
||
| 1573 | |||
| 1574 | /** |
||
| 1575 | * Renvoie le montant de la tva à partir du montant HT |
||
| 1576 | * @param $ht |
||
| 1577 | * @param $vat |
||
| 1578 | * @return float |
||
| 1579 | */ |
||
| 1580 | public static function getVAT($ht, $vat) |
||
| 1581 | { |
||
| 1582 | return (float)(($ht * $vat) / 100); |
||
| 1583 | } |
||
| 1584 | |||
| 1585 | /** |
||
| 1586 | * Retourne le montant TTC |
||
| 1587 | * |
||
| 1588 | * @param floatval $product_price Le montant du produit |
||
| 1589 | * @param integer $vat_id Le numéro de TVA |
||
| 1590 | * @return floatval Le montant TTC si on a trouvé sa TVA sinon |
||
| 1591 | */ |
||
| 1592 | View Code Duplication | public static function getAmountWithVat($product_price, $vat_id) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1593 | { |
||
| 1594 | static $vats = array(); |
||
| 1595 | $vat_rate = null; |
||
| 1596 | if (is_array($vats) && in_array($vat_id, $vats)) { |
||
| 1597 | $vat_rate = $vats[$vat_id]; |
||
| 1598 | } else { |
||
| 1599 | $handlers = OledrionHandler::getInstance(); |
||
| 1600 | $vat = null; |
||
|
0 ignored issues
–
show
$vat 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 Loading history...
|
|||
| 1601 | $vat = $handlers->h_oledrion_vat->get($vat_id); |
||
|
0 ignored issues
–
show
The property
h_oledrion_vat does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. Loading history...
|
|||
| 1602 | if (is_object($vat)) { |
||
| 1603 | $vat_rate = $vat->getVar('vat_rate', 'e'); |
||
| 1604 | $vats[$vat_id] = $vat_rate; |
||
| 1605 | } |
||
| 1606 | } |
||
| 1607 | |||
| 1608 | if (null !== $vat_rate) { |
||
| 1609 | return ((float)$product_price * (float)$vat_rate / 100) + (float)$product_price; |
||
|
0 ignored issues
–
show
The return type of
return (double) $product...double) $product_price; (double) is incompatible with the return type documented by OledrionUtility::getAmountWithVat of type floatval.
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function Loading history...
|
|||
| 1610 | } else { |
||
| 1611 | return $product_price; |
||
| 1612 | } |
||
| 1613 | } |
||
| 1614 | |||
| 1615 | /** |
||
| 1616 | * @param $datastream |
||
| 1617 | * @param $url |
||
| 1618 | * @return string |
||
| 1619 | */ |
||
| 1620 | View Code Duplication | public static function postIt($datastream, $url) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1621 | { |
||
| 1622 | $url = preg_replace('@^http://@i', '', $url); |
||
| 1623 | $host = substr($url, 0, strpos($url, '/')); |
||
| 1624 | $uri = strstr($url, '/'); |
||
| 1625 | $reqbody = ''; |
||
| 1626 | foreach ($datastream as $key => $val) { |
||
| 1627 | if (!empty($reqbody)) { |
||
| 1628 | $reqbody .= '&'; |
||
| 1629 | } |
||
| 1630 | $reqbody .= $key . '=' . urlencode($val); |
||
| 1631 | } |
||
| 1632 | $contentlength = strlen($reqbody); |
||
| 1633 | $reqheader = "POST $uri HTTP/1.1\r\n" . "Host: $host\n" . "Content-Type: application/x-www-form-urlencoded\r\n" . "Content-Length: $contentlength\r\n\r\n" . "$reqbody\r\n"; |
||
| 1634 | |||
| 1635 | return $reqheader; |
||
| 1636 | } |
||
| 1637 | |||
| 1638 | /** |
||
| 1639 | * Retourne le type Mime d'un fichier en utilisant d'abord finfo puis mime_content |
||
| 1640 | * |
||
| 1641 | * @param string $filename Le fichier (avec son chemin d'accès complet) dont on veut connaître le type mime |
||
| 1642 | * @return string |
||
| 1643 | */ |
||
| 1644 | View Code Duplication | public static function getMimeType($filename) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1645 | { |
||
| 1646 | if (function_exists('finfo_open')) { |
||
| 1647 | $finfo = finfo_open(); |
||
| 1648 | $mimetype = finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); |
||
| 1649 | finfo_close($finfo); |
||
| 1650 | |||
| 1651 | return $mimetype; |
||
| 1652 | } else { |
||
| 1653 | if (function_exists('mime_content_type')) { |
||
| 1654 | return mime_content_type($filename); |
||
| 1655 | } else { |
||
| 1656 | return ''; |
||
| 1657 | } |
||
| 1658 | } |
||
| 1659 | } |
||
| 1660 | |||
| 1661 | /** |
||
| 1662 | * Retourne un criteria compo qui permet de filtrer les produits sur le mois courant |
||
| 1663 | * |
||
| 1664 | * @return object |
||
| 1665 | */ |
||
| 1666 | View Code Duplication | public static function getThisMonthCriteria() |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1667 | { |
||
| 1668 | $start = mktime(0, 1, 0, date('n'), date('j'), date('Y')); |
||
| 1669 | $end = mktime(0, 0, 0, date('n'), date('t'), date('Y')); |
||
| 1670 | $criteriaThisMonth = new CriteriaCompo(); |
||
| 1671 | $criteriaThisMonth->add(new Criteria('product_submitted', $start, '>=')); |
||
| 1672 | $criteriaThisMonth->add(new Criteria('product_submitted', $end, '<=')); |
||
| 1673 | |||
| 1674 | return $criteriaThisMonth; |
||
| 1675 | } |
||
| 1676 | |||
| 1677 | /** |
||
| 1678 | * Retourne une liste d'objets XoopsUsers à partir d'une liste d'identifiants |
||
| 1679 | * |
||
| 1680 | * @param array $xoopsUsersIDs La liste des ID |
||
| 1681 | * @return array Les objets XoopsUsers |
||
| 1682 | */ |
||
| 1683 | View Code Duplication | public static function getUsersFromIds($xoopsUsersIDs) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1684 | { |
||
| 1685 | $users = array(); |
||
| 1686 | if (is_array($xoopsUsersIDs) && count($xoopsUsersIDs) > 0) { |
||
| 1687 | $xoopsUsersIDs = array_unique($xoopsUsersIDs); |
||
| 1688 | sort($xoopsUsersIDs); |
||
| 1689 | if (count($xoopsUsersIDs) > 0) { |
||
| 1690 | $memberHandler = xoops_getHandler('user'); |
||
| 1691 | $criteria = new Criteria('uid', '(' . implode(',', $xoopsUsersIDs) . ')', 'IN'); |
||
| 1692 | $criteria->setSort('uid'); |
||
| 1693 | $users = $memberHandler->getObjects($criteria, true); |
||
| 1694 | } |
||
| 1695 | } |
||
| 1696 | |||
| 1697 | return $users; |
||
| 1698 | } |
||
| 1699 | |||
| 1700 | /** |
||
| 1701 | * Retourne l'ID de l'utilisateur courant (s'il est connecté) |
||
| 1702 | * @return integer L'uid ou 0 |
||
| 1703 | */ |
||
| 1704 | public static function getCurrentUserID() |
||
| 1705 | { |
||
| 1706 | global $xoopsUser; |
||
| 1707 | $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; |
||
| 1708 | |||
| 1709 | return $uid; |
||
| 1710 | } |
||
| 1711 | |||
| 1712 | /** |
||
| 1713 | * Retourne la liste des groupes de l'utilisateur courant (avec cache) |
||
| 1714 | * @param int $uid |
||
| 1715 | * @return array Les ID des groupes auquel l'utilisateur courant appartient |
||
| 1716 | */ |
||
| 1717 | View Code Duplication | public static function getMemberGroups($uid = 0) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1718 | { |
||
| 1719 | static $buffer = array(); |
||
| 1720 | if ($uid == 0) { |
||
| 1721 | $uid = self::getCurrentUserID(); |
||
| 1722 | } |
||
| 1723 | |||
| 1724 | if (is_array($buffer) && count($buffer) > 0 && isset($buffer[$uid])) { |
||
| 1725 | return $buffer[$uid]; |
||
| 1726 | } else { |
||
| 1727 | if ($uid > 0) { |
||
| 1728 | $memberHandler = xoops_getHandler('member'); |
||
| 1729 | $buffer[$uid] = $memberHandler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
||
| 1730 | } else { |
||
| 1731 | $buffer[$uid] = array(XOOPS_GROUP_ANONYMOUS); |
||
| 1732 | } |
||
| 1733 | } |
||
| 1734 | |||
| 1735 | return $buffer[$uid]; |
||
| 1736 | } |
||
| 1737 | |||
| 1738 | /** |
||
| 1739 | * Indique si l'utilisateur courant fait partie d'une groupe donné (avec gestion de cache) |
||
| 1740 | * |
||
| 1741 | * @param integer $group Groupe recherché |
||
| 1742 | * @param int $uid |
||
| 1743 | * @return bool vrai si l'utilisateur fait partie du groupe, faux sinon |
||
| 1744 | */ |
||
| 1745 | View Code Duplication | public static function isMemberOfGroup($group = 0, $uid = 0) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1746 | { |
||
| 1747 | static $buffer = array(); |
||
| 1748 | $retval = false; |
||
|
0 ignored issues
–
show
$retval 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 Loading history...
|
|||
| 1749 | if ($uid == 0) { |
||
| 1750 | $uid = self::getCurrentUserID(); |
||
| 1751 | } |
||
| 1752 | if (is_array($buffer) && array_key_exists($group, $buffer)) { |
||
| 1753 | $retval = $buffer[$group]; |
||
| 1754 | } else { |
||
| 1755 | $memberHandler = xoops_getHandler('member'); |
||
| 1756 | $groups = $memberHandler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
||
| 1757 | $retval = in_array($group, $groups); |
||
| 1758 | $buffer[$group] = $retval; |
||
| 1759 | } |
||
| 1760 | |||
| 1761 | return $retval; |
||
| 1762 | } |
||
| 1763 | |||
| 1764 | /** |
||
| 1765 | * Fonction chargée de vérifier qu'un répertoire existe, qu'on peut écrire dedans et création d'un fichier index.html |
||
| 1766 | * |
||
| 1767 | * @param string $folder Le chemin complet du répertoire à vérifier |
||
| 1768 | * @return void |
||
| 1769 | */ |
||
| 1770 | View Code Duplication | public static function prepareFolder($folder) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1771 | { |
||
| 1772 | if (!is_dir($folder)) { |
||
| 1773 | mkdir($folder, 0777); |
||
| 1774 | file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
||
| 1775 | } |
||
| 1776 | chmod($folder, 0777); |
||
| 1777 | } |
||
| 1778 | |||
| 1779 | /** |
||
| 1780 | * Duplicate a file in local |
||
| 1781 | * |
||
| 1782 | * @param string $path The file's path |
||
| 1783 | * @param string $filename The filename |
||
| 1784 | * @return mixed If the copy succeed, the new filename else false |
||
| 1785 | * @since 2.1 |
||
| 1786 | */ |
||
| 1787 | View Code Duplication | public static function duplicateFile($path, $filename) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1788 | { |
||
| 1789 | $newName = self::createUploadName($path, $filename); |
||
| 1790 | if (copy($path . '/' . $filename, $path . '/' . $newName)) { |
||
| 1791 | return $newName; |
||
| 1792 | } else { |
||
| 1793 | return false; |
||
| 1794 | } |
||
| 1795 | } |
||
| 1796 | |||
| 1797 | /** |
||
| 1798 | * Load a language file |
||
| 1799 | * |
||
| 1800 | * @param string $languageFile The required language file |
||
| 1801 | * @param string $defaultExtension Default extension to use |
||
| 1802 | * @since 2.2.2009.02.13 |
||
| 1803 | */ |
||
| 1804 | View Code Duplication | public static function loadLanguageFile($languageFile, $defaultExtension = '.php') |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1805 | { |
||
| 1806 | global $xoopsConfig; |
||
| 1807 | $root = OLEDRION_PATH; |
||
| 1808 | if (false === strpos($languageFile, $defaultExtension)) { |
||
| 1809 | $languageFile .= $defaultExtension; |
||
| 1810 | } |
||
| 1811 | if (file_exists($root . 'language/' . $xoopsConfig['language'] . '/' . $languageFile)) { |
||
| 1812 | require_once $root . 'language/' . $xoopsConfig['language'] . '/' . $languageFile; |
||
| 1813 | } else { // Fallback |
||
| 1814 | require_once $root . 'language/english' . '/' . $languageFile; |
||
| 1815 | } |
||
| 1816 | } |
||
| 1817 | |||
| 1818 | /** |
||
| 1819 | * Formatage d'un floattant pour la base de données |
||
| 1820 | * |
||
| 1821 | * @param float Le montant à formater |
||
| 1822 | * @return string le montant formaté |
||
| 1823 | * @since 2.2.2009.02.25 |
||
| 1824 | */ |
||
| 1825 | public static function formatFloatForDB($amount) |
||
| 1826 | { |
||
| 1827 | return number_format($amount, 2, '.', ''); |
||
| 1828 | } |
||
| 1829 | |||
| 1830 | /** |
||
| 1831 | * Appelle un fichier Javascript à la manière de Xoops |
||
| 1832 | * |
||
| 1833 | * @note, l'url complète ne doit pas être fournie, la méthode se charge d'ajouter |
||
| 1834 | * le chemin vers le répertoire js en fonction de la requête, c'est à dire que si |
||
| 1835 | * on appelle un fichier de langue, la méthode ajoute l'url vers le répertoire de |
||
| 1836 | * langue, dans le cas contraire on ajoute l'url vers le répertoire JS du module. |
||
| 1837 | * |
||
| 1838 | * @param string $javascriptFile |
||
| 1839 | * @param bool $inLanguageFolder |
||
| 1840 | * @param bool $oldWay |
||
| 1841 | * @since 2.3.2009.03.14 |
||
| 1842 | */ |
||
| 1843 | View Code Duplication | public static function callJavascriptFile($javascriptFile, $inLanguageFolder = false, $oldWay = false) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1844 | { |
||
| 1845 | global $xoopsConfig, $xoTheme; |
||
| 1846 | $fileToCall = $javascriptFile; |
||
|
0 ignored issues
–
show
$fileToCall 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 Loading history...
|
|||
| 1847 | if ($inLanguageFolder) { |
||
| 1848 | $root = OLEDRION_PATH; |
||
| 1849 | $rootUrl = OLEDRION_URL; |
||
| 1850 | if (file_exists($root . 'language/' . $xoopsConfig['language'] . '/' . $javascriptFile)) { |
||
| 1851 | $fileToCall = $rootUrl . 'language/' . $xoopsConfig['language'] . '/' . $javascriptFile; |
||
| 1852 | } else { // Fallback |
||
| 1853 | $fileToCall = $rootUrl . 'language/english/' . $javascriptFile; |
||
| 1854 | } |
||
| 1855 | } else { |
||
| 1856 | $fileToCall = OLEDRION_JS_URL . $javascriptFile; |
||
| 1857 | } |
||
| 1858 | |||
| 1859 | $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js'); |
||
| 1860 | $xoTheme->addScript($fileToCall); |
||
| 1861 | } |
||
| 1862 | |||
| 1863 | /** |
||
| 1864 | * Create the <option> of an html select |
||
| 1865 | * |
||
| 1866 | * @param array $array Array of index and labels |
||
| 1867 | * @param mixed $default the default value |
||
| 1868 | * @param bool $withNull |
||
| 1869 | * @return string |
||
| 1870 | * @since 2.3.2009.03.13 |
||
| 1871 | */ |
||
| 1872 | View Code Duplication | public static function htmlSelectOptions($array, $default = 0, $withNull = true) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1873 | { |
||
| 1874 | $ret = array(); |
||
| 1875 | $selected = ''; |
||
| 1876 | if ($withNull) { |
||
| 1877 | if ($default === 0) { |
||
| 1878 | $selected = " selected = 'selected'"; |
||
| 1879 | } |
||
| 1880 | $ret[] = '<option value=0' . $selected . '>---</option>'; |
||
| 1881 | } |
||
| 1882 | |||
| 1883 | foreach ($array as $index => $label) { |
||
| 1884 | $selected = ''; |
||
| 1885 | if ($index == $default) { |
||
| 1886 | $selected = " selected = 'selected'"; |
||
| 1887 | } |
||
| 1888 | $ret[] = "<option value=\"" . $index . "\"" . $selected . '>' . $label . '</option>'; |
||
| 1889 | } |
||
| 1890 | |||
| 1891 | return implode("\n", $ret); |
||
| 1892 | } |
||
| 1893 | |||
| 1894 | /** |
||
| 1895 | * Creates an html select |
||
| 1896 | * |
||
| 1897 | * @param string $selectName Selector's name |
||
| 1898 | * @param array $array Options |
||
| 1899 | * @param mixed $default Default's value |
||
| 1900 | * @param boolean $withNull Do we include a null option ? |
||
| 1901 | * @return string |
||
| 1902 | * @since 2.3.2009.03.13 |
||
| 1903 | */ |
||
| 1904 | View Code Duplication | public static function htmlSelect($selectName, $array, $default, $withNull = true) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1905 | { |
||
| 1906 | $ret = ''; |
||
| 1907 | $ret .= "<select name='" . $selectName . "' id='" . $selectName . "'>\n"; |
||
| 1908 | $ret .= self::htmlSelectOptions($array, $default, $withNull); |
||
| 1909 | $ret .= "</select>\n"; |
||
| 1910 | |||
| 1911 | return $ret; |
||
| 1912 | } |
||
| 1913 | |||
| 1914 | /** |
||
| 1915 | * Extrait l'id d'une chaine formatée sous la forme xxxx-99 (duquel on récupère 99) |
||
| 1916 | * |
||
| 1917 | * @note: utilisé par les attributs produits |
||
| 1918 | * @param string $string La chaine de travail |
||
| 1919 | * @param string $separator Le séparateur |
||
| 1920 | * @return string |
||
|
0 ignored issues
–
show
|
|||
| 1921 | */ |
||
| 1922 | View Code Duplication | public static function getId($string, $separator = '_') |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1923 | { |
||
| 1924 | $pos = strrpos($string, $separator); |
||
| 1925 | if ($pos === false) { |
||
| 1926 | return $string; |
||
| 1927 | } else { |
||
| 1928 | return (int)substr($string, $pos + 1); |
||
| 1929 | } |
||
| 1930 | } |
||
| 1931 | |||
| 1932 | /** |
||
| 1933 | * Fonction "inverse" de getId (depuis xxxx-99 on récupère xxxx) |
||
| 1934 | * |
||
| 1935 | * @note: utilisé par les attributs produits |
||
| 1936 | * @param string $string La chaine de travail |
||
| 1937 | * @param string $separator Le séparateur |
||
| 1938 | * @return string |
||
| 1939 | */ |
||
| 1940 | View Code Duplication | public static function getName($string, $separator = '_') |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 1941 | { |
||
| 1942 | $pos = strrpos($string, $separator); |
||
| 1943 | if ($pos === false) { |
||
| 1944 | return $string; |
||
| 1945 | } else { |
||
| 1946 | return substr($string, 0, $pos); |
||
| 1947 | } |
||
| 1948 | } |
||
| 1949 | |||
| 1950 | /** |
||
| 1951 | * Renvoie un montant nul si le montant est négatif |
||
| 1952 | * |
||
| 1953 | * @param float $amount |
||
| 1954 | * @return float |
||
|
0 ignored issues
–
show
|
|||
| 1955 | */ |
||
| 1956 | public static function doNotAcceptNegativeAmounts(&$amount) |
||
| 1957 | { |
||
| 1958 | if ($amount < 0) { |
||
| 1959 | $amount = 0; |
||
| 1960 | } |
||
| 1961 | } |
||
| 1962 | |||
| 1963 | /** |
||
| 1964 | * Returns a string from the request |
||
| 1965 | * |
||
| 1966 | * @param string $valueName Name of the parameter you want to get |
||
| 1967 | * @param mixed $defaultValue Default value to return if the parameter is not set in the request |
||
| 1968 | * @return mixed |
||
| 1969 | */ |
||
| 1970 | public static function getFromRequest($valueName, $defaultValue = '') |
||
|
0 ignored issues
–
show
getFromRequest uses the super-global variable $_REQUEST 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...
|
|||
| 1971 | { |
||
| 1972 | return isset($_REQUEST[$valueName]) ? $_REQUEST[$valueName] : $defaultValue; |
||
| 1973 | } |
||
| 1974 | |||
| 1975 | /** |
||
| 1976 | * Verify that a mysql table exists |
||
| 1977 | * |
||
| 1978 | * @package Oledrion |
||
| 1979 | * @author Instant Zero (http://xoops.instant-zero.com) |
||
| 1980 | * @copyright (c) Instant Zero |
||
| 1981 | * @param $tablename |
||
| 1982 | * @return bool |
||
| 1983 | */ |
||
| 1984 | public static function tableExists($tablename) |
||
| 1985 | { |
||
| 1986 | global $xoopsDB; |
||
| 1987 | $result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); |
||
| 1988 | |||
| 1989 | return ($xoopsDB->getRowsNum($result) > 0); |
||
| 1990 | } |
||
| 1991 | |||
| 1992 | /** |
||
| 1993 | * Verify that a field exists inside a mysql table |
||
| 1994 | * |
||
| 1995 | * @package Oledrion |
||
| 1996 | * @author Instant Zero (http://xoops.instant-zero.com) |
||
| 1997 | * @copyright (c) Instant Zero |
||
| 1998 | * @param $fieldname |
||
| 1999 | * @param $table |
||
| 2000 | * @return bool |
||
| 2001 | */ |
||
| 2002 | public static function fieldExists($fieldname, $table) |
||
| 2003 | { |
||
| 2004 | global $xoopsDB; |
||
| 2005 | $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
||
| 2006 | |||
| 2007 | return ($xoopsDB->getRowsNum($result) > 0); |
||
| 2008 | } |
||
| 2009 | |||
| 2010 | /** |
||
| 2011 | * Retourne la définition d'un champ |
||
| 2012 | * |
||
| 2013 | * @param string $fieldname |
||
| 2014 | * @param string $table |
||
| 2015 | * @return array |
||
| 2016 | */ |
||
| 2017 | View Code Duplication | public static function getFieldDefinition($fieldname, $table) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 2018 | { |
||
| 2019 | global $xoopsDB; |
||
|
0 ignored issues
–
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
}
}
Loading history...
|
|||
| 2020 | $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
||
| 2021 | if ($result) { |
||
| 2022 | return $xoopsDB->fetchArray($result); |
||
| 2023 | } |
||
| 2024 | |||
| 2025 | return ''; |
||
|
0 ignored issues
–
show
The return type of
return ''; (string) is incompatible with the return type documented by OledrionUtility::getFieldDefinition of type array.
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function Loading history...
|
|||
| 2026 | } |
||
| 2027 | |||
| 2028 | /** |
||
| 2029 | * Add a field to a mysql table |
||
| 2030 | * |
||
| 2031 | * @package Oledrion |
||
| 2032 | * @author Instant Zero (http://xoops.instant-zero.com) |
||
| 2033 | * @copyright (c) Instant Zero |
||
| 2034 | * @param $field |
||
| 2035 | * @param $table |
||
| 2036 | * @return |
||
| 2037 | */ |
||
| 2038 | public static function addField($field, $table) |
||
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a Loading history...
|
|||
| 2039 | { |
||
| 2040 | global $xoopsDB; |
||
| 2041 | $result = $xoopsDB->queryF("ALTER TABLE $table ADD $field;"); |
||
| 2042 | |||
| 2043 | return $result; |
||
| 2044 | } |
||
| 2045 | |||
| 2046 | /** |
||
| 2047 | * @param $info |
||
| 2048 | * @return string |
||
| 2049 | */ |
||
| 2050 | View Code Duplication | public static function packingHtmlSelect($info) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 2051 | { |
||
| 2052 | $ret = ''; |
||
| 2053 | $ret .= '<div class="oledrion_htmlform">'; |
||
| 2054 | $ret .= '<img class="oledrion_htmlimage" src="' . $info['packing_image_url'] . '" alt="' . $info['packing_title'] . '">'; |
||
| 2055 | $ret .= '<h3>' . $info['packing_title'] . '</h3>'; |
||
| 2056 | if ($info['packing_price'] > 0) { |
||
| 2057 | $ret .= '<p><span class="bold">' . _OLEDRION_PRICE . '</span> : ' . $info['packing_price_fordisplay'] . '</p>'; |
||
| 2058 | } else { |
||
| 2059 | $ret .= '<p><span class="bold">' . _OLEDRION_PRICE . '</span> : ' . _OLEDRION_FREE . '</p>'; |
||
| 2060 | } |
||
| 2061 | $ret .= '<p>' . $info['packing_description'] . '</p>'; |
||
| 2062 | $ret .= '</div>'; |
||
| 2063 | |||
| 2064 | return $ret; |
||
| 2065 | } |
||
| 2066 | |||
| 2067 | /** |
||
| 2068 | * @param $info |
||
| 2069 | * @return string |
||
| 2070 | */ |
||
| 2071 | View Code Duplication | public static function deliveryHtmlSelect($info) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 2072 | { |
||
| 2073 | $ret = ''; |
||
| 2074 | $ret .= '<div class="oledrion_htmlform">'; |
||
| 2075 | $ret .= '<img class="oledrion_htmlimage" src="' . $info['delivery_image_url'] . '" alt="' . $info['delivery_title'] . '">'; |
||
| 2076 | $ret .= '<h3>' . $info['delivery_title'] . '</h3>'; |
||
| 2077 | if ($info['delivery_price'] > 0) { |
||
| 2078 | $ret .= '<p><span class="bold">' . _OLEDRION_PRICE . '</span> : ' . $info['delivery_price_fordisplay'] . '</p>'; |
||
| 2079 | } else { |
||
| 2080 | $ret .= '<p><span class="bold">' . _OLEDRION_PRICE . '</span> : ' . _OLEDRION_FREE . '</p>'; |
||
| 2081 | } |
||
| 2082 | $ret .= '<p><span class="bold">' . _OLEDRION_DELIVERY_TIME . '</span> : ' . $info['delivery_time'] . _OLEDRION_DELIVERY_DAY . '</p>'; |
||
| 2083 | $ret .= '<p>' . $info['delivery_description'] . '</p>'; |
||
| 2084 | $ret .= '</div>'; |
||
| 2085 | |||
| 2086 | return $ret; |
||
| 2087 | } |
||
| 2088 | |||
| 2089 | /** |
||
| 2090 | * @param $info |
||
| 2091 | * @return string |
||
| 2092 | */ |
||
| 2093 | View Code Duplication | public static function paymentHtmlSelect($info) |
|
|
0 ignored issues
–
show
This method 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...
|
|||
| 2094 | { |
||
| 2095 | $ret = ''; |
||
| 2096 | $ret .= '<div class="oledrion_htmlform">'; |
||
| 2097 | $ret .= '<img class="oledrion_htmlimage" src="' . $info['payment_image_url'] . '" alt="' . $info['payment_title'] . '">'; |
||
| 2098 | $ret .= '<h3>' . $info['payment_title'] . '</h3>'; |
||
| 2099 | $ret .= '<p>' . $info['payment_description'] . '</p>'; |
||
| 2100 | $ret .= '</div>'; |
||
| 2101 | |||
| 2102 | return $ret; |
||
| 2103 | } |
||
| 2104 | |||
| 2105 | /** |
||
| 2106 | * @return array |
||
| 2107 | */ |
||
| 2108 | public static function getCountriesList() |
||
| 2109 | { |
||
| 2110 | require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
||
| 2111 | |||
| 2112 | return XoopsLists::getCountryList(); |
||
| 2113 | } |
||
| 2114 | } |
||
| 2115 |
This check looks for classes that have been defined more than once.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.