PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / trunk
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler vtrunk
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 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Http / Requests / FluentMetaRequest.php

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

222 lines 10.6 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
10 class FluentMetaRequest extends RequestGuard
11 {
12
13 /**
14 * @return array
15 */
16 public function rules()
17 {
18
19
20 $rulesMap = [
21 'store_setup' => [
22 'store_name' => 'required|sanitizeText|maxLength:200',
23 'store_country' => 'required|sanitizeText|maxLength:200',
24 'seller_vat_id' => 'nullable|sanitizeText|maxLength:50',
25 'seller_tax_id' => 'nullable|sanitizeText|maxLength:50',
26 ]
27 ];
28
29 $rules = Arr::get($rulesMap, $this->get('settings_name'), []);
30 // $rules = [
31 // 'object_id' => 'integer|min:1',
32 // 'object_type' => 'nullable|sanitizeText|max:50',
33 // 'meta_key' => 'nullable|sanitizeText|max:50',
34 // 'meta_value' => 'nullable|sanitizeText',
35 // 'store_name' => 'required|sanitizeText|max:200',
36 // 'store_country' => 'required|sanitizeText|max:200',
37 // ];
38 return apply_filters('fluent_cart/store_settings/rules', $rules);
39 }
40
41
42 /**
43 * @return array
44 */
45 public function messages(): array
46 {
47 return [
48 'store_name.required' => esc_html__('Store name is required.', 'fluent-cart'),
49 'store_country.required' => esc_html__('Store country is required.', 'fluent-cart'),
50 ];
51 }
52
53
54 /**
55 * @return array
56 */
57 public function sanitize(): array
58 {
59 $sanitizer = [
60 'object_type' => 'sanitize_text_field',
61 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
62 'meta_key' => 'sanitize_text_field',
63 'type' => 'sanitize_text_field',
64 'default' => 'sanitize_text_field',
65 'store_name' => 'sanitize_text_field',
66 'company_name' => 'sanitize_text_field',
67 'legal_registration_id' => 'sanitize_text_field',
68 'seller_vat_id' => 'sanitize_text_field',
69 'seller_tax_id' => 'sanitize_text_field',
70 'store_logo' => function ($value) {
71 if (!is_array($value)) {
72 return '';
73 }
74 return [
75 'id' => sanitize_text_field(Arr::get($value, 'id')),
76 'url' => sanitize_url(Arr::get($value, 'url')),
77 'title' => sanitize_text_field(Arr::get($value, 'title')),
78 ];
79 },
80 'checkout_button_text' => 'sanitize_text_field',
81 'view_cart_button_text' => 'sanitize_text_field',
82 'note_for_user_account_creation' => 'sanitize_text_field',
83 'cart_button_text' => 'sanitize_text_field',
84 'popup_button_text' => 'sanitize_text_field',
85 'out_of_stock_button_text' => 'sanitize_text_field',
86 'thousand_separator' => 'sanitize_text_field',
87 'decimal_separator' => 'sanitize_text_field',
88 'currency_position' => 'sanitize_text_field',
89 'checkout_method_style' => 'sanitize_text_field',
90 'require_logged_in' => 'sanitize_text_field',
91 'enable_modal_checkout' => 'sanitize_text_field',
92 'show_cart_icon_in_nav' => 'sanitize_text_field',
93 'show_cart_icon_in_body' => 'sanitize_text_field',
94 'additional_address_field' => 'sanitize_text_field',
95 'hide_coupon_field' => 'sanitize_text_field',
96 'user_account_creation_mode' => 'sanitize_text_field',
97 'auto_login_after_account_creation' => function ($value) {
98 return $value === 'yes' ? 'yes' : 'no';
99 },
100 'force_ssl' => 'sanitize_text_field',
101 'checkout_page_id' => 'intval',
102 'custom_payment_page_id' => 'intval',
103 'cart_page_id' => 'intval',
104 'receipt_page_id' => 'intval',
105 'shop_page_id' => 'intval',
106 'customer_profile_page_id' => 'intval',
107 'customer_profile_page_slug' => 'sanitize_text_field',
108 'registration_page_id' => 'intval',
109 'login_page_id' => 'intval',
110 'plugin_activated_once' => 'sanitize_text_field',
111 'rest_route' => 'sanitize_text_field',
112 'currency' => 'sanitize_text_field',
113 'store_address1' => 'sanitize_text_field',
114 'store_address2' => 'sanitize_text_field',
115 'store_city' => 'sanitize_text_field',
116 'store_country' => 'sanitize_text_field',
117 'store_postcode' => 'sanitize_text_field',
118 'store_state' => 'sanitize_text_field',
119 'template_settings_checkout_page_mode' => 'sanitize_text_field',
120 'show_relevant_product_in_single_page' => 'sanitize_text_field',
121 'show_relevant_product_in_modal' => 'sanitize_text_field',
122 'enable_early_payment_for_installment' => 'sanitize_text_field',
123 'subscription_management_mode' => function ($value) {
124 $value = sanitize_text_field($value);
125 $allowed = ['gateway_managed', 'store_managed'];
126 return in_array($value, $allowed, true) ? $value : 'gateway_managed';
127 },
128 'subscription_system_charge' => function ($value) {
129 $value = sanitize_text_field($value);
130 return in_array($value, ['yes', 'no'], true) ? $value : 'no';
131 },
132 'subscription_manual_fallback' => function ($value) {
133 $value = sanitize_text_field($value);
134 return in_array($value, ['yes', 'no'], true) ? $value : 'no';
135 },
136 'order_mode' => 'sanitize_text_field',
137 'subscription_mode_guard' => function ($value) {
138 $value = sanitize_text_field($value);
139 return in_array($value, ['yes', 'no'], true) ? $value : 'yes';
140 },
141 'variation_view' => 'sanitize_text_field',
142 'variation_columns' => 'sanitize_text_field',
143 'modules_settings' => 'sanitize_text_field',
144 'product_slug' => 'sanitize_text_field',
145 'min_receipt_number' => 'sanitize_text_field',
146 'inv_prefix' => 'sanitize_text_field',
147 'date_time_format_source' => function ($value) {
148 $value = sanitize_text_field($value);
149 return in_array($value, ['fluent_cart', 'wordpress'], true) ? $value : 'fluent_cart';
150 },
151 'timezone_source' => function ($value) {
152 $value = sanitize_text_field($value);
153 return in_array($value, ['fluent_cart', 'wordpress'], true) ? $value : 'fluent_cart';
154 },
155 'weight_unit' => function ($value) {
156 if (!PermissionManager::hasPermission(['store/sensitive'])) {
157 $stored = get_option('fluent_cart_store_settings', []);
158 return $stored['weight_unit'] ?? 'kg';
159 }
160 $value = sanitize_text_field($value);
161 $allowed = ['kg', 'g', 'lbs', 'oz'];
162 return in_array($value, $allowed, true) ? $value : 'kg';
163 },
164 'dimension_unit' => function ($value) {
165 if (!PermissionManager::hasPermission(['store/sensitive'])) {
166 $stored = get_option('fluent_cart_store_settings', []);
167 return $stored['dimension_unit'] ?? 'cm';
168 }
169 $value = sanitize_text_field($value);
170 $allowed = ['cm', 'mm', 'in', 'm'];
171 return in_array($value, $allowed, true) ? $value : 'cm';
172 },
173 'enable_image_zoom_in_single_product' => 'sanitize_text_field',
174 'enable_image_zoom_in_modal' => 'sanitize_text_field',
175 'appearance_source' => function ($value) {
176 $value = sanitize_text_field($value);
177
178 return in_array($value, ColorPalette::sources(), true)
179 ? $value
180 : ColorPalette::SOURCE_DEFAULT;
181 },
182 'appearance_colors' => function ($value) {
183 if (!is_array($value)) {
184 return [];
185 }
186
187 // Driven off the registry rather than the submitted keys, so an
188 // unknown property can never reach the storefront stylesheet.
189 $colors = [];
190
191 foreach (ColorPalette::globals() as $key => $definition) {
192 $hex = sanitize_hex_color((string)Arr::get($value, $key, ''));
193
194 // sanitize_hex_color() returns null for anything malformed
195 // and '' for an empty picker; both mean "not set", which is
196 // how a colour falls back to FluentCart's own default.
197 if ($hex) {
198 $colors[$key] = $hex;
199 }
200 }
201
202 return $colors;
203 },
204 'theme_setup' => function ($value) {
205 if (!is_array($value)) {
206 return [];
207 }
208 $data = [];
209
210 foreach ($value as $key => $val) {
211 $data[sanitize_text_field($key)] = sanitize_hex_color($val);
212 }
213
214 return $data;
215 },
216
217 ];
218
219 return apply_filters('fluent_cart/store_settings/sanitizer', $sanitizer);
220 }
221 }
222