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 / Dashboard / Listing.php

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

288 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' => '',
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->prepareDefaultRoundCharts($data);
125 $statsController->prepareDefaultLineChart($data);
126 $statsController->prepareDefaultDevicesChart($data);
127 $statsController->prepareDefaultBrowsersChart($data);
128
129 $this->prepareStatsView($data);
130 $this->getUsersCount($data);
131 $statsEvolution = json_decode($this->config->get('statsEvolution', '{}'));
132 $data['newSubscribers'] = $statsEvolution->totalNewSubscribersEvolution ?? 0;
133 parent::display($data);
134 }
135
136 private function doDisplayBeginnerSteps(array $data): void
137 {
138 if ($this->config->get('install_date', time()) < strtotime('-14 days')) {
139 $this->config->saveConfig(['show_beginner_steps' => 0]);
140 } elseif (!$data['listCreated'] || $data['totalSubscribers'] <= 1 || !$data['campaignCreated'] || !$data['campaignSent'] || $data['mailStatsCheckedOnce'] != 1) {
141 $this->config->saveConfig(['show_beginner_steps' => 1]);
142 } else {
143 $this->config->saveConfig(['show_beginner_steps' => 0]);
144 }
145 }
146
147 public function getDashboardNotifications(array &$data): void
148 {
149 $data['dashboardNotifications'] = '';
150
151 if (empty($data['notifications'])) {
152 return;
153 }
154
155 $data['dashboardNotifications'] = '<div class="acym__dashboard__notifications">';
156
157 $notifications = array_map(fn($notif) => is_array($notif) ? (object)$notif : $notif, $data['notifications']);
158 $notifications = array_filter($notifications, fn($notif) => isset($notif->message, $notif->level, $notif->date));
159
160 foreach ($notifications as $notif) {
161 if ($notif->level === 'info') {
162 continue;
163 }
164
165 $fullMessageHover = $notif->message ?? '';
166
167 $fullMessageHover = ($fullMessageHover !== $notif->message)
168 ? 'data-acym-full="'.acym_escape($fullMessageHover).'"'
169 : '';
170
171 $logo = ($notif->level === 'warning')
172 ? 'acymicon-exclamation-triangle'
173 : 'acymicon-exclamation-circle';
174
175 $date = acym_date($notif->date ?? 'now', 'Y-m-d H:i:s', false);
176
177 $data['dashboardNotifications'] .= '<div class="cell grid-x acym__dashboard__notification acym__dashboard__notification__'.$notif->level.'">'
178 .'<div class="cell shrink small-1 align-center grid-x acym__dashboard__notification__icon"><i class="cell shrink '.$logo.'"></i></div>'
179 .'<div class="cell grid-x small-10"><p class="cell acym__dashboard__notification__message" '.$fullMessageHover.'>'.$notif->message
180 .'<div class="cell acym__dashboard__notification__date">'.$date.'</div></div>';
181
182 if (!isset($notif->removable) || $notif->removable != 0) {
183 $data['dashboardNotifications'] .= '<i class="cell shrink small-1 acym__dashboard__notification__delete acymicon-close" data-id="'.acym_escape(
184 $notif->name
185 ).'"></i>';
186 }
187
188 $data['dashboardNotifications'] .= '</div><span class="acym__dashboard__light__separator separator"></span>';
189 }
190
191 $data['dashboardNotifications'] .= '</div>';
192 }
193
194
195 private function prepareStatsView(array &$data): void
196 {
197 $data['stats'] = [
198 'ACYM_SUBSCRIBERS' => [
199 'value' => $data['totalSubscribers'] ?? 0,
200 'evolution' => $data['totalSubscribersEvolution'] ?? 0,
201 'icon' => 'acymicon-group',
202 ],
203 'ACYM_OPEN_RATE' => [
204 'value' => $data['mail']->percentageOpen ?? 0,
205 'evolution' => $data['openRateEvolution'] ?? 0,
206 'icon' => 'acymicon-mail-o-open',
207 ],
208 'ACYM_CLICK_RATE' => [
209 'value' => $data['mail']->percentageClick ?? 0,
210 'evolution' => $data['clickRateEvolution'] ?? 0,
211 'icon' => 'acymicon-trigger',
212 ],
213 'ACYM_BOUNCE_RATE' => [
214 'value' => $data['mail']->percentageBounce ?? 0,
215 'evolution' => $data['bounceRateEvolution'] ?? 0,
216 'icon' => 'acymicon-exclamation-triangle',
217 ],
218 ];
219 }
220
221 public function getCurrentCampaigns(array &$data): void
222 {
223 $queueClass = new QueueClass();
224 $campaignsPerPage = 3;
225 $activeCampaigns = $queueClass->getMatchingCampaigns(
226 [
227 'status' => 'sending',
228 'campaignsPerPage' => $campaignsPerPage,
229 'offset' => 0,
230 ]
231 );
232 $pausedCampaigns = $queueClass->getMatchingCampaigns(
233 [
234 'status' => 'paused',
235 'campaignsPerPage' => $campaignsPerPage,
236 'offset' => 0,
237 ]
238 );
239 $data['campaigns'] = array_merge($pausedCampaigns['elements'], $activeCampaigns['elements']);
240 }
241
242 public function getLastTwoCampaigns(array &$data): void
243 {
244 $campaignsPerPage = 2;
245 $campaignClass = new CampaignClass();
246 $lastTwoCampaigns = $campaignClass->getMatchingElements(
247 [
248 'element_tab' => 'campaigns',
249 'ordering' => 'creation_date',
250 'status' => 'sent',
251 'ordering_sort_order' => 'DESC',
252 'elementsPerPage' => $campaignsPerPage,
253 ]
254 );
255
256 $data['recent_campaigns'] = $lastTwoCampaigns['elements'];
257 }
258
259 public function getMainLists(array &$data): void
260 {
261 $listClass = new ListClass();
262 $listPerPage = 5;
263 $mainLists = $listClass->getMatchingElements(
264 [
265 'ordering_sort_order' => 'ASC',
266 'elementsPerPage' => $listPerPage,
267 'offset' => 0,
268 'status' => 'active',
269 ],
270 );
271
272 $data['main_lists'] = $mainLists['elements'];
273 }
274
275 public function getUsersCount(array &$data): void
276 {
277 $userClass = new UserClass();
278 $matchingUsers = $userClass->getMatchingElements(
279 [
280 'offset' => 0,
281 'cms_username' => true,
282 ],
283 );
284
285 $data['subscribers'] = $matchingUsers['status'];
286 }
287 }
288