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/Lists/Edition.php +83 -84 10.0.1 → 11.1.0 View file →
@@ -13,20 +13,20 @@
13 13 use AcyMailing\Helpers\WorkflowHelper;
14 14
15 15 trait Edition
16 16 {
17 - public function settings()
17 + public function settings(): void
18 18 {
19 19 acym_setVar('layout', 'settings');
20 20
21 21 $tab = acym_getVar('string', 'step', ListsController::LIST_EDITION_TABS_GENERAL);
22 22
23 + // In the front with the SEF activated, the tab is not always set
23 24 if (empty($tab)) {
24 25 $tab = ListsController::LIST_EDITION_TABS_GENERAL;
25 26 }
26 27
27 28 $data = [];
28 - $data['svg'] = acym_loaderLogo(false);
29 29 $data['workflowHelper'] = new WorkflowHelper();
30 30 $data['currentTab'] = $tab;
31 31 $data['tabs'] = [
32 32 'general' => ListsController::LIST_EDITION_TABS_GENERAL,
@@ -53,9 +53,9 @@
53 53
54 54 parent::display($data);
55 55 }
56 56
57 - private function prepareListSettings(&$data, $listId)
57 + private function prepareListSettings(array &$data, int $listId): bool
58 58 {
59 59 if (empty($listId)) {
60 60 $listInformation = new \stdClass();
61 61 $listInformation->id = '';
@@ -63,13 +63,16 @@
63 63 $listInformation->frontLabel = '';
64 64 $listInformation->description = '';
65 65 $listInformation->active = 1;
66 66 $listInformation->visible = 1;
67 - $randColor = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
68 - $listInformation->color = '#'.$randColor[rand(0, 15)].$randColor[rand(0, 15)].$randColor[rand(0, 15)].$randColor[rand(0, 15)].$randColor[rand(0, 15)].$randColor[rand(
69 - 0,
70 - 15
71 - )];
67 + $listInformation->color = '#'.implode('', [
68 + ListClass::COLOR_PARTS[acym_rand(0, 15)],
69 + ListClass::COLOR_PARTS[acym_rand(0, 15)],
70 + ListClass::COLOR_PARTS[acym_rand(0, 15)],
71 + ListClass::COLOR_PARTS[acym_rand(0, 15)],
72 + ListClass::COLOR_PARTS[acym_rand(0, 15)],
73 + ListClass::COLOR_PARTS[acym_rand(0, 15)],
74 + ]);
72 75 $listInformation->welcome_id = '';
73 76 $listInformation->unsubscribe_id = '';
74 77 $listInformation->access = [];
75 78 $listInformation->tracking = 1;
@@ -87,11 +90,11 @@
87 90 return false;
88 91 }
89 92
90 93
91 - $subscribersCount = $listClass->getSubscribersCountPerStatusByListId([$listId]);
94 + $subscribersCount = $listClass->getSubscribersCountPerStatusByListIds([$listId]);
92 95
93 - $this->breadcrumb[acym_escape($listInformation->name)] = acym_completeLink('lists&task=settings&listId='.$listId);
96 + $this->breadcrumb[$listInformation->name] = acym_completeLink('lists&task=settings&listId='.$listId);
94 97
95 98 $listInformation->access = empty($listInformation->access) ? [] : explode(',', $listInformation->access);
96 99
97 100 $currentUser = acym_currentUserId();
@@ -133,20 +136,20 @@
133 136
134 137 return true;
135 138 }
136 139
137 - private function prepareTagsSettings(&$data, $listId)
140 + private function prepareTagsSettings(array &$data, int $listId): void
138 141 {
139 142 $tagClass = new TagClass();
140 143 $data['allTags'] = $tagClass->getAllTagsByType(TagClass::TYPE_LIST);
141 144 $data['listTagsName'] = [];
142 - $listsTags = $tagClass->getAllTagsByElementId(TagClass::TYPE_LIST, intval($listId));
145 + $listsTags = $tagClass->getAllTagsByElementId(TagClass::TYPE_LIST, $listId);
143 146 foreach ($listsTags as $oneTag) {
144 147 $data['listTagsName'][] = $oneTag;
145 148 }
146 149 }
147 150
148 - private function prepareSubscribersSettings(&$data, $listId)
151 + private function prepareSubscribersSettings(array &$data, int $listId): void
149 152 {
150 153 $data['ordering'] = acym_getVar('string', 'users_ordering', 'id');
151 154 $data['orderingSortOrder'] = acym_getVar('string', 'users_ordering_sort_order', 'desc');
152 155 $data['classSortOrder'] = $data['orderingSortOrder'] == 'asc' ? 'acymicon-sort-amount-asc' : 'acymicon-sort-amount-desc';
@@ -166,9 +169,9 @@
166 169 $oneSub->subscription_date = acym_date(strtotime($oneSub->subscription_date), acym_translation('ACYM_DATE_FORMAT_LC2'));
167 170 }
168 171 }
169 172
170 - private function prepareSubscribersEntitySelect(&$data, $listId)
173 + private function prepareSubscribersEntitySelect(array &$data, int $listId): void
171 174 {
172 175 if (empty($listId)) {
173 176 $data['subscribersEntitySelect'] = '';
174 177
@@ -174,28 +177,12 @@
174 177
175 178 return;
176 179 }
177 180
178 - $entityHelper = new EntitySelectHelper();
179 -
180 - $data['subscribersEntitySelect'] = acym_modal(
181 - acym_translation('ACYM_MANAGE_SUBSCRIBERS'),
182 - $entityHelper->entitySelect(
183 - 'user',
184 - ['join' => 'join_list-'.$listId],
185 - $entityHelper->getColumnsForUser('userlist.user_id'),
186 - ['text' => acym_translation('ACYM_CONFIRM'), 'action' => 'saveSubscribers'],
187 - true,
188 - '',
189 - 'subscriber'
190 - ),
191 - 'acym__lists__settings__subscribers__entity__modal',
192 - '',
193 - 'class="cell medium-6 large-shrink button button-secondary"'
194 - );
181 + $data['subscribersEntitySelect'] = $listId;
195 182 }
196 183
197 - private function prepareListStat(&$data, $listId)
184 + private function prepareListStat(array &$data, int $listId): void
198 185 {
199 186 $data['listStats'] = ['deliveryRate' => 0, 'openRate' => 0, 'clickRate' => 0, 'failRate' => 0, 'bounceRate' => 0];
200 187 if (empty($listId)) return;
201 188 $listClass = new ListClass();
@@ -221,9 +208,9 @@
221 208 $nbClicks = $urlClickClass->getClickRateByMailIds($mails);
222 209 $data['listStats']['clickRate'] = number_format($nbClicks / $totalSent * 100, 2);
223 210 }
224 211
225 - private function prepareListStatEvolution(&$data, $listId)
212 + private function prepareListStatEvolution(array &$data, int $listId): void
226 213 {
227 214 $data['evol'] = [];
228 215 $listClass = new ListClass();
229 216 $subEvolStat = $listClass->getYearSubEvolutionPerList($listId);
@@ -228,13 +215,14 @@
228 215 $listClass = new ListClass();
229 216 $subEvolStat = $listClass->getYearSubEvolutionPerList($listId);
230 217 if (empty($subEvolStat['subscribers']) && empty($subEvolStat['unsubscribers'])) return;
231 218
232 - $firstMonth = date('n') + 1;
219 + // Init tables ordered by month number starting on month from one year ago
220 + $firstMonth = gmdate('n') + 1;
233 221 $zeroReached = false;
234 222 $evolSub = [];
235 223 $evolUnsub = [];
236 - for ($i = 0 ; $i < 12 ; $i++) {
224 + for ($i = 0; $i < 12; $i++) {
237 225 $month = ($firstMonth + $i) % 13;
238 226 if ($month == 0) $zeroReached = true;
239 227 if ($zeroReached) $month += 1;
240 228 $evolSub[$month] = $month.'_0';
@@ -254,9 +242,9 @@
254 242 $data['evol'][1][] = $evolUnsub[$month];
255 243 }
256 244 }
257 245
258 - protected function prepareWelcomeUnsubData(&$data)
246 + protected function prepareWelcomeUnsubData(array &$data): void
259 247 {
260 248 $data['tmpls'] = [];
261 249 if (empty($data['listInformation']->id)) return;
262 250 $listClass = new ListClass();
@@ -267,13 +255,16 @@
267 255 if (empty($data['listInformation']->{$full.'_id'}) && !empty($mailId)) {
268 256 $data['listInformation']->{$full.'_id'} = $mailId;
269 257 $listInfoSave = clone $data['listInformation'];
270 258 unset($listInfoSave->subscribers);
271 - if (!$listClass->save($listInfoSave)) acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVE_LIST'), 'error');
259 + $savedListId = $listClass->save($listInfoSave);
260 + if (empty($savedListId)) {
261 + acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVE_LIST'), 'error');
262 + }
272 263 }
273 264
274 265 $returnLink = acym_completeLink('lists&task=settings&listId='.$data['listInformation']->id.'&edition=1&'.$short.'mailid={mailid}');
275 - $favoriteTemplate = $this->config->get('favorite_template', 0);
266 + $favoriteTemplate = $mailClass->getFavoriteTemplateId();
276 267 $startFrom = empty($favoriteTemplate) ? '' : '&from='.$favoriteTemplate;
277 268
278 269 if (empty($data['listInformation']->{$full.'_id'})) {
279 270 $data['tmpls'][$short.'TmplUrl'] = acym_completeLink(
@@ -292,10 +283,12 @@
292 283 $data['tmpls'][$full] = !empty($data['listInformation']->{$full.'_id'}) ? $mailClass->getOneById($data['listInformation']->{$full.'_id'}) : '';
293 284 }
294 285 }
295 286
296 - public function unsetMail(string $type)
287 + public function unsetMail(string $type): void
297 288 {
289 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
290 +
298 291 $listClass = new ListClass();
299 292 $id = acym_getVar('int', 'listId', 0);
300 293 $list = $listClass->getOneById($id);
301 294
@@ -306,14 +299,15 @@
306 299 return;
307 300 }
308 301
309 302 if (!$listClass->hasUserAccess($id)) {
310 - die('Access denied for list '.acym_escape($id));
303 + die('Access denied for list '.esc_html($id));
311 304 }
312 305
313 306 $list->$type = null;
314 307
315 - if ($listClass->save($list)) {
308 + $savedListId = $listClass->save($list);
309 + if (!empty($savedListId)) {
316 310 acym_setVar('listId', $id);
317 311 $this->settings();
318 312 } else {
319 313 acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVE_LIST'), 'error');
@@ -320,64 +314,67 @@
320 314 $this->listing();
321 315 }
322 316 }
323 317
324 - public function unsetWelcome()
318 + public function unsetWelcome(): void
325 319 {
326 320 $this->unsetMail('welcome_id');
327 321 }
328 322
329 - public function unsetUnsubscribe()
323 + public function unsetUnsubscribe(): void
330 324 {
331 325 $this->unsetMail('unsubscribe_id');
332 326 }
333 327
334 - public function apply()
328 + public function apply(): void
335 329 {
336 330 $this->save(false);
337 331 }
338 332
339 - public function save($goToListing = true)
333 + public function save(bool $goToListing = true): void
340 334 {
341 - acym_checkToken();
335 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
342 336
343 - $listClass = new ListClass();
344 - $formData = (object)acym_getVar('array', 'list', []);
337 + $step = acym_getVar('string', 'step');
338 + if ($step === self::LIST_EDITION_TABS_GENERAL) {
339 + $listClass = new ListClass();
340 + $formData = (object)acym_getVar('array', 'list', []);
345 341
346 - $listId = acym_getVar('int', 'listId', 0);
347 - if (!empty($listId)) {
348 - $formData->id = $listId;
349 - }
342 + $listId = acym_getVar('int', 'listId', 0);
343 + if (!empty($listId)) {
344 + $formData->id = $listId;
345 + }
350 346
351 - $allowedFields = acym_getColumns('list');
352 - $listInformation = new \stdClass();
353 - if (empty($formData->welcome_id)) unset($formData->welcome_id);
354 - if (empty($formData->unsubscribe_id)) unset($formData->unsubscribe_id);
355 - foreach ($formData as $name => $data) {
356 - if (!in_array($name, $allowedFields)) {
357 - continue;
347 + $allowedFields = acym_getColumns('list');
348 + $listInformation = new \stdClass();
349 + if (empty($formData->welcome_id)) unset($formData->welcome_id);
350 + if (empty($formData->unsubscribe_id)) unset($formData->unsubscribe_id);
351 + foreach ($formData as $name => $data) {
352 + if (!in_array($name, $allowedFields)) {
353 + continue;
354 + }
355 + $listInformation->{$name} = $data;
358 356 }
359 - $listInformation->{$name} = $data;
360 - }
361 357
362 - $listInformation->tags = acym_getVar('array', 'list_tags', []);
358 + $listInformation->tags = acym_getVar('array', 'list_tags', []);
363 359
364 - if (acym_isAdmin()) {
365 - $listInformation->access = empty($listInformation->access) ? '' : ','.implode(',', $listInformation->access).',';
366 - } elseif (!empty($formData->id) && !$listClass->hasUserAccess($formData->id)) {
367 - die('Cannot save list '.acym_escape($formData->id));
368 - }
360 + if (acym_isAdmin()) {
361 + $listInformation->access = empty($listInformation->access) ? '' : ','.implode(',', $listInformation->access).',';
362 + } elseif (!empty($formData->id) && !$listClass->hasUserAccess($formData->id)) {
363 + die('Cannot save list '.esc_html($formData->id));
364 + }
369 365
370 - $listId = $listClass->save($listInformation);
366 + $listId = $listClass->save($listInformation);
371 367
372 - if (!empty($listId)) {
373 - acym_setVar('listId', $listId);
374 - acym_enqueueMessage(acym_translationSprintf('ACYM_LIST_IS_SAVED', $listInformation->name), 'success');
375 - $this->_saveSubscribersTolist();
376 - } else {
377 - acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING'), 'error');
378 - if (!empty($listClass->errors)) {
379 - acym_enqueueMessage($listClass->errors, 'error');
368 + if (!empty($listId)) {
369 + acym_setVar('listId', $listId);
370 + acym_enqueueMessage(acym_translationSprintf('ACYM_LIST_IS_SAVED', $listInformation->name), 'success');
371 + $this->saveSubscribersTolist();
372 + } else {
373 + acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING'), 'error');
374 + if (!empty($listClass->errors)) {
375 + acym_enqueueMessage($listClass->errors, 'error');
376 + }
380 377 }
381 378 }
382 379
383 380 if ($goToListing) {
@@ -386,12 +383,14 @@
386 383 $this->settings();
387 384 }
388 385 }
389 386
390 - private function _saveSubscribersTolist(): bool
387 + private function saveSubscribersTolist(): bool
391 388 {
392 - $usersIds = json_decode(acym_getVar('string', 'acym__entity_select__selected', '[]'));
393 - $usersIdsUnselected = json_decode(acym_getVar('string', 'acym__entity_select__unselected', '[]'));
389 + $selected = acym_getVar('string', 'acym__entity_select__selected', '[]');
390 + $unselected = acym_getVar('string', 'acym__entity_select__unselected', '[]');
391 + $usersIds = json_decode(empty($selected) ? '[]' : $selected, true);
392 + $usersIdsUnselected = json_decode(empty($unselected) ? '[]' : $unselected, true);
394 393 $listId = acym_getVar('int', 'listId', 0);
395 394
396 395 $listClass = new ListClass();
397 396 if (empty($listId) || !$listClass->hasUserAccess($listId)) return false;
@@ -417,13 +416,13 @@
417 416
418 417 return true;
419 418 }
420 419
421 - public function saveSubscribers()
420 + public function saveSubscribers(): void
422 421 {
423 - acym_checkToken();
422 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
424 423
425 - $this->_saveSubscribersTolist();
424 + $this->saveSubscribersTolist();
426 425 $listId = acym_getVar('int', 'listId', 0);
427 426 acym_setVar('listId', $listId);
428 427
429 428 $this->settings();
@@ -428,9 +427,9 @@
428 427
429 428 $this->settings();
430 429 }
431 430
432 - private function sortDataByList($data)
431 + private function sortDataByList(array $data): array
433 432 {
434 433 $sortedData = [];
435 434
436 435 foreach ($data as $entry) {
@@ -448,9 +447,9 @@
448 447
449 448 return $sortedData;
450 449 }
451 450
452 - private function prepareUnsubReasons(&$data)
451 + private function prepareUnsubReasons(array &$data): void
453 452 {
454 453 $historyClass = new HistoryClass();
455 454 $allReasonsData = $historyClass->getAllUnsubReasons();
456 455