| @@ -5,141 +5,47 @@ | ||
| 5 | 5 | use AcyMailing\Core\AcymObject; |
| 6 | 6 | |
| 7 | 7 | class HeaderHelper extends AcymObject |
| 8 | 8 | { |
| 9 | - public function display(array $breadcrumb): string | |
| 9 | + public function display(array $breadcrumb): void | |
| 10 | 10 | { |
| 11 | - $header = '<div class="cell large-6 xlarge-7 xxlarge-8 grid-x acym_vcenter">'; | |
| 12 | - $header .= $this->getBreadcrumb($breadcrumb); | |
| 13 | - $header .= '</div>'; | |
| 11 | + $this->displayLastNews(); | |
| 14 | 12 | |
| 15 | - $header .= '<div class="cell large-6 xlarge-5 xxlarge-4 grid-x">'; | |
| 13 | + echo '<div id="acym_header" class="grid-x margin-bottom-1">'; | |
| 14 | + echo '<div class="cell large-6 xlarge-7 xxlarge-8 grid-x acym_vcenter">'; | |
| 15 | + $this->displayBreadcrumb($breadcrumb); | |
| 16 | + echo '</div>'; | |
| 16 | 17 | |
| 17 | - $header .= '<div id="checkVersionArea" class="cell auto grid-x align-right acym_vcenter">'; | |
| 18 | - $header .= $this->checkVersionArea(); | |
| 19 | - $header .= '</div>'; | |
| 18 | + echo '<div class="cell large-6 xlarge-5 xxlarge-4 grid-x">'; | |
| 20 | 19 | |
| 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>'; | |
| 20 | + echo '<div id="checkVersionArea" class="cell auto grid-x align-right acym_vcenter">'; | |
| 21 | + $this->displayVersionArea(); | |
| 22 | + echo '</div>'; | |
| 27 | 23 | |
| 28 | - $header .= '</div>'; | |
| 24 | + echo '<div class="cell shrink grid-x align-right acym_vcenter">'; | |
| 25 | + $this->displayCheckVersionButton(); | |
| 26 | + $this->displayHelpWedButton(); | |
| 27 | + $this->displayDocumentationButton(); | |
| 28 | + $this->displayNotificationCenter(); | |
| 29 | + echo '</div>'; | |
| 29 | 30 | |
| 30 | - $header = '<div id="acym_header" class="grid-x margin-bottom-1">'.$header.'</div>'; | |
| 31 | - | |
| 32 | - return $this->getLastNews().$header; | |
| 31 | + echo '</div>'; | |
| 32 | + echo '</div>'; | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - private function getLastNews(): string | |
| 35 | + public function displayVersionArea(bool $reloading = false): void | |
| 36 | 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->saveConfig( | |
| 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)) { | |
| 53 | - return ''; | |
| 54 | - } | |
| 55 | - | |
| 56 | - $news = @simplexml_load_string($news); | |
| 57 | - if (empty($news->news)) { | |
| 58 | - return ''; | |
| 59 | - } | |
| 60 | - | |
| 61 | - $currentLanguage = acym_getLanguageTag(); | |
| 62 | - $latestNews = null; | |
| 63 | - $doNotRemind = json_decode($this->config->get('remindme', '[]')); | |
| 64 | - | |
| 65 | - foreach ($news->news as $oneNews) { | |
| 66 | - if (!empty($latestNews) && strtotime($latestNews->date) > strtotime($oneNews->date)) break; | |
| 67 | - | |
| 68 | - $language = strtolower($oneNews->language); | |
| 69 | - if (empty($oneNews->published) || ($language != strtolower($currentLanguage) && ($language != 'default' || !empty($latestNews)))) { | |
| 70 | - continue; | |
| 71 | - } | |
| 72 | - | |
| 73 | - if (!empty($oneNews->extension) && strtolower($oneNews->extension) !== 'acymailing') continue; | |
| 74 | - | |
| 75 | - if (!empty($oneNews->cms) && strtolower($oneNews->cms) != strtolower('WordPress')) continue; | |
| 76 | - | |
| 77 | - if (!empty($oneNews->level) && strtolower($oneNews->level) != strtolower($this->config->get('level'))) continue; | |
| 78 | - | |
| 79 | - if (!empty($oneNews->version)) { | |
| 80 | - [$version, $operator] = explode('_', $oneNews->version); | |
| 81 | - if (!version_compare($this->config->get('version'), $version, $operator)) continue; | |
| 82 | - } | |
| 83 | - | |
| 84 | - if (!empty($oneNews->mailermethod)) { | |
| 85 | - $sendMethod = $this->config->get('mailer_method', ''); | |
| 86 | - if ($oneNews->mailermethod !== $sendMethod) continue; | |
| 87 | - } | |
| 88 | - | |
| 89 | - if (in_array($oneNews->name, $doNotRemind)) continue; | |
| 90 | - | |
| 91 | - $latestNews = $oneNews; | |
| 92 | - } | |
| 93 | - | |
| 94 | - if (empty($latestNews)) { | |
| 95 | - return ''; | |
| 96 | - } | |
| 97 | - | |
| 98 | - $newsDisplay = '<div id="acym__header__banner__news" data-news="'.acym_escape($latestNews->name).'">'; | |
| 99 | - $newsDisplay .= $latestNews->content; | |
| 100 | - $newsDisplay .= '</div>'; | |
| 101 | - | |
| 102 | - return $newsDisplay; | |
| 103 | - } | |
| 104 | - | |
| 105 | - private function getBreadcrumb(array $breadcrumb): string | |
| 106 | - { | |
| 107 | - $links = []; | |
| 108 | - foreach ($breadcrumb as $oneLevel => $link) { | |
| 109 | - if (!empty($link)) { | |
| 110 | - $oneLevel = '<a href="'.$link.'">'.$oneLevel.'</a>'; | |
| 111 | - } | |
| 112 | - $links[] = '<li>'.$oneLevel.'</li>'; | |
| 113 | - } | |
| 114 | - | |
| 115 | - if (count($links) > 1) { | |
| 116 | - $links[count($links) - 1] = str_replace('<li>', '<li class="last_link cell shrink"><span class="show-for-sr">Current: </span>', $links[count($links) - 1]); | |
| 117 | - } | |
| 118 | - | |
| 119 | - $header = '<i class="cell shrink acym-logo"></i>'; | |
| 120 | - $header .= '<div id="acym_global_navigation" class="cell auto"> | |
| 121 | - <nav aria-label="You are here:" role="navigation"> | |
| 122 | - <ul class="breadcrumbs grid-x">'.implode('<li class="breadcrumbs__separator"><i class="acymicon-keyboard-arrow-right"></i></li>', $links).'</ul> | |
| 123 | - </nav> | |
| 124 | - </div>'; | |
| 125 | - | |
| 126 | - return $header; | |
| 127 | - } | |
| 128 | - | |
| 129 | - public function checkVersionArea(bool $reloading = false): string | |
| 130 | - { | |
| 131 | 37 | $currentLevel = $this->config->get('level', ''); |
| 132 | 38 | $currentVersion = $this->config->get('version', ''); |
| 133 | 39 | $latestVersion = $this->config->get('latestversion', ''); |
| 134 | 40 | |
| 135 | - $version = '<div id="acym_level_version_area" class="text-right">'; | |
| 136 | - $version .= '<div id="acym_level">'.ACYM_NAME.' '.$currentLevel.' '; | |
| 41 | + echo '<div id="acym_level_version_area" class="text-right">'; | |
| 42 | + echo '<div id="acym_level">'.esc_html(ACYM_NAME.' '.$currentLevel.' '); | |
| 137 | 43 | |
| 138 | 44 | if (version_compare($currentVersion, $latestVersion, '>=')) { |
| 139 | - $version .= acym_tooltip( | |
| 45 | + acym_tooltip( | |
| 140 | 46 | [ |
| 141 | - 'hoveredText' => '<span class="acym__color__green">'.$currentVersion.'</span>', | |
| 47 | + 'hoveredText' => '<span class="acym__color__green">'.esc_html($currentVersion).'</span>', | |
| 142 | 48 | 'textShownInTooltip' => acym_translation('ACYM_UP_TO_DATE'), |
| 143 | 49 | ] |
| 144 | 50 | ); |
| 145 | 51 | } elseif (!empty($latestVersion)) { |
| @@ -147,11 +53,11 @@ | ||
| 147 | 53 | $downloadLink = admin_url().'update-core.php'; |
| 148 | 54 | } else { |
| 149 | 55 | $downloadLink = ACYM_ACYMAILING_WEBSITE.'account/license/" target="_blank'; |
| 150 | 56 | } |
| 151 | - $version .= acym_tooltip( | |
| 57 | + acym_tooltip( | |
| 152 | 58 | [ |
| 153 | - 'hoveredText' => '<span class="acy_updateversion acym__color__red">'.$currentVersion.'</span>', | |
| 59 | + 'hoveredText' => '<span class="acy_updateversion acym__color__red">'.esc_html($currentVersion).'</span>', | |
| 154 | 60 | 'textShownInTooltip' => acym_translationSprintf('ACYM_CLICK_UPDATE', $latestVersion), |
| 155 | 61 | 'titleShownInTooltip' => acym_translation('ACYM_OLD_VERSION'), |
| 156 | 62 | 'link' => $downloadLink, |
| 157 | 63 | ] |
| @@ -157,35 +63,39 @@ | ||
| 157 | 63 | ] |
| 158 | 64 | ); |
| 159 | 65 | } |
| 160 | 66 | |
| 161 | - $version .= '</div></div>'; | |
| 67 | + echo '</div></div>'; | |
| 162 | 68 | |
| 163 | 69 | $expirationDate = $this->config->get('expirationdate', 0); |
| 164 | 70 | if ((empty($expirationDate) || $expirationDate == -1) && empty($this->config->get('acymailer_apikey', ''))) { |
| 165 | - return $version; | |
| 71 | + return; | |
| 166 | 72 | } |
| 167 | 73 | |
| 168 | - $version .= '<div id="acym_expiration" class="cell">'; | |
| 74 | + echo '<div id="acym_expiration" class="cell">'; | |
| 169 | 75 | if (acym_level(ACYM_ESSENTIAL) && ACYM_PRODUCTION) { |
| 170 | 76 | if ($expirationDate == -2) { |
| 171 | - $version .= '<div class="acylicence_expired"> | |
| 77 | + echo '<div class="acylicence_expired"> | |
| 172 | 78 | <a class="acy_attachlicence acymbuttons acym__color__red acym_link_license_tab" |
| 173 | - href="'.acym_completeLink('configuration', false, false, true).'">'.acym_translation('ACYM_ATTACH_LICENCE').'</a> | |
| 79 | + href="'.esc_url(acym_completeLink('configuration', false, false, true)).'">'.esc_html(acym_translation('ACYM_ATTACH_LICENCE')).'</a> | |
| 174 | 80 | </div>'; |
| 175 | 81 | } elseif ($expirationDate < time()) { |
| 176 | - $version .= acym_tooltip( | |
| 82 | + //TODO redirect to the subscription page directly instead of the subscriptions listing | |
| 83 | + // We'll need to return the subscription id when calling the API | |
| 84 | + acym_tooltip( | |
| 177 | 85 | [ |
| 178 | - 'hoveredText' => '<span class="acy_subscriptionexpired acym__color__red">'.acym_translation('ACYM_SUBSCRIPTION_EXPIRED').'</span>', | |
| 86 | + 'hoveredText' => '<span class="acy_subscriptionexpired acym__color__red">'.esc_html(acym_translation('ACYM_SUBSCRIPTION_EXPIRED')).'</span>', | |
| 179 | 87 | 'textShownInTooltip' => acym_translation('ACYM_SUBSCRIPTION_EXPIRED_LINK'), |
| 180 | 88 | 'link' => ACYM_ACYMAILING_WEBSITE.'account/license/', |
| 181 | 89 | ] |
| 182 | 90 | ); |
| 183 | 91 | } else { |
| 184 | - $version .= '<div class="acylicence_valid"> | |
| 185 | - <span class="acy_subscriptionok acym__color__green">'.acym_translationSprintf( | |
| 186 | - 'ACYM_VALID_UNTIL', | |
| 187 | - acym_getDate($expirationDate, acym_translation('ACYM_DATE_FORMAT_LC4')) | |
| 92 | + echo '<div class="acylicence_valid"> | |
| 93 | + <span class="acy_subscriptionok acym__color__green">'.esc_html( | |
| 94 | + acym_translationSprintf( | |
| 95 | + 'ACYM_VALID_UNTIL', | |
| 96 | + acym_getDate($expirationDate, acym_translation('ACYM_DATE_FORMAT_LC4')) | |
| 97 | + ) | |
| 188 | 98 | ).'</span> |
| 189 | 99 | </div>'; |
| 190 | 100 | } |
| 191 | 101 | } |
| @@ -192,71 +102,39 @@ | ||
| 192 | 102 | |
| 193 | 103 | $creditRemainingSendingMethod = ''; |
| 194 | 104 | acym_trigger('onAcymGetCreditRemainingSendingMethod', [&$creditRemainingSendingMethod, $reloading]); |
| 195 | 105 | if (!empty($creditRemainingSendingMethod)) { |
| 196 | - $version .= '<div class="acy_sending_method_credits"> | |
| 197 | - <span>'.$creditRemainingSendingMethod.'</span> | |
| 198 | - </div>'; | |
| 106 | + echo '<div class="acy_sending_method_credits"> | |
| 107 | + <span>'.wp_kses($creditRemainingSendingMethod, [ | |
| 108 | + 'span' => [ | |
| 109 | + 'class' => true, | |
| 110 | + ], | |
| 111 | + 'a' => [ | |
| 112 | + 'href' => true, | |
| 113 | + 'class' => true, | |
| 114 | + 'title' => true, | |
| 115 | + 'target' => true, | |
| 116 | + ], | |
| 117 | + ]).'</span> | |
| 118 | + </div>'; | |
| 199 | 119 | } |
| 200 | 120 | |
| 201 | - $version .= '</div>'; | |
| 202 | - | |
| 203 | - return $version; | |
| 121 | + echo '</div>'; | |
| 204 | 122 | } |
| 205 | 123 | |
| 206 | - private function getCheckVersionButton(): string | |
| 124 | + public function displayNotificationCenter(): void | |
| 207 | 125 | { |
| 208 | - if (ACYM_CMS == 'wordpress' && !acym_level(ACYM_ESSENTIAL)) { | |
| 209 | - return ''; | |
| 210 | - } | |
| 211 | - | |
| 212 | - $lastLicenseCheck = $this->config->get('lastlicensecheck', 0); | |
| 213 | - if (empty($lastLicenseCheck)) { | |
| 214 | - $lastLicenseCheck = time(); | |
| 215 | - } | |
| 216 | - | |
| 217 | - $lastDateFormatted = acym_date($lastLicenseCheck, 'ACYM_DATE_FORMAT_LC2'); | |
| 218 | - | |
| 219 | - return acym_tooltip( | |
| 220 | - [ | |
| 221 | - 'hoveredText' => '<a id="checkVersionButton" type="button" class="grid-x align-center button_header medium-shrink acym_vcenter"><i class="cell shrink acymicon-autorenew"></i></a>', | |
| 222 | - 'textShownInTooltip' => acym_translation('ACYM_LAST_CHECK').' <span id="acym__check__version__last__check">'.$lastDateFormatted.'</span>', | |
| 223 | - ] | |
| 224 | - ); | |
| 225 | - } | |
| 226 | - | |
| 227 | - private function getDocumentationButton(): string | |
| 228 | - { | |
| 229 | - return acym_tooltip( | |
| 230 | - [ | |
| 231 | - '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>', | |
| 232 | - 'textShownInTooltip' => acym_translation('ACYM_DOCUMENTATION'), | |
| 233 | - ] | |
| 234 | - ); | |
| 235 | - } | |
| 236 | - | |
| 237 | - private function getHelpWedButton(): string | |
| 238 | - { | |
| 239 | - if (ACYM_CMS !== 'wordpress' || acym_level(ACYM_ESSENTIAL)) { | |
| 240 | - return ''; | |
| 241 | - } | |
| 242 | - | |
| 243 | - return '<a type="button" class="grid-x align-center button_header medium-shrink acym_vcenter" target="_blank" href="https://wordpress.org/support/plugin/acymailing/"> | |
| 244 | - <i class="cell shrink acymicon-wordpress"></i> | |
| 245 | - </a>'; | |
| 246 | - } | |
| 247 | - | |
| 248 | - public function getNotificationCenter(): string | |
| 249 | - { | |
| 250 | 126 | $notifications = json_decode($this->config->get('notifications', '{}'), true); |
| 251 | 127 | if (!is_array($notifications) || empty($notifications)) { |
| 252 | 128 | $notifications = []; |
| 253 | 129 | } |
| 254 | 130 | $message = ''; |
| 131 | + //if we have a notifications for success | |
| 255 | 132 | $notificationLevel = 0; |
| 256 | - if (!empty($_SESSION['acym_success'])) { | |
| 257 | - $message = $_SESSION['acym_success']; | |
| 258 | - $_SESSION['acym_success'] = ''; | |
| 133 | + $successMessage = acym_getVar('string', 'acym_success', '', 'SESSION'); | |
| 134 | + if (!empty($successMessage)) { | |
| 135 | + $message = $successMessage; | |
| 136 | + acym_setSession('acym_success', ''); | |
| 259 | 137 | $notificationLevel = 1; |
| 260 | 138 | } |
| 261 | 139 | |
| 262 | 140 | if (!empty($notifications)) { |
| @@ -261,94 +139,108 @@ | ||
| 261 | 139 | |
| 262 | 140 | if (!empty($notifications)) { |
| 263 | 141 | foreach ($notifications as $notification) { |
| 264 | 142 | if ($notification['read']) continue; |
| 265 | - if ($notification['level'] == 'info' && $notificationLevel < 2) $notificationLevel = 2; | |
| 266 | - if ($notification['level'] == 'warning' && $notificationLevel < 3) $notificationLevel = 3; | |
| 267 | - if ($notification['level'] == 'error' && $notificationLevel < 4) $notificationLevel = 4; | |
| 143 | + if ($notification['level'] === 'info' && $notificationLevel < 2) $notificationLevel = 2; | |
| 144 | + if ($notification['level'] === 'warning' && $notificationLevel < 3) $notificationLevel = 3; | |
| 145 | + if ($notification['level'] === 'error' && $notificationLevel < 4) $notificationLevel = 4; | |
| 268 | 146 | } |
| 269 | 147 | } |
| 270 | 148 | |
| 271 | 149 | $iconToDisplay = ''; |
| 272 | - $tooltip = ''; | |
| 150 | + $tooltip = false; | |
| 273 | 151 | |
| 274 | 152 | switch ($notificationLevel) { |
| 275 | 153 | case 0: |
| 154 | + // default icon | |
| 276 | 155 | $iconToDisplay = 'acymicon-bell'; |
| 277 | 156 | $notificationLevel = ''; |
| 278 | 157 | break; |
| 279 | 158 | case 1: |
| 159 | + // success | |
| 280 | 160 | $iconToDisplay = 'acymicon-check-circle acym__color__green'; |
| 281 | 161 | $notificationLevel = 'acym__header__notification__button__success acym__header__notification__pulse'; |
| 282 | - $tooltip = 'data-acym-tooltip="'.acym_escape($message).'" data-acym-tooltip-position="left"'; | |
| 162 | + $tooltip = true; | |
| 283 | 163 | break; |
| 284 | 164 | case 2: |
| 165 | + // info | |
| 285 | 166 | $iconToDisplay = 'acymicon-bell acym__color__blue'; |
| 286 | 167 | $notificationLevel = 'acym__header__notification__button__info'; |
| 287 | 168 | break; |
| 288 | 169 | case 3: |
| 170 | + // warning | |
| 289 | 171 | $iconToDisplay = 'acymicon-exclamation-triangle acym__color__orange'; |
| 290 | 172 | $notificationLevel = 'acym__header__notification__button__warning'; |
| 291 | 173 | break; |
| 292 | 174 | case 4: |
| 175 | + // error | |
| 293 | 176 | $iconToDisplay = 'acymicon-exclamation-circle acym__color__red'; |
| 294 | 177 | $notificationLevel = 'acym__header__notification__button__error'; |
| 295 | 178 | break; |
| 296 | 179 | } |
| 297 | 180 | |
| 298 | - $notificationCenter = '<div class="cell grid-x align-center acym_vcenter medium-shrink acym__header__notification '.$notificationLevel.' button_header cursor-pointer" '.$tooltip.'>'; | |
| 299 | - $notificationCenter .= '<i class="'.$iconToDisplay.'"></i>'; | |
| 300 | - $notificationCenter .= '<div class="cell grid-x acym__header__notification__center align-center">'; | |
| 301 | - $notificationCenter .= $this->getNotificationCenterInner($notifications); | |
| 302 | - $notificationCenter .= '</div>'; | |
| 303 | - $notificationCenter .= '</div>'; | |
| 304 | - | |
| 305 | - return $notificationCenter; | |
| 181 | + echo '<div class="cell grid-x align-center acym_vcenter medium-shrink acym__header__notification '.esc_attr($notificationLevel).' button_header cursor-pointer"'; | |
| 182 | + if ($tooltip) { | |
| 183 | + echo ' data-acym-tooltip="'.esc_attr($message).'" data-acym-tooltip-position="left"'; | |
| 184 | + } | |
| 185 | + echo '>'; | |
| 186 | + echo '<i class="'.esc_attr($iconToDisplay).'"></i>'; | |
| 187 | + echo '<div class="cell grid-x acym__header__notification__center align-center">'; | |
| 188 | + $this->displayNotificationCenterInner($notifications); | |
| 189 | + echo '</div>'; | |
| 190 | + echo '</div>'; | |
| 306 | 191 | } |
| 307 | 192 | |
| 308 | - public function getNotificationCenterInner(array $notifications): string | |
| 193 | + public function displayNotificationCenterInner(array $notifications): void | |
| 309 | 194 | { |
| 310 | - $notificationCenter = ''; | |
| 311 | 195 | if (empty($notifications)) { |
| 312 | - $notificationCenter .= '<div class="cell grid-x acym__header__notification__one acym__header__notification__one__empty acym_vcenter">'; | |
| 313 | - $notificationCenter .= '<h2 class="cell text-center">'.acym_translation('ACYM_YOU_DONT_HAVE_NOTIFICATIONS').'</h2>'; | |
| 314 | - $notificationCenter .= '</div>'; | |
| 315 | - } else { | |
| 316 | - $notificationCenter .= '<div class="cell grid-x acym__header__notification__toolbox"><p class="cell auto">'; | |
| 317 | - $notificationCenter .= acym_translation('ACYM_NOTIFICATIONS'); | |
| 318 | - $notificationCenter .= '</p><div class="cell shrink cursor-pointer acym__header__notification__toolbox__remove text-right" data-id="all">'; | |
| 319 | - $notificationCenter .= acym_translation('ACYM_DELETE_ALL'); | |
| 320 | - $notificationCenter .= '</div></div>'; | |
| 321 | - foreach ($notifications as $key => $notif) { | |
| 322 | - $fullMessageHover = $notif['message']; | |
| 196 | + echo '<div class="cell grid-x acym__header__notification__one acym__header__notification__one__empty acym_vcenter">'; | |
| 197 | + echo '<h2 class="cell text-center">'.esc_html(acym_translation('ACYM_YOU_DONT_HAVE_NOTIFICATIONS')).'</h2>'; | |
| 198 | + echo '</div>'; | |
| 323 | 199 | |
| 324 | - if (strlen($notif['message']) > 150) { | |
| 325 | - $tag = new \stdClass(); | |
| 326 | - $tag->wrap = 150; | |
| 200 | + return; | |
| 201 | + } | |
| 327 | 202 | |
| 328 | - $pluginHelper = new PluginHelper(); | |
| 329 | - $notif['message'] = $pluginHelper->wrapText($notif['message'], $tag); | |
| 330 | - } | |
| 331 | - $fullMessageHover = $fullMessageHover != $notif['message'] ? 'data-acym-full="'.acym_escape($fullMessageHover).'"' : ''; | |
| 203 | + echo '<div class="cell grid-x acym__header__notification__toolbox"><p class="cell auto">'; | |
| 204 | + echo esc_html(acym_translation('ACYM_NOTIFICATIONS')); | |
| 205 | + echo '</p><div class="cell shrink cursor-pointer acym__header__notification__toolbox__remove text-right" data-id="all">'; | |
| 206 | + echo esc_html(acym_translation('ACYM_DELETE_ALL')); | |
| 207 | + echo '</div></div>'; | |
| 332 | 208 | |
| 333 | - $logo = $notif['level'] === 'info' ? 'acymicon-bell' : ($notif['level'] == 'warning' ? 'acymicon-exclamation-triangle' : 'acymicon-exclamation-circle'); | |
| 334 | - $read = $notif['read'] ? 'acym__header__notification__one__read' : ''; | |
| 335 | - $notificationCenter .= '<div class="'.$read.' cell grid-x acym__header__notification__one acym_vcenter acym_vcenter acym__header__notification__one__'.$notif['level'].'">'; | |
| 336 | - $notificationCenter .= '<div class="cell small-3 align-center grid-x acym__header__notification__one__icon"><i class="cell '.$logo.'"></i></div>'; | |
| 337 | - $notificationCenter .= '<div class="cell grid-x small-8"><p class="cell acym__header__notification__message" '.$fullMessageHover.'>'.$notif['message']; | |
| 338 | - $notificationCenter .= '<div class="cell acym__header__notification__one__date">'.acym_date($notif['date']).'</div></div>'; | |
| 339 | - $notificationCenter .= '<i class="cell small-1 acym__header__notification__one__delete acymicon-close" data-id="'.acym_escape($key).'"></i>'; | |
| 340 | - $notificationCenter .= '</div>'; | |
| 209 | + foreach ($notifications as $key => $notif) { | |
| 210 | + $fullMessageHover = $notif['message']; | |
| 211 | + | |
| 212 | + if (strlen($notif['message']) > 150) { | |
| 213 | + $tag = new \stdClass(); | |
| 214 | + $tag->wrap = 150; | |
| 215 | + | |
| 216 | + $pluginHelper = new PluginHelper(); | |
| 217 | + $notif['message'] = $pluginHelper->wrapText($notif['message'], $tag); | |
| 341 | 218 | } |
| 219 | + | |
| 220 | + $logo = $notif['level'] === 'info' ? 'acymicon-bell' : ($notif['level'] === 'warning' ? 'acymicon-exclamation-triangle' : 'acymicon-exclamation-circle'); | |
| 221 | + $read = $notif['read'] ? 'acym__header__notification__one__read' : ''; | |
| 222 | + echo '<div class="'.esc_attr($read).' cell grid-x acym__header__notification__one acym_vcenter acym_vcenter acym__header__notification__one__'.esc_attr( | |
| 223 | + $notif['level'] | |
| 224 | + ).'">'; | |
| 225 | + echo '<div class="cell small-3 align-center grid-x acym__header__notification__one__icon"><i class="cell '.esc_attr($logo).'"></i></div>'; | |
| 226 | + echo '<div class="cell grid-x small-8">'; | |
| 227 | + echo '<p class="cell acym__header__notification__message"'; | |
| 228 | + if ($fullMessageHover !== $notif['message']) { | |
| 229 | + echo ' data-acym-full="'.esc_attr($fullMessageHover).'"'; | |
| 230 | + } | |
| 231 | + echo '>'; | |
| 232 | + echo wp_kses($notif['message'], SecurityHelper::ALLOWED_HTML_NOTIFICATION); | |
| 233 | + echo '<div class="cell acym__header__notification__one__date">'.esc_html(acym_date($notif['date'])).'</div></div>'; | |
| 234 | + echo '<i class="cell small-1 acym__header__notification__one__delete acymicon-close" data-id="'.esc_attr($key).'"></i>'; | |
| 235 | + echo '</div>'; | |
| 342 | 236 | } |
| 343 | - | |
| 344 | - return $notificationCenter; | |
| 345 | 237 | } |
| 346 | 238 | |
| 347 | 239 | public function addNotification(object $notif): string |
| 348 | 240 | { |
| 349 | 241 | if ($notif->level === 'success') { |
| 350 | - $_SESSION['acym_success'] = $notif->message; | |
| 242 | + acym_setSession('acym_success', $notif->message); | |
| 351 | 243 | |
| 352 | 244 | return ''; |
| 353 | 245 | } |
| 354 | 246 | |
| @@ -357,10 +249,21 @@ | ||
| 357 | 249 | $notifications = []; |
| 358 | 250 | } |
| 359 | 251 | |
| 360 | 252 | $notif->message = str_replace('<br />', "\r\n", $notif->message); |
| 361 | - $notif->message = strip_tags($notif->message, '<a>'); | |
| 253 | + $notif->message = wp_kses( | |
| 254 | + $notif->message, | |
| 255 | + [ | |
| 256 | + 'a' => [ | |
| 257 | + 'href' => true, | |
| 258 | + 'class' => true, | |
| 259 | + 'id' => true, | |
| 260 | + 'target' => true, | |
| 261 | + ], | |
| 262 | + ] | |
| 263 | + ); | |
| 362 | 264 | |
| 265 | + // Prevent duplicated notifications | |
| 363 | 266 | foreach ($notifications as $key => $oneNotif) { |
| 364 | 267 | if ($oneNotif['message'] === $notif->message && $oneNotif['level'] === $notif->level) unset($notifications[$key]); |
| 365 | 268 | } |
| 366 | 269 | $notifications = array_values($notifications); |
| @@ -372,6 +275,176 @@ | ||
| 372 | 275 | |
| 373 | 276 | $this->config->saveConfig(['notifications' => json_encode($notifications)]); |
| 374 | 277 | |
| 375 | 278 | return $notif->id; |
| 279 | + } | |
| 280 | + | |
| 281 | + private function displayLastNews(): void | |
| 282 | + { | |
| 283 | + $lastNewsCheck = $this->config->get('last_news_check', 0); | |
| 284 | + if ($lastNewsCheck < time() - 7200) { | |
| 285 | + $context = stream_context_create(['http' => ['timeout' => 1]]); | |
| 286 | + $news = @file_get_contents(ACYM_ACYMAILING_WEBSITE.'acymnews.xml', false, $context); | |
| 287 | + $this->config->saveConfig( | |
| 288 | + [ | |
| 289 | + 'last_news_check' => time(), | |
| 290 | + 'last_news' => base64_encode($news), | |
| 291 | + ], | |
| 292 | + false | |
| 293 | + ); | |
| 294 | + } else { | |
| 295 | + $news = $this->config->get('last_news', ''); | |
| 296 | + if (!empty($news)) $news = base64_decode($news); | |
| 297 | + } | |
| 298 | + if (empty($news)) { | |
| 299 | + return; | |
| 300 | + } | |
| 301 | + | |
| 302 | + $news = @simplexml_load_string($news); | |
| 303 | + if (empty($news->news)) { | |
| 304 | + return; | |
| 305 | + } | |
| 306 | + | |
| 307 | + $currentLanguage = acym_getLanguageTag(); | |
| 308 | + $latestNews = null; | |
| 309 | + $doNotRemind = json_decode($this->config->get('remindme', '[]')); | |
| 310 | + | |
| 311 | + foreach ($news->news as $oneNews) { | |
| 312 | + // If we found a news more recent, it means we found the latest available one | |
| 313 | + if (!empty($latestNews) && strtotime($latestNews->date) > strtotime($oneNews->date)) break; | |
| 314 | + | |
| 315 | + // If the news isn't published or that the language isn't correct, leave | |
| 316 | + $language = strtolower($oneNews->language); | |
| 317 | + if (empty($oneNews->published) || ($language != strtolower($currentLanguage) && ($language != 'default' || !empty($latestNews)))) { | |
| 318 | + continue; | |
| 319 | + } | |
| 320 | + | |
| 321 | + // If the extension isn't correct, leave | |
| 322 | + if (!empty($oneNews->extension) && strtolower($oneNews->extension) !== 'acymailing') continue; | |
| 323 | + | |
| 324 | + // If the CMS isn't correct, leave | |
| 325 | + if (!empty($oneNews->cms) && strtolower($oneNews->cms) != strtolower('WordPress')) continue; | |
| 326 | + | |
| 327 | + // If the level of the extension isn't correct, leave | |
| 328 | + if (!empty($oneNews->level) && strtolower($oneNews->level) != strtolower($this->config->get('level'))) continue; | |
| 329 | + | |
| 330 | + // If the version of the extension isn't correct, leave | |
| 331 | + if (!empty($oneNews->version)) { | |
| 332 | + [$version, $operator] = explode('_', $oneNews->version); | |
| 333 | + if (!version_compare($this->config->get('version'), $version, $operator)) continue; | |
| 334 | + } | |
| 335 | + | |
| 336 | + if (!empty($oneNews->mailermethod)) { | |
| 337 | + $sendMethod = $this->config->get('mailer_method', ''); | |
| 338 | + if ($oneNews->mailermethod !== $sendMethod) continue; | |
| 339 | + } | |
| 340 | + | |
| 341 | + if (in_array($oneNews->name, $doNotRemind)) continue; | |
| 342 | + | |
| 343 | + $latestNews = $oneNews; | |
| 344 | + } | |
| 345 | + | |
| 346 | + if (empty($latestNews)) { | |
| 347 | + return; | |
| 348 | + } | |
| 349 | + | |
| 350 | + echo '<div id="acym__header__banner__news" data-news="'.esc_attr($latestNews->name).'">'; | |
| 351 | + echo wp_kses( | |
| 352 | + $latestNews->content, | |
| 353 | + [ | |
| 354 | + 'style' => [ | |
| 355 | + 'type' => true, | |
| 356 | + ], | |
| 357 | + 'div' => [ | |
| 358 | + 'class' => true, | |
| 359 | + 'title' => true, | |
| 360 | + ], | |
| 361 | + 'b' => [], | |
| 362 | + 'a' => [ | |
| 363 | + 'href' => true, | |
| 364 | + 'target' => true, | |
| 365 | + ], | |
| 366 | + ] | |
| 367 | + ); | |
| 368 | + echo '</div>'; | |
| 369 | + } | |
| 370 | + | |
| 371 | + private function displayBreadcrumb(array $breadcrumb): void | |
| 372 | + { | |
| 373 | + echo '<i class="cell shrink acym-logo"></i>'; | |
| 374 | + echo '<div id="acym_global_navigation" class="cell auto"> | |
| 375 | + <nav aria-label="You are here:" role="navigation"> | |
| 376 | + <ul class="breadcrumbs grid-x">'; | |
| 377 | + $i = 0; | |
| 378 | + foreach ($breadcrumb as $oneLevel => $link) { | |
| 379 | + if ($i !== 0) { | |
| 380 | + echo '<li class="breadcrumbs__separator"><i class="acymicon-keyboard-arrow-right"></i></li>'; | |
| 381 | + } | |
| 382 | + | |
| 383 | + if (count($breadcrumb) > 1 && $i === count($breadcrumb) - 1) { | |
| 384 | + echo '<li class="last_link cell shrink"><span class="show-for-sr">Current: </span>'; | |
| 385 | + } else { | |
| 386 | + echo '<li>'; | |
| 387 | + } | |
| 388 | + | |
| 389 | + if (!empty($link)) { | |
| 390 | + echo '<a href="'.esc_url($link).'">'; | |
| 391 | + } | |
| 392 | + echo esc_html($oneLevel); | |
| 393 | + if (!empty($link)) { | |
| 394 | + echo '</a>'; | |
| 395 | + } | |
| 396 | + echo '</li>'; | |
| 397 | + | |
| 398 | + $i++; | |
| 399 | + } | |
| 400 | + echo '</ul> | |
| 401 | + </nav> | |
| 402 | + </div>'; | |
| 403 | + } | |
| 404 | + | |
| 405 | + private function displayCheckVersionButton(): void | |
| 406 | + { | |
| 407 | + if (ACYM_CMS == 'wordpress' && !acym_level(ACYM_ESSENTIAL)) { | |
| 408 | + return; | |
| 409 | + } | |
| 410 | + | |
| 411 | + $lastLicenseCheck = $this->config->get('lastlicensecheck', 0); | |
| 412 | + if (empty($lastLicenseCheck)) { | |
| 413 | + $lastLicenseCheck = time(); | |
| 414 | + } | |
| 415 | + | |
| 416 | + $lastDateFormatted = acym_date($lastLicenseCheck, 'ACYM_DATE_FORMAT_LC2'); | |
| 417 | + | |
| 418 | + acym_tooltip( | |
| 419 | + [ | |
| 420 | + 'hoveredText' => '<a id="checkVersionButton" type="button" class="grid-x align-center button_header medium-shrink acym_vcenter"><i class="cell shrink acymicon-autorenew"></i></a>', | |
| 421 | + 'textShownInTooltip' => esc_html(acym_translation('ACYM_LAST_CHECK')).' <span id="acym__check__version__last__check">'.esc_html( | |
| 422 | + $lastDateFormatted | |
| 423 | + ).'</span>', | |
| 424 | + ] | |
| 425 | + ); | |
| 426 | + } | |
| 427 | + | |
| 428 | + private function displayHelpWedButton(): void | |
| 429 | + { | |
| 430 | + if (ACYM_CMS !== 'wordpress' || acym_level(ACYM_ESSENTIAL)) { | |
| 431 | + return; | |
| 432 | + } | |
| 433 | + | |
| 434 | + echo '<a type="button" class="grid-x align-center button_header medium-shrink acym_vcenter" target="_blank" href="https://wordpress.org/support/plugin/acymailing/"> | |
| 435 | + <i class="cell shrink acymicon-wordpress"></i> | |
| 436 | + </a>'; | |
| 437 | + } | |
| 438 | + | |
| 439 | + private function displayDocumentationButton(): void | |
| 440 | + { | |
| 441 | + acym_tooltip( | |
| 442 | + [ | |
| 443 | + 'hoveredText' => '<a type="button" class="grid-x align-center button_header medium-shrink acym_vcenter" target="_blank" href="'.esc_url( | |
| 444 | + ACYM_DOCUMENTATION | |
| 445 | + ).'"><i class="cell shrink acymicon-book"></i></a>', | |
| 446 | + 'textShownInTooltip' => acym_translation('ACYM_DOCUMENTATION'), | |
| 447 | + ] | |
| 448 | + ); | |
| 376 | 449 | } |
| 377 | 450 | } |