displayLastNews(); echo '
'; echo '
'; $this->displayBreadcrumb($breadcrumb); echo '
'; echo '
'; echo '
'; $this->displayVersionArea(); echo '
'; echo '
'; $this->displayCheckVersionButton(); $this->displayHelpWedButton(); $this->displayDocumentationButton(); $this->displayNotificationCenter(); echo '
'; echo '
'; echo '
'; } public function displayVersionArea(bool $reloading = false): void { $currentLevel = $this->config->get('level', ''); $currentVersion = $this->config->get('version', ''); $latestVersion = $this->config->get('latestversion', ''); echo '
'; echo '
'.esc_html(ACYM_NAME.' '.$currentLevel.' '); if (version_compare($currentVersion, $latestVersion, '>=')) { acym_tooltip( [ 'hoveredText' => ''.esc_html($currentVersion).'', 'textShownInTooltip' => acym_translation('ACYM_UP_TO_DATE'), ] ); } elseif (!empty($latestVersion)) { if ('wordpress' === ACYM_CMS) { $downloadLink = admin_url().'update-core.php'; } else { $downloadLink = ACYM_ACYMAILING_WEBSITE.'account/license/" target="_blank'; } acym_tooltip( [ 'hoveredText' => ''.esc_html($currentVersion).'', 'textShownInTooltip' => acym_translationSprintf('ACYM_CLICK_UPDATE', $latestVersion), 'titleShownInTooltip' => acym_translation('ACYM_OLD_VERSION'), 'link' => $downloadLink, ] ); } echo '
'; $expirationDate = $this->config->get('expirationdate', 0); if ((empty($expirationDate) || $expirationDate == -1) && empty($this->config->get('acymailer_apikey', ''))) { return; } echo '
'; if (acym_level(ACYM_ESSENTIAL) && ACYM_PRODUCTION) { if ($expirationDate == -2) { echo '
'.esc_html(acym_translation('ACYM_ATTACH_LICENCE')).'
'; } elseif ($expirationDate < time()) { //TODO redirect to the subscription page directly instead of the subscriptions listing // We'll need to return the subscription id when calling the API acym_tooltip( [ 'hoveredText' => ''.esc_html(acym_translation('ACYM_SUBSCRIPTION_EXPIRED')).'', 'textShownInTooltip' => acym_translation('ACYM_SUBSCRIPTION_EXPIRED_LINK'), 'link' => ACYM_ACYMAILING_WEBSITE.'account/license/', ] ); } else { echo '
'.esc_html( acym_translationSprintf( 'ACYM_VALID_UNTIL', acym_getDate($expirationDate, acym_translation('ACYM_DATE_FORMAT_LC4')) ) ).'
'; } } $creditRemainingSendingMethod = ''; acym_trigger('onAcymGetCreditRemainingSendingMethod', [&$creditRemainingSendingMethod, $reloading]); if (!empty($creditRemainingSendingMethod)) { echo '
'.wp_kses($creditRemainingSendingMethod, [ 'span' => [ 'class' => true, ], 'a' => [ 'href' => true, 'class' => true, 'title' => true, 'target' => true, ], ]).'
'; } echo '
'; } public function displayNotificationCenter(): void { $notifications = json_decode($this->config->get('notifications', '{}'), true); if (!is_array($notifications) || empty($notifications)) { $notifications = []; } $message = ''; //if we have a notifications for success $notificationLevel = 0; $successMessage = acym_getVar('string', 'acym_success', '', 'SESSION'); if (!empty($successMessage)) { $message = $successMessage; acym_setSession('acym_success', ''); $notificationLevel = 1; } if (!empty($notifications)) { foreach ($notifications as $notification) { if ($notification['read']) continue; if ($notification['level'] === 'info' && $notificationLevel < 2) $notificationLevel = 2; if ($notification['level'] === 'warning' && $notificationLevel < 3) $notificationLevel = 3; if ($notification['level'] === 'error' && $notificationLevel < 4) $notificationLevel = 4; } } $iconToDisplay = ''; $tooltip = false; switch ($notificationLevel) { case 0: // default icon $iconToDisplay = 'acymicon-bell'; $notificationLevel = ''; break; case 1: // success $iconToDisplay = 'acymicon-check-circle acym__color__green'; $notificationLevel = 'acym__header__notification__button__success acym__header__notification__pulse'; $tooltip = true; break; case 2: // info $iconToDisplay = 'acymicon-bell acym__color__blue'; $notificationLevel = 'acym__header__notification__button__info'; break; case 3: // warning $iconToDisplay = 'acymicon-exclamation-triangle acym__color__orange'; $notificationLevel = 'acym__header__notification__button__warning'; break; case 4: // error $iconToDisplay = 'acymicon-exclamation-circle acym__color__red'; $notificationLevel = 'acym__header__notification__button__error'; break; } echo '
'; echo ''; echo '
'; $this->displayNotificationCenterInner($notifications); echo '
'; echo '
'; } public function displayNotificationCenterInner(array $notifications): void { if (empty($notifications)) { echo '
'; echo '

'.esc_html(acym_translation('ACYM_YOU_DONT_HAVE_NOTIFICATIONS')).'

'; echo '
'; return; } echo '

'; echo esc_html(acym_translation('ACYM_NOTIFICATIONS')); echo '

'; echo esc_html(acym_translation('ACYM_DELETE_ALL')); echo '
'; foreach ($notifications as $key => $notif) { $fullMessageHover = $notif['message']; if (strlen($notif['message']) > 150) { $tag = new \stdClass(); $tag->wrap = 150; $pluginHelper = new PluginHelper(); $notif['message'] = $pluginHelper->wrapText($notif['message'], $tag); } $logo = $notif['level'] === 'info' ? 'acymicon-bell' : ($notif['level'] === 'warning' ? 'acymicon-exclamation-triangle' : 'acymicon-exclamation-circle'); $read = $notif['read'] ? 'acym__header__notification__one__read' : ''; echo '
'; echo '
'; echo '
'; echo '

'; echo wp_kses($notif['message'], SecurityHelper::ALLOWED_HTML_NOTIFICATION); echo '

'.esc_html(acym_date($notif['date'])).'
'; echo ''; echo '
'; } } public function addNotification(object $notif): string { if ($notif->level === 'success') { acym_setSession('acym_success', $notif->message); return ''; } $notifications = json_decode($this->config->get('notifications', '[]'), true); if (!is_array($notifications)) { $notifications = []; } $notif->message = str_replace('
', "\r\n", $notif->message); $notif->message = wp_kses( $notif->message, [ 'a' => [ 'href' => true, 'class' => true, 'id' => true, 'target' => true, ], ] ); // Prevent duplicated notifications foreach ($notifications as $key => $oneNotif) { if ($oneNotif['message'] === $notif->message && $oneNotif['level'] === $notif->level) unset($notifications[$key]); } $notifications = array_values($notifications); $notif->id = uniqid(); array_unshift($notifications, $notif); if (count($notifications) > 10) unset($notifications[10]); $this->config->saveConfig(['notifications' => json_encode($notifications)]); return $notif->id; } private function displayLastNews(): void { $lastNewsCheck = $this->config->get('last_news_check', 0); if ($lastNewsCheck < time() - 7200) { $context = stream_context_create(['http' => ['timeout' => 1]]); $news = @file_get_contents(ACYM_ACYMAILING_WEBSITE.'acymnews.xml', false, $context); $this->config->saveConfig( [ 'last_news_check' => time(), 'last_news' => base64_encode($news), ], false ); } else { $news = $this->config->get('last_news', ''); if (!empty($news)) $news = base64_decode($news); } if (empty($news)) { return; } $news = @simplexml_load_string($news); if (empty($news->news)) { return; } $currentLanguage = acym_getLanguageTag(); $latestNews = null; $doNotRemind = json_decode($this->config->get('remindme', '[]')); foreach ($news->news as $oneNews) { // If we found a news more recent, it means we found the latest available one if (!empty($latestNews) && strtotime($latestNews->date) > strtotime($oneNews->date)) break; // If the news isn't published or that the language isn't correct, leave $language = strtolower($oneNews->language); if (empty($oneNews->published) || ($language != strtolower($currentLanguage) && ($language != 'default' || !empty($latestNews)))) { continue; } // If the extension isn't correct, leave if (!empty($oneNews->extension) && strtolower($oneNews->extension) !== 'acymailing') continue; // If the CMS isn't correct, leave if (!empty($oneNews->cms) && strtolower($oneNews->cms) != strtolower('WordPress')) continue; // If the level of the extension isn't correct, leave if (!empty($oneNews->level) && strtolower($oneNews->level) != strtolower($this->config->get('level'))) continue; // If the version of the extension isn't correct, leave if (!empty($oneNews->version)) { [$version, $operator] = explode('_', $oneNews->version); if (!version_compare($this->config->get('version'), $version, $operator)) continue; } if (!empty($oneNews->mailermethod)) { $sendMethod = $this->config->get('mailer_method', ''); if ($oneNews->mailermethod !== $sendMethod) continue; } if (in_array($oneNews->name, $doNotRemind)) continue; $latestNews = $oneNews; } if (empty($latestNews)) { return; } echo '
'; echo wp_kses( $latestNews->content, [ 'style' => [ 'type' => true, ], 'div' => [ 'class' => true, 'title' => true, ], 'b' => [], 'a' => [ 'href' => true, 'target' => true, ], ] ); echo '
'; } private function displayBreadcrumb(array $breadcrumb): void { echo ''; echo '
'; } private function displayCheckVersionButton(): void { if (ACYM_CMS == 'wordpress' && !acym_level(ACYM_ESSENTIAL)) { return; } $lastLicenseCheck = $this->config->get('lastlicensecheck', 0); if (empty($lastLicenseCheck)) { $lastLicenseCheck = time(); } $lastDateFormatted = acym_date($lastLicenseCheck, 'ACYM_DATE_FORMAT_LC2'); acym_tooltip( [ 'hoveredText' => '', 'textShownInTooltip' => esc_html(acym_translation('ACYM_LAST_CHECK')).' '.esc_html( $lastDateFormatted ).'', ] ); } private function displayHelpWedButton(): void { if (ACYM_CMS !== 'wordpress' || acym_level(ACYM_ESSENTIAL)) { return; } echo ' '; } private function displayDocumentationButton(): void { acym_tooltip( [ 'hoveredText' => '', 'textShownInTooltip' => acym_translation('ACYM_DOCUMENTATION'), ] ); } }