|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Helper; |
|
6
|
|
|
|
|
7
|
|
|
class CreateReview |
|
8
|
|
|
{ |
|
9
|
|
|
public $ajax_request; |
|
10
|
|
|
public $assigned_to; |
|
11
|
|
|
public $author; |
|
12
|
|
|
public $avatar; |
|
13
|
|
|
public $blacklisted; |
|
14
|
|
|
public $category; |
|
15
|
|
|
public $content; |
|
16
|
|
|
public $custom; |
|
17
|
|
|
public $email; |
|
18
|
|
|
public $form_id; |
|
19
|
|
|
public $ip_address; |
|
20
|
|
|
public $rating; |
|
21
|
|
|
public $referrer; |
|
22
|
|
|
public $terms; |
|
23
|
|
|
public $title; |
|
24
|
|
|
|
|
25
|
|
|
protected $request; |
|
26
|
|
|
|
|
27
|
1 |
|
public function __construct( $input ) |
|
28
|
|
|
{ |
|
29
|
1 |
|
$this->request = $input; |
|
30
|
1 |
|
$this->ajax_request = isset( $input['ajax_request'] ); |
|
31
|
1 |
|
$this->assigned_to = $this->getNumeric( 'assign_to' ); |
|
32
|
1 |
|
$this->author = sanitize_text_field( $this->get( 'name' )); |
|
33
|
1 |
|
$this->avatar = get_avatar_url( $this->get( 'email' )); |
|
34
|
1 |
|
$this->blacklisted = isset( $input['blacklisted'] ); |
|
35
|
1 |
|
$this->category = sanitize_key( $this->get( 'category' )); |
|
36
|
1 |
|
$this->content = sanitize_textarea_field( $this->get( 'content' )); |
|
37
|
1 |
|
$this->custom = $this->getCustom(); |
|
38
|
1 |
|
$this->email = sanitize_email( $this->get( 'email' )); |
|
39
|
1 |
|
$this->form_id = sanitize_key( $this->get( 'form_id' )); |
|
40
|
1 |
|
$this->ip_address = $this->get( 'ip_address' ); |
|
41
|
1 |
|
$this->rating = intval( $this->get( 'rating' )); |
|
42
|
1 |
|
$this->referrer = $this->get( 'referrer' ); |
|
43
|
1 |
|
$this->terms = isset( $input['terms'] ); |
|
44
|
1 |
|
$this->title = sanitize_text_field( $this->get( 'title' )); |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $key |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
1 |
|
protected function get( $key ) |
|
52
|
|
|
{ |
|
53
|
1 |
|
return isset( $this->request[$key] ) |
|
54
|
1 |
|
? (string)$this->request[$key] |
|
55
|
1 |
|
: ''; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return array |
|
60
|
|
|
*/ |
|
61
|
1 |
|
protected function getCustom() |
|
62
|
|
|
{ |
|
63
|
|
|
$unset = [ |
|
64
|
1 |
|
'action', 'ajax_request', 'assign_to', 'category', 'content', 'email', 'excluded', |
|
65
|
|
|
'form_id', 'gotcha', 'ip_address', 'name', 'nonce', 'rating', 'referrer', 'terms', |
|
66
|
|
|
'title', |
|
67
|
|
|
]; |
|
68
|
1 |
|
$custom = $this->request; |
|
69
|
1 |
|
foreach( $unset as $value ) { |
|
70
|
1 |
|
unset( $custom[$value] ); |
|
71
|
|
|
} |
|
72
|
1 |
|
return $custom; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param string $key |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
1 |
|
protected function getNumeric( $key ) |
|
80
|
|
|
{ |
|
81
|
1 |
|
return is_numeric( $this->request[$key] ) |
|
82
|
|
|
? (string)$this->request[$key] |
|
83
|
1 |
|
: ''; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|