XoopsModules25x /
news
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * News functions |
||
| 4 | * |
||
| 5 | * You may not change or alter any portion of this comment or credits |
||
| 6 | * of supporting developers from this source code or any supporting source code |
||
| 7 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 8 | * This program is distributed in the hope that it will be useful, |
||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 11 | * |
||
| 12 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 13 | * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
||
| 14 | * @author Voltan |
||
| 15 | * @package News |
||
| 16 | * @param $xoopsModule |
||
| 17 | * @return bool |
||
| 18 | */ |
||
| 19 | |||
| 20 | function xoops_module_pre_install_news(XoopsModule $xoopsModule) |
||
| 21 | { |
||
| 22 | // Check if this XOOPS version is supported |
||
| 23 | $minSupportedVersion = explode('.', '2.5.0'); |
||
| 24 | $currentVersion = explode('.', substr(XOOPS_VERSION, 6)); |
||
| 25 | |||
| 26 | if ($currentVersion[0] > $minSupportedVersion[0]) { |
||
| 27 | return true; |
||
| 28 | } elseif ($currentVersion[0] == $minSupportedVersion[0]) { |
||
| 29 | if ($currentVersion[1] > $minSupportedVersion[1]) { |
||
| 30 | return true; |
||
| 31 | } elseif ($currentVersion[1] == $minSupportedVersion[1]) { |
||
| 32 | if ($currentVersion[2] > $minSupportedVersion[2]) { |
||
| 33 | return true; |
||
| 34 | } elseif ($currentVersion[2] == $minSupportedVersion[2]) { |
||
| 35 | return true; |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | return false; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param XoopsModule $xoopsModule |
||
| 45 | * |
||
| 46 | * @return bool |
||
| 47 | */ |
||
| 48 | function xoops_module_install_news(XoopsModule $xoopsModule) |
||
| 49 | { |
||
| 50 | $module_id = $xoopsModule->getVar('mid'); |
||
| 51 | $gpermHandler = xoops_getHandler('groupperm'); |
||
| 52 | $configHandler = xoops_getHandler('config'); |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Default public category permission mask |
||
| 56 | */ |
||
| 57 | |||
| 58 | // Access right |
||
| 59 | $gpermHandler->addRight('news_approve', 1, XOOPS_GROUP_ADMIN, $module_id); |
||
| 60 | $gpermHandler->addRight('news_submit', 1, XOOPS_GROUP_ADMIN, $module_id); |
||
| 61 | $gpermHandler->addRight('news_view', 1, XOOPS_GROUP_ADMIN, $module_id); |
||
| 62 | |||
| 63 | $gpermHandler->addRight('news_view', 1, XOOPS_GROUP_USERS, $module_id); |
||
| 64 | $gpermHandler->addRight('news_view', 1, XOOPS_GROUP_ANONYMOUS, $module_id); |
||
| 65 | |||
| 66 | $dir = XOOPS_ROOT_PATH . '/uploads/news'; |
||
| 67 | // if (!is_dir($dir)) { |
||
|
0 ignored issues
–
show
|
|||
| 68 | // mkdir($dir, 0777); |
||
|
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...
|
|||
| 69 | // } |
||
| 70 | |||
| 71 | View Code Duplication | if (!@mkdir($dir) && !is_dir($dir)) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 72 | throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); |
||
| 73 | } |
||
| 74 | |||
| 75 | chmod($dir, 0777); |
||
| 76 | |||
| 77 | $dir = XOOPS_ROOT_PATH . '/uploads/news/file'; |
||
| 78 | View Code Duplication | if (!@mkdir($dir) && !is_dir($dir)) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 79 | throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); |
||
| 80 | } |
||
| 81 | chmod($dir, 0777); |
||
| 82 | |||
| 83 | $dir = XOOPS_ROOT_PATH . '/uploads/news/image'; |
||
| 84 | View Code Duplication | if (!@mkdir($dir) && !is_dir($dir)) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 85 | throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); |
||
| 86 | } |
||
| 87 | chmod($dir, 0777); |
||
| 88 | |||
| 89 | // Copy index.html files on uploads folders |
||
| 90 | $indexFile = XOOPS_ROOT_PATH . '/modules/news/include/index.html'; |
||
| 91 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/news/index.html'); |
||
| 92 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/news/file/index.html'); |
||
| 93 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/news/image/index.html'); |
||
| 94 | |||
| 95 | return true; |
||
| 96 | } |
||
| 97 |
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.