Completed
Push — master ( 10bab4...a0a78b )
by Michael
02:06
created

oninstall.php ➔ xoops_module_install_planet()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 48
Code Lines 29

Duplication

Lines 13
Ratio 27.08 %

Importance

Changes 0
Metric Value
cc 5
eloc 29
nc 4
nop 1
dl 13
loc 48
rs 8.551
c 0
b 0
f 0
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
 * @copyright    XOOPS Project https://xoops.org/
14
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team
18
 */
19
20
//require_once __DIR__ . '/setup.php';
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...
21
22
/**
23
 *
24
 * Prepares system prior to attempting to install module
25
 * @param XoopsModule $module {@link XoopsModule}
26
 *
27
 * @return bool true if ready to install, false if not
28
 */
29
function xoops_module_pre_install_planet(\XoopsModule $module)
30
{
31
    include __DIR__ . '/../preloads/autoloader.php';
32
    /** @var \Utility $utility */
33
    $utility = new \XoopsModules\Planet\Utility();
34
    $xoopsSuccess = $utility::checkVerXoops($module);
35
    $phpSuccess   = $utility::checkVerPhp($module);
36
37
    if (false !== $xoopsSuccess && false !==  $phpSuccess) {
38
        $moduleTables =& $module->getInfo('tables');
39
        foreach ($moduleTables as $table) {
40
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
41
        }
42
    }
43
44
    return $xoopsSuccess && $phpSuccess;
45
}
46
47
/**
48
 *
49
 * Performs tasks required during installation of the module
50
 * @param XoopsModule $module {@link XoopsModule}
51
 *
52
 * @return bool true if installation successful, false if not
53
 */
54
function xoops_module_install_planet(\XoopsModule $module)
55
{
56
    require_once  __DIR__ . '/../../../mainfile.php';
57
    require_once  __DIR__ . '/../include/config.php';
58
59
    $moduleDirName = basename(dirname(__DIR__));
60
61
    $helper       = Planet\Helper::getInstance();
62
    $utility      = new Planet\Utility();
0 ignored issues
show
Unused Code introduced by
$utility 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
63
    $configurator = new Planet\Configurator();
64
    // Load language files
65
    $helper->loadLanguage('admin');
66
    $helper->loadLanguage('modinfo');
67
68
    // default Permission Settings ----------------------
69
    global $xoopsModule;
70
    $moduleId     = $xoopsModule->getVar('mid');
71
    $moduleId2    = $helper->getModule()->mid();
0 ignored issues
show
Unused Code introduced by
$moduleId2 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
72
    $gpermHandler = xoops_getHandler('groupperm');
73
    // access rights ------------------------------------------
74
    $gpermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
75
    $gpermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
76
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
77
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
78
    $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
79
80
    //  ---  CREATE FOLDERS ---------------
81 View Code Duplication
    if (count($configurator->uploadFolders) > 0) {
0 ignored issues
show
Duplication introduced by
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...
82
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
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...
83
        foreach (array_keys($configurator->uploadFolders) as $i) {
84
            $utilityClass::createFolder($configurator->uploadFolders[$i]);
0 ignored issues
show
Bug introduced by
The variable $utilityClass does not exist. Did you mean $utility?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
85
        }
86
    }
87
88
    //  ---  COPY blank.png FILES ---------------
89 View Code Duplication
    if (count($configurator->copyBlankFiles) > 0) {
0 ignored issues
show
Duplication introduced by
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...
90
        $file = __DIR__ . '/../assets/images/blank.png';
91
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
92
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
93
            $utilityClass::copyFile($file, $dest);
0 ignored issues
show
Bug introduced by
The variable $utilityClass does not exist. Did you mean $utility?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
94
        }
95
    }
96
    //delete .html entries from the tpl table
97
    $sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $xoopsModule->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
0 ignored issues
show
Bug introduced by
The variable $xoopsDB does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
98
    $xoopsDB->queryF($sql);
99
100
    return true;
101
}
102
103
//======================================================
104
105
$indexFile = 'index.html';
106
$blankFile = $GLOBALS['xoops']->path('modules/randomquote/assets/images/icons/blank.gif');
107
108
//Creation du dossier "uploads" pour le module à la racine du site
109
$module_uploads = $GLOBALS['xoops']->path('uploads/randomquote');
110
if (!is_dir($module_uploads)) {
111
    mkdir($module_uploads, 0777);
112
}
113
chmod($module_uploads, 0777);
114
copy($indexFile, $GLOBALS['xoops']->path('uploads/randomquote/index.html'));
115
116
//Creation du fichier citas dans uploads
117
$module_uploads = $GLOBALS['xoops']->path('uploads/randomquote/citas');
118
if (!is_dir($module_uploads)) {
119
    mkdir($module_uploads, 0777);
120
}
121
chmod($module_uploads, 0777);
122
copy($indexFile, $GLOBALS['xoops']->path('uploads/randomquote/citas/index.html'));
123