# acymailing/11.0.4/back/Controllers/ZonesController.php

AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress, version 11.0.4. 93 lines.

- Page: https://pluginprobe.com/plugins/acymailing/11.0.4/code/back/Controllers/ZonesController.php
- Raw: https://pluginprobe.com/plugins/acymailing/11.0.4/raw/back/Controllers/ZonesController.php
- Modified: 2026-08-03T10:18:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/acymailing/11.0.4/code/back/Controllers/ZonesController.php#L10-L20`.

```php
<?php

namespace AcyMailing\Controllers;

use AcyMailing\Core\AcymController;
use AcyMailing\Classes\ZoneClass;

class ZonesController extends AcymController
{
    private const ZONE_IMAGE_FOLDER = ACYM_UPLOAD_FOLDER.'zones'.DS;

    public function save(): void
    {
        wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');

        $zone = new \stdClass();
        $zone->name = acym_getVar('string', 'name');
        $zone->content = acym_getVar('string', 'content', '', 'default', ACYM_ALLOWRAW);

        if (empty($zone->name) || empty($zone->content)) {
            acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_SAVE'), [], false);
        }

        $zoneClass = new ZoneClass();
        $existingZone = $zoneClass->getOneByName($zone->name);

        if (!empty($existingZone)) {
            acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_SAVE_EXISTING'), [], false);
        }

        $zone->id = $zoneClass->save($zone);

        $dataResponse = ['id' => $zone->id];

        $image = acym_getVar('array', 'image', [], 'FILES');
        if (!empty($image['name'])) {
            $extension = pathinfo($image['name']);
            $newPath = self::ZONE_IMAGE_FOLDER.$zone->id.'.'.$extension['extension'];

            if (in_array($extension['extension'], acym_getImageFileExtensions(true)) && acym_uploadFile($image['tmp_name'], ACYM_ROOT.$newPath)) {
                if (strtolower($extension['extension']) === 'svg' && !acym_isSvgFileSafe(ACYM_ROOT.$newPath)) {
                    acym_deleteFile(ACYM_ROOT.$newPath);
                    acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_SAVE'), [], false);
                }

                $zone->image = $newPath;
                $savedZoneId = $zoneClass->save($zone);
                if (!empty($savedZoneId)) {
                    $dataResponse['image'] = acym_rootURI().$newPath;
                }
            }
        }

        acym_sendAjaxResponse('', $dataResponse);
    }

    private function getZoneData(): array
    {
        wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
        $zoneId = acym_getVar('int', 'zoneId', 0);
        if (empty($zoneId)) {
            acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_FIND'), [], false);
        }

        $zoneClass = new ZoneClass();
        $zone = $zoneClass->getOneById($zoneId);
        if (empty($zone)) {
            acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_FIND'), [], false);
        }

        return [
            'zoneClass' => $zoneClass,
            'zoneId' => $zoneId,
            'zone' => $zone,
        ];
    }

    public function getForInsertion(): void
    {
        $zoneData = $this->getZoneData();

        acym_sendAjaxResponse('', ['content' => $zoneData['zone']->content]);
    }

    public function delete(): void
    {
        $zoneData = $this->getZoneData();
        $zoneData['zoneClass']->delete([$zoneData['zoneId']]);

        acym_sendAjaxResponse();
    }
}

```
