xooghost_mkdirs()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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