@@ -7,48 +7,48 @@ |
||
7 | 7 | |
8 | 8 | class ReviewHtml extends ArrayObject |
9 | 9 | { |
10 | - /** |
|
11 | - * @var Review |
|
12 | - */ |
|
13 | - public $review; |
|
10 | + /** |
|
11 | + * @var Review |
|
12 | + */ |
|
13 | + public $review; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $values; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $values; |
|
19 | 19 | |
20 | - public function __construct(Review $review, array $values = []) |
|
21 | - { |
|
22 | - $this->review = $review; |
|
23 | - $this->values = $values; |
|
24 | - parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
25 | - } |
|
20 | + public function __construct(Review $review, array $values = []) |
|
21 | + { |
|
22 | + $this->review = $review; |
|
23 | + $this->values = $values; |
|
24 | + parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @return string|void |
|
29 | - */ |
|
30 | - public function __toString() |
|
31 | - { |
|
32 | - if (empty($this->values)) { |
|
33 | - return; |
|
34 | - } |
|
35 | - return glsr(Template::class)->build('templates/review', [ |
|
36 | - 'context' => $this->values, |
|
37 | - 'review' => $this->review, |
|
38 | - ]); |
|
39 | - } |
|
27 | + /** |
|
28 | + * @return string|void |
|
29 | + */ |
|
30 | + public function __toString() |
|
31 | + { |
|
32 | + if (empty($this->values)) { |
|
33 | + return; |
|
34 | + } |
|
35 | + return glsr(Template::class)->build('templates/review', [ |
|
36 | + 'context' => $this->values, |
|
37 | + 'review' => $this->review, |
|
38 | + ]); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param mixed $key |
|
43 | - * @return mixed |
|
44 | - */ |
|
45 | - public function offsetGet($key) |
|
46 | - { |
|
47 | - if (array_key_exists($key, $this->values)) { |
|
48 | - return $this->values[$key]; |
|
49 | - } |
|
50 | - return property_exists($this, $key) |
|
51 | - ? $this->$key |
|
52 | - : null; |
|
53 | - } |
|
41 | + /** |
|
42 | + * @param mixed $key |
|
43 | + * @return mixed |
|
44 | + */ |
|
45 | + public function offsetGet($key) |
|
46 | + { |
|
47 | + if (array_key_exists($key, $this->values)) { |
|
48 | + return $this->values[$key]; |
|
49 | + } |
|
50 | + return property_exists($this, $key) |
|
51 | + ? $this->$key |
|
52 | + : null; |
|
53 | + } |
|
54 | 54 | } |
@@ -8,135 +8,135 @@ |
||
8 | 8 | |
9 | 9 | class ReviewsHtml extends ArrayObject |
10 | 10 | { |
11 | - /** |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - public $args; |
|
11 | + /** |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + public $args; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @var int |
|
18 | - */ |
|
19 | - public $max_num_pages; |
|
16 | + /** |
|
17 | + * @var int |
|
18 | + */ |
|
19 | + public $max_num_pages; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public $pagination; |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public $pagination; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - public $reviews; |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + public $reviews; |
|
30 | 30 | |
31 | - public function __construct(array $renderedReviews, $maxPageCount, array $args) |
|
32 | - { |
|
33 | - $this->args = $args; |
|
34 | - $this->max_num_pages = $maxPageCount; |
|
35 | - $this->reviews = $renderedReviews; |
|
36 | - $this->pagination = $this->buildPagination(); |
|
37 | - parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
38 | - } |
|
31 | + public function __construct(array $renderedReviews, $maxPageCount, array $args) |
|
32 | + { |
|
33 | + $this->args = $args; |
|
34 | + $this->max_num_pages = $maxPageCount; |
|
35 | + $this->reviews = $renderedReviews; |
|
36 | + $this->pagination = $this->buildPagination(); |
|
37 | + parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function __toString() |
|
44 | - { |
|
45 | - return glsr(Template::class)->build('templates/reviews', [ |
|
46 | - 'args' => $this->args, |
|
47 | - 'context' => [ |
|
48 | - 'assigned_to' => $this->args['assigned_to'], |
|
49 | - 'category' => $this->args['category'], |
|
50 | - 'class' => $this->getClass(), |
|
51 | - 'id' => $this->args['id'], |
|
52 | - 'pagination' => $this->getPagination(), |
|
53 | - 'reviews' => $this->getReviews(), |
|
54 | - ], |
|
55 | - ]); |
|
56 | - } |
|
40 | + /** |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function __toString() |
|
44 | + { |
|
45 | + return glsr(Template::class)->build('templates/reviews', [ |
|
46 | + 'args' => $this->args, |
|
47 | + 'context' => [ |
|
48 | + 'assigned_to' => $this->args['assigned_to'], |
|
49 | + 'category' => $this->args['category'], |
|
50 | + 'class' => $this->getClass(), |
|
51 | + 'id' => $this->args['id'], |
|
52 | + 'pagination' => $this->getPagination(), |
|
53 | + 'reviews' => $this->getReviews(), |
|
54 | + ], |
|
55 | + ]); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getPagination() |
|
62 | - { |
|
63 | - return wp_validate_boolean($this->args['pagination']) |
|
64 | - ? $this->pagination |
|
65 | - : ''; |
|
66 | - } |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getPagination() |
|
62 | + { |
|
63 | + return wp_validate_boolean($this->args['pagination']) |
|
64 | + ? $this->pagination |
|
65 | + : ''; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function getReviews() |
|
72 | - { |
|
73 | - $html = empty($this->reviews) |
|
74 | - ? $this->getReviewsFallback() |
|
75 | - : implode(PHP_EOL, $this->reviews); |
|
76 | - $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
77 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | - return sprintf($wrapper, $html); |
|
79 | - } |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function getReviews() |
|
72 | + { |
|
73 | + $html = empty($this->reviews) |
|
74 | + ? $this->getReviewsFallback() |
|
75 | + : implode(PHP_EOL, $this->reviews); |
|
76 | + $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
77 | + $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | + return sprintf($wrapper, $html); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param mixed $key |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - public function offsetGet($key) |
|
86 | - { |
|
87 | - if ('navigation' == $key) { |
|
88 | - glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
89 | - return $this->pagination; |
|
90 | - } |
|
91 | - if (array_key_exists($key, $this->reviews)) { |
|
92 | - return $this->reviews[$key]; |
|
93 | - } |
|
94 | - return property_exists($this, $key) |
|
95 | - ? $this->$key |
|
96 | - : null; |
|
97 | - } |
|
81 | + /** |
|
82 | + * @param mixed $key |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + public function offsetGet($key) |
|
86 | + { |
|
87 | + if ('navigation' == $key) { |
|
88 | + glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
89 | + return $this->pagination; |
|
90 | + } |
|
91 | + if (array_key_exists($key, $this->reviews)) { |
|
92 | + return $this->reviews[$key]; |
|
93 | + } |
|
94 | + return property_exists($this, $key) |
|
95 | + ? $this->$key |
|
96 | + : null; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - protected function buildPagination() |
|
103 | - { |
|
104 | - $html = glsr(Partial::class)->build('pagination', [ |
|
105 | - 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | - 'current' => Arr::get($this->args, 'paged'), |
|
107 | - 'total' => $this->max_num_pages, |
|
108 | - ]); |
|
109 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
110 | - $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
111 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | - return sprintf($wrapper, $html); |
|
113 | - } |
|
99 | + /** |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + protected function buildPagination() |
|
103 | + { |
|
104 | + $html = glsr(Partial::class)->build('pagination', [ |
|
105 | + 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | + 'current' => Arr::get($this->args, 'paged'), |
|
107 | + 'total' => $this->max_num_pages, |
|
108 | + ]); |
|
109 | + $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
110 | + $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
111 | + $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | + return sprintf($wrapper, $html); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function getClass() |
|
119 | - { |
|
120 | - $defaults = [ |
|
121 | - 'glsr-default', |
|
122 | - ]; |
|
123 | - if ('ajax' == $this->args['pagination']) { |
|
124 | - $defaults[] = 'glsr-ajax-pagination'; |
|
125 | - } |
|
126 | - $classes = explode(' ', $this->args['class']); |
|
127 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | - return implode(' ', $classes); |
|
129 | - } |
|
115 | + /** |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function getClass() |
|
119 | + { |
|
120 | + $defaults = [ |
|
121 | + 'glsr-default', |
|
122 | + ]; |
|
123 | + if ('ajax' == $this->args['pagination']) { |
|
124 | + $defaults[] = 'glsr-ajax-pagination'; |
|
125 | + } |
|
126 | + $classes = explode(' ', $this->args['class']); |
|
127 | + $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | + return implode(' ', $classes); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - protected function getReviewsFallback() |
|
135 | - { |
|
136 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
138 | - } |
|
139 | - $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
140 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
141 | - } |
|
131 | + /** |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + protected function getReviewsFallback() |
|
135 | + { |
|
136 | + if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | + $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
138 | + } |
|
139 | + $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
140 | + return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
141 | + } |
|
142 | 142 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | interface PartialContract |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function build(array $args = []); |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function build(array $args = []); |
|
11 | 11 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | require_once $file; |
7 | 7 | |
8 | 8 | if (!(new GL_Plugin_Check_v4($file))->isValid()) { |
9 | - return; |
|
9 | + return; |
|
10 | 10 | } |
11 | 11 | delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey(3)); |
12 | 12 | delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey(4)); |
@@ -8,54 +8,54 @@ |
||
8 | 8 | |
9 | 9 | class StarRating implements PartialContract |
10 | 10 | { |
11 | - protected $prefix; |
|
12 | - protected $rating; |
|
11 | + protected $prefix; |
|
12 | + protected $rating; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @return string |
|
16 | - */ |
|
17 | - public function build(array $args = []) |
|
18 | - { |
|
19 | - $this->setProperties($args); |
|
20 | - $fullStars = intval(floor($this->rating)); |
|
21 | - $halfStars = intval(ceil($this->rating - $fullStars)); |
|
22 | - $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars); |
|
23 | - return glsr(Template::class)->build('templates/rating/stars', [ |
|
24 | - 'context' => [ |
|
25 | - 'empty_stars' => $this->getTemplate('empty-star', $emptyStars), |
|
26 | - 'full_stars' => $this->getTemplate('full-star', $fullStars), |
|
27 | - 'half_stars' => $this->getTemplate('half-star', $halfStars), |
|
28 | - 'prefix' => $this->prefix, |
|
29 | - 'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)), |
|
30 | - ], |
|
31 | - ]); |
|
32 | - } |
|
14 | + /** |
|
15 | + * @return string |
|
16 | + */ |
|
17 | + public function build(array $args = []) |
|
18 | + { |
|
19 | + $this->setProperties($args); |
|
20 | + $fullStars = intval(floor($this->rating)); |
|
21 | + $halfStars = intval(ceil($this->rating - $fullStars)); |
|
22 | + $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars); |
|
23 | + return glsr(Template::class)->build('templates/rating/stars', [ |
|
24 | + 'context' => [ |
|
25 | + 'empty_stars' => $this->getTemplate('empty-star', $emptyStars), |
|
26 | + 'full_stars' => $this->getTemplate('full-star', $fullStars), |
|
27 | + 'half_stars' => $this->getTemplate('half-star', $halfStars), |
|
28 | + 'prefix' => $this->prefix, |
|
29 | + 'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)), |
|
30 | + ], |
|
31 | + ]); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param string $templateName |
|
36 | - * @param int $timesRepeated |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - protected function getTemplate($templateName, $timesRepeated) |
|
40 | - { |
|
41 | - $template = glsr(Template::class)->build('templates/rating/'.$templateName, [ |
|
42 | - 'context' => [ |
|
43 | - 'prefix' => $this->prefix, |
|
44 | - ], |
|
45 | - ]); |
|
46 | - return str_repeat($template, $timesRepeated); |
|
47 | - } |
|
34 | + /** |
|
35 | + * @param string $templateName |
|
36 | + * @param int $timesRepeated |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + protected function getTemplate($templateName, $timesRepeated) |
|
40 | + { |
|
41 | + $template = glsr(Template::class)->build('templates/rating/'.$templateName, [ |
|
42 | + 'context' => [ |
|
43 | + 'prefix' => $this->prefix, |
|
44 | + ], |
|
45 | + ]); |
|
46 | + return str_repeat($template, $timesRepeated); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - protected function setProperties(array $args) |
|
53 | - { |
|
54 | - $args = wp_parse_args($args, [ |
|
55 | - 'prefix' => glsr()->isAdmin() ? '' : 'glsr-', |
|
56 | - 'rating' => 0, |
|
57 | - ]); |
|
58 | - $this->prefix = $args['prefix']; |
|
59 | - $this->rating = (float) str_replace(',', '.', $args['rating']); |
|
60 | - } |
|
49 | + /** |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + protected function setProperties(array $args) |
|
53 | + { |
|
54 | + $args = wp_parse_args($args, [ |
|
55 | + 'prefix' => glsr()->isAdmin() ? '' : 'glsr-', |
|
56 | + 'rating' => 0, |
|
57 | + ]); |
|
58 | + $this->prefix = $args['prefix']; |
|
59 | + $this->rating = (float) str_replace(',', '.', $args['rating']); |
|
60 | + } |
|
61 | 61 | } |
@@ -8,141 +8,141 @@ |
||
8 | 8 | */ |
9 | 9 | class GL_Plugin_Check_v4 |
10 | 10 | { |
11 | - const MIN_PHP_VERSION = '5.6.0'; |
|
12 | - const MIN_WORDPRESS_VERSION = '4.7.0'; |
|
11 | + const MIN_PHP_VERSION = '5.6.0'; |
|
12 | + const MIN_WORDPRESS_VERSION = '4.7.0'; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - public $versions; |
|
14 | + /** |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + public $versions; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $file; |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $file; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param string $file |
|
26 | - */ |
|
27 | - public function __construct($file) |
|
28 | - { |
|
29 | - $this->file = realpath($file); |
|
30 | - $versionRequirements = get_file_data($this->file, [ |
|
31 | - 'php' => 'Requires PHP', |
|
32 | - 'wordpress' => 'Requires at least', |
|
33 | - ]); |
|
34 | - $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
35 | - 'php' => static::MIN_PHP_VERSION, |
|
36 | - 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
37 | - ]); |
|
38 | - } |
|
24 | + /** |
|
25 | + * @param string $file |
|
26 | + */ |
|
27 | + public function __construct($file) |
|
28 | + { |
|
29 | + $this->file = realpath($file); |
|
30 | + $versionRequirements = get_file_data($this->file, [ |
|
31 | + 'php' => 'Requires PHP', |
|
32 | + 'wordpress' => 'Requires at least', |
|
33 | + ]); |
|
34 | + $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
35 | + 'php' => static::MIN_PHP_VERSION, |
|
36 | + 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
37 | + ]); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public function canProceed() |
|
44 | - { |
|
45 | - if ($this->isValid()) { |
|
46 | - return true; |
|
47 | - } |
|
48 | - add_action('activated_plugin', [$this, 'deactivate']); |
|
49 | - add_action('admin_notices', [$this, 'deactivate']); |
|
50 | - return false; |
|
51 | - } |
|
40 | + /** |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public function canProceed() |
|
44 | + { |
|
45 | + if ($this->isValid()) { |
|
46 | + return true; |
|
47 | + } |
|
48 | + add_action('activated_plugin', [$this, 'deactivate']); |
|
49 | + add_action('admin_notices', [$this, 'deactivate']); |
|
50 | + return false; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function isPhpValid() |
|
57 | - { |
|
58 | - return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
59 | - } |
|
53 | + /** |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function isPhpValid() |
|
57 | + { |
|
58 | + return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public function isValid() |
|
65 | - { |
|
66 | - return $this->isPhpValid() && $this->isWpValid(); |
|
67 | - } |
|
61 | + /** |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public function isValid() |
|
65 | + { |
|
66 | + return $this->isPhpValid() && $this->isWpValid(); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return bool |
|
71 | - */ |
|
72 | - public function isWpValid() |
|
73 | - { |
|
74 | - global $wp_version; |
|
75 | - return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
76 | - } |
|
69 | + /** |
|
70 | + * @return bool |
|
71 | + */ |
|
72 | + public function isWpValid() |
|
73 | + { |
|
74 | + global $wp_version; |
|
75 | + return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $plugin |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function deactivate($plugin) |
|
83 | - { |
|
84 | - if ($this->isValid()) { |
|
85 | - return; |
|
86 | - } |
|
87 | - $pluginSlug = plugin_basename($this->file); |
|
88 | - if ($plugin == $pluginSlug) { |
|
89 | - $this->redirect(); //exit |
|
90 | - } |
|
91 | - $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
92 | - deactivate_plugins($pluginSlug); |
|
93 | - $this->printNotice($pluginData['name']); |
|
94 | - } |
|
78 | + /** |
|
79 | + * @param string $plugin |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function deactivate($plugin) |
|
83 | + { |
|
84 | + if ($this->isValid()) { |
|
85 | + return; |
|
86 | + } |
|
87 | + $pluginSlug = plugin_basename($this->file); |
|
88 | + if ($plugin == $pluginSlug) { |
|
89 | + $this->redirect(); //exit |
|
90 | + } |
|
91 | + $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
92 | + deactivate_plugins($pluginSlug); |
|
93 | + $this->printNotice($pluginData['name']); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - protected function getMessages() |
|
100 | - { |
|
101 | - return [ |
|
102 | - 'notice' => __('The %s plugin was deactivated.', 'site-reviews'), |
|
103 | - 'php_version' => __('PHP version', 'site-reviews'), |
|
104 | - 'rollback' => __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'), |
|
105 | - 'update_php' => __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'), |
|
106 | - 'update_wp' => __('Update WordPress', 'site-reviews'), |
|
107 | - 'wp_version' => __('WordPress version', 'site-reviews'), |
|
108 | - 'wrong_version' => __('This plugin requires %s or greater in order to work properly.', 'site-reviews'), |
|
109 | - ]; |
|
110 | - } |
|
96 | + /** |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + protected function getMessages() |
|
100 | + { |
|
101 | + return [ |
|
102 | + 'notice' => __('The %s plugin was deactivated.', 'site-reviews'), |
|
103 | + 'php_version' => __('PHP version', 'site-reviews'), |
|
104 | + 'rollback' => __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'), |
|
105 | + 'update_php' => __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'), |
|
106 | + 'update_wp' => __('Update WordPress', 'site-reviews'), |
|
107 | + 'wp_version' => __('WordPress version', 'site-reviews'), |
|
108 | + 'wrong_version' => __('This plugin requires %s or greater in order to work properly.', 'site-reviews'), |
|
109 | + ]; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @param string $pluginName |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - protected function printNotice($pluginName) |
|
117 | - { |
|
118 | - $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
119 | - $messages = $this->getMessages(); |
|
120 | - $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
121 | - if (!$this->isPhpValid()) { |
|
122 | - printf($noticeTemplate, |
|
123 | - sprintf($messages['notice'], $pluginName), |
|
124 | - sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
125 | - sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
126 | - ); |
|
127 | - } elseif (!$this->isWpValid()) { |
|
128 | - printf($noticeTemplate, |
|
129 | - sprintf($messages['notice'], $pluginName), |
|
130 | - sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
131 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
132 | - ); |
|
133 | - } |
|
134 | - } |
|
112 | + /** |
|
113 | + * @param string $pluginName |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + protected function printNotice($pluginName) |
|
117 | + { |
|
118 | + $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
119 | + $messages = $this->getMessages(); |
|
120 | + $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
121 | + if (!$this->isPhpValid()) { |
|
122 | + printf($noticeTemplate, |
|
123 | + sprintf($messages['notice'], $pluginName), |
|
124 | + sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
125 | + sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
126 | + ); |
|
127 | + } elseif (!$this->isWpValid()) { |
|
128 | + printf($noticeTemplate, |
|
129 | + sprintf($messages['notice'], $pluginName), |
|
130 | + sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
131 | + $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
132 | + ); |
|
133 | + } |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * @return void |
|
138 | - */ |
|
139 | - protected function redirect() |
|
140 | - { |
|
141 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
142 | - filter_input(INPUT_GET, 'plugin_status'), |
|
143 | - filter_input(INPUT_GET, 'paged'), |
|
144 | - filter_input(INPUT_GET, 's') |
|
145 | - ))); |
|
146 | - exit; |
|
147 | - } |
|
136 | + /** |
|
137 | + * @return void |
|
138 | + */ |
|
139 | + protected function redirect() |
|
140 | + { |
|
141 | + wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
142 | + filter_input(INPUT_GET, 'plugin_status'), |
|
143 | + filter_input(INPUT_GET, 'paged'), |
|
144 | + filter_input(INPUT_GET, 's') |
|
145 | + ))); |
|
146 | + exit; |
|
147 | + } |
|
148 | 148 | } |
@@ -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 | } |