1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Modulebuilder; |
4
|
|
|
|
5
|
|
|
use XoopsModules\Modulebuilder; |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
You may not change or alter any portion of this comment or credits |
9
|
|
|
of supporting developers from this source code or any supporting source code |
10
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
11
|
|
|
|
12
|
|
|
This program is distributed in the hope that it will be useful, |
13
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Building class. |
19
|
|
|
* |
20
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
21
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
22
|
|
|
* |
23
|
|
|
* @since 2.5.x |
24
|
|
|
* |
25
|
|
|
* @author TDM TEAM DEV MODULE |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class Building. |
31
|
|
|
*/ |
32
|
|
|
class Building |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @static function getInstance |
36
|
|
|
* |
37
|
|
|
* @param null |
38
|
|
|
* |
39
|
|
|
* @return Building |
40
|
|
|
*/ |
41
|
|
|
public static function getInstance() |
42
|
|
|
{ |
43
|
|
|
static $instance = false; |
44
|
|
|
if (!$instance) { |
45
|
|
|
$instance = new self(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $instance; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param bool $action |
53
|
|
|
* |
54
|
|
|
* @return \XoopsThemeForm |
55
|
|
|
*/ |
56
|
|
|
public function getForm($action = false) |
57
|
|
|
{ |
58
|
|
|
$helper = Modulebuilder\Helper::getInstance(); |
59
|
|
|
if (false === $action) { |
60
|
|
|
$action = \Xmf\Request::getString('REQUEST_URI', '', 'SERVER'); |
61
|
|
|
} |
62
|
|
|
\xoops_load('XoopsFormLoader'); |
63
|
|
|
$form = new \XoopsThemeForm(\_AM_MODULEBUILDER_ADMIN_CONST, 'buildform', $action, 'post', true); |
|
|
|
|
64
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
65
|
|
|
$moduleObj = $helper->getHandler('Modules')->getObjects(null); |
66
|
|
|
$mod_select = new \XoopsFormSelect(\_AM_MODULEBUILDER_CONST_MODULES, 'mod_id', 'mod_id'); |
67
|
|
|
$mod_select->addOption('', \_AM_MODULEBUILDER_BUILD_MODSELOPT); |
68
|
|
|
foreach ($moduleObj as $mod) { |
69
|
|
|
$mod_select->addOption($mod->getVar('mod_id'), $mod->getVar('mod_name')); |
70
|
|
|
} |
71
|
|
|
$form->addElement($mod_select, true); |
72
|
|
|
|
73
|
|
|
$form->addElement(new \XoopsFormRadioYN(\_AM_MODULEBUILDER_BUILDING_INROOT_COPY, 'inroot_copy', $helper->getConfig('inroot_copy'))); |
74
|
|
|
$form->addElement(new \XoopsFormRadioYN(\_AM_MODULEBUILDER_BUILDING_TEST . \_AM_MODULEBUILDER_BUILDING_TEST_DESC, 'testdata_restore', 0)); |
75
|
|
|
|
76
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'build')); |
77
|
|
|
$btnTray = new \XoopsFormElementTray(\_REQUIRED . ' <sup class="red bold">*</sup>', ' '); |
78
|
|
|
$btnTray->addElement(new \XoopsFormButton('', 'submit', \_SUBMIT, 'submit')); |
79
|
|
|
$btnTray->addElement(new \XoopsFormButton('', 'check_data', \_AM_MODULEBUILDER_BUILDING_CHECK, 'submit')); |
80
|
|
|
$form->addElement($btnTray); |
81
|
|
|
|
82
|
|
|
return $form; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $dir |
87
|
|
|
* @param string $pattern |
88
|
|
|
*/ |
89
|
|
|
public function clearDir($dir, $pattern = '*') |
90
|
|
|
{ |
91
|
|
|
// Find all files and folders matching pattern |
92
|
|
|
$files = glob($dir . "/$pattern"); |
93
|
|
|
// Interate thorugh the files and folders |
94
|
|
|
foreach ($files as $file) { |
95
|
|
|
// if it's a directory then re-call clearDir function to delete files inside this directory |
96
|
|
|
if (\is_dir($file) && !\in_array($file, ['..', '.'])) { |
97
|
|
|
// Remove the directory itself |
98
|
|
|
$this->clearDir($file, $pattern); |
99
|
|
|
} elseif ((__FILE__ != $file) && is_file($file)) { |
100
|
|
|
// Make sure you don't delete the current script |
101
|
|
|
\unlink($file); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
if (\is_dir($dir)) { |
105
|
|
|
\rmdir($dir); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param string $src |
111
|
|
|
* @param string $dst |
112
|
|
|
*/ |
113
|
|
|
public function copyDir($src, $dst) |
114
|
|
|
{ |
115
|
|
|
$dir = \opendir($src); |
116
|
|
|
if (!\mkdir($dst) && !\is_dir($dst)) { |
117
|
|
|
throw new \RuntimeException(\sprintf('Directory "%s" was not created', $dst)); |
118
|
|
|
} |
119
|
|
|
while (false !== ($file = \readdir($dir))) { |
120
|
|
|
if (('.' !== $file) && ('..' !== $file)) { |
121
|
|
|
if (\is_dir($src . '/' . $file)) { |
122
|
|
|
// Copy the directory itself |
123
|
|
|
$this->copyDir($src . '/' . $file, $dst . '/' . $file); |
124
|
|
|
} else { |
125
|
|
|
// Make sure you copy the current script |
126
|
|
|
\copy($src . '/' . $file, $dst . '/' . $file); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
\closedir($dir); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|