@@ -8,9 +8,9 @@ discard block |
||
8 | 8 | * @param string $id |
9 | 9 | * @return string |
10 | 10 | */ |
11 | - public function buildFields($id) |
|
11 | + public function buildFields( $id ) |
|
12 | 12 | { |
13 | - return array_reduce($this->getFields($id), function ($carry, $field) { |
|
13 | + return array_reduce( $this->getFields( $id ), function( $carry, $field ) { |
|
14 | 14 | return $carry.$field; |
15 | 15 | }); |
16 | 16 | } |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | * @param string $id |
20 | 20 | * @return array |
21 | 21 | */ |
22 | - public function getFields($id) |
|
22 | + public function getFields( $id ) |
|
23 | 23 | { |
24 | 24 | $fields = []; |
25 | - foreach (glsr()->config('forms/'.$id) as $name => $field) { |
|
26 | - $fields[] = new Field(wp_parse_args($field, ['name' => $name])); |
|
25 | + foreach( glsr()->config( 'forms/'.$id ) as $name => $field ) { |
|
26 | + $fields[] = new Field( wp_parse_args( $field, ['name' => $name] ) ); |
|
27 | 27 | } |
28 | 28 | return $fields; |
29 | 29 | } |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | * @param string $id |
33 | 33 | * @return void |
34 | 34 | */ |
35 | - public function renderFields($id) |
|
35 | + public function renderFields( $id ) |
|
36 | 36 | { |
37 | - echo $this->buildFields($id); |
|
37 | + echo $this->buildFields( $id ); |
|
38 | 38 | } |
39 | 39 | } |
@@ -9,14 +9,14 @@ |
||
9 | 9 | /** |
10 | 10 | * @return void|string |
11 | 11 | */ |
12 | - public function build(array $args = []) |
|
12 | + public function build( array $args = [] ) |
|
13 | 13 | { |
14 | 14 | require_once ABSPATH.'wp-admin/includes/template.php'; |
15 | 15 | ob_start(); |
16 | - wp_star_rating($args); |
|
16 | + wp_star_rating( $args ); |
|
17 | 17 | $stars = ob_get_clean(); |
18 | 18 | return !glsr()->isAdmin() |
19 | - ? str_replace(['star-rating', 'star star'], ['glsr-stars', 'glsr-star glsr-star'], $stars) |
|
19 | + ? str_replace( ['star-rating', 'star star'], ['glsr-stars', 'glsr-star glsr-star'], $stars ) |
|
20 | 20 | : $stars; |
21 | 21 | } |
22 | 22 | } |
@@ -28,16 +28,16 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @return void|string |
30 | 30 | */ |
31 | - public function build(array $args = []) |
|
31 | + public function build( array $args = [] ) |
|
32 | 32 | { |
33 | 33 | $this->args = $args; |
34 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args); |
|
35 | - if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) { |
|
34 | + $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $args ); |
|
35 | + if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ) ) { |
|
36 | 36 | return; |
37 | 37 | } |
38 | - $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts); |
|
38 | + $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts ); |
|
39 | 39 | $this->generateSchema(); |
40 | - return glsr(Template::class)->build('templates/reviews-summary', [ |
|
40 | + return glsr( Template::class )->build( 'templates/reviews-summary', [ |
|
41 | 41 | 'context' => [ |
42 | 42 | 'assigned_to' => $this->args['assigned_to'], |
43 | 43 | 'category' => $this->args['category'], |
@@ -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,35 +56,35 @@ discard block |
||
56 | 56 | */ |
57 | 57 | protected function buildPercentage() |
58 | 58 | { |
59 | - if ($this->isHidden('bars')) { |
|
59 | + if( $this->isHidden( 'bars' ) ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | - $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts)); |
|
63 | - $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) { |
|
64 | - $label = $this->buildPercentageLabel($this->args['labels'][$level]); |
|
65 | - $background = $this->buildPercentageBackground($percentages[$level]); |
|
66 | - $count = apply_filters('site-reviews/summary/counts', |
|
62 | + $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts ) ); |
|
63 | + $bars = array_reduce( range( glsr()->constant( 'MAX_RATING', Rating::class ), 1 ), function( $carry, $level ) use ($percentages) { |
|
64 | + $label = $this->buildPercentageLabel( $this->args['labels'][$level] ); |
|
65 | + $background = $this->buildPercentageBackground( $percentages[$level] ); |
|
66 | + $count = apply_filters( 'site-reviews/summary/counts', |
|
67 | 67 | $percentages[$level], |
68 | 68 | $this->ratingCounts[$level] |
69 | 69 | ); |
70 | - $percent = $this->buildPercentageCount($count); |
|
71 | - return $carry.glsr(Builder::class)->div($label.$background.$percent, [ |
|
70 | + $percent = $this->buildPercentageCount( $count ); |
|
71 | + return $carry.glsr( Builder::class )->div( $label.$background.$percent, [ |
|
72 | 72 | 'class' => 'glsr-bar', |
73 | - ]); |
|
73 | + ] ); |
|
74 | 74 | }); |
75 | - return $this->wrap('percentage', $bars); |
|
75 | + return $this->wrap( 'percentage', $bars ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @param string $percent |
80 | 80 | * @return string |
81 | 81 | */ |
82 | - protected function buildPercentageBackground($percent) |
|
82 | + protected function buildPercentageBackground( $percent ) |
|
83 | 83 | { |
84 | - $backgroundPercent = glsr(Builder::class)->span([ |
|
84 | + $backgroundPercent = glsr( Builder::class )->span( [ |
|
85 | 85 | 'class' => 'glsr-bar-background-percent', |
86 | 86 | 'style' => 'width:'.$percent, |
87 | - ]); |
|
87 | + ] ); |
|
88 | 88 | return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>'; |
89 | 89 | } |
90 | 90 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @param string $count |
93 | 93 | * @return string |
94 | 94 | */ |
95 | - protected function buildPercentageCount($count) |
|
95 | + protected function buildPercentageCount( $count ) |
|
96 | 96 | { |
97 | 97 | return '<span class="glsr-bar-percent">'.$count.'</span>'; |
98 | 98 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @param string $label |
102 | 102 | * @return string |
103 | 103 | */ |
104 | - protected function buildPercentageLabel($label) |
|
104 | + protected function buildPercentageLabel( $label ) |
|
105 | 105 | { |
106 | 106 | return '<span class="glsr-bar-label">'.$label.'</span>'; |
107 | 107 | } |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | */ |
112 | 112 | protected function buildRating() |
113 | 113 | { |
114 | - if ($this->isHidden('rating')) { |
|
114 | + if( $this->isHidden( 'rating' ) ) { |
|
115 | 115 | return; |
116 | 116 | } |
117 | - return $this->wrap('rating', '<span>'.$this->averageRating.'</span>'); |
|
117 | + return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | */ |
123 | 123 | protected function buildStars() |
124 | 124 | { |
125 | - if ($this->isHidden('stars')) { |
|
125 | + if( $this->isHidden( 'stars' ) ) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | - $stars = glsr_star_rating($this->averageRating); |
|
129 | - return $this->wrap('stars', $stars); |
|
128 | + $stars = glsr_star_rating( $this->averageRating ); |
|
129 | + return $this->wrap( 'stars', $stars ); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function buildText() |
136 | 136 | { |
137 | - if ($this->isHidden('summary')) { |
|
137 | + if( $this->isHidden( 'summary' ) ) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | - $count = intval(array_sum($this->ratingCounts)); |
|
141 | - if (empty($this->args['text'])) { |
|
140 | + $count = intval( array_sum( $this->ratingCounts ) ); |
|
141 | + if( empty($this->args['text']) ) { |
|
142 | 142 | // @todo document this change |
143 | 143 | $this->args['text'] = _nx( |
144 | 144 | '{rating} out of {max} stars (based on {num} review)', |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | } |
151 | 151 | $summary = str_replace( |
152 | 152 | ['{rating}', '{max}', '{num}'], |
153 | - [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count], |
|
153 | + [$this->averageRating, glsr()->constant( 'MAX_RATING', Rating::class ), $count], |
|
154 | 154 | $this->args['text'] |
155 | 155 | ); |
156 | - return $this->wrap('text', '<span>'.$summary.'</span>'); |
|
156 | + return $this->wrap( 'text', '<span>'.$summary.'</span>' ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | */ |
162 | 162 | protected function generateSchema() |
163 | 163 | { |
164 | - if (!wp_validate_boolean($this->args['schema'])) { |
|
164 | + if( !wp_validate_boolean( $this->args['schema'] ) ) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | - glsr(Schema::class)->store( |
|
168 | - glsr(Schema::class)->buildSummary($this->args) |
|
167 | + glsr( Schema::class )->store( |
|
168 | + glsr( Schema::class )->buildSummary( $this->args ) |
|
169 | 169 | ); |
170 | 170 | } |
171 | 171 | |
@@ -174,16 +174,16 @@ discard block |
||
174 | 174 | */ |
175 | 175 | protected function getClass() |
176 | 176 | { |
177 | - return trim('glsr-summary glsr-default '.$this->args['class']); |
|
177 | + return trim( 'glsr-summary glsr-default '.$this->args['class'] ); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
181 | 181 | * @param string $key |
182 | 182 | * @return bool |
183 | 183 | */ |
184 | - protected function isHidden($key) |
|
184 | + protected function isHidden( $key ) |
|
185 | 185 | { |
186 | - return in_array($key, $this->args['hide']); |
|
186 | + return in_array( $key, $this->args['hide'] ); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -191,10 +191,10 @@ discard block |
||
191 | 191 | * @param string $value |
192 | 192 | * @return string |
193 | 193 | */ |
194 | - protected function wrap($key, $value) |
|
194 | + protected function wrap( $key, $value ) |
|
195 | 195 | { |
196 | - return glsr(Builder::class)->div($value, [ |
|
196 | + return glsr( Builder::class )->div( $value, [ |
|
197 | 197 | 'class' => 'glsr-summary-'.$key, |
198 | - ]); |
|
198 | + ] ); |
|
199 | 199 | } |
200 | 200 | } |
@@ -8,5 +8,5 @@ |
||
8 | 8 | * @params string|array $atts |
9 | 9 | * @return string |
10 | 10 | */ |
11 | - public function buildShortcode($atts = []); |
|
11 | + public function buildShortcode( $atts = [] ); |
|
12 | 12 | } |
@@ -7,5 +7,5 @@ |
||
7 | 7 | /** |
8 | 8 | * @return void|string |
9 | 9 | */ |
10 | - public function build(array $args = []); |
|
10 | + public function build( array $args = [] ); |
|
11 | 11 | } |
@@ -9,5 +9,5 @@ |
||
9 | 9 | /** |
10 | 10 | * @return void |
11 | 11 | */ |
12 | - public function register(Application $app); |
|
12 | + public function register( Application $app ); |
|
13 | 13 | } |
@@ -50,18 +50,18 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * @return string |
52 | 52 | */ |
53 | - public function render(array $attributes) |
|
53 | + public function render( array $attributes ) |
|
54 | 54 | { |
55 | 55 | $attributes['class'] = $attributes['className']; |
56 | - $shortcode = glsr(Shortcode::class); |
|
57 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
58 | - $attributes = $this->normalize($attributes); |
|
56 | + $shortcode = glsr( Shortcode::class ); |
|
57 | + if( 'edit' == filter_input( INPUT_GET, 'context' ) ) { |
|
58 | + $attributes = $this->normalize( $attributes ); |
|
59 | 59 | $this->filterShortcodeClass(); |
60 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
60 | + if( !$this->hasVisibleFields( $shortcode, $attributes ) ) { |
|
61 | 61 | $this->filterInterpolation(); |
62 | 62 | } |
63 | 63 | } |
64 | - return $shortcode->buildShortcode($attributes); |
|
64 | + return $shortcode->buildShortcode( $attributes ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | */ |
70 | 70 | protected function filterInterpolation() |
71 | 71 | { |
72 | - add_filter('site-reviews/interpolate/reviews-summary', function ($context) { |
|
72 | + add_filter( 'site-reviews/interpolate/reviews-summary', function( $context ) { |
|
73 | 73 | $context['class'] = 'glsr-default glsr-block-disabled'; |
74 | - $context['text'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
74 | + $context['text'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' ); |
|
75 | 75 | return $context; |
76 | 76 | }); |
77 | 77 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function filterShortcodeClass() |
83 | 83 | { |
84 | - add_filter('site-reviews/style', function () { |
|
84 | + add_filter( 'site-reviews/style', function() { |
|
85 | 85 | return 'default'; |
86 | 86 | }); |
87 | 87 | } |
@@ -38,20 +38,20 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * @return string |
40 | 40 | */ |
41 | - public function render(array $attributes) |
|
41 | + public function render( array $attributes ) |
|
42 | 42 | { |
43 | 43 | $attributes['class'] = $attributes['className']; |
44 | - $shortcode = glsr(Shortcode::class); |
|
45 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
44 | + $shortcode = glsr( Shortcode::class ); |
|
45 | + if( 'edit' == filter_input( INPUT_GET, 'context' ) ) { |
|
46 | 46 | $this->filterFormFields(); |
47 | 47 | $this->filterRatingField(); |
48 | 48 | $this->filterShortcodeClass(); |
49 | 49 | $this->filterSubmitButton(); |
50 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
50 | + if( !$this->hasVisibleFields( $shortcode, $attributes ) ) { |
|
51 | 51 | $this->filterInterpolation(); |
52 | 52 | } |
53 | 53 | } |
54 | - return $shortcode->buildShortcode($attributes); |
|
54 | + return $shortcode->buildShortcode( $attributes ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | */ |
60 | 60 | protected function filterFormFields() |
61 | 61 | { |
62 | - add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
63 | - array_walk($config, function (&$field) { |
|
62 | + add_filter( 'site-reviews/config/forms/submission-form', function( array $config ) { |
|
63 | + array_walk( $config, function( &$field ) { |
|
64 | 64 | $field['disabled'] = true; |
65 | 65 | $field['tabindex'] = '-1'; |
66 | 66 | }); |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | */ |
74 | 74 | protected function filterInterpolation() |
75 | 75 | { |
76 | - add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
76 | + add_filter( 'site-reviews/interpolate/reviews-form', function( $context ) { |
|
77 | 77 | $context['class'] = 'glsr-default glsr-block-disabled'; |
78 | - $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
78 | + $context['fields'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' ); |
|
79 | 79 | $context['response'] = ''; |
80 | 80 | $context['submit_button'] = ''; |
81 | 81 | return $context; |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | */ |
88 | 88 | protected function filterRatingField() |
89 | 89 | { |
90 | - add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
91 | - if ('rating' == $args['path']) { |
|
90 | + add_filter( 'site-reviews/rendered/field', function( $html, $type, $args ) { |
|
91 | + if( 'rating' == $args['path'] ) { |
|
92 | 92 | $stars = '<span class="glsr-stars">'; |
93 | - $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', 5); |
|
94 | - $stars.= '</span>'; |
|
95 | - $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html); |
|
93 | + $stars .= str_repeat( '<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', 5 ); |
|
94 | + $stars .= '</span>'; |
|
95 | + $html = preg_replace( '/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html ); |
|
96 | 96 | } |
97 | 97 | return $html; |
98 | - }, 10, 3); |
|
98 | + }, 10, 3 ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function filterShortcodeClass() |
105 | 105 | { |
106 | - add_filter('site-reviews/style', function () { |
|
106 | + add_filter( 'site-reviews/style', function() { |
|
107 | 107 | return 'default'; |
108 | 108 | }); |
109 | 109 | } |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | */ |
114 | 114 | protected function filterSubmitButton() |
115 | 115 | { |
116 | - add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
117 | - return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
116 | + add_filter( 'site-reviews/rendered/template/form/submit-button', function( $template ) { |
|
117 | + return str_replace( 'type="submit"', 'tabindex="-1"', $template ); |
|
118 | 118 | }); |
119 | 119 | } |
120 | 120 | } |
@@ -17,18 +17,18 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @return array |
19 | 19 | */ |
20 | - public function normalize(array $attributes) |
|
20 | + public function normalize( array $attributes ) |
|
21 | 21 | { |
22 | - $hide = array_flip(explode(',', $attributes['hide'])); |
|
22 | + $hide = array_flip( explode( ',', $attributes['hide'] ) ); |
|
23 | 23 | unset($hide['if_empty']); |
24 | - $attributes['hide'] = implode(',', array_keys($hide)); |
|
25 | - if (!isset($attributes['assigned_to'])) { |
|
24 | + $attributes['hide'] = implode( ',', array_keys( $hide ) ); |
|
25 | + if( !isset($attributes['assigned_to']) ) { |
|
26 | 26 | return $attributes; |
27 | 27 | } |
28 | - if ('post_id' == $attributes['assigned_to']) { |
|
28 | + if( 'post_id' == $attributes['assigned_to'] ) { |
|
29 | 29 | $attributes['assigned_to'] = $attributes['post_id']; |
30 | - } elseif ('parent_id' == $attributes['assigned_to']) { |
|
31 | - $attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']); |
|
30 | + } elseif( 'parent_id' == $attributes['assigned_to'] ) { |
|
31 | + $attributes['assigned_to'] = wp_get_post_parent_id( $attributes['post_id'] ); |
|
32 | 32 | } |
33 | 33 | return $attributes; |
34 | 34 | } |
@@ -36,35 +36,35 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @return void |
38 | 38 | */ |
39 | - public function register($block) |
|
39 | + public function register( $block ) |
|
40 | 40 | { |
41 | - if (!function_exists('register_block_type')) { |
|
41 | + if( !function_exists( 'register_block_type' ) ) { |
|
42 | 42 | return; |
43 | 43 | } |
44 | - register_block_type(Application::ID.'/'.$block, [ |
|
44 | + register_block_type( Application::ID.'/'.$block, [ |
|
45 | 45 | 'attributes' => $this->attributes(), |
46 | 46 | 'editor_script' => Application::ID.'/blocks', |
47 | 47 | 'editor_style' => Application::ID.'/blocks', |
48 | 48 | 'render_callback' => [$this, 'render'], |
49 | 49 | 'style' => Application::ID, |
50 | - ]); |
|
50 | + ] ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @return void |
55 | 55 | */ |
56 | - abstract public function render(array $attributes); |
|
56 | + abstract public function render( array $attributes ); |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @param mixed $shortcode |
60 | 60 | * @return bool |
61 | 61 | */ |
62 | - protected function hasVisibleFields($shortcode, array $attributes) |
|
62 | + protected function hasVisibleFields( $shortcode, array $attributes ) |
|
63 | 63 | { |
64 | - $args = $shortcode->normalizeAtts($attributes); |
|
64 | + $args = $shortcode->normalizeAtts( $attributes ); |
|
65 | 65 | $defaults = $shortcode->getHideOptions(); |
66 | - $hide = array_flip($args['hide']); |
|
66 | + $hide = array_flip( $args['hide'] ); |
|
67 | 67 | unset($defaults['if_empty'], $hide['if_empty']); |
68 | - return !empty(array_diff_key($defaults, $hide)); |
|
68 | + return !empty(array_diff_key( $defaults, $hide )); |
|
69 | 69 | } |
70 | 70 | } |