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
acymailing / back / Controllers / ZonesController.php

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

93 lines 3.0 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\Core\AcymController;
6 use AcyMailing\Classes\ZoneClass;
7
8 class ZonesController extends AcymController
9 {
10 private const ZONE_IMAGE_FOLDER = ACYM_UPLOAD_FOLDER.'zones'.DS;
11
12 public function save(): void
13 {
14 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
15
16 $zone = new \stdClass();
17 $zone->name = acym_getVar('string', 'name');
18 $zone->content = acym_getVar('string', 'content', '', 'default', ACYM_ALLOWRAW);
19
20 if (empty($zone->name) || empty($zone->content)) {
21 acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_SAVE'), [], false);
22 }
23
24 $zoneClass = new ZoneClass();
25 $existingZone = $zoneClass->getOneByName($zone->name);
26
27 if (!empty($existingZone)) {
28 acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_SAVE_EXISTING'), [], false);
29 }
30
31 $zone->id = $zoneClass->save($zone);
32
33 $dataResponse = ['id' => $zone->id];
34
35 $image = acym_getVar('array', 'image', [], 'FILES');
36 if (!empty($image['name'])) {
37 $extension = pathinfo($image['name']);
38 $newPath = self::ZONE_IMAGE_FOLDER.$zone->id.'.'.$extension['extension'];
39
40 if (in_array($extension['extension'], acym_getImageFileExtensions(true)) && acym_uploadFile($image['tmp_name'], ACYM_ROOT.$newPath)) {
41 if (strtolower($extension['extension']) === 'svg' && !acym_isSvgFileSafe(ACYM_ROOT.$newPath)) {
42 acym_deleteFile(ACYM_ROOT.$newPath);
43 acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_SAVE'), [], false);
44 }
45
46 $zone->image = $newPath;
47 $savedZoneId = $zoneClass->save($zone);
48 if (!empty($savedZoneId)) {
49 $dataResponse['image'] = acym_rootURI().$newPath;
50 }
51 }
52 }
53
54 acym_sendAjaxResponse('', $dataResponse);
55 }
56
57 private function getZoneData(): array
58 {
59 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
60 $zoneId = acym_getVar('int', 'zoneId', 0);
61 if (empty($zoneId)) {
62 acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_FIND'), [], false);
63 }
64
65 $zoneClass = new ZoneClass();
66 $zone = $zoneClass->getOneById($zoneId);
67 if (empty($zone)) {
68 acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_FIND'), [], false);
69 }
70
71 return [
72 'zoneClass' => $zoneClass,
73 'zoneId' => $zoneId,
74 'zone' => $zone,
75 ];
76 }
77
78 public function getForInsertion(): void
79 {
80 $zoneData = $this->getZoneData();
81
82 acym_sendAjaxResponse('', ['content' => $zoneData['zone']->content]);
83 }
84
85 public function delete(): void
86 {
87 $zoneData = $this->getZoneData();
88 $zoneData['zoneClass']->delete([$zoneData['zoneId']]);
89
90 acym_sendAjaxResponse();
91 }
92 }
93