@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | 'after_widget' => '</div>', |
24 | 24 | 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
25 | 25 | 'after_title' => '</h3>', |
26 | - ]); |
|
26 | + ] ); |
|
27 | 27 | $args = apply_filters( 'site-reviews/shortcode/args', $args, $type, $shortcodePartial ); |
28 | 28 | $instance = $this->normalize( $instance ); |
29 | 29 | $partial = glsr( Partial::class )->build( $shortcodePartial, $instance ); |
30 | - if( !empty( $instance['title'] )) { |
|
30 | + if( !empty($instance['title']) ) { |
|
31 | 31 | $instance['title'] = $args['before_title'].$instance['title'].$args['after_title']; |
32 | 32 | } |
33 | 33 | return $args['before_widget'].$instance['title'].$partial.$args['after_widget']; |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function normalize( $args ) |
92 | 92 | { |
93 | - $args = shortcode_atts( $this->getDefaults(), wp_parse_args( $args )); |
|
93 | + $args = shortcode_atts( $this->getDefaults(), wp_parse_args( $args ) ); |
|
94 | 94 | array_walk( $args, function( &$value, $key ) { |
95 | 95 | $methodName = glsr( Helper::class )->buildMethodName( $key, 'normalize' ); |
96 | - if( !method_exists( $this, $methodName ))return; |
|
96 | + if( !method_exists( $this, $methodName ) )return; |
|
97 | 97 | $value = $this->$methodName( $value ); |
98 | 98 | }); |
99 | 99 | return $this->sanitize( $args ); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | protected function normalizeAssignedTo( $postId ) |
112 | 112 | { |
113 | 113 | if( $postId == 'parent_id' ) { |
114 | - $postId = intval( wp_get_post_parent_id( intval( get_the_ID() ))); |
|
114 | + $postId = intval( wp_get_post_parent_id( intval( get_the_ID() ) ) ); |
|
115 | 115 | } |
116 | 116 | else if( $postId == 'post_id' ) { |
117 | 117 | $postId = intval( get_the_ID() ); |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function normalizeHide( $hide ) |
136 | 136 | { |
137 | - if( is_string( $hide )) { |
|
137 | + if( is_string( $hide ) ) { |
|
138 | 138 | $hide = explode( ',', $hide ); |
139 | 139 | } |
140 | 140 | $hideKeys = array_keys( $this->getHideOptions() ); |
141 | - return array_filter( array_map( 'trim', $hide ), function( $value ) use( $hideKeys ) { |
|
141 | + return array_filter( array_map( 'trim', $hide ), function( $value ) use($hideKeys) { |
|
142 | 142 | return in_array( $value, $hideKeys ); |
143 | 143 | }); |
144 | 144 | } |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | __( 'Terrible', 'site-reviews' ), |
167 | 167 | ]; |
168 | 168 | $defaults = array_pad( $defaults, glsr()->constant( 'MAX_RATING', Rating::class ), '' ); |
169 | - $labels = array_map( 'trim', explode( ',', $labels )); |
|
169 | + $labels = array_map( 'trim', explode( ',', $labels ) ); |
|
170 | 170 | foreach( $defaults as $i => $label ) { |
171 | - if( empty( $labels[$i] ))continue; |
|
171 | + if( empty($labels[$i]) )continue; |
|
172 | 172 | $defaults[$i] = $labels[$i]; |
173 | 173 | } |
174 | 174 | return array_combine( range( glsr()->constant( 'MAX_RATING', Rating::class ), 1 ), $defaults ); |
@@ -93,7 +93,9 @@ discard block |
||
93 | 93 | $args = shortcode_atts( $this->getDefaults(), wp_parse_args( $args )); |
94 | 94 | array_walk( $args, function( &$value, $key ) { |
95 | 95 | $methodName = glsr( Helper::class )->buildMethodName( $key, 'normalize' ); |
96 | - if( !method_exists( $this, $methodName ))return; |
|
96 | + if( !method_exists( $this, $methodName )) { |
|
97 | + return; |
|
98 | + } |
|
97 | 99 | $value = $this->$methodName( $value ); |
98 | 100 | }); |
99 | 101 | return $this->sanitize( $args ); |
@@ -168,7 +170,9 @@ discard block |
||
168 | 170 | $defaults = array_pad( $defaults, glsr()->constant( 'MAX_RATING', Rating::class ), '' ); |
169 | 171 | $labels = array_map( 'trim', explode( ',', $labels )); |
170 | 172 | foreach( $defaults as $i => $label ) { |
171 | - if( empty( $labels[$i] ))continue; |
|
173 | + if( empty( $labels[$i] )) { |
|
174 | + continue; |
|
175 | + } |
|
172 | 176 | $defaults[$i] = $labels[$i]; |
173 | 177 | } |
174 | 178 | return array_combine( range( glsr()->constant( 'MAX_RATING', Rating::class ), 1 ), $defaults ); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | { |
35 | 35 | $this->args = $args; |
36 | 36 | $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $args ); |
37 | - if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ))return; |
|
37 | + if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ) )return; |
|
38 | 38 | $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts ); |
39 | 39 | $this->generateSchema(); |
40 | 40 | return glsr( Template::class )->build( 'templates/reviews-summary', [ |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | 'stars' => $this->buildStars(), |
49 | 49 | 'text' => $this->buildText(), |
50 | 50 | ], |
51 | - ]); |
|
51 | + ] ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | */ |
57 | 57 | protected function buildPercentage() |
58 | 58 | { |
59 | - if( $this->isHidden( 'bars' ))return; |
|
60 | - $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts )); |
|
61 | - $bars = array_reduce( range( glsr()->constant( 'MAX_RATING', Rating::class ), 1 ), function( $carry, $level ) use( $percentages ) { |
|
59 | + if( $this->isHidden( 'bars' ) )return; |
|
60 | + $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts ) ); |
|
61 | + $bars = array_reduce( range( glsr()->constant( 'MAX_RATING', Rating::class ), 1 ), function( $carry, $level ) use($percentages) { |
|
62 | 62 | $label = $this->buildPercentageLabel( $this->args['labels'][$level] ); |
63 | 63 | $background = $this->buildPercentageBackground( $percentages[$level] ); |
64 | 64 | $count = apply_filters( 'site-reviews/summary/counts', |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $percent = $this->buildPercentageCount( $count ); |
69 | 69 | return $carry.glsr( Builder::class )->div( $label.$background.$percent, [ |
70 | 70 | 'class' => 'glsr-bar', |
71 | - ]); |
|
71 | + ] ); |
|
72 | 72 | }); |
73 | 73 | return $this->wrap( 'percentage', $bars ); |
74 | 74 | } |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | */ |
80 | 80 | protected function buildPercentageBackground( $percent ) |
81 | 81 | { |
82 | - $backgroundPercent = glsr( Builder::class )->span([ |
|
82 | + $backgroundPercent = glsr( Builder::class )->span( [ |
|
83 | 83 | 'class' => 'glsr-bar-background-percent', |
84 | 84 | 'style' => 'width:'.$percent, |
85 | - ]); |
|
85 | + ] ); |
|
86 | 86 | return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>'; |
87 | 87 | } |
88 | 88 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | protected function buildRating() |
111 | 111 | { |
112 | - if( $this->isHidden( 'rating' ))return; |
|
112 | + if( $this->isHidden( 'rating' ) )return; |
|
113 | 113 | return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' ); |
114 | 114 | } |
115 | 115 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | */ |
119 | 119 | protected function buildStars() |
120 | 120 | { |
121 | - if( $this->isHidden( 'stars' ))return; |
|
121 | + if( $this->isHidden( 'stars' ) )return; |
|
122 | 122 | $stars = glsr_star_rating( $this->averageRating ); |
123 | 123 | return $this->wrap( 'stars', $stars ); |
124 | 124 | } |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | */ |
129 | 129 | protected function buildText() |
130 | 130 | { |
131 | - if( $this->isHidden( 'summary' ))return; |
|
132 | - $count = intval( array_sum( $this->ratingCounts )); |
|
133 | - if( empty( $this->args['text'] )) { |
|
131 | + if( $this->isHidden( 'summary' ) )return; |
|
132 | + $count = intval( array_sum( $this->ratingCounts ) ); |
|
133 | + if( empty($this->args['text']) ) { |
|
134 | 134 | // @todo document this change |
135 | 135 | $this->args['text'] = _nx( |
136 | 136 | '{rating} out of {max} stars (based on {num} review)', |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | ); |
142 | 142 | } |
143 | 143 | $summary = str_replace( |
144 | - ['{rating}','{max}', '{num}'], |
|
144 | + ['{rating}', '{max}', '{num}'], |
|
145 | 145 | [$this->averageRating, glsr()->constant( 'MAX_RATING', Rating::class ), $count], |
146 | 146 | $this->args['text'] |
147 | 147 | ); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | */ |
154 | 154 | protected function generateSchema() |
155 | 155 | { |
156 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
156 | + if( !wp_validate_boolean( $this->args['schema'] ) )return; |
|
157 | 157 | glsr( Schema::class )->store( |
158 | 158 | glsr( Schema::class )->buildSummary( $this->args ) |
159 | 159 | ); |
@@ -185,6 +185,6 @@ discard block |
||
185 | 185 | { |
186 | 186 | return glsr( Builder::class )->div( $value, [ |
187 | 187 | 'class' => 'glsr-summary-'.$key, |
188 | - ]); |
|
188 | + ] ); |
|
189 | 189 | } |
190 | 190 | } |
@@ -34,7 +34,9 @@ discard block |
||
34 | 34 | { |
35 | 35 | $this->args = $args; |
36 | 36 | $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $args ); |
37 | - if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ))return; |
|
37 | + if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' )) { |
|
38 | + return; |
|
39 | + } |
|
38 | 40 | $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts ); |
39 | 41 | $this->generateSchema(); |
40 | 42 | return glsr( Template::class )->build( 'templates/reviews-summary', [ |
@@ -56,7 +58,9 @@ discard block |
||
56 | 58 | */ |
57 | 59 | protected function buildPercentage() |
58 | 60 | { |
59 | - if( $this->isHidden( 'bars' ))return; |
|
61 | + if( $this->isHidden( 'bars' )) { |
|
62 | + return; |
|
63 | + } |
|
60 | 64 | $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts )); |
61 | 65 | $bars = array_reduce( range( glsr()->constant( 'MAX_RATING', Rating::class ), 1 ), function( $carry, $level ) use( $percentages ) { |
62 | 66 | $label = $this->buildPercentageLabel( $this->args['labels'][$level] ); |
@@ -109,7 +113,9 @@ discard block |
||
109 | 113 | */ |
110 | 114 | protected function buildRating() |
111 | 115 | { |
112 | - if( $this->isHidden( 'rating' ))return; |
|
116 | + if( $this->isHidden( 'rating' )) { |
|
117 | + return; |
|
118 | + } |
|
113 | 119 | return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' ); |
114 | 120 | } |
115 | 121 | |
@@ -118,7 +124,9 @@ discard block |
||
118 | 124 | */ |
119 | 125 | protected function buildStars() |
120 | 126 | { |
121 | - if( $this->isHidden( 'stars' ))return; |
|
127 | + if( $this->isHidden( 'stars' )) { |
|
128 | + return; |
|
129 | + } |
|
122 | 130 | $stars = glsr_star_rating( $this->averageRating ); |
123 | 131 | return $this->wrap( 'stars', $stars ); |
124 | 132 | } |
@@ -128,7 +136,9 @@ discard block |
||
128 | 136 | */ |
129 | 137 | protected function buildText() |
130 | 138 | { |
131 | - if( $this->isHidden( 'summary' ))return; |
|
139 | + if( $this->isHidden( 'summary' )) { |
|
140 | + return; |
|
141 | + } |
|
132 | 142 | $count = intval( array_sum( $this->ratingCounts )); |
133 | 143 | if( empty( $this->args['text'] )) { |
134 | 144 | // @todo document this change |
@@ -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( |
158 | 170 | glsr( Schema::class )->buildSummary( $this->args ) |
159 | 171 | ); |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | if( $review->review_type != 'local' )continue; |
39 | 39 | $reviews[] = $this->buildReview( $review ); |
40 | 40 | } |
41 | - if( !empty( $reviews )) { |
|
41 | + if( !empty($reviews) ) { |
|
42 | 42 | array_walk( $reviews, function( &$review ) { |
43 | - unset( $review['@context'] ); |
|
44 | - unset( $review['itemReviewed'] ); |
|
43 | + unset($review['@context']); |
|
44 | + unset($review['itemReviewed']); |
|
45 | 45 | }); |
46 | 46 | $schema['review'] = $reviews; |
47 | 47 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function buildSummary( $args = null ) |
56 | 56 | { |
57 | - if( is_array( $args )) { |
|
57 | + if( is_array( $args ) ) { |
|
58 | 58 | $this->args = $args; |
59 | 59 | } |
60 | 60 | $buildSummary = glsr( Helper::class )->buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' ); |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | $schema = method_exists( $this, $buildSummary ) |
63 | 63 | ? $this->$buildSummary() |
64 | 64 | : $this->buildSummaryForCustom(); |
65 | - if( !empty( $count )) { |
|
65 | + if( !empty($count) ) { |
|
66 | 66 | $schema->aggregateRating( |
67 | 67 | $this->getSchemaType( 'AggregateRating' ) |
68 | 68 | ->ratingValue( $this->getRatingValue() ) |
69 | 69 | ->reviewCount( $count ) |
70 | - ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class )) |
|
71 | - ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class )) |
|
70 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
71 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
72 | 72 | ); |
73 | 73 | } |
74 | 74 | $schema = $schema->toArray(); |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function render() |
82 | 82 | { |
83 | - if( empty( glsr()->schemas ))return; |
|
83 | + if( empty(glsr()->schemas) )return; |
|
84 | 84 | printf( '<script type="application/ld+json">%s</script>', json_encode( |
85 | 85 | apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
86 | 86 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
87 | - )); |
|
87 | + ) ); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | { |
95 | 95 | $schemas = glsr()->schemas; |
96 | 96 | $schemas[] = $schema; |
97 | - glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ))); |
|
97 | + glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -104,21 +104,21 @@ discard block |
||
104 | 104 | protected function buildReview( $review ) |
105 | 105 | { |
106 | 106 | $schema = $this->getSchemaType( 'Review' ) |
107 | - ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use( $review ) { |
|
107 | + ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use($review) { |
|
108 | 108 | $schema->name( $review->title ); |
109 | 109 | }) |
110 | - ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use( $review ) { |
|
110 | + ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use($review) { |
|
111 | 111 | $schema->reviewBody( $review->content ); |
112 | 112 | }) |
113 | - ->datePublished(( new DateTime( $review->date ))) |
|
114 | - ->author( $this->getSchemaType( 'Person' )->name( $review->author )) |
|
115 | - ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ))); |
|
116 | - if( !empty( $review->rating )) { |
|
113 | + ->datePublished( (new DateTime( $review->date )) ) |
|
114 | + ->author( $this->getSchemaType( 'Person' )->name( $review->author ) ) |
|
115 | + ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) ); |
|
116 | + if( !empty($review->rating) ) { |
|
117 | 117 | $schema->reviewRating( |
118 | 118 | $this->getSchemaType( 'Rating' ) |
119 | 119 | ->ratingValue( $review->rating ) |
120 | - ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class )) |
|
121 | - ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class )) |
|
120 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
121 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
122 | 122 | ); |
123 | 123 | } |
124 | 124 | return apply_filters( 'site-reviews/schema/review', $schema->toArray(), $review, $this->args ); |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | { |
133 | 133 | foreach( $values as $value ) { |
134 | 134 | $option = $this->getSchemaOptionValue( $value ); |
135 | - if( empty( $option ))continue; |
|
135 | + if( empty($option) )continue; |
|
136 | 136 | $schema->$value( $option ); |
137 | 137 | } |
138 | 138 | return $schema; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | { |
146 | 146 | return $this->buildSchemaValues( $this->getSchemaType(), [ |
147 | 147 | 'description', 'image', 'name', 'url', |
148 | - ]); |
|
148 | + ] ); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | { |
156 | 156 | return $this->buildSchemaValues( $this->buildSummaryForCustom(), [ |
157 | 157 | 'address', 'priceRange', 'telephone', |
158 | - ]); |
|
158 | + ] ); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | $offerType = $this->getSchemaOption( 'offerType', 'AggregateOffer' ); |
167 | 167 | $offers = $this->buildSchemaValues( $this->getSchemaType( $offerType ), [ |
168 | 168 | 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
169 | - ]); |
|
169 | + ] ); |
|
170 | 170 | return $this->buildSummaryForCustom() |
171 | - ->doIf( !empty( $offers->getProperties() ), function( $schema ) use( $offers ) { |
|
171 | + ->doIf( !empty($offers->getProperties()), function( $schema ) use($offers) { |
|
172 | 172 | $schema->offers( $offers ); |
173 | 173 | }) |
174 | 174 | ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ).'#product' ); |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | protected function getRatingCounts() |
181 | 181 | { |
182 | - if( !isset( $this->ratingCounts )) { |
|
182 | + if( !isset($this->ratingCounts) ) { |
|
183 | 183 | $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $this->args ); |
184 | 184 | } |
185 | 185 | return $this->ratingCounts; |
@@ -201,14 +201,14 @@ discard block |
||
201 | 201 | protected function getSchemaOption( $option, $fallback ) |
202 | 202 | { |
203 | 203 | $option = strtolower( $option ); |
204 | - if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ))) { |
|
204 | + if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) { |
|
205 | 205 | return $schemaOption; |
206 | 206 | } |
207 | 207 | $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option ); |
208 | - if( is_array( $setting )) { |
|
208 | + if( is_array( $setting ) ) { |
|
209 | 209 | return $this->getSchemaOptionDefault( $setting, $fallback ); |
210 | 210 | } |
211 | - return !empty( $setting ) |
|
211 | + return !empty($setting) |
|
212 | 212 | ? $setting |
213 | 213 | : $fallback; |
214 | 214 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | $setting = wp_parse_args( $setting, [ |
223 | 223 | 'custom' => '', |
224 | 224 | 'default' => $fallback, |
225 | - ]); |
|
225 | + ] ); |
|
226 | 226 | return $setting['default'] != 'custom' |
227 | 227 | ? $setting['default'] |
228 | 228 | : $setting['custom']; |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | } |
242 | 242 | if( !is_single() && !is_page() )return; |
243 | 243 | $method = glsr( Helper::class )->buildMethodName( $option, 'getThing' ); |
244 | - if( method_exists( $this, $method )) { |
|
244 | + if( method_exists( $this, $method ) ) { |
|
245 | 245 | return $this->$method(); |
246 | 246 | } |
247 | 247 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | */ |
253 | 253 | protected function getSchemaType( $type = null ) |
254 | 254 | { |
255 | - if( !is_string( $type )) { |
|
255 | + if( !is_string( $type ) ) { |
|
256 | 256 | $type = $this->getSchemaOption( 'type', 'LocalBusiness' ); |
257 | 257 | } |
258 | 258 | $className = glsr( Helper::class )->buildClassName( $type, 'Modules\Schema' ); |
@@ -267,11 +267,11 @@ discard block |
||
267 | 267 | protected function getThingDescription() |
268 | 268 | { |
269 | 269 | $post = get_post(); |
270 | - if( !( $post instanceof WP_Post )) { |
|
270 | + if( !($post instanceof WP_Post) ) { |
|
271 | 271 | return ''; |
272 | 272 | } |
273 | - $text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt )); |
|
274 | - return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 )); |
|
273 | + $text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt ) ); |
|
274 | + return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) ); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | 'setting' => 'Plugin Settings', |
41 | 41 | 'reviews' => 'Review Counts', |
42 | 42 | ]; |
43 | - $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use( $details ) { |
|
43 | + $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use($details) { |
|
44 | 44 | $methodName = glsr( Helper::class )->buildMethodName( 'get-'.$key.'-details' ); |
45 | 45 | if( method_exists( $this, $methodName ) && $systemDetails = $this->$methodName() ) { |
46 | 46 | return $carry.$this->implode( |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | { |
61 | 61 | $plugins = get_plugins(); |
62 | 62 | $activePlugins = (array)get_option( 'active_plugins', [] ); |
63 | - $inactive = array_diff_key( $plugins, array_flip( $activePlugins )); |
|
64 | - return $this->normalizePluginList( array_diff_key( $plugins, $inactive )); |
|
63 | + $inactive = array_diff_key( $plugins, array_flip( $activePlugins ) ); |
|
64 | + return $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | public function getInactivePluginDetails() |
96 | 96 | { |
97 | 97 | $activePlugins = (array)get_option( 'active_plugins', [] ); |
98 | - $inactivePlugins = $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ))); |
|
98 | + $inactivePlugins = $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ) ) ); |
|
99 | 99 | $multisitePlugins = $this->getMultisitePluginDetails(); |
100 | 100 | return is_array( $multisitePlugins ) |
101 | 101 | ? array_diff( $inactivePlugins, $multisitePlugins ) |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function getMuPluginDetails() |
109 | 109 | { |
110 | - if( empty( $plugins = get_mu_plugins() ))return; |
|
110 | + if( empty($plugins = get_mu_plugins()) )return; |
|
111 | 111 | return $this->normalizePluginList( $plugins ); |
112 | 112 | } |
113 | 113 | |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | public function getMultisitePluginDetails() |
118 | 118 | { |
119 | 119 | $activePlugins = (array)get_site_option( 'active_sitewide_plugins', [] ); |
120 | - if( !is_multisite() || empty( $activePlugins ))return; |
|
121 | - return $this->normalizePluginList( array_intersect_key( get_plugins(), $activePlugins )); |
|
120 | + if( !is_multisite() || empty($activePlugins) )return; |
|
121 | + return $this->normalizePluginList( array_intersect_key( get_plugins(), $activePlugins ) ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | 'Memory Limit' => ini_get( 'memory_limit' ), |
146 | 146 | 'Post Max Size' => ini_get( 'post_max_size' ), |
147 | 147 | 'Sendmail Path' => ini_get( 'sendmail_path' ), |
148 | - 'Session Cookie Path' => esc_html( ini_get( 'session.cookie_path' )), |
|
149 | - 'Session Name' => esc_html( ini_get( 'session.name' )), |
|
150 | - 'Session Save Path' => esc_html( ini_get( 'session.save_path' )), |
|
151 | - 'Session Use Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_cookies' )), true ), |
|
152 | - 'Session Use Only Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_only_cookies' )), true ), |
|
148 | + 'Session Cookie Path' => esc_html( ini_get( 'session.cookie_path' ) ), |
|
149 | + 'Session Name' => esc_html( ini_get( 'session.name' ) ), |
|
150 | + 'Session Save Path' => esc_html( ini_get( 'session.save_path' ) ), |
|
151 | + 'Session Use Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_cookies' ) ), true ), |
|
152 | + 'Session Use Only Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_only_cookies' ) ), true ), |
|
153 | 153 | 'Upload Max Filesize' => ini_get( 'upload_max_filesize' ), |
154 | 154 | ]; |
155 | 155 | } |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | { |
162 | 162 | $counts = glsr( CountsManager::class )->getCounts(); |
163 | 163 | $counts = glsr( Helper::class )->flattenArray( $counts ); |
164 | - array_walk( $counts, function( &$ratings ) use( $counts ) { |
|
165 | - if( !is_array( $ratings )) { |
|
164 | + array_walk( $counts, function( &$ratings ) use($counts) { |
|
165 | + if( !is_array( $ratings ) ) { |
|
166 | 166 | glsr_log() |
167 | 167 | ->error( '$ratings is not an array, possibly due to incorrectly imported reviews.' ) |
168 | 168 | ->debug( $ratings ) |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | ksort( $settings ); |
202 | 202 | $details = []; |
203 | 203 | foreach( $settings as $key => $value ) { |
204 | - if( $helper->startsWith( 'strings', $key ) && $helper->endsWith( 'id', $key ))continue; |
|
205 | - $value = htmlspecialchars( trim( preg_replace('/\s\s+/', '\\n', $value )), ENT_QUOTES, 'UTF-8' ); |
|
204 | + if( $helper->startsWith( 'strings', $key ) && $helper->endsWith( 'id', $key ) )continue; |
|
205 | + $value = htmlspecialchars( trim( preg_replace( '/\s\s+/', '\\n', $value ) ), ENT_QUOTES, 'UTF-8' ); |
|
206 | 206 | $details[$key] = $value; |
207 | 207 | } |
208 | 208 | return $details; |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | return [ |
217 | 217 | 'Console level' => glsr( Console::class )->humanLevel(), |
218 | 218 | 'Console size' => glsr( Console::class )->humanSize( '0' ), |
219 | - 'Last Rating Count' => date_i18n( 'Y-m-d H:i', glsr( OptionManager::class )->get( 'last_review_count' )), |
|
219 | + 'Last Rating Count' => date_i18n( 'Y-m-d H:i', glsr( OptionManager::class )->get( 'last_review_count' ) ), |
|
220 | 220 | 'Version (current)' => glsr()->version, |
221 | 221 | 'Version (previous)' => glsr( OptionManager::class )->get( 'version_upgraded_from' ), |
222 | 222 | ]; |
@@ -277,10 +277,10 @@ discard block |
||
277 | 277 | 'WPE_APIKEY' => 'WP Engine', |
278 | 278 | ]; |
279 | 279 | foreach( $checks as $key => $value ) { |
280 | - if( !$this->isWebhostCheckValid( $key ))continue; |
|
280 | + if( !$this->isWebhostCheckValid( $key ) )continue; |
|
281 | 281 | return $value; |
282 | 282 | } |
283 | - return implode( ',', array_filter( [DB_HOST, filter_input( INPUT_SERVER, 'SERVER_NAME' )] )); |
|
283 | + return implode( ',', array_filter( [DB_HOST, filter_input( INPUT_SERVER, 'SERVER_NAME' )] ) ); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | { |
302 | 302 | $plugins = get_plugins(); |
303 | 303 | $activePlugins = (array)get_option( 'active_plugins', [] ); |
304 | - $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ))); |
|
305 | - $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive )); |
|
304 | + $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ) ) ); |
|
305 | + $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
306 | 306 | return $active + $inactive; |
307 | 307 | } |
308 | 308 | |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | protected function implode( $title, array $details ) |
314 | 314 | { |
315 | 315 | $strings = ['['.$title.']']; |
316 | - $padding = max( array_map( 'strlen', array_keys( $details )) ); |
|
316 | + $padding = max( array_map( 'strlen', array_keys( $details ) ) ); |
|
317 | 317 | $padding = max( [$padding, static::PAD] ); |
318 | 318 | foreach( $details as $key => $value ) { |
319 | 319 | $strings[] = is_string( $key ) |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | protected function normalizePluginList( array $plugins ) |
343 | 343 | { |
344 | 344 | $plugins = array_map( function( $plugin ) { |
345 | - return sprintf( '%s v%s', glsr_get( $plugin, 'Name' ), glsr_get( $plugin, 'Version' )); |
|
345 | + return sprintf( '%s v%s', glsr_get( $plugin, 'Name' ), glsr_get( $plugin, 'Version' ) ); |
|
346 | 346 | }, $plugins ); |
347 | 347 | natcasesort( $plugins ); |
348 | 348 | return array_flip( $plugins ); |
@@ -356,9 +356,9 @@ discard block |
||
356 | 356 | $keys = [ |
357 | 357 | 'licenses.', 'submissions.recaptcha.key', 'submissions.recaptcha.secret', |
358 | 358 | ]; |
359 | - array_walk( $settings, function( &$value, $setting ) use( $keys ) { |
|
359 | + array_walk( $settings, function( &$value, $setting ) use($keys) { |
|
360 | 360 | foreach( $keys as $key ) { |
361 | - if( !glsr( Helper::class )->startsWith( $key, $setting ) || empty( $value ))continue; |
|
361 | + if( !glsr( Helper::class )->startsWith( $key, $setting ) || empty($value) )continue; |
|
362 | 362 | $value = str_repeat( '•', 13 ); |
363 | 363 | return; |
364 | 364 | } |
@@ -107,7 +107,9 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function getMuPluginDetails() |
109 | 109 | { |
110 | - if( empty( $plugins = get_mu_plugins() ))return; |
|
110 | + if( empty( $plugins = get_mu_plugins() )) { |
|
111 | + return; |
|
112 | + } |
|
111 | 113 | return $this->normalizePluginList( $plugins ); |
112 | 114 | } |
113 | 115 | |
@@ -117,7 +119,9 @@ discard block |
||
117 | 119 | public function getMultisitePluginDetails() |
118 | 120 | { |
119 | 121 | $activePlugins = (array)get_site_option( 'active_sitewide_plugins', [] ); |
120 | - if( !is_multisite() || empty( $activePlugins ))return; |
|
122 | + if( !is_multisite() || empty( $activePlugins )) { |
|
123 | + return; |
|
124 | + } |
|
121 | 125 | return $this->normalizePluginList( array_intersect_key( get_plugins(), $activePlugins )); |
122 | 126 | } |
123 | 127 | |
@@ -201,7 +205,9 @@ discard block |
||
201 | 205 | ksort( $settings ); |
202 | 206 | $details = []; |
203 | 207 | foreach( $settings as $key => $value ) { |
204 | - if( $helper->startsWith( 'strings', $key ) && $helper->endsWith( 'id', $key ))continue; |
|
208 | + if( $helper->startsWith( 'strings', $key ) && $helper->endsWith( 'id', $key )) { |
|
209 | + continue; |
|
210 | + } |
|
205 | 211 | $value = htmlspecialchars( trim( preg_replace('/\s\s+/', '\\n', $value )), ENT_QUOTES, 'UTF-8' ); |
206 | 212 | $details[$key] = $value; |
207 | 213 | } |
@@ -277,7 +283,9 @@ discard block |
||
277 | 283 | 'WPE_APIKEY' => 'WP Engine', |
278 | 284 | ]; |
279 | 285 | foreach( $checks as $key => $value ) { |
280 | - if( !$this->isWebhostCheckValid( $key ))continue; |
|
286 | + if( !$this->isWebhostCheckValid( $key )) { |
|
287 | + continue; |
|
288 | + } |
|
281 | 289 | return $value; |
282 | 290 | } |
283 | 291 | return implode( ',', array_filter( [DB_HOST, filter_input( INPUT_SERVER, 'SERVER_NAME' )] )); |
@@ -358,7 +366,9 @@ discard block |
||
358 | 366 | ]; |
359 | 367 | array_walk( $settings, function( &$value, $setting ) use( $keys ) { |
360 | 368 | foreach( $keys as $key ) { |
361 | - if( !glsr( Helper::class )->startsWith( $key, $setting ) || empty( $value ))continue; |
|
369 | + if( !glsr( Helper::class )->startsWith( $key, $setting ) || empty( $value )) { |
|
370 | + continue; |
|
371 | + } |
|
362 | 372 | $value = str_repeat( '•', 13 ); |
363 | 373 | return; |
364 | 374 | } |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | { |
50 | 50 | $average = array_sum( $ratingCounts ); |
51 | 51 | if( $average > 0 ) { |
52 | - $average = round( $this->getTotalSum( $ratingCounts ) / $average, intval( $roundBy )); |
|
52 | + $average = round( $this->getTotalSum( $ratingCounts ) / $average, intval( $roundBy ) ); |
|
53 | 53 | } |
54 | - return floatval( apply_filters( 'site-reviews/rating/average', $average, $ratingCounts )); |
|
54 | + return floatval( apply_filters( 'site-reviews/rating/average', $average, $ratingCounts ) ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | } |
73 | 73 | $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
74 | 74 | $phat = 1 * $upDownCounts[1] / $numRatings; |
75 | - return ( $phat + $z * $z / ( 2 * $numRatings ) - $z * sqrt(( $phat * ( 1 - $phat ) + $z * $z / ( 4 * $numRatings )) / $numRatings )) / ( 1 + $z * $z / $numRatings ); |
|
75 | + return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt( ($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings )) / (1 + $z * $z / $numRatings); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | { |
91 | 91 | $total = array_sum( $ratingCounts ); |
92 | 92 | foreach( $ratingCounts as $index => $count ) { |
93 | - if( empty( $count ))continue; |
|
93 | + if( empty($count) )continue; |
|
94 | 94 | $ratingCounts[$index] = $count / $total * 100; |
95 | 95 | } |
96 | 96 | return $this->getRoundedPercentages( $ratingCounts ); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | $this->getRankingUsingImdb( $ratingCounts ), |
106 | 106 | $ratingCounts, |
107 | 107 | $this |
108 | - )); |
|
108 | + ) ); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | $avgRating = $this->getAverage( $ratingCounts ); |
124 | 124 | // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error. |
125 | 125 | // This could also be the average score of all items instead of a fixed value. |
126 | - $bayesMean = ( $confidencePercentage / 100 ) * glsr()->constant( 'MAX_RATING' ); // prior, 70% = 3.5 |
|
126 | + $bayesMean = ($confidencePercentage / 100) * glsr()->constant( 'MAX_RATING' ); // prior, 70% = 3.5 |
|
127 | 127 | // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior. |
128 | 128 | $bayesMinimal = 10; // confidence |
129 | 129 | $numOfReviews = array_sum( $ratingCounts ); |
130 | 130 | return $avgRating > 0 |
131 | - ? (( $bayesMinimal * $bayesMean ) + ( $avgRating * $numOfReviews )) / ( $bayesMinimal + $numOfReviews ) |
|
131 | + ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews) |
|
132 | 132 | : 0; |
133 | 133 | } |
134 | 134 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $weight = $this->getWeight( $ratingCounts, $ratingCountsSum ); |
149 | 149 | $weightPow2 = $this->getWeight( $ratingCounts, $ratingCountsSum, true ); |
150 | 150 | $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
151 | - return $weight - $zScore * sqrt(( $weightPow2 - pow( $weight, 2 )) / ( $ratingCountsSum + 1 )); |
|
151 | + return $weight - $zScore * sqrt( ($weightPow2 - pow( $weight, 2 )) / ($ratingCountsSum + 1) ); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -168,14 +168,14 @@ discard block |
||
168 | 168 | $remainders = glsr_array_column( $percentages, 'remainder' ); |
169 | 169 | array_multisort( $remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages ); |
170 | 170 | $i = 0; |
171 | - if( array_sum( glsr_array_column( $percentages, 'percent' )) > 0 ) { |
|
172 | - while( array_sum( glsr_array_column( $percentages, 'percent' )) < $totalPercent ) { |
|
171 | + if( array_sum( glsr_array_column( $percentages, 'percent' ) ) > 0 ) { |
|
172 | + while( array_sum( glsr_array_column( $percentages, 'percent' ) ) < $totalPercent ) { |
|
173 | 173 | $percentages[$i]['percent']++; |
174 | 174 | $i++; |
175 | 175 | } |
176 | 176 | } |
177 | 177 | array_multisort( $indexes, SORT_DESC, $percentages ); |
178 | - return array_combine( $indexes, glsr_array_column( $percentages, 'percent' )); |
|
178 | + return array_combine( $indexes, glsr_array_column( $percentages, 'percent' ) ); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | */ |
184 | 184 | protected function getTotalSum( array $ratingCounts ) |
185 | 185 | { |
186 | - return array_reduce( array_keys( $ratingCounts ), function( $carry, $index ) use( $ratingCounts ) { |
|
187 | - return $carry + ( $index * $ratingCounts[$index] ); |
|
186 | + return array_reduce( array_keys( $ratingCounts ), function( $carry, $index ) use($ratingCounts) { |
|
187 | + return $carry + ($index * $ratingCounts[$index]); |
|
188 | 188 | }); |
189 | 189 | } |
190 | 190 | |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | protected function getWeight( array $ratingCounts, $ratingCountsSum, $powerOf2 = false ) |
197 | 197 | { |
198 | 198 | return array_reduce( array_keys( $ratingCounts ), |
199 | - function( $count, $rating ) use( $ratingCounts, $ratingCountsSum, $powerOf2 ) { |
|
199 | + function( $count, $rating ) use($ratingCounts, $ratingCountsSum, $powerOf2) { |
|
200 | 200 | $ratingLevel = $powerOf2 |
201 | 201 | ? pow( $rating, 2 ) |
202 | 202 | : $rating; |
203 | - return $count + ( $ratingLevel * ( $ratingCounts[$rating] + 1 )) / $ratingCountsSum; |
|
203 | + return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum; |
|
204 | 204 | } |
205 | 205 | ); |
206 | 206 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function compose( Review $review, array $notification ) |
37 | 37 | { |
38 | - if( empty( $this->endpoint )) { |
|
38 | + if( empty($this->endpoint) ) { |
|
39 | 39 | return $this; |
40 | 40 | } |
41 | 41 | $args = shortcode_atts( glsr( SlackDefaults::class )->defaults(), $notification ); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function send() |
62 | 62 | { |
63 | - if( empty( $this->endpoint )) { |
|
63 | + if( empty($this->endpoint) ) { |
|
64 | 64 | return new WP_Error( 'slack', 'Slack notification was not sent: missing endpoint' ); |
65 | 65 | } |
66 | 66 | return wp_remote_post( $this->endpoint, [ |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'redirection' => 5, |
73 | 73 | 'sslverify' => false, |
74 | 74 | 'timeout' => 45, |
75 | - ]); |
|
75 | + ] ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | */ |
93 | 93 | protected function buildAuthorField() |
94 | 94 | { |
95 | - $email = !empty( $this->review->email ) |
|
95 | + $email = !empty($this->review->email) |
|
96 | 96 | ? '<'.$this->review->email.'>' |
97 | 97 | : ''; |
98 | 98 | $author = trim( rtrim( $this->review->author ).' '.$email ); |
99 | - return ['value' => implode( ' - ', array_filter( [$author, $this->review->ip_address] ))]; |
|
99 | + return ['value' => implode( ' - ', array_filter( [$author, $this->review->ip_address] ) )]; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | protected function buildContentField() |
106 | 106 | { |
107 | - return !empty( $this->review->content ) |
|
107 | + return !empty($this->review->content) |
|
108 | 108 | ? ['value' => $this->review->content] |
109 | 109 | : []; |
110 | 110 | } |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | protected function buildStarsField() |
130 | 130 | { |
131 | 131 | $solidStars = str_repeat( '★', $this->review->rating ); |
132 | - $emptyStars = str_repeat( '☆', max( 0, glsr()->constant( 'MAX_RATING', Rating::class ) - $this->review->rating )); |
|
132 | + $emptyStars = str_repeat( '☆', max( 0, glsr()->constant( 'MAX_RATING', Rating::class ) - $this->review->rating ) ); |
|
133 | 133 | $stars = $solidStars.$emptyStars; |
134 | - $stars = apply_filters( 'site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant( 'MAX_RATING', Rating::class )); |
|
134 | + $stars = apply_filters( 'site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant( 'MAX_RATING', Rating::class ) ); |
|
135 | 135 | return ['title' => $stars]; |
136 | 136 | } |
137 | 137 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function buildTitleField() |
142 | 142 | { |
143 | - return !empty( $this->review->title ) |
|
143 | + return !empty($this->review->title) |
|
144 | 144 | ? ['title' => $this->review->title] |
145 | 145 | : []; |
146 | 146 | } |
@@ -41,33 +41,33 @@ |
||
41 | 41 | */ |
42 | 42 | public function run() |
43 | 43 | { |
44 | - add_filter( 'map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2 ); |
|
45 | - add_filter( 'mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15 ); |
|
46 | - add_filter( 'plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks'] ); |
|
47 | - add_filter( 'dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems'] ); |
|
48 | - add_filter( 'block_categories', [$this->blocks, 'filterBlockCategories'] ); |
|
49 | - add_filter( 'classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2 ); |
|
50 | - add_filter( 'use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2 ); |
|
51 | - add_filter( 'wp_editor_settings', [$this->editor, 'filterEditorSettings'] ); |
|
52 | - add_filter( 'the_editor', [$this->editor, 'filterEditorTextarea'] ); |
|
53 | - add_filter( 'gettext', [$this->editor, 'filterPostStatusLabels'], 10, 3 ); |
|
54 | - add_filter( 'gettext_with_context', [$this->editor, 'filterPostStatusLabelsWithContext'], 10, 4 ); |
|
55 | - add_filter( 'post_updated_messages', [$this->editor, 'filterUpdateMessages'] ); |
|
56 | - add_filter( 'bulk_post_updated_messages', [$this->listtable, 'filterBulkUpdateMessages'], 10, 2 ); |
|
57 | - add_filter( 'manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType'] ); |
|
58 | - add_filter( 'post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2 ); |
|
59 | - add_filter( 'default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2 ); |
|
60 | - add_filter( 'display_post_states', [$this->listtable, 'filterPostStates'], 10, 2 ); |
|
61 | - add_filter( 'post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2 ); |
|
44 | + add_filter( 'map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2 ); |
|
45 | + add_filter( 'mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15 ); |
|
46 | + add_filter( 'plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks'] ); |
|
47 | + add_filter( 'dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems'] ); |
|
48 | + add_filter( 'block_categories', [$this->blocks, 'filterBlockCategories'] ); |
|
49 | + add_filter( 'classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2 ); |
|
50 | + add_filter( 'use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2 ); |
|
51 | + add_filter( 'wp_editor_settings', [$this->editor, 'filterEditorSettings'] ); |
|
52 | + add_filter( 'the_editor', [$this->editor, 'filterEditorTextarea'] ); |
|
53 | + add_filter( 'gettext', [$this->editor, 'filterPostStatusLabels'], 10, 3 ); |
|
54 | + add_filter( 'gettext_with_context', [$this->editor, 'filterPostStatusLabelsWithContext'], 10, 4 ); |
|
55 | + add_filter( 'post_updated_messages', [$this->editor, 'filterUpdateMessages'] ); |
|
56 | + add_filter( 'bulk_post_updated_messages', [$this->listtable, 'filterBulkUpdateMessages'], 10, 2 ); |
|
57 | + add_filter( 'manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType'] ); |
|
58 | + add_filter( 'post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2 ); |
|
59 | + add_filter( 'default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2 ); |
|
60 | + add_filter( 'display_post_states', [$this->listtable, 'filterPostStates'], 10, 2 ); |
|
61 | + add_filter( 'post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2 ); |
|
62 | 62 | add_filter( 'manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns'] ); |
63 | - add_filter( 'ngettext', [$this->listtable, 'filterStatusText'], 10, 5 ); |
|
64 | - add_filter( 'script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2 ); |
|
65 | - add_filter( 'site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11 ); |
|
66 | - add_filter( 'query_vars', [$this->public, 'filterQueryVars'] ); |
|
67 | - add_filter( 'site-reviews/render/view', [$this->public, 'filterRenderView'] ); |
|
68 | - add_filter( 'gettext', [$this->translator, 'filterGettext'], 10, 3 ); |
|
69 | - add_filter( 'gettext_with_context', [$this->translator, 'filterGettextWithContext'], 10, 4 ); |
|
70 | - add_filter( 'ngettext', [$this->translator, 'filterNgettext'], 10, 5 ); |
|
71 | - add_filter( 'ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 10, 6 ); |
|
63 | + add_filter( 'ngettext', [$this->listtable, 'filterStatusText'], 10, 5 ); |
|
64 | + add_filter( 'script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2 ); |
|
65 | + add_filter( 'site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11 ); |
|
66 | + add_filter( 'query_vars', [$this->public, 'filterQueryVars'] ); |
|
67 | + add_filter( 'site-reviews/render/view', [$this->public, 'filterRenderView'] ); |
|
68 | + add_filter( 'gettext', [$this->translator, 'filterGettext'], 10, 3 ); |
|
69 | + add_filter( 'gettext_with_context', [$this->translator, 'filterGettextWithContext'], 10, 4 ); |
|
70 | + add_filter( 'ngettext', [$this->translator, 'filterNgettext'], 10, 5 ); |
|
71 | + add_filter( 'ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 10, 6 ); |
|
72 | 72 | } |
73 | 73 | } |
@@ -22,11 +22,11 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function deleteAllSessions( $sessionCookiePrefix ) |
24 | 24 | { |
25 | - return $this->db->query(" |
|
25 | + return $this->db->query( " |
|
26 | 26 | DELETE |
27 | 27 | FROM {$this->db->options} |
28 | 28 | WHERE option_name LIKE '{$sessionCookiePrefix}_%' |
29 | - "); |
|
29 | + " ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function deleteExpiredSessions( $expiredSessions ) |
37 | 37 | { |
38 | - return $this->db->query(" |
|
38 | + return $this->db->query( " |
|
39 | 39 | DELETE |
40 | 40 | FROM {$this->db->options} |
41 | 41 | WHERE option_name IN ('{$expiredSessions}') |
42 | - "); |
|
42 | + " ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function getExpiredSessions( $sessionCookiePrefix, $limit ) |
51 | 51 | { |
52 | - return (array) $this->db->get_results(" |
|
52 | + return (array)$this->db->get_results( " |
|
53 | 53 | SELECT option_name AS name, option_value AS expiration |
54 | 54 | FROM {$this->db->options} |
55 | 55 | WHERE option_name LIKE '{$sessionCookiePrefix}_expires_%' |
56 | 56 | ORDER BY option_value ASC |
57 | 57 | LIMIT 0, {$limit} |
58 | - "); |
|
58 | + " ); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function getPostIdFromReviewId( $metaReviewId ) |
66 | 66 | { |
67 | - $postId = $this->db->get_var(" |
|
67 | + $postId = $this->db->get_var( " |
|
68 | 68 | SELECT p.ID |
69 | 69 | FROM {$this->db->posts} AS p |
70 | 70 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
71 | 71 | WHERE p.post_type = '{$this->postType}' |
72 | 72 | AND m.meta_key = 'review_id' |
73 | 73 | AND m.meta_value = '{$metaReviewId}' |
74 | - "); |
|
74 | + " ); |
|
75 | 75 | return intval( $postId ); |
76 | 76 | } |
77 | 77 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 ) |
84 | 84 | { |
85 | - return (array) $this->db->get_results(" |
|
85 | + return (array)$this->db->get_results( " |
|
86 | 86 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
87 | 87 | FROM {$this->db->posts} AS p |
88 | 88 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | {$this->getAndForCounts( $args )} |
97 | 97 | ORDER By p.ID ASC |
98 | 98 | LIMIT {$limit} |
99 | - "); |
|
99 | + " ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function getReviewCountsFor( $metaKey ) |
108 | 108 | { |
109 | - return (array) $this->db->get_results(" |
|
109 | + return (array)$this->db->get_results( " |
|
110 | 110 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
111 | 111 | FROM {$this->db->posts} AS p |
112 | 112 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
113 | 113 | WHERE p.post_type = '{$this->postType}' |
114 | 114 | AND m.meta_key = '{$metaKey}' |
115 | 115 | GROUP BY name |
116 | - "); |
|
116 | + " ); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function getReviewIdsByType( $reviewType ) |
125 | 125 | { |
126 | - $results = $this->db->get_col(" |
|
126 | + $results = $this->db->get_col( " |
|
127 | 127 | SELECT DISTINCT m1.meta_value AS review_id |
128 | 128 | FROM {$this->db->posts} AS p |
129 | 129 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | AND m1.meta_key = 'review_id' |
133 | 133 | AND m2.meta_key = 'review_type' |
134 | 134 | AND m2.meta_value = '{$reviewType}' |
135 | - "); |
|
136 | - return array_keys( array_flip( $results )); |
|
135 | + " ); |
|
136 | + return array_keys( array_flip( $results ) ); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 ) |
145 | 145 | { |
146 | 146 | sort( $postIds ); |
147 | - $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds )), $limit ); |
|
147 | + $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit ); |
|
148 | 148 | $postIds = implode( ',', $postIds ); |
149 | - return (array) $this->db->get_results(" |
|
149 | + return (array)$this->db->get_results( " |
|
150 | 150 | SELECT p.ID, m.meta_value AS rating |
151 | 151 | FROM {$this->db->posts} AS p |
152 | 152 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | GROUP BY p.ID |
159 | 159 | ORDER By p.ID ASC |
160 | 160 | LIMIT {$limit} |
161 | - "); |
|
161 | + " ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function getReviewsMeta( $key, $status = 'publish' ) |
170 | 170 | { |
171 | - $values = $this->db->get_col(" |
|
171 | + $values = $this->db->get_col( " |
|
172 | 172 | SELECT DISTINCT m.meta_value |
173 | 173 | FROM {$this->db->postmeta} m |
174 | 174 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | AND p.post_status = '{$status}' |
179 | 179 | GROUP BY p.ID -- remove duplicate meta_value entries |
180 | 180 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
181 | - "); |
|
181 | + " ); |
|
182 | 182 | sort( $values ); |
183 | 183 | return $values; |
184 | 184 | } |
@@ -189,16 +189,16 @@ discard block |
||
189 | 189 | */ |
190 | 190 | protected function getAndForCounts( array $args, $and = '' ) |
191 | 191 | { |
192 | - $postIds = implode( ',', array_filter( glsr_get( $args, 'post_ids'))); |
|
193 | - $termIds = implode( ',', array_filter( glsr_get( $args, 'term_ids'))); |
|
194 | - if( !empty( $args['type'] )) { |
|
195 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
192 | + $postIds = implode( ',', array_filter( glsr_get( $args, 'post_ids' ) ) ); |
|
193 | + $termIds = implode( ',', array_filter( glsr_get( $args, 'term_ids' ) ) ); |
|
194 | + if( !empty($args['type']) ) { |
|
195 | + $and .= "AND m2.meta_value = '{$args['type']}' "; |
|
196 | 196 | } |
197 | 197 | if( $postIds ) { |
198 | - $and.= "AND m3.meta_key = 'assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
198 | + $and .= "AND m3.meta_key = 'assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
199 | 199 | } |
200 | 200 | if( $termIds ) { |
201 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
201 | + $and .= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
202 | 202 | } |
203 | 203 | return $and; |
204 | 204 | } |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | */ |
210 | 210 | protected function getInnerJoinForCounts( array $args, $innerJoin = '' ) |
211 | 211 | { |
212 | - if( !empty( glsr_get( $args, 'post_ids'))) { |
|
213 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
212 | + if( !empty(glsr_get( $args, 'post_ids' )) ) { |
|
213 | + $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
214 | 214 | } |
215 | - if( !empty( glsr_get( $args, 'term_ids'))) { |
|
216 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
215 | + if( !empty(glsr_get( $args, 'term_ids' )) ) { |
|
216 | + $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
217 | 217 | } |
218 | 218 | return $innerJoin; |
219 | 219 | } |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | $query = $this->queryReviews( $args ); |
31 | 31 | while( $query ) { |
32 | 32 | // glsr_log($query); |
33 | - $types = array_keys( array_flip( glsr_array_column( $query->reviews, 'type' ))); |
|
34 | - $types = array_unique( array_merge( ['local'], $types )); |
|
33 | + $types = array_keys( array_flip( glsr_array_column( $query->reviews, 'type' ) ) ); |
|
34 | + $types = array_unique( array_merge( ['local'], $types ) ); |
|
35 | 35 | foreach( $types as $type ) { |
36 | 36 | $type = $this->normalizeType( $type ); |
37 | - if( isset( $counts[$type] ))continue; |
|
38 | - $counts[$type] = array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', Rating::class )), 0 ); |
|
37 | + if( isset($counts[$type]) )continue; |
|
38 | + $counts[$type] = array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ), 0 ); |
|
39 | 39 | } |
40 | 40 | foreach( $query->reviews as $review ) { |
41 | 41 | $type = $this->normalizeType( $review->type ); |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | { |
74 | 74 | $terms = glsr( Database::class )->getTerms( ['fields' => 'all'] ); |
75 | 75 | foreach( $terms as $term ) { |
76 | - $this->setTermCounts( $term->term_id, $this->buildTermCounts( $term->term_taxonomy_id )); |
|
76 | + $this->setTermCounts( $term->term_id, $this->buildTermCounts( $term->term_taxonomy_id ) ); |
|
77 | 77 | } |
78 | 78 | $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' ); |
79 | 79 | foreach( $postIds as $postId ) { |
80 | - $this->setPostCounts( $postId, $this->buildPostCounts( $postId )); |
|
80 | + $this->setPostCounts( $postId, $this->buildPostCounts( $postId ) ); |
|
81 | 81 | } |
82 | 82 | $this->setCounts( $this->buildCounts() ); |
83 | 83 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $this->getCounts(), |
102 | 102 | $review->review_type, |
103 | 103 | $review->rating |
104 | - )); |
|
104 | + ) ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function decreasePostCounts( Review $review ) |
111 | 111 | { |
112 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
112 | + if( empty($counts = $this->getPostCounts( $review->assigned_to )) )return; |
|
113 | 113 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
114 | 114 | $this->setPostCounts( $review->assigned_to, $counts ); |
115 | 115 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | public function decreaseTermCounts( Review $review ) |
121 | 121 | { |
122 | 122 | foreach( $review->term_ids as $termId ) { |
123 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
123 | + if( empty($counts = $this->getTermCounts( $termId )) )continue; |
|
124 | 124 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
125 | 125 | $this->setTermCounts( $termId, $counts ); |
126 | 126 | } |
@@ -132,15 +132,15 @@ discard block |
||
132 | 132 | public function flatten( array $reviewCounts, array $args = [] ) |
133 | 133 | { |
134 | 134 | $counts = []; |
135 | - array_walk_recursive( $reviewCounts, function( $num, $index ) use( &$counts ) { |
|
136 | - $counts[$index] = $num + intval( glsr_get( $counts, $index, 0 )); |
|
135 | + array_walk_recursive( $reviewCounts, function( $num, $index ) use(&$counts) { |
|
136 | + $counts[$index] = $num + intval( glsr_get( $counts, $index, 0 ) ); |
|
137 | 137 | }); |
138 | 138 | $args = wp_parse_args( $args, [ |
139 | 139 | 'max' => glsr()->constant( 'MAX_RATING', Rating::class ), |
140 | 140 | 'min' => glsr()->constant( 'MIN_RATING', Rating::class ), |
141 | - ]); |
|
141 | + ] ); |
|
142 | 142 | foreach( $counts as $index => &$num ) { |
143 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
143 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ) )continue; |
|
144 | 144 | $num = 0; |
145 | 145 | } |
146 | 146 | return $counts; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | { |
154 | 154 | $args = $this->normalizeArgs( $args ); |
155 | 155 | $counts = []; |
156 | - if( $this->isMixedCount( $args )) { |
|
156 | + if( $this->isMixedCount( $args ) ) { |
|
157 | 157 | $counts = [$this->buildCounts( $args )]; // force query the database |
158 | 158 | } |
159 | 159 | else { |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | foreach( $args['term_ids'] as $termId ) { |
164 | 164 | $counts[] = $this->getTermCounts( $termId ); |
165 | 165 | } |
166 | - if( empty( $counts )) { |
|
166 | + if( empty($counts) ) { |
|
167 | 167 | $counts[] = $this->getCounts(); |
168 | 168 | } |
169 | 169 | } |
170 | 170 | return in_array( $args['type'], ['', 'all'] ) |
171 | 171 | ? $this->normalize( [$this->flatten( $counts )] ) |
172 | - : $this->normalize( glsr_array_column( $counts, $args['type'] )); |
|
172 | + : $this->normalize( glsr_array_column( $counts, $args['type'] ) ); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | public function getCounts() |
179 | 179 | { |
180 | 180 | $counts = glsr( OptionManager::class )->get( 'counts', [] ); |
181 | - if( !is_array( $counts )) { |
|
181 | + if( !is_array( $counts ) ) { |
|
182 | 182 | glsr_log()->error( '$counts is not an array' )->debug( $counts ); |
183 | 183 | return []; |
184 | 184 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function getPostCounts( $postId ) |
193 | 193 | { |
194 | - return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true )); |
|
194 | + return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true ) ); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public function getTermCounts( $termId ) |
202 | 202 | { |
203 | - return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true )); |
|
203 | + return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true ) ); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | */ |
219 | 219 | public function increaseCounts( Review $review ) |
220 | 220 | { |
221 | - if( empty( $counts = $this->getCounts() )) { |
|
221 | + if( empty($counts = $this->getCounts()) ) { |
|
222 | 222 | $counts = $this->buildCounts(); |
223 | 223 | } |
224 | - $this->setCounts( $this->increaseRating( $counts, $review->review_type, $review->rating )); |
|
224 | + $this->setCounts( $this->increaseRating( $counts, $review->review_type, $review->rating ) ); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function increasePostCounts( Review $review ) |
231 | 231 | { |
232 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
232 | + if( !(get_post( $review->assigned_to ) instanceof WP_Post) )return; |
|
233 | 233 | $counts = $this->getPostCounts( $review->assigned_to ); |
234 | - $counts = empty( $counts ) |
|
234 | + $counts = empty($counts) |
|
235 | 235 | ? $this->buildPostCounts( $review->assigned_to ) |
236 | 236 | : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
237 | 237 | $this->setPostCounts( $review->assigned_to, $counts ); |
@@ -242,10 +242,10 @@ discard block |
||
242 | 242 | */ |
243 | 243 | public function increaseTermCounts( Review $review ) |
244 | 244 | { |
245 | - $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids )); |
|
245 | + $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) ); |
|
246 | 246 | foreach( $terms as $term ) { |
247 | 247 | $counts = $this->getTermCounts( $term['term_id'] ); |
248 | - $counts = empty( $counts ) |
|
248 | + $counts = empty($counts) |
|
249 | 249 | ? $this->buildTermCounts( $term['term_taxonomy_id'] ) |
250 | 250 | : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
251 | 251 | $this->setTermCounts( $term['term_id'], $counts ); |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | { |
269 | 269 | $ratingCounts = $this->flatten( $reviewCounts ); |
270 | 270 | update_post_meta( $postId, static::META_COUNT, $reviewCounts ); |
271 | - update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
272 | - update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
271 | + update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
272 | + update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -279,11 +279,11 @@ discard block |
||
279 | 279 | public function setTermCounts( $termId, array $reviewCounts ) |
280 | 280 | { |
281 | 281 | $term = get_term( $termId, Application::TAXONOMY ); |
282 | - if( !isset( $term->term_id ))return; |
|
282 | + if( !isset($term->term_id) )return; |
|
283 | 283 | $ratingCounts = $this->flatten( $reviewCounts ); |
284 | 284 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
285 | - update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
286 | - update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
285 | + update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
286 | + update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | */ |
294 | 294 | protected function decreaseRating( array $reviewCounts, $type, $rating ) |
295 | 295 | { |
296 | - if( isset( $reviewCounts[$type][$rating] )) { |
|
296 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
297 | 297 | $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
298 | 298 | } |
299 | 299 | return $reviewCounts; |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | */ |
307 | 307 | protected function increaseRating( array $reviewCounts, $type, $rating ) |
308 | 308 | { |
309 | - if( !array_key_exists( $type, glsr()->reviewTypes )) { |
|
309 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
310 | 310 | return $reviewCounts; |
311 | 311 | } |
312 | - if( !array_key_exists( $type, $reviewCounts )) { |
|
312 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
313 | 313 | $reviewCounts[$type] = []; |
314 | 314 | } |
315 | 315 | $reviewCounts = $this->normalize( $reviewCounts ); |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | protected function isMixedCount( array $args ) |
324 | 324 | { |
325 | - return !empty( $args['post_ids'] ) && !empty( $args['term_ids'] ); |
|
325 | + return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -330,12 +330,12 @@ discard block |
||
330 | 330 | */ |
331 | 331 | protected function normalize( array $reviewCounts ) |
332 | 332 | { |
333 | - if( empty( $reviewCounts )) { |
|
333 | + if( empty($reviewCounts) ) { |
|
334 | 334 | $reviewCounts = [[]]; |
335 | 335 | } |
336 | 336 | foreach( $reviewCounts as &$counts ) { |
337 | - foreach( range( 0, glsr()->constant( 'MAX_RATING', Rating::class )) as $index ) { |
|
338 | - if( isset( $counts[$index] ))continue; |
|
337 | + foreach( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ) as $index ) { |
|
338 | + if( isset($counts[$index]) )continue; |
|
339 | 339 | $counts[$index] = 0; |
340 | 340 | } |
341 | 341 | ksort( $counts ); |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | 'post_ids' => [], |
353 | 353 | 'term_ids' => [], |
354 | 354 | 'type' => 'local', |
355 | - ]); |
|
355 | + ] ); |
|
356 | 356 | $args['post_ids'] = glsr( Polylang::class )->getPostIds( $args['post_ids'] ); |
357 | 357 | $args['type'] = $this->normalizeType( $args['type'] ); |
358 | 358 | return $args; |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | */ |
365 | 365 | protected function normalizeType( $type ) |
366 | 366 | { |
367 | - return empty( $type ) || !is_string( $type ) |
|
367 | + return empty($type) || !is_string( $type ) |
|
368 | 368 | ? 'local' |
369 | 369 | : $type; |
370 | 370 | } |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | $hasMore = is_array( $reviews ) |
380 | 380 | ? count( $reviews ) == static::LIMIT |
381 | 381 | : false; |
382 | - return (object) [ |
|
382 | + return (object)[ |
|
383 | 383 | 'has_more' => $hasMore, |
384 | 384 | 'reviews' => $reviews, |
385 | 385 | ]; |
@@ -34,7 +34,9 @@ discard block |
||
34 | 34 | $types = array_unique( array_merge( ['local'], $types )); |
35 | 35 | foreach( $types as $type ) { |
36 | 36 | $type = $this->normalizeType( $type ); |
37 | - if( isset( $counts[$type] ))continue; |
|
37 | + if( isset( $counts[$type] )) { |
|
38 | + continue; |
|
39 | + } |
|
38 | 40 | $counts[$type] = array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', Rating::class )), 0 ); |
39 | 41 | } |
40 | 42 | foreach( $query->reviews as $review ) { |
@@ -109,7 +111,9 @@ discard block |
||
109 | 111 | */ |
110 | 112 | public function decreasePostCounts( Review $review ) |
111 | 113 | { |
112 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
114 | + if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) { |
|
115 | + return; |
|
116 | + } |
|
113 | 117 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
114 | 118 | $this->setPostCounts( $review->assigned_to, $counts ); |
115 | 119 | } |
@@ -120,7 +124,9 @@ discard block |
||
120 | 124 | public function decreaseTermCounts( Review $review ) |
121 | 125 | { |
122 | 126 | foreach( $review->term_ids as $termId ) { |
123 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
127 | + if( empty( $counts = $this->getTermCounts( $termId ))) { |
|
128 | + continue; |
|
129 | + } |
|
124 | 130 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
125 | 131 | $this->setTermCounts( $termId, $counts ); |
126 | 132 | } |
@@ -140,7 +146,9 @@ discard block |
||
140 | 146 | 'min' => glsr()->constant( 'MIN_RATING', Rating::class ), |
141 | 147 | ]); |
142 | 148 | foreach( $counts as $index => &$num ) { |
143 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
149 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] )) { |
|
150 | + continue; |
|
151 | + } |
|
144 | 152 | $num = 0; |
145 | 153 | } |
146 | 154 | return $counts; |
@@ -229,7 +237,9 @@ discard block |
||
229 | 237 | */ |
230 | 238 | public function increasePostCounts( Review $review ) |
231 | 239 | { |
232 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
240 | + if( !( get_post( $review->assigned_to ) instanceof WP_Post )) { |
|
241 | + return; |
|
242 | + } |
|
233 | 243 | $counts = $this->getPostCounts( $review->assigned_to ); |
234 | 244 | $counts = empty( $counts ) |
235 | 245 | ? $this->buildPostCounts( $review->assigned_to ) |
@@ -279,7 +289,9 @@ discard block |
||
279 | 289 | public function setTermCounts( $termId, array $reviewCounts ) |
280 | 290 | { |
281 | 291 | $term = get_term( $termId, Application::TAXONOMY ); |
282 | - if( !isset( $term->term_id ))return; |
|
292 | + if( !isset( $term->term_id )) { |
|
293 | + return; |
|
294 | + } |
|
283 | 295 | $ratingCounts = $this->flatten( $reviewCounts ); |
284 | 296 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
285 | 297 | update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
@@ -335,7 +347,9 @@ discard block |
||
335 | 347 | } |
336 | 348 | foreach( $reviewCounts as &$counts ) { |
337 | 349 | foreach( range( 0, glsr()->constant( 'MAX_RATING', Rating::class )) as $index ) { |
338 | - if( isset( $counts[$index] ))continue; |
|
350 | + if( isset( $counts[$index] )) { |
|
351 | + continue; |
|
352 | + } |
|
339 | 353 | $counts[$index] = 0; |
340 | 354 | } |
341 | 355 | ksort( $counts ); |