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