PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.1
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/ToggleController.php +0 -249 10.11.1 → 11.1.1 View file →
@@ -1,249 +1,0 @@
1 -<?php
2 -
3 -namespace AcyMailing\Controllers;
4 -
5 -use AcyMailing\Classes\ListClass;
6 -use AcyMailing\Classes\UserClass;
7 -use AcyMailing\Core\AcymController;
8 -
9 -class ToggleController extends AcymController
10 -{
11 - protected array $toggleableColumns = [];
12 - protected array $icons = [];
13 - protected array $tooltips = [];
14 - private array $deletableRows = [];
15 -
16 - public function __construct()
17 - {
18 - parent::__construct();
19 -
20 - $this->defaulttask = 'toggle';
21 -
22 - $this->defineToggles();
23 -
24 - acym_noCache();
25 - }
26 -
27 - protected function defineToggles(): void
28 - {
29 - $this->toggleableColumns['automation'] = ['active' => 'id'];
30 - $this->toggleableColumns['field'] = [
31 - 'active' => 'id',
32 - 'required' => 'id',
33 - 'backend_edition' => 'id',
34 - 'backend_listing' => 'id',
35 - 'frontend_edition' => 'id',
36 - 'frontend_listing' => 'id',
37 - ];
38 - $this->toggleableColumns['list'] = ['active' => 'id', 'visible' => 'id'];
39 - $this->toggleableColumns['rule'] = ['active' => 'id'];
40 - $this->toggleableColumns['user'] = ['active' => 'id', 'confirmed' => 'id'];
41 - $this->toggleableColumns['form'] = ['active' => 'id'];
42 - $this->toggleableColumns['segment'] = ['active' => 'id'];
43 - $this->toggleableColumns['campaign'] = ['visible' => 'id'];
44 - $this->toggleableColumns['followup'] = ['active' => 'id'];
45 - $this->toggleableColumns['mail_override'] = ['active' => 'id'];
46 - $this->toggleableColumns['mailbox_action'] = ['active' => 'id'];
47 - $this->toggleableColumns['scenario'] = ['active' => 'id'];
48 -
49 - $this->icons['automation']['active'][1] = 'acymicon-check-circle acym__color__green';
50 - $this->icons['automation']['active'][0] = 'acymicon-times-circle acym__color__red';
51 - $this->icons['field']['active'][1] = 'acymicon-check-circle acym__color__green';
52 - $this->icons['field']['active'][0] = 'acymicon-times-circle acym__color__red';
53 - $this->icons['field']['required'][1] = 'acymicon-check-circle acym__color__green';
54 - $this->icons['field']['required'][0] = 'acymicon-times-circle acym__color__red';
55 - $this->icons['field']['backend_edition'][1] = 'acymicon-check-circle acym__color__green';
56 - $this->icons['field']['backend_edition'][0] = 'acymicon-times-circle acym__color__red';
57 - $this->icons['field']['backend_listing'][1] = 'acymicon-check-circle acym__color__green';
58 - $this->icons['field']['backend_listing'][0] = 'acymicon-times-circle acym__color__red';
59 - $this->icons['field']['frontend_edition'][1] = 'acymicon-check-circle acym__color__green';
60 - $this->icons['field']['frontend_edition'][0] = 'acymicon-times-circle acym__color__red';
61 - $this->icons['field']['frontend_listing'][1] = 'acymicon-check-circle acym__color__green';
62 - $this->icons['field']['frontend_listing'][0] = 'acymicon-times-circle acym__color__red';
63 - $this->icons['list']['active'][1] = 'acymicon-check-circle acym__color__green';
64 - $this->icons['list']['active'][0] = 'acymicon-times-circle acym__color__red';
65 - $this->icons['list']['visible'][1] = 'acymicon-eye';
66 - $this->icons['list']['visible'][0] = 'acymicon-eye-slash acym__color__dark-gray';
67 - $this->icons['rule']['active'][0] = 'acymicon-times-circle acym__color__red';
68 - $this->icons['rule']['active'][1] = 'acymicon-check-circle acym__color__green';
69 - $this->icons['user']['active'][1] = 'acymicon-check-circle acym__color__green';
70 - $this->icons['user']['active'][0] = 'acymicon-times-circle acym__color__red';
71 - $this->icons['user']['confirmed'][1] = 'acymicon-check-circle acym__color__green';
72 - $this->icons['user']['confirmed'][0] = 'acymicon-times-circle acym__color__red';
73 - $this->icons['form']['active'][1] = 'acymicon-check-circle acym__color__green';
74 - $this->icons['form']['active'][0] = 'acymicon-times-circle acym__color__red';
75 - $this->icons['segment']['active'][1] = 'acymicon-check-circle acym__color__green';
76 - $this->icons['segment']['active'][0] = 'acymicon-times-circle acym__color__red';
77 - $this->icons['campaign']['visible'][1] = 'acymicon-eye';
78 - $this->icons['campaign']['visible'][0] = 'acymicon-eye-slash acym__color__dark-gray';
79 - $this->icons['followup']['active'][1] = 'acymicon-check-circle acym__color__green';
80 - $this->icons['followup']['active'][0] = 'acymicon-times-circle acym__color__red';
81 - $this->icons['mail_override']['active'][1] = 'acymicon-check-circle acym__color__green';
82 - $this->icons['mail_override']['active'][0] = 'acymicon-times-circle acym__color__red';
83 - $this->icons['mailbox_action']['active'][1] = 'acymicon-check-circle acym__color__green';
84 - $this->icons['mailbox_action']['active'][0] = 'acymicon-times-circle acym__color__red';
85 - $this->icons['scenario']['active'][1] = 'acymicon-check-circle acym__color__green';
86 - $this->icons['scenario']['active'][0] = 'acymicon-times-circle acym__color__red';
87 -
88 - $this->tooltips['user']['active'][1] = 'ACYM_ACTIVATED';
89 - $this->tooltips['user']['active'][0] = 'ACYM_DEACTIVATED';
90 - $this->tooltips['user']['confirmed'][1] = 'ACYM_CONFIRMED';
91 - $this->tooltips['user']['confirmed'][0] = 'ACYM_NOT_CONFIRMED';
92 - $this->tooltips['list']['active'][1] = 'ACYM_ACTIVATED';
93 - $this->tooltips['list']['active'][0] = 'ACYM_DEACTIVATED';
94 - $this->tooltips['list']['visible'][1] = 'ACYM_VISIBLE';
95 - $this->tooltips['list']['visible'][0] = 'ACYM_INVISIBLE';
96 - $this->tooltips['campaign']['visible'][0] = 'ACYM_INVISIBLE';
97 - $this->tooltips['campaign']['visible'][1] = 'ACYM_VISIBLE';
98 - $this->tooltips['mail_override']['active'][0] = 'ACYM_INACTIVE';
99 - $this->tooltips['mail_override']['active'][1] = 'ACYM_ACTIVE';
100 -
101 - $this->deletableRows[] = 'mail';
102 - $this->deletableRows[] = 'queue';
103 - }
104 -
105 - public function toggle(): void
106 - {
107 - acym_checkToken();
108 -
109 - $table = acym_getVar('word', 'table', '');
110 - $field = acym_getVar('cmd', 'field', '');
111 - $id = acym_getVar('int', 'id', 0);
112 - $newValue = acym_getVar('int', 'value', 0);
113 - if (!empty($newValue)) {
114 - $newValue = 1;
115 - }
116 -
117 - if (empty($table) || empty($field) || empty($id) || empty($this->toggleableColumns[$table][$field])) {
118 - exit;
119 - }
120 -
121 - $preciseMethod = $table.ucfirst($field);
122 - $globalMethod = $table.'Global';
123 - if (method_exists($this, $preciseMethod)) {
124 - $this->$preciseMethod($id, $table, $field, $newValue);
125 - } elseif (method_exists($this, $globalMethod)) {
126 - $this->$globalMethod($id, $table, $field, $newValue);
127 - } else {
128 - $this->doToggle($id, $table, $field, $newValue);
129 - }
130 -
131 - acym_trigger('onAcymToggle'.ucfirst($table).ucfirst($field), [&$id, &$newValue]);
132 -
133 - if (empty($this->icons[$table][$field][$newValue])) {
134 - acym_sendAjaxResponse(acym_translation('ACYM_UNAUTHORIZED_ACCESS'), [], false);
135 - }
136 -
137 - $data = [];
138 - $data['value'] = 1 - $newValue;
139 - $data['classes'] = 'acym_toggleable '.$this->icons[$table][$field][$newValue];
140 -
141 - if (!empty($this->tooltips[$table][$field][$newValue])) {
142 - $data['tooltip'] = ucfirst(acym_translation($this->tooltips[$table][$field][$newValue]));
143 - }
144 -
145 - acym_sendAjaxResponse('', $data);
146 - }
147 -
148 - protected function userActive(int $id, string $table, string $field, int $newValue): void
149 - {
150 - $userClass = new UserClass();
151 - if ($newValue === 0) {
152 - $userClass->deactivate([$id]);
153 - } else {
154 - $userClass->reactivate([$id]);
155 - }
156 - }
157 -
158 - protected function doToggle(int $id, string $table, string $field, int $newValue): void
159 - {
160 - $updateQuery = 'UPDATE '.acym_secureDBColumn(ACYM_DBPREFIX.$table);
161 - $updateQuery .= ' SET `'.acym_secureDBColumn($field).'` = '.$newValue;
162 - $updateQuery .= ' WHERE `'.acym_secureDBColumn($this->toggleableColumns[$table][$field]).'` = '.$id;
163 - $updateQuery .= ' LIMIT 1';
164 - acym_query($updateQuery);
165 - }
166 -
167 - public function delete(): void
168 - {
169 - if (!acym_isAdmin()) exit;
170 - acym_checkToken();
171 -
172 - $table = acym_getVar('word', 'table', '');
173 - $id = acym_getVar('int', 'id', 0);
174 -
175 - if (empty($table) || !in_array($table, $this->deletableRows) || empty($id)) {
176 - exit;
177 - }
178 -
179 - $method = $table === 'queue' ? 'deleteQueuedByUserIds' : 'delete';
180 -
181 - $namespaceClass = 'AcyMailing\\Classes\\'.ucfirst($table).'Class';
182 - $elementClass = new $namespaceClass();
183 - $elementClass->$method([$id]);
184 -
185 - exit;
186 - }
187 -
188 - public function setDoNotRemindMe(): void
189 - {
190 - $newValue = acym_getVar('string', 'value');
191 -
192 - if (empty($newValue)) {
193 - acym_sendAjaxResponse(acym_translation('ACYM_ERROR_SAVING'), [], false);
194 - }
195 -
196 - $remindMe = json_decode($this->config->get('remindme', '[]'));
197 - if (!in_array($newValue, $remindMe)) {
198 - $remindMe[] = $newValue;
199 - }
200 -
201 - if ($this->config->saveConfig(['remindme' => json_encode($remindMe)])) {
202 - acym_sendAjaxResponse(acym_translation('ACYM_THANKS'));
203 - } else {
204 - acym_sendAjaxResponse(acym_translation('ACYM_ERROR_SAVING'), [], false);
205 - }
206 - }
207 -
208 - public function subscribeOnClick(): void
209 - {
210 - $userIds = acym_getVar('array', 'userid', []);
211 - $listIds = acym_getVar('array', 'listid', []);
212 -
213 - $userClass = new UserClass();
214 - $userClass->onlyManageableUsers($userIds);
215 -
216 - $listClass = new ListClass();
217 - $listClass->onlyManageableLists($listIds);
218 -
219 - $userClass = new UserClass();
220 - $result = $userClass->subscribe($userIds, $listIds);
221 -
222 - if ($result) {
223 - acym_sendAjaxResponse();
224 - } else {
225 - acym_sendAjaxResponse('', [], false);
226 - }
227 - }
228 -
229 - public function unsubscribeOnClick(): void
230 - {
231 - $userIds = acym_getVar('array', 'userid', []);
232 - $listIds = acym_getVar('array', 'listid', []);
233 -
234 - $userClass = new UserClass();
235 - $userClass->onlyManageableUsers($userIds);
236 -
237 - $listClass = new ListClass();
238 - $listClass->onlyManageableLists($listIds);
239 -
240 - $userClass = new UserClass();
241 - $result = $userClass->unsubscribe($userIds, $listIds);
242 -
243 - if ($result) {
244 - acym_sendAjaxResponse();
245 - } else {
246 - acym_sendAjaxResponse('', [], false);
247 - }
248 - }
249 -}