@@ -10,228 +10,228 @@ |
||
10 | 10 | |
11 | 11 | class TranslationController |
12 | 12 | { |
13 | - /** |
|
14 | - * @var Translator |
|
15 | - */ |
|
16 | - public $translator; |
|
17 | - |
|
18 | - public function __construct(Translator $translator) |
|
19 | - { |
|
20 | - $this->translator = $translator; |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * @param array $messages |
|
25 | - * @return array |
|
26 | - * @filter bulk_post_updated_messages |
|
27 | - */ |
|
28 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
29 | - { |
|
30 | - $messages = Arr::consolidateArray($messages); |
|
31 | - $messages[Application::POST_TYPE] = [ |
|
32 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
33 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
34 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
35 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
36 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
37 | - ]; |
|
38 | - return $messages; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @param string $translation |
|
43 | - * @param string $text |
|
44 | - * @param string $domain |
|
45 | - * @return string |
|
46 | - * @filter gettext |
|
47 | - */ |
|
48 | - public function filterGettext($translation, $text, $domain) |
|
49 | - { |
|
50 | - return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string $translation |
|
55 | - * @param string $text |
|
56 | - * @return string |
|
57 | - * @filter site-reviews/gettext/site-reviews |
|
58 | - */ |
|
59 | - public function filterGettextSiteReviews($translation, $text) |
|
60 | - { |
|
61 | - return $this->translator->translate($translation, Application::ID, [ |
|
62 | - 'single' => $text, |
|
63 | - ]); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @param string $translation |
|
68 | - * @param string $text |
|
69 | - * @param string $context |
|
70 | - * @param string $domain |
|
71 | - * @return string |
|
72 | - * @filter gettext_with_context |
|
73 | - */ |
|
74 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
75 | - { |
|
76 | - return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $translation |
|
81 | - * @param string $text |
|
82 | - * @param string $context |
|
83 | - * @return string |
|
84 | - * @filter site-reviews/gettext_with_context/site-reviews |
|
85 | - */ |
|
86 | - public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
87 | - { |
|
88 | - return $this->translator->translate($translation, Application::ID, [ |
|
89 | - 'context' => $context, |
|
90 | - 'single' => $text, |
|
91 | - ]); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @param string $translation |
|
96 | - * @param string $single |
|
97 | - * @param string $plural |
|
98 | - * @param int $number |
|
99 | - * @param string $domain |
|
100 | - * @return string |
|
101 | - * @filter ngettext |
|
102 | - */ |
|
103 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
104 | - { |
|
105 | - return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $translation |
|
110 | - * @param string $single |
|
111 | - * @param string $plural |
|
112 | - * @param int $number |
|
113 | - * @return string |
|
114 | - * @filter site-reviews/ngettext/site-reviews |
|
115 | - */ |
|
116 | - public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
117 | - { |
|
118 | - return $this->translator->translate($translation, Application::ID, [ |
|
119 | - 'number' => $number, |
|
120 | - 'plural' => $plural, |
|
121 | - 'single' => $single, |
|
122 | - ]); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $translation |
|
127 | - * @param string $single |
|
128 | - * @param string $plural |
|
129 | - * @param int $number |
|
130 | - * @param string $context |
|
131 | - * @param string $domain |
|
132 | - * @return string |
|
133 | - * @filter ngettext_with_context |
|
134 | - */ |
|
135 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
136 | - { |
|
137 | - return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param string $translation |
|
142 | - * @param string $single |
|
143 | - * @param string $plural |
|
144 | - * @param int $number |
|
145 | - * @param string $context |
|
146 | - * @return string |
|
147 | - * @filter site-reviews/ngettext_with_context/site-reviews |
|
148 | - */ |
|
149 | - public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
150 | - { |
|
151 | - return $this->translator->translate($translation, Application::ID, [ |
|
152 | - 'context' => $context, |
|
153 | - 'number' => $number, |
|
154 | - 'plural' => $plural, |
|
155 | - 'single' => $single, |
|
156 | - ]); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @param array $postStates |
|
161 | - * @param \WP_Post $post |
|
162 | - * @return array |
|
163 | - * @filter display_post_states |
|
164 | - */ |
|
165 | - public function filterPostStates($postStates, $post) |
|
166 | - { |
|
167 | - $postStates = Arr::consolidateArray($postStates); |
|
168 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
169 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
170 | - } |
|
171 | - return $postStates; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param string $translation |
|
176 | - * @param string $text |
|
177 | - * @return string |
|
178 | - * @filter site-reviews/gettext/default |
|
179 | - * @filter site-reviews/gettext_with_context/default |
|
180 | - */ |
|
181 | - public function filterPostStatusLabels($translation, $text) |
|
182 | - { |
|
183 | - return $this->canModifyTranslation() |
|
184 | - ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
185 | - : $translation; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @param string $translation |
|
190 | - * @param string $single |
|
191 | - * @param string $plural |
|
192 | - * @param int $number |
|
193 | - * @return string |
|
194 | - * @filter site-reviews/ngettext/default |
|
195 | - */ |
|
196 | - public function filterPostStatusText($translation, $single, $plural, $number) |
|
197 | - { |
|
198 | - if ($this->canModifyTranslation()) { |
|
199 | - $strings = [ |
|
200 | - 'Published' => __('Approved', 'site-reviews'), |
|
201 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
202 | - ]; |
|
203 | - foreach ($strings as $search => $replace) { |
|
204 | - if (!Str::contains($single, $search)) { |
|
205 | - continue; |
|
206 | - } |
|
207 | - return $this->translator->getTranslation([ |
|
208 | - 'number' => $number, |
|
209 | - 'plural' => str_replace($search, $replace, $plural), |
|
210 | - 'single' => str_replace($search, $replace, $single), |
|
211 | - ]); |
|
212 | - } |
|
213 | - } |
|
214 | - return $translation; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @return void |
|
219 | - * @action admin_enqueue_scripts |
|
220 | - */ |
|
221 | - public function translatePostStatusLabels() |
|
222 | - { |
|
223 | - if ($this->canModifyTranslation()) { |
|
224 | - glsr(Labels::class)->translatePostStatusLabels(); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @return bool |
|
230 | - */ |
|
231 | - protected function canModifyTranslation() |
|
232 | - { |
|
233 | - $screen = glsr_current_screen(); |
|
234 | - return Application::POST_TYPE == $screen->post_type |
|
235 | - && in_array($screen->base, ['edit', 'post']); |
|
236 | - } |
|
13 | + /** |
|
14 | + * @var Translator |
|
15 | + */ |
|
16 | + public $translator; |
|
17 | + |
|
18 | + public function __construct(Translator $translator) |
|
19 | + { |
|
20 | + $this->translator = $translator; |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * @param array $messages |
|
25 | + * @return array |
|
26 | + * @filter bulk_post_updated_messages |
|
27 | + */ |
|
28 | + public function filterBulkUpdateMessages($messages, array $counts) |
|
29 | + { |
|
30 | + $messages = Arr::consolidateArray($messages); |
|
31 | + $messages[Application::POST_TYPE] = [ |
|
32 | + 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
33 | + 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
34 | + 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
35 | + 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
36 | + 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
37 | + ]; |
|
38 | + return $messages; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @param string $translation |
|
43 | + * @param string $text |
|
44 | + * @param string $domain |
|
45 | + * @return string |
|
46 | + * @filter gettext |
|
47 | + */ |
|
48 | + public function filterGettext($translation, $text, $domain) |
|
49 | + { |
|
50 | + return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string $translation |
|
55 | + * @param string $text |
|
56 | + * @return string |
|
57 | + * @filter site-reviews/gettext/site-reviews |
|
58 | + */ |
|
59 | + public function filterGettextSiteReviews($translation, $text) |
|
60 | + { |
|
61 | + return $this->translator->translate($translation, Application::ID, [ |
|
62 | + 'single' => $text, |
|
63 | + ]); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @param string $translation |
|
68 | + * @param string $text |
|
69 | + * @param string $context |
|
70 | + * @param string $domain |
|
71 | + * @return string |
|
72 | + * @filter gettext_with_context |
|
73 | + */ |
|
74 | + public function filterGettextWithContext($translation, $text, $context, $domain) |
|
75 | + { |
|
76 | + return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $translation |
|
81 | + * @param string $text |
|
82 | + * @param string $context |
|
83 | + * @return string |
|
84 | + * @filter site-reviews/gettext_with_context/site-reviews |
|
85 | + */ |
|
86 | + public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
87 | + { |
|
88 | + return $this->translator->translate($translation, Application::ID, [ |
|
89 | + 'context' => $context, |
|
90 | + 'single' => $text, |
|
91 | + ]); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @param string $translation |
|
96 | + * @param string $single |
|
97 | + * @param string $plural |
|
98 | + * @param int $number |
|
99 | + * @param string $domain |
|
100 | + * @return string |
|
101 | + * @filter ngettext |
|
102 | + */ |
|
103 | + public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
104 | + { |
|
105 | + return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $translation |
|
110 | + * @param string $single |
|
111 | + * @param string $plural |
|
112 | + * @param int $number |
|
113 | + * @return string |
|
114 | + * @filter site-reviews/ngettext/site-reviews |
|
115 | + */ |
|
116 | + public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
117 | + { |
|
118 | + return $this->translator->translate($translation, Application::ID, [ |
|
119 | + 'number' => $number, |
|
120 | + 'plural' => $plural, |
|
121 | + 'single' => $single, |
|
122 | + ]); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $translation |
|
127 | + * @param string $single |
|
128 | + * @param string $plural |
|
129 | + * @param int $number |
|
130 | + * @param string $context |
|
131 | + * @param string $domain |
|
132 | + * @return string |
|
133 | + * @filter ngettext_with_context |
|
134 | + */ |
|
135 | + public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
136 | + { |
|
137 | + return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param string $translation |
|
142 | + * @param string $single |
|
143 | + * @param string $plural |
|
144 | + * @param int $number |
|
145 | + * @param string $context |
|
146 | + * @return string |
|
147 | + * @filter site-reviews/ngettext_with_context/site-reviews |
|
148 | + */ |
|
149 | + public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
150 | + { |
|
151 | + return $this->translator->translate($translation, Application::ID, [ |
|
152 | + 'context' => $context, |
|
153 | + 'number' => $number, |
|
154 | + 'plural' => $plural, |
|
155 | + 'single' => $single, |
|
156 | + ]); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @param array $postStates |
|
161 | + * @param \WP_Post $post |
|
162 | + * @return array |
|
163 | + * @filter display_post_states |
|
164 | + */ |
|
165 | + public function filterPostStates($postStates, $post) |
|
166 | + { |
|
167 | + $postStates = Arr::consolidateArray($postStates); |
|
168 | + if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
169 | + $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
170 | + } |
|
171 | + return $postStates; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param string $translation |
|
176 | + * @param string $text |
|
177 | + * @return string |
|
178 | + * @filter site-reviews/gettext/default |
|
179 | + * @filter site-reviews/gettext_with_context/default |
|
180 | + */ |
|
181 | + public function filterPostStatusLabels($translation, $text) |
|
182 | + { |
|
183 | + return $this->canModifyTranslation() |
|
184 | + ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
185 | + : $translation; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @param string $translation |
|
190 | + * @param string $single |
|
191 | + * @param string $plural |
|
192 | + * @param int $number |
|
193 | + * @return string |
|
194 | + * @filter site-reviews/ngettext/default |
|
195 | + */ |
|
196 | + public function filterPostStatusText($translation, $single, $plural, $number) |
|
197 | + { |
|
198 | + if ($this->canModifyTranslation()) { |
|
199 | + $strings = [ |
|
200 | + 'Published' => __('Approved', 'site-reviews'), |
|
201 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
202 | + ]; |
|
203 | + foreach ($strings as $search => $replace) { |
|
204 | + if (!Str::contains($single, $search)) { |
|
205 | + continue; |
|
206 | + } |
|
207 | + return $this->translator->getTranslation([ |
|
208 | + 'number' => $number, |
|
209 | + 'plural' => str_replace($search, $replace, $plural), |
|
210 | + 'single' => str_replace($search, $replace, $single), |
|
211 | + ]); |
|
212 | + } |
|
213 | + } |
|
214 | + return $translation; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @return void |
|
219 | + * @action admin_enqueue_scripts |
|
220 | + */ |
|
221 | + public function translatePostStatusLabels() |
|
222 | + { |
|
223 | + if ($this->canModifyTranslation()) { |
|
224 | + glsr(Labels::class)->translatePostStatusLabels(); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @return bool |
|
230 | + */ |
|
231 | + protected function canModifyTranslation() |
|
232 | + { |
|
233 | + $screen = glsr_current_screen(); |
|
234 | + return Application::POST_TYPE == $screen->post_type |
|
235 | + && in_array($screen->base, ['edit', 'post']); |
|
236 | + } |
|
237 | 237 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | */ |
16 | 16 | public $translator; |
17 | 17 | |
18 | - public function __construct(Translator $translator) |
|
18 | + public function __construct( Translator $translator ) |
|
19 | 19 | { |
20 | 20 | $this->translator = $translator; |
21 | 21 | } |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | * @return array |
26 | 26 | * @filter bulk_post_updated_messages |
27 | 27 | */ |
28 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
28 | + public function filterBulkUpdateMessages( $messages, array $counts ) |
|
29 | 29 | { |
30 | - $messages = Arr::consolidateArray($messages); |
|
30 | + $messages = Arr::consolidateArray( $messages ); |
|
31 | 31 | $messages[Application::POST_TYPE] = [ |
32 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
33 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
34 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
35 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
36 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
32 | + 'updated' => _n( '%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews' ), |
|
33 | + 'locked' => _n( '%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews' ), |
|
34 | + 'deleted' => _n( '%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews' ), |
|
35 | + 'trashed' => _n( '%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews' ), |
|
36 | + 'untrashed' => _n( '%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews' ), |
|
37 | 37 | ]; |
38 | 38 | return $messages; |
39 | 39 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | * @return string |
46 | 46 | * @filter gettext |
47 | 47 | */ |
48 | - public function filterGettext($translation, $text, $domain) |
|
48 | + public function filterGettext( $translation, $text, $domain ) |
|
49 | 49 | { |
50 | - return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
50 | + return apply_filters( 'site-reviews/gettext/'.$domain, $translation, $text ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | * @return string |
57 | 57 | * @filter site-reviews/gettext/site-reviews |
58 | 58 | */ |
59 | - public function filterGettextSiteReviews($translation, $text) |
|
59 | + public function filterGettextSiteReviews( $translation, $text ) |
|
60 | 60 | { |
61 | - return $this->translator->translate($translation, Application::ID, [ |
|
61 | + return $this->translator->translate( $translation, Application::ID, [ |
|
62 | 62 | 'single' => $text, |
63 | - ]); |
|
63 | + ] ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * @return string |
72 | 72 | * @filter gettext_with_context |
73 | 73 | */ |
74 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
74 | + public function filterGettextWithContext( $translation, $text, $context, $domain ) |
|
75 | 75 | { |
76 | - return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
76 | + return apply_filters( 'site-reviews/gettext_with_context/'.$domain, $translation, $text, $context ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | * @return string |
84 | 84 | * @filter site-reviews/gettext_with_context/site-reviews |
85 | 85 | */ |
86 | - public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
86 | + public function filterGettextWithContextSiteReviews( $translation, $text, $context ) |
|
87 | 87 | { |
88 | - return $this->translator->translate($translation, Application::ID, [ |
|
88 | + return $this->translator->translate( $translation, Application::ID, [ |
|
89 | 89 | 'context' => $context, |
90 | 90 | 'single' => $text, |
91 | - ]); |
|
91 | + ] ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @return string |
101 | 101 | * @filter ngettext |
102 | 102 | */ |
103 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
103 | + public function filterNgettext( $translation, $single, $plural, $number, $domain ) |
|
104 | 104 | { |
105 | - return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
105 | + return apply_filters( 'site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | * @return string |
114 | 114 | * @filter site-reviews/ngettext/site-reviews |
115 | 115 | */ |
116 | - public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
116 | + public function filterNgettextSiteReviews( $translation, $single, $plural, $number ) |
|
117 | 117 | { |
118 | - return $this->translator->translate($translation, Application::ID, [ |
|
118 | + return $this->translator->translate( $translation, Application::ID, [ |
|
119 | 119 | 'number' => $number, |
120 | 120 | 'plural' => $plural, |
121 | 121 | 'single' => $single, |
122 | - ]); |
|
122 | + ] ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @return string |
133 | 133 | * @filter ngettext_with_context |
134 | 134 | */ |
135 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
135 | + public function filterNgettextWithContext( $translation, $single, $plural, $number, $context, $domain ) |
|
136 | 136 | { |
137 | - return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
137 | + return apply_filters( 'site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | * @return string |
147 | 147 | * @filter site-reviews/ngettext_with_context/site-reviews |
148 | 148 | */ |
149 | - public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
149 | + public function filterNgettextWithContextSiteReviews( $translation, $single, $plural, $number, $context ) |
|
150 | 150 | { |
151 | - return $this->translator->translate($translation, Application::ID, [ |
|
151 | + return $this->translator->translate( $translation, Application::ID, [ |
|
152 | 152 | 'context' => $context, |
153 | 153 | 'number' => $number, |
154 | 154 | 'plural' => $plural, |
155 | 155 | 'single' => $single, |
156 | - ]); |
|
156 | + ] ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | * @return array |
163 | 163 | * @filter display_post_states |
164 | 164 | */ |
165 | - public function filterPostStates($postStates, $post) |
|
165 | + public function filterPostStates( $postStates, $post ) |
|
166 | 166 | { |
167 | - $postStates = Arr::consolidateArray($postStates); |
|
168 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
169 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
167 | + $postStates = Arr::consolidateArray( $postStates ); |
|
168 | + if( Application::POST_TYPE == Arr::get( $post, 'post_type' ) && array_key_exists( 'pending', $postStates ) ) { |
|
169 | + $postStates['pending'] = __( 'Unapproved', 'site-reviews' ); |
|
170 | 170 | } |
171 | 171 | return $postStates; |
172 | 172 | } |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * @filter site-reviews/gettext/default |
179 | 179 | * @filter site-reviews/gettext_with_context/default |
180 | 180 | */ |
181 | - public function filterPostStatusLabels($translation, $text) |
|
181 | + public function filterPostStatusLabels( $translation, $text ) |
|
182 | 182 | { |
183 | 183 | return $this->canModifyTranslation() |
184 | - ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
184 | + ? glsr( Labels::class )->filterPostStatusLabels( $translation, $text ) |
|
185 | 185 | : $translation; |
186 | 186 | } |
187 | 187 | |
@@ -193,22 +193,22 @@ discard block |
||
193 | 193 | * @return string |
194 | 194 | * @filter site-reviews/ngettext/default |
195 | 195 | */ |
196 | - public function filterPostStatusText($translation, $single, $plural, $number) |
|
196 | + public function filterPostStatusText( $translation, $single, $plural, $number ) |
|
197 | 197 | { |
198 | - if ($this->canModifyTranslation()) { |
|
198 | + if( $this->canModifyTranslation() ) { |
|
199 | 199 | $strings = [ |
200 | - 'Published' => __('Approved', 'site-reviews'), |
|
201 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
200 | + 'Published' => __( 'Approved', 'site-reviews' ), |
|
201 | + 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
202 | 202 | ]; |
203 | - foreach ($strings as $search => $replace) { |
|
204 | - if (!Str::contains($single, $search)) { |
|
203 | + foreach( $strings as $search => $replace ) { |
|
204 | + if( !Str::contains( $single, $search ) ) { |
|
205 | 205 | continue; |
206 | 206 | } |
207 | - return $this->translator->getTranslation([ |
|
207 | + return $this->translator->getTranslation( [ |
|
208 | 208 | 'number' => $number, |
209 | - 'plural' => str_replace($search, $replace, $plural), |
|
210 | - 'single' => str_replace($search, $replace, $single), |
|
211 | - ]); |
|
209 | + 'plural' => str_replace( $search, $replace, $plural ), |
|
210 | + 'single' => str_replace( $search, $replace, $single ), |
|
211 | + ] ); |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | return $translation; |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public function translatePostStatusLabels() |
222 | 222 | { |
223 | - if ($this->canModifyTranslation()) { |
|
224 | - glsr(Labels::class)->translatePostStatusLabels(); |
|
223 | + if( $this->canModifyTranslation() ) { |
|
224 | + glsr( Labels::class )->translatePostStatusLabels(); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
@@ -232,6 +232,6 @@ discard block |
||
232 | 232 | { |
233 | 233 | $screen = glsr_current_screen(); |
234 | 234 | return Application::POST_TYPE == $screen->post_type |
235 | - && in_array($screen->base, ['edit', 'post']); |
|
235 | + && in_array( $screen->base, ['edit', 'post'] ); |
|
236 | 236 | } |
237 | 237 | } |
@@ -10,437 +10,437 @@ |
||
10 | 10 | |
11 | 11 | class Console |
12 | 12 | { |
13 | - const DEBUG = 0; // Detailed debug information |
|
14 | - const INFO = 1; // Interesting events |
|
15 | - const NOTICE = 2; // Normal but significant events |
|
16 | - const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | - const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | - const CRITICAL = 16; // Critical conditions |
|
19 | - const ALERT = 32; // Action must be taken immediately |
|
20 | - const EMERGENCY = 64; // System is unusable |
|
21 | - |
|
22 | - protected $file; |
|
23 | - protected $log; |
|
24 | - protected $logOnceKey = 'glsr_log_once'; |
|
25 | - |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->file = glsr()->path('console.log'); |
|
29 | - $this->log = file_exists($this->file) |
|
30 | - ? file_get_contents($this->file) |
|
31 | - : ''; |
|
32 | - $this->reset(); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function __toString() |
|
39 | - { |
|
40 | - return $this->get(); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Action must be taken immediately |
|
45 | - * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up. |
|
46 | - * @param mixed $message |
|
47 | - * @param array $context |
|
48 | - * @return static |
|
49 | - */ |
|
50 | - public function alert($message, array $context = []) |
|
51 | - { |
|
52 | - return $this->log(static::ALERT, $message, $context); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function clear() |
|
59 | - { |
|
60 | - $this->log = ''; |
|
61 | - file_put_contents($this->file, $this->log); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Critical conditions |
|
66 | - * Example: Application component unavailable, unexpected exception. |
|
67 | - * @param mixed $message |
|
68 | - * @param array $context |
|
69 | - * @return static |
|
70 | - */ |
|
71 | - public function critical($message, array $context = []) |
|
72 | - { |
|
73 | - return $this->log(static::CRITICAL, $message, $context); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Detailed debug information. |
|
78 | - * @param mixed $message |
|
79 | - * @param array $context |
|
80 | - * @return static |
|
81 | - */ |
|
82 | - public function debug($message, array $context = []) |
|
83 | - { |
|
84 | - return $this->log(static::DEBUG, $message, $context); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * System is unusable. |
|
89 | - * @param mixed $message |
|
90 | - * @param array $context |
|
91 | - * @return static |
|
92 | - */ |
|
93 | - public function emergency($message, array $context = []) |
|
94 | - { |
|
95 | - return $this->log(static::EMERGENCY, $message, $context); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Runtime errors that do not require immediate action but should typically be logged and monitored. |
|
100 | - * @param mixed $message |
|
101 | - * @param array $context |
|
102 | - * @return static |
|
103 | - */ |
|
104 | - public function error($message, array $context = []) |
|
105 | - { |
|
106 | - return $this->log(static::ERROR, $message, $context); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function get() |
|
113 | - { |
|
114 | - return empty($this->log) |
|
115 | - ? __('Console is empty', 'site-reviews') |
|
116 | - : $this->log; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @return int |
|
121 | - */ |
|
122 | - public function getLevel() |
|
123 | - { |
|
124 | - return intval(apply_filters('site-reviews/console/level', static::INFO)); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function getLevels() |
|
131 | - { |
|
132 | - $constants = (new ReflectionClass(__CLASS__))->getConstants(); |
|
133 | - return array_map('strtolower', array_flip($constants)); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function humanLevel() |
|
140 | - { |
|
141 | - $level = $this->getLevel(); |
|
142 | - return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @param string|null $valueIfEmpty |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function humanSize($valueIfEmpty = null) |
|
150 | - { |
|
151 | - $bytes = $this->size(); |
|
152 | - if (empty($bytes) && is_string($valueIfEmpty)) { |
|
153 | - return $valueIfEmpty; |
|
154 | - } |
|
155 | - $exponent = floor(log(max($bytes, 1), 1024)); |
|
156 | - return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Interesting events |
|
161 | - * Example: User logs in, SQL logs. |
|
162 | - * @param mixed $message |
|
163 | - * @param array $context |
|
164 | - * @return static |
|
165 | - */ |
|
166 | - public function info($message, array $context = []) |
|
167 | - { |
|
168 | - return $this->log(static::INFO, $message, $context); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param int $level |
|
173 | - * @param mixed $message |
|
174 | - * @param array $context |
|
175 | - * @param string $backtraceLine |
|
176 | - * @return static |
|
177 | - */ |
|
178 | - public function log($level, $message, $context = [], $backtraceLine = '') |
|
179 | - { |
|
180 | - if (empty($backtraceLine)) { |
|
181 | - $backtraceLine = $this->getBacktraceLine(); |
|
182 | - } |
|
183 | - if ($this->canLogEntry($level, $backtraceLine)) { |
|
184 | - $levelName = Arr::get($this->getLevels(), $level); |
|
185 | - $context = Arr::consolidateArray($context); |
|
186 | - $backtraceLine = $this->normalizeBacktraceLine($backtraceLine); |
|
187 | - $message = $this->interpolate($message, $context); |
|
188 | - $entry = $this->buildLogEntry($levelName, $message, $backtraceLine); |
|
189 | - file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX); |
|
190 | - apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed |
|
191 | - $this->reset(); |
|
192 | - } |
|
193 | - return $this; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @return void |
|
198 | - */ |
|
199 | - public function logOnce() |
|
200 | - { |
|
201 | - $once = Arr::consolidateArray(glsr()->{$this->logOnceKey}); |
|
202 | - $levels = $this->getLevels(); |
|
203 | - foreach ($once as $entry) { |
|
204 | - $levelName = Arr::get($entry, 'level'); |
|
205 | - if (!in_array($levelName, $levels)) { |
|
206 | - continue; |
|
207 | - } |
|
208 | - $level = Arr::get(array_flip($levels), $levelName); |
|
209 | - $message = Arr::get($entry, 'message'); |
|
210 | - $backtraceLine = Arr::get($entry, 'backtrace'); |
|
211 | - $this->log($level, $message, [], $backtraceLine); |
|
212 | - } |
|
213 | - glsr()->{$this->logOnceKey} = []; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Normal but significant events. |
|
218 | - * @param mixed $message |
|
219 | - * @param array $context |
|
220 | - * @return static |
|
221 | - */ |
|
222 | - public function notice($message, array $context = []) |
|
223 | - { |
|
224 | - return $this->log(static::NOTICE, $message, $context); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @param string $levelName |
|
229 | - * @param string $handle |
|
230 | - * @param mixed $data |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - public function once($levelName, $handle, $data) |
|
234 | - { |
|
235 | - $once = Arr::consolidateArray(glsr()->{$this->logOnceKey}); |
|
236 | - $filtered = array_filter($once, function ($entry) use ($levelName, $handle) { |
|
237 | - return Arr::get($entry, 'level') == $levelName |
|
238 | - && Arr::get($entry, 'handle') == $handle; |
|
239 | - }); |
|
240 | - if (!empty($filtered)) { |
|
241 | - return; |
|
242 | - } |
|
243 | - $once[] = [ |
|
244 | - 'backtrace' => $this->getBacktraceLineFromData($data), |
|
245 | - 'handle' => $handle, |
|
246 | - 'level' => $levelName, |
|
247 | - 'message' => '[RECURRING] '.$this->getMessageFromData($data), |
|
248 | - ]; |
|
249 | - glsr()->{$this->logOnceKey} = $once; |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * @return int |
|
254 | - */ |
|
255 | - public function size() |
|
256 | - { |
|
257 | - return file_exists($this->file) |
|
258 | - ? filesize($this->file) |
|
259 | - : 0; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Exceptional occurrences that are not errors |
|
264 | - * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong. |
|
265 | - * @param mixed $message |
|
266 | - * @param array $context |
|
267 | - * @return static |
|
268 | - */ |
|
269 | - public function warning($message, array $context = []) |
|
270 | - { |
|
271 | - return $this->log(static::WARNING, $message, $context); |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * @param array $backtrace |
|
276 | - * @param int $index |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - protected function buildBacktraceLine($backtrace, $index) |
|
280 | - { |
|
281 | - return sprintf('%s:%s', |
|
282 | - Arr::get($backtrace, $index.'.file'), // realpath |
|
283 | - Arr::get($backtrace, $index.'.line') |
|
284 | - ); |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * @param string $levelName |
|
289 | - * @param mixed $message |
|
290 | - * @param string $backtraceLine |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - protected function buildLogEntry($levelName, $message, $backtraceLine = '') |
|
294 | - { |
|
295 | - return sprintf('[%s] %s [%s] %s', |
|
296 | - current_time('mysql'), |
|
297 | - strtoupper($levelName), |
|
298 | - $backtraceLine, |
|
299 | - $message |
|
300 | - ); |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * @param int $level |
|
305 | - * @return bool |
|
306 | - */ |
|
307 | - protected function canLogEntry($level, $backtraceLine) |
|
308 | - { |
|
309 | - $levelExists = array_key_exists($level, $this->getLevels()); |
|
310 | - if (!Str::contains($backtraceLine, glsr()->path())) { |
|
311 | - return $levelExists; // ignore level restriction if triggered outside of the plugin |
|
312 | - } |
|
313 | - return $levelExists && $level >= $this->getLevel(); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * @return void|string |
|
318 | - */ |
|
319 | - protected function getBacktraceLine() |
|
320 | - { |
|
321 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6); |
|
322 | - $search = array_search('glsr_log', glsr_array_column($backtrace, 'function')); |
|
323 | - if (false !== $search) { |
|
324 | - return $this->buildBacktraceLine($backtrace, (int) $search); |
|
325 | - } |
|
326 | - $search = array_search('log', glsr_array_column($backtrace, 'function')); |
|
327 | - if (false !== $search) { |
|
328 | - $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function') |
|
329 | - ? $search + 4 |
|
330 | - : $search + 1; |
|
331 | - return $this->buildBacktraceLine($backtrace, $index); |
|
332 | - } |
|
333 | - return 'Unknown'; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * @param mixed $data |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - protected function getBacktraceLineFromData($data) |
|
341 | - { |
|
342 | - $backtrace = $data instanceof Throwable |
|
343 | - ? $data->getTrace() |
|
344 | - : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
345 | - return $this->buildBacktraceLine($backtrace, 0); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * @param mixed $data |
|
350 | - * @return string |
|
351 | - */ |
|
352 | - protected function getMessageFromData($data) |
|
353 | - { |
|
354 | - return $data instanceof Throwable |
|
355 | - ? $this->normalizeThrowableMessage($data->getMessage()) |
|
356 | - : print_r($data, 1); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Interpolates context values into the message placeholders. |
|
361 | - * @param mixed $message |
|
362 | - * @param array $context |
|
363 | - * @return string |
|
364 | - */ |
|
365 | - protected function interpolate($message, $context = []) |
|
366 | - { |
|
367 | - if ($this->isObjectOrArray($message) || !is_array($context)) { |
|
368 | - return print_r($message, true); |
|
369 | - } |
|
370 | - $replace = []; |
|
371 | - foreach ($context as $key => $value) { |
|
372 | - $replace['{'.$key.'}'] = $this->normalizeValue($value); |
|
373 | - } |
|
374 | - return strtr($message, $replace); |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * @param mixed $value |
|
379 | - * @return bool |
|
380 | - */ |
|
381 | - protected function isObjectOrArray($value) |
|
382 | - { |
|
383 | - return is_object($value) || is_array($value); |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * @param string $backtraceLine |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - protected function normalizeBacktraceLine($backtraceLine) |
|
391 | - { |
|
392 | - $search = [ |
|
393 | - glsr()->path('plugin/'), |
|
394 | - glsr()->path('plugin/', false), |
|
395 | - trailingslashit(glsr()->path()), |
|
396 | - trailingslashit(glsr()->path('', false)), |
|
397 | - WP_CONTENT_DIR, |
|
398 | - ABSPATH, |
|
399 | - ]; |
|
400 | - return str_replace(array_unique($search), '', $backtraceLine); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * @param string $message |
|
405 | - * @return string |
|
406 | - */ |
|
407 | - protected function normalizeThrowableMessage($message) |
|
408 | - { |
|
409 | - $calledIn = strpos($message, ', called in'); |
|
410 | - return false !== $calledIn |
|
411 | - ? substr($message, 0, $calledIn) |
|
412 | - : $message; |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * @param mixed $value |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - protected function normalizeValue($value) |
|
420 | - { |
|
421 | - if ($value instanceof DateTime) { |
|
422 | - $value = $value->format('Y-m-d H:i:s'); |
|
423 | - } elseif ($this->isObjectOrArray($value)) { |
|
424 | - $value = json_encode($value); |
|
425 | - } |
|
426 | - return (string) $value; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * @return void |
|
431 | - */ |
|
432 | - protected function reset() |
|
433 | - { |
|
434 | - if ($this->size() <= pow(1024, 2) / 8) { |
|
435 | - return; |
|
436 | - } |
|
437 | - $this->clear(); |
|
438 | - file_put_contents( |
|
439 | - $this->file, |
|
440 | - $this->buildLogEntry( |
|
441 | - static::NOTICE, |
|
442 | - __('Console was automatically cleared (128 KB maximum size)', 'site-reviews') |
|
443 | - ) |
|
444 | - ); |
|
445 | - } |
|
13 | + const DEBUG = 0; // Detailed debug information |
|
14 | + const INFO = 1; // Interesting events |
|
15 | + const NOTICE = 2; // Normal but significant events |
|
16 | + const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | + const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | + const CRITICAL = 16; // Critical conditions |
|
19 | + const ALERT = 32; // Action must be taken immediately |
|
20 | + const EMERGENCY = 64; // System is unusable |
|
21 | + |
|
22 | + protected $file; |
|
23 | + protected $log; |
|
24 | + protected $logOnceKey = 'glsr_log_once'; |
|
25 | + |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->file = glsr()->path('console.log'); |
|
29 | + $this->log = file_exists($this->file) |
|
30 | + ? file_get_contents($this->file) |
|
31 | + : ''; |
|
32 | + $this->reset(); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function __toString() |
|
39 | + { |
|
40 | + return $this->get(); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Action must be taken immediately |
|
45 | + * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up. |
|
46 | + * @param mixed $message |
|
47 | + * @param array $context |
|
48 | + * @return static |
|
49 | + */ |
|
50 | + public function alert($message, array $context = []) |
|
51 | + { |
|
52 | + return $this->log(static::ALERT, $message, $context); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function clear() |
|
59 | + { |
|
60 | + $this->log = ''; |
|
61 | + file_put_contents($this->file, $this->log); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Critical conditions |
|
66 | + * Example: Application component unavailable, unexpected exception. |
|
67 | + * @param mixed $message |
|
68 | + * @param array $context |
|
69 | + * @return static |
|
70 | + */ |
|
71 | + public function critical($message, array $context = []) |
|
72 | + { |
|
73 | + return $this->log(static::CRITICAL, $message, $context); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Detailed debug information. |
|
78 | + * @param mixed $message |
|
79 | + * @param array $context |
|
80 | + * @return static |
|
81 | + */ |
|
82 | + public function debug($message, array $context = []) |
|
83 | + { |
|
84 | + return $this->log(static::DEBUG, $message, $context); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * System is unusable. |
|
89 | + * @param mixed $message |
|
90 | + * @param array $context |
|
91 | + * @return static |
|
92 | + */ |
|
93 | + public function emergency($message, array $context = []) |
|
94 | + { |
|
95 | + return $this->log(static::EMERGENCY, $message, $context); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Runtime errors that do not require immediate action but should typically be logged and monitored. |
|
100 | + * @param mixed $message |
|
101 | + * @param array $context |
|
102 | + * @return static |
|
103 | + */ |
|
104 | + public function error($message, array $context = []) |
|
105 | + { |
|
106 | + return $this->log(static::ERROR, $message, $context); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function get() |
|
113 | + { |
|
114 | + return empty($this->log) |
|
115 | + ? __('Console is empty', 'site-reviews') |
|
116 | + : $this->log; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @return int |
|
121 | + */ |
|
122 | + public function getLevel() |
|
123 | + { |
|
124 | + return intval(apply_filters('site-reviews/console/level', static::INFO)); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function getLevels() |
|
131 | + { |
|
132 | + $constants = (new ReflectionClass(__CLASS__))->getConstants(); |
|
133 | + return array_map('strtolower', array_flip($constants)); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function humanLevel() |
|
140 | + { |
|
141 | + $level = $this->getLevel(); |
|
142 | + return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @param string|null $valueIfEmpty |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function humanSize($valueIfEmpty = null) |
|
150 | + { |
|
151 | + $bytes = $this->size(); |
|
152 | + if (empty($bytes) && is_string($valueIfEmpty)) { |
|
153 | + return $valueIfEmpty; |
|
154 | + } |
|
155 | + $exponent = floor(log(max($bytes, 1), 1024)); |
|
156 | + return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Interesting events |
|
161 | + * Example: User logs in, SQL logs. |
|
162 | + * @param mixed $message |
|
163 | + * @param array $context |
|
164 | + * @return static |
|
165 | + */ |
|
166 | + public function info($message, array $context = []) |
|
167 | + { |
|
168 | + return $this->log(static::INFO, $message, $context); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param int $level |
|
173 | + * @param mixed $message |
|
174 | + * @param array $context |
|
175 | + * @param string $backtraceLine |
|
176 | + * @return static |
|
177 | + */ |
|
178 | + public function log($level, $message, $context = [], $backtraceLine = '') |
|
179 | + { |
|
180 | + if (empty($backtraceLine)) { |
|
181 | + $backtraceLine = $this->getBacktraceLine(); |
|
182 | + } |
|
183 | + if ($this->canLogEntry($level, $backtraceLine)) { |
|
184 | + $levelName = Arr::get($this->getLevels(), $level); |
|
185 | + $context = Arr::consolidateArray($context); |
|
186 | + $backtraceLine = $this->normalizeBacktraceLine($backtraceLine); |
|
187 | + $message = $this->interpolate($message, $context); |
|
188 | + $entry = $this->buildLogEntry($levelName, $message, $backtraceLine); |
|
189 | + file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX); |
|
190 | + apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed |
|
191 | + $this->reset(); |
|
192 | + } |
|
193 | + return $this; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @return void |
|
198 | + */ |
|
199 | + public function logOnce() |
|
200 | + { |
|
201 | + $once = Arr::consolidateArray(glsr()->{$this->logOnceKey}); |
|
202 | + $levels = $this->getLevels(); |
|
203 | + foreach ($once as $entry) { |
|
204 | + $levelName = Arr::get($entry, 'level'); |
|
205 | + if (!in_array($levelName, $levels)) { |
|
206 | + continue; |
|
207 | + } |
|
208 | + $level = Arr::get(array_flip($levels), $levelName); |
|
209 | + $message = Arr::get($entry, 'message'); |
|
210 | + $backtraceLine = Arr::get($entry, 'backtrace'); |
|
211 | + $this->log($level, $message, [], $backtraceLine); |
|
212 | + } |
|
213 | + glsr()->{$this->logOnceKey} = []; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Normal but significant events. |
|
218 | + * @param mixed $message |
|
219 | + * @param array $context |
|
220 | + * @return static |
|
221 | + */ |
|
222 | + public function notice($message, array $context = []) |
|
223 | + { |
|
224 | + return $this->log(static::NOTICE, $message, $context); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @param string $levelName |
|
229 | + * @param string $handle |
|
230 | + * @param mixed $data |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + public function once($levelName, $handle, $data) |
|
234 | + { |
|
235 | + $once = Arr::consolidateArray(glsr()->{$this->logOnceKey}); |
|
236 | + $filtered = array_filter($once, function ($entry) use ($levelName, $handle) { |
|
237 | + return Arr::get($entry, 'level') == $levelName |
|
238 | + && Arr::get($entry, 'handle') == $handle; |
|
239 | + }); |
|
240 | + if (!empty($filtered)) { |
|
241 | + return; |
|
242 | + } |
|
243 | + $once[] = [ |
|
244 | + 'backtrace' => $this->getBacktraceLineFromData($data), |
|
245 | + 'handle' => $handle, |
|
246 | + 'level' => $levelName, |
|
247 | + 'message' => '[RECURRING] '.$this->getMessageFromData($data), |
|
248 | + ]; |
|
249 | + glsr()->{$this->logOnceKey} = $once; |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * @return int |
|
254 | + */ |
|
255 | + public function size() |
|
256 | + { |
|
257 | + return file_exists($this->file) |
|
258 | + ? filesize($this->file) |
|
259 | + : 0; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Exceptional occurrences that are not errors |
|
264 | + * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong. |
|
265 | + * @param mixed $message |
|
266 | + * @param array $context |
|
267 | + * @return static |
|
268 | + */ |
|
269 | + public function warning($message, array $context = []) |
|
270 | + { |
|
271 | + return $this->log(static::WARNING, $message, $context); |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * @param array $backtrace |
|
276 | + * @param int $index |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + protected function buildBacktraceLine($backtrace, $index) |
|
280 | + { |
|
281 | + return sprintf('%s:%s', |
|
282 | + Arr::get($backtrace, $index.'.file'), // realpath |
|
283 | + Arr::get($backtrace, $index.'.line') |
|
284 | + ); |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * @param string $levelName |
|
289 | + * @param mixed $message |
|
290 | + * @param string $backtraceLine |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + protected function buildLogEntry($levelName, $message, $backtraceLine = '') |
|
294 | + { |
|
295 | + return sprintf('[%s] %s [%s] %s', |
|
296 | + current_time('mysql'), |
|
297 | + strtoupper($levelName), |
|
298 | + $backtraceLine, |
|
299 | + $message |
|
300 | + ); |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * @param int $level |
|
305 | + * @return bool |
|
306 | + */ |
|
307 | + protected function canLogEntry($level, $backtraceLine) |
|
308 | + { |
|
309 | + $levelExists = array_key_exists($level, $this->getLevels()); |
|
310 | + if (!Str::contains($backtraceLine, glsr()->path())) { |
|
311 | + return $levelExists; // ignore level restriction if triggered outside of the plugin |
|
312 | + } |
|
313 | + return $levelExists && $level >= $this->getLevel(); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * @return void|string |
|
318 | + */ |
|
319 | + protected function getBacktraceLine() |
|
320 | + { |
|
321 | + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6); |
|
322 | + $search = array_search('glsr_log', glsr_array_column($backtrace, 'function')); |
|
323 | + if (false !== $search) { |
|
324 | + return $this->buildBacktraceLine($backtrace, (int) $search); |
|
325 | + } |
|
326 | + $search = array_search('log', glsr_array_column($backtrace, 'function')); |
|
327 | + if (false !== $search) { |
|
328 | + $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function') |
|
329 | + ? $search + 4 |
|
330 | + : $search + 1; |
|
331 | + return $this->buildBacktraceLine($backtrace, $index); |
|
332 | + } |
|
333 | + return 'Unknown'; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * @param mixed $data |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + protected function getBacktraceLineFromData($data) |
|
341 | + { |
|
342 | + $backtrace = $data instanceof Throwable |
|
343 | + ? $data->getTrace() |
|
344 | + : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
345 | + return $this->buildBacktraceLine($backtrace, 0); |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * @param mixed $data |
|
350 | + * @return string |
|
351 | + */ |
|
352 | + protected function getMessageFromData($data) |
|
353 | + { |
|
354 | + return $data instanceof Throwable |
|
355 | + ? $this->normalizeThrowableMessage($data->getMessage()) |
|
356 | + : print_r($data, 1); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Interpolates context values into the message placeholders. |
|
361 | + * @param mixed $message |
|
362 | + * @param array $context |
|
363 | + * @return string |
|
364 | + */ |
|
365 | + protected function interpolate($message, $context = []) |
|
366 | + { |
|
367 | + if ($this->isObjectOrArray($message) || !is_array($context)) { |
|
368 | + return print_r($message, true); |
|
369 | + } |
|
370 | + $replace = []; |
|
371 | + foreach ($context as $key => $value) { |
|
372 | + $replace['{'.$key.'}'] = $this->normalizeValue($value); |
|
373 | + } |
|
374 | + return strtr($message, $replace); |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * @param mixed $value |
|
379 | + * @return bool |
|
380 | + */ |
|
381 | + protected function isObjectOrArray($value) |
|
382 | + { |
|
383 | + return is_object($value) || is_array($value); |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * @param string $backtraceLine |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + protected function normalizeBacktraceLine($backtraceLine) |
|
391 | + { |
|
392 | + $search = [ |
|
393 | + glsr()->path('plugin/'), |
|
394 | + glsr()->path('plugin/', false), |
|
395 | + trailingslashit(glsr()->path()), |
|
396 | + trailingslashit(glsr()->path('', false)), |
|
397 | + WP_CONTENT_DIR, |
|
398 | + ABSPATH, |
|
399 | + ]; |
|
400 | + return str_replace(array_unique($search), '', $backtraceLine); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * @param string $message |
|
405 | + * @return string |
|
406 | + */ |
|
407 | + protected function normalizeThrowableMessage($message) |
|
408 | + { |
|
409 | + $calledIn = strpos($message, ', called in'); |
|
410 | + return false !== $calledIn |
|
411 | + ? substr($message, 0, $calledIn) |
|
412 | + : $message; |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * @param mixed $value |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + protected function normalizeValue($value) |
|
420 | + { |
|
421 | + if ($value instanceof DateTime) { |
|
422 | + $value = $value->format('Y-m-d H:i:s'); |
|
423 | + } elseif ($this->isObjectOrArray($value)) { |
|
424 | + $value = json_encode($value); |
|
425 | + } |
|
426 | + return (string) $value; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * @return void |
|
431 | + */ |
|
432 | + protected function reset() |
|
433 | + { |
|
434 | + if ($this->size() <= pow(1024, 2) / 8) { |
|
435 | + return; |
|
436 | + } |
|
437 | + $this->clear(); |
|
438 | + file_put_contents( |
|
439 | + $this->file, |
|
440 | + $this->buildLogEntry( |
|
441 | + static::NOTICE, |
|
442 | + __('Console was automatically cleared (128 KB maximum size)', 'site-reviews') |
|
443 | + ) |
|
444 | + ); |
|
445 | + } |
|
446 | 446 | } |
@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | |
11 | 11 | class Console |
12 | 12 | { |
13 | - const DEBUG = 0; // Detailed debug information |
|
14 | - const INFO = 1; // Interesting events |
|
15 | - const NOTICE = 2; // Normal but significant events |
|
16 | - const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | - const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | - const CRITICAL = 16; // Critical conditions |
|
19 | - const ALERT = 32; // Action must be taken immediately |
|
13 | + const DEBUG = 0; // Detailed debug information |
|
14 | + const INFO = 1; // Interesting events |
|
15 | + const NOTICE = 2; // Normal but significant events |
|
16 | + const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | + const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | + const CRITICAL = 16; // Critical conditions |
|
19 | + const ALERT = 32; // Action must be taken immediately |
|
20 | 20 | const EMERGENCY = 64; // System is unusable |
21 | 21 | |
22 | 22 | protected $file; |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | |
26 | 26 | public function __construct() |
27 | 27 | { |
28 | - $this->file = glsr()->path('console.log'); |
|
29 | - $this->log = file_exists($this->file) |
|
30 | - ? file_get_contents($this->file) |
|
28 | + $this->file = glsr()->path( 'console.log' ); |
|
29 | + $this->log = file_exists( $this->file ) |
|
30 | + ? file_get_contents( $this->file ) |
|
31 | 31 | : ''; |
32 | 32 | $this->reset(); |
33 | 33 | } |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * @param array $context |
48 | 48 | * @return static |
49 | 49 | */ |
50 | - public function alert($message, array $context = []) |
|
50 | + public function alert( $message, array $context = [] ) |
|
51 | 51 | { |
52 | - return $this->log(static::ALERT, $message, $context); |
|
52 | + return $this->log( static::ALERT, $message, $context ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public function clear() |
59 | 59 | { |
60 | 60 | $this->log = ''; |
61 | - file_put_contents($this->file, $this->log); |
|
61 | + file_put_contents( $this->file, $this->log ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * @param array $context |
69 | 69 | * @return static |
70 | 70 | */ |
71 | - public function critical($message, array $context = []) |
|
71 | + public function critical( $message, array $context = [] ) |
|
72 | 72 | { |
73 | - return $this->log(static::CRITICAL, $message, $context); |
|
73 | + return $this->log( static::CRITICAL, $message, $context ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | * @param array $context |
80 | 80 | * @return static |
81 | 81 | */ |
82 | - public function debug($message, array $context = []) |
|
82 | + public function debug( $message, array $context = [] ) |
|
83 | 83 | { |
84 | - return $this->log(static::DEBUG, $message, $context); |
|
84 | + return $this->log( static::DEBUG, $message, $context ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | * @param array $context |
91 | 91 | * @return static |
92 | 92 | */ |
93 | - public function emergency($message, array $context = []) |
|
93 | + public function emergency( $message, array $context = [] ) |
|
94 | 94 | { |
95 | - return $this->log(static::EMERGENCY, $message, $context); |
|
95 | + return $this->log( static::EMERGENCY, $message, $context ); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param array $context |
102 | 102 | * @return static |
103 | 103 | */ |
104 | - public function error($message, array $context = []) |
|
104 | + public function error( $message, array $context = [] ) |
|
105 | 105 | { |
106 | - return $this->log(static::ERROR, $message, $context); |
|
106 | + return $this->log( static::ERROR, $message, $context ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | public function get() |
113 | 113 | { |
114 | 114 | return empty($this->log) |
115 | - ? __('Console is empty', 'site-reviews') |
|
115 | + ? __( 'Console is empty', 'site-reviews' ) |
|
116 | 116 | : $this->log; |
117 | 117 | } |
118 | 118 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function getLevel() |
123 | 123 | { |
124 | - return intval(apply_filters('site-reviews/console/level', static::INFO)); |
|
124 | + return intval( apply_filters( 'site-reviews/console/level', static::INFO ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function getLevels() |
131 | 131 | { |
132 | - $constants = (new ReflectionClass(__CLASS__))->getConstants(); |
|
133 | - return array_map('strtolower', array_flip($constants)); |
|
132 | + $constants = (new ReflectionClass( __CLASS__ ))->getConstants(); |
|
133 | + return array_map( 'strtolower', array_flip( $constants ) ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,21 +139,21 @@ discard block |
||
139 | 139 | public function humanLevel() |
140 | 140 | { |
141 | 141 | $level = $this->getLevel(); |
142 | - return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level); |
|
142 | + return sprintf( '%s (%d)', strtoupper( Arr::get( $this->getLevels(), $level, 'unknown' ) ), $level ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | 146 | * @param string|null $valueIfEmpty |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - public function humanSize($valueIfEmpty = null) |
|
149 | + public function humanSize( $valueIfEmpty = null ) |
|
150 | 150 | { |
151 | 151 | $bytes = $this->size(); |
152 | - if (empty($bytes) && is_string($valueIfEmpty)) { |
|
152 | + if( empty($bytes) && is_string( $valueIfEmpty ) ) { |
|
153 | 153 | return $valueIfEmpty; |
154 | 154 | } |
155 | - $exponent = floor(log(max($bytes, 1), 1024)); |
|
156 | - return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
155 | + $exponent = floor( log( max( $bytes, 1 ), 1024 ) ); |
|
156 | + return round( $bytes / pow( 1024, $exponent ), 2 ).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * @param array $context |
164 | 164 | * @return static |
165 | 165 | */ |
166 | - public function info($message, array $context = []) |
|
166 | + public function info( $message, array $context = [] ) |
|
167 | 167 | { |
168 | - return $this->log(static::INFO, $message, $context); |
|
168 | + return $this->log( static::INFO, $message, $context ); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -175,19 +175,19 @@ discard block |
||
175 | 175 | * @param string $backtraceLine |
176 | 176 | * @return static |
177 | 177 | */ |
178 | - public function log($level, $message, $context = [], $backtraceLine = '') |
|
178 | + public function log( $level, $message, $context = [], $backtraceLine = '' ) |
|
179 | 179 | { |
180 | - if (empty($backtraceLine)) { |
|
180 | + if( empty($backtraceLine) ) { |
|
181 | 181 | $backtraceLine = $this->getBacktraceLine(); |
182 | 182 | } |
183 | - if ($this->canLogEntry($level, $backtraceLine)) { |
|
184 | - $levelName = Arr::get($this->getLevels(), $level); |
|
185 | - $context = Arr::consolidateArray($context); |
|
186 | - $backtraceLine = $this->normalizeBacktraceLine($backtraceLine); |
|
187 | - $message = $this->interpolate($message, $context); |
|
188 | - $entry = $this->buildLogEntry($levelName, $message, $backtraceLine); |
|
189 | - file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX); |
|
190 | - apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed |
|
183 | + if( $this->canLogEntry( $level, $backtraceLine ) ) { |
|
184 | + $levelName = Arr::get( $this->getLevels(), $level ); |
|
185 | + $context = Arr::consolidateArray( $context ); |
|
186 | + $backtraceLine = $this->normalizeBacktraceLine( $backtraceLine ); |
|
187 | + $message = $this->interpolate( $message, $context ); |
|
188 | + $entry = $this->buildLogEntry( $levelName, $message, $backtraceLine ); |
|
189 | + file_put_contents( $this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX ); |
|
190 | + apply_filters( 'console', $message, $levelName, $backtraceLine ); // Show in Blackbar plugin if installed |
|
191 | 191 | $this->reset(); |
192 | 192 | } |
193 | 193 | return $this; |
@@ -198,17 +198,17 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function logOnce() |
200 | 200 | { |
201 | - $once = Arr::consolidateArray(glsr()->{$this->logOnceKey}); |
|
201 | + $once = Arr::consolidateArray( glsr()->{$this->logOnceKey}); |
|
202 | 202 | $levels = $this->getLevels(); |
203 | - foreach ($once as $entry) { |
|
204 | - $levelName = Arr::get($entry, 'level'); |
|
205 | - if (!in_array($levelName, $levels)) { |
|
203 | + foreach( $once as $entry ) { |
|
204 | + $levelName = Arr::get( $entry, 'level' ); |
|
205 | + if( !in_array( $levelName, $levels ) ) { |
|
206 | 206 | continue; |
207 | 207 | } |
208 | - $level = Arr::get(array_flip($levels), $levelName); |
|
209 | - $message = Arr::get($entry, 'message'); |
|
210 | - $backtraceLine = Arr::get($entry, 'backtrace'); |
|
211 | - $this->log($level, $message, [], $backtraceLine); |
|
208 | + $level = Arr::get( array_flip( $levels ), $levelName ); |
|
209 | + $message = Arr::get( $entry, 'message' ); |
|
210 | + $backtraceLine = Arr::get( $entry, 'backtrace' ); |
|
211 | + $this->log( $level, $message, [], $backtraceLine ); |
|
212 | 212 | } |
213 | 213 | glsr()->{$this->logOnceKey} = []; |
214 | 214 | } |
@@ -219,9 +219,9 @@ discard block |
||
219 | 219 | * @param array $context |
220 | 220 | * @return static |
221 | 221 | */ |
222 | - public function notice($message, array $context = []) |
|
222 | + public function notice( $message, array $context = [] ) |
|
223 | 223 | { |
224 | - return $this->log(static::NOTICE, $message, $context); |
|
224 | + return $this->log( static::NOTICE, $message, $context ); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -230,21 +230,21 @@ discard block |
||
230 | 230 | * @param mixed $data |
231 | 231 | * @return void |
232 | 232 | */ |
233 | - public function once($levelName, $handle, $data) |
|
233 | + public function once( $levelName, $handle, $data ) |
|
234 | 234 | { |
235 | - $once = Arr::consolidateArray(glsr()->{$this->logOnceKey}); |
|
236 | - $filtered = array_filter($once, function ($entry) use ($levelName, $handle) { |
|
237 | - return Arr::get($entry, 'level') == $levelName |
|
238 | - && Arr::get($entry, 'handle') == $handle; |
|
235 | + $once = Arr::consolidateArray( glsr()->{$this->logOnceKey}); |
|
236 | + $filtered = array_filter( $once, function( $entry ) use ($levelName, $handle) { |
|
237 | + return Arr::get( $entry, 'level' ) == $levelName |
|
238 | + && Arr::get( $entry, 'handle' ) == $handle; |
|
239 | 239 | }); |
240 | - if (!empty($filtered)) { |
|
240 | + if( !empty($filtered) ) { |
|
241 | 241 | return; |
242 | 242 | } |
243 | 243 | $once[] = [ |
244 | - 'backtrace' => $this->getBacktraceLineFromData($data), |
|
244 | + 'backtrace' => $this->getBacktraceLineFromData( $data ), |
|
245 | 245 | 'handle' => $handle, |
246 | 246 | 'level' => $levelName, |
247 | - 'message' => '[RECURRING] '.$this->getMessageFromData($data), |
|
247 | + 'message' => '[RECURRING] '.$this->getMessageFromData( $data ), |
|
248 | 248 | ]; |
249 | 249 | glsr()->{$this->logOnceKey} = $once; |
250 | 250 | } |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function size() |
256 | 256 | { |
257 | - return file_exists($this->file) |
|
258 | - ? filesize($this->file) |
|
257 | + return file_exists( $this->file ) |
|
258 | + ? filesize( $this->file ) |
|
259 | 259 | : 0; |
260 | 260 | } |
261 | 261 | |
@@ -266,9 +266,9 @@ discard block |
||
266 | 266 | * @param array $context |
267 | 267 | * @return static |
268 | 268 | */ |
269 | - public function warning($message, array $context = []) |
|
269 | + public function warning( $message, array $context = [] ) |
|
270 | 270 | { |
271 | - return $this->log(static::WARNING, $message, $context); |
|
271 | + return $this->log( static::WARNING, $message, $context ); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * @param int $index |
277 | 277 | * @return string |
278 | 278 | */ |
279 | - protected function buildBacktraceLine($backtrace, $index) |
|
279 | + protected function buildBacktraceLine( $backtrace, $index ) |
|
280 | 280 | { |
281 | - return sprintf('%s:%s', |
|
282 | - Arr::get($backtrace, $index.'.file'), // realpath |
|
283 | - Arr::get($backtrace, $index.'.line') |
|
281 | + return sprintf( '%s:%s', |
|
282 | + Arr::get( $backtrace, $index.'.file' ), // realpath |
|
283 | + Arr::get( $backtrace, $index.'.line' ) |
|
284 | 284 | ); |
285 | 285 | } |
286 | 286 | |
@@ -290,11 +290,11 @@ discard block |
||
290 | 290 | * @param string $backtraceLine |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - protected function buildLogEntry($levelName, $message, $backtraceLine = '') |
|
293 | + protected function buildLogEntry( $levelName, $message, $backtraceLine = '' ) |
|
294 | 294 | { |
295 | - return sprintf('[%s] %s [%s] %s', |
|
296 | - current_time('mysql'), |
|
297 | - strtoupper($levelName), |
|
295 | + return sprintf( '[%s] %s [%s] %s', |
|
296 | + current_time( 'mysql' ), |
|
297 | + strtoupper( $levelName ), |
|
298 | 298 | $backtraceLine, |
299 | 299 | $message |
300 | 300 | ); |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | * @param int $level |
305 | 305 | * @return bool |
306 | 306 | */ |
307 | - protected function canLogEntry($level, $backtraceLine) |
|
307 | + protected function canLogEntry( $level, $backtraceLine ) |
|
308 | 308 | { |
309 | - $levelExists = array_key_exists($level, $this->getLevels()); |
|
310 | - if (!Str::contains($backtraceLine, glsr()->path())) { |
|
309 | + $levelExists = array_key_exists( $level, $this->getLevels() ); |
|
310 | + if( !Str::contains( $backtraceLine, glsr()->path() ) ) { |
|
311 | 311 | return $levelExists; // ignore level restriction if triggered outside of the plugin |
312 | 312 | } |
313 | 313 | return $levelExists && $level >= $this->getLevel(); |
@@ -318,17 +318,17 @@ discard block |
||
318 | 318 | */ |
319 | 319 | protected function getBacktraceLine() |
320 | 320 | { |
321 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6); |
|
322 | - $search = array_search('glsr_log', glsr_array_column($backtrace, 'function')); |
|
323 | - if (false !== $search) { |
|
324 | - return $this->buildBacktraceLine($backtrace, (int) $search); |
|
321 | + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 6 ); |
|
322 | + $search = array_search( 'glsr_log', glsr_array_column( $backtrace, 'function' ) ); |
|
323 | + if( false !== $search ) { |
|
324 | + return $this->buildBacktraceLine( $backtrace, (int)$search ); |
|
325 | 325 | } |
326 | - $search = array_search('log', glsr_array_column($backtrace, 'function')); |
|
327 | - if (false !== $search) { |
|
328 | - $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function') |
|
326 | + $search = array_search( 'log', glsr_array_column( $backtrace, 'function' ) ); |
|
327 | + if( false !== $search ) { |
|
328 | + $index = '{closure}' == Arr::get( $backtrace, ($search + 2).'.function' ) |
|
329 | 329 | ? $search + 4 |
330 | 330 | : $search + 1; |
331 | - return $this->buildBacktraceLine($backtrace, $index); |
|
331 | + return $this->buildBacktraceLine( $backtrace, $index ); |
|
332 | 332 | } |
333 | 333 | return 'Unknown'; |
334 | 334 | } |
@@ -337,23 +337,23 @@ discard block |
||
337 | 337 | * @param mixed $data |
338 | 338 | * @return string |
339 | 339 | */ |
340 | - protected function getBacktraceLineFromData($data) |
|
340 | + protected function getBacktraceLineFromData( $data ) |
|
341 | 341 | { |
342 | 342 | $backtrace = $data instanceof Throwable |
343 | 343 | ? $data->getTrace() |
344 | - : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
345 | - return $this->buildBacktraceLine($backtrace, 0); |
|
344 | + : debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1 ); |
|
345 | + return $this->buildBacktraceLine( $backtrace, 0 ); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
349 | 349 | * @param mixed $data |
350 | 350 | * @return string |
351 | 351 | */ |
352 | - protected function getMessageFromData($data) |
|
352 | + protected function getMessageFromData( $data ) |
|
353 | 353 | { |
354 | 354 | return $data instanceof Throwable |
355 | - ? $this->normalizeThrowableMessage($data->getMessage()) |
|
356 | - : print_r($data, 1); |
|
355 | + ? $this->normalizeThrowableMessage( $data->getMessage() ) |
|
356 | + : print_r( $data, 1 ); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -362,53 +362,53 @@ discard block |
||
362 | 362 | * @param array $context |
363 | 363 | * @return string |
364 | 364 | */ |
365 | - protected function interpolate($message, $context = []) |
|
365 | + protected function interpolate( $message, $context = [] ) |
|
366 | 366 | { |
367 | - if ($this->isObjectOrArray($message) || !is_array($context)) { |
|
368 | - return print_r($message, true); |
|
367 | + if( $this->isObjectOrArray( $message ) || !is_array( $context ) ) { |
|
368 | + return print_r( $message, true ); |
|
369 | 369 | } |
370 | 370 | $replace = []; |
371 | - foreach ($context as $key => $value) { |
|
372 | - $replace['{'.$key.'}'] = $this->normalizeValue($value); |
|
371 | + foreach( $context as $key => $value ) { |
|
372 | + $replace['{'.$key.'}'] = $this->normalizeValue( $value ); |
|
373 | 373 | } |
374 | - return strtr($message, $replace); |
|
374 | + return strtr( $message, $replace ); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
378 | 378 | * @param mixed $value |
379 | 379 | * @return bool |
380 | 380 | */ |
381 | - protected function isObjectOrArray($value) |
|
381 | + protected function isObjectOrArray( $value ) |
|
382 | 382 | { |
383 | - return is_object($value) || is_array($value); |
|
383 | + return is_object( $value ) || is_array( $value ); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
387 | 387 | * @param string $backtraceLine |
388 | 388 | * @return string |
389 | 389 | */ |
390 | - protected function normalizeBacktraceLine($backtraceLine) |
|
390 | + protected function normalizeBacktraceLine( $backtraceLine ) |
|
391 | 391 | { |
392 | 392 | $search = [ |
393 | - glsr()->path('plugin/'), |
|
394 | - glsr()->path('plugin/', false), |
|
395 | - trailingslashit(glsr()->path()), |
|
396 | - trailingslashit(glsr()->path('', false)), |
|
393 | + glsr()->path( 'plugin/' ), |
|
394 | + glsr()->path( 'plugin/', false ), |
|
395 | + trailingslashit( glsr()->path() ), |
|
396 | + trailingslashit( glsr()->path( '', false ) ), |
|
397 | 397 | WP_CONTENT_DIR, |
398 | 398 | ABSPATH, |
399 | 399 | ]; |
400 | - return str_replace(array_unique($search), '', $backtraceLine); |
|
400 | + return str_replace( array_unique( $search ), '', $backtraceLine ); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
404 | 404 | * @param string $message |
405 | 405 | * @return string |
406 | 406 | */ |
407 | - protected function normalizeThrowableMessage($message) |
|
407 | + protected function normalizeThrowableMessage( $message ) |
|
408 | 408 | { |
409 | - $calledIn = strpos($message, ', called in'); |
|
409 | + $calledIn = strpos( $message, ', called in' ); |
|
410 | 410 | return false !== $calledIn |
411 | - ? substr($message, 0, $calledIn) |
|
411 | + ? substr( $message, 0, $calledIn ) |
|
412 | 412 | : $message; |
413 | 413 | } |
414 | 414 | |
@@ -416,14 +416,14 @@ discard block |
||
416 | 416 | * @param mixed $value |
417 | 417 | * @return string |
418 | 418 | */ |
419 | - protected function normalizeValue($value) |
|
419 | + protected function normalizeValue( $value ) |
|
420 | 420 | { |
421 | - if ($value instanceof DateTime) { |
|
422 | - $value = $value->format('Y-m-d H:i:s'); |
|
423 | - } elseif ($this->isObjectOrArray($value)) { |
|
424 | - $value = json_encode($value); |
|
421 | + if( $value instanceof DateTime ) { |
|
422 | + $value = $value->format( 'Y-m-d H:i:s' ); |
|
423 | + } elseif( $this->isObjectOrArray( $value ) ) { |
|
424 | + $value = json_encode( $value ); |
|
425 | 425 | } |
426 | - return (string) $value; |
|
426 | + return (string)$value; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | */ |
432 | 432 | protected function reset() |
433 | 433 | { |
434 | - if ($this->size() <= pow(1024, 2) / 8) { |
|
434 | + if( $this->size() <= pow( 1024, 2 ) / 8 ) { |
|
435 | 435 | return; |
436 | 436 | } |
437 | 437 | $this->clear(); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | $this->file, |
440 | 440 | $this->buildLogEntry( |
441 | 441 | static::NOTICE, |
442 | - __('Console was automatically cleared (128 KB maximum size)', 'site-reviews') |
|
442 | + __( 'Console was automatically cleared (128 KB maximum size)', 'site-reviews' ) |
|
443 | 443 | ) |
444 | 444 | ); |
445 | 445 | } |
@@ -3,134 +3,134 @@ |
||
3 | 3 | defined('WPINC') || die; |
4 | 4 | |
5 | 5 | if (apply_filters('site-reviews/support/deprecated/v4', true)) { |
6 | - // Unprotected review meta has been deprecated |
|
7 | - add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) { |
|
8 | - $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults()); |
|
9 | - if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) { |
|
10 | - return $data; |
|
11 | - } |
|
12 | - glsr()->deprecated[] = sprintf( |
|
13 | - 'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.', |
|
14 | - $metaKey |
|
15 | - ); |
|
16 | - return get_post_meta($postId, '_'.$metaKey, $single); |
|
17 | - }, 10, 4); |
|
6 | + // Unprotected review meta has been deprecated |
|
7 | + add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) { |
|
8 | + $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults()); |
|
9 | + if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) { |
|
10 | + return $data; |
|
11 | + } |
|
12 | + glsr()->deprecated[] = sprintf( |
|
13 | + 'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.', |
|
14 | + $metaKey |
|
15 | + ); |
|
16 | + return get_post_meta($postId, '_'.$metaKey, $single); |
|
17 | + }, 10, 4); |
|
18 | 18 | |
19 | - // Modules/Html/Template.php |
|
20 | - add_filter('site-reviews/interpolate/reviews', function ($context, $template) { |
|
21 | - $search = '{{ navigation }}'; |
|
22 | - if (false !== strpos($template, $search)) { |
|
23 | - $context['navigation'] = $context['pagination']; |
|
24 | - glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.'; |
|
25 | - } |
|
26 | - return $context; |
|
27 | - }, 10, 2); |
|
19 | + // Modules/Html/Template.php |
|
20 | + add_filter('site-reviews/interpolate/reviews', function ($context, $template) { |
|
21 | + $search = '{{ navigation }}'; |
|
22 | + if (false !== strpos($template, $search)) { |
|
23 | + $context['navigation'] = $context['pagination']; |
|
24 | + glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.'; |
|
25 | + } |
|
26 | + return $context; |
|
27 | + }, 10, 2); |
|
28 | 28 | |
29 | - // Database/ReviewManager.php |
|
30 | - add_action('site-reviews/review/created', function ($review) { |
|
31 | - if (has_action('site-reviews/local/review/create')) { |
|
32 | - glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.'; |
|
33 | - do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID); |
|
34 | - } |
|
35 | - }, 9); |
|
29 | + // Database/ReviewManager.php |
|
30 | + add_action('site-reviews/review/created', function ($review) { |
|
31 | + if (has_action('site-reviews/local/review/create')) { |
|
32 | + glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.'; |
|
33 | + do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID); |
|
34 | + } |
|
35 | + }, 9); |
|
36 | 36 | |
37 | - // Handlers/CreateReview.php |
|
38 | - add_action('site-reviews/review/submitted', function ($review) { |
|
39 | - if (has_action('site-reviews/local/review/submitted')) { |
|
40 | - glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.'; |
|
41 | - do_action('site-reviews/local/review/submitted', null, $review); |
|
42 | - } |
|
43 | - if (has_filter('site-reviews/local/review/submitted/message')) { |
|
44 | - glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.'; |
|
45 | - } |
|
46 | - }, 9); |
|
37 | + // Handlers/CreateReview.php |
|
38 | + add_action('site-reviews/review/submitted', function ($review) { |
|
39 | + if (has_action('site-reviews/local/review/submitted')) { |
|
40 | + glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.'; |
|
41 | + do_action('site-reviews/local/review/submitted', null, $review); |
|
42 | + } |
|
43 | + if (has_filter('site-reviews/local/review/submitted/message')) { |
|
44 | + glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.'; |
|
45 | + } |
|
46 | + }, 9); |
|
47 | 47 | |
48 | - // Database/ReviewManager.php |
|
49 | - add_filter('site-reviews/create/review-values', function ($values, $command) { |
|
50 | - if (has_filter('site-reviews/local/review')) { |
|
51 | - glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.'; |
|
52 | - return apply_filters('site-reviews/local/review', $values, $command); |
|
53 | - } |
|
54 | - return $values; |
|
55 | - }, 9, 2); |
|
48 | + // Database/ReviewManager.php |
|
49 | + add_filter('site-reviews/create/review-values', function ($values, $command) { |
|
50 | + if (has_filter('site-reviews/local/review')) { |
|
51 | + glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.'; |
|
52 | + return apply_filters('site-reviews/local/review', $values, $command); |
|
53 | + } |
|
54 | + return $values; |
|
55 | + }, 9, 2); |
|
56 | 56 | |
57 | - // Handlers/EnqueuePublicAssets.php |
|
58 | - add_filter('site-reviews/enqueue/public/localize', function ($variables) { |
|
59 | - if (has_filter('site-reviews/enqueue/localize')) { |
|
60 | - glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.'; |
|
61 | - return apply_filters('site-reviews/enqueue/localize', $variables); |
|
62 | - } |
|
63 | - return $variables; |
|
64 | - }, 9); |
|
57 | + // Handlers/EnqueuePublicAssets.php |
|
58 | + add_filter('site-reviews/enqueue/public/localize', function ($variables) { |
|
59 | + if (has_filter('site-reviews/enqueue/localize')) { |
|
60 | + glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.'; |
|
61 | + return apply_filters('site-reviews/enqueue/localize', $variables); |
|
62 | + } |
|
63 | + return $variables; |
|
64 | + }, 9); |
|
65 | 65 | |
66 | - // Modules/Rating.php |
|
67 | - add_filter('site-reviews/rating/average', function ($average) { |
|
68 | - if (has_filter('site-reviews/average/rating')) { |
|
69 | - glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.'; |
|
70 | - } |
|
71 | - return $average; |
|
72 | - }, 9); |
|
66 | + // Modules/Rating.php |
|
67 | + add_filter('site-reviews/rating/average', function ($average) { |
|
68 | + if (has_filter('site-reviews/average/rating')) { |
|
69 | + glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.'; |
|
70 | + } |
|
71 | + return $average; |
|
72 | + }, 9); |
|
73 | 73 | |
74 | - // Modules/Rating.php |
|
75 | - add_filter('site-reviews/rating/ranking', function ($ranking) { |
|
76 | - if (has_filter('site-reviews/bayesian/ranking')) { |
|
77 | - glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.'; |
|
78 | - } |
|
79 | - return $ranking; |
|
80 | - }, 9); |
|
74 | + // Modules/Rating.php |
|
75 | + add_filter('site-reviews/rating/ranking', function ($ranking) { |
|
76 | + if (has_filter('site-reviews/bayesian/ranking')) { |
|
77 | + glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.'; |
|
78 | + } |
|
79 | + return $ranking; |
|
80 | + }, 9); |
|
81 | 81 | |
82 | - // Modules/Html/Partials/SiteReviews.php |
|
83 | - add_filter('site-reviews/review/build/after', function ($renderedFields) { |
|
84 | - if (has_filter('site-reviews/reviews/review/text')) { |
|
85 | - glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
86 | - } |
|
87 | - if (has_filter('site-reviews/reviews/review/title')) { |
|
88 | - glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
89 | - } |
|
90 | - return $renderedFields; |
|
91 | - }, 9); |
|
82 | + // Modules/Html/Partials/SiteReviews.php |
|
83 | + add_filter('site-reviews/review/build/after', function ($renderedFields) { |
|
84 | + if (has_filter('site-reviews/reviews/review/text')) { |
|
85 | + glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
86 | + } |
|
87 | + if (has_filter('site-reviews/reviews/review/title')) { |
|
88 | + glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
89 | + } |
|
90 | + return $renderedFields; |
|
91 | + }, 9); |
|
92 | 92 | |
93 | - // Modules/Html/Partials/SiteReviews.php |
|
94 | - add_filter('site-reviews/review/build/before', function ($review) { |
|
95 | - if (has_filter('site-reviews/rendered/review')) { |
|
96 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.'; |
|
97 | - } |
|
98 | - if (has_filter('site-reviews/rendered/review/meta/order')) { |
|
99 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
100 | - } |
|
101 | - if (has_filter('site-reviews/rendered/review/order')) { |
|
102 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
103 | - } |
|
104 | - if (has_filter('site-reviews/rendered/review-form/login-register')) { |
|
105 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).'; |
|
106 | - } |
|
107 | - if (has_filter('site-reviews/reviews/navigation_links')) { |
|
108 | - glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).'; |
|
109 | - } |
|
110 | - return $review; |
|
111 | - }, 9); |
|
93 | + // Modules/Html/Partials/SiteReviews.php |
|
94 | + add_filter('site-reviews/review/build/before', function ($review) { |
|
95 | + if (has_filter('site-reviews/rendered/review')) { |
|
96 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.'; |
|
97 | + } |
|
98 | + if (has_filter('site-reviews/rendered/review/meta/order')) { |
|
99 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
100 | + } |
|
101 | + if (has_filter('site-reviews/rendered/review/order')) { |
|
102 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
103 | + } |
|
104 | + if (has_filter('site-reviews/rendered/review-form/login-register')) { |
|
105 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).'; |
|
106 | + } |
|
107 | + if (has_filter('site-reviews/reviews/navigation_links')) { |
|
108 | + glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).'; |
|
109 | + } |
|
110 | + return $review; |
|
111 | + }, 9); |
|
112 | 112 | |
113 | - add_filter('site-reviews/validate/custom', function ($result, $request) { |
|
114 | - if (has_filter('site-reviews/validate/review/submission')) { |
|
115 | - glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.'); |
|
116 | - return apply_filters('site-reviews/validate/review/submission', $result, $request); |
|
117 | - } |
|
118 | - return $result; |
|
119 | - }, 9, 2); |
|
113 | + add_filter('site-reviews/validate/custom', function ($result, $request) { |
|
114 | + if (has_filter('site-reviews/validate/review/submission')) { |
|
115 | + glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.'); |
|
116 | + return apply_filters('site-reviews/validate/review/submission', $result, $request); |
|
117 | + } |
|
118 | + return $result; |
|
119 | + }, 9, 2); |
|
120 | 120 | |
121 | - add_filter('site-reviews/views/file', function ($file, $view, $data) { |
|
122 | - if (has_filter('site-reviews/addon/views/file')) { |
|
123 | - glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.'; |
|
124 | - $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data); |
|
125 | - } |
|
126 | - return $file; |
|
127 | - }, 9, 3); |
|
121 | + add_filter('site-reviews/views/file', function ($file, $view, $data) { |
|
122 | + if (has_filter('site-reviews/addon/views/file')) { |
|
123 | + glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.'; |
|
124 | + $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data); |
|
125 | + } |
|
126 | + return $file; |
|
127 | + }, 9, 3); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | add_action('wp_footer', function () { |
131 | - $notices = array_keys(array_flip(glsr()->deprecated)); |
|
132 | - natsort($notices); |
|
133 | - foreach ($notices as $notice) { |
|
134 | - glsr_log()->warning($notice); |
|
135 | - } |
|
131 | + $notices = array_keys(array_flip(glsr()->deprecated)); |
|
132 | + natsort($notices); |
|
133 | + foreach ($notices as $notice) { |
|
134 | + glsr_log()->warning($notice); |
|
135 | + } |
|
136 | 136 | }); |
@@ -1,136 +1,136 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -defined('WPINC') || die; |
|
3 | +defined( 'WPINC' ) || die; |
|
4 | 4 | |
5 | -if (apply_filters('site-reviews/support/deprecated/v4', true)) { |
|
5 | +if( apply_filters( 'site-reviews/support/deprecated/v4', true ) ) { |
|
6 | 6 | // Unprotected review meta has been deprecated |
7 | - add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) { |
|
8 | - $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults()); |
|
9 | - if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) { |
|
7 | + add_filter( 'get_post_metadata', function( $data, $postId, $metaKey, $single ) { |
|
8 | + $metaKeys = array_keys( glsr( 'Defaults\CreateReviewDefaults' )->defaults() ); |
|
9 | + if( !in_array( $metaKey, $metaKeys ) || glsr()->post_type != get_post_type( $postId ) ) { |
|
10 | 10 | return $data; |
11 | 11 | } |
12 | 12 | glsr()->deprecated[] = sprintf( |
13 | 13 | 'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.', |
14 | 14 | $metaKey |
15 | 15 | ); |
16 | - return get_post_meta($postId, '_'.$metaKey, $single); |
|
17 | - }, 10, 4); |
|
16 | + return get_post_meta( $postId, '_'.$metaKey, $single ); |
|
17 | + }, 10, 4 ); |
|
18 | 18 | |
19 | 19 | // Modules/Html/Template.php |
20 | - add_filter('site-reviews/interpolate/reviews', function ($context, $template) { |
|
20 | + add_filter( 'site-reviews/interpolate/reviews', function( $context, $template ) { |
|
21 | 21 | $search = '{{ navigation }}'; |
22 | - if (false !== strpos($template, $search)) { |
|
22 | + if( false !== strpos( $template, $search ) ) { |
|
23 | 23 | $context['navigation'] = $context['pagination']; |
24 | 24 | glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.'; |
25 | 25 | } |
26 | 26 | return $context; |
27 | - }, 10, 2); |
|
27 | + }, 10, 2 ); |
|
28 | 28 | |
29 | 29 | // Database/ReviewManager.php |
30 | - add_action('site-reviews/review/created', function ($review) { |
|
31 | - if (has_action('site-reviews/local/review/create')) { |
|
30 | + add_action( 'site-reviews/review/created', function( $review ) { |
|
31 | + if( has_action( 'site-reviews/local/review/create' ) ) { |
|
32 | 32 | glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.'; |
33 | - do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID); |
|
33 | + do_action( 'site-reviews/local/review/create', (array)get_post( $review->ID ), (array)$review, $review->ID ); |
|
34 | 34 | } |
35 | - }, 9); |
|
35 | + }, 9 ); |
|
36 | 36 | |
37 | 37 | // Handlers/CreateReview.php |
38 | - add_action('site-reviews/review/submitted', function ($review) { |
|
39 | - if (has_action('site-reviews/local/review/submitted')) { |
|
38 | + add_action( 'site-reviews/review/submitted', function( $review ) { |
|
39 | + if( has_action( 'site-reviews/local/review/submitted' ) ) { |
|
40 | 40 | glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.'; |
41 | - do_action('site-reviews/local/review/submitted', null, $review); |
|
41 | + do_action( 'site-reviews/local/review/submitted', null, $review ); |
|
42 | 42 | } |
43 | - if (has_filter('site-reviews/local/review/submitted/message')) { |
|
43 | + if( has_filter( 'site-reviews/local/review/submitted/message' ) ) { |
|
44 | 44 | glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.'; |
45 | 45 | } |
46 | - }, 9); |
|
46 | + }, 9 ); |
|
47 | 47 | |
48 | 48 | // Database/ReviewManager.php |
49 | - add_filter('site-reviews/create/review-values', function ($values, $command) { |
|
50 | - if (has_filter('site-reviews/local/review')) { |
|
49 | + add_filter( 'site-reviews/create/review-values', function( $values, $command ) { |
|
50 | + if( has_filter( 'site-reviews/local/review' ) ) { |
|
51 | 51 | glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.'; |
52 | - return apply_filters('site-reviews/local/review', $values, $command); |
|
52 | + return apply_filters( 'site-reviews/local/review', $values, $command ); |
|
53 | 53 | } |
54 | 54 | return $values; |
55 | - }, 9, 2); |
|
55 | + }, 9, 2 ); |
|
56 | 56 | |
57 | 57 | // Handlers/EnqueuePublicAssets.php |
58 | - add_filter('site-reviews/enqueue/public/localize', function ($variables) { |
|
59 | - if (has_filter('site-reviews/enqueue/localize')) { |
|
58 | + add_filter( 'site-reviews/enqueue/public/localize', function( $variables ) { |
|
59 | + if( has_filter( 'site-reviews/enqueue/localize' ) ) { |
|
60 | 60 | glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.'; |
61 | - return apply_filters('site-reviews/enqueue/localize', $variables); |
|
61 | + return apply_filters( 'site-reviews/enqueue/localize', $variables ); |
|
62 | 62 | } |
63 | 63 | return $variables; |
64 | - }, 9); |
|
64 | + }, 9 ); |
|
65 | 65 | |
66 | 66 | // Modules/Rating.php |
67 | - add_filter('site-reviews/rating/average', function ($average) { |
|
68 | - if (has_filter('site-reviews/average/rating')) { |
|
67 | + add_filter( 'site-reviews/rating/average', function( $average ) { |
|
68 | + if( has_filter( 'site-reviews/average/rating' ) ) { |
|
69 | 69 | glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.'; |
70 | 70 | } |
71 | 71 | return $average; |
72 | - }, 9); |
|
72 | + }, 9 ); |
|
73 | 73 | |
74 | 74 | // Modules/Rating.php |
75 | - add_filter('site-reviews/rating/ranking', function ($ranking) { |
|
76 | - if (has_filter('site-reviews/bayesian/ranking')) { |
|
75 | + add_filter( 'site-reviews/rating/ranking', function( $ranking ) { |
|
76 | + if( has_filter( 'site-reviews/bayesian/ranking' ) ) { |
|
77 | 77 | glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.'; |
78 | 78 | } |
79 | 79 | return $ranking; |
80 | - }, 9); |
|
80 | + }, 9 ); |
|
81 | 81 | |
82 | 82 | // Modules/Html/Partials/SiteReviews.php |
83 | - add_filter('site-reviews/review/build/after', function ($renderedFields) { |
|
84 | - if (has_filter('site-reviews/reviews/review/text')) { |
|
83 | + add_filter( 'site-reviews/review/build/after', function( $renderedFields ) { |
|
84 | + if( has_filter( 'site-reviews/reviews/review/text' ) ) { |
|
85 | 85 | glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
86 | 86 | } |
87 | - if (has_filter('site-reviews/reviews/review/title')) { |
|
87 | + if( has_filter( 'site-reviews/reviews/review/title' ) ) { |
|
88 | 88 | glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
89 | 89 | } |
90 | 90 | return $renderedFields; |
91 | - }, 9); |
|
91 | + }, 9 ); |
|
92 | 92 | |
93 | 93 | // Modules/Html/Partials/SiteReviews.php |
94 | - add_filter('site-reviews/review/build/before', function ($review) { |
|
95 | - if (has_filter('site-reviews/rendered/review')) { |
|
94 | + add_filter( 'site-reviews/review/build/before', function( $review ) { |
|
95 | + if( has_filter( 'site-reviews/rendered/review' ) ) { |
|
96 | 96 | glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.'; |
97 | 97 | } |
98 | - if (has_filter('site-reviews/rendered/review/meta/order')) { |
|
98 | + if( has_filter( 'site-reviews/rendered/review/meta/order' ) ) { |
|
99 | 99 | glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
100 | 100 | } |
101 | - if (has_filter('site-reviews/rendered/review/order')) { |
|
101 | + if( has_filter( 'site-reviews/rendered/review/order' ) ) { |
|
102 | 102 | glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
103 | 103 | } |
104 | - if (has_filter('site-reviews/rendered/review-form/login-register')) { |
|
104 | + if( has_filter( 'site-reviews/rendered/review-form/login-register' ) ) { |
|
105 | 105 | glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).'; |
106 | 106 | } |
107 | - if (has_filter('site-reviews/reviews/navigation_links')) { |
|
107 | + if( has_filter( 'site-reviews/reviews/navigation_links' ) ) { |
|
108 | 108 | glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).'; |
109 | 109 | } |
110 | 110 | return $review; |
111 | - }, 9); |
|
111 | + }, 9 ); |
|
112 | 112 | |
113 | - add_filter('site-reviews/validate/custom', function ($result, $request) { |
|
114 | - if (has_filter('site-reviews/validate/review/submission')) { |
|
115 | - glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.'); |
|
116 | - return apply_filters('site-reviews/validate/review/submission', $result, $request); |
|
113 | + add_filter( 'site-reviews/validate/custom', function( $result, $request ) { |
|
114 | + if( has_filter( 'site-reviews/validate/review/submission' ) ) { |
|
115 | + glsr_log()->warning( 'The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.' ); |
|
116 | + return apply_filters( 'site-reviews/validate/review/submission', $result, $request ); |
|
117 | 117 | } |
118 | 118 | return $result; |
119 | - }, 9, 2); |
|
119 | + }, 9, 2 ); |
|
120 | 120 | |
121 | - add_filter('site-reviews/views/file', function ($file, $view, $data) { |
|
122 | - if (has_filter('site-reviews/addon/views/file')) { |
|
121 | + add_filter( 'site-reviews/views/file', function( $file, $view, $data ) { |
|
122 | + if( has_filter( 'site-reviews/addon/views/file' ) ) { |
|
123 | 123 | glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.'; |
124 | - $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data); |
|
124 | + $file = apply_filters( 'site-reviews/addon/views/file', $file, $view, $data ); |
|
125 | 125 | } |
126 | 126 | return $file; |
127 | - }, 9, 3); |
|
127 | + }, 9, 3 ); |
|
128 | 128 | } |
129 | 129 | |
130 | -add_action('wp_footer', function () { |
|
131 | - $notices = array_keys(array_flip(glsr()->deprecated)); |
|
132 | - natsort($notices); |
|
133 | - foreach ($notices as $notice) { |
|
134 | - glsr_log()->warning($notice); |
|
130 | +add_action( 'wp_footer', function() { |
|
131 | + $notices = array_keys( array_flip( glsr()->deprecated ) ); |
|
132 | + natsort( $notices ); |
|
133 | + foreach( $notices as $notice ) { |
|
134 | + glsr_log()->warning( $notice ); |
|
135 | 135 | } |
136 | 136 | }); |
@@ -10,158 +10,158 @@ |
||
10 | 10 | |
11 | 11 | class EnqueueAdminAssets |
12 | 12 | { |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $pointers; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $pointers; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return void |
|
20 | - */ |
|
21 | - public function handle(Command $command) |
|
22 | - { |
|
23 | - $this->generatePointers($command->pointers); |
|
24 | - $this->enqueueAssets(); |
|
25 | - $this->localizeAssets(); |
|
26 | - } |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + */ |
|
21 | + public function handle(Command $command) |
|
22 | + { |
|
23 | + $this->generatePointers($command->pointers); |
|
24 | + $this->enqueueAssets(); |
|
25 | + $this->localizeAssets(); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function enqueueAssets() |
|
32 | - { |
|
33 | - if (!$this->isCurrentScreen()) { |
|
34 | - return; |
|
35 | - } |
|
36 | - wp_enqueue_style( |
|
37 | - Application::ID, |
|
38 | - glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
39 | - [], |
|
40 | - glsr()->version |
|
41 | - ); |
|
42 | - wp_enqueue_script( |
|
43 | - Application::ID, |
|
44 | - glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
45 | - $this->getDependencies(), |
|
46 | - glsr()->version, |
|
47 | - true |
|
48 | - ); |
|
49 | - if (!empty($this->pointers)) { |
|
50 | - wp_enqueue_style('wp-pointer'); |
|
51 | - wp_enqueue_script('wp-pointer'); |
|
52 | - } |
|
53 | - } |
|
28 | + /** |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function enqueueAssets() |
|
32 | + { |
|
33 | + if (!$this->isCurrentScreen()) { |
|
34 | + return; |
|
35 | + } |
|
36 | + wp_enqueue_style( |
|
37 | + Application::ID, |
|
38 | + glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
39 | + [], |
|
40 | + glsr()->version |
|
41 | + ); |
|
42 | + wp_enqueue_script( |
|
43 | + Application::ID, |
|
44 | + glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
45 | + $this->getDependencies(), |
|
46 | + glsr()->version, |
|
47 | + true |
|
48 | + ); |
|
49 | + if (!empty($this->pointers)) { |
|
50 | + wp_enqueue_style('wp-pointer'); |
|
51 | + wp_enqueue_script('wp-pointer'); |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function localizeAssets() |
|
59 | - { |
|
60 | - $variables = [ |
|
61 | - 'action' => Application::PREFIX.'action', |
|
62 | - 'addons' => [], |
|
63 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
64 | - 'hideoptions' => [ |
|
65 | - 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | - 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | - 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
68 | - ], |
|
69 | - 'nameprefix' => Application::ID, |
|
70 | - 'nonce' => [ |
|
71 | - 'change-status' => wp_create_nonce('change-status'), |
|
72 | - 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | - 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | - 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | - 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | - 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | - 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
78 | - ], |
|
79 | - 'pointers' => $this->pointers, |
|
80 | - 'shortcodes' => [], |
|
81 | - 'tinymce' => [ |
|
82 | - 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
83 | - ], |
|
84 | - ]; |
|
85 | - if (user_can_richedit()) { |
|
86 | - $variables['shortcodes'] = $this->localizeShortcodes(); |
|
87 | - } |
|
88 | - $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | - wp_localize_script(Application::ID, 'GLSR', $variables); |
|
90 | - } |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function localizeAssets() |
|
59 | + { |
|
60 | + $variables = [ |
|
61 | + 'action' => Application::PREFIX.'action', |
|
62 | + 'addons' => [], |
|
63 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
64 | + 'hideoptions' => [ |
|
65 | + 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | + 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | + 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
68 | + ], |
|
69 | + 'nameprefix' => Application::ID, |
|
70 | + 'nonce' => [ |
|
71 | + 'change-status' => wp_create_nonce('change-status'), |
|
72 | + 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | + 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | + 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | + 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | + 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | + 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
78 | + ], |
|
79 | + 'pointers' => $this->pointers, |
|
80 | + 'shortcodes' => [], |
|
81 | + 'tinymce' => [ |
|
82 | + 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
83 | + ], |
|
84 | + ]; |
|
85 | + if (user_can_richedit()) { |
|
86 | + $variables['shortcodes'] = $this->localizeShortcodes(); |
|
87 | + } |
|
88 | + $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | + wp_localize_script(Application::ID, 'GLSR', $variables); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - protected function getDependencies() |
|
96 | - { |
|
97 | - $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | - $dependencies = array_merge($dependencies, [ |
|
99 | - 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
|
100 | - ]); |
|
101 | - return $dependencies; |
|
102 | - } |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + protected function getDependencies() |
|
96 | + { |
|
97 | + $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | + $dependencies = array_merge($dependencies, [ |
|
99 | + 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
|
100 | + ]); |
|
101 | + return $dependencies; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - protected function generatePointer(array $pointer) |
|
108 | - { |
|
109 | - return [ |
|
110 | - 'id' => $pointer['id'], |
|
111 | - 'options' => [ |
|
112 | - 'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>', |
|
113 | - 'position' => $pointer['position'], |
|
114 | - ], |
|
115 | - 'screen' => $pointer['screen'], |
|
116 | - 'target' => $pointer['target'], |
|
117 | - ]; |
|
118 | - } |
|
104 | + /** |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + protected function generatePointer(array $pointer) |
|
108 | + { |
|
109 | + return [ |
|
110 | + 'id' => $pointer['id'], |
|
111 | + 'options' => [ |
|
112 | + 'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>', |
|
113 | + 'position' => $pointer['position'], |
|
114 | + ], |
|
115 | + 'screen' => $pointer['screen'], |
|
116 | + 'target' => $pointer['target'], |
|
117 | + ]; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - protected function generatePointers(array $pointers) |
|
124 | - { |
|
125 | - $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | - $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
127 | - $generatedPointers = []; |
|
128 | - foreach ($pointers as $pointer) { |
|
129 | - if ($pointer['screen'] != glsr_current_screen()->id) { |
|
130 | - continue; |
|
131 | - } |
|
132 | - if (in_array($pointer['id'], $dismissedPointers)) { |
|
133 | - continue; |
|
134 | - } |
|
135 | - $generatedPointers[] = $this->generatePointer($pointer); |
|
136 | - } |
|
137 | - $this->pointers = $generatedPointers; |
|
138 | - } |
|
120 | + /** |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + protected function generatePointers(array $pointers) |
|
124 | + { |
|
125 | + $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | + $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
127 | + $generatedPointers = []; |
|
128 | + foreach ($pointers as $pointer) { |
|
129 | + if ($pointer['screen'] != glsr_current_screen()->id) { |
|
130 | + continue; |
|
131 | + } |
|
132 | + if (in_array($pointer['id'], $dismissedPointers)) { |
|
133 | + continue; |
|
134 | + } |
|
135 | + $generatedPointers[] = $this->generatePointer($pointer); |
|
136 | + } |
|
137 | + $this->pointers = $generatedPointers; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - protected function isCurrentScreen() |
|
144 | - { |
|
145 | - $screen = glsr_current_screen(); |
|
146 | - return Application::POST_TYPE == $screen->post_type |
|
147 | - || 'dashboard' == $screen->id |
|
148 | - || 'plugins_page_'.Application::ID == $screen->id |
|
149 | - || 'post' == $screen->base |
|
150 | - || 'widgets' == $screen->id; |
|
151 | - } |
|
140 | + /** |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + protected function isCurrentScreen() |
|
144 | + { |
|
145 | + $screen = glsr_current_screen(); |
|
146 | + return Application::POST_TYPE == $screen->post_type |
|
147 | + || 'dashboard' == $screen->id |
|
148 | + || 'plugins_page_'.Application::ID == $screen->id |
|
149 | + || 'post' == $screen->base |
|
150 | + || 'widgets' == $screen->id; |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - protected function localizeShortcodes() |
|
157 | - { |
|
158 | - $variables = []; |
|
159 | - foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | - if (empty($args['required'])) { |
|
161 | - continue; |
|
162 | - } |
|
163 | - $variables[$tag] = $args['required']; |
|
164 | - } |
|
165 | - return $variables; |
|
166 | - } |
|
153 | + /** |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + protected function localizeShortcodes() |
|
157 | + { |
|
158 | + $variables = []; |
|
159 | + foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | + if (empty($args['required'])) { |
|
161 | + continue; |
|
162 | + } |
|
163 | + $variables[$tag] = $args['required']; |
|
164 | + } |
|
165 | + return $variables; |
|
166 | + } |
|
167 | 167 | } |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @return void |
20 | 20 | */ |
21 | - public function handle(Command $command) |
|
21 | + public function handle( Command $command ) |
|
22 | 22 | { |
23 | - $this->generatePointers($command->pointers); |
|
23 | + $this->generatePointers( $command->pointers ); |
|
24 | 24 | $this->enqueueAssets(); |
25 | 25 | $this->localizeAssets(); |
26 | 26 | } |
@@ -30,25 +30,25 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function enqueueAssets() |
32 | 32 | { |
33 | - if (!$this->isCurrentScreen()) { |
|
33 | + if( !$this->isCurrentScreen() ) { |
|
34 | 34 | return; |
35 | 35 | } |
36 | 36 | wp_enqueue_style( |
37 | 37 | Application::ID, |
38 | - glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
38 | + glsr()->url( 'assets/styles/'.Application::ID.'-admin.css' ), |
|
39 | 39 | [], |
40 | 40 | glsr()->version |
41 | 41 | ); |
42 | 42 | wp_enqueue_script( |
43 | 43 | Application::ID, |
44 | - glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
44 | + glsr()->url( 'assets/scripts/'.Application::ID.'-admin.js' ), |
|
45 | 45 | $this->getDependencies(), |
46 | 46 | glsr()->version, |
47 | 47 | true |
48 | 48 | ); |
49 | - if (!empty($this->pointers)) { |
|
50 | - wp_enqueue_style('wp-pointer'); |
|
51 | - wp_enqueue_script('wp-pointer'); |
|
49 | + if( !empty($this->pointers) ) { |
|
50 | + wp_enqueue_style( 'wp-pointer' ); |
|
51 | + wp_enqueue_script( 'wp-pointer' ); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
@@ -60,33 +60,33 @@ discard block |
||
60 | 60 | $variables = [ |
61 | 61 | 'action' => Application::PREFIX.'action', |
62 | 62 | 'addons' => [], |
63 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
63 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
64 | 64 | 'hideoptions' => [ |
65 | - 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | - 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | - 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
65 | + 'site_reviews' => glsr( SiteReviewsShortcode::class )->getHideOptions(), |
|
66 | + 'site_reviews_form' => glsr( SiteReviewsFormShortcode::class )->getHideOptions(), |
|
67 | + 'site_reviews_summary' => glsr( SiteReviewsSummaryShortcode::class )->getHideOptions(), |
|
68 | 68 | ], |
69 | 69 | 'nameprefix' => Application::ID, |
70 | 70 | 'nonce' => [ |
71 | - 'change-status' => wp_create_nonce('change-status'), |
|
72 | - 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | - 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | - 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | - 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | - 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | - 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
71 | + 'change-status' => wp_create_nonce( 'change-status' ), |
|
72 | + 'clear-console' => wp_create_nonce( 'clear-console' ), |
|
73 | + 'count-reviews' => wp_create_nonce( 'count-reviews' ), |
|
74 | + 'fetch-console' => wp_create_nonce( 'fetch-console' ), |
|
75 | + 'mce-shortcode' => wp_create_nonce( 'mce-shortcode' ), |
|
76 | + 'sync-reviews' => wp_create_nonce( 'sync-reviews' ), |
|
77 | + 'toggle-pinned' => wp_create_nonce( 'toggle-pinned' ), |
|
78 | 78 | ], |
79 | 79 | 'pointers' => $this->pointers, |
80 | 80 | 'shortcodes' => [], |
81 | 81 | 'tinymce' => [ |
82 | - 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
82 | + 'glsr_shortcode' => glsr()->url( 'assets/scripts/mce-plugin.js' ), |
|
83 | 83 | ], |
84 | 84 | ]; |
85 | - if (user_can_richedit()) { |
|
85 | + if( user_can_richedit() ) { |
|
86 | 86 | $variables['shortcodes'] = $this->localizeShortcodes(); |
87 | 87 | } |
88 | - $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | - wp_localize_script(Application::ID, 'GLSR', $variables); |
|
88 | + $variables = apply_filters( 'site-reviews/enqueue/admin/localize', $variables ); |
|
89 | + wp_localize_script( Application::ID, 'GLSR', $variables ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | */ |
95 | 95 | protected function getDependencies() |
96 | 96 | { |
97 | - $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | - $dependencies = array_merge($dependencies, [ |
|
97 | + $dependencies = apply_filters( 'site-reviews/enqueue/admin/dependencies', [] ); |
|
98 | + $dependencies = array_merge( $dependencies, [ |
|
99 | 99 | 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
100 | - ]); |
|
100 | + ] ); |
|
101 | 101 | return $dependencies; |
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * @return array |
106 | 106 | */ |
107 | - protected function generatePointer(array $pointer) |
|
107 | + protected function generatePointer( array $pointer ) |
|
108 | 108 | { |
109 | 109 | return [ |
110 | 110 | 'id' => $pointer['id'], |
@@ -120,19 +120,19 @@ discard block |
||
120 | 120 | /** |
121 | 121 | * @return void |
122 | 122 | */ |
123 | - protected function generatePointers(array $pointers) |
|
123 | + protected function generatePointers( array $pointers ) |
|
124 | 124 | { |
125 | - $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | - $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
125 | + $dismissedPointers = get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ); |
|
126 | + $dismissedPointers = explode( ',', (string)$dismissedPointers ); |
|
127 | 127 | $generatedPointers = []; |
128 | - foreach ($pointers as $pointer) { |
|
129 | - if ($pointer['screen'] != glsr_current_screen()->id) { |
|
128 | + foreach( $pointers as $pointer ) { |
|
129 | + if( $pointer['screen'] != glsr_current_screen()->id ) { |
|
130 | 130 | continue; |
131 | 131 | } |
132 | - if (in_array($pointer['id'], $dismissedPointers)) { |
|
132 | + if( in_array( $pointer['id'], $dismissedPointers ) ) { |
|
133 | 133 | continue; |
134 | 134 | } |
135 | - $generatedPointers[] = $this->generatePointer($pointer); |
|
135 | + $generatedPointers[] = $this->generatePointer( $pointer ); |
|
136 | 136 | } |
137 | 137 | $this->pointers = $generatedPointers; |
138 | 138 | } |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | protected function localizeShortcodes() |
157 | 157 | { |
158 | 158 | $variables = []; |
159 | - foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | - if (empty($args['required'])) { |
|
159 | + foreach( glsr()->mceShortcodes as $tag => $args ) { |
|
160 | + if( empty($args['required']) ) { |
|
161 | 161 | continue; |
162 | 162 | } |
163 | 163 | $variables[$tag] = $args['required']; |
@@ -12,190 +12,190 @@ |
||
12 | 12 | |
13 | 13 | class QueryBuilder |
14 | 14 | { |
15 | - /** |
|
16 | - * Build a WP_Query meta_query/tax_query. |
|
17 | - * @return array |
|
18 | - */ |
|
19 | - public function buildQuery(array $keys = [], array $values = []) |
|
20 | - { |
|
21 | - $queries = []; |
|
22 | - foreach ($keys as $key) { |
|
23 | - if (!array_key_exists($key, $values)) { |
|
24 | - continue; |
|
25 | - } |
|
26 | - $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
27 | - if (!method_exists($this, $methodName)) { |
|
28 | - continue; |
|
29 | - } |
|
30 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
31 | - if (is_array($query)) { |
|
32 | - $queries[] = $query; |
|
33 | - } |
|
34 | - } |
|
35 | - return $queries; |
|
36 | - } |
|
15 | + /** |
|
16 | + * Build a WP_Query meta_query/tax_query. |
|
17 | + * @return array |
|
18 | + */ |
|
19 | + public function buildQuery(array $keys = [], array $values = []) |
|
20 | + { |
|
21 | + $queries = []; |
|
22 | + foreach ($keys as $key) { |
|
23 | + if (!array_key_exists($key, $values)) { |
|
24 | + continue; |
|
25 | + } |
|
26 | + $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
27 | + if (!method_exists($this, $methodName)) { |
|
28 | + continue; |
|
29 | + } |
|
30 | + $query = call_user_func([$this, $methodName], $values[$key]); |
|
31 | + if (is_array($query)) { |
|
32 | + $queries[] = $query; |
|
33 | + } |
|
34 | + } |
|
35 | + return $queries; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function buildSqlLines(array $values, array $conditions) |
|
42 | - { |
|
43 | - $string = ''; |
|
44 | - $values = array_filter($values); |
|
45 | - foreach ($conditions as $key => $value) { |
|
46 | - if (!isset($values[$key])) { |
|
47 | - continue; |
|
48 | - } |
|
49 | - $values[$key] = implode(',', (array) $values[$key]); |
|
50 | - $string.= Str::contains($value, '%s') |
|
51 | - ? sprintf($value, strval($values[$key])) |
|
52 | - : $value; |
|
53 | - } |
|
54 | - return $string; |
|
55 | - } |
|
38 | + /** |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function buildSqlLines(array $values, array $conditions) |
|
42 | + { |
|
43 | + $string = ''; |
|
44 | + $values = array_filter($values); |
|
45 | + foreach ($conditions as $key => $value) { |
|
46 | + if (!isset($values[$key])) { |
|
47 | + continue; |
|
48 | + } |
|
49 | + $values[$key] = implode(',', (array) $values[$key]); |
|
50 | + $string.= Str::contains($value, '%s') |
|
51 | + ? sprintf($value, strval($values[$key])) |
|
52 | + : $value; |
|
53 | + } |
|
54 | + return $string; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Build a SQL 'OR' string from an array. |
|
59 | - * @param string|array $values |
|
60 | - * @param string $sprintfFormat |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function buildSqlOr($values, $sprintfFormat) |
|
64 | - { |
|
65 | - if (!is_array($values)) { |
|
66 | - $values = explode(',', $values); |
|
67 | - } |
|
68 | - $values = array_filter(array_map('trim', (array) $values)); |
|
69 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
70 | - return sprintf($sprintfFormat, $value); |
|
71 | - }, $values); |
|
72 | - return implode(' OR ', $values); |
|
73 | - } |
|
57 | + /** |
|
58 | + * Build a SQL 'OR' string from an array. |
|
59 | + * @param string|array $values |
|
60 | + * @param string $sprintfFormat |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function buildSqlOr($values, $sprintfFormat) |
|
64 | + { |
|
65 | + if (!is_array($values)) { |
|
66 | + $values = explode(',', $values); |
|
67 | + } |
|
68 | + $values = array_filter(array_map('trim', (array) $values)); |
|
69 | + $values = array_map(function ($value) use ($sprintfFormat) { |
|
70 | + return sprintf($sprintfFormat, $value); |
|
71 | + }, $values); |
|
72 | + return implode(' OR ', $values); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Search SQL filter for matching against post title only. |
|
77 | - * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
78 | - * @param string $search |
|
79 | - * @return string |
|
80 | - * @filter posts_search |
|
81 | - */ |
|
82 | - public function filterSearchByTitle($search, WP_Query $query) |
|
83 | - { |
|
84 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
85 | - return $search; |
|
86 | - } |
|
87 | - global $wpdb; |
|
88 | - $n = empty($query->get('exact')) |
|
89 | - ? '%' |
|
90 | - : ''; |
|
91 | - $search = []; |
|
92 | - foreach ((array) $query->get('search_terms') as $term) { |
|
93 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
94 | - } |
|
95 | - if (!is_user_logged_in()) { |
|
96 | - $search[] = "{$wpdb->posts}.post_password = ''"; |
|
97 | - } |
|
98 | - return ' AND '.implode(' AND ', $search); |
|
99 | - } |
|
75 | + /** |
|
76 | + * Search SQL filter for matching against post title only. |
|
77 | + * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
78 | + * @param string $search |
|
79 | + * @return string |
|
80 | + * @filter posts_search |
|
81 | + */ |
|
82 | + public function filterSearchByTitle($search, WP_Query $query) |
|
83 | + { |
|
84 | + if (empty($search) || empty($query->get('search_terms'))) { |
|
85 | + return $search; |
|
86 | + } |
|
87 | + global $wpdb; |
|
88 | + $n = empty($query->get('exact')) |
|
89 | + ? '%' |
|
90 | + : ''; |
|
91 | + $search = []; |
|
92 | + foreach ((array) $query->get('search_terms') as $term) { |
|
93 | + $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
94 | + } |
|
95 | + if (!is_user_logged_in()) { |
|
96 | + $search[] = "{$wpdb->posts}.post_password = ''"; |
|
97 | + } |
|
98 | + return ' AND '.implode(' AND ', $search); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get the current page number from the global query. |
|
103 | - * @param bool $isEnabled |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public function getPaged($isEnabled = true) |
|
107 | - { |
|
108 | - return $isEnabled |
|
109 | - ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR')))) |
|
110 | - : 1; |
|
111 | - } |
|
101 | + /** |
|
102 | + * Get the current page number from the global query. |
|
103 | + * @param bool $isEnabled |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public function getPaged($isEnabled = true) |
|
107 | + { |
|
108 | + return $isEnabled |
|
109 | + ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR')))) |
|
110 | + : 1; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param string $value |
|
115 | - * @return void|array |
|
116 | - */ |
|
117 | - protected function buildQueryAssignedTo($value) |
|
118 | - { |
|
119 | - if (!empty($value)) { |
|
120 | - $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
121 | - return [ |
|
122 | - 'compare' => 'IN', |
|
123 | - 'key' => '_assigned_to', |
|
124 | - 'value' => glsr(Multilingual::class)->getPostIds($postIds), |
|
125 | - ]; |
|
126 | - } |
|
127 | - } |
|
113 | + /** |
|
114 | + * @param string $value |
|
115 | + * @return void|array |
|
116 | + */ |
|
117 | + protected function buildQueryAssignedTo($value) |
|
118 | + { |
|
119 | + if (!empty($value)) { |
|
120 | + $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
121 | + return [ |
|
122 | + 'compare' => 'IN', |
|
123 | + 'key' => '_assigned_to', |
|
124 | + 'value' => glsr(Multilingual::class)->getPostIds($postIds), |
|
125 | + ]; |
|
126 | + } |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @param array $value |
|
131 | - * @return void|array |
|
132 | - */ |
|
133 | - protected function buildQueryCategory($value) |
|
134 | - { |
|
135 | - if (!empty($value)) { |
|
136 | - return [ |
|
137 | - 'field' => 'term_id', |
|
138 | - 'taxonomy' => Application::TAXONOMY, |
|
139 | - 'terms' => $value, |
|
140 | - ]; |
|
141 | - } |
|
142 | - } |
|
129 | + /** |
|
130 | + * @param array $value |
|
131 | + * @return void|array |
|
132 | + */ |
|
133 | + protected function buildQueryCategory($value) |
|
134 | + { |
|
135 | + if (!empty($value)) { |
|
136 | + return [ |
|
137 | + 'field' => 'term_id', |
|
138 | + 'taxonomy' => Application::TAXONOMY, |
|
139 | + 'terms' => $value, |
|
140 | + ]; |
|
141 | + } |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @param string $value |
|
146 | - * @return void|array |
|
147 | - */ |
|
148 | - protected function buildQueryEmail($value) |
|
149 | - { |
|
150 | - if (!empty($value)) { |
|
151 | - return [ |
|
152 | - 'key' => '_email', |
|
153 | - 'value' => $value, |
|
154 | - ]; |
|
155 | - } |
|
156 | - } |
|
144 | + /** |
|
145 | + * @param string $value |
|
146 | + * @return void|array |
|
147 | + */ |
|
148 | + protected function buildQueryEmail($value) |
|
149 | + { |
|
150 | + if (!empty($value)) { |
|
151 | + return [ |
|
152 | + 'key' => '_email', |
|
153 | + 'value' => $value, |
|
154 | + ]; |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * @param string $value |
|
160 | - * @return void|array |
|
161 | - */ |
|
162 | - protected function buildQueryIpAddress($value) |
|
163 | - { |
|
164 | - if (!empty($value)) { |
|
165 | - return [ |
|
166 | - 'key' => '_ip_address', |
|
167 | - 'value' => $value, |
|
168 | - ]; |
|
169 | - } |
|
170 | - } |
|
158 | + /** |
|
159 | + * @param string $value |
|
160 | + * @return void|array |
|
161 | + */ |
|
162 | + protected function buildQueryIpAddress($value) |
|
163 | + { |
|
164 | + if (!empty($value)) { |
|
165 | + return [ |
|
166 | + 'key' => '_ip_address', |
|
167 | + 'value' => $value, |
|
168 | + ]; |
|
169 | + } |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * @param string $value |
|
174 | - * @return void|array |
|
175 | - */ |
|
176 | - protected function buildQueryRating($value) |
|
177 | - { |
|
178 | - if (is_numeric($value) |
|
179 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
180 | - return [ |
|
181 | - 'compare' => '>=', |
|
182 | - 'key' => '_rating', |
|
183 | - 'value' => $value, |
|
184 | - ]; |
|
185 | - } |
|
186 | - } |
|
172 | + /** |
|
173 | + * @param string $value |
|
174 | + * @return void|array |
|
175 | + */ |
|
176 | + protected function buildQueryRating($value) |
|
177 | + { |
|
178 | + if (is_numeric($value) |
|
179 | + && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
180 | + return [ |
|
181 | + 'compare' => '>=', |
|
182 | + 'key' => '_rating', |
|
183 | + 'value' => $value, |
|
184 | + ]; |
|
185 | + } |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * @param string $value |
|
190 | - * @return void|array |
|
191 | - */ |
|
192 | - protected function buildQueryType($value) |
|
193 | - { |
|
194 | - if (!in_array($value, ['', 'all'])) { |
|
195 | - return [ |
|
196 | - 'key' => '_review_type', |
|
197 | - 'value' => $value, |
|
198 | - ]; |
|
199 | - } |
|
200 | - } |
|
188 | + /** |
|
189 | + * @param string $value |
|
190 | + * @return void|array |
|
191 | + */ |
|
192 | + protected function buildQueryType($value) |
|
193 | + { |
|
194 | + if (!in_array($value, ['', 'all'])) { |
|
195 | + return [ |
|
196 | + 'key' => '_review_type', |
|
197 | + 'value' => $value, |
|
198 | + ]; |
|
199 | + } |
|
200 | + } |
|
201 | 201 | } |
@@ -16,19 +16,19 @@ discard block |
||
16 | 16 | * Build a WP_Query meta_query/tax_query. |
17 | 17 | * @return array |
18 | 18 | */ |
19 | - public function buildQuery(array $keys = [], array $values = []) |
|
19 | + public function buildQuery( array $keys = [], array $values = [] ) |
|
20 | 20 | { |
21 | 21 | $queries = []; |
22 | - foreach ($keys as $key) { |
|
23 | - if (!array_key_exists($key, $values)) { |
|
22 | + foreach( $keys as $key ) { |
|
23 | + if( !array_key_exists( $key, $values ) ) { |
|
24 | 24 | continue; |
25 | 25 | } |
26 | - $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
27 | - if (!method_exists($this, $methodName)) { |
|
26 | + $methodName = Helper::buildMethodName( $key, __FUNCTION__ ); |
|
27 | + if( !method_exists( $this, $methodName ) ) { |
|
28 | 28 | continue; |
29 | 29 | } |
30 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
31 | - if (is_array($query)) { |
|
30 | + $query = call_user_func( [$this, $methodName], $values[$key] ); |
|
31 | + if( is_array( $query ) ) { |
|
32 | 32 | $queries[] = $query; |
33 | 33 | } |
34 | 34 | } |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * @return string |
40 | 40 | */ |
41 | - public function buildSqlLines(array $values, array $conditions) |
|
41 | + public function buildSqlLines( array $values, array $conditions ) |
|
42 | 42 | { |
43 | 43 | $string = ''; |
44 | - $values = array_filter($values); |
|
45 | - foreach ($conditions as $key => $value) { |
|
46 | - if (!isset($values[$key])) { |
|
44 | + $values = array_filter( $values ); |
|
45 | + foreach( $conditions as $key => $value ) { |
|
46 | + if( !isset($values[$key]) ) { |
|
47 | 47 | continue; |
48 | 48 | } |
49 | - $values[$key] = implode(',', (array) $values[$key]); |
|
50 | - $string.= Str::contains($value, '%s') |
|
51 | - ? sprintf($value, strval($values[$key])) |
|
49 | + $values[$key] = implode( ',', (array)$values[$key] ); |
|
50 | + $string .= Str::contains( $value, '%s' ) |
|
51 | + ? sprintf( $value, strval( $values[$key] ) ) |
|
52 | 52 | : $value; |
53 | 53 | } |
54 | 54 | return $string; |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | * @param string $sprintfFormat |
61 | 61 | * @return string |
62 | 62 | */ |
63 | - public function buildSqlOr($values, $sprintfFormat) |
|
63 | + public function buildSqlOr( $values, $sprintfFormat ) |
|
64 | 64 | { |
65 | - if (!is_array($values)) { |
|
66 | - $values = explode(',', $values); |
|
65 | + if( !is_array( $values ) ) { |
|
66 | + $values = explode( ',', $values ); |
|
67 | 67 | } |
68 | - $values = array_filter(array_map('trim', (array) $values)); |
|
69 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
70 | - return sprintf($sprintfFormat, $value); |
|
71 | - }, $values); |
|
72 | - return implode(' OR ', $values); |
|
68 | + $values = array_filter( array_map( 'trim', (array)$values ) ); |
|
69 | + $values = array_map( function( $value ) use ($sprintfFormat) { |
|
70 | + return sprintf( $sprintfFormat, $value ); |
|
71 | + }, $values ); |
|
72 | + return implode( ' OR ', $values ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -79,23 +79,23 @@ discard block |
||
79 | 79 | * @return string |
80 | 80 | * @filter posts_search |
81 | 81 | */ |
82 | - public function filterSearchByTitle($search, WP_Query $query) |
|
82 | + public function filterSearchByTitle( $search, WP_Query $query ) |
|
83 | 83 | { |
84 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
84 | + if( empty($search) || empty($query->get( 'search_terms' )) ) { |
|
85 | 85 | return $search; |
86 | 86 | } |
87 | 87 | global $wpdb; |
88 | - $n = empty($query->get('exact')) |
|
88 | + $n = empty($query->get( 'exact' )) |
|
89 | 89 | ? '%' |
90 | 90 | : ''; |
91 | 91 | $search = []; |
92 | - foreach ((array) $query->get('search_terms') as $term) { |
|
93 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
92 | + foreach( (array)$query->get( 'search_terms' ) as $term ) { |
|
93 | + $search[] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like( $term ).$n ); |
|
94 | 94 | } |
95 | - if (!is_user_logged_in()) { |
|
95 | + if( !is_user_logged_in() ) { |
|
96 | 96 | $search[] = "{$wpdb->posts}.post_password = ''"; |
97 | 97 | } |
98 | - return ' AND '.implode(' AND ', $search); |
|
98 | + return ' AND '.implode( ' AND ', $search ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | * @param bool $isEnabled |
104 | 104 | * @return int |
105 | 105 | */ |
106 | - public function getPaged($isEnabled = true) |
|
106 | + public function getPaged( $isEnabled = true ) |
|
107 | 107 | { |
108 | 108 | return $isEnabled |
109 | - ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR')))) |
|
109 | + ? max( 1, intval( filter_input( INPUT_GET, glsr()->constant( 'PAGED_QUERY_VAR' ) ) ) ) |
|
110 | 110 | : 1; |
111 | 111 | } |
112 | 112 | |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | * @param string $value |
115 | 115 | * @return void|array |
116 | 116 | */ |
117 | - protected function buildQueryAssignedTo($value) |
|
117 | + protected function buildQueryAssignedTo( $value ) |
|
118 | 118 | { |
119 | - if (!empty($value)) { |
|
120 | - $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
119 | + if( !empty($value) ) { |
|
120 | + $postIds = Arr::convertStringToArray( $value, 'is_numeric' ); |
|
121 | 121 | return [ |
122 | 122 | 'compare' => 'IN', |
123 | 123 | 'key' => '_assigned_to', |
124 | - 'value' => glsr(Multilingual::class)->getPostIds($postIds), |
|
124 | + 'value' => glsr( Multilingual::class )->getPostIds( $postIds ), |
|
125 | 125 | ]; |
126 | 126 | } |
127 | 127 | } |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | * @param array $value |
131 | 131 | * @return void|array |
132 | 132 | */ |
133 | - protected function buildQueryCategory($value) |
|
133 | + protected function buildQueryCategory( $value ) |
|
134 | 134 | { |
135 | - if (!empty($value)) { |
|
135 | + if( !empty($value) ) { |
|
136 | 136 | return [ |
137 | 137 | 'field' => 'term_id', |
138 | 138 | 'taxonomy' => Application::TAXONOMY, |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | * @param string $value |
146 | 146 | * @return void|array |
147 | 147 | */ |
148 | - protected function buildQueryEmail($value) |
|
148 | + protected function buildQueryEmail( $value ) |
|
149 | 149 | { |
150 | - if (!empty($value)) { |
|
150 | + if( !empty($value) ) { |
|
151 | 151 | return [ |
152 | 152 | 'key' => '_email', |
153 | 153 | 'value' => $value, |
@@ -159,9 +159,9 @@ discard block |
||
159 | 159 | * @param string $value |
160 | 160 | * @return void|array |
161 | 161 | */ |
162 | - protected function buildQueryIpAddress($value) |
|
162 | + protected function buildQueryIpAddress( $value ) |
|
163 | 163 | { |
164 | - if (!empty($value)) { |
|
164 | + if( !empty($value) ) { |
|
165 | 165 | return [ |
166 | 166 | 'key' => '_ip_address', |
167 | 167 | 'value' => $value, |
@@ -173,10 +173,10 @@ discard block |
||
173 | 173 | * @param string $value |
174 | 174 | * @return void|array |
175 | 175 | */ |
176 | - protected function buildQueryRating($value) |
|
176 | + protected function buildQueryRating( $value ) |
|
177 | 177 | { |
178 | - if (is_numeric($value) |
|
179 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
178 | + if( is_numeric( $value ) |
|
179 | + && in_array( intval( $value ), range( 1, glsr()->constant( 'MAX_RATING', Rating::class ) ) ) ) { |
|
180 | 180 | return [ |
181 | 181 | 'compare' => '>=', |
182 | 182 | 'key' => '_rating', |
@@ -189,9 +189,9 @@ discard block |
||
189 | 189 | * @param string $value |
190 | 190 | * @return void|array |
191 | 191 | */ |
192 | - protected function buildQueryType($value) |
|
192 | + protected function buildQueryType( $value ) |
|
193 | 193 | { |
194 | - if (!in_array($value, ['', 'all'])) { |
|
194 | + if( !in_array( $value, ['', 'all'] ) ) { |
|
195 | 195 | return [ |
196 | 196 | 'key' => '_review_type', |
197 | 197 | 'value' => $value, |
@@ -12,160 +12,160 @@ |
||
12 | 12 | |
13 | 13 | class SettingsController extends Controller |
14 | 14 | { |
15 | - /** |
|
16 | - * @param mixed $input |
|
17 | - * @return array |
|
18 | - * @callback register_setting |
|
19 | - */ |
|
20 | - public function callbackRegisterSettings($input) |
|
21 | - { |
|
22 | - $settings = Arr::consolidateArray($input); |
|
23 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
24 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
25 | - $options = $this->sanitizeGeneral($input, $options); |
|
26 | - $options = $this->sanitizeLicenses($input, $options); |
|
27 | - $options = $this->sanitizeSubmissions($input, $options); |
|
28 | - $options = $this->sanitizeTranslations($input, $options); |
|
29 | - $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
30 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
31 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
32 | - } |
|
33 | - return $options; |
|
34 | - } |
|
35 | - return $input; |
|
36 | - } |
|
15 | + /** |
|
16 | + * @param mixed $input |
|
17 | + * @return array |
|
18 | + * @callback register_setting |
|
19 | + */ |
|
20 | + public function callbackRegisterSettings($input) |
|
21 | + { |
|
22 | + $settings = Arr::consolidateArray($input); |
|
23 | + if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
24 | + $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
25 | + $options = $this->sanitizeGeneral($input, $options); |
|
26 | + $options = $this->sanitizeLicenses($input, $options); |
|
27 | + $options = $this->sanitizeSubmissions($input, $options); |
|
28 | + $options = $this->sanitizeTranslations($input, $options); |
|
29 | + $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
30 | + if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
31 | + glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
32 | + } |
|
33 | + return $options; |
|
34 | + } |
|
35 | + return $input; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return void |
|
40 | - * @action admin_init |
|
41 | - */ |
|
42 | - public function registerSettings() |
|
43 | - { |
|
44 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
45 | - 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
46 | - ]); |
|
47 | - } |
|
38 | + /** |
|
39 | + * @return void |
|
40 | + * @action admin_init |
|
41 | + */ |
|
42 | + public function registerSettings() |
|
43 | + { |
|
44 | + register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
45 | + 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
46 | + ]); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - protected function sanitizeGeneral(array $input, array $options) |
|
53 | - { |
|
54 | - $key = 'settings.general'; |
|
55 | - $inputForm = Arr::get($input, $key); |
|
56 | - if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
57 | - $options = Arr::set($options, $key.'.multilingual', ''); |
|
58 | - } |
|
59 | - if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
60 | - $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
61 | - $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
62 | - } |
|
63 | - $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
64 | - $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
65 | - return $options; |
|
66 | - } |
|
49 | + /** |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + protected function sanitizeGeneral(array $input, array $options) |
|
53 | + { |
|
54 | + $key = 'settings.general'; |
|
55 | + $inputForm = Arr::get($input, $key); |
|
56 | + if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
57 | + $options = Arr::set($options, $key.'.multilingual', ''); |
|
58 | + } |
|
59 | + if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
60 | + $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
61 | + $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
62 | + } |
|
63 | + $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
64 | + $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
65 | + return $options; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - protected function sanitizeLicenses(array $input, array $options) |
|
72 | - { |
|
73 | - $key = 'settings.licenses'; |
|
74 | - $licenses = Arr::consolidateArray(Arr::get($input, $key)); |
|
75 | - foreach ($licenses as $slug => &$license) { |
|
76 | - $license = $this->verifyLicense($license, $slug); |
|
77 | - } |
|
78 | - $options = Arr::set($options, $key, $licenses); |
|
79 | - return $options; |
|
80 | - } |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + protected function sanitizeLicenses(array $input, array $options) |
|
72 | + { |
|
73 | + $key = 'settings.licenses'; |
|
74 | + $licenses = Arr::consolidateArray(Arr::get($input, $key)); |
|
75 | + foreach ($licenses as $slug => &$license) { |
|
76 | + $license = $this->verifyLicense($license, $slug); |
|
77 | + } |
|
78 | + $options = Arr::set($options, $key, $licenses); |
|
79 | + return $options; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - protected function sanitizeSubmissions(array $input, array $options) |
|
86 | - { |
|
87 | - $key = 'settings.submissions'; |
|
88 | - $inputForm = Arr::get($input, $key); |
|
89 | - $defaultValue = isset($inputForm['required']) |
|
90 | - ? $inputForm['required'] |
|
91 | - : []; |
|
92 | - $options = Arr::set($options, $key.'.required', $defaultValue); |
|
93 | - return $options; |
|
94 | - } |
|
82 | + /** |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + protected function sanitizeSubmissions(array $input, array $options) |
|
86 | + { |
|
87 | + $key = 'settings.submissions'; |
|
88 | + $inputForm = Arr::get($input, $key); |
|
89 | + $defaultValue = isset($inputForm['required']) |
|
90 | + ? $inputForm['required'] |
|
91 | + : []; |
|
92 | + $options = Arr::set($options, $key.'.required', $defaultValue); |
|
93 | + return $options; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - protected function sanitizeTranslations(array $input, array $options) |
|
100 | - { |
|
101 | - $key = 'settings.strings'; |
|
102 | - $inputForm = Arr::consolidateArray(Arr::get($input, $key)); |
|
103 | - if (!empty($inputForm)) { |
|
104 | - $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
105 | - $allowedTags = [ |
|
106 | - 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
107 | - 'span' => ['class' => []], |
|
108 | - ]; |
|
109 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
110 | - if (isset($string['s2'])) { |
|
111 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
112 | - } |
|
113 | - if (isset($string['p2'])) { |
|
114 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
115 | - } |
|
116 | - }); |
|
117 | - } |
|
118 | - return $options; |
|
119 | - } |
|
96 | + /** |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + protected function sanitizeTranslations(array $input, array $options) |
|
100 | + { |
|
101 | + $key = 'settings.strings'; |
|
102 | + $inputForm = Arr::consolidateArray(Arr::get($input, $key)); |
|
103 | + if (!empty($inputForm)) { |
|
104 | + $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
105 | + $allowedTags = [ |
|
106 | + 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
107 | + 'span' => ['class' => []], |
|
108 | + ]; |
|
109 | + array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
110 | + if (isset($string['s2'])) { |
|
111 | + $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
112 | + } |
|
113 | + if (isset($string['p2'])) { |
|
114 | + $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
115 | + } |
|
116 | + }); |
|
117 | + } |
|
118 | + return $options; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @param string $integrationSlug |
|
123 | - * @return bool |
|
124 | - */ |
|
125 | - protected function hasMultilingualIntegration($integrationSlug) |
|
126 | - { |
|
127 | - $integration = glsr(Multilingual::class)->getIntegration($integrationSlug); |
|
128 | - if (!$integration) { |
|
129 | - return false; |
|
130 | - } |
|
131 | - if (!$integration->isActive()) { |
|
132 | - glsr(Notice::class)->addError(sprintf( |
|
133 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
134 | - $integration->pluginName |
|
135 | - )); |
|
136 | - return false; |
|
137 | - } elseif (!$integration->isSupported()) { |
|
138 | - glsr(Notice::class)->addError(sprintf( |
|
139 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
140 | - $integration->pluginName, |
|
141 | - $integration->supportedVersion |
|
142 | - )); |
|
143 | - return false; |
|
144 | - } |
|
145 | - return true; |
|
146 | - } |
|
121 | + /** |
|
122 | + * @param string $integrationSlug |
|
123 | + * @return bool |
|
124 | + */ |
|
125 | + protected function hasMultilingualIntegration($integrationSlug) |
|
126 | + { |
|
127 | + $integration = glsr(Multilingual::class)->getIntegration($integrationSlug); |
|
128 | + if (!$integration) { |
|
129 | + return false; |
|
130 | + } |
|
131 | + if (!$integration->isActive()) { |
|
132 | + glsr(Notice::class)->addError(sprintf( |
|
133 | + __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
134 | + $integration->pluginName |
|
135 | + )); |
|
136 | + return false; |
|
137 | + } elseif (!$integration->isSupported()) { |
|
138 | + glsr(Notice::class)->addError(sprintf( |
|
139 | + __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
140 | + $integration->pluginName, |
|
141 | + $integration->supportedVersion |
|
142 | + )); |
|
143 | + return false; |
|
144 | + } |
|
145 | + return true; |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * @param string $license |
|
150 | - * @param string $slug |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - protected function verifyLicense($license, $slug) |
|
154 | - { |
|
155 | - try { |
|
156 | - $addon = glsr($slug); |
|
157 | - $updater = new Updater($addon->update_url, $addon->file, [ |
|
158 | - 'license' => $license, |
|
159 | - 'testedTo' => $addon->testedTo, |
|
160 | - ]); |
|
161 | - if (!$updater->isLicenseValid()) { |
|
162 | - throw new Exception('Invalid license: '.$license.' ('.$addon->id.')'); |
|
163 | - } |
|
164 | - } catch (Exception $e) { |
|
165 | - $license = ''; |
|
166 | - glsr_log()->debug($e->getMessage()); |
|
167 | - glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews')); |
|
168 | - } |
|
169 | - return $license; |
|
170 | - } |
|
148 | + /** |
|
149 | + * @param string $license |
|
150 | + * @param string $slug |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + protected function verifyLicense($license, $slug) |
|
154 | + { |
|
155 | + try { |
|
156 | + $addon = glsr($slug); |
|
157 | + $updater = new Updater($addon->update_url, $addon->file, [ |
|
158 | + 'license' => $license, |
|
159 | + 'testedTo' => $addon->testedTo, |
|
160 | + ]); |
|
161 | + if (!$updater->isLicenseValid()) { |
|
162 | + throw new Exception('Invalid license: '.$license.' ('.$addon->id.')'); |
|
163 | + } |
|
164 | + } catch (Exception $e) { |
|
165 | + $license = ''; |
|
166 | + glsr_log()->debug($e->getMessage()); |
|
167 | + glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews')); |
|
168 | + } |
|
169 | + return $license; |
|
170 | + } |
|
171 | 171 | } |
@@ -17,18 +17,18 @@ discard block |
||
17 | 17 | * @return array |
18 | 18 | * @callback register_setting |
19 | 19 | */ |
20 | - public function callbackRegisterSettings($input) |
|
20 | + public function callbackRegisterSettings( $input ) |
|
21 | 21 | { |
22 | - $settings = Arr::consolidateArray($input); |
|
23 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
24 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
25 | - $options = $this->sanitizeGeneral($input, $options); |
|
26 | - $options = $this->sanitizeLicenses($input, $options); |
|
27 | - $options = $this->sanitizeSubmissions($input, $options); |
|
28 | - $options = $this->sanitizeTranslations($input, $options); |
|
29 | - $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
30 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
31 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
22 | + $settings = Arr::consolidateArray( $input ); |
|
23 | + if( 1 === count( $settings ) && array_key_exists( 'settings', $settings ) ) { |
|
24 | + $options = array_replace_recursive( glsr( OptionManager::class )->all(), $input ); |
|
25 | + $options = $this->sanitizeGeneral( $input, $options ); |
|
26 | + $options = $this->sanitizeLicenses( $input, $options ); |
|
27 | + $options = $this->sanitizeSubmissions( $input, $options ); |
|
28 | + $options = $this->sanitizeTranslations( $input, $options ); |
|
29 | + $options = apply_filters( 'site-reviews/settings/callback', $options, $settings ); |
|
30 | + if( filter_input( INPUT_POST, 'option_page' ) == Application::ID.'-settings' ) { |
|
31 | + glsr( Notice::class )->addSuccess( __( 'Settings updated.', 'site-reviews' ) ); |
|
32 | 32 | } |
33 | 33 | return $options; |
34 | 34 | } |
@@ -41,77 +41,77 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function registerSettings() |
43 | 43 | { |
44 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
44 | + register_setting( Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
45 | 45 | 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
46 | - ]); |
|
46 | + ] ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - protected function sanitizeGeneral(array $input, array $options) |
|
52 | + protected function sanitizeGeneral( array $input, array $options ) |
|
53 | 53 | { |
54 | 54 | $key = 'settings.general'; |
55 | - $inputForm = Arr::get($input, $key); |
|
56 | - if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
57 | - $options = Arr::set($options, $key.'.multilingual', ''); |
|
55 | + $inputForm = Arr::get( $input, $key ); |
|
56 | + if( !$this->hasMultilingualIntegration( Arr::get( $inputForm, 'multilingual' ) ) ) { |
|
57 | + $options = Arr::set( $options, $key.'.multilingual', '' ); |
|
58 | 58 | } |
59 | - if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
60 | - $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
61 | - $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
59 | + if( '' == trim( Arr::get( $inputForm, 'notification_message' ) ) ) { |
|
60 | + $defaultValue = Arr::get( glsr()->defaults, $key.'.notification_message' ); |
|
61 | + $options = Arr::set( $options, $key.'.notification_message', $defaultValue ); |
|
62 | 62 | } |
63 | - $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
64 | - $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
63 | + $defaultValue = Arr::get( $inputForm, 'notifications', [] ); |
|
64 | + $options = Arr::set( $options, $key.'.notifications', $defaultValue ); |
|
65 | 65 | return $options; |
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @return array |
70 | 70 | */ |
71 | - protected function sanitizeLicenses(array $input, array $options) |
|
71 | + protected function sanitizeLicenses( array $input, array $options ) |
|
72 | 72 | { |
73 | 73 | $key = 'settings.licenses'; |
74 | - $licenses = Arr::consolidateArray(Arr::get($input, $key)); |
|
75 | - foreach ($licenses as $slug => &$license) { |
|
76 | - $license = $this->verifyLicense($license, $slug); |
|
74 | + $licenses = Arr::consolidateArray( Arr::get( $input, $key ) ); |
|
75 | + foreach( $licenses as $slug => &$license ) { |
|
76 | + $license = $this->verifyLicense( $license, $slug ); |
|
77 | 77 | } |
78 | - $options = Arr::set($options, $key, $licenses); |
|
78 | + $options = Arr::set( $options, $key, $licenses ); |
|
79 | 79 | return $options; |
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * @return array |
84 | 84 | */ |
85 | - protected function sanitizeSubmissions(array $input, array $options) |
|
85 | + protected function sanitizeSubmissions( array $input, array $options ) |
|
86 | 86 | { |
87 | 87 | $key = 'settings.submissions'; |
88 | - $inputForm = Arr::get($input, $key); |
|
88 | + $inputForm = Arr::get( $input, $key ); |
|
89 | 89 | $defaultValue = isset($inputForm['required']) |
90 | 90 | ? $inputForm['required'] |
91 | 91 | : []; |
92 | - $options = Arr::set($options, $key.'.required', $defaultValue); |
|
92 | + $options = Arr::set( $options, $key.'.required', $defaultValue ); |
|
93 | 93 | return $options; |
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | 97 | * @return array |
98 | 98 | */ |
99 | - protected function sanitizeTranslations(array $input, array $options) |
|
99 | + protected function sanitizeTranslations( array $input, array $options ) |
|
100 | 100 | { |
101 | 101 | $key = 'settings.strings'; |
102 | - $inputForm = Arr::consolidateArray(Arr::get($input, $key)); |
|
103 | - if (!empty($inputForm)) { |
|
104 | - $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
102 | + $inputForm = Arr::consolidateArray( Arr::get( $input, $key ) ); |
|
103 | + if( !empty($inputForm) ) { |
|
104 | + $options = Arr::set( $options, $key, array_values( array_filter( $inputForm ) ) ); |
|
105 | 105 | $allowedTags = [ |
106 | 106 | 'a' => ['class' => [], 'href' => [], 'target' => []], |
107 | 107 | 'span' => ['class' => []], |
108 | 108 | ]; |
109 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
110 | - if (isset($string['s2'])) { |
|
111 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
109 | + array_walk( $options['settings']['strings'], function( &$string ) use ($allowedTags) { |
|
110 | + if( isset($string['s2']) ) { |
|
111 | + $string['s2'] = wp_kses( $string['s2'], $allowedTags ); |
|
112 | 112 | } |
113 | - if (isset($string['p2'])) { |
|
114 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
113 | + if( isset($string['p2']) ) { |
|
114 | + $string['p2'] = wp_kses( $string['p2'], $allowedTags ); |
|
115 | 115 | } |
116 | 116 | }); |
117 | 117 | } |
@@ -122,24 +122,24 @@ discard block |
||
122 | 122 | * @param string $integrationSlug |
123 | 123 | * @return bool |
124 | 124 | */ |
125 | - protected function hasMultilingualIntegration($integrationSlug) |
|
125 | + protected function hasMultilingualIntegration( $integrationSlug ) |
|
126 | 126 | { |
127 | - $integration = glsr(Multilingual::class)->getIntegration($integrationSlug); |
|
128 | - if (!$integration) { |
|
127 | + $integration = glsr( Multilingual::class )->getIntegration( $integrationSlug ); |
|
128 | + if( !$integration ) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | - if (!$integration->isActive()) { |
|
132 | - glsr(Notice::class)->addError(sprintf( |
|
133 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
131 | + if( !$integration->isActive() ) { |
|
132 | + glsr( Notice::class )->addError( sprintf( |
|
133 | + __( 'Please install/activate the %s plugin to enable integration.', 'site-reviews' ), |
|
134 | 134 | $integration->pluginName |
135 | - )); |
|
135 | + ) ); |
|
136 | 136 | return false; |
137 | - } elseif (!$integration->isSupported()) { |
|
138 | - glsr(Notice::class)->addError(sprintf( |
|
139 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
137 | + } elseif( !$integration->isSupported() ) { |
|
138 | + glsr( Notice::class )->addError( sprintf( |
|
139 | + __( 'Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews' ), |
|
140 | 140 | $integration->pluginName, |
141 | 141 | $integration->supportedVersion |
142 | - )); |
|
142 | + ) ); |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | return true; |
@@ -150,21 +150,21 @@ discard block |
||
150 | 150 | * @param string $slug |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - protected function verifyLicense($license, $slug) |
|
153 | + protected function verifyLicense( $license, $slug ) |
|
154 | 154 | { |
155 | 155 | try { |
156 | - $addon = glsr($slug); |
|
157 | - $updater = new Updater($addon->update_url, $addon->file, [ |
|
156 | + $addon = glsr( $slug ); |
|
157 | + $updater = new Updater( $addon->update_url, $addon->file, [ |
|
158 | 158 | 'license' => $license, |
159 | 159 | 'testedTo' => $addon->testedTo, |
160 | - ]); |
|
161 | - if (!$updater->isLicenseValid()) { |
|
162 | - throw new Exception('Invalid license: '.$license.' ('.$addon->id.')'); |
|
160 | + ] ); |
|
161 | + if( !$updater->isLicenseValid() ) { |
|
162 | + throw new Exception( 'Invalid license: '.$license.' ('.$addon->id.')' ); |
|
163 | 163 | } |
164 | - } catch (Exception $e) { |
|
164 | + } catch( Exception $e ) { |
|
165 | 165 | $license = ''; |
166 | - glsr_log()->debug($e->getMessage()); |
|
167 | - glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews')); |
|
166 | + glsr_log()->debug( $e->getMessage() ); |
|
167 | + glsr( Notice::class )->addError( __( 'A license you entered was invalid.', 'site-reviews' ) ); |
|
168 | 168 | } |
169 | 169 | return $license; |
170 | 170 | } |
@@ -10,52 +10,52 @@ |
||
10 | 10 | |
11 | 11 | class Pagination implements PartialContract |
12 | 12 | { |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $args; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $args; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return string |
|
20 | - */ |
|
21 | - public function build(array $args = []) |
|
22 | - { |
|
23 | - $this->args = $this->normalize($args); |
|
24 | - if ($this->args['total'] < 2) { |
|
25 | - return ''; |
|
26 | - } |
|
27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
28 | - 'context' => [ |
|
29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
30 | - 'loader' => '<div class="glsr-loader"></div>', |
|
31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
32 | - ], |
|
33 | - ]); |
|
34 | - } |
|
18 | + /** |
|
19 | + * @return string |
|
20 | + */ |
|
21 | + public function build(array $args = []) |
|
22 | + { |
|
23 | + $this->args = $this->normalize($args); |
|
24 | + if ($this->args['total'] < 2) { |
|
25 | + return ''; |
|
26 | + } |
|
27 | + return glsr(Template::class)->build('templates/pagination', [ |
|
28 | + 'context' => [ |
|
29 | + 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
30 | + 'loader' => '<div class="glsr-loader"></div>', |
|
31 | + 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
32 | + ], |
|
33 | + ]); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - protected function buildLinks() |
|
40 | - { |
|
41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | - if ('array' == $args['type']) { |
|
43 | - $args['type'] = 'plain'; |
|
44 | - } |
|
45 | - return paginate_links($args); |
|
46 | - } |
|
36 | + /** |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + protected function buildLinks() |
|
40 | + { |
|
41 | + $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | + if ('array' == $args['type']) { |
|
43 | + $args['type'] = 'plain'; |
|
44 | + } |
|
45 | + return paginate_links($args); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - protected function normalize(array $args) |
|
52 | - { |
|
53 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
54 | - $args['base'] = $baseUrl.'%_%'; |
|
55 | - } |
|
56 | - return wp_parse_args(array_filter($args), [ |
|
57 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
58 | - 'total' => 1, |
|
59 | - ]); |
|
60 | - } |
|
48 | + /** |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + protected function normalize(array $args) |
|
52 | + { |
|
53 | + if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
54 | + $args['base'] = $baseUrl.'%_%'; |
|
55 | + } |
|
56 | + return wp_parse_args(array_filter($args), [ |
|
57 | + 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
58 | + 'total' => 1, |
|
59 | + ]); |
|
60 | + } |
|
61 | 61 | } |
@@ -18,19 +18,19 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @return string |
20 | 20 | */ |
21 | - public function build(array $args = []) |
|
21 | + public function build( array $args = [] ) |
|
22 | 22 | { |
23 | - $this->args = $this->normalize($args); |
|
24 | - if ($this->args['total'] < 2) { |
|
23 | + $this->args = $this->normalize( $args ); |
|
24 | + if( $this->args['total'] < 2 ) { |
|
25 | 25 | return ''; |
26 | 26 | } |
27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
27 | + return glsr( Template::class )->build( 'templates/pagination', [ |
|
28 | 28 | 'context' => [ |
29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
29 | + 'links' => apply_filters( 'site-reviews/paginate_links', $this->buildLinks(), $this->args ), |
|
30 | 30 | 'loader' => '<div class="glsr-loader"></div>', |
31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
31 | + 'screen_reader_text' => __( 'Site Reviews navigation', 'site-reviews' ), |
|
32 | 32 | ], |
33 | - ]); |
|
33 | + ] ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,24 +38,24 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected function buildLinks() |
40 | 40 | { |
41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | - if ('array' == $args['type']) { |
|
41 | + $args = glsr( Style::class )->paginationArgs( $this->args ); |
|
42 | + if( 'array' == $args['type'] ) { |
|
43 | 43 | $args['type'] = 'plain'; |
44 | 44 | } |
45 | - return paginate_links($args); |
|
45 | + return paginate_links( $args ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | 49 | * @return array |
50 | 50 | */ |
51 | - protected function normalize(array $args) |
|
51 | + protected function normalize( array $args ) |
|
52 | 52 | { |
53 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
53 | + if( $baseUrl = Arr::get( $args, 'baseUrl' ) ) { |
|
54 | 54 | $args['base'] = $baseUrl.'%_%'; |
55 | 55 | } |
56 | - return wp_parse_args(array_filter($args), [ |
|
57 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
56 | + return wp_parse_args( array_filter( $args ), [ |
|
57 | + 'current' => glsr( QueryBuilder::class )->getPaged(), |
|
58 | 58 | 'total' => 1, |
59 | - ]); |
|
59 | + ] ); |
|
60 | 60 | } |
61 | 61 | } |
@@ -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 $renderedReviews, $maxPageCount, array $args) |
|
32 | - { |
|
33 | - $this->args = $args; |
|
34 | - $this->max_num_pages = $maxPageCount; |
|
35 | - $this->reviews = $renderedReviews; |
|
36 | - $this->pagination = $this->buildPagination(); |
|
37 | - parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
38 | - } |
|
31 | + public function __construct(array $renderedReviews, $maxPageCount, array $args) |
|
32 | + { |
|
33 | + $this->args = $args; |
|
34 | + $this->max_num_pages = $maxPageCount; |
|
35 | + $this->reviews = $renderedReviews; |
|
36 | + $this->pagination = $this->buildPagination(); |
|
37 | + parent::__construct($renderedReviews, 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 (array_key_exists($key, $this->reviews)) { |
|
92 | - return $this->reviews[$key]; |
|
93 | - } |
|
94 | - return property_exists($this, $key) |
|
95 | - ? $this->$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 (array_key_exists($key, $this->reviews)) { |
|
92 | + return $this->reviews[$key]; |
|
93 | + } |
|
94 | + return property_exists($this, $key) |
|
95 | + ? $this->$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 $renderedReviews, $maxPageCount, array $args) |
|
31 | + public function __construct( array $renderedReviews, $maxPageCount, array $args ) |
|
32 | 32 | { |
33 | 33 | $this->args = $args; |
34 | 34 | $this->max_num_pages = $maxPageCount; |
35 | 35 | $this->reviews = $renderedReviews; |
36 | 36 | $this->pagination = $this->buildPagination(); |
37 | - parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
37 | + parent::__construct( $renderedReviews, 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 (array_key_exists($key, $this->reviews)) { |
|
91 | + if( array_key_exists( $key, $this->reviews ) ) { |
|
92 | 92 | return $this->reviews[$key]; |
93 | 93 | } |
94 | - return property_exists($this, $key) |
|
94 | + return property_exists( $this, $key ) |
|
95 | 95 | ? $this->$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 | } |
@@ -8,54 +8,54 @@ |
||
8 | 8 | |
9 | 9 | class StarRating implements PartialContract |
10 | 10 | { |
11 | - protected $prefix; |
|
12 | - protected $rating; |
|
11 | + protected $prefix; |
|
12 | + protected $rating; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @return string |
|
16 | - */ |
|
17 | - public function build(array $args = []) |
|
18 | - { |
|
19 | - $this->setProperties($args); |
|
20 | - $fullStars = intval(floor($this->rating)); |
|
21 | - $halfStars = intval(ceil($this->rating - $fullStars)); |
|
22 | - $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars); |
|
23 | - return glsr(Template::class)->build('templates/rating/stars', [ |
|
24 | - 'context' => [ |
|
25 | - 'empty_stars' => $this->getTemplate('empty-star', $emptyStars), |
|
26 | - 'full_stars' => $this->getTemplate('full-star', $fullStars), |
|
27 | - 'half_stars' => $this->getTemplate('half-star', $halfStars), |
|
28 | - 'prefix' => $this->prefix, |
|
29 | - 'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)), |
|
30 | - ], |
|
31 | - ]); |
|
32 | - } |
|
14 | + /** |
|
15 | + * @return string |
|
16 | + */ |
|
17 | + public function build(array $args = []) |
|
18 | + { |
|
19 | + $this->setProperties($args); |
|
20 | + $fullStars = intval(floor($this->rating)); |
|
21 | + $halfStars = intval(ceil($this->rating - $fullStars)); |
|
22 | + $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars); |
|
23 | + return glsr(Template::class)->build('templates/rating/stars', [ |
|
24 | + 'context' => [ |
|
25 | + 'empty_stars' => $this->getTemplate('empty-star', $emptyStars), |
|
26 | + 'full_stars' => $this->getTemplate('full-star', $fullStars), |
|
27 | + 'half_stars' => $this->getTemplate('half-star', $halfStars), |
|
28 | + 'prefix' => $this->prefix, |
|
29 | + 'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)), |
|
30 | + ], |
|
31 | + ]); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param string $templateName |
|
36 | - * @param int $timesRepeated |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - protected function getTemplate($templateName, $timesRepeated) |
|
40 | - { |
|
41 | - $template = glsr(Template::class)->build('templates/rating/'.$templateName, [ |
|
42 | - 'context' => [ |
|
43 | - 'prefix' => $this->prefix, |
|
44 | - ], |
|
45 | - ]); |
|
46 | - return str_repeat($template, $timesRepeated); |
|
47 | - } |
|
34 | + /** |
|
35 | + * @param string $templateName |
|
36 | + * @param int $timesRepeated |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + protected function getTemplate($templateName, $timesRepeated) |
|
40 | + { |
|
41 | + $template = glsr(Template::class)->build('templates/rating/'.$templateName, [ |
|
42 | + 'context' => [ |
|
43 | + 'prefix' => $this->prefix, |
|
44 | + ], |
|
45 | + ]); |
|
46 | + return str_repeat($template, $timesRepeated); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - protected function setProperties(array $args) |
|
53 | - { |
|
54 | - $args = wp_parse_args($args, [ |
|
55 | - 'prefix' => glsr()->isAdmin() ? '' : 'glsr-', |
|
56 | - 'rating' => 0, |
|
57 | - ]); |
|
58 | - $this->prefix = $args['prefix']; |
|
59 | - $this->rating = (float) str_replace(',', '.', $args['rating']); |
|
60 | - } |
|
49 | + /** |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + protected function setProperties(array $args) |
|
53 | + { |
|
54 | + $args = wp_parse_args($args, [ |
|
55 | + 'prefix' => glsr()->isAdmin() ? '' : 'glsr-', |
|
56 | + 'rating' => 0, |
|
57 | + ]); |
|
58 | + $this->prefix = $args['prefix']; |
|
59 | + $this->rating = (float) str_replace(',', '.', $args['rating']); |
|
60 | + } |
|
61 | 61 | } |
@@ -14,21 +14,21 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @return string |
16 | 16 | */ |
17 | - public function build(array $args = []) |
|
17 | + public function build( array $args = [] ) |
|
18 | 18 | { |
19 | - $this->setProperties($args); |
|
20 | - $fullStars = intval(floor($this->rating)); |
|
21 | - $halfStars = intval(ceil($this->rating - $fullStars)); |
|
22 | - $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars); |
|
23 | - return glsr(Template::class)->build('templates/rating/stars', [ |
|
19 | + $this->setProperties( $args ); |
|
20 | + $fullStars = intval( floor( $this->rating ) ); |
|
21 | + $halfStars = intval( ceil( $this->rating - $fullStars ) ); |
|
22 | + $emptyStars = max( 0, glsr()->constant( 'MAX_RATING', Rating::class ) - $fullStars - $halfStars ); |
|
23 | + return glsr( Template::class )->build( 'templates/rating/stars', [ |
|
24 | 24 | 'context' => [ |
25 | - 'empty_stars' => $this->getTemplate('empty-star', $emptyStars), |
|
26 | - 'full_stars' => $this->getTemplate('full-star', $fullStars), |
|
27 | - 'half_stars' => $this->getTemplate('half-star', $halfStars), |
|
25 | + 'empty_stars' => $this->getTemplate( 'empty-star', $emptyStars ), |
|
26 | + 'full_stars' => $this->getTemplate( 'full-star', $fullStars ), |
|
27 | + 'half_stars' => $this->getTemplate( 'half-star', $halfStars ), |
|
28 | 28 | 'prefix' => $this->prefix, |
29 | - 'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)), |
|
29 | + 'title' => sprintf( __( '%s rating', 'site-reviews' ), number_format_i18n( $this->rating, 1 ) ), |
|
30 | 30 | ], |
31 | - ]); |
|
31 | + ] ); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -36,26 +36,26 @@ discard block |
||
36 | 36 | * @param int $timesRepeated |
37 | 37 | * @return string |
38 | 38 | */ |
39 | - protected function getTemplate($templateName, $timesRepeated) |
|
39 | + protected function getTemplate( $templateName, $timesRepeated ) |
|
40 | 40 | { |
41 | - $template = glsr(Template::class)->build('templates/rating/'.$templateName, [ |
|
41 | + $template = glsr( Template::class )->build( 'templates/rating/'.$templateName, [ |
|
42 | 42 | 'context' => [ |
43 | 43 | 'prefix' => $this->prefix, |
44 | 44 | ], |
45 | - ]); |
|
46 | - return str_repeat($template, $timesRepeated); |
|
45 | + ] ); |
|
46 | + return str_repeat( $template, $timesRepeated ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - protected function setProperties(array $args) |
|
52 | + protected function setProperties( array $args ) |
|
53 | 53 | { |
54 | - $args = wp_parse_args($args, [ |
|
54 | + $args = wp_parse_args( $args, [ |
|
55 | 55 | 'prefix' => glsr()->isAdmin() ? '' : 'glsr-', |
56 | 56 | 'rating' => 0, |
57 | - ]); |
|
57 | + ] ); |
|
58 | 58 | $this->prefix = $args['prefix']; |
59 | - $this->rating = (float) str_replace(',', '.', $args['rating']); |
|
59 | + $this->rating = (float)str_replace( ',', '.', $args['rating'] ); |
|
60 | 60 | } |
61 | 61 | } |