PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.1.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.1.4
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
acymailing / back / dynamics / subscriber / SubscriberInsertion.php

SubscriberInsertion.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.1.4, at back/dynamics/subscriber/SubscriberInsertion.php

155 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use AcyMailing\Classes\MailClass;
4 use AcyMailing\Classes\FieldClass;
5
6 trait SubscriberInsertion
7 {
8 public function dynamicText($mailId)
9 {
10 return $this->pluginDescription;
11 }
12
13 public function textPopup()
14 {
15 ?>
16 <script type="text/javascript">
17 let selectedSubscriberDText;
18
19 function changeSubscriberTag(tagname, element) {
20 if (!tagname) return;
21
22 selectedSubscriberDText = tagname;
23
24 let baseTag = '<?php echo $this->name; ?>';
25 const $inputType = jQuery('input[name="typeInfoSubscriber"]:checked');
26 if ($inputType.length > 0 && $inputType.val() === 'current') {
27 baseTag = 'user';
28 }
29 let finalTag = '{' + baseTag + ':' + tagname;
30
31 if ($inputType.length > 0 && $inputType.val() !== 'current') {
32 finalTag += '|info:' + $inputType.val() + '';
33 }
34 finalTag += '}';
35
36 setTag(finalTag, element);
37 }
38 </script>
39 <?php
40 $fieldClass = new FieldClass();
41 $fieldsUser = acym_getColumns('user');
42 $fieldsStats = acym_getColumns('user_stat');
43 $fields = array_merge($fieldsUser, $fieldsStats);
44 $customFields = $fieldClass->getAllFieldsForUser();
45 $descriptions = [];
46 $isAutomationAdmin = acym_getVar('string', 'automation');
47 $mailType = acym_getVar('string', 'mail_type', MailClass::TYPE_STANDARD);
48 $typeNotif = acym_getVar('string', 'notification', '');
49
50 foreach ($customFields as $one) {
51 $descriptions[$one->namekey] = acym_translation('ACYM_CUSTOM_FIELD');
52 $fields[] = $one;
53 }
54
55 $descriptions['id'] = acym_translation('ACYM_USER_ID');
56 $descriptions['email'] = acym_translation('ACYM_USER_EMAIL');
57 $descriptions['name'] = acym_translation('ACYM_USER_NAME');
58 $descriptions['cms_id'] = acym_translation('ACYM_USER_CMSID');
59 $descriptions['source'] = acym_translation('ACYM_USER_SOURCE');
60 $descriptions['confirmed'] = acym_translation('ACYM_USER_CONFIRMED');
61 $descriptions['active'] = acym_translation('ACYM_USER_ACTIVE');
62 $descriptions['creation_date'] = acym_translation('ACYM_USER_CREATION_DATE');
63 $descriptions['open_date'] = acym_translation('ACYM_USER_OPEN_DATE');
64 $descriptions['date_click'] = acym_translation('ACYM_USER_CLICK_DATE');
65 $descriptions['send_date'] = acym_translation('ACYM_USER_SEND_DATE');
66
67 echo '<div class="acym__popup__listing text-center grid-x">';
68 if (!empty($isAutomationAdmin) || ($mailType === 'notification' && $typeNotif !== 'acy_confirm')) {
69 $textTrigger = $mailType == 'notification' ? 'ACYM_USER_TRIGGERING_NOTIFICATION' : 'ACYM_USER_TRIGGERING_AUTOMATION';
70 $typeinfo = [];
71 $typeinfo[] = acym_selectOption('receiver', 'ACYM_RECEIVER_INFORMATION');
72 $typeinfo[] = acym_selectOption('current', $textTrigger);
73 echo acym_radio(
74 $typeinfo,
75 'typeInfoSubscriber',
76 'receiver',
77 ['onclick' => 'changeSubscriberTag(selectedSubscriberDText, jQuery(this))']
78 );
79 }
80 echo '<h1 class="acym__title acym__title__secondary text-center cell">'.acym_translation('ACYM_RECEIVER_INFORMATION').'</h1>';
81
82 $others = [];
83 $others['name|part:first|ucfirst'] = ['name' => acym_translation('ACYM_USER_FIRSTPART'), 'desc' => acym_translation('ACYM_USER_FIRSTPART_DESC')];
84 $others['name|part:last|ucfirst'] = ['name' => acym_translation('ACYM_USER_LASTPART'), 'desc' => acym_translation('ACYM_USER_LASTPART_DESC')];
85
86 foreach ($others as $tagname => $tag) {
87 echo '<div style="cursor:pointer" class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriberTag(\''.$tagname.'\', jQuery(this));">
88 <div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.$tag['name'].'</div>
89 <div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.$tag['desc'].'</div>
90 </div>';
91 }
92
93 foreach ($fields as $field) {
94 $fieldKey = is_object($field) ? $field->namekey : $field;
95 $fieldName = is_object($field) ? acym_translation($field->name) : $field;
96 if (empty($descriptions[$fieldKey])) {
97 continue;
98 }
99
100 $type = '';
101 if (in_array($fieldKey, ['creation_date', 'open_date', 'date_click', 'send_date'])) {
102 $type = '|type:time';
103 }
104
105 echo '<div style="cursor:pointer" class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriberTag(\''.$fieldKey.$type.'\', jQuery(this));">
106 <div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.acym_escape($fieldName).'</div>
107 <div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.acym_escape($descriptions[$fieldKey]).'</div>
108 </div>';
109 }
110
111 echo '</div>';
112 }
113
114 public function replaceUserInformation(&$email, &$user, $send = true)
115 {
116 $extractedTags = $this->pluginHelper->extractTags($email, $this->name);
117 $backwardsTags = $this->pluginHelper->extractTags($email, 'subtag');
118 foreach ($backwardsTags as $tag => $params) {
119 $extractedTags[$tag] = $params;
120 }
121
122 if (empty($extractedTags)) return;
123
124 $fieldClass = new FieldClass();
125 $fields = $fieldClass->getFieldsByNameKey(array_column($extractedTags, 'id'));
126 $fieldsData = empty($user->id) ? [] : $fieldClass->getAllFieldsListingByUserIds($user->id, array_keys($fields));
127 $fieldsNameKeyIdMap = array_combine(array_column($fields, 'namekey'), array_column($fields, 'id'));
128
129 $tags = [];
130 foreach ($extractedTags as $i => $oneTag) {
131 if (isset($tags[$i]) || (!empty($oneTag->info) && $oneTag->info === 'current')) {
132 continue;
133 }
134
135 $fieldNameKey = $oneTag->id === 'acym_language' ? 'language' : $oneTag->id;
136 $fieldId = $fieldsNameKeyIdMap[$fieldNameKey] ?? 0;
137 $fieldValue = $user->$fieldNameKey ?? '';
138
139 if (strlen($fieldValue) === 0 && !empty($user->id) && !empty($fieldId)) {
140 $fieldValue = $fieldsData[$fieldId.'-'.$user->id] ?? $oneTag->default;
141 }
142
143 if (strlen($fieldValue) === 0) {
144 $fieldValue = $oneTag->default;
145 }
146
147 $fieldValue = acym_translation(nl2br($fieldValue));
148 $this->pluginHelper->formatString($fieldValue, $oneTag);
149 $tags[$i] = $fieldValue;
150 }
151
152 $this->pluginHelper->replaceTags($email, $tags);
153 }
154 }
155