PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.0.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.0.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 / Helpers / HeaderHelper.php

HeaderHelper.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.0.1, at back/Helpers/HeaderHelper.php

364 lines 15.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\Helpers;
4
5 use AcyMailing\Core\AcymObject;
6
7 class HeaderHelper extends AcymObject
8 {
9 public function display($breadcrumb)
10 {
11 $header = '<div class="cell large-6 xlarge-7 xxlarge-8 grid-x acym_vcenter">';
12 $header .= $this->getBreadcrumb($breadcrumb);
13 $header .= '</div>';
14
15 $header .= '<div class="cell large-6 xlarge-5 xxlarge-4 grid-x">';
16
17 $header .= '<div id="checkVersionArea" class="cell auto grid-x align-right check-version-area acym_vcenter padding-right-1">';
18 $header .= $this->checkVersionArea();
19 $header .= '</div>';
20
21 $header .= '<div class="cell shrink grid-x align-right acym_vcenter">';
22 $header .= $this->getCheckVersionButton();
23 $header .= $this->getHelpWedButton();
24 $header .= $this->getDocumentationButton();
25 $header .= $this->getNotificationCenter();
26 $header .= '</div>';
27
28 $header .= '</div>';
29
30 $header = '<div id="acym_header" class="grid-x margin-bottom-1">'.$header.'</div>';
31
32 return $this->getLastNews().$header;
33 }
34
35 private function getLastNews()
36 {
37 $lastNewsCheck = $this->config->get('last_news_check', 0);
38 if ($lastNewsCheck < time() - 7200) {
39 $context = stream_context_create(['http' => ['timeout' => 1]]);
40 $news = @file_get_contents(ACYM_ACYMAILING_WEBSITE.'acymnews.xml', false, $context);
41 $this->config->save(
42 [
43 'last_news_check' => time(),
44 'last_news' => base64_encode($news),
45 ],
46 false
47 );
48 } else {
49 $news = $this->config->get('last_news', '');
50 if (!empty($news)) $news = base64_decode($news);
51 }
52 if (empty($news)) return '';
53
54 $news = @simplexml_load_string($news);
55 if (empty($news->news)) return '';
56
57 $currentLanguage = acym_getLanguageTag();
58 $latestNews = null;
59 $doNotRemind = json_decode($this->config->get('remindme', '[]'));
60
61 foreach ($news->news as $oneNews) {
62 if (!empty($latestNews) && strtotime($latestNews->date) > strtotime($oneNews->date)) break;
63
64 $language = strtolower($oneNews->language);
65 if (empty($oneNews->published) || ($language != strtolower($currentLanguage) && ($language != 'default' || !empty($latestNews)))) {
66 continue;
67 }
68
69 if (!empty($oneNews->extension) && strtolower($oneNews->extension) !== 'acymailing') continue;
70
71 if (!empty($oneNews->cms) && strtolower($oneNews->cms) != strtolower('WordPress')) continue;
72
73 if (!empty($oneNews->level) && strtolower($oneNews->level) != strtolower($this->config->get('level'))) continue;
74
75 if (!empty($oneNews->version)) {
76 [$version, $operator] = explode('_', $oneNews->version);
77 if (!version_compare($this->config->get('version'), $version, $operator)) continue;
78 }
79
80 if (!empty($oneNews->mailermethod)) {
81 $sendMethod = $this->config->get('mailer_method', '');
82 if ($oneNews->mailermethod !== $sendMethod) continue;
83 }
84
85 if (in_array($oneNews->name, $doNotRemind)) continue;
86
87 $latestNews = $oneNews;
88 }
89
90 if (empty($latestNews)) return '';
91
92 $newsDisplay = '<div id="acym__header__banner__news" data-news="'.acym_escape($latestNews->name).'">';
93
94 if (!empty($latestNews)) {
95 $newsDisplay .= $latestNews->content;
96 }
97
98 $newsDisplay .= '</div>';
99
100 return $newsDisplay;
101 }
102
103 private function getBreadcrumb($breadcrumb)
104 {
105 $links = [];
106 foreach ($breadcrumb as $oneLevel => $link) {
107 if (!empty($link)) {
108 $oneLevel = '<a href="'.$link.'">'.$oneLevel.'</a>';
109 }
110 $links[] = '<li>'.$oneLevel.'</li>';
111 }
112
113 if (count($links) > 1) {
114 $links[count($links) - 1] = str_replace('<li>', '<li class="last_link cell shrink"><span class="show-for-sr">Current: </span>', $links[count($links) - 1]);
115 }
116
117 $header = '<i class="cell shrink acym-logo"></i>';
118 $header .= '<div id="acym_global_navigation" class="cell auto">
119 <nav aria-label="You are here:" role="navigation">
120 <ul class="breadcrumbs grid-x">'.implode('<li class="breadcrumbs__separator"><i class="acymicon-keyboard-arrow-right"></i></li>', $links).'</ul>
121 </nav>
122 </div>';
123
124 return $header;
125 }
126
127 public function checkVersionArea($reloading = false): string
128 {
129 $currentLevel = $this->config->get('level', '');
130 $currentVersion = $this->config->get('version', '');
131 $latestVersion = $this->config->get('latestversion', '');
132
133 $version = '<div id="acym_level_version_area" class="text-right">';
134 $version .= '<div id="acym_level">'.ACYM_NAME.' '.$currentLevel.' ';
135
136 if (version_compare($currentVersion, $latestVersion, '>=')) {
137 $version .= acym_tooltip(
138 [
139 'hoveredText' => '<span class="acym__color__green">'.$currentVersion.'</span>',
140 'textShownInTooltip' => acym_translation('ACYM_UP_TO_DATE'),
141 ]
142 );
143 } elseif (!empty($latestVersion)) {
144 if ('wordpress' === ACYM_CMS) {
145 $downloadLink = admin_url().'update-core.php';
146 } else {
147 $downloadLink = ACYM_ACYMAILING_WEBSITE.'account/license/" target="_blank';
148 }
149 $version .= acym_tooltip(
150 [
151 'hoveredText' => '<span class="acy_updateversion acym__color__red">'.$currentVersion.'</span>',
152 'textShownInTooltip' => acym_translationSprintf('ACYM_CLICK_UPDATE', $latestVersion),
153 'titleShownInTooltip' => acym_translation('ACYM_OLD_VERSION'),
154 'link' => $downloadLink,
155 ]
156 );
157 }
158
159 $version .= '</div></div>';
160
161 $expirationDate = $this->config->get('expirationdate', 0);
162 if ((empty($expirationDate) || $expirationDate == -1) && empty($this->config->get('acymailer_apikey', ''))) return $version;
163
164 $version .= '<div id="acym_expiration" class="text-right cell">';
165 if (acym_level(ACYM_ESSENTIAL) && ACYM_PRODUCTION) {
166 if ($expirationDate == -2) {
167 $version .= '<div class="acylicence_expired">
168 <a class="acy_attachlicence acymbuttons acym__color__red acym_link_license_tab"
169 href="'.acym_completeLink('configuration', false, false, true).'">'.acym_translation('ACYM_ATTACH_LICENCE').'</a>
170 </div>';
171 } elseif ($expirationDate < time()) {
172 $version .= acym_tooltip(
173 [
174 'hoveredText' => '<span class="acy_subscriptionexpired acym__color__red">'.acym_translation('ACYM_SUBSCRIPTION_EXPIRED').'</span>',
175 'textShownInTooltip' => acym_translation('ACYM_SUBSCRIPTION_EXPIRED_LINK'),
176 'link' => ACYM_ACYMAILING_WEBSITE.'account/license/',
177 ]
178 );
179 } else {
180 $version .= '<div class="acylicence_valid">
181 <span class="acy_subscriptionok acym__color__green">'.acym_translationSprintf(
182 'ACYM_VALID_UNTIL',
183 acym_getDate($expirationDate, acym_translation('ACYM_DATE_FORMAT_LC4'))
184 ).'</span>
185 </div>';
186 }
187 }
188
189 $creditRemainingSendingMethod = '';
190 acym_trigger('onAcymGetCreditRemainingSendingMethod', [&$creditRemainingSendingMethod, $reloading]);
191 if (!empty($creditRemainingSendingMethod)) {
192 $version .= '<div class="acy_sending_method_credits">
193 <span>'.$creditRemainingSendingMethod.'</span>
194 </div>';
195 }
196
197 $version .= '</div>';
198
199 return $version;
200 }
201
202 private function getCheckVersionButton()
203 {
204 if (ACYM_CMS == 'wordpress' && !acym_level(ACYM_ESSENTIAL)) return '';
205 $lastLicenseCheck = $this->config->get('lastlicensecheck', 0);
206 $time = time();
207 $checking = ($time > $lastLicenseCheck + 604800) ? $checking = '1' : '0';
208 if (empty($lastLicenseCheck)) $lastLicenseCheck = $time;
209
210 return acym_tooltip(
211 [
212 'hoveredText' => '<a id="checkVersionButton" type="button" class="grid-x align-center button_header medium-shrink acym_vcenter" data-check="'.acym_escape(
213 $checking
214 ).'"><i class="cell shrink acymicon-autorenew"></i></a>',
215 'textShownInTooltip' => acym_translation('ACYM_LAST_CHECK').' <span id="acym__check__version__last__check">'.acym_date($lastLicenseCheck, 'Y/m/d H:i').'</span>',
216 ]
217 );
218 }
219
220 private function getDocumentationButton()
221 {
222 return acym_tooltip(
223 [
224 'hoveredText' => '<a type="button" class="grid-x align-center button_header medium-shrink acym_vcenter" target="_blank" href="'.ACYM_DOCUMENTATION.'"><i class="cell shrink acymicon-book"></i></a>',
225 'textShownInTooltip' => acym_translation('ACYM_DOCUMENTATION'),
226 ]
227 );
228 }
229
230 private function getHelpWedButton()
231 {
232 if (ACYM_CMS != 'wordpress' || acym_level(ACYM_ESSENTIAL)) return '';
233
234 return '<a type="button" class="grid-x align-center button_header medium-shrink acym_vcenter" target="_blank" href="https://wordpress.org/support/plugin/acymailing/">
235 <i class="cell shrink acymicon-book"></i>
236 </a>';
237 }
238
239 public function getNotificationCenter()
240 {
241 $notifications = json_decode($this->config->get('notifications', '{}'), true);
242 $message = '';
243 $notificationLevel = 0;
244 if (!empty($_SESSION['acym_success'])) {
245 $message = $_SESSION['acym_success'];
246 $_SESSION['acym_success'] = '';
247 $notificationLevel = 1;
248 }
249
250 if (!empty($notifications)) {
251 foreach ($notifications as $notification) {
252 if ($notification['read']) continue;
253 if ($notification['level'] == 'info' && $notificationLevel < 2) $notificationLevel = 2;
254 if ($notification['level'] == 'warning' && $notificationLevel < 3) $notificationLevel = 3;
255 if ($notification['level'] == 'error' && $notificationLevel < 4) $notificationLevel = 4;
256 }
257 }
258
259 $iconToDisplay = '';
260 $tooltip = '';
261
262 switch ($notificationLevel) {
263 case 0:
264 $iconToDisplay = 'acymicon-bell';
265 $notificationLevel = '';
266 break;
267 case 1:
268 $iconToDisplay = 'acymicon-check-circle acym__color__green';
269 $notificationLevel = 'acym__header__notification__button__success acym__header__notification__pulse';
270 $tooltip = 'data-acym-tooltip="'.acym_escape($message).'" data-acym-tooltip-position="left"';
271 break;
272 case 2:
273 $iconToDisplay = 'acymicon-bell acym__color__blue';
274 $notificationLevel = 'acym__header__notification__button__info';
275 break;
276 case 3:
277 $iconToDisplay = 'acymicon-exclamation-triangle acym__color__orange';
278 $notificationLevel = 'acym__header__notification__button__warning';
279 break;
280 case 4:
281 $iconToDisplay = 'acymicon-exclamation-circle acym__color__red';
282 $notificationLevel = 'acym__header__notification__button__error';
283 break;
284 }
285
286 $notificationCenter = '<div class="cell grid-x align-center acym_vcenter medium-shrink acym__header__notification '.$notificationLevel.' button_header cursor-pointer" '.$tooltip.'>';
287 $notificationCenter .= '<i class="'.$iconToDisplay.'"></i>';
288 $notificationCenter .= '<div class="cell grid-x acym__header__notification__center align-center">';
289 $notificationCenter .= $this->getNotificationCenterInner($notifications);
290 $notificationCenter .= '</div>';
291 $notificationCenter .= '</div>';
292
293 return $notificationCenter;
294 }
295
296 public function getNotificationCenterInner($notifications)
297 {
298 $notificationCenter = '';
299 if (empty($notifications)) {
300 $notificationCenter .= '<div class="cell grid-x acym__header__notification__one acym__header__notification__one__empty acym_vcenter">';
301 $notificationCenter .= '<h2 class="cell text-center">'.acym_translation('ACYM_YOU_DONT_HAVE_NOTIFICATIONS').'</h2>';
302 $notificationCenter .= '</div>';
303 } else {
304 $notificationCenter .= '<div class="cell grid-x acym__header__notification__toolbox"><p class="cell auto">'.acym_translation(
305 'ACYM_NOTIFICATIONS'
306 ).'</p><div class="cell shrink cursor-pointer acym__header__notification__toolbox__remove text-right">'.acym_translation('ACYM_DELETE_ALL').'</div></div>';
307 foreach ($notifications as $key => $notif) {
308 $fullMessageHover = $notif['message'];
309
310 if (strlen($notif['message']) > 150) {
311 $tag = new \stdClass();
312 $tag->wrap = 150;
313
314 $pluginHelperClass = new PluginHelper();
315 $notif['message'] = $pluginHelperClass->wrapText($notif['message'], $tag);
316 }
317 $fullMessageHover = $fullMessageHover != $notif['message'] ? 'data-acym-full="'.acym_escape($fullMessageHover).'"' : '';
318
319 $logo = $notif['level'] == 'info' ? 'acymicon-bell' : ($notif['level'] == 'warning' ? 'acymicon-exclamation-triangle' : 'acymicon-exclamation-circle');
320 $read = $notif['read'] ? 'acym__header__notification__one__read' : '';
321 $notificationCenter .= '<div class="'.$read.' cell grid-x acym__header__notification__one acym_vcenter acym_vcenter acym__header__notification__one__'.$notif['level'].'">';
322 $notificationCenter .= '<div class="cell small-3 align-center grid-x acym__header__notification__one__icon"><i class="cell '.$logo.'"></i></div>';
323 $notificationCenter .= '<div class="cell grid-x small-8"><p class="cell acym__header__notification__message" '.$fullMessageHover.'>'.$notif['message'];
324 $notificationCenter .= '<div class="cell acym__header__notification__one__date">'.acym_date($notif['date']).'</div></div>';
325 $notificationCenter .= '<i class="cell small-1 acym__header__notification__one__delete acymicon-close" data-id="'.acym_escape($key).'"></i>';
326 $notificationCenter .= '</div>';
327 }
328 }
329
330 return $notificationCenter;
331 }
332
333 public function addNotification($notif)
334 {
335 if ($notif->level == 'success') {
336 $_SESSION['acym_success'] = $notif->message;
337
338 return true;
339 }
340
341 $notifications = json_decode($this->config->get('notifications', '[]'), true);
342 if (!is_array($notifications)) {
343 $notifications = [];
344 }
345
346 $notif->message = str_replace('<br />', "\r\n", $notif->message);
347 $notif->message = strip_tags($notif->message, '<a>');
348
349 foreach ($notifications as $key => $oneNotif) {
350 if ($oneNotif['message'] === $notif->message && $oneNotif['level'] === $notif->level) unset($notifications[$key]);
351 }
352 $notifications = array_values($notifications);
353
354 $notif->id = uniqid();
355 array_unshift($notifications, $notif);
356
357 if (count($notifications) > 10) unset($notifications[10]);
358
359 $this->config->save(['notifications' => json_encode($notifications)]);
360
361 return $notif->id;
362 }
363 }
364