@@ -14,346 +14,346 @@ |
||
14 | 14 | |
15 | 15 | class ListTableController extends Controller |
16 | 16 | { |
17 | - /** |
|
18 | - * @return void |
|
19 | - * @action admin_action_approve |
|
20 | - */ |
|
21 | - public function approve() |
|
22 | - { |
|
23 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
24 | - return; |
|
25 | - } |
|
26 | - check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
27 | - wp_update_post([ |
|
28 | - 'ID' => $postId, |
|
29 | - 'post_status' => 'publish', |
|
30 | - ]); |
|
31 | - wp_safe_redirect(wp_get_referer()); |
|
32 | - exit; |
|
33 | - } |
|
17 | + /** |
|
18 | + * @return void |
|
19 | + * @action admin_action_approve |
|
20 | + */ |
|
21 | + public function approve() |
|
22 | + { |
|
23 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
24 | + return; |
|
25 | + } |
|
26 | + check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
27 | + wp_update_post([ |
|
28 | + 'ID' => $postId, |
|
29 | + 'post_status' => 'publish', |
|
30 | + ]); |
|
31 | + wp_safe_redirect(wp_get_referer()); |
|
32 | + exit; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param array $messages |
|
37 | - * @return array |
|
38 | - * @filter bulk_post_updated_messages |
|
39 | - */ |
|
40 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
41 | - { |
|
42 | - $messages = Arr::consolidateArray($messages); |
|
43 | - $messages[Application::POST_TYPE] = [ |
|
44 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
45 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
46 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
47 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
48 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
49 | - ]; |
|
50 | - return $messages; |
|
51 | - } |
|
35 | + /** |
|
36 | + * @param array $messages |
|
37 | + * @return array |
|
38 | + * @filter bulk_post_updated_messages |
|
39 | + */ |
|
40 | + public function filterBulkUpdateMessages($messages, array $counts) |
|
41 | + { |
|
42 | + $messages = Arr::consolidateArray($messages); |
|
43 | + $messages[Application::POST_TYPE] = [ |
|
44 | + 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
45 | + 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
46 | + 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
47 | + 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
48 | + 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
49 | + ]; |
|
50 | + return $messages; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param array $columns |
|
55 | - * @return array |
|
56 | - * @filter manage_.Application::POST_TYPE._posts_columns |
|
57 | - */ |
|
58 | - public function filterColumnsForPostType($columns) |
|
59 | - { |
|
60 | - $columns = Arr::consolidateArray($columns); |
|
61 | - $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
62 | - foreach ($postTypeColumns as $key => &$value) { |
|
63 | - if (!array_key_exists($key, $columns) || !empty($value)) { |
|
64 | - continue; |
|
65 | - } |
|
66 | - $value = $columns[$key]; |
|
67 | - } |
|
68 | - if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
69 | - unset($postTypeColumns['review_type']); |
|
70 | - } |
|
71 | - return array_filter($postTypeColumns, 'strlen'); |
|
72 | - } |
|
53 | + /** |
|
54 | + * @param array $columns |
|
55 | + * @return array |
|
56 | + * @filter manage_.Application::POST_TYPE._posts_columns |
|
57 | + */ |
|
58 | + public function filterColumnsForPostType($columns) |
|
59 | + { |
|
60 | + $columns = Arr::consolidateArray($columns); |
|
61 | + $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
62 | + foreach ($postTypeColumns as $key => &$value) { |
|
63 | + if (!array_key_exists($key, $columns) || !empty($value)) { |
|
64 | + continue; |
|
65 | + } |
|
66 | + $value = $columns[$key]; |
|
67 | + } |
|
68 | + if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
69 | + unset($postTypeColumns['review_type']); |
|
70 | + } |
|
71 | + return array_filter($postTypeColumns, 'strlen'); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $status |
|
76 | - * @param WP_Post $post |
|
77 | - * @return string |
|
78 | - * @filter post_date_column_status |
|
79 | - */ |
|
80 | - public function filterDateColumnStatus($status, $post) |
|
81 | - { |
|
82 | - if (Application::POST_TYPE == Arr::get($post, 'post_type')) { |
|
83 | - $status = __('Submitted', 'site-reviews'); |
|
84 | - } |
|
85 | - return $status; |
|
86 | - } |
|
74 | + /** |
|
75 | + * @param string $status |
|
76 | + * @param WP_Post $post |
|
77 | + * @return string |
|
78 | + * @filter post_date_column_status |
|
79 | + */ |
|
80 | + public function filterDateColumnStatus($status, $post) |
|
81 | + { |
|
82 | + if (Application::POST_TYPE == Arr::get($post, 'post_type')) { |
|
83 | + $status = __('Submitted', 'site-reviews'); |
|
84 | + } |
|
85 | + return $status; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @param array $hidden |
|
90 | - * @param WP_Screen $post |
|
91 | - * @return array |
|
92 | - * @filter default_hidden_columns |
|
93 | - */ |
|
94 | - public function filterDefaultHiddenColumns($hidden, $screen) |
|
95 | - { |
|
96 | - if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
97 | - $hidden = Arr::consolidateArray($hidden); |
|
98 | - $hidden = ['reviewer']; |
|
99 | - } |
|
100 | - return $hidden; |
|
101 | - } |
|
88 | + /** |
|
89 | + * @param array $hidden |
|
90 | + * @param WP_Screen $post |
|
91 | + * @return array |
|
92 | + * @filter default_hidden_columns |
|
93 | + */ |
|
94 | + public function filterDefaultHiddenColumns($hidden, $screen) |
|
95 | + { |
|
96 | + if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
97 | + $hidden = Arr::consolidateArray($hidden); |
|
98 | + $hidden = ['reviewer']; |
|
99 | + } |
|
100 | + return $hidden; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @param array $postStates |
|
105 | - * @param WP_Post $post |
|
106 | - * @return array |
|
107 | - * @filter display_post_states |
|
108 | - */ |
|
109 | - public function filterPostStates($postStates, $post) |
|
110 | - { |
|
111 | - $postStates = Arr::consolidateArray($postStates); |
|
112 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
113 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
114 | - } |
|
115 | - return $postStates; |
|
116 | - } |
|
103 | + /** |
|
104 | + * @param array $postStates |
|
105 | + * @param WP_Post $post |
|
106 | + * @return array |
|
107 | + * @filter display_post_states |
|
108 | + */ |
|
109 | + public function filterPostStates($postStates, $post) |
|
110 | + { |
|
111 | + $postStates = Arr::consolidateArray($postStates); |
|
112 | + if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
113 | + $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
114 | + } |
|
115 | + return $postStates; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @param array $actions |
|
120 | - * @param WP_Post $post |
|
121 | - * @return array |
|
122 | - * @filter post_row_actions |
|
123 | - */ |
|
124 | - public function filterRowActions($actions, $post) |
|
125 | - { |
|
126 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) { |
|
127 | - return $actions; |
|
128 | - } |
|
129 | - unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
|
130 | - $rowActions = [ |
|
131 | - 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
132 | - 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
133 | - ]; |
|
134 | - $newActions = []; |
|
135 | - foreach ($rowActions as $key => $text) { |
|
136 | - $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
137 | - 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
138 | - 'class' => 'glsr-change-status', |
|
139 | - 'href' => wp_nonce_url( |
|
140 | - admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
141 | - $key.'-review_'.$post->ID |
|
142 | - ), |
|
143 | - ]); |
|
144 | - } |
|
145 | - return $newActions + Arr::consolidateArray($actions); |
|
146 | - } |
|
118 | + /** |
|
119 | + * @param array $actions |
|
120 | + * @param WP_Post $post |
|
121 | + * @return array |
|
122 | + * @filter post_row_actions |
|
123 | + */ |
|
124 | + public function filterRowActions($actions, $post) |
|
125 | + { |
|
126 | + if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) { |
|
127 | + return $actions; |
|
128 | + } |
|
129 | + unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
|
130 | + $rowActions = [ |
|
131 | + 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
132 | + 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
133 | + ]; |
|
134 | + $newActions = []; |
|
135 | + foreach ($rowActions as $key => $text) { |
|
136 | + $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
137 | + 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
138 | + 'class' => 'glsr-change-status', |
|
139 | + 'href' => wp_nonce_url( |
|
140 | + admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
141 | + $key.'-review_'.$post->ID |
|
142 | + ), |
|
143 | + ]); |
|
144 | + } |
|
145 | + return $newActions + Arr::consolidateArray($actions); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * @param array $columns |
|
150 | - * @return array |
|
151 | - * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
|
152 | - */ |
|
153 | - public function filterSortableColumns($columns) |
|
154 | - { |
|
155 | - $columns = Arr::consolidateArray($columns); |
|
156 | - $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
157 | - unset($postTypeColumns['cb']); |
|
158 | - foreach ($postTypeColumns as $key => $value) { |
|
159 | - if (Str::startsWith('taxonomy', $key)) { |
|
160 | - continue; |
|
161 | - } |
|
162 | - $columns[$key] = $key; |
|
163 | - } |
|
164 | - return $columns; |
|
165 | - } |
|
148 | + /** |
|
149 | + * @param array $columns |
|
150 | + * @return array |
|
151 | + * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
|
152 | + */ |
|
153 | + public function filterSortableColumns($columns) |
|
154 | + { |
|
155 | + $columns = Arr::consolidateArray($columns); |
|
156 | + $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
157 | + unset($postTypeColumns['cb']); |
|
158 | + foreach ($postTypeColumns as $key => $value) { |
|
159 | + if (Str::startsWith('taxonomy', $key)) { |
|
160 | + continue; |
|
161 | + } |
|
162 | + $columns[$key] = $key; |
|
163 | + } |
|
164 | + return $columns; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Customize the post_type status text. |
|
169 | - * @param string $translation |
|
170 | - * @param string $single |
|
171 | - * @param string $plural |
|
172 | - * @param int $number |
|
173 | - * @param string $domain |
|
174 | - * @return string |
|
175 | - * @filter ngettext |
|
176 | - */ |
|
177 | - public function filterStatusText($translation, $single, $plural, $number, $domain) |
|
178 | - { |
|
179 | - if ($this->canModifyTranslation($domain)) { |
|
180 | - $strings = [ |
|
181 | - 'Published' => __('Approved', 'site-reviews'), |
|
182 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
183 | - ]; |
|
184 | - foreach ($strings as $search => $replace) { |
|
185 | - if (false === strpos($single, $search)) { |
|
186 | - continue; |
|
187 | - } |
|
188 | - $translation = $this->getTranslation([ |
|
189 | - 'number' => $number, |
|
190 | - 'plural' => str_replace($search, $replace, $plural), |
|
191 | - 'single' => str_replace($search, $replace, $single), |
|
192 | - ]); |
|
193 | - } |
|
194 | - } |
|
195 | - return $translation; |
|
196 | - } |
|
167 | + /** |
|
168 | + * Customize the post_type status text. |
|
169 | + * @param string $translation |
|
170 | + * @param string $single |
|
171 | + * @param string $plural |
|
172 | + * @param int $number |
|
173 | + * @param string $domain |
|
174 | + * @return string |
|
175 | + * @filter ngettext |
|
176 | + */ |
|
177 | + public function filterStatusText($translation, $single, $plural, $number, $domain) |
|
178 | + { |
|
179 | + if ($this->canModifyTranslation($domain)) { |
|
180 | + $strings = [ |
|
181 | + 'Published' => __('Approved', 'site-reviews'), |
|
182 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
183 | + ]; |
|
184 | + foreach ($strings as $search => $replace) { |
|
185 | + if (false === strpos($single, $search)) { |
|
186 | + continue; |
|
187 | + } |
|
188 | + $translation = $this->getTranslation([ |
|
189 | + 'number' => $number, |
|
190 | + 'plural' => str_replace($search, $replace, $plural), |
|
191 | + 'single' => str_replace($search, $replace, $single), |
|
192 | + ]); |
|
193 | + } |
|
194 | + } |
|
195 | + return $translation; |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * @param string $columnName |
|
200 | - * @param string $postType |
|
201 | - * @return void |
|
202 | - * @action bulk_edit_custom_box |
|
203 | - */ |
|
204 | - public function renderBulkEditFields($columnName, $postType) |
|
205 | - { |
|
206 | - if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
207 | - glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
208 | - } |
|
209 | - } |
|
198 | + /** |
|
199 | + * @param string $columnName |
|
200 | + * @param string $postType |
|
201 | + * @return void |
|
202 | + * @action bulk_edit_custom_box |
|
203 | + */ |
|
204 | + public function renderBulkEditFields($columnName, $postType) |
|
205 | + { |
|
206 | + if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
207 | + glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
208 | + } |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * @param string $postType |
|
213 | - * @return void |
|
214 | - * @action restrict_manage_posts |
|
215 | - */ |
|
216 | - public function renderColumnFilters($postType) |
|
217 | - { |
|
218 | - glsr(Columns::class)->renderFilters($postType); |
|
219 | - } |
|
211 | + /** |
|
212 | + * @param string $postType |
|
213 | + * @return void |
|
214 | + * @action restrict_manage_posts |
|
215 | + */ |
|
216 | + public function renderColumnFilters($postType) |
|
217 | + { |
|
218 | + glsr(Columns::class)->renderFilters($postType); |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * @param string $column |
|
223 | - * @param string $postId |
|
224 | - * @return void |
|
225 | - * @action manage_posts_custom_column |
|
226 | - */ |
|
227 | - public function renderColumnValues($column, $postId) |
|
228 | - { |
|
229 | - glsr(Columns::class)->renderValues($column, $postId); |
|
230 | - } |
|
221 | + /** |
|
222 | + * @param string $column |
|
223 | + * @param string $postId |
|
224 | + * @return void |
|
225 | + * @action manage_posts_custom_column |
|
226 | + */ |
|
227 | + public function renderColumnValues($column, $postId) |
|
228 | + { |
|
229 | + glsr(Columns::class)->renderValues($column, $postId); |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * @param int $postId |
|
234 | - * @return void |
|
235 | - * @action save_post_.Application::POST_TYPE |
|
236 | - */ |
|
237 | - public function saveBulkEditFields($postId) |
|
238 | - { |
|
239 | - if (!current_user_can('edit_posts')) { |
|
240 | - return; |
|
241 | - } |
|
242 | - $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
243 | - if ($assignedTo && get_post($assignedTo)) { |
|
244 | - glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
245 | - } |
|
246 | - } |
|
232 | + /** |
|
233 | + * @param int $postId |
|
234 | + * @return void |
|
235 | + * @action save_post_.Application::POST_TYPE |
|
236 | + */ |
|
237 | + public function saveBulkEditFields($postId) |
|
238 | + { |
|
239 | + if (!current_user_can('edit_posts')) { |
|
240 | + return; |
|
241 | + } |
|
242 | + $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
243 | + if ($assignedTo && get_post($assignedTo)) { |
|
244 | + glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
245 | + } |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * @return void |
|
250 | - * @action pre_get_posts |
|
251 | - */ |
|
252 | - public function setQueryForColumn(WP_Query $query) |
|
253 | - { |
|
254 | - if (!$this->hasPermission($query)) { |
|
255 | - return; |
|
256 | - } |
|
257 | - $this->setMetaQuery($query, [ |
|
258 | - 'rating', 'review_type', |
|
259 | - ]); |
|
260 | - $this->setOrderby($query); |
|
261 | - } |
|
248 | + /** |
|
249 | + * @return void |
|
250 | + * @action pre_get_posts |
|
251 | + */ |
|
252 | + public function setQueryForColumn(WP_Query $query) |
|
253 | + { |
|
254 | + if (!$this->hasPermission($query)) { |
|
255 | + return; |
|
256 | + } |
|
257 | + $this->setMetaQuery($query, [ |
|
258 | + 'rating', 'review_type', |
|
259 | + ]); |
|
260 | + $this->setOrderby($query); |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * @return void |
|
265 | - * @action admin_action_unapprove |
|
266 | - */ |
|
267 | - public function unapprove() |
|
268 | - { |
|
269 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
270 | - return; |
|
271 | - } |
|
272 | - check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
273 | - wp_update_post([ |
|
274 | - 'ID' => $postId, |
|
275 | - 'post_status' => 'pending', |
|
276 | - ]); |
|
277 | - wp_safe_redirect(wp_get_referer()); |
|
278 | - exit; |
|
279 | - } |
|
263 | + /** |
|
264 | + * @return void |
|
265 | + * @action admin_action_unapprove |
|
266 | + */ |
|
267 | + public function unapprove() |
|
268 | + { |
|
269 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
270 | + return; |
|
271 | + } |
|
272 | + check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
273 | + wp_update_post([ |
|
274 | + 'ID' => $postId, |
|
275 | + 'post_status' => 'pending', |
|
276 | + ]); |
|
277 | + wp_safe_redirect(wp_get_referer()); |
|
278 | + exit; |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * Check if the translation string can be modified. |
|
283 | - * @param string $domain |
|
284 | - * @return bool |
|
285 | - */ |
|
286 | - protected function canModifyTranslation($domain = 'default') |
|
287 | - { |
|
288 | - $screen = glsr_current_screen(); |
|
289 | - return 'default' == $domain |
|
290 | - && 'edit' == $screen->base |
|
291 | - && Application::POST_TYPE == $screen->post_type; |
|
292 | - } |
|
281 | + /** |
|
282 | + * Check if the translation string can be modified. |
|
283 | + * @param string $domain |
|
284 | + * @return bool |
|
285 | + */ |
|
286 | + protected function canModifyTranslation($domain = 'default') |
|
287 | + { |
|
288 | + $screen = glsr_current_screen(); |
|
289 | + return 'default' == $domain |
|
290 | + && 'edit' == $screen->base |
|
291 | + && Application::POST_TYPE == $screen->post_type; |
|
292 | + } |
|
293 | 293 | |
294 | - /** |
|
295 | - * Get the modified translation string. |
|
296 | - * @return string |
|
297 | - */ |
|
298 | - protected function getTranslation(array $args) |
|
299 | - { |
|
300 | - $defaults = [ |
|
301 | - 'number' => 0, |
|
302 | - 'plural' => '', |
|
303 | - 'single' => '', |
|
304 | - 'text' => '', |
|
305 | - ]; |
|
306 | - $args = (object) wp_parse_args($args, $defaults); |
|
307 | - $translations = get_translations_for_domain(Application::ID); |
|
308 | - return $args->text |
|
309 | - ? $translations->translate($args->text) |
|
310 | - : $translations->translate_plural($args->single, $args->plural, $args->number); |
|
311 | - } |
|
294 | + /** |
|
295 | + * Get the modified translation string. |
|
296 | + * @return string |
|
297 | + */ |
|
298 | + protected function getTranslation(array $args) |
|
299 | + { |
|
300 | + $defaults = [ |
|
301 | + 'number' => 0, |
|
302 | + 'plural' => '', |
|
303 | + 'single' => '', |
|
304 | + 'text' => '', |
|
305 | + ]; |
|
306 | + $args = (object) wp_parse_args($args, $defaults); |
|
307 | + $translations = get_translations_for_domain(Application::ID); |
|
308 | + return $args->text |
|
309 | + ? $translations->translate($args->text) |
|
310 | + : $translations->translate_plural($args->single, $args->plural, $args->number); |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
314 | - * @return bool |
|
315 | - */ |
|
316 | - protected function hasPermission(WP_Query $query) |
|
317 | - { |
|
318 | - global $pagenow; |
|
319 | - return is_admin() |
|
320 | - && $query->is_main_query() |
|
321 | - && Application::POST_TYPE == $query->get('post_type') |
|
322 | - && 'edit.php' == $pagenow; |
|
323 | - } |
|
313 | + /** |
|
314 | + * @return bool |
|
315 | + */ |
|
316 | + protected function hasPermission(WP_Query $query) |
|
317 | + { |
|
318 | + global $pagenow; |
|
319 | + return is_admin() |
|
320 | + && $query->is_main_query() |
|
321 | + && Application::POST_TYPE == $query->get('post_type') |
|
322 | + && 'edit.php' == $pagenow; |
|
323 | + } |
|
324 | 324 | |
325 | - /** |
|
326 | - * @return void |
|
327 | - */ |
|
328 | - protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
329 | - { |
|
330 | - foreach ($metaKeys as $key) { |
|
331 | - if (!($value = filter_input(INPUT_GET, $key))) { |
|
332 | - continue; |
|
333 | - } |
|
334 | - $metaQuery = (array) $query->get('meta_query'); |
|
335 | - $metaQuery[] = [ |
|
336 | - 'key' => Str::prefix('_', $key), |
|
337 | - 'value' => $value, |
|
338 | - ]; |
|
339 | - $query->set('meta_query', $metaQuery); |
|
340 | - } |
|
341 | - } |
|
325 | + /** |
|
326 | + * @return void |
|
327 | + */ |
|
328 | + protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
329 | + { |
|
330 | + foreach ($metaKeys as $key) { |
|
331 | + if (!($value = filter_input(INPUT_GET, $key))) { |
|
332 | + continue; |
|
333 | + } |
|
334 | + $metaQuery = (array) $query->get('meta_query'); |
|
335 | + $metaQuery[] = [ |
|
336 | + 'key' => Str::prefix('_', $key), |
|
337 | + 'value' => $value, |
|
338 | + ]; |
|
339 | + $query->set('meta_query', $metaQuery); |
|
340 | + } |
|
341 | + } |
|
342 | 342 | |
343 | - /** |
|
344 | - * @return void |
|
345 | - */ |
|
346 | - protected function setOrderby(WP_Query $query) |
|
347 | - { |
|
348 | - $orderby = $query->get('orderby'); |
|
349 | - $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
350 | - unset($columns['cb'], $columns['title'], $columns['date']); |
|
351 | - if (in_array($orderby, array_keys($columns))) { |
|
352 | - if ('reviewer' == $orderby) { |
|
353 | - $orderby = '_author'; |
|
354 | - } |
|
355 | - $query->set('meta_key', $orderby); |
|
356 | - $query->set('orderby', 'meta_value'); |
|
357 | - } |
|
358 | - } |
|
343 | + /** |
|
344 | + * @return void |
|
345 | + */ |
|
346 | + protected function setOrderby(WP_Query $query) |
|
347 | + { |
|
348 | + $orderby = $query->get('orderby'); |
|
349 | + $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
350 | + unset($columns['cb'], $columns['title'], $columns['date']); |
|
351 | + if (in_array($orderby, array_keys($columns))) { |
|
352 | + if ('reviewer' == $orderby) { |
|
353 | + $orderby = '_author'; |
|
354 | + } |
|
355 | + $query->set('meta_key', $orderby); |
|
356 | + $query->set('orderby', 'meta_value'); |
|
357 | + } |
|
358 | + } |
|
359 | 359 | } |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public function approve() |
22 | 22 | { |
23 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
23 | + if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) { |
|
24 | 24 | return; |
25 | 25 | } |
26 | - check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
27 | - wp_update_post([ |
|
26 | + check_admin_referer( 'approve-review_'.($postId = $this->getPostId()) ); |
|
27 | + wp_update_post( [ |
|
28 | 28 | 'ID' => $postId, |
29 | 29 | 'post_status' => 'publish', |
30 | - ]); |
|
31 | - wp_safe_redirect(wp_get_referer()); |
|
30 | + ] ); |
|
31 | + wp_safe_redirect( wp_get_referer() ); |
|
32 | 32 | exit; |
33 | 33 | } |
34 | 34 | |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | * @return array |
38 | 38 | * @filter bulk_post_updated_messages |
39 | 39 | */ |
40 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
40 | + public function filterBulkUpdateMessages( $messages, array $counts ) |
|
41 | 41 | { |
42 | - $messages = Arr::consolidateArray($messages); |
|
42 | + $messages = Arr::consolidateArray( $messages ); |
|
43 | 43 | $messages[Application::POST_TYPE] = [ |
44 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
45 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
46 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
47 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
48 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
44 | + 'updated' => _n( '%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews' ), |
|
45 | + 'locked' => _n( '%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews' ), |
|
46 | + 'deleted' => _n( '%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews' ), |
|
47 | + 'trashed' => _n( '%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews' ), |
|
48 | + 'untrashed' => _n( '%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews' ), |
|
49 | 49 | ]; |
50 | 50 | return $messages; |
51 | 51 | } |
@@ -55,20 +55,20 @@ discard block |
||
55 | 55 | * @return array |
56 | 56 | * @filter manage_.Application::POST_TYPE._posts_columns |
57 | 57 | */ |
58 | - public function filterColumnsForPostType($columns) |
|
58 | + public function filterColumnsForPostType( $columns ) |
|
59 | 59 | { |
60 | - $columns = Arr::consolidateArray($columns); |
|
60 | + $columns = Arr::consolidateArray( $columns ); |
|
61 | 61 | $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
62 | - foreach ($postTypeColumns as $key => &$value) { |
|
63 | - if (!array_key_exists($key, $columns) || !empty($value)) { |
|
62 | + foreach( $postTypeColumns as $key => &$value ) { |
|
63 | + if( !array_key_exists( $key, $columns ) || !empty($value) ) { |
|
64 | 64 | continue; |
65 | 65 | } |
66 | 66 | $value = $columns[$key]; |
67 | 67 | } |
68 | - if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
68 | + if( count( glsr( Database::class )->getReviewsMeta( 'review_type' ) ) < 2 ) { |
|
69 | 69 | unset($postTypeColumns['review_type']); |
70 | 70 | } |
71 | - return array_filter($postTypeColumns, 'strlen'); |
|
71 | + return array_filter( $postTypeColumns, 'strlen' ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | * @return string |
78 | 78 | * @filter post_date_column_status |
79 | 79 | */ |
80 | - public function filterDateColumnStatus($status, $post) |
|
80 | + public function filterDateColumnStatus( $status, $post ) |
|
81 | 81 | { |
82 | - if (Application::POST_TYPE == Arr::get($post, 'post_type')) { |
|
83 | - $status = __('Submitted', 'site-reviews'); |
|
82 | + if( Application::POST_TYPE == Arr::get( $post, 'post_type' ) ) { |
|
83 | + $status = __( 'Submitted', 'site-reviews' ); |
|
84 | 84 | } |
85 | 85 | return $status; |
86 | 86 | } |
@@ -91,10 +91,10 @@ discard block |
||
91 | 91 | * @return array |
92 | 92 | * @filter default_hidden_columns |
93 | 93 | */ |
94 | - public function filterDefaultHiddenColumns($hidden, $screen) |
|
94 | + public function filterDefaultHiddenColumns( $hidden, $screen ) |
|
95 | 95 | { |
96 | - if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
97 | - $hidden = Arr::consolidateArray($hidden); |
|
96 | + if( Arr::get( $screen, 'id' ) == 'edit-'.Application::POST_TYPE ) { |
|
97 | + $hidden = Arr::consolidateArray( $hidden ); |
|
98 | 98 | $hidden = ['reviewer']; |
99 | 99 | } |
100 | 100 | return $hidden; |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | * @return array |
107 | 107 | * @filter display_post_states |
108 | 108 | */ |
109 | - public function filterPostStates($postStates, $post) |
|
109 | + public function filterPostStates( $postStates, $post ) |
|
110 | 110 | { |
111 | - $postStates = Arr::consolidateArray($postStates); |
|
112 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
113 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
111 | + $postStates = Arr::consolidateArray( $postStates ); |
|
112 | + if( Application::POST_TYPE == Arr::get( $post, 'post_type' ) && array_key_exists( 'pending', $postStates ) ) { |
|
113 | + $postStates['pending'] = __( 'Unapproved', 'site-reviews' ); |
|
114 | 114 | } |
115 | 115 | return $postStates; |
116 | 116 | } |
@@ -121,28 +121,28 @@ discard block |
||
121 | 121 | * @return array |
122 | 122 | * @filter post_row_actions |
123 | 123 | */ |
124 | - public function filterRowActions($actions, $post) |
|
124 | + public function filterRowActions( $actions, $post ) |
|
125 | 125 | { |
126 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) { |
|
126 | + if( Application::POST_TYPE != Arr::get( $post, 'post_type' ) || 'trash' == $post->post_status ) { |
|
127 | 127 | return $actions; |
128 | 128 | } |
129 | 129 | unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
130 | 130 | $rowActions = [ |
131 | - 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
132 | - 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
131 | + 'approve' => esc_attr__( 'Approve', 'site-reviews' ), |
|
132 | + 'unapprove' => esc_attr__( 'Unapprove', 'site-reviews' ), |
|
133 | 133 | ]; |
134 | 134 | $newActions = []; |
135 | - foreach ($rowActions as $key => $text) { |
|
136 | - $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
137 | - 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
135 | + foreach( $rowActions as $key => $text ) { |
|
136 | + $newActions[$key] = glsr( Builder::class )->a( $text, [ |
|
137 | + 'aria-label' => sprintf( esc_attr_x( '%s this review', 'Approve the review', 'site-reviews' ), $text ), |
|
138 | 138 | 'class' => 'glsr-change-status', |
139 | 139 | 'href' => wp_nonce_url( |
140 | - admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
140 | + admin_url( 'post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID ), |
|
141 | 141 | $key.'-review_'.$post->ID |
142 | 142 | ), |
143 | - ]); |
|
143 | + ] ); |
|
144 | 144 | } |
145 | - return $newActions + Arr::consolidateArray($actions); |
|
145 | + return $newActions + Arr::consolidateArray( $actions ); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -150,13 +150,13 @@ discard block |
||
150 | 150 | * @return array |
151 | 151 | * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
152 | 152 | */ |
153 | - public function filterSortableColumns($columns) |
|
153 | + public function filterSortableColumns( $columns ) |
|
154 | 154 | { |
155 | - $columns = Arr::consolidateArray($columns); |
|
155 | + $columns = Arr::consolidateArray( $columns ); |
|
156 | 156 | $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
157 | 157 | unset($postTypeColumns['cb']); |
158 | - foreach ($postTypeColumns as $key => $value) { |
|
159 | - if (Str::startsWith('taxonomy', $key)) { |
|
158 | + foreach( $postTypeColumns as $key => $value ) { |
|
159 | + if( Str::startsWith( 'taxonomy', $key ) ) { |
|
160 | 160 | continue; |
161 | 161 | } |
162 | 162 | $columns[$key] = $key; |
@@ -174,22 +174,22 @@ discard block |
||
174 | 174 | * @return string |
175 | 175 | * @filter ngettext |
176 | 176 | */ |
177 | - public function filterStatusText($translation, $single, $plural, $number, $domain) |
|
177 | + public function filterStatusText( $translation, $single, $plural, $number, $domain ) |
|
178 | 178 | { |
179 | - if ($this->canModifyTranslation($domain)) { |
|
179 | + if( $this->canModifyTranslation( $domain ) ) { |
|
180 | 180 | $strings = [ |
181 | - 'Published' => __('Approved', 'site-reviews'), |
|
182 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
181 | + 'Published' => __( 'Approved', 'site-reviews' ), |
|
182 | + 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
183 | 183 | ]; |
184 | - foreach ($strings as $search => $replace) { |
|
185 | - if (false === strpos($single, $search)) { |
|
184 | + foreach( $strings as $search => $replace ) { |
|
185 | + if( false === strpos( $single, $search ) ) { |
|
186 | 186 | continue; |
187 | 187 | } |
188 | - $translation = $this->getTranslation([ |
|
188 | + $translation = $this->getTranslation( [ |
|
189 | 189 | 'number' => $number, |
190 | - 'plural' => str_replace($search, $replace, $plural), |
|
191 | - 'single' => str_replace($search, $replace, $single), |
|
192 | - ]); |
|
190 | + 'plural' => str_replace( $search, $replace, $plural ), |
|
191 | + 'single' => str_replace( $search, $replace, $single ), |
|
192 | + ] ); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | return $translation; |
@@ -201,10 +201,10 @@ discard block |
||
201 | 201 | * @return void |
202 | 202 | * @action bulk_edit_custom_box |
203 | 203 | */ |
204 | - public function renderBulkEditFields($columnName, $postType) |
|
204 | + public function renderBulkEditFields( $columnName, $postType ) |
|
205 | 205 | { |
206 | - if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
207 | - glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
206 | + if( 'assigned_to' == $columnName && Application::POST_TYPE == $postType ) { |
|
207 | + glsr()->render( 'partials/editor/bulk-edit-assigned-to' ); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
@@ -213,9 +213,9 @@ discard block |
||
213 | 213 | * @return void |
214 | 214 | * @action restrict_manage_posts |
215 | 215 | */ |
216 | - public function renderColumnFilters($postType) |
|
216 | + public function renderColumnFilters( $postType ) |
|
217 | 217 | { |
218 | - glsr(Columns::class)->renderFilters($postType); |
|
218 | + glsr( Columns::class )->renderFilters( $postType ); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | * @return void |
225 | 225 | * @action manage_posts_custom_column |
226 | 226 | */ |
227 | - public function renderColumnValues($column, $postId) |
|
227 | + public function renderColumnValues( $column, $postId ) |
|
228 | 228 | { |
229 | - glsr(Columns::class)->renderValues($column, $postId); |
|
229 | + glsr( Columns::class )->renderValues( $column, $postId ); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -234,14 +234,14 @@ discard block |
||
234 | 234 | * @return void |
235 | 235 | * @action save_post_.Application::POST_TYPE |
236 | 236 | */ |
237 | - public function saveBulkEditFields($postId) |
|
237 | + public function saveBulkEditFields( $postId ) |
|
238 | 238 | { |
239 | - if (!current_user_can('edit_posts')) { |
|
239 | + if( !current_user_can( 'edit_posts' ) ) { |
|
240 | 240 | return; |
241 | 241 | } |
242 | - $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
243 | - if ($assignedTo && get_post($assignedTo)) { |
|
244 | - glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
242 | + $assignedTo = filter_input( INPUT_GET, 'assigned_to' ); |
|
243 | + if( $assignedTo && get_post( $assignedTo ) ) { |
|
244 | + glsr( Database::class )->update( $postId, 'assigned_to', $assignedTo ); |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
@@ -249,15 +249,15 @@ discard block |
||
249 | 249 | * @return void |
250 | 250 | * @action pre_get_posts |
251 | 251 | */ |
252 | - public function setQueryForColumn(WP_Query $query) |
|
252 | + public function setQueryForColumn( WP_Query $query ) |
|
253 | 253 | { |
254 | - if (!$this->hasPermission($query)) { |
|
254 | + if( !$this->hasPermission( $query ) ) { |
|
255 | 255 | return; |
256 | 256 | } |
257 | - $this->setMetaQuery($query, [ |
|
257 | + $this->setMetaQuery( $query, [ |
|
258 | 258 | 'rating', 'review_type', |
259 | - ]); |
|
260 | - $this->setOrderby($query); |
|
259 | + ] ); |
|
260 | + $this->setOrderby( $query ); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -266,15 +266,15 @@ discard block |
||
266 | 266 | */ |
267 | 267 | public function unapprove() |
268 | 268 | { |
269 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
269 | + if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) { |
|
270 | 270 | return; |
271 | 271 | } |
272 | - check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
273 | - wp_update_post([ |
|
272 | + check_admin_referer( 'unapprove-review_'.($postId = $this->getPostId()) ); |
|
273 | + wp_update_post( [ |
|
274 | 274 | 'ID' => $postId, |
275 | 275 | 'post_status' => 'pending', |
276 | - ]); |
|
277 | - wp_safe_redirect(wp_get_referer()); |
|
276 | + ] ); |
|
277 | + wp_safe_redirect( wp_get_referer() ); |
|
278 | 278 | exit; |
279 | 279 | } |
280 | 280 | |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param string $domain |
284 | 284 | * @return bool |
285 | 285 | */ |
286 | - protected function canModifyTranslation($domain = 'default') |
|
286 | + protected function canModifyTranslation( $domain = 'default' ) |
|
287 | 287 | { |
288 | 288 | $screen = glsr_current_screen(); |
289 | 289 | return 'default' == $domain |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * Get the modified translation string. |
296 | 296 | * @return string |
297 | 297 | */ |
298 | - protected function getTranslation(array $args) |
|
298 | + protected function getTranslation( array $args ) |
|
299 | 299 | { |
300 | 300 | $defaults = [ |
301 | 301 | 'number' => 0, |
@@ -303,57 +303,57 @@ discard block |
||
303 | 303 | 'single' => '', |
304 | 304 | 'text' => '', |
305 | 305 | ]; |
306 | - $args = (object) wp_parse_args($args, $defaults); |
|
307 | - $translations = get_translations_for_domain(Application::ID); |
|
306 | + $args = (object)wp_parse_args( $args, $defaults ); |
|
307 | + $translations = get_translations_for_domain( Application::ID ); |
|
308 | 308 | return $args->text |
309 | - ? $translations->translate($args->text) |
|
310 | - : $translations->translate_plural($args->single, $args->plural, $args->number); |
|
309 | + ? $translations->translate( $args->text ) |
|
310 | + : $translations->translate_plural( $args->single, $args->plural, $args->number ); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
314 | 314 | * @return bool |
315 | 315 | */ |
316 | - protected function hasPermission(WP_Query $query) |
|
316 | + protected function hasPermission( WP_Query $query ) |
|
317 | 317 | { |
318 | 318 | global $pagenow; |
319 | 319 | return is_admin() |
320 | 320 | && $query->is_main_query() |
321 | - && Application::POST_TYPE == $query->get('post_type') |
|
321 | + && Application::POST_TYPE == $query->get( 'post_type' ) |
|
322 | 322 | && 'edit.php' == $pagenow; |
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
326 | 326 | * @return void |
327 | 327 | */ |
328 | - protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
328 | + protected function setMetaQuery( WP_Query $query, array $metaKeys ) |
|
329 | 329 | { |
330 | - foreach ($metaKeys as $key) { |
|
331 | - if (!($value = filter_input(INPUT_GET, $key))) { |
|
330 | + foreach( $metaKeys as $key ) { |
|
331 | + if( !($value = filter_input( INPUT_GET, $key )) ) { |
|
332 | 332 | continue; |
333 | 333 | } |
334 | - $metaQuery = (array) $query->get('meta_query'); |
|
334 | + $metaQuery = (array)$query->get( 'meta_query' ); |
|
335 | 335 | $metaQuery[] = [ |
336 | - 'key' => Str::prefix('_', $key), |
|
336 | + 'key' => Str::prefix( '_', $key ), |
|
337 | 337 | 'value' => $value, |
338 | 338 | ]; |
339 | - $query->set('meta_query', $metaQuery); |
|
339 | + $query->set( 'meta_query', $metaQuery ); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
344 | 344 | * @return void |
345 | 345 | */ |
346 | - protected function setOrderby(WP_Query $query) |
|
346 | + protected function setOrderby( WP_Query $query ) |
|
347 | 347 | { |
348 | - $orderby = $query->get('orderby'); |
|
348 | + $orderby = $query->get( 'orderby' ); |
|
349 | 349 | $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
350 | 350 | unset($columns['cb'], $columns['title'], $columns['date']); |
351 | - if (in_array($orderby, array_keys($columns))) { |
|
352 | - if ('reviewer' == $orderby) { |
|
351 | + if( in_array( $orderby, array_keys( $columns ) ) ) { |
|
352 | + if( 'reviewer' == $orderby ) { |
|
353 | 353 | $orderby = '_author'; |
354 | 354 | } |
355 | - $query->set('meta_key', $orderby); |
|
356 | - $query->set('orderby', 'meta_value'); |
|
355 | + $query->set( 'meta_key', $orderby ); |
|
356 | + $query->set( 'orderby', 'meta_value' ); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | } |
@@ -16,222 +16,222 @@ |
||
16 | 16 | |
17 | 17 | class AdminController extends Controller |
18 | 18 | { |
19 | - /** |
|
20 | - * @return void |
|
21 | - * @action admin_enqueue_scripts |
|
22 | - */ |
|
23 | - public function enqueueAssets() |
|
24 | - { |
|
25 | - $command = new EnqueueAdminAssets([ |
|
26 | - 'pointers' => [[ |
|
27 | - 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
28 | - 'id' => 'glsr-pointer-pinned', |
|
29 | - 'position' => [ |
|
30 | - 'edge' => 'right', |
|
31 | - 'align' => 'middle', |
|
32 | - ], |
|
33 | - 'screen' => Application::POST_TYPE, |
|
34 | - 'target' => '#misc-pub-pinned', |
|
35 | - 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
36 | - ]], |
|
37 | - ]); |
|
38 | - $this->execute($command); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @return array |
|
43 | - * @filter plugin_action_links_site-reviews/site-reviews.php |
|
44 | - */ |
|
45 | - public function filterActionLinks(array $links) |
|
46 | - { |
|
47 | - $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
48 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
49 | - ]); |
|
50 | - $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
51 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
52 | - ]); |
|
53 | - return $links; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param array $capabilities |
|
58 | - * @param string $capability |
|
59 | - * @return array |
|
60 | - * @filter map_meta_cap |
|
61 | - */ |
|
62 | - public function filterCreateCapability($capabilities, $capability) |
|
63 | - { |
|
64 | - if ($capability == 'create_'.Application::POST_TYPE) { |
|
65 | - $capabilities[] = 'do_not_allow'; |
|
66 | - } |
|
67 | - return $capabilities; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param array $items |
|
72 | - * @return array |
|
73 | - * @filter dashboard_glance_items |
|
74 | - */ |
|
75 | - public function filterDashboardGlanceItems($items) |
|
76 | - { |
|
77 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
78 | - if (empty($postCount->publish)) { |
|
79 | - return $items; |
|
80 | - } |
|
81 | - $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
82 | - $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
83 | - $items = Arr::consolidateArray($items); |
|
84 | - $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
85 | - ? glsr(Builder::class)->a($text, [ |
|
86 | - 'class' => 'glsr-review-count', |
|
87 | - 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
88 | - ]) |
|
89 | - : glsr(Builder::class)->span($text, [ |
|
90 | - 'class' => 'glsr-review-count', |
|
91 | - ]); |
|
92 | - return $items; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @param array $plugins |
|
97 | - * @return array |
|
98 | - * @filter mce_external_plugins |
|
99 | - */ |
|
100 | - public function filterTinymcePlugins($plugins) |
|
101 | - { |
|
102 | - if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
103 | - $plugins = Arr::consolidateArray($plugins); |
|
104 | - $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
105 | - } |
|
106 | - return $plugins; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return void |
|
111 | - * @action admin_init |
|
112 | - */ |
|
113 | - public function registerTinymcePopups() |
|
114 | - { |
|
115 | - $command = new RegisterTinymcePopups([ |
|
116 | - 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
117 | - 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
118 | - 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
119 | - ]); |
|
120 | - $this->execute($command); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @param string $editorId |
|
125 | - * @return void|null |
|
126 | - * @action media_buttons |
|
127 | - */ |
|
128 | - public function renderTinymceButton($editorId) |
|
129 | - { |
|
130 | - $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
131 | - if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
132 | - return; |
|
133 | - } |
|
134 | - $shortcodes = []; |
|
135 | - foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
136 | - $shortcodes[$shortcode] = $values; |
|
137 | - } |
|
138 | - if (empty($shortcodes)) { |
|
139 | - return; |
|
140 | - } |
|
141 | - glsr()->render('partials/editor/tinymce', [ |
|
142 | - 'shortcodes' => $shortcodes, |
|
143 | - ]); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return void |
|
148 | - */ |
|
149 | - public function routerClearConsole() |
|
150 | - { |
|
151 | - glsr(Console::class)->clear(); |
|
152 | - glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @return void |
|
157 | - */ |
|
158 | - public function routerFetchConsole() |
|
159 | - { |
|
160 | - glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @param bool $showNotice |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - public function routerCountReviews($showNotice = true) |
|
168 | - { |
|
169 | - glsr(CountsManager::class)->countAll(); |
|
170 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
171 | - if ($showNotice) { |
|
172 | - glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @return void |
|
178 | - */ |
|
179 | - public function routerDownloadConsole() |
|
180 | - { |
|
181 | - $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @return void |
|
186 | - */ |
|
187 | - public function routerDownloadSystemInfo() |
|
188 | - { |
|
189 | - $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * @return void |
|
194 | - */ |
|
195 | - public function routerExportSettings() |
|
196 | - { |
|
197 | - $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - public function routerImportSettings() |
|
204 | - { |
|
205 | - $file = $_FILES['import-file']; |
|
206 | - if (UPLOAD_ERR_OK !== $file['error']) { |
|
207 | - return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
208 | - } |
|
209 | - if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
210 | - return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
211 | - } |
|
212 | - $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
213 | - if (empty($settings)) { |
|
214 | - return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
215 | - } |
|
216 | - glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
217 | - glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @param int $errorCode |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - protected function getUploadError($errorCode) |
|
225 | - { |
|
226 | - $errors = [ |
|
227 | - UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
228 | - UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
229 | - UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
230 | - UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
231 | - UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
232 | - UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
233 | - UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
234 | - ]; |
|
235 | - return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
236 | - } |
|
19 | + /** |
|
20 | + * @return void |
|
21 | + * @action admin_enqueue_scripts |
|
22 | + */ |
|
23 | + public function enqueueAssets() |
|
24 | + { |
|
25 | + $command = new EnqueueAdminAssets([ |
|
26 | + 'pointers' => [[ |
|
27 | + 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
28 | + 'id' => 'glsr-pointer-pinned', |
|
29 | + 'position' => [ |
|
30 | + 'edge' => 'right', |
|
31 | + 'align' => 'middle', |
|
32 | + ], |
|
33 | + 'screen' => Application::POST_TYPE, |
|
34 | + 'target' => '#misc-pub-pinned', |
|
35 | + 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
36 | + ]], |
|
37 | + ]); |
|
38 | + $this->execute($command); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @return array |
|
43 | + * @filter plugin_action_links_site-reviews/site-reviews.php |
|
44 | + */ |
|
45 | + public function filterActionLinks(array $links) |
|
46 | + { |
|
47 | + $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
48 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
49 | + ]); |
|
50 | + $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
51 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
52 | + ]); |
|
53 | + return $links; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param array $capabilities |
|
58 | + * @param string $capability |
|
59 | + * @return array |
|
60 | + * @filter map_meta_cap |
|
61 | + */ |
|
62 | + public function filterCreateCapability($capabilities, $capability) |
|
63 | + { |
|
64 | + if ($capability == 'create_'.Application::POST_TYPE) { |
|
65 | + $capabilities[] = 'do_not_allow'; |
|
66 | + } |
|
67 | + return $capabilities; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param array $items |
|
72 | + * @return array |
|
73 | + * @filter dashboard_glance_items |
|
74 | + */ |
|
75 | + public function filterDashboardGlanceItems($items) |
|
76 | + { |
|
77 | + $postCount = wp_count_posts(Application::POST_TYPE); |
|
78 | + if (empty($postCount->publish)) { |
|
79 | + return $items; |
|
80 | + } |
|
81 | + $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
82 | + $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
83 | + $items = Arr::consolidateArray($items); |
|
84 | + $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
85 | + ? glsr(Builder::class)->a($text, [ |
|
86 | + 'class' => 'glsr-review-count', |
|
87 | + 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
88 | + ]) |
|
89 | + : glsr(Builder::class)->span($text, [ |
|
90 | + 'class' => 'glsr-review-count', |
|
91 | + ]); |
|
92 | + return $items; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @param array $plugins |
|
97 | + * @return array |
|
98 | + * @filter mce_external_plugins |
|
99 | + */ |
|
100 | + public function filterTinymcePlugins($plugins) |
|
101 | + { |
|
102 | + if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
103 | + $plugins = Arr::consolidateArray($plugins); |
|
104 | + $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
105 | + } |
|
106 | + return $plugins; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return void |
|
111 | + * @action admin_init |
|
112 | + */ |
|
113 | + public function registerTinymcePopups() |
|
114 | + { |
|
115 | + $command = new RegisterTinymcePopups([ |
|
116 | + 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
117 | + 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
118 | + 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
119 | + ]); |
|
120 | + $this->execute($command); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @param string $editorId |
|
125 | + * @return void|null |
|
126 | + * @action media_buttons |
|
127 | + */ |
|
128 | + public function renderTinymceButton($editorId) |
|
129 | + { |
|
130 | + $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
131 | + if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
132 | + return; |
|
133 | + } |
|
134 | + $shortcodes = []; |
|
135 | + foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
136 | + $shortcodes[$shortcode] = $values; |
|
137 | + } |
|
138 | + if (empty($shortcodes)) { |
|
139 | + return; |
|
140 | + } |
|
141 | + glsr()->render('partials/editor/tinymce', [ |
|
142 | + 'shortcodes' => $shortcodes, |
|
143 | + ]); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return void |
|
148 | + */ |
|
149 | + public function routerClearConsole() |
|
150 | + { |
|
151 | + glsr(Console::class)->clear(); |
|
152 | + glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @return void |
|
157 | + */ |
|
158 | + public function routerFetchConsole() |
|
159 | + { |
|
160 | + glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @param bool $showNotice |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + public function routerCountReviews($showNotice = true) |
|
168 | + { |
|
169 | + glsr(CountsManager::class)->countAll(); |
|
170 | + glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
171 | + if ($showNotice) { |
|
172 | + glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @return void |
|
178 | + */ |
|
179 | + public function routerDownloadConsole() |
|
180 | + { |
|
181 | + $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @return void |
|
186 | + */ |
|
187 | + public function routerDownloadSystemInfo() |
|
188 | + { |
|
189 | + $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * @return void |
|
194 | + */ |
|
195 | + public function routerExportSettings() |
|
196 | + { |
|
197 | + $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + public function routerImportSettings() |
|
204 | + { |
|
205 | + $file = $_FILES['import-file']; |
|
206 | + if (UPLOAD_ERR_OK !== $file['error']) { |
|
207 | + return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
208 | + } |
|
209 | + if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
210 | + return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
211 | + } |
|
212 | + $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
213 | + if (empty($settings)) { |
|
214 | + return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
215 | + } |
|
216 | + glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
217 | + glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @param int $errorCode |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + protected function getUploadError($errorCode) |
|
225 | + { |
|
226 | + $errors = [ |
|
227 | + UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
228 | + UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
229 | + UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
230 | + UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
231 | + UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
232 | + UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
233 | + UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
234 | + ]; |
|
235 | + return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
236 | + } |
|
237 | 237 | } |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function enqueueAssets() |
24 | 24 | { |
25 | - $command = new EnqueueAdminAssets([ |
|
25 | + $command = new EnqueueAdminAssets( [ |
|
26 | 26 | 'pointers' => [[ |
27 | - 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
27 | + 'content' => __( 'You can pin exceptional reviews so that they are always shown first.', 'site-reviews' ), |
|
28 | 28 | 'id' => 'glsr-pointer-pinned', |
29 | 29 | 'position' => [ |
30 | 30 | 'edge' => 'right', |
@@ -32,24 +32,24 @@ discard block |
||
32 | 32 | ], |
33 | 33 | 'screen' => Application::POST_TYPE, |
34 | 34 | 'target' => '#misc-pub-pinned', |
35 | - 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
35 | + 'title' => __( 'Pin Your Reviews', 'site-reviews' ), |
|
36 | 36 | ]], |
37 | - ]); |
|
38 | - $this->execute($command); |
|
37 | + ] ); |
|
38 | + $this->execute( $command ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @return array |
43 | 43 | * @filter plugin_action_links_site-reviews/site-reviews.php |
44 | 44 | */ |
45 | - public function filterActionLinks(array $links) |
|
45 | + public function filterActionLinks( array $links ) |
|
46 | 46 | { |
47 | - $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
48 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
49 | - ]); |
|
50 | - $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
51 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
52 | - ]); |
|
47 | + $links['documentation'] = glsr( Builder::class )->a( __( 'Help', 'site-reviews' ), [ |
|
48 | + 'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=documentation' ), |
|
49 | + ] ); |
|
50 | + $links['settings'] = glsr( Builder::class )->a( __( 'Settings', 'site-reviews' ), [ |
|
51 | + 'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=settings' ), |
|
52 | + ] ); |
|
53 | 53 | return $links; |
54 | 54 | } |
55 | 55 | |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | * @return array |
60 | 60 | * @filter map_meta_cap |
61 | 61 | */ |
62 | - public function filterCreateCapability($capabilities, $capability) |
|
62 | + public function filterCreateCapability( $capabilities, $capability ) |
|
63 | 63 | { |
64 | - if ($capability == 'create_'.Application::POST_TYPE) { |
|
64 | + if( $capability == 'create_'.Application::POST_TYPE ) { |
|
65 | 65 | $capabilities[] = 'do_not_allow'; |
66 | 66 | } |
67 | 67 | return $capabilities; |
@@ -72,23 +72,23 @@ discard block |
||
72 | 72 | * @return array |
73 | 73 | * @filter dashboard_glance_items |
74 | 74 | */ |
75 | - public function filterDashboardGlanceItems($items) |
|
75 | + public function filterDashboardGlanceItems( $items ) |
|
76 | 76 | { |
77 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
78 | - if (empty($postCount->publish)) { |
|
77 | + $postCount = wp_count_posts( Application::POST_TYPE ); |
|
78 | + if( empty($postCount->publish) ) { |
|
79 | 79 | return $items; |
80 | 80 | } |
81 | - $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
82 | - $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
83 | - $items = Arr::consolidateArray($items); |
|
84 | - $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
85 | - ? glsr(Builder::class)->a($text, [ |
|
81 | + $text = _n( '%s Review', '%s Reviews', $postCount->publish, 'site-reviews' ); |
|
82 | + $text = sprintf( $text, number_format_i18n( $postCount->publish ) ); |
|
83 | + $items = Arr::consolidateArray( $items ); |
|
84 | + $items[] = current_user_can( get_post_type_object( Application::POST_TYPE )->cap->edit_posts ) |
|
85 | + ? glsr( Builder::class )->a( $text, [ |
|
86 | 86 | 'class' => 'glsr-review-count', |
87 | 87 | 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
88 | - ]) |
|
89 | - : glsr(Builder::class)->span($text, [ |
|
88 | + ] ) |
|
89 | + : glsr( Builder::class )->span( $text, [ |
|
90 | 90 | 'class' => 'glsr-review-count', |
91 | - ]); |
|
91 | + ] ); |
|
92 | 92 | return $items; |
93 | 93 | } |
94 | 94 | |
@@ -97,11 +97,11 @@ discard block |
||
97 | 97 | * @return array |
98 | 98 | * @filter mce_external_plugins |
99 | 99 | */ |
100 | - public function filterTinymcePlugins($plugins) |
|
100 | + public function filterTinymcePlugins( $plugins ) |
|
101 | 101 | { |
102 | - if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
103 | - $plugins = Arr::consolidateArray($plugins); |
|
104 | - $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
102 | + if( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) { |
|
103 | + $plugins = Arr::consolidateArray( $plugins ); |
|
104 | + $plugins['glsr_shortcode'] = glsr()->url( 'assets/scripts/mce-plugin.js' ); |
|
105 | 105 | } |
106 | 106 | return $plugins; |
107 | 107 | } |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function registerTinymcePopups() |
114 | 114 | { |
115 | - $command = new RegisterTinymcePopups([ |
|
116 | - 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
117 | - 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
118 | - 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
119 | - ]); |
|
120 | - $this->execute($command); |
|
115 | + $command = new RegisterTinymcePopups( [ |
|
116 | + 'site_reviews' => esc_html__( 'Recent Reviews', 'site-reviews' ), |
|
117 | + 'site_reviews_form' => esc_html__( 'Submit a Review', 'site-reviews' ), |
|
118 | + 'site_reviews_summary' => esc_html__( 'Summary of Reviews', 'site-reviews' ), |
|
119 | + ] ); |
|
120 | + $this->execute( $command ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -125,22 +125,22 @@ discard block |
||
125 | 125 | * @return void|null |
126 | 126 | * @action media_buttons |
127 | 127 | */ |
128 | - public function renderTinymceButton($editorId) |
|
128 | + public function renderTinymceButton( $editorId ) |
|
129 | 129 | { |
130 | - $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
131 | - if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
130 | + $allowedEditors = apply_filters( 'site-reviews/tinymce/editor-ids', ['content'], $editorId ); |
|
131 | + if( 'post' != glsr_current_screen()->base || !in_array( $editorId, $allowedEditors ) ) { |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | $shortcodes = []; |
135 | - foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
135 | + foreach( glsr()->mceShortcodes as $shortcode => $values ) { |
|
136 | 136 | $shortcodes[$shortcode] = $values; |
137 | 137 | } |
138 | - if (empty($shortcodes)) { |
|
138 | + if( empty($shortcodes) ) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | - glsr()->render('partials/editor/tinymce', [ |
|
141 | + glsr()->render( 'partials/editor/tinymce', [ |
|
142 | 142 | 'shortcodes' => $shortcodes, |
143 | - ]); |
|
143 | + ] ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | */ |
149 | 149 | public function routerClearConsole() |
150 | 150 | { |
151 | - glsr(Console::class)->clear(); |
|
152 | - glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
151 | + glsr( Console::class )->clear(); |
|
152 | + glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' ) ); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -157,19 +157,19 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function routerFetchConsole() |
159 | 159 | { |
160 | - glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
160 | + glsr( Notice::class )->addSuccess( __( 'Console reloaded.', 'site-reviews' ) ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
164 | 164 | * @param bool $showNotice |
165 | 165 | * @return void |
166 | 166 | */ |
167 | - public function routerCountReviews($showNotice = true) |
|
167 | + public function routerCountReviews( $showNotice = true ) |
|
168 | 168 | { |
169 | - glsr(CountsManager::class)->countAll(); |
|
170 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
171 | - if ($showNotice) { |
|
172 | - glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
169 | + glsr( CountsManager::class )->countAll(); |
|
170 | + glsr( OptionManager::class )->set( 'last_review_count', current_time( 'timestamp' ) ); |
|
171 | + if( $showNotice ) { |
|
172 | + glsr( Notice::class )->clear()->addSuccess( __( 'Recalculated rating counts.', 'site-reviews' ) ); |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | public function routerDownloadConsole() |
180 | 180 | { |
181 | - $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
181 | + $this->download( Application::ID.'-console.txt', glsr( Console::class )->get() ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public function routerDownloadSystemInfo() |
188 | 188 | { |
189 | - $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
189 | + $this->download( Application::ID.'-system-info.txt', glsr( System::class )->get() ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function routerExportSettings() |
196 | 196 | { |
197 | - $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
197 | + $this->download( Application::ID.'-settings.json', glsr( OptionManager::class )->json() ); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -203,35 +203,35 @@ discard block |
||
203 | 203 | public function routerImportSettings() |
204 | 204 | { |
205 | 205 | $file = $_FILES['import-file']; |
206 | - if (UPLOAD_ERR_OK !== $file['error']) { |
|
207 | - return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
206 | + if( UPLOAD_ERR_OK !== $file['error'] ) { |
|
207 | + return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] ) ); |
|
208 | 208 | } |
209 | - if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
210 | - return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
209 | + if( 'application/json' !== $file['type'] || !Str::endsWith( '.json', $file['name'] ) ) { |
|
210 | + return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' ) ); |
|
211 | 211 | } |
212 | - $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
213 | - if (empty($settings)) { |
|
214 | - return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
212 | + $settings = json_decode( file_get_contents( $file['tmp_name'] ), true ); |
|
213 | + if( empty($settings) ) { |
|
214 | + return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' ) ); |
|
215 | 215 | } |
216 | - glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
217 | - glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
216 | + glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings ) ); |
|
217 | + glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' ) ); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
221 | 221 | * @param int $errorCode |
222 | 222 | * @return string |
223 | 223 | */ |
224 | - protected function getUploadError($errorCode) |
|
224 | + protected function getUploadError( $errorCode ) |
|
225 | 225 | { |
226 | 226 | $errors = [ |
227 | - UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
228 | - UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
229 | - UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
230 | - UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
231 | - UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
232 | - UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
233 | - UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
227 | + UPLOAD_ERR_INI_SIZE => __( 'The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews' ), |
|
228 | + UPLOAD_ERR_FORM_SIZE => __( 'The uploaded file is too big.', 'site-reviews' ), |
|
229 | + UPLOAD_ERR_PARTIAL => __( 'The uploaded file was only partially uploaded.', 'site-reviews' ), |
|
230 | + UPLOAD_ERR_NO_FILE => __( 'No file was uploaded.', 'site-reviews' ), |
|
231 | + UPLOAD_ERR_NO_TMP_DIR => __( 'Missing a temporary folder.', 'site-reviews' ), |
|
232 | + UPLOAD_ERR_CANT_WRITE => __( 'Failed to write file to disk.', 'site-reviews' ), |
|
233 | + UPLOAD_ERR_EXTENSION => __( 'A PHP extension stopped the file upload.', 'site-reviews' ), |
|
234 | 234 | ]; |
235 | - return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
235 | + return Arr::get( $errors, $errorCode, __( 'Unknown upload error.', 'site-reviews' ) ); |
|
236 | 236 | } |
237 | 237 | } |
@@ -9,308 +9,308 @@ |
||
9 | 9 | |
10 | 10 | final class Application extends Container |
11 | 11 | { |
12 | - const CAPABILITY = 'edit_others_posts'; |
|
13 | - const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
14 | - const ID = 'site-reviews'; |
|
15 | - const PAGED_QUERY_VAR = 'reviews-page'; |
|
16 | - const POST_TYPE = 'site-review'; |
|
17 | - const PREFIX = 'glsr_'; |
|
18 | - const TAXONOMY = 'site-review-category'; |
|
12 | + const CAPABILITY = 'edit_others_posts'; |
|
13 | + const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
14 | + const ID = 'site-reviews'; |
|
15 | + const PAGED_QUERY_VAR = 'reviews-page'; |
|
16 | + const POST_TYPE = 'site-review'; |
|
17 | + const PREFIX = 'glsr_'; |
|
18 | + const TAXONOMY = 'site-review-category'; |
|
19 | 19 | |
20 | - public $defaults; |
|
21 | - public $deprecated = []; |
|
22 | - public $file; |
|
23 | - public $languages; |
|
24 | - public $mceShortcodes = []; //defined elsewhere |
|
25 | - public $name; |
|
26 | - public $reviewTypes; |
|
27 | - public $schemas = []; //defined elsewhere |
|
28 | - public $version; |
|
20 | + public $defaults; |
|
21 | + public $deprecated = []; |
|
22 | + public $file; |
|
23 | + public $languages; |
|
24 | + public $mceShortcodes = []; //defined elsewhere |
|
25 | + public $name; |
|
26 | + public $reviewTypes; |
|
27 | + public $schemas = []; //defined elsewhere |
|
28 | + public $version; |
|
29 | 29 | |
30 | - public function __construct() |
|
31 | - { |
|
32 | - static::$instance = $this; |
|
33 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
34 | - $plugin = get_file_data($this->file, [ |
|
35 | - 'languages' => 'Domain Path', |
|
36 | - 'name' => 'Plugin Name', |
|
37 | - 'version' => 'Version', |
|
38 | - ], 'plugin'); |
|
39 | - array_walk($plugin, function ($value, $key) { |
|
40 | - $this->$key = $value; |
|
41 | - }); |
|
42 | - } |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + static::$instance = $this; |
|
33 | + $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
34 | + $plugin = get_file_data($this->file, [ |
|
35 | + 'languages' => 'Domain Path', |
|
36 | + 'name' => 'Plugin Name', |
|
37 | + 'version' => 'Version', |
|
38 | + ], 'plugin'); |
|
39 | + array_walk($plugin, function ($value, $key) { |
|
40 | + $this->$key = $value; |
|
41 | + }); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function activate() |
|
48 | - { |
|
49 | - $this->make(DefaultsManager::class)->set(); |
|
50 | - $this->scheduleCronJob(); |
|
51 | - $this->upgrade(); |
|
52 | - } |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function activate() |
|
48 | + { |
|
49 | + $this->make(DefaultsManager::class)->set(); |
|
50 | + $this->scheduleCronJob(); |
|
51 | + $this->upgrade(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function catchFatalError() |
|
58 | - { |
|
59 | - $error = error_get_last(); |
|
60 | - if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
61 | - return; |
|
62 | - } |
|
63 | - glsr_log()->error($error['message']); |
|
64 | - } |
|
54 | + /** |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function catchFatalError() |
|
58 | + { |
|
59 | + $error = error_get_last(); |
|
60 | + if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
61 | + return; |
|
62 | + } |
|
63 | + glsr_log()->error($error['message']); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param string $name |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public function config($name) |
|
71 | - { |
|
72 | - $configFile = $this->path('config/'.$name.'.php'); |
|
73 | - $config = file_exists($configFile) |
|
74 | - ? include $configFile |
|
75 | - : []; |
|
76 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
77 | - } |
|
66 | + /** |
|
67 | + * @param string $name |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public function config($name) |
|
71 | + { |
|
72 | + $configFile = $this->path('config/'.$name.'.php'); |
|
73 | + $config = file_exists($configFile) |
|
74 | + ? include $configFile |
|
75 | + : []; |
|
76 | + return apply_filters('site-reviews/config/'.$name, $config); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @param string $property |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function constant($property, $className = 'static') |
|
84 | - { |
|
85 | - $constant = $className.'::'.$property; |
|
86 | - return defined($constant) |
|
87 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
88 | - : ''; |
|
89 | - } |
|
79 | + /** |
|
80 | + * @param string $property |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function constant($property, $className = 'static') |
|
84 | + { |
|
85 | + $constant = $className.'::'.$property; |
|
86 | + return defined($constant) |
|
87 | + ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
88 | + : ''; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function deactivate() |
|
95 | - { |
|
96 | - $this->unscheduleCronJob(); |
|
97 | - } |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function deactivate() |
|
95 | + { |
|
96 | + $this->unscheduleCronJob(); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @param string $view |
|
101 | - * @return void|string |
|
102 | - */ |
|
103 | - public function file($view) |
|
104 | - { |
|
105 | - $view.= '.php'; |
|
106 | - $filePaths = []; |
|
107 | - if (Str::startsWith('templates/', $view)) { |
|
108 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
109 | - } |
|
110 | - $filePaths[] = $this->path($view); |
|
111 | - $filePaths[] = $this->path('views/'.$view); |
|
112 | - foreach ($filePaths as $file) { |
|
113 | - if (!file_exists($file)) { |
|
114 | - continue; |
|
115 | - } |
|
116 | - return $file; |
|
117 | - } |
|
118 | - } |
|
99 | + /** |
|
100 | + * @param string $view |
|
101 | + * @return void|string |
|
102 | + */ |
|
103 | + public function file($view) |
|
104 | + { |
|
105 | + $view.= '.php'; |
|
106 | + $filePaths = []; |
|
107 | + if (Str::startsWith('templates/', $view)) { |
|
108 | + $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
109 | + } |
|
110 | + $filePaths[] = $this->path($view); |
|
111 | + $filePaths[] = $this->path('views/'.$view); |
|
112 | + foreach ($filePaths as $file) { |
|
113 | + if (!file_exists($file)) { |
|
114 | + continue; |
|
115 | + } |
|
116 | + return $file; |
|
117 | + } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return array |
|
122 | - */ |
|
123 | - public function getDefaults() |
|
124 | - { |
|
125 | - if (empty($this->defaults)) { |
|
126 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
127 | - $this->upgrade(); |
|
128 | - } |
|
129 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
130 | - } |
|
120 | + /** |
|
121 | + * @return array |
|
122 | + */ |
|
123 | + public function getDefaults() |
|
124 | + { |
|
125 | + if (empty($this->defaults)) { |
|
126 | + $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
127 | + $this->upgrade(); |
|
128 | + } |
|
129 | + return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function getPermission($page = '') |
|
136 | - { |
|
137 | - $permissions = [ |
|
138 | - 'addons' => 'install_plugins', |
|
139 | - 'settings' => 'manage_options', |
|
140 | - // 'welcome' => 'activate_plugins', |
|
141 | - ]; |
|
142 | - return Arr::get($permissions, $page, $this->constant('CAPABILITY')); |
|
143 | - } |
|
132 | + /** |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function getPermission($page = '') |
|
136 | + { |
|
137 | + $permissions = [ |
|
138 | + 'addons' => 'install_plugins', |
|
139 | + 'settings' => 'manage_options', |
|
140 | + // 'welcome' => 'activate_plugins', |
|
141 | + ]; |
|
142 | + return Arr::get($permissions, $page, $this->constant('CAPABILITY')); |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @return bool |
|
147 | - */ |
|
148 | - public function hasPermission($page = '') |
|
149 | - { |
|
150 | - $isAdmin = $this->isAdmin(); |
|
151 | - return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
152 | - } |
|
145 | + /** |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | + public function hasPermission($page = '') |
|
149 | + { |
|
150 | + $isAdmin = $this->isAdmin(); |
|
151 | + return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - public function init() |
|
158 | - { |
|
159 | - $this->make(Actions::class)->run(); |
|
160 | - $this->make(Filters::class)->run(); |
|
161 | - } |
|
154 | + /** |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + public function init() |
|
158 | + { |
|
159 | + $this->make(Actions::class)->run(); |
|
160 | + $this->make(Filters::class)->run(); |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @return bool |
|
165 | - */ |
|
166 | - public function isAdmin() |
|
167 | - { |
|
168 | - return is_admin() && !wp_doing_ajax(); |
|
169 | - } |
|
163 | + /** |
|
164 | + * @return bool |
|
165 | + */ |
|
166 | + public function isAdmin() |
|
167 | + { |
|
168 | + return is_admin() && !wp_doing_ajax(); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @param string $file |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function path($file = '', $realpath = true) |
|
176 | - { |
|
177 | - $path = plugin_dir_path($this->file); |
|
178 | - if (!$realpath) { |
|
179 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
180 | - } |
|
181 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
182 | - return apply_filters('site-reviews/path', $path, $file); |
|
183 | - } |
|
171 | + /** |
|
172 | + * @param string $file |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function path($file = '', $realpath = true) |
|
176 | + { |
|
177 | + $path = plugin_dir_path($this->file); |
|
178 | + if (!$realpath) { |
|
179 | + $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
180 | + } |
|
181 | + $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
182 | + return apply_filters('site-reviews/path', $path, $file); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * @return void |
|
187 | - */ |
|
188 | - public function registerAddons() |
|
189 | - { |
|
190 | - do_action('site-reviews/addon/register', $this); |
|
191 | - } |
|
185 | + /** |
|
186 | + * @return void |
|
187 | + */ |
|
188 | + public function registerAddons() |
|
189 | + { |
|
190 | + do_action('site-reviews/addon/register', $this); |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * @return void |
|
195 | - */ |
|
196 | - public function registerLanguages() |
|
197 | - { |
|
198 | - load_plugin_textdomain(static::ID, false, |
|
199 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
200 | - ); |
|
201 | - } |
|
193 | + /** |
|
194 | + * @return void |
|
195 | + */ |
|
196 | + public function registerLanguages() |
|
197 | + { |
|
198 | + load_plugin_textdomain(static::ID, false, |
|
199 | + trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
200 | + ); |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * @return void |
|
205 | - */ |
|
206 | - public function registerReviewTypes() |
|
207 | - { |
|
208 | - $types = apply_filters('site-reviews/addon/types', []); |
|
209 | - $this->reviewTypes = wp_parse_args($types, [ |
|
210 | - 'local' => __('Local', 'site-reviews'), |
|
211 | - ]); |
|
212 | - } |
|
203 | + /** |
|
204 | + * @return void |
|
205 | + */ |
|
206 | + public function registerReviewTypes() |
|
207 | + { |
|
208 | + $types = apply_filters('site-reviews/addon/types', []); |
|
209 | + $this->reviewTypes = wp_parse_args($types, [ |
|
210 | + 'local' => __('Local', 'site-reviews'), |
|
211 | + ]); |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * @param string $view |
|
216 | - * @return void |
|
217 | - */ |
|
218 | - public function render($view, array $data = []) |
|
219 | - { |
|
220 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
221 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
222 | - if (!file_exists($file)) { |
|
223 | - glsr_log()->error('File not found: '.$file); |
|
224 | - return; |
|
225 | - } |
|
226 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
227 | - extract($data); |
|
228 | - include $file; |
|
229 | - } |
|
214 | + /** |
|
215 | + * @param string $view |
|
216 | + * @return void |
|
217 | + */ |
|
218 | + public function render($view, array $data = []) |
|
219 | + { |
|
220 | + $view = apply_filters('site-reviews/render/view', $view, $data); |
|
221 | + $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
222 | + if (!file_exists($file)) { |
|
223 | + glsr_log()->error('File not found: '.$file); |
|
224 | + return; |
|
225 | + } |
|
226 | + $data = apply_filters('site-reviews/views/data', $data, $view); |
|
227 | + extract($data); |
|
228 | + include $file; |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * @return void |
|
233 | - */ |
|
234 | - public function scheduleCronJob() |
|
235 | - { |
|
236 | - if (wp_next_scheduled(static::CRON_EVENT)) { |
|
237 | - return; |
|
238 | - } |
|
239 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
240 | - } |
|
231 | + /** |
|
232 | + * @return void |
|
233 | + */ |
|
234 | + public function scheduleCronJob() |
|
235 | + { |
|
236 | + if (wp_next_scheduled(static::CRON_EVENT)) { |
|
237 | + return; |
|
238 | + } |
|
239 | + wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
240 | + } |
|
241 | 241 | |
242 | - /** |
|
243 | - * @param string $file |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public function themePath($file = '') |
|
247 | - { |
|
248 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
249 | - } |
|
242 | + /** |
|
243 | + * @param string $file |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public function themePath($file = '') |
|
247 | + { |
|
248 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
249 | + } |
|
250 | 250 | |
251 | - /** |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - public function unscheduleCronJob() |
|
255 | - { |
|
256 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
257 | - } |
|
251 | + /** |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + public function unscheduleCronJob() |
|
255 | + { |
|
256 | + wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * @return void |
|
261 | - */ |
|
262 | - public function upgrade() |
|
263 | - { |
|
264 | - $this->make(Upgrader::class)->run(); |
|
265 | - } |
|
259 | + /** |
|
260 | + * @return void |
|
261 | + */ |
|
262 | + public function upgrade() |
|
263 | + { |
|
264 | + $this->make(Upgrader::class)->run(); |
|
265 | + } |
|
266 | 266 | |
267 | - /** |
|
268 | - * @param mixed $upgrader |
|
269 | - * @return void |
|
270 | - * @action upgrader_process_complete |
|
271 | - */ |
|
272 | - public function upgraded($upgrader, array $data) |
|
273 | - { |
|
274 | - if (array_key_exists('plugins', $data) |
|
275 | - && in_array(plugin_basename($this->file), $data['plugins']) |
|
276 | - && 'update' === $data['action'] |
|
277 | - && 'plugin' === $data['type'] |
|
278 | - ) { |
|
279 | - $this->upgrade(); |
|
280 | - } |
|
281 | - } |
|
267 | + /** |
|
268 | + * @param mixed $upgrader |
|
269 | + * @return void |
|
270 | + * @action upgrader_process_complete |
|
271 | + */ |
|
272 | + public function upgraded($upgrader, array $data) |
|
273 | + { |
|
274 | + if (array_key_exists('plugins', $data) |
|
275 | + && in_array(plugin_basename($this->file), $data['plugins']) |
|
276 | + && 'update' === $data['action'] |
|
277 | + && 'plugin' === $data['type'] |
|
278 | + ) { |
|
279 | + $this->upgrade(); |
|
280 | + } |
|
281 | + } |
|
282 | 282 | |
283 | - /** |
|
284 | - * @param string $path |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - public function url($path = '') |
|
288 | - { |
|
289 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
290 | - return apply_filters('site-reviews/url', $url, $path); |
|
291 | - } |
|
283 | + /** |
|
284 | + * @param string $path |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + public function url($path = '') |
|
288 | + { |
|
289 | + $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
290 | + return apply_filters('site-reviews/url', $url, $path); |
|
291 | + } |
|
292 | 292 | |
293 | - /** |
|
294 | - * @param string $versionLevel |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public function version($versionLevel = '') |
|
298 | - { |
|
299 | - $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
300 | - preg_match($pattern, $this->version, $matches); |
|
301 | - switch ($versionLevel) { |
|
302 | - case 'major': |
|
303 | - $version = Arr::get($matches, 1); |
|
304 | - break; |
|
305 | - case 'minor': |
|
306 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
307 | - break; |
|
308 | - case 'patch': |
|
309 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
310 | - break; |
|
311 | - } |
|
312 | - return empty($version) |
|
313 | - ? $this->version |
|
314 | - : $version; |
|
315 | - } |
|
293 | + /** |
|
294 | + * @param string $versionLevel |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public function version($versionLevel = '') |
|
298 | + { |
|
299 | + $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
300 | + preg_match($pattern, $this->version, $matches); |
|
301 | + switch ($versionLevel) { |
|
302 | + case 'major': |
|
303 | + $version = Arr::get($matches, 1); |
|
304 | + break; |
|
305 | + case 'minor': |
|
306 | + $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
307 | + break; |
|
308 | + case 'patch': |
|
309 | + $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
310 | + break; |
|
311 | + } |
|
312 | + return empty($version) |
|
313 | + ? $this->version |
|
314 | + : $version; |
|
315 | + } |
|
316 | 316 | } |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | public function __construct() |
31 | 31 | { |
32 | 32 | static::$instance = $this; |
33 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
34 | - $plugin = get_file_data($this->file, [ |
|
33 | + $this->file = realpath( trailingslashit( dirname( __DIR__ ) ).static::ID.'.php' ); |
|
34 | + $plugin = get_file_data( $this->file, [ |
|
35 | 35 | 'languages' => 'Domain Path', |
36 | 36 | 'name' => 'Plugin Name', |
37 | 37 | 'version' => 'Version', |
38 | - ], 'plugin'); |
|
39 | - array_walk($plugin, function ($value, $key) { |
|
38 | + ], 'plugin' ); |
|
39 | + array_walk( $plugin, function( $value, $key ) { |
|
40 | 40 | $this->$key = $value; |
41 | 41 | }); |
42 | 42 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function activate() |
48 | 48 | { |
49 | - $this->make(DefaultsManager::class)->set(); |
|
49 | + $this->make( DefaultsManager::class )->set(); |
|
50 | 50 | $this->scheduleCronJob(); |
51 | 51 | $this->upgrade(); |
52 | 52 | } |
@@ -57,34 +57,34 @@ discard block |
||
57 | 57 | public function catchFatalError() |
58 | 58 | { |
59 | 59 | $error = error_get_last(); |
60 | - if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
60 | + if( E_ERROR !== $error['type'] || false === strpos( $error['message'], $this->path() ) ) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | - glsr_log()->error($error['message']); |
|
63 | + glsr_log()->error( $error['message'] ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @param string $name |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public function config($name) |
|
70 | + public function config( $name ) |
|
71 | 71 | { |
72 | - $configFile = $this->path('config/'.$name.'.php'); |
|
73 | - $config = file_exists($configFile) |
|
72 | + $configFile = $this->path( 'config/'.$name.'.php' ); |
|
73 | + $config = file_exists( $configFile ) |
|
74 | 74 | ? include $configFile |
75 | 75 | : []; |
76 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
76 | + return apply_filters( 'site-reviews/config/'.$name, $config ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @param string $property |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - public function constant($property, $className = 'static') |
|
83 | + public function constant( $property, $className = 'static' ) |
|
84 | 84 | { |
85 | 85 | $constant = $className.'::'.$property; |
86 | - return defined($constant) |
|
87 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
86 | + return defined( $constant ) |
|
87 | + ? apply_filters( 'site-reviews/const/'.$property, constant( $constant ) ) |
|
88 | 88 | : ''; |
89 | 89 | } |
90 | 90 | |
@@ -100,17 +100,17 @@ discard block |
||
100 | 100 | * @param string $view |
101 | 101 | * @return void|string |
102 | 102 | */ |
103 | - public function file($view) |
|
103 | + public function file( $view ) |
|
104 | 104 | { |
105 | - $view.= '.php'; |
|
105 | + $view .= '.php'; |
|
106 | 106 | $filePaths = []; |
107 | - if (Str::startsWith('templates/', $view)) { |
|
108 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
107 | + if( Str::startsWith( 'templates/', $view ) ) { |
|
108 | + $filePaths[] = $this->themePath( Str::removePrefix( 'templates/', $view ) ); |
|
109 | 109 | } |
110 | - $filePaths[] = $this->path($view); |
|
111 | - $filePaths[] = $this->path('views/'.$view); |
|
112 | - foreach ($filePaths as $file) { |
|
113 | - if (!file_exists($file)) { |
|
110 | + $filePaths[] = $this->path( $view ); |
|
111 | + $filePaths[] = $this->path( 'views/'.$view ); |
|
112 | + foreach( $filePaths as $file ) { |
|
113 | + if( !file_exists( $file ) ) { |
|
114 | 114 | continue; |
115 | 115 | } |
116 | 116 | return $file; |
@@ -122,33 +122,33 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function getDefaults() |
124 | 124 | { |
125 | - if (empty($this->defaults)) { |
|
126 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
125 | + if( empty($this->defaults) ) { |
|
126 | + $this->defaults = $this->make( DefaultsManager::class )->get(); |
|
127 | 127 | $this->upgrade(); |
128 | 128 | } |
129 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
129 | + return apply_filters( 'site-reviews/get/defaults', $this->defaults ); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - public function getPermission($page = '') |
|
135 | + public function getPermission( $page = '' ) |
|
136 | 136 | { |
137 | 137 | $permissions = [ |
138 | 138 | 'addons' => 'install_plugins', |
139 | 139 | 'settings' => 'manage_options', |
140 | 140 | // 'welcome' => 'activate_plugins', |
141 | 141 | ]; |
142 | - return Arr::get($permissions, $page, $this->constant('CAPABILITY')); |
|
142 | + return Arr::get( $permissions, $page, $this->constant( 'CAPABILITY' ) ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | 146 | * @return bool |
147 | 147 | */ |
148 | - public function hasPermission($page = '') |
|
148 | + public function hasPermission( $page = '' ) |
|
149 | 149 | { |
150 | 150 | $isAdmin = $this->isAdmin(); |
151 | - return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
151 | + return !$isAdmin || ($isAdmin && current_user_can( $this->getPermission( $page ) )); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function init() |
158 | 158 | { |
159 | - $this->make(Actions::class)->run(); |
|
160 | - $this->make(Filters::class)->run(); |
|
159 | + $this->make( Actions::class )->run(); |
|
160 | + $this->make( Filters::class )->run(); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -172,14 +172,14 @@ discard block |
||
172 | 172 | * @param string $file |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - public function path($file = '', $realpath = true) |
|
175 | + public function path( $file = '', $realpath = true ) |
|
176 | 176 | { |
177 | - $path = plugin_dir_path($this->file); |
|
178 | - if (!$realpath) { |
|
179 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
177 | + $path = plugin_dir_path( $this->file ); |
|
178 | + if( !$realpath ) { |
|
179 | + $path = trailingslashit( WP_PLUGIN_DIR ).basename( dirname( $this->file ) ); |
|
180 | 180 | } |
181 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
182 | - return apply_filters('site-reviews/path', $path, $file); |
|
181 | + $path = trailingslashit( $path ).ltrim( trim( $file ), '/' ); |
|
182 | + return apply_filters( 'site-reviews/path', $path, $file ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function registerAddons() |
189 | 189 | { |
190 | - do_action('site-reviews/addon/register', $this); |
|
190 | + do_action( 'site-reviews/addon/register', $this ); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function registerLanguages() |
197 | 197 | { |
198 | - load_plugin_textdomain(static::ID, false, |
|
199 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
198 | + load_plugin_textdomain( static::ID, false, |
|
199 | + trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages ) |
|
200 | 200 | ); |
201 | 201 | } |
202 | 202 | |
@@ -205,26 +205,26 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public function registerReviewTypes() |
207 | 207 | { |
208 | - $types = apply_filters('site-reviews/addon/types', []); |
|
209 | - $this->reviewTypes = wp_parse_args($types, [ |
|
210 | - 'local' => __('Local', 'site-reviews'), |
|
211 | - ]); |
|
208 | + $types = apply_filters( 'site-reviews/addon/types', [] ); |
|
209 | + $this->reviewTypes = wp_parse_args( $types, [ |
|
210 | + 'local' => __( 'Local', 'site-reviews' ), |
|
211 | + ] ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | 215 | * @param string $view |
216 | 216 | * @return void |
217 | 217 | */ |
218 | - public function render($view, array $data = []) |
|
218 | + public function render( $view, array $data = [] ) |
|
219 | 219 | { |
220 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
221 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
222 | - if (!file_exists($file)) { |
|
223 | - glsr_log()->error('File not found: '.$file); |
|
220 | + $view = apply_filters( 'site-reviews/render/view', $view, $data ); |
|
221 | + $file = apply_filters( 'site-reviews/views/file', $this->file( $view ), $view, $data ); |
|
222 | + if( !file_exists( $file ) ) { |
|
223 | + glsr_log()->error( 'File not found: '.$file ); |
|
224 | 224 | return; |
225 | 225 | } |
226 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
227 | - extract($data); |
|
226 | + $data = apply_filters( 'site-reviews/views/data', $data, $view ); |
|
227 | + extract( $data ); |
|
228 | 228 | include $file; |
229 | 229 | } |
230 | 230 | |
@@ -233,19 +233,19 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public function scheduleCronJob() |
235 | 235 | { |
236 | - if (wp_next_scheduled(static::CRON_EVENT)) { |
|
236 | + if( wp_next_scheduled( static::CRON_EVENT ) ) { |
|
237 | 237 | return; |
238 | 238 | } |
239 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
239 | + wp_schedule_event( time(), 'twicedaily', static::CRON_EVENT ); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | 243 | * @param string $file |
244 | 244 | * @return string |
245 | 245 | */ |
246 | - public function themePath($file = '') |
|
246 | + public function themePath( $file = '' ) |
|
247 | 247 | { |
248 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
248 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim( trim( $file ), '/' ); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function unscheduleCronJob() |
255 | 255 | { |
256 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
256 | + wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT ) ), static::CRON_EVENT ); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function upgrade() |
263 | 263 | { |
264 | - $this->make(Upgrader::class)->run(); |
|
264 | + $this->make( Upgrader::class )->run(); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | * @return void |
270 | 270 | * @action upgrader_process_complete |
271 | 271 | */ |
272 | - public function upgraded($upgrader, array $data) |
|
272 | + public function upgraded( $upgrader, array $data ) |
|
273 | 273 | { |
274 | - if (array_key_exists('plugins', $data) |
|
275 | - && in_array(plugin_basename($this->file), $data['plugins']) |
|
274 | + if( array_key_exists( 'plugins', $data ) |
|
275 | + && in_array( plugin_basename( $this->file ), $data['plugins'] ) |
|
276 | 276 | && 'update' === $data['action'] |
277 | 277 | && 'plugin' === $data['type'] |
278 | 278 | ) { |
@@ -284,29 +284,29 @@ discard block |
||
284 | 284 | * @param string $path |
285 | 285 | * @return string |
286 | 286 | */ |
287 | - public function url($path = '') |
|
287 | + public function url( $path = '' ) |
|
288 | 288 | { |
289 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
290 | - return apply_filters('site-reviews/url', $url, $path); |
|
289 | + $url = esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' ) ); |
|
290 | + return apply_filters( 'site-reviews/url', $url, $path ); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | 294 | * @param string $versionLevel |
295 | 295 | * @return string |
296 | 296 | */ |
297 | - public function version($versionLevel = '') |
|
297 | + public function version( $versionLevel = '' ) |
|
298 | 298 | { |
299 | 299 | $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
300 | - preg_match($pattern, $this->version, $matches); |
|
301 | - switch ($versionLevel) { |
|
300 | + preg_match( $pattern, $this->version, $matches ); |
|
301 | + switch( $versionLevel ) { |
|
302 | 302 | case 'major': |
303 | - $version = Arr::get($matches, 1); |
|
303 | + $version = Arr::get( $matches, 1 ); |
|
304 | 304 | break; |
305 | 305 | case 'minor': |
306 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
306 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ); |
|
307 | 307 | break; |
308 | 308 | case 'patch': |
309 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
309 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ).Arr::get( $matches, 3 ); |
|
310 | 310 | break; |
311 | 311 | } |
312 | 312 | return empty($version) |
@@ -8,103 +8,103 @@ |
||
8 | 8 | |
9 | 9 | class ReviewLimits |
10 | 10 | { |
11 | - protected $request; |
|
11 | + protected $request; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @return array |
|
15 | - * @filter site-reviews/get/reviews/query |
|
16 | - */ |
|
17 | - public function filterReviewsQuery(array $parameters, array $args) |
|
18 | - { |
|
19 | - if ($authorId = get_current_user_id()) { |
|
20 | - $parameters['author'] = $authorId; |
|
21 | - } |
|
22 | - $parameters['post_status'] = ['pending', 'publish']; |
|
23 | - return apply_filters('site-reviews/reviews-limits/query', $parameters, $args); |
|
24 | - } |
|
13 | + /** |
|
14 | + * @return array |
|
15 | + * @filter site-reviews/get/reviews/query |
|
16 | + */ |
|
17 | + public function filterReviewsQuery(array $parameters, array $args) |
|
18 | + { |
|
19 | + if ($authorId = get_current_user_id()) { |
|
20 | + $parameters['author'] = $authorId; |
|
21 | + } |
|
22 | + $parameters['post_status'] = ['pending', 'publish']; |
|
23 | + return apply_filters('site-reviews/reviews-limits/query', $parameters, $args); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public function hasReachedLimit(array $request = []) |
|
30 | - { |
|
31 | - $this->request = $request; |
|
32 | - $method = Helper::buildMethodName( |
|
33 | - glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' |
|
34 | - ); |
|
35 | - return method_exists($this, $method) |
|
36 | - ? !call_user_func([$this, $method]) |
|
37 | - : false; |
|
38 | - } |
|
26 | + /** |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public function hasReachedLimit(array $request = []) |
|
30 | + { |
|
31 | + $this->request = $request; |
|
32 | + $method = Helper::buildMethodName( |
|
33 | + glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' |
|
34 | + ); |
|
35 | + return method_exists($this, $method) |
|
36 | + ? !call_user_func([$this, $method]) |
|
37 | + : false; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $value |
|
42 | - * @param string $whitelist |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function isWhitelisted($value, $whitelist) |
|
46 | - { |
|
47 | - if (empty($whitelist)) { |
|
48 | - return false; |
|
49 | - } |
|
50 | - return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); |
|
51 | - } |
|
40 | + /** |
|
41 | + * @param string $value |
|
42 | + * @param string $whitelist |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function isWhitelisted($value, $whitelist) |
|
46 | + { |
|
47 | + if (empty($whitelist)) { |
|
48 | + return false; |
|
49 | + } |
|
50 | + return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param string $whitelistName |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - protected function getWhitelist($whitelistName) |
|
58 | - { |
|
59 | - return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); |
|
60 | - } |
|
53 | + /** |
|
54 | + * @param string $whitelistName |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + protected function getWhitelist($whitelistName) |
|
58 | + { |
|
59 | + return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - protected function validate($key, $value, $addMetaQuery = true) |
|
66 | - { |
|
67 | - if ($this->isWhitelisted($value, $this->getWhitelist($key))) { |
|
68 | - return true; |
|
69 | - } |
|
70 | - add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); |
|
71 | - $args = ['assigned_to' => Arr::get($this->request, 'assign_to')]; |
|
72 | - if ($addMetaQuery) { |
|
73 | - $args[$key] = $value; |
|
74 | - } |
|
75 | - $reviews = glsr_get_reviews($args); |
|
76 | - remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); |
|
77 | - return 0 === count($reviews); |
|
78 | - } |
|
62 | + /** |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + protected function validate($key, $value, $addMetaQuery = true) |
|
66 | + { |
|
67 | + if ($this->isWhitelisted($value, $this->getWhitelist($key))) { |
|
68 | + return true; |
|
69 | + } |
|
70 | + add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); |
|
71 | + $args = ['assigned_to' => Arr::get($this->request, 'assign_to')]; |
|
72 | + if ($addMetaQuery) { |
|
73 | + $args[$key] = $value; |
|
74 | + } |
|
75 | + $reviews = glsr_get_reviews($args); |
|
76 | + remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); |
|
77 | + return 0 === count($reviews); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return bool |
|
82 | - */ |
|
83 | - protected function validateByEmail() |
|
84 | - { |
|
85 | - glsr_log()->debug('Email is: '.Arr::get($this->request, 'email')); |
|
86 | - return $this->validate('email', Arr::get($this->request, 'email')); |
|
87 | - } |
|
80 | + /** |
|
81 | + * @return bool |
|
82 | + */ |
|
83 | + protected function validateByEmail() |
|
84 | + { |
|
85 | + glsr_log()->debug('Email is: '.Arr::get($this->request, 'email')); |
|
86 | + return $this->validate('email', Arr::get($this->request, 'email')); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - protected function validateByIpAddress() |
|
93 | - { |
|
94 | - glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address')); |
|
95 | - return $this->validate('ip_address', Arr::get($this->request, 'ip_address')); |
|
96 | - } |
|
89 | + /** |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + protected function validateByIpAddress() |
|
93 | + { |
|
94 | + glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address')); |
|
95 | + return $this->validate('ip_address', Arr::get($this->request, 'ip_address')); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - protected function validateByUsername() |
|
102 | - { |
|
103 | - $user = wp_get_current_user(); |
|
104 | - if (!$user->exists()) { |
|
105 | - return true; |
|
106 | - } |
|
107 | - glsr_log()->debug('Username is: '.$user->user_login); |
|
108 | - return $this->validate('username', $user->user_login, false); |
|
109 | - } |
|
98 | + /** |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + protected function validateByUsername() |
|
102 | + { |
|
103 | + $user = wp_get_current_user(); |
|
104 | + if (!$user->exists()) { |
|
105 | + return true; |
|
106 | + } |
|
107 | + glsr_log()->debug('Username is: '.$user->user_login); |
|
108 | + return $this->validate('username', $user->user_login, false); |
|
109 | + } |
|
110 | 110 | } |
@@ -14,26 +14,26 @@ discard block |
||
14 | 14 | * @return array |
15 | 15 | * @filter site-reviews/get/reviews/query |
16 | 16 | */ |
17 | - public function filterReviewsQuery(array $parameters, array $args) |
|
17 | + public function filterReviewsQuery( array $parameters, array $args ) |
|
18 | 18 | { |
19 | - if ($authorId = get_current_user_id()) { |
|
19 | + if( $authorId = get_current_user_id() ) { |
|
20 | 20 | $parameters['author'] = $authorId; |
21 | 21 | } |
22 | 22 | $parameters['post_status'] = ['pending', 'publish']; |
23 | - return apply_filters('site-reviews/reviews-limits/query', $parameters, $args); |
|
23 | + return apply_filters( 'site-reviews/reviews-limits/query', $parameters, $args ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @return bool |
28 | 28 | */ |
29 | - public function hasReachedLimit(array $request = []) |
|
29 | + public function hasReachedLimit( array $request = [] ) |
|
30 | 30 | { |
31 | 31 | $this->request = $request; |
32 | 32 | $method = Helper::buildMethodName( |
33 | - glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' |
|
33 | + glsr( OptionManager::class )->get( 'settings.submissions.limit' ), 'validateBy' |
|
34 | 34 | ); |
35 | - return method_exists($this, $method) |
|
36 | - ? !call_user_func([$this, $method]) |
|
35 | + return method_exists( $this, $method ) |
|
36 | + ? !call_user_func( [$this, $method] ) |
|
37 | 37 | : false; |
38 | 38 | } |
39 | 39 | |
@@ -42,39 +42,39 @@ discard block |
||
42 | 42 | * @param string $whitelist |
43 | 43 | * @return bool |
44 | 44 | */ |
45 | - public function isWhitelisted($value, $whitelist) |
|
45 | + public function isWhitelisted( $value, $whitelist ) |
|
46 | 46 | { |
47 | - if (empty($whitelist)) { |
|
47 | + if( empty($whitelist) ) { |
|
48 | 48 | return false; |
49 | 49 | } |
50 | - return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); |
|
50 | + return in_array( $value, array_filter( explode( "\n", $whitelist ), 'trim' ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @param string $whitelistName |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - protected function getWhitelist($whitelistName) |
|
57 | + protected function getWhitelist( $whitelistName ) |
|
58 | 58 | { |
59 | - return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); |
|
59 | + return glsr( OptionManager::class )->get( 'settings.submissions.limit_whitelist.'.$whitelistName ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @return bool |
64 | 64 | */ |
65 | - protected function validate($key, $value, $addMetaQuery = true) |
|
65 | + protected function validate( $key, $value, $addMetaQuery = true ) |
|
66 | 66 | { |
67 | - if ($this->isWhitelisted($value, $this->getWhitelist($key))) { |
|
67 | + if( $this->isWhitelisted( $value, $this->getWhitelist( $key ) ) ) { |
|
68 | 68 | return true; |
69 | 69 | } |
70 | - add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); |
|
71 | - $args = ['assigned_to' => Arr::get($this->request, 'assign_to')]; |
|
72 | - if ($addMetaQuery) { |
|
70 | + add_filter( 'site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2 ); |
|
71 | + $args = ['assigned_to' => Arr::get( $this->request, 'assign_to' )]; |
|
72 | + if( $addMetaQuery ) { |
|
73 | 73 | $args[$key] = $value; |
74 | 74 | } |
75 | - $reviews = glsr_get_reviews($args); |
|
76 | - remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); |
|
77 | - return 0 === count($reviews); |
|
75 | + $reviews = glsr_get_reviews( $args ); |
|
76 | + remove_filter( 'site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5 ); |
|
77 | + return 0 === count( $reviews ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | */ |
83 | 83 | protected function validateByEmail() |
84 | 84 | { |
85 | - glsr_log()->debug('Email is: '.Arr::get($this->request, 'email')); |
|
86 | - return $this->validate('email', Arr::get($this->request, 'email')); |
|
85 | + glsr_log()->debug( 'Email is: '.Arr::get( $this->request, 'email' ) ); |
|
86 | + return $this->validate( 'email', Arr::get( $this->request, 'email' ) ); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | */ |
92 | 92 | protected function validateByIpAddress() |
93 | 93 | { |
94 | - glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address')); |
|
95 | - return $this->validate('ip_address', Arr::get($this->request, 'ip_address')); |
|
94 | + glsr_log()->debug( 'IP Address is: '.Arr::get( $this->request, 'ip_address' ) ); |
|
95 | + return $this->validate( 'ip_address', Arr::get( $this->request, 'ip_address' ) ); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | protected function validateByUsername() |
102 | 102 | { |
103 | 103 | $user = wp_get_current_user(); |
104 | - if (!$user->exists()) { |
|
104 | + if( !$user->exists() ) { |
|
105 | 105 | return true; |
106 | 106 | } |
107 | - glsr_log()->debug('Username is: '.$user->user_login); |
|
108 | - return $this->validate('username', $user->user_login, false); |
|
107 | + glsr_log()->debug( 'Username is: '.$user->user_login ); |
|
108 | + return $this->validate( 'username', $user->user_login, false ); |
|
109 | 109 | } |
110 | 110 | } |
@@ -13,288 +13,288 @@ |
||
13 | 13 | |
14 | 14 | class ValidateReview |
15 | 15 | { |
16 | - const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
16 | + const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
17 | 17 | |
18 | - const RECAPTCHA_DISABLED = 0; |
|
19 | - const RECAPTCHA_EMPTY = 1; |
|
20 | - const RECAPTCHA_FAILED = 2; |
|
21 | - const RECAPTCHA_INVALID = 3; |
|
22 | - const RECAPTCHA_VALID = 4; |
|
18 | + const RECAPTCHA_DISABLED = 0; |
|
19 | + const RECAPTCHA_EMPTY = 1; |
|
20 | + const RECAPTCHA_FAILED = 2; |
|
21 | + const RECAPTCHA_INVALID = 3; |
|
22 | + const RECAPTCHA_VALID = 4; |
|
23 | 23 | |
24 | - const VALIDATION_RULES = [ |
|
25 | - 'content' => 'required', |
|
26 | - 'email' => 'required|email', |
|
27 | - 'name' => 'required', |
|
28 | - 'rating' => 'required|number|between:1,5', |
|
29 | - 'terms' => 'accepted', |
|
30 | - 'title' => 'required', |
|
31 | - ]; |
|
24 | + const VALIDATION_RULES = [ |
|
25 | + 'content' => 'required', |
|
26 | + 'email' => 'required|email', |
|
27 | + 'name' => 'required', |
|
28 | + 'rating' => 'required|number|between:1,5', |
|
29 | + 'terms' => 'accepted', |
|
30 | + 'title' => 'required', |
|
31 | + ]; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var string|void |
|
35 | - */ |
|
36 | - public $error; |
|
33 | + /** |
|
34 | + * @var string|void |
|
35 | + */ |
|
36 | + public $error; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $form_id; |
|
38 | + /** |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $form_id; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - public $recaptchaIsUnset = false; |
|
43 | + /** |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + public $recaptchaIsUnset = false; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - public $request; |
|
48 | + /** |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + public $request; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - protected $options; |
|
53 | + /** |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + protected $options; |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return static |
|
60 | - */ |
|
61 | - public function validate(array $request) |
|
62 | - { |
|
63 | - $this->form_id = $request['form_id']; |
|
64 | - $this->options = glsr(OptionManager::class)->all(); |
|
65 | - $this->request = $this->validateRequest($request); |
|
66 | - $this->validateCustom(); |
|
67 | - $this->validateHoneyPot(); |
|
68 | - $this->validateReviewLimits(); |
|
69 | - $this->validateBlacklist(); |
|
70 | - $this->validateAkismet(); |
|
71 | - $this->validateRecaptcha(); |
|
72 | - if (!empty($this->error)) { |
|
73 | - $this->setSessionValues('message', $this->error); |
|
74 | - } |
|
75 | - return $this; |
|
76 | - } |
|
58 | + /** |
|
59 | + * @return static |
|
60 | + */ |
|
61 | + public function validate(array $request) |
|
62 | + { |
|
63 | + $this->form_id = $request['form_id']; |
|
64 | + $this->options = glsr(OptionManager::class)->all(); |
|
65 | + $this->request = $this->validateRequest($request); |
|
66 | + $this->validateCustom(); |
|
67 | + $this->validateHoneyPot(); |
|
68 | + $this->validateReviewLimits(); |
|
69 | + $this->validateBlacklist(); |
|
70 | + $this->validateAkismet(); |
|
71 | + $this->validateRecaptcha(); |
|
72 | + if (!empty($this->error)) { |
|
73 | + $this->setSessionValues('message', $this->error); |
|
74 | + } |
|
75 | + return $this; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $path |
|
80 | - * @param mixed $fallback |
|
81 | - * @return mixed |
|
82 | - */ |
|
83 | - protected function getOption($path, $fallback = '') |
|
84 | - { |
|
85 | - return Arr::get($this->options, $path, $fallback); |
|
86 | - } |
|
78 | + /** |
|
79 | + * @param string $path |
|
80 | + * @param mixed $fallback |
|
81 | + * @return mixed |
|
82 | + */ |
|
83 | + protected function getOption($path, $fallback = '') |
|
84 | + { |
|
85 | + return Arr::get($this->options, $path, $fallback); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return int |
|
90 | - */ |
|
91 | - protected function getRecaptchaStatus() |
|
92 | - { |
|
93 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
94 | - return static::RECAPTCHA_DISABLED; |
|
95 | - } |
|
96 | - if (empty($this->request['_recaptcha-token'])) { |
|
97 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
98 | - ? static::RECAPTCHA_EMPTY |
|
99 | - : static::RECAPTCHA_FAILED; |
|
100 | - } |
|
101 | - return $this->getRecaptchaTokenStatus(); |
|
102 | - } |
|
88 | + /** |
|
89 | + * @return int |
|
90 | + */ |
|
91 | + protected function getRecaptchaStatus() |
|
92 | + { |
|
93 | + if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
94 | + return static::RECAPTCHA_DISABLED; |
|
95 | + } |
|
96 | + if (empty($this->request['_recaptcha-token'])) { |
|
97 | + return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
98 | + ? static::RECAPTCHA_EMPTY |
|
99 | + : static::RECAPTCHA_FAILED; |
|
100 | + } |
|
101 | + return $this->getRecaptchaTokenStatus(); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return int |
|
106 | - */ |
|
107 | - protected function getRecaptchaTokenStatus() |
|
108 | - { |
|
109 | - $endpoint = add_query_arg([ |
|
110 | - 'remoteip' => Helper::getIpAddress(), |
|
111 | - 'response' => $this->request['_recaptcha-token'], |
|
112 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
113 | - ], static::RECAPTCHA_ENDPOINT); |
|
114 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
115 | - glsr_log()->error($response->get_error_message()); |
|
116 | - return static::RECAPTCHA_FAILED; |
|
117 | - } |
|
118 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
119 | - if (!empty($response->success)) { |
|
120 | - return boolval($response->success) |
|
121 | - ? static::RECAPTCHA_VALID |
|
122 | - : static::RECAPTCHA_INVALID; |
|
123 | - } |
|
124 | - foreach ($response->{'error-codes'} as $error) { |
|
125 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
126 | - } |
|
127 | - return static::RECAPTCHA_INVALID; |
|
128 | - } |
|
104 | + /** |
|
105 | + * @return int |
|
106 | + */ |
|
107 | + protected function getRecaptchaTokenStatus() |
|
108 | + { |
|
109 | + $endpoint = add_query_arg([ |
|
110 | + 'remoteip' => Helper::getIpAddress(), |
|
111 | + 'response' => $this->request['_recaptcha-token'], |
|
112 | + 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
113 | + ], static::RECAPTCHA_ENDPOINT); |
|
114 | + if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
115 | + glsr_log()->error($response->get_error_message()); |
|
116 | + return static::RECAPTCHA_FAILED; |
|
117 | + } |
|
118 | + $response = json_decode(wp_remote_retrieve_body($response)); |
|
119 | + if (!empty($response->success)) { |
|
120 | + return boolval($response->success) |
|
121 | + ? static::RECAPTCHA_VALID |
|
122 | + : static::RECAPTCHA_INVALID; |
|
123 | + } |
|
124 | + foreach ($response->{'error-codes'} as $error) { |
|
125 | + glsr_log()->error('reCAPTCHA error: '.$error); |
|
126 | + } |
|
127 | + return static::RECAPTCHA_INVALID; |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @return array |
|
132 | - */ |
|
133 | - protected function getValidationRules(array $request) |
|
134 | - { |
|
135 | - $rules = array_intersect_key( |
|
136 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
137 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
138 | - ); |
|
139 | - $excluded = explode(',', Arr::get($request, 'excluded')); |
|
140 | - return array_diff_key($rules, array_flip($excluded)); |
|
141 | - } |
|
130 | + /** |
|
131 | + * @return array |
|
132 | + */ |
|
133 | + protected function getValidationRules(array $request) |
|
134 | + { |
|
135 | + $rules = array_intersect_key( |
|
136 | + apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
137 | + array_flip($this->getOption('settings.submissions.required', [])) |
|
138 | + ); |
|
139 | + $excluded = explode(',', Arr::get($request, 'excluded')); |
|
140 | + return array_diff_key($rules, array_flip($excluded)); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * @return bool |
|
145 | - */ |
|
146 | - protected function isRequestValid(array $request) |
|
147 | - { |
|
148 | - $rules = $this->getValidationRules($request); |
|
149 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
150 | - if (empty($errors)) { |
|
151 | - return true; |
|
152 | - } |
|
153 | - $this->setSessionValues('errors', $errors); |
|
154 | - $this->setSessionValues('values', $request); |
|
155 | - return false; |
|
156 | - } |
|
143 | + /** |
|
144 | + * @return bool |
|
145 | + */ |
|
146 | + protected function isRequestValid(array $request) |
|
147 | + { |
|
148 | + $rules = $this->getValidationRules($request); |
|
149 | + $errors = glsr(Validator::class)->validate($request, $rules); |
|
150 | + if (empty($errors)) { |
|
151 | + return true; |
|
152 | + } |
|
153 | + $this->setSessionValues('errors', $errors); |
|
154 | + $this->setSessionValues('values', $request); |
|
155 | + return false; |
|
156 | + } |
|
157 | 157 | |
158 | - protected function setError($message, $loggedMessage = '') |
|
159 | - { |
|
160 | - $this->setSessionValues('errors', [], $loggedMessage); |
|
161 | - $this->error = $message; |
|
162 | - } |
|
158 | + protected function setError($message, $loggedMessage = '') |
|
159 | + { |
|
160 | + $this->setSessionValues('errors', [], $loggedMessage); |
|
161 | + $this->error = $message; |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * @param string $type |
|
166 | - * @param mixed $value |
|
167 | - * @param string $loggedMessage |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
171 | - { |
|
172 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
173 | - if (!empty($loggedMessage)) { |
|
174 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
175 | - } |
|
176 | - } |
|
164 | + /** |
|
165 | + * @param string $type |
|
166 | + * @param mixed $value |
|
167 | + * @param string $loggedMessage |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + protected function setSessionValues($type, $value, $loggedMessage = '') |
|
171 | + { |
|
172 | + glsr()->sessionSet($this->form_id.$type, $value); |
|
173 | + if (!empty($loggedMessage)) { |
|
174 | + glsr_log()->warning($loggedMessage)->debug($this->request); |
|
175 | + } |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - protected function validateAkismet() |
|
182 | - { |
|
183 | - if (!empty($this->error)) { |
|
184 | - return; |
|
185 | - } |
|
186 | - if (!glsr(Akismet::class)->isSpam($this->request)) { |
|
187 | - return; |
|
188 | - } |
|
189 | - $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
190 | - 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
|
191 | - ); |
|
192 | - } |
|
178 | + /** |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + protected function validateAkismet() |
|
182 | + { |
|
183 | + if (!empty($this->error)) { |
|
184 | + return; |
|
185 | + } |
|
186 | + if (!glsr(Akismet::class)->isSpam($this->request)) { |
|
187 | + return; |
|
188 | + } |
|
189 | + $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
190 | + 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
|
191 | + ); |
|
192 | + } |
|
193 | 193 | |
194 | - /** |
|
195 | - * @return void |
|
196 | - */ |
|
197 | - protected function validateBlacklist() |
|
198 | - { |
|
199 | - if (!empty($this->error)) { |
|
200 | - return; |
|
201 | - } |
|
202 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
203 | - return; |
|
204 | - } |
|
205 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
206 | - if ('reject' != $blacklistAction) { |
|
207 | - $this->request['blacklisted'] = true; |
|
208 | - return; |
|
209 | - } |
|
210 | - $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
211 | - 'Blacklisted submission detected:' |
|
212 | - ); |
|
213 | - } |
|
194 | + /** |
|
195 | + * @return void |
|
196 | + */ |
|
197 | + protected function validateBlacklist() |
|
198 | + { |
|
199 | + if (!empty($this->error)) { |
|
200 | + return; |
|
201 | + } |
|
202 | + if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
203 | + return; |
|
204 | + } |
|
205 | + $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
206 | + if ('reject' != $blacklistAction) { |
|
207 | + $this->request['blacklisted'] = true; |
|
208 | + return; |
|
209 | + } |
|
210 | + $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
211 | + 'Blacklisted submission detected:' |
|
212 | + ); |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * @return void |
|
217 | - */ |
|
218 | - protected function validateCustom() |
|
219 | - { |
|
220 | - if (!empty($this->error)) { |
|
221 | - return; |
|
222 | - } |
|
223 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
224 | - if (true === $validated) { |
|
225 | - return; |
|
226 | - } |
|
227 | - $errorMessage = is_string($validated) |
|
228 | - ? $validated |
|
229 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
230 | - $this->setError($errorMessage); |
|
231 | - $this->setSessionValues('values', $this->request); |
|
232 | - } |
|
215 | + /** |
|
216 | + * @return void |
|
217 | + */ |
|
218 | + protected function validateCustom() |
|
219 | + { |
|
220 | + if (!empty($this->error)) { |
|
221 | + return; |
|
222 | + } |
|
223 | + $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
224 | + if (true === $validated) { |
|
225 | + return; |
|
226 | + } |
|
227 | + $errorMessage = is_string($validated) |
|
228 | + ? $validated |
|
229 | + : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
230 | + $this->setError($errorMessage); |
|
231 | + $this->setSessionValues('values', $this->request); |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * @return void |
|
236 | - */ |
|
237 | - protected function validateHoneyPot() |
|
238 | - { |
|
239 | - if (!empty($this->error)) { |
|
240 | - return; |
|
241 | - } |
|
242 | - if (empty($this->request['gotcha'])) { |
|
243 | - return; |
|
244 | - } |
|
245 | - $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
246 | - 'The Honeypot caught a bad submission:' |
|
247 | - ); |
|
248 | - } |
|
234 | + /** |
|
235 | + * @return void |
|
236 | + */ |
|
237 | + protected function validateHoneyPot() |
|
238 | + { |
|
239 | + if (!empty($this->error)) { |
|
240 | + return; |
|
241 | + } |
|
242 | + if (empty($this->request['gotcha'])) { |
|
243 | + return; |
|
244 | + } |
|
245 | + $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
246 | + 'The Honeypot caught a bad submission:' |
|
247 | + ); |
|
248 | + } |
|
249 | 249 | |
250 | - /** |
|
251 | - * @return void |
|
252 | - */ |
|
253 | - protected function validateReviewLimits() |
|
254 | - { |
|
255 | - if (!empty($this->error)) { |
|
256 | - return; |
|
257 | - } |
|
258 | - if (!glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
259 | - return; |
|
260 | - } |
|
261 | - $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
262 | - } |
|
250 | + /** |
|
251 | + * @return void |
|
252 | + */ |
|
253 | + protected function validateReviewLimits() |
|
254 | + { |
|
255 | + if (!empty($this->error)) { |
|
256 | + return; |
|
257 | + } |
|
258 | + if (!glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
259 | + return; |
|
260 | + } |
|
261 | + $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
265 | - * @return void |
|
266 | - */ |
|
267 | - protected function validateRecaptcha() |
|
268 | - { |
|
269 | - if (!empty($this->error)) { |
|
270 | - return; |
|
271 | - } |
|
272 | - $status = $this->getRecaptchaStatus(); |
|
273 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
274 | - return; |
|
275 | - } |
|
276 | - if (static::RECAPTCHA_EMPTY === $status) { |
|
277 | - $this->setSessionValues('recaptcha', 'unset'); |
|
278 | - $this->recaptchaIsUnset = true; |
|
279 | - return; |
|
280 | - } |
|
281 | - $this->setSessionValues('recaptcha', 'reset'); |
|
282 | - $errors = [ |
|
283 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
284 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
285 | - ]; |
|
286 | - $this->setError($errors[$status]); |
|
287 | - } |
|
264 | + /** |
|
265 | + * @return void |
|
266 | + */ |
|
267 | + protected function validateRecaptcha() |
|
268 | + { |
|
269 | + if (!empty($this->error)) { |
|
270 | + return; |
|
271 | + } |
|
272 | + $status = $this->getRecaptchaStatus(); |
|
273 | + if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
274 | + return; |
|
275 | + } |
|
276 | + if (static::RECAPTCHA_EMPTY === $status) { |
|
277 | + $this->setSessionValues('recaptcha', 'unset'); |
|
278 | + $this->recaptchaIsUnset = true; |
|
279 | + return; |
|
280 | + } |
|
281 | + $this->setSessionValues('recaptcha', 'reset'); |
|
282 | + $errors = [ |
|
283 | + static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
284 | + static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
285 | + ]; |
|
286 | + $this->setError($errors[$status]); |
|
287 | + } |
|
288 | 288 | |
289 | - /** |
|
290 | - * @return array |
|
291 | - */ |
|
292 | - protected function validateRequest(array $request) |
|
293 | - { |
|
294 | - if (!$this->isRequestValid($request)) { |
|
295 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
296 | - return $request; |
|
297 | - } |
|
298 | - return array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request); |
|
299 | - } |
|
289 | + /** |
|
290 | + * @return array |
|
291 | + */ |
|
292 | + protected function validateRequest(array $request) |
|
293 | + { |
|
294 | + if (!$this->isRequestValid($request)) { |
|
295 | + $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
296 | + return $request; |
|
297 | + } |
|
298 | + return array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request); |
|
299 | + } |
|
300 | 300 | } |
@@ -58,19 +58,19 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * @return static |
60 | 60 | */ |
61 | - public function validate(array $request) |
|
61 | + public function validate( array $request ) |
|
62 | 62 | { |
63 | 63 | $this->form_id = $request['form_id']; |
64 | - $this->options = glsr(OptionManager::class)->all(); |
|
65 | - $this->request = $this->validateRequest($request); |
|
64 | + $this->options = glsr( OptionManager::class )->all(); |
|
65 | + $this->request = $this->validateRequest( $request ); |
|
66 | 66 | $this->validateCustom(); |
67 | 67 | $this->validateHoneyPot(); |
68 | 68 | $this->validateReviewLimits(); |
69 | 69 | $this->validateBlacklist(); |
70 | 70 | $this->validateAkismet(); |
71 | 71 | $this->validateRecaptcha(); |
72 | - if (!empty($this->error)) { |
|
73 | - $this->setSessionValues('message', $this->error); |
|
72 | + if( !empty($this->error) ) { |
|
73 | + $this->setSessionValues( 'message', $this->error ); |
|
74 | 74 | } |
75 | 75 | return $this; |
76 | 76 | } |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * @param mixed $fallback |
81 | 81 | * @return mixed |
82 | 82 | */ |
83 | - protected function getOption($path, $fallback = '') |
|
83 | + protected function getOption( $path, $fallback = '' ) |
|
84 | 84 | { |
85 | - return Arr::get($this->options, $path, $fallback); |
|
85 | + return Arr::get( $this->options, $path, $fallback ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function getRecaptchaStatus() |
92 | 92 | { |
93 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
93 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
94 | 94 | return static::RECAPTCHA_DISABLED; |
95 | 95 | } |
96 | - if (empty($this->request['_recaptcha-token'])) { |
|
97 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
96 | + if( empty($this->request['_recaptcha-token']) ) { |
|
97 | + return $this->request['_counter'] < intval( apply_filters( 'site-reviews/recaptcha/timeout', 5 ) ) |
|
98 | 98 | ? static::RECAPTCHA_EMPTY |
99 | 99 | : static::RECAPTCHA_FAILED; |
100 | 100 | } |
@@ -106,23 +106,23 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function getRecaptchaTokenStatus() |
108 | 108 | { |
109 | - $endpoint = add_query_arg([ |
|
109 | + $endpoint = add_query_arg( [ |
|
110 | 110 | 'remoteip' => Helper::getIpAddress(), |
111 | 111 | 'response' => $this->request['_recaptcha-token'], |
112 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
113 | - ], static::RECAPTCHA_ENDPOINT); |
|
114 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
115 | - glsr_log()->error($response->get_error_message()); |
|
112 | + 'secret' => $this->getOption( 'settings.submissions.recaptcha.secret' ), |
|
113 | + ], static::RECAPTCHA_ENDPOINT ); |
|
114 | + if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) { |
|
115 | + glsr_log()->error( $response->get_error_message() ); |
|
116 | 116 | return static::RECAPTCHA_FAILED; |
117 | 117 | } |
118 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
119 | - if (!empty($response->success)) { |
|
120 | - return boolval($response->success) |
|
118 | + $response = json_decode( wp_remote_retrieve_body( $response ) ); |
|
119 | + if( !empty($response->success) ) { |
|
120 | + return boolval( $response->success ) |
|
121 | 121 | ? static::RECAPTCHA_VALID |
122 | 122 | : static::RECAPTCHA_INVALID; |
123 | 123 | } |
124 | - foreach ($response->{'error-codes'} as $error) { |
|
125 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
124 | + foreach( $response->{'error-codes'} as $error ) { |
|
125 | + glsr_log()->error( 'reCAPTCHA error: '.$error ); |
|
126 | 126 | } |
127 | 127 | return static::RECAPTCHA_INVALID; |
128 | 128 | } |
@@ -130,34 +130,34 @@ discard block |
||
130 | 130 | /** |
131 | 131 | * @return array |
132 | 132 | */ |
133 | - protected function getValidationRules(array $request) |
|
133 | + protected function getValidationRules( array $request ) |
|
134 | 134 | { |
135 | 135 | $rules = array_intersect_key( |
136 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
137 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
136 | + apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES, $request ), |
|
137 | + array_flip( $this->getOption( 'settings.submissions.required', [] ) ) |
|
138 | 138 | ); |
139 | - $excluded = explode(',', Arr::get($request, 'excluded')); |
|
140 | - return array_diff_key($rules, array_flip($excluded)); |
|
139 | + $excluded = explode( ',', Arr::get( $request, 'excluded' ) ); |
|
140 | + return array_diff_key( $rules, array_flip( $excluded ) ); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
144 | 144 | * @return bool |
145 | 145 | */ |
146 | - protected function isRequestValid(array $request) |
|
146 | + protected function isRequestValid( array $request ) |
|
147 | 147 | { |
148 | - $rules = $this->getValidationRules($request); |
|
149 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
150 | - if (empty($errors)) { |
|
148 | + $rules = $this->getValidationRules( $request ); |
|
149 | + $errors = glsr( Validator::class )->validate( $request, $rules ); |
|
150 | + if( empty($errors) ) { |
|
151 | 151 | return true; |
152 | 152 | } |
153 | - $this->setSessionValues('errors', $errors); |
|
154 | - $this->setSessionValues('values', $request); |
|
153 | + $this->setSessionValues( 'errors', $errors ); |
|
154 | + $this->setSessionValues( 'values', $request ); |
|
155 | 155 | return false; |
156 | 156 | } |
157 | 157 | |
158 | - protected function setError($message, $loggedMessage = '') |
|
158 | + protected function setError( $message, $loggedMessage = '' ) |
|
159 | 159 | { |
160 | - $this->setSessionValues('errors', [], $loggedMessage); |
|
160 | + $this->setSessionValues( 'errors', [], $loggedMessage ); |
|
161 | 161 | $this->error = $message; |
162 | 162 | } |
163 | 163 | |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | * @param string $loggedMessage |
168 | 168 | * @return void |
169 | 169 | */ |
170 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
170 | + protected function setSessionValues( $type, $value, $loggedMessage = '' ) |
|
171 | 171 | { |
172 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
173 | - if (!empty($loggedMessage)) { |
|
174 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
172 | + glsr()->sessionSet( $this->form_id.$type, $value ); |
|
173 | + if( !empty($loggedMessage) ) { |
|
174 | + glsr_log()->warning( $loggedMessage )->debug( $this->request ); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | */ |
181 | 181 | protected function validateAkismet() |
182 | 182 | { |
183 | - if (!empty($this->error)) { |
|
183 | + if( !empty($this->error) ) { |
|
184 | 184 | return; |
185 | 185 | } |
186 | - if (!glsr(Akismet::class)->isSpam($this->request)) { |
|
186 | + if( !glsr( Akismet::class )->isSpam( $this->request ) ) { |
|
187 | 187 | return; |
188 | 188 | } |
189 | - $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
189 | + $this->setError( __( 'This review has been flagged as possible spam and cannot be submitted.', 'site-reviews' ), |
|
190 | 190 | 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
191 | 191 | ); |
192 | 192 | } |
@@ -196,18 +196,18 @@ discard block |
||
196 | 196 | */ |
197 | 197 | protected function validateBlacklist() |
198 | 198 | { |
199 | - if (!empty($this->error)) { |
|
199 | + if( !empty($this->error) ) { |
|
200 | 200 | return; |
201 | 201 | } |
202 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
202 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) ) { |
|
203 | 203 | return; |
204 | 204 | } |
205 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
206 | - if ('reject' != $blacklistAction) { |
|
205 | + $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
|
206 | + if( 'reject' != $blacklistAction ) { |
|
207 | 207 | $this->request['blacklisted'] = true; |
208 | 208 | return; |
209 | 209 | } |
210 | - $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
210 | + $this->setError( __( 'Your review cannot be submitted at this time.', 'site-reviews' ), |
|
211 | 211 | 'Blacklisted submission detected:' |
212 | 212 | ); |
213 | 213 | } |
@@ -217,18 +217,18 @@ discard block |
||
217 | 217 | */ |
218 | 218 | protected function validateCustom() |
219 | 219 | { |
220 | - if (!empty($this->error)) { |
|
220 | + if( !empty($this->error) ) { |
|
221 | 221 | return; |
222 | 222 | } |
223 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
224 | - if (true === $validated) { |
|
223 | + $validated = apply_filters( 'site-reviews/validate/custom', true, $this->request ); |
|
224 | + if( true === $validated ) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | - $errorMessage = is_string($validated) |
|
227 | + $errorMessage = is_string( $validated ) |
|
228 | 228 | ? $validated |
229 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
230 | - $this->setError($errorMessage); |
|
231 | - $this->setSessionValues('values', $this->request); |
|
229 | + : __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
|
230 | + $this->setError( $errorMessage ); |
|
231 | + $this->setSessionValues( 'values', $this->request ); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -236,13 +236,13 @@ discard block |
||
236 | 236 | */ |
237 | 237 | protected function validateHoneyPot() |
238 | 238 | { |
239 | - if (!empty($this->error)) { |
|
239 | + if( !empty($this->error) ) { |
|
240 | 240 | return; |
241 | 241 | } |
242 | - if (empty($this->request['gotcha'])) { |
|
242 | + if( empty($this->request['gotcha']) ) { |
|
243 | 243 | return; |
244 | 244 | } |
245 | - $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
245 | + $this->setError( __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ), |
|
246 | 246 | 'The Honeypot caught a bad submission:' |
247 | 247 | ); |
248 | 248 | } |
@@ -252,13 +252,13 @@ discard block |
||
252 | 252 | */ |
253 | 253 | protected function validateReviewLimits() |
254 | 254 | { |
255 | - if (!empty($this->error)) { |
|
255 | + if( !empty($this->error) ) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | - if (!glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
258 | + if( !glsr( ReviewLimits::class )->hasReachedLimit( $this->request ) ) { |
|
259 | 259 | return; |
260 | 260 | } |
261 | - $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
261 | + $this->setError( __( 'You have already submitted a review.', 'site-reviews' ) ); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -266,35 +266,35 @@ discard block |
||
266 | 266 | */ |
267 | 267 | protected function validateRecaptcha() |
268 | 268 | { |
269 | - if (!empty($this->error)) { |
|
269 | + if( !empty($this->error) ) { |
|
270 | 270 | return; |
271 | 271 | } |
272 | 272 | $status = $this->getRecaptchaStatus(); |
273 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
273 | + if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ) ) { |
|
274 | 274 | return; |
275 | 275 | } |
276 | - if (static::RECAPTCHA_EMPTY === $status) { |
|
277 | - $this->setSessionValues('recaptcha', 'unset'); |
|
276 | + if( static::RECAPTCHA_EMPTY === $status ) { |
|
277 | + $this->setSessionValues( 'recaptcha', 'unset' ); |
|
278 | 278 | $this->recaptchaIsUnset = true; |
279 | 279 | return; |
280 | 280 | } |
281 | - $this->setSessionValues('recaptcha', 'reset'); |
|
281 | + $this->setSessionValues( 'recaptcha', 'reset' ); |
|
282 | 282 | $errors = [ |
283 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
284 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
283 | + static::RECAPTCHA_FAILED => __( 'The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews' ), |
|
284 | + static::RECAPTCHA_INVALID => __( 'The reCAPTCHA verification failed, please try again.', 'site-reviews' ), |
|
285 | 285 | ]; |
286 | - $this->setError($errors[$status]); |
|
286 | + $this->setError( $errors[$status] ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
290 | 290 | * @return array |
291 | 291 | */ |
292 | - protected function validateRequest(array $request) |
|
292 | + protected function validateRequest( array $request ) |
|
293 | 293 | { |
294 | - if (!$this->isRequestValid($request)) { |
|
295 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
294 | + if( !$this->isRequestValid( $request ) ) { |
|
295 | + $this->error = __( 'Please fix the submission errors.', 'site-reviews' ); |
|
296 | 296 | return $request; |
297 | 297 | } |
298 | - return array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request); |
|
298 | + return array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request ); |
|
299 | 299 | } |
300 | 300 | } |
@@ -12,370 +12,370 @@ |
||
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 = ini_get('display_errors') |
|
135 | - ? 'On ('.ini_get('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' => ini_get('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' => ini_get('max_execution_time'), |
|
148 | - 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
149 | - 'Max Input Vars' => ini_get('max_input_vars'), |
|
150 | - 'Memory Limit' => ini_get('memory_limit'), |
|
151 | - 'Post Max Size' => ini_get('post_max_size'), |
|
152 | - 'Sendmail Path' => ini_get('sendmail_path'), |
|
153 | - 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
154 | - 'Session Name' => esc_html(ini_get('session.name')), |
|
155 | - 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
156 | - 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
157 | - 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
158 | - 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
159 | - ]; |
|
160 | - } |
|
129 | + /** |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public function getPhpDetails() |
|
133 | + { |
|
134 | + $displayErrors = ini_get('display_errors') |
|
135 | + ? 'On ('.ini_get('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' => ini_get('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' => ini_get('max_execution_time'), |
|
148 | + 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
149 | + 'Max Input Vars' => ini_get('max_input_vars'), |
|
150 | + 'Memory Limit' => ini_get('memory_limit'), |
|
151 | + 'Post Max Size' => ini_get('post_max_size'), |
|
152 | + 'Sendmail Path' => ini_get('sendmail_path'), |
|
153 | + 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
154 | + 'Session Name' => esc_html(ini_get('session.name')), |
|
155 | + 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
156 | + 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
157 | + 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
158 | + 'Upload Max Filesize' => ini_get('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 | - glsr_log() |
|
172 | - ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
173 | - ->debug($ratings) |
|
174 | - ->debug($counts); |
|
175 | - return; |
|
176 | - } |
|
177 | - $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
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 | + glsr_log() |
|
172 | + ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
173 | + ->debug($ratings) |
|
174 | + ->debug($counts); |
|
175 | + return; |
|
176 | + } |
|
177 | + $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
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', ini_get('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', ini_get('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 | - /** |
|
306 | - * @return array |
|
307 | - */ |
|
308 | - protected function getWordpressPlugins() |
|
309 | - { |
|
310 | - $plugins = get_plugins(); |
|
311 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
312 | - $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
313 | - $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
314 | - return $active + $inactive; |
|
315 | - } |
|
305 | + /** |
|
306 | + * @return array |
|
307 | + */ |
|
308 | + protected function getWordpressPlugins() |
|
309 | + { |
|
310 | + $plugins = get_plugins(); |
|
311 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
312 | + $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
313 | + $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
314 | + return $active + $inactive; |
|
315 | + } |
|
316 | 316 | |
317 | - /** |
|
318 | - * @param string $title |
|
319 | - * @return string |
|
320 | - */ |
|
321 | - protected function implode($title, array $details) |
|
322 | - { |
|
323 | - $strings = ['['.$title.']']; |
|
324 | - $padding = max(array_map('strlen', array_keys($details))); |
|
325 | - $padding = max([$padding, static::PAD]); |
|
326 | - foreach ($details as $key => $value) { |
|
327 | - $strings[] = is_string($key) |
|
328 | - ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
329 | - : ' - '.$value; |
|
330 | - } |
|
331 | - return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
332 | - } |
|
317 | + /** |
|
318 | + * @param string $title |
|
319 | + * @return string |
|
320 | + */ |
|
321 | + protected function implode($title, array $details) |
|
322 | + { |
|
323 | + $strings = ['['.$title.']']; |
|
324 | + $padding = max(array_map('strlen', array_keys($details))); |
|
325 | + $padding = max([$padding, static::PAD]); |
|
326 | + foreach ($details as $key => $value) { |
|
327 | + $strings[] = is_string($key) |
|
328 | + ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
329 | + : ' - '.$value; |
|
330 | + } |
|
331 | + return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
332 | + } |
|
333 | 333 | |
334 | - /** |
|
335 | - * @param string $key |
|
336 | - * @return bool |
|
337 | - */ |
|
338 | - protected function isWebhostCheckValid($key) |
|
339 | - { |
|
340 | - return defined($key) |
|
341 | - || filter_input(INPUT_SERVER, $key) |
|
342 | - || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
343 | - || false !== strpos(DB_HOST, $key) |
|
344 | - || false !== strpos(php_uname(), $key); |
|
345 | - } |
|
334 | + /** |
|
335 | + * @param string $key |
|
336 | + * @return bool |
|
337 | + */ |
|
338 | + protected function isWebhostCheckValid($key) |
|
339 | + { |
|
340 | + return defined($key) |
|
341 | + || filter_input(INPUT_SERVER, $key) |
|
342 | + || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
343 | + || false !== strpos(DB_HOST, $key) |
|
344 | + || false !== strpos(php_uname(), $key); |
|
345 | + } |
|
346 | 346 | |
347 | - /** |
|
348 | - * @return array |
|
349 | - */ |
|
350 | - protected function normalizePluginList(array $plugins) |
|
351 | - { |
|
352 | - $plugins = array_map(function ($plugin) { |
|
353 | - return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version')); |
|
354 | - }, $plugins); |
|
355 | - natcasesort($plugins); |
|
356 | - return array_flip($plugins); |
|
357 | - } |
|
347 | + /** |
|
348 | + * @return array |
|
349 | + */ |
|
350 | + protected function normalizePluginList(array $plugins) |
|
351 | + { |
|
352 | + $plugins = array_map(function ($plugin) { |
|
353 | + return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version')); |
|
354 | + }, $plugins); |
|
355 | + natcasesort($plugins); |
|
356 | + return array_flip($plugins); |
|
357 | + } |
|
358 | 358 | |
359 | - /** |
|
360 | - * @return array |
|
361 | - */ |
|
362 | - protected function purgeSensitiveData(array $settings) |
|
363 | - { |
|
364 | - $keys = [ |
|
365 | - 'general.rebusify_serial', |
|
366 | - 'licenses.', |
|
367 | - 'submissions.recaptcha.key', |
|
368 | - 'submissions.recaptcha.secret', |
|
369 | - ]; |
|
370 | - array_walk($settings, function (&$value, $setting) use ($keys) { |
|
371 | - foreach ($keys as $key) { |
|
372 | - if (!Str::startsWith($key, $setting) || empty($value)) { |
|
373 | - continue; |
|
374 | - } |
|
375 | - $value = str_repeat('•', 13); |
|
376 | - return; |
|
377 | - } |
|
378 | - }); |
|
379 | - return $settings; |
|
380 | - } |
|
359 | + /** |
|
360 | + * @return array |
|
361 | + */ |
|
362 | + protected function purgeSensitiveData(array $settings) |
|
363 | + { |
|
364 | + $keys = [ |
|
365 | + 'general.rebusify_serial', |
|
366 | + 'licenses.', |
|
367 | + 'submissions.recaptcha.key', |
|
368 | + 'submissions.recaptcha.secret', |
|
369 | + ]; |
|
370 | + array_walk($settings, function (&$value, $setting) use ($keys) { |
|
371 | + foreach ($keys as $key) { |
|
372 | + if (!Str::startsWith($key, $setting) || empty($value)) { |
|
373 | + continue; |
|
374 | + } |
|
375 | + $value = str_repeat('•', 13); |
|
376 | + return; |
|
377 | + } |
|
378 | + }); |
|
379 | + return $settings; |
|
380 | + } |
|
381 | 381 | } |
@@ -41,17 +41,17 @@ discard block |
||
41 | 41 | 'setting' => 'Plugin Settings', |
42 | 42 | 'reviews' => 'Review Counts', |
43 | 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()) { |
|
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 | 47 | return $carry.$this->implode( |
48 | - strtoupper($details[$key]), |
|
49 | - apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
48 | + strtoupper( $details[$key] ), |
|
49 | + apply_filters( 'site-reviews/system/'.$key, $systemDetails ) |
|
50 | 50 | ); |
51 | 51 | } |
52 | 52 | return $carry; |
53 | 53 | }); |
54 | - return trim($systemInfo); |
|
54 | + return trim( $systemInfo ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | public function getActivePluginDetails() |
61 | 61 | { |
62 | 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)); |
|
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 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function getAddonDetails() |
72 | 72 | { |
73 | - $details = apply_filters('site-reviews/addon/system-info', []); |
|
74 | - ksort($details); |
|
73 | + $details = apply_filters( 'site-reviews/addon/system-info', [] ); |
|
74 | + ksort( $details ); |
|
75 | 75 | return $details; |
76 | 76 | } |
77 | 77 | |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | public function getBrowserDetails() |
82 | 82 | { |
83 | 83 | $browser = new Browser(); |
84 | - $name = esc_attr($browser->getName()); |
|
85 | - $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
86 | - $version = esc_attr($browser->getVersion()); |
|
84 | + $name = esc_attr( $browser->getName() ); |
|
85 | + $userAgent = esc_attr( $browser->getUserAgent()->getUserAgentString() ); |
|
86 | + $version = esc_attr( $browser->getVersion() ); |
|
87 | 87 | return [ |
88 | - 'Browser Name' => sprintf('%s %s', $name, $version), |
|
88 | + 'Browser Name' => sprintf( '%s %s', $name, $version ), |
|
89 | 89 | 'Browser UA' => $userAgent, |
90 | 90 | ]; |
91 | 91 | } |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function getInactivePluginDetails() |
97 | 97 | { |
98 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
99 | - $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
98 | + $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' ); |
|
99 | + $inactivePlugins = $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ) ) ); |
|
100 | 100 | $multisitePlugins = $this->getMultisitePluginDetails(); |
101 | 101 | return empty($multisitePlugins) |
102 | 102 | ? $inactivePlugins |
103 | - : array_diff($inactivePlugins, $multisitePlugins); |
|
103 | + : array_diff( $inactivePlugins, $multisitePlugins ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function getMuPluginDetails() |
110 | 110 | { |
111 | - if (empty($plugins = get_mu_plugins())) { |
|
111 | + if( empty($plugins = get_mu_plugins()) ) { |
|
112 | 112 | return []; |
113 | 113 | } |
114 | - return $this->normalizePluginList($plugins); |
|
114 | + return $this->normalizePluginList( $plugins ); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function getMultisitePluginDetails() |
121 | 121 | { |
122 | - $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
123 | - if (!is_multisite() || empty($activePlugins)) { |
|
122 | + $activePlugins = (array)get_site_option( 'active_sitewide_plugins', [] ); |
|
123 | + if( !is_multisite() || empty($activePlugins) ) { |
|
124 | 124 | return []; |
125 | 125 | } |
126 | - return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
126 | + return $this->normalizePluginList( array_intersect_key( get_plugins(), $activePlugins ) ); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -131,31 +131,31 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function getPhpDetails() |
133 | 133 | { |
134 | - $displayErrors = ini_get('display_errors') |
|
135 | - ? 'On ('.ini_get('display_errors').')' |
|
134 | + $displayErrors = ini_get( 'display_errors' ) |
|
135 | + ? 'On ('.ini_get( 'display_errors' ).')' |
|
136 | 136 | : 'N/A'; |
137 | - $intlSupport = extension_loaded('intl') |
|
138 | - ? phpversion('intl') |
|
137 | + $intlSupport = extension_loaded( 'intl' ) |
|
138 | + ? phpversion( 'intl' ) |
|
139 | 139 | : 'false'; |
140 | 140 | return [ |
141 | - 'cURL' => var_export(function_exists('curl_init'), true), |
|
142 | - 'Default Charset' => ini_get('default_charset'), |
|
141 | + 'cURL' => var_export( function_exists( 'curl_init' ), true ), |
|
142 | + 'Default Charset' => ini_get( 'default_charset' ), |
|
143 | 143 | 'Display Errors' => $displayErrors, |
144 | - 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
144 | + 'fsockopen' => var_export( function_exists( 'fsockopen' ), true ), |
|
145 | 145 | 'Intl' => $intlSupport, |
146 | - 'IPv6' => var_export(defined('AF_INET6'), true), |
|
147 | - 'Max Execution Time' => ini_get('max_execution_time'), |
|
148 | - 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
149 | - 'Max Input Vars' => ini_get('max_input_vars'), |
|
150 | - 'Memory Limit' => ini_get('memory_limit'), |
|
151 | - 'Post Max Size' => ini_get('post_max_size'), |
|
152 | - 'Sendmail Path' => ini_get('sendmail_path'), |
|
153 | - 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
154 | - 'Session Name' => esc_html(ini_get('session.name')), |
|
155 | - 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
156 | - 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
157 | - 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
158 | - 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
146 | + 'IPv6' => var_export( defined( 'AF_INET6' ), true ), |
|
147 | + 'Max Execution Time' => ini_get( 'max_execution_time' ), |
|
148 | + 'Max Input Nesting Level' => ini_get( 'max_input_nesting_level' ), |
|
149 | + 'Max Input Vars' => ini_get( 'max_input_vars' ), |
|
150 | + 'Memory Limit' => ini_get( 'memory_limit' ), |
|
151 | + 'Post Max Size' => ini_get( 'post_max_size' ), |
|
152 | + 'Sendmail Path' => ini_get( 'sendmail_path' ), |
|
153 | + 'Session Cookie Path' => esc_html( ini_get( 'session.cookie_path' ) ), |
|
154 | + 'Session Name' => esc_html( ini_get( 'session.name' ) ), |
|
155 | + 'Session Save Path' => esc_html( ini_get( 'session.save_path' ) ), |
|
156 | + 'Session Use Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_cookies' ) ), true ), |
|
157 | + 'Session Use Only Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_only_cookies' ) ), true ), |
|
158 | + 'Upload Max Filesize' => ini_get( 'upload_max_filesize' ), |
|
159 | 159 | ]; |
160 | 160 | } |
161 | 161 | |
@@ -164,19 +164,19 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public function getReviewsDetails() |
166 | 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)) { |
|
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 | 171 | glsr_log() |
172 | - ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
173 | - ->debug($ratings) |
|
174 | - ->debug($counts); |
|
172 | + ->error( '$ratings is not an array, possibly due to incorrectly imported reviews.' ) |
|
173 | + ->debug( $ratings ) |
|
174 | + ->debug( $counts ); |
|
175 | 175 | return; |
176 | 176 | } |
177 | - $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
177 | + $ratings = array_sum( $ratings ).' ('.implode( ', ', $ratings ).')'; |
|
178 | 178 | }); |
179 | - ksort($counts); |
|
179 | + ksort( $counts ); |
|
180 | 180 | return $counts; |
181 | 181 | } |
182 | 182 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | 'Host Name' => $this->getHostName(), |
191 | 191 | 'MySQL Version' => $wpdb->db_version(), |
192 | 192 | 'PHP Version' => PHP_VERSION, |
193 | - 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
193 | + 'Server Software' => filter_input( INPUT_SERVER, 'SERVER_SOFTWARE' ), |
|
194 | 194 | ]; |
195 | 195 | } |
196 | 196 | |
@@ -199,16 +199,16 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function getSettingDetails() |
201 | 201 | { |
202 | - $settings = glsr(OptionManager::class)->get('settings', []); |
|
203 | - $settings = Arr::flattenArray($settings, true); |
|
204 | - $settings = $this->purgeSensitiveData($settings); |
|
205 | - ksort($settings); |
|
202 | + $settings = glsr( OptionManager::class )->get( 'settings', [] ); |
|
203 | + $settings = Arr::flattenArray( $settings, true ); |
|
204 | + $settings = $this->purgeSensitiveData( $settings ); |
|
205 | + ksort( $settings ); |
|
206 | 206 | $details = []; |
207 | - foreach ($settings as $key => $value) { |
|
208 | - if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) { |
|
207 | + foreach( $settings as $key => $value ) { |
|
208 | + if( Str::startsWith( 'strings', $key ) && Str::endsWith( 'id', $key ) ) { |
|
209 | 209 | continue; |
210 | 210 | } |
211 | - $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
211 | + $value = htmlspecialchars( trim( preg_replace( '/\s\s+/', '\\n', $value ) ), ENT_QUOTES, 'UTF-8' ); |
|
212 | 212 | $details[$key] = $value; |
213 | 213 | } |
214 | 214 | return $details; |
@@ -220,11 +220,11 @@ discard block |
||
220 | 220 | public function getPluginDetails() |
221 | 221 | { |
222 | 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')), |
|
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 | 226 | 'Version (current)' => glsr()->version, |
227 | - 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
227 | + 'Version (previous)' => glsr( OptionManager::class )->get( 'version_upgraded_from' ), |
|
228 | 228 | ]; |
229 | 229 | } |
230 | 230 | |
@@ -236,23 +236,23 @@ discard block |
||
236 | 236 | global $wpdb; |
237 | 237 | $theme = wp_get_theme(); |
238 | 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), |
|
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 | 241 | 'Home URL' => home_url(), |
242 | 242 | 'Language' => get_locale(), |
243 | 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'), |
|
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 | 251 | 'Site URL' => site_url(), |
252 | - 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('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()), |
|
252 | + 'Timezone' => glsr( OptionManager::class )->getWP( 'timezone_string', ini_get( '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 | 256 | 'WP Memory Limit' => WP_MEMORY_LIMIT, |
257 | 257 | ]; |
258 | 258 | } |
@@ -282,13 +282,13 @@ discard block |
||
282 | 282 | 'secureserver.net' => 'GoDaddy', |
283 | 283 | 'WPE_APIKEY' => 'WP Engine', |
284 | 284 | ]; |
285 | - foreach ($checks as $key => $value) { |
|
286 | - if (!$this->isWebhostCheckValid($key)) { |
|
285 | + foreach( $checks as $key => $value ) { |
|
286 | + if( !$this->isWebhostCheckValid( $key ) ) { |
|
287 | 287 | continue; |
288 | 288 | } |
289 | 289 | return $value; |
290 | 290 | } |
291 | - return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
291 | + return implode( ',', array_filter( [DB_HOST, filter_input( INPUT_SERVER, 'SERVER_NAME' )] ) ); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | */ |
297 | 297 | protected function getHostName() |
298 | 298 | { |
299 | - return sprintf('%s (%s)', |
|
299 | + return sprintf( '%s (%s)', |
|
300 | 300 | $this->detectWebhostProvider(), |
301 | 301 | Helper::getIpAddress() |
302 | 302 | ); |
@@ -308,9 +308,9 @@ discard block |
||
308 | 308 | protected function getWordpressPlugins() |
309 | 309 | { |
310 | 310 | $plugins = get_plugins(); |
311 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
312 | - $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
313 | - $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
311 | + $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' ); |
|
312 | + $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ) ) ); |
|
313 | + $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
314 | 314 | return $active + $inactive; |
315 | 315 | } |
316 | 316 | |
@@ -318,48 +318,48 @@ discard block |
||
318 | 318 | * @param string $title |
319 | 319 | * @return string |
320 | 320 | */ |
321 | - protected function implode($title, array $details) |
|
321 | + protected function implode( $title, array $details ) |
|
322 | 322 | { |
323 | 323 | $strings = ['['.$title.']']; |
324 | - $padding = max(array_map('strlen', array_keys($details))); |
|
325 | - $padding = max([$padding, static::PAD]); |
|
326 | - foreach ($details as $key => $value) { |
|
327 | - $strings[] = is_string($key) |
|
328 | - ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
324 | + $padding = max( array_map( 'strlen', array_keys( $details ) ) ); |
|
325 | + $padding = max( [$padding, static::PAD] ); |
|
326 | + foreach( $details as $key => $value ) { |
|
327 | + $strings[] = is_string( $key ) |
|
328 | + ? sprintf( '%s : %s', str_pad( $key, $padding, '.' ), $value ) |
|
329 | 329 | : ' - '.$value; |
330 | 330 | } |
331 | - return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
331 | + return implode( PHP_EOL, $strings ).PHP_EOL.PHP_EOL; |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
335 | 335 | * @param string $key |
336 | 336 | * @return bool |
337 | 337 | */ |
338 | - protected function isWebhostCheckValid($key) |
|
338 | + protected function isWebhostCheckValid( $key ) |
|
339 | 339 | { |
340 | - return defined($key) |
|
341 | - || filter_input(INPUT_SERVER, $key) |
|
342 | - || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
343 | - || false !== strpos(DB_HOST, $key) |
|
344 | - || false !== strpos(php_uname(), $key); |
|
340 | + return defined( $key ) |
|
341 | + || filter_input( INPUT_SERVER, $key ) |
|
342 | + || false !== strpos( filter_input( INPUT_SERVER, 'SERVER_NAME' ), $key ) |
|
343 | + || false !== strpos( DB_HOST, $key ) |
|
344 | + || false !== strpos( php_uname(), $key ); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
348 | 348 | * @return array |
349 | 349 | */ |
350 | - protected function normalizePluginList(array $plugins) |
|
350 | + protected function normalizePluginList( array $plugins ) |
|
351 | 351 | { |
352 | - $plugins = array_map(function ($plugin) { |
|
353 | - return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version')); |
|
354 | - }, $plugins); |
|
355 | - natcasesort($plugins); |
|
356 | - return array_flip($plugins); |
|
352 | + $plugins = array_map( function( $plugin ) { |
|
353 | + return sprintf( '%s v%s', Arr::get( $plugin, 'Name' ), Arr::get( $plugin, 'Version' ) ); |
|
354 | + }, $plugins ); |
|
355 | + natcasesort( $plugins ); |
|
356 | + return array_flip( $plugins ); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
360 | 360 | * @return array |
361 | 361 | */ |
362 | - protected function purgeSensitiveData(array $settings) |
|
362 | + protected function purgeSensitiveData( array $settings ) |
|
363 | 363 | { |
364 | 364 | $keys = [ |
365 | 365 | 'general.rebusify_serial', |
@@ -367,12 +367,12 @@ discard block |
||
367 | 367 | 'submissions.recaptcha.key', |
368 | 368 | 'submissions.recaptcha.secret', |
369 | 369 | ]; |
370 | - array_walk($settings, function (&$value, $setting) use ($keys) { |
|
371 | - foreach ($keys as $key) { |
|
372 | - if (!Str::startsWith($key, $setting) || empty($value)) { |
|
370 | + array_walk( $settings, function( &$value, $setting ) use ($keys) { |
|
371 | + foreach( $keys as $key ) { |
|
372 | + if( !Str::startsWith( $key, $setting ) || empty($value) ) { |
|
373 | 373 | continue; |
374 | 374 | } |
375 | - $value = str_repeat('•', 13); |
|
375 | + $value = str_repeat( '•', 13 ); |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | }); |
@@ -13,248 +13,248 @@ |
||
13 | 13 | |
14 | 14 | abstract class BaseType implements ArrayAccess, JsonSerializable, Type |
15 | 15 | { |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $allowed = []; |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $allowed = []; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - public $parents = []; |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + public $parents = []; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $properties = []; |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $properties = []; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $type; |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $type; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $method |
|
38 | - * @return static |
|
39 | - */ |
|
40 | - public function __call($method, array $arguments) |
|
41 | - { |
|
42 | - return $this->setProperty($method, Arr::get($arguments, 0)); |
|
43 | - } |
|
36 | + /** |
|
37 | + * @param string $method |
|
38 | + * @return static |
|
39 | + */ |
|
40 | + public function __call($method, array $arguments) |
|
41 | + { |
|
42 | + return $this->setProperty($method, Arr::get($arguments, 0)); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $type |
|
47 | - */ |
|
48 | - public function __construct($type = null) |
|
49 | - { |
|
50 | - $this->type = !is_string($type) |
|
51 | - ? (new ReflectionClass($this))->getShortName() |
|
52 | - : $type; |
|
53 | - $this->setAllowedProperties(); |
|
54 | - } |
|
45 | + /** |
|
46 | + * @param string $type |
|
47 | + */ |
|
48 | + public function __construct($type = null) |
|
49 | + { |
|
50 | + $this->type = !is_string($type) |
|
51 | + ? (new ReflectionClass($this))->getShortName() |
|
52 | + : $type; |
|
53 | + $this->setAllowedProperties(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function __toString() |
|
60 | - { |
|
61 | - return $this->toScript(); |
|
62 | - } |
|
56 | + /** |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function __toString() |
|
60 | + { |
|
61 | + return $this->toScript(); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return static |
|
66 | - */ |
|
67 | - public function addProperties(array $properties) |
|
68 | - { |
|
69 | - foreach ($properties as $property => $value) { |
|
70 | - $this->setProperty($property, $value); |
|
71 | - } |
|
72 | - return $this; |
|
73 | - } |
|
64 | + /** |
|
65 | + * @return static |
|
66 | + */ |
|
67 | + public function addProperties(array $properties) |
|
68 | + { |
|
69 | + foreach ($properties as $property => $value) { |
|
70 | + $this->setProperty($property, $value); |
|
71 | + } |
|
72 | + return $this; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function getContext() |
|
79 | - { |
|
80 | - return 'https://schema.org'; |
|
81 | - } |
|
75 | + /** |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function getContext() |
|
79 | + { |
|
80 | + return 'https://schema.org'; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - public function getProperties() |
|
87 | - { |
|
88 | - return $this->properties; |
|
89 | - } |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + public function getProperties() |
|
87 | + { |
|
88 | + return $this->properties; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string $property |
|
93 | - * @param mixed $default |
|
94 | - * @return mixed |
|
95 | - */ |
|
96 | - public function getProperty($property, $default = null) |
|
97 | - { |
|
98 | - return Arr::get($this->properties, $property, $default); |
|
99 | - } |
|
91 | + /** |
|
92 | + * @param string $property |
|
93 | + * @param mixed $default |
|
94 | + * @return mixed |
|
95 | + */ |
|
96 | + public function getProperty($property, $default = null) |
|
97 | + { |
|
98 | + return Arr::get($this->properties, $property, $default); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public function getType() |
|
105 | - { |
|
106 | - return $this->type; |
|
107 | - } |
|
101 | + /** |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public function getType() |
|
105 | + { |
|
106 | + return $this->type; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param bool $condition |
|
111 | - * @param mixed $callback |
|
112 | - * @return static |
|
113 | - */ |
|
114 | - public function doIf($condition, $callback) |
|
115 | - { |
|
116 | - if ($condition) { |
|
117 | - $callback($this); |
|
118 | - } |
|
119 | - return $this; |
|
120 | - } |
|
109 | + /** |
|
110 | + * @param bool $condition |
|
111 | + * @param mixed $callback |
|
112 | + * @return static |
|
113 | + */ |
|
114 | + public function doIf($condition, $callback) |
|
115 | + { |
|
116 | + if ($condition) { |
|
117 | + $callback($this); |
|
118 | + } |
|
119 | + return $this; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function jsonSerialize() |
|
126 | - { |
|
127 | - return $this->toArray(); |
|
128 | - } |
|
122 | + /** |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function jsonSerialize() |
|
126 | + { |
|
127 | + return $this->toArray(); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @param mixed $offset |
|
132 | - * @return bool |
|
133 | - */ |
|
134 | - public function offsetExists($offset) |
|
135 | - { |
|
136 | - return array_key_exists($offset, $this->properties); |
|
137 | - } |
|
130 | + /** |
|
131 | + * @param mixed $offset |
|
132 | + * @return bool |
|
133 | + */ |
|
134 | + public function offsetExists($offset) |
|
135 | + { |
|
136 | + return array_key_exists($offset, $this->properties); |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param string $offset |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function offsetGet($offset) |
|
144 | - { |
|
145 | - return $this->getProperty($offset); |
|
146 | - } |
|
139 | + /** |
|
140 | + * @param string $offset |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function offsetGet($offset) |
|
144 | + { |
|
145 | + return $this->getProperty($offset); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * @param string $offset |
|
150 | - * @param mixed $value |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - public function offsetSet($offset, $value) |
|
154 | - { |
|
155 | - $this->setProperty($offset, $value); |
|
156 | - } |
|
148 | + /** |
|
149 | + * @param string $offset |
|
150 | + * @param mixed $value |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + public function offsetSet($offset, $value) |
|
154 | + { |
|
155 | + $this->setProperty($offset, $value); |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * @param string $offset |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - public function offsetUnset($offset) |
|
163 | - { |
|
164 | - unset($this->properties[$offset]); |
|
165 | - } |
|
158 | + /** |
|
159 | + * @param string $offset |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + public function offsetUnset($offset) |
|
163 | + { |
|
164 | + unset($this->properties[$offset]); |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @param string $property |
|
169 | - * @param mixed $value |
|
170 | - * @return static |
|
171 | - */ |
|
172 | - public function setProperty($property, $value) |
|
173 | - { |
|
174 | - if (!in_array($property, $this->allowed) |
|
175 | - && 'UnknownType' != (new ReflectionClass($this))->getShortName()) { |
|
176 | - glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property'); |
|
177 | - return $this; |
|
178 | - } |
|
179 | - $this->properties[$property] = $value; |
|
180 | - return $this; |
|
181 | - } |
|
167 | + /** |
|
168 | + * @param string $property |
|
169 | + * @param mixed $value |
|
170 | + * @return static |
|
171 | + */ |
|
172 | + public function setProperty($property, $value) |
|
173 | + { |
|
174 | + if (!in_array($property, $this->allowed) |
|
175 | + && 'UnknownType' != (new ReflectionClass($this))->getShortName()) { |
|
176 | + glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property'); |
|
177 | + return $this; |
|
178 | + } |
|
179 | + $this->properties[$property] = $value; |
|
180 | + return $this; |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - public function toArray() |
|
187 | - { |
|
188 | - return [ |
|
189 | - '@context' => $this->getContext(), |
|
190 | - '@type' => $this->getType(), |
|
191 | - ] + $this->serializeProperty($this->getProperties()); |
|
192 | - } |
|
183 | + /** |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + public function toArray() |
|
187 | + { |
|
188 | + return [ |
|
189 | + '@context' => $this->getContext(), |
|
190 | + '@type' => $this->getType(), |
|
191 | + ] + $this->serializeProperty($this->getProperties()); |
|
192 | + } |
|
193 | 193 | |
194 | - /** |
|
195 | - * @return string |
|
196 | - */ |
|
197 | - public function toScript() |
|
198 | - { |
|
199 | - return sprintf('<script type="application/ld+json">%s</script>', |
|
200 | - json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) |
|
201 | - ); |
|
202 | - } |
|
194 | + /** |
|
195 | + * @return string |
|
196 | + */ |
|
197 | + public function toScript() |
|
198 | + { |
|
199 | + return sprintf('<script type="application/ld+json">%s</script>', |
|
200 | + json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) |
|
201 | + ); |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * @param array|null $parents |
|
206 | - * @return array |
|
207 | - */ |
|
208 | - protected function getParents($parents = null) |
|
209 | - { |
|
210 | - if (!isset($parents)) { |
|
211 | - $parents = $this->parents; |
|
212 | - } |
|
213 | - $newParents = $parents; |
|
214 | - foreach ($parents as $parent) { |
|
215 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
216 | - if (!class_exists($parentClass)) { |
|
217 | - continue; |
|
218 | - } |
|
219 | - $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents)); |
|
220 | - } |
|
221 | - return array_values(array_unique($newParents)); |
|
222 | - } |
|
204 | + /** |
|
205 | + * @param array|null $parents |
|
206 | + * @return array |
|
207 | + */ |
|
208 | + protected function getParents($parents = null) |
|
209 | + { |
|
210 | + if (!isset($parents)) { |
|
211 | + $parents = $this->parents; |
|
212 | + } |
|
213 | + $newParents = $parents; |
|
214 | + foreach ($parents as $parent) { |
|
215 | + $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
216 | + if (!class_exists($parentClass)) { |
|
217 | + continue; |
|
218 | + } |
|
219 | + $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents)); |
|
220 | + } |
|
221 | + return array_values(array_unique($newParents)); |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * @return void |
|
226 | - */ |
|
227 | - protected function setAllowedProperties() |
|
228 | - { |
|
229 | - $parents = $this->getParents(); |
|
230 | - foreach ($parents as $parent) { |
|
231 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
232 | - if (!class_exists($parentClass)) { |
|
233 | - continue; |
|
234 | - } |
|
235 | - $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed))); |
|
236 | - } |
|
237 | - } |
|
224 | + /** |
|
225 | + * @return void |
|
226 | + */ |
|
227 | + protected function setAllowedProperties() |
|
228 | + { |
|
229 | + $parents = $this->getParents(); |
|
230 | + foreach ($parents as $parent) { |
|
231 | + $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
232 | + if (!class_exists($parentClass)) { |
|
233 | + continue; |
|
234 | + } |
|
235 | + $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed))); |
|
236 | + } |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * @param mixed $property |
|
241 | - * @return array|string |
|
242 | - */ |
|
243 | - protected function serializeProperty($property) |
|
244 | - { |
|
245 | - if (is_array($property)) { |
|
246 | - return array_map([$this, 'serializeProperty'], $property); |
|
247 | - } |
|
248 | - if ($property instanceof Type) { |
|
249 | - $property = $property->toArray(); |
|
250 | - unset($property['@context']); |
|
251 | - } |
|
252 | - if ($property instanceof DateTimeInterface) { |
|
253 | - $property = $property->format(DateTime::ATOM); |
|
254 | - } |
|
255 | - if (is_object($property)) { |
|
256 | - throw new InvalidProperty(); |
|
257 | - } |
|
258 | - return $property; |
|
259 | - } |
|
239 | + /** |
|
240 | + * @param mixed $property |
|
241 | + * @return array|string |
|
242 | + */ |
|
243 | + protected function serializeProperty($property) |
|
244 | + { |
|
245 | + if (is_array($property)) { |
|
246 | + return array_map([$this, 'serializeProperty'], $property); |
|
247 | + } |
|
248 | + if ($property instanceof Type) { |
|
249 | + $property = $property->toArray(); |
|
250 | + unset($property['@context']); |
|
251 | + } |
|
252 | + if ($property instanceof DateTimeInterface) { |
|
253 | + $property = $property->format(DateTime::ATOM); |
|
254 | + } |
|
255 | + if (is_object($property)) { |
|
256 | + throw new InvalidProperty(); |
|
257 | + } |
|
258 | + return $property; |
|
259 | + } |
|
260 | 260 | } |
@@ -37,18 +37,18 @@ discard block |
||
37 | 37 | * @param string $method |
38 | 38 | * @return static |
39 | 39 | */ |
40 | - public function __call($method, array $arguments) |
|
40 | + public function __call( $method, array $arguments ) |
|
41 | 41 | { |
42 | - return $this->setProperty($method, Arr::get($arguments, 0)); |
|
42 | + return $this->setProperty( $method, Arr::get( $arguments, 0 ) ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @param string $type |
47 | 47 | */ |
48 | - public function __construct($type = null) |
|
48 | + public function __construct( $type = null ) |
|
49 | 49 | { |
50 | - $this->type = !is_string($type) |
|
51 | - ? (new ReflectionClass($this))->getShortName() |
|
50 | + $this->type = !is_string( $type ) |
|
51 | + ? (new ReflectionClass( $this ))->getShortName() |
|
52 | 52 | : $type; |
53 | 53 | $this->setAllowedProperties(); |
54 | 54 | } |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | /** |
65 | 65 | * @return static |
66 | 66 | */ |
67 | - public function addProperties(array $properties) |
|
67 | + public function addProperties( array $properties ) |
|
68 | 68 | { |
69 | - foreach ($properties as $property => $value) { |
|
70 | - $this->setProperty($property, $value); |
|
69 | + foreach( $properties as $property => $value ) { |
|
70 | + $this->setProperty( $property, $value ); |
|
71 | 71 | } |
72 | 72 | return $this; |
73 | 73 | } |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | * @param mixed $default |
94 | 94 | * @return mixed |
95 | 95 | */ |
96 | - public function getProperty($property, $default = null) |
|
96 | + public function getProperty( $property, $default = null ) |
|
97 | 97 | { |
98 | - return Arr::get($this->properties, $property, $default); |
|
98 | + return Arr::get( $this->properties, $property, $default ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | * @param mixed $callback |
112 | 112 | * @return static |
113 | 113 | */ |
114 | - public function doIf($condition, $callback) |
|
114 | + public function doIf( $condition, $callback ) |
|
115 | 115 | { |
116 | - if ($condition) { |
|
117 | - $callback($this); |
|
116 | + if( $condition ) { |
|
117 | + $callback( $this ); |
|
118 | 118 | } |
119 | 119 | return $this; |
120 | 120 | } |
@@ -131,18 +131,18 @@ discard block |
||
131 | 131 | * @param mixed $offset |
132 | 132 | * @return bool |
133 | 133 | */ |
134 | - public function offsetExists($offset) |
|
134 | + public function offsetExists( $offset ) |
|
135 | 135 | { |
136 | - return array_key_exists($offset, $this->properties); |
|
136 | + return array_key_exists( $offset, $this->properties ); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
140 | 140 | * @param string $offset |
141 | 141 | * @return mixed |
142 | 142 | */ |
143 | - public function offsetGet($offset) |
|
143 | + public function offsetGet( $offset ) |
|
144 | 144 | { |
145 | - return $this->getProperty($offset); |
|
145 | + return $this->getProperty( $offset ); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -150,16 +150,16 @@ discard block |
||
150 | 150 | * @param mixed $value |
151 | 151 | * @return void |
152 | 152 | */ |
153 | - public function offsetSet($offset, $value) |
|
153 | + public function offsetSet( $offset, $value ) |
|
154 | 154 | { |
155 | - $this->setProperty($offset, $value); |
|
155 | + $this->setProperty( $offset, $value ); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * @param string $offset |
160 | 160 | * @return void |
161 | 161 | */ |
162 | - public function offsetUnset($offset) |
|
162 | + public function offsetUnset( $offset ) |
|
163 | 163 | { |
164 | 164 | unset($this->properties[$offset]); |
165 | 165 | } |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param mixed $value |
170 | 170 | * @return static |
171 | 171 | */ |
172 | - public function setProperty($property, $value) |
|
172 | + public function setProperty( $property, $value ) |
|
173 | 173 | { |
174 | - if (!in_array($property, $this->allowed) |
|
175 | - && 'UnknownType' != (new ReflectionClass($this))->getShortName()) { |
|
176 | - glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property'); |
|
174 | + if( !in_array( $property, $this->allowed ) |
|
175 | + && 'UnknownType' != (new ReflectionClass( $this ))->getShortName() ) { |
|
176 | + glsr_log()->warning( $this->getType().' does not allow the "'.$property.'" property' ); |
|
177 | 177 | return $this; |
178 | 178 | } |
179 | 179 | $this->properties[$property] = $value; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | return [ |
189 | 189 | '@context' => $this->getContext(), |
190 | 190 | '@type' => $this->getType(), |
191 | - ] + $this->serializeProperty($this->getProperties()); |
|
191 | + ] + $this->serializeProperty( $this->getProperties() ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function toScript() |
198 | 198 | { |
199 | - return sprintf('<script type="application/ld+json">%s</script>', |
|
200 | - json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) |
|
199 | + return sprintf( '<script type="application/ld+json">%s</script>', |
|
200 | + json_encode( $this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) |
|
201 | 201 | ); |
202 | 202 | } |
203 | 203 | |
@@ -205,20 +205,20 @@ discard block |
||
205 | 205 | * @param array|null $parents |
206 | 206 | * @return array |
207 | 207 | */ |
208 | - protected function getParents($parents = null) |
|
208 | + protected function getParents( $parents = null ) |
|
209 | 209 | { |
210 | - if (!isset($parents)) { |
|
210 | + if( !isset($parents) ) { |
|
211 | 211 | $parents = $this->parents; |
212 | 212 | } |
213 | 213 | $newParents = $parents; |
214 | - foreach ($parents as $parent) { |
|
215 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
216 | - if (!class_exists($parentClass)) { |
|
214 | + foreach( $parents as $parent ) { |
|
215 | + $parentClass = Helper::buildClassName( $parent, __NAMESPACE__ ); |
|
216 | + if( !class_exists( $parentClass ) ) { |
|
217 | 217 | continue; |
218 | 218 | } |
219 | - $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents)); |
|
219 | + $newParents = array_merge( $newParents, $this->getParents( (new $parentClass())->parents ) ); |
|
220 | 220 | } |
221 | - return array_values(array_unique($newParents)); |
|
221 | + return array_values( array_unique( $newParents ) ); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | protected function setAllowedProperties() |
228 | 228 | { |
229 | 229 | $parents = $this->getParents(); |
230 | - foreach ($parents as $parent) { |
|
231 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
232 | - if (!class_exists($parentClass)) { |
|
230 | + foreach( $parents as $parent ) { |
|
231 | + $parentClass = Helper::buildClassName( $parent, __NAMESPACE__ ); |
|
232 | + if( !class_exists( $parentClass ) ) { |
|
233 | 233 | continue; |
234 | 234 | } |
235 | - $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed))); |
|
235 | + $this->allowed = array_values( array_unique( array_merge( (new $parentClass())->allowed, $this->allowed ) ) ); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
@@ -240,19 +240,19 @@ discard block |
||
240 | 240 | * @param mixed $property |
241 | 241 | * @return array|string |
242 | 242 | */ |
243 | - protected function serializeProperty($property) |
|
243 | + protected function serializeProperty( $property ) |
|
244 | 244 | { |
245 | - if (is_array($property)) { |
|
246 | - return array_map([$this, 'serializeProperty'], $property); |
|
245 | + if( is_array( $property ) ) { |
|
246 | + return array_map( [$this, 'serializeProperty'], $property ); |
|
247 | 247 | } |
248 | - if ($property instanceof Type) { |
|
248 | + if( $property instanceof Type ) { |
|
249 | 249 | $property = $property->toArray(); |
250 | 250 | unset($property['@context']); |
251 | 251 | } |
252 | - if ($property instanceof DateTimeInterface) { |
|
253 | - $property = $property->format(DateTime::ATOM); |
|
252 | + if( $property instanceof DateTimeInterface ) { |
|
253 | + $property = $property->format( DateTime::ATOM ); |
|
254 | 254 | } |
255 | - if (is_object($property)) { |
|
255 | + if( is_object( $property ) ) { |
|
256 | 256 | throw new InvalidProperty(); |
257 | 257 | } |
258 | 258 | return $property; |
@@ -8,135 +8,135 @@ |
||
8 | 8 | |
9 | 9 | class ReviewsHtml extends ArrayObject |
10 | 10 | { |
11 | - /** |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - public $args; |
|
11 | + /** |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + public $args; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @var int |
|
18 | - */ |
|
19 | - public $max_num_pages; |
|
16 | + /** |
|
17 | + * @var int |
|
18 | + */ |
|
19 | + public $max_num_pages; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public $pagination; |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public $pagination; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - public $reviews; |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + public $reviews; |
|
30 | 30 | |
31 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
32 | - { |
|
33 | - $this->args = $args; |
|
34 | - $this->max_num_pages = $maxPageCount; |
|
35 | - $this->reviews = $reviews; |
|
36 | - $this->pagination = $this->buildPagination(); |
|
37 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
38 | - } |
|
31 | + public function __construct(array $reviews, $maxPageCount, array $args) |
|
32 | + { |
|
33 | + $this->args = $args; |
|
34 | + $this->max_num_pages = $maxPageCount; |
|
35 | + $this->reviews = $reviews; |
|
36 | + $this->pagination = $this->buildPagination(); |
|
37 | + parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function __toString() |
|
44 | - { |
|
45 | - return glsr(Template::class)->build('templates/reviews', [ |
|
46 | - 'args' => $this->args, |
|
47 | - 'context' => [ |
|
48 | - 'assigned_to' => $this->args['assigned_to'], |
|
49 | - 'category' => $this->args['category'], |
|
50 | - 'class' => $this->getClass(), |
|
51 | - 'id' => $this->args['id'], |
|
52 | - 'pagination' => $this->getPagination(), |
|
53 | - 'reviews' => $this->getReviews(), |
|
54 | - ], |
|
55 | - ]); |
|
56 | - } |
|
40 | + /** |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function __toString() |
|
44 | + { |
|
45 | + return glsr(Template::class)->build('templates/reviews', [ |
|
46 | + 'args' => $this->args, |
|
47 | + 'context' => [ |
|
48 | + 'assigned_to' => $this->args['assigned_to'], |
|
49 | + 'category' => $this->args['category'], |
|
50 | + 'class' => $this->getClass(), |
|
51 | + 'id' => $this->args['id'], |
|
52 | + 'pagination' => $this->getPagination(), |
|
53 | + 'reviews' => $this->getReviews(), |
|
54 | + ], |
|
55 | + ]); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getPagination() |
|
62 | - { |
|
63 | - return wp_validate_boolean($this->args['pagination']) |
|
64 | - ? $this->pagination |
|
65 | - : ''; |
|
66 | - } |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getPagination() |
|
62 | + { |
|
63 | + return wp_validate_boolean($this->args['pagination']) |
|
64 | + ? $this->pagination |
|
65 | + : ''; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function getReviews() |
|
72 | - { |
|
73 | - $html = empty($this->reviews) |
|
74 | - ? $this->getReviewsFallback() |
|
75 | - : implode(PHP_EOL, $this->reviews); |
|
76 | - $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
77 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | - return sprintf($wrapper, $html); |
|
79 | - } |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function getReviews() |
|
72 | + { |
|
73 | + $html = empty($this->reviews) |
|
74 | + ? $this->getReviewsFallback() |
|
75 | + : implode(PHP_EOL, $this->reviews); |
|
76 | + $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
77 | + $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | + return sprintf($wrapper, $html); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param mixed $key |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - public function offsetGet($key) |
|
86 | - { |
|
87 | - if ('navigation' == $key) { |
|
88 | - glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
89 | - return $this->pagination; |
|
90 | - } |
|
91 | - if (property_exists($this, $key)) { |
|
92 | - return $this->$key; |
|
93 | - } |
|
94 | - return array_key_exists($key, $this->reviews) |
|
95 | - ? $this->reviews[$key] |
|
96 | - : null; |
|
97 | - } |
|
81 | + /** |
|
82 | + * @param mixed $key |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + public function offsetGet($key) |
|
86 | + { |
|
87 | + if ('navigation' == $key) { |
|
88 | + glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
89 | + return $this->pagination; |
|
90 | + } |
|
91 | + if (property_exists($this, $key)) { |
|
92 | + return $this->$key; |
|
93 | + } |
|
94 | + return array_key_exists($key, $this->reviews) |
|
95 | + ? $this->reviews[$key] |
|
96 | + : null; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - protected function buildPagination() |
|
103 | - { |
|
104 | - $html = glsr(Partial::class)->build('pagination', [ |
|
105 | - 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | - 'current' => Arr::get($this->args, 'paged'), |
|
107 | - 'total' => $this->max_num_pages, |
|
108 | - ]); |
|
109 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
110 | - $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
111 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | - return sprintf($wrapper, $html); |
|
113 | - } |
|
99 | + /** |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + protected function buildPagination() |
|
103 | + { |
|
104 | + $html = glsr(Partial::class)->build('pagination', [ |
|
105 | + 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | + 'current' => Arr::get($this->args, 'paged'), |
|
107 | + 'total' => $this->max_num_pages, |
|
108 | + ]); |
|
109 | + $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
110 | + $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
111 | + $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | + return sprintf($wrapper, $html); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function getClass() |
|
119 | - { |
|
120 | - $defaults = [ |
|
121 | - 'glsr-default', |
|
122 | - ]; |
|
123 | - if ('ajax' == $this->args['pagination']) { |
|
124 | - $defaults[] = 'glsr-ajax-pagination'; |
|
125 | - } |
|
126 | - $classes = explode(' ', $this->args['class']); |
|
127 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | - return implode(' ', $classes); |
|
129 | - } |
|
115 | + /** |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function getClass() |
|
119 | + { |
|
120 | + $defaults = [ |
|
121 | + 'glsr-default', |
|
122 | + ]; |
|
123 | + if ('ajax' == $this->args['pagination']) { |
|
124 | + $defaults[] = 'glsr-ajax-pagination'; |
|
125 | + } |
|
126 | + $classes = explode(' ', $this->args['class']); |
|
127 | + $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | + return implode(' ', $classes); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - protected function getReviewsFallback() |
|
135 | - { |
|
136 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
138 | - } |
|
139 | - $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
140 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
141 | - } |
|
131 | + /** |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + protected function getReviewsFallback() |
|
135 | + { |
|
136 | + if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | + $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
138 | + } |
|
139 | + $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
140 | + return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
141 | + } |
|
142 | 142 | } |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public $reviews; |
30 | 30 | |
31 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
31 | + public function __construct( array $reviews, $maxPageCount, array $args ) |
|
32 | 32 | { |
33 | 33 | $this->args = $args; |
34 | 34 | $this->max_num_pages = $maxPageCount; |
35 | 35 | $this->reviews = $reviews; |
36 | 36 | $this->pagination = $this->buildPagination(); |
37 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
37 | + parent::__construct( $reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function __toString() |
44 | 44 | { |
45 | - return glsr(Template::class)->build('templates/reviews', [ |
|
45 | + return glsr( Template::class )->build( 'templates/reviews', [ |
|
46 | 46 | 'args' => $this->args, |
47 | 47 | 'context' => [ |
48 | 48 | 'assigned_to' => $this->args['assigned_to'], |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | 'pagination' => $this->getPagination(), |
53 | 53 | 'reviews' => $this->getReviews(), |
54 | 54 | ], |
55 | - ]); |
|
55 | + ] ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function getPagination() |
62 | 62 | { |
63 | - return wp_validate_boolean($this->args['pagination']) |
|
63 | + return wp_validate_boolean( $this->args['pagination'] ) |
|
64 | 64 | ? $this->pagination |
65 | 65 | : ''; |
66 | 66 | } |
@@ -72,26 +72,26 @@ discard block |
||
72 | 72 | { |
73 | 73 | $html = empty($this->reviews) |
74 | 74 | ? $this->getReviewsFallback() |
75 | - : implode(PHP_EOL, $this->reviews); |
|
75 | + : implode( PHP_EOL, $this->reviews ); |
|
76 | 76 | $wrapper = '<div class="glsr-reviews">%s</div>'; |
77 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | - return sprintf($wrapper, $html); |
|
77 | + $wrapper = apply_filters( 'site-reviews/reviews/reviews-wrapper', $wrapper ); |
|
78 | + return sprintf( $wrapper, $html ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @param mixed $key |
83 | 83 | * @return mixed |
84 | 84 | */ |
85 | - public function offsetGet($key) |
|
85 | + public function offsetGet( $key ) |
|
86 | 86 | { |
87 | - if ('navigation' == $key) { |
|
87 | + if( 'navigation' == $key ) { |
|
88 | 88 | glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
89 | 89 | return $this->pagination; |
90 | 90 | } |
91 | - if (property_exists($this, $key)) { |
|
91 | + if( property_exists( $this, $key ) ) { |
|
92 | 92 | return $this->$key; |
93 | 93 | } |
94 | - return array_key_exists($key, $this->reviews) |
|
94 | + return array_key_exists( $key, $this->reviews ) |
|
95 | 95 | ? $this->reviews[$key] |
96 | 96 | : null; |
97 | 97 | } |
@@ -101,15 +101,15 @@ discard block |
||
101 | 101 | */ |
102 | 102 | protected function buildPagination() |
103 | 103 | { |
104 | - $html = glsr(Partial::class)->build('pagination', [ |
|
105 | - 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | - 'current' => Arr::get($this->args, 'paged'), |
|
104 | + $html = glsr( Partial::class )->build( 'pagination', [ |
|
105 | + 'baseUrl' => Arr::get( $this->args, 'pagedUrl' ), |
|
106 | + 'current' => Arr::get( $this->args, 'paged' ), |
|
107 | 107 | 'total' => $this->max_num_pages, |
108 | - ]); |
|
109 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
108 | + ] ); |
|
109 | + $html .= sprintf( '<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json'] ); |
|
110 | 110 | $wrapper = '<div class="glsr-pagination">%s</div>'; |
111 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | - return sprintf($wrapper, $html); |
|
111 | + $wrapper = apply_filters( 'site-reviews/reviews/pagination-wrapper', $wrapper ); |
|
112 | + return sprintf( $wrapper, $html ); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | $defaults = [ |
121 | 121 | 'glsr-default', |
122 | 122 | ]; |
123 | - if ('ajax' == $this->args['pagination']) { |
|
123 | + if( 'ajax' == $this->args['pagination'] ) { |
|
124 | 124 | $defaults[] = 'glsr-ajax-pagination'; |
125 | 125 | } |
126 | - $classes = explode(' ', $this->args['class']); |
|
127 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | - return implode(' ', $classes); |
|
126 | + $classes = explode( ' ', $this->args['class'] ); |
|
127 | + $classes = array_unique( array_merge( $defaults, array_filter( $classes ) ) ); |
|
128 | + return implode( ' ', $classes ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function getReviewsFallback() |
135 | 135 | { |
136 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
136 | + if( empty($this->args['fallback']) && glsr( OptionManager::class )->getBool( 'settings.reviews.fallback' ) ) { |
|
137 | + $this->args['fallback'] = __( 'There are no reviews yet. Be the first one to write one.', 'site-reviews' ); |
|
138 | 138 | } |
139 | 139 | $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
140 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
140 | + return apply_filters( 'site-reviews/reviews/fallback', $fallback, $this->args ); |
|
141 | 141 | } |
142 | 142 | } |
@@ -7,73 +7,73 @@ |
||
7 | 7 | |
8 | 8 | abstract class Field |
9 | 9 | { |
10 | - /** |
|
11 | - * @var Builder |
|
12 | - */ |
|
13 | - protected $builder; |
|
10 | + /** |
|
11 | + * @var Builder |
|
12 | + */ |
|
13 | + protected $builder; |
|
14 | 14 | |
15 | - public function __construct(Builder $builder) |
|
16 | - { |
|
17 | - $this->builder = $builder; |
|
18 | - } |
|
15 | + public function __construct(Builder $builder) |
|
16 | + { |
|
17 | + $this->builder = $builder; |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @return string|void |
|
22 | - */ |
|
23 | - public function build() |
|
24 | - { |
|
25 | - glsr_log()->error('Build method is not implemented for '.get_class($this)); |
|
26 | - } |
|
20 | + /** |
|
21 | + * @return string|void |
|
22 | + */ |
|
23 | + public function build() |
|
24 | + { |
|
25 | + glsr_log()->error('Build method is not implemented for '.get_class($this)); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - public static function defaults() |
|
32 | - { |
|
33 | - return []; |
|
34 | - } |
|
28 | + /** |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + public static function defaults() |
|
32 | + { |
|
33 | + return []; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public static function merge(array $args) |
|
40 | - { |
|
41 | - $merged = array_merge( |
|
42 | - wp_parse_args($args, static::defaults()), |
|
43 | - static::required() |
|
44 | - ); |
|
45 | - $merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args)); |
|
46 | - $merged['style'] = implode(';', static::mergedAttribute('style', ';', $args)); |
|
47 | - return $merged; |
|
48 | - } |
|
36 | + /** |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public static function merge(array $args) |
|
40 | + { |
|
41 | + $merged = array_merge( |
|
42 | + wp_parse_args($args, static::defaults()), |
|
43 | + static::required() |
|
44 | + ); |
|
45 | + $merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args)); |
|
46 | + $merged['style'] = implode(';', static::mergedAttribute('style', ';', $args)); |
|
47 | + return $merged; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $delimiter |
|
52 | - * @param string $key |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public static function mergedAttribute($key, $delimiter, array $args) |
|
56 | - { |
|
57 | - return array_filter(array_merge( |
|
58 | - explode($delimiter, Arr::get($args, $key)), |
|
59 | - explode($delimiter, Arr::get(static::defaults(), $key)), |
|
60 | - explode($delimiter, Arr::get(static::required(), $key)) |
|
61 | - )); |
|
62 | - } |
|
50 | + /** |
|
51 | + * @param string $delimiter |
|
52 | + * @param string $key |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public static function mergedAttribute($key, $delimiter, array $args) |
|
56 | + { |
|
57 | + return array_filter(array_merge( |
|
58 | + explode($delimiter, Arr::get($args, $key)), |
|
59 | + explode($delimiter, Arr::get(static::defaults(), $key)), |
|
60 | + explode($delimiter, Arr::get(static::required(), $key)) |
|
61 | + )); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public static function required() |
|
68 | - { |
|
69 | - return []; |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public static function required() |
|
68 | + { |
|
69 | + return []; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - protected function mergeFieldArgs() |
|
76 | - { |
|
77 | - $this->builder->args = static::merge($this->builder->args); |
|
78 | - } |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + protected function mergeFieldArgs() |
|
76 | + { |
|
77 | + $this->builder->args = static::merge($this->builder->args); |
|
78 | + } |
|
79 | 79 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | protected $builder; |
14 | 14 | |
15 | - public function __construct(Builder $builder) |
|
15 | + public function __construct( Builder $builder ) |
|
16 | 16 | { |
17 | 17 | $this->builder = $builder; |
18 | 18 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function build() |
24 | 24 | { |
25 | - glsr_log()->error('Build method is not implemented for '.get_class($this)); |
|
25 | + glsr_log()->error( 'Build method is not implemented for '.get_class( $this ) ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @return array |
38 | 38 | */ |
39 | - public static function merge(array $args) |
|
39 | + public static function merge( array $args ) |
|
40 | 40 | { |
41 | 41 | $merged = array_merge( |
42 | - wp_parse_args($args, static::defaults()), |
|
42 | + wp_parse_args( $args, static::defaults() ), |
|
43 | 43 | static::required() |
44 | 44 | ); |
45 | - $merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args)); |
|
46 | - $merged['style'] = implode(';', static::mergedAttribute('style', ';', $args)); |
|
45 | + $merged['class'] = implode( ' ', static::mergedAttribute( 'class', ' ', $args ) ); |
|
46 | + $merged['style'] = implode( ';', static::mergedAttribute( 'style', ';', $args ) ); |
|
47 | 47 | return $merged; |
48 | 48 | } |
49 | 49 | |
@@ -52,13 +52,13 @@ discard block |
||
52 | 52 | * @param string $key |
53 | 53 | * @return array |
54 | 54 | */ |
55 | - public static function mergedAttribute($key, $delimiter, array $args) |
|
55 | + public static function mergedAttribute( $key, $delimiter, array $args ) |
|
56 | 56 | { |
57 | - return array_filter(array_merge( |
|
58 | - explode($delimiter, Arr::get($args, $key)), |
|
59 | - explode($delimiter, Arr::get(static::defaults(), $key)), |
|
60 | - explode($delimiter, Arr::get(static::required(), $key)) |
|
61 | - )); |
|
57 | + return array_filter( array_merge( |
|
58 | + explode( $delimiter, Arr::get( $args, $key ) ), |
|
59 | + explode( $delimiter, Arr::get( static::defaults(), $key ) ), |
|
60 | + explode( $delimiter, Arr::get( static::required(), $key ) ) |
|
61 | + ) ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -74,6 +74,6 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function mergeFieldArgs() |
76 | 76 | { |
77 | - $this->builder->args = static::merge($this->builder->args); |
|
77 | + $this->builder->args = static::merge( $this->builder->args ); |
|
78 | 78 | } |
79 | 79 | } |