PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.2
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.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.5.2, at app/Http/Requests/FluentMetaRequest.php

164 lines 7.8 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 'order_mode' => 'sanitize_text_field',
120 'variation_view' => 'sanitize_text_field',
121 'variation_columns' => 'sanitize_text_field',
122 'modules_settings' => 'sanitize_text_field',
123 'product_slug' => 'sanitize_text_field',
124 'min_receipt_number' => 'sanitize_text_field',
125 'inv_prefix' => 'sanitize_text_field',
126 'weight_unit' => function ($value) {
127 if (!PermissionManager::hasPermission(['store/sensitive'])) {
128 $stored = get_option('fluent_cart_store_settings', []);
129 return $stored['weight_unit'] ?? 'kg';
130 }
131 $value = sanitize_text_field($value);
132 $allowed = ['kg', 'g', 'lbs', 'oz'];
133 return in_array($value, $allowed, true) ? $value : 'kg';
134 },
135 'dimension_unit' => function ($value) {
136 if (!PermissionManager::hasPermission(['store/sensitive'])) {
137 $stored = get_option('fluent_cart_store_settings', []);
138 return $stored['dimension_unit'] ?? 'cm';
139 }
140 $value = sanitize_text_field($value);
141 $allowed = ['cm', 'mm', 'in', 'm'];
142 return in_array($value, $allowed, true) ? $value : 'cm';
143 },
144 'enable_image_zoom_in_single_product' => 'sanitize_text_field',
145 'enable_image_zoom_in_modal' => 'sanitize_text_field',
146 'theme_setup' => function ($value) {
147 if (!is_array($value)) {
148 return [];
149 }
150 $data = [];
151
152 foreach ($value as $key => $val) {
153 $data[sanitize_text_field($key)] = sanitize_hex_color($val);
154 }
155
156 return $data;
157 },
158
159 ];
160
161 return apply_filters('fluent_cart/store_settings/sanitizer', $sanitizer);
162 }
163 }
164