PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.10.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.10.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 / ZonesController.php

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

87 lines 2.6 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 acym_checkToken();
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 if (!empty($_FILES['image']['name'])) {
36 $extension = pathinfo($_FILES['image']['name']);
37 $newPath = self::ZONE_IMAGE_FOLDER.$zone->id.'.'.$extension['extension'];
38
39 if (in_array($extension['extension'], acym_getImageFileExtensions()) && acym_uploadFile($_FILES['image']['tmp_name'], ACYM_ROOT.$newPath)) {
40 $zone->image = $newPath;
41 $savedZoneId = $zoneClass->save($zone);
42 if (!empty($savedZoneId)) {
43 $dataResponse['image'] = acym_rootURI().$newPath;
44 }
45 }
46 }
47
48 acym_sendAjaxResponse('', $dataResponse);
49 }
50
51 private function getZoneData(): array
52 {
53 acym_checkToken();
54 $zoneId = acym_getVar('int', 'zoneId', 0);
55 if (empty($zoneId)) {
56 acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_FIND'), [], false);
57 }
58
59 $zoneClass = new ZoneClass();
60 $zone = $zoneClass->getOneById($zoneId);
61 if (empty($zone)) {
62 acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_FIND'), [], false);
63 }
64
65 return [
66 'zoneClass' => $zoneClass,
67 'zoneId' => $zoneId,
68 'zone' => $zone,
69 ];
70 }
71
72 public function getForInsertion(): void
73 {
74 $zoneData = $this->getZoneData();
75
76 acym_sendAjaxResponse('', ['content' => $zoneData['zone']->content]);
77 }
78
79 public function delete(): void
80 {
81 $zoneData = $this->getZoneData();
82 $zoneData['zoneClass']->delete([$zoneData['zoneId']]);
83
84 acym_sendAjaxResponse();
85 }
86 }
87