PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.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
← All changes | back/dynamics/subscription/SubscriptionInsertion.php +0 -694 10.10.2 → 11.1.1 View file →
@@ -1,694 +1,0 @@
1 -<?php
2 -
3 -use AcyMailing\Classes\CampaignClass;
4 -use AcyMailing\Classes\MailClass;
5 -use AcyMailing\Classes\UserClass;
6 -use AcyMailing\Classes\ListClass;
7 -
8 -trait SubscriptionInsertion
9 -{
10 - private $addedListUnsubscribe = [];
11 - private $lists = [];
12 - private $listsowner = [];
13 - private $listsinfo = [];
14 - private $unsubscribeLink = [];
15 - private $mailLists = [];
16 - private $userClass = null;
17 -
18 - public function dynamicText(?int $mailId): ?object
19 - {
20 - return $this->pluginDescription;
21 - }
22 -
23 - public function textPopup(): void
24 - {
25 - $others = [];
26 - $others['unsubscribe'] = ['name' => acym_translation('ACYM_UNSUBSCRIBE_LINK'), 'default' => 'ACYM_UNSUBSCRIBE'];
27 - $others['unsubscribeall'] = ['name' => acym_translation('ACYM_UNSUBSCRIBE_ALL_LISTS_LINK'), 'default' => 'ACYM_UNSUBSCRIBE_ALL_LISTS'];
28 - $others['direct_unsubscribe'] = ['name' => acym_translation('ACYM_DIRECT_UNSUBSCRIBE_LINK'), 'default' => 'ACYM_UNSUBSCRIBE'];
29 - $others['confirm'] = ['name' => acym_translation('ACYM_CONFIRM_SUBSCRIPTION_LINK'), 'default' => 'ACYM_CONFIRM_SUBSCRIPTION'];
30 - $others['subscribe'] = ['name' => acym_translation('ACYM_SUBSCRIBE_LINK'), 'default' => 'ACYM_SUBSCRIBE'];
31 -
32 - ?>
33 - <script type="text/javascript">
34 - let openedLists = false;
35 - let openedDirectUnsubscribeRedirect = false;
36 - let openedUnsubscribeAllRedirect = false;
37 - let selectedSubscriptionDText = '';
38 -
39 - function changeSubscriptionTag(tagName) {
40 - selectedSubscriptionDText = tagName;
41 - let defaultText = [];
42 - <?php
43 - foreach ($others as $tagname => $tag) {
44 - echo 'defaultText["'.$tagname.'"] = "'.acym_translation($tag['default'], true).'";';
45 - }
46 - ?>
47 - jQuery('.selected_row').removeClass('selected_row');
48 - jQuery('#tr_' + tagName).addClass('selected_row');
49 - jQuery('#acym__popup__subscription__tagtext').val(defaultText[tagName]);
50 - setSubscriptionTag();
51 - }
52 -
53 - function setSubscriptionTag() {
54 - if (openedLists && selectedSubscriptionDText !== 'subscribe') {
55 - jQuery('#acym__popup__plugin__subscription__lists__modal').slideUp();
56 - jQuery('#select_lists_zone').hide();
57 - openedLists = false;
58 - }
59 - if (openedDirectUnsubscribeRedirect && selectedSubscriptionDText !== 'direct_unsubscribe') {
60 - jQuery('#acym__popup__plugin__direct_unsubscribe__modal').slideUp();
61 - openedDirectUnsubscribeRedirect = false;
62 - }
63 - if (openedUnsubscribeAllRedirect && selectedSubscriptionDText !== 'unsubscribeall') {
64 - jQuery('#acym__popup__plugin__unsubscribeall__modal').slideUp();
65 - openedUnsubscribeAllRedirect = false;
66 - }
67 -
68 - let tag = '{' + selectedSubscriptionDText;
69 - let lists = jQuery('#acym__popup__subscription__listids');
70 -
71 - if ('subscribe' === selectedSubscriptionDText) {
72 - tag += '|lists:' + lists.html();
73 - }
74 -
75 - if (selectedSubscriptionDText === 'direct_unsubscribe') {
76 - let redirect = jQuery('#acym__popup__direct_unsubscribe__redirect').val();
77 - if (redirect) tag += '|redirect:' + encodeURIComponent(redirect);
78 - } else if (selectedSubscriptionDText === 'unsubscribeall') {
79 - let redirect = jQuery('#acym__popup__unsubscribeall__redirect').val();
80 - if (redirect) tag += '|redirect:' + encodeURIComponent(redirect);
81 - }
82 -
83 - tag += '}' + jQuery('#acym__popup__subscription__tagtext').val() + '{/' + selectedSubscriptionDText + '}';
84 - setTag(tag, jQuery('#tr_' + selectedSubscriptionDText));
85 - }
86 -
87 - function displayLists() {
88 - if (openedLists) return;
89 - openedLists = true;
90 -
91 - jQuery.acymModal();
92 - jQuery('#acym__popup__plugin__subscription__lists__modal').slideDown();
93 - jQuery('#select_lists_zone').toggle();
94 -
95 - jQuery('#acym__popup__subscription__change').off('change').on('change', function () {
96 - const lists = JSON.parse(jQuery('#acym__modal__lists-selected').val());
97 - jQuery('#acym__popup__subscription__listids').html(lists.join());
98 - changeSubscriptionTag('subscribe');
99 - });
100 - }
101 -
102 - function displayDirectUnsubscribeRedirect() {
103 - if (openedDirectUnsubscribeRedirect) return;
104 - openedDirectUnsubscribeRedirect = true;
105 - jQuery('#acym__popup__plugin__direct_unsubscribe__modal').slideDown();
106 -
107 - jQuery('#acym__popup__direct_unsubscribe__redirect').off('input').on('input', function () {
108 - let redirectLink = jQuery(this).val();
109 - jQuery('#acym__popup__direct_unsubscribe__preview').html(redirectLink);
110 - changeSubscriptionTag('direct_unsubscribe');
111 - });
112 - }
113 -
114 - function displayUnsubscribeAllRedirect() {
115 - if (openedUnsubscribeAllRedirect) return;
116 - openedUnsubscribeAllRedirect = true;
117 - jQuery('#acym__popup__plugin__unsubscribeall__modal').slideDown();
118 -
119 - jQuery('#acym__popup__unsubscribeall__redirect').off('input').on('input', function () {
120 - let redirectLink = jQuery(this).val();
121 - jQuery('#acym__popup__unsubscribeall__preview').html(redirectLink);
122 - changeSubscriptionTag('unsubscribeall');
123 - });
124 - }
125 - </script>
126 - <?php
127 - $text = '<div class="acym__popup__listing text-center grid-x">
128 - <h1 class="acym__title acym__title__secondary text-center cell">'.acym_translation('ACYM_SUBSCRIPTION').'</h1>
129 - <div class="grid-x medium-12 cell acym__row__no-listing text-left acym_vcenter">
130 - <div class="grid-x cell medium-5 small-12 acym__listing__title acym__listing__title__dynamics acym__subscription__subscription acym_vcenter">
131 - <label class="small-3 margin-bottom-0" for="acym__popup__subscription__tagtext">'.acym_translation('ACYM_TEXT').': </label>
132 - <input class="small-9" type="text" name="tagtext" id="acym__popup__subscription__tagtext" onchange="setSubscriptionTag();">
133 - </div>
134 - <div class="medium-1"></div>
135 - <div style="display: none;" id="select_lists_zone" class="grid-x cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">
136 - <p class="shrink" id="acym__popup__subscription__text__list">'.acym_translation('ACYM_LISTS_SELECTED').'</p>
137 - <p class="shrink" id="acym__popup__subscription__listids"></p>
138 - </div>
139 - </div>';
140 - $text .= '
141 - <div class="cell grid-x">';
142 -
143 - foreach ($others as $tagname => $tag) {
144 - $onclick = "changeSubscriptionTag('".$tagname."');";
145 - if ($tagname == 'subscribe') {
146 - $onclick .= 'displayLists();return false;';
147 - } elseif ($tagname == 'direct_unsubscribe') {
148 - $onclick .= 'displayDirectUnsubscribeRedirect();return false;';
149 - } elseif ($tagname == 'unsubscribeall') {
150 - $onclick .= 'displayUnsubscribeAllRedirect();return false;';
151 - }
152 - $text .= '<div class="grid-x small-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="'.$onclick.'" id="tr_'.$tagname.'" >';
153 - $text .= '<div class="cell small-12 acym__listing__title acym__listing__title__dynamics">'.$tag['name'].'</div>';
154 - $text .= '</div>';
155 - }
156 - $text .= '</div>
157 - <div class="medium-1"></div>
158 - <div class="medium-10 text-left">';
159 - $text .= acym_modalPaginationLists(
160 - 'acym__popup__subscription__change',
161 - ''
162 - );
163 - $text .= '
164 - <div style="display: none;" id="acym__popup__plugin__direct_unsubscribe__modal" class="grid-x cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">
165 - <label>'.acym_translation('ACYM_REDIRECTION_URL').'</label>
166 - <input type="text" id="acym__popup__direct_unsubscribe__redirect" placeholder="https://example.com/unsubscribed" />
167 - <p id="acym__popup__direct_unsubscribe__preview" class="acym_smalltext text-gray"></p>
168 - </div>';
169 -
170 - $text .= '
171 - <div style="display: none;" id="acym__popup__plugin__unsubscribeall__modal" class="grid-x cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">
172 - <label>'.acym_translation('ACYM_REDIRECTION_URL').'</label>
173 - <input type="text" id="acym__popup__unsubscribeall__redirect" placeholder="https://example.com/all-unsubscribed" />
174 - <p id="acym__popup__unsubscribeall__preview" class="acym_smalltext text-gray"></p>
175 - </div>';
176 - $text .= ' </div>
177 - <div class="medium-1"></div>
178 - </div>';
179 -
180 - $others = [];
181 - $others['name'] = acym_translation('ACYM_LIST_NAME');
182 - $others['description'] = acym_translation('ACYM_LIST_DESCRIPTION');
183 - $others['names'] = acym_translation('ACYM_LIST_NAMES');
184 - $others['descriptions'] = acym_translation('ACYM_LIST_DESCRIPTIONS');
185 - $others['id'] = acym_translation('ACYM_LIST_ID', true);
186 -
187 - $text .= '<div class="acym__popup__listing text-center grid-x">
188 - <h1 class="acym__title acym__title__secondary text-center cell">'.acym_translation('ACYM_LIST').'</h1>
189 - <div class="cell grid-x">';
190 -
191 - foreach ($others as $tagname => $tag) {
192 - $text .= '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriptionTag(\'list\');setTag(\'{list:'.$tagname.'}\', jQuery(this));" id="tr_'.$tagname.'">
193 - <div class="cell medium-12 small-12 acym__listing__title acym__listing__title__dynamics">'.$tag.'</div>
194 - </div>';
195 - }
196 -
197 - $text .= '</div></div>';
198 -
199 - $text .= '<div class="acym__popup__listing text-center grid-x">
200 - <span class="acym__title acym__title__secondary text-center cell">'.acym_translation('ACYM_CAMPAIGN').'</span>
201 - <div class="cell grid-x">';
202 - $othersMail = ['campaignid', 'subject'];
203 -
204 - foreach ($othersMail as $tag) {
205 - $text .= '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriptionTag(\'mail\');setTag(\'{mail:'.$tag.'}\', jQuery(this));" id="tr_'.$tag.'">
206 - <div class="cell medium-12 small-12 acym__listing__title acym__listing__title__dynamics">'.$tag.'</div>
207 - </div>';
208 - }
209 - $text .= '</div></div>';
210 -
211 - $text .= '<div class="acym__popup__listing text-center grid-x">
212 - <span class="acym__title acym__title__secondary text-center cell">'.acym_translation('ACYM_AUTO').' '.acym_translation('ACYM_CAMPAIGNS').'</span>
213 - <div class="cell grid-x">';
214 - $autoMail = ['number_generated' => ['name' => acym_translation('ACYM_ISSUE_NB'), 'default' => '#1']];
215 -
216 - foreach ($autoMail as $tag => $oneTag) {
217 - $tagInserted = $tag;
218 - if (!empty($oneTag['default'])) $tagInserted = $tag.'|default:'.$oneTag['default'];
219 - $text .= '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriptionTag(\'automail\');setTag(\'{automail:'.$tagInserted.'}\', jQuery(this));" id="tr_'.$tag.'">
220 - <div class="cell medium-12 small-12 acym__listing__title acym__listing__title__dynamics">'.$oneTag['name'].'</div>
221 - </div>';
222 - }
223 - $text .= '</div></div>';
224 -
225 - echo $text;
226 - }
227 -
228 - public function replaceUserInformation(object &$email, ?object &$user, bool $send = true): void
229 - {
230 - if (empty($email->id)) {
231 - return;
232 - }
233 - $this->replacelisttags($email, $user, $send);
234 -
235 - if (empty($user->id) || !empty($this->addedListUnsubscribe[$email->id][$user->id])) return;
236 - if (empty($this->unsubscribeLink[$email->id]) || !method_exists($email, 'addCustomHeader')) return;
237 -
238 -
239 - $this->addedListUnsubscribe[$email->id][$user->id] = true;
240 -
241 - $mailto = '';
242 - if ($this->config->get('auto_bounce', 0)) {
243 - $mailto = $this->config->get('bounce_email');
244 - }
245 - if (empty($mailto)) {
246 - $mailto = empty($email->replyemail) ? $this->config->get('replyto_email') : $email->replyemail;
247 - }
248 -
249 - if (empty($mailto)) {
250 - return;
251 - }
252 -
253 - $body = 'Please%20unsubscribe%20user%20ID%20'.$user->id;
254 -
255 - if (!isset($this->mailLists[$email->id])) {
256 - $mailClass = new MailClass();
257 - $lists = $mailClass->getAllListsByMailId($email->id);
258 - $this->mailLists[$email->id] = empty($lists) ? null : array_keys($lists);
259 - }
260 -
261 - if (!empty($this->mailLists[$email->id])) {
262 - $userClass = $this->getUserClass();
263 - $userLists = $userClass->getSubscriptionStatus($user->id, [], UserClass::STATUS_SUBSCRIBED);
264 - if (!empty($userLists)) {
265 - $commonLists = array_intersect($this->mailLists[$email->id], array_keys($userLists));
266 -
267 - if (!empty($commonLists)) {
268 - $body .= '%20from%20list(s)%20'.implode(',', $commonLists).'.';
269 - }
270 - }
271 - }
272 -
273 - $unsubscribeLink = str_replace(
274 - ['{subscriber:id}', '{subscriber:key|urlencode}'],
275 - [$user->id, urlencode($user->key)],
276 - $this->unsubscribeLink[$email->id]
277 - );
278 - $email->addCustomHeader('List-Unsubscribe', '<'.$unsubscribeLink.'&ajax=1>, <mailto:'.$mailto.'?subject=unsubscribe_user_'.$user->id.'&body='.$body.'>');
279 - $email->addCustomHeader('List-Unsubscribe-Post', 'List-Unsubscribe=One-Click');
280 - }
281 -
282 - public function replaceContent(object &$email): void
283 - {
284 - $this->replaceSubscriptionTags($email);
285 - $this->replacemailtags($email);
286 - $this->replaceAutomailTags($email);
287 - }
288 -
289 - private function replacemailtags(&$email)
290 - {
291 - $result = $this->pluginHelper->extractTags($email, 'mail');
292 - $tags = [];
293 -
294 - foreach ($result as $key => $oneTag) {
295 - if (isset($tags[$key])) {
296 - continue;
297 - }
298 -
299 - $field = $oneTag->id;
300 - if (!empty($email) && !empty($email->$field)) {
301 - $text = $email->$field;
302 - $this->pluginHelper->formatString($text, $oneTag);
303 - $tags[$key] = $text;
304 - } elseif (substr($field, 0, 8) == 'campaign') {
305 - $this->getCampaignTags($email, $tags, $oneTag, $key);
306 - } else {
307 - $tags[$key] = $oneTag->default;
308 - }
309 - }
310 -
311 - $this->pluginHelper->replaceTags($email, $tags);
312 - }
313 -
314 - private function getCampaignTags(&$email, &$tags, $oneTag, $key)
315 - {
316 - $campaignClass = new CampaignClass();
317 - $campaignFromMail = $campaignClass->getOneCampaignByMailId($email->id);
318 - $campaignField = substr($oneTag->id, 8);
319 - if (!empty($campaignFromMail) && !empty($campaignFromMail->$campaignField)) {
320 - $text = $campaignFromMail->$campaignField;
321 - $this->pluginHelper->formatString($text, $oneTag);
322 - $tags[$key] = $text;
323 - } else {
324 - $tags[$key] = $oneTag->default;
325 - }
326 - }
327 -
328 - private function replaceAutomailTags(&$email)
329 - {
330 - $result = $this->pluginHelper->extractTags($email, 'automail');
331 - $tags = [];
332 -
333 - foreach ($result as $key => $oneTag) {
334 - if (isset($tags[$key])) {
335 - continue;
336 - }
337 -
338 - $field = $oneTag->id;
339 -
340 - $campaignClass = new CampaignClass();
341 - $autoCampaignFromMail = $campaignClass->getAutoCampaignFromGeneratedMailId($email->id);
342 -
343 - if (!empty($autoCampaignFromMail) && !empty($autoCampaignFromMail->sending_params[$field])) {
344 - $text = $autoCampaignFromMail->sending_params[$field];
345 - $this->pluginHelper->formatString($text, $oneTag);
346 - $tags[$key] = $text;
347 - } else {
348 - $tags[$key] = $oneTag->default;
349 - }
350 - }
351 -
352 - $this->pluginHelper->replaceTags($email, $tags);
353 - }
354 -
355 - private function replacelisttags(&$email, &$user, $send)
356 - {
357 - $tags = $this->pluginHelper->extractTags($email, 'list');
358 - if (empty($tags)) {
359 - return;
360 - }
361 -
362 - $replaceTags = [];
363 - foreach ($tags as $oneTag => $parameter) {
364 - $method = 'list'.trim(strtolower($parameter->id));
365 -
366 - if (method_exists($this, $method)) {
367 - $replaceTags[$oneTag] = $this->$method($email, $user, $parameter);
368 - } else {
369 - $replaceTags[$oneTag] = 'Method not found: '.$method;
370 - }
371 - }
372 -
373 - $this->pluginHelper->replaceTags($email, $replaceTags, true);
374 - }
375 -
376 - private function getAttachedListid($email, $subid)
377 - {
378 - $mailid = $email->id;
379 -
380 - if (isset($this->lists[$mailid][$subid])) {
381 - return $this->lists[$mailid][$subid];
382 - }
383 -
384 - $mailClass = new MailClass();
385 - $mailLists = array_keys($mailClass->getAllListsByMailId($mailid));
386 - $userLists = [];
387 -
388 - if (!empty($subid)) {
389 - $userClass = $this->getUserClass();
390 - $userLists = $userClass->getUserSubscriptionById($subid, 'id', false, false, false, true);
391 -
392 - $listid = null;
393 - foreach ($userLists as $id => $oneList) {
394 - if ($oneList->status == 1 && in_array($id, $mailLists)) {
395 - $this->lists[$mailid][$subid] = $id;
396 -
397 - return $this->lists[$mailid][$subid];
398 - }
399 - }
400 -
401 - if (!empty($listid)) {
402 - $this->lists[$mailid][$subid] = $listid;
403 -
404 - return $listid;
405 - }
406 - }
407 -
408 - if (!empty($mailLists)) {
409 - $this->lists[$mailid][$subid] = array_shift($mailLists);
410 -
411 - return $this->lists[$mailid][$subid];
412 - }
413 -
414 - if (!empty($subid) && !empty($email->type) && $email->type === MailClass::TYPE_WELCOME) {
415 - $listid = acym_loadResult(
416 - 'SELECT list.id
417 - FROM #__acym_list AS list
418 - JOIN #__acym_user_has_list AS userlist ON list.id = userlist.list_id
419 - WHERE list.welcome_id = '.intval($mailid).' AND userlist.user_id = '.intval($subid).'
420 - ORDER BY userlist.subscription_date DESC'
421 - );
422 - if (!empty($listid)) {
423 - $this->lists[$mailid][$subid] = $listid;
424 -
425 - return $listid;
426 - }
427 - }
428 -
429 - if (!empty($subid) && !empty($email->type) && $email->type === MailClass::TYPE_UNSUBSCRIBE) {
430 - $listid = acym_loadResult(
431 - 'SELECT list.id
432 - FROM #__acym_list AS list
433 - JOIN #__acym_user_has_list AS userlist ON list.id = userlist.list_id
434 - WHERE list.unsubscribe_id = '.intval($mailid).' AND userlist.user_id = '.intval($subid).'
435 - ORDER BY userlist.unsubscribe_date DESC'
436 - );
437 - if (!empty($listid)) {
438 - $this->lists[$mailid][$subid] = $listid;
439 -
440 - return $listid;
441 - }
442 - }
443 -
444 - if (!empty($userLists)) {
445 - $listIds = array_keys($userLists);
446 - $this->lists[$mailid][$subid] = array_shift($listIds);
447 -
448 - return $this->lists[$mailid][$subid];
449 - }
450 -
451 - return 0;
452 - }
453 -
454 - private function listnames(&$email, &$user, &$parameter)
455 - {
456 - if (empty($user->id)) return '';
457 -
458 - $userClass = $this->getUserClass();
459 - $usersubscription = $userClass->getUserSubscriptionById($user->id, 'id', false, true);
460 - $lists = [];
461 - if (!empty($usersubscription)) {
462 - foreach ($usersubscription as $onesub) {
463 - if ($onesub->status < 1 || empty($onesub->active)) {
464 - continue;
465 - }
466 - $lists[] = (!empty($onesub->display_name) ? $onesub->display_name : $onesub->name);
467 - }
468 - }
469 -
470 - return implode(isset($parameter->separator) ? $parameter->separator : ', ', $lists);
471 - }
472 -
473 - private function listowner(&$email, &$user, &$parameter)
474 - {
475 - if (empty($user->id)) {
476 - return '';
477 - }
478 -
479 - if (!in_array($parameter->field, ['username', 'name', 'email'])) {
480 - return 'Field not found : '.$parameter->field;
481 - }
482 -
483 - $listid = $this->getAttachedListid($email, $user->id);
484 - if (empty($listid)) {
485 - return '';
486 - }
487 -
488 - global $acymCmsUserVars;
489 - if (!isset($this->listsowner[$listid])) {
490 - $this->listsowner[$listid] = acym_loadObject(
491 - 'SELECT `user`.* FROM #__acym_list AS `list`
492 - JOIN '.$acymCmsUserVars->table.' AS `user`
493 - ON `user`.'.$acymCmsUserVars->id.' = `list`.cms_user_id
494 - WHERE `list`.id = '.intval($listid)
495 - );
496 - }
497 -
498 - return @$this->listsowner[$listid]->{$acymCmsUserVars->{$parameter->field}};
499 - }
500 -
501 - private function listname(&$email, &$user, &$parameter)
502 - {
503 - if (empty($user->id)) {
504 - return '';
505 - }
506 - $listid = $this->getAttachedListid($email, $user->id);
507 - if (empty($listid)) {
508 - return '';
509 - }
510 -
511 - $this->loadlist($listid);
512 -
513 - return !empty($this->listsinfo[$listid]->display_name) ? $this->listsinfo[$listid]->display_name : @$this->listsinfo[$listid]->name;
514 - }
515 -
516 - private function listdescription(&$email, &$user, &$parameter)
517 - {
518 - if (empty($user->id)) {
519 - return '';
520 - }
521 - if (!empty($parameter->listid)) $listid = $parameter->listid;
522 - if (empty($listid)) $listid = $this->getAttachedListid($email, $user->id);
523 - if (empty($listid)) {
524 - return '';
525 - }
526 -
527 - $this->loadlist($listid);
528 -
529 - return @$this->listsinfo[$listid]->description;
530 - }
531 -
532 - private function loadlist($listid)
533 - {
534 - if (isset($this->listsinfo[$listid])) {
535 - return;
536 - }
537 -
538 - $listClass = new ListClass();
539 - $this->listsinfo[$listid] = $listClass->getOneById(intval($listid));
540 - }
541 -
542 - private function listdescriptions(&$email, &$user, &$parameter)
543 - {
544 - if (empty($user->id)) return '';
545 -
546 - $userClass = $this->getUserClass();
547 - $usersubscription = $userClass->getUserSubscriptionById($user->id);
548 - $listids = [];
549 - if (!empty($parameter->listids)) $listids = explode(',', $parameter->listids);
550 - $lists = [];
551 - if (!empty($usersubscription)) {
552 - foreach ($usersubscription as $onesub) {
553 - if (empty($onesub->description) || $onesub->status < 1 || empty($onesub->active) || (!empty($listids) && !in_array($onesub->id, $listids))) {
554 - continue;
555 - }
556 - $lists[] = $onesub->description;
557 - }
558 - }
559 -
560 - return implode(isset($parameter->separator) ? $parameter->separator : ', ', $lists);
561 - }
562 -
563 - private function listid(&$email, &$user, &$parameter)
564 - {
565 - if (empty($user->id)) {
566 - return '';
567 - }
568 - $listid = $this->getAttachedListid($email, $user->id);
569 - if (empty($listid)) {
570 - return '';
571 - }
572 -
573 - return $listid;
574 - }
575 -
576 - private function replaceSubscriptionTags(&$email)
577 - {
578 - $match = '#(?:{|%7B)(confirm|unsubscribe(?:\|[^}]+)*|unsubscribeall(?:\|[^}]+)*|direct_unsubscribe(?:\|[^}]+)*|subscribe(?:\|[^}]+)*)(?:}|%7D)(.*)(?:{|%7B)/(confirm|unsubscribe|direct_unsubscribe|unsubscribeall|subscribe)(?:}|%7D)#Uis';
579 - $variables = ['subject', 'body'];
580 - $found = false;
581 - $results = [];
582 - foreach ($variables as $var) {
583 - if (empty($email->$var)) continue;
584 -
585 - $found = preg_match_all($match, $email->$var, $results[$var]) || $found;
586 - if (empty($results[$var][0])) unset($results[$var]);
587 - }
588 -
589 - if (!$found) return;
590 -
591 - $tags = [];
592 - $this->addedListUnsubscribe[$email->id] = [];
593 - foreach ($results as $var => $allresults) {
594 - foreach ($allresults[0] as $i => $oneTag) {
595 - if (isset($tags[$oneTag])) continue;
596 -
597 - $tags[$oneTag] = $this->replaceSubscriptionTag($allresults, $i, $email);
598 - }
599 - }
600 -
601 - $this->pluginHelper->replaceTags($email, $tags);
602 - }
603 -
604 - private function replaceSubscriptionTag(&$allresults, $i, &$email)
605 - {
606 - $parameters = $this->pluginHelper->extractTag($allresults[1][$i]);
607 -
608 - $lang = $this->getLanguage($email->links_language);
609 -
610 - if ($parameters->id === 'confirm') {
611 - $myLink = acym_frontendLink('frontusers&task=confirm&userId={subscriber:id}&userKey={subscriber:key|urlencode}'.$lang);
612 - if (empty($allresults[2][$i])) {
613 - return $myLink;
614 - }
615 -
616 - return '<a target="_blank" href="'.$myLink.'"><span class="acym_confirm acym_link">'.$allresults[2][$i].'</span></a>';
617 - } elseif ($parameters->id === 'subscribe') {
618 - if (empty($parameters->lists)) {
619 - return acym_translation('ACYM_EXPORT_SELECT_LIST');
620 - }
621 - $lists = explode(',', $parameters->lists);
622 - acym_arrayToInteger($lists);
623 - $captchaKey = $this->config->get('captcha', 'none') !== 'none' ? '&seckey='.$this->config->get('security_key', '') : '';
624 - $myLink = acym_frontendLink(
625 - 'frontusers&task=subscribe&hiddenlists='.implode(',', $lists).'&userId={subscriber:id}&userKey={subscriber:key|urlencode}'.$lang.$captchaKey
626 - );
627 - if (empty($allresults[2][$i])) {
628 - return $myLink;
629 - }
630 -
631 - return '<a style="text-decoration:none;" target="_blank" href="'.$myLink.'"><span class="acym_subscribe acym_link">'.$allresults[2][$i].'</span></a>';
632 - } elseif ($parameters->id === 'direct_unsubscribe') {
633 - $mailId = $email->id;
634 - $myLink = acym_frontendLink(
635 - 'frontusers&task=unsubscribe'
636 - .'&userId={subscriber:id}'
637 - .'&userKey={subscriber:key|urlencode}'
638 - .'&direct=1'
639 - .'&mail_id='.$mailId
640 - .$lang
641 - );
642 - if (!empty($parameters->redirect)) {
643 - $myLink .= '&redirectunsub='.urlencode($parameters->redirect);
644 - }
645 -
646 - if (empty($allresults[2][$i])) {
647 - return $myLink;
648 - }
649 -
650 - return '<a style="text-decoration:none;" target="_blank" href="'.$myLink.'"><span class="acym_unsubscribe_direct acym_link">'.$allresults[2][$i].'</span></a>';
651 - } else {
652 - $baseLink = 'frontusers'.$lang.'&mail_id='.$email->id;
653 - if ($parameters->id === 'unsubscribe') {
654 - $unsubscribeLink = $baseLink.'&task=unsubscribe&userId={subscriber:id}&userKey={subscriber:key|urlencode}';
655 - if (ACYM_CMS !== 'wordpress') {
656 - $unsubscribeLink .= '&'.acym_noTemplate();
657 - }
658 - $unsubClass = 'acym_unsubscribe';
659 - } else {
660 - $unsubscribeLink = $baseLink.'&task=unsubscribeAll&user_id={subscriber:id}&user_key={subscriber:key|urlencode}';
661 - $unsubClass = 'acym_unsubscribe_all_lists';
662 - }
663 -
664 - $needToCompleteLink = true;
665 - if (!empty($parameters->baseUrl)) {
666 - $unsubscribeLink = $parameters->baseUrl.$unsubscribeLink;
667 - $needToCompleteLink = false;
668 - }
669 -
670 - $unsubscribeLink = acym_frontendLink($unsubscribeLink, $needToCompleteLink);
671 -
672 - if ($parameters->id === 'unsubscribeall' && !empty($parameters->redirect)) {
673 - $unsubscribeLink .= (strpos($unsubscribeLink, '?') === false ? '?' : '&').'redirectunsub='.urlencode($parameters->redirect);
674 - }
675 -
676 - $this->unsubscribeLink[$email->id] = $unsubscribeLink;
677 -
678 - if (empty($allresults[2][$i])) {
679 - return $unsubscribeLink;
680 - }
681 -
682 - return '<a style="text-decoration:none;" target="_blank" href="'.$unsubscribeLink.'"><span class="'.$unsubClass.' acym_link">'.$allresults[2][$i].'</span></a>';
683 - }
684 - }
685 -
686 - private function getUserClass()
687 - {
688 - if ($this->userClass === null) {
689 - $this->userClass = new UserClass();
690 - }
691 -
692 - return $this->userClass;
693 - }
694 -}