@@ -12,10 +12,10 @@ discard block |
||
12 | 12 | * @param string $test |
13 | 13 | * @return string |
14 | 14 | */ |
15 | - public function filterPostStatusLabels($translation, $text) |
|
15 | + public function filterPostStatusLabels( $translation, $text ) |
|
16 | 16 | { |
17 | 17 | $replacements = $this->getStatusLabels(); |
18 | - return array_key_exists($text, $replacements) |
|
18 | + return array_key_exists( $text, $replacements ) |
|
19 | 19 | ? $replacements[$text] |
20 | 20 | : $translation; |
21 | 21 | } |
@@ -23,18 +23,18 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * @return array |
25 | 25 | */ |
26 | - public function filterUpdateMessages(array $messages) |
|
26 | + public function filterUpdateMessages( array $messages ) |
|
27 | 27 | { |
28 | 28 | $post = get_post(); |
29 | - if (!($post instanceof WP_Post)) { |
|
29 | + if( !($post instanceof WP_Post) ) { |
|
30 | 30 | return; |
31 | 31 | } |
32 | 32 | $strings = $this->getReviewLabels(); |
33 | - $restored = filter_input(INPUT_GET, 'revision'); |
|
34 | - if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
35 | - $restored = sprintf($strings['restored'], $revisionTitle); |
|
33 | + $restored = filter_input( INPUT_GET, 'revision' ); |
|
34 | + if( $revisionTitle = wp_post_revision_title( intval( $restored ), false ) ) { |
|
35 | + $restored = sprintf( $strings['restored'], $revisionTitle ); |
|
36 | 36 | } |
37 | - $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
37 | + $scheduled_date = date_i18n( 'M j, Y @ H:i', strtotime( $post->post_date ) ); |
|
38 | 38 | $messages[Application::POST_TYPE] = [ |
39 | 39 | 1 => $strings['updated'], |
40 | 40 | 4 => $strings['updated'], |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | 6 => $strings['published'], |
43 | 43 | 7 => $strings['saved'], |
44 | 44 | 8 => $strings['submitted'], |
45 | - 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
45 | + 9 => sprintf( $strings['scheduled'], '<strong>'.$scheduled_date.'</strong>' ), |
|
46 | 46 | 10 => $strings['draft_updated'], |
47 | 47 | 50 => $strings['approved'], |
48 | 48 | 51 => $strings['unapproved'], |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | { |
59 | 59 | global $wp_scripts; |
60 | 60 | $strings = [ |
61 | - 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
62 | - 'published' => __('Approved', 'site-reviews'), |
|
61 | + 'savePending' => __( 'Save as Unapproved', 'site-reviews' ), |
|
62 | + 'published' => __( 'Approved', 'site-reviews' ), |
|
63 | 63 | ]; |
64 | - if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
64 | + if( isset($wp_scripts->registered['post']->extra['data']) ) { |
|
65 | 65 | $l10n = &$wp_scripts->registered['post']->extra['data']; |
66 | - foreach ($strings as $search => $replace) { |
|
67 | - $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n); |
|
66 | + foreach( $strings as $search => $replace ) { |
|
67 | + $l10n = preg_replace( '/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n ); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | } |
@@ -75,18 +75,18 @@ discard block |
||
75 | 75 | protected function getReviewLabels() |
76 | 76 | { |
77 | 77 | return [ |
78 | - 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
79 | - 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
80 | - 'preview' => __('Preview review', 'site-reviews'), |
|
81 | - 'published' => __('Review approved and published.', 'site-reviews'), |
|
82 | - 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
83 | - 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
84 | - 'saved' => __('Review saved.', 'site-reviews'), |
|
85 | - 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
86 | - 'submitted' => __('Review submitted.', 'site-reviews'), |
|
87 | - 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
88 | - 'updated' => __('Review updated.', 'site-reviews'), |
|
89 | - 'view' => __('View review', 'site-reviews'), |
|
78 | + 'approved' => __( 'Review has been approved and published.', 'site-reviews' ), |
|
79 | + 'draft_updated' => __( 'Review draft updated.', 'site-reviews' ), |
|
80 | + 'preview' => __( 'Preview review', 'site-reviews' ), |
|
81 | + 'published' => __( 'Review approved and published.', 'site-reviews' ), |
|
82 | + 'restored' => __( 'Review restored to revision from %s.', 'site-reviews' ), |
|
83 | + 'reverted' => __( 'Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews' ), |
|
84 | + 'saved' => __( 'Review saved.', 'site-reviews' ), |
|
85 | + 'scheduled' => __( 'Review scheduled for: %s.', 'site-reviews' ), |
|
86 | + 'submitted' => __( 'Review submitted.', 'site-reviews' ), |
|
87 | + 'unapproved' => __( 'Review has been unapproved and is now pending.', 'site-reviews' ), |
|
88 | + 'updated' => __( 'Review updated.', 'site-reviews' ), |
|
89 | + 'view' => __( 'View review', 'site-reviews' ), |
|
90 | 90 | ]; |
91 | 91 | } |
92 | 92 | |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | protected function getStatusLabels() |
98 | 98 | { |
99 | 99 | static $labels; |
100 | - if (empty($labels)) { |
|
100 | + if( empty($labels) ) { |
|
101 | 101 | $labels = [ |
102 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
103 | - 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
104 | - 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
105 | - 'Publish' => __('Approve', 'site-reviews'), |
|
106 | - 'Published' => __('Approved', 'site-reviews'), |
|
107 | - 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
102 | + 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
103 | + 'Pending Review' => __( 'Unapproved', 'site-reviews' ), |
|
104 | + 'Privately Published' => __( 'Privately Approved', 'site-reviews' ), |
|
105 | + 'Publish' => __( 'Approve', 'site-reviews' ), |
|
106 | + 'Published' => __( 'Approved', 'site-reviews' ), |
|
107 | + 'Save as Pending' => __( 'Save as Unapproved', 'site-reviews' ), |
|
108 | 108 | ]; |
109 | 109 | } |
110 | 110 | return $labels; |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | * @return array |
26 | 26 | * @filter wp_editor_settings |
27 | 27 | */ |
28 | - public function filterEditorSettings($settings) |
|
28 | + public function filterEditorSettings( $settings ) |
|
29 | 29 | { |
30 | - return glsr(Customization::class)->filterEditorSettings( |
|
31 | - Arr::consolidateArray($settings) |
|
30 | + return glsr( Customization::class )->filterEditorSettings( |
|
31 | + Arr::consolidateArray( $settings ) |
|
32 | 32 | ); |
33 | 33 | } |
34 | 34 | |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | * @return string |
39 | 39 | * @filter the_editor |
40 | 40 | */ |
41 | - public function filterEditorTextarea($html) |
|
41 | + public function filterEditorTextarea( $html ) |
|
42 | 42 | { |
43 | - return glsr(Customization::class)->filterEditorTextarea($html); |
|
43 | + return glsr( Customization::class )->filterEditorTextarea( $html ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | * @return bool |
51 | 51 | * @filter is_protected_meta |
52 | 52 | */ |
53 | - public function filterIsProtectedMeta($protected, $metaKey, $metaType) |
|
53 | + public function filterIsProtectedMeta( $protected, $metaKey, $metaType ) |
|
54 | 54 | { |
55 | - if ('post' == $metaType && Application::POST_TYPE == get_post_type()) { |
|
56 | - $values = glsr(CreateReviewDefaults::class)->unguarded(); |
|
57 | - $values = Arr::prefixArrayKeys($values); |
|
58 | - if (array_key_exists($metaKey, $values)) { |
|
55 | + if( 'post' == $metaType && Application::POST_TYPE == get_post_type() ) { |
|
56 | + $values = glsr( CreateReviewDefaults::class )->unguarded(); |
|
57 | + $values = Arr::prefixArrayKeys( $values ); |
|
58 | + if( array_key_exists( $metaKey, $values ) ) { |
|
59 | 59 | $protected = false; |
60 | 60 | } |
61 | 61 | } |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | * @return array |
68 | 68 | * @filter post_updated_messages |
69 | 69 | */ |
70 | - public function filterUpdateMessages($messages) |
|
70 | + public function filterUpdateMessages( $messages ) |
|
71 | 71 | { |
72 | - return glsr(Labels::class)->filterUpdateMessages( |
|
73 | - Arr::consolidateArray($messages) |
|
72 | + return glsr( Labels::class )->filterUpdateMessages( |
|
73 | + Arr::consolidateArray( $messages ) |
|
74 | 74 | ); |
75 | 75 | } |
76 | 76 | |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | * @return void |
79 | 79 | * @action add_meta_boxes_{Application::POST_TYPE} |
80 | 80 | */ |
81 | - public function registerMetaBoxes($post) |
|
81 | + public function registerMetaBoxes( $post ) |
|
82 | 82 | { |
83 | - add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side'); |
|
84 | - add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side'); |
|
85 | - if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) { |
|
83 | + add_meta_box( Application::ID.'_assigned_to', __( 'Assigned To', 'site-reviews' ), [$this, 'renderAssignedToMetabox'], null, 'side' ); |
|
84 | + add_meta_box( Application::ID.'_review', __( 'Details', 'site-reviews' ), [$this, 'renderDetailsMetaBox'], null, 'side' ); |
|
85 | + if( 'local' != glsr( Database::class )->get( $post->ID, 'review_type' ) ) { |
|
86 | 86 | return; |
87 | 87 | } |
88 | - add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal'); |
|
88 | + add_meta_box( Application::ID.'_response', __( 'Respond Publicly', 'site-reviews' ), [$this, 'renderResponseMetaBox'], null, 'normal' ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function removeAutosave() |
96 | 96 | { |
97 | - glsr(Customization::class)->removeAutosave(); |
|
97 | + glsr( Customization::class )->removeAutosave(); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function removeMetaBoxes() |
105 | 105 | { |
106 | - glsr(Customization::class)->removeMetaBoxes(); |
|
106 | + glsr( Customization::class )->removeMetaBoxes(); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function removePostTypeSupport() |
113 | 113 | { |
114 | - glsr(Customization::class)->removePostTypeSupport(); |
|
114 | + glsr( Customization::class )->removePostTypeSupport(); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -119,17 +119,17 @@ discard block |
||
119 | 119 | * @return void |
120 | 120 | * @callback add_meta_box |
121 | 121 | */ |
122 | - public function renderAssignedToMetabox($post) |
|
122 | + public function renderAssignedToMetabox( $post ) |
|
123 | 123 | { |
124 | - if (!$this->isReviewPostType($post)) { |
|
124 | + if( !$this->isReviewPostType( $post ) ) { |
|
125 | 125 | return; |
126 | 126 | } |
127 | - $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to'); |
|
128 | - wp_nonce_field('assigned_to', '_nonce-assigned-to', false); |
|
129 | - glsr()->render('partials/editor/metabox-assigned-to', [ |
|
127 | + $assignedTo = (string)glsr( Database::class )->get( $post->ID, 'assigned_to' ); |
|
128 | + wp_nonce_field( 'assigned_to', '_nonce-assigned-to', false ); |
|
129 | + glsr()->render( 'partials/editor/metabox-assigned-to', [ |
|
130 | 130 | 'id' => $assignedTo, |
131 | - 'template' => $this->buildAssignedToTemplate($assignedTo, $post), |
|
132 | - ]); |
|
131 | + 'template' => $this->buildAssignedToTemplate( $assignedTo, $post ), |
|
132 | + ] ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -137,16 +137,16 @@ discard block |
||
137 | 137 | * @return void |
138 | 138 | * @callback add_meta_box |
139 | 139 | */ |
140 | - public function renderDetailsMetaBox($post) |
|
140 | + public function renderDetailsMetaBox( $post ) |
|
141 | 141 | { |
142 | - if (!$this->isReviewPostType($post)) { |
|
142 | + if( !$this->isReviewPostType( $post ) ) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | - $review = glsr_get_review($post); |
|
146 | - glsr()->render('partials/editor/metabox-details', [ |
|
147 | - 'button' => $this->buildDetailsMetaBoxRevertButton($review, $post), |
|
148 | - 'metabox' => $this->normalizeDetailsMetaBox($review), |
|
149 | - ]); |
|
145 | + $review = glsr_get_review( $post ); |
|
146 | + glsr()->render( 'partials/editor/metabox-details', [ |
|
147 | + 'button' => $this->buildDetailsMetaBoxRevertButton( $review, $post ), |
|
148 | + 'metabox' => $this->normalizeDetailsMetaBox( $review ), |
|
149 | + ] ); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public function renderPinnedInPublishMetaBox() |
157 | 157 | { |
158 | - if (!$this->isReviewPostType(get_post())) { |
|
158 | + if( !$this->isReviewPostType( get_post() ) ) { |
|
159 | 159 | return; |
160 | 160 | } |
161 | - glsr(Template::class)->render('partials/editor/pinned', [ |
|
161 | + glsr( Template::class )->render( 'partials/editor/pinned', [ |
|
162 | 162 | 'context' => [ |
163 | - 'no' => __('No', 'site-reviews'), |
|
164 | - 'yes' => __('Yes', 'site-reviews'), |
|
163 | + 'no' => __( 'No', 'site-reviews' ), |
|
164 | + 'yes' => __( 'Yes', 'site-reviews' ), |
|
165 | 165 | ], |
166 | - 'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')), |
|
167 | - ]); |
|
166 | + 'pinned' => wp_validate_boolean( glsr( Database::class )->get( get_the_ID(), 'pinned' ) ), |
|
167 | + ] ); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | * @return void |
173 | 173 | * @callback add_meta_box |
174 | 174 | */ |
175 | - public function renderResponseMetaBox($post) |
|
175 | + public function renderResponseMetaBox( $post ) |
|
176 | 176 | { |
177 | - if (!$this->isReviewPostType($post)) { |
|
177 | + if( !$this->isReviewPostType( $post ) ) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | - wp_nonce_field('response', '_nonce-response', false); |
|
181 | - glsr()->render('partials/editor/metabox-response', [ |
|
182 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
183 | - ]); |
|
180 | + wp_nonce_field( 'response', '_nonce-response', false ); |
|
181 | + glsr()->render( 'partials/editor/metabox-response', [ |
|
182 | + 'response' => glsr( Database::class )->get( $post->ID, 'response' ), |
|
183 | + ] ); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | * @return void |
189 | 189 | * @action edit_form_after_title |
190 | 190 | */ |
191 | - public function renderReviewEditor($post) |
|
191 | + public function renderReviewEditor( $post ) |
|
192 | 192 | { |
193 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
193 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) ) { |
|
194 | 194 | return; |
195 | 195 | } |
196 | - glsr()->render('partials/editor/review', [ |
|
196 | + glsr()->render( 'partials/editor/review', [ |
|
197 | 197 | 'post' => $post, |
198 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
199 | - ]); |
|
198 | + 'response' => glsr( Database::class )->get( $post->ID, 'response' ), |
|
199 | + ] ); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | public function renderReviewFields() |
207 | 207 | { |
208 | 208 | $screen = glsr_current_screen(); |
209 | - if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) { |
|
209 | + if( 'post' != $screen->base || Application::POST_TYPE != $screen->post_type ) { |
|
210 | 210 | return; |
211 | 211 | } |
212 | - add_action('edit_form_after_title', [$this, 'renderReviewEditor']); |
|
213 | - add_action('edit_form_top', [$this, 'renderReviewNotice']); |
|
212 | + add_action( 'edit_form_after_title', [$this, 'renderReviewEditor'] ); |
|
213 | + add_action( 'edit_form_top', [$this, 'renderReviewNotice'] ); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -218,20 +218,20 @@ discard block |
||
218 | 218 | * @return void |
219 | 219 | * @action edit_form_top |
220 | 220 | */ |
221 | - public function renderReviewNotice($post) |
|
221 | + public function renderReviewNotice( $post ) |
|
222 | 222 | { |
223 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
223 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) ) { |
|
224 | 224 | return; |
225 | 225 | } |
226 | - glsr(Notice::class)->addWarning(sprintf( |
|
227 | - __('%s reviews are read-only.', 'site-reviews'), |
|
228 | - glsr(Columns::class)->buildColumnReviewType($post->ID) |
|
229 | - )); |
|
230 | - glsr(Template::class)->render('partials/editor/notice', [ |
|
226 | + glsr( Notice::class )->addWarning( sprintf( |
|
227 | + __( '%s reviews are read-only.', 'site-reviews' ), |
|
228 | + glsr( Columns::class )->buildColumnReviewType( $post->ID ) |
|
229 | + ) ); |
|
230 | + glsr( Template::class )->render( 'partials/editor/notice', [ |
|
231 | 231 | 'context' => [ |
232 | - 'notices' => glsr(Notice::class)->get(), |
|
232 | + 'notices' => glsr( Notice::class )->get(), |
|
233 | 233 | ], |
234 | - ]); |
|
234 | + ] ); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -240,16 +240,16 @@ discard block |
||
240 | 240 | * @see glsr_categories_meta_box() |
241 | 241 | * @callback register_taxonomy |
242 | 242 | */ |
243 | - public function renderTaxonomyMetabox($post) |
|
243 | + public function renderTaxonomyMetabox( $post ) |
|
244 | 244 | { |
245 | - if (!$this->isReviewPostType($post)) { |
|
245 | + if( !$this->isReviewPostType( $post ) ) { |
|
246 | 246 | return; |
247 | 247 | } |
248 | - glsr()->render('partials/editor/metabox-categories', [ |
|
248 | + glsr()->render( 'partials/editor/metabox-categories', [ |
|
249 | 249 | 'post' => $post, |
250 | 250 | 'tax_name' => Application::TAXONOMY, |
251 | - 'taxonomy' => get_taxonomy(Application::TAXONOMY), |
|
252 | - ]); |
|
251 | + 'taxonomy' => get_taxonomy( Application::TAXONOMY ), |
|
252 | + ] ); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -259,12 +259,12 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public function revertReview() |
261 | 261 | { |
262 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
262 | + if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) { |
|
263 | 263 | return; |
264 | 264 | } |
265 | - check_admin_referer('revert-review_'.($postId = $this->getPostId())); |
|
266 | - glsr(ReviewManager::class)->revert($postId); |
|
267 | - $this->redirect($postId, 52); |
|
265 | + check_admin_referer( 'revert-review_'.($postId = $this->getPostId()) ); |
|
266 | + glsr( ReviewManager::class )->revert( $postId ); |
|
267 | + $this->redirect( $postId, 52 ); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -274,12 +274,12 @@ discard block |
||
274 | 274 | * @return void |
275 | 275 | * @action save_post_.Application::POST_TYPE |
276 | 276 | */ |
277 | - public function saveMetaboxes($postId, $post, $isUpdating) |
|
277 | + public function saveMetaboxes( $postId, $post, $isUpdating ) |
|
278 | 278 | { |
279 | - glsr(Metaboxes::class)->saveAssignedToMetabox($postId); |
|
280 | - glsr(Metaboxes::class)->saveResponseMetabox($postId); |
|
281 | - if ($isUpdating) { |
|
282 | - do_action('site-reviews/review/saved', glsr_get_review($postId)); |
|
279 | + glsr( Metaboxes::class )->saveAssignedToMetabox( $postId ); |
|
280 | + glsr( Metaboxes::class )->saveResponseMetabox( $postId ); |
|
281 | + if( $isUpdating ) { |
|
282 | + do_action( 'site-reviews/review/saved', glsr_get_review( $postId ) ); |
|
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
@@ -287,68 +287,68 @@ discard block |
||
287 | 287 | * @param string $assignedTo |
288 | 288 | * @return string |
289 | 289 | */ |
290 | - protected function buildAssignedToTemplate($assignedTo, WP_Post $post) |
|
290 | + protected function buildAssignedToTemplate( $assignedTo, WP_Post $post ) |
|
291 | 291 | { |
292 | - $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo); |
|
293 | - if (!($assignedPost instanceof WP_Post)) { |
|
292 | + $assignedPost = glsr( Database::class )->getAssignedToPost( $post->ID, $assignedTo ); |
|
293 | + if( !($assignedPost instanceof WP_Post) ) { |
|
294 | 294 | return; |
295 | 295 | } |
296 | - return glsr(Template::class)->build('partials/editor/assigned-post', [ |
|
296 | + return glsr( Template::class )->build( 'partials/editor/assigned-post', [ |
|
297 | 297 | 'context' => [ |
298 | - 'data.url' => (string) get_permalink($assignedPost), |
|
299 | - 'data.title' => get_the_title($assignedPost), |
|
298 | + 'data.url' => (string)get_permalink( $assignedPost ), |
|
299 | + 'data.title' => get_the_title( $assignedPost ), |
|
300 | 300 | ], |
301 | - ]); |
|
301 | + ] ); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
305 | 305 | * @return string |
306 | 306 | */ |
307 | - protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post) |
|
307 | + protected function buildDetailsMetaBoxRevertButton( Review $review, WP_Post $post ) |
|
308 | 308 | { |
309 | 309 | $isModified = !Arr::compareArrays( |
310 | 310 | [$review->title, $review->content, $review->date], |
311 | 311 | [ |
312 | - glsr(Database::class)->get($post->ID, 'title'), |
|
313 | - glsr(Database::class)->get($post->ID, 'content'), |
|
314 | - glsr(Database::class)->get($post->ID, 'date'), |
|
312 | + glsr( Database::class )->get( $post->ID, 'title' ), |
|
313 | + glsr( Database::class )->get( $post->ID, 'content' ), |
|
314 | + glsr( Database::class )->get( $post->ID, 'date' ), |
|
315 | 315 | ] |
316 | 316 | ); |
317 | - if ($isModified) { |
|
317 | + if( $isModified ) { |
|
318 | 318 | $revertUrl = wp_nonce_url( |
319 | - admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID), |
|
319 | + admin_url( 'post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID ), |
|
320 | 320 | 'revert-review_'.$post->ID |
321 | 321 | ); |
322 | - return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [ |
|
322 | + return glsr( Builder::class )->a( __( 'Revert Changes', 'site-reviews' ), [ |
|
323 | 323 | 'class' => 'button button-large', |
324 | 324 | 'href' => $revertUrl, |
325 | 325 | 'id' => 'revert', |
326 | - ]); |
|
326 | + ] ); |
|
327 | 327 | } |
328 | - return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [ |
|
328 | + return glsr( Builder::class )->button( __( 'Nothing to Revert', 'site-reviews' ), [ |
|
329 | 329 | 'class' => 'button-large', |
330 | 330 | 'disabled' => true, |
331 | 331 | 'id' => 'revert', |
332 | - ]); |
|
332 | + ] ); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
336 | 336 | * @param object $review |
337 | 337 | * @return string|void |
338 | 338 | */ |
339 | - protected function getReviewType($review) |
|
339 | + protected function getReviewType( $review ) |
|
340 | 340 | { |
341 | - if (count(glsr()->reviewTypes) < 2) { |
|
341 | + if( count( glsr()->reviewTypes ) < 2 ) { |
|
342 | 342 | return; |
343 | 343 | } |
344 | - $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes) |
|
344 | + $reviewType = array_key_exists( $review->review_type, glsr()->reviewTypes ) |
|
345 | 345 | ? glsr()->reviewTypes[$review->review_type] |
346 | - : __('Unknown', 'site-reviews'); |
|
347 | - if (!empty($review->url)) { |
|
348 | - $reviewType = glsr(Builder::class)->a($reviewType, [ |
|
346 | + : __( 'Unknown', 'site-reviews' ); |
|
347 | + if( !empty($review->url) ) { |
|
348 | + $reviewType = glsr( Builder::class )->a( $reviewType, [ |
|
349 | 349 | 'href' => $review->url, |
350 | 350 | 'target' => '_blank', |
351 | - ]); |
|
351 | + ] ); |
|
352 | 352 | } |
353 | 353 | return $reviewType; |
354 | 354 | } |
@@ -356,18 +356,18 @@ discard block |
||
356 | 356 | /** |
357 | 357 | * @return bool |
358 | 358 | */ |
359 | - protected function isReviewEditable($post) |
|
359 | + protected function isReviewEditable( $post ) |
|
360 | 360 | { |
361 | - return $this->isReviewPostType($post) |
|
362 | - && post_type_supports(Application::POST_TYPE, 'title') |
|
363 | - && 'local' == glsr(Database::class)->get($post->ID, 'review_type'); |
|
361 | + return $this->isReviewPostType( $post ) |
|
362 | + && post_type_supports( Application::POST_TYPE, 'title' ) |
|
363 | + && 'local' == glsr( Database::class )->get( $post->ID, 'review_type' ); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
367 | 367 | * @param mixed $post |
368 | 368 | * @return bool |
369 | 369 | */ |
370 | - protected function isReviewPostType($post) |
|
370 | + protected function isReviewPostType( $post ) |
|
371 | 371 | { |
372 | 372 | return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type; |
373 | 373 | } |
@@ -375,29 +375,29 @@ discard block |
||
375 | 375 | /** |
376 | 376 | * @return array |
377 | 377 | */ |
378 | - protected function normalizeDetailsMetaBox(Review $review) |
|
378 | + protected function normalizeDetailsMetaBox( Review $review ) |
|
379 | 379 | { |
380 | 380 | $user = empty($review->user_id) |
381 | - ? __('Unregistered user', 'site-reviews') |
|
382 | - : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [ |
|
383 | - 'href' => get_author_posts_url($review->user_id), |
|
384 | - ]); |
|
381 | + ? __( 'Unregistered user', 'site-reviews' ) |
|
382 | + : glsr( Builder::class )->a( get_the_author_meta( 'display_name', $review->user_id ), [ |
|
383 | + 'href' => get_author_posts_url( $review->user_id ), |
|
384 | + ] ); |
|
385 | 385 | $email = empty($review->email) |
386 | 386 | ? '—' |
387 | - : glsr(Builder::class)->a($review->email, [ |
|
388 | - 'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title), |
|
389 | - ]); |
|
387 | + : glsr( Builder::class )->a( $review->email, [ |
|
388 | + 'href' => 'mailto:'.$review->email.'?subject='.esc_attr( __( 'RE:', 'site-reviews' ).' '.$review->title ), |
|
389 | + ] ); |
|
390 | 390 | $metabox = [ |
391 | - __('Rating', 'site-reviews') => glsr_star_rating($review->rating), |
|
392 | - __('Type', 'site-reviews') => $this->getReviewType($review), |
|
393 | - __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'), |
|
394 | - __('Name', 'site-reviews') => $review->author, |
|
395 | - __('Email', 'site-reviews') => $email, |
|
396 | - __('User', 'site-reviews') => $user, |
|
397 | - __('IP Address', 'site-reviews') => $review->ip_address, |
|
398 | - __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar), |
|
391 | + __( 'Rating', 'site-reviews' ) => glsr_star_rating( $review->rating ), |
|
392 | + __( 'Type', 'site-reviews' ) => $this->getReviewType( $review ), |
|
393 | + __( 'Date', 'site-reviews' ) => get_date_from_gmt( $review->date, 'F j, Y' ), |
|
394 | + __( 'Name', 'site-reviews' ) => $review->author, |
|
395 | + __( 'Email', 'site-reviews' ) => $email, |
|
396 | + __( 'User', 'site-reviews' ) => $user, |
|
397 | + __( 'IP Address', 'site-reviews' ) => $review->ip_address, |
|
398 | + __( 'Avatar', 'site-reviews' ) => sprintf( '<img src="%s" width="96">', $review->avatar ), |
|
399 | 399 | ]; |
400 | - return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review)); |
|
400 | + return array_filter( apply_filters( 'site-reviews/metabox/details', $metabox, $review ) ); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -405,16 +405,16 @@ discard block |
||
405 | 405 | * @param int $messageIndex |
406 | 406 | * @return void |
407 | 407 | */ |
408 | - protected function redirect($postId, $messageIndex) |
|
408 | + protected function redirect( $postId, $messageIndex ) |
|
409 | 409 | { |
410 | 410 | $referer = wp_get_referer(); |
411 | 411 | $hasReferer = !$referer |
412 | - || Str::contains($referer, 'post.php') |
|
413 | - || Str::contains($referer, 'post-new.php'); |
|
412 | + || Str::contains( $referer, 'post.php' ) |
|
413 | + || Str::contains( $referer, 'post-new.php' ); |
|
414 | 414 | $redirectUri = $hasReferer |
415 | - ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer) |
|
416 | - : get_edit_post_link($postId); |
|
417 | - wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri)); |
|
415 | + ? remove_query_arg( ['deleted', 'ids', 'trashed', 'untrashed'], $referer ) |
|
416 | + : get_edit_post_link( $postId ); |
|
417 | + wp_safe_redirect( add_query_arg( ['message' => $messageIndex], $redirectUri ) ); |
|
418 | 418 | exit; |
419 | 419 | } |
420 | 420 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public static function load() |
47 | 47 | { |
48 | - if (empty(static::$instance)) { |
|
48 | + if( empty(static::$instance) ) { |
|
49 | 49 | static::$instance = new static(); |
50 | 50 | } |
51 | 51 | return static::$instance; |
@@ -55,16 +55,16 @@ discard block |
||
55 | 55 | * @param string $property |
56 | 56 | * @return mixed |
57 | 57 | */ |
58 | - public function __get($property) |
|
58 | + public function __get( $property ) |
|
59 | 59 | { |
60 | - if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) { |
|
60 | + if( property_exists( $this, $property ) && !in_array( $property, static::PROTECTED_PROPERTIES ) ) { |
|
61 | 61 | return $this->$property; |
62 | 62 | } |
63 | - $constant = 'static::'.strtoupper(Str::snakeCase($property)); |
|
64 | - if (defined($constant)) { |
|
65 | - return constant($constant); |
|
63 | + $constant = 'static::'.strtoupper( Str::snakeCase( $property ) ); |
|
64 | + if( defined( $constant ) ) { |
|
65 | + return constant( $constant ); |
|
66 | 66 | } |
67 | - return Arr::get($this->storage, $property, null); |
|
67 | + return Arr::get( $this->storage, $property, null ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -72,14 +72,14 @@ discard block |
||
72 | 72 | * @param string $value |
73 | 73 | * @return void |
74 | 74 | */ |
75 | - public function __set($property, $value) |
|
75 | + public function __set( $property, $value ) |
|
76 | 76 | { |
77 | - if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
|
77 | + if( !property_exists( $this, $property ) || in_array( $property, static::PROTECTED_PROPERTIES ) ) { |
|
78 | 78 | $this->storage[$property] = $value; |
79 | - } elseif (!isset($this->$property)) { |
|
79 | + } elseif( !isset($this->$property) ) { |
|
80 | 80 | $this->$property = $value; |
81 | 81 | } else { |
82 | - throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
|
82 | + throw new Exception( sprintf( 'The "%s" property cannot be changed once set.', $property ) ); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @param mixed $concrete |
90 | 90 | * @return mixed |
91 | 91 | */ |
92 | - public function bind($alias, $concrete) |
|
92 | + public function bind( $alias, $concrete ) |
|
93 | 93 | { |
94 | 94 | $this->services[$alias] = $concrete; |
95 | 95 | } |
@@ -99,21 +99,21 @@ discard block |
||
99 | 99 | * @param mixed $abstract |
100 | 100 | * @return mixed |
101 | 101 | */ |
102 | - public function make($abstract) |
|
102 | + public function make( $abstract ) |
|
103 | 103 | { |
104 | - if (!isset($this->services[$abstract])) { |
|
105 | - $abstract = $this->addNamespace($abstract); |
|
104 | + if( !isset($this->services[$abstract]) ) { |
|
105 | + $abstract = $this->addNamespace( $abstract ); |
|
106 | 106 | } |
107 | - if (isset($this->services[$abstract])) { |
|
107 | + if( isset($this->services[$abstract]) ) { |
|
108 | 108 | $abstract = $this->services[$abstract]; |
109 | 109 | } |
110 | - if (is_callable($abstract)) { |
|
111 | - return call_user_func_array($abstract, [$this]); |
|
110 | + if( is_callable( $abstract ) ) { |
|
111 | + return call_user_func_array( $abstract, [$this] ); |
|
112 | 112 | } |
113 | - if (is_object($abstract)) { |
|
113 | + if( is_object( $abstract ) ) { |
|
114 | 114 | return $abstract; |
115 | 115 | } |
116 | - return $this->resolve($abstract); |
|
116 | + return $this->resolve( $abstract ); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | /** |
128 | 128 | * @return mixed |
129 | 129 | */ |
130 | - public function sessionGet($key, $fallback = '') |
|
130 | + public function sessionGet( $key, $fallback = '' ) |
|
131 | 131 | { |
132 | - $value = Arr::get($this->session, $key, $fallback); |
|
132 | + $value = Arr::get( $this->session, $key, $fallback ); |
|
133 | 133 | unset($this->session[$key]); |
134 | 134 | return $value; |
135 | 135 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | /** |
138 | 138 | * @return void |
139 | 139 | */ |
140 | - public function sessionSet($key, $value) |
|
140 | + public function sessionSet( $key, $value ) |
|
141 | 141 | { |
142 | 142 | $this->session[$key] = $value; |
143 | 143 | } |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | * @param callable|string|null $binding |
149 | 149 | * @return void |
150 | 150 | */ |
151 | - public function singleton($alias, $binding) |
|
151 | + public function singleton( $alias, $binding ) |
|
152 | 152 | { |
153 | - $this->bind($alias, $this->make($binding)); |
|
153 | + $this->bind( $alias, $this->make( $binding ) ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * @param string $abstract |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - protected function addNamespace($abstract) |
|
161 | + protected function addNamespace( $abstract ) |
|
162 | 162 | { |
163 | - if (!Str::contains($abstract, __NAMESPACE__) && !class_exists($abstract)) { |
|
163 | + if( !Str::contains( $abstract, __NAMESPACE__ ) && !class_exists( $abstract ) ) { |
|
164 | 164 | $abstract = __NAMESPACE__.'\\'.$abstract; |
165 | 165 | } |
166 | 166 | return $abstract; |
@@ -172,21 +172,21 @@ discard block |
||
172 | 172 | * @return mixed |
173 | 173 | * @throws Exception |
174 | 174 | */ |
175 | - protected function resolve($concrete) |
|
175 | + protected function resolve( $concrete ) |
|
176 | 176 | { |
177 | - if ($concrete instanceof Closure) { |
|
178 | - return $concrete($this); |
|
177 | + if( $concrete instanceof Closure ) { |
|
178 | + return $concrete( $this ); |
|
179 | 179 | } |
180 | - $reflector = new ReflectionClass($concrete); |
|
181 | - if (!$reflector->isInstantiable()) { |
|
182 | - throw new Exception('Target ['.$concrete.'] is not instantiable.'); |
|
180 | + $reflector = new ReflectionClass( $concrete ); |
|
181 | + if( !$reflector->isInstantiable() ) { |
|
182 | + throw new Exception( 'Target ['.$concrete.'] is not instantiable.' ); |
|
183 | 183 | } |
184 | 184 | $constructor = $reflector->getConstructor(); |
185 | - if (empty($constructor)) { |
|
185 | + if( empty($constructor) ) { |
|
186 | 186 | return new $concrete(); |
187 | 187 | } |
188 | 188 | return $reflector->newInstanceArgs( |
189 | - $this->resolveDependencies($constructor->getParameters()) |
|
189 | + $this->resolveDependencies( $constructor->getParameters() ) |
|
190 | 190 | ); |
191 | 191 | } |
192 | 192 | |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | * @return mixed |
196 | 196 | * @throws Exception |
197 | 197 | */ |
198 | - protected function resolveClass(ReflectionParameter $parameter) |
|
198 | + protected function resolveClass( ReflectionParameter $parameter ) |
|
199 | 199 | { |
200 | 200 | try { |
201 | - return $this->make($parameter->getClass()->name); |
|
202 | - } catch (Exception $error) { |
|
203 | - if ($parameter->isOptional()) { |
|
201 | + return $this->make( $parameter->getClass()->name ); |
|
202 | + } catch( Exception $error ) { |
|
203 | + if( $parameter->isOptional() ) { |
|
204 | 204 | return $parameter->getDefaultValue(); |
205 | 205 | } |
206 | 206 | throw $error; |
@@ -211,13 +211,13 @@ discard block |
||
211 | 211 | * Resolve all of the dependencies from the ReflectionParameters. |
212 | 212 | * @return array |
213 | 213 | */ |
214 | - protected function resolveDependencies(array $dependencies) |
|
214 | + protected function resolveDependencies( array $dependencies ) |
|
215 | 215 | { |
216 | 216 | $results = []; |
217 | - foreach ($dependencies as $dependency) { |
|
218 | - $results[] = !is_null($class = $dependency->getClass()) |
|
219 | - ? $this->resolveClass($dependency) |
|
220 | - : $this->resolveDependency($dependency); |
|
217 | + foreach( $dependencies as $dependency ) { |
|
218 | + $results[] = !is_null( $class = $dependency->getClass() ) |
|
219 | + ? $this->resolveClass( $dependency ) |
|
220 | + : $this->resolveDependency( $dependency ); |
|
221 | 221 | } |
222 | 222 | return $results; |
223 | 223 | } |
@@ -226,9 +226,9 @@ discard block |
||
226 | 226 | * Resolve a single ReflectionParameter dependency. |
227 | 227 | * @return array|null |
228 | 228 | */ |
229 | - protected function resolveDependency(ReflectionParameter $parameter) |
|
229 | + protected function resolveDependency( ReflectionParameter $parameter ) |
|
230 | 230 | { |
231 | - if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) { |
|
231 | + if( $parameter->isArray() && $parameter->isDefaultValueAvailable() ) { |
|
232 | 232 | return $parameter->getDefaultValue(); |
233 | 233 | } |
234 | 234 | return null; |
@@ -40,24 +40,24 @@ discard block |
||
40 | 40 | protected $translator; |
41 | 41 | protected $welcome; |
42 | 42 | |
43 | - public function __construct(Application $app ) { |
|
43 | + public function __construct( Application $app ) { |
|
44 | 44 | $this->app = $app; |
45 | - $this->admin = $app->make(AdminController::class); |
|
46 | - $this->blocks = $app->make(BlocksController::class); |
|
47 | - $this->console = $app->make(Console::class); |
|
48 | - $this->editor = $app->make(EditorController::class); |
|
49 | - $this->listtable = $app->make(ListTableController::class); |
|
50 | - $this->main = $app->make(MainController::class); |
|
51 | - $this->menu = $app->make(MenuController::class); |
|
52 | - $this->notices = $app->make(NoticeController::class); |
|
53 | - $this->public = $app->make(PublicController::class); |
|
54 | - $this->rebusify = $app->make(RebusifyController::class); |
|
55 | - $this->review = $app->make(ReviewController::class); |
|
56 | - $this->router = $app->make(Router::class); |
|
57 | - $this->settings = $app->make(SettingsController::class); |
|
58 | - $this->taxonomy = $app->make(TaxonomyController::class); |
|
59 | - $this->translator = $app->make(TranslationController::class); |
|
60 | - $this->welcome = $app->make(WelcomeController::class); |
|
45 | + $this->admin = $app->make( AdminController::class ); |
|
46 | + $this->blocks = $app->make( BlocksController::class ); |
|
47 | + $this->console = $app->make( Console::class ); |
|
48 | + $this->editor = $app->make( EditorController::class ); |
|
49 | + $this->listtable = $app->make( ListTableController::class ); |
|
50 | + $this->main = $app->make( MainController::class ); |
|
51 | + $this->menu = $app->make( MenuController::class ); |
|
52 | + $this->notices = $app->make( NoticeController::class ); |
|
53 | + $this->public = $app->make( PublicController::class ); |
|
54 | + $this->rebusify = $app->make( RebusifyController::class ); |
|
55 | + $this->review = $app->make( ReviewController::class ); |
|
56 | + $this->router = $app->make( Router::class ); |
|
57 | + $this->settings = $app->make( SettingsController::class ); |
|
58 | + $this->taxonomy = $app->make( TaxonomyController::class ); |
|
59 | + $this->translator = $app->make( TranslationController::class ); |
|
60 | + $this->welcome = $app->make( WelcomeController::class ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -65,66 +65,66 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function run() |
67 | 67 | { |
68 | - add_action('admin_enqueue_scripts', [$this->admin, 'enqueueAssets']); |
|
69 | - add_action('admin_init', [$this->admin, 'registerTinymcePopups']); |
|
70 | - add_action('media_buttons', [$this->admin, 'renderTinymceButton'], 11); |
|
71 | - add_action('plugins_loaded', [$this->app, 'getDefaults'], 11); |
|
72 | - add_action('plugins_loaded', [$this->app, 'registerAddons']); |
|
73 | - add_action('plugins_loaded', [$this->app, 'registerLanguages']); |
|
74 | - add_action('plugins_loaded', [$this->app, 'registerReviewTypes']); |
|
75 | - add_action('upgrader_process_complete', [$this->app, 'upgraded'], 10, 2); |
|
76 | - add_action('init', [$this->blocks, 'registerAssets'], 9); |
|
77 | - add_action('init', [$this->blocks, 'registerBlocks']); |
|
78 | - add_action('admin_footer', [$this->console, 'logOnce']); |
|
79 | - add_action('wp_footer', [$this->console, 'logOnce']); |
|
80 | - add_action('add_meta_boxes_'.Application::POST_TYPE, [$this->editor, 'registerMetaBoxes']); |
|
81 | - add_action('admin_print_scripts', [$this->editor, 'removeAutosave'], 999); |
|
82 | - add_action('admin_menu', [$this->editor, 'removeMetaBoxes']); |
|
83 | - add_action('current_screen', [$this->editor, 'removePostTypeSupport']); |
|
84 | - add_action('post_submitbox_misc_actions', [$this->editor, 'renderPinnedInPublishMetaBox']); |
|
85 | - add_action('admin_head', [$this->editor, 'renderReviewFields']); |
|
86 | - add_action('admin_action_revert', [$this->editor, 'revertReview']); |
|
87 | - add_action('save_post_'.Application::POST_TYPE, [$this->editor, 'saveMetaboxes'], 10, 3); |
|
88 | - add_action('admin_action_approve', [$this->listtable, 'approve']); |
|
89 | - add_action('bulk_edit_custom_box', [$this->listtable, 'renderBulkEditFields'], 10, 2); |
|
90 | - add_action('restrict_manage_posts', [$this->listtable, 'renderColumnFilters']); |
|
91 | - add_action('manage_'.Application::POST_TYPE.'_posts_custom_column', [$this->listtable, 'renderColumnValues'], 10, 2); |
|
92 | - add_action('save_post_'.Application::POST_TYPE, [$this->listtable, 'saveBulkEditFields']); |
|
93 | - add_action('pre_get_posts', [$this->listtable, 'setQueryForColumn']); |
|
94 | - add_action('admin_action_unapprove', [$this->listtable, 'unapprove']); |
|
95 | - add_action('init', [$this->main, 'registerPostType'], 8); |
|
96 | - add_action('init', [$this->main, 'registerShortcodes']); |
|
97 | - add_action('init', [$this->main, 'registerTaxonomy']); |
|
98 | - add_action('widgets_init', [$this->main, 'registerWidgets']); |
|
99 | - add_action('admin_menu', [$this->menu, 'registerMenuCount']); |
|
100 | - add_action('admin_menu', [$this->menu, 'registerSubMenus']); |
|
101 | - add_action('admin_init', [$this->menu, 'setCustomPermissions'], 999); |
|
102 | - add_action('admin_notices', [$this->notices, 'filterAdminNotices']); |
|
103 | - add_action('wp_enqueue_scripts', [$this->public, 'enqueueAssets'], 999); |
|
104 | - add_filter('site-reviews/builder', [$this->public, 'modifyBuilder']); |
|
105 | - add_action('wp_footer', [$this->public, 'renderSchema']); |
|
106 | - add_action('site-reviews/review/created', [$this->rebusify, 'onCreated']); |
|
107 | - add_action('site-reviews/review/reverted', [$this->rebusify, 'onReverted']); |
|
108 | - add_action('site-reviews/review/saved', [$this->rebusify, 'onSaved']); |
|
109 | - add_action('updated_postmeta', [$this->rebusify, 'onUpdatedMeta'], 10, 3); |
|
110 | - add_action('set_object_terms', [$this->review, 'onAfterChangeCategory'], 10, 6); |
|
111 | - add_action('transition_post_status', [$this->review, 'onAfterChangeStatus'], 10, 3); |
|
112 | - add_action('site-reviews/review/created', [$this->review, 'onAfterCreate']); |
|
113 | - add_action('before_delete_post', [$this->review, 'onBeforeDelete']); |
|
114 | - add_action('update_postmeta', [$this->review, 'onBeforeUpdate'], 10, 4); |
|
115 | - add_action('admin_init', [$this->router, 'routeAdminPostRequest']); |
|
116 | - add_action('wp_ajax_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
117 | - add_action('wp_ajax_nopriv_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
118 | - add_action('init', [$this->router, 'routePublicPostRequest']); |
|
119 | - add_action('admin_init', [$this->settings, 'registerSettings']); |
|
120 | - add_action(Application::TAXONOMY.'_term_edit_form_top', [$this->taxonomy, 'disableParents']); |
|
121 | - add_action(Application::TAXONOMY.'_term_new_form_tag', [$this->taxonomy, 'disableParents']); |
|
122 | - add_action(Application::TAXONOMY.'_add_form_fields', [$this->taxonomy, 'enableParents']); |
|
123 | - add_action(Application::TAXONOMY.'_edit_form', [$this->taxonomy, 'enableParents']); |
|
124 | - add_action('restrict_manage_posts', [$this->taxonomy, 'renderTaxonomyFilter'], 9); |
|
125 | - add_action('set_object_terms', [$this->taxonomy, 'restrictTermSelection'], 9, 6); |
|
126 | - add_action('admin_enqueue_scripts', [$this->translator, 'translatePostStatusLabels']); |
|
127 | - add_action('activated_plugin', [$this->welcome, 'redirectOnActivation'], 10, 2); |
|
128 | - add_action('admin_menu', [$this->welcome, 'registerPage']); |
|
68 | + add_action( 'admin_enqueue_scripts', [$this->admin, 'enqueueAssets'] ); |
|
69 | + add_action( 'admin_init', [$this->admin, 'registerTinymcePopups'] ); |
|
70 | + add_action( 'media_buttons', [$this->admin, 'renderTinymceButton'], 11 ); |
|
71 | + add_action( 'plugins_loaded', [$this->app, 'getDefaults'], 11 ); |
|
72 | + add_action( 'plugins_loaded', [$this->app, 'registerAddons'] ); |
|
73 | + add_action( 'plugins_loaded', [$this->app, 'registerLanguages'] ); |
|
74 | + add_action( 'plugins_loaded', [$this->app, 'registerReviewTypes'] ); |
|
75 | + add_action( 'upgrader_process_complete', [$this->app, 'upgraded'], 10, 2 ); |
|
76 | + add_action( 'init', [$this->blocks, 'registerAssets'], 9 ); |
|
77 | + add_action( 'init', [$this->blocks, 'registerBlocks'] ); |
|
78 | + add_action( 'admin_footer', [$this->console, 'logOnce'] ); |
|
79 | + add_action( 'wp_footer', [$this->console, 'logOnce'] ); |
|
80 | + add_action( 'add_meta_boxes_'.Application::POST_TYPE, [$this->editor, 'registerMetaBoxes'] ); |
|
81 | + add_action( 'admin_print_scripts', [$this->editor, 'removeAutosave'], 999 ); |
|
82 | + add_action( 'admin_menu', [$this->editor, 'removeMetaBoxes'] ); |
|
83 | + add_action( 'current_screen', [$this->editor, 'removePostTypeSupport'] ); |
|
84 | + add_action( 'post_submitbox_misc_actions', [$this->editor, 'renderPinnedInPublishMetaBox'] ); |
|
85 | + add_action( 'admin_head', [$this->editor, 'renderReviewFields'] ); |
|
86 | + add_action( 'admin_action_revert', [$this->editor, 'revertReview'] ); |
|
87 | + add_action( 'save_post_'.Application::POST_TYPE, [$this->editor, 'saveMetaboxes'], 10, 3 ); |
|
88 | + add_action( 'admin_action_approve', [$this->listtable, 'approve'] ); |
|
89 | + add_action( 'bulk_edit_custom_box', [$this->listtable, 'renderBulkEditFields'], 10, 2 ); |
|
90 | + add_action( 'restrict_manage_posts', [$this->listtable, 'renderColumnFilters'] ); |
|
91 | + add_action( 'manage_'.Application::POST_TYPE.'_posts_custom_column', [$this->listtable, 'renderColumnValues'], 10, 2 ); |
|
92 | + add_action( 'save_post_'.Application::POST_TYPE, [$this->listtable, 'saveBulkEditFields'] ); |
|
93 | + add_action( 'pre_get_posts', [$this->listtable, 'setQueryForColumn'] ); |
|
94 | + add_action( 'admin_action_unapprove', [$this->listtable, 'unapprove'] ); |
|
95 | + add_action( 'init', [$this->main, 'registerPostType'], 8 ); |
|
96 | + add_action( 'init', [$this->main, 'registerShortcodes'] ); |
|
97 | + add_action( 'init', [$this->main, 'registerTaxonomy'] ); |
|
98 | + add_action( 'widgets_init', [$this->main, 'registerWidgets'] ); |
|
99 | + add_action( 'admin_menu', [$this->menu, 'registerMenuCount'] ); |
|
100 | + add_action( 'admin_menu', [$this->menu, 'registerSubMenus'] ); |
|
101 | + add_action( 'admin_init', [$this->menu, 'setCustomPermissions'], 999 ); |
|
102 | + add_action( 'admin_notices', [$this->notices, 'filterAdminNotices'] ); |
|
103 | + add_action( 'wp_enqueue_scripts', [$this->public, 'enqueueAssets'], 999 ); |
|
104 | + add_filter( 'site-reviews/builder', [$this->public, 'modifyBuilder'] ); |
|
105 | + add_action( 'wp_footer', [$this->public, 'renderSchema'] ); |
|
106 | + add_action( 'site-reviews/review/created', [$this->rebusify, 'onCreated'] ); |
|
107 | + add_action( 'site-reviews/review/reverted', [$this->rebusify, 'onReverted'] ); |
|
108 | + add_action( 'site-reviews/review/saved', [$this->rebusify, 'onSaved'] ); |
|
109 | + add_action( 'updated_postmeta', [$this->rebusify, 'onUpdatedMeta'], 10, 3 ); |
|
110 | + add_action( 'set_object_terms', [$this->review, 'onAfterChangeCategory'], 10, 6 ); |
|
111 | + add_action( 'transition_post_status', [$this->review, 'onAfterChangeStatus'], 10, 3 ); |
|
112 | + add_action( 'site-reviews/review/created', [$this->review, 'onAfterCreate'] ); |
|
113 | + add_action( 'before_delete_post', [$this->review, 'onBeforeDelete'] ); |
|
114 | + add_action( 'update_postmeta', [$this->review, 'onBeforeUpdate'], 10, 4 ); |
|
115 | + add_action( 'admin_init', [$this->router, 'routeAdminPostRequest'] ); |
|
116 | + add_action( 'wp_ajax_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest'] ); |
|
117 | + add_action( 'wp_ajax_nopriv_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest'] ); |
|
118 | + add_action( 'init', [$this->router, 'routePublicPostRequest'] ); |
|
119 | + add_action( 'admin_init', [$this->settings, 'registerSettings'] ); |
|
120 | + add_action( Application::TAXONOMY.'_term_edit_form_top', [$this->taxonomy, 'disableParents'] ); |
|
121 | + add_action( Application::TAXONOMY.'_term_new_form_tag', [$this->taxonomy, 'disableParents'] ); |
|
122 | + add_action( Application::TAXONOMY.'_add_form_fields', [$this->taxonomy, 'enableParents'] ); |
|
123 | + add_action( Application::TAXONOMY.'_edit_form', [$this->taxonomy, 'enableParents'] ); |
|
124 | + add_action( 'restrict_manage_posts', [$this->taxonomy, 'renderTaxonomyFilter'], 9 ); |
|
125 | + add_action( 'set_object_terms', [$this->taxonomy, 'restrictTermSelection'], 9, 6 ); |
|
126 | + add_action( 'admin_enqueue_scripts', [$this->translator, 'translatePostStatusLabels'] ); |
|
127 | + add_action( 'activated_plugin', [$this->welcome, 'redirectOnActivation'], 10, 2 ); |
|
128 | + add_action( 'admin_menu', [$this->welcome, 'registerPage'] ); |
|
129 | 129 | } |
130 | 130 | } |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | public function all() |
31 | 31 | { |
32 | 32 | $translations = $this->translations(); |
33 | - $entries = $this->filter($translations, $this->entries())->results(); |
|
34 | - array_walk($translations, function (&$entry) use ($entries) { |
|
35 | - $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
36 | - ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
33 | + $entries = $this->filter( $translations, $this->entries() )->results(); |
|
34 | + array_walk( $translations, function( &$entry ) use ($entries) { |
|
35 | + $entry['desc'] = array_key_exists( $entry['id'], $entries ) |
|
36 | + ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' ) |
|
37 | 37 | : ''; |
38 | 38 | }); |
39 | 39 | return $translations; |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function entries() |
46 | 46 | { |
47 | - if (!isset($this->entries)) { |
|
48 | - $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
49 | - $entries = $this->extractEntriesFromPotFile($potFile); |
|
50 | - $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
47 | + if( !isset($this->entries) ) { |
|
48 | + $potFile = glsr()->path( glsr()->languages.'/'.Application::ID.'.pot' ); |
|
49 | + $entries = $this->extractEntriesFromPotFile( $potFile ); |
|
50 | + $entries = apply_filters( 'site-reviews/translation/entries', $entries ); |
|
51 | 51 | $this->entries = $entries; |
52 | 52 | } |
53 | 53 | return $this->entries; |
@@ -58,24 +58,24 @@ discard block |
||
58 | 58 | * @param array|null $entries |
59 | 59 | * @return static |
60 | 60 | */ |
61 | - public function exclude($entriesToExclude = null, $entries = null) |
|
61 | + public function exclude( $entriesToExclude = null, $entries = null ) |
|
62 | 62 | { |
63 | - return $this->filter($entriesToExclude, $entries, false); |
|
63 | + return $this->filter( $entriesToExclude, $entries, false ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @param string $potFile |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
70 | + public function extractEntriesFromPotFile( $potFile, array $entries = [] ) |
|
71 | 71 | { |
72 | 72 | try { |
73 | - $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
74 | - foreach ($potEntries as $key => $entry) { |
|
75 | - $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
73 | + $potEntries = $this->normalize( Parser::parseFile( $potFile )->getEntries() ); |
|
74 | + foreach( $potEntries as $key => $entry ) { |
|
75 | + $entries[html_entity_decode( $key, ENT_COMPAT, 'UTF-8' )] = $entry; |
|
76 | 76 | } |
77 | - } catch (Exception $e) { |
|
78 | - glsr_log()->error($e->getMessage()); |
|
77 | + } catch( Exception $e ) { |
|
78 | + glsr_log()->error( $e->getMessage() ); |
|
79 | 79 | } |
80 | 80 | return $entries; |
81 | 81 | } |
@@ -86,18 +86,18 @@ discard block |
||
86 | 86 | * @param bool $intersect |
87 | 87 | * @return static |
88 | 88 | */ |
89 | - public function filter($filterWith = null, $entries = null, $intersect = true) |
|
89 | + public function filter( $filterWith = null, $entries = null, $intersect = true ) |
|
90 | 90 | { |
91 | - if (!is_array($entries)) { |
|
91 | + if( !is_array( $entries ) ) { |
|
92 | 92 | $entries = $this->results; |
93 | 93 | } |
94 | - if (!is_array($filterWith)) { |
|
94 | + if( !is_array( $filterWith ) ) { |
|
95 | 95 | $filterWith = $this->translations(); |
96 | 96 | } |
97 | - $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
97 | + $keys = array_flip( glsr_array_column( $filterWith, 'id' ) ); |
|
98 | 98 | $this->results = $intersect |
99 | - ? array_intersect_key($entries, $keys) |
|
100 | - : array_diff_key($entries, $keys); |
|
99 | + ? array_intersect_key( $entries, $keys ) |
|
100 | + : array_diff_key( $entries, $keys ); |
|
101 | 101 | return $this; |
102 | 102 | } |
103 | 103 | |
@@ -105,20 +105,20 @@ discard block |
||
105 | 105 | * @param string $template |
106 | 106 | * @return string |
107 | 107 | */ |
108 | - public function render($template, array $entry) |
|
108 | + public function render( $template, array $entry ) |
|
109 | 109 | { |
110 | 110 | $data = array_combine( |
111 | - array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
111 | + array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ), |
|
112 | 112 | $entry |
113 | 113 | ); |
114 | 114 | $data['data.class'] = $data['data.error'] = ''; |
115 | - if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
115 | + if( false === array_search( $entry['s1'], glsr_array_column( $this->entries(), 'msgid' ) ) ) { |
|
116 | 116 | $data['data.class'] = 'is-invalid'; |
117 | - $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
117 | + $data['data.error'] = __( 'This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews' ); |
|
118 | 118 | } |
119 | - return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
120 | - 'context' => array_map('esc_html', $data), |
|
121 | - ]); |
|
119 | + return glsr( Template::class )->build( 'partials/translations/'.$template, [ |
|
120 | + 'context' => array_map( 'esc_html', $data ), |
|
121 | + ] ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | public function renderAll() |
129 | 129 | { |
130 | 130 | $rendered = ''; |
131 | - foreach ($this->all() as $index => $entry) { |
|
131 | + foreach( $this->all() as $index => $entry ) { |
|
132 | 132 | $entry['index'] = $index; |
133 | 133 | $entry['prefix'] = OptionManager::databaseKey(); |
134 | - $rendered.= $this->render($entry['type'], $entry); |
|
134 | + $rendered .= $this->render( $entry['type'], $entry ); |
|
135 | 135 | } |
136 | 136 | return $rendered; |
137 | 137 | } |
@@ -140,25 +140,25 @@ discard block |
||
140 | 140 | * @param bool $resetAfterRender |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - public function renderResults($resetAfterRender = true) |
|
143 | + public function renderResults( $resetAfterRender = true ) |
|
144 | 144 | { |
145 | 145 | $rendered = ''; |
146 | - foreach ($this->results as $id => $entry) { |
|
146 | + foreach( $this->results as $id => $entry ) { |
|
147 | 147 | $data = [ |
148 | - 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
148 | + 'desc' => $this->getEntryString( $entry, 'msgctxt' ), |
|
149 | 149 | 'id' => $id, |
150 | - 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
151 | - 's1' => $this->getEntryString($entry, 'msgid'), |
|
150 | + 'p1' => $this->getEntryString( $entry, 'msgid_plural' ), |
|
151 | + 's1' => $this->getEntryString( $entry, 'msgid' ), |
|
152 | 152 | ]; |
153 | 153 | $text = !empty($data['p1']) |
154 | - ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
154 | + ? sprintf( '%s | %s', $data['s1'], $data['p1'] ) |
|
155 | 155 | : $data['s1']; |
156 | - $rendered.= $this->render('result', [ |
|
157 | - 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
158 | - 'text' => wp_strip_all_tags($text), |
|
159 | - ]); |
|
156 | + $rendered .= $this->render( 'result', [ |
|
157 | + 'entry' => json_encode( $data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ), |
|
158 | + 'text' => wp_strip_all_tags( $text ), |
|
159 | + ] ); |
|
160 | 160 | } |
161 | - if ($resetAfterRender) { |
|
161 | + if( $resetAfterRender ) { |
|
162 | 162 | $this->reset(); |
163 | 163 | } |
164 | 164 | return $rendered; |
@@ -186,18 +186,18 @@ discard block |
||
186 | 186 | * @param string $needle |
187 | 187 | * @return static |
188 | 188 | */ |
189 | - public function search($needle = '') |
|
189 | + public function search( $needle = '' ) |
|
190 | 190 | { |
191 | 191 | $this->reset(); |
192 | - $needle = trim(strtolower($needle)); |
|
193 | - foreach ($this->entries() as $key => $entry) { |
|
194 | - $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
195 | - $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
196 | - if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
197 | - if (in_array($needle, [$single, $plural])) { |
|
192 | + $needle = trim( strtolower( $needle ) ); |
|
193 | + foreach( $this->entries() as $key => $entry ) { |
|
194 | + $single = strtolower( $this->getEntryString( $entry, 'msgid' ) ); |
|
195 | + $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) ); |
|
196 | + if( strlen( $needle ) < static::SEARCH_THRESHOLD ) { |
|
197 | + if( in_array( $needle, [$single, $plural] ) ) { |
|
198 | 198 | $this->results[$key] = $entry; |
199 | 199 | } |
200 | - } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
200 | + } elseif( Str::contains( sprintf( '%s %s', $single, $plural ), $needle ) ) { |
|
201 | 201 | $this->results[$key] = $entry; |
202 | 202 | } |
203 | 203 | } |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | public function translations() |
212 | 212 | { |
213 | 213 | static $translations; |
214 | - if (empty($translations)) { |
|
215 | - $settings = glsr(OptionManager::class)->get('settings'); |
|
214 | + if( empty($translations) ) { |
|
215 | + $settings = glsr( OptionManager::class )->get( 'settings' ); |
|
216 | 216 | $translations = isset($settings['strings']) |
217 | - ? $this->normalizeSettings((array) $settings['strings']) |
|
217 | + ? $this->normalizeSettings( (array)$settings['strings'] ) |
|
218 | 218 | : []; |
219 | 219 | } |
220 | 220 | return $translations; |
@@ -224,28 +224,28 @@ discard block |
||
224 | 224 | * @param string $key |
225 | 225 | * @return string |
226 | 226 | */ |
227 | - protected function getEntryString(array $entry, $key) |
|
227 | + protected function getEntryString( array $entry, $key ) |
|
228 | 228 | { |
229 | 229 | return isset($entry[$key]) |
230 | - ? implode('', (array) $entry[$key]) |
|
230 | + ? implode( '', (array)$entry[$key] ) |
|
231 | 231 | : ''; |
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
235 | 235 | * @return array |
236 | 236 | */ |
237 | - protected function normalize(array $entries) |
|
237 | + protected function normalize( array $entries ) |
|
238 | 238 | { |
239 | 239 | $keys = [ |
240 | 240 | 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
241 | 241 | ]; |
242 | - array_walk($entries, function (&$entry) use ($keys) { |
|
243 | - foreach ($keys as $key) { |
|
242 | + array_walk( $entries, function( &$entry ) use ($keys) { |
|
243 | + foreach( $keys as $key ) { |
|
244 | 244 | try { |
245 | - $entry = $this->normalizeEntryString($entry, $key); |
|
246 | - } catch (\TypeError $error) { |
|
247 | - glsr_log()->once('error', 'Translation/normalize', $error); |
|
248 | - glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
245 | + $entry = $this->normalizeEntryString( $entry, $key ); |
|
246 | + } catch( \TypeError $error ) { |
|
247 | + glsr_log()->once( 'error', 'Translation/normalize', $error ); |
|
248 | + glsr_log()->once( 'debug', 'Translation/normalize', $entry ); |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 | }); |
@@ -256,10 +256,10 @@ discard block |
||
256 | 256 | * @param string $key |
257 | 257 | * @return array |
258 | 258 | */ |
259 | - protected function normalizeEntryString(array $entry, $key) |
|
259 | + protected function normalizeEntryString( array $entry, $key ) |
|
260 | 260 | { |
261 | - if (isset($entry[$key])) { |
|
262 | - $entry[$key] = $this->getEntryString($entry, $key); |
|
261 | + if( isset($entry[$key]) ) { |
|
262 | + $entry[$key] = $this->getEntryString( $entry, $key ); |
|
263 | 263 | } |
264 | 264 | return $entry; |
265 | 265 | } |
@@ -267,15 +267,15 @@ discard block |
||
267 | 267 | /** |
268 | 268 | * @return array |
269 | 269 | */ |
270 | - protected function normalizeSettings(array $strings) |
|
270 | + protected function normalizeSettings( array $strings ) |
|
271 | 271 | { |
272 | - $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
273 | - $strings = array_filter($strings, 'is_array'); |
|
274 | - foreach ($strings as &$string) { |
|
272 | + $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' ); |
|
273 | + $strings = array_filter( $strings, 'is_array' ); |
|
274 | + foreach( $strings as &$string ) { |
|
275 | 275 | $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
276 | - $string = wp_parse_args($string, $defaultString); |
|
276 | + $string = wp_parse_args( $string, $defaultString ); |
|
277 | 277 | } |
278 | - return array_filter($strings, function ($string) { |
|
278 | + return array_filter( $strings, function( $string ) { |
|
279 | 279 | return !empty($string['id']); |
280 | 280 | }); |
281 | 281 | } |
@@ -28,26 +28,26 @@ |
||
28 | 28 | /** |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function relative($date) |
|
31 | + public function relative( $date ) |
|
32 | 32 | { |
33 | - $diff = time() - strtotime($date); |
|
34 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
35 | - if ($diff > $timePeriod[0]) { |
|
33 | + $diff = time() - strtotime( $date ); |
|
34 | + foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
|
35 | + if( $diff > $timePeriod[0] ) { |
|
36 | 36 | continue; |
37 | 37 | } |
38 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
38 | + $unit = intval( floor( $diff / $timePeriod[1] ) ); |
|
39 | 39 | $relativeDates = [ |
40 | - _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
41 | - _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
42 | - _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
43 | - _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
44 | - _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
45 | - _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
46 | - _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
40 | + _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
|
41 | + _n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ), |
|
42 | + _n( 'an hour ago', '%s hours ago', $unit, 'site-reviews' ), |
|
43 | + _n( 'yesterday', '%s days ago', $unit, 'site-reviews' ), |
|
44 | + _n( 'a week ago', '%s weeks ago', $unit, 'site-reviews' ), |
|
45 | + _n( '%s month ago', '%s months ago', $unit, 'site-reviews' ), |
|
46 | + _n( '%s year ago', '%s years ago', $unit, 'site-reviews' ), |
|
47 | 47 | ]; |
48 | 48 | $relativeDate = $relativeDates[$i]; |
49 | - return Str::contains($relativeDate, '%s') |
|
50 | - ? sprintf($relativeDate, $unit) |
|
49 | + return Str::contains( $relativeDate, '%s' ) |
|
50 | + ? sprintf( $relativeDate, $unit ) |
|
51 | 51 | : $relativeDate; |
52 | 52 | } |
53 | 53 | } |
@@ -66,14 +66,14 @@ discard block |
||
66 | 66 | * @param mixed $data |
67 | 67 | * @return array |
68 | 68 | */ |
69 | - public function validate($data, array $rules = []) |
|
69 | + public function validate( $data, array $rules = [] ) |
|
70 | 70 | { |
71 | - $this->normalizeData($data); |
|
72 | - $this->setRules($rules); |
|
73 | - foreach ($this->rules as $attribute => $rules) { |
|
74 | - foreach ($rules as $rule) { |
|
75 | - $this->validateAttribute($attribute, $rule); |
|
76 | - if ($this->shouldStopValidating($attribute)) { |
|
71 | + $this->normalizeData( $data ); |
|
72 | + $this->setRules( $rules ); |
|
73 | + foreach( $this->rules as $attribute => $rules ) { |
|
74 | + foreach( $rules as $rule ) { |
|
75 | + $this->validateAttribute( $attribute, $rule ); |
|
76 | + if( $this->shouldStopValidating( $attribute ) ) { |
|
77 | 77 | break; |
78 | 78 | } |
79 | 79 | } |
@@ -88,18 +88,18 @@ discard block |
||
88 | 88 | * @return void |
89 | 89 | * @throws BadMethodCallException |
90 | 90 | */ |
91 | - public function validateAttribute($attribute, $rule) |
|
91 | + public function validateAttribute( $attribute, $rule ) |
|
92 | 92 | { |
93 | - list($rule, $parameters) = $this->parseRule($rule); |
|
94 | - if ('' == $rule) { |
|
93 | + list($rule, $parameters) = $this->parseRule( $rule ); |
|
94 | + if( '' == $rule ) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | - $value = $this->getValue($attribute); |
|
98 | - if (!method_exists($this, $method = 'validate'.$rule)) { |
|
99 | - throw new BadMethodCallException("Method [$method] does not exist."); |
|
97 | + $value = $this->getValue( $attribute ); |
|
98 | + if( !method_exists( $this, $method = 'validate'.$rule ) ) { |
|
99 | + throw new BadMethodCallException( "Method [$method] does not exist." ); |
|
100 | 100 | } |
101 | - if (!$this->$method($value, $attribute, $parameters)) { |
|
102 | - $this->addFailure($attribute, $rule, $parameters); |
|
101 | + if( !$this->$method( $value, $attribute, $parameters ) ) { |
|
102 | + $this->addFailure( $attribute, $rule, $parameters ); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | * @param string $rule |
110 | 110 | * @return void |
111 | 111 | */ |
112 | - protected function addError($attribute, $rule, array $parameters) |
|
112 | + protected function addError( $attribute, $rule, array $parameters ) |
|
113 | 113 | { |
114 | - $message = $this->getMessage($attribute, $rule, $parameters); |
|
114 | + $message = $this->getMessage( $attribute, $rule, $parameters ); |
|
115 | 115 | $this->errors[$attribute][] = $message; |
116 | 116 | } |
117 | 117 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * @param string $rule |
122 | 122 | * @return void |
123 | 123 | */ |
124 | - protected function addFailure($attribute, $rule, array $parameters) |
|
124 | + protected function addFailure( $attribute, $rule, array $parameters ) |
|
125 | 125 | { |
126 | - $this->addError($attribute, $rule, $parameters); |
|
126 | + $this->addError( $attribute, $rule, $parameters ); |
|
127 | 127 | $this->failedRules[$attribute][$rule] = $parameters; |
128 | 128 | } |
129 | 129 | |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @param string $attribute |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - protected function getAttributeType($attribute) |
|
135 | + protected function getAttributeType( $attribute ) |
|
136 | 136 | { |
137 | - return !$this->hasRule($attribute, $this->numericRules) |
|
137 | + return !$this->hasRule( $attribute, $this->numericRules ) |
|
138 | 138 | ? 'length' |
139 | 139 | : ''; |
140 | 140 | } |
@@ -145,13 +145,13 @@ discard block |
||
145 | 145 | * @param string $rule |
146 | 146 | * @return string|null |
147 | 147 | */ |
148 | - protected function getMessage($attribute, $rule, array $parameters) |
|
148 | + protected function getMessage( $attribute, $rule, array $parameters ) |
|
149 | 149 | { |
150 | - if (in_array($rule, $this->sizeRules)) { |
|
151 | - return $this->getSizeMessage($attribute, $rule, $parameters); |
|
150 | + if( in_array( $rule, $this->sizeRules ) ) { |
|
151 | + return $this->getSizeMessage( $attribute, $rule, $parameters ); |
|
152 | 152 | } |
153 | - $lowerRule = Str::snakeCase($rule); |
|
154 | - return $this->translator($lowerRule, $parameters); |
|
153 | + $lowerRule = Str::snakeCase( $rule ); |
|
154 | + return $this->translator( $lowerRule, $parameters ); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -160,15 +160,15 @@ discard block |
||
160 | 160 | * @param string|array $rules |
161 | 161 | * @return array|null |
162 | 162 | */ |
163 | - protected function getRule($attribute, $rules) |
|
163 | + protected function getRule( $attribute, $rules ) |
|
164 | 164 | { |
165 | - if (!array_key_exists($attribute, $this->rules)) { |
|
165 | + if( !array_key_exists( $attribute, $this->rules ) ) { |
|
166 | 166 | return; |
167 | 167 | } |
168 | - $rules = (array) $rules; |
|
169 | - foreach ($this->rules[$attribute] as $rule) { |
|
170 | - list($rule, $parameters) = $this->parseRule($rule); |
|
171 | - if (in_array($rule, $rules)) { |
|
168 | + $rules = (array)$rules; |
|
169 | + foreach( $this->rules[$attribute] as $rule ) { |
|
170 | + list($rule, $parameters) = $this->parseRule( $rule ); |
|
171 | + if( in_array( $rule, $rules ) ) { |
|
172 | 172 | return [$rule, $parameters]; |
173 | 173 | } |
174 | 174 | } |
@@ -180,17 +180,17 @@ discard block |
||
180 | 180 | * @param mixed $value |
181 | 181 | * @return mixed |
182 | 182 | */ |
183 | - protected function getSize($attribute, $value) |
|
183 | + protected function getSize( $attribute, $value ) |
|
184 | 184 | { |
185 | - $hasNumeric = $this->hasRule($attribute, $this->numericRules); |
|
186 | - if (is_numeric($value) && $hasNumeric) { |
|
185 | + $hasNumeric = $this->hasRule( $attribute, $this->numericRules ); |
|
186 | + if( is_numeric( $value ) && $hasNumeric ) { |
|
187 | 187 | return $value; |
188 | - } elseif (is_array($value)) { |
|
189 | - return count($value); |
|
188 | + } elseif( is_array( $value ) ) { |
|
189 | + return count( $value ); |
|
190 | 190 | } |
191 | - return function_exists('mb_strlen') |
|
192 | - ? mb_strlen($value) |
|
193 | - : strlen($value); |
|
191 | + return function_exists( 'mb_strlen' ) |
|
192 | + ? mb_strlen( $value ) |
|
193 | + : strlen( $value ); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | * @param string $rule |
200 | 200 | * @return string|null |
201 | 201 | */ |
202 | - protected function getSizeMessage($attribute, $rule, array $parameters) |
|
202 | + protected function getSizeMessage( $attribute, $rule, array $parameters ) |
|
203 | 203 | { |
204 | - $type = $this->getAttributeType($attribute); |
|
205 | - $lowerRule = Str::snakeCase($rule.$type); |
|
206 | - return $this->translator($lowerRule, $parameters); |
|
204 | + $type = $this->getAttributeType( $attribute ); |
|
205 | + $lowerRule = Str::snakeCase( $rule.$type ); |
|
206 | + return $this->translator( $lowerRule, $parameters ); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | * @param string $attribute |
212 | 212 | * @return mixed |
213 | 213 | */ |
214 | - protected function getValue($attribute) |
|
214 | + protected function getValue( $attribute ) |
|
215 | 215 | { |
216 | - if (isset($this->data[$attribute])) { |
|
216 | + if( isset($this->data[$attribute]) ) { |
|
217 | 217 | return $this->data[$attribute]; |
218 | 218 | } |
219 | 219 | } |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | * @param string|array $rules |
225 | 225 | * @return bool |
226 | 226 | */ |
227 | - protected function hasRule($attribute, $rules) |
|
227 | + protected function hasRule( $attribute, $rules ) |
|
228 | 228 | { |
229 | - return !is_null($this->getRule($attribute, $rules)); |
|
229 | + return !is_null( $this->getRule( $attribute, $rules ) ); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -234,10 +234,10 @@ discard block |
||
234 | 234 | * @param mixed $data |
235 | 235 | * @return void |
236 | 236 | */ |
237 | - protected function normalizeData($data) |
|
237 | + protected function normalizeData( $data ) |
|
238 | 238 | { |
239 | - $this->data = is_object($data) |
|
240 | - ? get_object_vars($data) |
|
239 | + $this->data = is_object( $data ) |
|
240 | + ? get_object_vars( $data ) |
|
241 | 241 | : $data; |
242 | 242 | } |
243 | 243 | |
@@ -247,11 +247,11 @@ discard block |
||
247 | 247 | * @param string $parameter |
248 | 248 | * @return array |
249 | 249 | */ |
250 | - protected function parseParameters($rule, $parameter) |
|
250 | + protected function parseParameters( $rule, $parameter ) |
|
251 | 251 | { |
252 | - return 'regex' == strtolower($rule) |
|
252 | + return 'regex' == strtolower( $rule ) |
|
253 | 253 | ? [$parameter] |
254 | - : str_getcsv($parameter); |
|
254 | + : str_getcsv( $parameter ); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -259,14 +259,14 @@ discard block |
||
259 | 259 | * @param string $rule |
260 | 260 | * @return array |
261 | 261 | */ |
262 | - protected function parseRule($rule) |
|
262 | + protected function parseRule( $rule ) |
|
263 | 263 | { |
264 | 264 | $parameters = []; |
265 | - if (Str::contains($rule, ':')) { |
|
266 | - list($rule, $parameter) = explode(':', $rule, 2); |
|
267 | - $parameters = $this->parseParameters($rule, $parameter); |
|
265 | + if( Str::contains( $rule, ':' ) ) { |
|
266 | + list($rule, $parameter) = explode( ':', $rule, 2 ); |
|
267 | + $parameters = $this->parseParameters( $rule, $parameter ); |
|
268 | 268 | } |
269 | - $rule = Str::camelCase($rule); |
|
269 | + $rule = Str::camelCase( $rule ); |
|
270 | 270 | return [$rule, $parameters]; |
271 | 271 | } |
272 | 272 | |
@@ -274,11 +274,11 @@ discard block |
||
274 | 274 | * Set the validation rules. |
275 | 275 | * @return void |
276 | 276 | */ |
277 | - protected function setRules(array $rules) |
|
277 | + protected function setRules( array $rules ) |
|
278 | 278 | { |
279 | - foreach ($rules as $key => $rule) { |
|
280 | - $rules[$key] = is_string($rule) |
|
281 | - ? explode('|', $rule) |
|
279 | + foreach( $rules as $key => $rule ) { |
|
280 | + $rules[$key] = is_string( $rule ) |
|
281 | + ? explode( '|', $rule ) |
|
282 | 282 | : $rule; |
283 | 283 | } |
284 | 284 | $this->rules = $rules; |
@@ -289,11 +289,11 @@ discard block |
||
289 | 289 | * @param string $attribute |
290 | 290 | * @return bool |
291 | 291 | */ |
292 | - protected function shouldStopValidating($attribute) |
|
292 | + protected function shouldStopValidating( $attribute ) |
|
293 | 293 | { |
294 | - return $this->hasRule($attribute, $this->implicitRules) |
|
294 | + return $this->hasRule( $attribute, $this->implicitRules ) |
|
295 | 295 | && isset($this->failedRules[$attribute]) |
296 | - && array_intersect(array_keys($this->failedRules[$attribute]), $this->implicitRules); |
|
296 | + && array_intersect( array_keys( $this->failedRules[$attribute] ), $this->implicitRules ); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | * @param string $attribute |
303 | 303 | * @return void|string |
304 | 304 | */ |
305 | - protected function translator($key, array $parameters) |
|
305 | + protected function translator( $key, array $parameters ) |
|
306 | 306 | { |
307 | - $strings = glsr(ValidationStringsDefaults::class)->defaults(); |
|
308 | - if (isset($strings[$key])) { |
|
309 | - return $this->replace($strings[$key], $parameters); |
|
307 | + $strings = glsr( ValidationStringsDefaults::class )->defaults(); |
|
308 | + if( isset($strings[$key]) ) { |
|
309 | + return $this->replace( $strings[$key], $parameters ); |
|
310 | 310 | } |
311 | 311 | return 'error'; |
312 | 312 | } |
@@ -16,23 +16,23 @@ discard block |
||
16 | 16 | * @param mixed $value |
17 | 17 | * @return mixed |
18 | 18 | */ |
19 | - abstract protected function getSize($attribute, $value); |
|
19 | + abstract protected function getSize( $attribute, $value ); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Replace all placeholders. |
23 | 23 | * @param string $message |
24 | 24 | * @return string |
25 | 25 | */ |
26 | - protected function replace($message, array $parameters) |
|
26 | + protected function replace( $message, array $parameters ) |
|
27 | 27 | { |
28 | - if (!Str::contains($message, '%s')) { |
|
28 | + if( !Str::contains( $message, '%s' ) ) { |
|
29 | 29 | return $message; |
30 | 30 | } |
31 | - return preg_replace_callback('/(%s)/', function () use (&$parameters) { |
|
32 | - foreach ($parameters as $key => $value) { |
|
33 | - return array_shift($parameters); |
|
31 | + return preg_replace_callback( '/(%s)/', function() use (&$parameters) { |
|
32 | + foreach( $parameters as $key => $value ) { |
|
33 | + return array_shift( $parameters ); |
|
34 | 34 | } |
35 | - }, $message); |
|
35 | + }, $message ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | * @param mixed $value |
43 | 43 | * @return bool |
44 | 44 | */ |
45 | - public function validateAccepted($value) |
|
45 | + public function validateAccepted( $value ) |
|
46 | 46 | { |
47 | 47 | $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
48 | - return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
48 | + return $this->validateRequired( $value ) && in_array( $value, $acceptable, true ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | * @param mixed $value |
55 | 55 | * @return bool |
56 | 56 | */ |
57 | - public function validateBetween($value, $attribute, array $parameters) |
|
57 | + public function validateBetween( $value, $attribute, array $parameters ) |
|
58 | 58 | { |
59 | - $this->requireParameterCount(2, $parameters, 'between'); |
|
60 | - $size = $this->getSize($attribute, $value); |
|
59 | + $this->requireParameterCount( 2, $parameters, 'between' ); |
|
60 | + $size = $this->getSize( $attribute, $value ); |
|
61 | 61 | return $size >= $parameters[0] && $size <= $parameters[1]; |
62 | 62 | } |
63 | 63 | |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * @param mixed $value |
67 | 67 | * @return bool |
68 | 68 | */ |
69 | - public function validateEmail($value) |
|
69 | + public function validateEmail( $value ) |
|
70 | 70 | { |
71 | - return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|
71 | + return false !== filter_var( $value, FILTER_VALIDATE_EMAIL ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | * @param mixed $value |
78 | 78 | * @return bool |
79 | 79 | */ |
80 | - public function validateMax($value, $attribute, array $parameters) |
|
80 | + public function validateMax( $value, $attribute, array $parameters ) |
|
81 | 81 | { |
82 | - $this->requireParameterCount(1, $parameters, 'max'); |
|
83 | - return $this->getSize($attribute, $value) <= $parameters[0]; |
|
82 | + $this->requireParameterCount( 1, $parameters, 'max' ); |
|
83 | + return $this->getSize( $attribute, $value ) <= $parameters[0]; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | * @param mixed $value |
90 | 90 | * @return bool |
91 | 91 | */ |
92 | - public function validateMin($value, $attribute, array $parameters) |
|
92 | + public function validateMin( $value, $attribute, array $parameters ) |
|
93 | 93 | { |
94 | - $this->requireParameterCount(1, $parameters, 'min'); |
|
95 | - return $this->getSize($attribute, $value) >= $parameters[0]; |
|
94 | + $this->requireParameterCount( 1, $parameters, 'min' ); |
|
95 | + return $this->getSize( $attribute, $value ) >= $parameters[0]; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @param mixed $value |
101 | 101 | * @return bool |
102 | 102 | */ |
103 | - public function validateNumber($value) |
|
103 | + public function validateNumber( $value ) |
|
104 | 104 | { |
105 | - return is_numeric($value); |
|
105 | + return is_numeric( $value ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | * @param mixed $value |
111 | 111 | * @return bool |
112 | 112 | */ |
113 | - public function validateRequired($value) |
|
113 | + public function validateRequired( $value ) |
|
114 | 114 | { |
115 | - return is_null($value) |
|
116 | - || (is_string($value) && '' === trim($value)) |
|
117 | - || (is_array($value) && count($value) < 1) |
|
115 | + return is_null( $value ) |
|
116 | + || (is_string( $value ) && '' === trim( $value )) |
|
117 | + || (is_array( $value ) && count( $value ) < 1) |
|
118 | 118 | ? false |
119 | 119 | : true; |
120 | 120 | } |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | * @return void |
127 | 127 | * @throws InvalidArgumentException |
128 | 128 | */ |
129 | - protected function requireParameterCount($count, array $parameters, $rule) |
|
129 | + protected function requireParameterCount( $count, array $parameters, $rule ) |
|
130 | 130 | { |
131 | - if (count($parameters) < $count) { |
|
132 | - throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
131 | + if( count( $parameters ) < $count ) { |
|
132 | + throw new InvalidArgumentException( "Validation rule $rule requires at least $count parameters." ); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
@@ -11,31 +11,31 @@ discard block |
||
11 | 11 | * @param string $domain |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function translate($original, $domain, array $args) |
|
14 | + public function translate( $original, $domain, array $args ) |
|
15 | 15 | { |
16 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
17 | - if (!in_array($domain, $domains)) { |
|
16 | + $domains = apply_filters( 'site-reviews/translator/domains', [Application::ID] ); |
|
17 | + if( !in_array( $domain, $domains ) ) { |
|
18 | 18 | return $original; |
19 | 19 | } |
20 | - $args = $this->normalizeTranslationArgs($args); |
|
21 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
22 | - if (empty($strings)) { |
|
20 | + $args = $this->normalizeTranslationArgs( $args ); |
|
21 | + $strings = $this->getTranslationStrings( $args['single'], $args['plural'] ); |
|
22 | + if( empty($strings) ) { |
|
23 | 23 | return $original; |
24 | 24 | } |
25 | - $string = current($strings); |
|
25 | + $string = current( $strings ); |
|
26 | 26 | return 'plural' == $string['type'] |
27 | - ? $this->translatePlural($domain, $string, $args) |
|
28 | - : $this->translateSingle($domain, $string, $args); |
|
27 | + ? $this->translatePlural( $domain, $string, $args ) |
|
28 | + : $this->translateSingle( $domain, $string, $args ); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Used when search/replacing a default text-domain translation |
33 | 33 | * @return string |
34 | 34 | */ |
35 | - public function getTranslation(array $args) |
|
35 | + public function getTranslation( array $args ) |
|
36 | 36 | { |
37 | - $args = $this->normalizeTranslationArgs($args); |
|
38 | - return get_translations_for_domain(Application::ID)->translate_plural($args['single'], $args['plural'], $args['number']); |
|
37 | + $args = $this->normalizeTranslationArgs( $args ); |
|
38 | + return get_translations_for_domain( Application::ID )->translate_plural( $args['single'], $args['plural'], $args['number'] ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | * @param string $plural |
44 | 44 | * @return array |
45 | 45 | */ |
46 | - protected function getTranslationStrings($single, $plural) |
|
46 | + protected function getTranslationStrings( $single, $plural ) |
|
47 | 47 | { |
48 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
49 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
50 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
48 | + return array_filter( glsr( Translation::class )->translations(), function( $string ) use ($single, $plural) { |
|
49 | + return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' ) |
|
50 | + && $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' ); |
|
51 | 51 | }); |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - protected function normalizeTranslationArgs(array $args) |
|
57 | + protected function normalizeTranslationArgs( array $args ) |
|
58 | 58 | { |
59 | 59 | $defaults = [ |
60 | 60 | 'context' => '', |
@@ -62,22 +62,22 @@ discard block |
||
62 | 62 | 'plural' => '', |
63 | 63 | 'single' => '', |
64 | 64 | ]; |
65 | - return shortcode_atts($defaults, $args); |
|
65 | + return shortcode_atts( $defaults, $args ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @param string $domain |
70 | 70 | * @return string |
71 | 71 | */ |
72 | - protected function translatePlural($domain, array $string, array $args) |
|
72 | + protected function translatePlural( $domain, array $string, array $args ) |
|
73 | 73 | { |
74 | - if (!empty($string['s2'])) { |
|
74 | + if( !empty($string['s2']) ) { |
|
75 | 75 | $args['single'] = $string['s2']; |
76 | 76 | } |
77 | - if (!empty($string['p2'])) { |
|
77 | + if( !empty($string['p2']) ) { |
|
78 | 78 | $args['plural'] = $string['p2']; |
79 | 79 | } |
80 | - return get_translations_for_domain($domain)->translate_plural( |
|
80 | + return get_translations_for_domain( $domain )->translate_plural( |
|
81 | 81 | $args['single'], |
82 | 82 | $args['plural'], |
83 | 83 | $args['number'], |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | * @param string $domain |
90 | 90 | * @return string |
91 | 91 | */ |
92 | - protected function translateSingle($domain, array $string, array $args) |
|
92 | + protected function translateSingle( $domain, array $string, array $args ) |
|
93 | 93 | { |
94 | - if (!empty($string['s2'])) { |
|
94 | + if( !empty($string['s2']) ) { |
|
95 | 95 | $args['single'] = $string['s2']; |
96 | 96 | } |
97 | - return get_translations_for_domain($domain)->translate( |
|
97 | + return get_translations_for_domain( $domain )->translate( |
|
98 | 98 | $args['single'], |
99 | 99 | $args['context'] |
100 | 100 | ); |