PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / trunk
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution vtrunk
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
← All changes | app/Services/SanitizeService.php +41 -12 1.5.21trunk View file →
@@ -5,9 +5,9 @@
5 5 use FluentBooking\Framework\Support\Arr;
6 6
7 7 class SanitizeService
8 8 {
9 - public static function weeklySchedules($schedules, $fromTimeZone = '', $toTimeZone = false, $fromUser = true)
9 + public static function weeklySchedules($schedules, $fromTimeZone = '', $toTimeZone = false, $fromUser = false)
10 10 {
11 11 $dstTimeZone = $fromTimeZone == 'UTC' ? $toTimeZone : $fromTimeZone;
12 12
13 13 $dateWithoutDST = DateTimeHelper::getDateWithoutDST($dstTimeZone);
@@ -21,9 +21,16 @@
21 21 }
22 22
23 23 $schedule['enabled'] = true;
24 24
25 - foreach ($schedule['slots'] as $index => $slot) {
25 + if ($fromUser) {
26 + usort($schedule['slots'], function ($a, $b) {
27 + return strcmp($a['start'], $b['start']);
28 + });
29 + }
30 +
31 + $cleanedSlots = [];
32 + foreach ($schedule['slots'] as $slot) {
26 33 if ($fromUser) {
27 34 $slot['start'] = sanitize_text_field($slot['start']);
28 35 $slot['end'] = sanitize_text_field($slot['end']);
29 36 }
@@ -28,9 +35,8 @@
28 35 $slot['end'] = sanitize_text_field($slot['end']);
29 36 }
30 37
31 38 if (!$slot['start'] || !$slot['end']) {
32 - unset($schedule['slots'][$index]);
33 39 continue;
34 40 }
35 41
36 42 if ($toTimeZone && $fromTimeZone) {
@@ -37,18 +43,18 @@
37 43 $slot['start'] = DateTimeHelper::convertToTimeZone($slot['start'], $fromTimeZone, $toTimeZone, 'H:i', $dateWithoutDST);
38 44 $slot['end'] = DateTimeHelper::convertToTimeZone($slot['end'], $fromTimeZone, $toTimeZone, 'H:i', $dateWithoutDST);
39 45 }
40 46
41 - $schedule['slots'][$index] = $slot;
47 + $cleanedSlots[] = $slot;
42 48 }
43 49
44 - $schedule['slots'] = array_values($schedule['slots']);
50 + $schedule['slots'] = array_values($cleanedSlots);
45 51 }
46 52
47 53 return $schedules;
48 54 }
49 55
50 - public static function slotDateOverrides($overrides, $fromTimeZone = '', $toTimeZone = false, $event = false)
56 + public static function slotDateOverrides($overrides, $fromTimeZone = '', $toTimeZone = false, $event = null, $fromUser = false)
51 57 {
52 58 $todayTimeStamp = strtotime(gmdate('Y-m-d')); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
53 59
54 60 $validOverrides = [];
@@ -65,12 +71,20 @@
65 71 $isSkipped = true;
66 72 continue;
67 73 }
68 74
75 + if ($fromUser) {
76 + usort($slots, function ($a, $b) {
77 + return strcmp($a['start'], $b['start']);
78 + });
79 + }
80 +
69 81 $utcSlots = [];
70 82 foreach ($slots as $index => $slot) {
71 - $slot['start'] = sanitize_text_field($slot['start']);
72 - $slot['end'] = sanitize_text_field($slot['end']);
83 + if ($fromUser) {
84 + $slot['start'] = sanitize_text_field($slot['start']);
85 + $slot['end'] = sanitize_text_field($slot['end']);
86 + }
73 87
74 88 if (empty($slot['start']) || empty($slot['end'])) {
75 89 unset($slots[$index]);
76 90 continue;
@@ -88,11 +102,13 @@
88 102 if ($utcSlots) {
89 103 $updatedOverRides[$date] = $utcSlots;
90 104 }
91 105
92 - if ($slots) {
93 - $validOverrides[$date] = array_values($slots);
106 + if (!$slots) {
107 + continue;
94 108 }
109 +
110 + $validOverrides[$date] = array_values($slots);
95 111 }
96 112
97 113 if ($isSkipped && $fromTimeZone == 'UTC' && $event) {
98 114 $event->settings = ['date_overrides' => $updatedOverRides];
@@ -101,9 +117,8 @@
101 117
102 118 return $validOverrides;
103 119 }
104 120
105 -
106 121 public static function rangeDateBetween($range)
107 122 {
108 123 $range = array_filter($range);
109 124 if (!$range || count($range) != 2) {
@@ -127,9 +142,9 @@
127 142 ];
128 143 }
129 144
130 145 return [
131 - 'value' => (int)Arr::get($conditions, 'value', 4),
146 + 'value' => max(0, (int)Arr::get($conditions, 'value', 4)),
132 147 'unit' => sanitize_text_field(Arr::get($conditions, 'unit', 'hours'))
133 148 ];
134 149 }
135 150
@@ -170,6 +185,20 @@
170 185 $sanitizedLocations[] = $sanitizedLocation;
171 186 }
172 187
173 188 return $sanitizedLocations;
189 + }
190 +
191 + public static function sanitizeUtmData($value)
192 + {
193 + return sanitize_text_field($value);
194 + }
195 +
196 + public static function sanitizeAddons($inputs)
197 + {
198 + return array_keys(array_filter([
199 + 'fluent-crm' => Arr::get($inputs, 'install_fluentcrm', 'no') == 'yes',
200 + 'fluent-smtp' => Arr::get($inputs, 'install_fluentsmtp', 'no') == 'yes',
201 + 'fluent-cart' => Arr::get($inputs, 'install_fluentcart', 'no') == 'yes',
202 + ]));
174 203 }
175 204 }