@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="glsr-form-wrap"> |
4 | 4 | <form class="{{ class }}" id="{{ id }}" method="post" enctype="multipart/form-data"> |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="glsr-form-message {{ class }}"> |
4 | 4 | {{ message }} |
@@ -61,18 +61,18 @@ discard block |
||
61 | 61 | * @param array $args |
62 | 62 | * @return string|void |
63 | 63 | */ |
64 | - public function __call($method, $args) |
|
64 | + public function __call( $method, $args ) |
|
65 | 65 | { |
66 | 66 | $instance = new static(); |
67 | - $instance->setTagFromMethod($method); |
|
68 | - call_user_func_array([$instance, 'normalize'], $args += ['', '']); |
|
69 | - $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT); |
|
70 | - do_action_ref_array('site-reviews/builder', [$instance]); |
|
71 | - $generatedTag = in_array($instance->tag, $tags) |
|
67 | + $instance->setTagFromMethod( $method ); |
|
68 | + call_user_func_array( [$instance, 'normalize'], $args += ['', ''] ); |
|
69 | + $tags = array_merge( static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT ); |
|
70 | + do_action_ref_array( 'site-reviews/builder', [$instance] ); |
|
71 | + $generatedTag = in_array( $instance->tag, $tags ) |
|
72 | 72 | ? $instance->buildTag() |
73 | 73 | : $instance->buildCustomField(); |
74 | - $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance); |
|
75 | - if (!$this->render) { |
|
74 | + $generatedTag = apply_filters( 'site-reviews/builder/result', $generatedTag, $instance ); |
|
75 | + if( !$this->render ) { |
|
76 | 76 | return $generatedTag; |
77 | 77 | } |
78 | 78 | echo $generatedTag; |
@@ -83,15 +83,15 @@ discard block |
||
83 | 83 | * @param mixed $value |
84 | 84 | * @return void |
85 | 85 | */ |
86 | - public function __set($property, $value) |
|
86 | + public function __set( $property, $value ) |
|
87 | 87 | { |
88 | 88 | $properties = [ |
89 | 89 | 'args' => 'is_array', |
90 | 90 | 'render' => 'is_bool', |
91 | 91 | 'tag' => 'is_string', |
92 | 92 | ]; |
93 | - if (!isset($properties[$property]) |
|
94 | - || empty(array_filter([$value], $properties[$property])) |
|
93 | + if( !isset($properties[$property]) |
|
94 | + || empty(array_filter( [$value], $properties[$property] )) |
|
95 | 95 | ) { |
96 | 96 | return; |
97 | 97 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getClosingTag() |
105 | 105 | { |
106 | - if (empty($this->tag)) { |
|
106 | + if( empty($this->tag) ) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | return '</'.$this->tag.'>'; |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function getOpeningTag() |
116 | 116 | { |
117 | - if (empty($this->tag)) { |
|
117 | + if( empty($this->tag) ) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | - $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString(); |
|
121 | - return '<'.trim($this->tag.' '.$attributes).'>'; |
|
120 | + $attributes = glsr( Attributes::class )->{$this->tag}($this->args)->toString(); |
|
121 | + return '<'.trim( $this->tag.' '.$attributes ).'>'; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,19 +126,19 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function getTag() |
128 | 128 | { |
129 | - if (in_array($this->tag, static::TAGS_SINGLE)) { |
|
129 | + if( in_array( $this->tag, static::TAGS_SINGLE ) ) { |
|
130 | 130 | return $this->getOpeningTag(); |
131 | 131 | } |
132 | - if (!in_array($this->tag, static::TAGS_FORM)) { |
|
132 | + if( !in_array( $this->tag, static::TAGS_FORM ) ) { |
|
133 | 133 | return $this->buildDefaultTag(); |
134 | 134 | } |
135 | - return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription(); |
|
135 | + return call_user_func( [$this, 'buildForm'.ucfirst( $this->tag )] ).$this->buildFieldDescription(); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * @return string |
140 | 140 | */ |
141 | - public function raw(array $field) |
|
141 | + public function raw( array $field ) |
|
142 | 142 | { |
143 | 143 | unset($field['label']); |
144 | 144 | return $this->{$field['type']}($field); |
@@ -150,18 +150,18 @@ discard block |
||
150 | 150 | protected function buildCustomField() |
151 | 151 | { |
152 | 152 | $className = $this->getCustomFieldClassName(); |
153 | - if (class_exists($className)) { |
|
154 | - return (new $className($this))->build(); |
|
153 | + if( class_exists( $className ) ) { |
|
154 | + return (new $className( $this ))->build(); |
|
155 | 155 | } |
156 | - glsr_log()->error('Field missing: '.$className); |
|
156 | + glsr_log()->error( 'Field missing: '.$className ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | 160 | * @return string|void |
161 | 161 | */ |
162 | - protected function buildDefaultTag($text = '') |
|
162 | + protected function buildDefaultTag( $text = '' ) |
|
163 | 163 | { |
164 | - if (empty($text)) { |
|
164 | + if( empty($text) ) { |
|
165 | 165 | $text = $this->args['text']; |
166 | 166 | } |
167 | 167 | return $this->getOpeningTag().$text.$this->getClosingTag(); |
@@ -172,13 +172,13 @@ discard block |
||
172 | 172 | */ |
173 | 173 | protected function buildFieldDescription() |
174 | 174 | { |
175 | - if (empty($this->args['description'])) { |
|
175 | + if( empty($this->args['description']) ) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | - if ($this->args['is_widget']) { |
|
179 | - return $this->small($this->args['description']); |
|
178 | + if( $this->args['is_widget'] ) { |
|
179 | + return $this->small( $this->args['description'] ); |
|
180 | 180 | } |
181 | - return $this->p($this->args['description'], ['class' => 'description']); |
|
181 | + return $this->p( $this->args['description'], ['class' => 'description'] ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | */ |
187 | 187 | protected function buildFormInput() |
188 | 188 | { |
189 | - if (!in_array($this->args['type'], ['checkbox', 'radio'])) { |
|
190 | - if (isset($this->args['multiple'])) { |
|
191 | - $this->args['name'].= '[]'; |
|
189 | + if( !in_array( $this->args['type'], ['checkbox', 'radio'] ) ) { |
|
190 | + if( isset($this->args['multiple']) ) { |
|
191 | + $this->args['name'] .= '[]'; |
|
192 | 192 | } |
193 | 193 | return $this->buildFormLabel().$this->getOpeningTag(); |
194 | 194 | } |
@@ -202,19 +202,19 @@ discard block |
||
202 | 202 | */ |
203 | 203 | protected function buildFormInputChoice() |
204 | 204 | { |
205 | - if (!empty($this->args['text'])) { |
|
205 | + if( !empty($this->args['text']) ) { |
|
206 | 206 | $this->args['label'] = $this->args['text']; |
207 | 207 | } |
208 | - if (!$this->args['is_public']) { |
|
209 | - return $this->buildFormLabel([ |
|
208 | + if( !$this->args['is_public'] ) { |
|
209 | + return $this->buildFormLabel( [ |
|
210 | 210 | 'class' => 'glsr-'.$this->args['type'].'-label', |
211 | 211 | 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>', |
212 | - ]); |
|
212 | + ] ); |
|
213 | 213 | } |
214 | - return $this->getOpeningTag().$this->buildFormLabel([ |
|
214 | + return $this->getOpeningTag().$this->buildFormLabel( [ |
|
215 | 215 | 'class' => 'glsr-'.$this->args['type'].'-label', |
216 | 216 | 'text' => $this->args['label'].'<span></span>', |
217 | - ]); |
|
217 | + ] ); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -222,39 +222,39 @@ discard block |
||
222 | 222 | */ |
223 | 223 | protected function buildFormInputMultiChoice() |
224 | 224 | { |
225 | - if ('checkbox' == $this->args['type']) { |
|
226 | - $this->args['name'].= '[]'; |
|
225 | + if( 'checkbox' == $this->args['type'] ) { |
|
226 | + $this->args['name'] .= '[]'; |
|
227 | 227 | } |
228 | 228 | $index = 0; |
229 | - $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) { |
|
230 | - return $carry.$this->li($this->{$this->args['type']}([ |
|
231 | - 'checked' => in_array($key, (array) $this->args['value']), |
|
229 | + $options = array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use (&$index) { |
|
230 | + return $carry.$this->li( $this->{$this->args['type']}([ |
|
231 | + 'checked' => in_array( $key, (array)$this->args['value'] ), |
|
232 | 232 | 'id' => $this->args['id'].'-'.$index++, |
233 | 233 | 'name' => $this->args['name'], |
234 | 234 | 'text' => $this->args['options'][$key], |
235 | 235 | 'value' => $key, |
236 | - ])); |
|
236 | + ]) ); |
|
237 | 237 | }); |
238 | - return $this->ul($options, [ |
|
238 | + return $this->ul( $options, [ |
|
239 | 239 | 'class' => $this->args['class'], |
240 | 240 | 'id' => $this->args['id'], |
241 | - ]); |
|
241 | + ] ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | 245 | * @return void|string |
246 | 246 | */ |
247 | - protected function buildFormLabel(array $customArgs = []) |
|
247 | + protected function buildFormLabel( array $customArgs = [] ) |
|
248 | 248 | { |
249 | - if (empty($this->args['label']) || 'hidden' == $this->args['type']) { |
|
249 | + if( empty($this->args['label']) || 'hidden' == $this->args['type'] ) { |
|
250 | 250 | return; |
251 | 251 | } |
252 | - return $this->label(wp_parse_args($customArgs, [ |
|
252 | + return $this->label( wp_parse_args( $customArgs, [ |
|
253 | 253 | 'for' => $this->args['id'], |
254 | 254 | 'is_public' => $this->args['is_public'], |
255 | 255 | 'text' => $this->args['label'], |
256 | 256 | 'type' => $this->args['type'], |
257 | - ])); |
|
257 | + ] ) ); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | */ |
263 | 263 | protected function buildFormSelect() |
264 | 264 | { |
265 | - return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions()); |
|
265 | + return $this->buildFormLabel().$this->buildDefaultTag( $this->buildFormSelectOptions() ); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -270,12 +270,12 @@ discard block |
||
270 | 270 | */ |
271 | 271 | protected function buildFormSelectOptions() |
272 | 272 | { |
273 | - return array_reduce(array_keys($this->args['options']), function ($carry, $key) { |
|
274 | - return $carry.$this->option([ |
|
273 | + return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) { |
|
274 | + return $carry.$this->option( [ |
|
275 | 275 | 'selected' => $this->args['value'] == $key, |
276 | 276 | 'text' => $this->args['options'][$key], |
277 | 277 | 'value' => $key, |
278 | - ]); |
|
278 | + ] ); |
|
279 | 279 | }); |
280 | 280 | } |
281 | 281 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | */ |
285 | 285 | protected function buildFormTextarea() |
286 | 286 | { |
287 | - return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']); |
|
287 | + return $this->buildFormLabel().$this->buildDefaultTag( $this->args['value'] ); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | */ |
302 | 302 | protected function getCustomFieldClassName() |
303 | 303 | { |
304 | - $classname = glsr(Helper::class)->buildClassName($this->tag, __NAMESPACE__.'\Fields'); |
|
305 | - return apply_filters('site-reviews/builder/field/'.$this->tag, $classname); |
|
304 | + $classname = glsr( Helper::class )->buildClassName( $this->tag, __NAMESPACE__.'\Fields' ); |
|
305 | + return apply_filters( 'site-reviews/builder/field/'.$this->tag, $classname ); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -311,27 +311,27 @@ discard block |
||
311 | 311 | protected function mergeArgsWithRequiredDefaults() |
312 | 312 | { |
313 | 313 | $className = $this->getCustomFieldClassName(); |
314 | - if (class_exists($className)) { |
|
315 | - $this->args = $className::merge($this->args); |
|
314 | + if( class_exists( $className ) ) { |
|
315 | + $this->args = $className::merge( $this->args ); |
|
316 | 316 | } |
317 | - $this->args = glsr(BuilderDefaults::class)->merge($this->args); |
|
317 | + $this->args = glsr( BuilderDefaults::class )->merge( $this->args ); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
321 | 321 | * @param string|array ...$params |
322 | 322 | * @return void |
323 | 323 | */ |
324 | - protected function normalize(...$params) |
|
324 | + protected function normalize( ...$params ) |
|
325 | 325 | { |
326 | - if (is_string($params[0]) || is_numeric($params[0])) { |
|
327 | - $this->setNameOrTextAttributeForTag($params[0]); |
|
326 | + if( is_string( $params[0] ) || is_numeric( $params[0] ) ) { |
|
327 | + $this->setNameOrTextAttributeForTag( $params[0] ); |
|
328 | 328 | } |
329 | - if (is_array($params[0])) { |
|
329 | + if( is_array( $params[0] ) ) { |
|
330 | 330 | $this->args += $params[0]; |
331 | - } elseif (is_array($params[1])) { |
|
331 | + } elseif( is_array( $params[1] ) ) { |
|
332 | 332 | $this->args += $params[1]; |
333 | 333 | } |
334 | - if (!isset($this->args['is_public'])) { |
|
334 | + if( !isset($this->args['is_public']) ) { |
|
335 | 335 | $this->args['is_public'] = false; |
336 | 336 | } |
337 | 337 | } |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | * @param string $value |
341 | 341 | * @return void |
342 | 342 | */ |
343 | - protected function setNameOrTextAttributeForTag($value) |
|
343 | + protected function setNameOrTextAttributeForTag( $value ) |
|
344 | 344 | { |
345 | - $attribute = in_array($this->tag, static::TAGS_FORM) |
|
345 | + $attribute = in_array( $this->tag, static::TAGS_FORM ) |
|
346 | 346 | ? 'name' |
347 | 347 | : 'text'; |
348 | 348 | $this->args[$attribute] = $value; |
@@ -352,10 +352,10 @@ discard block |
||
352 | 352 | * @param string $method |
353 | 353 | * @return void |
354 | 354 | */ |
355 | - protected function setTagFromMethod($method) |
|
355 | + protected function setTagFromMethod( $method ) |
|
356 | 356 | { |
357 | - $this->tag = strtolower($method); |
|
358 | - if (in_array($this->tag, static::INPUT_TYPES)) { |
|
357 | + $this->tag = strtolower( $method ); |
|
358 | + if( in_array( $this->tag, static::INPUT_TYPES ) ) { |
|
359 | 359 | $this->args['type'] = $this->tag; |
360 | 360 | $this->tag = 'input'; |
361 | 361 | } |
@@ -27,13 +27,13 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public $reviews; |
29 | 29 | |
30 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
30 | + public function __construct( array $reviews, $maxPageCount, array $args ) |
|
31 | 31 | { |
32 | 32 | $this->args = $args; |
33 | 33 | $this->max_num_pages = $maxPageCount; |
34 | 34 | $this->reviews = $reviews; |
35 | 35 | $this->pagination = $this->buildPagination(); |
36 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
36 | + parent::__construct( $reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function __toString() |
43 | 43 | { |
44 | - return glsr(Template::class)->build('templates/reviews', [ |
|
44 | + return glsr( Template::class )->build( 'templates/reviews', [ |
|
45 | 45 | 'args' => $this->args, |
46 | 46 | 'context' => [ |
47 | 47 | 'assigned_to' => $this->args['assigned_to'], |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | 'pagination' => $this->getPagination(), |
52 | 52 | 'reviews' => $this->getReviews(), |
53 | 53 | ], |
54 | - ]); |
|
54 | + ] ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function getPagination() |
61 | 61 | { |
62 | - return wp_validate_boolean($this->args['pagination']) |
|
62 | + return wp_validate_boolean( $this->args['pagination'] ) |
|
63 | 63 | ? $this->pagination |
64 | 64 | : ''; |
65 | 65 | } |
@@ -71,26 +71,26 @@ discard block |
||
71 | 71 | { |
72 | 72 | $html = empty($this->reviews) |
73 | 73 | ? $this->getReviewsFallback() |
74 | - : implode(PHP_EOL, $this->reviews); |
|
74 | + : implode( PHP_EOL, $this->reviews ); |
|
75 | 75 | $wrapper = '<div class="glsr-reviews">%s</div>'; |
76 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
77 | - return sprintf($wrapper, $html); |
|
76 | + $wrapper = apply_filters( 'site-reviews/reviews/reviews-wrapper', $wrapper ); |
|
77 | + return sprintf( $wrapper, $html ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
81 | 81 | * @param mixed $key |
82 | 82 | * @return mixed |
83 | 83 | */ |
84 | - public function offsetGet($key) |
|
84 | + public function offsetGet( $key ) |
|
85 | 85 | { |
86 | - if ('navigation' == $key) { |
|
86 | + if( 'navigation' == $key ) { |
|
87 | 87 | glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
88 | 88 | return $this->pagination; |
89 | 89 | } |
90 | - if (property_exists($this, $key)) { |
|
90 | + if( property_exists( $this, $key ) ) { |
|
91 | 91 | return $this->{$key}; |
92 | 92 | } |
93 | - return array_key_exists($key, $this->reviews) |
|
93 | + return array_key_exists( $key, $this->reviews ) |
|
94 | 94 | ? $this->reviews[$key] |
95 | 95 | : null; |
96 | 96 | } |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected function buildPagination() |
102 | 102 | { |
103 | - $html = glsr(Partial::class)->build('pagination', [ |
|
104 | - 'baseUrl' => glsr_get($this->args, 'pagedUrl'), |
|
105 | - 'current' => glsr_get($this->args, 'paged'), |
|
103 | + $html = glsr( Partial::class )->build( 'pagination', [ |
|
104 | + 'baseUrl' => glsr_get( $this->args, 'pagedUrl' ), |
|
105 | + 'current' => glsr_get( $this->args, 'paged' ), |
|
106 | 106 | 'total' => $this->max_num_pages, |
107 | - ]); |
|
108 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
107 | + ] ); |
|
108 | + $html .= sprintf( '<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json'] ); |
|
109 | 109 | $wrapper = '<div class="glsr-pagination">%s</div>'; |
110 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
111 | - return sprintf($wrapper, $html); |
|
110 | + $wrapper = apply_filters( 'site-reviews/reviews/pagination-wrapper', $wrapper ); |
|
111 | + return sprintf( $wrapper, $html ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | $defaults = [ |
120 | 120 | 'glsr-default', |
121 | 121 | ]; |
122 | - if ('ajax' == $this->args['pagination']) { |
|
122 | + if( 'ajax' == $this->args['pagination'] ) { |
|
123 | 123 | $defaults[] = 'glsr-ajax-pagination'; |
124 | 124 | } |
125 | - $classes = explode(' ', $this->args['class']); |
|
126 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
127 | - return implode(' ', $classes); |
|
125 | + $classes = explode( ' ', $this->args['class'] ); |
|
126 | + $classes = array_unique( array_merge( $defaults, array_filter( $classes ) ) ); |
|
127 | + return implode( ' ', $classes ); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | */ |
133 | 133 | protected function getReviewsFallback() |
134 | 134 | { |
135 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
136 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
135 | + if( empty($this->args['fallback']) && glsr( OptionManager::class )->getBool( 'settings.reviews.fallback' ) ) { |
|
136 | + $this->args['fallback'] = __( 'There are no reviews yet. Be the first one to write one.', 'site-reviews' ); |
|
137 | 137 | } |
138 | 138 | $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
139 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
139 | + return apply_filters( 'site-reviews/reviews/fallback', $fallback, $this->args ); |
|
140 | 140 | } |
141 | 141 | } |
@@ -13,41 +13,41 @@ discard block |
||
13 | 13 | * @param string|array|WP_Error $message |
14 | 14 | * @return void |
15 | 15 | */ |
16 | - public function add($type, $message, array $args = []) |
|
16 | + public function add( $type, $message, array $args = [] ) |
|
17 | 17 | { |
18 | - if (empty(array_filter([$message, $type]))) { |
|
18 | + if( empty(array_filter( [$message, $type] )) ) { |
|
19 | 19 | return; |
20 | 20 | } |
21 | 21 | $args['message'] = $message; |
22 | 22 | $args['type'] = $type; |
23 | - add_settings_error(Application::ID, '', json_encode($this->normalize($args))); |
|
23 | + add_settings_error( Application::ID, '', json_encode( $this->normalize( $args ) ) ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @param string|array|WP_Error $message |
28 | 28 | * @return void |
29 | 29 | */ |
30 | - public function addError($message, array $args = []) |
|
30 | + public function addError( $message, array $args = [] ) |
|
31 | 31 | { |
32 | - $this->add('error', $message, $args); |
|
32 | + $this->add( 'error', $message, $args ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | 36 | * @param string|array|WP_Error $message |
37 | 37 | * @return void |
38 | 38 | */ |
39 | - public function addSuccess($message, array $args = []) |
|
39 | + public function addSuccess( $message, array $args = [] ) |
|
40 | 40 | { |
41 | - $this->add('success', $message, $args); |
|
41 | + $this->add( 'success', $message, $args ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @param string|array|WP_Error $message |
46 | 46 | * @return void |
47 | 47 | */ |
48 | - public function addWarning($message, array $args = []) |
|
48 | + public function addWarning( $message, array $args = [] ) |
|
49 | 49 | { |
50 | - $this->add('warning', $message, $args); |
|
50 | + $this->add( 'warning', $message, $args ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | { |
58 | 58 | global $wp_settings_errors; |
59 | 59 | $wp_settings_errors = []; |
60 | - delete_transient('settings_errors'); |
|
60 | + delete_transient( 'settings_errors' ); |
|
61 | 61 | return $this; |
62 | 62 | } |
63 | 63 | |
@@ -66,41 +66,41 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function get() |
68 | 68 | { |
69 | - $notices = array_map('unserialize', |
|
70 | - array_unique(array_map('serialize', get_settings_errors(Application::ID))) |
|
69 | + $notices = array_map( 'unserialize', |
|
70 | + array_unique( array_map( 'serialize', get_settings_errors( Application::ID ) ) ) |
|
71 | 71 | ); |
72 | - if (empty($notices)) { |
|
72 | + if( empty($notices) ) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | - return array_reduce($notices, function ($carry, $notice) { |
|
76 | - return $carry.$this->buildNotice(json_decode($notice['message'], true)); |
|
75 | + return array_reduce( $notices, function( $carry, $notice ) { |
|
76 | + return $carry.$this->buildNotice( json_decode( $notice['message'], true ) ); |
|
77 | 77 | }); |
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - protected function buildNotice(array $args) |
|
83 | + protected function buildNotice( array $args ) |
|
84 | 84 | { |
85 | - $messages = array_reduce($args['messages'], function ($carry, $message) { |
|
86 | - return $carry.glsr(Builder::class)->p($message); |
|
85 | + $messages = array_reduce( $args['messages'], function( $carry, $message ) { |
|
86 | + return $carry.glsr( Builder::class )->p( $message ); |
|
87 | 87 | }); |
88 | 88 | $class = 'notice notice-'.$args['type']; |
89 | - if ($args['inline']) { |
|
90 | - $class.= ' inline'; |
|
89 | + if( $args['inline'] ) { |
|
90 | + $class .= ' inline'; |
|
91 | 91 | } |
92 | - if ($args['dismissible']) { |
|
93 | - $class.= ' is-dismissible'; |
|
92 | + if( $args['dismissible'] ) { |
|
93 | + $class .= ' is-dismissible'; |
|
94 | 94 | } |
95 | - return glsr(Builder::class)->div($messages, [ |
|
95 | + return glsr( Builder::class )->div( $messages, [ |
|
96 | 96 | 'class' => $class, |
97 | - ]); |
|
97 | + ] ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @return array |
102 | 102 | */ |
103 | - protected function normalize(array $args) |
|
103 | + protected function normalize( array $args ) |
|
104 | 104 | { |
105 | 105 | $defaults = [ |
106 | 106 | 'dismissible' => true, |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | 'message' => '', |
109 | 109 | 'type' => '', |
110 | 110 | ]; |
111 | - $args = shortcode_atts($defaults, $args); |
|
112 | - if (!in_array($args['type'], ['error', 'warning', 'success'])) { |
|
111 | + $args = shortcode_atts( $defaults, $args ); |
|
112 | + if( !in_array( $args['type'], ['error', 'warning', 'success'] ) ) { |
|
113 | 113 | $args['type'] = 'success'; |
114 | 114 | } |
115 | - $args['messages'] = is_wp_error($args['message']) |
|
116 | - ? (array) $args['message']->get_error_message() |
|
117 | - : (array) $args['message']; |
|
115 | + $args['messages'] = is_wp_error( $args['message'] ) |
|
116 | + ? (array)$args['message']->get_error_message() |
|
117 | + : (array)$args['message']; |
|
118 | 118 | unset($args['message']); |
119 | 119 | return $args; |
120 | 120 | } |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | public function all() |
30 | 30 | { |
31 | 31 | $translations = $this->translations(); |
32 | - $entries = $this->filter($translations, $this->entries())->results(); |
|
33 | - array_walk($translations, function (&$entry) use ($entries) { |
|
34 | - $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
35 | - ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
32 | + $entries = $this->filter( $translations, $this->entries() )->results(); |
|
33 | + array_walk( $translations, function( &$entry ) use ($entries) { |
|
34 | + $entry['desc'] = array_key_exists( $entry['id'], $entries ) |
|
35 | + ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' ) |
|
36 | 36 | : ''; |
37 | 37 | }); |
38 | 38 | return $translations; |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function entries() |
45 | 45 | { |
46 | - if (!isset($this->entries)) { |
|
47 | - $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
48 | - $entries = $this->extractEntriesFromPotFile($potFile); |
|
49 | - $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
46 | + if( !isset($this->entries) ) { |
|
47 | + $potFile = glsr()->path( glsr()->languages.'/'.Application::ID.'.pot' ); |
|
48 | + $entries = $this->extractEntriesFromPotFile( $potFile ); |
|
49 | + $entries = apply_filters( 'site-reviews/translation/entries', $entries ); |
|
50 | 50 | $this->entries = $entries; |
51 | 51 | } |
52 | 52 | return $this->entries; |
@@ -57,24 +57,24 @@ discard block |
||
57 | 57 | * @param array|null $entries |
58 | 58 | * @return static |
59 | 59 | */ |
60 | - public function exclude($entriesToExclude = null, $entries = null) |
|
60 | + public function exclude( $entriesToExclude = null, $entries = null ) |
|
61 | 61 | { |
62 | - return $this->filter($entriesToExclude, $entries, false); |
|
62 | + return $this->filter( $entriesToExclude, $entries, false ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @param string $potFile |
67 | 67 | * @return array |
68 | 68 | */ |
69 | - public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
69 | + public function extractEntriesFromPotFile( $potFile, array $entries = [] ) |
|
70 | 70 | { |
71 | 71 | try { |
72 | - $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
73 | - foreach ($potEntries as $key => $entry) { |
|
74 | - $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
72 | + $potEntries = $this->normalize( Parser::parseFile( $potFile )->getEntries() ); |
|
73 | + foreach( $potEntries as $key => $entry ) { |
|
74 | + $entries[html_entity_decode( $key, ENT_COMPAT, 'UTF-8' )] = $entry; |
|
75 | 75 | } |
76 | - } catch (Exception $e) { |
|
77 | - glsr_log()->error($e->getMessage()); |
|
76 | + } catch( Exception $e ) { |
|
77 | + glsr_log()->error( $e->getMessage() ); |
|
78 | 78 | } |
79 | 79 | return $entries; |
80 | 80 | } |
@@ -85,18 +85,18 @@ discard block |
||
85 | 85 | * @param bool $intersect |
86 | 86 | * @return static |
87 | 87 | */ |
88 | - public function filter($filterWith = null, $entries = null, $intersect = true) |
|
88 | + public function filter( $filterWith = null, $entries = null, $intersect = true ) |
|
89 | 89 | { |
90 | - if (!is_array($entries)) { |
|
90 | + if( !is_array( $entries ) ) { |
|
91 | 91 | $entries = $this->results; |
92 | 92 | } |
93 | - if (!is_array($filterWith)) { |
|
93 | + if( !is_array( $filterWith ) ) { |
|
94 | 94 | $filterWith = $this->translations(); |
95 | 95 | } |
96 | - $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
96 | + $keys = array_flip( glsr_array_column( $filterWith, 'id' ) ); |
|
97 | 97 | $this->results = $intersect |
98 | - ? array_intersect_key($entries, $keys) |
|
99 | - : array_diff_key($entries, $keys); |
|
98 | + ? array_intersect_key( $entries, $keys ) |
|
99 | + : array_diff_key( $entries, $keys ); |
|
100 | 100 | return $this; |
101 | 101 | } |
102 | 102 | |
@@ -104,20 +104,20 @@ discard block |
||
104 | 104 | * @param string $template |
105 | 105 | * @return string |
106 | 106 | */ |
107 | - public function render($template, array $entry) |
|
107 | + public function render( $template, array $entry ) |
|
108 | 108 | { |
109 | 109 | $data = array_combine( |
110 | - array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
110 | + array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ), |
|
111 | 111 | $entry |
112 | 112 | ); |
113 | 113 | $data['data.class'] = $data['data.error'] = ''; |
114 | - if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
114 | + if( false === array_search( $entry['s1'], glsr_array_column( $this->entries(), 'msgid' ) ) ) { |
|
115 | 115 | $data['data.class'] = 'is-invalid'; |
116 | - $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
116 | + $data['data.error'] = __( 'This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews' ); |
|
117 | 117 | } |
118 | - return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
118 | + return glsr( Template::class )->build( 'partials/translations/'.$template, [ |
|
119 | 119 | 'context' => $data, |
120 | - ]); |
|
120 | + ] ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | public function renderAll() |
128 | 128 | { |
129 | 129 | $rendered = ''; |
130 | - foreach ($this->all() as $index => $entry) { |
|
130 | + foreach( $this->all() as $index => $entry ) { |
|
131 | 131 | $entry['index'] = $index; |
132 | 132 | $entry['prefix'] = OptionManager::databaseKey(); |
133 | - $rendered.= $this->render($entry['type'], $entry); |
|
133 | + $rendered .= $this->render( $entry['type'], $entry ); |
|
134 | 134 | } |
135 | 135 | return $rendered; |
136 | 136 | } |
@@ -139,25 +139,25 @@ discard block |
||
139 | 139 | * @param bool $resetAfterRender |
140 | 140 | * @return string |
141 | 141 | */ |
142 | - public function renderResults($resetAfterRender = true) |
|
142 | + public function renderResults( $resetAfterRender = true ) |
|
143 | 143 | { |
144 | 144 | $rendered = ''; |
145 | - foreach ($this->results as $id => $entry) { |
|
145 | + foreach( $this->results as $id => $entry ) { |
|
146 | 146 | $data = [ |
147 | - 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
147 | + 'desc' => $this->getEntryString( $entry, 'msgctxt' ), |
|
148 | 148 | 'id' => $id, |
149 | - 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
150 | - 's1' => $this->getEntryString($entry, 'msgid'), |
|
149 | + 'p1' => $this->getEntryString( $entry, 'msgid_plural' ), |
|
150 | + 's1' => $this->getEntryString( $entry, 'msgid' ), |
|
151 | 151 | ]; |
152 | 152 | $text = !empty($data['p1']) |
153 | - ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
153 | + ? sprintf( '%s | %s', $data['s1'], $data['p1'] ) |
|
154 | 154 | : $data['s1']; |
155 | - $rendered.= $this->render('result', [ |
|
156 | - 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
157 | - 'text' => wp_strip_all_tags($text), |
|
158 | - ]); |
|
155 | + $rendered .= $this->render( 'result', [ |
|
156 | + 'entry' => json_encode( $data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ), |
|
157 | + 'text' => wp_strip_all_tags( $text ), |
|
158 | + ] ); |
|
159 | 159 | } |
160 | - if ($resetAfterRender) { |
|
160 | + if( $resetAfterRender ) { |
|
161 | 161 | $this->reset(); |
162 | 162 | } |
163 | 163 | return $rendered; |
@@ -185,18 +185,18 @@ discard block |
||
185 | 185 | * @param string $needle |
186 | 186 | * @return static |
187 | 187 | */ |
188 | - public function search($needle = '') |
|
188 | + public function search( $needle = '' ) |
|
189 | 189 | { |
190 | 190 | $this->reset(); |
191 | - $needle = trim(strtolower($needle)); |
|
192 | - foreach ($this->entries() as $key => $entry) { |
|
193 | - $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
194 | - $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
195 | - if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
196 | - if (in_array($needle, [$single, $plural])) { |
|
191 | + $needle = trim( strtolower( $needle ) ); |
|
192 | + foreach( $this->entries() as $key => $entry ) { |
|
193 | + $single = strtolower( $this->getEntryString( $entry, 'msgid' ) ); |
|
194 | + $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) ); |
|
195 | + if( strlen( $needle ) < static::SEARCH_THRESHOLD ) { |
|
196 | + if( in_array( $needle, [$single, $plural] ) ) { |
|
197 | 197 | $this->results[$key] = $entry; |
198 | 198 | } |
199 | - } elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) { |
|
199 | + } elseif( false !== strpos( sprintf( '%s %s', $single, $plural ), $needle ) ) { |
|
200 | 200 | $this->results[$key] = $entry; |
201 | 201 | } |
202 | 202 | } |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | public function translations() |
211 | 211 | { |
212 | 212 | static $translations; |
213 | - if (empty($translations)) { |
|
214 | - $settings = glsr(OptionManager::class)->get('settings'); |
|
213 | + if( empty($translations) ) { |
|
214 | + $settings = glsr( OptionManager::class )->get( 'settings' ); |
|
215 | 215 | $translations = isset($settings['strings']) |
216 | - ? $this->normalizeSettings((array) $settings['strings']) |
|
216 | + ? $this->normalizeSettings( (array)$settings['strings'] ) |
|
217 | 217 | : []; |
218 | 218 | } |
219 | 219 | return $translations; |
@@ -223,28 +223,28 @@ discard block |
||
223 | 223 | * @param string $key |
224 | 224 | * @return string |
225 | 225 | */ |
226 | - protected function getEntryString(array $entry, $key) |
|
226 | + protected function getEntryString( array $entry, $key ) |
|
227 | 227 | { |
228 | 228 | return isset($entry[$key]) |
229 | - ? implode('', (array) $entry[$key]) |
|
229 | + ? implode( '', (array)$entry[$key] ) |
|
230 | 230 | : ''; |
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
234 | 234 | * @return array |
235 | 235 | */ |
236 | - protected function normalize(array $entries) |
|
236 | + protected function normalize( array $entries ) |
|
237 | 237 | { |
238 | 238 | $keys = [ |
239 | 239 | 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
240 | 240 | ]; |
241 | - array_walk($entries, function (&$entry) use ($keys) { |
|
242 | - foreach ($keys as $key) { |
|
241 | + array_walk( $entries, function( &$entry ) use ($keys) { |
|
242 | + foreach( $keys as $key ) { |
|
243 | 243 | try { |
244 | - $entry = $this->normalizeEntryString($entry, $key); |
|
245 | - } catch (\TypeError $error) { |
|
246 | - glsr_log()->once('error', 'Translation/normalize', $error); |
|
247 | - glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
244 | + $entry = $this->normalizeEntryString( $entry, $key ); |
|
245 | + } catch( \TypeError $error ) { |
|
246 | + glsr_log()->once( 'error', 'Translation/normalize', $error ); |
|
247 | + glsr_log()->once( 'debug', 'Translation/normalize', $entry ); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | }); |
@@ -255,10 +255,10 @@ discard block |
||
255 | 255 | * @param string $key |
256 | 256 | * @return array |
257 | 257 | */ |
258 | - protected function normalizeEntryString(array $entry, $key) |
|
258 | + protected function normalizeEntryString( array $entry, $key ) |
|
259 | 259 | { |
260 | - if (isset($entry[$key])) { |
|
261 | - $entry[$key] = $this->getEntryString($entry, $key); |
|
260 | + if( isset($entry[$key]) ) { |
|
261 | + $entry[$key] = $this->getEntryString( $entry, $key ); |
|
262 | 262 | } |
263 | 263 | return $entry; |
264 | 264 | } |
@@ -266,15 +266,15 @@ discard block |
||
266 | 266 | /** |
267 | 267 | * @return array |
268 | 268 | */ |
269 | - protected function normalizeSettings(array $strings) |
|
269 | + protected function normalizeSettings( array $strings ) |
|
270 | 270 | { |
271 | - $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
272 | - $strings = array_filter($strings, 'is_array'); |
|
273 | - foreach ($strings as &$string) { |
|
271 | + $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' ); |
|
272 | + $strings = array_filter( $strings, 'is_array' ); |
|
273 | + foreach( $strings as &$string ) { |
|
274 | 274 | $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
275 | - $string = wp_parse_args($string, $defaultString); |
|
275 | + $string = wp_parse_args( $string, $defaultString ); |
|
276 | 276 | } |
277 | - return array_filter($strings, function ($string) { |
|
277 | + return array_filter( $strings, function( $string ) { |
|
278 | 278 | return !empty($string['id']); |
279 | 279 | }); |
280 | 280 | } |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | public function __construct() |
29 | 29 | { |
30 | 30 | static::$instance = $this; |
31 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
32 | - $plugin = get_file_data($this->file, [ |
|
31 | + $this->file = realpath( trailingslashit( dirname( __DIR__ ) ).static::ID.'.php' ); |
|
32 | + $plugin = get_file_data( $this->file, [ |
|
33 | 33 | 'languages' => 'Domain Path', |
34 | 34 | 'name' => 'Plugin Name', |
35 | 35 | 'version' => 'Version', |
36 | - ], 'plugin'); |
|
37 | - array_walk($plugin, function ($value, $key) { |
|
36 | + ], 'plugin' ); |
|
37 | + array_walk( $plugin, function( $value, $key ) { |
|
38 | 38 | $this->$key = $value; |
39 | 39 | }); |
40 | 40 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function activate() |
46 | 46 | { |
47 | - $this->make(DefaultsManager::class)->set(); |
|
47 | + $this->make( DefaultsManager::class )->set(); |
|
48 | 48 | $this->scheduleCronJob(); |
49 | 49 | $this->upgrade(); |
50 | 50 | } |
@@ -55,34 +55,34 @@ discard block |
||
55 | 55 | public function catchFatalError() |
56 | 56 | { |
57 | 57 | $error = error_get_last(); |
58 | - if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
58 | + if( E_ERROR !== $error['type'] || false === strpos( $error['message'], $this->path() ) ) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | - glsr_log()->error($error['message']); |
|
61 | + glsr_log()->error( $error['message'] ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @param string $name |
66 | 66 | * @return array |
67 | 67 | */ |
68 | - public function config($name) |
|
68 | + public function config( $name ) |
|
69 | 69 | { |
70 | - $configFile = $this->path('config/'.$name.'.php'); |
|
71 | - $config = file_exists($configFile) |
|
70 | + $configFile = $this->path( 'config/'.$name.'.php' ); |
|
71 | + $config = file_exists( $configFile ) |
|
72 | 72 | ? include $configFile |
73 | 73 | : []; |
74 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
74 | + return apply_filters( 'site-reviews/config/'.$name, $config ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | 78 | * @param string $property |
79 | 79 | * @return string |
80 | 80 | */ |
81 | - public function constant($property, $className = 'static') |
|
81 | + public function constant( $property, $className = 'static' ) |
|
82 | 82 | { |
83 | 83 | $constant = $className.'::'.$property; |
84 | - return defined($constant) |
|
85 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
84 | + return defined( $constant ) |
|
85 | + ? apply_filters( 'site-reviews/const/'.$property, constant( $constant ) ) |
|
86 | 86 | : ''; |
87 | 87 | } |
88 | 88 | |
@@ -98,17 +98,17 @@ discard block |
||
98 | 98 | * @param string $view |
99 | 99 | * @return void|string |
100 | 100 | */ |
101 | - public function file($view) |
|
101 | + public function file( $view ) |
|
102 | 102 | { |
103 | - $view.= '.php'; |
|
103 | + $view .= '.php'; |
|
104 | 104 | $filePaths = []; |
105 | - if (glsr(Helper::class)->startsWith('templates/', $view)) { |
|
106 | - $filePaths[] = $this->themePath(glsr(Helper::class)->removePrefix('templates/', $view)); |
|
105 | + if( glsr( Helper::class )->startsWith( 'templates/', $view ) ) { |
|
106 | + $filePaths[] = $this->themePath( glsr( Helper::class )->removePrefix( 'templates/', $view ) ); |
|
107 | 107 | } |
108 | - $filePaths[] = $this->path($view); |
|
109 | - $filePaths[] = $this->path('views/'.$view); |
|
110 | - foreach ($filePaths as $file) { |
|
111 | - if (!file_exists($file)) { |
|
108 | + $filePaths[] = $this->path( $view ); |
|
109 | + $filePaths[] = $this->path( 'views/'.$view ); |
|
110 | + foreach( $filePaths as $file ) { |
|
111 | + if( !file_exists( $file ) ) { |
|
112 | 112 | continue; |
113 | 113 | } |
114 | 114 | return $file; |
@@ -120,32 +120,32 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function getDefaults() |
122 | 122 | { |
123 | - if (empty($this->defaults)) { |
|
124 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
123 | + if( empty($this->defaults) ) { |
|
124 | + $this->defaults = $this->make( DefaultsManager::class )->get(); |
|
125 | 125 | $this->upgrade(); |
126 | 126 | } |
127 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
127 | + return apply_filters( 'site-reviews/get/defaults', $this->defaults ); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @return bool |
132 | 132 | */ |
133 | - public function getPermission($page = '') |
|
133 | + public function getPermission( $page = '' ) |
|
134 | 134 | { |
135 | 135 | $permissions = [ |
136 | 136 | 'addons' => 'install_plugins', |
137 | 137 | 'settings' => 'manage_options', |
138 | 138 | ]; |
139 | - return glsr_get($permissions, $page, $this->constant('CAPABILITY')); |
|
139 | + return glsr_get( $permissions, $page, $this->constant( 'CAPABILITY' ) ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | 143 | * @return bool |
144 | 144 | */ |
145 | - public function hasPermission($page = '') |
|
145 | + public function hasPermission( $page = '' ) |
|
146 | 146 | { |
147 | 147 | $isAdmin = $this->isAdmin(); |
148 | - return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
148 | + return !$isAdmin || ($isAdmin && current_user_can( $this->getPermission( $page ) )); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function init() |
155 | 155 | { |
156 | - $this->make(Actions::class)->run(); |
|
157 | - $this->make(Filters::class)->run(); |
|
156 | + $this->make( Actions::class )->run(); |
|
157 | + $this->make( Filters::class )->run(); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | * @param string $file |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function path($file = '', $realpath = true) |
|
172 | + public function path( $file = '', $realpath = true ) |
|
173 | 173 | { |
174 | - $path = plugin_dir_path($this->file); |
|
175 | - if (!$realpath) { |
|
176 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
174 | + $path = plugin_dir_path( $this->file ); |
|
175 | + if( !$realpath ) { |
|
176 | + $path = trailingslashit( WP_PLUGIN_DIR ).basename( dirname( $this->file ) ); |
|
177 | 177 | } |
178 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
179 | - return apply_filters('site-reviews/path', $path, $file); |
|
178 | + $path = trailingslashit( $path ).ltrim( trim( $file ), '/' ); |
|
179 | + return apply_filters( 'site-reviews/path', $path, $file ); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function registerAddons() |
186 | 186 | { |
187 | - do_action('site-reviews/addon/register', $this); |
|
187 | + do_action( 'site-reviews/addon/register', $this ); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public function registerLanguages() |
194 | 194 | { |
195 | - load_plugin_textdomain(static::ID, false, |
|
196 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
195 | + load_plugin_textdomain( static::ID, false, |
|
196 | + trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages ) |
|
197 | 197 | ); |
198 | 198 | } |
199 | 199 | |
@@ -202,26 +202,26 @@ discard block |
||
202 | 202 | */ |
203 | 203 | public function registerReviewTypes() |
204 | 204 | { |
205 | - $types = apply_filters('site-reviews/addon/types', []); |
|
206 | - $this->reviewTypes = wp_parse_args($types, [ |
|
207 | - 'local' => __('Local', 'site-reviews'), |
|
208 | - ]); |
|
205 | + $types = apply_filters( 'site-reviews/addon/types', [] ); |
|
206 | + $this->reviewTypes = wp_parse_args( $types, [ |
|
207 | + 'local' => __( 'Local', 'site-reviews' ), |
|
208 | + ] ); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | 212 | * @param string $view |
213 | 213 | * @return void |
214 | 214 | */ |
215 | - public function render($view, array $data = []) |
|
215 | + public function render( $view, array $data = [] ) |
|
216 | 216 | { |
217 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
218 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
219 | - if (!file_exists($file)) { |
|
220 | - glsr_log()->error('File not found: '.$file); |
|
217 | + $view = apply_filters( 'site-reviews/render/view', $view, $data ); |
|
218 | + $file = apply_filters( 'site-reviews/views/file', $this->file( $view ), $view, $data ); |
|
219 | + if( !file_exists( $file ) ) { |
|
220 | + glsr_log()->error( 'File not found: '.$file ); |
|
221 | 221 | return; |
222 | 222 | } |
223 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
224 | - extract($data); |
|
223 | + $data = apply_filters( 'site-reviews/views/data', $data, $view ); |
|
224 | + extract( $data ); |
|
225 | 225 | include $file; |
226 | 226 | } |
227 | 227 | |
@@ -230,19 +230,19 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public function scheduleCronJob() |
232 | 232 | { |
233 | - if (wp_next_scheduled(static::CRON_EVENT)) { |
|
233 | + if( wp_next_scheduled( static::CRON_EVENT ) ) { |
|
234 | 234 | return; |
235 | 235 | } |
236 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
236 | + wp_schedule_event( time(), 'twicedaily', static::CRON_EVENT ); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
240 | 240 | * @param string $file |
241 | 241 | * @return string |
242 | 242 | */ |
243 | - public function themePath($file = '') |
|
243 | + public function themePath( $file = '' ) |
|
244 | 244 | { |
245 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
245 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim( trim( $file ), '/' ); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | */ |
251 | 251 | public function unscheduleCronJob() |
252 | 252 | { |
253 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
253 | + wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT ) ), static::CRON_EVENT ); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function upgrade() |
260 | 260 | { |
261 | - $this->make(Upgrader::class)->run(); |
|
261 | + $this->make( Upgrader::class )->run(); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | * @return void |
267 | 267 | * @action upgrader_process_complete |
268 | 268 | */ |
269 | - public function upgraded($upgrader, array $data) |
|
269 | + public function upgraded( $upgrader, array $data ) |
|
270 | 270 | { |
271 | - if (array_key_exists('plugins', $data) |
|
272 | - && in_array(plugin_basename($this->file), $data['plugins']) |
|
271 | + if( array_key_exists( 'plugins', $data ) |
|
272 | + && in_array( plugin_basename( $this->file ), $data['plugins'] ) |
|
273 | 273 | && 'update' === $data['action'] |
274 | 274 | && 'plugin' === $data['type'] |
275 | 275 | ) { |
@@ -281,9 +281,9 @@ discard block |
||
281 | 281 | * @param string $path |
282 | 282 | * @return string |
283 | 283 | */ |
284 | - public function url($path = '') |
|
284 | + public function url( $path = '' ) |
|
285 | 285 | { |
286 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
287 | - return apply_filters('site-reviews/url', $url, $path); |
|
286 | + $url = esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' ) ); |
|
287 | + return apply_filters( 'site-reviews/url', $url, $path ); |
|
288 | 288 | } |
289 | 289 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function enqueueAssets() |
28 | 28 | { |
29 | - if (apply_filters('site-reviews/assets/css', true)) { |
|
29 | + if( apply_filters( 'site-reviews/assets/css', true ) ) { |
|
30 | 30 | wp_enqueue_style( |
31 | 31 | Application::ID, |
32 | 32 | $this->getStylesheet(), |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | glsr()->version |
35 | 35 | ); |
36 | 36 | } |
37 | - if (apply_filters('site-reviews/assets/js', true)) { |
|
38 | - $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
37 | + if( apply_filters( 'site-reviews/assets/js', true ) ) { |
|
38 | + $dependencies = apply_filters( 'site-reviews/assets/polyfill', true ) |
|
39 | 39 | ? [Application::ID.'/polyfill'] |
40 | 40 | : []; |
41 | - $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
41 | + $dependencies = apply_filters( 'site-reviews/enqueue/public/dependencies', $dependencies ); |
|
42 | 42 | wp_enqueue_script( |
43 | 43 | Application::ID, |
44 | - glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
44 | + glsr()->url( 'assets/scripts/'.Application::ID.'.js' ), |
|
45 | 45 | $dependencies, |
46 | 46 | glsr()->version, |
47 | 47 | true |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function enqueuePolyfillService() |
56 | 56 | { |
57 | - if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
57 | + if( !apply_filters( 'site-reviews/assets/polyfill', true ) ) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | - wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
60 | + wp_enqueue_script( Application::ID.'/polyfill', add_query_arg( [ |
|
61 | 61 | 'features' => 'CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
62 | 62 | 'flags' => 'gated', |
63 | - ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
63 | + ], 'https://polyfill.io/v3/polyfill.min.js' ) ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | // wpforms-recaptcha |
72 | 72 | // google-recaptcha |
73 | 73 | // nf-google-recaptcha |
74 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
74 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | - $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
78 | - wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
77 | + $language = apply_filters( 'site-reviews/recaptcha/language', get_locale() ); |
|
78 | + wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg( [ |
|
79 | 79 | 'hl' => $language, |
80 | 80 | 'render' => 'explicit', |
81 | - ], 'https://www.google.com/recaptcha/api.js')); |
|
81 | + ], 'https://www.google.com/recaptcha/api.js' ) ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | $variables = [ |
90 | 90 | 'action' => Application::PREFIX.'action', |
91 | 91 | 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
92 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
92 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
93 | 93 | 'nameprefix' => Application::ID, |
94 | - 'validationconfig' => glsr(Style::class)->validation, |
|
95 | - 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
94 | + 'validationconfig' => glsr( Style::class )->validation, |
|
95 | + 'validationstrings' => glsr( ValidationStringsDefaults::class )->defaults(), |
|
96 | 96 | ]; |
97 | - $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
98 | - wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
97 | + $variables = apply_filters( 'site-reviews/enqueue/public/localize', $variables ); |
|
98 | + wp_add_inline_script( Application::ID, $this->buildInlineScript( $variables ), 'before' ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,35 +103,35 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function inlineStyles() |
105 | 105 | { |
106 | - $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
107 | - if (!apply_filters('site-reviews/assets/css', true)) { |
|
106 | + $inlineStylesheetPath = glsr()->path( 'assets/styles/inline-styles.css' ); |
|
107 | + if( !apply_filters( 'site-reviews/assets/css', true ) ) { |
|
108 | 108 | return; |
109 | 109 | } |
110 | - if (!file_exists($inlineStylesheetPath)) { |
|
111 | - glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
110 | + if( !file_exists( $inlineStylesheetPath ) ) { |
|
111 | + glsr_log()->error( 'Inline stylesheet is missing: '.$inlineStylesheetPath ); |
|
112 | 112 | return; |
113 | 113 | } |
114 | - $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
114 | + $inlineStylesheetValues = glsr()->config( 'inline-styles' ); |
|
115 | 115 | $stylesheet = str_replace( |
116 | - array_keys($inlineStylesheetValues), |
|
117 | - array_values($inlineStylesheetValues), |
|
118 | - file_get_contents($inlineStylesheetPath) |
|
116 | + array_keys( $inlineStylesheetValues ), |
|
117 | + array_values( $inlineStylesheetValues ), |
|
118 | + file_get_contents( $inlineStylesheetPath ) |
|
119 | 119 | ); |
120 | - wp_add_inline_style(Application::ID, $stylesheet); |
|
120 | + wp_add_inline_style( Application::ID, $stylesheet ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | 124 | * @return string |
125 | 125 | */ |
126 | - protected function buildInlineScript(array $variables) |
|
126 | + protected function buildInlineScript( array $variables ) |
|
127 | 127 | { |
128 | 128 | $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
129 | - foreach ($variables as $key => $value) { |
|
130 | - $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
129 | + foreach( $variables as $key => $value ) { |
|
130 | + $script .= sprintf( 'GLSR.%s=%s;', $key, json_encode( $value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ); |
|
131 | 131 | } |
132 | 132 | $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
133 | - $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
134 | - return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
133 | + $optimizedScript = preg_replace( $pattern, '$1$2', $script ); |
|
134 | + return apply_filters( 'site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables ); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | protected function getFixedSelectorsForPagination() |
141 | 141 | { |
142 | 142 | $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
143 | - return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
143 | + return apply_filters( 'site-reviews/enqueue/public/localize/ajax-pagination', $selectors ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | */ |
149 | 149 | protected function getStylesheet() |
150 | 150 | { |
151 | - $currentStyle = glsr(Style::class)->style; |
|
152 | - return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
153 | - ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
154 | - : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
151 | + $currentStyle = glsr( Style::class )->style; |
|
152 | + return file_exists( glsr()->path( 'assets/styles/custom/'.$currentStyle.'.css' ) ) |
|
153 | + ? glsr()->url( 'assets/styles/custom/'.$currentStyle.'.css' ) |
|
154 | + : glsr()->url( 'assets/styles/'.Application::ID.'.css' ); |
|
155 | 155 | } |
156 | 156 | } |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -defined('WPINC') || die; |
|
3 | +defined( 'WPINC' ) || die; |
|
4 | 4 | |
5 | 5 | require_once ABSPATH.WPINC.'/class-phpass.php'; |
6 | 6 | |
7 | -spl_autoload_register(function ($className) { |
|
7 | +spl_autoload_register( function( $className ) { |
|
8 | 8 | $namespaces = [ |
9 | 9 | 'GeminiLabs\\SiteReviews\\' => __DIR__.'/plugin/', |
10 | 10 | 'GeminiLabs\\SiteReviews\\Tests\\' => __DIR__.'/tests/', |
@@ -12,13 +12,13 @@ discard block |
||
12 | 12 | 'GeminiLabs\\Sinergi\\BrowserDetector\\' => __DIR__.'/vendors/sinergi/browser-detector/', |
13 | 13 | 'GeminiLabs\\Vectorface\\Whip\\' => __DIR__.'/vendors/vectorface/whip/', |
14 | 14 | ]; |
15 | - foreach ($namespaces as $prefix => $baseDir) { |
|
16 | - $len = strlen($prefix); |
|
17 | - if (0 !== strncmp($prefix, $className, $len)) { |
|
15 | + foreach( $namespaces as $prefix => $baseDir ) { |
|
16 | + $len = strlen( $prefix ); |
|
17 | + if( 0 !== strncmp( $prefix, $className, $len ) ) { |
|
18 | 18 | continue; |
19 | 19 | } |
20 | - $file = $baseDir.str_replace('\\', '/', substr($className, $len)).'.php'; |
|
21 | - if (!file_exists($file)) { |
|
20 | + $file = $baseDir.str_replace( '\\', '/', substr( $className, $len ) ).'.php'; |
|
21 | + if( !file_exists( $file ) ) { |
|
22 | 22 | continue; |
23 | 23 | } |
24 | 24 | require $file; |