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/time/TimeAutomationTriggers.php +0 -418 10.10.2 → 11.1.1 View file →
@@ -1,418 +1,0 @@
1 -<?php
2 -
3 -trait TimeAutomationTriggers
4 -{
5 - public function onAcymDeclareTriggers(&$triggers, &$defaultValues)
6 - {
7 - $dailyHour = $this->config->get('daily_hour', '12');
8 - $dailyMinute = $this->config->get('daily_minute', '00');
9 -
10 - $triggers['classic']['asap'] = new stdClass();
11 - $triggers['classic']['asap']->name = acym_translation('ACYM_EACH_TIME');
12 - $triggers['classic']['asap']->option = '<input type="hidden" name="[triggers][classic][asap]" value="y">';
13 -
14 - $hour = [];
15 - $minutes = [];
16 - $i = 0;
17 - while ($i <= 59) {
18 - if ($i <= 23) {
19 - $hour[$i] = $i < 10 ? '0'.$i : $i;
20 - }
21 - $minutes[$i] = $i < 10 ? '0'.$i : $i;
22 - $i++;
23 - }
24 -
25 -
26 - $triggers['classic']['day'] = new stdClass();
27 - $triggers['classic']['day']->name = acym_translation('ACYM_EVERY_DAY_AT');
28 - $triggers['classic']['day']->option = '<div class="grid-x grid-margin-x" style="height: 40px;">';
29 - $triggers['classic']['day']->option .= '<div class="cell medium-shrink">'.acym_select(
30 - $hour,
31 - '[triggers][classic][day][hour]',
32 - empty($defaultValues['day']) ? date('H') : $defaultValues['day']['hour'],
33 - ['data-class' => 'intext_select acym__select']
34 - ).'</div>';
35 - $triggers['classic']['day']->option .= '<div class="cell medium-shrink acym_vcenter">:</div>';
36 - $triggers['classic']['day']->option .= '<div class="cell medium-auto">'.acym_select(
37 - $minutes,
38 - '[triggers][classic][day][minutes]',
39 - empty($defaultValues['day']) ? date('i') : $defaultValues['day']['minutes'],
40 - ['data-class' => 'intext_select acym__select']
41 - ).'</div>';
42 - $triggers['classic']['day']->option .= '</div>';
43 -
44 - $days = [
45 - 'monday' => acym_translation('ACYM_MONDAY'),
46 - 'tuesday' => acym_translation('ACYM_TUESDAY'),
47 - 'wednesday' => acym_translation('ACYM_WEDNESDAY'),
48 - 'thursday' => acym_translation('ACYM_THURSDAY'),
49 - 'friday' => acym_translation('ACYM_FRIDAY'),
50 - 'saturday' => acym_translation('ACYM_SATURDAY'),
51 - 'sunday' => acym_translation('ACYM_SUNDAY'),
52 - ];
53 -
54 - $triggers['classic']['weeks_on'] = new stdClass();
55 - $triggers['classic']['weeks_on']->name = acym_translation('ACYM_EVERY_WEEK_ON');
56 - $triggers['classic']['weeks_on']->option = '<div class="grid-x">';
57 - $triggers['classic']['weeks_on']->option .= '<div class="cell">'.acym_selectMultiple(
58 - $days,
59 - '[triggers][classic][weeks_on][day]',
60 - empty($defaultValues['weeks_on']) ? ['monday'] : $defaultValues['weeks_on']['day'],
61 - ['data-class' => 'acym__select']
62 - ).'</div>';
63 - $triggers['classic']['weeks_on']->option .= '<div class="cell margin-top-1 acym_vcenter">';
64 - $triggers['classic']['weeks_on']->option .= acym_translationSprintf(
65 - 'ACYM_AT_DATE_TIME',
66 - '<div class="margin-left-1 margin-right-1">'.acym_select(
67 - $hour,
68 - '[triggers][classic][weeks_on][hour]',
69 - !isset($defaultValues['weeks_on']['hour']) ? $dailyHour : $defaultValues['weeks_on']['hour'],
70 - ['data-class' => 'intext_select acym__select']
71 - ).'</div>',
72 - '<div class="margin-left-1 margin-right-1">'.acym_select(
73 - $minutes,
74 - '[triggers][classic][weeks_on][minutes]',
75 - !isset($defaultValues['weeks_on']['minutes']) ? $dailyMinute : $defaultValues['weeks_on']['minutes'],
76 - ['data-class' => 'intext_select acym__select']
77 - ).'</div>'
78 - );
79 - $triggers['classic']['weeks_on']->option .= '</div>';
80 - $triggers['classic']['weeks_on']->option .= '</div>';
81 -
82 -
83 - $triggers['classic']['on_day_month'] = new stdClass();
84 - $triggers['classic']['on_day_month']->name = acym_translation('ACYM_ONTHE');
85 - $triggers['classic']['on_day_month']->option = '<div class="grid-x grid-margin-x margin-y">';
86 - $triggers['classic']['on_day_month']->option .= '<div class="cell medium-4">'.acym_select(
87 - [
88 - 'first' => acym_translation('ACYM_FIRST'),
89 - 'second' => acym_translation('ACYM_SECOND'),
90 - 'third' => acym_translation('ACYM_THIRD'),
91 - 'fourth' => acym_translation('ACYM_FOURTH'),
92 - 'last' => acym_translation('ACYM_LAST'),
93 - ],
94 - '[triggers][classic][on_day_month][number]',
95 - empty($defaultValues['on_day_month']) ? null : $defaultValues['on_day_month']['number'],
96 - ['data-class' => 'acym__select']
97 - ).'</div>';
98 - $triggers['classic']['on_day_month']->option .= '<div class="cell medium-4">'.acym_select(
99 - $days,
100 - '[triggers][classic][on_day_month][day]',
101 - empty($defaultValues['on_day_month']) ? null : $defaultValues['on_day_month']['day'],
102 - [
103 - 'data-class' => 'acym__select',
104 - 'style' => 'margin: 0 10px;',
105 - ]
106 - ).'</div>';
107 - $triggers['classic']['on_day_month']->option .= '<div class="cell medium-4 acym_vcenter">'.acym_translation('ACYM_DAYOFMONTH').'</div>';
108 - $triggers['classic']['on_day_month']->option .= '<div class="cell acym_vcenter">';
109 - $triggers['classic']['on_day_month']->option .= acym_translationSprintf(
110 - 'ACYM_AT_DATE_TIME',
111 - '<div class="margin-left-1 margin-right-1">'.acym_select(
112 - $hour,
113 - '[triggers][classic][on_day_month][hour]',
114 - !isset($defaultValues['on_day_month']['hour']) ? $dailyHour : $defaultValues['on_day_month']['hour'],
115 - ['data-class' => 'intext_select acym__select']
116 - ).'</div>',
117 - '<div class="margin-left-1 margin-right-1">'.acym_select(
118 - $minutes,
119 - '[triggers][classic][on_day_month][minutes]',
120 - !isset($defaultValues['on_day_month']['minutes']) ? $dailyMinute : $defaultValues['on_day_month']['minutes'],
121 - ['data-class' => 'intext_select acym__select']
122 - ).'</div>'
123 - );
124 - $triggers['classic']['on_day_month']->option .= '</div>';
125 - $triggers['classic']['on_day_month']->option .= '</div>';
126 -
127 -
128 - $every = [
129 - '3600' => acym_translation('ACYM_HOURS'),
130 - '86400' => acym_translation('ACYM_DAYS'),
131 - '604800' => acym_translation('ACYM_WEEKS'),
132 - '2628000' => acym_translation('ACYM_MONTHS'),
133 - ];
134 -
135 - $defaultEvery = empty($defaultValues['every']['number']) ? '1' : $defaultValues['every']['number'];
136 - $triggers['classic']['every'] = new stdClass();
137 - $triggers['classic']['every']->name = acym_translation('ACYM_EVERY');
138 - $triggers['classic']['every']->option = '<div class="grid-x grid-margin-x">';
139 - $triggers['classic']['every']->option .= '<div class="cell medium-shrink">';
140 - $triggers['classic']['every']->option .= '<input type="number" min="1" name="[triggers][classic][every][number]" class="intext_input" value="'.intval($defaultEvery).'">';
141 - $triggers['classic']['every']->option .= '</div>';
142 - $triggers['classic']['every']->option .= '<div class="cell medium-auto">'.acym_select(
143 - $every,
144 - '[triggers][classic][every][type]',
145 - empty($defaultValues['every']) ? '604800' : $defaultValues['every']['type'],
146 - ['data-class' => 'intext_select acym__select']
147 - ).'</div>';
148 - $triggers['classic']['every']->option .= '</div>';
149 - }
150 -
151 - public function onAcymExecuteTrigger(&$step, &$execute, &$data)
152 - {
153 - if (!empty($step->is_scenario)) {
154 - return;
155 - }
156 -
157 - $time = $data['time'];
158 - $triggers = $step->triggers;
159 -
160 - $nextExecutionDate = [];
161 -
162 - $dailyHour = $this->config->get('daily_hour', '12');
163 - $dailyMinute = $this->config->get('daily_minute', '00');
164 -
165 -
166 - if (!empty($triggers['asap'])) {
167 - $execute = true;
168 - $nextExecutionDate[] = $time;
169 - }
170 -
171 - if (!empty($triggers['day'])) {
172 - $dayBasedOnCMSTimezone = acym_date('now', 'Y-m-d');
173 -
174 - $hour = $triggers['day']['hour'];
175 - $minutes = $triggers['day']['minutes'];
176 -
177 - if (strlen($hour) < 2) $hour = '0'.$hour;
178 - if (strlen($minutes) < 2) $minutes = '0'.$minutes;
179 -
180 - $dayBasedOnCMSTimezoneAtSpecifiedHour = acym_getTimeFromCMSDate($dayBasedOnCMSTimezone.' '.$hour.':'.$minutes);
181 -
182 - if ($time < $dayBasedOnCMSTimezoneAtSpecifiedHour) {
183 - $nextExecutionDate[] = $dayBasedOnCMSTimezoneAtSpecifiedHour;
184 - } else {
185 - $nextExecutionDate[] = $dayBasedOnCMSTimezoneAtSpecifiedHour + 86400;
186 -
187 - if (empty($step->last_execution)) $execute = true;
188 - }
189 - }
190 -
191 - if (!empty($triggers['weeks_on'])) {
192 - if (isset($triggers['weeks_on']['hour'])) {
193 - $hour = $triggers['weeks_on']['hour'];
194 - $minutes = $triggers['weeks_on']['minutes'];
195 - } else {
196 - $hour = $dailyHour;
197 - $minutes = $dailyMinute;
198 - }
199 -
200 - if (strlen($hour) < 2) $hour = '0'.$hour;
201 - if (strlen($minutes) < 2) $minutes = '0'.$minutes;
202 -
203 - foreach ($triggers['weeks_on']['day'] as $day) {
204 - $dayBasedOnCMSTimezone = acym_date('now', 'Y-m-d');
205 -
206 - $dayBasedOnCMSTimezoneAtSpecifiedHour = acym_getTimeFromCMSDate($dayBasedOnCMSTimezone.' '.$hour.':'.$minutes);
207 -
208 - if ($day == strtolower(acym_date('now', 'l', true, false))) {
209 - if ($time < $dayBasedOnCMSTimezoneAtSpecifiedHour) {
210 - $nextExecutionDate[] = $dayBasedOnCMSTimezoneAtSpecifiedHour;
211 - } else {
212 - $nextExecutionDate[] = $dayBasedOnCMSTimezoneAtSpecifiedHour + 604800;
213 -
214 - $lastExecutionIsNotToday = acym_date($step->last_execution, 'Y-m-d') !== $dayBasedOnCMSTimezone;
215 - $nextExecutionIsToday = acym_date($step->next_execution, 'Y-m-d') === $dayBasedOnCMSTimezone;
216 - if (empty($step->last_execution) || ($lastExecutionIsNotToday && $nextExecutionIsToday)) $execute = true;
217 - }
218 - } else {
219 - $days = [
220 - 'monday',
221 - 'tuesday',
222 - 'wednesday',
223 - 'thursday',
224 - 'friday',
225 - 'saturday',
226 - 'sunday',
227 - ];
228 - $currentDayOfWeek = acym_date('now', 'N') - 1;
229 - $wantedDayOfWeek = array_search($day, $days);
230 -
231 - $shift = $wantedDayOfWeek - $currentDayOfWeek;
232 - if ($shift < 0) $shift += 7;
233 -
234 - $nextExecutionDate[] = $dayBasedOnCMSTimezoneAtSpecifiedHour + 86400 * $shift;
235 - }
236 - }
237 - }
238 -
239 - if (!empty($triggers['on_day_month'])) {
240 - if (isset($triggers['on_day_month']['hour'])) {
241 - $hour = $triggers['on_day_month']['hour'];
242 - $minutes = $triggers['on_day_month']['minutes'];
243 - } else {
244 - $hour = $dailyHour;
245 - $minutes = $dailyMinute;
246 - }
247 -
248 - if (strlen($hour) < 2) $hour = '0'.$hour;
249 - if (strlen($minutes) < 2) $minutes = '0'.$minutes;
250 -
251 - $today = acym_getTime('today '.$hour.':'.$minutes);
252 -
253 - $execution = acym_getTime($triggers['on_day_month']['number'].' '.$triggers['on_day_month']['day'].' of this month '.$hour.':'.$minutes);
254 -
255 - if ($execution < $today) {
256 - $execution = acym_getTime($triggers['on_day_month']['number'].' '.$triggers['on_day_month']['day'].' of next month '.$hour.':'.$minutes);
257 - }
258 -
259 - if ($execution > $time) {
260 - $nextExecutionDate[] = $execution;
261 - } else {
262 -
263 -
264 - if (empty($step->last_execution)) {
265 - $execute = true;
266 - }
267 -
268 - $nextExecutionDate[] = $execution + 2628000;
269 - }
270 - }
271 -
272 - if (!empty($triggers['every'])) {
273 - if (empty($step->last_execution)) {
274 - $execute = true;
275 - } else {
276 - if ($triggers['every']['type'] == 2628000) {
277 - $nextDate = new \DateTime(acym_date($step->last_execution, 'Y-m-d H:m:i', false), new \DateTimeZone('UTC'));
278 - $nextDate = $nextDate->add(new \DateInterval('P'.$triggers['every']['number'].'M'));
279 - $nextDate = $nextDate->getTimestamp();
280 - } else {
281 - $nextDate = $step->last_execution + ($triggers['every']['number'] * $triggers['every']['type']);
282 - }
283 -
284 - if ($nextDate > $time) {
285 - $nextExecutionDate[] = $nextDate;
286 - } else {
287 - $execute = true;
288 - }
289 - }
290 -
291 - if ($execute) {
292 - $nextExecutionDate[] = $time + ($triggers['every']['number'] * $triggers['every']['type']);
293 - }
294 - }
295 -
296 - if (!empty($nextExecutionDate)) {
297 - $step->next_execution = min($nextExecutionDate);
298 - }
299 - }
300 -
301 - public function onAcymDeclareSummary_triggers(object $automation): void
302 - {
303 - if (!empty($automation->triggers['type_trigger'])) {
304 - unset($automation->triggers['type_trigger']);
305 - }
306 -
307 - $days = [
308 - 'monday' => acym_translation('ACYM_MONDAY'),
309 - 'tuesday' => acym_translation('ACYM_TUESDAY'),
310 - 'wednesday' => acym_translation('ACYM_WEDNESDAY'),
311 - 'thursday' => acym_translation('ACYM_THURSDAY'),
312 - 'friday' => acym_translation('ACYM_FRIDAY'),
313 - 'saturday' => acym_translation('ACYM_SATURDAY'),
314 - 'sunday' => acym_translation('ACYM_SUNDAY'),
315 - ];
316 -
317 - $this->summaryAsap($automation);
318 - $this->summaryDay($automation);
319 - $this->summaryWeeksOn($automation, $days);
320 - $this->summaryOnDayMonth($automation, $days);
321 - $this->summaryEvery($automation);
322 - }
323 -
324 - private function summaryAsap(object $automation): void
325 - {
326 - if (!empty($automation->triggers['asap'])) {
327 - $automation->triggers['asap'] = acym_translation('ACYM_EACH_TIME');
328 - }
329 - }
330 -
331 - private function summaryDay(object $automation): void
332 - {
333 - if (empty($automation->triggers['day']) || !is_array($automation->triggers['day'])) {
334 - return;
335 - }
336 -
337 - $hour = sprintf('%02d', $automation->triggers['day']['hour']);
338 - $minutes = sprintf('%02d', $automation->triggers['day']['minutes']);
339 -
340 - $automation->triggers['day'] = acym_translationSprintf('ACYM_TRIGGER_DAY_SUMMARY', $hour, $minutes);
341 - }
342 -
343 - private function summaryWeeksOn(object $automation, array $days): void
344 - {
345 - if (empty($automation->triggers['weeks_on']) || !is_array($automation->triggers['weeks_on'])) {
346 - return;
347 - }
348 -
349 - foreach ($automation->triggers['weeks_on']['day'] as $i => $oneDay) {
350 - $automation->triggers['weeks_on']['day'][$i] = $days[$oneDay];
351 - }
352 -
353 - if (isset($automation->triggers['weeks_on']['hour'])) {
354 - $hour = $automation->triggers['weeks_on']['hour'];
355 - $minutes = $automation->triggers['weeks_on']['minutes'];
356 - } else {
357 - $hour = $this->config->get('daily_hour', '12');
358 - $minutes = $this->config->get('daily_minute', '00');
359 - }
360 -
361 - $hour = sprintf('%02d', $hour);
362 - $minutes = sprintf('%02d', $minutes);
363 -
364 - $automation->triggers['weeks_on'] = acym_translationSprintf(
365 - 'ACYM_TRIGGER_WEEKS_ON_SUMMARY',
366 - implode(', ', $automation->triggers['weeks_on']['day'])
367 - ).' '.acym_translationSprintf('ACYM_AT_DATE_TIME', $hour, $minutes);
368 - }
369 -
370 - private function summaryOnDayMonth(object $automation, array $days): void
371 - {
372 - if (empty($automation->triggers['on_day_month']) || !is_array($automation->triggers['on_day_month'])) {
373 - return;
374 - }
375 -
376 - $numbers = [
377 - 'first' => acym_translation('ACYM_FIRST'),
378 - 'second' => acym_translation('ACYM_SECOND'),
379 - 'third' => acym_translation('ACYM_THIRD'),
380 - 'fourth' => acym_translation('ACYM_FOURTH'),
381 - 'last' => acym_translation('ACYM_LAST'),
382 - ];
383 -
384 - if (isset($automation->triggers['on_day_month']['hour'])) {
385 - $hour = $automation->triggers['on_day_month']['hour'];
386 - $minutes = $automation->triggers['on_day_month']['minutes'];
387 - } else {
388 - $hour = $this->config->get('daily_hour', '12');
389 - $minutes = $this->config->get('daily_minute', '00');
390 - }
391 -
392 - $hour = sprintf('%02d', $hour);
393 - $minutes = sprintf('%02d', $minutes);
394 -
395 - $automation->triggers['on_day_month'] = acym_translationSprintf(
396 - 'ACYM_TRIGGER_ON_DAY_MONTH_SUMMARY',
397 - $numbers[$automation->triggers['on_day_month']['number']],
398 - $days[$automation->triggers['on_day_month']['day']]
399 - ).' '.acym_translationSprintf('ACYM_AT_DATE_TIME', $hour, $minutes);
400 - }
401 -
402 - private function summaryEvery(object $automation): void
403 - {
404 - if (empty($automation->triggers['every']) || !is_array($automation->triggers['every'])) {
405 - return;
406 - }
407 -
408 - if ($automation->triggers['every']['type'] == 3600) $automation->triggers['every']['type'] = acym_translation('ACYM_HOURS');
409 - if ($automation->triggers['every']['type'] == 86400) $automation->triggers['every']['type'] = acym_translation('ACYM_DAYS');
410 - if ($automation->triggers['every']['type'] == 604800) $automation->triggers['every']['type'] = acym_translation('ACYM_WEEKS');
411 - if ($automation->triggers['every']['type'] == 2628000) $automation->triggers['every']['type'] = acym_translation('ACYM_MONTHS');
412 - $automation->triggers['every'] = acym_translationSprintf(
413 - 'ACYM_TRIGGER_EVERY_SUMMARY',
414 - $automation->triggers['every']['number'],
415 - $automation->triggers['every']['type']
416 - );
417 - }
418 -}