PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
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
← All changes | back/Controllers/LanguageController.php +41 -23 10.0.1 → 11.1.0 View file →
@@ -8,32 +8,39 @@
8 8 use AcyMailing\Core\AcymController;
9 9
10 10 class LanguageController extends AcymController
11 11 {
12 - public function saveLanguage($fromShare = false)
12 + public function saveLanguage(bool $fromShare = false): bool
13 13 {
14 - acym_checkToken();
14 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
15 15
16 16 $code = acym_getVar('cmd', 'code');
17 17 acym_setVar('code', $code);
18 18
19 + // Get content that can be modified when loading the latest version from our site
19 20 $content = acym_getVar('string', 'content', '', '', ACYM_ALLOWRAW);
20 21 $content = str_replace('</textarea>', '', $content);
21 22
22 23 if (empty($code) || empty($content)) {
23 - return $this->displayLanguage();
24 + $this->displayLanguage();
25 +
26 + return true;
24 27 }
25 28
29 + // Get the custom translations
26 30 $customcontent = acym_getVar('string', 'customcontent', '', '', ACYM_ALLOWRAW);
27 31 $customcontent = str_replace('</textarea>', '', $customcontent);
28 32
33 + // We have a code, we have a content... so we can simply save the file!
29 34 $path = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.com_acym.ini';
30 35 $result = acym_writeFile($path, $content);
31 36 if ($result) {
32 37 acym_enqueueMessage(acym_translation('ACYM_SUCCESSFULLY_SAVED'), 'success');
38 + //We update the picture from "add" to "edit"
33 39 $js = 'let langIcon = window.top.document.getElementById("image'.$code.'"); langIcon.className = langIcon.className.replace("acymicon-add", "") + " acymicon-edit"';
34 40 acym_addScript(true, $js);
35 41
42 + //Now we will also create a menu language file and save it
36 43 $updateHelper = new UpdateHelper();
37 44 $updateHelper->installBackLanguages($code);
38 45 } else {
39 46 acym_enqueueMessage(acym_translationSprintf('ACYM_FAIL_SAVE_FILE', $path), 'error');
@@ -38,8 +45,9 @@
38 45 } else {
39 46 acym_enqueueMessage(acym_translationSprintf('ACYM_FAIL_SAVE_FILE', $path), 'error');
40 47 }
41 48
49 + // Let's save the custom language file now...
42 50 $custompath = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.com_acym_custom.ini';
43 51 $customresult = acym_writeFile($custompath, $customcontent);
44 52 if (!$customresult) {
45 53 acym_enqueueMessage(acym_translationSprintf('ACYM_FAIL_SAVE_FILE', $custompath), 'error');
@@ -48,8 +56,9 @@
48 56 if ($code == acym_getLanguageTag()) {
49 57 acym_loadLanguage();
50 58 }
51 59
60 + //We add lang to menu
52 61 $updateHelper = new UpdateHelper();
53 62 $updateHelper->installBackLanguages();
54 63
55 64 if ($fromShare) {
@@ -54,15 +63,17 @@
54 63
55 64 if ($fromShare) {
56 65 return $result;
57 66 } else {
58 - return $this->displayLanguage();
67 + $this->displayLanguage();
68 +
69 + return true;
59 70 }
60 71 }
61 72
62 - public function share()
73 + public function share(): void
63 74 {
64 - acym_checkToken();
75 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
65 76
66 77 if ($this->saveLanguage(true)) {
67 78 acym_setVar('layout', 'share');
68 79
@@ -68,17 +79,17 @@
68 79
69 80 $file = new \stdClass();
70 81 $file->name = acym_getVar('cmd', 'code');
71 82
72 - return parent::display(['file' => $file]);
83 + parent::display(['file' => $file]);
73 84 } else {
74 - return $this->displayLanguage();
85 + $this->displayLanguage();
75 86 }
76 87 }
77 88
78 - public function send()
89 + public function send(): void
79 90 {
80 - acym_checkToken();
91 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
81 92
82 93 $bodyEmail = acym_getVar('string', 'mailbody');
83 94 $code = acym_getVar('cmd', 'code');
84 95 acym_setVar('code', $code);
@@ -86,13 +97,14 @@
86 97 if (empty($code)) {
87 98 return;
88 99 }
89 100
90 - $mailer = new MailerHelper();
91 - $mailer->Subject = '[ACYMAILING LANGUAGE FILE] '.$code;
92 - $mailer->Body = 'The website '.ACYM_LIVE.' using AcyMailing '.$this->config->get('level').' '.$this->config->get('version').' sent a language file : '.$code;
93 - $mailer->Body .= "\n\n\n".$bodyEmail;
101 + $mailerHelper = new MailerHelper();
102 + $mailerHelper->Subject = '[ACYMAILING LANGUAGE FILE] '.$code;
103 + $mailerHelper->Body = 'The website '.ACYM_LIVE.' using AcyMailing '.$this->config->get('level').' '.$this->config->get('version').' sent a language file : '.$code;
104 + $mailerHelper->Body .= "\n\n\n".$bodyEmail;
94 105
106 + //Include the extra language file....
95 107 $file = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.com_acym.ini';
96 108 if (!file_exists($file)) {
97 109 return;
98 110 }
@@ -98,8 +110,9 @@
98 110 }
99 111
100 112 $translation = acym_fileGetContent($file);
101 113
114 + // Include the custom translations
102 115 $customFile = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.com_acym_custom.ini';
103 116
104 117 if (file_exists($customFile)) {
105 118 $customTranslation = acym_fileGetContent($customFile);
@@ -104,8 +117,9 @@
104 117 if (file_exists($customFile)) {
105 118 $customTranslation = acym_fileGetContent($customFile);
106 119
107 120 if (!empty($customTranslation)) {
121 + // Replace translations in the main lang file by the custom ones if they exist
108 122 $newKeys = [];
109 123 $customKeys = [];
110 124 preg_match_all('#([0-9A-Z_]+)="((?:[^"]|"_QQ_")+)"#is', $customTranslation, $customKeys);
111 125
@@ -115,39 +129,42 @@
115 129
116 130 foreach ($customKeys[1] as $index => $oneKey) {
117 131 $position = array_search($oneKey, $mainKeys[1]);
118 132 if ($position !== false) {
133 + // Replace the translation in the main file
119 134 $translation = str_replace($mainKeys[0][$position], $customKeys[0][$index], $translation);
120 135 } else {
136 + // Add the additional translation to the email body, it may be useful somehow
121 137 $newKeys[] = $customKeys[0][$index];
122 138 }
123 139 }
124 140
125 141 if (!empty($newKeys)) {
126 - $mailer->Body .= "\n\n\nCustom content:\n".implode("\n", $newKeys);
142 + $mailerHelper->Body .= "\n\n\nCustom content:\n".implode("\n", $newKeys);
127 143 }
128 144 }
129 145 }
130 146 }
131 147
132 - $mailer->addStringAttachment($translation, $code.'.com_acym.ini');
148 + // Attach the file
149 + $mailerHelper->addStringAttachment($translation, $code.'.com_acym.ini');
133 150
134 - $mailer->AddAddress(acym_currentUserEmail(), acym_currentUserName());
135 - $mailer->AddAddress('[email protected]', 'Acyba Translation Team');
136 - $mailer->report = false;
151 + $mailerHelper->AddAddress(acym_currentUserEmail(), acym_currentUserName());
152 + $mailerHelper->AddAddress('[email protected]', 'Acyba Translation Team');
153 + $mailerHelper->report = false;
137 154
138 - $result = $mailer->send();
155 + $result = $mailerHelper->send();
139 156
140 157 if ($result) {
141 158 acym_enqueueMessage(acym_translation('ACYM_THANK_YOU_SHARING').'<br>'.acym_translation('ACYM_MESSAGE_SENT'), 'success');
142 159 } else {
143 - acym_enqueueMessage($mailer->reportMessage, 'error');
160 + acym_enqueueMessage($mailerHelper->reportMessage, 'error');
144 161 }
145 162
146 163 $this->displayLanguage();
147 164 }
148 165
149 - public function displayLanguage()
166 + public function displayLanguage(): void
150 167 {
151 168 acym_setVar('layout', 'default');
152 169
153 170 $code = acym_getVar('string', 'code');
@@ -168,8 +185,9 @@
168 185 if (empty($file->content)) {
169 186 acym_display(acym_translationSprintf('ACYM_FILE_NOT_FOUND', $path), 'error');
170 187 }
171 188 } else {
189 + // Load the default language
172 190 if (ACYM_CMS === 'joomla') {
173 191 $message = acym_translation('ACYM_LOAD_ENGLISH_1');
174 192 $message .= '<br />'.acym_translation('ACYM_LOAD_ENGLISH_2');
175 193 $message .= '<br />'.acym_translation('ACYM_LOAD_ENGLISH_3');
@@ -193,9 +211,9 @@
193 211
194 212 parent::display($data);
195 213 }
196 214
197 - public function getLatestTranslationAjax()
215 + public function getLatestTranslationAjax(): void
198 216 {
199 217 $languagesContent = UpdatemeHelper::call('public/download/translations?version=latest&codes='.acym_getVar('cmd', 'code'));
200 218
201 219 if (empty($languagesContent['translations'])) {