@@ -7,73 +7,73 @@ |
||
7 | 7 | |
8 | 8 | class GlobalCountsManager |
9 | 9 | { |
10 | - /** |
|
11 | - * @var CountsManager |
|
12 | - */ |
|
13 | - protected $manager; |
|
10 | + /** |
|
11 | + * @var CountsManager |
|
12 | + */ |
|
13 | + protected $manager; |
|
14 | 14 | |
15 | - public function __construct() |
|
16 | - { |
|
17 | - $this->manager = glsr(CountsManager::class); |
|
18 | - } |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + $this->manager = glsr(CountsManager::class); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @return array |
|
22 | - */ |
|
23 | - public function build() |
|
24 | - { |
|
25 | - return $this->manager->buildCounts(); |
|
26 | - } |
|
20 | + /** |
|
21 | + * @return array |
|
22 | + */ |
|
23 | + public function build() |
|
24 | + { |
|
25 | + return $this->manager->buildCounts(); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function decrease(Review $review) |
|
32 | - { |
|
33 | - $this->update($this->manager->decreaseRating( |
|
34 | - $this->get(), |
|
35 | - $review->review_type, |
|
36 | - $review->rating |
|
37 | - )); |
|
38 | - } |
|
28 | + /** |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function decrease(Review $review) |
|
32 | + { |
|
33 | + $this->update($this->manager->decreaseRating( |
|
34 | + $this->get(), |
|
35 | + $review->review_type, |
|
36 | + $review->rating |
|
37 | + )); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public function get() |
|
44 | - { |
|
45 | - $counts = glsr(OptionManager::class)->get('counts', []); |
|
46 | - if (!is_array($counts)) { |
|
47 | - glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
48 | - return []; |
|
49 | - } |
|
50 | - return $counts; |
|
51 | - } |
|
40 | + /** |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public function get() |
|
44 | + { |
|
45 | + $counts = glsr(OptionManager::class)->get('counts', []); |
|
46 | + if (!is_array($counts)) { |
|
47 | + glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
48 | + return []; |
|
49 | + } |
|
50 | + return $counts; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function increase(Review $review) |
|
57 | - { |
|
58 | - if (empty($counts = $this->get())) { |
|
59 | - $counts = $this->build(); |
|
60 | - } |
|
61 | - $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating)); |
|
62 | - } |
|
53 | + /** |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function increase(Review $review) |
|
57 | + { |
|
58 | + if (empty($counts = $this->get())) { |
|
59 | + $counts = $this->build(); |
|
60 | + } |
|
61 | + $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating)); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - public function update(array $reviewCounts) |
|
68 | - { |
|
69 | - glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + public function update(array $reviewCounts) |
|
68 | + { |
|
69 | + glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function updateAll() |
|
76 | - { |
|
77 | - $this->update($this->build()); |
|
78 | - } |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function updateAll() |
|
76 | + { |
|
77 | + $this->update($this->build()); |
|
78 | + } |
|
79 | 79 | } |
@@ -16,159 +16,159 @@ |
||
16 | 16 | |
17 | 17 | class ReviewController extends Controller |
18 | 18 | { |
19 | - /** |
|
20 | - * Triggered when a category is added to a review. |
|
21 | - * |
|
22 | - * @param int $postId |
|
23 | - * @param array $terms |
|
24 | - * @param array $newTTIds |
|
25 | - * @param string $taxonomy |
|
26 | - * @param bool $append |
|
27 | - * @param array $oldTTIds |
|
28 | - * @return void |
|
29 | - * @action set_object_terms |
|
30 | - */ |
|
31 | - public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
32 | - { |
|
33 | - sort($newTTIds); |
|
34 | - sort($oldTTIds); |
|
35 | - if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
36 | - return; |
|
37 | - } |
|
38 | - $review = glsr_get_review($postId); |
|
39 | - if ('publish' !== $review->status) { |
|
40 | - return; |
|
41 | - } |
|
42 | - $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
43 | - $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
44 | - $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
45 | - if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
46 | - glsr(TermCountsManager::class)->decrease($review); |
|
47 | - } |
|
48 | - if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
49 | - glsr(TermCountsManager::class)->increase($review); |
|
50 | - } |
|
51 | - } |
|
19 | + /** |
|
20 | + * Triggered when a category is added to a review. |
|
21 | + * |
|
22 | + * @param int $postId |
|
23 | + * @param array $terms |
|
24 | + * @param array $newTTIds |
|
25 | + * @param string $taxonomy |
|
26 | + * @param bool $append |
|
27 | + * @param array $oldTTIds |
|
28 | + * @return void |
|
29 | + * @action set_object_terms |
|
30 | + */ |
|
31 | + public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
32 | + { |
|
33 | + sort($newTTIds); |
|
34 | + sort($oldTTIds); |
|
35 | + if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
36 | + return; |
|
37 | + } |
|
38 | + $review = glsr_get_review($postId); |
|
39 | + if ('publish' !== $review->status) { |
|
40 | + return; |
|
41 | + } |
|
42 | + $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
43 | + $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
44 | + $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
45 | + if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
46 | + glsr(TermCountsManager::class)->decrease($review); |
|
47 | + } |
|
48 | + if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
49 | + glsr(TermCountsManager::class)->increase($review); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Triggered when an existing review is approved|unapproved. |
|
55 | - * |
|
56 | - * @param string $oldStatus |
|
57 | - * @param string $newStatus |
|
58 | - * @param \WP_Post $post |
|
59 | - * @return void |
|
60 | - * @action transition_post_status |
|
61 | - */ |
|
62 | - public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
63 | - { |
|
64 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') |
|
65 | - || in_array($oldStatus, ['new', $newStatus])) { |
|
66 | - return; |
|
67 | - } |
|
68 | - $review = glsr_get_review($post); |
|
69 | - if ('publish' == $post->post_status) { |
|
70 | - glsr(CountsManager::class)->increaseAll($review); |
|
71 | - } else { |
|
72 | - glsr(CountsManager::class)->decreaseAll($review); |
|
73 | - } |
|
74 | - } |
|
53 | + /** |
|
54 | + * Triggered when an existing review is approved|unapproved. |
|
55 | + * |
|
56 | + * @param string $oldStatus |
|
57 | + * @param string $newStatus |
|
58 | + * @param \WP_Post $post |
|
59 | + * @return void |
|
60 | + * @action transition_post_status |
|
61 | + */ |
|
62 | + public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
63 | + { |
|
64 | + if (Application::POST_TYPE != Arr::get($post, 'post_type') |
|
65 | + || in_array($oldStatus, ['new', $newStatus])) { |
|
66 | + return; |
|
67 | + } |
|
68 | + $review = glsr_get_review($post); |
|
69 | + if ('publish' == $post->post_status) { |
|
70 | + glsr(CountsManager::class)->increaseAll($review); |
|
71 | + } else { |
|
72 | + glsr(CountsManager::class)->decreaseAll($review); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Triggered when a review is first created. |
|
78 | - * |
|
79 | - * @return void |
|
80 | - * @action site-reviews/review/created |
|
81 | - */ |
|
82 | - public function onAfterCreate(Review $review) |
|
83 | - { |
|
84 | - if ('publish' !== $review->status) { |
|
85 | - return; |
|
86 | - } |
|
87 | - glsr(GlobalCountsManager::class)->increase($review); |
|
88 | - glsr(PostCountsManager::class)->increase($review); |
|
89 | - } |
|
76 | + /** |
|
77 | + * Triggered when a review is first created. |
|
78 | + * |
|
79 | + * @return void |
|
80 | + * @action site-reviews/review/created |
|
81 | + */ |
|
82 | + public function onAfterCreate(Review $review) |
|
83 | + { |
|
84 | + if ('publish' !== $review->status) { |
|
85 | + return; |
|
86 | + } |
|
87 | + glsr(GlobalCountsManager::class)->increase($review); |
|
88 | + glsr(PostCountsManager::class)->increase($review); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Triggered when a review is deleted. |
|
93 | - * |
|
94 | - * @param int $postId |
|
95 | - * @return void |
|
96 | - * @action before_delete_post |
|
97 | - */ |
|
98 | - public function onBeforeDelete($postId) |
|
99 | - { |
|
100 | - if (!$this->isReviewPostId($postId)) { |
|
101 | - return; |
|
102 | - } |
|
103 | - $review = glsr_get_review($postId); |
|
104 | - if ('trash' !== $review->status) { // do not run for trashed posts |
|
105 | - glsr(CountsManager::class)->decreaseAll($review); |
|
106 | - } |
|
107 | - } |
|
91 | + /** |
|
92 | + * Triggered when a review is deleted. |
|
93 | + * |
|
94 | + * @param int $postId |
|
95 | + * @return void |
|
96 | + * @action before_delete_post |
|
97 | + */ |
|
98 | + public function onBeforeDelete($postId) |
|
99 | + { |
|
100 | + if (!$this->isReviewPostId($postId)) { |
|
101 | + return; |
|
102 | + } |
|
103 | + $review = glsr_get_review($postId); |
|
104 | + if ('trash' !== $review->status) { // do not run for trashed posts |
|
105 | + glsr(CountsManager::class)->decreaseAll($review); |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Triggered when a review's rating, assigned_to, or review_type is changed. |
|
111 | - * |
|
112 | - * @param int $metaId |
|
113 | - * @param int $postId |
|
114 | - * @param string $metaKey |
|
115 | - * @param mixed $metaValue |
|
116 | - * @return void |
|
117 | - * @action update_postmeta |
|
118 | - */ |
|
119 | - public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
120 | - { |
|
121 | - if (!$this->isReviewPostId($postId)) { |
|
122 | - return; |
|
123 | - } |
|
124 | - $metaKey = Str::removePrefix('_', $metaKey); |
|
125 | - if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
126 | - return; |
|
127 | - } |
|
128 | - $review = glsr_get_review($postId); |
|
129 | - if ($review->$metaKey == $metaValue) { |
|
130 | - return; |
|
131 | - } |
|
132 | - $method = Helper::buildMethodName($metaKey, 'onBeforeChange'); |
|
133 | - call_user_func([$this, $method], $review, $metaValue); |
|
134 | - } |
|
109 | + /** |
|
110 | + * Triggered when a review's rating, assigned_to, or review_type is changed. |
|
111 | + * |
|
112 | + * @param int $metaId |
|
113 | + * @param int $postId |
|
114 | + * @param string $metaKey |
|
115 | + * @param mixed $metaValue |
|
116 | + * @return void |
|
117 | + * @action update_postmeta |
|
118 | + */ |
|
119 | + public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
120 | + { |
|
121 | + if (!$this->isReviewPostId($postId)) { |
|
122 | + return; |
|
123 | + } |
|
124 | + $metaKey = Str::removePrefix('_', $metaKey); |
|
125 | + if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
126 | + return; |
|
127 | + } |
|
128 | + $review = glsr_get_review($postId); |
|
129 | + if ($review->$metaKey == $metaValue) { |
|
130 | + return; |
|
131 | + } |
|
132 | + $method = Helper::buildMethodName($metaKey, 'onBeforeChange'); |
|
133 | + call_user_func([$this, $method], $review, $metaValue); |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Triggered by the onBeforeUpdate method. |
|
138 | - * |
|
139 | - * @param string|int $assignedTo |
|
140 | - * @return void |
|
141 | - */ |
|
142 | - protected function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
143 | - { |
|
144 | - glsr(PostCountsManager::class)->decrease($review); |
|
145 | - $review->assigned_to = $assignedTo; |
|
146 | - glsr(PostCountsManager::class)->increase($review); |
|
147 | - } |
|
136 | + /** |
|
137 | + * Triggered by the onBeforeUpdate method. |
|
138 | + * |
|
139 | + * @param string|int $assignedTo |
|
140 | + * @return void |
|
141 | + */ |
|
142 | + protected function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
143 | + { |
|
144 | + glsr(PostCountsManager::class)->decrease($review); |
|
145 | + $review->assigned_to = $assignedTo; |
|
146 | + glsr(PostCountsManager::class)->increase($review); |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Triggered by the onBeforeUpdate method. |
|
151 | - * |
|
152 | - * @param string|int $rating |
|
153 | - * @return void |
|
154 | - */ |
|
155 | - protected function onBeforeChangeRating(Review $review, $rating) |
|
156 | - { |
|
157 | - glsr(CountsManager::class)->decreaseAll($review); |
|
158 | - $review->rating = $rating; |
|
159 | - glsr(CountsManager::class)->increaseAll($review); |
|
160 | - } |
|
149 | + /** |
|
150 | + * Triggered by the onBeforeUpdate method. |
|
151 | + * |
|
152 | + * @param string|int $rating |
|
153 | + * @return void |
|
154 | + */ |
|
155 | + protected function onBeforeChangeRating(Review $review, $rating) |
|
156 | + { |
|
157 | + glsr(CountsManager::class)->decreaseAll($review); |
|
158 | + $review->rating = $rating; |
|
159 | + glsr(CountsManager::class)->increaseAll($review); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Triggered by the onBeforeUpdate method. |
|
164 | - * |
|
165 | - * @param string $reviewType |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - protected function onBeforeChangeReviewType(Review $review, $reviewType) |
|
169 | - { |
|
170 | - glsr(CountsManager::class)->decreaseAll($review); |
|
171 | - $review->review_type = $reviewType; |
|
172 | - glsr(CountsManager::class)->increaseAll($review); |
|
173 | - } |
|
162 | + /** |
|
163 | + * Triggered by the onBeforeUpdate method. |
|
164 | + * |
|
165 | + * @param string $reviewType |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + protected function onBeforeChangeReviewType(Review $review, $reviewType) |
|
169 | + { |
|
170 | + glsr(CountsManager::class)->decreaseAll($review); |
|
171 | + $review->review_type = $reviewType; |
|
172 | + glsr(CountsManager::class)->increaseAll($review); |
|
173 | + } |
|
174 | 174 | } |
@@ -12,377 +12,377 @@ |
||
12 | 12 | |
13 | 13 | class System |
14 | 14 | { |
15 | - const PAD = 40; |
|
15 | + const PAD = 40; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function __toString() |
|
21 | - { |
|
22 | - return $this->get(); |
|
23 | - } |
|
17 | + /** |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function __toString() |
|
21 | + { |
|
22 | + return $this->get(); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function get() |
|
29 | - { |
|
30 | - $details = [ |
|
31 | - 'plugin' => 'Plugin Details', |
|
32 | - 'addon' => 'Addon Details', |
|
33 | - 'browser' => 'Browser Details', |
|
34 | - 'server' => 'Server Details', |
|
35 | - 'php' => 'PHP Configuration', |
|
36 | - 'wordpress' => 'WordPress Configuration', |
|
37 | - 'mu-plugin' => 'Must-Use Plugins', |
|
38 | - 'multisite-plugin' => 'Network Active Plugins', |
|
39 | - 'active-plugin' => 'Active Plugins', |
|
40 | - 'inactive-plugin' => 'Inactive Plugins', |
|
41 | - 'setting' => 'Plugin Settings', |
|
42 | - 'reviews' => 'Review Counts', |
|
43 | - ]; |
|
44 | - $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
45 | - $methodName = Helper::buildMethodName('get-'.$key.'-details'); |
|
46 | - if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
47 | - return $carry.$this->implode( |
|
48 | - strtoupper($details[$key]), |
|
49 | - apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
50 | - ); |
|
51 | - } |
|
52 | - return $carry; |
|
53 | - }); |
|
54 | - return trim($systemInfo); |
|
55 | - } |
|
25 | + /** |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function get() |
|
29 | + { |
|
30 | + $details = [ |
|
31 | + 'plugin' => 'Plugin Details', |
|
32 | + 'addon' => 'Addon Details', |
|
33 | + 'browser' => 'Browser Details', |
|
34 | + 'server' => 'Server Details', |
|
35 | + 'php' => 'PHP Configuration', |
|
36 | + 'wordpress' => 'WordPress Configuration', |
|
37 | + 'mu-plugin' => 'Must-Use Plugins', |
|
38 | + 'multisite-plugin' => 'Network Active Plugins', |
|
39 | + 'active-plugin' => 'Active Plugins', |
|
40 | + 'inactive-plugin' => 'Inactive Plugins', |
|
41 | + 'setting' => 'Plugin Settings', |
|
42 | + 'reviews' => 'Review Counts', |
|
43 | + ]; |
|
44 | + $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
45 | + $methodName = Helper::buildMethodName('get-'.$key.'-details'); |
|
46 | + if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
47 | + return $carry.$this->implode( |
|
48 | + strtoupper($details[$key]), |
|
49 | + apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
50 | + ); |
|
51 | + } |
|
52 | + return $carry; |
|
53 | + }); |
|
54 | + return trim($systemInfo); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return array |
|
59 | - */ |
|
60 | - public function getActivePluginDetails() |
|
61 | - { |
|
62 | - $plugins = get_plugins(); |
|
63 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
64 | - $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
65 | - return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
66 | - } |
|
57 | + /** |
|
58 | + * @return array |
|
59 | + */ |
|
60 | + public function getActivePluginDetails() |
|
61 | + { |
|
62 | + $plugins = get_plugins(); |
|
63 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
64 | + $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
65 | + return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public function getAddonDetails() |
|
72 | - { |
|
73 | - $details = apply_filters('site-reviews/addon/system-info', []); |
|
74 | - ksort($details); |
|
75 | - return $details; |
|
76 | - } |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public function getAddonDetails() |
|
72 | + { |
|
73 | + $details = apply_filters('site-reviews/addon/system-info', []); |
|
74 | + ksort($details); |
|
75 | + return $details; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - public function getBrowserDetails() |
|
82 | - { |
|
83 | - $browser = new Browser(); |
|
84 | - $name = esc_attr($browser->getName()); |
|
85 | - $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
86 | - $version = esc_attr($browser->getVersion()); |
|
87 | - return [ |
|
88 | - 'Browser Name' => sprintf('%s %s', $name, $version), |
|
89 | - 'Browser UA' => $userAgent, |
|
90 | - ]; |
|
91 | - } |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + public function getBrowserDetails() |
|
82 | + { |
|
83 | + $browser = new Browser(); |
|
84 | + $name = esc_attr($browser->getName()); |
|
85 | + $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
86 | + $version = esc_attr($browser->getVersion()); |
|
87 | + return [ |
|
88 | + 'Browser Name' => sprintf('%s %s', $name, $version), |
|
89 | + 'Browser UA' => $userAgent, |
|
90 | + ]; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function getInactivePluginDetails() |
|
97 | - { |
|
98 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
99 | - $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
100 | - $multisitePlugins = $this->getMultisitePluginDetails(); |
|
101 | - return empty($multisitePlugins) |
|
102 | - ? $inactivePlugins |
|
103 | - : array_diff($inactivePlugins, $multisitePlugins); |
|
104 | - } |
|
93 | + /** |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function getInactivePluginDetails() |
|
97 | + { |
|
98 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
99 | + $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
100 | + $multisitePlugins = $this->getMultisitePluginDetails(); |
|
101 | + return empty($multisitePlugins) |
|
102 | + ? $inactivePlugins |
|
103 | + : array_diff($inactivePlugins, $multisitePlugins); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @return array |
|
108 | - */ |
|
109 | - public function getMuPluginDetails() |
|
110 | - { |
|
111 | - if (empty($plugins = get_mu_plugins())) { |
|
112 | - return []; |
|
113 | - } |
|
114 | - return $this->normalizePluginList($plugins); |
|
115 | - } |
|
106 | + /** |
|
107 | + * @return array |
|
108 | + */ |
|
109 | + public function getMuPluginDetails() |
|
110 | + { |
|
111 | + if (empty($plugins = get_mu_plugins())) { |
|
112 | + return []; |
|
113 | + } |
|
114 | + return $this->normalizePluginList($plugins); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public function getMultisitePluginDetails() |
|
121 | - { |
|
122 | - $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
123 | - if (!is_multisite() || empty($activePlugins)) { |
|
124 | - return []; |
|
125 | - } |
|
126 | - return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
127 | - } |
|
117 | + /** |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public function getMultisitePluginDetails() |
|
121 | + { |
|
122 | + $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
123 | + if (!is_multisite() || empty($activePlugins)) { |
|
124 | + return []; |
|
125 | + } |
|
126 | + return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public function getPhpDetails() |
|
133 | - { |
|
134 | - $displayErrors = $this->getINI('display_errors', null) |
|
135 | - ? 'On ('.$this->getINI('display_errors').')' |
|
136 | - : 'N/A'; |
|
137 | - $intlSupport = extension_loaded('intl') |
|
138 | - ? phpversion('intl') |
|
139 | - : 'false'; |
|
140 | - return [ |
|
141 | - 'cURL' => var_export(function_exists('curl_init'), true), |
|
142 | - 'Default Charset' => $this->getINI('default_charset'), |
|
143 | - 'Display Errors' => $displayErrors, |
|
144 | - 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
145 | - 'Intl' => $intlSupport, |
|
146 | - 'IPv6' => var_export(defined('AF_INET6'), true), |
|
147 | - 'Max Execution Time' => $this->getINI('max_execution_time'), |
|
148 | - 'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'), |
|
149 | - 'Max Input Vars' => $this->getINI('max_input_vars'), |
|
150 | - 'Memory Limit' => $this->getINI('memory_limit'), |
|
151 | - 'Post Max Size' => $this->getINI('post_max_size'), |
|
152 | - 'Sendmail Path' => $this->getINI('sendmail_path'), |
|
153 | - 'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')), |
|
154 | - 'Session Name' => esc_html($this->getINI('session.name')), |
|
155 | - 'Session Save Path' => esc_html($this->getINI('session.save_path')), |
|
156 | - 'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true), |
|
157 | - 'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true), |
|
158 | - 'Upload Max Filesize' => $this->getINI('upload_max_filesize'), |
|
159 | - ]; |
|
160 | - } |
|
129 | + /** |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public function getPhpDetails() |
|
133 | + { |
|
134 | + $displayErrors = $this->getINI('display_errors', null) |
|
135 | + ? 'On ('.$this->getINI('display_errors').')' |
|
136 | + : 'N/A'; |
|
137 | + $intlSupport = extension_loaded('intl') |
|
138 | + ? phpversion('intl') |
|
139 | + : 'false'; |
|
140 | + return [ |
|
141 | + 'cURL' => var_export(function_exists('curl_init'), true), |
|
142 | + 'Default Charset' => $this->getINI('default_charset'), |
|
143 | + 'Display Errors' => $displayErrors, |
|
144 | + 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
145 | + 'Intl' => $intlSupport, |
|
146 | + 'IPv6' => var_export(defined('AF_INET6'), true), |
|
147 | + 'Max Execution Time' => $this->getINI('max_execution_time'), |
|
148 | + 'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'), |
|
149 | + 'Max Input Vars' => $this->getINI('max_input_vars'), |
|
150 | + 'Memory Limit' => $this->getINI('memory_limit'), |
|
151 | + 'Post Max Size' => $this->getINI('post_max_size'), |
|
152 | + 'Sendmail Path' => $this->getINI('sendmail_path'), |
|
153 | + 'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')), |
|
154 | + 'Session Name' => esc_html($this->getINI('session.name')), |
|
155 | + 'Session Save Path' => esc_html($this->getINI('session.save_path')), |
|
156 | + 'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true), |
|
157 | + 'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true), |
|
158 | + 'Upload Max Filesize' => $this->getINI('upload_max_filesize'), |
|
159 | + ]; |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - public function getReviewsDetails() |
|
166 | - { |
|
167 | - $counts = glsr(CountsManager::class)->getCounts(); |
|
168 | - $counts = Arr::flattenArray($counts); |
|
169 | - array_walk($counts, function (&$ratings) use ($counts) { |
|
170 | - if (is_array($ratings)) { |
|
171 | - $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
172 | - return; |
|
173 | - } |
|
174 | - glsr_log() |
|
175 | - ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
176 | - ->debug($ratings) |
|
177 | - ->debug($counts); |
|
178 | - }); |
|
179 | - ksort($counts); |
|
180 | - return $counts; |
|
181 | - } |
|
162 | + /** |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + public function getReviewsDetails() |
|
166 | + { |
|
167 | + $counts = glsr(CountsManager::class)->getCounts(); |
|
168 | + $counts = Arr::flattenArray($counts); |
|
169 | + array_walk($counts, function (&$ratings) use ($counts) { |
|
170 | + if (is_array($ratings)) { |
|
171 | + $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
172 | + return; |
|
173 | + } |
|
174 | + glsr_log() |
|
175 | + ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
176 | + ->debug($ratings) |
|
177 | + ->debug($counts); |
|
178 | + }); |
|
179 | + ksort($counts); |
|
180 | + return $counts; |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - public function getServerDetails() |
|
187 | - { |
|
188 | - global $wpdb; |
|
189 | - return [ |
|
190 | - 'Host Name' => $this->getHostName(), |
|
191 | - 'MySQL Version' => $wpdb->db_version(), |
|
192 | - 'PHP Version' => PHP_VERSION, |
|
193 | - 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
194 | - ]; |
|
195 | - } |
|
183 | + /** |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + public function getServerDetails() |
|
187 | + { |
|
188 | + global $wpdb; |
|
189 | + return [ |
|
190 | + 'Host Name' => $this->getHostName(), |
|
191 | + 'MySQL Version' => $wpdb->db_version(), |
|
192 | + 'PHP Version' => PHP_VERSION, |
|
193 | + 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
194 | + ]; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * @return array |
|
199 | - */ |
|
200 | - public function getSettingDetails() |
|
201 | - { |
|
202 | - $settings = glsr(OptionManager::class)->get('settings', []); |
|
203 | - $settings = Arr::flattenArray($settings, true); |
|
204 | - $settings = $this->purgeSensitiveData($settings); |
|
205 | - ksort($settings); |
|
206 | - $details = []; |
|
207 | - foreach ($settings as $key => $value) { |
|
208 | - if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) { |
|
209 | - continue; |
|
210 | - } |
|
211 | - $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
212 | - $details[$key] = $value; |
|
213 | - } |
|
214 | - return $details; |
|
215 | - } |
|
197 | + /** |
|
198 | + * @return array |
|
199 | + */ |
|
200 | + public function getSettingDetails() |
|
201 | + { |
|
202 | + $settings = glsr(OptionManager::class)->get('settings', []); |
|
203 | + $settings = Arr::flattenArray($settings, true); |
|
204 | + $settings = $this->purgeSensitiveData($settings); |
|
205 | + ksort($settings); |
|
206 | + $details = []; |
|
207 | + foreach ($settings as $key => $value) { |
|
208 | + if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) { |
|
209 | + continue; |
|
210 | + } |
|
211 | + $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
212 | + $details[$key] = $value; |
|
213 | + } |
|
214 | + return $details; |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @return array |
|
219 | - */ |
|
220 | - public function getPluginDetails() |
|
221 | - { |
|
222 | - return [ |
|
223 | - 'Console level' => glsr(Console::class)->humanLevel(), |
|
224 | - 'Console size' => glsr(Console::class)->humanSize('0'), |
|
225 | - 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
226 | - 'Version (current)' => glsr()->version, |
|
227 | - 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
228 | - ]; |
|
229 | - } |
|
217 | + /** |
|
218 | + * @return array |
|
219 | + */ |
|
220 | + public function getPluginDetails() |
|
221 | + { |
|
222 | + return [ |
|
223 | + 'Console level' => glsr(Console::class)->humanLevel(), |
|
224 | + 'Console size' => glsr(Console::class)->humanSize('0'), |
|
225 | + 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
226 | + 'Version (current)' => glsr()->version, |
|
227 | + 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
228 | + ]; |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - public function getWordpressDetails() |
|
235 | - { |
|
236 | - global $wpdb; |
|
237 | - $theme = wp_get_theme(); |
|
238 | - return [ |
|
239 | - 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
240 | - 'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1), |
|
241 | - 'Home URL' => home_url(), |
|
242 | - 'Language' => get_locale(), |
|
243 | - 'Memory Limit' => WP_MEMORY_LIMIT, |
|
244 | - 'Multisite' => var_export(is_multisite(), true), |
|
245 | - 'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'), |
|
246 | - 'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'), |
|
247 | - 'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'), |
|
248 | - 'Post Stati' => implode(', ', get_post_stati()), |
|
249 | - 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
250 | - 'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'), |
|
251 | - 'Site URL' => site_url(), |
|
252 | - 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'), |
|
253 | - 'Version' => get_bloginfo('version'), |
|
254 | - 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
255 | - 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
256 | - 'WP Memory Limit' => WP_MEMORY_LIMIT, |
|
257 | - ]; |
|
258 | - } |
|
231 | + /** |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + public function getWordpressDetails() |
|
235 | + { |
|
236 | + global $wpdb; |
|
237 | + $theme = wp_get_theme(); |
|
238 | + return [ |
|
239 | + 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
240 | + 'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1), |
|
241 | + 'Home URL' => home_url(), |
|
242 | + 'Language' => get_locale(), |
|
243 | + 'Memory Limit' => WP_MEMORY_LIMIT, |
|
244 | + 'Multisite' => var_export(is_multisite(), true), |
|
245 | + 'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'), |
|
246 | + 'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'), |
|
247 | + 'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'), |
|
248 | + 'Post Stati' => implode(', ', get_post_stati()), |
|
249 | + 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
250 | + 'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'), |
|
251 | + 'Site URL' => site_url(), |
|
252 | + 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'), |
|
253 | + 'Version' => get_bloginfo('version'), |
|
254 | + 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
255 | + 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
256 | + 'WP Memory Limit' => WP_MEMORY_LIMIT, |
|
257 | + ]; |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * @return string |
|
262 | - */ |
|
263 | - protected function detectWebhostProvider() |
|
264 | - { |
|
265 | - $checks = [ |
|
266 | - '.accountservergroup.com' => 'Site5', |
|
267 | - '.gridserver.com' => 'MediaTemple Grid', |
|
268 | - '.inmotionhosting.com' => 'InMotion Hosting', |
|
269 | - '.ovh.net' => 'OVH', |
|
270 | - '.pair.com' => 'pair Networks', |
|
271 | - '.stabletransit.com' => 'Rackspace Cloud', |
|
272 | - '.stratoserver.net' => 'STRATO', |
|
273 | - '.sysfix.eu' => 'SysFix.eu Power Hosting', |
|
274 | - 'bluehost.com' => 'Bluehost', |
|
275 | - 'DH_USER' => 'DreamHost', |
|
276 | - 'Flywheel' => 'Flywheel', |
|
277 | - 'ipagemysql.com' => 'iPage', |
|
278 | - 'ipowermysql.com' => 'IPower', |
|
279 | - 'localhost:/tmp/mysql5.sock' => 'ICDSoft', |
|
280 | - 'mysqlv5' => 'NetworkSolutions', |
|
281 | - 'PAGELYBIN' => 'Pagely', |
|
282 | - 'secureserver.net' => 'GoDaddy', |
|
283 | - 'WPE_APIKEY' => 'WP Engine', |
|
284 | - ]; |
|
285 | - foreach ($checks as $key => $value) { |
|
286 | - if (!$this->isWebhostCheckValid($key)) { |
|
287 | - continue; |
|
288 | - } |
|
289 | - return $value; |
|
290 | - } |
|
291 | - return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
292 | - } |
|
260 | + /** |
|
261 | + * @return string |
|
262 | + */ |
|
263 | + protected function detectWebhostProvider() |
|
264 | + { |
|
265 | + $checks = [ |
|
266 | + '.accountservergroup.com' => 'Site5', |
|
267 | + '.gridserver.com' => 'MediaTemple Grid', |
|
268 | + '.inmotionhosting.com' => 'InMotion Hosting', |
|
269 | + '.ovh.net' => 'OVH', |
|
270 | + '.pair.com' => 'pair Networks', |
|
271 | + '.stabletransit.com' => 'Rackspace Cloud', |
|
272 | + '.stratoserver.net' => 'STRATO', |
|
273 | + '.sysfix.eu' => 'SysFix.eu Power Hosting', |
|
274 | + 'bluehost.com' => 'Bluehost', |
|
275 | + 'DH_USER' => 'DreamHost', |
|
276 | + 'Flywheel' => 'Flywheel', |
|
277 | + 'ipagemysql.com' => 'iPage', |
|
278 | + 'ipowermysql.com' => 'IPower', |
|
279 | + 'localhost:/tmp/mysql5.sock' => 'ICDSoft', |
|
280 | + 'mysqlv5' => 'NetworkSolutions', |
|
281 | + 'PAGELYBIN' => 'Pagely', |
|
282 | + 'secureserver.net' => 'GoDaddy', |
|
283 | + 'WPE_APIKEY' => 'WP Engine', |
|
284 | + ]; |
|
285 | + foreach ($checks as $key => $value) { |
|
286 | + if (!$this->isWebhostCheckValid($key)) { |
|
287 | + continue; |
|
288 | + } |
|
289 | + return $value; |
|
290 | + } |
|
291 | + return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
292 | + } |
|
293 | 293 | |
294 | - /** |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - protected function getHostName() |
|
298 | - { |
|
299 | - return sprintf('%s (%s)', |
|
300 | - $this->detectWebhostProvider(), |
|
301 | - Helper::getIpAddress() |
|
302 | - ); |
|
303 | - } |
|
294 | + /** |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + protected function getHostName() |
|
298 | + { |
|
299 | + return sprintf('%s (%s)', |
|
300 | + $this->detectWebhostProvider(), |
|
301 | + Helper::getIpAddress() |
|
302 | + ); |
|
303 | + } |
|
304 | 304 | |
305 | - protected function getINI($name, $disabledValue = 'ini_get() is disabled.') |
|
306 | - { |
|
307 | - return function_exists('ini_get') |
|
308 | - ? ini_get($name) |
|
309 | - : $disabledValue; |
|
310 | - } |
|
305 | + protected function getINI($name, $disabledValue = 'ini_get() is disabled.') |
|
306 | + { |
|
307 | + return function_exists('ini_get') |
|
308 | + ? ini_get($name) |
|
309 | + : $disabledValue; |
|
310 | + } |
|
311 | 311 | |
312 | - /** |
|
313 | - * @return array |
|
314 | - */ |
|
315 | - protected function getWordpressPlugins() |
|
316 | - { |
|
317 | - $plugins = get_plugins(); |
|
318 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
319 | - $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
320 | - $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
321 | - return $active + $inactive; |
|
322 | - } |
|
312 | + /** |
|
313 | + * @return array |
|
314 | + */ |
|
315 | + protected function getWordpressPlugins() |
|
316 | + { |
|
317 | + $plugins = get_plugins(); |
|
318 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
319 | + $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
320 | + $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
321 | + return $active + $inactive; |
|
322 | + } |
|
323 | 323 | |
324 | - /** |
|
325 | - * @param string $title |
|
326 | - * @return string |
|
327 | - */ |
|
328 | - protected function implode($title, array $details) |
|
329 | - { |
|
330 | - $strings = ['['.$title.']']; |
|
331 | - $padding = max(array_map('strlen', array_keys($details))); |
|
332 | - $padding = max([$padding, static::PAD]); |
|
333 | - foreach ($details as $key => $value) { |
|
334 | - $strings[] = is_string($key) |
|
335 | - ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
336 | - : ' - '.$value; |
|
337 | - } |
|
338 | - return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
339 | - } |
|
324 | + /** |
|
325 | + * @param string $title |
|
326 | + * @return string |
|
327 | + */ |
|
328 | + protected function implode($title, array $details) |
|
329 | + { |
|
330 | + $strings = ['['.$title.']']; |
|
331 | + $padding = max(array_map('strlen', array_keys($details))); |
|
332 | + $padding = max([$padding, static::PAD]); |
|
333 | + foreach ($details as $key => $value) { |
|
334 | + $strings[] = is_string($key) |
|
335 | + ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
336 | + : ' - '.$value; |
|
337 | + } |
|
338 | + return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
339 | + } |
|
340 | 340 | |
341 | - /** |
|
342 | - * @param string $key |
|
343 | - * @return bool |
|
344 | - */ |
|
345 | - protected function isWebhostCheckValid($key) |
|
346 | - { |
|
347 | - return defined($key) |
|
348 | - || filter_input(INPUT_SERVER, $key) |
|
349 | - || Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
350 | - || Str::contains(DB_HOST, $key) |
|
351 | - || Str::contains(php_uname(), $key); |
|
352 | - } |
|
341 | + /** |
|
342 | + * @param string $key |
|
343 | + * @return bool |
|
344 | + */ |
|
345 | + protected function isWebhostCheckValid($key) |
|
346 | + { |
|
347 | + return defined($key) |
|
348 | + || filter_input(INPUT_SERVER, $key) |
|
349 | + || Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
350 | + || Str::contains(DB_HOST, $key) |
|
351 | + || Str::contains(php_uname(), $key); |
|
352 | + } |
|
353 | 353 | |
354 | - /** |
|
355 | - * @return array |
|
356 | - */ |
|
357 | - protected function normalizePluginList(array $plugins) |
|
358 | - { |
|
359 | - $plugins = array_map(function ($plugin) { |
|
360 | - return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version')); |
|
361 | - }, $plugins); |
|
362 | - natcasesort($plugins); |
|
363 | - return array_flip($plugins); |
|
364 | - } |
|
354 | + /** |
|
355 | + * @return array |
|
356 | + */ |
|
357 | + protected function normalizePluginList(array $plugins) |
|
358 | + { |
|
359 | + $plugins = array_map(function ($plugin) { |
|
360 | + return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version')); |
|
361 | + }, $plugins); |
|
362 | + natcasesort($plugins); |
|
363 | + return array_flip($plugins); |
|
364 | + } |
|
365 | 365 | |
366 | - /** |
|
367 | - * @return array |
|
368 | - */ |
|
369 | - protected function purgeSensitiveData(array $settings) |
|
370 | - { |
|
371 | - $keys = [ |
|
372 | - 'general.rebusify_serial', |
|
373 | - 'licenses.', |
|
374 | - 'submissions.recaptcha.key', |
|
375 | - 'submissions.recaptcha.secret', |
|
376 | - ]; |
|
377 | - array_walk($settings, function (&$value, $setting) use ($keys) { |
|
378 | - foreach ($keys as $key) { |
|
379 | - if (!Str::startsWith($key, $setting) || empty($value)) { |
|
380 | - continue; |
|
381 | - } |
|
382 | - $value = str_repeat('•', 13); |
|
383 | - return; |
|
384 | - } |
|
385 | - }); |
|
386 | - return $settings; |
|
387 | - } |
|
366 | + /** |
|
367 | + * @return array |
|
368 | + */ |
|
369 | + protected function purgeSensitiveData(array $settings) |
|
370 | + { |
|
371 | + $keys = [ |
|
372 | + 'general.rebusify_serial', |
|
373 | + 'licenses.', |
|
374 | + 'submissions.recaptcha.key', |
|
375 | + 'submissions.recaptcha.secret', |
|
376 | + ]; |
|
377 | + array_walk($settings, function (&$value, $setting) use ($keys) { |
|
378 | + foreach ($keys as $key) { |
|
379 | + if (!Str::startsWith($key, $setting) || empty($value)) { |
|
380 | + continue; |
|
381 | + } |
|
382 | + $value = str_repeat('•', 13); |
|
383 | + return; |
|
384 | + } |
|
385 | + }); |
|
386 | + return $settings; |
|
387 | + } |
|
388 | 388 | } |
@@ -4,186 +4,186 @@ |
||
4 | 4 | |
5 | 5 | class Str |
6 | 6 | { |
7 | - /** |
|
8 | - * @param string $subject |
|
9 | - * @param string $search |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - public static function afterLast($subject, $search) |
|
13 | - { |
|
14 | - return '' === $search |
|
15 | - ? $subject |
|
16 | - : array_reverse(explode($search, $subject))[0]; |
|
17 | - } |
|
7 | + /** |
|
8 | + * @param string $subject |
|
9 | + * @param string $search |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + public static function afterLast($subject, $search) |
|
13 | + { |
|
14 | + return '' === $search |
|
15 | + ? $subject |
|
16 | + : array_reverse(explode($search, $subject))[0]; |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string $string |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - public static function camelCase($string) |
|
24 | - { |
|
25 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
26 | - return str_replace(' ', '', $string); |
|
27 | - } |
|
19 | + /** |
|
20 | + * @param string $string |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + public static function camelCase($string) |
|
24 | + { |
|
25 | + $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
26 | + return str_replace(' ', '', $string); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param string $haystack |
|
31 | - * @param string $needle |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public static function contains($haystack, $needle) |
|
35 | - { |
|
36 | - return false !== strpos($haystack, $needle); |
|
37 | - } |
|
29 | + /** |
|
30 | + * @param string $haystack |
|
31 | + * @param string $needle |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public static function contains($haystack, $needle) |
|
35 | + { |
|
36 | + return false !== strpos($haystack, $needle); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $name |
|
41 | - * @param string $nameType first|first_initial|initials|last|last_initial |
|
42 | - * @param string $initialType period|period_space|space |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public static function convertName($name, $nameType = '', $initialType = '') |
|
46 | - { |
|
47 | - $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
48 | - $firstName = array_shift($names); |
|
49 | - $lastName = array_pop($names); |
|
50 | - $initialTypes = [ |
|
51 | - 'period' => '.', |
|
52 | - 'period_space' => '. ', |
|
53 | - 'space' => ' ', |
|
54 | - ]; |
|
55 | - $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
56 | - if ('initials' == $nameType) { |
|
57 | - return static::convertToInitials($name, $initialPunctuation); |
|
58 | - } |
|
59 | - $nameTypes = [ |
|
60 | - 'first' => $firstName, |
|
61 | - 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
62 | - 'last' => $lastName, |
|
63 | - 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
64 | - ]; |
|
65 | - return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
66 | - } |
|
39 | + /** |
|
40 | + * @param string $name |
|
41 | + * @param string $nameType first|first_initial|initials|last|last_initial |
|
42 | + * @param string $initialType period|period_space|space |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public static function convertName($name, $nameType = '', $initialType = '') |
|
46 | + { |
|
47 | + $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
48 | + $firstName = array_shift($names); |
|
49 | + $lastName = array_pop($names); |
|
50 | + $initialTypes = [ |
|
51 | + 'period' => '.', |
|
52 | + 'period_space' => '. ', |
|
53 | + 'space' => ' ', |
|
54 | + ]; |
|
55 | + $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
56 | + if ('initials' == $nameType) { |
|
57 | + return static::convertToInitials($name, $initialPunctuation); |
|
58 | + } |
|
59 | + $nameTypes = [ |
|
60 | + 'first' => $firstName, |
|
61 | + 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
62 | + 'last' => $lastName, |
|
63 | + 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
64 | + ]; |
|
65 | + return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param string $path |
|
70 | - * @param string $prefix |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public static function convertPathToId($path, $prefix = '') |
|
74 | - { |
|
75 | - return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
76 | - } |
|
68 | + /** |
|
69 | + * @param string $path |
|
70 | + * @param string $prefix |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public static function convertPathToId($path, $prefix = '') |
|
74 | + { |
|
75 | + return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $path |
|
80 | - * @param string $prefix |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public static function convertPathToName($path, $prefix = '') |
|
84 | - { |
|
85 | - $levels = explode('.', $path); |
|
86 | - return array_reduce($levels, function ($result, $value) { |
|
87 | - return $result .= '['.$value.']'; |
|
88 | - }, $prefix); |
|
89 | - } |
|
78 | + /** |
|
79 | + * @param string $path |
|
80 | + * @param string $prefix |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public static function convertPathToName($path, $prefix = '') |
|
84 | + { |
|
85 | + $levels = explode('.', $path); |
|
86 | + return array_reduce($levels, function ($result, $value) { |
|
87 | + return $result .= '['.$value.']'; |
|
88 | + }, $prefix); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string $name |
|
93 | - * @param string $initialPunctuation |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public static function convertToInitials($name, $initialPunctuation = '') |
|
97 | - { |
|
98 | - preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
99 | - return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
100 | - return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
101 | - }); |
|
102 | - } |
|
91 | + /** |
|
92 | + * @param string $name |
|
93 | + * @param string $initialPunctuation |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public static function convertToInitials($name, $initialPunctuation = '') |
|
97 | + { |
|
98 | + preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
99 | + return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
100 | + return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
101 | + }); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @param string $string |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public static function dashCase($string) |
|
109 | - { |
|
110 | - return str_replace('_', '-', static::snakeCase($string)); |
|
111 | - } |
|
104 | + /** |
|
105 | + * @param string $string |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public static function dashCase($string) |
|
109 | + { |
|
110 | + return str_replace('_', '-', static::snakeCase($string)); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param string $needle |
|
115 | - * @param string $haystack |
|
116 | - * @return bool |
|
117 | - */ |
|
118 | - public static function endsWith($needle, $haystack) |
|
119 | - { |
|
120 | - $length = strlen($needle); |
|
121 | - return 0 != $length |
|
122 | - ? substr($haystack, -$length) === $needle |
|
123 | - : true; |
|
124 | - } |
|
113 | + /** |
|
114 | + * @param string $needle |
|
115 | + * @param string $haystack |
|
116 | + * @return bool |
|
117 | + */ |
|
118 | + public static function endsWith($needle, $haystack) |
|
119 | + { |
|
120 | + $length = strlen($needle); |
|
121 | + return 0 != $length |
|
122 | + ? substr($haystack, -$length) === $needle |
|
123 | + : true; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @param string $prefix |
|
128 | - * @param string $string |
|
129 | - * @param string|null $trim |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public static function prefix($prefix, $string, $trim = null) |
|
133 | - { |
|
134 | - if (null === $trim) { |
|
135 | - $trim = $prefix; |
|
136 | - } |
|
137 | - return $prefix.trim(static::removePrefix($trim, $string)); |
|
138 | - } |
|
126 | + /** |
|
127 | + * @param string $prefix |
|
128 | + * @param string $string |
|
129 | + * @param string|null $trim |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public static function prefix($prefix, $string, $trim = null) |
|
133 | + { |
|
134 | + if (null === $trim) { |
|
135 | + $trim = $prefix; |
|
136 | + } |
|
137 | + return $prefix.trim(static::removePrefix($trim, $string)); |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @param string $prefix |
|
142 | - * @param string $string |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public static function removePrefix($prefix, $string) |
|
146 | - { |
|
147 | - return static::startsWith($prefix, $string) |
|
148 | - ? substr($string, strlen($prefix)) |
|
149 | - : $string; |
|
150 | - } |
|
140 | + /** |
|
141 | + * @param string $prefix |
|
142 | + * @param string $string |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public static function removePrefix($prefix, $string) |
|
146 | + { |
|
147 | + return static::startsWith($prefix, $string) |
|
148 | + ? substr($string, strlen($prefix)) |
|
149 | + : $string; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * @param string $string |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - public static function snakeCase($string) |
|
157 | - { |
|
158 | - if (!ctype_lower($string)) { |
|
159 | - $string = preg_replace('/\s+/u', '', $string); |
|
160 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
161 | - $string = function_exists('mb_strtolower') |
|
162 | - ? mb_strtolower($string, 'UTF-8') |
|
163 | - : strtolower($string); |
|
164 | - } |
|
165 | - return str_replace('-', '_', $string); |
|
166 | - } |
|
152 | + /** |
|
153 | + * @param string $string |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + public static function snakeCase($string) |
|
157 | + { |
|
158 | + if (!ctype_lower($string)) { |
|
159 | + $string = preg_replace('/\s+/u', '', $string); |
|
160 | + $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
161 | + $string = function_exists('mb_strtolower') |
|
162 | + ? mb_strtolower($string, 'UTF-8') |
|
163 | + : strtolower($string); |
|
164 | + } |
|
165 | + return str_replace('-', '_', $string); |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @param string $needle |
|
170 | - * @param string $haystack |
|
171 | - * @return bool |
|
172 | - */ |
|
173 | - public static function startsWith($needle, $haystack) |
|
174 | - { |
|
175 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
176 | - } |
|
168 | + /** |
|
169 | + * @param string $needle |
|
170 | + * @param string $haystack |
|
171 | + * @return bool |
|
172 | + */ |
|
173 | + public static function startsWith($needle, $haystack) |
|
174 | + { |
|
175 | + return substr($haystack, 0, strlen($needle)) === $needle; |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * @param string $string |
|
180 | - * @param int $length |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - public static function truncate($string, $length) |
|
184 | - { |
|
185 | - return strlen($string) > $length |
|
186 | - ? substr($string, 0, $length) |
|
187 | - : $string; |
|
188 | - } |
|
178 | + /** |
|
179 | + * @param string $string |
|
180 | + * @param int $length |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + public static function truncate($string, $length) |
|
184 | + { |
|
185 | + return strlen($string) > $length |
|
186 | + ? substr($string, 0, $length) |
|
187 | + : $string; |
|
188 | + } |
|
189 | 189 | } |
@@ -13,247 +13,247 @@ |
||
13 | 13 | |
14 | 14 | class CountsManager |
15 | 15 | { |
16 | - const LIMIT = 500; |
|
17 | - const META_AVERAGE = '_glsr_average'; |
|
18 | - const META_COUNT = '_glsr_count'; |
|
19 | - const META_RANKING = '_glsr_ranking'; |
|
16 | + const LIMIT = 500; |
|
17 | + const META_AVERAGE = '_glsr_average'; |
|
18 | + const META_COUNT = '_glsr_count'; |
|
19 | + const META_RANKING = '_glsr_ranking'; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function buildCounts(array $args = []) |
|
25 | - { |
|
26 | - $counts = [ |
|
27 | - 'local' => $this->generateEmptyCountsArray(), |
|
28 | - ]; |
|
29 | - $query = $this->queryReviews($args); |
|
30 | - while ($query) { |
|
31 | - $counts = $this->populateCountsFromQuery($query, $counts); |
|
32 | - $query = $query->has_more |
|
33 | - ? $this->queryReviews($args, end($query->reviews)->ID) |
|
34 | - : false; |
|
35 | - } |
|
36 | - return $counts; |
|
37 | - } |
|
21 | + /** |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function buildCounts(array $args = []) |
|
25 | + { |
|
26 | + $counts = [ |
|
27 | + 'local' => $this->generateEmptyCountsArray(), |
|
28 | + ]; |
|
29 | + $query = $this->queryReviews($args); |
|
30 | + while ($query) { |
|
31 | + $counts = $this->populateCountsFromQuery($query, $counts); |
|
32 | + $query = $query->has_more |
|
33 | + ? $this->queryReviews($args, end($query->reviews)->ID) |
|
34 | + : false; |
|
35 | + } |
|
36 | + return $counts; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function decreaseAll(Review $review) |
|
43 | - { |
|
44 | - glsr(GlobalCountsManager::class)->decrease($review); |
|
45 | - glsr(PostCountsManager::class)->decrease($review); |
|
46 | - glsr(TermCountsManager::class)->decrease($review); |
|
47 | - } |
|
39 | + /** |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function decreaseAll(Review $review) |
|
43 | + { |
|
44 | + glsr(GlobalCountsManager::class)->decrease($review); |
|
45 | + glsr(PostCountsManager::class)->decrease($review); |
|
46 | + glsr(TermCountsManager::class)->decrease($review); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param string $type |
|
51 | - * @param int $rating |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function decreaseRating(array $reviewCounts, $type, $rating) |
|
55 | - { |
|
56 | - if (isset($reviewCounts[$type][$rating])) { |
|
57 | - $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
58 | - } |
|
59 | - return $reviewCounts; |
|
60 | - } |
|
49 | + /** |
|
50 | + * @param string $type |
|
51 | + * @param int $rating |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function decreaseRating(array $reviewCounts, $type, $rating) |
|
55 | + { |
|
56 | + if (isset($reviewCounts[$type][$rating])) { |
|
57 | + $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
58 | + } |
|
59 | + return $reviewCounts; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - public function flatten(array $reviewCounts, array $args = []) |
|
66 | - { |
|
67 | - $counts = []; |
|
68 | - array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
69 | - $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
70 | - }); |
|
71 | - $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
72 | - $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
73 | - foreach ($counts as $index => &$num) { |
|
74 | - if (!Helper::inRange($index, $min, $max)) { |
|
75 | - $num = 0; |
|
76 | - } |
|
77 | - } |
|
78 | - return $counts; |
|
79 | - } |
|
62 | + /** |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + public function flatten(array $reviewCounts, array $args = []) |
|
66 | + { |
|
67 | + $counts = []; |
|
68 | + array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
69 | + $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
70 | + }); |
|
71 | + $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
72 | + $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
73 | + foreach ($counts as $index => &$num) { |
|
74 | + if (!Helper::inRange($index, $min, $max)) { |
|
75 | + $num = 0; |
|
76 | + } |
|
77 | + } |
|
78 | + return $counts; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function getCounts(array $args = []) |
|
85 | - { |
|
86 | - $args = $this->normalizeArgs($args); |
|
87 | - $counts = $this->hasMixedAssignment($args) |
|
88 | - ? $this->buildCounts($args) // force query the database |
|
89 | - : $this->get($args); |
|
90 | - return $this->normalize($counts); |
|
91 | - } |
|
81 | + /** |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function getCounts(array $args = []) |
|
85 | + { |
|
86 | + $args = $this->normalizeArgs($args); |
|
87 | + $counts = $this->hasMixedAssignment($args) |
|
88 | + ? $this->buildCounts($args) // force query the database |
|
89 | + : $this->get($args); |
|
90 | + return $this->normalize($counts); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function increaseAll(Review $review) |
|
97 | - { |
|
98 | - glsr(GlobalCountsManager::class)->increase($review); |
|
99 | - glsr(PostCountsManager::class)->increase($review); |
|
100 | - glsr(TermCountsManager::class)->increase($review); |
|
101 | - } |
|
93 | + /** |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function increaseAll(Review $review) |
|
97 | + { |
|
98 | + glsr(GlobalCountsManager::class)->increase($review); |
|
99 | + glsr(PostCountsManager::class)->increase($review); |
|
100 | + glsr(TermCountsManager::class)->increase($review); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @param string $type |
|
105 | - * @param int $rating |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - public function increaseRating(array $reviewCounts, $type, $rating) |
|
109 | - { |
|
110 | - if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
111 | - return $reviewCounts; |
|
112 | - } |
|
113 | - if (!array_key_exists($type, $reviewCounts)) { |
|
114 | - $reviewCounts[$type] = []; |
|
115 | - } |
|
116 | - $reviewCounts = $this->normalize($reviewCounts); |
|
117 | - $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
118 | - return $reviewCounts; |
|
119 | - } |
|
103 | + /** |
|
104 | + * @param string $type |
|
105 | + * @param int $rating |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + public function increaseRating(array $reviewCounts, $type, $rating) |
|
109 | + { |
|
110 | + if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
111 | + return $reviewCounts; |
|
112 | + } |
|
113 | + if (!array_key_exists($type, $reviewCounts)) { |
|
114 | + $reviewCounts[$type] = []; |
|
115 | + } |
|
116 | + $reviewCounts = $this->normalize($reviewCounts); |
|
117 | + $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
118 | + return $reviewCounts; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function updateAll() |
|
125 | - { |
|
126 | - glsr(GlobalCountsManager::class)->updateAll(); |
|
127 | - glsr(PostCountsManager::class)->updateAll(); |
|
128 | - glsr(TermCountsManager::class)->updateAll(); |
|
129 | - } |
|
121 | + /** |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function updateAll() |
|
125 | + { |
|
126 | + glsr(GlobalCountsManager::class)->updateAll(); |
|
127 | + glsr(PostCountsManager::class)->updateAll(); |
|
128 | + glsr(TermCountsManager::class)->updateAll(); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @return array |
|
133 | - */ |
|
134 | - protected function combine(array $results) |
|
135 | - { |
|
136 | - if (!wp_is_numeric_array($results)) { |
|
137 | - return $results; |
|
138 | - } |
|
139 | - $mergedKeys = array_keys(array_merge(...$results)); |
|
140 | - $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
141 | - foreach ($results as $typeRatings) { |
|
142 | - foreach ($typeRatings as $type => $ratings) { |
|
143 | - foreach ($ratings as $index => $rating) { |
|
144 | - $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - return $counts; |
|
149 | - } |
|
131 | + /** |
|
132 | + * @return array |
|
133 | + */ |
|
134 | + protected function combine(array $results) |
|
135 | + { |
|
136 | + if (!wp_is_numeric_array($results)) { |
|
137 | + return $results; |
|
138 | + } |
|
139 | + $mergedKeys = array_keys(array_merge(...$results)); |
|
140 | + $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
141 | + foreach ($results as $typeRatings) { |
|
142 | + foreach ($typeRatings as $type => $ratings) { |
|
143 | + foreach ($ratings as $index => $rating) { |
|
144 | + $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + return $counts; |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - protected function generateEmptyCountsArray() |
|
155 | - { |
|
156 | - return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
157 | - } |
|
151 | + /** |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + protected function generateEmptyCountsArray() |
|
155 | + { |
|
156 | + return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - protected function get($args) |
|
163 | - { |
|
164 | - $results = []; |
|
165 | - foreach ($args['post_ids'] as $postId) { |
|
166 | - $results[] = glsr(PostCountsManager::class)->get($postId); |
|
167 | - } |
|
168 | - foreach ($args['term_ids'] as $termId) { |
|
169 | - $results[] = glsr(TermCountsManager::class)->get($termId); |
|
170 | - } |
|
171 | - if (empty($results)) { |
|
172 | - $results[] = glsr(GlobalCountsManager::class)->get(); |
|
173 | - } |
|
174 | - $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
|
175 | - return $this->combine($results); |
|
176 | - } |
|
159 | + /** |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + protected function get($args) |
|
163 | + { |
|
164 | + $results = []; |
|
165 | + foreach ($args['post_ids'] as $postId) { |
|
166 | + $results[] = glsr(PostCountsManager::class)->get($postId); |
|
167 | + } |
|
168 | + foreach ($args['term_ids'] as $termId) { |
|
169 | + $results[] = glsr(TermCountsManager::class)->get($termId); |
|
170 | + } |
|
171 | + if (empty($results)) { |
|
172 | + $results[] = glsr(GlobalCountsManager::class)->get(); |
|
173 | + } |
|
174 | + $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
|
175 | + return $this->combine($results); |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - protected function hasMixedAssignment(array $args) |
|
182 | - { |
|
183 | - return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
184 | - } |
|
178 | + /** |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + protected function hasMixedAssignment(array $args) |
|
182 | + { |
|
183 | + return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * @return array |
|
188 | - */ |
|
189 | - protected function normalize(array $reviewCounts) |
|
190 | - { |
|
191 | - foreach ($reviewCounts as &$counts) { |
|
192 | - foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
193 | - if (!isset($counts[$index])) { |
|
194 | - $counts[$index] = 0; |
|
195 | - } |
|
196 | - } |
|
197 | - ksort($counts); |
|
198 | - } |
|
199 | - return $reviewCounts; |
|
200 | - } |
|
186 | + /** |
|
187 | + * @return array |
|
188 | + */ |
|
189 | + protected function normalize(array $reviewCounts) |
|
190 | + { |
|
191 | + foreach ($reviewCounts as &$counts) { |
|
192 | + foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
193 | + if (!isset($counts[$index])) { |
|
194 | + $counts[$index] = 0; |
|
195 | + } |
|
196 | + } |
|
197 | + ksort($counts); |
|
198 | + } |
|
199 | + return $reviewCounts; |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * @return array |
|
204 | - */ |
|
205 | - protected function normalizeArgs(array $args) |
|
206 | - { |
|
207 | - $args = wp_parse_args(array_filter($args), [ |
|
208 | - 'post_ids' => [], |
|
209 | - 'term_ids' => [], |
|
210 | - 'type' => 'local', |
|
211 | - ]); |
|
212 | - $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
213 | - $args['type'] = $this->normalizeType($args['type']); |
|
214 | - return $args; |
|
215 | - } |
|
202 | + /** |
|
203 | + * @return array |
|
204 | + */ |
|
205 | + protected function normalizeArgs(array $args) |
|
206 | + { |
|
207 | + $args = wp_parse_args(array_filter($args), [ |
|
208 | + 'post_ids' => [], |
|
209 | + 'term_ids' => [], |
|
210 | + 'type' => 'local', |
|
211 | + ]); |
|
212 | + $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
213 | + $args['type'] = $this->normalizeType($args['type']); |
|
214 | + return $args; |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @param string $type |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - protected function normalizeType($type) |
|
222 | - { |
|
223 | - return empty($type) || !is_string($type) |
|
224 | - ? 'local' |
|
225 | - : $type; |
|
226 | - } |
|
217 | + /** |
|
218 | + * @param string $type |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + protected function normalizeType($type) |
|
222 | + { |
|
223 | + return empty($type) || !is_string($type) |
|
224 | + ? 'local' |
|
225 | + : $type; |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * @param object $query |
|
230 | - * @return array |
|
231 | - */ |
|
232 | - protected function populateCountsFromQuery($query, array $counts) |
|
233 | - { |
|
234 | - foreach ($query->reviews as $review) { |
|
235 | - $type = $this->normalizeType($review->type); |
|
236 | - if (!array_key_exists($type, $counts)) { |
|
237 | - $counts[$type] = $this->generateEmptyCountsArray(); |
|
238 | - } |
|
239 | - ++$counts[$type][$review->rating]; |
|
240 | - } |
|
241 | - return $counts; |
|
242 | - } |
|
228 | + /** |
|
229 | + * @param object $query |
|
230 | + * @return array |
|
231 | + */ |
|
232 | + protected function populateCountsFromQuery($query, array $counts) |
|
233 | + { |
|
234 | + foreach ($query->reviews as $review) { |
|
235 | + $type = $this->normalizeType($review->type); |
|
236 | + if (!array_key_exists($type, $counts)) { |
|
237 | + $counts[$type] = $this->generateEmptyCountsArray(); |
|
238 | + } |
|
239 | + ++$counts[$type][$review->rating]; |
|
240 | + } |
|
241 | + return $counts; |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * @param int $lastPostId |
|
246 | - * @return object |
|
247 | - */ |
|
248 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
249 | - { |
|
250 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
251 | - $hasMore = is_array($reviews) |
|
252 | - ? count($reviews) == static::LIMIT |
|
253 | - : false; |
|
254 | - return (object) [ |
|
255 | - 'has_more' => $hasMore, |
|
256 | - 'reviews' => $reviews, |
|
257 | - ]; |
|
258 | - } |
|
244 | + /** |
|
245 | + * @param int $lastPostId |
|
246 | + * @return object |
|
247 | + */ |
|
248 | + protected function queryReviews(array $args = [], $lastPostId = 0) |
|
249 | + { |
|
250 | + $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
251 | + $hasMore = is_array($reviews) |
|
252 | + ? count($reviews) == static::LIMIT |
|
253 | + : false; |
|
254 | + return (object) [ |
|
255 | + 'has_more' => $hasMore, |
|
256 | + 'reviews' => $reviews, |
|
257 | + ]; |
|
258 | + } |
|
259 | 259 | } |
@@ -8,163 +8,163 @@ |
||
8 | 8 | |
9 | 9 | class Upgrade_3_0_0 |
10 | 10 | { |
11 | - const MAPPED_SETTINGS = [ |
|
12 | - 'settings.general.notification' => 'settings.general.notifications', // array |
|
13 | - 'settings.general.notification_email' => 'settings.general.notification_email', |
|
14 | - 'settings.general.notification_message' => 'settings.general.notification_message', |
|
15 | - 'settings.general.require.approval' => 'settings.general.require.approval', |
|
16 | - 'settings.general.require.login' => 'settings.general.require.login', |
|
17 | - 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
18 | - 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
19 | - 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
20 | - 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
21 | - 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
22 | - 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
23 | - 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
24 | - 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
25 | - 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
26 | - 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
27 | - 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
28 | - 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
29 | - 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
30 | - 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
31 | - 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
32 | - 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
33 | - 'settings.reviews.schema.address' => 'settings.schema.address', |
|
34 | - 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
35 | - 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
36 | - 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
37 | - 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
38 | - 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
39 | - 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
40 | - 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
41 | - 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
42 | - 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
43 | - 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
44 | - 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
45 | - 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
46 | - 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
47 | - 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
48 | - 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
49 | - 'version' => 'version_upgraded_from', |
|
50 | - ]; |
|
11 | + const MAPPED_SETTINGS = [ |
|
12 | + 'settings.general.notification' => 'settings.general.notifications', // array |
|
13 | + 'settings.general.notification_email' => 'settings.general.notification_email', |
|
14 | + 'settings.general.notification_message' => 'settings.general.notification_message', |
|
15 | + 'settings.general.require.approval' => 'settings.general.require.approval', |
|
16 | + 'settings.general.require.login' => 'settings.general.require.login', |
|
17 | + 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
18 | + 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
19 | + 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
20 | + 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
21 | + 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
22 | + 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
23 | + 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
24 | + 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
25 | + 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
26 | + 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
27 | + 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
28 | + 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
29 | + 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
30 | + 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
31 | + 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
32 | + 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
33 | + 'settings.reviews.schema.address' => 'settings.schema.address', |
|
34 | + 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
35 | + 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
36 | + 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
37 | + 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
38 | + 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
39 | + 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
40 | + 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
41 | + 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
42 | + 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
43 | + 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
44 | + 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
45 | + 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
46 | + 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
47 | + 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
48 | + 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
49 | + 'version' => 'version_upgraded_from', |
|
50 | + ]; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - protected $newSettings; |
|
52 | + /** |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + protected $newSettings; |
|
56 | 56 | |
57 | - /** |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - protected $oldSettings; |
|
57 | + /** |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + protected $oldSettings; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function migrateSettings() |
|
66 | - { |
|
67 | - $this->newSettings = $this->getNewSettings(); |
|
68 | - $this->oldSettings = $this->getOldSettings(); |
|
69 | - if (empty($this->oldSettings)) { |
|
70 | - return; |
|
71 | - } |
|
72 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
73 | - if (empty($this->oldSettings[$old])) { |
|
74 | - continue; |
|
75 | - } |
|
76 | - $this->newSettings[$new] = $this->oldSettings[$old]; |
|
77 | - } |
|
78 | - $this->migrateNotificationSettings(); |
|
79 | - $this->migrateRecaptchaSettings(); |
|
80 | - $this->migrateRequiredSettings(); |
|
81 | - $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
82 | - $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
83 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
84 | - $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
85 | - } |
|
86 | - glsr(OptionManager::class)->set($newSettings); |
|
87 | - } |
|
62 | + /** |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function migrateSettings() |
|
66 | + { |
|
67 | + $this->newSettings = $this->getNewSettings(); |
|
68 | + $this->oldSettings = $this->getOldSettings(); |
|
69 | + if (empty($this->oldSettings)) { |
|
70 | + return; |
|
71 | + } |
|
72 | + foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
73 | + if (empty($this->oldSettings[$old])) { |
|
74 | + continue; |
|
75 | + } |
|
76 | + $this->newSettings[$new] = $this->oldSettings[$old]; |
|
77 | + } |
|
78 | + $this->migrateNotificationSettings(); |
|
79 | + $this->migrateRecaptchaSettings(); |
|
80 | + $this->migrateRequiredSettings(); |
|
81 | + $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
82 | + $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
83 | + if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
84 | + $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
85 | + } |
|
86 | + glsr(OptionManager::class)->set($newSettings); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function run() |
|
93 | - { |
|
94 | - $this->migrateSettings(); |
|
95 | - } |
|
89 | + /** |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function run() |
|
93 | + { |
|
94 | + $this->migrateSettings(); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - protected function getNewSettings() |
|
101 | - { |
|
102 | - return wp_parse_args( |
|
103 | - Arr::flattenArray(glsr(OptionManager::class)->all()), |
|
104 | - glsr(DefaultsManager::class)->defaults() |
|
105 | - ); |
|
106 | - } |
|
97 | + /** |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + protected function getNewSettings() |
|
101 | + { |
|
102 | + return wp_parse_args( |
|
103 | + Arr::flattenArray(glsr(OptionManager::class)->all()), |
|
104 | + glsr(DefaultsManager::class)->defaults() |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - protected function getOldSettings() |
|
112 | - { |
|
113 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
114 | - $settings = Arr::flattenArray((array) get_option('geminilabs_site_reviews-v2', [])); |
|
115 | - if (!empty($settings)) { |
|
116 | - $settings = wp_parse_args($settings, $defaults); |
|
117 | - } |
|
118 | - return $settings; |
|
119 | - } |
|
108 | + /** |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + protected function getOldSettings() |
|
112 | + { |
|
113 | + $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
114 | + $settings = Arr::flattenArray((array) get_option('geminilabs_site_reviews-v2', [])); |
|
115 | + if (!empty($settings)) { |
|
116 | + $settings = wp_parse_args($settings, $defaults); |
|
117 | + } |
|
118 | + return $settings; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - protected function migrateNotificationSettings() |
|
125 | - { |
|
126 | - $notifications = [ |
|
127 | - 'custom' => 'custom', |
|
128 | - 'default' => 'admin', |
|
129 | - 'webhook' => 'slack', |
|
130 | - ]; |
|
131 | - $this->newSettings['settings.general.notifications'] = []; |
|
132 | - foreach ($notifications as $old => $new) { |
|
133 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
134 | - continue; |
|
135 | - } |
|
136 | - $this->newSettings['settings.general.notifications'][] = $new; |
|
137 | - } |
|
138 | - } |
|
121 | + /** |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + protected function migrateNotificationSettings() |
|
125 | + { |
|
126 | + $notifications = [ |
|
127 | + 'custom' => 'custom', |
|
128 | + 'default' => 'admin', |
|
129 | + 'webhook' => 'slack', |
|
130 | + ]; |
|
131 | + $this->newSettings['settings.general.notifications'] = []; |
|
132 | + foreach ($notifications as $old => $new) { |
|
133 | + if ($this->oldSettings['settings.general.notification'] != $old) { |
|
134 | + continue; |
|
135 | + } |
|
136 | + $this->newSettings['settings.general.notifications'][] = $new; |
|
137 | + } |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - protected function migrateRecaptchaSettings() |
|
144 | - { |
|
145 | - $recaptcha = [ |
|
146 | - 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
147 | - 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
148 | - 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
149 | - ]; |
|
150 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
151 | - $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
152 | - } |
|
153 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
154 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
155 | - } |
|
156 | - $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
157 | - $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
158 | - $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
159 | - } |
|
140 | + /** |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + protected function migrateRecaptchaSettings() |
|
144 | + { |
|
145 | + $recaptcha = [ |
|
146 | + 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
147 | + 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
148 | + 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
149 | + ]; |
|
150 | + if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
151 | + $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
152 | + } |
|
153 | + if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
154 | + $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
155 | + } |
|
156 | + $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
157 | + $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
158 | + $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - protected function migrateRequiredSettings() |
|
165 | - { |
|
166 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
167 | - $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
168 | - $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
169 | - } |
|
161 | + /** |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + protected function migrateRequiredSettings() |
|
165 | + { |
|
166 | + $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
167 | + $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
168 | + $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
169 | + } |
|
170 | 170 | } |
@@ -9,70 +9,70 @@ |
||
9 | 9 | |
10 | 10 | class Upgrade_4_0_2 |
11 | 11 | { |
12 | - /** |
|
13 | - * @return void |
|
14 | - */ |
|
15 | - public function deleteSessions() |
|
16 | - { |
|
17 | - global $wpdb; |
|
18 | - $wpdb->query(" |
|
12 | + /** |
|
13 | + * @return void |
|
14 | + */ |
|
15 | + public function deleteSessions() |
|
16 | + { |
|
17 | + global $wpdb; |
|
18 | + $wpdb->query(" |
|
19 | 19 | DELETE |
20 | 20 | FROM {$wpdb->options} |
21 | 21 | WHERE option_name LIKE '_glsr_session%' |
22 | 22 | "); |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function migrateSettings() |
|
29 | - { |
|
30 | - if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
31 | - $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang') |
|
32 | - ? 'polylang' |
|
33 | - : ''; |
|
34 | - $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual); |
|
35 | - $settings = Arr::set($settings, 'settings.general.rebusify', 'no'); |
|
36 | - $settings = Arr::set($settings, 'settings.general.rebusify_email', ''); |
|
37 | - $settings = Arr::set($settings, 'settings.general.rebusify_serial', ''); |
|
38 | - $settings = Arr::set($settings, 'settings.reviews.name.format', ''); |
|
39 | - $settings = Arr::set($settings, 'settings.reviews.name.initial', ''); |
|
40 | - $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', ''); |
|
41 | - $settings = Arr::set($settings, 'settings.submissions.limit', ''); |
|
42 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
43 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
44 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
45 | - unset($settings['settings']['general']['support']); |
|
46 | - update_option(OptionManager::databaseKey(4), $settings); |
|
47 | - } |
|
48 | - } |
|
25 | + /** |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function migrateSettings() |
|
29 | + { |
|
30 | + if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
31 | + $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang') |
|
32 | + ? 'polylang' |
|
33 | + : ''; |
|
34 | + $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual); |
|
35 | + $settings = Arr::set($settings, 'settings.general.rebusify', 'no'); |
|
36 | + $settings = Arr::set($settings, 'settings.general.rebusify_email', ''); |
|
37 | + $settings = Arr::set($settings, 'settings.general.rebusify_serial', ''); |
|
38 | + $settings = Arr::set($settings, 'settings.reviews.name.format', ''); |
|
39 | + $settings = Arr::set($settings, 'settings.reviews.name.initial', ''); |
|
40 | + $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', ''); |
|
41 | + $settings = Arr::set($settings, 'settings.submissions.limit', ''); |
|
42 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
43 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
44 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
45 | + unset($settings['settings']['general']['support']); |
|
46 | + update_option(OptionManager::databaseKey(4), $settings); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function protectMetaKeys() |
|
54 | - { |
|
55 | - global $wpdb; |
|
56 | - $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
57 | - $keys = implode("','", $keys); |
|
58 | - $postType = Application::POST_TYPE; |
|
59 | - $wpdb->query(" |
|
50 | + /** |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function protectMetaKeys() |
|
54 | + { |
|
55 | + global $wpdb; |
|
56 | + $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
57 | + $keys = implode("','", $keys); |
|
58 | + $postType = Application::POST_TYPE; |
|
59 | + $wpdb->query(" |
|
60 | 60 | UPDATE {$wpdb->postmeta} pm |
61 | 61 | INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id |
62 | 62 | SET pm.meta_key = CONCAT('_', pm.meta_key) |
63 | 63 | WHERE pm.meta_key IN ('{$keys}') |
64 | 64 | AND p.post_type = '{$postType}' |
65 | 65 | "); |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function run() |
|
72 | - { |
|
73 | - $this->migrateSettings(); |
|
74 | - $this->protectMetaKeys(); |
|
75 | - $this->deleteSessions(); |
|
76 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
77 | - } |
|
68 | + /** |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function run() |
|
72 | + { |
|
73 | + $this->migrateSettings(); |
|
74 | + $this->protectMetaKeys(); |
|
75 | + $this->deleteSessions(); |
|
76 | + delete_transient(Application::ID.'_cloudflare_ips'); |
|
77 | + } |
|
78 | 78 | } |
@@ -8,95 +8,95 @@ |
||
8 | 8 | |
9 | 9 | class Upgrader |
10 | 10 | { |
11 | - /** |
|
12 | - * @return string |
|
13 | - */ |
|
14 | - public $currentVersion; |
|
11 | + /** |
|
12 | + * @return string |
|
13 | + */ |
|
14 | + public $currentVersion; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - public function run() |
|
20 | - { |
|
21 | - $files = $this->getUpgraderFiles(); |
|
22 | - $this->currentVersion = $this->currentVersion(); |
|
23 | - array_walk($files, function ($file) { |
|
24 | - $className = str_replace('.php', '', $file); |
|
25 | - $upgradeFromVersion = str_replace(['Upgrade_', '_'], ['', '.'], $className); |
|
26 | - $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
27 | - if (version_compare($this->currentVersion, $upgradeFromVersion.$suffix, '>=')) { |
|
28 | - return; |
|
29 | - } |
|
30 | - glsr('Modules\\Upgrader\\'.$className)->run(); |
|
31 | - glsr_log()->notice('Completed Upgrade for v'.$upgradeFromVersion.$suffix); |
|
32 | - }); |
|
33 | - $this->finish(); |
|
34 | - } |
|
16 | + /** |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + public function run() |
|
20 | + { |
|
21 | + $files = $this->getUpgraderFiles(); |
|
22 | + $this->currentVersion = $this->currentVersion(); |
|
23 | + array_walk($files, function ($file) { |
|
24 | + $className = str_replace('.php', '', $file); |
|
25 | + $upgradeFromVersion = str_replace(['Upgrade_', '_'], ['', '.'], $className); |
|
26 | + $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
27 | + if (version_compare($this->currentVersion, $upgradeFromVersion.$suffix, '>=')) { |
|
28 | + return; |
|
29 | + } |
|
30 | + glsr('Modules\\Upgrader\\'.$className)->run(); |
|
31 | + glsr_log()->notice('Completed Upgrade for v'.$upgradeFromVersion.$suffix); |
|
32 | + }); |
|
33 | + $this->finish(); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function finish() |
|
40 | - { |
|
41 | - if ($this->currentVersion !== glsr()->version) { |
|
42 | - $this->setReviewCounts(); |
|
43 | - $this->updateVersionFrom($this->currentVersion); |
|
44 | - } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
45 | - $this->setReviewCounts(); |
|
46 | - } |
|
47 | - } |
|
36 | + /** |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function finish() |
|
40 | + { |
|
41 | + if ($this->currentVersion !== glsr()->version) { |
|
42 | + $this->setReviewCounts(); |
|
43 | + $this->updateVersionFrom($this->currentVersion); |
|
44 | + } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
45 | + $this->setReviewCounts(); |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - protected function currentVersion() |
|
53 | - { |
|
54 | - $fallback = '0.0.0'; |
|
55 | - $majorVersions = [4, 3, 2]; |
|
56 | - foreach ($majorVersions as $majorVersion) { |
|
57 | - $settings = get_option(OptionManager::databaseKey($majorVersion)); |
|
58 | - $version = Arr::get($settings, 'version', $fallback); |
|
59 | - if (version_compare($version, $fallback, '>')) { |
|
60 | - return $version; |
|
61 | - } |
|
62 | - } |
|
63 | - return $fallback; |
|
64 | - } |
|
49 | + /** |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + protected function currentVersion() |
|
53 | + { |
|
54 | + $fallback = '0.0.0'; |
|
55 | + $majorVersions = [4, 3, 2]; |
|
56 | + foreach ($majorVersions as $majorVersion) { |
|
57 | + $settings = get_option(OptionManager::databaseKey($majorVersion)); |
|
58 | + $version = Arr::get($settings, 'version', $fallback); |
|
59 | + if (version_compare($version, $fallback, '>')) { |
|
60 | + return $version; |
|
61 | + } |
|
62 | + } |
|
63 | + return $fallback; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - protected function getUpgraderFiles() |
|
70 | - { |
|
71 | - $files = []; |
|
72 | - $upgradeDir = dirname(__FILE__).'/Upgrades'; |
|
73 | - if (is_dir($upgradeDir)) { |
|
74 | - $iterator = new DirectoryIterator($upgradeDir); |
|
75 | - foreach ($iterator as $fileinfo) { |
|
76 | - if ($fileinfo->isFile()) { |
|
77 | - $files[] = $fileinfo->getFilename(); |
|
78 | - } |
|
79 | - } |
|
80 | - natsort($files); |
|
81 | - } |
|
82 | - return $files; |
|
83 | - } |
|
66 | + /** |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + protected function getUpgraderFiles() |
|
70 | + { |
|
71 | + $files = []; |
|
72 | + $upgradeDir = dirname(__FILE__).'/Upgrades'; |
|
73 | + if (is_dir($upgradeDir)) { |
|
74 | + $iterator = new DirectoryIterator($upgradeDir); |
|
75 | + foreach ($iterator as $fileinfo) { |
|
76 | + if ($fileinfo->isFile()) { |
|
77 | + $files[] = $fileinfo->getFilename(); |
|
78 | + } |
|
79 | + } |
|
80 | + natsort($files); |
|
81 | + } |
|
82 | + return $files; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - protected function setReviewCounts() |
|
89 | - { |
|
90 | - add_action('admin_init', 'glsr_calculate_ratings'); |
|
91 | - } |
|
85 | + /** |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + protected function setReviewCounts() |
|
89 | + { |
|
90 | + add_action('admin_init', 'glsr_calculate_ratings'); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @param string $previousVersion |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - protected function updateVersionFrom($previousVersion) |
|
98 | - { |
|
99 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
100 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
101 | - } |
|
93 | + /** |
|
94 | + * @param string $previousVersion |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + protected function updateVersionFrom($previousVersion) |
|
98 | + { |
|
99 | + glsr(OptionManager::class)->set('version', glsr()->version); |
|
100 | + glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
101 | + } |
|
102 | 102 | } |
@@ -17,231 +17,231 @@ |
||
17 | 17 | |
18 | 18 | class AdminController extends Controller |
19 | 19 | { |
20 | - /** |
|
21 | - * @return void |
|
22 | - * @action admin_enqueue_scripts |
|
23 | - */ |
|
24 | - public function enqueueAssets() |
|
25 | - { |
|
26 | - $command = new EnqueueAdminAssets([ |
|
27 | - 'pointers' => [[ |
|
28 | - 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
29 | - 'id' => 'glsr-pointer-pinned', |
|
30 | - 'position' => [ |
|
31 | - 'edge' => 'right', |
|
32 | - 'align' => 'middle', |
|
33 | - ], |
|
34 | - 'screen' => Application::POST_TYPE, |
|
35 | - 'target' => '#misc-pub-pinned', |
|
36 | - 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
37 | - ]], |
|
38 | - ]); |
|
39 | - $this->execute($command); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @return array |
|
44 | - * @filter plugin_action_links_site-reviews/site-reviews.php |
|
45 | - */ |
|
46 | - public function filterActionLinks(array $links) |
|
47 | - { |
|
48 | - $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
49 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
50 | - ]); |
|
51 | - $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
52 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
53 | - ]); |
|
54 | - return $links; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param array $capabilities |
|
59 | - * @param string $capability |
|
60 | - * @return array |
|
61 | - * @filter map_meta_cap |
|
62 | - */ |
|
63 | - public function filterCreateCapability($capabilities, $capability) |
|
64 | - { |
|
65 | - if ($capability == 'create_'.Application::POST_TYPE) { |
|
66 | - $capabilities[] = 'do_not_allow'; |
|
67 | - } |
|
68 | - return $capabilities; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param array $items |
|
73 | - * @return array |
|
74 | - * @filter dashboard_glance_items |
|
75 | - */ |
|
76 | - public function filterDashboardGlanceItems($items) |
|
77 | - { |
|
78 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
79 | - if (empty($postCount->publish)) { |
|
80 | - return $items; |
|
81 | - } |
|
82 | - $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
83 | - $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
84 | - $items = Arr::consolidateArray($items); |
|
85 | - $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
86 | - ? glsr(Builder::class)->a($text, [ |
|
87 | - 'class' => 'glsr-review-count', |
|
88 | - 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
89 | - ]) |
|
90 | - : glsr(Builder::class)->span($text, [ |
|
91 | - 'class' => 'glsr-review-count', |
|
92 | - ]); |
|
93 | - return $items; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @param array $plugins |
|
98 | - * @return array |
|
99 | - * @filter mce_external_plugins |
|
100 | - */ |
|
101 | - public function filterTinymcePlugins($plugins) |
|
102 | - { |
|
103 | - if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
104 | - $plugins = Arr::consolidateArray($plugins); |
|
105 | - $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
106 | - } |
|
107 | - return $plugins; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @return void |
|
112 | - * @action admin_init |
|
113 | - */ |
|
114 | - public function registerTinymcePopups() |
|
115 | - { |
|
116 | - $command = new RegisterTinymcePopups([ |
|
117 | - 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
118 | - 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
119 | - 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
120 | - ]); |
|
121 | - $this->execute($command); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @param string $editorId |
|
126 | - * @return void|null |
|
127 | - * @action media_buttons |
|
128 | - */ |
|
129 | - public function renderTinymceButton($editorId) |
|
130 | - { |
|
131 | - $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
132 | - if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
133 | - return; |
|
134 | - } |
|
135 | - $shortcodes = []; |
|
136 | - foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
137 | - $shortcodes[$shortcode] = $values; |
|
138 | - } |
|
139 | - if (empty($shortcodes)) { |
|
140 | - return; |
|
141 | - } |
|
142 | - glsr()->render('partials/editor/tinymce', [ |
|
143 | - 'shortcodes' => $shortcodes, |
|
144 | - ]); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return void |
|
149 | - */ |
|
150 | - public function routerClearConsole() |
|
151 | - { |
|
152 | - glsr(Console::class)->clear(); |
|
153 | - glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - public function routerFetchConsole() |
|
160 | - { |
|
161 | - glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @param bool $showNotice |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - public function routerCountReviews($showNotice = true) |
|
169 | - { |
|
170 | - glsr(CountsManager::class)->updateAll(); |
|
171 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
172 | - if ($showNotice) { |
|
173 | - glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * @return void |
|
179 | - */ |
|
180 | - public function routerMigrateReviews() |
|
181 | - { |
|
182 | - glsr(Upgrade_4_0_2::class)->protectMetaKeys(); |
|
183 | - glsr(Notice::class)->clear()->addSuccess(__('All reviews have been migrated.', 'site-reviews')); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - public function routerDownloadConsole() |
|
190 | - { |
|
191 | - $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @return void |
|
196 | - */ |
|
197 | - public function routerDownloadSystemInfo() |
|
198 | - { |
|
199 | - $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - public function routerExportSettings() |
|
206 | - { |
|
207 | - $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @return void |
|
212 | - */ |
|
213 | - public function routerImportSettings() |
|
214 | - { |
|
215 | - $file = $_FILES['import-file']; |
|
216 | - if (UPLOAD_ERR_OK !== $file['error']) { |
|
217 | - return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
218 | - } |
|
219 | - if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
220 | - return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
221 | - } |
|
222 | - $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
223 | - if (empty($settings)) { |
|
224 | - return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
225 | - } |
|
226 | - glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
227 | - glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @param int $errorCode |
|
232 | - * @return string |
|
233 | - */ |
|
234 | - protected function getUploadError($errorCode) |
|
235 | - { |
|
236 | - $errors = [ |
|
237 | - UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
238 | - UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
239 | - UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
240 | - UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
241 | - UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
242 | - UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
243 | - UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
244 | - ]; |
|
245 | - return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
246 | - } |
|
20 | + /** |
|
21 | + * @return void |
|
22 | + * @action admin_enqueue_scripts |
|
23 | + */ |
|
24 | + public function enqueueAssets() |
|
25 | + { |
|
26 | + $command = new EnqueueAdminAssets([ |
|
27 | + 'pointers' => [[ |
|
28 | + 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
29 | + 'id' => 'glsr-pointer-pinned', |
|
30 | + 'position' => [ |
|
31 | + 'edge' => 'right', |
|
32 | + 'align' => 'middle', |
|
33 | + ], |
|
34 | + 'screen' => Application::POST_TYPE, |
|
35 | + 'target' => '#misc-pub-pinned', |
|
36 | + 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
37 | + ]], |
|
38 | + ]); |
|
39 | + $this->execute($command); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @return array |
|
44 | + * @filter plugin_action_links_site-reviews/site-reviews.php |
|
45 | + */ |
|
46 | + public function filterActionLinks(array $links) |
|
47 | + { |
|
48 | + $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
49 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
50 | + ]); |
|
51 | + $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
52 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
53 | + ]); |
|
54 | + return $links; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param array $capabilities |
|
59 | + * @param string $capability |
|
60 | + * @return array |
|
61 | + * @filter map_meta_cap |
|
62 | + */ |
|
63 | + public function filterCreateCapability($capabilities, $capability) |
|
64 | + { |
|
65 | + if ($capability == 'create_'.Application::POST_TYPE) { |
|
66 | + $capabilities[] = 'do_not_allow'; |
|
67 | + } |
|
68 | + return $capabilities; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param array $items |
|
73 | + * @return array |
|
74 | + * @filter dashboard_glance_items |
|
75 | + */ |
|
76 | + public function filterDashboardGlanceItems($items) |
|
77 | + { |
|
78 | + $postCount = wp_count_posts(Application::POST_TYPE); |
|
79 | + if (empty($postCount->publish)) { |
|
80 | + return $items; |
|
81 | + } |
|
82 | + $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
83 | + $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
84 | + $items = Arr::consolidateArray($items); |
|
85 | + $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
86 | + ? glsr(Builder::class)->a($text, [ |
|
87 | + 'class' => 'glsr-review-count', |
|
88 | + 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
89 | + ]) |
|
90 | + : glsr(Builder::class)->span($text, [ |
|
91 | + 'class' => 'glsr-review-count', |
|
92 | + ]); |
|
93 | + return $items; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @param array $plugins |
|
98 | + * @return array |
|
99 | + * @filter mce_external_plugins |
|
100 | + */ |
|
101 | + public function filterTinymcePlugins($plugins) |
|
102 | + { |
|
103 | + if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
104 | + $plugins = Arr::consolidateArray($plugins); |
|
105 | + $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
106 | + } |
|
107 | + return $plugins; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @return void |
|
112 | + * @action admin_init |
|
113 | + */ |
|
114 | + public function registerTinymcePopups() |
|
115 | + { |
|
116 | + $command = new RegisterTinymcePopups([ |
|
117 | + 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
118 | + 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
119 | + 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
120 | + ]); |
|
121 | + $this->execute($command); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @param string $editorId |
|
126 | + * @return void|null |
|
127 | + * @action media_buttons |
|
128 | + */ |
|
129 | + public function renderTinymceButton($editorId) |
|
130 | + { |
|
131 | + $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
132 | + if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
133 | + return; |
|
134 | + } |
|
135 | + $shortcodes = []; |
|
136 | + foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
137 | + $shortcodes[$shortcode] = $values; |
|
138 | + } |
|
139 | + if (empty($shortcodes)) { |
|
140 | + return; |
|
141 | + } |
|
142 | + glsr()->render('partials/editor/tinymce', [ |
|
143 | + 'shortcodes' => $shortcodes, |
|
144 | + ]); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return void |
|
149 | + */ |
|
150 | + public function routerClearConsole() |
|
151 | + { |
|
152 | + glsr(Console::class)->clear(); |
|
153 | + glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + public function routerFetchConsole() |
|
160 | + { |
|
161 | + glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @param bool $showNotice |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + public function routerCountReviews($showNotice = true) |
|
169 | + { |
|
170 | + glsr(CountsManager::class)->updateAll(); |
|
171 | + glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
172 | + if ($showNotice) { |
|
173 | + glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * @return void |
|
179 | + */ |
|
180 | + public function routerMigrateReviews() |
|
181 | + { |
|
182 | + glsr(Upgrade_4_0_2::class)->protectMetaKeys(); |
|
183 | + glsr(Notice::class)->clear()->addSuccess(__('All reviews have been migrated.', 'site-reviews')); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + public function routerDownloadConsole() |
|
190 | + { |
|
191 | + $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @return void |
|
196 | + */ |
|
197 | + public function routerDownloadSystemInfo() |
|
198 | + { |
|
199 | + $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + public function routerExportSettings() |
|
206 | + { |
|
207 | + $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @return void |
|
212 | + */ |
|
213 | + public function routerImportSettings() |
|
214 | + { |
|
215 | + $file = $_FILES['import-file']; |
|
216 | + if (UPLOAD_ERR_OK !== $file['error']) { |
|
217 | + return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
218 | + } |
|
219 | + if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
220 | + return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
221 | + } |
|
222 | + $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
223 | + if (empty($settings)) { |
|
224 | + return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
225 | + } |
|
226 | + glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
227 | + glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @param int $errorCode |
|
232 | + * @return string |
|
233 | + */ |
|
234 | + protected function getUploadError($errorCode) |
|
235 | + { |
|
236 | + $errors = [ |
|
237 | + UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
238 | + UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
239 | + UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
240 | + UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
241 | + UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
242 | + UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
243 | + UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
244 | + ]; |
|
245 | + return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
246 | + } |
|
247 | 247 | } |