PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.3
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.3
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 / Dashboard / Listing.php

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

286 lines 10.8 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\Dashboard;
4
5 use AcyMailing\Classes\CampaignClass;
6 use AcyMailing\Classes\MailStatClass;
7 use AcyMailing\Classes\QueueClass;
8 use AcyMailing\Controllers\StatsController;
9 use AcyMailing\Classes\ListClass;
10 use AcyMailing\Classes\UserClass;
11
12 trait Listing
13 {
14 public function listing(): void
15 {
16 acym_setVar('layout', 'listing');
17
18 if ($this->migration() || $this->walkthrough()) {
19 return;
20 }
21
22 $campaignClass = new CampaignClass();
23 $mailStatClass = new MailStatClass();
24 $statsController = new StatsController();
25 $listsClass = new ListClass();
26 $usersClass = new UserClass();
27
28 $numberOfUsers = $usersClass->getCountTotalUsers();
29
30 $data = [
31 'page_title' => true,
32 'mail_filter_options' => [],
33 'stats_export' => '',
34 'selectedMailid' => '',
35 'show_date_filters' => false,
36 'campaignsScheduled' => $campaignClass->getCampaignForDashboard(),
37 'sentMails' => $mailStatClass->getAllMailsForStats(),
38 'userCreated' => $numberOfUsers > 1,
39 'listCreated' => $listsClass->getOneList(),
40 'totalSubscribers' => $numberOfUsers,
41 'campaignCreated' => $campaignClass->getOneCampaign(),
42 'campaignSent' => $mailStatClass->getOneSentEmail(),
43 'mailStatsCheckedOnce' => $this->config->get('mail_stats_checked_once', 0),
44 'notifications' => json_decode($this->config->get('dashboard_notif', '[]'), true),
45 'engage_community' => [
46 [
47 'title' => 'ACYM_START_SENDING',
48 'text' => 'ACYM_WEBSITE_LINKED',
49 'link' => 'configuration',
50 'icon' => 'acymicon-cogs',
51 ],
52 [
53 'title' => 'ACYM_SUBSCRIPTION_FORM',
54 'text' => 'ACYM_RAISE_SUBSCRIBER',
55 'link' => 'forms',
56 'icon' => 'acymicon-edit',
57 ],
58 [
59 'title' => 'ACYM_SET_WELCOME_EMAIL',
60 'text' => 'ACYM_WELCOME_NEW_SUBSCRIBER',
61 'link' => 'campaigns&task=welcome',
62 'icon' => 'acymicon-mail-o',
63 ],
64 [
65 'title' => 'ACYM_OVERRIDE_WEBSITE',
66 'text' => 'ACYM_HOMOGENOUS_COMMUNICATION',
67 'link' => 'override',
68 'icon' => 'acymicon-edit',
69 ],
70 [
71 'title' => 'ACYM_ADD_MORE_USERS',
72 'text' => 'ACYM_IMPORT_USERS',
73 'link' => 'users&task=import',
74 'icon' => 'acymicon-user-plus',
75 ],
76 [
77 'title' => 'ACYM_TRIGGER_ACTION',
78 'text' => 'ACYM_EXTERNAL_SERVICES_ZAPIER',
79 'link' => '',
80 'link_doc' => ACYM_DOCUMENTATION.'addons/zapier',
81 'icon' => 'acymicon-arrows-h',
82 ],
83 [
84 'title' => 'ACYM_ADVENCED_SCENARIOS',
85 'text' => 'ACYM_CREATE_SCENARIOS_AND_ACTIONS',
86 'link' => 'scenarios',
87 'icon' => 'acymicon-movie',
88 ],
89 [
90 'title' => 'ACYM_BUILD_MEANINGFUL_PROFILES',
91 'text' => 'ACYM_CREATE_CUSTOM_FIELDS',
92 'link' => 'fields',
93 'icon' => 'acymicon-group',
94 ],
95 [
96 'title' => 'ACYM_TARGET_YOUR_AUDIENCE',
97 'text' => 'ACYM_CREATE_DIFFERENT_LISTS',
98 'link' => 'segments',
99 'icon' => 'acymicon-user-check',
100 ],
101 [
102 'title' => 'ACYM_CHOOSE_YOUR_COMMUNICATION',
103 'text' => 'ACYM_CHOOSE_AMONG_DIFFERENT_KIND_OF_EMAIL',
104 'link' => 'campaigns',
105 'icon' => 'acymicon-mobile',
106 ],
107 [
108 'title' => 'ACYM_SEND_RELATED_INFORMATION',
109 'text' => 'ACYM_INSERT_SPECIFIC_CONTENT',
110 'link' => 'plugins',
111 'icon' => 'acymicon-edit',
112 ],
113 ],
114 ];
115
116 $this->doDisplayBeginnerSteps($data);
117 $this->getDashboardNotifications($data);
118 $this->getCurrentCampaigns($data);
119 $this->getLastTwoCampaigns($data);
120 $this->getMainLists($data);
121
122 $statsController->prepareOpenTimeChart($data);
123 $statsController->preparecharts($data);
124 $statsController->prepareDefaultLineChart($data);
125 $statsController->prepareDefaultDevicesChart($data);
126 $statsController->prepareDefaultBrowsersChart($data);
127
128 $this->prepareStatsView($data);
129 $this->getUsersCount($data);
130 $statsEvolution = json_decode($this->config->get('statsEvolution', '{}'));
131 $data['newSubscribers'] = $statsEvolution->totalNewSubscribersEvolution ?? 0;
132 parent::display($data);
133 }
134
135 public function getDashboardNotifications(array &$data): void
136 {
137 $data['dashboardNotifications'] = '';
138
139 if (empty($data['notifications'])) {
140 return;
141 }
142
143 $data['dashboardNotifications'] = '<div class="acym__dashboard__notifications">';
144
145 $notifications = array_map(fn($notif) => is_array($notif) ? (object)$notif : $notif, $data['notifications']);
146 $notifications = array_filter($notifications, fn($notif) => isset($notif->message, $notif->level, $notif->date));
147
148 foreach ($notifications as $notif) {
149 if ($notif->level === 'info') {
150 continue;
151 }
152
153 $fullMessageHover = $notif->message ?? '';
154
155 $fullMessageHover = ($fullMessageHover !== $notif->message)
156 ? 'data-acym-full="'.esc_attr($fullMessageHover).'"'
157 : '';
158
159 $logo = ($notif->level === 'warning')
160 ? 'acymicon-exclamation-triangle'
161 : 'acymicon-exclamation-circle';
162
163 $date = acym_date($notif->date ?? 'now', 'Y-m-d H:i:s', false);
164
165 $data['dashboardNotifications'] .= '<div class="cell grid-x acym__dashboard__notification acym__dashboard__notification__'.$notif->level.'">'
166 .'<div class="cell shrink small-1 align-center grid-x acym__dashboard__notification__icon"><i class="cell shrink '.$logo.'"></i></div>'
167 .'<div class="cell grid-x small-10"><p class="cell acym__dashboard__notification__message" '.$fullMessageHover.'>'.$notif->message
168 .'<div class="cell acym__dashboard__notification__date">'.$date.'</div></div>';
169
170 if (!isset($notif->removable) || $notif->removable != 0) {
171 $data['dashboardNotifications'] .= '<i class="cell shrink small-1 acym__dashboard__notification__delete acymicon-close" data-id="'.esc_attr(
172 $notif->name
173 ).'"></i>';
174 }
175
176 $data['dashboardNotifications'] .= '</div><span class="acym__dashboard__light__separator separator"></span>';
177 }
178
179 $data['dashboardNotifications'] .= '</div>';
180 }
181
182 private function doDisplayBeginnerSteps(array $data): void
183 {
184 if ($this->config->get('install_date', time()) < strtotime('-14 days')) {
185 $this->config->saveConfig(['show_beginner_steps' => 0]);
186 } elseif (!$data['listCreated'] || $data['totalSubscribers'] <= 1 || !$data['campaignCreated'] || !$data['campaignSent'] || $data['mailStatsCheckedOnce'] != 1) {
187 $this->config->saveConfig(['show_beginner_steps' => 1]);
188 } else {
189 $this->config->saveConfig(['show_beginner_steps' => 0]);
190 }
191 }
192
193 private function prepareStatsView(array &$data): void
194 {
195 $data['stats'] = [
196 'ACYM_SUBSCRIBERS' => [
197 'value' => $data['totalSubscribers'] ?? 0,
198 'evolution' => $data['totalSubscribersEvolution'] ?? 0,
199 'icon' => 'acymicon-group',
200 ],
201 'ACYM_OPEN_RATE' => [
202 'value' => $data['mail']->percentageOpen ?? 0,
203 'evolution' => $data['openRateEvolution'] ?? 0,
204 'icon' => 'acymicon-mail-o-open',
205 ],
206 'ACYM_CLICK_RATE' => [
207 'value' => $data['mail']->percentageClick ?? 0,
208 'evolution' => $data['clickRateEvolution'] ?? 0,
209 'icon' => 'acymicon-trigger',
210 ],
211 'ACYM_BOUNCE_RATE' => [
212 'value' => $data['mail']->percentageBounce ?? 0,
213 'evolution' => $data['bounceRateEvolution'] ?? 0,
214 'icon' => 'acymicon-exclamation-triangle',
215 ],
216 ];
217 }
218
219 private function getCurrentCampaigns(array &$data): void
220 {
221 $queueClass = new QueueClass();
222 $campaignsPerPage = 3;
223 $activeCampaigns = $queueClass->getMatchingCampaigns(
224 [
225 'status' => 'sending',
226 'campaignsPerPage' => $campaignsPerPage,
227 'offset' => 0,
228 ]
229 );
230 $pausedCampaigns = $queueClass->getMatchingCampaigns(
231 [
232 'status' => 'paused',
233 'campaignsPerPage' => $campaignsPerPage,
234 'offset' => 0,
235 ]
236 );
237 $data['campaigns'] = array_merge($pausedCampaigns['elements'], $activeCampaigns['elements']);
238 }
239
240 private function getLastTwoCampaigns(array &$data): void
241 {
242 $campaignsPerPage = 2;
243 $campaignClass = new CampaignClass();
244 $lastTwoCampaigns = $campaignClass->getMatchingElements(
245 [
246 'element_tab' => 'campaigns',
247 'ordering' => 'creation_date',
248 'status' => 'sent',
249 'ordering_sort_order' => 'DESC',
250 'elementsPerPage' => $campaignsPerPage,
251 ]
252 );
253
254 $data['recent_campaigns'] = $lastTwoCampaigns['elements'];
255 }
256
257 private function getMainLists(array &$data): void
258 {
259 $listClass = new ListClass();
260 $listPerPage = 5;
261 $mainLists = $listClass->getMatchingElements(
262 [
263 'ordering_sort_order' => 'ASC',
264 'elementsPerPage' => $listPerPage,
265 'offset' => 0,
266 'status' => 'active',
267 ],
268 );
269
270 $data['main_lists'] = $mainLists['elements'];
271 }
272
273 private function getUsersCount(array &$data): void
274 {
275 $userClass = new UserClass();
276 $matchingUsers = $userClass->getMatchingElements(
277 [
278 'offset' => 0,
279 'cms_username' => true,
280 ],
281 );
282
283 $data['subscribers'] = $matchingUsers['status'];
284 }
285 }
286