@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | * @param Reviews|null $reviews |
46 | 46 | * @return ReviewsHtml |
47 | 47 | */ |
48 | - public function build(array $args = [], $reviews = null) |
|
48 | + public function build( array $args = [], $reviews = null ) |
|
49 | 49 | { |
50 | - $this->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
51 | - $this->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
50 | + $this->args = glsr( SiteReviewsDefaults::class )->merge( $args ); |
|
51 | + $this->options = Arr::flattenArray( glsr( OptionManager::class )->all() ); |
|
52 | 52 | $this->reviews = $reviews instanceof Reviews |
53 | 53 | ? $reviews |
54 | - : glsr(ReviewManager::class)->get($this->args); |
|
54 | + : glsr( ReviewManager::class )->get( $this->args ); |
|
55 | 55 | $this->generateSchema(); |
56 | 56 | return $this->buildReviews(); |
57 | 57 | } |
@@ -59,26 +59,26 @@ discard block |
||
59 | 59 | /** |
60 | 60 | * @return ReviewHtml |
61 | 61 | */ |
62 | - public function buildReview(Review $review) |
|
62 | + public function buildReview( Review $review ) |
|
63 | 63 | { |
64 | - $review = apply_filters('site-reviews/review/build/before', $review); |
|
64 | + $review = apply_filters( 'site-reviews/review/build/before', $review ); |
|
65 | 65 | $this->current = $review; |
66 | 66 | $renderedFields = []; |
67 | - foreach ($review as $key => $value) { |
|
68 | - $method = Helper::buildMethodName($key, 'buildOption'); |
|
69 | - $field = method_exists($this, $method) |
|
70 | - ? $this->$method($key, $value) |
|
67 | + foreach( $review as $key => $value ) { |
|
68 | + $method = Helper::buildMethodName( $key, 'buildOption' ); |
|
69 | + $field = method_exists( $this, $method ) |
|
70 | + ? $this->$method( $key, $value ) |
|
71 | 71 | : false; |
72 | - $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this); |
|
73 | - if (false === $field) { |
|
72 | + $field = apply_filters( 'site-reviews/review/build/'.$key, $field, $value, $review, $this ); |
|
73 | + if( false === $field ) { |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | $renderedFields[$key] = $field; |
77 | 77 | } |
78 | - $this->wrap($renderedFields, $review); |
|
79 | - $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this); |
|
78 | + $this->wrap( $renderedFields, $review ); |
|
79 | + $renderedFields = apply_filters( 'site-reviews/review/build/after', $renderedFields, $review, $this ); |
|
80 | 80 | $this->current = null; |
81 | - return new ReviewHtml($review, (array) $renderedFields); |
|
81 | + return new ReviewHtml( $review, (array)$renderedFields ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -87,10 +87,10 @@ discard block |
||
87 | 87 | public function buildReviews() |
88 | 88 | { |
89 | 89 | $renderedReviews = []; |
90 | - foreach ($this->reviews as $index => $review) { |
|
91 | - $renderedReviews[] = $this->buildReview($review); |
|
90 | + foreach( $this->reviews as $index => $review ) { |
|
91 | + $renderedReviews[] = $this->buildReview( $review ); |
|
92 | 92 | } |
93 | - return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args); |
|
93 | + return new ReviewsHtml( $renderedReviews, $this->reviews->max_num_pages, $this->args ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function generateSchema() |
100 | 100 | { |
101 | - if (!wp_validate_boolean($this->args['schema'])) { |
|
101 | + if( !wp_validate_boolean( $this->args['schema'] ) ) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | - glsr(Schema::class)->store( |
|
105 | - glsr(Schema::class)->build($this->args) |
|
104 | + glsr( Schema::class )->store( |
|
105 | + glsr( Schema::class )->build( $this->args ) |
|
106 | 106 | ); |
107 | 107 | } |
108 | 108 | |
@@ -110,20 +110,20 @@ discard block |
||
110 | 110 | * @param string $text |
111 | 111 | * @return string |
112 | 112 | */ |
113 | - public function getExcerpt($text) |
|
113 | + public function getExcerpt( $text ) |
|
114 | 114 | { |
115 | - $limit = intval($this->getOption('settings.reviews.excerpts_length', 55)); |
|
116 | - $split = extension_loaded('intl') |
|
117 | - ? $this->getExcerptIntlSplit($text, $limit) |
|
118 | - : $this->getExcerptSplit($text, $limit); |
|
119 | - $hiddenText = substr($text, $split); |
|
120 | - if (!empty($hiddenText)) { |
|
121 | - $showMore = glsr(Builder::class)->span($hiddenText, [ |
|
115 | + $limit = intval( $this->getOption( 'settings.reviews.excerpts_length', 55 ) ); |
|
116 | + $split = extension_loaded( 'intl' ) |
|
117 | + ? $this->getExcerptIntlSplit( $text, $limit ) |
|
118 | + : $this->getExcerptSplit( $text, $limit ); |
|
119 | + $hiddenText = substr( $text, $split ); |
|
120 | + if( !empty($hiddenText) ) { |
|
121 | + $showMore = glsr( Builder::class )->span( $hiddenText, [ |
|
122 | 122 | 'class' => 'glsr-hidden glsr-hidden-text', |
123 | - 'data-show-less' => __('Show less', 'site-reviews'), |
|
124 | - 'data-show-more' => __('Show more', 'site-reviews'), |
|
125 | - ]); |
|
126 | - $text = ltrim(substr($text, 0, $split)).$showMore; |
|
123 | + 'data-show-less' => __( 'Show less', 'site-reviews' ), |
|
124 | + 'data-show-more' => __( 'Show more', 'site-reviews' ), |
|
125 | + ] ); |
|
126 | + $text = ltrim( substr( $text, 0, $split ) ).$showMore; |
|
127 | 127 | } |
128 | 128 | return $text; |
129 | 129 | } |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | * @param string $path |
134 | 134 | * @return bool |
135 | 135 | */ |
136 | - public function isHidden($key, $path = '') |
|
136 | + public function isHidden( $key, $path = '' ) |
|
137 | 137 | { |
138 | 138 | $isOptionEnabled = !empty($path) |
139 | - ? $this->isOptionEnabled($path) |
|
139 | + ? $this->isOptionEnabled( $path ) |
|
140 | 140 | : true; |
141 | - return in_array($key, $this->args['hide']) || !$isOptionEnabled; |
|
141 | + return in_array( $key, $this->args['hide'] ) || !$isOptionEnabled; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -146,25 +146,25 @@ discard block |
||
146 | 146 | * @param string $value |
147 | 147 | * @return bool |
148 | 148 | */ |
149 | - public function isHiddenOrEmpty($key, $value) |
|
149 | + public function isHiddenOrEmpty( $key, $value ) |
|
150 | 150 | { |
151 | - return $this->isHidden($key) || empty($value); |
|
151 | + return $this->isHidden( $key ) || empty($value); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * @param string $text |
156 | 156 | * @return string |
157 | 157 | */ |
158 | - public function normalizeText($text) |
|
158 | + public function normalizeText( $text ) |
|
159 | 159 | { |
160 | - $text = wp_kses($text, wp_kses_allowed_html()); |
|
161 | - $text = convert_smilies(strip_shortcodes($text)); |
|
162 | - $text = str_replace(']]>', ']]>', $text); |
|
163 | - $text = preg_replace('/(\R){2,}/', '$1', $text); |
|
164 | - if ($this->isOptionEnabled('settings.reviews.excerpts')) { |
|
165 | - $text = $this->getExcerpt($text); |
|
160 | + $text = wp_kses( $text, wp_kses_allowed_html() ); |
|
161 | + $text = convert_smilies( strip_shortcodes( $text ) ); |
|
162 | + $text = str_replace( ']]>', ']]>', $text ); |
|
163 | + $text = preg_replace( '/(\R){2,}/', '$1', $text ); |
|
164 | + if( $this->isOptionEnabled( 'settings.reviews.excerpts' ) ) { |
|
165 | + $text = $this->getExcerpt( $text ); |
|
166 | 166 | } |
167 | - return wptexturize(nl2br($text)); |
|
167 | + return wptexturize( nl2br( $text ) ); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | * @param string $value |
173 | 173 | * @return void|string |
174 | 174 | */ |
175 | - protected function buildOptionAssignedTo($key, $value) |
|
175 | + protected function buildOptionAssignedTo( $key, $value ) |
|
176 | 176 | { |
177 | - if ($this->isHidden($key, 'settings.reviews.assigned_links')) { |
|
177 | + if( $this->isHidden( $key, 'settings.reviews.assigned_links' ) ) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | - $post = get_post(glsr(Multilingual::class)->getPostId($value)); |
|
181 | - if (empty($post->ID)) { |
|
180 | + $post = get_post( glsr( Multilingual::class )->getPostId( $value ) ); |
|
181 | + if( empty($post->ID) ) { |
|
182 | 182 | return; |
183 | 183 | } |
184 | - $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [ |
|
185 | - 'href' => get_the_permalink($post->ID), |
|
186 | - ]); |
|
187 | - $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink); |
|
184 | + $permalink = glsr( Builder::class )->a( get_the_title( $post->ID ), [ |
|
185 | + 'href' => get_the_permalink( $post->ID ), |
|
186 | + ] ); |
|
187 | + $assignedTo = sprintf( __( 'Review of %s', 'site-reviews' ), $permalink ); |
|
188 | 188 | return '<span>'.$assignedTo.'</span>'; |
189 | 189 | } |
190 | 190 | |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | * @param string $value |
194 | 194 | * @return void|string |
195 | 195 | */ |
196 | - protected function buildOptionAuthor($key, $value) |
|
196 | + protected function buildOptionAuthor( $key, $value ) |
|
197 | 197 | { |
198 | - if (!$this->isHidden($key)) { |
|
198 | + if( !$this->isHidden( $key ) ) { |
|
199 | 199 | $name = Str::convertName( |
200 | 200 | $value, |
201 | - glsr_get_option('reviews.name.format'), |
|
202 | - glsr_get_option('reviews.name.initial') |
|
201 | + glsr_get_option( 'reviews.name.format' ), |
|
202 | + glsr_get_option( 'reviews.name.initial' ) |
|
203 | 203 | ); |
204 | 204 | return '<span>'.$name.'</span>'; |
205 | 205 | } |
@@ -210,18 +210,18 @@ discard block |
||
210 | 210 | * @param string $value |
211 | 211 | * @return void|string |
212 | 212 | */ |
213 | - protected function buildOptionAvatar($key, $value) |
|
213 | + protected function buildOptionAvatar( $key, $value ) |
|
214 | 214 | { |
215 | - if ($this->isHidden($key, 'settings.reviews.avatars')) { |
|
215 | + if( $this->isHidden( $key, 'settings.reviews.avatars' ) ) { |
|
216 | 216 | return; |
217 | 217 | } |
218 | - $size = $this->getOption('settings.reviews.avatars_size', 40); |
|
219 | - return glsr(Builder::class)->img([ |
|
218 | + $size = $this->getOption( 'settings.reviews.avatars_size', 40 ); |
|
219 | + return glsr( Builder::class )->img( [ |
|
220 | 220 | 'height' => $size, |
221 | - 'src' => $this->generateAvatar($value), |
|
222 | - 'style' => sprintf('width:%1$spx; height:%1$spx;', $size), |
|
221 | + 'src' => $this->generateAvatar( $value ), |
|
222 | + 'style' => sprintf( 'width:%1$spx; height:%1$spx;', $size ), |
|
223 | 223 | 'width' => $size, |
224 | - ]); |
|
224 | + ] ); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -229,10 +229,10 @@ discard block |
||
229 | 229 | * @param string $value |
230 | 230 | * @return void|string |
231 | 231 | */ |
232 | - protected function buildOptionContent($key, $value) |
|
232 | + protected function buildOptionContent( $key, $value ) |
|
233 | 233 | { |
234 | - $text = $this->normalizeText($value); |
|
235 | - if (!$this->isHiddenOrEmpty($key, $text)) { |
|
234 | + $text = $this->normalizeText( $value ); |
|
235 | + if( !$this->isHiddenOrEmpty( $key, $text ) ) { |
|
236 | 236 | return '<p>'.$text.'</p>'; |
237 | 237 | } |
238 | 238 | } |
@@ -242,19 +242,19 @@ discard block |
||
242 | 242 | * @param string $value |
243 | 243 | * @return void|string |
244 | 244 | */ |
245 | - protected function buildOptionDate($key, $value) |
|
245 | + protected function buildOptionDate( $key, $value ) |
|
246 | 246 | { |
247 | - if ($this->isHidden($key)) { |
|
247 | + if( $this->isHidden( $key ) ) { |
|
248 | 248 | return; |
249 | 249 | } |
250 | - $dateFormat = $this->getOption('settings.reviews.date.format', 'default'); |
|
251 | - if ('relative' == $dateFormat) { |
|
252 | - $date = glsr(Date::class)->relative($value); |
|
250 | + $dateFormat = $this->getOption( 'settings.reviews.date.format', 'default' ); |
|
251 | + if( 'relative' == $dateFormat ) { |
|
252 | + $date = glsr( Date::class )->relative( $value ); |
|
253 | 253 | } else { |
254 | 254 | $format = 'custom' == $dateFormat |
255 | - ? $this->getOption('settings.reviews.date.custom', 'M j, Y') |
|
256 | - : glsr(OptionManager::class)->getWP('date_format', 'F j, Y'); |
|
257 | - $date = date_i18n($format, strtotime($value)); |
|
255 | + ? $this->getOption( 'settings.reviews.date.custom', 'M j, Y' ) |
|
256 | + : glsr( OptionManager::class )->getWP( 'date_format', 'F j, Y' ); |
|
257 | + $date = date_i18n( $format, strtotime( $value ) ); |
|
258 | 258 | } |
259 | 259 | return '<span>'.$date.'</span>'; |
260 | 260 | } |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | * @param string $value |
265 | 265 | * @return void|string |
266 | 266 | */ |
267 | - protected function buildOptionRating($key, $value) |
|
267 | + protected function buildOptionRating( $key, $value ) |
|
268 | 268 | { |
269 | - if (!$this->isHiddenOrEmpty($key, $value)) { |
|
270 | - return glsr_star_rating($value); |
|
269 | + if( !$this->isHiddenOrEmpty( $key, $value ) ) { |
|
270 | + return glsr_star_rating( $value ); |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
@@ -276,16 +276,16 @@ discard block |
||
276 | 276 | * @param string $value |
277 | 277 | * @return void|string |
278 | 278 | */ |
279 | - protected function buildOptionResponse($key, $value) |
|
279 | + protected function buildOptionResponse( $key, $value ) |
|
280 | 280 | { |
281 | - if ($this->isHiddenOrEmpty($key, $value)) { |
|
281 | + if( $this->isHiddenOrEmpty( $key, $value ) ) { |
|
282 | 282 | return; |
283 | 283 | } |
284 | - $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name')); |
|
285 | - $text = $this->normalizeText($value); |
|
284 | + $title = sprintf( __( 'Response from %s', 'site-reviews' ), get_bloginfo( 'name' ) ); |
|
285 | + $text = $this->normalizeText( $value ); |
|
286 | 286 | $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
287 | - $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']); |
|
288 | - $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']); |
|
287 | + $response = glsr( Builder::class )->div( $text, ['class' => 'glsr-review-response-inner'] ); |
|
288 | + $background = glsr( Builder::class )->div( ['class' => 'glsr-review-response-background'] ); |
|
289 | 289 | return $response.$background; |
290 | 290 | } |
291 | 291 | |
@@ -294,13 +294,13 @@ discard block |
||
294 | 294 | * @param string $value |
295 | 295 | * @return void|string |
296 | 296 | */ |
297 | - protected function buildOptionTitle($key, $value) |
|
297 | + protected function buildOptionTitle( $key, $value ) |
|
298 | 298 | { |
299 | - if ($this->isHidden($key)) { |
|
299 | + if( $this->isHidden( $key ) ) { |
|
300 | 300 | return; |
301 | 301 | } |
302 | - if (empty($value)) { |
|
303 | - $value = __('No Title', 'site-reviews'); |
|
302 | + if( empty($value) ) { |
|
303 | + $value = __( 'No Title', 'site-reviews' ); |
|
304 | 304 | } |
305 | 305 | return '<h3>'.$value.'</h3>'; |
306 | 306 | } |
@@ -309,18 +309,18 @@ discard block |
||
309 | 309 | * @param string $avatarUrl |
310 | 310 | * @return string |
311 | 311 | */ |
312 | - protected function generateAvatar($avatarUrl) |
|
312 | + protected function generateAvatar( $avatarUrl ) |
|
313 | 313 | { |
314 | - if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) { |
|
314 | + if( !$this->isOptionEnabled( 'settings.reviews.avatars_regenerate' ) || 'local' != $this->current->review_type ) { |
|
315 | 315 | return $avatarUrl; |
316 | 316 | } |
317 | - if ($this->current->user_id) { |
|
318 | - $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id); |
|
317 | + if( $this->current->user_id ) { |
|
318 | + $authorIdOrEmail = get_the_author_meta( 'ID', $this->current->user_id ); |
|
319 | 319 | } |
320 | - if (empty($authorIdOrEmail)) { |
|
320 | + if( empty($authorIdOrEmail) ) { |
|
321 | 321 | $authorIdOrEmail = $this->current->email; |
322 | 322 | } |
323 | - if ($newAvatar = get_avatar_url($authorIdOrEmail)) { |
|
323 | + if( $newAvatar = get_avatar_url( $authorIdOrEmail ) ) { |
|
324 | 324 | return $newAvatar; |
325 | 325 | } |
326 | 326 | return $avatarUrl; |
@@ -331,22 +331,22 @@ discard block |
||
331 | 331 | * @param int $limit |
332 | 332 | * @return int |
333 | 333 | */ |
334 | - protected function getExcerptIntlSplit($text, $limit) |
|
334 | + protected function getExcerptIntlSplit( $text, $limit ) |
|
335 | 335 | { |
336 | - $words = IntlRuleBasedBreakIterator::createWordInstance(''); |
|
337 | - $words->setText($text); |
|
336 | + $words = IntlRuleBasedBreakIterator::createWordInstance( '' ); |
|
337 | + $words->setText( $text ); |
|
338 | 338 | $count = 0; |
339 | - foreach ($words as $offset) { |
|
340 | - if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) { |
|
339 | + foreach( $words as $offset ) { |
|
340 | + if( IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus() ) { |
|
341 | 341 | continue; |
342 | 342 | } |
343 | 343 | ++$count; |
344 | - if ($count != $limit) { |
|
344 | + if( $count != $limit ) { |
|
345 | 345 | continue; |
346 | 346 | } |
347 | 347 | return $offset; |
348 | 348 | } |
349 | - return strlen($text); |
|
349 | + return strlen( $text ); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -354,13 +354,13 @@ discard block |
||
354 | 354 | * @param int $limit |
355 | 355 | * @return int |
356 | 356 | */ |
357 | - protected function getExcerptSplit($text, $limit) |
|
357 | + protected function getExcerptSplit( $text, $limit ) |
|
358 | 358 | { |
359 | - if (str_word_count($text, 0) > $limit) { |
|
360 | - $words = array_keys(str_word_count($text, 2)); |
|
359 | + if( str_word_count( $text, 0 ) > $limit ) { |
|
360 | + $words = array_keys( str_word_count( $text, 2 ) ); |
|
361 | 361 | return $words[$limit]; |
362 | 362 | } |
363 | - return strlen($text); |
|
363 | + return strlen( $text ); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -368,9 +368,9 @@ discard block |
||
368 | 368 | * @param mixed $fallback |
369 | 369 | * @return mixed |
370 | 370 | */ |
371 | - protected function getOption($path, $fallback = '') |
|
371 | + protected function getOption( $path, $fallback = '' ) |
|
372 | 372 | { |
373 | - if (array_key_exists($path, $this->options)) { |
|
373 | + if( array_key_exists( $path, $this->options ) ) { |
|
374 | 374 | return $this->options[$path]; |
375 | 375 | } |
376 | 376 | return $fallback; |
@@ -380,25 +380,25 @@ discard block |
||
380 | 380 | * @param string $path |
381 | 381 | * @return bool |
382 | 382 | */ |
383 | - protected function isOptionEnabled($path) |
|
383 | + protected function isOptionEnabled( $path ) |
|
384 | 384 | { |
385 | - return 'yes' == $this->getOption($path); |
|
385 | + return 'yes' == $this->getOption( $path ); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
389 | 389 | * @return void |
390 | 390 | */ |
391 | - protected function wrap(array &$renderedFields, Review $review) |
|
391 | + protected function wrap( array &$renderedFields, Review $review ) |
|
392 | 392 | { |
393 | - $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this); |
|
394 | - array_walk($renderedFields, function (&$value, $key) use ($review) { |
|
395 | - $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review); |
|
396 | - if (empty($value)) { |
|
393 | + $renderedFields = apply_filters( 'site-reviews/review/wrap', $renderedFields, $review, $this ); |
|
394 | + array_walk( $renderedFields, function( &$value, $key ) use ($review) { |
|
395 | + $value = apply_filters( 'site-reviews/review/wrap/'.$key, $value, $review ); |
|
396 | + if( empty($value) ) { |
|
397 | 397 | return; |
398 | 398 | } |
399 | - $value = glsr(Builder::class)->div($value, [ |
|
399 | + $value = glsr( Builder::class )->div( $value, [ |
|
400 | 400 | 'class' => 'glsr-review-'.$key, |
401 | - ]); |
|
401 | + ] ); |
|
402 | 402 | }); |
403 | 403 | } |
404 | 404 | } |
@@ -39,20 +39,20 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @return string |
41 | 41 | */ |
42 | - public function render(array $attributes) |
|
42 | + public function render( array $attributes ) |
|
43 | 43 | { |
44 | 44 | $attributes['class'] = $attributes['className']; |
45 | - $shortcode = glsr(Shortcode::class); |
|
46 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
45 | + $shortcode = glsr( Shortcode::class ); |
|
46 | + if( 'edit' == filter_input( INPUT_GET, 'context' ) ) { |
|
47 | 47 | $this->filterFormFields(); |
48 | 48 | $this->filterRatingField(); |
49 | 49 | $this->filterShortcodeClass(); |
50 | 50 | $this->filterSubmitButton(); |
51 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
51 | + if( !$this->hasVisibleFields( $shortcode, $attributes ) ) { |
|
52 | 52 | $this->filterInterpolation(); |
53 | 53 | } |
54 | 54 | } |
55 | - return $shortcode->buildShortcode($attributes); |
|
55 | + return $shortcode->buildShortcode( $attributes ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | */ |
61 | 61 | protected function filterFormFields() |
62 | 62 | { |
63 | - add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
64 | - array_walk($config, function (&$field) { |
|
63 | + add_filter( 'site-reviews/config/forms/submission-form', function( array $config ) { |
|
64 | + array_walk( $config, function( &$field ) { |
|
65 | 65 | $field['disabled'] = true; |
66 | 66 | $field['tabindex'] = '-1'; |
67 | 67 | }); |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function filterInterpolation() |
76 | 76 | { |
77 | - add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
77 | + add_filter( 'site-reviews/interpolate/reviews-form', function( $context ) { |
|
78 | 78 | $context['class'] = 'glsr-default glsr-block-disabled'; |
79 | - $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
79 | + $context['fields'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' ); |
|
80 | 80 | $context['response'] = ''; |
81 | 81 | $context['submit_button'] = ''; |
82 | 82 | return $context; |
@@ -88,15 +88,15 @@ discard block |
||
88 | 88 | */ |
89 | 89 | protected function filterRatingField() |
90 | 90 | { |
91 | - add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
92 | - if ('rating' == $args['path']) { |
|
91 | + add_filter( 'site-reviews/rendered/field', function( $html, $type, $args ) { |
|
92 | + if( 'rating' == $args['path'] ) { |
|
93 | 93 | $stars = '<span class="glsr-stars">'; |
94 | - $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int) glsr()->constant('MAX_RATING', Rating::class)); |
|
95 | - $stars.= '</span>'; |
|
96 | - $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html); |
|
94 | + $stars .= str_repeat( '<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int)glsr()->constant( 'MAX_RATING', Rating::class ) ); |
|
95 | + $stars .= '</span>'; |
|
96 | + $html = preg_replace( '/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html ); |
|
97 | 97 | } |
98 | 98 | return $html; |
99 | - }, 10, 3); |
|
99 | + }, 10, 3 ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | protected function filterShortcodeClass() |
106 | 106 | { |
107 | - add_filter('site-reviews/style', function () { |
|
107 | + add_filter( 'site-reviews/style', function() { |
|
108 | 108 | return 'default'; |
109 | 109 | }); |
110 | 110 | } |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function filterSubmitButton() |
116 | 116 | { |
117 | - add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
118 | - return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
117 | + add_filter( 'site-reviews/rendered/template/form/submit-button', function( $template ) { |
|
118 | + return str_replace( 'type="submit"', 'tabindex="-1"', $template ); |
|
119 | 119 | }); |
120 | 120 | } |
121 | 121 | } |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <p class="about-description">We hope you love the changes in this new release!</p> |
4 | 4 | <div class="is-fullwidth"> |
@@ -16,31 +16,31 @@ discard block |
||
16 | 16 | |
17 | 17 | public function __construct() |
18 | 18 | { |
19 | - $this->manager = glsr(CountsManager::class); |
|
19 | + $this->manager = glsr( CountsManager::class ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param int $termTaxonomyId |
24 | 24 | * @return array |
25 | 25 | */ |
26 | - public function build($termTaxonomyId) |
|
26 | + public function build( $termTaxonomyId ) |
|
27 | 27 | { |
28 | - return $this->manager->buildCounts([ |
|
28 | + return $this->manager->buildCounts( [ |
|
29 | 29 | 'term_ids' => [$termTaxonomyId], |
30 | - ]); |
|
30 | + ] ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @return void |
35 | 35 | */ |
36 | - public function decrease(Review $review) |
|
36 | + public function decrease( Review $review ) |
|
37 | 37 | { |
38 | - foreach ($review->term_ids as $termId) { |
|
39 | - if (empty($counts = $this->get($termId))) { |
|
38 | + foreach( $review->term_ids as $termId ) { |
|
39 | + if( empty($counts = $this->get( $termId )) ) { |
|
40 | 40 | continue; |
41 | 41 | } |
42 | - $this->update($termId, |
|
43 | - $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
42 | + $this->update( $termId, |
|
43 | + $this->manager->decreaseRating( $counts, $review->review_type, $review->rating ) |
|
44 | 44 | ); |
45 | 45 | } |
46 | 46 | } |
@@ -49,23 +49,23 @@ discard block |
||
49 | 49 | * @param int $termId |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - public function get($termId) |
|
52 | + public function get( $termId ) |
|
53 | 53 | { |
54 | - return array_filter((array) get_term_meta($termId, CountsManager::META_COUNT, true)); |
|
54 | + return array_filter( (array)get_term_meta( $termId, CountsManager::META_COUNT, true ) ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @return void |
59 | 59 | */ |
60 | - public function increase(Review $review) |
|
60 | + public function increase( Review $review ) |
|
61 | 61 | { |
62 | - $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
63 | - foreach ($terms as $term) { |
|
64 | - $counts = $this->get($term['term_id']); |
|
62 | + $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) ); |
|
63 | + foreach( $terms as $term ) { |
|
64 | + $counts = $this->get( $term['term_id'] ); |
|
65 | 65 | $counts = empty($counts) |
66 | - ? $this->build($term['term_taxonomy_id']) |
|
67 | - : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
68 | - $this->update($term['term_id'], $counts); |
|
66 | + ? $this->build( $term['term_taxonomy_id'] ) |
|
67 | + : $this->manager->increaseRating( $counts, $review->review_type, $review->rating ); |
|
68 | + $this->update( $term['term_id'], $counts ); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -73,16 +73,16 @@ discard block |
||
73 | 73 | * @param int $termId |
74 | 74 | * @return void |
75 | 75 | */ |
76 | - public function update($termId, array $reviewCounts) |
|
76 | + public function update( $termId, array $reviewCounts ) |
|
77 | 77 | { |
78 | - $term = get_term($termId, Application::TAXONOMY); |
|
79 | - if (!isset($term->term_id)) { |
|
78 | + $term = get_term( $termId, Application::TAXONOMY ); |
|
79 | + if( !isset($term->term_id) ) { |
|
80 | 80 | return; |
81 | 81 | } |
82 | - $ratingCounts = $this->manager->flatten($reviewCounts); |
|
83 | - update_term_meta($termId, CountsManager::META_COUNT, $reviewCounts); |
|
84 | - update_term_meta($termId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
85 | - update_term_meta($termId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
82 | + $ratingCounts = $this->manager->flatten( $reviewCounts ); |
|
83 | + update_term_meta( $termId, CountsManager::META_COUNT, $reviewCounts ); |
|
84 | + update_term_meta( $termId, CountsManager::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
85 | + update_term_meta( $termId, CountsManager::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function updateAll() |
92 | 92 | { |
93 | - $terms = glsr(Database::class)->getTerms([ |
|
93 | + $terms = glsr( Database::class )->getTerms( [ |
|
94 | 94 | 'fields' => 'all', |
95 | - ]); |
|
96 | - foreach ($terms as $term) { |
|
97 | - $this->update($term->term_id, $this->build($term->term_taxonomy_id)); |
|
95 | + ] ); |
|
96 | + foreach( $terms as $term ) { |
|
97 | + $this->update( $term->term_id, $this->build( $term->term_taxonomy_id ) ); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | } |
@@ -14,30 +14,30 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - $this->manager = glsr(CountsManager::class); |
|
17 | + $this->manager = glsr( CountsManager::class ); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @param int $postId |
22 | 22 | * @return array |
23 | 23 | */ |
24 | - public function build($postId) |
|
24 | + public function build( $postId ) |
|
25 | 25 | { |
26 | - return $this->manager->buildCounts([ |
|
26 | + return $this->manager->buildCounts( [ |
|
27 | 27 | 'post_ids' => [$postId], |
28 | - ]); |
|
28 | + ] ); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @return void |
33 | 33 | */ |
34 | - public function decrease(Review $review) |
|
34 | + public function decrease( Review $review ) |
|
35 | 35 | { |
36 | - if (empty($counts = $this->get($review->assigned_to))) { |
|
36 | + if( empty($counts = $this->get( $review->assigned_to )) ) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | - $this->update($review->assigned_to, |
|
40 | - $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
39 | + $this->update( $review->assigned_to, |
|
40 | + $this->manager->decreaseRating( $counts, $review->review_type, $review->rating ) |
|
41 | 41 | ); |
42 | 42 | } |
43 | 43 | |
@@ -45,36 +45,36 @@ discard block |
||
45 | 45 | * @param int $postId |
46 | 46 | * @return array |
47 | 47 | */ |
48 | - public function get($postId) |
|
48 | + public function get( $postId ) |
|
49 | 49 | { |
50 | - return array_filter((array) get_post_meta($postId, CountsManager::META_COUNT, true)); |
|
50 | + return array_filter( (array)get_post_meta( $postId, CountsManager::META_COUNT, true ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @return void |
55 | 55 | */ |
56 | - public function increase(Review $review) |
|
56 | + public function increase( Review $review ) |
|
57 | 57 | { |
58 | - if (!(get_post($review->assigned_to) instanceof \WP_Post)) { |
|
58 | + if( !(get_post( $review->assigned_to ) instanceof \WP_Post) ) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | - $counts = $this->get($review->assigned_to); |
|
61 | + $counts = $this->get( $review->assigned_to ); |
|
62 | 62 | $counts = empty($counts) |
63 | - ? $this->build($review->assigned_to) |
|
64 | - : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
65 | - $this->update($review->assigned_to, $counts); |
|
63 | + ? $this->build( $review->assigned_to ) |
|
64 | + : $this->manager->increaseRating( $counts, $review->review_type, $review->rating ); |
|
65 | + $this->update( $review->assigned_to, $counts ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @param int $postId |
70 | 70 | * @return void |
71 | 71 | */ |
72 | - public function update($postId, array $reviewCounts) |
|
72 | + public function update( $postId, array $reviewCounts ) |
|
73 | 73 | { |
74 | - $ratingCounts = $this->manager->flatten($reviewCounts); |
|
75 | - update_post_meta($postId, CountsManager::META_COUNT, $reviewCounts); |
|
76 | - update_post_meta($postId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
77 | - update_post_meta($postId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
74 | + $ratingCounts = $this->manager->flatten( $reviewCounts ); |
|
75 | + update_post_meta( $postId, CountsManager::META_COUNT, $reviewCounts ); |
|
76 | + update_post_meta( $postId, CountsManager::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
77 | + update_post_meta( $postId, CountsManager::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function updateAll() |
84 | 84 | { |
85 | - $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
86 | - foreach ($postIds as $postId) { |
|
87 | - $this->update($postId, $this->build($postId)); |
|
85 | + $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' ); |
|
86 | + foreach( $postIds as $postId ) { |
|
87 | + $this->update( $postId, $this->build( $postId ) ); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @return false|Review |
21 | 21 | */ |
22 | - public function create(CreateReview $command) |
|
22 | + public function create( CreateReview $command ) |
|
23 | 23 | { |
24 | - $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command); |
|
25 | - $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command); |
|
26 | - $reviewValues = Arr::prefixArrayKeys($reviewValues); |
|
24 | + $reviewValues = glsr( CreateReviewDefaults::class )->restrict( (array)$command ); |
|
25 | + $reviewValues = apply_filters( 'site-reviews/create/review-values', $reviewValues, $command ); |
|
26 | + $reviewValues = Arr::prefixArrayKeys( $reviewValues ); |
|
27 | 27 | unset($reviewValues['json']); // @todo remove the need for this |
28 | 28 | $postValues = [ |
29 | 29 | 'comment_status' => 'closed', |
@@ -31,20 +31,20 @@ discard block |
||
31 | 31 | 'ping_status' => 'closed', |
32 | 32 | 'post_content' => $reviewValues['_content'], |
33 | 33 | 'post_date' => $reviewValues['_date'], |
34 | - 'post_date_gmt' => get_gmt_from_date($reviewValues['_date']), |
|
34 | + 'post_date_gmt' => get_gmt_from_date( $reviewValues['_date'] ), |
|
35 | 35 | 'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'], |
36 | - 'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted), |
|
36 | + 'post_status' => $this->getNewPostStatus( $reviewValues, $command->blacklisted ), |
|
37 | 37 | 'post_title' => $reviewValues['_title'], |
38 | 38 | 'post_type' => Application::POST_TYPE, |
39 | 39 | ]; |
40 | - $postId = wp_insert_post($postValues, true); |
|
41 | - if (is_wp_error($postId)) { |
|
42 | - glsr_log()->error($postId->get_error_message())->debug($postValues); |
|
40 | + $postId = wp_insert_post( $postValues, true ); |
|
41 | + if( is_wp_error( $postId ) ) { |
|
42 | + glsr_log()->error( $postId->get_error_message() )->debug( $postValues ); |
|
43 | 43 | return false; |
44 | 44 | } |
45 | - $this->setTerms($postId, $command->category); |
|
46 | - $review = $this->single(get_post($postId)); |
|
47 | - do_action('site-reviews/review/created', $review, $command); |
|
45 | + $this->setTerms( $postId, $command->category ); |
|
46 | + $review = $this->single( get_post( $postId ) ); |
|
47 | + do_action( 'site-reviews/review/created', $review, $command ); |
|
48 | 48 | return $review; |
49 | 49 | } |
50 | 50 | |
@@ -52,29 +52,29 @@ discard block |
||
52 | 52 | * @param string $metaReviewId |
53 | 53 | * @return void |
54 | 54 | */ |
55 | - public function delete($metaReviewId) |
|
55 | + public function delete( $metaReviewId ) |
|
56 | 56 | { |
57 | - if ($postId = $this->getPostId($metaReviewId)) { |
|
58 | - wp_delete_post($postId, true); |
|
57 | + if( $postId = $this->getPostId( $metaReviewId ) ) { |
|
58 | + wp_delete_post( $postId, true ); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @return object |
64 | 64 | */ |
65 | - public function get(array $args = []) |
|
65 | + public function get( array $args = [] ) |
|
66 | 66 | { |
67 | - $args = glsr(ReviewsDefaults::class)->merge($args); |
|
68 | - $metaQuery = glsr(QueryBuilder::class)->buildQuery( |
|
67 | + $args = glsr( ReviewsDefaults::class )->merge( $args ); |
|
68 | + $metaQuery = glsr( QueryBuilder::class )->buildQuery( |
|
69 | 69 | ['assigned_to', 'email', 'ip_address', 'type', 'rating'], |
70 | 70 | $args |
71 | 71 | ); |
72 | - $taxQuery = glsr(QueryBuilder::class)->buildQuery( |
|
72 | + $taxQuery = glsr( QueryBuilder::class )->buildQuery( |
|
73 | 73 | ['category'], |
74 | - ['category' => $this->normalizeTermIds($args['category'])] |
|
74 | + ['category' => $this->normalizeTermIds( $args['category'] )] |
|
75 | 75 | ); |
76 | - $paged = glsr(QueryBuilder::class)->getPaged( |
|
77 | - wp_validate_boolean($args['pagination']) |
|
76 | + $paged = glsr( QueryBuilder::class )->getPaged( |
|
77 | + wp_validate_boolean( $args['pagination'] ) |
|
78 | 78 | ); |
79 | 79 | $parameters = [ |
80 | 80 | 'meta_key' => '_pinned', |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | 'offset' => $args['offset'], |
83 | 83 | 'order' => $args['order'], |
84 | 84 | 'orderby' => 'meta_value '.$args['orderby'], |
85 | - 'paged' => Arr::get($args, 'paged', $paged), |
|
85 | + 'paged' => Arr::get( $args, 'paged', $paged ), |
|
86 | 86 | 'post__in' => $args['post__in'], |
87 | 87 | 'post__not_in' => $args['post__not_in'], |
88 | 88 | 'post_status' => 'publish', |
@@ -90,62 +90,62 @@ discard block |
||
90 | 90 | 'posts_per_page' => $args['per_page'], |
91 | 91 | 'tax_query' => $taxQuery, |
92 | 92 | ]; |
93 | - $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args); |
|
94 | - $query = new WP_Query($parameters); |
|
95 | - $results = array_map([$this, 'single'], $query->posts); |
|
96 | - $reviews = new Reviews($results, $query->max_num_pages, $args); |
|
97 | - return apply_filters('site-reviews/get/reviews', $reviews, $query); |
|
93 | + $parameters = apply_filters( 'site-reviews/get/reviews/query', $parameters, $args ); |
|
94 | + $query = new WP_Query( $parameters ); |
|
95 | + $results = array_map( [$this, 'single'], $query->posts ); |
|
96 | + $reviews = new Reviews( $results, $query->max_num_pages, $args ); |
|
97 | + return apply_filters( 'site-reviews/get/reviews', $reviews, $query ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @param string $metaReviewId |
102 | 102 | * @return int |
103 | 103 | */ |
104 | - public function getPostId($metaReviewId) |
|
104 | + public function getPostId( $metaReviewId ) |
|
105 | 105 | { |
106 | - return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId); |
|
106 | + return glsr( SqlQueries::class )->getPostIdFromReviewId( $metaReviewId ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * @return array |
111 | 111 | */ |
112 | - public function getRatingCounts(array $args = []) |
|
112 | + public function getRatingCounts( array $args = [] ) |
|
113 | 113 | { |
114 | - $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args); |
|
115 | - $counts = glsr(CountsManager::class)->getCounts([ |
|
116 | - 'post_ids' => Arr::convertStringToArray($args['assigned_to']), |
|
117 | - 'term_ids' => $this->normalizeTermIds($args['category']), |
|
114 | + $args = glsr( SiteReviewsSummaryDefaults::class )->filter( $args ); |
|
115 | + $counts = glsr( CountsManager::class )->getCounts( [ |
|
116 | + 'post_ids' => Arr::convertStringToArray( $args['assigned_to'] ), |
|
117 | + 'term_ids' => $this->normalizeTermIds( $args['category'] ), |
|
118 | 118 | 'type' => $args['type'], |
119 | - ]); |
|
120 | - return glsr(CountsManager::class)->flatten($counts, [ |
|
119 | + ] ); |
|
120 | + return glsr( CountsManager::class )->flatten( $counts, [ |
|
121 | 121 | 'min' => $args['rating'], |
122 | - ]); |
|
122 | + ] ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | 126 | * @param string $commaSeparatedTermIds |
127 | 127 | * @return array |
128 | 128 | */ |
129 | - public function normalizeTermIds($commaSeparatedTermIds) |
|
129 | + public function normalizeTermIds( $commaSeparatedTermIds ) |
|
130 | 130 | { |
131 | - $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id'); |
|
132 | - return array_unique(array_map('intval', $termIds)); |
|
131 | + $termIds = glsr_array_column( $this->normalizeTerms( $commaSeparatedTermIds ), 'term_id' ); |
|
132 | + return array_unique( array_map( 'intval', $termIds ) ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | 136 | * @param string $commaSeparatedTermIds |
137 | 137 | * @return array |
138 | 138 | */ |
139 | - public function normalizeTerms($commaSeparatedTermIds) |
|
139 | + public function normalizeTerms( $commaSeparatedTermIds ) |
|
140 | 140 | { |
141 | 141 | $terms = []; |
142 | - $termIds = Arr::convertStringToArray($commaSeparatedTermIds); |
|
143 | - foreach ($termIds as $termId) { |
|
144 | - if (is_numeric($termId)) { |
|
145 | - $termId = intval($termId); |
|
142 | + $termIds = Arr::convertStringToArray( $commaSeparatedTermIds ); |
|
143 | + foreach( $termIds as $termId ) { |
|
144 | + if( is_numeric( $termId ) ) { |
|
145 | + $termId = intval( $termId ); |
|
146 | 146 | } |
147 | - $term = term_exists($termId, Application::TAXONOMY); |
|
148 | - if (!isset($term['term_id'])) { |
|
147 | + $term = term_exists( $termId, Application::TAXONOMY ); |
|
148 | + if( !isset($term['term_id']) ) { |
|
149 | 149 | continue; |
150 | 150 | } |
151 | 151 | $terms[] = $term; |
@@ -157,44 +157,44 @@ discard block |
||
157 | 157 | * @param int $postId |
158 | 158 | * @return void |
159 | 159 | */ |
160 | - public function revert($postId) |
|
160 | + public function revert( $postId ) |
|
161 | 161 | { |
162 | - if (Application::POST_TYPE != get_post_field('post_type', $postId)) { |
|
162 | + if( Application::POST_TYPE != get_post_field( 'post_type', $postId ) ) { |
|
163 | 163 | return; |
164 | 164 | } |
165 | - delete_post_meta($postId, '_edit_last'); |
|
166 | - $result = wp_update_post([ |
|
165 | + delete_post_meta( $postId, '_edit_last' ); |
|
166 | + $result = wp_update_post( [ |
|
167 | 167 | 'ID' => $postId, |
168 | - 'post_content' => glsr(Database::class)->get($postId, 'content'), |
|
169 | - 'post_date' => glsr(Database::class)->get($postId, 'date'), |
|
170 | - 'post_title' => glsr(Database::class)->get($postId, 'title'), |
|
171 | - ]); |
|
172 | - if (is_wp_error($result)) { |
|
173 | - glsr_log()->error($result->get_error_message()); |
|
168 | + 'post_content' => glsr( Database::class )->get( $postId, 'content' ), |
|
169 | + 'post_date' => glsr( Database::class )->get( $postId, 'date' ), |
|
170 | + 'post_title' => glsr( Database::class )->get( $postId, 'title' ), |
|
171 | + ] ); |
|
172 | + if( is_wp_error( $result ) ) { |
|
173 | + glsr_log()->error( $result->get_error_message() ); |
|
174 | 174 | return; |
175 | 175 | } |
176 | - do_action('site-reviews/review/reverted', glsr_get_review($postId)); |
|
176 | + do_action( 'site-reviews/review/reverted', glsr_get_review( $postId ) ); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * @return Review |
181 | 181 | */ |
182 | - public function single(WP_Post $post) |
|
182 | + public function single( WP_Post $post ) |
|
183 | 183 | { |
184 | - if (Application::POST_TYPE != $post->post_type) { |
|
185 | - $post = new WP_Post((object) []); |
|
184 | + if( Application::POST_TYPE != $post->post_type ) { |
|
185 | + $post = new WP_Post( (object)[] ); |
|
186 | 186 | } |
187 | - $review = new Review($post); |
|
188 | - return apply_filters('site-reviews/get/review', $review, $post); |
|
187 | + $review = new Review( $post ); |
|
188 | + return apply_filters( 'site-reviews/get/review', $review, $post ); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * @param bool $isBlacklisted |
193 | 193 | * @return string |
194 | 194 | */ |
195 | - protected function getNewPostStatus(array $reviewValues, $isBlacklisted) |
|
195 | + protected function getNewPostStatus( array $reviewValues, $isBlacklisted ) |
|
196 | 196 | { |
197 | - $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval'); |
|
197 | + $requireApproval = glsr( OptionManager::class )->getBool( 'settings.general.require.approval' ); |
|
198 | 198 | return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted) |
199 | 199 | ? 'pending' |
200 | 200 | : 'publish'; |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | * @param string $termIds |
206 | 206 | * @return void |
207 | 207 | */ |
208 | - protected function setTerms($postId, $termIds) |
|
208 | + protected function setTerms( $postId, $termIds ) |
|
209 | 209 | { |
210 | - $termIds = $this->normalizeTermIds($termIds); |
|
211 | - if (empty($termIds)) { |
|
210 | + $termIds = $this->normalizeTermIds( $termIds ); |
|
211 | + if( empty($termIds) ) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | - $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY); |
|
215 | - if (is_wp_error($termTaxonomyIds)) { |
|
216 | - glsr_log()->error($termTaxonomyIds->get_error_message()); |
|
214 | + $termTaxonomyIds = wp_set_object_terms( $postId, $termIds, Application::TAXONOMY ); |
|
215 | + if( is_wp_error( $termTaxonomyIds ) ) { |
|
216 | + glsr_log()->error( $termTaxonomyIds->get_error_message() ); |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - $this->manager = glsr(CountsManager::class); |
|
17 | + $this->manager = glsr( CountsManager::class ); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @return void |
30 | 30 | */ |
31 | - public function decrease(Review $review) |
|
31 | + public function decrease( Review $review ) |
|
32 | 32 | { |
33 | - $this->update($this->manager->decreaseRating( |
|
33 | + $this->update( $this->manager->decreaseRating( |
|
34 | 34 | $this->get(), |
35 | 35 | $review->review_type, |
36 | 36 | $review->rating |
37 | - )); |
|
37 | + ) ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function get() |
44 | 44 | { |
45 | - $counts = glsr(OptionManager::class)->get('counts', []); |
|
46 | - if (!is_array($counts)) { |
|
47 | - glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
45 | + $counts = glsr( OptionManager::class )->get( 'counts', [] ); |
|
46 | + if( !is_array( $counts ) ) { |
|
47 | + glsr_log()->error( 'Review counts is not an array; possibly due to incorrectly imported reviews.' )->debug( $counts ); |
|
48 | 48 | return []; |
49 | 49 | } |
50 | 50 | return $counts; |
@@ -53,20 +53,20 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @return void |
55 | 55 | */ |
56 | - public function increase(Review $review) |
|
56 | + public function increase( Review $review ) |
|
57 | 57 | { |
58 | - if (empty($counts = $this->get())) { |
|
58 | + if( empty($counts = $this->get()) ) { |
|
59 | 59 | $counts = $this->build(); |
60 | 60 | } |
61 | - $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating)); |
|
61 | + $this->update( $this->manager->increaseRating( $counts, $review->review_type, $review->rating ) ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @return void |
66 | 66 | */ |
67 | - public function update(array $reviewCounts) |
|
67 | + public function update( array $reviewCounts ) |
|
68 | 68 | { |
69 | - glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
69 | + glsr( OptionManager::class )->set( 'counts', $reviewCounts ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,6 +74,6 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function updateAll() |
76 | 76 | { |
77 | - $this->update($this->build()); |
|
77 | + $this->update( $this->build() ); |
|
78 | 78 | } |
79 | 79 | } |
@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | * @return void |
29 | 29 | * @action set_object_terms |
30 | 30 | */ |
31 | - public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
31 | + public function onAfterChangeCategory( $postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds ) |
|
32 | 32 | { |
33 | - sort($newTTIds); |
|
34 | - sort($oldTTIds); |
|
35 | - if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
33 | + sort( $newTTIds ); |
|
34 | + sort( $oldTTIds ); |
|
35 | + if( $newTTIds === $oldTTIds || !$this->isReviewPostId( $postId ) ) { |
|
36 | 36 | return; |
37 | 37 | } |
38 | - $review = glsr_get_review($postId); |
|
39 | - if ('publish' !== $review->status) { |
|
38 | + $review = glsr_get_review( $postId ); |
|
39 | + if( 'publish' !== $review->status ) { |
|
40 | 40 | return; |
41 | 41 | } |
42 | - $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
43 | - $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
44 | - $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
45 | - if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
46 | - glsr(TermCountsManager::class)->decrease($review); |
|
42 | + $ignoredIds = array_intersect( $oldTTIds, $newTTIds ); |
|
43 | + $decreasedIds = array_diff( $oldTTIds, $ignoredIds ); |
|
44 | + $increasedIds = array_diff( $newTTIds, $ignoredIds ); |
|
45 | + if( $review->term_ids = glsr( Database::class )->getTermIds( $decreasedIds, 'term_taxonomy_id' ) ) { |
|
46 | + glsr( TermCountsManager::class )->decrease( $review ); |
|
47 | 47 | } |
48 | - if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
49 | - glsr(TermCountsManager::class)->increase($review); |
|
48 | + if( $review->term_ids = glsr( Database::class )->getTermIds( $increasedIds, 'term_taxonomy_id' ) ) { |
|
49 | + glsr( TermCountsManager::class )->increase( $review ); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | * @return void |
60 | 60 | * @action transition_post_status |
61 | 61 | */ |
62 | - public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
62 | + public function onAfterChangeStatus( $newStatus, $oldStatus, $post ) |
|
63 | 63 | { |
64 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') |
|
65 | - || in_array($oldStatus, ['new', $newStatus])) { |
|
64 | + if( Application::POST_TYPE != Arr::get( $post, 'post_type' ) |
|
65 | + || in_array( $oldStatus, ['new', $newStatus] ) ) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | - $review = glsr_get_review($post); |
|
69 | - if ('publish' == $post->post_status) { |
|
70 | - glsr(CountsManager::class)->increaseAll($review); |
|
68 | + $review = glsr_get_review( $post ); |
|
69 | + if( 'publish' == $post->post_status ) { |
|
70 | + glsr( CountsManager::class )->increaseAll( $review ); |
|
71 | 71 | } else { |
72 | - glsr(CountsManager::class)->decreaseAll($review); |
|
72 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
@@ -79,13 +79,13 @@ discard block |
||
79 | 79 | * @return void |
80 | 80 | * @action site-reviews/review/created |
81 | 81 | */ |
82 | - public function onAfterCreate(Review $review) |
|
82 | + public function onAfterCreate( Review $review ) |
|
83 | 83 | { |
84 | - if ('publish' !== $review->status) { |
|
84 | + if( 'publish' !== $review->status ) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | - glsr(GlobalCountsManager::class)->increase($review); |
|
88 | - glsr(PostCountsManager::class)->increase($review); |
|
87 | + glsr( GlobalCountsManager::class )->increase( $review ); |
|
88 | + glsr( PostCountsManager::class )->increase( $review ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | * @return void |
96 | 96 | * @action before_delete_post |
97 | 97 | */ |
98 | - public function onBeforeDelete($postId) |
|
98 | + public function onBeforeDelete( $postId ) |
|
99 | 99 | { |
100 | - if (!$this->isReviewPostId($postId)) { |
|
100 | + if( !$this->isReviewPostId( $postId ) ) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | - $review = glsr_get_review($postId); |
|
104 | - if ('trash' !== $review->status) { // do not run for trashed posts |
|
105 | - glsr(CountsManager::class)->decreaseAll($review); |
|
103 | + $review = glsr_get_review( $postId ); |
|
104 | + if( 'trash' !== $review->status ) { // do not run for trashed posts |
|
105 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -116,21 +116,21 @@ discard block |
||
116 | 116 | * @return void |
117 | 117 | * @action update_postmeta |
118 | 118 | */ |
119 | - public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
119 | + public function onBeforeUpdate( $metaId, $postId, $metaKey, $metaValue ) |
|
120 | 120 | { |
121 | - if (!$this->isReviewPostId($postId)) { |
|
121 | + if( !$this->isReviewPostId( $postId ) ) { |
|
122 | 122 | return; |
123 | 123 | } |
124 | - $metaKey = Str::removePrefix('_', $metaKey); |
|
125 | - if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
124 | + $metaKey = Str::removePrefix( '_', $metaKey ); |
|
125 | + if( !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] ) ) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | - $review = glsr_get_review($postId); |
|
129 | - if ($review->$metaKey == $metaValue) { |
|
128 | + $review = glsr_get_review( $postId ); |
|
129 | + if( $review->$metaKey == $metaValue ) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | - $method = Helper::buildMethodName($metaKey, 'onBeforeChange'); |
|
133 | - call_user_func([$this, $method], $review, $metaValue); |
|
132 | + $method = Helper::buildMethodName( $metaKey, 'onBeforeChange' ); |
|
133 | + call_user_func( [$this, $method], $review, $metaValue ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | * @param string|int $assignedTo |
140 | 140 | * @return void |
141 | 141 | */ |
142 | - protected function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
142 | + protected function onBeforeChangeAssignedTo( Review $review, $assignedTo ) |
|
143 | 143 | { |
144 | - glsr(PostCountsManager::class)->decrease($review); |
|
144 | + glsr( PostCountsManager::class )->decrease( $review ); |
|
145 | 145 | $review->assigned_to = $assignedTo; |
146 | - glsr(PostCountsManager::class)->increase($review); |
|
146 | + glsr( PostCountsManager::class )->increase( $review ); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | * @param string|int $rating |
153 | 153 | * @return void |
154 | 154 | */ |
155 | - protected function onBeforeChangeRating(Review $review, $rating) |
|
155 | + protected function onBeforeChangeRating( Review $review, $rating ) |
|
156 | 156 | { |
157 | - glsr(CountsManager::class)->decreaseAll($review); |
|
157 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
158 | 158 | $review->rating = $rating; |
159 | - glsr(CountsManager::class)->increaseAll($review); |
|
159 | + glsr( CountsManager::class )->increaseAll( $review ); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | * @param string $reviewType |
166 | 166 | * @return void |
167 | 167 | */ |
168 | - protected function onBeforeChangeReviewType(Review $review, $reviewType) |
|
168 | + protected function onBeforeChangeReviewType( Review $review, $reviewType ) |
|
169 | 169 | { |
170 | - glsr(CountsManager::class)->decreaseAll($review); |
|
170 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
171 | 171 | $review->review_type = $reviewType; |
172 | - glsr(CountsManager::class)->increaseAll($review); |
|
172 | + glsr( CountsManager::class )->increaseAll( $review ); |
|
173 | 173 | } |
174 | 174 | } |
@@ -9,21 +9,21 @@ discard block |
||
9 | 9 | * @param string $search |
10 | 10 | * @return string |
11 | 11 | */ |
12 | - public static function afterLast($subject, $search) |
|
12 | + public static function afterLast( $subject, $search ) |
|
13 | 13 | { |
14 | 14 | return '' === $search |
15 | 15 | ? $subject |
16 | - : array_reverse(explode($search, $subject))[0]; |
|
16 | + : array_reverse( explode( $search, $subject ) )[0]; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @param string $string |
21 | 21 | * @return string |
22 | 22 | */ |
23 | - public static function camelCase($string) |
|
23 | + public static function camelCase( $string ) |
|
24 | 24 | { |
25 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
26 | - return str_replace(' ', '', $string); |
|
25 | + $string = ucwords( str_replace( ['-', '_'], ' ', trim( $string ) ) ); |
|
26 | + return str_replace( ' ', '', $string ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | * @param string $needle |
32 | 32 | * @return bool |
33 | 33 | */ |
34 | - public static function contains($haystack, $needle) |
|
34 | + public static function contains( $haystack, $needle ) |
|
35 | 35 | { |
36 | - return false !== strpos($haystack, $needle); |
|
36 | + return false !== strpos( $haystack, $needle ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -42,27 +42,27 @@ discard block |
||
42 | 42 | * @param string $initialType period|period_space|space |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public static function convertName($name, $nameType = '', $initialType = '') |
|
45 | + public static function convertName( $name, $nameType = '', $initialType = '' ) |
|
46 | 46 | { |
47 | - $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
48 | - $firstName = array_shift($names); |
|
49 | - $lastName = array_pop($names); |
|
47 | + $names = preg_split( '/\W/', $name, 0, PREG_SPLIT_NO_EMPTY ); |
|
48 | + $firstName = array_shift( $names ); |
|
49 | + $lastName = array_pop( $names ); |
|
50 | 50 | $initialTypes = [ |
51 | 51 | 'period' => '.', |
52 | 52 | 'period_space' => '. ', |
53 | 53 | 'space' => ' ', |
54 | 54 | ]; |
55 | - $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
56 | - if ('initials' == $nameType) { |
|
57 | - return static::convertToInitials($name, $initialPunctuation); |
|
55 | + $initialPunctuation = (string)Arr::get( $initialTypes, $initialType, ' ' ); |
|
56 | + if( 'initials' == $nameType ) { |
|
57 | + return static::convertToInitials( $name, $initialPunctuation ); |
|
58 | 58 | } |
59 | 59 | $nameTypes = [ |
60 | 60 | 'first' => $firstName, |
61 | - 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
61 | + 'first_initial' => substr( $firstName, 0, 1 ).$initialPunctuation.$lastName, |
|
62 | 62 | 'last' => $lastName, |
63 | - 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
63 | + 'last_initial' => $firstName.' '.substr( $lastName, 0, 1 ).$initialPunctuation, |
|
64 | 64 | ]; |
65 | - return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
65 | + return trim( (string)Arr::get( $nameTypes, $nameType, $name ) ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | * @param string $prefix |
71 | 71 | * @return string |
72 | 72 | */ |
73 | - public static function convertPathToId($path, $prefix = '') |
|
73 | + public static function convertPathToId( $path, $prefix = '' ) |
|
74 | 74 | { |
75 | - return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
75 | + return str_replace( ['[', ']'], ['-', ''], static::convertPathToName( $path, $prefix ) ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | * @param string $prefix |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - public static function convertPathToName($path, $prefix = '') |
|
83 | + public static function convertPathToName( $path, $prefix = '' ) |
|
84 | 84 | { |
85 | - $levels = explode('.', $path); |
|
86 | - return array_reduce($levels, function ($result, $value) { |
|
85 | + $levels = explode( '.', $path ); |
|
86 | + return array_reduce( $levels, function( $result, $value ) { |
|
87 | 87 | return $result .= '['.$value.']'; |
88 | - }, $prefix); |
|
88 | + }, $prefix ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | * @param string $initialPunctuation |
94 | 94 | * @return string |
95 | 95 | */ |
96 | - public static function convertToInitials($name, $initialPunctuation = '') |
|
96 | + public static function convertToInitials( $name, $initialPunctuation = '' ) |
|
97 | 97 | { |
98 | - preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
99 | - return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
100 | - return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
98 | + preg_match_all( '/(?<=\s|\b)\pL/u', $name, $matches ); |
|
99 | + return array_reduce( $matches[0], function( $carry, $word ) use ($initialPunctuation) { |
|
100 | + return $carry.strtoupper( substr( $word, 0, 1 ) ).$initialPunctuation; |
|
101 | 101 | }); |
102 | 102 | } |
103 | 103 | |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param string $string |
106 | 106 | * @return string |
107 | 107 | */ |
108 | - public static function dashCase($string) |
|
108 | + public static function dashCase( $string ) |
|
109 | 109 | { |
110 | - return str_replace('_', '-', static::snakeCase($string)); |
|
110 | + return str_replace( '_', '-', static::snakeCase( $string ) ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | * @param string $haystack |
116 | 116 | * @return bool |
117 | 117 | */ |
118 | - public static function endsWith($needle, $haystack) |
|
118 | + public static function endsWith( $needle, $haystack ) |
|
119 | 119 | { |
120 | - $length = strlen($needle); |
|
120 | + $length = strlen( $needle ); |
|
121 | 121 | return 0 != $length |
122 | - ? substr($haystack, -$length) === $needle |
|
122 | + ? substr( $haystack, -$length ) === $needle |
|
123 | 123 | : true; |
124 | 124 | } |
125 | 125 | |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | * @param string|null $trim |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - public static function prefix($prefix, $string, $trim = null) |
|
132 | + public static function prefix( $prefix, $string, $trim = null ) |
|
133 | 133 | { |
134 | - if (null === $trim) { |
|
134 | + if( null === $trim ) { |
|
135 | 135 | $trim = $prefix; |
136 | 136 | } |
137 | - return $prefix.trim(static::removePrefix($trim, $string)); |
|
137 | + return $prefix.trim( static::removePrefix( $trim, $string ) ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | * @param string $string |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public static function removePrefix($prefix, $string) |
|
145 | + public static function removePrefix( $prefix, $string ) |
|
146 | 146 | { |
147 | - return static::startsWith($prefix, $string) |
|
148 | - ? substr($string, strlen($prefix)) |
|
147 | + return static::startsWith( $prefix, $string ) |
|
148 | + ? substr( $string, strlen( $prefix ) ) |
|
149 | 149 | : $string; |
150 | 150 | } |
151 | 151 | |
@@ -153,16 +153,16 @@ discard block |
||
153 | 153 | * @param string $string |
154 | 154 | * @return string |
155 | 155 | */ |
156 | - public static function snakeCase($string) |
|
156 | + public static function snakeCase( $string ) |
|
157 | 157 | { |
158 | - if (!ctype_lower($string)) { |
|
159 | - $string = preg_replace('/\s+/u', '', $string); |
|
160 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
161 | - $string = function_exists('mb_strtolower') |
|
162 | - ? mb_strtolower($string, 'UTF-8') |
|
163 | - : strtolower($string); |
|
158 | + if( !ctype_lower( $string ) ) { |
|
159 | + $string = preg_replace( '/\s+/u', '', $string ); |
|
160 | + $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string ); |
|
161 | + $string = function_exists( 'mb_strtolower' ) |
|
162 | + ? mb_strtolower( $string, 'UTF-8' ) |
|
163 | + : strtolower( $string ); |
|
164 | 164 | } |
165 | - return str_replace('-', '_', $string); |
|
165 | + return str_replace( '-', '_', $string ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * @param string $haystack |
171 | 171 | * @return bool |
172 | 172 | */ |
173 | - public static function startsWith($needle, $haystack) |
|
173 | + public static function startsWith( $needle, $haystack ) |
|
174 | 174 | { |
175 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
175 | + return substr( $haystack, 0, strlen( $needle ) ) === $needle; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | * @param int $length |
181 | 181 | * @return string |
182 | 182 | */ |
183 | - public static function truncate($string, $length) |
|
183 | + public static function truncate( $string, $length ) |
|
184 | 184 | { |
185 | - return strlen($string) > $length |
|
186 | - ? substr($string, 0, $length) |
|
185 | + return strlen( $string ) > $length |
|
186 | + ? substr( $string, 0, $length ) |
|
187 | 187 | : $string; |
188 | 188 | } |
189 | 189 | } |