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

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