1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19:
20:
21: include_once __DIR__ . "/admin_header.php";
22:
23: $xoops = Xoops::getInstance();
24: PublisherUtils::cpHeader();
25:
26: PublisherUtils::openCollapsableBar('clone', 'cloneicon', _AM_PUBLISHER_CLONE, _AM_PUBLISHER_CLONE_DSC);
27:
28: if (@$_POST['op'] === 'submit') {
29:
30: if (!$xoops->security()->check()) {
31: $xoops->redirect('clone.php', 3, implode('<br />', $xoops->security()->getErrors()));
32: }
33:
34: $clone = $_POST['clone'];
35:
36:
37: if (empty($clone) || preg_match('/[^a-zA-Z0-9\_\-]/', $clone)) {
38: $xoops->redirect('clone.php', 3, sprintf(_AM_PUBLISHER_CLONE_INVALIDNAME, $clone));
39: exit();
40: }
41:
42:
43: if ($clone && is_dir(\XoopsBaseConfig::get('root-path') . '/modules/' . $clone)) {
44: $xoops->redirect('clone.php', 3, sprintf(_AM_PUBLISHER_CLONE_EXISTS, $clone));
45: }
46:
47: $patterns = array(
48: strtolower(PUBLISHER_DIRNAME) => strtolower($clone),
49: strtoupper(PUBLISHER_DIRNAME) => strtoupper($clone),
50: ucfirst(strtolower(PUBLISHER_DIRNAME)) => ucfirst(strtolower($clone))
51: );
52:
53: $patKeys = array_keys($patterns);
54: $patValues = array_values($patterns);
55: publisher_cloneFileFolder(PUBLISHER_ROOT_PATH);
56: $logocreated = publisher_createLogo(strtolower($clone));
57:
58: $msg = "";
59: if (is_dir(\XoopsBaseConfig::get('root-path') . '/modules/' . strtolower($clone))) {
60: $msg .= sprintf(_AM_PUBLISHER_CLONE_CONGRAT, "<a href='" . \XoopsBaseConfig::get('url') . "/modules/system/admin.php?fct=modulesadmin'>" . ucfirst(strtolower($clone)) . "</a>") . "<br />\n";
61: if (!$logocreated) {
62: $msg .= _AM_PUBLISHER_CLONE_IMAGEFAIL;
63: }
64: } else {
65: $msg .= _AM_PUBLISHER_CLONE_FAIL;
66: }
67: echo $msg;
68:
69: } else {
70: $form = new Xoops\Form\ThemeForm(sprintf(_AM_PUBLISHER_CLONE_TITLE, $publisher->getModule()->getVar('name', 'E')), 'clone', 'clone.php', 'post', true);
71: $clone = new Xoops\Form\Text(_AM_PUBLISHER_CLONE_NAME, 'clone', 20, 20, '');
72: $clone->setDescription(_AM_PUBLISHER_CLONE_NAME_DSC);
73: $form->addElement($clone, true);
74: $form->addElement(new Xoops\Form\Hidden('op', 'submit'));
75: $form->addElement(new Xoops\Form\Button('', '', XoopsLocale::A_SUBMIT, 'submit'));
76: $form->display();
77: }
78:
79:
80: PublisherUtils::closeCollapsableBar('clone', 'cloneicon');
81: $xoops->footer();
82:
83:
84: if (!function_exists('file_put_contents')) {
85: function file_put_contents($filename, $data, $file_append = false)
86: {
87: if ($fp = fopen($filename, (!$file_append ? 'w+' : 'a+'))) {
88: fputs($fp, $data);
89: fclose($fp);
90: }
91: }
92: }
93:
94:
95: function publisher_cloneFileFolder($path)
96: {
97: global $patKeys;
98: global $patValues;
99:
100: $newPath = str_replace($patKeys[0], $patValues[0], $path);
101:
102: if (is_dir($path)) {
103:
104: mkdir($newPath);
105:
106:
107: if ($handle = opendir($path)) {
108: while ($file = readdir($handle)) {
109: if ($file !== '.' && $file !== '..' && $file !== '.svn') {
110: publisher_cloneFileFolder("{$path}/{$file}");
111: }
112: }
113: closedir($handle);
114: }
115: } else {
116:
117: if (preg_match('/(.jpg|.gif|.png|.zip)$/i', $path)) {
118:
119: copy($path, $newPath);
120: } else {
121:
122: $content = file_get_contents($path);
123: $content = str_replace($patKeys, $patValues, $content);
124: file_put_contents($newPath, $content);
125: }
126: }
127: }
128:
129: function publisher_createLogo($dirname)
130: {
131: if (!extension_loaded("gd")) {
132: return false;
133: } else {
134: $required_functions = array("imagecreatetruecolor", "imagecolorallocate", "imagefilledrectangle", "imagejpeg", "imagedestroy", "imageftbbox");
135: foreach ($required_functions as $func) {
136: if (!function_exists($func)) {
137: return false;
138: }
139: }
140: }
141:
142: if (!XoopsLoad::fileExists($imageBase = \XoopsBaseConfig::get('root-path') . "/modules/" . $dirname . "/images/module_logo.png") || !XoopsLoad::fileExists($font = \XoopsBaseConfig::get('root-path') . "/modules/" . $dirname . "/images/VeraBd.ttf")) {
143: return false;
144: }
145:
146: $imageModule = imagecreatefrompng($imageBase);
147:
148:
149: $grey_color = imagecolorallocate($imageModule, 237, 237, 237);
150: imagefilledrectangle($imageModule, 5, 35, 85, 46, $grey_color);
151:
152:
153: $text_color = imagecolorallocate($imageModule, 0, 0, 0);
154: $space_to_border = (80 - strlen($dirname) * 6.5) / 2;
155: imagefttext($imageModule, 8.5, 0, $space_to_border, 45, $text_color, $font, ucfirst($dirname), array());
156:
157:
158: $white = imagecolorallocatealpha($imageModule, 255, 255, 255, 127);
159: imagefill($imageModule, 0, 0, $white);
160: imagecolortransparent($imageModule, $white);
161: imagepng($imageModule, \XoopsBaseConfig::get('root-path') . "/modules/" . $dirname . "/images/module_logo.png");
162: imagedestroy($imageModule);
163: return true;
164: }
165: