@@ -21,382 +21,382 @@ |
||
21 | 21 | |
22 | 22 | class SiteReviews |
23 | 23 | { |
24 | - /** |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - public $args; |
|
24 | + /** |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + public $args; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var Review |
|
31 | - */ |
|
32 | - public $current; |
|
29 | + /** |
|
30 | + * @var Review |
|
31 | + */ |
|
32 | + public $current; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - public $options; |
|
34 | + /** |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + public $options; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var Reviews |
|
41 | - */ |
|
42 | - protected $reviews; |
|
39 | + /** |
|
40 | + * @var Reviews |
|
41 | + */ |
|
42 | + protected $reviews; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param Reviews|null $reviews |
|
46 | - * @return ReviewsHtml |
|
47 | - */ |
|
48 | - public function build(array $args = [], $reviews = null) |
|
49 | - { |
|
50 | - $this->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
51 | - $this->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
52 | - $this->reviews = $reviews instanceof Reviews |
|
53 | - ? $reviews |
|
54 | - : glsr(ReviewManager::class)->get($this->args); |
|
55 | - $this->generateSchema(); |
|
56 | - return $this->buildReviews(); |
|
57 | - } |
|
44 | + /** |
|
45 | + * @param Reviews|null $reviews |
|
46 | + * @return ReviewsHtml |
|
47 | + */ |
|
48 | + public function build(array $args = [], $reviews = null) |
|
49 | + { |
|
50 | + $this->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
51 | + $this->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
52 | + $this->reviews = $reviews instanceof Reviews |
|
53 | + ? $reviews |
|
54 | + : glsr(ReviewManager::class)->get($this->args); |
|
55 | + $this->generateSchema(); |
|
56 | + return $this->buildReviews(); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return ReviewHtml |
|
61 | - */ |
|
62 | - public function buildReview(Review $review) |
|
63 | - { |
|
64 | - $review = apply_filters('site-reviews/review/build/before', $review); |
|
65 | - $this->current = $review; |
|
66 | - $renderedFields = []; |
|
67 | - foreach ($review as $key => $value) { |
|
68 | - $method = Helper::buildMethodName($key, 'buildOption'); |
|
69 | - $field = method_exists($this, $method) |
|
70 | - ? $this->$method($key, $value) |
|
71 | - : false; |
|
72 | - $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this); |
|
73 | - if (false === $field) { |
|
74 | - continue; |
|
75 | - } |
|
76 | - $renderedFields[$key] = $field; |
|
77 | - } |
|
78 | - $this->wrap($renderedFields, $review); |
|
79 | - $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this); |
|
80 | - $this->current = null; |
|
81 | - return new ReviewHtml($review, (array) $renderedFields); |
|
82 | - } |
|
59 | + /** |
|
60 | + * @return ReviewHtml |
|
61 | + */ |
|
62 | + public function buildReview(Review $review) |
|
63 | + { |
|
64 | + $review = apply_filters('site-reviews/review/build/before', $review); |
|
65 | + $this->current = $review; |
|
66 | + $renderedFields = []; |
|
67 | + foreach ($review as $key => $value) { |
|
68 | + $method = Helper::buildMethodName($key, 'buildOption'); |
|
69 | + $field = method_exists($this, $method) |
|
70 | + ? $this->$method($key, $value) |
|
71 | + : false; |
|
72 | + $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this); |
|
73 | + if (false === $field) { |
|
74 | + continue; |
|
75 | + } |
|
76 | + $renderedFields[$key] = $field; |
|
77 | + } |
|
78 | + $this->wrap($renderedFields, $review); |
|
79 | + $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this); |
|
80 | + $this->current = null; |
|
81 | + return new ReviewHtml($review, (array) $renderedFields); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return ReviewsHtml |
|
86 | - */ |
|
87 | - public function buildReviews() |
|
88 | - { |
|
89 | - $renderedReviews = []; |
|
90 | - foreach ($this->reviews as $index => $review) { |
|
91 | - $renderedReviews[] = $this->buildReview($review); |
|
92 | - } |
|
93 | - return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args); |
|
94 | - } |
|
84 | + /** |
|
85 | + * @return ReviewsHtml |
|
86 | + */ |
|
87 | + public function buildReviews() |
|
88 | + { |
|
89 | + $renderedReviews = []; |
|
90 | + foreach ($this->reviews as $index => $review) { |
|
91 | + $renderedReviews[] = $this->buildReview($review); |
|
92 | + } |
|
93 | + return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - public function generateSchema() |
|
100 | - { |
|
101 | - if (!wp_validate_boolean($this->args['schema'])) { |
|
102 | - return; |
|
103 | - } |
|
104 | - glsr(Schema::class)->store( |
|
105 | - glsr(Schema::class)->build($this->args) |
|
106 | - ); |
|
107 | - } |
|
96 | + /** |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + public function generateSchema() |
|
100 | + { |
|
101 | + if (!wp_validate_boolean($this->args['schema'])) { |
|
102 | + return; |
|
103 | + } |
|
104 | + glsr(Schema::class)->store( |
|
105 | + glsr(Schema::class)->build($this->args) |
|
106 | + ); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param string $text |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function getExcerpt($text) |
|
114 | - { |
|
115 | - $limit = intval($this->getOption('settings.reviews.excerpts_length', 55)); |
|
116 | - $split = extension_loaded('intl') |
|
117 | - ? $this->getExcerptIntlSplit($text, $limit) |
|
118 | - : $this->getExcerptSplit($text, $limit); |
|
119 | - $hiddenText = substr($text, $split); |
|
120 | - if (!empty($hiddenText)) { |
|
121 | - $showMore = glsr(Builder::class)->span($hiddenText, [ |
|
122 | - 'class' => 'glsr-hidden glsr-hidden-text', |
|
123 | - 'data-show-less' => __('Show less', 'site-reviews'), |
|
124 | - 'data-show-more' => __('Show more', 'site-reviews'), |
|
125 | - ]); |
|
126 | - $text = ltrim(substr($text, 0, $split)).$showMore; |
|
127 | - } |
|
128 | - return $text; |
|
129 | - } |
|
109 | + /** |
|
110 | + * @param string $text |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function getExcerpt($text) |
|
114 | + { |
|
115 | + $limit = intval($this->getOption('settings.reviews.excerpts_length', 55)); |
|
116 | + $split = extension_loaded('intl') |
|
117 | + ? $this->getExcerptIntlSplit($text, $limit) |
|
118 | + : $this->getExcerptSplit($text, $limit); |
|
119 | + $hiddenText = substr($text, $split); |
|
120 | + if (!empty($hiddenText)) { |
|
121 | + $showMore = glsr(Builder::class)->span($hiddenText, [ |
|
122 | + 'class' => 'glsr-hidden glsr-hidden-text', |
|
123 | + 'data-show-less' => __('Show less', 'site-reviews'), |
|
124 | + 'data-show-more' => __('Show more', 'site-reviews'), |
|
125 | + ]); |
|
126 | + $text = ltrim(substr($text, 0, $split)).$showMore; |
|
127 | + } |
|
128 | + return $text; |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @param string $key |
|
133 | - * @param string $path |
|
134 | - * @return bool |
|
135 | - */ |
|
136 | - public function isHidden($key, $path = '') |
|
137 | - { |
|
138 | - $isOptionEnabled = !empty($path) |
|
139 | - ? $this->isOptionEnabled($path) |
|
140 | - : true; |
|
141 | - return in_array($key, $this->args['hide']) || !$isOptionEnabled; |
|
142 | - } |
|
131 | + /** |
|
132 | + * @param string $key |
|
133 | + * @param string $path |
|
134 | + * @return bool |
|
135 | + */ |
|
136 | + public function isHidden($key, $path = '') |
|
137 | + { |
|
138 | + $isOptionEnabled = !empty($path) |
|
139 | + ? $this->isOptionEnabled($path) |
|
140 | + : true; |
|
141 | + return in_array($key, $this->args['hide']) || !$isOptionEnabled; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @param string $key |
|
146 | - * @param string $value |
|
147 | - * @return bool |
|
148 | - */ |
|
149 | - public function isHiddenOrEmpty($key, $value) |
|
150 | - { |
|
151 | - return $this->isHidden($key) || empty($value); |
|
152 | - } |
|
144 | + /** |
|
145 | + * @param string $key |
|
146 | + * @param string $value |
|
147 | + * @return bool |
|
148 | + */ |
|
149 | + public function isHiddenOrEmpty($key, $value) |
|
150 | + { |
|
151 | + return $this->isHidden($key) || empty($value); |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * @param string $text |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public function normalizeText($text) |
|
159 | - { |
|
160 | - $text = wp_kses($text, wp_kses_allowed_html()); |
|
161 | - $text = convert_smilies(strip_shortcodes($text)); |
|
162 | - $text = str_replace(']]>', ']]>', $text); |
|
163 | - $text = preg_replace('/(\R){2,}/', '$1', $text); |
|
164 | - if ($this->isOptionEnabled('settings.reviews.excerpts')) { |
|
165 | - $text = $this->getExcerpt($text); |
|
166 | - } |
|
167 | - return wptexturize(nl2br($text)); |
|
168 | - } |
|
154 | + /** |
|
155 | + * @param string $text |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public function normalizeText($text) |
|
159 | + { |
|
160 | + $text = wp_kses($text, wp_kses_allowed_html()); |
|
161 | + $text = convert_smilies(strip_shortcodes($text)); |
|
162 | + $text = str_replace(']]>', ']]>', $text); |
|
163 | + $text = preg_replace('/(\R){2,}/', '$1', $text); |
|
164 | + if ($this->isOptionEnabled('settings.reviews.excerpts')) { |
|
165 | + $text = $this->getExcerpt($text); |
|
166 | + } |
|
167 | + return wptexturize(nl2br($text)); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * @param string $key |
|
172 | - * @param string $value |
|
173 | - * @return void|string |
|
174 | - */ |
|
175 | - protected function buildOptionAssignedTo($key, $value) |
|
176 | - { |
|
177 | - if ($this->isHidden($key, 'settings.reviews.assigned_links')) { |
|
178 | - return; |
|
179 | - } |
|
180 | - $post = glsr(Multilingual::class)->getPost($value); |
|
181 | - if (!($post instanceof WP_Post)) { |
|
182 | - return; |
|
183 | - } |
|
184 | - $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [ |
|
185 | - 'href' => get_the_permalink($post->ID), |
|
186 | - ]); |
|
187 | - $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink); |
|
188 | - return '<span>'.$assignedTo.'</span>'; |
|
189 | - } |
|
170 | + /** |
|
171 | + * @param string $key |
|
172 | + * @param string $value |
|
173 | + * @return void|string |
|
174 | + */ |
|
175 | + protected function buildOptionAssignedTo($key, $value) |
|
176 | + { |
|
177 | + if ($this->isHidden($key, 'settings.reviews.assigned_links')) { |
|
178 | + return; |
|
179 | + } |
|
180 | + $post = glsr(Multilingual::class)->getPost($value); |
|
181 | + if (!($post instanceof WP_Post)) { |
|
182 | + return; |
|
183 | + } |
|
184 | + $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [ |
|
185 | + 'href' => get_the_permalink($post->ID), |
|
186 | + ]); |
|
187 | + $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink); |
|
188 | + return '<span>'.$assignedTo.'</span>'; |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * @param string $key |
|
193 | - * @param string $value |
|
194 | - * @return void|string |
|
195 | - */ |
|
196 | - protected function buildOptionAuthor($key, $value) |
|
197 | - { |
|
198 | - if (!$this->isHidden($key)) { |
|
199 | - $name = Str::convertName( |
|
200 | - $value, |
|
201 | - glsr_get_option('reviews.name.format'), |
|
202 | - glsr_get_option('reviews.name.initial') |
|
203 | - ); |
|
204 | - return '<span>'.$name.'</span>'; |
|
205 | - } |
|
206 | - } |
|
191 | + /** |
|
192 | + * @param string $key |
|
193 | + * @param string $value |
|
194 | + * @return void|string |
|
195 | + */ |
|
196 | + protected function buildOptionAuthor($key, $value) |
|
197 | + { |
|
198 | + if (!$this->isHidden($key)) { |
|
199 | + $name = Str::convertName( |
|
200 | + $value, |
|
201 | + glsr_get_option('reviews.name.format'), |
|
202 | + glsr_get_option('reviews.name.initial') |
|
203 | + ); |
|
204 | + return '<span>'.$name.'</span>'; |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * @param string $key |
|
210 | - * @param string $value |
|
211 | - * @return void|string |
|
212 | - */ |
|
213 | - protected function buildOptionAvatar($key, $value) |
|
214 | - { |
|
215 | - if ($this->isHidden($key, 'settings.reviews.avatars')) { |
|
216 | - return; |
|
217 | - } |
|
218 | - $size = $this->getOption('settings.reviews.avatars_size', 40); |
|
219 | - return glsr(Builder::class)->img([ |
|
220 | - 'height' => $size, |
|
221 | - 'src' => $this->generateAvatar($value), |
|
222 | - 'style' => sprintf('width:%1$spx; height:%1$spx;', $size), |
|
223 | - 'width' => $size, |
|
224 | - ]); |
|
225 | - } |
|
208 | + /** |
|
209 | + * @param string $key |
|
210 | + * @param string $value |
|
211 | + * @return void|string |
|
212 | + */ |
|
213 | + protected function buildOptionAvatar($key, $value) |
|
214 | + { |
|
215 | + if ($this->isHidden($key, 'settings.reviews.avatars')) { |
|
216 | + return; |
|
217 | + } |
|
218 | + $size = $this->getOption('settings.reviews.avatars_size', 40); |
|
219 | + return glsr(Builder::class)->img([ |
|
220 | + 'height' => $size, |
|
221 | + 'src' => $this->generateAvatar($value), |
|
222 | + 'style' => sprintf('width:%1$spx; height:%1$spx;', $size), |
|
223 | + 'width' => $size, |
|
224 | + ]); |
|
225 | + } |
|
226 | 226 | |
227 | - /** |
|
228 | - * @param string $key |
|
229 | - * @param string $value |
|
230 | - * @return void|string |
|
231 | - */ |
|
232 | - protected function buildOptionContent($key, $value) |
|
233 | - { |
|
234 | - $text = $this->normalizeText($value); |
|
235 | - if (!$this->isHiddenOrEmpty($key, $text)) { |
|
236 | - return '<p>'.$text.'</p>'; |
|
237 | - } |
|
238 | - } |
|
227 | + /** |
|
228 | + * @param string $key |
|
229 | + * @param string $value |
|
230 | + * @return void|string |
|
231 | + */ |
|
232 | + protected function buildOptionContent($key, $value) |
|
233 | + { |
|
234 | + $text = $this->normalizeText($value); |
|
235 | + if (!$this->isHiddenOrEmpty($key, $text)) { |
|
236 | + return '<p>'.$text.'</p>'; |
|
237 | + } |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * @param string $key |
|
242 | - * @param string $value |
|
243 | - * @return void|string |
|
244 | - */ |
|
245 | - protected function buildOptionDate($key, $value) |
|
246 | - { |
|
247 | - if ($this->isHidden($key)) { |
|
248 | - return; |
|
249 | - } |
|
250 | - $dateFormat = $this->getOption('settings.reviews.date.format', 'default'); |
|
251 | - if ('relative' == $dateFormat) { |
|
252 | - $date = glsr(Date::class)->relative($value); |
|
253 | - } else { |
|
254 | - $format = 'custom' == $dateFormat |
|
255 | - ? $this->getOption('settings.reviews.date.custom', 'M j, Y') |
|
256 | - : glsr(OptionManager::class)->getWP('date_format', 'F j, Y'); |
|
257 | - $date = date_i18n($format, strtotime($value)); |
|
258 | - } |
|
259 | - return '<span>'.$date.'</span>'; |
|
260 | - } |
|
240 | + /** |
|
241 | + * @param string $key |
|
242 | + * @param string $value |
|
243 | + * @return void|string |
|
244 | + */ |
|
245 | + protected function buildOptionDate($key, $value) |
|
246 | + { |
|
247 | + if ($this->isHidden($key)) { |
|
248 | + return; |
|
249 | + } |
|
250 | + $dateFormat = $this->getOption('settings.reviews.date.format', 'default'); |
|
251 | + if ('relative' == $dateFormat) { |
|
252 | + $date = glsr(Date::class)->relative($value); |
|
253 | + } else { |
|
254 | + $format = 'custom' == $dateFormat |
|
255 | + ? $this->getOption('settings.reviews.date.custom', 'M j, Y') |
|
256 | + : glsr(OptionManager::class)->getWP('date_format', 'F j, Y'); |
|
257 | + $date = date_i18n($format, strtotime($value)); |
|
258 | + } |
|
259 | + return '<span>'.$date.'</span>'; |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * @param string $key |
|
264 | - * @param string $value |
|
265 | - * @return void|string |
|
266 | - */ |
|
267 | - protected function buildOptionRating($key, $value) |
|
268 | - { |
|
269 | - if (!$this->isHiddenOrEmpty($key, $value)) { |
|
270 | - return glsr_star_rating($value); |
|
271 | - } |
|
272 | - } |
|
262 | + /** |
|
263 | + * @param string $key |
|
264 | + * @param string $value |
|
265 | + * @return void|string |
|
266 | + */ |
|
267 | + protected function buildOptionRating($key, $value) |
|
268 | + { |
|
269 | + if (!$this->isHiddenOrEmpty($key, $value)) { |
|
270 | + return glsr_star_rating($value); |
|
271 | + } |
|
272 | + } |
|
273 | 273 | |
274 | - /** |
|
275 | - * @param string $key |
|
276 | - * @param string $value |
|
277 | - * @return void|string |
|
278 | - */ |
|
279 | - protected function buildOptionResponse($key, $value) |
|
280 | - { |
|
281 | - if ($this->isHiddenOrEmpty($key, $value)) { |
|
282 | - return; |
|
283 | - } |
|
284 | - $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name')); |
|
285 | - $text = $this->normalizeText($value); |
|
286 | - $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
|
287 | - $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']); |
|
288 | - $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']); |
|
289 | - return $response.$background; |
|
290 | - } |
|
274 | + /** |
|
275 | + * @param string $key |
|
276 | + * @param string $value |
|
277 | + * @return void|string |
|
278 | + */ |
|
279 | + protected function buildOptionResponse($key, $value) |
|
280 | + { |
|
281 | + if ($this->isHiddenOrEmpty($key, $value)) { |
|
282 | + return; |
|
283 | + } |
|
284 | + $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name')); |
|
285 | + $text = $this->normalizeText($value); |
|
286 | + $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
|
287 | + $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']); |
|
288 | + $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']); |
|
289 | + return $response.$background; |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * @param string $key |
|
294 | - * @param string $value |
|
295 | - * @return void|string |
|
296 | - */ |
|
297 | - protected function buildOptionTitle($key, $value) |
|
298 | - { |
|
299 | - if ($this->isHidden($key)) { |
|
300 | - return; |
|
301 | - } |
|
302 | - if (empty($value)) { |
|
303 | - $value = __('No Title', 'site-reviews'); |
|
304 | - } |
|
305 | - return '<h3>'.$value.'</h3>'; |
|
306 | - } |
|
292 | + /** |
|
293 | + * @param string $key |
|
294 | + * @param string $value |
|
295 | + * @return void|string |
|
296 | + */ |
|
297 | + protected function buildOptionTitle($key, $value) |
|
298 | + { |
|
299 | + if ($this->isHidden($key)) { |
|
300 | + return; |
|
301 | + } |
|
302 | + if (empty($value)) { |
|
303 | + $value = __('No Title', 'site-reviews'); |
|
304 | + } |
|
305 | + return '<h3>'.$value.'</h3>'; |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * @param string $avatarUrl |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - protected function generateAvatar($avatarUrl) |
|
313 | - { |
|
314 | - if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) { |
|
315 | - return $avatarUrl; |
|
316 | - } |
|
317 | - $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id); |
|
318 | - if (empty($authorIdOrEmail)) { |
|
319 | - $authorIdOrEmail = $this->current->email; |
|
320 | - } |
|
321 | - if ($newAvatar = get_avatar_url($authorIdOrEmail)) { |
|
322 | - return $newAvatar; |
|
323 | - } |
|
324 | - return $avatarUrl; |
|
325 | - } |
|
308 | + /** |
|
309 | + * @param string $avatarUrl |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + protected function generateAvatar($avatarUrl) |
|
313 | + { |
|
314 | + if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) { |
|
315 | + return $avatarUrl; |
|
316 | + } |
|
317 | + $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id); |
|
318 | + if (empty($authorIdOrEmail)) { |
|
319 | + $authorIdOrEmail = $this->current->email; |
|
320 | + } |
|
321 | + if ($newAvatar = get_avatar_url($authorIdOrEmail)) { |
|
322 | + return $newAvatar; |
|
323 | + } |
|
324 | + return $avatarUrl; |
|
325 | + } |
|
326 | 326 | |
327 | - /** |
|
328 | - * @param string $text |
|
329 | - * @param int $limit |
|
330 | - * @return int |
|
331 | - */ |
|
332 | - protected function getExcerptIntlSplit($text, $limit) |
|
333 | - { |
|
334 | - $words = IntlRuleBasedBreakIterator::createWordInstance(''); |
|
335 | - $words->setText($text); |
|
336 | - $count = 0; |
|
337 | - foreach ($words as $offset) { |
|
338 | - if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) { |
|
339 | - continue; |
|
340 | - } |
|
341 | - ++$count; |
|
342 | - if ($count != $limit) { |
|
343 | - continue; |
|
344 | - } |
|
345 | - return $offset; |
|
346 | - } |
|
347 | - return strlen($text); |
|
348 | - } |
|
327 | + /** |
|
328 | + * @param string $text |
|
329 | + * @param int $limit |
|
330 | + * @return int |
|
331 | + */ |
|
332 | + protected function getExcerptIntlSplit($text, $limit) |
|
333 | + { |
|
334 | + $words = IntlRuleBasedBreakIterator::createWordInstance(''); |
|
335 | + $words->setText($text); |
|
336 | + $count = 0; |
|
337 | + foreach ($words as $offset) { |
|
338 | + if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) { |
|
339 | + continue; |
|
340 | + } |
|
341 | + ++$count; |
|
342 | + if ($count != $limit) { |
|
343 | + continue; |
|
344 | + } |
|
345 | + return $offset; |
|
346 | + } |
|
347 | + return strlen($text); |
|
348 | + } |
|
349 | 349 | |
350 | - /** |
|
351 | - * @param string $text |
|
352 | - * @param int $limit |
|
353 | - * @return int |
|
354 | - */ |
|
355 | - protected function getExcerptSplit($text, $limit) |
|
356 | - { |
|
357 | - if (str_word_count($text, 0) > $limit) { |
|
358 | - $words = array_keys(str_word_count($text, 2)); |
|
359 | - return $words[$limit]; |
|
360 | - } |
|
361 | - return strlen($text); |
|
362 | - } |
|
350 | + /** |
|
351 | + * @param string $text |
|
352 | + * @param int $limit |
|
353 | + * @return int |
|
354 | + */ |
|
355 | + protected function getExcerptSplit($text, $limit) |
|
356 | + { |
|
357 | + if (str_word_count($text, 0) > $limit) { |
|
358 | + $words = array_keys(str_word_count($text, 2)); |
|
359 | + return $words[$limit]; |
|
360 | + } |
|
361 | + return strlen($text); |
|
362 | + } |
|
363 | 363 | |
364 | - /** |
|
365 | - * @param string $path |
|
366 | - * @param mixed $fallback |
|
367 | - * @return mixed |
|
368 | - */ |
|
369 | - protected function getOption($path, $fallback = '') |
|
370 | - { |
|
371 | - if (array_key_exists($path, $this->options)) { |
|
372 | - return $this->options[$path]; |
|
373 | - } |
|
374 | - return $fallback; |
|
375 | - } |
|
364 | + /** |
|
365 | + * @param string $path |
|
366 | + * @param mixed $fallback |
|
367 | + * @return mixed |
|
368 | + */ |
|
369 | + protected function getOption($path, $fallback = '') |
|
370 | + { |
|
371 | + if (array_key_exists($path, $this->options)) { |
|
372 | + return $this->options[$path]; |
|
373 | + } |
|
374 | + return $fallback; |
|
375 | + } |
|
376 | 376 | |
377 | - /** |
|
378 | - * @param string $path |
|
379 | - * @return bool |
|
380 | - */ |
|
381 | - protected function isOptionEnabled($path) |
|
382 | - { |
|
383 | - return 'yes' == $this->getOption($path); |
|
384 | - } |
|
377 | + /** |
|
378 | + * @param string $path |
|
379 | + * @return bool |
|
380 | + */ |
|
381 | + protected function isOptionEnabled($path) |
|
382 | + { |
|
383 | + return 'yes' == $this->getOption($path); |
|
384 | + } |
|
385 | 385 | |
386 | - /** |
|
387 | - * @return void |
|
388 | - */ |
|
389 | - protected function wrap(array &$renderedFields, Review $review) |
|
390 | - { |
|
391 | - $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this); |
|
392 | - array_walk($renderedFields, function (&$value, $key) use ($review) { |
|
393 | - $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review); |
|
394 | - if (empty($value)) { |
|
395 | - return; |
|
396 | - } |
|
397 | - $value = glsr(Builder::class)->div($value, [ |
|
398 | - 'class' => 'glsr-review-'.$key, |
|
399 | - ]); |
|
400 | - }); |
|
401 | - } |
|
386 | + /** |
|
387 | + * @return void |
|
388 | + */ |
|
389 | + protected function wrap(array &$renderedFields, Review $review) |
|
390 | + { |
|
391 | + $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this); |
|
392 | + array_walk($renderedFields, function (&$value, $key) use ($review) { |
|
393 | + $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review); |
|
394 | + if (empty($value)) { |
|
395 | + return; |
|
396 | + } |
|
397 | + $value = glsr(Builder::class)->div($value, [ |
|
398 | + 'class' => 'glsr-review-'.$key, |
|
399 | + ]); |
|
400 | + }); |
|
401 | + } |
|
402 | 402 | } |
@@ -12,190 +12,190 @@ |
||
12 | 12 | |
13 | 13 | class QueryBuilder |
14 | 14 | { |
15 | - /** |
|
16 | - * Build a WP_Query meta_query/tax_query. |
|
17 | - * @return array |
|
18 | - */ |
|
19 | - public function buildQuery(array $keys = [], array $values = []) |
|
20 | - { |
|
21 | - $queries = []; |
|
22 | - foreach ($keys as $key) { |
|
23 | - if (!array_key_exists($key, $values)) { |
|
24 | - continue; |
|
25 | - } |
|
26 | - $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
27 | - if (!method_exists($this, $methodName)) { |
|
28 | - continue; |
|
29 | - } |
|
30 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
31 | - if (is_array($query)) { |
|
32 | - $queries[] = $query; |
|
33 | - } |
|
34 | - } |
|
35 | - return $queries; |
|
36 | - } |
|
15 | + /** |
|
16 | + * Build a WP_Query meta_query/tax_query. |
|
17 | + * @return array |
|
18 | + */ |
|
19 | + public function buildQuery(array $keys = [], array $values = []) |
|
20 | + { |
|
21 | + $queries = []; |
|
22 | + foreach ($keys as $key) { |
|
23 | + if (!array_key_exists($key, $values)) { |
|
24 | + continue; |
|
25 | + } |
|
26 | + $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
27 | + if (!method_exists($this, $methodName)) { |
|
28 | + continue; |
|
29 | + } |
|
30 | + $query = call_user_func([$this, $methodName], $values[$key]); |
|
31 | + if (is_array($query)) { |
|
32 | + $queries[] = $query; |
|
33 | + } |
|
34 | + } |
|
35 | + return $queries; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function buildSqlLines(array $values, array $conditions) |
|
42 | - { |
|
43 | - $string = ''; |
|
44 | - $values = array_filter($values); |
|
45 | - foreach ($conditions as $key => $value) { |
|
46 | - if (!isset($values[$key])) { |
|
47 | - continue; |
|
48 | - } |
|
49 | - $values[$key] = implode(',', (array) $values[$key]); |
|
50 | - $string.= Str::contains($value, '%s') |
|
51 | - ? sprintf($value, strval($values[$key])) |
|
52 | - : $value; |
|
53 | - } |
|
54 | - return $string; |
|
55 | - } |
|
38 | + /** |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function buildSqlLines(array $values, array $conditions) |
|
42 | + { |
|
43 | + $string = ''; |
|
44 | + $values = array_filter($values); |
|
45 | + foreach ($conditions as $key => $value) { |
|
46 | + if (!isset($values[$key])) { |
|
47 | + continue; |
|
48 | + } |
|
49 | + $values[$key] = implode(',', (array) $values[$key]); |
|
50 | + $string.= Str::contains($value, '%s') |
|
51 | + ? sprintf($value, strval($values[$key])) |
|
52 | + : $value; |
|
53 | + } |
|
54 | + return $string; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Build a SQL 'OR' string from an array. |
|
59 | - * @param string|array $values |
|
60 | - * @param string $sprintfFormat |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function buildSqlOr($values, $sprintfFormat) |
|
64 | - { |
|
65 | - if (!is_array($values)) { |
|
66 | - $values = explode(',', $values); |
|
67 | - } |
|
68 | - $values = array_filter(array_map('trim', (array) $values)); |
|
69 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
70 | - return sprintf($sprintfFormat, $value); |
|
71 | - }, $values); |
|
72 | - return implode(' OR ', $values); |
|
73 | - } |
|
57 | + /** |
|
58 | + * Build a SQL 'OR' string from an array. |
|
59 | + * @param string|array $values |
|
60 | + * @param string $sprintfFormat |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function buildSqlOr($values, $sprintfFormat) |
|
64 | + { |
|
65 | + if (!is_array($values)) { |
|
66 | + $values = explode(',', $values); |
|
67 | + } |
|
68 | + $values = array_filter(array_map('trim', (array) $values)); |
|
69 | + $values = array_map(function ($value) use ($sprintfFormat) { |
|
70 | + return sprintf($sprintfFormat, $value); |
|
71 | + }, $values); |
|
72 | + return implode(' OR ', $values); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Search SQL filter for matching against post title only. |
|
77 | - * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
78 | - * @param string $search |
|
79 | - * @return string |
|
80 | - * @filter posts_search |
|
81 | - */ |
|
82 | - public function filterSearchByTitle($search, WP_Query $query) |
|
83 | - { |
|
84 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
85 | - return $search; |
|
86 | - } |
|
87 | - global $wpdb; |
|
88 | - $n = empty($query->get('exact')) |
|
89 | - ? '%' |
|
90 | - : ''; |
|
91 | - $search = []; |
|
92 | - foreach ((array) $query->get('search_terms') as $term) { |
|
93 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
94 | - } |
|
95 | - if (!is_user_logged_in()) { |
|
96 | - $search[] = "{$wpdb->posts}.post_password = ''"; |
|
97 | - } |
|
98 | - return ' AND '.implode(' AND ', $search); |
|
99 | - } |
|
75 | + /** |
|
76 | + * Search SQL filter for matching against post title only. |
|
77 | + * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
78 | + * @param string $search |
|
79 | + * @return string |
|
80 | + * @filter posts_search |
|
81 | + */ |
|
82 | + public function filterSearchByTitle($search, WP_Query $query) |
|
83 | + { |
|
84 | + if (empty($search) || empty($query->get('search_terms'))) { |
|
85 | + return $search; |
|
86 | + } |
|
87 | + global $wpdb; |
|
88 | + $n = empty($query->get('exact')) |
|
89 | + ? '%' |
|
90 | + : ''; |
|
91 | + $search = []; |
|
92 | + foreach ((array) $query->get('search_terms') as $term) { |
|
93 | + $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
94 | + } |
|
95 | + if (!is_user_logged_in()) { |
|
96 | + $search[] = "{$wpdb->posts}.post_password = ''"; |
|
97 | + } |
|
98 | + return ' AND '.implode(' AND ', $search); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get the current page number from the global query. |
|
103 | - * @param bool $isEnabled |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public function getPaged($isEnabled = true) |
|
107 | - { |
|
108 | - return $isEnabled |
|
109 | - ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR')))) |
|
110 | - : 1; |
|
111 | - } |
|
101 | + /** |
|
102 | + * Get the current page number from the global query. |
|
103 | + * @param bool $isEnabled |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public function getPaged($isEnabled = true) |
|
107 | + { |
|
108 | + return $isEnabled |
|
109 | + ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR')))) |
|
110 | + : 1; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param string $value |
|
115 | - * @return void|array |
|
116 | - */ |
|
117 | - protected function buildQueryAssignedTo($value) |
|
118 | - { |
|
119 | - if (!empty($value)) { |
|
120 | - $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
121 | - return [ |
|
122 | - 'compare' => 'IN', |
|
123 | - 'key' => '_assigned_to', |
|
124 | - 'value' => glsr(Multilingual::class)->getPostIds($postIds), |
|
125 | - ]; |
|
126 | - } |
|
127 | - } |
|
113 | + /** |
|
114 | + * @param string $value |
|
115 | + * @return void|array |
|
116 | + */ |
|
117 | + protected function buildQueryAssignedTo($value) |
|
118 | + { |
|
119 | + if (!empty($value)) { |
|
120 | + $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
121 | + return [ |
|
122 | + 'compare' => 'IN', |
|
123 | + 'key' => '_assigned_to', |
|
124 | + 'value' => glsr(Multilingual::class)->getPostIds($postIds), |
|
125 | + ]; |
|
126 | + } |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @param array $value |
|
131 | - * @return void|array |
|
132 | - */ |
|
133 | - protected function buildQueryCategory($value) |
|
134 | - { |
|
135 | - if (!empty($value)) { |
|
136 | - return [ |
|
137 | - 'field' => 'term_id', |
|
138 | - 'taxonomy' => Application::TAXONOMY, |
|
139 | - 'terms' => $value, |
|
140 | - ]; |
|
141 | - } |
|
142 | - } |
|
129 | + /** |
|
130 | + * @param array $value |
|
131 | + * @return void|array |
|
132 | + */ |
|
133 | + protected function buildQueryCategory($value) |
|
134 | + { |
|
135 | + if (!empty($value)) { |
|
136 | + return [ |
|
137 | + 'field' => 'term_id', |
|
138 | + 'taxonomy' => Application::TAXONOMY, |
|
139 | + 'terms' => $value, |
|
140 | + ]; |
|
141 | + } |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @param string $value |
|
146 | - * @return void|array |
|
147 | - */ |
|
148 | - protected function buildQueryEmail($value) |
|
149 | - { |
|
150 | - if (!empty($value)) { |
|
151 | - return [ |
|
152 | - 'key' => '_email', |
|
153 | - 'value' => $value, |
|
154 | - ]; |
|
155 | - } |
|
156 | - } |
|
144 | + /** |
|
145 | + * @param string $value |
|
146 | + * @return void|array |
|
147 | + */ |
|
148 | + protected function buildQueryEmail($value) |
|
149 | + { |
|
150 | + if (!empty($value)) { |
|
151 | + return [ |
|
152 | + 'key' => '_email', |
|
153 | + 'value' => $value, |
|
154 | + ]; |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * @param string $value |
|
160 | - * @return void|array |
|
161 | - */ |
|
162 | - protected function buildQueryIpAddress($value) |
|
163 | - { |
|
164 | - if (!empty($value)) { |
|
165 | - return [ |
|
166 | - 'key' => '_ip_address', |
|
167 | - 'value' => $value, |
|
168 | - ]; |
|
169 | - } |
|
170 | - } |
|
158 | + /** |
|
159 | + * @param string $value |
|
160 | + * @return void|array |
|
161 | + */ |
|
162 | + protected function buildQueryIpAddress($value) |
|
163 | + { |
|
164 | + if (!empty($value)) { |
|
165 | + return [ |
|
166 | + 'key' => '_ip_address', |
|
167 | + 'value' => $value, |
|
168 | + ]; |
|
169 | + } |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * @param string $value |
|
174 | - * @return void|array |
|
175 | - */ |
|
176 | - protected function buildQueryRating($value) |
|
177 | - { |
|
178 | - if (is_numeric($value) |
|
179 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
180 | - return [ |
|
181 | - 'compare' => '>=', |
|
182 | - 'key' => '_rating', |
|
183 | - 'value' => $value, |
|
184 | - ]; |
|
185 | - } |
|
186 | - } |
|
172 | + /** |
|
173 | + * @param string $value |
|
174 | + * @return void|array |
|
175 | + */ |
|
176 | + protected function buildQueryRating($value) |
|
177 | + { |
|
178 | + if (is_numeric($value) |
|
179 | + && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
180 | + return [ |
|
181 | + 'compare' => '>=', |
|
182 | + 'key' => '_rating', |
|
183 | + 'value' => $value, |
|
184 | + ]; |
|
185 | + } |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * @param string $value |
|
190 | - * @return void|array |
|
191 | - */ |
|
192 | - protected function buildQueryType($value) |
|
193 | - { |
|
194 | - if (!in_array($value, ['', 'all'])) { |
|
195 | - return [ |
|
196 | - 'key' => '_review_type', |
|
197 | - 'value' => $value, |
|
198 | - ]; |
|
199 | - } |
|
200 | - } |
|
188 | + /** |
|
189 | + * @param string $value |
|
190 | + * @return void|array |
|
191 | + */ |
|
192 | + protected function buildQueryType($value) |
|
193 | + { |
|
194 | + if (!in_array($value, ['', 'all'])) { |
|
195 | + return [ |
|
196 | + 'key' => '_review_type', |
|
197 | + 'value' => $value, |
|
198 | + ]; |
|
199 | + } |
|
200 | + } |
|
201 | 201 | } |
@@ -12,385 +12,385 @@ |
||
12 | 12 | |
13 | 13 | class CountsManager |
14 | 14 | { |
15 | - const LIMIT = 500; |
|
16 | - const META_AVERAGE = '_glsr_average'; |
|
17 | - const META_COUNT = '_glsr_count'; |
|
18 | - const META_RANKING = '_glsr_ranking'; |
|
15 | + const LIMIT = 500; |
|
16 | + const META_AVERAGE = '_glsr_average'; |
|
17 | + const META_COUNT = '_glsr_count'; |
|
18 | + const META_RANKING = '_glsr_ranking'; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @return array |
|
22 | - * @todo verify the additional type checks are needed |
|
23 | - */ |
|
24 | - public function buildCounts(array $args = []) |
|
25 | - { |
|
26 | - $counts = []; |
|
27 | - $query = $this->queryReviews($args); |
|
28 | - while ($query) { |
|
29 | - $types = array_keys(array_flip(glsr_array_column($query->reviews, 'type'))); |
|
30 | - $types = array_unique(array_merge(['local'], $types)); |
|
31 | - foreach ($types as $type) { |
|
32 | - $type = $this->normalizeType($type); |
|
33 | - if (isset($counts[$type])) { |
|
34 | - continue; |
|
35 | - } |
|
36 | - $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
37 | - } |
|
38 | - foreach ($query->reviews as $review) { |
|
39 | - $type = $this->normalizeType($review->type); |
|
40 | - ++$counts[$type][$review->rating]; |
|
41 | - } |
|
42 | - $query = $query->has_more |
|
43 | - ? $this->queryReviews($args, end($query->reviews)->ID) |
|
44 | - : false; |
|
45 | - } |
|
46 | - return $counts; |
|
47 | - } |
|
20 | + /** |
|
21 | + * @return array |
|
22 | + * @todo verify the additional type checks are needed |
|
23 | + */ |
|
24 | + public function buildCounts(array $args = []) |
|
25 | + { |
|
26 | + $counts = []; |
|
27 | + $query = $this->queryReviews($args); |
|
28 | + while ($query) { |
|
29 | + $types = array_keys(array_flip(glsr_array_column($query->reviews, 'type'))); |
|
30 | + $types = array_unique(array_merge(['local'], $types)); |
|
31 | + foreach ($types as $type) { |
|
32 | + $type = $this->normalizeType($type); |
|
33 | + if (isset($counts[$type])) { |
|
34 | + continue; |
|
35 | + } |
|
36 | + $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
37 | + } |
|
38 | + foreach ($query->reviews as $review) { |
|
39 | + $type = $this->normalizeType($review->type); |
|
40 | + ++$counts[$type][$review->rating]; |
|
41 | + } |
|
42 | + $query = $query->has_more |
|
43 | + ? $this->queryReviews($args, end($query->reviews)->ID) |
|
44 | + : false; |
|
45 | + } |
|
46 | + return $counts; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param int $postId |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - public function buildPostCounts($postId) |
|
54 | - { |
|
55 | - return $this->buildCounts(['post_ids' => [$postId]]); |
|
56 | - } |
|
49 | + /** |
|
50 | + * @param int $postId |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + public function buildPostCounts($postId) |
|
54 | + { |
|
55 | + return $this->buildCounts(['post_ids' => [$postId]]); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param int $termTaxonomyId |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function buildTermCounts($termTaxonomyId) |
|
63 | - { |
|
64 | - return $this->buildCounts(['term_ids' => [$termTaxonomyId]]); |
|
65 | - } |
|
58 | + /** |
|
59 | + * @param int $termTaxonomyId |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function buildTermCounts($termTaxonomyId) |
|
63 | + { |
|
64 | + return $this->buildCounts(['term_ids' => [$termTaxonomyId]]); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public function countAll() |
|
71 | - { |
|
72 | - $terms = glsr(Database::class)->getTerms(['fields' => 'all']); |
|
73 | - foreach ($terms as $term) { |
|
74 | - $this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id)); |
|
75 | - } |
|
76 | - $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
77 | - foreach ($postIds as $postId) { |
|
78 | - $this->setPostCounts($postId, $this->buildPostCounts($postId)); |
|
79 | - } |
|
80 | - $this->setCounts($this->buildCounts()); |
|
81 | - } |
|
67 | + /** |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public function countAll() |
|
71 | + { |
|
72 | + $terms = glsr(Database::class)->getTerms(['fields' => 'all']); |
|
73 | + foreach ($terms as $term) { |
|
74 | + $this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id)); |
|
75 | + } |
|
76 | + $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
77 | + foreach ($postIds as $postId) { |
|
78 | + $this->setPostCounts($postId, $this->buildPostCounts($postId)); |
|
79 | + } |
|
80 | + $this->setCounts($this->buildCounts()); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public function decrease(Review $review) |
|
87 | - { |
|
88 | - $this->decreaseCounts($review); |
|
89 | - $this->decreasePostCounts($review); |
|
90 | - $this->decreaseTermCounts($review); |
|
91 | - } |
|
83 | + /** |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public function decrease(Review $review) |
|
87 | + { |
|
88 | + $this->decreaseCounts($review); |
|
89 | + $this->decreasePostCounts($review); |
|
90 | + $this->decreaseTermCounts($review); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function decreaseCounts(Review $review) |
|
97 | - { |
|
98 | - $this->setCounts($this->decreaseRating( |
|
99 | - $this->getCounts(), |
|
100 | - $review->review_type, |
|
101 | - $review->rating |
|
102 | - )); |
|
103 | - } |
|
93 | + /** |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function decreaseCounts(Review $review) |
|
97 | + { |
|
98 | + $this->setCounts($this->decreaseRating( |
|
99 | + $this->getCounts(), |
|
100 | + $review->review_type, |
|
101 | + $review->rating |
|
102 | + )); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function decreasePostCounts(Review $review) |
|
109 | - { |
|
110 | - if (empty($counts = $this->getPostCounts($review->assigned_to))) { |
|
111 | - return; |
|
112 | - } |
|
113 | - $counts = $this->decreaseRating($counts, $review->review_type, $review->rating); |
|
114 | - $this->setPostCounts($review->assigned_to, $counts); |
|
115 | - } |
|
105 | + /** |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function decreasePostCounts(Review $review) |
|
109 | + { |
|
110 | + if (empty($counts = $this->getPostCounts($review->assigned_to))) { |
|
111 | + return; |
|
112 | + } |
|
113 | + $counts = $this->decreaseRating($counts, $review->review_type, $review->rating); |
|
114 | + $this->setPostCounts($review->assigned_to, $counts); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function decreaseTermCounts(Review $review) |
|
121 | - { |
|
122 | - foreach ($review->term_ids as $termId) { |
|
123 | - if (empty($counts = $this->getTermCounts($termId))) { |
|
124 | - continue; |
|
125 | - } |
|
126 | - $counts = $this->decreaseRating($counts, $review->review_type, $review->rating); |
|
127 | - $this->setTermCounts($termId, $counts); |
|
128 | - } |
|
129 | - } |
|
117 | + /** |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function decreaseTermCounts(Review $review) |
|
121 | + { |
|
122 | + foreach ($review->term_ids as $termId) { |
|
123 | + if (empty($counts = $this->getTermCounts($termId))) { |
|
124 | + continue; |
|
125 | + } |
|
126 | + $counts = $this->decreaseRating($counts, $review->review_type, $review->rating); |
|
127 | + $this->setTermCounts($termId, $counts); |
|
128 | + } |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @return array |
|
133 | - */ |
|
134 | - public function flatten(array $reviewCounts, array $args = []) |
|
135 | - { |
|
136 | - $counts = []; |
|
137 | - array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
138 | - $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
139 | - }); |
|
140 | - $args = wp_parse_args($args, [ |
|
141 | - 'max' => glsr()->constant('MAX_RATING', Rating::class), |
|
142 | - 'min' => glsr()->constant('MIN_RATING', Rating::class), |
|
143 | - ]); |
|
144 | - foreach ($counts as $index => &$num) { |
|
145 | - if ($index >= intval($args['min']) && $index <= intval($args['max'])) { |
|
146 | - continue; |
|
147 | - } |
|
148 | - $num = 0; |
|
149 | - } |
|
150 | - return $counts; |
|
151 | - } |
|
131 | + /** |
|
132 | + * @return array |
|
133 | + */ |
|
134 | + public function flatten(array $reviewCounts, array $args = []) |
|
135 | + { |
|
136 | + $counts = []; |
|
137 | + array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
138 | + $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
139 | + }); |
|
140 | + $args = wp_parse_args($args, [ |
|
141 | + 'max' => glsr()->constant('MAX_RATING', Rating::class), |
|
142 | + 'min' => glsr()->constant('MIN_RATING', Rating::class), |
|
143 | + ]); |
|
144 | + foreach ($counts as $index => &$num) { |
|
145 | + if ($index >= intval($args['min']) && $index <= intval($args['max'])) { |
|
146 | + continue; |
|
147 | + } |
|
148 | + $num = 0; |
|
149 | + } |
|
150 | + return $counts; |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - public function get(array $args = []) |
|
157 | - { |
|
158 | - $args = $this->normalizeArgs($args); |
|
159 | - $counts = []; |
|
160 | - if ($this->isMixedCount($args)) { |
|
161 | - $counts = [$this->buildCounts($args)]; // force query the database |
|
162 | - } else { |
|
163 | - foreach ($args['post_ids'] as $postId) { |
|
164 | - $counts[] = $this->getPostCounts($postId); |
|
165 | - } |
|
166 | - foreach ($args['term_ids'] as $termId) { |
|
167 | - $counts[] = $this->getTermCounts($termId); |
|
168 | - } |
|
169 | - if (empty($counts)) { |
|
170 | - $counts[] = $this->getCounts(); |
|
171 | - } |
|
172 | - } |
|
173 | - return in_array($args['type'], ['', 'all']) |
|
174 | - ? $this->normalize([$this->flatten($counts)]) |
|
175 | - : $this->normalize(glsr_array_column($counts, $args['type'])); |
|
176 | - } |
|
153 | + /** |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + public function get(array $args = []) |
|
157 | + { |
|
158 | + $args = $this->normalizeArgs($args); |
|
159 | + $counts = []; |
|
160 | + if ($this->isMixedCount($args)) { |
|
161 | + $counts = [$this->buildCounts($args)]; // force query the database |
|
162 | + } else { |
|
163 | + foreach ($args['post_ids'] as $postId) { |
|
164 | + $counts[] = $this->getPostCounts($postId); |
|
165 | + } |
|
166 | + foreach ($args['term_ids'] as $termId) { |
|
167 | + $counts[] = $this->getTermCounts($termId); |
|
168 | + } |
|
169 | + if (empty($counts)) { |
|
170 | + $counts[] = $this->getCounts(); |
|
171 | + } |
|
172 | + } |
|
173 | + return in_array($args['type'], ['', 'all']) |
|
174 | + ? $this->normalize([$this->flatten($counts)]) |
|
175 | + : $this->normalize(glsr_array_column($counts, $args['type'])); |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * @return array |
|
180 | - */ |
|
181 | - public function getCounts() |
|
182 | - { |
|
183 | - $counts = glsr(OptionManager::class)->get('counts', []); |
|
184 | - if (!is_array($counts)) { |
|
185 | - glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
186 | - return []; |
|
187 | - } |
|
188 | - return $counts; |
|
189 | - } |
|
178 | + /** |
|
179 | + * @return array |
|
180 | + */ |
|
181 | + public function getCounts() |
|
182 | + { |
|
183 | + $counts = glsr(OptionManager::class)->get('counts', []); |
|
184 | + if (!is_array($counts)) { |
|
185 | + glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
186 | + return []; |
|
187 | + } |
|
188 | + return $counts; |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * @param int $postId |
|
193 | - * @return array |
|
194 | - */ |
|
195 | - public function getPostCounts($postId) |
|
196 | - { |
|
197 | - return array_filter((array) get_post_meta($postId, static::META_COUNT, true)); |
|
198 | - } |
|
191 | + /** |
|
192 | + * @param int $postId |
|
193 | + * @return array |
|
194 | + */ |
|
195 | + public function getPostCounts($postId) |
|
196 | + { |
|
197 | + return array_filter((array) get_post_meta($postId, static::META_COUNT, true)); |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * @param int $termId |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function getTermCounts($termId) |
|
205 | - { |
|
206 | - return array_filter((array) get_term_meta($termId, static::META_COUNT, true)); |
|
207 | - } |
|
200 | + /** |
|
201 | + * @param int $termId |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function getTermCounts($termId) |
|
205 | + { |
|
206 | + return array_filter((array) get_term_meta($termId, static::META_COUNT, true)); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * @return void |
|
211 | - */ |
|
212 | - public function increase(Review $review) |
|
213 | - { |
|
214 | - $this->increaseCounts($review); |
|
215 | - $this->increasePostCounts($review); |
|
216 | - $this->increaseTermCounts($review); |
|
217 | - } |
|
209 | + /** |
|
210 | + * @return void |
|
211 | + */ |
|
212 | + public function increase(Review $review) |
|
213 | + { |
|
214 | + $this->increaseCounts($review); |
|
215 | + $this->increasePostCounts($review); |
|
216 | + $this->increaseTermCounts($review); |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * @return void |
|
221 | - */ |
|
222 | - public function increaseCounts(Review $review) |
|
223 | - { |
|
224 | - if (empty($counts = $this->getCounts())) { |
|
225 | - $counts = $this->buildCounts(); |
|
226 | - } |
|
227 | - $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating)); |
|
228 | - } |
|
219 | + /** |
|
220 | + * @return void |
|
221 | + */ |
|
222 | + public function increaseCounts(Review $review) |
|
223 | + { |
|
224 | + if (empty($counts = $this->getCounts())) { |
|
225 | + $counts = $this->buildCounts(); |
|
226 | + } |
|
227 | + $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating)); |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - public function increasePostCounts(Review $review) |
|
234 | - { |
|
235 | - if (!(get_post($review->assigned_to) instanceof WP_Post)) { |
|
236 | - return; |
|
237 | - } |
|
238 | - $counts = $this->getPostCounts($review->assigned_to); |
|
239 | - $counts = empty($counts) |
|
240 | - ? $this->buildPostCounts($review->assigned_to) |
|
241 | - : $this->increaseRating($counts, $review->review_type, $review->rating); |
|
242 | - $this->setPostCounts($review->assigned_to, $counts); |
|
243 | - } |
|
230 | + /** |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + public function increasePostCounts(Review $review) |
|
234 | + { |
|
235 | + if (!(get_post($review->assigned_to) instanceof WP_Post)) { |
|
236 | + return; |
|
237 | + } |
|
238 | + $counts = $this->getPostCounts($review->assigned_to); |
|
239 | + $counts = empty($counts) |
|
240 | + ? $this->buildPostCounts($review->assigned_to) |
|
241 | + : $this->increaseRating($counts, $review->review_type, $review->rating); |
|
242 | + $this->setPostCounts($review->assigned_to, $counts); |
|
243 | + } |
|
244 | 244 | |
245 | - /** |
|
246 | - * @return void |
|
247 | - */ |
|
248 | - public function increaseTermCounts(Review $review) |
|
249 | - { |
|
250 | - $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
251 | - foreach ($terms as $term) { |
|
252 | - $counts = $this->getTermCounts($term['term_id']); |
|
253 | - $counts = empty($counts) |
|
254 | - ? $this->buildTermCounts($term['term_taxonomy_id']) |
|
255 | - : $this->increaseRating($counts, $review->review_type, $review->rating); |
|
256 | - $this->setTermCounts($term['term_id'], $counts); |
|
257 | - } |
|
258 | - } |
|
245 | + /** |
|
246 | + * @return void |
|
247 | + */ |
|
248 | + public function increaseTermCounts(Review $review) |
|
249 | + { |
|
250 | + $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
251 | + foreach ($terms as $term) { |
|
252 | + $counts = $this->getTermCounts($term['term_id']); |
|
253 | + $counts = empty($counts) |
|
254 | + ? $this->buildTermCounts($term['term_taxonomy_id']) |
|
255 | + : $this->increaseRating($counts, $review->review_type, $review->rating); |
|
256 | + $this->setTermCounts($term['term_id'], $counts); |
|
257 | + } |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * @return void |
|
262 | - */ |
|
263 | - public function setCounts(array $reviewCounts) |
|
264 | - { |
|
265 | - glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
266 | - } |
|
260 | + /** |
|
261 | + * @return void |
|
262 | + */ |
|
263 | + public function setCounts(array $reviewCounts) |
|
264 | + { |
|
265 | + glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
266 | + } |
|
267 | 267 | |
268 | - /** |
|
269 | - * @param int $postId |
|
270 | - * @return void |
|
271 | - */ |
|
272 | - public function setPostCounts($postId, array $reviewCounts) |
|
273 | - { |
|
274 | - $ratingCounts = $this->flatten($reviewCounts); |
|
275 | - update_post_meta($postId, static::META_COUNT, $reviewCounts); |
|
276 | - update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
277 | - update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
278 | - } |
|
268 | + /** |
|
269 | + * @param int $postId |
|
270 | + * @return void |
|
271 | + */ |
|
272 | + public function setPostCounts($postId, array $reviewCounts) |
|
273 | + { |
|
274 | + $ratingCounts = $this->flatten($reviewCounts); |
|
275 | + update_post_meta($postId, static::META_COUNT, $reviewCounts); |
|
276 | + update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
277 | + update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * @param int $termId |
|
282 | - * @return void |
|
283 | - */ |
|
284 | - public function setTermCounts($termId, array $reviewCounts) |
|
285 | - { |
|
286 | - $term = get_term($termId, Application::TAXONOMY); |
|
287 | - if (!isset($term->term_id)) { |
|
288 | - return; |
|
289 | - } |
|
290 | - $ratingCounts = $this->flatten($reviewCounts); |
|
291 | - update_term_meta($termId, static::META_COUNT, $reviewCounts); |
|
292 | - update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
293 | - update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
294 | - } |
|
280 | + /** |
|
281 | + * @param int $termId |
|
282 | + * @return void |
|
283 | + */ |
|
284 | + public function setTermCounts($termId, array $reviewCounts) |
|
285 | + { |
|
286 | + $term = get_term($termId, Application::TAXONOMY); |
|
287 | + if (!isset($term->term_id)) { |
|
288 | + return; |
|
289 | + } |
|
290 | + $ratingCounts = $this->flatten($reviewCounts); |
|
291 | + update_term_meta($termId, static::META_COUNT, $reviewCounts); |
|
292 | + update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
293 | + update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * @param string $type |
|
298 | - * @param int $rating |
|
299 | - * @return array |
|
300 | - */ |
|
301 | - protected function decreaseRating(array $reviewCounts, $type, $rating) |
|
302 | - { |
|
303 | - if (isset($reviewCounts[$type][$rating])) { |
|
304 | - $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
305 | - } |
|
306 | - return $reviewCounts; |
|
307 | - } |
|
296 | + /** |
|
297 | + * @param string $type |
|
298 | + * @param int $rating |
|
299 | + * @return array |
|
300 | + */ |
|
301 | + protected function decreaseRating(array $reviewCounts, $type, $rating) |
|
302 | + { |
|
303 | + if (isset($reviewCounts[$type][$rating])) { |
|
304 | + $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
305 | + } |
|
306 | + return $reviewCounts; |
|
307 | + } |
|
308 | 308 | |
309 | - /** |
|
310 | - * @param string $type |
|
311 | - * @param int $rating |
|
312 | - * @return array |
|
313 | - */ |
|
314 | - protected function increaseRating(array $reviewCounts, $type, $rating) |
|
315 | - { |
|
316 | - if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
317 | - return $reviewCounts; |
|
318 | - } |
|
319 | - if (!array_key_exists($type, $reviewCounts)) { |
|
320 | - $reviewCounts[$type] = []; |
|
321 | - } |
|
322 | - $reviewCounts = $this->normalize($reviewCounts); |
|
323 | - $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
324 | - return $reviewCounts; |
|
325 | - } |
|
309 | + /** |
|
310 | + * @param string $type |
|
311 | + * @param int $rating |
|
312 | + * @return array |
|
313 | + */ |
|
314 | + protected function increaseRating(array $reviewCounts, $type, $rating) |
|
315 | + { |
|
316 | + if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
317 | + return $reviewCounts; |
|
318 | + } |
|
319 | + if (!array_key_exists($type, $reviewCounts)) { |
|
320 | + $reviewCounts[$type] = []; |
|
321 | + } |
|
322 | + $reviewCounts = $this->normalize($reviewCounts); |
|
323 | + $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
324 | + return $reviewCounts; |
|
325 | + } |
|
326 | 326 | |
327 | - /** |
|
328 | - * @return bool |
|
329 | - */ |
|
330 | - protected function isMixedCount(array $args) |
|
331 | - { |
|
332 | - return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
333 | - } |
|
327 | + /** |
|
328 | + * @return bool |
|
329 | + */ |
|
330 | + protected function isMixedCount(array $args) |
|
331 | + { |
|
332 | + return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
333 | + } |
|
334 | 334 | |
335 | - /** |
|
336 | - * @return array |
|
337 | - */ |
|
338 | - protected function normalize(array $reviewCounts) |
|
339 | - { |
|
340 | - if (empty($reviewCounts)) { |
|
341 | - $reviewCounts = [[]]; |
|
342 | - } |
|
343 | - foreach ($reviewCounts as &$counts) { |
|
344 | - foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) { |
|
345 | - if (isset($counts[$index])) { |
|
346 | - continue; |
|
347 | - } |
|
348 | - $counts[$index] = 0; |
|
349 | - } |
|
350 | - ksort($counts); |
|
351 | - } |
|
352 | - return $reviewCounts; |
|
353 | - } |
|
335 | + /** |
|
336 | + * @return array |
|
337 | + */ |
|
338 | + protected function normalize(array $reviewCounts) |
|
339 | + { |
|
340 | + if (empty($reviewCounts)) { |
|
341 | + $reviewCounts = [[]]; |
|
342 | + } |
|
343 | + foreach ($reviewCounts as &$counts) { |
|
344 | + foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) { |
|
345 | + if (isset($counts[$index])) { |
|
346 | + continue; |
|
347 | + } |
|
348 | + $counts[$index] = 0; |
|
349 | + } |
|
350 | + ksort($counts); |
|
351 | + } |
|
352 | + return $reviewCounts; |
|
353 | + } |
|
354 | 354 | |
355 | - /** |
|
356 | - * @return array |
|
357 | - */ |
|
358 | - protected function normalizeArgs(array $args) |
|
359 | - { |
|
360 | - $args = wp_parse_args(array_filter($args), [ |
|
361 | - 'post_ids' => [], |
|
362 | - 'term_ids' => [], |
|
363 | - 'type' => 'local', |
|
364 | - ]); |
|
365 | - $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
366 | - $args['type'] = $this->normalizeType($args['type']); |
|
367 | - return $args; |
|
368 | - } |
|
355 | + /** |
|
356 | + * @return array |
|
357 | + */ |
|
358 | + protected function normalizeArgs(array $args) |
|
359 | + { |
|
360 | + $args = wp_parse_args(array_filter($args), [ |
|
361 | + 'post_ids' => [], |
|
362 | + 'term_ids' => [], |
|
363 | + 'type' => 'local', |
|
364 | + ]); |
|
365 | + $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
366 | + $args['type'] = $this->normalizeType($args['type']); |
|
367 | + return $args; |
|
368 | + } |
|
369 | 369 | |
370 | - /** |
|
371 | - * @param string $type |
|
372 | - * @return string |
|
373 | - */ |
|
374 | - protected function normalizeType($type) |
|
375 | - { |
|
376 | - return empty($type) || !is_string($type) |
|
377 | - ? 'local' |
|
378 | - : $type; |
|
379 | - } |
|
370 | + /** |
|
371 | + * @param string $type |
|
372 | + * @return string |
|
373 | + */ |
|
374 | + protected function normalizeType($type) |
|
375 | + { |
|
376 | + return empty($type) || !is_string($type) |
|
377 | + ? 'local' |
|
378 | + : $type; |
|
379 | + } |
|
380 | 380 | |
381 | - /** |
|
382 | - * @param int $lastPostId |
|
383 | - * @return object |
|
384 | - */ |
|
385 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
386 | - { |
|
387 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
388 | - $hasMore = is_array($reviews) |
|
389 | - ? count($reviews) == static::LIMIT |
|
390 | - : false; |
|
391 | - return (object) [ |
|
392 | - 'has_more' => $hasMore, |
|
393 | - 'reviews' => $reviews, |
|
394 | - ]; |
|
395 | - } |
|
381 | + /** |
|
382 | + * @param int $lastPostId |
|
383 | + * @return object |
|
384 | + */ |
|
385 | + protected function queryReviews(array $args = [], $lastPostId = 0) |
|
386 | + { |
|
387 | + $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
388 | + $hasMore = is_array($reviews) |
|
389 | + ? count($reviews) == static::LIMIT |
|
390 | + : false; |
|
391 | + return (object) [ |
|
392 | + 'has_more' => $hasMore, |
|
393 | + 'reviews' => $reviews, |
|
394 | + ]; |
|
395 | + } |
|
396 | 396 | } |
@@ -7,83 +7,83 @@ |
||
7 | 7 | |
8 | 8 | class Wpml implements Contract |
9 | 9 | { |
10 | - public $pluginName = 'WPML'; |
|
11 | - public $supportedVersion = '3.3.5'; |
|
10 | + public $pluginName = 'WPML'; |
|
11 | + public $supportedVersion = '3.3.5'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * {@inheritdoc} |
|
15 | - */ |
|
16 | - public function getPost($postId) |
|
17 | - { |
|
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
20 | - return; |
|
21 | - } |
|
22 | - if ($this->isEnabled()) { |
|
23 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
24 | - } |
|
25 | - return get_post(intval($postId)); |
|
26 | - } |
|
13 | + /** |
|
14 | + * {@inheritdoc} |
|
15 | + */ |
|
16 | + public function getPost($postId) |
|
17 | + { |
|
18 | + $postId = trim($postId); |
|
19 | + if (!is_numeric($postId)) { |
|
20 | + return; |
|
21 | + } |
|
22 | + if ($this->isEnabled()) { |
|
23 | + $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
24 | + } |
|
25 | + return get_post(intval($postId)); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - public function getPostIds(array $postIds) |
|
32 | - { |
|
33 | - if (!$this->isEnabled()) { |
|
34 | - return $postIds; |
|
35 | - } |
|
36 | - $newPostIds = []; |
|
37 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
38 | - $postType = get_post_type($postId); |
|
39 | - if (!$postType) { |
|
40 | - continue; |
|
41 | - } |
|
42 | - $elementType = 'post_'.$postType; |
|
43 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
44 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
45 | - if (!is_array($translations)) { |
|
46 | - $translations = []; |
|
47 | - } |
|
48 | - $newPostIds = array_merge( |
|
49 | - $newPostIds, |
|
50 | - array_column($translations, 'element_id') |
|
51 | - ); |
|
52 | - } |
|
53 | - return $this->cleanIds($newPostIds); |
|
54 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + public function getPostIds(array $postIds) |
|
32 | + { |
|
33 | + if (!$this->isEnabled()) { |
|
34 | + return $postIds; |
|
35 | + } |
|
36 | + $newPostIds = []; |
|
37 | + foreach ($this->cleanIds($postIds) as $postId) { |
|
38 | + $postType = get_post_type($postId); |
|
39 | + if (!$postType) { |
|
40 | + continue; |
|
41 | + } |
|
42 | + $elementType = 'post_'.$postType; |
|
43 | + $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
44 | + $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
45 | + if (!is_array($translations)) { |
|
46 | + $translations = []; |
|
47 | + } |
|
48 | + $newPostIds = array_merge( |
|
49 | + $newPostIds, |
|
50 | + array_column($translations, 'element_id') |
|
51 | + ); |
|
52 | + } |
|
53 | + return $this->cleanIds($newPostIds); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - public function isActive() |
|
60 | - { |
|
61 | - return defined('ICL_SITEPRESS_VERSION'); |
|
62 | - } |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + public function isActive() |
|
60 | + { |
|
61 | + return defined('ICL_SITEPRESS_VERSION'); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - public function isEnabled() |
|
68 | - { |
|
69 | - return $this->isActive() |
|
70 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
71 | - } |
|
64 | + /** |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + public function isEnabled() |
|
68 | + { |
|
69 | + return $this->isActive() |
|
70 | + && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * {@inheritdoc} |
|
75 | - */ |
|
76 | - public function isSupported() |
|
77 | - { |
|
78 | - return $this->isActive() |
|
79 | - && version_compare(ICL_SITEPRESS_VERSION, $this->supportedVersion, '>='); |
|
80 | - } |
|
73 | + /** |
|
74 | + * {@inheritdoc} |
|
75 | + */ |
|
76 | + public function isSupported() |
|
77 | + { |
|
78 | + return $this->isActive() |
|
79 | + && version_compare(ICL_SITEPRESS_VERSION, $this->supportedVersion, '>='); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - protected function cleanIds(array $postIds) |
|
86 | - { |
|
87 | - return array_filter(array_unique($postIds)); |
|
88 | - } |
|
82 | + /** |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + protected function cleanIds(array $postIds) |
|
86 | + { |
|
87 | + return array_filter(array_unique($postIds)); |
|
88 | + } |
|
89 | 89 | } |
@@ -7,79 +7,79 @@ |
||
7 | 7 | |
8 | 8 | class Polylang implements Contract |
9 | 9 | { |
10 | - public $pluginName = 'Polylang'; |
|
11 | - public $supportedVersion = '2.3'; |
|
10 | + public $pluginName = 'Polylang'; |
|
11 | + public $supportedVersion = '2.3'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * {@inheritdoc} |
|
15 | - */ |
|
16 | - public function getPost($postId) |
|
17 | - { |
|
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
20 | - return; |
|
21 | - } |
|
22 | - if ($this->isEnabled()) { |
|
23 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | - } |
|
25 | - if (!empty($polylangPostId)) { |
|
26 | - $postId = $polylangPostId; |
|
27 | - } |
|
28 | - return get_post(intval($postId)); |
|
29 | - } |
|
13 | + /** |
|
14 | + * {@inheritdoc} |
|
15 | + */ |
|
16 | + public function getPost($postId) |
|
17 | + { |
|
18 | + $postId = trim($postId); |
|
19 | + if (!is_numeric($postId)) { |
|
20 | + return; |
|
21 | + } |
|
22 | + if ($this->isEnabled()) { |
|
23 | + $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | + } |
|
25 | + if (!empty($polylangPostId)) { |
|
26 | + $postId = $polylangPostId; |
|
27 | + } |
|
28 | + return get_post(intval($postId)); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - public function getPostIds(array $postIds) |
|
35 | - { |
|
36 | - if (!$this->isEnabled()) { |
|
37 | - return $postIds; |
|
38 | - } |
|
39 | - $newPostIds = []; |
|
40 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
41 | - $newPostIds = array_merge( |
|
42 | - $newPostIds, |
|
43 | - array_values(pll_get_post_translations($postId)) |
|
44 | - ); |
|
45 | - } |
|
46 | - return $this->cleanIds($newPostIds); |
|
47 | - } |
|
31 | + /** |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + public function getPostIds(array $postIds) |
|
35 | + { |
|
36 | + if (!$this->isEnabled()) { |
|
37 | + return $postIds; |
|
38 | + } |
|
39 | + $newPostIds = []; |
|
40 | + foreach ($this->cleanIds($postIds) as $postId) { |
|
41 | + $newPostIds = array_merge( |
|
42 | + $newPostIds, |
|
43 | + array_values(pll_get_post_translations($postId)) |
|
44 | + ); |
|
45 | + } |
|
46 | + return $this->cleanIds($newPostIds); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function isActive() |
|
53 | - { |
|
54 | - return function_exists('PLL') |
|
55 | - && function_exists('pll_get_post') |
|
56 | - && function_exists('pll_get_post_language') |
|
57 | - && function_exists('pll_get_post_translations'); |
|
58 | - } |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function isActive() |
|
53 | + { |
|
54 | + return function_exists('PLL') |
|
55 | + && function_exists('pll_get_post') |
|
56 | + && function_exists('pll_get_post_language') |
|
57 | + && function_exists('pll_get_post_translations'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inheritdoc} |
|
62 | - */ |
|
63 | - public function isEnabled() |
|
64 | - { |
|
65 | - return $this->isActive() |
|
66 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
67 | - } |
|
60 | + /** |
|
61 | + * {@inheritdoc} |
|
62 | + */ |
|
63 | + public function isEnabled() |
|
64 | + { |
|
65 | + return $this->isActive() |
|
66 | + && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * {@inheritdoc} |
|
71 | - */ |
|
72 | - public function isSupported() |
|
73 | - { |
|
74 | - return defined('POLYLANG_VERSION') |
|
75 | - && version_compare(POLYLANG_VERSION, $this->supportedVersion, '>='); |
|
76 | - } |
|
69 | + /** |
|
70 | + * {@inheritdoc} |
|
71 | + */ |
|
72 | + public function isSupported() |
|
73 | + { |
|
74 | + return defined('POLYLANG_VERSION') |
|
75 | + && version_compare(POLYLANG_VERSION, $this->supportedVersion, '>='); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - protected function cleanIds(array $postIds) |
|
82 | - { |
|
83 | - return array_filter(array_unique($postIds)); |
|
84 | - } |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + protected function cleanIds(array $postIds) |
|
82 | + { |
|
83 | + return array_filter(array_unique($postIds)); |
|
84 | + } |
|
85 | 85 | } |
@@ -9,121 +9,121 @@ |
||
9 | 9 | |
10 | 10 | class SettingsController extends Controller |
11 | 11 | { |
12 | - /** |
|
13 | - * @param mixed $input |
|
14 | - * @return array |
|
15 | - * @callback register_setting |
|
16 | - */ |
|
17 | - public function callbackRegisterSettings($input) |
|
18 | - { |
|
19 | - $settings = Arr::consolidateArray($input); |
|
20 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
21 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
22 | - $options = $this->sanitizeGeneral($input, $options); |
|
23 | - $options = $this->sanitizeSubmissions($input, $options); |
|
24 | - $options = $this->sanitizeTranslations($input, $options); |
|
25 | - $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
26 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
27 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
28 | - } |
|
29 | - return $options; |
|
30 | - } |
|
31 | - return $input; |
|
32 | - } |
|
12 | + /** |
|
13 | + * @param mixed $input |
|
14 | + * @return array |
|
15 | + * @callback register_setting |
|
16 | + */ |
|
17 | + public function callbackRegisterSettings($input) |
|
18 | + { |
|
19 | + $settings = Arr::consolidateArray($input); |
|
20 | + if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
21 | + $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
22 | + $options = $this->sanitizeGeneral($input, $options); |
|
23 | + $options = $this->sanitizeSubmissions($input, $options); |
|
24 | + $options = $this->sanitizeTranslations($input, $options); |
|
25 | + $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
26 | + if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
27 | + glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
28 | + } |
|
29 | + return $options; |
|
30 | + } |
|
31 | + return $input; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @return void |
|
36 | - * @action admin_init |
|
37 | - */ |
|
38 | - public function registerSettings() |
|
39 | - { |
|
40 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
41 | - 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
42 | - ]); |
|
43 | - } |
|
34 | + /** |
|
35 | + * @return void |
|
36 | + * @action admin_init |
|
37 | + */ |
|
38 | + public function registerSettings() |
|
39 | + { |
|
40 | + register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
41 | + 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
42 | + ]); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - protected function sanitizeGeneral(array $input, array $options) |
|
49 | - { |
|
50 | - $key = 'settings.general'; |
|
51 | - $inputForm = Arr::get($input, $key); |
|
52 | - if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
53 | - $options = Arr::set($options, $key.'.multilingual', ''); |
|
54 | - } |
|
55 | - if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
56 | - $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
57 | - $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
58 | - } |
|
59 | - $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
60 | - $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
61 | - return $options; |
|
62 | - } |
|
45 | + /** |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + protected function sanitizeGeneral(array $input, array $options) |
|
49 | + { |
|
50 | + $key = 'settings.general'; |
|
51 | + $inputForm = Arr::get($input, $key); |
|
52 | + if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
53 | + $options = Arr::set($options, $key.'.multilingual', ''); |
|
54 | + } |
|
55 | + if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
56 | + $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
57 | + $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
58 | + } |
|
59 | + $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
60 | + $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
61 | + return $options; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - protected function sanitizeSubmissions(array $input, array $options) |
|
68 | - { |
|
69 | - $key = 'settings.submissions'; |
|
70 | - $inputForm = Arr::get($input, $key); |
|
71 | - $defaultValue = isset($inputForm['required']) |
|
72 | - ? $inputForm['required'] |
|
73 | - : []; |
|
74 | - $options = Arr::set($options, $key.'.required', $defaultValue); |
|
75 | - return $options; |
|
76 | - } |
|
64 | + /** |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + protected function sanitizeSubmissions(array $input, array $options) |
|
68 | + { |
|
69 | + $key = 'settings.submissions'; |
|
70 | + $inputForm = Arr::get($input, $key); |
|
71 | + $defaultValue = isset($inputForm['required']) |
|
72 | + ? $inputForm['required'] |
|
73 | + : []; |
|
74 | + $options = Arr::set($options, $key.'.required', $defaultValue); |
|
75 | + return $options; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - protected function sanitizeTranslations(array $input, array $options) |
|
82 | - { |
|
83 | - $key = 'settings.strings'; |
|
84 | - $inputForm = Arr::consolidateArray(Arr::get($input, $key)); |
|
85 | - if (!empty($inputForm)) { |
|
86 | - $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
87 | - $allowedTags = [ |
|
88 | - 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
89 | - 'span' => ['class' => []], |
|
90 | - ]; |
|
91 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
92 | - if (isset($string['s2'])) { |
|
93 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
94 | - } |
|
95 | - if (isset($string['p2'])) { |
|
96 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
97 | - } |
|
98 | - }); |
|
99 | - } |
|
100 | - return $options; |
|
101 | - } |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + protected function sanitizeTranslations(array $input, array $options) |
|
82 | + { |
|
83 | + $key = 'settings.strings'; |
|
84 | + $inputForm = Arr::consolidateArray(Arr::get($input, $key)); |
|
85 | + if (!empty($inputForm)) { |
|
86 | + $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
87 | + $allowedTags = [ |
|
88 | + 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
89 | + 'span' => ['class' => []], |
|
90 | + ]; |
|
91 | + array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
92 | + if (isset($string['s2'])) { |
|
93 | + $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
94 | + } |
|
95 | + if (isset($string['p2'])) { |
|
96 | + $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
97 | + } |
|
98 | + }); |
|
99 | + } |
|
100 | + return $options; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @param string $integrationSlug |
|
105 | - * @return bool |
|
106 | - */ |
|
107 | - protected function hasMultilingualIntegration($integrationSlug) |
|
108 | - { |
|
109 | - $integration = glsr(Multilingual::class)->getIntegration($integrationSlug); |
|
110 | - if (!$integration) { |
|
111 | - return false; |
|
112 | - } |
|
113 | - if (!$integration->isActive()) { |
|
114 | - glsr(Notice::class)->addError(sprintf( |
|
115 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
116 | - $integration->pluginName |
|
117 | - )); |
|
118 | - return false; |
|
119 | - } elseif (!$integration->isSupported()) { |
|
120 | - glsr(Notice::class)->addError(sprintf( |
|
121 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
122 | - $integration->pluginName, |
|
123 | - $integration->supportedVersion |
|
124 | - )); |
|
125 | - return false; |
|
126 | - } |
|
127 | - return true; |
|
128 | - } |
|
103 | + /** |
|
104 | + * @param string $integrationSlug |
|
105 | + * @return bool |
|
106 | + */ |
|
107 | + protected function hasMultilingualIntegration($integrationSlug) |
|
108 | + { |
|
109 | + $integration = glsr(Multilingual::class)->getIntegration($integrationSlug); |
|
110 | + if (!$integration) { |
|
111 | + return false; |
|
112 | + } |
|
113 | + if (!$integration->isActive()) { |
|
114 | + glsr(Notice::class)->addError(sprintf( |
|
115 | + __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
116 | + $integration->pluginName |
|
117 | + )); |
|
118 | + return false; |
|
119 | + } elseif (!$integration->isSupported()) { |
|
120 | + glsr(Notice::class)->addError(sprintf( |
|
121 | + __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
122 | + $integration->pluginName, |
|
123 | + $integration->supportedVersion |
|
124 | + )); |
|
125 | + return false; |
|
126 | + } |
|
127 | + return true; |
|
128 | + } |
|
129 | 129 | } |
@@ -7,87 +7,87 @@ |
||
7 | 7 | |
8 | 8 | class Multilingual implements Contract |
9 | 9 | { |
10 | - protected $integration; |
|
10 | + protected $integration; |
|
11 | 11 | |
12 | - /** |
|
13 | - * @param string $integration |
|
14 | - * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml |
|
15 | - */ |
|
16 | - public function getIntegration($integration = '') |
|
17 | - { |
|
18 | - if (empty($integration)) { |
|
19 | - $integration = ucfirst(glsr(OptionManager::class)->get('settings.general.multilingual')); |
|
20 | - } |
|
21 | - $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.$integration; |
|
22 | - if (class_exists($integrationClass)) { |
|
23 | - return glsr($integrationClass); |
|
24 | - } |
|
25 | - glsr_log()->error($integrationClass.' does not exist'); |
|
26 | - return false; |
|
27 | - } |
|
12 | + /** |
|
13 | + * @param string $integration |
|
14 | + * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml |
|
15 | + */ |
|
16 | + public function getIntegration($integration = '') |
|
17 | + { |
|
18 | + if (empty($integration)) { |
|
19 | + $integration = ucfirst(glsr(OptionManager::class)->get('settings.general.multilingual')); |
|
20 | + } |
|
21 | + $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.$integration; |
|
22 | + if (class_exists($integrationClass)) { |
|
23 | + return glsr($integrationClass); |
|
24 | + } |
|
25 | + glsr_log()->error($integrationClass.' does not exist'); |
|
26 | + return false; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * {@inheritdoc} |
|
31 | - */ |
|
32 | - public function getPost($postId) |
|
33 | - { |
|
34 | - return $this->isIntegrated() |
|
35 | - ? $this->integration->getPostIds($postId) |
|
36 | - : $postId; |
|
37 | - } |
|
29 | + /** |
|
30 | + * {@inheritdoc} |
|
31 | + */ |
|
32 | + public function getPost($postId) |
|
33 | + { |
|
34 | + return $this->isIntegrated() |
|
35 | + ? $this->integration->getPostIds($postId) |
|
36 | + : $postId; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * {@inheritdoc} |
|
41 | - */ |
|
42 | - public function getPostIds(array $postIds) |
|
43 | - { |
|
44 | - return $this->isIntegrated() |
|
45 | - ? $this->integration->getPostIds($postIds) |
|
46 | - : $postIds; |
|
47 | - } |
|
39 | + /** |
|
40 | + * {@inheritdoc} |
|
41 | + */ |
|
42 | + public function getPostIds(array $postIds) |
|
43 | + { |
|
44 | + return $this->isIntegrated() |
|
45 | + ? $this->integration->getPostIds($postIds) |
|
46 | + : $postIds; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function isActive() |
|
53 | - { |
|
54 | - return $this->isIntegrated() |
|
55 | - ? $this->integration->isActive() |
|
56 | - : false; |
|
57 | - } |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function isActive() |
|
53 | + { |
|
54 | + return $this->isIntegrated() |
|
55 | + ? $this->integration->isActive() |
|
56 | + : false; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inheritdoc} |
|
61 | - */ |
|
62 | - public function isEnabled() |
|
63 | - { |
|
64 | - return $this->isIntegrated() |
|
65 | - ? $this->integration->isEnabled() |
|
66 | - : false; |
|
67 | - } |
|
59 | + /** |
|
60 | + * {@inheritdoc} |
|
61 | + */ |
|
62 | + public function isEnabled() |
|
63 | + { |
|
64 | + return $this->isIntegrated() |
|
65 | + ? $this->integration->isEnabled() |
|
66 | + : false; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * {@inheritdoc} |
|
71 | - */ |
|
72 | - public function isSupported() |
|
73 | - { |
|
74 | - return $this->isIntegrated() |
|
75 | - ? $this->integration->isSupported() |
|
76 | - : false; |
|
77 | - } |
|
69 | + /** |
|
70 | + * {@inheritdoc} |
|
71 | + */ |
|
72 | + public function isSupported() |
|
73 | + { |
|
74 | + return $this->isIntegrated() |
|
75 | + ? $this->integration->isSupported() |
|
76 | + : false; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * return bool |
|
81 | - */ |
|
82 | - protected function isIntegrated() |
|
83 | - { |
|
84 | - if (!empty($this->integration)) { |
|
85 | - return true; |
|
86 | - } |
|
87 | - if ($integration = $this->getIntegration()) { |
|
88 | - $this->integration = $integration; |
|
89 | - return true; |
|
90 | - } |
|
91 | - return false; |
|
92 | - } |
|
79 | + /** |
|
80 | + * return bool |
|
81 | + */ |
|
82 | + protected function isIntegrated() |
|
83 | + { |
|
84 | + if (!empty($this->integration)) { |
|
85 | + return true; |
|
86 | + } |
|
87 | + if ($integration = $this->getIntegration()) { |
|
88 | + $this->integration = $integration; |
|
89 | + return true; |
|
90 | + } |
|
91 | + return false; |
|
92 | + } |
|
93 | 93 | } |