PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.2.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.2.2
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 / user / UserInsertion.php

UserInsertion.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.2.2, at back/dynamics/user/UserInsertion.php

258 lines 10.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 trait UserInsertion
4 {
5 private $customFields;
6 private $usergroups;
7
8 private $sendervalues = [];
9
10 public function dynamicText($mailId)
11 {
12 return $this->pluginDescription;
13 }
14
15 public function textPopup()
16 {
17 ?>
18 <script type="text/javascript">
19 let selectedUserDText;
20
21 function changeUserTag(tagname) {
22 if (!tagname) return;
23
24 selectedUserDText = tagname;
25
26 let dText;
27 const iscf = tagname.toLowerCase().indexOf('custom');
28
29 if (iscf >= 0) {
30 dText = '{usertag:' + tagname.substring(0, iscf) + '|type:custom';
31 } else {
32 dText = '{usertag:' + tagname;
33 }
34
35 if (tagname.toLowerCase().indexOf('date') >= 0) {
36 dText += '|type:date';
37 }
38 dText += '|info:' + jQuery('input[name="typeInfoUser"]:checked').val() + '}';
39
40 setTag(dText, jQuery('#' + tagname + 'option'));
41 }
42 </script>
43
44 <?php
45
46 $isAutomation = acym_getVar('string', 'automation');
47 echo '<div class="acym__popup__listing text-center grid-x">';
48
49 $typeinfo = [];
50 $typeinfo[] = acym_selectOption('receiver', 'ACYM_RECEIVER_INFORMATION');
51 $typeinfo[] = acym_selectOption('sender', 'ACYM_SENDER_INFORMATION');
52 if (!empty($isAutomation)) {
53 $typeinfo[] = acym_selectOption('current', 'ACYM_USER_TRIGGERING_AUTOMATION');
54 }
55
56 echo acym_radio(
57 $typeinfo,
58 'typeInfoUser',
59 'receiver',
60 ['onclick' => 'changeUserTag(selectedUserDText)'],
61 ['containerClass' => 'margin-bottom-1']
62 );
63
64 global $acymCmsUserVars;
65 $fields = [
66 $acymCmsUserVars->username => 'ACYM_LOGIN_NAME',
67 $acymCmsUserVars->name => 'ACYM_USER_NAME',
68 $acymCmsUserVars->registered => 'ACYM_REGISTRATION_DATE',
69 'groups' => 'ACYM_USER_GROUPS',
70 ];
71
72 foreach ($fields as $fieldname => $description) {
73 echo '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" id="'.$fieldname.'option" onclick="changeUserTag(\''.$fieldname.'\');" >
74 <div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.acym_escape($fieldname).'</div>
75 <div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.acym_escape(acym_translation($description)).'</div>
76 </div>';
77 }
78
79 if (ACYM_CMS == 'joomla' && ACYM_J37) {
80 $groups = acym_loadObjectList('SELECT id, title FROM #__fields_groups WHERE context = "com_users.user" AND state = 1 ORDER BY title ASC');
81 $defaultGroup = new stdClass();
82 $defaultGroup->id = 0;
83 $defaultGroup->title = acym_translation('ACYM_NO_GROUP');
84 array_unshift($groups, $defaultGroup);
85
86 $customFields = acym_loadObjectList('SELECT id, title, group_id FROM #__fields WHERE context = "com_users.user" AND state = 1 ORDER BY title ASC');
87 if (!empty($customFields)) {
88 echo '<h1 class="acym__title acym__title__secondary text-center cell" style="margin-top: 20px;">'.acym_translation('ACYM_CUSTOM_FIELDS').'</h1>';
89
90 foreach ($groups as $oneGroup) {
91 foreach ($customFields as $oneCF) {
92 if ($oneCF->group_id != $oneGroup->id) {
93 continue;
94 }
95 echo '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" id="'.$oneCF->id.'customoption" onclick="changeUserTag(\''.$oneCF->id.'custom\');" >
96 <div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.acym_escape($oneCF->title).'</div>
97 </div>';
98 }
99 }
100 }
101 }
102
103 echo '</div>';
104 }
105
106 public function replaceUserInformation(&$email, &$user, $send = true)
107 {
108 $extractedTags = $this->pluginHelper->extractTags($email, 'usertag');
109 if (empty($extractedTags)) {
110 return;
111 }
112
113 if (empty($this->customFields) && ACYM_CMS == 'joomla' && ACYM_J37) {
114 $this->customFields = acym_loadObjectList('SELECT * FROM #__fields WHERE context = "com_users.user"', 'id');
115 foreach ($this->customFields as &$oneCF) {
116 if (!empty($oneCF->fieldparams)) {
117 $oneCF->fieldparams = json_decode($oneCF->fieldparams, true);
118 }
119 }
120 }
121
122 $tags = [];
123 $receivervalues = [];
124 foreach ($extractedTags as $i => $mytag) {
125 if (isset($tags[$i])) {
126 continue;
127 }
128 $mytag->default = '';
129
130 $values = new stdClass();
131 $idused = 0;
132 $save = false;
133
134 if (!empty($mytag->info) && $mytag->info == 'sender' && !empty($email->creator_id)) {
135 $idused = $email->creator_id;
136 $save = true;
137 }
138
139 if (!empty($mytag->info) && $mytag->info == 'current') {
140 continue;
141 }
142
143 if ((empty($mytag->info) || $mytag->info == 'receiver') && !empty($user->cms_id)) {
144 $idused = $user->cms_id;
145 }
146
147 if (!empty($idused) && empty($this->sendervalues[$idused]) && empty($receivervalues[$idused])) {
148 global $acymCmsUserVars;
149 $receivervalues[$idused] = acym_loadObject('SELECT * FROM '.$acymCmsUserVars->table.' WHERE '.$acymCmsUserVars->id.' = '.intval($idused));
150
151 if ($save) {
152 $this->sendervalues[$idused] = $receivervalues[$idused];
153 }
154 }
155
156 if (!empty($this->sendervalues[$idused])) {
157 $values = $this->sendervalues[$idused];
158 } elseif (!empty($receivervalues[$idused])) {
159 $values = $receivervalues[$idused];
160 }
161
162 if ($mytag->id == 'groups') {
163 $groups = acym_getGroupsByUser($idused, true, true);
164 $values->groups = implode(', ', $groups);
165 }
166
167 if (empty($mytag->type)) {
168 $mytag->type = '';
169 }
170
171 if ($mytag->type == 'custom' && ACYM_CMS == 'joomla') {
172 $mytag->id = intval($mytag->id);
173 if (empty($mytag->id)) {
174 $replaceme = '';
175 } else {
176 $userFieldVals = acym_loadResultArray('SELECT value FROM #__fields_values WHERE item_id = '.intval($idused).' AND field_id = '.intval($mytag->id));
177
178 $fieldValues = trim(implode(', ', $userFieldVals), ', ');
179 if (empty($fieldValues)) {
180 $defaultValue = acym_loadObject('SELECT default_value, type FROM #__fields WHERE id = '.intval($mytag->id));
181 if (($defaultValue->type == 'user' && !empty($defaultValue->default_value)) || ($defaultValue->type != 'user' && strlen(
182 $defaultValue->default_value
183 ) > 0)) {
184 $userFieldVals = [$defaultValue->default_value];
185 }
186 }
187
188 foreach ($userFieldVals as &$oneFieldVal) {
189 switch ($this->customFields[$mytag->id]->type) {
190 case 'radio':
191 case 'list':
192 case 'checkboxes':
193 foreach ($this->customFields[$mytag->id]->fieldparams['options'] as $oneOPT) {
194 if ($oneOPT['value'] == $oneFieldVal) {
195 $oneFieldVal = $oneOPT['name'];
196 break;
197 }
198 }
199 break;
200
201 case 'usergrouplist':
202 if (empty($this->usergroups)) {
203 $this->usergroups = acym_loadObjectList('SELECT id, title FROM #__usergroups', 'id');
204 }
205
206 $oneFieldVal = $this->usergroups[$oneFieldVal]->title;
207 break;
208
209 case 'imagelist':
210 if (strlen($this->customFields[$mytag->id]->fieldparams['directory']) > 1) {
211 $oneFieldVal = '/'.$oneFieldVal;
212 } else {
213 $this->customFields[$mytag->id]->fieldparams['directory'] = '';
214 }
215 $oneFieldVal = '<img src="images/'.$this->customFields[$mytag->id]->fieldparams['directory'].$oneFieldVal.'" />';
216 break;
217
218 case 'url':
219 $oneFieldVal = '<a target="_blank" href="'.$oneFieldVal.'">'.$oneFieldVal.'</a>';
220 break;
221
222 case 'sql':
223 if (empty($this->customFields[$mytag->id]->options)) {
224 $this->customFields[$mytag->id]->options = acym_loadObjectList($this->customFields[$mytag->id]->fieldparams['query'], 'value');
225 }
226
227 $oneFieldVal = $this->customFields[$mytag->id]->options[$oneFieldVal]->text;
228 break;
229
230 case 'user':
231 $oneFieldVal = acym_currentUserName($oneFieldVal);
232 break;
233
234 case 'media':
235 $oneFieldVal = '<img src="'.$oneFieldVal.'" />';
236 break;
237
238 case 'calendar':
239 $format = $this->customFields[$mytag->id]->fieldparams['showtime'] == '1' ? 'Y-m-d H:i' : 'Y-m-d';
240 $oneFieldVal = acym_date(strtotime($oneFieldVal), $format);
241 break;
242 }
243 }
244
245 $replaceme = implode(', ', $userFieldVals);
246 }
247 } else {
248 $replaceme = isset($values->{$mytag->id}) ? $values->{$mytag->id} : $mytag->default;
249 }
250
251 $tags[$i] = $replaceme;
252 $this->pluginHelper->formatString($tags[$i], $mytag);
253 }
254
255 $this->pluginHelper->replaceTags($email, $tags);
256 }
257 }
258