PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.11.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.11.1
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 / Queue / Campaigns.php

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

162 lines 5.9 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\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 $searchFilter = $this->getVarFiltersListing('string', 'cqueue_search', '');
32 $tagFilter = $this->getVarFiltersListing('string', 'cqueue_tag', '');
33 $status = $this->getVarFiltersListing('string', 'cqueue_status', '');
34
35 $pagination = new PaginationHelper();
36 $campaignsPerPage = $pagination->getListLimit();
37 $page = $this->getVarFiltersListing('int', 'cqueue_pagination_page', 1);
38
39 $queueClass = new QueueClass();
40 $matchingElements = $queueClass->getMatchingCampaigns(
41 [
42 'search' => $searchFilter,
43 'tag' => $tagFilter,
44 'status' => $status,
45 'campaignsPerPage' => $campaignsPerPage,
46 'offset' => ($page - 1) * $campaignsPerPage,
47 ]
48 );
49
50 $pagination->setStatus((int)$matchingElements['total']->total, $page, $campaignsPerPage);
51 $tagClass = new TagClass();
52
53 $viewData = [
54 'allElements' => $matchingElements['elements'],
55 'pagination' => $pagination,
56 'search' => $searchFilter,
57 'tag' => $tagFilter,
58 'allTags' => $tagClass->getAllTagsByType(TagClass::TYPE_MAIL),
59 'numberPerStatus' => $matchingElements['status'],
60 'status' => $status,
61 'campaignClass' => new CampaignClass(),
62 'languages' => acym_getLanguages(),
63 'workflowHelper' => new WorkflowHelper(),
64 ];
65
66 $this->prepareToolbar($viewData);
67
68 $this->breadcrumb[acym_translation('ACYM_MAILS')] = acym_completeLink('queue');
69 parent::display($viewData);
70 }
71
72 public function prepareToolbar(array &$data): void
73 {
74 $toolbarHelper = new ToolbarHelper();
75 $toolbarHelper->addSearchBar($data['search'], 'cqueue_search', 'ACYM_SEARCH');
76 $toolbarHelper->addButton(
77 acym_translation('ACYM_EMPTY_QUEUE'),
78 [
79 'data-task' => 'emptyQueue',
80 'data-confirmation-message' => 'ACYM_ARE_YOU_SURE',
81 ],
82 'close'
83 );
84 $otherContent = acym_modal(
85 '<i class="acymicon-paper-plane"></i>'.acym_translation('ACYM_SEND_MAILS_MANUALLY'),
86 '',
87 null,
88 ['data-reveal-larger' => true],
89 [
90 'class' => 'cell medium-6 large-shrink button',
91 'data-reload' => 'true',
92 'data-ajax' => 'true',
93 'data-iframe' => '&ctrl=queue&task=continuesend&id=0&totalsend=0',
94 ]
95 );
96 $toolbarHelper->addOtherContent($otherContent);
97 $toolbarHelper->addFilterByTag($data, 'cqueue_tag', 'acym__queue__filter__tags acym__select');
98
99 $data['toolbar'] = $toolbarHelper;
100 if (!empty($data['tag'])) {
101 $data['status_toolbar'] = [
102 'cqueue_tag' => $data['tag'],
103 ];
104 }
105 }
106
107 public function cancelSending(): void
108 {
109 $mailId = acym_getVar('int', 'acym__queue__cancel__mail_id');
110
111 if (!empty($mailId)) {
112 $hasStat = acym_loadResult('SELECT COUNT(*) FROM #__acym_user_stat WHERE mail_id = '.intval($mailId));
113
114 acym_query('DELETE FROM #__acym_queue WHERE mail_id = '.intval($mailId));
115 acym_query('UPDATE #__acym_mail_stat SET total_subscribers = sent WHERE mail_id = '.intval($mailId));
116 acym_query('UPDATE #__acym_campaign SET active = 1 WHERE mail_id = '.intval($mailId));
117 if (empty($hasStat)) {
118 acym_query('UPDATE #__acym_campaign SET draft = "1", sent = "0", sending_date = NULL WHERE mail_id = '.intval($mailId));
119 acym_query('DELETE FROM #__acym_mail_stat WHERE mail_id = '.intval($mailId));
120 }
121 } else {
122 acym_enqueueMessage(acym_translation('ACYM_ERROR_QUEUE_CANCEL_CAMPAIGN'), 'error');
123 }
124 }
125
126 public function cancelCampaignSending(): void
127 {
128 $this->cancelSending();
129 $this->campaigns();
130 }
131
132 public function playPauseSending(): void
133 {
134 $active = acym_getVar('int', 'acym__queue__play_pause__active__new_value');
135 $campaignId = acym_getVar('int', 'acym__queue__play_pause__campaign_id');
136
137 if (!empty($campaignId)) {
138 $queueClass = new QueueClass();
139 $queueClass->unpauseCampaign($campaignId, $active);
140 } else {
141 if (!empty($active)) {
142 acym_enqueueMessage(acym_translation('ACYM_ERROR_QUEUE_RESUME'), 'error');
143 } else {
144 acym_enqueueMessage(acym_translation('ACYM_ERROR_QUEUE_PAUSE'), 'error');
145 }
146 }
147
148 $this->campaigns();
149 }
150
151 public function emptyQueue(): void
152 {
153 acym_checkToken();
154
155 $queueClass = new QueueClass();
156 $deleted = $queueClass->emptyQueue();
157 acym_enqueueMessage(acym_translationSprintf('ACYM_EMAILS_REMOVED_QUEUE', $deleted));
158
159 $this->campaigns();
160 }
161 }
162