PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / trunk
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler vtrunk
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 / ReviewRequest.php

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

88 lines 4.3 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
7 class ReviewRequest extends RequestGuard
8 {
9 public function rules(): array
10 {
11 return [
12 'rating' => 'nullable|numeric|min:0|max:5',
13 'title' => 'nullable|sanitizeText|maxLength:192',
14 'content' => 'nullable|maxLength:5000',
15 'status' => 'nullable|sanitizeText|maxLength:50',
16 'post_id' => 'nullable|numeric',
17 'search' => 'nullable|sanitizeText|maxLength:200',
18 // Admin-authored reviews (create): the reviewer is typed in by the
19 // moderator, so name/email arrive as input rather than being
20 // derived from the session the way the storefront derives them.
21 'reviewer_name' => 'nullable|sanitizeText|maxLength:100',
22 'reviewer_email' => 'nullable|sanitizeText|email|maxLength:192',
23 'is_verified' => 'nullable|numeric|min:0|max:1',
24 'sort_by' => 'nullable|sanitizeText|maxLength:50',
25 'sort_order' => 'nullable|sanitizeText|maxLength:10',
26 'sort_type' => 'nullable|sanitizeText|maxLength:10',
27 'active_view' => 'nullable|sanitizeText|maxLength:50',
28 'filter_type' => 'nullable|sanitizeText|maxLength:20',
29 'advanced_filters' => 'nullable|maxLength:5000',
30 'user_tz' => 'nullable|sanitizeText|maxLength:100',
31 // The page-size control offers up to 150, and it is shared by
32 // every admin table, so a lower ceiling here made the reviews
33 // table the only one that rejected its own dropdown.
34 'per_page' => 'nullable|numeric|min:1|max:150',
35 'page' => 'nullable|numeric|min:1',
36 'action_type' => 'nullable|sanitizeText|maxLength:50',
37 'review_ids' => 'nullable|array',
38 'review_ids.*'=> 'numeric',
39 ];
40 }
41
42 public function messages(): array
43 {
44 return [
45 'rating.numeric' => esc_html__('Rating must be a number.', 'fluent-cart'),
46 'rating.min' => esc_html__('Rating must be at least 0.', 'fluent-cart'),
47 'rating.max' => esc_html__('Rating must not exceed 5.', 'fluent-cart'),
48 'title.maxLength' => esc_html__('Review title must not exceed 192 characters.', 'fluent-cart'),
49 'content.maxLength'=> esc_html__('Review content must not exceed 5000 characters.', 'fluent-cart'),
50 'reviewer_name.maxLength' => esc_html__('Reviewer name must not exceed 100 characters.', 'fluent-cart'),
51 'reviewer_email.email' => esc_html__('Please enter a valid email address.', 'fluent-cart'),
52 'reviewer_email.maxLength' => esc_html__('Email address must not exceed 192 characters.', 'fluent-cart'),
53 'per_page.max' => esc_html__('Reviews per page must not exceed 150.', 'fluent-cart'),
54 ];
55 }
56
57 public function sanitize(): array
58 {
59 return [
60 'rating' => 'intval',
61 'title' => 'sanitize_text_field',
62 'content' => 'sanitize_textarea_field',
63 'status' => 'sanitize_text_field',
64 'reviewer_name' => 'sanitize_text_field',
65 'reviewer_email' => 'sanitize_email',
66 'post_id' => 'intval',
67 'search' => 'sanitize_text_field',
68 'sort_by' => 'sanitize_text_field',
69 'sort_order' => 'sanitize_text_field',
70 'sort_type' => 'sanitize_text_field',
71 'active_view' => 'sanitize_text_field',
72 'filter_type' => 'sanitize_text_field',
73 'advanced_filters' => static function ($value) {
74 if (is_array($value)) {
75 return map_deep($value, 'sanitize_text_field');
76 }
77 return is_string($value) ? sanitize_text_field($value) : $value;
78 },
79 'user_tz' => 'sanitize_text_field',
80 'per_page' => 'intval',
81 'page' => 'intval',
82 'action_type' => 'sanitize_text_field',
83 'review_ids.*' => 'intval',
84 'is_verified' => 'intval',
85 ];
86 }
87 }
88