@@ -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 | } |
@@ -13,246 +13,246 @@ |
||
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 | - return $this->combine($results); |
|
175 | - } |
|
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 | + return $this->combine($results); |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - protected function hasMixedAssignment(array $args) |
|
181 | - { |
|
182 | - return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
183 | - } |
|
177 | + /** |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + protected function hasMixedAssignment(array $args) |
|
181 | + { |
|
182 | + return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * @return array |
|
187 | - */ |
|
188 | - protected function normalize(array $reviewCounts) |
|
189 | - { |
|
190 | - foreach ($reviewCounts as &$counts) { |
|
191 | - foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
192 | - if (!isset($counts[$index])) { |
|
193 | - $counts[$index] = 0; |
|
194 | - } |
|
195 | - } |
|
196 | - ksort($counts); |
|
197 | - } |
|
198 | - return $reviewCounts; |
|
199 | - } |
|
185 | + /** |
|
186 | + * @return array |
|
187 | + */ |
|
188 | + protected function normalize(array $reviewCounts) |
|
189 | + { |
|
190 | + foreach ($reviewCounts as &$counts) { |
|
191 | + foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
192 | + if (!isset($counts[$index])) { |
|
193 | + $counts[$index] = 0; |
|
194 | + } |
|
195 | + } |
|
196 | + ksort($counts); |
|
197 | + } |
|
198 | + return $reviewCounts; |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - protected function normalizeArgs(array $args) |
|
205 | - { |
|
206 | - $args = wp_parse_args(array_filter($args), [ |
|
207 | - 'post_ids' => [], |
|
208 | - 'term_ids' => [], |
|
209 | - 'type' => 'local', |
|
210 | - ]); |
|
211 | - $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
212 | - $args['type'] = $this->normalizeType($args['type']); |
|
213 | - return $args; |
|
214 | - } |
|
201 | + /** |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + protected function normalizeArgs(array $args) |
|
205 | + { |
|
206 | + $args = wp_parse_args(array_filter($args), [ |
|
207 | + 'post_ids' => [], |
|
208 | + 'term_ids' => [], |
|
209 | + 'type' => 'local', |
|
210 | + ]); |
|
211 | + $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
212 | + $args['type'] = $this->normalizeType($args['type']); |
|
213 | + return $args; |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * @param string $type |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - protected function normalizeType($type) |
|
221 | - { |
|
222 | - return empty($type) || !is_string($type) |
|
223 | - ? 'local' |
|
224 | - : $type; |
|
225 | - } |
|
216 | + /** |
|
217 | + * @param string $type |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + protected function normalizeType($type) |
|
221 | + { |
|
222 | + return empty($type) || !is_string($type) |
|
223 | + ? 'local' |
|
224 | + : $type; |
|
225 | + } |
|
226 | 226 | |
227 | - /** |
|
228 | - * @param object $query |
|
229 | - * @return array |
|
230 | - */ |
|
231 | - protected function populateCountsFromQuery($query, array $counts) |
|
232 | - { |
|
233 | - foreach ($query->reviews as $review) { |
|
234 | - $type = $this->normalizeType($review->type); |
|
235 | - if (!array_key_exists($type, $counts)) { |
|
236 | - $counts[$type] = $this->generateEmptyCountsArray(); |
|
237 | - } |
|
238 | - ++$counts[$type][$review->rating]; |
|
239 | - } |
|
240 | - return $counts; |
|
241 | - } |
|
227 | + /** |
|
228 | + * @param object $query |
|
229 | + * @return array |
|
230 | + */ |
|
231 | + protected function populateCountsFromQuery($query, array $counts) |
|
232 | + { |
|
233 | + foreach ($query->reviews as $review) { |
|
234 | + $type = $this->normalizeType($review->type); |
|
235 | + if (!array_key_exists($type, $counts)) { |
|
236 | + $counts[$type] = $this->generateEmptyCountsArray(); |
|
237 | + } |
|
238 | + ++$counts[$type][$review->rating]; |
|
239 | + } |
|
240 | + return $counts; |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * @param int $lastPostId |
|
245 | - * @return object |
|
246 | - */ |
|
247 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
248 | - { |
|
249 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
250 | - $hasMore = is_array($reviews) |
|
251 | - ? count($reviews) == static::LIMIT |
|
252 | - : false; |
|
253 | - return (object) [ |
|
254 | - 'has_more' => $hasMore, |
|
255 | - 'reviews' => $reviews, |
|
256 | - ]; |
|
257 | - } |
|
243 | + /** |
|
244 | + * @param int $lastPostId |
|
245 | + * @return object |
|
246 | + */ |
|
247 | + protected function queryReviews(array $args = [], $lastPostId = 0) |
|
248 | + { |
|
249 | + $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
250 | + $hasMore = is_array($reviews) |
|
251 | + ? count($reviews) == static::LIMIT |
|
252 | + : false; |
|
253 | + return (object) [ |
|
254 | + 'has_more' => $hasMore, |
|
255 | + 'reviews' => $reviews, |
|
256 | + ]; |
|
257 | + } |
|
258 | 258 | } |
@@ -8,139 +8,139 @@ |
||
8 | 8 | |
9 | 9 | class Helper |
10 | 10 | { |
11 | - /** |
|
12 | - * @param string $name |
|
13 | - * @param string $path |
|
14 | - * @return string |
|
15 | - */ |
|
16 | - public static function buildClassName($name, $path = '') |
|
17 | - { |
|
18 | - $className = Str::camelCase($name); |
|
19 | - $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
20 | - return !empty($path) |
|
21 | - ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
22 | - : $className; |
|
23 | - } |
|
11 | + /** |
|
12 | + * @param string $name |
|
13 | + * @param string $path |
|
14 | + * @return string |
|
15 | + */ |
|
16 | + public static function buildClassName($name, $path = '') |
|
17 | + { |
|
18 | + $className = Str::camelCase($name); |
|
19 | + $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
20 | + return !empty($path) |
|
21 | + ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
22 | + : $className; |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param string $name |
|
27 | - * @param string $prefix |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public static function buildMethodName($name, $prefix = '') |
|
31 | - { |
|
32 | - return lcfirst($prefix.static::buildClassName($name)); |
|
33 | - } |
|
25 | + /** |
|
26 | + * @param string $name |
|
27 | + * @param string $prefix |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public static function buildMethodName($name, $prefix = '') |
|
31 | + { |
|
32 | + return lcfirst($prefix.static::buildClassName($name)); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param string $name |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public static function buildPropertyName($name) |
|
40 | - { |
|
41 | - return static::buildMethodName($name); |
|
42 | - } |
|
35 | + /** |
|
36 | + * @param string $name |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public static function buildPropertyName($name) |
|
40 | + { |
|
41 | + return static::buildMethodName($name); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param string $cast |
|
46 | - * @param mixed $value |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public static function castTo($cast = '', $value) |
|
50 | - { |
|
51 | - switch ($cast) { |
|
52 | - case 'array': |
|
53 | - return (array) $value; |
|
54 | - case 'bool': |
|
55 | - case 'boolean': |
|
56 | - return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
57 | - case 'float': |
|
58 | - return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
59 | - case 'int': |
|
60 | - case 'integer': |
|
61 | - return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
62 | - case 'object': |
|
63 | - return (object) (array) $value; |
|
64 | - case 'str': |
|
65 | - case 'string': |
|
66 | - if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
67 | - return (string) $value->__toString(); |
|
68 | - } |
|
69 | - if (is_array($value) || is_object($value)) { |
|
70 | - return serialize($value); |
|
71 | - } |
|
72 | - return (string) $value; |
|
73 | - default: |
|
74 | - return $value; |
|
75 | - } |
|
76 | - } |
|
44 | + /** |
|
45 | + * @param string $cast |
|
46 | + * @param mixed $value |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public static function castTo($cast = '', $value) |
|
50 | + { |
|
51 | + switch ($cast) { |
|
52 | + case 'array': |
|
53 | + return (array) $value; |
|
54 | + case 'bool': |
|
55 | + case 'boolean': |
|
56 | + return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
57 | + case 'float': |
|
58 | + return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
59 | + case 'int': |
|
60 | + case 'integer': |
|
61 | + return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
62 | + case 'object': |
|
63 | + return (object) (array) $value; |
|
64 | + case 'str': |
|
65 | + case 'string': |
|
66 | + if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
67 | + return (string) $value->__toString(); |
|
68 | + } |
|
69 | + if (is_array($value) || is_object($value)) { |
|
70 | + return serialize($value); |
|
71 | + } |
|
72 | + return (string) $value; |
|
73 | + default: |
|
74 | + return $value; |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $key |
|
80 | - * @return mixed |
|
81 | - */ |
|
82 | - public static function filterInput($key, array $request = []) |
|
83 | - { |
|
84 | - if (isset($request[$key])) { |
|
85 | - return $request[$key]; |
|
86 | - } |
|
87 | - $variable = filter_input(INPUT_POST, $key); |
|
88 | - if (is_null($variable) && isset($_POST[$key])) { |
|
89 | - $variable = $_POST[$key]; |
|
90 | - } |
|
91 | - return $variable; |
|
92 | - } |
|
78 | + /** |
|
79 | + * @param string $key |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | + public static function filterInput($key, array $request = []) |
|
83 | + { |
|
84 | + if (isset($request[$key])) { |
|
85 | + return $request[$key]; |
|
86 | + } |
|
87 | + $variable = filter_input(INPUT_POST, $key); |
|
88 | + if (is_null($variable) && isset($_POST[$key])) { |
|
89 | + $variable = $_POST[$key]; |
|
90 | + } |
|
91 | + return $variable; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @param string $key |
|
96 | - * @return array |
|
97 | - */ |
|
98 | - public static function filterInputArray($key) |
|
99 | - { |
|
100 | - $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
101 | - if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
102 | - $variable = $_POST[$key]; |
|
103 | - } |
|
104 | - return (array) $variable; |
|
105 | - } |
|
94 | + /** |
|
95 | + * @param string $key |
|
96 | + * @return array |
|
97 | + */ |
|
98 | + public static function filterInputArray($key) |
|
99 | + { |
|
100 | + $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
101 | + if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
102 | + $variable = $_POST[$key]; |
|
103 | + } |
|
104 | + return (array) $variable; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public static function getIpAddress() |
|
111 | - { |
|
112 | - $whitelist = []; |
|
113 | - $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP')); |
|
114 | - if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) { |
|
115 | - $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
116 | - $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']]; |
|
117 | - if (defined('AF_INET6')) { |
|
118 | - $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6']; |
|
119 | - } |
|
120 | - } |
|
121 | - $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist); |
|
122 | - $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS); |
|
123 | - $whip = new Whip($methods, $whitelist); |
|
124 | - do_action_ref_array('site-reviews/whip', [$whip]); |
|
125 | - if (false !== ($clientAddress = $whip->getValidIpAddress())) { |
|
126 | - return (string) $clientAddress; |
|
127 | - } |
|
128 | - glsr_log()->error('Unable to detect IP address.'); |
|
129 | - return 'unknown'; |
|
130 | - } |
|
107 | + /** |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public static function getIpAddress() |
|
111 | + { |
|
112 | + $whitelist = []; |
|
113 | + $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP')); |
|
114 | + if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) { |
|
115 | + $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
116 | + $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']]; |
|
117 | + if (defined('AF_INET6')) { |
|
118 | + $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6']; |
|
119 | + } |
|
120 | + } |
|
121 | + $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist); |
|
122 | + $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS); |
|
123 | + $whip = new Whip($methods, $whitelist); |
|
124 | + do_action_ref_array('site-reviews/whip', [$whip]); |
|
125 | + if (false !== ($clientAddress = $whip->getValidIpAddress())) { |
|
126 | + return (string) $clientAddress; |
|
127 | + } |
|
128 | + glsr_log()->error('Unable to detect IP address.'); |
|
129 | + return 'unknown'; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @param mixed $value |
|
134 | - * @param string|int $min |
|
135 | - * @param string|int $max |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - public static function inRange($value, $min, $max) |
|
139 | - { |
|
140 | - $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [ |
|
141 | - 'min_range' => intval($min), |
|
142 | - 'max_range' => intval($max), |
|
143 | - ]]); |
|
144 | - return false !== $inRange; |
|
145 | - } |
|
132 | + /** |
|
133 | + * @param mixed $value |
|
134 | + * @param string|int $min |
|
135 | + * @param string|int $max |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + public static function inRange($value, $min, $max) |
|
139 | + { |
|
140 | + $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [ |
|
141 | + 'min_range' => intval($min), |
|
142 | + 'max_range' => intval($max), |
|
143 | + ]]); |
|
144 | + return false !== $inRange; |
|
145 | + } |
|
146 | 146 | } |