@@ -7,115 +7,115 @@ |
||
7 | 7 | |
8 | 8 | class SiteReviewsFormBlock extends BlockGenerator |
9 | 9 | { |
10 | - /** |
|
11 | - * @return array |
|
12 | - */ |
|
13 | - public function attributes() |
|
14 | - { |
|
15 | - return [ |
|
16 | - 'assign_to' => [ |
|
17 | - 'default' => '', |
|
18 | - 'type' => 'string', |
|
19 | - ], |
|
20 | - 'category' => [ |
|
21 | - 'default' => '', |
|
22 | - 'type' => 'string', |
|
23 | - ], |
|
24 | - 'className' => [ |
|
25 | - 'default' => '', |
|
26 | - 'type' => 'string', |
|
27 | - ], |
|
28 | - 'hide' => [ |
|
29 | - 'default' => '', |
|
30 | - 'type' => 'string', |
|
31 | - ], |
|
32 | - 'id' => [ |
|
33 | - 'default' => '', |
|
34 | - 'type' => 'string', |
|
35 | - ], |
|
36 | - ]; |
|
37 | - } |
|
10 | + /** |
|
11 | + * @return array |
|
12 | + */ |
|
13 | + public function attributes() |
|
14 | + { |
|
15 | + return [ |
|
16 | + 'assign_to' => [ |
|
17 | + 'default' => '', |
|
18 | + 'type' => 'string', |
|
19 | + ], |
|
20 | + 'category' => [ |
|
21 | + 'default' => '', |
|
22 | + 'type' => 'string', |
|
23 | + ], |
|
24 | + 'className' => [ |
|
25 | + 'default' => '', |
|
26 | + 'type' => 'string', |
|
27 | + ], |
|
28 | + 'hide' => [ |
|
29 | + 'default' => '', |
|
30 | + 'type' => 'string', |
|
31 | + ], |
|
32 | + 'id' => [ |
|
33 | + 'default' => '', |
|
34 | + 'type' => 'string', |
|
35 | + ], |
|
36 | + ]; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function render(array $attributes) |
|
43 | - { |
|
44 | - $attributes['class'] = $attributes['className']; |
|
45 | - $shortcode = glsr(Shortcode::class); |
|
46 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
47 | - $this->filterFormFields(); |
|
48 | - $this->filterRatingField(); |
|
49 | - $this->filterShortcodeClass(); |
|
50 | - $this->filterSubmitButton(); |
|
51 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
52 | - $this->filterInterpolation(); |
|
53 | - } |
|
54 | - } |
|
55 | - return $shortcode->buildShortcode($attributes); |
|
56 | - } |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function render(array $attributes) |
|
43 | + { |
|
44 | + $attributes['class'] = $attributes['className']; |
|
45 | + $shortcode = glsr(Shortcode::class); |
|
46 | + if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
47 | + $this->filterFormFields(); |
|
48 | + $this->filterRatingField(); |
|
49 | + $this->filterShortcodeClass(); |
|
50 | + $this->filterSubmitButton(); |
|
51 | + if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
52 | + $this->filterInterpolation(); |
|
53 | + } |
|
54 | + } |
|
55 | + return $shortcode->buildShortcode($attributes); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - protected function filterFormFields() |
|
62 | - { |
|
63 | - add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
64 | - array_walk($config, function (&$field) { |
|
65 | - $field['disabled'] = true; |
|
66 | - $field['tabindex'] = '-1'; |
|
67 | - }); |
|
68 | - return $config; |
|
69 | - }); |
|
70 | - } |
|
58 | + /** |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + protected function filterFormFields() |
|
62 | + { |
|
63 | + add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
64 | + array_walk($config, function (&$field) { |
|
65 | + $field['disabled'] = true; |
|
66 | + $field['tabindex'] = '-1'; |
|
67 | + }); |
|
68 | + return $config; |
|
69 | + }); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - protected function filterInterpolation() |
|
76 | - { |
|
77 | - add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
78 | - $context['class'] = 'glsr-default glsr-block-disabled'; |
|
79 | - $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
80 | - $context['response'] = ''; |
|
81 | - $context['submit_button'] = ''; |
|
82 | - return $context; |
|
83 | - }); |
|
84 | - } |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + protected function filterInterpolation() |
|
76 | + { |
|
77 | + add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
78 | + $context['class'] = 'glsr-default glsr-block-disabled'; |
|
79 | + $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
80 | + $context['response'] = ''; |
|
81 | + $context['submit_button'] = ''; |
|
82 | + return $context; |
|
83 | + }); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @return void |
|
88 | - */ |
|
89 | - protected function filterRatingField() |
|
90 | - { |
|
91 | - add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
92 | - if ('rating' == $args['path']) { |
|
93 | - $stars = '<span class="glsr-stars">'; |
|
94 | - $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int) glsr()->constant('MAX_RATING', Rating::class)); |
|
95 | - $stars.= '</span>'; |
|
96 | - $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html); |
|
97 | - } |
|
98 | - return $html; |
|
99 | - }, 10, 3); |
|
100 | - } |
|
86 | + /** |
|
87 | + * @return void |
|
88 | + */ |
|
89 | + protected function filterRatingField() |
|
90 | + { |
|
91 | + add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
92 | + if ('rating' == $args['path']) { |
|
93 | + $stars = '<span class="glsr-stars">'; |
|
94 | + $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int) glsr()->constant('MAX_RATING', Rating::class)); |
|
95 | + $stars.= '</span>'; |
|
96 | + $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html); |
|
97 | + } |
|
98 | + return $html; |
|
99 | + }, 10, 3); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - protected function filterShortcodeClass() |
|
106 | - { |
|
107 | - add_filter('site-reviews/style', function () { |
|
108 | - return 'default'; |
|
109 | - }); |
|
110 | - } |
|
102 | + /** |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + protected function filterShortcodeClass() |
|
106 | + { |
|
107 | + add_filter('site-reviews/style', function () { |
|
108 | + return 'default'; |
|
109 | + }); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - protected function filterSubmitButton() |
|
116 | - { |
|
117 | - add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
118 | - return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
119 | - }); |
|
120 | - } |
|
112 | + /** |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + protected function filterSubmitButton() |
|
116 | + { |
|
117 | + add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
118 | + return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
119 | + }); |
|
120 | + } |
|
121 | 121 | } |
@@ -9,92 +9,92 @@ |
||
9 | 9 | |
10 | 10 | class TermCountsManager |
11 | 11 | { |
12 | - /** |
|
13 | - * @var CountsManager |
|
14 | - */ |
|
15 | - protected $manager; |
|
12 | + /** |
|
13 | + * @var CountsManager |
|
14 | + */ |
|
15 | + protected $manager; |
|
16 | 16 | |
17 | - public function __construct() |
|
18 | - { |
|
19 | - $this->manager = glsr(CountsManager::class); |
|
20 | - } |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + $this->manager = glsr(CountsManager::class); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param int $termTaxonomyId |
|
24 | - * @return array |
|
25 | - */ |
|
26 | - public function build($termTaxonomyId) |
|
27 | - { |
|
28 | - return $this->manager->buildCounts([ |
|
29 | - 'term_ids' => [$termTaxonomyId], |
|
30 | - ]); |
|
31 | - } |
|
22 | + /** |
|
23 | + * @param int $termTaxonomyId |
|
24 | + * @return array |
|
25 | + */ |
|
26 | + public function build($termTaxonomyId) |
|
27 | + { |
|
28 | + return $this->manager->buildCounts([ |
|
29 | + 'term_ids' => [$termTaxonomyId], |
|
30 | + ]); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function decrease(Review $review) |
|
37 | - { |
|
38 | - foreach ($review->term_ids as $termId) { |
|
39 | - if (empty($counts = $this->get($termId))) { |
|
40 | - continue; |
|
41 | - } |
|
42 | - $this->update($termId, |
|
43 | - $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
44 | - ); |
|
45 | - } |
|
46 | - } |
|
33 | + /** |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function decrease(Review $review) |
|
37 | + { |
|
38 | + foreach ($review->term_ids as $termId) { |
|
39 | + if (empty($counts = $this->get($termId))) { |
|
40 | + continue; |
|
41 | + } |
|
42 | + $this->update($termId, |
|
43 | + $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
44 | + ); |
|
45 | + } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param int $termId |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - public function get($termId) |
|
53 | - { |
|
54 | - return array_filter((array) get_term_meta($termId, CountsManager::META_COUNT, true)); |
|
55 | - } |
|
48 | + /** |
|
49 | + * @param int $termId |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + public function get($termId) |
|
53 | + { |
|
54 | + return array_filter((array) get_term_meta($termId, CountsManager::META_COUNT, true)); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function increase(Review $review) |
|
61 | - { |
|
62 | - $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
63 | - foreach ($terms as $term) { |
|
64 | - $counts = $this->get($term['term_id']); |
|
65 | - $counts = empty($counts) |
|
66 | - ? $this->build($term['term_taxonomy_id']) |
|
67 | - : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
68 | - $this->update($term['term_id'], $counts); |
|
69 | - } |
|
70 | - } |
|
57 | + /** |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function increase(Review $review) |
|
61 | + { |
|
62 | + $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
63 | + foreach ($terms as $term) { |
|
64 | + $counts = $this->get($term['term_id']); |
|
65 | + $counts = empty($counts) |
|
66 | + ? $this->build($term['term_taxonomy_id']) |
|
67 | + : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
68 | + $this->update($term['term_id'], $counts); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @param int $termId |
|
74 | - * @return void |
|
75 | - */ |
|
76 | - public function update($termId, array $reviewCounts) |
|
77 | - { |
|
78 | - $term = get_term($termId, Application::TAXONOMY); |
|
79 | - if (!isset($term->term_id)) { |
|
80 | - return; |
|
81 | - } |
|
82 | - $ratingCounts = $this->manager->flatten($reviewCounts); |
|
83 | - update_term_meta($termId, CountsManager::META_COUNT, $reviewCounts); |
|
84 | - update_term_meta($termId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
85 | - update_term_meta($termId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
86 | - } |
|
72 | + /** |
|
73 | + * @param int $termId |
|
74 | + * @return void |
|
75 | + */ |
|
76 | + public function update($termId, array $reviewCounts) |
|
77 | + { |
|
78 | + $term = get_term($termId, Application::TAXONOMY); |
|
79 | + if (!isset($term->term_id)) { |
|
80 | + return; |
|
81 | + } |
|
82 | + $ratingCounts = $this->manager->flatten($reviewCounts); |
|
83 | + update_term_meta($termId, CountsManager::META_COUNT, $reviewCounts); |
|
84 | + update_term_meta($termId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
85 | + update_term_meta($termId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - public function updateAll() |
|
92 | - { |
|
93 | - $terms = glsr(Database::class)->getTerms([ |
|
94 | - 'fields' => 'all', |
|
95 | - ]); |
|
96 | - foreach ($terms as $term) { |
|
97 | - $this->update($term->term_id, $this->build($term->term_taxonomy_id)); |
|
98 | - } |
|
99 | - } |
|
88 | + /** |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + public function updateAll() |
|
92 | + { |
|
93 | + $terms = glsr(Database::class)->getTerms([ |
|
94 | + 'fields' => 'all', |
|
95 | + ]); |
|
96 | + foreach ($terms as $term) { |
|
97 | + $this->update($term->term_id, $this->build($term->term_taxonomy_id)); |
|
98 | + } |
|
99 | + } |
|
100 | 100 | } |
@@ -7,84 +7,84 @@ |
||
7 | 7 | |
8 | 8 | class PostCountsManager |
9 | 9 | { |
10 | - /** |
|
11 | - * @var CountsManager |
|
12 | - */ |
|
13 | - protected $manager; |
|
10 | + /** |
|
11 | + * @var CountsManager |
|
12 | + */ |
|
13 | + protected $manager; |
|
14 | 14 | |
15 | - public function __construct() |
|
16 | - { |
|
17 | - $this->manager = glsr(CountsManager::class); |
|
18 | - } |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + $this->manager = glsr(CountsManager::class); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @param int $postId |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function build($postId) |
|
25 | - { |
|
26 | - return $this->manager->buildCounts([ |
|
27 | - 'post_ids' => [$postId], |
|
28 | - ]); |
|
29 | - } |
|
20 | + /** |
|
21 | + * @param int $postId |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function build($postId) |
|
25 | + { |
|
26 | + return $this->manager->buildCounts([ |
|
27 | + 'post_ids' => [$postId], |
|
28 | + ]); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function decrease(Review $review) |
|
35 | - { |
|
36 | - if (empty($counts = $this->get($review->assigned_to))) { |
|
37 | - return; |
|
38 | - } |
|
39 | - $this->update($review->assigned_to, |
|
40 | - $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
41 | - ); |
|
42 | - } |
|
31 | + /** |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function decrease(Review $review) |
|
35 | + { |
|
36 | + if (empty($counts = $this->get($review->assigned_to))) { |
|
37 | + return; |
|
38 | + } |
|
39 | + $this->update($review->assigned_to, |
|
40 | + $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
41 | + ); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int $postId |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function get($postId) |
|
49 | - { |
|
50 | - return array_filter((array) get_post_meta($postId, CountsManager::META_COUNT, true)); |
|
51 | - } |
|
44 | + /** |
|
45 | + * @param int $postId |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function get($postId) |
|
49 | + { |
|
50 | + return array_filter((array) get_post_meta($postId, CountsManager::META_COUNT, true)); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function increase(Review $review) |
|
57 | - { |
|
58 | - if (!(get_post($review->assigned_to) instanceof \WP_Post)) { |
|
59 | - return; |
|
60 | - } |
|
61 | - $counts = $this->get($review->assigned_to); |
|
62 | - $counts = empty($counts) |
|
63 | - ? $this->build($review->assigned_to) |
|
64 | - : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
65 | - $this->update($review->assigned_to, $counts); |
|
66 | - } |
|
53 | + /** |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function increase(Review $review) |
|
57 | + { |
|
58 | + if (!(get_post($review->assigned_to) instanceof \WP_Post)) { |
|
59 | + return; |
|
60 | + } |
|
61 | + $counts = $this->get($review->assigned_to); |
|
62 | + $counts = empty($counts) |
|
63 | + ? $this->build($review->assigned_to) |
|
64 | + : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
65 | + $this->update($review->assigned_to, $counts); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param int $postId |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function update($postId, array $reviewCounts) |
|
73 | - { |
|
74 | - $ratingCounts = $this->manager->flatten($reviewCounts); |
|
75 | - update_post_meta($postId, CountsManager::META_COUNT, $reviewCounts); |
|
76 | - update_post_meta($postId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
77 | - update_post_meta($postId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
78 | - } |
|
68 | + /** |
|
69 | + * @param int $postId |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function update($postId, array $reviewCounts) |
|
73 | + { |
|
74 | + $ratingCounts = $this->manager->flatten($reviewCounts); |
|
75 | + update_post_meta($postId, CountsManager::META_COUNT, $reviewCounts); |
|
76 | + update_post_meta($postId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
77 | + update_post_meta($postId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - public function updateAll() |
|
84 | - { |
|
85 | - $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
86 | - foreach ($postIds as $postId) { |
|
87 | - $this->update($postId, $this->build($postId)); |
|
88 | - } |
|
89 | - } |
|
80 | + /** |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + public function updateAll() |
|
84 | + { |
|
85 | + $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
86 | + foreach ($postIds as $postId) { |
|
87 | + $this->update($postId, $this->build($postId)); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | } |
@@ -16,204 +16,204 @@ |
||
16 | 16 | |
17 | 17 | class ReviewManager |
18 | 18 | { |
19 | - /** |
|
20 | - * @return false|Review |
|
21 | - */ |
|
22 | - public function create(CreateReview $command) |
|
23 | - { |
|
24 | - $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command); |
|
25 | - $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command); |
|
26 | - $reviewValues = Arr::prefixArrayKeys($reviewValues); |
|
27 | - unset($reviewValues['json']); // @todo remove the need for this |
|
28 | - $postValues = [ |
|
29 | - 'comment_status' => 'closed', |
|
30 | - 'meta_input' => $reviewValues, |
|
31 | - 'ping_status' => 'closed', |
|
32 | - 'post_content' => $reviewValues['_content'], |
|
33 | - 'post_date' => $reviewValues['_date'], |
|
34 | - 'post_date_gmt' => get_gmt_from_date($reviewValues['_date']), |
|
35 | - 'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'], |
|
36 | - 'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted), |
|
37 | - 'post_title' => $reviewValues['_title'], |
|
38 | - 'post_type' => Application::POST_TYPE, |
|
39 | - ]; |
|
40 | - $postId = wp_insert_post($postValues, true); |
|
41 | - if (is_wp_error($postId)) { |
|
42 | - glsr_log()->error($postId->get_error_message())->debug($postValues); |
|
43 | - return false; |
|
44 | - } |
|
45 | - $this->setTerms($postId, $command->category); |
|
46 | - $review = $this->single(get_post($postId)); |
|
47 | - do_action('site-reviews/review/created', $review, $command); |
|
48 | - return $review; |
|
49 | - } |
|
19 | + /** |
|
20 | + * @return false|Review |
|
21 | + */ |
|
22 | + public function create(CreateReview $command) |
|
23 | + { |
|
24 | + $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command); |
|
25 | + $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command); |
|
26 | + $reviewValues = Arr::prefixArrayKeys($reviewValues); |
|
27 | + unset($reviewValues['json']); // @todo remove the need for this |
|
28 | + $postValues = [ |
|
29 | + 'comment_status' => 'closed', |
|
30 | + 'meta_input' => $reviewValues, |
|
31 | + 'ping_status' => 'closed', |
|
32 | + 'post_content' => $reviewValues['_content'], |
|
33 | + 'post_date' => $reviewValues['_date'], |
|
34 | + 'post_date_gmt' => get_gmt_from_date($reviewValues['_date']), |
|
35 | + 'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'], |
|
36 | + 'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted), |
|
37 | + 'post_title' => $reviewValues['_title'], |
|
38 | + 'post_type' => Application::POST_TYPE, |
|
39 | + ]; |
|
40 | + $postId = wp_insert_post($postValues, true); |
|
41 | + if (is_wp_error($postId)) { |
|
42 | + glsr_log()->error($postId->get_error_message())->debug($postValues); |
|
43 | + return false; |
|
44 | + } |
|
45 | + $this->setTerms($postId, $command->category); |
|
46 | + $review = $this->single(get_post($postId)); |
|
47 | + do_action('site-reviews/review/created', $review, $command); |
|
48 | + return $review; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string $metaReviewId |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function delete($metaReviewId) |
|
56 | - { |
|
57 | - if ($postId = $this->getPostId($metaReviewId)) { |
|
58 | - wp_delete_post($postId, true); |
|
59 | - } |
|
60 | - } |
|
51 | + /** |
|
52 | + * @param string $metaReviewId |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function delete($metaReviewId) |
|
56 | + { |
|
57 | + if ($postId = $this->getPostId($metaReviewId)) { |
|
58 | + wp_delete_post($postId, true); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return object |
|
64 | - */ |
|
65 | - public function get(array $args = []) |
|
66 | - { |
|
67 | - $args = glsr(ReviewsDefaults::class)->merge($args); |
|
68 | - $metaQuery = glsr(QueryBuilder::class)->buildQuery( |
|
69 | - ['assigned_to', 'email', 'ip_address', 'type', 'rating'], |
|
70 | - $args |
|
71 | - ); |
|
72 | - $taxQuery = glsr(QueryBuilder::class)->buildQuery( |
|
73 | - ['category'], |
|
74 | - ['category' => $this->normalizeTermIds($args['category'])] |
|
75 | - ); |
|
76 | - $paged = glsr(QueryBuilder::class)->getPaged( |
|
77 | - wp_validate_boolean($args['pagination']) |
|
78 | - ); |
|
79 | - $parameters = [ |
|
80 | - 'meta_key' => '_pinned', |
|
81 | - 'meta_query' => $metaQuery, |
|
82 | - 'offset' => $args['offset'], |
|
83 | - 'order' => $args['order'], |
|
84 | - 'orderby' => 'meta_value '.$args['orderby'], |
|
85 | - 'paged' => Arr::get($args, 'paged', $paged), |
|
86 | - 'post__in' => $args['post__in'], |
|
87 | - 'post__not_in' => $args['post__not_in'], |
|
88 | - 'post_status' => 'publish', |
|
89 | - 'post_type' => Application::POST_TYPE, |
|
90 | - 'posts_per_page' => $args['per_page'], |
|
91 | - 'tax_query' => $taxQuery, |
|
92 | - ]; |
|
93 | - $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args); |
|
94 | - $query = new WP_Query($parameters); |
|
95 | - $results = array_map([$this, 'single'], $query->posts); |
|
96 | - $reviews = new Reviews($results, $query->max_num_pages, $args); |
|
97 | - return apply_filters('site-reviews/get/reviews', $reviews, $query); |
|
98 | - } |
|
62 | + /** |
|
63 | + * @return object |
|
64 | + */ |
|
65 | + public function get(array $args = []) |
|
66 | + { |
|
67 | + $args = glsr(ReviewsDefaults::class)->merge($args); |
|
68 | + $metaQuery = glsr(QueryBuilder::class)->buildQuery( |
|
69 | + ['assigned_to', 'email', 'ip_address', 'type', 'rating'], |
|
70 | + $args |
|
71 | + ); |
|
72 | + $taxQuery = glsr(QueryBuilder::class)->buildQuery( |
|
73 | + ['category'], |
|
74 | + ['category' => $this->normalizeTermIds($args['category'])] |
|
75 | + ); |
|
76 | + $paged = glsr(QueryBuilder::class)->getPaged( |
|
77 | + wp_validate_boolean($args['pagination']) |
|
78 | + ); |
|
79 | + $parameters = [ |
|
80 | + 'meta_key' => '_pinned', |
|
81 | + 'meta_query' => $metaQuery, |
|
82 | + 'offset' => $args['offset'], |
|
83 | + 'order' => $args['order'], |
|
84 | + 'orderby' => 'meta_value '.$args['orderby'], |
|
85 | + 'paged' => Arr::get($args, 'paged', $paged), |
|
86 | + 'post__in' => $args['post__in'], |
|
87 | + 'post__not_in' => $args['post__not_in'], |
|
88 | + 'post_status' => 'publish', |
|
89 | + 'post_type' => Application::POST_TYPE, |
|
90 | + 'posts_per_page' => $args['per_page'], |
|
91 | + 'tax_query' => $taxQuery, |
|
92 | + ]; |
|
93 | + $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args); |
|
94 | + $query = new WP_Query($parameters); |
|
95 | + $results = array_map([$this, 'single'], $query->posts); |
|
96 | + $reviews = new Reviews($results, $query->max_num_pages, $args); |
|
97 | + return apply_filters('site-reviews/get/reviews', $reviews, $query); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @param string $metaReviewId |
|
102 | - * @return int |
|
103 | - */ |
|
104 | - public function getPostId($metaReviewId) |
|
105 | - { |
|
106 | - return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId); |
|
107 | - } |
|
100 | + /** |
|
101 | + * @param string $metaReviewId |
|
102 | + * @return int |
|
103 | + */ |
|
104 | + public function getPostId($metaReviewId) |
|
105 | + { |
|
106 | + return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function getRatingCounts(array $args = []) |
|
113 | - { |
|
114 | - $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args); |
|
115 | - $counts = glsr(CountsManager::class)->getCounts([ |
|
116 | - 'post_ids' => Arr::convertStringToArray($args['assigned_to']), |
|
117 | - 'term_ids' => $this->normalizeTermIds($args['category']), |
|
118 | - 'type' => $args['type'], |
|
119 | - ]); |
|
120 | - return glsr(CountsManager::class)->flatten($counts, [ |
|
121 | - 'min' => $args['rating'], |
|
122 | - ]); |
|
123 | - } |
|
109 | + /** |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function getRatingCounts(array $args = []) |
|
113 | + { |
|
114 | + $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args); |
|
115 | + $counts = glsr(CountsManager::class)->getCounts([ |
|
116 | + 'post_ids' => Arr::convertStringToArray($args['assigned_to']), |
|
117 | + 'term_ids' => $this->normalizeTermIds($args['category']), |
|
118 | + 'type' => $args['type'], |
|
119 | + ]); |
|
120 | + return glsr(CountsManager::class)->flatten($counts, [ |
|
121 | + 'min' => $args['rating'], |
|
122 | + ]); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * @param string $commaSeparatedTermIds |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public function normalizeTermIds($commaSeparatedTermIds) |
|
130 | - { |
|
131 | - $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id'); |
|
132 | - return array_unique(array_map('intval', $termIds)); |
|
133 | - } |
|
125 | + /** |
|
126 | + * @param string $commaSeparatedTermIds |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public function normalizeTermIds($commaSeparatedTermIds) |
|
130 | + { |
|
131 | + $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id'); |
|
132 | + return array_unique(array_map('intval', $termIds)); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @param string $commaSeparatedTermIds |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function normalizeTerms($commaSeparatedTermIds) |
|
140 | - { |
|
141 | - $terms = []; |
|
142 | - $termIds = Arr::convertStringToArray($commaSeparatedTermIds); |
|
143 | - foreach ($termIds as $termId) { |
|
144 | - if (is_numeric($termId)) { |
|
145 | - $termId = intval($termId); |
|
146 | - } |
|
147 | - $term = term_exists($termId, Application::TAXONOMY); |
|
148 | - if (!isset($term['term_id'])) { |
|
149 | - continue; |
|
150 | - } |
|
151 | - $terms[] = $term; |
|
152 | - } |
|
153 | - return $terms; |
|
154 | - } |
|
135 | + /** |
|
136 | + * @param string $commaSeparatedTermIds |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function normalizeTerms($commaSeparatedTermIds) |
|
140 | + { |
|
141 | + $terms = []; |
|
142 | + $termIds = Arr::convertStringToArray($commaSeparatedTermIds); |
|
143 | + foreach ($termIds as $termId) { |
|
144 | + if (is_numeric($termId)) { |
|
145 | + $termId = intval($termId); |
|
146 | + } |
|
147 | + $term = term_exists($termId, Application::TAXONOMY); |
|
148 | + if (!isset($term['term_id'])) { |
|
149 | + continue; |
|
150 | + } |
|
151 | + $terms[] = $term; |
|
152 | + } |
|
153 | + return $terms; |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * @param int $postId |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - public function revert($postId) |
|
161 | - { |
|
162 | - if (Application::POST_TYPE != get_post_field('post_type', $postId)) { |
|
163 | - return; |
|
164 | - } |
|
165 | - delete_post_meta($postId, '_edit_last'); |
|
166 | - $result = wp_update_post([ |
|
167 | - 'ID' => $postId, |
|
168 | - 'post_content' => glsr(Database::class)->get($postId, 'content'), |
|
169 | - 'post_date' => glsr(Database::class)->get($postId, 'date'), |
|
170 | - 'post_title' => glsr(Database::class)->get($postId, 'title'), |
|
171 | - ]); |
|
172 | - if (is_wp_error($result)) { |
|
173 | - glsr_log()->error($result->get_error_message()); |
|
174 | - return; |
|
175 | - } |
|
176 | - do_action('site-reviews/review/reverted', glsr_get_review($postId)); |
|
177 | - } |
|
156 | + /** |
|
157 | + * @param int $postId |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + public function revert($postId) |
|
161 | + { |
|
162 | + if (Application::POST_TYPE != get_post_field('post_type', $postId)) { |
|
163 | + return; |
|
164 | + } |
|
165 | + delete_post_meta($postId, '_edit_last'); |
|
166 | + $result = wp_update_post([ |
|
167 | + 'ID' => $postId, |
|
168 | + 'post_content' => glsr(Database::class)->get($postId, 'content'), |
|
169 | + 'post_date' => glsr(Database::class)->get($postId, 'date'), |
|
170 | + 'post_title' => glsr(Database::class)->get($postId, 'title'), |
|
171 | + ]); |
|
172 | + if (is_wp_error($result)) { |
|
173 | + glsr_log()->error($result->get_error_message()); |
|
174 | + return; |
|
175 | + } |
|
176 | + do_action('site-reviews/review/reverted', glsr_get_review($postId)); |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * @return Review |
|
181 | - */ |
|
182 | - public function single(WP_Post $post) |
|
183 | - { |
|
184 | - if (Application::POST_TYPE != $post->post_type) { |
|
185 | - $post = new WP_Post((object) []); |
|
186 | - } |
|
187 | - $review = new Review($post); |
|
188 | - return apply_filters('site-reviews/get/review', $review, $post); |
|
189 | - } |
|
179 | + /** |
|
180 | + * @return Review |
|
181 | + */ |
|
182 | + public function single(WP_Post $post) |
|
183 | + { |
|
184 | + if (Application::POST_TYPE != $post->post_type) { |
|
185 | + $post = new WP_Post((object) []); |
|
186 | + } |
|
187 | + $review = new Review($post); |
|
188 | + return apply_filters('site-reviews/get/review', $review, $post); |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * @param bool $isBlacklisted |
|
193 | - * @return string |
|
194 | - */ |
|
195 | - protected function getNewPostStatus(array $reviewValues, $isBlacklisted) |
|
196 | - { |
|
197 | - $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval'); |
|
198 | - return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted) |
|
199 | - ? 'pending' |
|
200 | - : 'publish'; |
|
201 | - } |
|
191 | + /** |
|
192 | + * @param bool $isBlacklisted |
|
193 | + * @return string |
|
194 | + */ |
|
195 | + protected function getNewPostStatus(array $reviewValues, $isBlacklisted) |
|
196 | + { |
|
197 | + $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval'); |
|
198 | + return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted) |
|
199 | + ? 'pending' |
|
200 | + : 'publish'; |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * @param int $postId |
|
205 | - * @param string $termIds |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - protected function setTerms($postId, $termIds) |
|
209 | - { |
|
210 | - $termIds = $this->normalizeTermIds($termIds); |
|
211 | - if (empty($termIds)) { |
|
212 | - return; |
|
213 | - } |
|
214 | - $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY); |
|
215 | - if (is_wp_error($termTaxonomyIds)) { |
|
216 | - glsr_log()->error($termTaxonomyIds->get_error_message()); |
|
217 | - } |
|
218 | - } |
|
203 | + /** |
|
204 | + * @param int $postId |
|
205 | + * @param string $termIds |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + protected function setTerms($postId, $termIds) |
|
209 | + { |
|
210 | + $termIds = $this->normalizeTermIds($termIds); |
|
211 | + if (empty($termIds)) { |
|
212 | + return; |
|
213 | + } |
|
214 | + $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY); |
|
215 | + if (is_wp_error($termTaxonomyIds)) { |
|
216 | + glsr_log()->error($termTaxonomyIds->get_error_message()); |
|
217 | + } |
|
218 | + } |
|
219 | 219 | } |
@@ -7,73 +7,73 @@ |
||
7 | 7 | |
8 | 8 | class GlobalCountsManager |
9 | 9 | { |
10 | - /** |
|
11 | - * @var CountsManager |
|
12 | - */ |
|
13 | - protected $manager; |
|
10 | + /** |
|
11 | + * @var CountsManager |
|
12 | + */ |
|
13 | + protected $manager; |
|
14 | 14 | |
15 | - public function __construct() |
|
16 | - { |
|
17 | - $this->manager = glsr(CountsManager::class); |
|
18 | - } |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + $this->manager = glsr(CountsManager::class); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @return array |
|
22 | - */ |
|
23 | - public function build() |
|
24 | - { |
|
25 | - return $this->manager->buildCounts(); |
|
26 | - } |
|
20 | + /** |
|
21 | + * @return array |
|
22 | + */ |
|
23 | + public function build() |
|
24 | + { |
|
25 | + return $this->manager->buildCounts(); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function decrease(Review $review) |
|
32 | - { |
|
33 | - $this->update($this->manager->decreaseRating( |
|
34 | - $this->get(), |
|
35 | - $review->review_type, |
|
36 | - $review->rating |
|
37 | - )); |
|
38 | - } |
|
28 | + /** |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function decrease(Review $review) |
|
32 | + { |
|
33 | + $this->update($this->manager->decreaseRating( |
|
34 | + $this->get(), |
|
35 | + $review->review_type, |
|
36 | + $review->rating |
|
37 | + )); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public function get() |
|
44 | - { |
|
45 | - $counts = glsr(OptionManager::class)->get('counts', []); |
|
46 | - if (!is_array($counts)) { |
|
47 | - glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
48 | - return []; |
|
49 | - } |
|
50 | - return $counts; |
|
51 | - } |
|
40 | + /** |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public function get() |
|
44 | + { |
|
45 | + $counts = glsr(OptionManager::class)->get('counts', []); |
|
46 | + if (!is_array($counts)) { |
|
47 | + glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
48 | + return []; |
|
49 | + } |
|
50 | + return $counts; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function increase(Review $review) |
|
57 | - { |
|
58 | - if (empty($counts = $this->get())) { |
|
59 | - $counts = $this->build(); |
|
60 | - } |
|
61 | - $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating)); |
|
62 | - } |
|
53 | + /** |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function increase(Review $review) |
|
57 | + { |
|
58 | + if (empty($counts = $this->get())) { |
|
59 | + $counts = $this->build(); |
|
60 | + } |
|
61 | + $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating)); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - public function update(array $reviewCounts) |
|
68 | - { |
|
69 | - glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + public function update(array $reviewCounts) |
|
68 | + { |
|
69 | + glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function updateAll() |
|
76 | - { |
|
77 | - $this->update($this->build()); |
|
78 | - } |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function updateAll() |
|
76 | + { |
|
77 | + $this->update($this->build()); |
|
78 | + } |
|
79 | 79 | } |
@@ -16,159 +16,159 @@ |
||
16 | 16 | |
17 | 17 | class ReviewController extends Controller |
18 | 18 | { |
19 | - /** |
|
20 | - * Triggered when a category is added to a review. |
|
21 | - * |
|
22 | - * @param int $postId |
|
23 | - * @param array $terms |
|
24 | - * @param array $newTTIds |
|
25 | - * @param string $taxonomy |
|
26 | - * @param bool $append |
|
27 | - * @param array $oldTTIds |
|
28 | - * @return void |
|
29 | - * @action set_object_terms |
|
30 | - */ |
|
31 | - public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
32 | - { |
|
33 | - sort($newTTIds); |
|
34 | - sort($oldTTIds); |
|
35 | - if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
36 | - return; |
|
37 | - } |
|
38 | - $review = glsr_get_review($postId); |
|
39 | - if ('publish' !== $review->status) { |
|
40 | - return; |
|
41 | - } |
|
42 | - $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
43 | - $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
44 | - $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
45 | - if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
46 | - glsr(TermCountsManager::class)->decrease($review); |
|
47 | - } |
|
48 | - if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
49 | - glsr(TermCountsManager::class)->increase($review); |
|
50 | - } |
|
51 | - } |
|
19 | + /** |
|
20 | + * Triggered when a category is added to a review. |
|
21 | + * |
|
22 | + * @param int $postId |
|
23 | + * @param array $terms |
|
24 | + * @param array $newTTIds |
|
25 | + * @param string $taxonomy |
|
26 | + * @param bool $append |
|
27 | + * @param array $oldTTIds |
|
28 | + * @return void |
|
29 | + * @action set_object_terms |
|
30 | + */ |
|
31 | + public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
32 | + { |
|
33 | + sort($newTTIds); |
|
34 | + sort($oldTTIds); |
|
35 | + if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
36 | + return; |
|
37 | + } |
|
38 | + $review = glsr_get_review($postId); |
|
39 | + if ('publish' !== $review->status) { |
|
40 | + return; |
|
41 | + } |
|
42 | + $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
43 | + $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
44 | + $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
45 | + if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
46 | + glsr(TermCountsManager::class)->decrease($review); |
|
47 | + } |
|
48 | + if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
49 | + glsr(TermCountsManager::class)->increase($review); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Triggered when an existing review is approved|unapproved. |
|
55 | - * |
|
56 | - * @param string $oldStatus |
|
57 | - * @param string $newStatus |
|
58 | - * @param \WP_Post $post |
|
59 | - * @return void |
|
60 | - * @action transition_post_status |
|
61 | - */ |
|
62 | - public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
63 | - { |
|
64 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') |
|
65 | - || in_array($oldStatus, ['new', $newStatus])) { |
|
66 | - return; |
|
67 | - } |
|
68 | - $review = glsr_get_review($post); |
|
69 | - if ('publish' == $post->post_status) { |
|
70 | - glsr(CountsManager::class)->increaseAll($review); |
|
71 | - } else { |
|
72 | - glsr(CountsManager::class)->decreaseAll($review); |
|
73 | - } |
|
74 | - } |
|
53 | + /** |
|
54 | + * Triggered when an existing review is approved|unapproved. |
|
55 | + * |
|
56 | + * @param string $oldStatus |
|
57 | + * @param string $newStatus |
|
58 | + * @param \WP_Post $post |
|
59 | + * @return void |
|
60 | + * @action transition_post_status |
|
61 | + */ |
|
62 | + public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
63 | + { |
|
64 | + if (Application::POST_TYPE != Arr::get($post, 'post_type') |
|
65 | + || in_array($oldStatus, ['new', $newStatus])) { |
|
66 | + return; |
|
67 | + } |
|
68 | + $review = glsr_get_review($post); |
|
69 | + if ('publish' == $post->post_status) { |
|
70 | + glsr(CountsManager::class)->increaseAll($review); |
|
71 | + } else { |
|
72 | + glsr(CountsManager::class)->decreaseAll($review); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Triggered when a review is first created. |
|
78 | - * |
|
79 | - * @return void |
|
80 | - * @action site-reviews/review/created |
|
81 | - */ |
|
82 | - public function onAfterCreate(Review $review) |
|
83 | - { |
|
84 | - if ('publish' !== $review->status) { |
|
85 | - return; |
|
86 | - } |
|
87 | - glsr(GlobalCountsManager::class)->increase($review); |
|
88 | - glsr(PostCountsManager::class)->increase($review); |
|
89 | - } |
|
76 | + /** |
|
77 | + * Triggered when a review is first created. |
|
78 | + * |
|
79 | + * @return void |
|
80 | + * @action site-reviews/review/created |
|
81 | + */ |
|
82 | + public function onAfterCreate(Review $review) |
|
83 | + { |
|
84 | + if ('publish' !== $review->status) { |
|
85 | + return; |
|
86 | + } |
|
87 | + glsr(GlobalCountsManager::class)->increase($review); |
|
88 | + glsr(PostCountsManager::class)->increase($review); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Triggered when a review is deleted. |
|
93 | - * |
|
94 | - * @param int $postId |
|
95 | - * @return void |
|
96 | - * @action before_delete_post |
|
97 | - */ |
|
98 | - public function onBeforeDelete($postId) |
|
99 | - { |
|
100 | - if (!$this->isReviewPostId($postId)) { |
|
101 | - return; |
|
102 | - } |
|
103 | - $review = glsr_get_review($postId); |
|
104 | - if ('trash' !== $review->status) { // do not run for trashed posts |
|
105 | - glsr(CountsManager::class)->decreaseAll($review); |
|
106 | - } |
|
107 | - } |
|
91 | + /** |
|
92 | + * Triggered when a review is deleted. |
|
93 | + * |
|
94 | + * @param int $postId |
|
95 | + * @return void |
|
96 | + * @action before_delete_post |
|
97 | + */ |
|
98 | + public function onBeforeDelete($postId) |
|
99 | + { |
|
100 | + if (!$this->isReviewPostId($postId)) { |
|
101 | + return; |
|
102 | + } |
|
103 | + $review = glsr_get_review($postId); |
|
104 | + if ('trash' !== $review->status) { // do not run for trashed posts |
|
105 | + glsr(CountsManager::class)->decreaseAll($review); |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Triggered when a review's rating, assigned_to, or review_type is changed. |
|
111 | - * |
|
112 | - * @param int $metaId |
|
113 | - * @param int $postId |
|
114 | - * @param string $metaKey |
|
115 | - * @param mixed $metaValue |
|
116 | - * @return void |
|
117 | - * @action update_postmeta |
|
118 | - */ |
|
119 | - public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
120 | - { |
|
121 | - if (!$this->isReviewPostId($postId)) { |
|
122 | - return; |
|
123 | - } |
|
124 | - $metaKey = Str::removePrefix('_', $metaKey); |
|
125 | - if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
126 | - return; |
|
127 | - } |
|
128 | - $review = glsr_get_review($postId); |
|
129 | - if ($review->$metaKey == $metaValue) { |
|
130 | - return; |
|
131 | - } |
|
132 | - $method = Helper::buildMethodName($metaKey, 'onBeforeChange'); |
|
133 | - call_user_func([$this, $method], $review, $metaValue); |
|
134 | - } |
|
109 | + /** |
|
110 | + * Triggered when a review's rating, assigned_to, or review_type is changed. |
|
111 | + * |
|
112 | + * @param int $metaId |
|
113 | + * @param int $postId |
|
114 | + * @param string $metaKey |
|
115 | + * @param mixed $metaValue |
|
116 | + * @return void |
|
117 | + * @action update_postmeta |
|
118 | + */ |
|
119 | + public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
120 | + { |
|
121 | + if (!$this->isReviewPostId($postId)) { |
|
122 | + return; |
|
123 | + } |
|
124 | + $metaKey = Str::removePrefix('_', $metaKey); |
|
125 | + if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
126 | + return; |
|
127 | + } |
|
128 | + $review = glsr_get_review($postId); |
|
129 | + if ($review->$metaKey == $metaValue) { |
|
130 | + return; |
|
131 | + } |
|
132 | + $method = Helper::buildMethodName($metaKey, 'onBeforeChange'); |
|
133 | + call_user_func([$this, $method], $review, $metaValue); |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Triggered by the onBeforeUpdate method. |
|
138 | - * |
|
139 | - * @param string|int $assignedTo |
|
140 | - * @return void |
|
141 | - */ |
|
142 | - protected function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
143 | - { |
|
144 | - glsr(PostCountsManager::class)->decrease($review); |
|
145 | - $review->assigned_to = $assignedTo; |
|
146 | - glsr(PostCountsManager::class)->increase($review); |
|
147 | - } |
|
136 | + /** |
|
137 | + * Triggered by the onBeforeUpdate method. |
|
138 | + * |
|
139 | + * @param string|int $assignedTo |
|
140 | + * @return void |
|
141 | + */ |
|
142 | + protected function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
143 | + { |
|
144 | + glsr(PostCountsManager::class)->decrease($review); |
|
145 | + $review->assigned_to = $assignedTo; |
|
146 | + glsr(PostCountsManager::class)->increase($review); |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Triggered by the onBeforeUpdate method. |
|
151 | - * |
|
152 | - * @param string|int $rating |
|
153 | - * @return void |
|
154 | - */ |
|
155 | - protected function onBeforeChangeRating(Review $review, $rating) |
|
156 | - { |
|
157 | - glsr(CountsManager::class)->decreaseAll($review); |
|
158 | - $review->rating = $rating; |
|
159 | - glsr(CountsManager::class)->increaseAll($review); |
|
160 | - } |
|
149 | + /** |
|
150 | + * Triggered by the onBeforeUpdate method. |
|
151 | + * |
|
152 | + * @param string|int $rating |
|
153 | + * @return void |
|
154 | + */ |
|
155 | + protected function onBeforeChangeRating(Review $review, $rating) |
|
156 | + { |
|
157 | + glsr(CountsManager::class)->decreaseAll($review); |
|
158 | + $review->rating = $rating; |
|
159 | + glsr(CountsManager::class)->increaseAll($review); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Triggered by the onBeforeUpdate method. |
|
164 | - * |
|
165 | - * @param string $reviewType |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - protected function onBeforeChangeReviewType(Review $review, $reviewType) |
|
169 | - { |
|
170 | - glsr(CountsManager::class)->decreaseAll($review); |
|
171 | - $review->review_type = $reviewType; |
|
172 | - glsr(CountsManager::class)->increaseAll($review); |
|
173 | - } |
|
162 | + /** |
|
163 | + * Triggered by the onBeforeUpdate method. |
|
164 | + * |
|
165 | + * @param string $reviewType |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + protected function onBeforeChangeReviewType(Review $review, $reviewType) |
|
169 | + { |
|
170 | + glsr(CountsManager::class)->decreaseAll($review); |
|
171 | + $review->review_type = $reviewType; |
|
172 | + glsr(CountsManager::class)->increaseAll($review); |
|
173 | + } |
|
174 | 174 | } |
@@ -4,186 +4,186 @@ |
||
4 | 4 | |
5 | 5 | class Str |
6 | 6 | { |
7 | - /** |
|
8 | - * @param string $subject |
|
9 | - * @param string $search |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - public static function afterLast($subject, $search) |
|
13 | - { |
|
14 | - return '' === $search |
|
15 | - ? $subject |
|
16 | - : array_reverse(explode($search, $subject))[0]; |
|
17 | - } |
|
7 | + /** |
|
8 | + * @param string $subject |
|
9 | + * @param string $search |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + public static function afterLast($subject, $search) |
|
13 | + { |
|
14 | + return '' === $search |
|
15 | + ? $subject |
|
16 | + : array_reverse(explode($search, $subject))[0]; |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string $string |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - public static function camelCase($string) |
|
24 | - { |
|
25 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
26 | - return str_replace(' ', '', $string); |
|
27 | - } |
|
19 | + /** |
|
20 | + * @param string $string |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + public static function camelCase($string) |
|
24 | + { |
|
25 | + $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
26 | + return str_replace(' ', '', $string); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param string $haystack |
|
31 | - * @param string $needle |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public static function contains($haystack, $needle) |
|
35 | - { |
|
36 | - return false !== strpos($haystack, $needle); |
|
37 | - } |
|
29 | + /** |
|
30 | + * @param string $haystack |
|
31 | + * @param string $needle |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public static function contains($haystack, $needle) |
|
35 | + { |
|
36 | + return false !== strpos($haystack, $needle); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $name |
|
41 | - * @param string $nameType first|first_initial|initials|last|last_initial |
|
42 | - * @param string $initialType period|period_space|space |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public static function convertName($name, $nameType = '', $initialType = '') |
|
46 | - { |
|
47 | - $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
48 | - $firstName = array_shift($names); |
|
49 | - $lastName = array_pop($names); |
|
50 | - $initialTypes = [ |
|
51 | - 'period' => '.', |
|
52 | - 'period_space' => '. ', |
|
53 | - 'space' => ' ', |
|
54 | - ]; |
|
55 | - $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
56 | - if ('initials' == $nameType) { |
|
57 | - return static::convertToInitials($name, $initialPunctuation); |
|
58 | - } |
|
59 | - $nameTypes = [ |
|
60 | - 'first' => $firstName, |
|
61 | - 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
62 | - 'last' => $lastName, |
|
63 | - 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
64 | - ]; |
|
65 | - return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
66 | - } |
|
39 | + /** |
|
40 | + * @param string $name |
|
41 | + * @param string $nameType first|first_initial|initials|last|last_initial |
|
42 | + * @param string $initialType period|period_space|space |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public static function convertName($name, $nameType = '', $initialType = '') |
|
46 | + { |
|
47 | + $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
48 | + $firstName = array_shift($names); |
|
49 | + $lastName = array_pop($names); |
|
50 | + $initialTypes = [ |
|
51 | + 'period' => '.', |
|
52 | + 'period_space' => '. ', |
|
53 | + 'space' => ' ', |
|
54 | + ]; |
|
55 | + $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
56 | + if ('initials' == $nameType) { |
|
57 | + return static::convertToInitials($name, $initialPunctuation); |
|
58 | + } |
|
59 | + $nameTypes = [ |
|
60 | + 'first' => $firstName, |
|
61 | + 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
62 | + 'last' => $lastName, |
|
63 | + 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
64 | + ]; |
|
65 | + return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param string $path |
|
70 | - * @param string $prefix |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public static function convertPathToId($path, $prefix = '') |
|
74 | - { |
|
75 | - return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
76 | - } |
|
68 | + /** |
|
69 | + * @param string $path |
|
70 | + * @param string $prefix |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public static function convertPathToId($path, $prefix = '') |
|
74 | + { |
|
75 | + return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $path |
|
80 | - * @param string $prefix |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public static function convertPathToName($path, $prefix = '') |
|
84 | - { |
|
85 | - $levels = explode('.', $path); |
|
86 | - return array_reduce($levels, function ($result, $value) { |
|
87 | - return $result .= '['.$value.']'; |
|
88 | - }, $prefix); |
|
89 | - } |
|
78 | + /** |
|
79 | + * @param string $path |
|
80 | + * @param string $prefix |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public static function convertPathToName($path, $prefix = '') |
|
84 | + { |
|
85 | + $levels = explode('.', $path); |
|
86 | + return array_reduce($levels, function ($result, $value) { |
|
87 | + return $result .= '['.$value.']'; |
|
88 | + }, $prefix); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string $name |
|
93 | - * @param string $initialPunctuation |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public static function convertToInitials($name, $initialPunctuation = '') |
|
97 | - { |
|
98 | - preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
99 | - return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
100 | - return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
101 | - }); |
|
102 | - } |
|
91 | + /** |
|
92 | + * @param string $name |
|
93 | + * @param string $initialPunctuation |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public static function convertToInitials($name, $initialPunctuation = '') |
|
97 | + { |
|
98 | + preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
99 | + return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
100 | + return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
101 | + }); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @param string $string |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public static function dashCase($string) |
|
109 | - { |
|
110 | - return str_replace('_', '-', static::snakeCase($string)); |
|
111 | - } |
|
104 | + /** |
|
105 | + * @param string $string |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public static function dashCase($string) |
|
109 | + { |
|
110 | + return str_replace('_', '-', static::snakeCase($string)); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param string $needle |
|
115 | - * @param string $haystack |
|
116 | - * @return bool |
|
117 | - */ |
|
118 | - public static function endsWith($needle, $haystack) |
|
119 | - { |
|
120 | - $length = strlen($needle); |
|
121 | - return 0 != $length |
|
122 | - ? substr($haystack, -$length) === $needle |
|
123 | - : true; |
|
124 | - } |
|
113 | + /** |
|
114 | + * @param string $needle |
|
115 | + * @param string $haystack |
|
116 | + * @return bool |
|
117 | + */ |
|
118 | + public static function endsWith($needle, $haystack) |
|
119 | + { |
|
120 | + $length = strlen($needle); |
|
121 | + return 0 != $length |
|
122 | + ? substr($haystack, -$length) === $needle |
|
123 | + : true; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @param string $prefix |
|
128 | - * @param string $string |
|
129 | - * @param string|null $trim |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public static function prefix($prefix, $string, $trim = null) |
|
133 | - { |
|
134 | - if (null === $trim) { |
|
135 | - $trim = $prefix; |
|
136 | - } |
|
137 | - return $prefix.trim(static::removePrefix($trim, $string)); |
|
138 | - } |
|
126 | + /** |
|
127 | + * @param string $prefix |
|
128 | + * @param string $string |
|
129 | + * @param string|null $trim |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public static function prefix($prefix, $string, $trim = null) |
|
133 | + { |
|
134 | + if (null === $trim) { |
|
135 | + $trim = $prefix; |
|
136 | + } |
|
137 | + return $prefix.trim(static::removePrefix($trim, $string)); |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @param string $prefix |
|
142 | - * @param string $string |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public static function removePrefix($prefix, $string) |
|
146 | - { |
|
147 | - return static::startsWith($prefix, $string) |
|
148 | - ? substr($string, strlen($prefix)) |
|
149 | - : $string; |
|
150 | - } |
|
140 | + /** |
|
141 | + * @param string $prefix |
|
142 | + * @param string $string |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public static function removePrefix($prefix, $string) |
|
146 | + { |
|
147 | + return static::startsWith($prefix, $string) |
|
148 | + ? substr($string, strlen($prefix)) |
|
149 | + : $string; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * @param string $string |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - public static function snakeCase($string) |
|
157 | - { |
|
158 | - if (!ctype_lower($string)) { |
|
159 | - $string = preg_replace('/\s+/u', '', $string); |
|
160 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
161 | - $string = function_exists('mb_strtolower') |
|
162 | - ? mb_strtolower($string, 'UTF-8') |
|
163 | - : strtolower($string); |
|
164 | - } |
|
165 | - return str_replace('-', '_', $string); |
|
166 | - } |
|
152 | + /** |
|
153 | + * @param string $string |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + public static function snakeCase($string) |
|
157 | + { |
|
158 | + if (!ctype_lower($string)) { |
|
159 | + $string = preg_replace('/\s+/u', '', $string); |
|
160 | + $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
161 | + $string = function_exists('mb_strtolower') |
|
162 | + ? mb_strtolower($string, 'UTF-8') |
|
163 | + : strtolower($string); |
|
164 | + } |
|
165 | + return str_replace('-', '_', $string); |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @param string $needle |
|
170 | - * @param string $haystack |
|
171 | - * @return bool |
|
172 | - */ |
|
173 | - public static function startsWith($needle, $haystack) |
|
174 | - { |
|
175 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
176 | - } |
|
168 | + /** |
|
169 | + * @param string $needle |
|
170 | + * @param string $haystack |
|
171 | + * @return bool |
|
172 | + */ |
|
173 | + public static function startsWith($needle, $haystack) |
|
174 | + { |
|
175 | + return substr($haystack, 0, strlen($needle)) === $needle; |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * @param string $string |
|
180 | - * @param int $length |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - public static function truncate($string, $length) |
|
184 | - { |
|
185 | - return strlen($string) > $length |
|
186 | - ? substr($string, 0, $length) |
|
187 | - : $string; |
|
188 | - } |
|
178 | + /** |
|
179 | + * @param string $string |
|
180 | + * @param int $length |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + public static function truncate($string, $length) |
|
184 | + { |
|
185 | + return strlen($string) > $length |
|
186 | + ? substr($string, 0, $length) |
|
187 | + : $string; |
|
188 | + } |
|
189 | 189 | } |
@@ -13,299 +13,299 @@ |
||
13 | 13 | |
14 | 14 | class ValidateReview |
15 | 15 | { |
16 | - const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
16 | + const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
17 | 17 | |
18 | - const RECAPTCHA_DISABLED = 0; |
|
19 | - const RECAPTCHA_EMPTY = 1; |
|
20 | - const RECAPTCHA_FAILED = 2; |
|
21 | - const RECAPTCHA_INVALID = 3; |
|
22 | - const RECAPTCHA_VALID = 4; |
|
18 | + const RECAPTCHA_DISABLED = 0; |
|
19 | + const RECAPTCHA_EMPTY = 1; |
|
20 | + const RECAPTCHA_FAILED = 2; |
|
21 | + const RECAPTCHA_INVALID = 3; |
|
22 | + const RECAPTCHA_VALID = 4; |
|
23 | 23 | |
24 | - const VALIDATION_RULES = [ |
|
25 | - 'content' => 'required', |
|
26 | - 'email' => 'required|email', |
|
27 | - 'name' => 'required', |
|
28 | - 'rating' => 'required|number|between:1,5', |
|
29 | - 'terms' => 'accepted', |
|
30 | - 'title' => 'required', |
|
31 | - ]; |
|
24 | + const VALIDATION_RULES = [ |
|
25 | + 'content' => 'required', |
|
26 | + 'email' => 'required|email', |
|
27 | + 'name' => 'required', |
|
28 | + 'rating' => 'required|number|between:1,5', |
|
29 | + 'terms' => 'accepted', |
|
30 | + 'title' => 'required', |
|
31 | + ]; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var string|void |
|
35 | - */ |
|
36 | - public $error; |
|
33 | + /** |
|
34 | + * @var string|void |
|
35 | + */ |
|
36 | + public $error; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $form_id; |
|
38 | + /** |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $form_id; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - public $recaptchaIsUnset = false; |
|
43 | + /** |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + public $recaptchaIsUnset = false; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - public $request; |
|
48 | + /** |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + public $request; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - protected $options; |
|
53 | + /** |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + protected $options; |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return static |
|
60 | - */ |
|
61 | - public function validate(array $request) |
|
62 | - { |
|
63 | - $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation |
|
64 | - $this->form_id = $request['form_id']; |
|
65 | - $this->options = glsr(OptionManager::class)->all(); |
|
66 | - $this->request = $this->validateRequest($request); |
|
67 | - $this->validateCustom(); |
|
68 | - $this->validatePermission(); |
|
69 | - $this->validateHoneyPot(); |
|
70 | - $this->validateReviewLimits(); |
|
71 | - $this->validateBlacklist(); |
|
72 | - $this->validateAkismet(); |
|
73 | - $this->validateRecaptcha(); |
|
74 | - if (!empty($this->error)) { |
|
75 | - $this->setSessionValues('message', $this->error); |
|
76 | - } |
|
77 | - return $this; |
|
78 | - } |
|
58 | + /** |
|
59 | + * @return static |
|
60 | + */ |
|
61 | + public function validate(array $request) |
|
62 | + { |
|
63 | + $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation |
|
64 | + $this->form_id = $request['form_id']; |
|
65 | + $this->options = glsr(OptionManager::class)->all(); |
|
66 | + $this->request = $this->validateRequest($request); |
|
67 | + $this->validateCustom(); |
|
68 | + $this->validatePermission(); |
|
69 | + $this->validateHoneyPot(); |
|
70 | + $this->validateReviewLimits(); |
|
71 | + $this->validateBlacklist(); |
|
72 | + $this->validateAkismet(); |
|
73 | + $this->validateRecaptcha(); |
|
74 | + if (!empty($this->error)) { |
|
75 | + $this->setSessionValues('message', $this->error); |
|
76 | + } |
|
77 | + return $this; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param string $path |
|
82 | - * @param mixed $fallback |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - protected function getOption($path, $fallback = '') |
|
86 | - { |
|
87 | - return Arr::get($this->options, $path, $fallback); |
|
88 | - } |
|
80 | + /** |
|
81 | + * @param string $path |
|
82 | + * @param mixed $fallback |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + protected function getOption($path, $fallback = '') |
|
86 | + { |
|
87 | + return Arr::get($this->options, $path, $fallback); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @return int |
|
92 | - */ |
|
93 | - protected function getRecaptchaStatus() |
|
94 | - { |
|
95 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
96 | - return static::RECAPTCHA_DISABLED; |
|
97 | - } |
|
98 | - if (empty($this->request['_recaptcha-token'])) { |
|
99 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
100 | - ? static::RECAPTCHA_EMPTY |
|
101 | - : static::RECAPTCHA_FAILED; |
|
102 | - } |
|
103 | - return $this->getRecaptchaTokenStatus(); |
|
104 | - } |
|
90 | + /** |
|
91 | + * @return int |
|
92 | + */ |
|
93 | + protected function getRecaptchaStatus() |
|
94 | + { |
|
95 | + if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
96 | + return static::RECAPTCHA_DISABLED; |
|
97 | + } |
|
98 | + if (empty($this->request['_recaptcha-token'])) { |
|
99 | + return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
100 | + ? static::RECAPTCHA_EMPTY |
|
101 | + : static::RECAPTCHA_FAILED; |
|
102 | + } |
|
103 | + return $this->getRecaptchaTokenStatus(); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @return int |
|
108 | - */ |
|
109 | - protected function getRecaptchaTokenStatus() |
|
110 | - { |
|
111 | - $endpoint = add_query_arg([ |
|
112 | - 'remoteip' => Helper::getIpAddress(), |
|
113 | - 'response' => $this->request['_recaptcha-token'], |
|
114 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
115 | - ], static::RECAPTCHA_ENDPOINT); |
|
116 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
117 | - glsr_log()->error($response->get_error_message()); |
|
118 | - return static::RECAPTCHA_FAILED; |
|
119 | - } |
|
120 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
121 | - if (!empty($response->success)) { |
|
122 | - return boolval($response->success) |
|
123 | - ? static::RECAPTCHA_VALID |
|
124 | - : static::RECAPTCHA_INVALID; |
|
125 | - } |
|
126 | - foreach ($response->{'error-codes'} as $error) { |
|
127 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
128 | - } |
|
129 | - return static::RECAPTCHA_INVALID; |
|
130 | - } |
|
106 | + /** |
|
107 | + * @return int |
|
108 | + */ |
|
109 | + protected function getRecaptchaTokenStatus() |
|
110 | + { |
|
111 | + $endpoint = add_query_arg([ |
|
112 | + 'remoteip' => Helper::getIpAddress(), |
|
113 | + 'response' => $this->request['_recaptcha-token'], |
|
114 | + 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
115 | + ], static::RECAPTCHA_ENDPOINT); |
|
116 | + if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
117 | + glsr_log()->error($response->get_error_message()); |
|
118 | + return static::RECAPTCHA_FAILED; |
|
119 | + } |
|
120 | + $response = json_decode(wp_remote_retrieve_body($response)); |
|
121 | + if (!empty($response->success)) { |
|
122 | + return boolval($response->success) |
|
123 | + ? static::RECAPTCHA_VALID |
|
124 | + : static::RECAPTCHA_INVALID; |
|
125 | + } |
|
126 | + foreach ($response->{'error-codes'} as $error) { |
|
127 | + glsr_log()->error('reCAPTCHA error: '.$error); |
|
128 | + } |
|
129 | + return static::RECAPTCHA_INVALID; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - protected function getValidationRules(array $request) |
|
136 | - { |
|
137 | - $rules = array_intersect_key( |
|
138 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
139 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
140 | - ); |
|
141 | - $excluded = explode(',', Arr::get($request, 'excluded')); |
|
142 | - return array_diff_key($rules, array_flip($excluded)); |
|
143 | - } |
|
132 | + /** |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + protected function getValidationRules(array $request) |
|
136 | + { |
|
137 | + $rules = array_intersect_key( |
|
138 | + apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
139 | + array_flip($this->getOption('settings.submissions.required', [])) |
|
140 | + ); |
|
141 | + $excluded = explode(',', Arr::get($request, 'excluded')); |
|
142 | + return array_diff_key($rules, array_flip($excluded)); |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @return bool |
|
147 | - */ |
|
148 | - protected function isRequestValid(array $request) |
|
149 | - { |
|
150 | - $rules = $this->getValidationRules($request); |
|
151 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
152 | - if (empty($errors)) { |
|
153 | - return true; |
|
154 | - } |
|
155 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
156 | - $this->setSessionValues('errors', $errors); |
|
157 | - $this->setSessionValues('values', $request); |
|
158 | - return false; |
|
159 | - } |
|
145 | + /** |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | + protected function isRequestValid(array $request) |
|
149 | + { |
|
150 | + $rules = $this->getValidationRules($request); |
|
151 | + $errors = glsr(Validator::class)->validate($request, $rules); |
|
152 | + if (empty($errors)) { |
|
153 | + return true; |
|
154 | + } |
|
155 | + $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
156 | + $this->setSessionValues('errors', $errors); |
|
157 | + $this->setSessionValues('values', $request); |
|
158 | + return false; |
|
159 | + } |
|
160 | 160 | |
161 | - protected function setError($message, $loggedMessage = '') |
|
162 | - { |
|
163 | - $this->setSessionValues('errors', [], $loggedMessage); |
|
164 | - $this->error = $message; |
|
165 | - } |
|
161 | + protected function setError($message, $loggedMessage = '') |
|
162 | + { |
|
163 | + $this->setSessionValues('errors', [], $loggedMessage); |
|
164 | + $this->error = $message; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @param string $type |
|
169 | - * @param mixed $value |
|
170 | - * @param string $loggedMessage |
|
171 | - * @return void |
|
172 | - */ |
|
173 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
174 | - { |
|
175 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
176 | - if (!empty($loggedMessage)) { |
|
177 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
178 | - } |
|
179 | - } |
|
167 | + /** |
|
168 | + * @param string $type |
|
169 | + * @param mixed $value |
|
170 | + * @param string $loggedMessage |
|
171 | + * @return void |
|
172 | + */ |
|
173 | + protected function setSessionValues($type, $value, $loggedMessage = '') |
|
174 | + { |
|
175 | + glsr()->sessionSet($this->form_id.$type, $value); |
|
176 | + if (!empty($loggedMessage)) { |
|
177 | + glsr_log()->warning($loggedMessage)->debug($this->request); |
|
178 | + } |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * @return void |
|
183 | - */ |
|
184 | - protected function validateAkismet() |
|
185 | - { |
|
186 | - if (!empty($this->error)) { |
|
187 | - return; |
|
188 | - } |
|
189 | - if (glsr(Akismet::class)->isSpam($this->request)) { |
|
190 | - $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
191 | - 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
|
192 | - ); |
|
193 | - } |
|
194 | - } |
|
181 | + /** |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + protected function validateAkismet() |
|
185 | + { |
|
186 | + if (!empty($this->error)) { |
|
187 | + return; |
|
188 | + } |
|
189 | + if (glsr(Akismet::class)->isSpam($this->request)) { |
|
190 | + $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
191 | + 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
|
192 | + ); |
|
193 | + } |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * @return void |
|
198 | - */ |
|
199 | - protected function validateBlacklist() |
|
200 | - { |
|
201 | - if (!empty($this->error)) { |
|
202 | - return; |
|
203 | - } |
|
204 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
205 | - return; |
|
206 | - } |
|
207 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
208 | - if ('reject' != $blacklistAction) { |
|
209 | - $this->request['blacklisted'] = true; |
|
210 | - return; |
|
211 | - } |
|
212 | - $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
213 | - 'Blacklisted submission detected:' |
|
214 | - ); |
|
215 | - } |
|
196 | + /** |
|
197 | + * @return void |
|
198 | + */ |
|
199 | + protected function validateBlacklist() |
|
200 | + { |
|
201 | + if (!empty($this->error)) { |
|
202 | + return; |
|
203 | + } |
|
204 | + if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
205 | + return; |
|
206 | + } |
|
207 | + $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
208 | + if ('reject' != $blacklistAction) { |
|
209 | + $this->request['blacklisted'] = true; |
|
210 | + return; |
|
211 | + } |
|
212 | + $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
213 | + 'Blacklisted submission detected:' |
|
214 | + ); |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @return void |
|
219 | - */ |
|
220 | - protected function validateCustom() |
|
221 | - { |
|
222 | - if (!empty($this->error)) { |
|
223 | - return; |
|
224 | - } |
|
225 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
226 | - if (true === $validated) { |
|
227 | - return; |
|
228 | - } |
|
229 | - $errorMessage = is_string($validated) |
|
230 | - ? $validated |
|
231 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
232 | - $this->setError($errorMessage); |
|
233 | - $this->setSessionValues('values', $this->request); |
|
234 | - } |
|
217 | + /** |
|
218 | + * @return void |
|
219 | + */ |
|
220 | + protected function validateCustom() |
|
221 | + { |
|
222 | + if (!empty($this->error)) { |
|
223 | + return; |
|
224 | + } |
|
225 | + $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
226 | + if (true === $validated) { |
|
227 | + return; |
|
228 | + } |
|
229 | + $errorMessage = is_string($validated) |
|
230 | + ? $validated |
|
231 | + : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
232 | + $this->setError($errorMessage); |
|
233 | + $this->setSessionValues('values', $this->request); |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * @return void |
|
238 | - */ |
|
239 | - protected function validateHoneyPot() |
|
240 | - { |
|
241 | - if (!empty($this->error)) { |
|
242 | - return; |
|
243 | - } |
|
244 | - if (!empty($this->request['gotcha'])) { |
|
245 | - $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
246 | - 'The Honeypot caught a bad submission:' |
|
247 | - ); |
|
248 | - } |
|
249 | - } |
|
236 | + /** |
|
237 | + * @return void |
|
238 | + */ |
|
239 | + protected function validateHoneyPot() |
|
240 | + { |
|
241 | + if (!empty($this->error)) { |
|
242 | + return; |
|
243 | + } |
|
244 | + if (!empty($this->request['gotcha'])) { |
|
245 | + $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
246 | + 'The Honeypot caught a bad submission:' |
|
247 | + ); |
|
248 | + } |
|
249 | + } |
|
250 | 250 | |
251 | - /** |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - protected function validatePermission() |
|
255 | - { |
|
256 | - if (!empty($this->error)) { |
|
257 | - return; |
|
258 | - } |
|
259 | - if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
260 | - $this->setError(__('You must be logged in to submit a review.', 'site-reviews')); |
|
261 | - } |
|
262 | - } |
|
251 | + /** |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + protected function validatePermission() |
|
255 | + { |
|
256 | + if (!empty($this->error)) { |
|
257 | + return; |
|
258 | + } |
|
259 | + if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
260 | + $this->setError(__('You must be logged in to submit a review.', 'site-reviews')); |
|
261 | + } |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
265 | - * @return void |
|
266 | - */ |
|
267 | - protected function validateReviewLimits() |
|
268 | - { |
|
269 | - if (!empty($this->error)) { |
|
270 | - return; |
|
271 | - } |
|
272 | - if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
273 | - $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
274 | - } |
|
275 | - } |
|
264 | + /** |
|
265 | + * @return void |
|
266 | + */ |
|
267 | + protected function validateReviewLimits() |
|
268 | + { |
|
269 | + if (!empty($this->error)) { |
|
270 | + return; |
|
271 | + } |
|
272 | + if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
273 | + $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * @return void |
|
279 | - */ |
|
280 | - protected function validateRecaptcha() |
|
281 | - { |
|
282 | - if (!empty($this->error)) { |
|
283 | - return; |
|
284 | - } |
|
285 | - $status = $this->getRecaptchaStatus(); |
|
286 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
287 | - return; |
|
288 | - } |
|
289 | - if (static::RECAPTCHA_EMPTY === $status) { |
|
290 | - $this->setSessionValues('recaptcha', 'unset'); |
|
291 | - $this->recaptchaIsUnset = true; |
|
292 | - return; |
|
293 | - } |
|
294 | - $this->setSessionValues('recaptcha', 'reset'); |
|
295 | - $errors = [ |
|
296 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
297 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
298 | - ]; |
|
299 | - $this->setError($errors[$status]); |
|
300 | - } |
|
277 | + /** |
|
278 | + * @return void |
|
279 | + */ |
|
280 | + protected function validateRecaptcha() |
|
281 | + { |
|
282 | + if (!empty($this->error)) { |
|
283 | + return; |
|
284 | + } |
|
285 | + $status = $this->getRecaptchaStatus(); |
|
286 | + if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
287 | + return; |
|
288 | + } |
|
289 | + if (static::RECAPTCHA_EMPTY === $status) { |
|
290 | + $this->setSessionValues('recaptcha', 'unset'); |
|
291 | + $this->recaptchaIsUnset = true; |
|
292 | + return; |
|
293 | + } |
|
294 | + $this->setSessionValues('recaptcha', 'reset'); |
|
295 | + $errors = [ |
|
296 | + static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
297 | + static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
298 | + ]; |
|
299 | + $this->setError($errors[$status]); |
|
300 | + } |
|
301 | 301 | |
302 | - /** |
|
303 | - * @return array |
|
304 | - */ |
|
305 | - protected function validateRequest(array $request) |
|
306 | - { |
|
307 | - return $this->isRequestValid($request) |
|
308 | - ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request) |
|
309 | - : $request; |
|
310 | - } |
|
302 | + /** |
|
303 | + * @return array |
|
304 | + */ |
|
305 | + protected function validateRequest(array $request) |
|
306 | + { |
|
307 | + return $this->isRequestValid($request) |
|
308 | + ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request) |
|
309 | + : $request; |
|
310 | + } |
|
311 | 311 | } |
@@ -12,335 +12,335 @@ |
||
12 | 12 | |
13 | 13 | class Schema |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $args; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $args; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $keyValues = []; |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $keyValues = []; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $ratingCounts; |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $ratingCounts; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - public function build(array $args = []) |
|
34 | - { |
|
35 | - $this->args = $args; |
|
36 | - $schema = $this->buildSummary($args); |
|
37 | - if (!empty($schema)) { |
|
38 | - $reviews = $this->buildReviews(); |
|
39 | - foreach ($reviews as &$review) { |
|
40 | - unset($review['@context']); |
|
41 | - unset($review['itemReviewed']); |
|
42 | - } |
|
43 | - } |
|
44 | - if (!empty($reviews)) { |
|
45 | - $schema['review'] = $reviews; |
|
46 | - } |
|
47 | - return $schema; |
|
48 | - } |
|
30 | + /** |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + public function build(array $args = []) |
|
34 | + { |
|
35 | + $this->args = $args; |
|
36 | + $schema = $this->buildSummary($args); |
|
37 | + if (!empty($schema)) { |
|
38 | + $reviews = $this->buildReviews(); |
|
39 | + foreach ($reviews as &$review) { |
|
40 | + unset($review['@context']); |
|
41 | + unset($review['itemReviewed']); |
|
42 | + } |
|
43 | + } |
|
44 | + if (!empty($reviews)) { |
|
45 | + $schema['review'] = $reviews; |
|
46 | + } |
|
47 | + return $schema; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param array|null $args |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function buildSummary($args = null) |
|
55 | - { |
|
56 | - if (is_array($args)) { |
|
57 | - $this->args = $args; |
|
58 | - } |
|
59 | - $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
60 | - if ($count = array_sum($this->getRatingCounts())) { |
|
61 | - $schema = method_exists($this, $buildSummary) |
|
62 | - ? $this->$buildSummary() |
|
63 | - : $this->buildSummaryForCustom(); |
|
64 | - $schema->aggregateRating( |
|
65 | - $this->getSchemaType('AggregateRating') |
|
66 | - ->ratingValue($this->getRatingValue()) |
|
67 | - ->reviewCount($count) |
|
68 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
69 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
70 | - ); |
|
71 | - $schema = $schema->toArray(); |
|
72 | - return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
73 | - } |
|
74 | - return []; |
|
75 | - } |
|
50 | + /** |
|
51 | + * @param array|null $args |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function buildSummary($args = null) |
|
55 | + { |
|
56 | + if (is_array($args)) { |
|
57 | + $this->args = $args; |
|
58 | + } |
|
59 | + $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
60 | + if ($count = array_sum($this->getRatingCounts())) { |
|
61 | + $schema = method_exists($this, $buildSummary) |
|
62 | + ? $this->$buildSummary() |
|
63 | + : $this->buildSummaryForCustom(); |
|
64 | + $schema->aggregateRating( |
|
65 | + $this->getSchemaType('AggregateRating') |
|
66 | + ->ratingValue($this->getRatingValue()) |
|
67 | + ->reviewCount($count) |
|
68 | + ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
69 | + ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
70 | + ); |
|
71 | + $schema = $schema->toArray(); |
|
72 | + return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
73 | + } |
|
74 | + return []; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - public function render() |
|
81 | - { |
|
82 | - if (empty(glsr()->schemas)) { |
|
83 | - return; |
|
84 | - } |
|
85 | - printf('<script type="application/ld+json">%s</script>', json_encode( |
|
86 | - apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
87 | - JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
|
88 | - )); |
|
89 | - } |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + public function render() |
|
81 | + { |
|
82 | + if (empty(glsr()->schemas)) { |
|
83 | + return; |
|
84 | + } |
|
85 | + printf('<script type="application/ld+json">%s</script>', json_encode( |
|
86 | + apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
87 | + JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
|
88 | + )); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function store(array $schema) |
|
95 | - { |
|
96 | - if (empty($schema)) { |
|
97 | - return; |
|
98 | - } |
|
99 | - $schemas = glsr()->schemas; |
|
100 | - $schemas[] = $schema; |
|
101 | - glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
102 | - } |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function store(array $schema) |
|
95 | + { |
|
96 | + if (empty($schema)) { |
|
97 | + return; |
|
98 | + } |
|
99 | + $schemas = glsr()->schemas; |
|
100 | + $schemas[] = $schema; |
|
101 | + glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @param Review $review |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - protected function buildReview($review) |
|
109 | - { |
|
110 | - $schema = $this->getSchemaType('Review') |
|
111 | - ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
112 | - $schema->name($review->title); |
|
113 | - }) |
|
114 | - ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
115 | - $schema->reviewBody($review->content); |
|
116 | - }) |
|
117 | - ->datePublished((new DateTime($review->date))) |
|
118 | - ->author($this->getSchemaType('Person')->name($review->author)) |
|
119 | - ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
120 | - if (!empty($review->rating)) { |
|
121 | - $schema->reviewRating( |
|
122 | - $this->getSchemaType('Rating') |
|
123 | - ->ratingValue($review->rating) |
|
124 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
125 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
126 | - ); |
|
127 | - } |
|
128 | - return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
129 | - } |
|
104 | + /** |
|
105 | + * @param Review $review |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + protected function buildReview($review) |
|
109 | + { |
|
110 | + $schema = $this->getSchemaType('Review') |
|
111 | + ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
112 | + $schema->name($review->title); |
|
113 | + }) |
|
114 | + ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
115 | + $schema->reviewBody($review->content); |
|
116 | + }) |
|
117 | + ->datePublished((new DateTime($review->date))) |
|
118 | + ->author($this->getSchemaType('Person')->name($review->author)) |
|
119 | + ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
120 | + if (!empty($review->rating)) { |
|
121 | + $schema->reviewRating( |
|
122 | + $this->getSchemaType('Rating') |
|
123 | + ->ratingValue($review->rating) |
|
124 | + ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
125 | + ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
126 | + ); |
|
127 | + } |
|
128 | + return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @return array |
|
133 | - */ |
|
134 | - protected function buildReviews() |
|
135 | - { |
|
136 | - $reviews = []; |
|
137 | - foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
138 | - // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
|
139 | - // @see https://developers.google.com/search/docs/data-types/review |
|
140 | - if ('local' === $review->review_type) { |
|
141 | - $reviews[] = $this->buildReview($review); |
|
142 | - } |
|
143 | - } |
|
144 | - return $reviews; |
|
145 | - } |
|
131 | + /** |
|
132 | + * @return array |
|
133 | + */ |
|
134 | + protected function buildReviews() |
|
135 | + { |
|
136 | + $reviews = []; |
|
137 | + foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
138 | + // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
|
139 | + // @see https://developers.google.com/search/docs/data-types/review |
|
140 | + if ('local' === $review->review_type) { |
|
141 | + $reviews[] = $this->buildReview($review); |
|
142 | + } |
|
143 | + } |
|
144 | + return $reviews; |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * @param mixed $schema |
|
149 | - * @return mixed |
|
150 | - */ |
|
151 | - protected function buildSchemaValues($schema, array $values = []) |
|
152 | - { |
|
153 | - foreach ($values as $value) { |
|
154 | - $option = $this->getSchemaOptionValue($value); |
|
155 | - if (empty($option)) { |
|
156 | - continue; |
|
157 | - } |
|
158 | - $schema->$value($option); |
|
159 | - } |
|
160 | - return $schema; |
|
161 | - } |
|
147 | + /** |
|
148 | + * @param mixed $schema |
|
149 | + * @return mixed |
|
150 | + */ |
|
151 | + protected function buildSchemaValues($schema, array $values = []) |
|
152 | + { |
|
153 | + foreach ($values as $value) { |
|
154 | + $option = $this->getSchemaOptionValue($value); |
|
155 | + if (empty($option)) { |
|
156 | + continue; |
|
157 | + } |
|
158 | + $schema->$value($option); |
|
159 | + } |
|
160 | + return $schema; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @return mixed |
|
165 | - */ |
|
166 | - protected function buildSummaryForCustom() |
|
167 | - { |
|
168 | - return $this->buildSchemaValues($this->getSchemaType(), [ |
|
169 | - 'description', 'image', 'name', 'url', |
|
170 | - ]); |
|
171 | - } |
|
163 | + /** |
|
164 | + * @return mixed |
|
165 | + */ |
|
166 | + protected function buildSummaryForCustom() |
|
167 | + { |
|
168 | + return $this->buildSchemaValues($this->getSchemaType(), [ |
|
169 | + 'description', 'image', 'name', 'url', |
|
170 | + ]); |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * @return mixed |
|
175 | - */ |
|
176 | - protected function buildSummaryForLocalBusiness() |
|
177 | - { |
|
178 | - return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
179 | - 'address', 'priceRange', 'telephone', |
|
180 | - ]); |
|
181 | - } |
|
173 | + /** |
|
174 | + * @return mixed |
|
175 | + */ |
|
176 | + protected function buildSummaryForLocalBusiness() |
|
177 | + { |
|
178 | + return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
179 | + 'address', 'priceRange', 'telephone', |
|
180 | + ]); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @return mixed |
|
185 | - */ |
|
186 | - protected function buildSummaryForProduct() |
|
187 | - { |
|
188 | - $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
189 | - $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
190 | - 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
|
191 | - ]); |
|
192 | - return $this->buildSummaryForCustom() |
|
193 | - ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
194 | - $schema->offers($offers); |
|
195 | - }) |
|
196 | - ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
197 | - } |
|
183 | + /** |
|
184 | + * @return mixed |
|
185 | + */ |
|
186 | + protected function buildSummaryForProduct() |
|
187 | + { |
|
188 | + $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
189 | + $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
190 | + 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
|
191 | + ]); |
|
192 | + return $this->buildSummaryForCustom() |
|
193 | + ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
194 | + $schema->offers($offers); |
|
195 | + }) |
|
196 | + ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * @return array |
|
201 | - */ |
|
202 | - protected function getRatingCounts() |
|
203 | - { |
|
204 | - if (!isset($this->ratingCounts)) { |
|
205 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
206 | - } |
|
207 | - return $this->ratingCounts; |
|
208 | - } |
|
199 | + /** |
|
200 | + * @return array |
|
201 | + */ |
|
202 | + protected function getRatingCounts() |
|
203 | + { |
|
204 | + if (!isset($this->ratingCounts)) { |
|
205 | + $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
206 | + } |
|
207 | + return $this->ratingCounts; |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * @return int|float |
|
212 | - */ |
|
213 | - protected function getRatingValue() |
|
214 | - { |
|
215 | - return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
216 | - } |
|
210 | + /** |
|
211 | + * @return int|float |
|
212 | + */ |
|
213 | + protected function getRatingValue() |
|
214 | + { |
|
215 | + return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * @param string $option |
|
220 | - * @param string $fallback |
|
221 | - * @return string |
|
222 | - */ |
|
223 | - protected function getSchemaOption($option, $fallback) |
|
224 | - { |
|
225 | - $option = strtolower($option); |
|
226 | - if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
227 | - return $schemaOption; |
|
228 | - } |
|
229 | - $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
230 | - if (is_array($setting)) { |
|
231 | - return $this->getSchemaOptionDefault($setting, $fallback); |
|
232 | - } |
|
233 | - return !empty($setting) |
|
234 | - ? $setting |
|
235 | - : $fallback; |
|
236 | - } |
|
218 | + /** |
|
219 | + * @param string $option |
|
220 | + * @param string $fallback |
|
221 | + * @return string |
|
222 | + */ |
|
223 | + protected function getSchemaOption($option, $fallback) |
|
224 | + { |
|
225 | + $option = strtolower($option); |
|
226 | + if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
227 | + return $schemaOption; |
|
228 | + } |
|
229 | + $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
230 | + if (is_array($setting)) { |
|
231 | + return $this->getSchemaOptionDefault($setting, $fallback); |
|
232 | + } |
|
233 | + return !empty($setting) |
|
234 | + ? $setting |
|
235 | + : $fallback; |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
239 | - * @param string $fallback |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - protected function getSchemaOptionDefault(array $setting, $fallback) |
|
243 | - { |
|
244 | - $setting = wp_parse_args($setting, [ |
|
245 | - 'custom' => '', |
|
246 | - 'default' => $fallback, |
|
247 | - ]); |
|
248 | - return 'custom' != $setting['default'] |
|
249 | - ? $setting['default'] |
|
250 | - : $setting['custom']; |
|
251 | - } |
|
238 | + /** |
|
239 | + * @param string $fallback |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + protected function getSchemaOptionDefault(array $setting, $fallback) |
|
243 | + { |
|
244 | + $setting = wp_parse_args($setting, [ |
|
245 | + 'custom' => '', |
|
246 | + 'default' => $fallback, |
|
247 | + ]); |
|
248 | + return 'custom' != $setting['default'] |
|
249 | + ? $setting['default'] |
|
250 | + : $setting['custom']; |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * @param string $option |
|
255 | - * @param string $fallback |
|
256 | - * @return void|string |
|
257 | - */ |
|
258 | - protected function getSchemaOptionValue($option, $fallback = 'post') |
|
259 | - { |
|
260 | - if (array_key_exists($option, $this->keyValues)) { |
|
261 | - return $this->keyValues[$option]; |
|
262 | - } |
|
263 | - $value = $this->getSchemaOption($option, $fallback); |
|
264 | - if ($value != $fallback) { |
|
265 | - return $this->setAndGetKeyValue($option, $value); |
|
266 | - } |
|
267 | - if (!is_single() && !is_page()) { |
|
268 | - return; |
|
269 | - } |
|
270 | - $method = Helper::buildMethodName($option, 'getThing'); |
|
271 | - if (method_exists($this, $method)) { |
|
272 | - return $this->setAndGetKeyValue($option, $this->$method()); |
|
273 | - } |
|
274 | - } |
|
253 | + /** |
|
254 | + * @param string $option |
|
255 | + * @param string $fallback |
|
256 | + * @return void|string |
|
257 | + */ |
|
258 | + protected function getSchemaOptionValue($option, $fallback = 'post') |
|
259 | + { |
|
260 | + if (array_key_exists($option, $this->keyValues)) { |
|
261 | + return $this->keyValues[$option]; |
|
262 | + } |
|
263 | + $value = $this->getSchemaOption($option, $fallback); |
|
264 | + if ($value != $fallback) { |
|
265 | + return $this->setAndGetKeyValue($option, $value); |
|
266 | + } |
|
267 | + if (!is_single() && !is_page()) { |
|
268 | + return; |
|
269 | + } |
|
270 | + $method = Helper::buildMethodName($option, 'getThing'); |
|
271 | + if (method_exists($this, $method)) { |
|
272 | + return $this->setAndGetKeyValue($option, $this->$method()); |
|
273 | + } |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * @param string|null $type |
|
278 | - * @return mixed |
|
279 | - */ |
|
280 | - protected function getSchemaType($type = null) |
|
281 | - { |
|
282 | - if (!is_string($type)) { |
|
283 | - $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
284 | - } |
|
285 | - $className = Helper::buildClassName($type, 'Modules\Schema'); |
|
286 | - return class_exists($className) |
|
287 | - ? new $className() |
|
288 | - : new UnknownType($type); |
|
289 | - } |
|
276 | + /** |
|
277 | + * @param string|null $type |
|
278 | + * @return mixed |
|
279 | + */ |
|
280 | + protected function getSchemaType($type = null) |
|
281 | + { |
|
282 | + if (!is_string($type)) { |
|
283 | + $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
284 | + } |
|
285 | + $className = Helper::buildClassName($type, 'Modules\Schema'); |
|
286 | + return class_exists($className) |
|
287 | + ? new $className() |
|
288 | + : new UnknownType($type); |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * @return string |
|
293 | - */ |
|
294 | - protected function getThingDescription() |
|
295 | - { |
|
296 | - $post = get_post(); |
|
297 | - $text = Arr::get($post, 'post_excerpt'); |
|
298 | - if (empty($text)) { |
|
299 | - $text = Arr::get($post, 'post_content'); |
|
300 | - } |
|
301 | - if (function_exists('excerpt_remove_blocks')) { |
|
302 | - $text = excerpt_remove_blocks($text); |
|
303 | - } |
|
304 | - $text = strip_shortcodes($text); |
|
305 | - $text = wpautop($text); |
|
306 | - $text = wptexturize($text); |
|
307 | - $text = wp_strip_all_tags($text); |
|
308 | - $text = str_replace(']]>', ']]>', $text); |
|
309 | - return wp_trim_words($text, apply_filters('excerpt_length', 55)); |
|
310 | - } |
|
291 | + /** |
|
292 | + * @return string |
|
293 | + */ |
|
294 | + protected function getThingDescription() |
|
295 | + { |
|
296 | + $post = get_post(); |
|
297 | + $text = Arr::get($post, 'post_excerpt'); |
|
298 | + if (empty($text)) { |
|
299 | + $text = Arr::get($post, 'post_content'); |
|
300 | + } |
|
301 | + if (function_exists('excerpt_remove_blocks')) { |
|
302 | + $text = excerpt_remove_blocks($text); |
|
303 | + } |
|
304 | + $text = strip_shortcodes($text); |
|
305 | + $text = wpautop($text); |
|
306 | + $text = wptexturize($text); |
|
307 | + $text = wp_strip_all_tags($text); |
|
308 | + $text = str_replace(']]>', ']]>', $text); |
|
309 | + return wp_trim_words($text, apply_filters('excerpt_length', 55)); |
|
310 | + } |
|
311 | 311 | |
312 | - /** |
|
313 | - * @return string |
|
314 | - */ |
|
315 | - protected function getThingImage() |
|
316 | - { |
|
317 | - return (string) get_the_post_thumbnail_url(null, 'large'); |
|
318 | - } |
|
312 | + /** |
|
313 | + * @return string |
|
314 | + */ |
|
315 | + protected function getThingImage() |
|
316 | + { |
|
317 | + return (string) get_the_post_thumbnail_url(null, 'large'); |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * @return string |
|
322 | - */ |
|
323 | - protected function getThingName() |
|
324 | - { |
|
325 | - return get_the_title(); |
|
326 | - } |
|
320 | + /** |
|
321 | + * @return string |
|
322 | + */ |
|
323 | + protected function getThingName() |
|
324 | + { |
|
325 | + return get_the_title(); |
|
326 | + } |
|
327 | 327 | |
328 | - /** |
|
329 | - * @return string |
|
330 | - */ |
|
331 | - protected function getThingUrl() |
|
332 | - { |
|
333 | - return (string) get_the_permalink(); |
|
334 | - } |
|
328 | + /** |
|
329 | + * @return string |
|
330 | + */ |
|
331 | + protected function getThingUrl() |
|
332 | + { |
|
333 | + return (string) get_the_permalink(); |
|
334 | + } |
|
335 | 335 | |
336 | - /** |
|
337 | - * @param string $option |
|
338 | - * @param string $value |
|
339 | - * @return string |
|
340 | - */ |
|
341 | - protected function setAndGetKeyValue($option, $value) |
|
342 | - { |
|
343 | - $this->keyValues[$option] = $value; |
|
344 | - return $value; |
|
345 | - } |
|
336 | + /** |
|
337 | + * @param string $option |
|
338 | + * @param string $value |
|
339 | + * @return string |
|
340 | + */ |
|
341 | + protected function setAndGetKeyValue($option, $value) |
|
342 | + { |
|
343 | + $this->keyValues[$option] = $value; |
|
344 | + return $value; |
|
345 | + } |
|
346 | 346 | } |