@@ -15,14 +15,20 @@ |
||
15 | 15 | <span class="glsr-addon-link button button-secondary" disabled> |
16 | 16 | <?= __('Installed', 'site-reviews'); ?> |
17 | 17 | </span> |
18 | - <?php else: ?> |
|
19 | - <a href="<?= wp_nonce_url(self_admin_url('plugins.php?action=activate&plugin='.$plugin), 'activate-plugin_'.$plugin); ?>" class="glsr-addon-link button button-secondary"> |
|
18 | + <?php else { |
|
19 | + : ?> |
|
20 | + <a href="<?= wp_nonce_url(self_admin_url('plugins.php?action=activate&plugin='.$plugin), 'activate-plugin_'.$plugin); |
|
21 | +} |
|
22 | +?>" class="glsr-addon-link button button-secondary"> |
|
20 | 23 | <?= __('Activate', 'site-reviews'); ?> |
21 | 24 | </a> |
22 | 25 | <?php endif; ?> |
23 | - <?php else: ?> |
|
26 | + <?php else { |
|
27 | + : ?> |
|
24 | 28 | <a href="{{ link }}" class="glsr-addon-link glsr-external button button-secondary"> |
25 | - <?= __('More Info', 'site-reviews'); ?> |
|
29 | + <?= __('More Info', 'site-reviews'); |
|
30 | +} |
|
31 | +?> |
|
26 | 32 | </a> |
27 | 33 | <?php endif; ?> |
28 | 34 | </div> |
@@ -130,7 +130,8 @@ |
||
130 | 130 | $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
131 | 131 | if (!empty($template)) { |
132 | 132 | $message = glsr(Template::class)->interpolate($template, $this->email['template-tags'], $this->email['template']); |
133 | - } elseif ($this->email['template']) { |
|
133 | + } |
|
134 | + elseif ($this->email['template']) { |
|
134 | 135 | $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
135 | 136 | 'context' => $this->email['template-tags'], |
136 | 137 | ]); |
@@ -216,7 +216,8 @@ |
||
216 | 216 | if (!empty($field['label'])) { |
217 | 217 | $field['legend'] = $field['label']; |
218 | 218 | unset($field['label']); |
219 | - } else { |
|
219 | + } |
|
220 | + else { |
|
220 | 221 | $field['is_valid'] = false; |
221 | 222 | glsr_log()->warning('Setting field is missing a label')->debug($field); |
222 | 223 | } |
@@ -328,7 +328,8 @@ |
||
328 | 328 | } |
329 | 329 | if (is_array($params[0])) { |
330 | 330 | $this->args += $params[0]; |
331 | - } elseif (is_array($params[1])) { |
|
331 | + } |
|
332 | + elseif (is_array($params[1])) { |
|
332 | 333 | $this->args += $params[1]; |
333 | 334 | } |
334 | 335 | if (!isset($this->args['is_public'])) { |
@@ -302,7 +302,8 @@ |
||
302 | 302 | } |
303 | 303 | if (in_array($field->field['type'], ['radio', 'checkbox'])) { |
304 | 304 | $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
305 | - } else { |
|
305 | + } |
|
306 | + else { |
|
306 | 307 | $field->field['value'] = $this->values[$field->field['path']]; |
307 | 308 | } |
308 | 309 | } |
@@ -73,7 +73,8 @@ discard block |
||
73 | 73 | foreach ($potEntries as $key => $entry) { |
74 | 74 | $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
75 | 75 | } |
76 | - } catch (Exception $e) { |
|
76 | + } |
|
77 | + catch (Exception $e) { |
|
77 | 78 | glsr_log()->error($e->getMessage()); |
78 | 79 | } |
79 | 80 | return $entries; |
@@ -196,7 +197,8 @@ discard block |
||
196 | 197 | if (in_array($needle, [$single, $plural])) { |
197 | 198 | $this->results[$key] = $entry; |
198 | 199 | } |
199 | - } elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) { |
|
200 | + } |
|
201 | + elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) { |
|
200 | 202 | $this->results[$key] = $entry; |
201 | 203 | } |
202 | 204 | } |
@@ -242,7 +244,8 @@ discard block |
||
242 | 244 | foreach ($keys as $key) { |
243 | 245 | try { |
244 | 246 | $entry = $this->normalizeEntryString($entry, $key); |
245 | - } catch (\TypeError $error) { |
|
247 | + } |
|
248 | + catch (\TypeError $error) { |
|
246 | 249 | glsr_log()->once('error', 'Translation/normalize', $error); |
247 | 250 | glsr_log()->once('debug', 'Translation/normalize', $entry); |
248 | 251 | } |
@@ -415,7 +415,8 @@ |
||
415 | 415 | { |
416 | 416 | if ($value instanceof DateTime) { |
417 | 417 | $value = $value->format('Y-m-d H:i:s'); |
418 | - } elseif ($this->isObjectOrArray($value)) { |
|
418 | + } |
|
419 | + elseif ($this->isObjectOrArray($value)) { |
|
419 | 420 | $value = json_encode($value); |
420 | 421 | } |
421 | 422 | return (string) $value; |
@@ -185,7 +185,8 @@ |
||
185 | 185 | $hasNumeric = $this->hasRule($attribute, $this->numericRules); |
186 | 186 | if (is_numeric($value) && $hasNumeric) { |
187 | 187 | return $value; |
188 | - } elseif (is_array($value)) { |
|
188 | + } |
|
189 | + elseif (is_array($value)) { |
|
189 | 190 | return count($value); |
190 | 191 | } |
191 | 192 | return function_exists('mb_strlen') |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @todo verify the additional type checks are needed |
22 | 22 | */ |
23 | 23 | public function buildCounts(array $args = []) |
24 | - { |
|
24 | + { |
|
25 | 25 | $counts = []; |
26 | 26 | $query = $this->queryReviews($args); |
27 | 27 | while ($query) { |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @return array |
52 | 52 | */ |
53 | 53 | public function buildPostCounts($postId) |
54 | - { |
|
54 | + { |
|
55 | 55 | return $this->buildCounts(['post_ids' => [$postId]]); |
56 | 56 | } |
57 | 57 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return array |
61 | 61 | */ |
62 | 62 | public function buildTermCounts($termTaxonomyId) |
63 | - { |
|
63 | + { |
|
64 | 64 | return $this->buildCounts(['term_ids' => [$termTaxonomyId]]); |
65 | 65 | } |
66 | 66 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @return void |
85 | 85 | */ |
86 | 86 | public function decrease(Review $review) |
87 | - { |
|
87 | + { |
|
88 | 88 | $this->decreaseCounts($review); |
89 | 89 | $this->decreasePostCounts($review); |
90 | 90 | $this->decreaseTermCounts($review); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @return void |
95 | 95 | */ |
96 | 96 | public function decreaseCounts(Review $review) |
97 | - { |
|
97 | + { |
|
98 | 98 | $this->setCounts($this->decreaseRating( |
99 | 99 | $this->getCounts(), |
100 | 100 | $review->review_type, |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @return void |
107 | 107 | */ |
108 | 108 | public function decreasePostCounts(Review $review) |
109 | - { |
|
109 | + { |
|
110 | 110 | if (empty($counts = $this->getPostCounts($review->assigned_to))) { |
111 | 111 | return; |
112 | 112 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @return void |
119 | 119 | */ |
120 | 120 | public function decreaseTermCounts(Review $review) |
121 | - { |
|
121 | + { |
|
122 | 122 | foreach ($review->term_ids as $termId) { |
123 | 123 | if (empty($counts = $this->getTermCounts($termId))) { |
124 | 124 | continue; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @return array |
133 | 133 | */ |
134 | 134 | public function flatten(array $reviewCounts, array $args = []) |
135 | - { |
|
135 | + { |
|
136 | 136 | $counts = []; |
137 | 137 | array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
138 | 138 | $counts[$index] = $num + intval(glsr_get($counts, $index, 0)); |
@@ -154,12 +154,13 @@ discard block |
||
154 | 154 | * @return array |
155 | 155 | */ |
156 | 156 | public function get(array $args = []) |
157 | - { |
|
157 | + { |
|
158 | 158 | $args = $this->normalizeArgs($args); |
159 | 159 | $counts = []; |
160 | 160 | if ($this->isMixedCount($args)) { |
161 | 161 | $counts = [$this->buildCounts($args)]; // force query the database |
162 | - } else { |
|
162 | + } |
|
163 | + else { |
|
163 | 164 | foreach ($args['post_ids'] as $postId) { |
164 | 165 | $counts[] = $this->getPostCounts($postId); |
165 | 166 | } |
@@ -193,7 +194,7 @@ discard block |
||
193 | 194 | * @return array |
194 | 195 | */ |
195 | 196 | public function getPostCounts($postId) |
196 | - { |
|
197 | + { |
|
197 | 198 | return array_filter((array) get_post_meta($postId, static::META_COUNT, true)); |
198 | 199 | } |
199 | 200 | |
@@ -202,7 +203,7 @@ discard block |
||
202 | 203 | * @return array |
203 | 204 | */ |
204 | 205 | public function getTermCounts($termId) |
205 | - { |
|
206 | + { |
|
206 | 207 | return array_filter((array) get_term_meta($termId, static::META_COUNT, true)); |
207 | 208 | } |
208 | 209 | |
@@ -210,7 +211,7 @@ discard block |
||
210 | 211 | * @return void |
211 | 212 | */ |
212 | 213 | public function increase(Review $review) |
213 | - { |
|
214 | + { |
|
214 | 215 | $this->increaseCounts($review); |
215 | 216 | $this->increasePostCounts($review); |
216 | 217 | $this->increaseTermCounts($review); |
@@ -220,7 +221,7 @@ discard block |
||
220 | 221 | * @return void |
221 | 222 | */ |
222 | 223 | public function increaseCounts(Review $review) |
223 | - { |
|
224 | + { |
|
224 | 225 | if (empty($counts = $this->getCounts())) { |
225 | 226 | $counts = $this->buildCounts(); |
226 | 227 | } |
@@ -231,7 +232,7 @@ discard block |
||
231 | 232 | * @return void |
232 | 233 | */ |
233 | 234 | public function increasePostCounts(Review $review) |
234 | - { |
|
235 | + { |
|
235 | 236 | if (!(get_post($review->assigned_to) instanceof WP_Post)) { |
236 | 237 | return; |
237 | 238 | } |
@@ -246,7 +247,7 @@ discard block |
||
246 | 247 | * @return void |
247 | 248 | */ |
248 | 249 | public function increaseTermCounts(Review $review) |
249 | - { |
|
250 | + { |
|
250 | 251 | $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
251 | 252 | foreach ($terms as $term) { |
252 | 253 | $counts = $this->getTermCounts($term['term_id']); |
@@ -261,7 +262,7 @@ discard block |
||
261 | 262 | * @return void |
262 | 263 | */ |
263 | 264 | public function setCounts(array $reviewCounts) |
264 | - { |
|
265 | + { |
|
265 | 266 | glsr(OptionManager::class)->set('counts', $reviewCounts); |
266 | 267 | } |
267 | 268 | |
@@ -270,7 +271,7 @@ discard block |
||
270 | 271 | * @return void |
271 | 272 | */ |
272 | 273 | public function setPostCounts($postId, array $reviewCounts) |
273 | - { |
|
274 | + { |
|
274 | 275 | $ratingCounts = $this->flatten($reviewCounts); |
275 | 276 | update_post_meta($postId, static::META_COUNT, $reviewCounts); |
276 | 277 | update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
@@ -282,7 +283,7 @@ discard block |
||
282 | 283 | * @return void |
283 | 284 | */ |
284 | 285 | public function setTermCounts($termId, array $reviewCounts) |
285 | - { |
|
286 | + { |
|
286 | 287 | $term = get_term($termId, Application::TAXONOMY); |
287 | 288 | if (!isset($term->term_id)) { |
288 | 289 | return; |
@@ -299,7 +300,7 @@ discard block |
||
299 | 300 | * @return array |
300 | 301 | */ |
301 | 302 | protected function decreaseRating(array $reviewCounts, $type, $rating) |
302 | - { |
|
303 | + { |
|
303 | 304 | if (isset($reviewCounts[$type][$rating])) { |
304 | 305 | $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
305 | 306 | } |
@@ -312,7 +313,7 @@ discard block |
||
312 | 313 | * @return array |
313 | 314 | */ |
314 | 315 | protected function increaseRating(array $reviewCounts, $type, $rating) |
315 | - { |
|
316 | + { |
|
316 | 317 | if (!array_key_exists($type, glsr()->reviewTypes)) { |
317 | 318 | return $reviewCounts; |
318 | 319 | } |
@@ -328,7 +329,7 @@ discard block |
||
328 | 329 | * @return bool |
329 | 330 | */ |
330 | 331 | protected function isMixedCount(array $args) |
331 | - { |
|
332 | + { |
|
332 | 333 | return !empty($args['post_ids']) && !empty($args['term_ids']); |
333 | 334 | } |
334 | 335 | |
@@ -336,7 +337,7 @@ discard block |
||
336 | 337 | * @return array |
337 | 338 | */ |
338 | 339 | protected function normalize(array $reviewCounts) |
339 | - { |
|
340 | + { |
|
340 | 341 | if (empty($reviewCounts)) { |
341 | 342 | $reviewCounts = [[]]; |
342 | 343 | } |
@@ -356,7 +357,7 @@ discard block |
||
356 | 357 | * @return array |
357 | 358 | */ |
358 | 359 | protected function normalizeArgs(array $args) |
359 | - { |
|
360 | + { |
|
360 | 361 | $args = wp_parse_args(array_filter($args), [ |
361 | 362 | 'post_ids' => [], |
362 | 363 | 'term_ids' => [], |
@@ -372,7 +373,7 @@ discard block |
||
372 | 373 | * @return string |
373 | 374 | */ |
374 | 375 | protected function normalizeType($type) |
375 | - { |
|
376 | + { |
|
376 | 377 | return empty($type) || !is_string($type) |
377 | 378 | ? 'local' |
378 | 379 | : $type; |
@@ -383,7 +384,7 @@ discard block |
||
383 | 384 | * @return object |
384 | 385 | */ |
385 | 386 | protected function queryReviews(array $args = [], $lastPostId = 0) |
386 | - { |
|
387 | + { |
|
387 | 388 | $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
388 | 389 | $hasMore = is_array($reviews) |
389 | 390 | ? count($reviews) == static::LIMIT |