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

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

229 lines 11.1 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 'require_customer_email_verification' => function ($value) {
98 return $value === 'no' ? 'no' : 'yes';
99 },
100 'auto_login_after_account_creation' => function ($value) {
101 return $value === 'yes' ? 'yes' : 'no';
102 },
103 'force_ssl' => 'sanitize_text_field',
104 'checkout_page_id' => 'intval',
105 'custom_payment_page_id' => 'intval',
106 'cart_page_id' => 'intval',
107 'receipt_page_id' => 'intval',
108 'order_review_page_id' => 'intval',
109 'shop_page_id' => 'intval',
110 'customer_profile_page_id' => 'intval',
111 'customer_profile_page_slug' => 'sanitize_text_field',
112 'registration_page_id' => 'intval',
113 'login_page_id' => 'intval',
114 'plugin_activated_once' => 'sanitize_text_field',
115 'rest_route' => 'sanitize_text_field',
116 'currency' => 'sanitize_text_field',
117 'store_address1' => 'sanitize_text_field',
118 'store_address2' => 'sanitize_text_field',
119 'store_city' => 'sanitize_text_field',
120 'store_country' => 'sanitize_text_field',
121 'store_postcode' => 'sanitize_text_field',
122 'store_state' => 'sanitize_text_field',
123 'template_settings_checkout_page_mode' => 'sanitize_text_field',
124 'show_relevant_product_in_single_page' => 'sanitize_text_field',
125 'show_relevant_product_in_modal' => 'sanitize_text_field',
126 'show_reviews_in_single_page' => 'sanitize_text_field',
127 'show_rating_in_shop' => 'sanitize_text_field',
128 'show_rating_in_relevant' => 'sanitize_text_field',
129 'enable_early_payment_for_installment' => 'sanitize_text_field',
130 'subscription_management_mode' => function ($value) {
131 $value = sanitize_text_field($value);
132 $allowed = ['gateway_managed', 'store_managed'];
133 return in_array($value, $allowed, true) ? $value : 'gateway_managed';
134 },
135 'subscription_system_charge' => function ($value) {
136 $value = sanitize_text_field($value);
137 return in_array($value, ['yes', 'no'], true) ? $value : 'no';
138 },
139 'subscription_manual_fallback' => function ($value) {
140 $value = sanitize_text_field($value);
141 return in_array($value, ['yes', 'no'], true) ? $value : 'no';
142 },
143 'order_mode' => 'sanitize_text_field',
144 'subscription_mode_guard' => function ($value) {
145 $value = sanitize_text_field($value);
146 return in_array($value, ['yes', 'no'], true) ? $value : 'yes';
147 },
148 'variation_view' => 'sanitize_text_field',
149 'variation_columns' => 'sanitize_text_field',
150 'modules_settings' => 'sanitize_text_field',
151 'product_slug' => 'sanitize_text_field',
152 'min_receipt_number' => 'sanitize_text_field',
153 'inv_prefix' => 'sanitize_text_field',
154 'date_time_format_source' => function ($value) {
155 $value = sanitize_text_field($value);
156 return in_array($value, ['fluent_cart', 'wordpress'], true) ? $value : 'fluent_cart';
157 },
158 'timezone_source' => function ($value) {
159 $value = sanitize_text_field($value);
160 return in_array($value, ['fluent_cart', 'wordpress'], true) ? $value : 'fluent_cart';
161 },
162 'weight_unit' => function ($value) {
163 if (!PermissionManager::hasPermission(['store/sensitive'])) {
164 $stored = get_option('fluent_cart_store_settings', []);
165 return $stored['weight_unit'] ?? 'kg';
166 }
167 $value = sanitize_text_field($value);
168 $allowed = ['kg', 'g', 'lbs', 'oz'];
169 return in_array($value, $allowed, true) ? $value : 'kg';
170 },
171 'dimension_unit' => function ($value) {
172 if (!PermissionManager::hasPermission(['store/sensitive'])) {
173 $stored = get_option('fluent_cart_store_settings', []);
174 return $stored['dimension_unit'] ?? 'cm';
175 }
176 $value = sanitize_text_field($value);
177 $allowed = ['cm', 'mm', 'in', 'm'];
178 return in_array($value, $allowed, true) ? $value : 'cm';
179 },
180 'enable_image_zoom_in_single_product' => 'sanitize_text_field',
181 'enable_image_zoom_in_modal' => 'sanitize_text_field',
182 'appearance_source' => function ($value) {
183 $value = sanitize_text_field($value);
184
185 return in_array($value, ColorPalette::sources(), true)
186 ? $value
187 : ColorPalette::SOURCE_DEFAULT;
188 },
189 'appearance_colors' => function ($value) {
190 if (!is_array($value)) {
191 return [];
192 }
193
194 // Driven off the registry rather than the submitted keys, so an
195 // unknown property can never reach the storefront stylesheet.
196 $colors = [];
197
198 foreach (ColorPalette::globals() as $key => $definition) {
199 $hex = sanitize_hex_color((string)Arr::get($value, $key, ''));
200
201 // sanitize_hex_color() returns null for anything malformed
202 // and '' for an empty picker; both mean "not set", which is
203 // how a colour falls back to FluentCart's own default.
204 if ($hex) {
205 $colors[$key] = $hex;
206 }
207 }
208
209 return $colors;
210 },
211 'theme_setup' => function ($value) {
212 if (!is_array($value)) {
213 return [];
214 }
215 $data = [];
216
217 foreach ($value as $key => $val) {
218 $data[sanitize_text_field($key)] = sanitize_hex_color($val);
219 }
220
221 return $data;
222 },
223
224 ];
225
226 return apply_filters('fluent_cart/store_settings/sanitizer', $sanitizer);
227 }
228 }
229