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

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

177 lines 8.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
9 class FluentMetaRequest extends RequestGuard
10 {
11
12 /**
13 * @return array
14 */
15 public function rules()
16 {
17
18
19 $rulesMap = [
20 'store_setup' => [
21 'store_name' => 'required|sanitizeText|maxLength:200',
22 'store_country' => 'required|sanitizeText|maxLength:200',
23 'seller_vat_id' => 'nullable|sanitizeText|maxLength:50',
24 'seller_tax_id' => 'nullable|sanitizeText|maxLength:50',
25 ]
26 ];
27
28 $rules = Arr::get($rulesMap, $this->get('settings_name'), []);
29 // $rules = [
30 // 'object_id' => 'integer|min:1',
31 // 'object_type' => 'nullable|sanitizeText|max:50',
32 // 'meta_key' => 'nullable|sanitizeText|max:50',
33 // 'meta_value' => 'nullable|sanitizeText',
34 // 'store_name' => 'required|sanitizeText|max:200',
35 // 'store_country' => 'required|sanitizeText|max:200',
36 // ];
37 return apply_filters('fluent_cart/store_settings/rules', $rules);
38 }
39
40
41 /**
42 * @return array
43 */
44 public function messages(): array
45 {
46 return [
47 'store_name.required' => esc_html__('Store name is required.', 'fluent-cart'),
48 'store_country.required' => esc_html__('Store country is required.', 'fluent-cart'),
49 ];
50 }
51
52
53 /**
54 * @return array
55 */
56 public function sanitize(): array
57 {
58 $sanitizer = [
59 'object_type' => 'sanitize_text_field',
60 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
61 'meta_key' => 'sanitize_text_field',
62 'type' => 'sanitize_text_field',
63 'default' => 'sanitize_text_field',
64 'store_name' => 'sanitize_text_field',
65 'company_name' => 'sanitize_text_field',
66 'legal_registration_id' => 'sanitize_text_field',
67 'seller_vat_id' => 'sanitize_text_field',
68 'seller_tax_id' => 'sanitize_text_field',
69 'store_logo' => function ($value) {
70 if (!is_array($value)) {
71 return '';
72 }
73 return [
74 'id' => sanitize_text_field(Arr::get($value, 'id')),
75 'url' => sanitize_url(Arr::get($value, 'url')),
76 'title' => sanitize_text_field(Arr::get($value, 'title')),
77 ];
78 },
79 'checkout_button_text' => 'sanitize_text_field',
80 'view_cart_button_text' => 'sanitize_text_field',
81 'note_for_user_account_creation' => 'sanitize_text_field',
82 'cart_button_text' => 'sanitize_text_field',
83 'popup_button_text' => 'sanitize_text_field',
84 'out_of_stock_button_text' => 'sanitize_text_field',
85 'thousand_separator' => 'sanitize_text_field',
86 'decimal_separator' => 'sanitize_text_field',
87 'currency_position' => 'sanitize_text_field',
88 'checkout_method_style' => 'sanitize_text_field',
89 'require_logged_in' => 'sanitize_text_field',
90 'enable_modal_checkout' => 'sanitize_text_field',
91 'show_cart_icon_in_nav' => 'sanitize_text_field',
92 'show_cart_icon_in_body' => 'sanitize_text_field',
93 'additional_address_field' => 'sanitize_text_field',
94 'hide_coupon_field' => 'sanitize_text_field',
95 'user_account_creation_mode' => 'sanitize_text_field',
96 'force_ssl' => 'sanitize_text_field',
97 'checkout_page_id' => 'intval',
98 'custom_payment_page_id' => 'intval',
99 'cart_page_id' => 'intval',
100 'receipt_page_id' => 'intval',
101 'shop_page_id' => 'intval',
102 'customer_profile_page_id' => 'intval',
103 'customer_profile_page_slug' => 'sanitize_text_field',
104 'registration_page_id' => 'intval',
105 'login_page_id' => 'intval',
106 'plugin_activated_once' => 'sanitize_text_field',
107 'rest_route' => 'sanitize_text_field',
108 'currency' => 'sanitize_text_field',
109 'store_address1' => 'sanitize_text_field',
110 'store_address2' => 'sanitize_text_field',
111 'store_city' => 'sanitize_text_field',
112 'store_country' => 'sanitize_text_field',
113 'store_postcode' => 'sanitize_text_field',
114 'store_state' => 'sanitize_text_field',
115 'template_settings_checkout_page_mode' => 'sanitize_text_field',
116 'show_relevant_product_in_single_page' => 'sanitize_text_field',
117 'show_relevant_product_in_modal' => 'sanitize_text_field',
118 'enable_early_payment_for_installment' => 'sanitize_text_field',
119 'subscription_management_mode' => function ($value) {
120 $value = sanitize_text_field($value);
121 $allowed = ['gateway_managed', 'store_managed'];
122 return in_array($value, $allowed, true) ? $value : 'gateway_managed';
123 },
124 'subscription_system_charge' => function ($value) {
125 $value = sanitize_text_field($value);
126 return in_array($value, ['yes', 'no'], true) ? $value : 'no';
127 },
128 'subscription_manual_fallback' => function ($value) {
129 $value = sanitize_text_field($value);
130 return in_array($value, ['yes', 'no'], true) ? $value : 'no';
131 },
132 'order_mode' => 'sanitize_text_field',
133 'variation_view' => 'sanitize_text_field',
134 'variation_columns' => 'sanitize_text_field',
135 'modules_settings' => 'sanitize_text_field',
136 'product_slug' => 'sanitize_text_field',
137 'min_receipt_number' => 'sanitize_text_field',
138 'inv_prefix' => 'sanitize_text_field',
139 'weight_unit' => function ($value) {
140 if (!PermissionManager::hasPermission(['store/sensitive'])) {
141 $stored = get_option('fluent_cart_store_settings', []);
142 return $stored['weight_unit'] ?? 'kg';
143 }
144 $value = sanitize_text_field($value);
145 $allowed = ['kg', 'g', 'lbs', 'oz'];
146 return in_array($value, $allowed, true) ? $value : 'kg';
147 },
148 'dimension_unit' => function ($value) {
149 if (!PermissionManager::hasPermission(['store/sensitive'])) {
150 $stored = get_option('fluent_cart_store_settings', []);
151 return $stored['dimension_unit'] ?? 'cm';
152 }
153 $value = sanitize_text_field($value);
154 $allowed = ['cm', 'mm', 'in', 'm'];
155 return in_array($value, $allowed, true) ? $value : 'cm';
156 },
157 'enable_image_zoom_in_single_product' => 'sanitize_text_field',
158 'enable_image_zoom_in_modal' => 'sanitize_text_field',
159 'theme_setup' => function ($value) {
160 if (!is_array($value)) {
161 return [];
162 }
163 $data = [];
164
165 foreach ($value as $key => $val) {
166 $data[sanitize_text_field($key)] = sanitize_hex_color($val);
167 }
168
169 return $data;
170 },
171
172 ];
173
174 return apply_filters('fluent_cart/store_settings/sanitizer', $sanitizer);
175 }
176 }
177