PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.2.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.2.2
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Controllers / LanguageController.php

LanguageController.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.2.2, at back/Controllers/LanguageController.php

212 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Controllers;
4
5 use AcyMailing\Helpers\MailerHelper;
6 use AcyMailing\Helpers\UpdateHelper;
7 use AcyMailing\Helpers\UpdatemeHelper;
8 use AcyMailing\Core\AcymController;
9
10 class LanguageController extends AcymController
11 {
12 public function saveLanguage(bool $fromShare = false): bool
13 {
14 acym_checkToken();
15
16 $code = acym_getVar('cmd', 'code');
17 acym_setVar('code', $code);
18
19 $content = acym_getVar('string', 'content', '', '', ACYM_ALLOWRAW);
20 $content = str_replace('</textarea>', '', $content);
21
22 if (empty($code) || empty($content)) {
23 $this->displayLanguage();
24
25 return true;
26 }
27
28 $customcontent = acym_getVar('string', 'customcontent', '', '', ACYM_ALLOWRAW);
29 $customcontent = str_replace('</textarea>', '', $customcontent);
30
31 $path = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.com_acym.ini';
32 $result = acym_writeFile($path, $content);
33 if ($result) {
34 acym_enqueueMessage(acym_translation('ACYM_SUCCESSFULLY_SAVED'), 'success');
35 $js = 'let langIcon = window.top.document.getElementById("image'.$code.'"); langIcon.className = langIcon.className.replace("acymicon-add", "") + " acymicon-edit"';
36 acym_addScript(true, $js);
37
38 $updateHelper = new UpdateHelper();
39 $updateHelper->installBackLanguages($code);
40 } else {
41 acym_enqueueMessage(acym_translationSprintf('ACYM_FAIL_SAVE_FILE', $path), 'error');
42 }
43
44 $custompath = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.com_acym_custom.ini';
45 $customresult = acym_writeFile($custompath, $customcontent);
46 if (!$customresult) {
47 acym_enqueueMessage(acym_translationSprintf('ACYM_FAIL_SAVE_FILE', $custompath), 'error');
48 }
49
50 if ($code == acym_getLanguageTag()) {
51 acym_loadLanguage();
52 }
53
54 $updateHelper = new UpdateHelper();
55 $updateHelper->installBackLanguages();
56
57 if ($fromShare) {
58 return $result;
59 } else {
60 $this->displayLanguage();
61
62 return true;
63 }
64 }
65
66 public function share(): void
67 {
68 acym_checkToken();
69
70 if ($this->saveLanguage(true)) {
71 acym_setVar('layout', 'share');
72
73 $file = new \stdClass();
74 $file->name = acym_getVar('cmd', 'code');
75
76 parent::display(['file' => $file]);
77 } else {
78 $this->displayLanguage();
79 }
80 }
81
82 public function send(): void
83 {
84 acym_checkToken();
85
86 $bodyEmail = acym_getVar('string', 'mailbody');
87 $code = acym_getVar('cmd', 'code');
88 acym_setVar('code', $code);
89
90 if (empty($code)) {
91 return;
92 }
93
94 $mailerHelper = new MailerHelper();
95 $mailerHelper->Subject = '[ACYMAILING LANGUAGE FILE] '.$code;
96 $mailerHelper->Body = 'The website '.ACYM_LIVE.' using AcyMailing '.$this->config->get('level').' '.$this->config->get('version').' sent a language file : '.$code;
97 $mailerHelper->Body .= "\n\n\n".$bodyEmail;
98
99 $file = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.com_acym.ini';
100 if (!file_exists($file)) {
101 return;
102 }
103
104 $translation = acym_fileGetContent($file);
105
106 $customFile = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.com_acym_custom.ini';
107
108 if (file_exists($customFile)) {
109 $customTranslation = acym_fileGetContent($customFile);
110
111 if (!empty($customTranslation)) {
112 $newKeys = [];
113 $customKeys = [];
114 preg_match_all('#([0-9A-Z_]+)="((?:[^"]|"_QQ_")+)"#is', $customTranslation, $customKeys);
115
116 if (!empty($customKeys)) {
117 $mainKeys = [];
118 preg_match_all('#([0-9A-Z_]+)="((?:[^"]|"_QQ_")+)"#is', $translation, $mainKeys);
119
120 foreach ($customKeys[1] as $index => $oneKey) {
121 $position = array_search($oneKey, $mainKeys[1]);
122 if ($position !== false) {
123 $translation = str_replace($mainKeys[0][$position], $customKeys[0][$index], $translation);
124 } else {
125 $newKeys[] = $customKeys[0][$index];
126 }
127 }
128
129 if (!empty($newKeys)) {
130 $mailerHelper->Body .= "\n\n\nCustom content:\n".implode("\n", $newKeys);
131 }
132 }
133 }
134 }
135
136 $mailerHelper->addStringAttachment($translation, $code.'.com_acym.ini');
137
138 $mailerHelper->AddAddress(acym_currentUserEmail(), acym_currentUserName());
139 $mailerHelper->AddAddress('[email protected]', 'Acyba Translation Team');
140 $mailerHelper->report = false;
141
142 $result = $mailerHelper->send();
143
144 if ($result) {
145 acym_enqueueMessage(acym_translation('ACYM_THANK_YOU_SHARING').'<br>'.acym_translation('ACYM_MESSAGE_SENT'), 'success');
146 } else {
147 acym_enqueueMessage($mailerHelper->reportMessage, 'error');
148 }
149
150 $this->displayLanguage();
151 }
152
153 public function displayLanguage(): void
154 {
155 acym_setVar('layout', 'default');
156
157 $code = acym_getVar('string', 'code');
158 if (empty($code)) {
159 acym_display(acym_translation('ACYM_LANGUAGE_CODE_NOT_FOUND'), 'error');
160
161 return;
162 }
163
164 $file = new \stdClass();
165 $file->name = $code;
166 $path = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.com_acym.ini';
167 $file->path = $path;
168 $file->customcontent = '';
169
170 if (file_exists($path)) {
171 $file->content = acym_fileGetContent($path);
172 if (empty($file->content)) {
173 acym_display(acym_translationSprintf('ACYM_FILE_NOT_FOUND', $path), 'error');
174 }
175 } else {
176 if (ACYM_CMS === 'joomla') {
177 $message = acym_translation('ACYM_LOAD_ENGLISH_1');
178 $message .= '<br />'.acym_translation('ACYM_LOAD_ENGLISH_2');
179 $message .= '<br />'.acym_translation('ACYM_LOAD_ENGLISH_3');
180 acym_enqueueMessage($message, 'info');
181 }
182 $file->content = acym_fileGetContent(acym_getLanguagePath(ACYM_ROOT, ACYM_DEFAULT_LANGUAGE).DS.ACYM_DEFAULT_LANGUAGE.'.com_acym.ini');
183 }
184
185 $customPath = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.com_acym_custom.ini';
186 if (file_exists($customPath)) {
187 $file->customcontent = acym_fileGetContent($customPath);
188 }
189
190 if (!file_exists(acym_getLanguagePath(ACYM_ROOT, $code))) {
191 acym_enqueueMessage(acym_translationSprintf('ACYM_LANGUAGE_NOT_INSTALLED', $code), 'warning');
192 }
193
194 $data = [
195 'file' => $file,
196 ];
197
198 parent::display($data);
199 }
200
201 public function getLatestTranslationAjax(): void
202 {
203 $languagesContent = UpdatemeHelper::call('public/download/translations?version=latest&codes='.acym_getVar('cmd', 'code'));
204
205 if (empty($languagesContent['translations'])) {
206 acym_sendAjaxResponse(acym_translation('ACYM_ERROR_LOAD_LATEST_TRANSLATION'), [], false);
207 }
208
209 acym_sendAjaxResponse('', ['translations' => array_pop($languagesContent['translations'])]);
210 }
211 }
212