PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.1
1.7.1 1.7.0 1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 All 51 releases
fluent-cart / app / Http / Requests / FluentMetaRequest.php

FluentMetaRequest.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.7.1, at app/Http/Requests/FluentMetaRequest.php

243 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Http\Requests;
4
5 use FluentCart\Framework\Foundation\RequestGuard;
6 use FluentCart\Framework\Support\Arr;
7 use FluentCart\App\Services\Permission\PermissionManager;
8 use FluentCart\App\Services\Theme\ColorPalette;
9 use FluentCart\App\Services\Theme\RadiusPalette;
10
11 class FluentMetaRequest extends RequestGuard
12 {
13
14 /**
15 * @return array
16 */
17 public function rules()
18 {
19
20
21 $rulesMap = [
22 'store_setup' => [
23 'store_name' => 'required|sanitizeText|maxLength:200',
24 'store_country' => 'required|sanitizeText|maxLength:200',
25 'seller_vat_id' => 'nullable|sanitizeText|maxLength:50',
26 'seller_tax_id' => 'nullable|sanitizeText|maxLength:50',
27 ]
28 ];
29
30 $rules = Arr::get($rulesMap, $this->get('settings_name'), []);
31
32 // The radius fields only show under Customize; a value hidden under
33 // another source is dropped by the sanitiser rather than blocking the save.
34 if ($this->get('settings_name') === 'appearance' && $this->get('appearance_source') === ColorPalette::SOURCE_CUSTOM) {
35 $rules = array_merge($rules, RadiusPalette::validationRules());
36 }
37 // $rules = [
38 // 'object_id' => 'integer|min:1',
39 // 'object_type' => 'nullable|sanitizeText|max:50',
40 // 'meta_key' => 'nullable|sanitizeText|max:50',
41 // 'meta_value' => 'nullable|sanitizeText',
42 // 'store_name' => 'required|sanitizeText|max:200',
43 // 'store_country' => 'required|sanitizeText|max:200',
44 // ];
45 return apply_filters('fluent_cart/store_settings/rules', $rules);
46 }
47
48
49 /**
50 * @return array
51 */
52 public function messages(): array
53 {
54 return [
55 'store_name.required' => esc_html__('Store name is required.', 'fluent-cart'),
56 'store_country.required' => esc_html__('Store country is required.', 'fluent-cart'),
57 ];
58 }
59
60
61 /**
62 * @return array
63 */
64 public function sanitize(): array
65 {
66 $sanitizer = [
67 'object_type' => 'sanitize_text_field',
68 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
69 'meta_key' => 'sanitize_text_field',
70 'type' => 'sanitize_text_field',
71 'default' => 'sanitize_text_field',
72 'store_name' => 'sanitize_text_field',
73 'company_name' => 'sanitize_text_field',
74 'legal_registration_id' => 'sanitize_text_field',
75 'seller_vat_id' => 'sanitize_text_field',
76 'seller_tax_id' => 'sanitize_text_field',
77 'store_logo' => function ($value) {
78 if (!is_array($value)) {
79 return '';
80 }
81 return [
82 'id' => sanitize_text_field(Arr::get($value, 'id')),
83 'url' => sanitize_url(Arr::get($value, 'url')),
84 'title' => sanitize_text_field(Arr::get($value, 'title')),
85 ];
86 },
87 'checkout_button_text' => 'sanitize_text_field',
88 'view_cart_button_text' => 'sanitize_text_field',
89 'note_for_user_account_creation' => 'sanitize_text_field',
90 'cart_button_text' => 'sanitize_text_field',
91 'popup_button_text' => 'sanitize_text_field',
92 'out_of_stock_button_text' => 'sanitize_text_field',
93 'thousand_separator' => 'sanitize_text_field',
94 'decimal_separator' => 'sanitize_text_field',
95 'currency_position' => 'sanitize_text_field',
96 'checkout_method_style' => 'sanitize_text_field',
97 'require_logged_in' => 'sanitize_text_field',
98 'enable_modal_checkout' => 'sanitize_text_field',
99 'show_cart_icon_in_nav' => 'sanitize_text_field',
100 'show_cart_icon_in_body' => 'sanitize_text_field',
101 'additional_address_field' => 'sanitize_text_field',
102 'hide_coupon_field' => 'sanitize_text_field',
103 'user_account_creation_mode' => 'sanitize_text_field',
104 'require_customer_email_verification' => function ($value) {
105 return $value === 'no' ? 'no' : 'yes';
106 },
107 'auto_login_after_account_creation' => function ($value) {
108 return $value === 'yes' ? 'yes' : 'no';
109 },
110 'force_ssl' => 'sanitize_text_field',
111 'checkout_page_id' => 'intval',
112 'custom_payment_page_id' => 'intval',
113 'cart_page_id' => 'intval',
114 'receipt_page_id' => 'intval',
115 'order_review_page_id' => 'intval',
116 'shop_page_id' => 'intval',
117 'customer_profile_page_id' => 'intval',
118 'customer_profile_page_slug' => 'sanitize_text_field',
119 'registration_page_id' => 'intval',
120 'login_page_id' => 'intval',
121 'plugin_activated_once' => 'sanitize_text_field',
122 'rest_route' => 'sanitize_text_field',
123 'currency' => 'sanitize_text_field',
124 'store_address1' => 'sanitize_text_field',
125 'store_address2' => 'sanitize_text_field',
126 'store_city' => 'sanitize_text_field',
127 'store_country' => 'sanitize_text_field',
128 'store_postcode' => 'sanitize_text_field',
129 'store_state' => 'sanitize_text_field',
130 'template_settings_checkout_page_mode' => 'sanitize_text_field',
131 'show_relevant_product_in_single_page' => 'sanitize_text_field',
132 'show_relevant_product_in_modal' => 'sanitize_text_field',
133 'show_reviews_in_single_page' => 'sanitize_text_field',
134 'show_rating_in_shop' => 'sanitize_text_field',
135 'show_rating_in_relevant' => 'sanitize_text_field',
136 'enable_early_payment_for_installment' => 'sanitize_text_field',
137 'subscription_management_mode' => function ($value) {
138 $value = sanitize_text_field($value);
139 $allowed = ['gateway_managed', 'store_managed'];
140 return in_array($value, $allowed, true) ? $value : 'gateway_managed';
141 },
142 'subscription_system_charge' => function ($value) {
143 $value = sanitize_text_field($value);
144 return in_array($value, ['yes', 'no'], true) ? $value : 'no';
145 },
146 'subscription_manual_fallback' => function ($value) {
147 $value = sanitize_text_field($value);
148 return in_array($value, ['yes', 'no'], true) ? $value : 'no';
149 },
150 'order_mode' => 'sanitize_text_field',
151 'subscription_mode_guard' => function ($value) {
152 $value = sanitize_text_field($value);
153 return in_array($value, ['yes', 'no'], true) ? $value : 'yes';
154 },
155 'variation_view' => 'sanitize_text_field',
156 'variation_columns' => 'sanitize_text_field',
157 'modules_settings' => 'sanitize_text_field',
158 'product_slug' => 'sanitize_text_field',
159 'min_receipt_number' => 'sanitize_text_field',
160 'inv_prefix' => 'sanitize_text_field',
161 'date_time_format_source' => function ($value) {
162 $value = sanitize_text_field($value);
163 return in_array($value, ['fluent_cart', 'wordpress'], true) ? $value : 'fluent_cart';
164 },
165 'timezone_source' => function ($value) {
166 $value = sanitize_text_field($value);
167 return in_array($value, ['fluent_cart', 'wordpress'], true) ? $value : 'fluent_cart';
168 },
169 'weight_unit' => function ($value) {
170 if (!PermissionManager::hasPermission(['store/sensitive'])) {
171 $stored = get_option('fluent_cart_store_settings', []);
172 return $stored['weight_unit'] ?? 'kg';
173 }
174 $value = sanitize_text_field($value);
175 $allowed = ['kg', 'g', 'lbs', 'oz'];
176 return in_array($value, $allowed, true) ? $value : 'kg';
177 },
178 'dimension_unit' => function ($value) {
179 if (!PermissionManager::hasPermission(['store/sensitive'])) {
180 $stored = get_option('fluent_cart_store_settings', []);
181 return $stored['dimension_unit'] ?? 'cm';
182 }
183 $value = sanitize_text_field($value);
184 $allowed = ['cm', 'mm', 'in', 'm'];
185 return in_array($value, $allowed, true) ? $value : 'cm';
186 },
187 'enable_image_zoom_in_single_product' => 'sanitize_text_field',
188 'enable_image_zoom_in_modal' => 'sanitize_text_field',
189 'appearance_source' => function ($value) {
190 $value = sanitize_text_field($value);
191
192 return in_array($value, ColorPalette::sources(), true)
193 ? $value
194 : ColorPalette::SOURCE_DEFAULT;
195 },
196 'appearance_colors' => function ($value) {
197 if (!is_array($value)) {
198 return [];
199 }
200
201 // Driven off the registry rather than the submitted keys, so an
202 // unknown property can never reach the storefront stylesheet.
203 $colors = [];
204
205 foreach (ColorPalette::globals() as $key => $definition) {
206 $hex = sanitize_hex_color((string)Arr::get($value, $key, ''));
207
208 // sanitize_hex_color() returns null for anything malformed
209 // and '' for an empty picker; both mean "not set", which is
210 // how a colour falls back to FluentCart's own default.
211 if ($hex) {
212 $colors[$key] = $hex;
213 }
214 }
215
216 return $colors;
217 },
218 'appearance_radius' => function ($value) {
219 // Registry-driven like the colours: only the known roles, each
220 // one length. A bare number means pixels; px, rem and em are
221 // kept as typed. An empty field means "not set", so the
222 // stylesheet's own fallback applies; 0 is a real value.
223 return RadiusPalette::sanitizeOwnerMap($value);
224 },
225 'theme_setup' => function ($value) {
226 if (!is_array($value)) {
227 return [];
228 }
229 $data = [];
230
231 foreach ($value as $key => $val) {
232 $data[sanitize_text_field($key)] = sanitize_hex_color($val);
233 }
234
235 return $data;
236 },
237
238 ];
239
240 return apply_filters('fluent_cart/store_settings/sanitizer', $sanitizer);
241 }
242 }
243