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