xoops_module_install_xoosocialnetwork()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 21
rs 9.5222
c 1
b 0
f 0
cc 5
nc 5
nop 0
1
<?php
2
/**
3
 * Xoosocialnetwork module
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       XOOPS Project (https://xoops.org)
13
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @package         Xoosocialnetwork
15
 * @since           2.6.0
16
 * @author          Laurent JEN (Aka DuGris)
17
18
 */
19
20
/**
21
 * @return bool
22
 */
23
function xoops_module_install_xoosocialnetwork()
24
{
25
    $xoops = \Xoops::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $xoops is dead and can be removed.
Loading history...
26
    $folders = [];
27
    $folders[] = \XoopsBaseConfig::get('uploads-path') . '/xoosocialnetwork/images';
28
    $images = [
29
        'index.html',
30
        'blank.gif', ];
31
32
    foreach ($folders as $folder) {
33
        if (!xoosocialnetwork_mkdirs($folder)) {
34
            return false;
35
        }
36
        foreach ($images as $image) {
37
            if (!xoosocialnetwork_copyfile(\XoopsBaseConfig::get('uploads-path'), $image, $folder)) {
38
                return false;
39
            }
40
        }
41
    }
42
43
    return true;
44
}
45
46
/**
47
 * @param              $pathname
48
 * @param mixed|string $pathout
49
 * @return bool
50
 */
51
function xoosocialnetwork_mkdirs($pathname, $pathout = XOOPS_ROOT_PATH)
52
{
53
    $xoops = \Xoops::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $xoops is dead and can be removed.
Loading history...
54
    $pathname = mb_substr($pathname, mb_strlen(\XoopsBaseConfig::get('root-path')));
55
    $pathname = str_replace(DIRECTORY_SEPARATOR, '/', $pathname);
56
57
    $dest = $pathout;
58
    $paths = explode('/', $pathname);
59
60
    foreach ($paths as $path) {
61
        if (!empty($path)) {
62
            $dest = $dest . '/' . $path;
63
            if (!is_dir($dest)) {
64
                if (!mkdir($dest, 0755) && !is_dir($dest)) {
65
                    return false;
66
                }
67
                xoosocialnetwork_copyfile(\XoopsBaseConfig::get('uploads-path'), 'index.html', $dest);
68
            }
69
        }
70
    }
71
72
    return true;
73
}
74
75
/**
76
 * @param $folder_in
77
 * @param $source_file
78
 * @param $folder_out
79
 * @return bool
80
 */
81
function xoosocialnetwork_copyfile($folder_in, $source_file, $folder_out)
82
{
83
    if (!is_dir($folder_out)) {
84
        if (!xoosocialnetwork_mkdirs($folder_out)) {
85
            return false;
86
        }
87
    }
88
89
    // Simple copy for a file
90
    if (is_file($folder_in . '/' . $source_file)) {
91
        return copy($folder_in . '/' . $source_file, $folder_out . '/' . basename($source_file));
92
    }
93
94
    return false;
95
}
96