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/Queue/Campaigns.php +169 -0 11.1.1 → 11.1.0 View file →
@@ -1,0 +1,169 @@
1 +<?php
2 +
3 +namespace AcyMailing\Controllers\Queue;
4 +
5 +use AcyMailing\Classes\CampaignClass;
6 +use AcyMailing\Classes\QueueClass;
7 +use AcyMailing\Classes\TagClass;
8 +use AcyMailing\Helpers\PaginationHelper;
9 +use AcyMailing\Helpers\ToolbarHelper;
10 +use AcyMailing\Helpers\WorkflowHelper;
11 +
12 +trait Campaigns
13 +{
14 + public function campaigns(): void
15 + {
16 + acym_setVar('layout', 'campaigns');
17 +
18 + if (ACYM_PRODUCTION) {
19 + if (acym_level(ACYM_ESSENTIAL) && $this->config->get('cron_last', 0) < (time() - 43200)) {
20 + $message = acym_translation('ACYM_CREATE_CRON_REMINDER');
21 + $message .= ' <a id="acym__queue__configure-cron" href="'.acym_completeLink('configuration&tab=license').'">'.acym_translation('ACYM_GOTO_CONFIG').'</a>';
22 +
23 + $notification = [
24 + 'name' => 'cron_reminder',
25 + 'removable' => 1,
26 + ];
27 + acym_enqueueMessage($message, 'warning', true, [$notification]);
28 + }
29 + }
30 +
31 + // Get filters data
32 + $searchFilter = $this->getVarFiltersListing('string', 'cqueue_search', '');
33 + $tagFilter = $this->getVarFiltersListing('string', 'cqueue_tag', '');
34 + $status = $this->getVarFiltersListing('string', 'cqueue_status', '');
35 +
36 + // Get pagination data
37 + $pagination = new PaginationHelper();
38 + $campaignsPerPage = $pagination->getListLimit();
39 + $page = $this->getVarFiltersListing('int', 'cqueue_pagination_page', 1);
40 +
41 + $queueClass = new QueueClass();
42 + $matchingElements = $queueClass->getMatchingCampaigns(
43 + [
44 + 'search' => $searchFilter,
45 + 'tag' => $tagFilter,
46 + 'status' => $status,
47 + 'campaignsPerPage' => $campaignsPerPage,
48 + 'offset' => ($page - 1) * $campaignsPerPage,
49 + ]
50 + );
51 +
52 + // Prepare the pagination
53 + $pagination->setStatus((int)$matchingElements['total']->total, $page, $campaignsPerPage);
54 + $tagClass = new TagClass();
55 +
56 + $viewData = [
57 + 'allElements' => $matchingElements['elements'],
58 + 'pagination' => $pagination,
59 + 'search' => $searchFilter,
60 + 'tag' => $tagFilter,
61 + 'allTags' => $tagClass->getAllTagsByType(TagClass::TYPE_MAIL),
62 + 'numberPerStatus' => $matchingElements['status'],
63 + 'status' => $status,
64 + 'campaignClass' => new CampaignClass(),
65 + 'languages' => acym_getLanguages(),
66 + 'workflowHelper' => new WorkflowHelper(),
67 + ];
68 +
69 + $this->prepareToolbar($viewData);
70 +
71 + $this->breadcrumb[acym_translation('ACYM_MAILS')] = acym_completeLink('queue');
72 + parent::display($viewData);
73 + }
74 +
75 + public function prepareToolbar(array &$data): void
76 + {
77 + $toolbarHelper = new ToolbarHelper();
78 + $toolbarHelper->addSearchBar($data['search'], 'cqueue_search', 'ACYM_SEARCH');
79 + $toolbarHelper->addButton(
80 + acym_translation('ACYM_EMPTY_QUEUE'),
81 + [
82 + 'data-task' => 'emptyQueue',
83 + 'data-confirmation-message' => 'ACYM_ARE_YOU_SURE',
84 + ],
85 + 'close'
86 + );
87 + $toolbarHelper->addModalButton(
88 + [
89 + 'button' => '<i class="acymicon-paper-plane"></i>'.esc_html(acym_translation('ACYM_SEND_MAILS_MANUALLY')),
90 + 'attributesModal' => [
91 + 'data-reveal-larger' => true,
92 + ],
93 + 'attributesButton' => [
94 + 'class' => 'cell medium-6 large-shrink button',
95 + 'data-reload' => 'true',
96 + 'data-ajax' => 'true',
97 + 'data-iframe' => '&ctrl=queue&task=continuesend&id=0&totalsend=0',
98 + ],
99 + ]
100 + );
101 + $toolbarHelper->addFilterByTag($data, 'cqueue_tag', 'acym__queue__filter__tags acym__select');
102 +
103 + $data['toolbar'] = $toolbarHelper;
104 + if (!empty($data['tag'])) {
105 + $data['status_toolbar'] = [
106 + 'cqueue_tag' => $data['tag'],
107 + ];
108 + }
109 + }
110 +
111 + public function cancelSending(): void
112 + {
113 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
114 +
115 + $mailId = acym_getVar('int', 'acym__queue__cancel__mail_id');
116 +
117 + if (!empty($mailId)) {
118 + $hasStat = acym_loadResult('SELECT COUNT(*) FROM #__acym_user_stat WHERE mail_id = '.intval($mailId));
119 +
120 + acym_query('DELETE FROM #__acym_queue WHERE mail_id = '.intval($mailId));
121 + acym_query('UPDATE #__acym_mail_stat SET total_subscribers = sent WHERE mail_id = '.intval($mailId));
122 + acym_query('UPDATE #__acym_campaign SET active = 1 WHERE mail_id = '.intval($mailId));
123 + if (empty($hasStat)) {
124 + acym_query('UPDATE #__acym_campaign SET draft = "1", sent = "0", sending_date = NULL WHERE mail_id = '.intval($mailId));
125 + acym_query('DELETE FROM #__acym_mail_stat WHERE mail_id = '.intval($mailId));
126 + }
127 + } else {
128 + acym_enqueueMessage(acym_translation('ACYM_ERROR_QUEUE_CANCEL_CAMPAIGN'), 'error');
129 + }
130 + }
131 +
132 + public function cancelCampaignSending(): void
133 + {
134 + $this->cancelSending();
135 + $this->campaigns();
136 + }
137 +
138 + public function playPauseSending(): void
139 + {
140 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
141 +
142 + $active = acym_getVar('int', 'acym__queue__play_pause__active__new_value');
143 + $campaignId = acym_getVar('int', 'acym__queue__play_pause__campaign_id');
144 +
145 + if (!empty($campaignId)) {
146 + $queueClass = new QueueClass();
147 + $queueClass->unpauseCampaign($campaignId, $active);
148 + } else {
149 + if (!empty($active)) {
150 + acym_enqueueMessage(acym_translation('ACYM_ERROR_QUEUE_RESUME'), 'error');
151 + } else {
152 + acym_enqueueMessage(acym_translation('ACYM_ERROR_QUEUE_PAUSE'), 'error');
153 + }
154 + }
155 +
156 + $this->campaigns();
157 + }
158 +
159 + public function emptyQueue(): void
160 + {
161 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
162 +
163 + $queueClass = new QueueClass();
164 + $deleted = $queueClass->emptyQueue();
165 + acym_enqueueMessage(acym_translationSprintf('ACYM_EMAILS_REMOVED_QUEUE', $deleted));
166 +
167 + $this->campaigns();
168 + }
169 +}