Passed
Branch master (acf800)
by Michael
02:26
created

PublisherClone::cloneFileFolder()   B

Complexity

Conditions 8
Paths 7

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 19
nc 7
nop 1
dl 0
loc 32
rs 8.4444
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       The XUUPS Project http://sourceforge.net/projects/xuups/
14
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @package         Publisher
16
 * @since           1.0
17
 * @author          trabis <[email protected]>
18
 */
19
20
use Xmf\Request;
21
use XoopsModules\Publisher;
22
23
require_once __DIR__ . '/admin_header.php';
24
25
Publisher\Utility::cpHeader();
26
//publisher_adminMenu(-1, _AM_PUBLISHER_CLONE);
27
Publisher\Utility::openCollapsableBar('clone', 'cloneicon', _AM_PUBLISHER_CLONE, _AM_PUBLISHER_CLONE_DSC);
28
29
if ('submit' === Request::getString('op', '', 'POST')) {
30
    if (!$GLOBALS['xoopsSecurity']->check()) {
31
        redirect_header('clone.php', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
32
        //        exit();
33
    }
34
35
    //    $clone = $_POST['clone'];
36
    $clone = Request::getString('clone', '', 'POST');
37
38
    //check if name is valid
39
    if (empty($clone) || preg_match('/[^a-zA-Z0-9\_\-]/', $clone)) {
40
        redirect_header('clone.php', 3, sprintf(_AM_PUBLISHER_CLONE_INVALIDNAME, $clone));
41
        //        exit();
42
    }
43
44
    // Check wether the cloned module exists or not
45
    if ($clone && is_dir($GLOBALS['xoops']->path('modules/' . $clone))) {
46
        redirect_header('clone.php', 3, sprintf(_AM_PUBLISHER_CLONE_EXISTS, $clone));
47
    }
48
49
    $patterns = [
50
        mb_strtolower(PUBLISHER_DIRNAME)          => mb_strtolower($clone),
1 ignored issue
show
Bug introduced by
The constant PUBLISHER_DIRNAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
51
        mb_strtoupper(PUBLISHER_DIRNAME)          => mb_strtoupper($clone),
52
        ucfirst(mb_strtolower(PUBLISHER_DIRNAME)) => ucfirst(mb_strtolower($clone)),
53
    ];
54
55
    $patKeys   = array_keys($patterns);
56
    $patValues = array_values($patterns);
57
    Publisher\Cloner::cloneFileFolder(PUBLISHER_ROOT_PATH);
1 ignored issue
show
Bug introduced by
The constant PUBLISHER_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
58
    $logocreated = Publisher\Cloner::createLogo(mb_strtolower($clone));
59
60
    $msg = '';
61
    if (is_dir($GLOBALS['xoops']->path('modules/' . mb_strtolower($clone)))) {
62
        $msg .= sprintf(_AM_PUBLISHER_CLONE_CONGRAT, "<a href='" . XOOPS_URL . "/modules/system/admin.php?fct=modulesadmin'>" . ucfirst(mb_strtolower($clone)) . '</a>') . "<br>\n";
63
        if (!$logocreated) {
64
            $msg .= _AM_PUBLISHER_CLONE_IMAGEFAIL;
65
        }
66
    } else {
67
        $msg .= _AM_PUBLISHER_CLONE_FAIL;
68
    }
69
    echo $msg;
70
} else {
71
    require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
72
    $form  = new \XoopsThemeForm(sprintf(_AM_PUBLISHER_CLONE_TITLE, $helper->getModule()->getVar('name', 'E')), 'clone', 'clone.php', 'post', true);
73
    $clone = new \XoopsFormText(_AM_PUBLISHER_CLONE_NAME, 'clone', 20, 20, '');
74
    $clone->setDescription(_AM_PUBLISHER_CLONE_NAME_DSC);
75
    $form->addElement($clone, true);
76
    $form->addElement(new \XoopsFormHidden('op', 'submit'));
77
    $form->addElement(new \XoopsFormButton('', '', _SUBMIT, 'submit'));
78
    $form->display();
79
}
80
81
// End of collapsable bar
82
Publisher\Utility::closeCollapsableBar('clone', 'cloneicon');
83
84
require_once __DIR__ . '/admin_footer.php';
85
86
// work around for PHP < 5.0.x
87
/*
88
if (!function_exists('file_put_contents')) {
89
    function file_put_contents($filename, $data, $file_append = false)
90
    {
91
        if ($fp == fopen($filename, (!$file_append ? 'w+' : 'a+'))) {
92
            fwrite($fp, $data);
93
            fclose($fp);
94
        }
95
    }
96
}
97
*/
98