1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Shortcodes; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Database\ReviewManager; |
6
|
|
|
use GeminiLabs\SiteReviews\Defaults\SiteReviewsDefaults; |
7
|
|
|
use GeminiLabs\SiteReviews\Helpers\Cast; |
8
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\ReviewsHtml; |
9
|
|
|
use GeminiLabs\SiteReviews\Modules\Schema; |
10
|
|
|
use GeminiLabs\SiteReviews\Reviews; |
11
|
|
|
|
12
|
|
|
class SiteReviewsShortcode extends Shortcode |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
public $args; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @return ReviewsHtml |
21
|
|
|
*/ |
22
|
|
|
public function buildReviewsHtml(array $args = []) |
23
|
|
|
{ |
24
|
|
|
$this->args = glsr(SiteReviewsDefaults::class)->unguardedMerge($args); |
25
|
|
|
$reviews = glsr(ReviewManager::class)->reviews($args); |
26
|
|
|
$this->debug((array) $reviews); |
27
|
|
|
$this->generateSchema($reviews); |
28
|
|
|
if ('modal' === glsr_get_option('reviews.excerpts_action')) { |
29
|
|
|
glsr()->store('use_modal', true); |
30
|
|
|
} |
31
|
|
|
return new ReviewsHtml($reviews); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public function buildTemplate(array $args = []) |
38
|
|
|
{ |
39
|
|
|
return (string) $this->buildReviewsHtml($args); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function generateSchema(Reviews $reviews) |
46
|
|
|
{ |
47
|
|
|
if (Cast::toBool($this->args['schema'])) { |
48
|
|
|
glsr(Schema::class)->store( |
49
|
|
|
glsr(Schema::class)->build($this->args, $reviews) |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
protected function debug(array $data = []) |
58
|
|
|
{ |
59
|
|
|
if (!empty($this->args['debug'])) { |
60
|
|
|
$reviews = []; |
61
|
|
|
foreach ($data['reviews'] as $review) { |
62
|
|
|
$reviews[$review->ID] = get_class($review); |
63
|
|
|
} |
64
|
|
|
$data['reviews'] = $reviews; |
65
|
|
|
parent::debug($data); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
7 |
|
protected function hideOptions() |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
7 |
|
'title' => _x('Hide the title', 'admin-text', 'site-reviews'), |
76
|
7 |
|
'rating' => _x('Hide the rating', 'admin-text', 'site-reviews'), |
77
|
7 |
|
'date' => _x('Hide the date', 'admin-text', 'site-reviews'), |
78
|
7 |
|
'assigned_links' => _x('Hide the assigned links (if shown)', 'admin-text', 'site-reviews'), |
79
|
7 |
|
'content' => _x('Hide the content', 'admin-text', 'site-reviews'), |
80
|
7 |
|
'avatar' => _x('Hide the avatar (if shown)', 'admin-text', 'site-reviews'), |
81
|
7 |
|
'author' => _x('Hide the author', 'admin-text', 'site-reviews'), |
82
|
7 |
|
'response' => _x('Hide the response', 'admin-text', 'site-reviews'), |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|