PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / trunk
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress vtrunk
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 10.3.0 10.4.0 All 60 releases
acymailing / back / Types / DelayType.php

DelayType.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress trunk, at back/Types/DelayType.php

133 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Types;
4
5 use AcyMailing\Core\AcymObject;
6
7 class DelayType extends AcymObject
8 {
9 const TYPE_SECONDS_MINUTES = 0;
10 const TYPE_MINUTES_HOURS_DAYS_WEEKS = 1;
11 const TYPE_MINUTES_HOURS = 2;
12 const TYPE_HOURS_DAYS_WEEKS_MONTHS = 3;
13 const TYPE_WEEKS_MONTHS = 4;
14
15 public function display(
16 string $map,
17 int $value,
18 int $type = 1,
19 string $inputClass = '',
20 string $hiddenInputClass = ''
21 ): void {
22 static $num = 0;
23 $num++;
24
25 $js = '
26 function updateDelay'.$num.'() {
27 delayvar = window.document.getElementById("delayvar'.$num.'");
28 delaytype = window.document.getElementById("delaytype'.$num.'").value;
29 delayvalue = window.document.getElementById("delayvalue'.$num.'");
30 realValue = delayvalue.value;
31 if(delaytype === "minute"){ realValue = realValue*60; }
32 if(delaytype === "hour"){ realValue = realValue*3600; }
33 if(delaytype === "day"){ realValue = realValue*86400; }
34 if(delaytype === "week"){ realValue = realValue*604800; }
35 if(delaytype === "month"){ realValue = realValue*2592000; }
36 delayvar.value = realValue;
37 delayvar.dispatchEvent(new Event("change"));
38 }';
39 $updateFunction = 'updateDelay'.$num.'();';
40 acym_addScript(true, $js);
41
42 $values = [];
43
44 if ($type === self::TYPE_SECONDS_MINUTES) {
45 $values[] = acym_selectOption('second', 'ACYM_SECONDS');
46 $values[] = acym_selectOption('minute', 'ACYM_MINUTES');
47 } elseif ($type === self::TYPE_MINUTES_HOURS_DAYS_WEEKS) {
48 $values[] = acym_selectOption('minute', 'ACYM_MINUTES');
49 $values[] = acym_selectOption('hour', 'ACYM_HOURS');
50 $values[] = acym_selectOption('day', 'ACYM_DAYS');
51 $values[] = acym_selectOption('week', 'ACYM_WEEKS');
52 } elseif ($type === self::TYPE_MINUTES_HOURS) {
53 $values[] = acym_selectOption('minute', 'ACYM_MINUTES');
54 $values[] = acym_selectOption('hour', 'ACYM_HOURS');
55 } elseif ($type === self::TYPE_HOURS_DAYS_WEEKS_MONTHS) {
56 $values[] = acym_selectOption('hour', 'ACYM_HOURS');
57 $values[] = acym_selectOption('day', 'ACYM_DAYS');
58 $values[] = acym_selectOption('week', 'ACYM_WEEKS');
59 $values[] = acym_selectOption('month', 'ACYM_MONTHS');
60 } elseif ($type === self::TYPE_WEEKS_MONTHS) {
61 $values[] = acym_selectOption('week', 'ACYM_WEEKS');
62 $values[] = acym_selectOption('month', 'ACYM_MONTHS');
63 }
64
65 $return = $this->get($value, $type);
66 echo '<input class="intext_input '.esc_attr($inputClass).'"
67 onchange="'.esc_attr($updateFunction).'"
68 type="number"
69 min="0"
70 id="delayvalue'.esc_attr($num).'"
71 value="'.esc_attr($return->value).'" /> ';
72
73 acym_select(
74 $values,
75 'delaytype'.$num,
76 $return->type,
77 [
78 'class' => 'intext_select',
79 'onchange' => $updateFunction,
80 ],
81 'value',
82 'text',
83 'delaytype'.$num,
84 false,
85 true
86 );
87
88 echo '<input class="'.esc_attr($hiddenInputClass).'" type="hidden" name="'.esc_attr($map).'" id="delayvar'.esc_attr($num).'" value="'.esc_attr($value).'"/>';
89 }
90
91 public function get(int $value, int $type): object
92 {
93
94 $return = new \stdClass();
95
96 $return->value = $value;
97 if ($type === 0) {
98 $return->type = 'second';
99 $return->typeText = acym_translation('ACYM_SECONDS');
100 } else {
101 $return->type = 'minute';
102 $return->typeText = acym_translation('ACYM_MINUTES');
103 }
104
105 if ($return->value >= 60 && $return->value % 60 == 0) {
106 $return->value = (int)$return->value / 60;
107 $return->type = 'minute';
108 $return->typeText = acym_translation('ACYM_MINUTES');
109 if ($type !== 0 && $return->value >= 60 && $return->value % 60 == 0) {
110 $return->type = 'hour';
111 $return->typeText = acym_translation('ACYM_HOURS');
112 $return->value = $return->value / 60;
113 if ($type !== 2 && $return->value >= 24 && $return->value % 24 == 0) {
114 $return->type = 'day';
115 $return->typeText = acym_translation('ACYM_DAYS');
116 $return->value = $return->value / 24;
117 if ($type >= 3 && $return->value >= 30 && $return->value % 30 == 0) {
118 $return->type = 'month';
119 $return->typeText = acym_translation('ACYM_MONTHS');
120 $return->value = $return->value / 30;
121 } elseif ($return->value >= 7 && $return->value % 7 == 0) {
122 $return->type = 'week';
123 $return->typeText = acym_translation('ACYM_WEEKS');
124 $return->value = $return->value / 7;
125 }
126 }
127 }
128 }
129
130 return $return;
131 }
132 }
133