1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Application; |
6
|
|
|
use GeminiLabs\SiteReviews\Defaults\CreateReviewDefaults; |
7
|
|
|
use WP_Post; |
8
|
|
|
|
9
|
|
|
class Review |
10
|
|
|
{ |
11
|
|
|
public $assigned_to; |
12
|
|
|
public $author; |
13
|
|
|
public $avatar; |
14
|
|
|
public $content; |
15
|
|
|
public $custom; |
16
|
|
|
public $date; |
17
|
|
|
public $email; |
18
|
|
|
public $ID; |
19
|
|
|
public $ip_address; |
20
|
|
|
public $modified; |
21
|
|
|
public $pinned; |
22
|
|
|
public $rating; |
23
|
|
|
public $response; |
24
|
|
|
public $review_id; |
25
|
|
|
public $review_type; |
26
|
|
|
public $status; |
27
|
|
|
public $term_ids; |
28
|
|
|
public $title; |
29
|
|
|
public $url; |
30
|
|
|
public $user_id; |
31
|
|
|
|
32
|
1 |
|
public function __construct( WP_Post $post ) |
33
|
|
|
{ |
34
|
1 |
|
$this->content = $post->post_content; |
35
|
1 |
|
$this->date = $post->post_date; |
36
|
1 |
|
$this->ID = intval( $post->ID ); |
37
|
1 |
|
$this->status = $post->post_status; |
38
|
1 |
|
$this->title = $post->post_title; |
39
|
1 |
|
$this->user_id = intval( $post->post_author ); |
40
|
1 |
|
$this->setProperties( $post ); |
41
|
1 |
|
$this->setTermIds( $post ); |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
1 |
|
protected function isModified( array $properties ) |
48
|
|
|
{ |
49
|
1 |
|
return $this->date != $properties['date'] |
50
|
1 |
|
|| $this->content != $properties['content'] |
51
|
1 |
|
|| $this->title != $properties['title']; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
1 |
|
protected function setProperties( WP_Post $post ) |
58
|
|
|
{ |
59
|
|
|
$defaults = [ |
60
|
1 |
|
'author' => __( 'Anonymous', 'site-reviews' ), |
61
|
1 |
|
'date' => '', |
62
|
1 |
|
'review_id' => '', |
63
|
1 |
|
'review_type' => '', |
64
|
|
|
]; |
65
|
1 |
|
$meta = array_filter( |
66
|
1 |
|
array_map( 'array_shift', (array)get_post_meta( $post->ID )), |
67
|
1 |
|
'strlen' |
68
|
|
|
); |
69
|
1 |
|
$properties = glsr( CreateReviewDefaults::class )->restrict( array_merge( $defaults, $meta )); |
70
|
1 |
|
$this->modified = $this->isModified( $properties ); |
71
|
1 |
|
array_walk( $properties, function( $value, $key ) { |
72
|
1 |
|
if( !property_exists( $this, $key ) || isset( $this->$key ))return; |
73
|
1 |
|
$this->$key = maybe_unserialize( $value ); |
74
|
1 |
|
}); |
75
|
1 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
1 |
|
protected function setTermIds( WP_Post $post ) |
81
|
|
|
{ |
82
|
1 |
|
$this->term_ids = []; |
83
|
1 |
|
if( !is_array( $terms = get_the_terms( $post, Application::TAXONOMY )))return; |
84
|
|
|
foreach( $terms as $term ) { |
85
|
|
|
$this->term_ids[] = $term->term_id; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|