@@ -42,7 +42,9 @@ discard block |
||
| 42 | 42 | $this->ratingCounts = glsr( CountsManager::class )->flatten( $counts, [ |
| 43 | 43 | 'min' => $args['rating'], |
| 44 | 44 | ]); |
| 45 | - if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ))return; |
|
| 45 | + if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' )) { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 46 | 48 | $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts ); |
| 47 | 49 | $this->generateSchema(); |
| 48 | 50 | return glsr( Template::class )->build( 'templates/reviews-summary', [ |
@@ -63,7 +65,9 @@ discard block |
||
| 63 | 65 | */ |
| 64 | 66 | protected function buildPercentage() |
| 65 | 67 | { |
| 66 | - if( $this->isHidden( 'bars' ))return; |
|
| 68 | + if( $this->isHidden( 'bars' )) { |
|
| 69 | + return; |
|
| 70 | + } |
|
| 67 | 71 | $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts )); |
| 68 | 72 | $bars = array_reduce( range( Rating::MAX_RATING, 1 ), function( $carry, $level ) use( $percentages ) { |
| 69 | 73 | $label = $this->buildPercentageLabel( $this->args['labels'][$level] ); |
@@ -116,7 +120,9 @@ discard block |
||
| 116 | 120 | */ |
| 117 | 121 | protected function buildRating() |
| 118 | 122 | { |
| 119 | - if( $this->isHidden( 'rating' ))return; |
|
| 123 | + if( $this->isHidden( 'rating' )) { |
|
| 124 | + return; |
|
| 125 | + } |
|
| 120 | 126 | return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' ); |
| 121 | 127 | } |
| 122 | 128 | |
@@ -125,7 +131,9 @@ discard block |
||
| 125 | 131 | */ |
| 126 | 132 | protected function buildStars() |
| 127 | 133 | { |
| 128 | - if( $this->isHidden( 'stars' ))return; |
|
| 134 | + if( $this->isHidden( 'stars' )) { |
|
| 135 | + return; |
|
| 136 | + } |
|
| 129 | 137 | $stars = glsr_star_rating( $this->averageRating ); |
| 130 | 138 | return $this->wrap( 'stars', $stars ); |
| 131 | 139 | } |
@@ -135,7 +143,9 @@ discard block |
||
| 135 | 143 | */ |
| 136 | 144 | protected function buildText() |
| 137 | 145 | { |
| 138 | - if( $this->isHidden( 'summary' ))return; |
|
| 146 | + if( $this->isHidden( 'summary' )) { |
|
| 147 | + return; |
|
| 148 | + } |
|
| 139 | 149 | $count = intval( array_sum( $this->ratingCounts )); |
| 140 | 150 | if( empty( $this->args['text'] )) { |
| 141 | 151 | // @todo document this change |
@@ -160,7 +170,9 @@ discard block |
||
| 160 | 170 | */ |
| 161 | 171 | protected function generateSchema() |
| 162 | 172 | { |
| 163 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
| 173 | + if( !wp_validate_boolean( $this->args['schema'] )) { |
|
| 174 | + return; |
|
| 175 | + } |
|
| 164 | 176 | glsr( Schema::class )->store( |
| 165 | 177 | glsr( Schema::class )->buildSummary( $this->args ) |
| 166 | 178 | ); |
@@ -67,7 +67,9 @@ discard block |
||
| 67 | 67 | $field = method_exists( $this, $method ) |
| 68 | 68 | ? $this->$method( $key, $value ) |
| 69 | 69 | : apply_filters( 'site-reviews/review/build/'.$key, false, $value, $this, $review ); |
| 70 | - if( $field === false )continue; |
|
| 70 | + if( $field === false ) { |
|
| 71 | + continue; |
|
| 72 | + } |
|
| 71 | 73 | $renderedFields[$key] = $field; |
| 72 | 74 | } |
| 73 | 75 | $this->wrap( $renderedFields, $review ); |
@@ -95,7 +97,9 @@ discard block |
||
| 95 | 97 | */ |
| 96 | 98 | public function generateSchema() |
| 97 | 99 | { |
| 98 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
| 100 | + if( !wp_validate_boolean( $this->args['schema'] )) { |
|
| 101 | + return; |
|
| 102 | + } |
|
| 99 | 103 | glsr( Schema::class )->store( |
| 100 | 104 | glsr( Schema::class )->build( $this->args ) |
| 101 | 105 | ); |
@@ -121,9 +125,13 @@ discard block |
||
| 121 | 125 | */ |
| 122 | 126 | protected function buildOptionAssignedTo( $key, $value ) |
| 123 | 127 | { |
| 124 | - if( $this->isHidden( $key, 'settings.reviews.assigned_links' ))return; |
|
| 128 | + if( $this->isHidden( $key, 'settings.reviews.assigned_links' )) { |
|
| 129 | + return; |
|
| 130 | + } |
|
| 125 | 131 | $post = glsr( Polylang::class )->getPost( $value ); |
| 126 | - if( !( $post instanceof WP_Post ))return; |
|
| 132 | + if( !( $post instanceof WP_Post )) { |
|
| 133 | + return; |
|
| 134 | + } |
|
| 127 | 135 | $permalink = glsr( Builder::class )->a( get_the_title( $post->ID ), [ |
| 128 | 136 | 'href' => get_the_permalink( $post->ID ), |
| 129 | 137 | ]); |
@@ -138,7 +146,9 @@ discard block |
||
| 138 | 146 | */ |
| 139 | 147 | protected function buildOptionAuthor( $key, $value ) |
| 140 | 148 | { |
| 141 | - if( $this->isHidden( $key ))return; |
|
| 149 | + if( $this->isHidden( $key )) { |
|
| 150 | + return; |
|
| 151 | + } |
|
| 142 | 152 | return '<span>'.$value.'</span>'; |
| 143 | 153 | } |
| 144 | 154 | |
@@ -149,7 +159,9 @@ discard block |
||
| 149 | 159 | */ |
| 150 | 160 | protected function buildOptionAvatar( $key, $value ) |
| 151 | 161 | { |
| 152 | - if( $this->isHidden( $key, 'settings.reviews.avatars' ))return; |
|
| 162 | + if( $this->isHidden( $key, 'settings.reviews.avatars' )) { |
|
| 163 | + return; |
|
| 164 | + } |
|
| 153 | 165 | $size = $this->getOption( 'settings.reviews.avatars_size', 40 ); |
| 154 | 166 | return glsr( Builder::class )->img([ |
| 155 | 167 | 'height' => $size, |
@@ -167,7 +179,9 @@ discard block |
||
| 167 | 179 | protected function buildOptionContent( $key, $value ) |
| 168 | 180 | { |
| 169 | 181 | $text = $this->normalizeText( $value ); |
| 170 | - if( $this->isHiddenOrEmpty( $key, $text ))return; |
|
| 182 | + if( $this->isHiddenOrEmpty( $key, $text )) { |
|
| 183 | + return; |
|
| 184 | + } |
|
| 171 | 185 | return '<p>'.$text.'</p>'; |
| 172 | 186 | } |
| 173 | 187 | |
@@ -178,7 +192,9 @@ discard block |
||
| 178 | 192 | */ |
| 179 | 193 | protected function buildOptionDate( $key, $value ) |
| 180 | 194 | { |
| 181 | - if( $this->isHidden( $key ))return; |
|
| 195 | + if( $this->isHidden( $key )) { |
|
| 196 | + return; |
|
| 197 | + } |
|
| 182 | 198 | $dateFormat = $this->getOption( 'settings.reviews.date.format', 'default' ); |
| 183 | 199 | if( $dateFormat == 'relative' ) { |
| 184 | 200 | $date = glsr( Date::class )->relative( $value ); |
@@ -199,7 +215,9 @@ discard block |
||
| 199 | 215 | */ |
| 200 | 216 | protected function buildOptionRating( $key, $value ) |
| 201 | 217 | { |
| 202 | - if( $this->isHiddenOrEmpty( $key, $value ))return; |
|
| 218 | + if( $this->isHiddenOrEmpty( $key, $value )) { |
|
| 219 | + return; |
|
| 220 | + } |
|
| 203 | 221 | return glsr_star_rating( $value ); |
| 204 | 222 | } |
| 205 | 223 | |
@@ -210,7 +228,9 @@ discard block |
||
| 210 | 228 | */ |
| 211 | 229 | protected function buildOptionResponse( $key, $value ) |
| 212 | 230 | { |
| 213 | - if( $this->isHiddenOrEmpty( $key, $value ))return; |
|
| 231 | + if( $this->isHiddenOrEmpty( $key, $value )) { |
|
| 232 | + return; |
|
| 233 | + } |
|
| 214 | 234 | $title = sprintf( __( 'Response from %s', 'site-reviews' ), get_bloginfo( 'name' )); |
| 215 | 235 | $text = $this->normalizeText( $value ); |
| 216 | 236 | $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
@@ -226,7 +246,9 @@ discard block |
||
| 226 | 246 | */ |
| 227 | 247 | protected function buildOptionTitle( $key, $value ) |
| 228 | 248 | { |
| 229 | - if( $this->isHidden( $key ))return; |
|
| 249 | + if( $this->isHidden( $key )) { |
|
| 250 | + return; |
|
| 251 | + } |
|
| 230 | 252 | if( empty( $value )) { |
| 231 | 253 | $value = __( 'No Title', 'site-reviews' ); |
| 232 | 254 | } |
@@ -285,9 +307,13 @@ discard block |
||
| 285 | 307 | $words->setText( $text ); |
| 286 | 308 | $count = 0; |
| 287 | 309 | foreach( $words as $offset ){ |
| 288 | - if( $words->getRuleStatus() === IntlRuleBasedBreakIterator::WORD_NONE )continue; |
|
| 310 | + if( $words->getRuleStatus() === IntlRuleBasedBreakIterator::WORD_NONE ) { |
|
| 311 | + continue; |
|
| 312 | + } |
|
| 289 | 313 | $count++; |
| 290 | - if( $count != $limit )continue; |
|
| 314 | + if( $count != $limit ) { |
|
| 315 | + continue; |
|
| 316 | + } |
|
| 291 | 317 | return $offset; |
| 292 | 318 | } |
| 293 | 319 | return strlen( $text ); |
@@ -363,7 +389,9 @@ discard block |
||
| 363 | 389 | $renderedFields = apply_filters( 'site-reviews/review/wrap', $renderedFields, $review ); |
| 364 | 390 | array_walk( $renderedFields, function( &$value, $key ) use( $review ) { |
| 365 | 391 | $value = apply_filters( 'site-reviews/review/wrap/'.$key, $value, $review ); |
| 366 | - if( empty( $value ))return; |
|
| 392 | + if( empty( $value )) { |
|
| 393 | + return; |
|
| 394 | + } |
|
| 367 | 395 | $value = glsr( Builder::class )->div( $value, [ |
| 368 | 396 | 'class' => 'glsr-review-'.$key, |
| 369 | 397 | ]); |
@@ -20,7 +20,9 @@ discard block |
||
| 20 | 20 | 'glsr_log', |
| 21 | 21 | 'glsr_star_rating', |
| 22 | 22 | ); |
| 23 | - if( !in_array( $hook, $hooks ) || !function_exists( $hook ))return; |
|
| 23 | + if( !in_array( $hook, $hooks ) || !function_exists( $hook )) { |
|
| 24 | + return; |
|
| 25 | + } |
|
| 24 | 26 | add_filter( $hook, function() use( $hook, $args ) { |
| 25 | 27 | array_shift( $args ); // remove the fallback value |
| 26 | 28 | return call_user_func_array( $hook, $args ); |
@@ -30,7 +32,8 @@ discard block |
||
| 30 | 32 | /** |
| 31 | 33 | * @return mixed |
| 32 | 34 | */ |
| 33 | -function glsr( $alias = null ) { |
|
| 35 | +function glsr( $alias = null ) |
|
| 36 | +{ |
|
| 34 | 37 | $app = \GeminiLabs\SiteReviews\Application::load(); |
| 35 | 38 | return !empty( $alias ) |
| 36 | 39 | ? $app->make( $alias ) |
@@ -42,11 +45,14 @@ discard block |
||
| 42 | 45 | * @param $column string |
| 43 | 46 | * @return array |
| 44 | 47 | */ |
| 45 | -function glsr_array_column( array $array, $column ) { |
|
| 48 | +function glsr_array_column( array $array, $column ) |
|
| 49 | +{ |
|
| 46 | 50 | $result = array(); |
| 47 | 51 | foreach( $array as $subarray ) { |
| 48 | 52 | $subarray = (array)$subarray; |
| 49 | - if( !isset( $subarray[$column] ))continue; |
|
| 53 | + if( !isset( $subarray[$column] )) { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 50 | 56 | $result[] = $subarray[$column]; |
| 51 | 57 | } |
| 52 | 58 | return $result; |
@@ -55,7 +61,8 @@ discard block |
||
| 55 | 61 | /** |
| 56 | 62 | * @return void |
| 57 | 63 | */ |
| 58 | -function glsr_calculate_ratings() { |
|
| 64 | +function glsr_calculate_ratings() |
|
| 65 | +{ |
|
| 59 | 66 | glsr( 'Controllers\AdminController' )->routerCountReviews( false ); |
| 60 | 67 | glsr_log()->info( __( 'Recalculated rating counts.', 'site-reviews' )); |
| 61 | 68 | } |
@@ -63,7 +70,8 @@ discard block |
||
| 63 | 70 | /** |
| 64 | 71 | * @return \GeminiLabs\SiteReviews\Review|false |
| 65 | 72 | */ |
| 66 | -function glsr_create_review( $reviewValues = array() ) { |
|
| 73 | +function glsr_create_review( $reviewValues = array() ) |
|
| 74 | +{ |
|
| 67 | 75 | if( !is_array( $reviewValues )) { |
| 68 | 76 | $reviewValues = array(); |
| 69 | 77 | } |
@@ -74,7 +82,8 @@ discard block |
||
| 74 | 82 | /** |
| 75 | 83 | * @return \WP_Screen|object |
| 76 | 84 | */ |
| 77 | -function glsr_current_screen() { |
|
| 85 | +function glsr_current_screen() |
|
| 86 | +{ |
|
| 78 | 87 | if( function_exists( 'get_current_screen' )) { |
| 79 | 88 | $screen = get_current_screen(); |
| 80 | 89 | } |
@@ -87,7 +96,8 @@ discard block |
||
| 87 | 96 | * @param mixed ...$vars |
| 88 | 97 | * @return void |
| 89 | 98 | */ |
| 90 | -function glsr_debug( ...$vars ) { |
|
| 99 | +function glsr_debug( ...$vars ) |
|
| 100 | +{ |
|
| 91 | 101 | if( count( $vars ) == 1 ) { |
| 92 | 102 | $value = htmlspecialchars( print_r( $vars[0], true ), ENT_QUOTES, 'UTF-8' ); |
| 93 | 103 | printf( '<div class="glsr-debug"><pre>%s</pre></div>', $value ); |
@@ -106,7 +116,8 @@ discard block |
||
| 106 | 116 | * @param mixed $fallback |
| 107 | 117 | * @return string|array |
| 108 | 118 | */ |
| 109 | -function glsr_get_option( $path = '', $fallback = '' ) { |
|
| 119 | +function glsr_get_option( $path = '', $fallback = '' ) |
|
| 120 | +{ |
|
| 110 | 121 | return is_string( $path ) |
| 111 | 122 | ? glsr( 'Database\OptionManager' )->get( 'settings.'.$path, $fallback ) |
| 112 | 123 | : $fallback; |
@@ -115,7 +126,8 @@ discard block |
||
| 115 | 126 | /** |
| 116 | 127 | * @return array |
| 117 | 128 | */ |
| 118 | -function glsr_get_options() { |
|
| 129 | +function glsr_get_options() |
|
| 130 | +{ |
|
| 119 | 131 | return glsr( 'Database\OptionManager' )->get( 'settings' ); |
| 120 | 132 | } |
| 121 | 133 | |
@@ -123,7 +135,8 @@ discard block |
||
| 123 | 135 | * @param int $post_id |
| 124 | 136 | * @return \GeminiLabs\SiteReviews\Review |
| 125 | 137 | */ |
| 126 | -function glsr_get_review( $post_id ) { |
|
| 138 | +function glsr_get_review( $post_id ) |
|
| 139 | +{ |
|
| 127 | 140 | $post = null; |
| 128 | 141 | if( is_numeric( $post_id )) { |
| 129 | 142 | $post = get_post( $post_id ); |
@@ -137,7 +150,8 @@ discard block |
||
| 137 | 150 | /** |
| 138 | 151 | * @return array |
| 139 | 152 | */ |
| 140 | -function glsr_get_reviews( $args = array() ) { |
|
| 153 | +function glsr_get_reviews( $args = array() ) |
|
| 154 | +{ |
|
| 141 | 155 | if( !is_array( $args )) { |
| 142 | 156 | $args = []; |
| 143 | 157 | } |
@@ -147,7 +161,8 @@ discard block |
||
| 147 | 161 | /** |
| 148 | 162 | * @return \GeminiLabs\SiteReviews\Modules\Console |
| 149 | 163 | */ |
| 150 | -function glsr_log() { |
|
| 164 | +function glsr_log() |
|
| 165 | +{ |
|
| 151 | 166 | $args = func_get_args(); |
| 152 | 167 | $context = isset( $args[1] ) |
| 153 | 168 | ? $args[1] |
@@ -161,6 +176,7 @@ discard block |
||
| 161 | 176 | /** |
| 162 | 177 | * @return string |
| 163 | 178 | */ |
| 164 | -function glsr_star_rating( $rating ) { |
|
| 179 | +function glsr_star_rating( $rating ) |
|
| 180 | +{ |
|
| 165 | 181 | return glsr( 'Modules\Html\Partial' )->build( 'star-rating', ['rating' => $rating] ); |
| 166 | 182 | } |