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
|
|
|
include_once __DIR__ . '/admin_header.php'; |
21
|
|
|
|
22
|
|
|
publisherCpHeader(); |
23
|
|
|
//publisher_adminMenu(-1, _AM_PUBLISHER_CLONE); |
|
|
|
|
24
|
|
|
publisherOpenCollapsableBar('clone', 'cloneicon', _AM_PUBLISHER_CLONE, _AM_PUBLISHER_CLONE_DSC); |
25
|
|
|
|
26
|
|
|
if ('submit' === XoopsRequest::getString('op', '', 'POST')) { |
27
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
28
|
|
|
redirect_header('clone.php', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
29
|
|
|
// exit(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// $clone = $_POST['clone']; |
|
|
|
|
33
|
|
|
$clone = XoopsRequest::getString('clone', '', 'POST'); |
34
|
|
|
|
35
|
|
|
//check if name is valid |
36
|
|
|
if (empty($clone) || preg_match('/[^a-zA-Z0-9\_\-]/', $clone)) { |
37
|
|
|
redirect_header('clone.php', 3, sprintf(_AM_PUBLISHER_CLONE_INVALIDNAME, $clone)); |
38
|
|
|
// exit(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// Check wether the cloned module exists or not |
42
|
|
|
if ($clone && is_dir($GLOBALS['xoops']->path('modules/' . $clone))) { |
43
|
|
|
redirect_header('clone.php', 3, sprintf(_AM_PUBLISHER_CLONE_EXISTS, $clone)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$patterns = array( |
47
|
|
|
strtolower(PUBLISHER_DIRNAME) => strtolower($clone), |
48
|
|
|
strtoupper(PUBLISHER_DIRNAME) => strtoupper($clone), |
49
|
|
|
ucfirst(strtolower(PUBLISHER_DIRNAME)) => ucfirst(strtolower($clone)) |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$patKeys = array_keys($patterns); |
53
|
|
|
$patValues = array_values($patterns); |
54
|
|
|
PublisherClone::cloneFileFolder(PUBLISHER_ROOT_PATH); |
55
|
|
|
$logocreated = PublisherClone::createLogo(strtolower($clone)); |
56
|
|
|
|
57
|
|
|
$msg = ''; |
58
|
|
|
if (is_dir($GLOBALS['xoops']->path('modules/' . strtolower($clone)))) { |
59
|
|
|
$msg .= sprintf( |
60
|
|
|
_AM_PUBLISHER_CLONE_CONGRAT, |
61
|
|
|
"<a href='" . XOOPS_URL . "/modules/system/admin.php?fct=modulesadmin'>" |
62
|
|
|
. ucfirst(strtolower($clone)) . '</a>' |
63
|
|
|
) . "<br>\n"; |
64
|
|
|
if (!$logocreated) { |
65
|
|
|
$msg .= _AM_PUBLISHER_CLONE_IMAGEFAIL; |
66
|
|
|
} |
67
|
|
|
} else { |
68
|
|
|
$msg .= _AM_PUBLISHER_CLONE_FAIL; |
69
|
|
|
} |
70
|
|
|
echo $msg; |
71
|
|
|
} else { |
72
|
|
|
include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
73
|
|
|
$form = new XoopsThemeForm( |
74
|
|
|
sprintf(_AM_PUBLISHER_CLONE_TITLE, $publisher->getModule()->getVar('name', 'E')), |
75
|
|
|
'clone', |
76
|
|
|
'clone.php', |
77
|
|
|
'post', |
78
|
|
|
true |
79
|
|
|
); |
80
|
|
|
$clone = new XoopsFormText(_AM_PUBLISHER_CLONE_NAME, 'clone', 20, 20, ''); |
81
|
|
|
$clone->setDescription(_AM_PUBLISHER_CLONE_NAME_DSC); |
82
|
|
|
$form->addElement($clone, true); |
83
|
|
|
$form->addElement(new XoopsFormHidden('op', 'submit')); |
84
|
|
|
$form->addElement(new XoopsFormButton('', '', _SUBMIT, 'submit')); |
85
|
|
|
$form->display(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// End of collapsable bar |
89
|
|
|
publisherCloseCollapsableBar('clone', 'cloneicon'); |
90
|
|
|
|
91
|
|
|
include_once __DIR__ . '/admin_footer.php'; |
92
|
|
|
|
93
|
|
|
// work around for PHP < 5.0.x |
|
|
|
|
94
|
|
|
/* |
95
|
|
|
if (!function_exists('file_put_contents')) { |
96
|
|
|
function file_put_contents($filename, $data, $file_append = false) |
97
|
|
|
{ |
98
|
|
|
if ($fp == fopen($filename, (!$file_append ? 'w+' : 'a+'))) { |
99
|
|
|
fwrite($fp, $data); |
100
|
|
|
fclose($fp); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
*/ |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Class PublisherClone |
108
|
|
|
*/ |
109
|
|
|
class PublisherClone |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
// recursive cloning script |
112
|
|
|
/** |
113
|
|
|
* @param $path |
114
|
|
|
*/ |
115
|
|
|
public static function cloneFileFolder($path) |
116
|
|
|
{ |
117
|
|
|
global $patKeys; |
|
|
|
|
118
|
|
|
global $patValues; |
|
|
|
|
119
|
|
|
|
120
|
|
|
$newPath = str_replace($patKeys[0], $patValues[0], $path); |
121
|
|
|
|
122
|
|
|
if (is_dir($path)) { |
123
|
|
|
// create new dir |
124
|
|
|
mkdir($newPath); |
125
|
|
|
|
126
|
|
|
// check all files in dir, and process it |
127
|
|
|
if ($handle = opendir($path)) { |
128
|
|
|
while (($file = readdir($handle)) !== false) { |
129
|
|
|
if (substr($file, 0, 1) !== '.') { |
130
|
|
|
self::cloneFileFolder("{$path}/{$file}"); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
closedir($handle); |
134
|
|
|
} |
135
|
|
|
} else { |
136
|
|
|
$noChangeExtensions = array('jpeg', 'jpg', 'gif', 'png', 'zip', 'ttf'); |
137
|
|
|
if (in_array(strtolower(pathinfo($path, PATHINFO_EXTENSION)), $noChangeExtensions)) { |
138
|
|
|
// image |
139
|
|
|
copy($path, $newPath); |
140
|
|
|
} else { |
141
|
|
|
// file, read it |
142
|
|
|
$content = file_get_contents($path); |
143
|
|
|
$content = str_replace($patKeys, $patValues, $content); |
144
|
|
|
file_put_contents($newPath, $content); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param $dirname |
151
|
|
|
* |
152
|
|
|
* @return bool |
153
|
|
|
*/ |
154
|
|
|
public static function createLogo($dirname) |
|
|
|
|
155
|
|
|
{ |
156
|
|
|
if (!extension_loaded('gd')) { |
157
|
|
|
return false; |
158
|
|
|
} else { |
159
|
|
|
$requiredFunctions = array( |
160
|
|
|
'imagecreatefrompng', 'imagecolorallocate', 'imagefilledrectangle', |
161
|
|
|
'imagepng', 'imagedestroy', 'imagefttext', |
162
|
|
|
'imagealphablending', 'imagesavealpha', |
163
|
|
|
); |
164
|
|
|
foreach ($requiredFunctions as $func) { |
165
|
|
|
if (!function_exists($func)) { |
166
|
|
|
return false; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
// unset($func); |
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
if (!file_exists($imageBase = $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/logo_module.png')) || |
173
|
|
|
!file_exists($font = $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/VeraBd.ttf')) |
174
|
|
|
) { |
175
|
|
|
return false; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
$imageModule = imagecreatefrompng($imageBase); |
179
|
|
|
// save existing alpha channel |
180
|
|
|
imagealphablending($imageModule, false); |
181
|
|
|
imagesavealpha($imageModule, true); |
182
|
|
|
|
183
|
|
|
//Erase old text |
184
|
|
|
$greyColor = imagecolorallocate($imageModule, 237, 237, 237); |
185
|
|
|
imagefilledrectangle($imageModule, 5, 35, 85, 46, $greyColor); |
186
|
|
|
|
187
|
|
|
// Write text |
188
|
|
|
$textColor = imagecolorallocate($imageModule, 0, 0, 0); |
189
|
|
|
$spaceToBorder = (80 - strlen($dirname) * 6.5) / 2; |
190
|
|
|
imagefttext($imageModule, 8.5, 0, $spaceToBorder, 45, $textColor, $font, ucfirst($dirname), array()); |
191
|
|
|
|
192
|
|
|
// Set transparency color |
193
|
|
|
//$white = imagecolorallocatealpha($imageModule, 255, 255, 255, 127); |
|
|
|
|
194
|
|
|
//imagefill($imageModule, 0, 0, $white); |
|
|
|
|
195
|
|
|
//imagecolortransparent($imageModule, $white); |
|
|
|
|
196
|
|
|
|
197
|
|
|
imagepng($imageModule, $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/logo_module.png')); |
198
|
|
|
imagedestroy($imageModule); |
199
|
|
|
|
200
|
|
|
return true; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.