|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Helpers\Cast; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Helpers\Str; |
|
8
|
|
|
use GeminiLabs\SiteReviews\Modules\Captcha; |
|
9
|
|
|
use GeminiLabs\SiteReviews\Modules\Encryption; |
|
10
|
|
|
|
|
11
|
8 |
|
class Request extends Arguments |
|
12
|
|
|
{ |
|
13
|
8 |
|
public function decrypt(string $key): string |
|
14
|
8 |
|
{ |
|
15
|
|
|
$value = glsr(Encryption::class)->decrypt($this->cast($key, 'string')); |
|
16
|
|
|
return Cast::toString($value); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param mixed $key |
|
21
|
|
|
* @param mixed $fallback |
|
22
|
|
|
* |
|
23
|
14 |
|
* @return mixed |
|
24
|
|
|
*/ |
|
25
|
14 |
|
public function get($key, $fallback = null) |
|
26
|
14 |
|
{ |
|
27
|
14 |
|
$value = Arr::get($this->getArrayCopy(), $key, null); |
|
28
|
|
|
if (is_null($fallback)) { |
|
29
|
|
|
return $value; |
|
30
|
|
|
} |
|
31
|
|
|
if (!Helper::isEmpty($value)) { |
|
32
|
|
|
return $value; |
|
33
|
|
|
} |
|
34
|
|
|
return Helper::runClosure($fallback); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
8 |
|
/** |
|
38
|
|
|
* @return static |
|
39
|
8 |
|
* |
|
40
|
8 |
|
* @todo support array values |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function inputGet(): Request |
|
43
|
|
|
{ |
|
44
|
8 |
|
$values = []; |
|
45
|
|
|
if ($token = filter_input(INPUT_GET, glsr()->prefix)) { |
|
46
|
|
|
$token = sanitize_text_field($token); |
|
47
|
|
|
$values = glsr(Encryption::class)->decryptRequest($token); |
|
48
|
|
|
} |
|
49
|
|
|
return new static($values); |
|
50
|
8 |
|
} |
|
51
|
|
|
|
|
52
|
8 |
|
/** |
|
53
|
8 |
|
* @return static |
|
54
|
8 |
|
*/ |
|
55
|
8 |
|
public static function inputPost(): Request |
|
56
|
|
|
{ |
|
57
|
8 |
|
$action = Helper::filterInput('action'); |
|
58
|
8 |
|
$values = Helper::filterInputArray(glsr()->id); |
|
59
|
8 |
|
if (in_array($action, [glsr()->prefix.'admin_action', glsr()->prefix.'public_action'])) { |
|
60
|
8 |
|
$values['_ajax_request'] = true; |
|
61
|
8 |
|
} |
|
62
|
|
|
$requestAction = Helper::filterInput('_action', $values); |
|
63
|
8 |
|
if (in_array($requestAction, glsr(Captcha::class)->actions())) { |
|
64
|
|
|
$values['_frcaptcha'] = Helper::filterInput('frc-captcha-solution'); |
|
65
|
|
|
$values['_hcaptcha'] = Helper::filterInput('h-captcha-response'); |
|
66
|
|
|
$values['_procaptcha'] = Helper::filterInput('procaptcha-response'); |
|
67
|
|
|
$values['_recaptcha'] = Helper::filterInput('g-recaptcha-response'); |
|
68
|
|
|
$values['_turnstile'] = Helper::filterInput('cf-turnstile-response'); |
|
69
|
|
|
} |
|
70
|
|
|
return new static($values); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param mixed $value |
|
75
|
|
|
*/ |
|
76
|
|
|
public function set(string $path, $value): void |
|
77
|
|
|
{ |
|
78
|
|
|
$storage = Arr::set($this->getArrayCopy(), $path, $value); |
|
79
|
|
|
$this->exchangeArray($storage); |
|
80
|
|
|
if (!$this->exists('form_signature') || 'form_signature' === $path) { |
|
81
|
|
|
return; |
|
82
|
|
|
} |
|
83
|
|
|
$values = $this->decrypt('form_signature'); |
|
84
|
|
|
$values = wp_parse_args(maybe_unserialize($values)); |
|
85
|
|
|
if (array_key_exists($path, $values)) { |
|
86
|
|
|
$values[$path] = $value; |
|
87
|
|
|
$storage['form_signature'] = glsr(Encryption::class)->encrypt(maybe_serialize($values)); |
|
88
|
|
|
$this->exchangeArray($storage); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|