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/user/UserInsertion.php +0 -257 10.11.1 → 11.1.1 View file →
@@ -1,257 +1,0 @@
1 -<?php
2 -
3 -trait UserInsertion
4 -{
5 - private $customFields;
6 - private $usergroups;
7 -
8 - private $sendervalues = [];
9 -
10 - public function dynamicText(?int $mailId): ?object
11 - {
12 - return $this->pluginDescription;
13 - }
14 -
15 - public function textPopup(): void
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 - $isAutomation = acym_getVar('string', 'automation');
46 - echo '<div class="acym__popup__listing text-center grid-x">';
47 -
48 - $typeinfo = [];
49 - $typeinfo[] = acym_selectOption('receiver', 'ACYM_RECEIVER_INFORMATION');
50 - $typeinfo[] = acym_selectOption('sender', 'ACYM_SENDER_INFORMATION');
51 - if (!empty($isAutomation)) {
52 - $typeinfo[] = acym_selectOption('current', 'ACYM_USER_TRIGGERING_AUTOMATION');
53 - }
54 -
55 - echo acym_radio(
56 - $typeinfo,
57 - 'typeInfoUser',
58 - 'receiver',
59 - ['onclick' => 'changeUserTag(selectedUserDText)'],
60 - ['containerClass' => 'margin-bottom-1']
61 - );
62 -
63 - global $acymCmsUserVars;
64 - $fields = [
65 - $acymCmsUserVars->username => 'ACYM_LOGIN_NAME',
66 - $acymCmsUserVars->name => 'ACYM_USER_NAME',
67 - $acymCmsUserVars->registered => 'ACYM_REGISTRATION_DATE',
68 - 'groups' => 'ACYM_USER_GROUPS',
69 - ];
70 -
71 - foreach ($fields as $fieldname => $description) {
72 - echo '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" id="'.$fieldname.'option" onclick="changeUserTag(\''.$fieldname.'\');" >
73 - <div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.acym_escape($fieldname).'</div>
74 - <div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.acym_escape(acym_translation($description)).'</div>
75 - </div>';
76 - }
77 -
78 - if (ACYM_CMS == 'joomla' && ACYM_J37) {
79 - $groups = acym_loadObjectList('SELECT id, title FROM #__fields_groups WHERE context = "com_users.user" AND state = 1 ORDER BY title ASC');
80 - $defaultGroup = new stdClass();
81 - $defaultGroup->id = 0;
82 - $defaultGroup->title = acym_translation('ACYM_NO_GROUP');
83 - array_unshift($groups, $defaultGroup);
84 -
85 - $customFields = acym_loadObjectList('SELECT id, title, group_id FROM #__fields WHERE context = "com_users.user" AND state = 1 ORDER BY title ASC');
86 - if (!empty($customFields)) {
87 - echo '<h1 class="acym__title acym__title__secondary text-center cell" style="margin-top: 20px;">'.acym_translation('ACYM_CUSTOM_FIELDS').'</h1>';
88 -
89 - foreach ($groups as $oneGroup) {
90 - foreach ($customFields as $oneCF) {
91 - if ($oneCF->group_id != $oneGroup->id) {
92 - continue;
93 - }
94 - 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\');" >
95 - <div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.acym_escape($oneCF->title).'</div>
96 - </div>';
97 - }
98 - }
99 - }
100 - }
101 -
102 - echo '</div>';
103 - }
104 -
105 - public function replaceUserInformation(object &$email, ?object &$user, bool $send = true): void
106 - {
107 - $extractedTags = $this->pluginHelper->extractTags($email, 'usertag');
108 - if (empty($extractedTags)) {
109 - return;
110 - }
111 -
112 - if (empty($this->customFields) && ACYM_CMS == 'joomla' && ACYM_J37) {
113 - $this->customFields = acym_loadObjectList('SELECT * FROM #__fields WHERE context = "com_users.user"', 'id');
114 - foreach ($this->customFields as &$oneCF) {
115 - if (!empty($oneCF->fieldparams)) {
116 - $oneCF->fieldparams = json_decode($oneCF->fieldparams, true);
117 - }
118 - }
119 - }
120 -
121 - $tags = [];
122 - $receivervalues = [];
123 - foreach ($extractedTags as $i => $mytag) {
124 - if (isset($tags[$i])) {
125 - continue;
126 - }
127 - $mytag->default = '';
128 -
129 - $values = new stdClass();
130 - $idused = 0;
131 - $save = false;
132 -
133 - if (!empty($mytag->info) && $mytag->info == 'sender' && !empty($email->creator_id)) {
134 - $idused = $email->creator_id;
135 - $save = true;
136 - }
137 -
138 - if (!empty($mytag->info) && $mytag->info == 'current') {
139 - continue;
140 - }
141 -
142 - if ((empty($mytag->info) || $mytag->info == 'receiver') && !empty($user->cms_id)) {
143 - $idused = $user->cms_id;
144 - }
145 -
146 - if (!empty($idused) && empty($this->sendervalues[$idused]) && empty($receivervalues[$idused])) {
147 - global $acymCmsUserVars;
148 - $receivervalues[$idused] = acym_loadObject('SELECT * FROM '.$acymCmsUserVars->table.' WHERE '.$acymCmsUserVars->id.' = '.intval($idused));
149 -
150 - if ($save) {
151 - $this->sendervalues[$idused] = $receivervalues[$idused];
152 - }
153 - }
154 -
155 - if (!empty($this->sendervalues[$idused])) {
156 - $values = $this->sendervalues[$idused];
157 - } elseif (!empty($receivervalues[$idused])) {
158 - $values = $receivervalues[$idused];
159 - }
160 -
161 - if ($mytag->id == 'groups') {
162 - $groups = acym_getGroupsByUser($idused, true, true);
163 - $values->groups = implode(', ', $groups);
164 - }
165 -
166 - if (empty($mytag->type)) {
167 - $mytag->type = '';
168 - }
169 -
170 - if ($mytag->type == 'custom' && ACYM_CMS == 'joomla') {
171 - $mytag->id = intval($mytag->id);
172 - if (empty($mytag->id)) {
173 - $replaceme = '';
174 - } else {
175 - $userFieldVals = acym_loadResultArray('SELECT value FROM #__fields_values WHERE item_id = '.intval($idused).' AND field_id = '.intval($mytag->id));
176 -
177 - $fieldValues = trim(implode(', ', $userFieldVals), ', ');
178 - if (empty($fieldValues)) {
179 - $defaultValue = acym_loadObject('SELECT default_value, type FROM #__fields WHERE id = '.intval($mytag->id));
180 - if (
181 - ($defaultValue->type === 'user' && !empty($defaultValue->default_value))
182 - || ($defaultValue->type !== 'user' && strlen($defaultValue->default_value) > 0)
183 - ) {
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 -}