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/Controllers/Segments/Edition.php +0 -239 11.0.4 → 11.1.1 View file →
@@ -1,239 +1,0 @@
1 -<?php
2 -
3 -namespace AcyMailing\Controllers\Segments;
4 -
5 -use AcyMailing\Classes\SegmentClass;
6 -use AcyMailing\Controllers\AutomationController;
7 -use AcyMailing\Helpers\AutomationHelper;
8 -
9 -trait Edition
10 -{
11 - public function edit(): void
12 - {
13 - if (!acym_level(ACYM_ENTERPRISE)) {
14 - acym_redirect(acym_completeLink('dashboard&task=upgrade&version=enterprise', false, true));
15 - }
16 -
17 - }
18 -
19 - public function apply(): void
20 - {
21 - $segmentId = $this->store();
22 - if (empty($segmentId)) {
23 - acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_SAVE_SEGMENT'), 'error');
24 - $this->listing();
25 - } else {
26 - acym_enqueueMessage(acym_translation('ACYM_SEGMENT_WELL_SAVE'));
27 - acym_setVar('segmentId', $segmentId);
28 - $this->edit();
29 - }
30 - }
31 -
32 - public function save(): void
33 - {
34 - $segmentId = $this->store();
35 - acym_enqueueMessage(acym_translation(empty($segmentId) ? 'ACYM_COULD_NOT_SAVE_SEGMENT' : 'ACYM_SEGMENT_WELL_SAVE'), empty($segmentId) ? 'error' : 'success');
36 - $this->listing();
37 - }
38 -
39 - private function store(): int
40 - {
41 - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
42 -
43 - $segmentId = acym_getVar('int', 'segmentId');
44 - $filters = acym_getVar('array', 'acym_action');
45 - $segmentRequest = acym_getVar('array', 'segment');
46 -
47 - if (acym_conditionsContainRestrictedFilter($filters) && !acym_hasAdminPermissions()) {
48 - acym_enqueueMessage(acym_translation('ACYM_ACCESS_DENIED'), 'error');
49 -
50 - return 0;
51 - }
52 -
53 - $segmentClass = new SegmentClass();
54 -
55 - if (empty($segmentId)) {
56 - $segment = new \stdClass();
57 - $segment->creation_date = acym_date('now', 'Y-m-d H:i:s');
58 - } else {
59 - $segment = $segmentClass->getOneById($segmentId);
60 - if (empty($segment)) {
61 - return 0;
62 - }
63 - }
64 -
65 - $segment->name = $segmentRequest['name'];
66 - $segment->active = $segmentRequest['active'];
67 - $segment->filters = json_encode($filters['filters'], JSON_FORCE_OBJECT);
68 -
69 - $segmentId = $segmentClass->save($segment);
70 -
71 - return empty($segmentId) ? 0 : $segmentId;
72 - }
73 -
74 - public function countResultsTotal(): void
75 - {
76 - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
77 -
78 - $segmentSelected = acym_getVar('int', 'segment_selected');
79 - if (empty($segmentSelected)) {
80 - $stepAutomation = acym_getVar('array', 'acym_action', []);
81 - acym_blockRestrictedFilterAjax($stepAutomation);
82 - } else {
83 - $segmentClass = new SegmentClass();
84 - $segment = $segmentClass->getOneById($segmentSelected);
85 - if (empty($segment)) {
86 - $stepAutomation = [];
87 - } else {
88 - $stepAutomation = ['filters' => $segment->filters];
89 - }
90 - }
91 -
92 - //if we are in the campaign edition
93 - $listsIds = acym_getVar('string', 'list_selected', '[]');
94 - $listsIds = empty($listsIds) ? [] : json_decode($listsIds, true);
95 -
96 - $isExclude = acym_getVar('boolean', 'exclude', false);
97 - acym_sendAjaxResponse($this->countSegmentByParams($stepAutomation, $listsIds, $isExclude));
98 - }
99 -
100 - public function countSegmentByParams(array $segment, array $listsIds, bool $exclude = false): int
101 - {
102 - $automationHelpers = [];
103 -
104 - if (!empty($segment) && !empty($segment['filters'])) {
105 - foreach ($segment['filters'] as $or => $orValues) {
106 - if (empty($orValues)) continue;
107 -
108 - $automationHelpers[$or] = new AutomationHelper();
109 - foreach ($orValues as $and => $andValues) {
110 - $and = intval($and);
111 - foreach ($andValues as $filterName => $options) {
112 - acym_trigger('onAcymProcessFilter_'.$filterName, [&$automationHelpers[$or], &$options, $and.'_'.$or]);
113 - }
114 - }
115 -
116 - $automationHelpers[$or]->excludeSelected = $exclude;
117 - $automationHelpers[$or]->addFlag(self::FLAG_COUNT);
118 - }
119 - }
120 -
121 - if (!empty($listsIds)) {
122 - acym_arrayToInteger($listsIds);
123 -
124 - $join = ' #__acym_user_has_list AS user_list ON user_list.user_id = user.id ';
125 - $join .= 'AND user_list.list_id IN ('.implode(',', $listsIds).') ';
126 - $join .= 'AND user_list.status = 1 ';
127 - $join .= 'AND user.active = 1 ';
128 - if ($this->config->get('require_confirmation', 1) == 1) {
129 - $join .= 'AND user.confirmed = 1 ';
130 - }
131 - }
132 -
133 - if (empty($automationHelpers)) {
134 - $automationHelperBase = new AutomationHelper();
135 - if (!empty($listsIds)) {
136 - $automationHelperBase->join['user_list'] = $join;
137 - }
138 -
139 - return acym_loadResult($automationHelperBase->getQuery(['COUNT(DISTINCT user.id)']));
140 - } else {
141 - $automationHelperBase = array_pop($automationHelpers);
142 - if (!empty($listsIds)) {
143 - $automationHelperBase->join['user_list'] = $join;
144 - }
145 - $numberOfRecipients = acym_loadResult($automationHelperBase->getQuery(['COUNT(DISTINCT user.id)']));
146 - $automationHelperBase->removeFlag(self::FLAG_COUNT);
147 -
148 - return $numberOfRecipients;
149 - }
150 - }
151 -
152 - public function countResults(): void
153 - {
154 - wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
155 -
156 - $and = acym_getVar('int', 'and');
157 - $or = acym_getVar('int', 'or');
158 - $stepAutomation = acym_getVar('array', 'acym_action');
159 - acym_blockRestrictedFilterAjax($stepAutomation);
160 -
161 - //if we are in the campaign edition
162 - $listsIds = acym_getVar('string', 'list_selected', '');
163 -
164 - if (empty($stepAutomation['filters'][$or][$and])) {
165 - acym_sendAjaxResponse(acym_translation('ACYM_AUTOMATION_NOT_FOUND'), [], false);
166 - }
167 -
168 - $automationHelper = new AutomationHelper();
169 -
170 - if (!empty($listsIds)) {
171 - $listsIds = json_decode($listsIds);
172 - acym_arrayToInteger($listsIds);
173 - $join = $this->config->get('require_confirmation', 1) == 1 ? ' AND user.confirmed = 1' : '';
174 - $automationHelper->join['user_list'] = ' #__acym_user_has_list AS user_list ON user_list.user_id = user.id AND user_list.list_id IN ('.implode(
175 - ',',
176 - $listsIds
177 - ).') and user_list.status = 1 '.$join;
178 - }
179 -
180 - $filterName = key($stepAutomation['filters'][$or][$and]);
181 - $options = current($stepAutomation['filters'][$or][$and]);
182 - $messages = acym_trigger('onAcymProcessFilterCount_'.$filterName, [&$automationHelper, &$options, &$and]);
183 - $messages = $messages[0];
184 -
185 - if (!empty($listsIds)) {
186 - ob_start();
187 - acym_info(['textShownInTooltip' => 'ACYM_CONDITION_WITH_LISTS_COUNT', 'classText' => 'wysid_tooltip']);
188 - $messages .= ob_get_clean();
189 - }
190 -
191 - acym_sendAjaxResponse($messages);
192 - }
193 -
194 - public function usersSummary(): void
195 - {
196 - $offset = acym_getVar('int', 'offset', 0);
197 - $limit = acym_getVar('int', 'limit', 50);
198 - $search = acym_getVar('string', 'modal_search', '');
199 -
200 - $and = acym_getVar('int', 'and');
201 - $or = acym_getVar('int', 'or');
202 - $stepAutomation = acym_getVar('array', 'acym_action');
203 - acym_blockRestrictedFilterAjax($stepAutomation);
204 -
205 - if (empty($stepAutomation['filters'][$or][$and])) {
206 - acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_RETRIEVE_DATA'), [], false);
207 - }
208 -
209 - $automationHelper = new AutomationHelper();
210 -
211 - //if we are in the campaign edition
212 - $listsIds = acym_getVar('string', 'list_selected', '');
213 -
214 - if (!empty($listsIds)) {
215 - $listsIds = json_decode($listsIds);
216 - acym_arrayToInteger($listsIds);
217 - $join = $this->config->get('require_confirmation', 1) == 1 ? ' AND user.confirmed = 1' : '';
218 - $automationHelper->join['user_list'] = ' #__acym_user_has_list AS user_list ON user_list.user_id = user.id AND user_list.list_id IN ('.implode(
219 - ',',
220 - $listsIds
221 - ).') and user_list.status = 1 '.$join;
222 - }
223 -
224 - $filterName = key($stepAutomation['filters'][$or][$and]);
225 - $options = current($stepAutomation['filters'][$or][$and]);
226 - acym_trigger('onAcymProcessFilter_'.$filterName, [&$automationHelper, &$options, &$and]);
227 -
228 - if (!empty($search)) {
229 - $search = acym_escapeDB('%'.$search.'%');
230 - $automationHelper->where[] = ' (user.email LIKE '.$search.' OR user.name LIKE '.$search.' OR user.id LIKE '.$search.') ';
231 - }
232 -
233 - $automationHelper->limit = intval($offset).', '.intval($limit);
234 -
235 - $users = acym_loadObjectList($automationHelper->getQuery(['user.email', 'user.name', 'user.id']), 'id');
236 -
237 - acym_sendAjaxResponse('', ['users' => $users]);
238 - }
239 -}