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 $post_id; |
21
|
|
|
public $rating; |
22
|
|
|
public $referer; |
23
|
|
|
public $terms; |
24
|
|
|
public $title; |
25
|
|
|
|
26
|
|
|
protected $request; |
27
|
|
|
|
28
|
|
|
public function __construct( $input ) |
29
|
|
|
{ |
30
|
|
|
$this->request = $input; |
31
|
|
|
$this->ajax_request = isset( $input['ajax_request'] ); |
32
|
|
|
$this->assigned_to = $this->getNumeric( 'assign_to' ); |
33
|
|
|
$this->author = sanitize_text_field( $this->get( 'name' )); |
34
|
|
|
$this->avatar = get_avatar_url( $this->get( 'email' )); |
35
|
|
|
$this->blacklisted = isset( $input['blacklisted'] ); |
36
|
|
|
$this->category = sanitize_key( $this->get( 'category' )); |
37
|
|
|
$this->content = sanitize_textarea_field( $this->get( 'content' )); |
38
|
|
|
$this->custom = $this->getCustom(); |
39
|
|
|
$this->email = sanitize_email( $this->get( 'email' )); |
40
|
|
|
$this->form_id = sanitize_key( $this->get( 'form_id' )); |
41
|
|
|
$this->ip_address = $this->get( 'ip_address' ); |
42
|
|
|
$this->post_id = intval( $this->get( 'post_id' )); |
43
|
|
|
$this->rating = intval( $this->get( 'rating' )); |
44
|
|
|
$this->referer = $this->get( 'referer' ); |
45
|
|
|
$this->terms = isset( $input['terms'] ); |
46
|
|
|
$this->title = sanitize_text_field( $this->get( 'title' )); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $key |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
protected function get( $key ) |
54
|
|
|
{ |
55
|
|
|
return isset( $this->request[$key] ) |
56
|
|
|
? (string)$this->request[$key] |
57
|
|
|
: ''; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
protected function getCustom() |
64
|
|
|
{ |
65
|
|
|
$unset = [ |
66
|
|
|
'action', 'ajax_request', 'assign_to', 'category', 'content', 'email', 'excluded', |
67
|
|
|
'form_id', 'gotcha', 'ip_address', 'name', 'nonce', 'post_id', 'rating', |
68
|
|
|
'recaptcha-token', 'referer', 'terms', 'title', |
69
|
|
|
]; |
70
|
|
|
$custom = $this->request; |
71
|
|
|
foreach( $unset as $value ) { |
72
|
|
|
unset( $custom[$value] ); |
73
|
|
|
} |
74
|
|
|
return $custom; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $key |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
protected function getNumeric( $key ) |
82
|
|
|
{ |
83
|
|
|
return is_numeric( $this->request[$key] ) |
84
|
|
|
? (string)$this->request[$key] |
85
|
|
|
: ''; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|