1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* The Review Schema |
4
|
|
|
* |
5
|
|
|
* @package to-reviews |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Returns schema Review data. |
10
|
|
|
* |
11
|
|
|
* @since 10.2 |
12
|
|
|
*/ |
13
|
|
|
class LSX_TO_Schema_Review extends LSX_TO_Schema_Graph_Piece { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Constructor. |
17
|
|
|
* |
18
|
|
|
* @param \WPSEO_Schema_Context $context A value object with context variables. |
19
|
|
|
*/ |
20
|
|
|
public function __construct( WPSEO_Schema_Context $context ) { |
|
|
|
|
21
|
|
|
$this->post_type = 'review'; |
22
|
|
|
parent::__construct( $context ); |
23
|
|
|
} |
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Returns Review data. |
27
|
|
|
* |
28
|
|
|
* @return array $data Review data. |
29
|
|
|
*/ |
30
|
|
|
public function generate() { |
31
|
|
|
$post = get_post( $this->context->id ); |
32
|
|
|
$review_author = get_post_meta( $post->ID, 'reviewer_name', true ); |
33
|
|
|
$review_email = get_post_meta( $post->ID, 'reviewer_email', true ); |
34
|
|
|
$rating_value = get_post_meta( $post->ID, 'rating', true ); |
35
|
|
|
$description = wp_strip_all_tags( get_the_content() ); |
36
|
|
|
$tour_list = get_post_meta( get_the_ID(), 'tour_to_review', false ); |
|
|
|
|
37
|
|
|
$accom_list = get_post_meta( get_the_ID(), 'accommodation_to_review', false ); |
38
|
|
|
$comment_count = get_comment_count( $this->context->id ); |
39
|
|
|
$review_author = get_post_meta( $post->ID, 'reviewer_name', true ); |
40
|
|
|
$date_of_visit_start = get_post_meta( $post->ID, 'date_of_visit_start', true ); |
41
|
|
|
$date_of_visit_end = get_post_meta( $post->ID, 'date_of_visit_end', true ); |
42
|
|
|
|
43
|
|
|
$data = array( |
|
|
|
|
44
|
|
|
'@type' => 'Review', |
45
|
|
|
'@id' => $this->context->canonical . '#review', |
46
|
|
|
'author' => array( |
47
|
|
|
'@type' => 'Person', |
48
|
|
|
'@id' => \lsx\legacy\Schema_Utils::get_author_schema_id( $review_author, $review_email, $this->context ), |
|
|
|
|
49
|
|
|
'name' => $review_author, |
50
|
|
|
'email' => $review_email, |
51
|
|
|
), |
52
|
|
|
'headline' => get_the_title(), |
53
|
|
|
'datePublished' => mysql2date( DATE_W3C, $post->post_date_gmt, false ), |
54
|
|
|
'dateModified' => mysql2date( DATE_W3C, $post->post_modified_gmt, false ), |
55
|
|
|
'commentCount' => $comment_count['approved'], |
56
|
|
|
'mainEntityOfPage' => array( |
57
|
|
|
'@id' => $this->context->canonical . WPSEO_Schema_IDs::WEBPAGE_HASH, |
|
|
|
|
58
|
|
|
), |
59
|
|
|
'reviewRating' => array( |
|
|
|
|
60
|
|
|
'@type' => 'Rating', |
61
|
|
|
'ratingValue' => $rating_value, |
62
|
|
|
'bestRating' => $rating_value, |
63
|
|
|
), |
64
|
|
|
'reviewBody' => $description, |
65
|
|
|
'itemReviewed' => \lsx\legacy\Schema_Utils::get_item_reviewed( $tour_list, 'Product' ), |
|
|
|
|
66
|
|
|
'itemReviewed' => \lsx\legacy\Schema_Utils::get_item_reviewed( $accom_list, 'Product' ), |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
if ( $this->context->site_represents_reference ) { |
|
|
|
|
70
|
|
|
$data['publisher'] = $this->context->site_represents_reference; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if ( '' !== $date_of_visit_start && '' !== $date_of_visit_end ) { |
|
|
|
|
74
|
|
|
$data['temporalCoverage'] = $date_of_visit_start . ' - ' . $date_of_visit_end; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$data = \lsx\legacy\Schema_Utils::add_image( $data, $this->context ); |
78
|
|
|
$data = $this->add_taxonomy_terms( $data, 'keywords', 'post_tag' ); |
|
|
|
|
79
|
|
|
$data = $this->add_taxonomy_terms( $data, 'reviewSection', 'category' ); |
80
|
|
|
$data = $this->add_offers( $data ); |
81
|
|
|
$data = $this->add_destinations( $data ); |
82
|
|
|
return $data; |
83
|
|
|
} |
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
|
|
|
|
86
|
|
|
* Adds the Destinations attached to the review |
87
|
|
|
* |
88
|
|
|
* @param array $data Country / State data. |
89
|
|
|
* |
90
|
|
|
* @return array $data Country / State data. |
91
|
|
|
*/ |
92
|
|
|
public function add_destinations( $data, $data_key = '' ) { |
93
|
|
|
$places_array = array(); |
94
|
|
|
$destinations = get_post_meta( $this->context->id, 'destination_to_' . $this->post_type, false ); |
95
|
|
|
if ( ! empty( $destinations ) ) { |
|
|
|
|
96
|
|
|
foreach ( $destinations as $destination_id ) { |
|
|
|
|
97
|
|
|
if ( '' !== $destination_id ) { |
|
|
|
|
98
|
|
|
if ( 0 === wp_get_post_parent_id( $destination_id ) || false === wp_get_post_parent_id( $destination_id ) ) { |
|
|
|
|
99
|
|
|
$places_array = \lsx\legacy\Schema_Utils::add_place( $places_array, 'Country', $destination_id, $this->context ); |
100
|
|
|
} else { |
101
|
|
|
$places_array = \lsx\legacy\Schema_Utils::add_place( $places_array, 'State', $destination_id, $this->context ); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
|
|
|
|
106
|
|
|
if ( ! empty( $places_array ) ) { |
|
|
|
|
107
|
|
|
$data['spatialCoverage'] = $places_array; |
108
|
|
|
} |
|
|
|
|
109
|
|
|
return $data; |
110
|
|
|
} |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|