@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | 'navigation' => $navigation, |
| 51 | 51 | ], |
| 52 | 52 | 'reviews' => $this->buildReviews(), |
| 53 | - ]); |
|
| 53 | + ] ); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $generatedReview = []; |
| 75 | 75 | foreach( $review as $key => $value ) { |
| 76 | 76 | $method = glsr( Helper::class )->buildMethodName( $key, 'buildOption' ); |
| 77 | - if( !method_exists( $this, $method ))continue; |
|
| 77 | + if( !method_exists( $this, $method ) )continue; |
|
| 78 | 78 | $generatedReview[$key] = $this->$method( $key, $value ); |
| 79 | 79 | } |
| 80 | 80 | return (object)$generatedReview; |
@@ -87,12 +87,12 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | protected function buildOptionAssignedTo( $key, $value ) |
| 89 | 89 | { |
| 90 | - if( $this->isHiddenOrEmpty( $key, 'settings.reviews.assigned_links.enabled' ))return; |
|
| 91 | - $post = get_post( intval( $value )); |
|
| 92 | - if( !( $post instanceof WP_Post ))return; |
|
| 90 | + if( $this->isHiddenOrEmpty( $key, 'settings.reviews.assigned_links.enabled' ) )return; |
|
| 91 | + $post = get_post( intval( $value ) ); |
|
| 92 | + if( !($post instanceof WP_Post) )return; |
|
| 93 | 93 | $permalink = glsr( Builder::class )->a( get_the_title( $post->ID ), [ |
| 94 | 94 | 'href' => get_the_permalink( $post->ID ), |
| 95 | - ]); |
|
| 95 | + ] ); |
|
| 96 | 96 | $assignedTo = sprintf( __( 'Review of %s', 'site-reviews' ), $permalink ); |
| 97 | 97 | return $this->wrap( $key, '<span>'.$assignedTo.'</span>' ); |
| 98 | 98 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | protected function buildOptionAuthor( $key, $value ) |
| 106 | 106 | { |
| 107 | - if( $this->isHidden( $key ))return; |
|
| 107 | + if( $this->isHidden( $key ) )return; |
|
| 108 | 108 | $prefix = !$this->isOptionEnabled( 'settings.reviews.avatars.enabled' ) |
| 109 | 109 | ? apply_filters( 'site-reviews/review/author/prefix', '—' ) |
| 110 | 110 | : ''; |
@@ -118,13 +118,13 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | protected function buildOptionAvatar( $key, $value ) |
| 120 | 120 | { |
| 121 | - if( $this->isHidden( $key, 'settings.reviews.avatars.enabled' ))return; |
|
| 121 | + if( $this->isHidden( $key, 'settings.reviews.avatars.enabled' ) )return; |
|
| 122 | 122 | $size = $this->getOption( 'settings.reviews.avatars.size', 36 ); |
| 123 | - return $this->wrap( $key, glsr( Builder::class )->img([ |
|
| 123 | + return $this->wrap( $key, glsr( Builder::class )->img( [ |
|
| 124 | 124 | 'src' => $value, |
| 125 | 125 | 'height' => $size, |
| 126 | 126 | 'width' => $size, |
| 127 | - ])); |
|
| 127 | + ] ) ); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | protected function buildOptionContent( $key, $value ) |
| 136 | 136 | { |
| 137 | 137 | $text = $this->normalizeText( $value ); |
| 138 | - if( $this->isHiddenOrEmpty( $key, $text ))return; |
|
| 138 | + if( $this->isHiddenOrEmpty( $key, $text ) )return; |
|
| 139 | 139 | return $this->wrap( $key, '<p>'.$text.'</p>' ); |
| 140 | 140 | } |
| 141 | 141 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | protected function buildOptionDate( $key, $value ) |
| 148 | 148 | { |
| 149 | - if( $this->isHidden( $key ))return; |
|
| 149 | + if( $this->isHidden( $key ) )return; |
|
| 150 | 150 | $dateFormat = $this->getOption( 'settings.reviews.date.format', 'default' ); |
| 151 | 151 | if( $dateFormat == 'relative' ) { |
| 152 | 152 | $date = glsr( Date::class )->relative( $value ); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | $format = $dateFormat == 'custom' |
| 156 | 156 | ? $this->getOption( 'settings.reviews.date.custom', 'M j, Y' ) |
| 157 | 157 | : (string)get_option( 'date_format' ); |
| 158 | - $date = date_i18n( $format, strtotime( $value )); |
|
| 158 | + $date = date_i18n( $format, strtotime( $value ) ); |
|
| 159 | 159 | } |
| 160 | 160 | return $this->wrap( $key, '<span>'.$date.'</span>' ); |
| 161 | 161 | } |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | protected function buildOptionRating( $key, $value ) |
| 169 | 169 | { |
| 170 | - if( $this->isHiddenOrEmpty( $key, $value ))return; |
|
| 170 | + if( $this->isHiddenOrEmpty( $key, $value ) )return; |
|
| 171 | 171 | $rating = glsr( Html::class )->buildPartial( 'star-rating', [ |
| 172 | 172 | 'rating' => $value, |
| 173 | - ]); |
|
| 173 | + ] ); |
|
| 174 | 174 | return $this->wrap( $key, $rating ); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | protected function buildOptionResponse( $key, $value ) |
| 183 | 183 | { |
| 184 | - if( $this->isHiddenOrEmpty( $key, $value ))return; |
|
| 185 | - $title = sprintf( __( 'Response from %s', 'site-reviews' ), get_bloginfo( 'name' )); |
|
| 184 | + if( $this->isHiddenOrEmpty( $key, $value ) )return; |
|
| 185 | + $title = sprintf( __( 'Response from %s', 'site-reviews' ), get_bloginfo( 'name' ) ); |
|
| 186 | 186 | $text = $this->normalizeText( $value ); |
| 187 | 187 | $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
| 188 | 188 | return $this->wrap( $key, |
@@ -198,8 +198,8 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | protected function buildOptionTitle( $key, $value ) |
| 200 | 200 | { |
| 201 | - if( $this->isHidden( $key ))return; |
|
| 202 | - if( empty( $value )) { |
|
| 201 | + if( $this->isHidden( $key ) )return; |
|
| 202 | + if( empty($value) ) { |
|
| 203 | 203 | $value = __( 'No Title', 'site-reviews' ); |
| 204 | 204 | } |
| 205 | 205 | return $this->wrap( $key, '<h3>'.$value.'</h3>' ); |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | protected function generateSchema() |
| 212 | 212 | { |
| 213 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
| 214 | - glsr( Schema::class )->store( glsr( Schema::class )->build( $this->args )); |
|
| 213 | + if( !wp_validate_boolean( $this->args['schema'] ) )return; |
|
| 214 | + glsr( Schema::class )->store( glsr( Schema::class )->build( $this->args ) ); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -234,14 +234,14 @@ discard block |
||
| 234 | 234 | { |
| 235 | 235 | $limit = $this->getOption( 'settings.reviews.excerpt.length', 55 ); |
| 236 | 236 | if( str_word_count( $text, 0 ) > $limit ) { |
| 237 | - $words = array_keys( str_word_count( $text, 2 )); |
|
| 238 | - $excerpt = ltrim( substr( $text, 0, $words[$limit] )); |
|
| 239 | - $hiddenText = substr( $text, strlen( $excerpt )); |
|
| 237 | + $words = array_keys( str_word_count( $text, 2 ) ); |
|
| 238 | + $excerpt = ltrim( substr( $text, 0, $words[$limit] ) ); |
|
| 239 | + $hiddenText = substr( $text, strlen( $excerpt ) ); |
|
| 240 | 240 | $showMore = glsr( Builder::class )->span( $hiddenText, [ |
| 241 | 241 | 'class' => 'glsr-hidden glsr-hidden-text', |
| 242 | 242 | 'data-show-less' => __( 'Show less', 'site-reviews' ), |
| 243 | 243 | 'data-show-more' => __( 'Show more', 'site-reviews' ), |
| 244 | - ]); |
|
| 244 | + ] ); |
|
| 245 | 245 | $text = $excerpt.$showMore; |
| 246 | 246 | } |
| 247 | 247 | return nl2br( $text ); |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | protected function getOption( $path, $fallback = '' ) |
| 256 | 256 | { |
| 257 | - if( array_key_exists( $path, $this->options )) { |
|
| 257 | + if( array_key_exists( $path, $this->options ) ) { |
|
| 258 | 258 | return $this->options[$path]; |
| 259 | 259 | } |
| 260 | 260 | return $fallback; |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | */ |
| 268 | 268 | protected function isHidden( $key, $path = '' ) |
| 269 | 269 | { |
| 270 | - $isOptionEnabled = !empty( $path ) |
|
| 270 | + $isOptionEnabled = !empty($path) |
|
| 271 | 271 | ? $this->isOptionEnabled( $path ) |
| 272 | 272 | : true; |
| 273 | 273 | return in_array( $key, $this->args['hide'] ) || !$isOptionEnabled; |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | */ |
| 281 | 281 | protected function isHiddenOrEmpty( $key, $value ) |
| 282 | 282 | { |
| 283 | - return $this->isHidden( $key ) || empty( $value ); |
|
| 283 | + return $this->isHidden( $key ) || empty($value); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | protected function normalizeText( $text ) |
| 300 | 300 | { |
| 301 | 301 | $text = wp_kses( $text, wp_kses_allowed_html() ); |
| 302 | - $text = convert_smilies( wptexturize( strip_shortcodes( $text ))); |
|
| 302 | + $text = convert_smilies( wptexturize( strip_shortcodes( $text ) ) ); |
|
| 303 | 303 | $text = str_replace( ']]>', ']]>', $text ); |
| 304 | 304 | $text = preg_replace( '/(\R){2,}/', '$1', $text ); |
| 305 | 305 | return $this->isOptionEnabled( 'settings.reviews.excerpt.enabled' ) |
@@ -316,6 +316,6 @@ discard block |
||
| 316 | 316 | { |
| 317 | 317 | return glsr( Builder::class )->div( $value, [ |
| 318 | 318 | 'class' => 'glsr-review-'.$key, |
| 319 | - ]); |
|
| 319 | + ] ); |
|
| 320 | 320 | } |
| 321 | 321 | } |
@@ -74,7 +74,9 @@ discard block |
||
| 74 | 74 | $generatedReview = []; |
| 75 | 75 | foreach( $review as $key => $value ) { |
| 76 | 76 | $method = glsr( Helper::class )->buildMethodName( $key, 'buildOption' ); |
| 77 | - if( !method_exists( $this, $method ))continue; |
|
| 77 | + if( !method_exists( $this, $method )) { |
|
| 78 | + continue; |
|
| 79 | + } |
|
| 78 | 80 | $generatedReview[$key] = $this->$method( $key, $value ); |
| 79 | 81 | } |
| 80 | 82 | return (object)$generatedReview; |
@@ -87,9 +89,13 @@ discard block |
||
| 87 | 89 | */ |
| 88 | 90 | protected function buildOptionAssignedTo( $key, $value ) |
| 89 | 91 | { |
| 90 | - if( $this->isHiddenOrEmpty( $key, 'settings.reviews.assigned_links.enabled' ))return; |
|
| 92 | + if( $this->isHiddenOrEmpty( $key, 'settings.reviews.assigned_links.enabled' )) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 91 | 95 | $post = get_post( intval( $value )); |
| 92 | - if( !( $post instanceof WP_Post ))return; |
|
| 96 | + if( !( $post instanceof WP_Post )) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 93 | 99 | $permalink = glsr( Builder::class )->a( get_the_title( $post->ID ), [ |
| 94 | 100 | 'href' => get_the_permalink( $post->ID ), |
| 95 | 101 | ]); |
@@ -104,7 +110,9 @@ discard block |
||
| 104 | 110 | */ |
| 105 | 111 | protected function buildOptionAuthor( $key, $value ) |
| 106 | 112 | { |
| 107 | - if( $this->isHidden( $key ))return; |
|
| 113 | + if( $this->isHidden( $key )) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 108 | 116 | $prefix = !$this->isOptionEnabled( 'settings.reviews.avatars.enabled' ) |
| 109 | 117 | ? apply_filters( 'site-reviews/review/author/prefix', '—' ) |
| 110 | 118 | : ''; |
@@ -118,7 +126,9 @@ discard block |
||
| 118 | 126 | */ |
| 119 | 127 | protected function buildOptionAvatar( $key, $value ) |
| 120 | 128 | { |
| 121 | - if( $this->isHidden( $key, 'settings.reviews.avatars.enabled' ))return; |
|
| 129 | + if( $this->isHidden( $key, 'settings.reviews.avatars.enabled' )) { |
|
| 130 | + return; |
|
| 131 | + } |
|
| 122 | 132 | $size = $this->getOption( 'settings.reviews.avatars.size', 36 ); |
| 123 | 133 | return $this->wrap( $key, glsr( Builder::class )->img([ |
| 124 | 134 | 'src' => $value, |
@@ -135,7 +145,9 @@ discard block |
||
| 135 | 145 | protected function buildOptionContent( $key, $value ) |
| 136 | 146 | { |
| 137 | 147 | $text = $this->normalizeText( $value ); |
| 138 | - if( $this->isHiddenOrEmpty( $key, $text ))return; |
|
| 148 | + if( $this->isHiddenOrEmpty( $key, $text )) { |
|
| 149 | + return; |
|
| 150 | + } |
|
| 139 | 151 | return $this->wrap( $key, '<p>'.$text.'</p>' ); |
| 140 | 152 | } |
| 141 | 153 | |
@@ -146,7 +158,9 @@ discard block |
||
| 146 | 158 | */ |
| 147 | 159 | protected function buildOptionDate( $key, $value ) |
| 148 | 160 | { |
| 149 | - if( $this->isHidden( $key ))return; |
|
| 161 | + if( $this->isHidden( $key )) { |
|
| 162 | + return; |
|
| 163 | + } |
|
| 150 | 164 | $dateFormat = $this->getOption( 'settings.reviews.date.format', 'default' ); |
| 151 | 165 | if( $dateFormat == 'relative' ) { |
| 152 | 166 | $date = glsr( Date::class )->relative( $value ); |
@@ -167,7 +181,9 @@ discard block |
||
| 167 | 181 | */ |
| 168 | 182 | protected function buildOptionRating( $key, $value ) |
| 169 | 183 | { |
| 170 | - if( $this->isHiddenOrEmpty( $key, $value ))return; |
|
| 184 | + if( $this->isHiddenOrEmpty( $key, $value )) { |
|
| 185 | + return; |
|
| 186 | + } |
|
| 171 | 187 | $rating = glsr( Html::class )->buildPartial( 'star-rating', [ |
| 172 | 188 | 'rating' => $value, |
| 173 | 189 | ]); |
@@ -181,7 +197,9 @@ discard block |
||
| 181 | 197 | */ |
| 182 | 198 | protected function buildOptionResponse( $key, $value ) |
| 183 | 199 | { |
| 184 | - if( $this->isHiddenOrEmpty( $key, $value ))return; |
|
| 200 | + if( $this->isHiddenOrEmpty( $key, $value )) { |
|
| 201 | + return; |
|
| 202 | + } |
|
| 185 | 203 | $title = sprintf( __( 'Response from %s', 'site-reviews' ), get_bloginfo( 'name' )); |
| 186 | 204 | $text = $this->normalizeText( $value ); |
| 187 | 205 | $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
@@ -198,7 +216,9 @@ discard block |
||
| 198 | 216 | */ |
| 199 | 217 | protected function buildOptionTitle( $key, $value ) |
| 200 | 218 | { |
| 201 | - if( $this->isHidden( $key ))return; |
|
| 219 | + if( $this->isHidden( $key )) { |
|
| 220 | + return; |
|
| 221 | + } |
|
| 202 | 222 | if( empty( $value )) { |
| 203 | 223 | $value = __( 'No Title', 'site-reviews' ); |
| 204 | 224 | } |
@@ -210,7 +230,9 @@ discard block |
||
| 210 | 230 | */ |
| 211 | 231 | protected function generateSchema() |
| 212 | 232 | { |
| 213 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
| 233 | + if( !wp_validate_boolean( $this->args['schema'] )) { |
|
| 234 | + return; |
|
| 235 | + } |
|
| 214 | 236 | glsr( Schema::class )->store( glsr( Schema::class )->build( $this->args )); |
| 215 | 237 | } |
| 216 | 238 | |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | 'after_widget' => '</div>', |
| 23 | 23 | 'before_title' => '<h3 class="glsr-shortcode-title">', |
| 24 | 24 | 'after_title' => '</h3>', |
| 25 | - ]); |
|
| 25 | + ] ); |
|
| 26 | 26 | $instance = $this->normalize( $instance ); |
| 27 | 27 | $partial = glsr( Html::class )->buildPartial( $shortcodePartial, $instance ); |
| 28 | - if( !empty( $instance['title'] )) { |
|
| 28 | + if( !empty($instance['title']) ) { |
|
| 29 | 29 | $instance['title'] = $args['before_title'].$instance['title'].$args['after_title']; |
| 30 | 30 | } |
| 31 | 31 | return $args['before_widget'].$instance['title'].$partial.$args['after_widget']; |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function normalize( $args ) |
| 70 | 70 | { |
| 71 | - $args = shortcode_atts( $this->getDefaults(), wp_parse_args( $args )); |
|
| 71 | + $args = shortcode_atts( $this->getDefaults(), wp_parse_args( $args ) ); |
|
| 72 | 72 | array_walk( $args, function( &$value, $key ) { |
| 73 | 73 | $methodName = glsr( Helper::class )->buildMethodName( $key, 'normalize' ); |
| 74 | - if( !method_exists( $this, $methodName ))return; |
|
| 74 | + if( !method_exists( $this, $methodName ) )return; |
|
| 75 | 75 | $value = $this->$methodName( $value ); |
| 76 | 76 | }); |
| 77 | 77 | return $this->sanitize( $args ); |
@@ -103,13 +103,13 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | protected function normalizeHide( $hide ) |
| 105 | 105 | { |
| 106 | - if( is_string( $hide )) { |
|
| 106 | + if( is_string( $hide ) ) { |
|
| 107 | 107 | $hide = explode( ',', $hide ); |
| 108 | 108 | } |
| 109 | 109 | $hiddenKeys = defined( 'static::HIDDEN_KEYS' ) |
| 110 | 110 | ? static::HIDDEN_KEYS |
| 111 | 111 | : []; |
| 112 | - return array_filter( array_map( 'trim', $hide ), function( $value ) use( $hiddenKeys ) { |
|
| 112 | + return array_filter( array_map( 'trim', $hide ), function( $value ) use($hiddenKeys) { |
|
| 113 | 113 | return in_array( $value, $hiddenKeys ); |
| 114 | 114 | }); |
| 115 | 115 | } |
@@ -137,9 +137,9 @@ discard block |
||
| 137 | 137 | __( 'Terrible', 'site-reviews' ), |
| 138 | 138 | ]; |
| 139 | 139 | $defaults = array_pad( $defaults, Rating::MAX_RATING, '' ); |
| 140 | - $labels = array_map( 'trim', explode( ',', $labels )); |
|
| 140 | + $labels = array_map( 'trim', explode( ',', $labels ) ); |
|
| 141 | 141 | foreach( $defaults as $i => $label ) { |
| 142 | - if( empty( $labels[$i] ))continue; |
|
| 142 | + if( empty($labels[$i]) )continue; |
|
| 143 | 143 | $defaults[$i] = $labels[$i]; |
| 144 | 144 | } |
| 145 | 145 | return array_combine( range( Rating::MAX_RATING, 1 ), $defaults ); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | { |
| 35 | 35 | $this->args = $args; |
| 36 | 36 | $this->reviews = glsr( Database::class )->getReviews( $args )->results; |
| 37 | - if( empty( $this->reviews ) && $this->isHidden( 'if_empty' ))return; |
|
| 37 | + if( empty($this->reviews) && $this->isHidden( 'if_empty' ) )return; |
|
| 38 | 38 | $this->rating = glsr( Rating::class )->getAverage( $this->reviews ); |
| 39 | 39 | $this->generateSchema(); |
| 40 | 40 | return glsr( Template::class )->build( 'templates/reviews-summary', [ |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | 'stars' => $this->buildStars(), |
| 47 | 47 | 'text' => $this->buildText(), |
| 48 | 48 | ], |
| 49 | - ]); |
|
| 49 | + ] ); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -54,16 +54,16 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | protected function buildPercentage() |
| 56 | 56 | { |
| 57 | - if( $this->isHidden( 'bars' ))return; |
|
| 57 | + if( $this->isHidden( 'bars' ) )return; |
|
| 58 | 58 | $range = range( Rating::MAX_RATING, 1 ); |
| 59 | - $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->reviews )); |
|
| 60 | - $bars = array_reduce( $range, function( $carry, $level ) use( $percentages ) { |
|
| 59 | + $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->reviews ) ); |
|
| 60 | + $bars = array_reduce( $range, function( $carry, $level ) use($percentages) { |
|
| 61 | 61 | $label = $this->buildPercentageLabel( $this->args['labels'][$level] ); |
| 62 | 62 | $background = $this->buildPercentageBackground( $percentages[$level] ); |
| 63 | 63 | $percent = $this->buildPercentagePercent( $percentages[$level] ); |
| 64 | 64 | return $carry.glsr( Builder::class )->div( $label.$background.$percent, [ |
| 65 | 65 | 'class' => 'glsr-bar', |
| 66 | - ]); |
|
| 66 | + ] ); |
|
| 67 | 67 | }); |
| 68 | 68 | return $this->wrap( 'percentage', $bars ); |
| 69 | 69 | } |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | protected function buildPercentageBackground( $percent ) |
| 76 | 76 | { |
| 77 | - $backgroundPercent = glsr( Builder::class )->span([ |
|
| 77 | + $backgroundPercent = glsr( Builder::class )->span( [ |
|
| 78 | 78 | 'class' => 'glsr-bar-background-percent', |
| 79 | 79 | 'style' => 'width:'.$percent, |
| 80 | - ]); |
|
| 80 | + ] ); |
|
| 81 | 81 | return glsr( Builder::class )->span( $backgroundPercent, [ |
| 82 | 82 | 'class' => 'glsr-bar-background', |
| 83 | - ]); |
|
| 83 | + ] ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | { |
| 92 | 92 | return glsr( Builder::class )->span( $label, [ |
| 93 | 93 | 'class' => 'glsr-bar-label', |
| 94 | - ]); |
|
| 94 | + ] ); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | return glsr( Builder::class )->span( $percent, [ |
| 104 | 104 | 'class' => 'glsr-bar-percent', |
| 105 | - ]); |
|
| 105 | + ] ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | protected function buildRating() |
| 112 | 112 | { |
| 113 | - if( $this->isHidden( 'rating' ))return; |
|
| 113 | + if( $this->isHidden( 'rating' ) )return; |
|
| 114 | 114 | return $this->wrap( 'rating', '<span>'.$this->rating.'</span>' ); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -119,11 +119,11 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | protected function buildStars() |
| 121 | 121 | { |
| 122 | - if( $this->isHidden( 'stars' ))return; |
|
| 122 | + if( $this->isHidden( 'stars' ) )return; |
|
| 123 | 123 | $stars = glsr( Partial::class )->build( 'star-rating', [ |
| 124 | 124 | // 'number' => count( $this->reviews ), |
| 125 | 125 | 'rating' => $this->rating, |
| 126 | - ]); |
|
| 126 | + ] ); |
|
| 127 | 127 | return $this->wrap( 'stars', $stars ); |
| 128 | 128 | } |
| 129 | 129 | |
@@ -132,9 +132,9 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | protected function buildText() |
| 134 | 134 | { |
| 135 | - if( $this->isHidden( 'summary' ))return; |
|
| 135 | + if( $this->isHidden( 'summary' ) )return; |
|
| 136 | 136 | $count = count( $this->reviews ); |
| 137 | - if( empty( $this->args['text'] )) { |
|
| 137 | + if( empty($this->args['text']) ) { |
|
| 138 | 138 | $this->args['text'] = _nx( |
| 139 | 139 | '{rating} out of {max} stars (based on %d review)', |
| 140 | 140 | '{rating} out of {max} stars (based on %d reviews)', |
@@ -143,8 +143,8 @@ discard block |
||
| 143 | 143 | 'site-reviews' |
| 144 | 144 | ); |
| 145 | 145 | } |
| 146 | - $summary = str_replace( ['{rating}','{max}'], [$this->rating, Rating::MAX_RATING], $this->args['text'] ); |
|
| 147 | - $summary = str_replace( ['%s','%d'], $count, $summary ); |
|
| 146 | + $summary = str_replace( ['{rating}', '{max}'], [$this->rating, Rating::MAX_RATING], $this->args['text'] ); |
|
| 147 | + $summary = str_replace( ['%s', '%d'], $count, $summary ); |
|
| 148 | 148 | return $this->wrap( 'text', '<span>'.$summary.'</span>' ); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -153,8 +153,8 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | protected function generateSchema() |
| 155 | 155 | { |
| 156 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
| 157 | - glsr( Schema::class )->store( glsr( Schema::class )->buildSummary( $this->args )); |
|
| 156 | + if( !wp_validate_boolean( $this->args['schema'] ) )return; |
|
| 157 | + glsr( Schema::class )->store( glsr( Schema::class )->buildSummary( $this->args ) ); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -184,6 +184,6 @@ discard block |
||
| 184 | 184 | { |
| 185 | 185 | return glsr( Builder::class )->div( $value, [ |
| 186 | 186 | 'class' => 'glsr-summary-'.$key, |
| 187 | - ]); |
|
| 187 | + ] ); |
|
| 188 | 188 | } |
| 189 | 189 | } |
@@ -34,7 +34,9 @@ discard block |
||
| 34 | 34 | { |
| 35 | 35 | $this->args = $args; |
| 36 | 36 | $this->reviews = glsr( Database::class )->getReviews( $args )->results; |
| 37 | - if( empty( $this->reviews ) && $this->isHidden( 'if_empty' ))return; |
|
| 37 | + if( empty( $this->reviews ) && $this->isHidden( 'if_empty' )) { |
|
| 38 | + return; |
|
| 39 | + } |
|
| 38 | 40 | $this->rating = glsr( Rating::class )->getAverage( $this->reviews ); |
| 39 | 41 | $this->generateSchema(); |
| 40 | 42 | return glsr( Template::class )->build( 'templates/reviews-summary', [ |
@@ -54,7 +56,9 @@ discard block |
||
| 54 | 56 | */ |
| 55 | 57 | protected function buildPercentage() |
| 56 | 58 | { |
| 57 | - if( $this->isHidden( 'bars' ))return; |
|
| 59 | + if( $this->isHidden( 'bars' )) { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 58 | 62 | $range = range( Rating::MAX_RATING, 1 ); |
| 59 | 63 | $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->reviews )); |
| 60 | 64 | $bars = array_reduce( $range, function( $carry, $level ) use( $percentages ) { |
@@ -110,7 +114,9 @@ discard block |
||
| 110 | 114 | */ |
| 111 | 115 | protected function buildRating() |
| 112 | 116 | { |
| 113 | - if( $this->isHidden( 'rating' ))return; |
|
| 117 | + if( $this->isHidden( 'rating' )) { |
|
| 118 | + return; |
|
| 119 | + } |
|
| 114 | 120 | return $this->wrap( 'rating', '<span>'.$this->rating.'</span>' ); |
| 115 | 121 | } |
| 116 | 122 | |
@@ -119,7 +125,9 @@ discard block |
||
| 119 | 125 | */ |
| 120 | 126 | protected function buildStars() |
| 121 | 127 | { |
| 122 | - if( $this->isHidden( 'stars' ))return; |
|
| 128 | + if( $this->isHidden( 'stars' )) { |
|
| 129 | + return; |
|
| 130 | + } |
|
| 123 | 131 | $stars = glsr( Partial::class )->build( 'star-rating', [ |
| 124 | 132 | // 'number' => count( $this->reviews ), |
| 125 | 133 | 'rating' => $this->rating, |
@@ -132,7 +140,9 @@ discard block |
||
| 132 | 140 | */ |
| 133 | 141 | protected function buildText() |
| 134 | 142 | { |
| 135 | - if( $this->isHidden( 'summary' ))return; |
|
| 143 | + if( $this->isHidden( 'summary' )) { |
|
| 144 | + return; |
|
| 145 | + } |
|
| 136 | 146 | $count = count( $this->reviews ); |
| 137 | 147 | if( empty( $this->args['text'] )) { |
| 138 | 148 | $this->args['text'] = _nx( |
@@ -153,7 +163,9 @@ discard block |
||
| 153 | 163 | */ |
| 154 | 164 | protected function generateSchema() |
| 155 | 165 | { |
| 156 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
| 166 | + if( !wp_validate_boolean( $this->args['schema'] )) { |
|
| 167 | + return; |
|
| 168 | + } |
|
| 157 | 169 | glsr( Schema::class )->store( glsr( Schema::class )->buildSummary( $this->args )); |
| 158 | 170 | } |
| 159 | 171 | |