PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.1
1.7.1 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 All 51 releases
fluent-cart / app / Http / Requests / FrontendRequests / ReviewRequest.php

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

121 lines 5.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\FrontendRequests;
4
5 use FluentCart\Framework\Foundation\RequestGuard;
6
7 /**
8 * RequestGuard forwards unknown calls to the wrapped request via __call(), and its
9 * $request property is protected with no accessor. Declaring the forwarded methods
10 * we actually use keeps static analysis honest about calls that resolve at runtime.
11 *
12 * @method string|null get_header(string $key)
13 */
14 class ReviewRequest extends RequestGuard
15 {
16 public function rules(): array
17 {
18 return [
19 'rating' => 'nullable|numeric|min:1|max:5',
20 // Star chips, comma separated ("5,4"). Five stars and four commas at most.
21 'ratings' => 'nullable|sanitizeText|maxLength:9',
22 'title' => 'nullable|sanitizeText|maxLength:192',
23 'content' => 'nullable|maxLength:5000',
24 'reviewer_name' => 'nullable|sanitizeText|maxLength:100',
25 'reviewer_email' => 'nullable|sanitizeText|email|maxLength:192',
26 // The order-review page's proof of purchase: an order uuid. Bounded
27 // here so a junk value is rejected before it reaches a query.
28 'order_hash' => 'nullable|sanitizeText|maxLength:64',
29 // The variation the review is about. Only honoured alongside an
30 // order grant that covers that item; the controller forces 0
31 // otherwise.
32 'item_id' => 'nullable|numeric',
33 'per_page' => 'nullable|numeric|min:1|max:50',
34 'sort_by' => 'nullable|sanitizeText|maxLength:50',
35 'sort_order' => 'nullable|sanitizeText|maxLength:10',
36 'has_media' => 'nullable|numeric',
37 'verified_only' => 'nullable|numeric',
38 // Display flags are sent again when Reviews.js refreshes a page,
39 // so the endpoint renders the same preset after sorting or
40 // pagination. Keep them constrained to the wire's 0/1 shape.
41 'show_avatar' => 'nullable|numeric|min:0|max:1',
42 'show_title' => 'nullable|numeric|min:0|max:1',
43 'show_content' => 'nullable|numeric|min:0|max:1',
44 'show_photos' => 'nullable|numeric|min:0|max:1',
45 'show_footer' => 'nullable|numeric|min:0|max:1',
46 'show_variation' => 'nullable|numeric|min:0|max:1',
47 'page' => 'nullable|numeric|min:1',
48 'client_id' => 'nullable|sanitizeText|maxLength:64',
49 'rating_token' => 'nullable|sanitizeText|maxLength:64',
50 'max_words' => 'nullable|numeric|min:0|max:500',
51 'pagination_type'=> 'nullable|sanitizeText|maxLength:20',
52 'media_visible' => 'nullable|numeric|min:0|max:100',
53 'media_width' => 'nullable|numeric|min:0|max:2000',
54 'media_height' => 'nullable|numeric|min:0|max:2000',
55 'media_full_width'=> 'nullable|numeric|min:0|max:1',
56 'media_flush' => 'nullable|numeric|min:0|max:1',
57 'media_backdrop' => 'nullable|numeric|min:0|max:1',
58 'photos_first' => 'nullable|numeric|min:0|max:1',
59 'rating_first' => 'nullable|numeric|min:0|max:1',
60 'badge_last' => 'nullable|numeric|min:0|max:1',
61 'show_meta' => 'nullable|numeric|min:0|max:1',
62 'item_class' => 'nullable|string',
63 'media_more' => 'nullable|sanitizeText|maxLength:20',
64 ];
65 }
66
67 public function messages(): array
68 {
69 return [
70 'rating.numeric' => esc_html__('Rating must be a number.', 'fluent-cart'),
71 'rating.min' => esc_html__('Rating must be at least 1.', 'fluent-cart'),
72 'rating.max' => esc_html__('Rating must not exceed 5.', 'fluent-cart'),
73 'title.maxLength' => esc_html__('Review title must not exceed 192 characters.', 'fluent-cart'),
74 'content.required' => esc_html__('Review content is required.', 'fluent-cart'),
75 'content.maxLength' => esc_html__('Review content must not exceed 5000 characters.', 'fluent-cart'),
76 ];
77 }
78
79 public function sanitize(): array
80 {
81 return [
82 'rating' => 'intval',
83 'ratings' => 'sanitize_text_field',
84 'title' => 'sanitize_text_field',
85 'content' => 'sanitize_textarea_field',
86 'reviewer_name' => 'sanitize_text_field',
87 'reviewer_email' => 'sanitize_email',
88 'order_hash' => 'sanitize_text_field',
89 'item_id' => 'intval',
90 'per_page' => 'intval',
91 'sort_by' => 'sanitize_text_field',
92 'sort_order' => 'sanitize_text_field',
93 'has_media' => 'intval',
94 'verified_only' => 'intval',
95 'show_avatar' => 'intval',
96 'show_title' => 'intval',
97 'show_content' => 'intval',
98 'show_photos' => 'intval',
99 'show_footer' => 'intval',
100 'show_variation' => 'intval',
101 'page' => 'intval',
102 'client_id' => 'sanitize_text_field',
103 'rating_token' => 'sanitize_text_field',
104 'max_words' => 'intval',
105 'pagination_type'=> 'sanitize_text_field',
106 'media_visible' => 'intval',
107 'media_width' => 'intval',
108 'media_height' => 'intval',
109 'media_full_width'=> 'intval',
110 'media_flush' => 'intval',
111 'media_backdrop' => 'intval',
112 'photos_first' => 'intval',
113 'rating_first' => 'intval',
114 'badge_last' => 'intval',
115 'show_meta' => 'intval',
116 'item_class' => 'sanitize_html_class',
117 'media_more' => 'sanitize_text_field',
118 ];
119 }
120 }
121