1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Modules\Html; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\FieldContract; |
6
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
7
|
|
|
use GeminiLabs\SiteReviews\Helpers\Cast; |
8
|
|
|
use GeminiLabs\SiteReviews\Modules\Encryption; |
9
|
|
|
|
10
|
|
|
class ReviewForm extends Form |
11
|
|
|
{ |
12
|
16 |
|
public function __construct(array $args = [], array $values = []) |
13
|
|
|
{ |
14
|
16 |
|
$overrides = [ |
15
|
16 |
|
'button_text' => __('Submit Review', 'site-reviews'), |
16
|
16 |
|
'class' => 'glsr-review-form', |
17
|
16 |
|
]; |
18
|
16 |
|
parent::__construct(wp_parse_args($overrides, $args), $values); |
19
|
16 |
|
} |
20
|
|
|
|
21
|
|
|
public function config(): array |
22
|
16 |
|
{ |
23
|
|
|
return glsr()->config('forms/review-form'); |
24
|
16 |
|
} |
25
|
16 |
|
|
26
|
16 |
|
public function configHidden(): array |
27
|
|
|
{ |
28
|
|
|
do_action('litespeed_nonce', 'submit-review'); // @litespeedcache |
29
|
16 |
|
$referer = glsr()->filterString('review-form/referer', wp_get_referer()); |
30
|
|
|
$config = [ |
31
|
16 |
|
'_action' => 'submit-review', |
32
|
16 |
|
'_nonce' => wp_create_nonce('submit-review'), |
33
|
16 |
|
'_post_id' => get_the_ID(), |
34
|
|
|
'_referer' => wp_unslash($referer), |
35
|
|
|
'assigned_posts' => $this->args->assigned_posts, |
36
|
16 |
|
'assigned_terms' => $this->args->assigned_terms, |
37
|
|
|
'assigned_users' => $this->args->assigned_users, |
38
|
16 |
|
'excluded' => $this->args->cast('hide', 'string'), |
39
|
16 |
|
'form_id' => $this->args->id, |
40
|
16 |
|
'terms_exist' => Cast::toInt(!in_array('terms', $this->args->cast('hide', 'array'))), |
41
|
16 |
|
]; |
42
|
16 |
|
return $config; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function fieldClass(): string |
46
|
|
|
{ |
47
|
|
|
return ReviewField::class; |
48
|
16 |
|
} |
49
|
|
|
|
50
|
16 |
|
public function loadSession(array $values): void |
51
|
16 |
|
{ |
52
|
16 |
|
$this->session = glsr()->args([ |
53
|
|
|
'errors' => glsr()->session()->array('form_errors'), |
54
|
|
|
'failed' => glsr()->session()->cast('form_invalid', 'bool'), |
55
|
|
|
'message' => glsr()->session()->cast('form_message', 'string'), |
56
|
|
|
'values' => $values ?: glsr()->session()->array('form_values'), |
57
|
|
|
]); |
58
|
16 |
|
} |
59
|
|
|
|
60
|
16 |
|
/** |
61
|
16 |
|
* An array of field names that can be overridden in the hiddenConfig array |
62
|
16 |
|
* by fields with the same name in the config array. |
63
|
16 |
|
* |
64
|
16 |
|
* @return string[] |
65
|
16 |
|
*/ |
66
|
16 |
|
protected function allowedHiddenFieldOverrides(): array |
67
|
16 |
|
{ |
68
|
16 |
|
return [ |
69
|
16 |
|
'assigned_posts', |
70
|
16 |
|
'assigned_terms', |
71
|
16 |
|
'assigned_users', |
72
|
16 |
|
'content', |
73
|
16 |
|
'email', |
74
|
16 |
|
'name', |
75
|
16 |
|
'rating', |
76
|
16 |
|
'terms', |
77
|
16 |
|
'title', |
78
|
16 |
|
]; |
79
|
16 |
|
} |
80
|
16 |
|
|
81
|
16 |
|
/** |
82
|
|
|
* @return FieldContract[] |
83
|
|
|
*/ |
84
|
16 |
|
protected function fieldsVisible(): array |
85
|
16 |
|
{ |
86
|
|
|
$fields = parent::fieldsVisible(); |
87
|
|
|
$fields = array_filter($fields, fn ($field) => !in_array($field->original_name, $this->args->cast('hide', 'array'))); |
88
|
|
|
return $fields; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|