PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
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
← All changes | front/FrontControllers/ArchiveController.php +75 -3 10.1.4 → 11.1.0 View file →
@@ -2,10 +2,13 @@
2 2
3 3 namespace AcyMailing\FrontControllers;
4 4
5 5 use AcyMailing\Classes\CampaignClass;
6 +use AcyMailing\Classes\HistoryClass;
6 7 use AcyMailing\Classes\MailArchiveClass;
8 +use AcyMailing\Classes\MailClass;
7 9 use AcyMailing\Classes\UserClass;
10 +use AcyMailing\Classes\UserStatClass;
8 11 use AcyMailing\Helpers\EditorHelper;
9 12 use AcyMailing\Helpers\MailerHelper;
10 13 use AcyMailing\Helpers\PaginationHelper;
11 14 use AcyMailing\Core\AcymController;
@@ -37,9 +40,9 @@
37 40 $isPopup = acym_getVar('int', 'is_popup', 0);
38 41
39 42 $mailArchiveClass = new MailArchiveClass();
40 43 $oneMail = $mailArchiveClass->getOneByMailId($mailId);
41 - if (empty($oneMail)) {
44 + if (empty($oneMail) && $this->canViewMailOnline($mailId)) {
42 45 $mailerHelper = new MailerHelper();
43 46 $oneMail = $mailerHelper->load($mailId);
44 47 }
45 48
@@ -52,8 +55,9 @@
52 55 acym_addMetadata('og:url', acym_frontendLink('archive&task=view&id='.$mailId));
53 56 acym_addMetadata('og:title', $oneMail->subject);
54 57 acym_setPageTitle($oneMail->subject);
55 58
59 + // Replace the user Dtexts for the preview if the key/userid here
56 60 $userKeys = acym_getVar('string', 'userid', 0);
57 61 if (!empty($userKeys)) {
58 62 $userId = intval(substr($userKeys, 0, strpos($userKeys, '-')));
59 63 $userKey = substr($userKeys, strpos($userKeys, '-') + 1);
@@ -72,13 +76,16 @@
72 76 }
73 77
74 78 acym_trigger('replaceUserInformation', [&$oneMail, &$receiver, false]);
75 79
80 + // If there is the unsubscribe link for elastic email
76 81 preg_match('@href="{unsubscribe:(.*)}"@', $oneMail->body, $match);
77 82 if (!empty($match)) {
83 + //We replace the tag by the url
78 84 $oneMail->body = str_replace($match[0], 'href="'.$match[1].'"', $oneMail->body);
79 85 }
80 86
87 + // Add foundation for email CSS only for D&D emails
81 88 if (strpos($oneMail->body, 'acym__wysid__template') !== false) {
82 89 acym_addStyle(false, ACYM_CSS.'libraries/foundation_email.min.css?v='.filemtime(ACYM_MEDIA.'css'.DS.'libraries'.DS.'foundation_email.min.css'));
83 90 }
84 91 acym_addStyle(true, acym_getEmailCssFixes());
@@ -85,9 +92,9 @@
85 92 if (!empty($oneMail->stylesheet)) {
86 93 acym_addStyle(true, $oneMail->stylesheet);
87 94 }
88 95 $editorHelper = new EditorHelper();
89 - $settings = json_decode($oneMail->settings, true);
96 + $settings = json_decode($oneMail->settings ?? '[]', true);
90 97 if (!empty($settings)) {
91 98 $settings = $editorHelper->getSettingsStyle($settings);
92 99
93 100 if (!empty($settings)) {
@@ -94,8 +101,9 @@
94 101 acym_addStyle(true, $settings);
95 102 }
96 103 }
97 104
105 + // Make sure the background image works on the archive
98 106 $oneMail->body = preg_replace('#background\-image: url\("([^)]*)"\)#Uis', 'background-image: url($1)', $oneMail->body);
99 107
100 108 $data = [
101 109 'mail' => $oneMail,
@@ -104,11 +112,72 @@
104 112
105 113 acym_includeHeaders();
106 114 parent::display($data);
107 115
116 + // We are forced to use exit because of WordPress that displays a 0 if an exit isn't used
108 117 if ($isPopup || 'wordpress' === ACYM_CMS) exit;
109 118 }
110 119
120 + private function canViewMailOnline(int $mailId): bool
121 + {
122 + if (empty($mailId)) {
123 + return false;
124 + }
125 +
126 + $mailClass = new MailClass();
127 + if ($mailClass->hasUserAccess($mailId)) {
128 + return true;
129 + }
130 +
131 + $campaignClass = new CampaignClass();
132 + $campaign = $campaignClass->getOneByMailId($mailId);
133 + if (
134 + !empty($campaign)
135 + && (int)$campaign->visible === 1
136 + && (int)$campaign->active === 1
137 + && (int)$campaign->sent === 1
138 + ) {
139 + return true;
140 + }
141 +
142 + $userKeys = acym_getVar('string', 'userid', '');
143 + $separatorPosition = strpos($userKeys, '-');
144 + if ($separatorPosition === false) {
145 + return false;
146 + }
147 +
148 + $userId = intval(substr($userKeys, 0, $separatorPosition));
149 + $userKey = substr($userKeys, $separatorPosition + 1);
150 + if (empty($userId) || empty($userKey)) {
151 + return false;
152 + }
153 +
154 + $historyClass = new HistoryClass();
155 + $userHistory = $historyClass->getHistoryOfOneById($userId);
156 + foreach ($userHistory as $userHistoryItem) {
157 + if ((int)$userHistoryItem->mail_id === $mailId && $userHistoryItem->action === 'test_sent') {
158 + return true;
159 + }
160 + }
161 +
162 + acym_setVar('id', $userId);
163 + acym_setVar('key', $userKey);
164 + $userClass = new UserClass();
165 + $user = $userClass->identify(true);
166 +
167 + if (empty($user)) {
168 + return false;
169 + }
170 +
171 + if (!empty($user->cms_id) && $mailClass->hasUserAccess($mailId, false, $user->cms_id)) {
172 + return true;
173 + }
174 +
175 + $userStatClass = new UserStatClass();
176 +
177 + return $userStatClass->hasUserReceivedMail($mailId, $userId);
178 + }
179 +
111 180 public function listing(): void
112 181 {
113 182 acym_setVar('layout', 'listing');
114 183
@@ -113,8 +182,9 @@
113 182 acym_setVar('layout', 'listing');
114 183
115 184 $search = acym_getVar('string', 'acym_search', '');
116 185
186 + // Get the Joomla menu parameters
117 187 $menu = acym_getMenu();
118 188 if (!is_object($menu)) {
119 189 acym_redirect(acym_rootURI());
120 190
@@ -122,8 +192,9 @@
122 192 }
123 193 $params = method_exists($menu, 'getParams') ? $menu->getParams() : $menu->params;
124 194 $menuParams = new AcymParameter($params);
125 195
196 + // Handle the core Joomla params
126 197 $paramsJoomla = [];
127 198 $paramsJoomla['suffix'] = $menuParams->get('pageclass_sfx', '');
128 199 $paramsJoomla['page_heading'] = $menuParams->get('page_heading');
129 200 $paramsJoomla['show_page_heading'] = $menuParams->get('show_page_heading', 0);
@@ -139,8 +210,9 @@
139 210 if ($menuParams->get('robots')) {
140 211 acym_addMetadata('robots', $menuParams->get('robots'));
141 212 }
142 213
214 + // Initialize our own params then call the generic view
143 215 $nbNewslettersPerPage = $menuParams->get('archiveNbNewslettersPerPage', 10);
144 216 $listsSent = $menuParams->get('lists', '');
145 217 $popup = $menuParams->get('popup', '1');
146 218 $displayUserListOnly = $menuParams->get('displayUserListOnly', '1');
@@ -193,9 +265,9 @@
193 265 if (!empty($viewParams['displayUserListOnly'])) {
194 266 $params['displayUserListOnly'] = $viewParams['displayUserListOnly'];
195 267 }
196 268
197 - $params['page'] = $this->getVarFiltersListing('int', 'archive_pagination_page', 1);
269 + $params['page'] = max(1, $this->getVarFiltersListing('int', 'archive_pagination_page', 1));
198 270 $campaignClass = new CampaignClass();
199 271 $pagination = new PaginationHelper();
200 272 $params['numberPerPage'] = (int)$viewParams['nbNewslettersPerPage'];
201 273