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/UserAutomationConditions.php +0 -286 10.11.1 → 11.1.1 View file →
@@ -1,286 +1,0 @@
1 -<?php
2 -
3 -use AcyMailing\Helpers\AutomationHelper;
4 -use AcyMailing\Types\OperatorInType;
5 -use AcyMailing\Types\OperatorType;
6 -
7 -trait UserAutomationConditions
8 -{
9 - public function onAcymDeclareConditions(array &$conditions): void
10 - {
11 - $allGroups = acym_getGroups();
12 - $groups = ['' => acym_translation('ACYM_NO_GROUP')];
13 - foreach ($allGroups as $group) {
14 - $groups[$group->id] = $group->text;
15 - }
16 - $operatorIn = new OperatorInType();
17 -
18 - $conditions['user']['acy_group'] = new stdClass();
19 - $conditions['user']['acy_group']->name = acym_translation('ACYM_GROUP');
20 - $conditions['user']['acy_group']->option = '<div class="intext_select_automation cell">';
21 - $conditions['user']['acy_group']->option .= $operatorIn->display('acym_condition[conditions][__numor__][__numand__][acy_group][in]');
22 - $conditions['user']['acy_group']->option .= '</div>';
23 - $conditions['user']['acy_group']->option .= '<div class="intext_select_automation cell">';
24 - $conditions['user']['acy_group']->option .= acym_select(
25 - $groups,
26 - 'acym_condition[conditions][__numor__][__numand__][acy_group][group]',
27 - null,
28 - ['class' => 'acym__select']
29 - );
30 - $conditions['user']['acy_group']->option .= '</div>';
31 - if (ACYM_CMS === 'joomla') {
32 - $conditions['user']['acy_group']->option .= '<div class="cell grid-x medium-3">';
33 - $conditions['user']['acy_group']->option .= acym_switch(
34 - 'acym_condition[conditions][__numor__][__numand__][acy_group][subgroup]',
35 - 1,
36 - acym_translation('ACYM_INCLUDE_SUB_GROUPS')
37 - );
38 - $conditions['user']['acy_group']->option .= '</div>';
39 - }
40 -
41 - $cmsFields = [];
42 - foreach (acym_getColumns('users', false) as $key => $column) {
43 - $cmsFields[$column] = $column;
44 - }
45 -
46 - if (ACYM_CMS == 'joomla' && ACYM_J37) {
47 - $query = 'SELECT id, title
48 - FROM #__fields
49 - WHERE context = "com_users.user"
50 - AND state = 1
51 - AND type IN ("calendar", "checkboxes", "color", "integer", "list", "radio", "sql", "text", "url")
52 - ORDER BY title ASC';
53 - $customFields = acym_loadObjectList($query);
54 - foreach ($customFields as $oneCF) {
55 - $cmsFields['cf_'.$oneCF->id] = $oneCF->title;
56 - }
57 - }
58 - $excluded = ['password', 'params', 'activation', 'lastResetTime', 'resetCount', 'optKey', 'otep', 'requireReset', 'user_pass', 'user_activation_key'];
59 - foreach ($excluded as $oneExcluded) {
60 - unset($cmsFields[$oneExcluded]);
61 - }
62 -
63 - $operator = new OperatorType();
64 -
65 - $conditions['user']['acy_cmsfield'] = new stdClass();
66 - $conditions['user']['acy_cmsfield']->name = acym_translation('ACYM_ACCOUNT_USER_FIELD');
67 - $conditions['user']['acy_cmsfield']->option = '<div class="intext_select_automation cell">';
68 - $conditions['user']['acy_cmsfield']->option .= acym_select(
69 - $cmsFields,
70 - 'acym_condition[conditions][__numor__][__numand__][acy_cmsfield][field]',
71 - null,
72 - ['class' => 'acym__select']
73 - );
74 - $conditions['user']['acy_cmsfield']->option .= '</div>';
75 - $conditions['user']['acy_cmsfield']->option .= '<div class="intext_select_automation cell">';
76 - $conditions['user']['acy_cmsfield']->option .= $operator->display('acym_condition[conditions][__numor__][__numand__][acy_cmsfield][operator]');
77 - $conditions['user']['acy_cmsfield']->option .= '</div>';
78 - $conditions['user']['acy_cmsfield']->option .= '<input class="intext_input_automation cell" type="text" name="acym_condition[conditions][__numor__][__numand__][acy_cmsfield][value]">';
79 -
80 - $conditions['classic']['acy_totaluser'] = new stdClass();
81 - $conditions['classic']['acy_totaluser']->name = acym_translation('ACYM_NUMBER_OF_SUBSCRIBERS');
82 - $conditions['classic']['acy_totaluser']->option = '<div class="cell shrink acym__automation__inner__text">'.acym_translation('ACYM_THERE_IS').'</div>';
83 - $conditions['classic']['acy_totaluser']->option .= '<div class="intext_select_automation cell">';
84 - $conditions['classic']['acy_totaluser']->option .= acym_select(
85 - ['=' => acym_translation('ACYM_EXACTLY'), '>' => acym_translation('ACYM_MORE_THAN'), '<' => acym_translation('ACYM_LESS_THAN')],
86 - 'acym_condition[conditions][__numor__][__numand__][acy_totaluser][operator]',
87 - null,
88 - ['class' => 'intext_select_automation acym__select']
89 - );
90 - $conditions['classic']['acy_totaluser']->option .= '</div>';
91 - $conditions['classic']['acy_totaluser']->option .= '<input type="number" min="0" class="intext_input_automation cell" name="acym_condition[conditions][__numor__][__numand__][acy_totaluser][number]">';
92 - $conditions['classic']['acy_totaluser']->option .= '<div class="cell shrink acym__automation__inner__text">'.acym_translation('ACYM_ACYMAILING_USERS').'</div>';
93 -
94 - $conditions['both']['acy_toss'] = new stdClass();
95 - $conditions['both']['acy_toss']->name = acym_translation('ACYM_TOSS');
96 - $conditions['both']['acy_toss']->option = '<input type="hidden" name="acym_condition[conditions][__numor__][__numand__][acy_toss][toss]" value="true"><div class="acym__automation__inner__text">'.acym_translation(
97 - 'ACYM_TOSS_DESC'
98 - ).'</div>';
99 - }
100 -
101 - public function onAcymDeclareConditionsScenario(array &$conditions): void
102 - {
103 - $this->onAcymDeclareConditions($conditions);
104 - }
105 -
106 - public function onAcymProcessCondition_acy_toss(&$query, $option, $num, &$conditionNotValid)
107 - {
108 - if (!mt_rand(0, 1)) $conditionNotValid++;
109 - }
110 -
111 - public function onAcymProcessCondition_acy_totaluser(&$query, $option, $num, &$conditionNotValid)
112 - {
113 - $numberUsers = $query->count();
114 - $res = false;
115 -
116 - switch ($option['operator']) {
117 - case '=':
118 - $res = $numberUsers == $option['number'];
119 - break;
120 - case '>':
121 - $res = $numberUsers > $option['number'];
122 - break;
123 - case '<':
124 - $res = $numberUsers < $option['number'];
125 - break;
126 - }
127 -
128 - if (!$res) $conditionNotValid++;
129 - }
130 -
131 - public function onAcymProcessCondition_acy_group(&$query, $options, $num, &$conditionNotValid)
132 - {
133 - $affectedRows = $this->processAcyGroup($query, $options, $num);
134 - if (empty($affectedRows)) $conditionNotValid++;
135 - }
136 -
137 - private function processAcyGroup(&$query, $options, $num)
138 - {
139 - if (empty($options['group'])) {
140 - if (ACYM_CMS === 'joomla') {
141 - $operator = (empty($options['in']) || $options['in'] === 'in') ? 'IS NULL' : 'IS NOT NULL AND cmsuser'.$num.'.user_id != 0';
142 - $query->leftjoin['cmsuser'.$num] = '#__user_usergroup_map AS cmsuser'.$num.'
143 - ON cmsuser'.$num.'.user_id = user.cms_id ';
144 - } else {
145 - $operator = (empty($options['in']) || $options['in'] === 'in') ? 'IS NOT NULL AND cmsuser'.$num.'.user_id != 0' : 'IS NULL AND user.cms_id != 0';
146 - $query->leftjoin['cmsuser'.$num] = '#__usermeta AS cmsuser'.$num.'
147 - ON cmsuser'.$num.'.user_id = user.cms_id
148 - AND cmsuser'.$num.'.meta_key = "#__capabilities"
149 - AND cmsuser'.$num.'.meta_value = "a:0:{}"';
150 - }
151 - } else {
152 - $operator = (empty($options['in']) || $options['in'] === 'in') ? 'IS NOT NULL AND cmsuser'.$num.'.user_id != 0' : 'IS NULL';
153 -
154 - if (ACYM_CMS === 'joomla') {
155 - if (empty($options['subgroup'])) {
156 - $value = ' = '.intval($options['group']);
157 - } else {
158 - $lftrgt = acym_loadObject('SELECT lft, rgt FROM #__usergroups WHERE id = '.intval($options['group']));
159 - $allSubGroups = acym_loadResultArray('SELECT id FROM #__usergroups WHERE lft > '.intval($lftrgt->lft).' AND rgt < '.intval($lftrgt->rgt));
160 - array_unshift($allSubGroups, intval($options['group']));
161 - $value = ' IN ('.implode(', ', $allSubGroups).')';
162 - }
163 -
164 - $query->leftjoin['cmsuser'.$num] = '#__user_usergroup_map AS cmsuser'.$num.'
165 - ON cmsuser'.$num.'.user_id = user.cms_id
166 - AND cmsuser'.$num.'.group_id'.$value;
167 - } else {
168 - $query->leftjoin['cmsuser'.$num] = '#__usermeta AS cmsuser'.$num.'
169 - ON cmsuser'.$num.'.user_id = user.cms_id
170 - AND cmsuser'.$num.'.meta_key = "#__capabilities"
171 - AND cmsuser'.$num.'.meta_value LIKE '.acym_escapeDB('%'.strlen($options['group']).':"'.acym_secureDBColumn($options['group']).'"%');
172 - }
173 - }
174 -
175 - $query->where[] = 'cmsuser'.$num.'.user_id '.$operator;
176 -
177 - return $query->count();
178 - }
179 -
180 - public function onAcymProcessCondition_acy_cmsfield(&$query, $options, $num, &$conditionNotValid)
181 - {
182 - $affectedRows = $this->processAcyCMSField($query, $options, $num);
183 - if (empty($affectedRows)) $conditionNotValid++;
184 - }
185 -
186 - private function processAcyCMSField(&$query, $options, $num)
187 - {
188 - if (empty($options['field'])) {
189 - return;
190 - }
191 -
192 - if (strpos($options['field'], 'cf_') !== false) {
193 - $cfId = substr($options['field'], 3);
194 - $query->leftjoin['cmsuserfields'.$num] = '#__fields_values AS cmsuserfields'.$num.' ON cmsuserfields'.$num.'.item_id = user.cms_id AND cmsuserfields'.$num.'.field_id = '.intval(
195 - $cfId
196 - );
197 - $query->where[] = $query->convertQuery('cmsuserfields'.$num, 'value', $options['operator'], $options['value']);
198 - } else {
199 - $type = '';
200 - $query->leftjoin['cmsuser'.$num] = '#__users AS cmsuser'.$num.' ON cmsuser'.$num.'.id = user.cms_id';
201 -
202 - if (in_array($options['field'], ['registerDate', 'lastvisitDate', 'user_registered'])) {
203 - $type = AutomationHelper::TYPE_DATETIME;
204 - $options['value'] = acym_replaceDate($options['value']);
205 -
206 - if (!is_numeric($options['value']) && strtotime($options['value']) !== false) {
207 - $options['value'] = strtotime($options['value']);
208 - }
209 - if (is_numeric($options['value'])) {
210 - $options['value'] = date('Y-m-d H:i:s', $options['value']);
211 - }
212 - }
213 -
214 - $query->where[] = $query->convertQuery(
215 - 'cmsuser'.$num,
216 - $options['field'],
217 - $options['operator'],
218 - $options['value'],
219 - $type
220 - );
221 - }
222 -
223 - return $query->count();
224 - }
225 -
226 - public function onAcymDeclareSummary_conditions(&$automation)
227 - {
228 - $this->summaryGroup($automation);
229 -
230 - if (!empty($automation['acy_cmsfield'])) {
231 - $automation = acym_translationSprintf(
232 - 'ACYM_CONDITION_ACY_CMS_FIELD_SUMMARY',
233 - $automation['acy_cmsfield']['field'],
234 - $automation['acy_cmsfield']['operator'],
235 - $automation['acy_cmsfield']['value']
236 - );
237 - }
238 -
239 - if (!empty($automation['acy_totaluser'])) {
240 - $operators = ['=' => acym_translation('ACYM_EXACTLY'), '>' => acym_translation('ACYM_MORE_THAN'), '<' => acym_translation('ACYM_LESS_THAN')];
241 - $automation = acym_translation('ACYM_THERE_IS').' '.acym_strtolower(
242 - $operators[$automation['acy_totaluser']['operator']]
243 - ).' '.$automation['acy_totaluser']['number'].' '.acym_translation('ACYM_ACYMAILING_USERS').' ';
244 - }
245 -
246 - if (!empty($automation['acy_toss'])) {
247 - $automation = acym_translation('ACYM_TOSS_DESC');
248 - }
249 - }
250 -
251 - private function summaryGroup(&$automation)
252 - {
253 - if (empty($automation['acy_group'])) return;
254 -
255 - if ('joomla' === ACYM_CMS) {
256 - $allGroups = acym_getGroups();
257 - $groups = [];
258 - foreach ($allGroups as $group) {
259 - if ($automation['acy_group']['group'] == $group->id) {
260 - $automation['acy_group']['group'] = $group->text;
261 - }
262 - $groups[$group->id] = $group->text;
263 - }
264 - } else {
265 - $groupKey = 'ACYM_'.strtoupper($automation['acy_group']['group']);
266 - if (acym_translationExists($groupKey)) {
267 - $automation['acy_group']['group'] = $groupKey;
268 - }
269 - }
270 -
271 - if (empty($automation['acy_group']['group'])) {
272 - $automation['acy_group']['group'] = acym_translation('ACYM_NO_GROUP');
273 - }
274 -
275 - $finalText = acym_translationSprintf(
276 - 'ACYM_FILTER_ACY_GROUP_SUMMARY',
277 - acym_translation($automation['acy_group']['in'] == 'in' ? 'ACYM_IN' : 'ACYM_NOT_IN'),
278 - acym_translation($automation['acy_group']['group'])
279 - );
280 - if ('joomla' === ACYM_CMS) {
281 - $finalText .= $automation['acy_group']['subgroup'] == 1 ? ' '.acym_translation('ACYM_FILTER_ACY_GROUP_SUBGROUP_SUMMARY') : '';
282 - }
283 -
284 - $automation = $finalText;
285 - }
286 -}