@@ -1,4 +1,4 @@ |
||
| 1 | -<?php defined('WPINC') || die; ?> |
|
| 1 | +<?php defined( 'WPINC' ) || die; ?> |
|
| 2 | 2 | |
| 3 | 3 | <button type="submit" class="glsr-button et_pb_contact_submit et_pb_button"> |
| 4 | 4 | <span class="glsr-button-loading"></span> |
@@ -328,7 +328,8 @@ |
||
| 328 | 328 | } |
| 329 | 329 | if (is_array($params[0])) { |
| 330 | 330 | $this->args += $params[0]; |
| 331 | - } elseif (is_array($params[1])) { |
|
| 331 | + } |
|
| 332 | + elseif (is_array($params[1])) { |
|
| 332 | 333 | $this->args += $params[1]; |
| 333 | 334 | } |
| 334 | 335 | if (!isset($this->args['is_public'])) { |
@@ -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([ |
|
| 275 | - 'selected' => $this->args['value'] === (string) $key, |
|
| 273 | + return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) { |
|
| 274 | + return $carry.$this->option( [ |
|
| 275 | + 'selected' => $this->args['value'] === (string)$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 = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields'); |
|
| 305 | - return apply_filters('site-reviews/builder/field/'.$this->tag, $classname); |
|
| 304 | + $classname = Helper::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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -27,7 +27,8 @@ |
||
| 27 | 27 | } |
| 28 | 28 | if ('post_id' == $attributes['assigned_to']) { |
| 29 | 29 | $attributes['assigned_to'] = $attributes['post_id']; |
| 30 | - } elseif ('parent_id' == $attributes['assigned_to']) { |
|
| 30 | + } |
|
| 31 | + elseif ('parent_id' == $attributes['assigned_to']) { |
|
| 31 | 32 | $attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']); |
| 32 | 33 | } |
| 33 | 34 | return $attributes; |
@@ -62,21 +62,21 @@ discard block |
||
| 62 | 62 | /** |
| 63 | 63 | * @return string |
| 64 | 64 | */ |
| 65 | - public function render(array $attributes) |
|
| 65 | + public function render( array $attributes ) |
|
| 66 | 66 | { |
| 67 | 67 | $attributes['class'] = $attributes['className']; |
| 68 | - $shortcode = glsr(Shortcode::class); |
|
| 69 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
| 70 | - $attributes = $this->normalize($attributes); |
|
| 68 | + $shortcode = glsr( Shortcode::class ); |
|
| 69 | + if( 'edit' == filter_input( INPUT_GET, 'context' ) ) { |
|
| 70 | + $attributes = $this->normalize( $attributes ); |
|
| 71 | 71 | $this->filterReviewLinks(); |
| 72 | 72 | $this->filterShortcodeClass(); |
| 73 | - $this->filterShowMoreLinks('content'); |
|
| 74 | - $this->filterShowMoreLinks('response'); |
|
| 75 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
| 73 | + $this->filterShowMoreLinks( 'content' ); |
|
| 74 | + $this->filterShowMoreLinks( 'response' ); |
|
| 75 | + if( !$this->hasVisibleFields( $shortcode, $attributes ) ) { |
|
| 76 | 76 | $this->filterInterpolation(); |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | - return $shortcode->buildShortcode($attributes); |
|
| 79 | + return $shortcode->buildShortcode( $attributes ); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | protected function filterInterpolation() |
| 86 | 86 | { |
| 87 | - add_filter('site-reviews/interpolate/reviews', function ($context) { |
|
| 87 | + add_filter( 'site-reviews/interpolate/reviews', function( $context ) { |
|
| 88 | 88 | $context['class'] = 'glsr-default glsr-block-disabled'; |
| 89 | - $context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
| 89 | + $context['reviews'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' ); |
|
| 90 | 90 | return $context; |
| 91 | 91 | }); |
| 92 | 92 | } |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | protected function filterReviewLinks() |
| 98 | 98 | { |
| 99 | - add_filter('site-reviews/rendered/template/reviews', function ($template) { |
|
| 100 | - return str_replace('<a', '<a tabindex="-1"', $template); |
|
| 99 | + add_filter( 'site-reviews/rendered/template/reviews', function( $template ) { |
|
| 100 | + return str_replace( '<a', '<a tabindex="-1"', $template ); |
|
| 101 | 101 | }); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | protected function filterShortcodeClass() |
| 108 | 108 | { |
| 109 | - add_filter('site-reviews/style', function () { |
|
| 109 | + add_filter( 'site-reviews/style', function() { |
|
| 110 | 110 | return 'default'; |
| 111 | 111 | }); |
| 112 | 112 | } |
@@ -115,12 +115,12 @@ discard block |
||
| 115 | 115 | * @param string $field |
| 116 | 116 | * @return void |
| 117 | 117 | */ |
| 118 | - protected function filterShowMoreLinks($field) |
|
| 118 | + protected function filterShowMoreLinks( $field ) |
|
| 119 | 119 | { |
| 120 | - add_filter('site-reviews/review/wrap/'.$field, function ($value) { |
|
| 120 | + add_filter( 'site-reviews/review/wrap/'.$field, function( $value ) { |
|
| 121 | 121 | $value = preg_replace( |
| 122 | 122 | '/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/s', |
| 123 | - '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5', |
|
| 123 | + '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__( 'Show more', 'site-reviews' ).'</a>$5', |
|
| 124 | 124 | $value |
| 125 | 125 | ); |
| 126 | 126 | return $value; |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | { |
| 7 | 7 | public $widgets; |
| 8 | 8 | |
| 9 | - public function __construct($input) |
|
| 9 | + public function __construct( $input ) |
|
| 10 | 10 | { |
| 11 | 11 | $this->widgets = $input; |
| 12 | 12 | } |
@@ -40,20 +40,20 @@ discard block |
||
| 40 | 40 | /** |
| 41 | 41 | * @return void|string |
| 42 | 42 | */ |
| 43 | - public function build(array $args = []) |
|
| 43 | + public function build( array $args = [] ) |
|
| 44 | 44 | { |
| 45 | 45 | $this->args = $args; |
| 46 | - if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
| 46 | + if( !is_user_logged_in() && glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) { |
|
| 47 | 47 | return $this->buildLoginRegister(); |
| 48 | 48 | } |
| 49 | - $this->errors = glsr()->sessionGet($args['id'].'errors', []); |
|
| 50 | - $this->message = glsr()->sessionGet($args['id'].'message', ''); |
|
| 51 | - $this->required = glsr(OptionManager::class)->get('settings.submissions.required', []); |
|
| 52 | - $this->values = glsr()->sessionGet($args['id'].'values', []); |
|
| 53 | - $fields = array_reduce($this->getFields(), function ($carry, $field) { |
|
| 49 | + $this->errors = glsr()->sessionGet( $args['id'].'errors', [] ); |
|
| 50 | + $this->message = glsr()->sessionGet( $args['id'].'message', '' ); |
|
| 51 | + $this->required = glsr( OptionManager::class )->get( 'settings.submissions.required', [] ); |
|
| 52 | + $this->values = glsr()->sessionGet( $args['id'].'values', [] ); |
|
| 53 | + $fields = array_reduce( $this->getFields(), function( $carry, $field ) { |
|
| 54 | 54 | return $carry.$field; |
| 55 | 55 | }); |
| 56 | - return glsr(Template::class)->build('templates/reviews-form', [ |
|
| 56 | + return glsr( Template::class )->build( 'templates/reviews-form', [ |
|
| 57 | 57 | 'args' => $args, |
| 58 | 58 | 'context' => [ |
| 59 | 59 | 'class' => $this->getClass(), |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | 'response' => $this->buildResponse(), |
| 63 | 63 | 'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(), |
| 64 | 64 | ], |
| 65 | - ]); |
|
| 65 | + ] ); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | protected function buildLoginRegister() |
| 72 | 72 | { |
| 73 | - return glsr(Template::class)->build('templates/login-register', [ |
|
| 73 | + return glsr( Template::class )->build( 'templates/login-register', [ |
|
| 74 | 74 | 'context' => [ |
| 75 | - 'text' => trim($this->getLoginText().' '.$this->getRegisterText()), |
|
| 75 | + 'text' => trim( $this->getLoginText().' '.$this->getRegisterText() ), |
|
| 76 | 76 | ], |
| 77 | - ]); |
|
| 77 | + ] ); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -82,15 +82,15 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | protected function buildRecaptcha() |
| 84 | 84 | { |
| 85 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
| 85 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
| 86 | 86 | return; |
| 87 | 87 | } |
| 88 | - return glsr(Builder::class)->div([ |
|
| 88 | + return glsr( Builder::class )->div( [ |
|
| 89 | 89 | 'class' => 'glsr-recaptcha-holder', |
| 90 | - 'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'), |
|
| 91 | - 'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')), |
|
| 90 | + 'data-badge' => glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.position' ), |
|
| 91 | + 'data-sitekey' => sanitize_text_field( glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.key' ) ), |
|
| 92 | 92 | 'data-size' => 'invisible', |
| 93 | - ]); |
|
| 93 | + ] ); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -99,15 +99,15 @@ discard block |
||
| 99 | 99 | protected function buildResponse() |
| 100 | 100 | { |
| 101 | 101 | $classes = !empty($this->errors) |
| 102 | - ? glsr(StyleValidationDefaults::class)->defaults()['message_error_class'] |
|
| 102 | + ? glsr( StyleValidationDefaults::class )->defaults()['message_error_class'] |
|
| 103 | 103 | : ''; |
| 104 | - return glsr(Template::class)->build('templates/form/response', [ |
|
| 104 | + return glsr( Template::class )->build( 'templates/form/response', [ |
|
| 105 | 105 | 'context' => [ |
| 106 | 106 | 'class' => $classes, |
| 107 | - 'message' => wpautop($this->message), |
|
| 107 | + 'message' => wpautop( $this->message ), |
|
| 108 | 108 | ], |
| 109 | 109 | 'has_errors' => !empty($this->errors), |
| 110 | - ]); |
|
| 110 | + ] ); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -115,11 +115,11 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | protected function buildSubmitButton() |
| 117 | 117 | { |
| 118 | - return glsr(Template::class)->build('templates/form/submit-button', [ |
|
| 118 | + return glsr( Template::class )->build( 'templates/form/submit-button', [ |
|
| 119 | 119 | 'context' => [ |
| 120 | - 'text' => __('Submit your review', 'site-reviews'), |
|
| 120 | + 'text' => __( 'Submit your review', 'site-reviews' ), |
|
| 121 | 121 | ], |
| 122 | - ]); |
|
| 122 | + ] ); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | protected function getClass() |
| 129 | 129 | { |
| 130 | - return trim('glsr-form glsr-'.glsr(Style::class)->get().' '.$this->args['class']); |
|
| 130 | + return trim( 'glsr-form glsr-'.glsr( Style::class )->get().' '.$this->args['class'] ); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -137,18 +137,18 @@ discard block |
||
| 137 | 137 | { |
| 138 | 138 | $hiddenFields = $this->getHiddenFields(); |
| 139 | 139 | $hiddenFields[] = $this->getHoneypotField(); |
| 140 | - $fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form')); |
|
| 141 | - $paths = array_map(function ($obj) { |
|
| 140 | + $fields = $this->normalizeFields( glsr( Form::class )->getFields( 'submission-form' ) ); |
|
| 141 | + $paths = array_map( function( $obj ) { |
|
| 142 | 142 | return $obj->field['path']; |
| 143 | - }, $hiddenFields); |
|
| 144 | - foreach ($fields as $field) { |
|
| 145 | - $index = array_search($field->field['path'], $paths); |
|
| 146 | - if (false === $index) { |
|
| 143 | + }, $hiddenFields ); |
|
| 144 | + foreach( $fields as $field ) { |
|
| 145 | + $index = array_search( $field->field['path'], $paths ); |
|
| 146 | + if( false === $index ) { |
|
| 147 | 147 | continue; |
| 148 | 148 | } |
| 149 | 149 | unset($hiddenFields[$index]); |
| 150 | 150 | } |
| 151 | - return array_merge($hiddenFields, $fields); |
|
| 151 | + return array_merge( $hiddenFields, $fields ); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -156,11 +156,11 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | protected function getLoginText() |
| 158 | 158 | { |
| 159 | - $loginLink = glsr(Builder::class)->a([ |
|
| 160 | - 'href' => wp_login_url(strval(get_permalink())), |
|
| 161 | - 'text' => __('logged in', 'site-reviews'), |
|
| 162 | - ]); |
|
| 163 | - return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink); |
|
| 159 | + $loginLink = glsr( Builder::class )->a( [ |
|
| 160 | + 'href' => wp_login_url( strval( get_permalink() ) ), |
|
| 161 | + 'text' => __( 'logged in', 'site-reviews' ), |
|
| 162 | + ] ); |
|
| 163 | + return sprintf( __( 'You must be %s to submit a review.', 'site-reviews' ), $loginLink ); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -168,14 +168,14 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | protected function getRegisterText() |
| 170 | 170 | { |
| 171 | - if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
| 171 | + if( !get_option( 'users_can_register' ) || !glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) { |
|
| 172 | 172 | return; |
| 173 | 173 | } |
| 174 | - $registerLink = glsr(Builder::class)->a([ |
|
| 174 | + $registerLink = glsr( Builder::class )->a( [ |
|
| 175 | 175 | 'href' => wp_registration_url(), |
| 176 | - 'text' => __('register', 'site-reviews'), |
|
| 177 | - ]); |
|
| 178 | - return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink); |
|
| 176 | + 'text' => __( 'register', 'site-reviews' ), |
|
| 177 | + ] ); |
|
| 178 | + return sprintf( __( 'You may also %s for an account.', 'site-reviews' ), $registerLink ); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -190,13 +190,13 @@ discard block |
||
| 190 | 190 | 'name' => '_counter', |
| 191 | 191 | ], [ |
| 192 | 192 | 'name' => '_nonce', |
| 193 | - 'value' => wp_create_nonce('submit-review'), |
|
| 193 | + 'value' => wp_create_nonce( 'submit-review' ), |
|
| 194 | 194 | ], [ |
| 195 | 195 | 'name' => '_post_id', |
| 196 | 196 | 'value' => get_the_ID(), |
| 197 | 197 | ], [ |
| 198 | 198 | 'name' => '_referer', |
| 199 | - 'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')), |
|
| 199 | + 'value' => wp_unslash( filter_input( INPUT_SERVER, 'REQUEST_URI' ) ), |
|
| 200 | 200 | ], [ |
| 201 | 201 | 'name' => 'assign_to', |
| 202 | 202 | 'value' => $this->args['assign_to'], |
@@ -210,9 +210,9 @@ discard block |
||
| 210 | 210 | 'name' => 'form_id', |
| 211 | 211 | 'value' => $this->args['id'], |
| 212 | 212 | ]]; |
| 213 | - return array_map(function ($field) { |
|
| 214 | - return new Field(wp_parse_args($field, ['type' => 'hidden'])); |
|
| 215 | - }, $fields); |
|
| 213 | + return array_map( function( $field ) { |
|
| 214 | + return new Field( wp_parse_args( $field, ['type' => 'hidden'] ) ); |
|
| 215 | + }, $fields ); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -220,40 +220,40 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | protected function getHoneypotField() |
| 222 | 222 | { |
| 223 | - return new Field([ |
|
| 223 | + return new Field( [ |
|
| 224 | 224 | 'name' => 'gotcha', |
| 225 | 225 | 'type' => 'honeypot', |
| 226 | - ]); |
|
| 226 | + ] ); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | 230 | * @return void |
| 231 | 231 | */ |
| 232 | - protected function normalizeFieldId(Field &$field) |
|
| 232 | + protected function normalizeFieldId( Field &$field ) |
|
| 233 | 233 | { |
| 234 | - if (empty($this->args['id']) || empty($field->field['id'])) { |
|
| 234 | + if( empty($this->args['id']) || empty($field->field['id']) ) { |
|
| 235 | 235 | return; |
| 236 | 236 | } |
| 237 | - $field->field['id'].= '-'.$this->args['id']; |
|
| 237 | + $field->field['id'] .= '-'.$this->args['id']; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
| 241 | 241 | * @return void |
| 242 | 242 | */ |
| 243 | - protected function normalizeFieldClass(Field &$field) |
|
| 243 | + protected function normalizeFieldClass( Field &$field ) |
|
| 244 | 244 | { |
| 245 | - if (!isset($field->field['class'])) { |
|
| 245 | + if( !isset($field->field['class']) ) { |
|
| 246 | 246 | $field->field['class'] = ''; |
| 247 | 247 | } |
| 248 | - $field->field['class'] = trim($field->field['class'].' glsr-field-control'); |
|
| 248 | + $field->field['class'] = trim( $field->field['class'].' glsr-field-control' ); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
| 252 | 252 | * @return void |
| 253 | 253 | */ |
| 254 | - protected function normalizeFieldErrors(Field &$field) |
|
| 254 | + protected function normalizeFieldErrors( Field &$field ) |
|
| 255 | 255 | { |
| 256 | - if (!array_key_exists($field->field['path'], $this->errors)) { |
|
| 256 | + if( !array_key_exists( $field->field['path'], $this->errors ) ) { |
|
| 257 | 257 | return; |
| 258 | 258 | } |
| 259 | 259 | $field->field['errors'] = $this->errors[$field->field['path']]; |
@@ -262,9 +262,9 @@ discard block |
||
| 262 | 262 | /** |
| 263 | 263 | * @return void |
| 264 | 264 | */ |
| 265 | - protected function normalizeFieldRequired(Field &$field) |
|
| 265 | + protected function normalizeFieldRequired( Field &$field ) |
|
| 266 | 266 | { |
| 267 | - if (!in_array($field->field['path'], $this->required)) { |
|
| 267 | + if( !in_array( $field->field['path'], $this->required ) ) { |
|
| 268 | 268 | return; |
| 269 | 269 | } |
| 270 | 270 | $field->field['required'] = true; |
@@ -273,19 +273,19 @@ discard block |
||
| 273 | 273 | /** |
| 274 | 274 | * @return array |
| 275 | 275 | */ |
| 276 | - protected function normalizeFields($fields) |
|
| 276 | + protected function normalizeFields( $fields ) |
|
| 277 | 277 | { |
| 278 | 278 | $normalizedFields = []; |
| 279 | - foreach ($fields as $field) { |
|
| 280 | - if (in_array($field->field['path'], $this->args['hide'])) { |
|
| 279 | + foreach( $fields as $field ) { |
|
| 280 | + if( in_array( $field->field['path'], $this->args['hide'] ) ) { |
|
| 281 | 281 | continue; |
| 282 | 282 | } |
| 283 | 283 | $field->field['is_public'] = true; |
| 284 | - $this->normalizeFieldClass($field); |
|
| 285 | - $this->normalizeFieldErrors($field); |
|
| 286 | - $this->normalizeFieldRequired($field); |
|
| 287 | - $this->normalizeFieldValue($field); |
|
| 288 | - $this->normalizeFieldId($field); |
|
| 284 | + $this->normalizeFieldClass( $field ); |
|
| 285 | + $this->normalizeFieldErrors( $field ); |
|
| 286 | + $this->normalizeFieldRequired( $field ); |
|
| 287 | + $this->normalizeFieldValue( $field ); |
|
| 288 | + $this->normalizeFieldId( $field ); |
|
| 289 | 289 | $normalizedFields[] = $field; |
| 290 | 290 | } |
| 291 | 291 | return $normalizedFields; |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | /** |
| 295 | 295 | * @return void |
| 296 | 296 | */ |
| 297 | - protected function normalizeFieldValue(Field &$field) |
|
| 297 | + protected function normalizeFieldValue( Field &$field ) |
|
| 298 | 298 | { |
| 299 | - if (!array_key_exists($field->field['path'], $this->values)) { |
|
| 299 | + if( !array_key_exists( $field->field['path'], $this->values ) ) { |
|
| 300 | 300 | return; |
| 301 | 301 | } |
| 302 | - if (in_array($field->field['type'], ['radio', 'checkbox'])) { |
|
| 302 | + if( in_array( $field->field['type'], ['radio', 'checkbox'] ) ) { |
|
| 303 | 303 | $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
| 304 | 304 | } else { |
| 305 | 305 | $field->field['value'] = $this->values[$field->field['path']]; |
@@ -64,7 +64,8 @@ |
||
| 64 | 64 | if ($flattenValue) { |
| 65 | 65 | $value = '['.implode(', ', $value).']'; |
| 66 | 66 | } |
| 67 | - } elseif (is_array($value)) { |
|
| 67 | + } |
|
| 68 | + elseif (is_array($value)) { |
|
| 68 | 69 | $result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey)); |
| 69 | 70 | continue; |
| 70 | 71 | } |
@@ -7,10 +7,10 @@ discard block |
||
| 7 | 7 | /** |
| 8 | 8 | * @return bool |
| 9 | 9 | */ |
| 10 | - public static function compareArrays(array $arr1, array $arr2) |
|
| 10 | + public static function compareArrays( array $arr1, array $arr2 ) |
|
| 11 | 11 | { |
| 12 | - sort($arr1); |
|
| 13 | - sort($arr2); |
|
| 12 | + sort( $arr1 ); |
|
| 13 | + sort( $arr2 ); |
|
| 14 | 14 | return $arr1 == $arr2; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -18,21 +18,21 @@ discard block |
||
| 18 | 18 | * @param mixed $array |
| 19 | 19 | * @return array |
| 20 | 20 | */ |
| 21 | - public static function consolidateArray($array) |
|
| 21 | + public static function consolidateArray( $array ) |
|
| 22 | 22 | { |
| 23 | - return is_array($array) || is_object($array) |
|
| 24 | - ? (array) $array |
|
| 23 | + return is_array( $array ) || is_object( $array ) |
|
| 24 | + ? (array)$array |
|
| 25 | 25 | : []; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @return array |
| 30 | 30 | */ |
| 31 | - public static function convertDotNotationArray(array $array) |
|
| 31 | + public static function convertDotNotationArray( array $array ) |
|
| 32 | 32 | { |
| 33 | 33 | $results = []; |
| 34 | - foreach ($array as $path => $value) { |
|
| 35 | - $results = static::set($results, $path, $value); |
|
| 34 | + foreach( $array as $path => $value ) { |
|
| 35 | + $results = static::set( $results, $path, $value ); |
|
| 36 | 36 | } |
| 37 | 37 | return $results; |
| 38 | 38 | } |
@@ -42,12 +42,12 @@ discard block |
||
| 42 | 42 | * @param mixed $callback |
| 43 | 43 | * @return array |
| 44 | 44 | */ |
| 45 | - public static function convertStringToArray($string, $callback = null) |
|
| 45 | + public static function convertStringToArray( $string, $callback = null ) |
|
| 46 | 46 | { |
| 47 | - $array = array_map('trim', explode(',', $string)); |
|
| 47 | + $array = array_map( 'trim', explode( ',', $string ) ); |
|
| 48 | 48 | return $callback |
| 49 | - ? array_filter($array, $callback) |
|
| 50 | - : array_filter($array); |
|
| 49 | + ? array_filter( $array, $callback ) |
|
| 50 | + : array_filter( $array ); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -55,17 +55,17 @@ discard block |
||
| 55 | 55 | * @param string $prefix |
| 56 | 56 | * @return array |
| 57 | 57 | */ |
| 58 | - public static function flattenArray(array $array, $flattenValue = false, $prefix = '') |
|
| 58 | + public static function flattenArray( array $array, $flattenValue = false, $prefix = '' ) |
|
| 59 | 59 | { |
| 60 | 60 | $result = []; |
| 61 | - foreach ($array as $key => $value) { |
|
| 62 | - $newKey = ltrim($prefix.'.'.$key, '.'); |
|
| 63 | - if (static::isIndexedFlatArray($value)) { |
|
| 64 | - if ($flattenValue) { |
|
| 65 | - $value = '['.implode(', ', $value).']'; |
|
| 61 | + foreach( $array as $key => $value ) { |
|
| 62 | + $newKey = ltrim( $prefix.'.'.$key, '.' ); |
|
| 63 | + if( static::isIndexedFlatArray( $value ) ) { |
|
| 64 | + if( $flattenValue ) { |
|
| 65 | + $value = '['.implode( ', ', $value ).']'; |
|
| 66 | 66 | } |
| 67 | - } elseif (is_array($value)) { |
|
| 68 | - $result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey)); |
|
| 67 | + } elseif( is_array( $value ) ) { |
|
| 68 | + $result = array_merge( $result, static::flattenArray( $value, $flattenValue, $newKey ) ); |
|
| 69 | 69 | continue; |
| 70 | 70 | } |
| 71 | 71 | $result[$newKey] = $value; |
@@ -80,12 +80,12 @@ discard block |
||
| 80 | 80 | * @param mixed $fallback |
| 81 | 81 | * @return mixed |
| 82 | 82 | */ |
| 83 | - public static function get($data, $path = '', $fallback = '') |
|
| 83 | + public static function get( $data, $path = '', $fallback = '' ) |
|
| 84 | 84 | { |
| 85 | - $data = static::consolidateArray($data); |
|
| 86 | - $keys = explode('.', $path); |
|
| 87 | - foreach ($keys as $key) { |
|
| 88 | - if (!isset($data[$key])) { |
|
| 85 | + $data = static::consolidateArray( $data ); |
|
| 86 | + $keys = explode( '.', $path ); |
|
| 87 | + foreach( $keys as $key ) { |
|
| 88 | + if( !isset($data[$key]) ) { |
|
| 89 | 89 | return $fallback; |
| 90 | 90 | } |
| 91 | 91 | $data = $data[$key]; |
@@ -97,18 +97,18 @@ discard block |
||
| 97 | 97 | * @param string $key |
| 98 | 98 | * @return array |
| 99 | 99 | */ |
| 100 | - public static function insertAfter($key, array $array, array $insert) |
|
| 100 | + public static function insertAfter( $key, array $array, array $insert ) |
|
| 101 | 101 | { |
| 102 | - return static::insertInArray($array, $insert, $key, 'after'); |
|
| 102 | + return static::insertInArray( $array, $insert, $key, 'after' ); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | 106 | * @param string $key |
| 107 | 107 | * @return array |
| 108 | 108 | */ |
| 109 | - public static function insertBefore($key, array $array, array $insert) |
|
| 109 | + public static function insertBefore( $key, array $array, array $insert ) |
|
| 110 | 110 | { |
| 111 | - return static::insertInArray($array, $insert, $key, 'before'); |
|
| 111 | + return static::insertInArray( $array, $insert, $key, 'before' ); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -116,47 +116,47 @@ discard block |
||
| 116 | 116 | * @param string $position |
| 117 | 117 | * @return array |
| 118 | 118 | */ |
| 119 | - public static function insertInArray(array $array, array $insert, $key, $position = 'before') |
|
| 119 | + public static function insertInArray( array $array, array $insert, $key, $position = 'before' ) |
|
| 120 | 120 | { |
| 121 | - $keyPosition = intval(array_search($key, array_keys($array))); |
|
| 122 | - if ('after' == $position) { |
|
| 121 | + $keyPosition = intval( array_search( $key, array_keys( $array ) ) ); |
|
| 122 | + if( 'after' == $position ) { |
|
| 123 | 123 | ++$keyPosition; |
| 124 | 124 | } |
| 125 | - if (false !== $keyPosition) { |
|
| 126 | - $result = array_slice($array, 0, $keyPosition); |
|
| 127 | - $result = array_merge($result, $insert); |
|
| 128 | - return array_merge($result, array_slice($array, $keyPosition)); |
|
| 125 | + if( false !== $keyPosition ) { |
|
| 126 | + $result = array_slice( $array, 0, $keyPosition ); |
|
| 127 | + $result = array_merge( $result, $insert ); |
|
| 128 | + return array_merge( $result, array_slice( $array, $keyPosition ) ); |
|
| 129 | 129 | } |
| 130 | - return array_merge($array, $insert); |
|
| 130 | + return array_merge( $array, $insert ); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | 134 | * @param mixed $array |
| 135 | 135 | * @return bool |
| 136 | 136 | */ |
| 137 | - public static function isIndexedFlatArray($array) |
|
| 137 | + public static function isIndexedFlatArray( $array ) |
|
| 138 | 138 | { |
| 139 | - if (!is_array($array) || array_filter($array, 'is_array')) { |
|
| 139 | + if( !is_array( $array ) || array_filter( $array, 'is_array' ) ) { |
|
| 140 | 140 | return false; |
| 141 | 141 | } |
| 142 | - return wp_is_numeric_array($array); |
|
| 142 | + return wp_is_numeric_array( $array ); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | 146 | * @param bool $prefixed |
| 147 | 147 | * @return array |
| 148 | 148 | */ |
| 149 | - public static function prefixArrayKeys(array $values, $prefixed = true) |
|
| 149 | + public static function prefixArrayKeys( array $values, $prefixed = true ) |
|
| 150 | 150 | { |
| 151 | 151 | $trim = '_'; |
| 152 | 152 | $prefix = $prefixed |
| 153 | 153 | ? $trim |
| 154 | 154 | : ''; |
| 155 | 155 | $prefixed = []; |
| 156 | - foreach ($values as $key => $value) { |
|
| 157 | - $key = trim($key); |
|
| 158 | - if (0 === strpos($key, $trim)) { |
|
| 159 | - $key = substr($key, strlen($trim)); |
|
| 156 | + foreach( $values as $key => $value ) { |
|
| 157 | + $key = trim( $key ); |
|
| 158 | + if( 0 === strpos( $key, $trim ) ) { |
|
| 159 | + $key = substr( $key, strlen( $trim ) ); |
|
| 160 | 160 | } |
| 161 | 161 | $prefixed[$prefix.$key] = $value; |
| 162 | 162 | } |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | /** |
| 167 | 167 | * @return array |
| 168 | 168 | */ |
| 169 | - public static function removeEmptyArrayValues(array $array) |
|
| 169 | + public static function removeEmptyArrayValues( array $array ) |
|
| 170 | 170 | { |
| 171 | 171 | $result = []; |
| 172 | - foreach ($array as $key => $value) { |
|
| 173 | - if (!$value) { |
|
| 172 | + foreach( $array as $key => $value ) { |
|
| 173 | + if( !$value ) { |
|
| 174 | 174 | continue; |
| 175 | 175 | } |
| 176 | - $result[$key] = is_array($value) |
|
| 177 | - ? static::removeEmptyArrayValues($value) |
|
| 176 | + $result[$key] = is_array( $value ) |
|
| 177 | + ? static::removeEmptyArrayValues( $value ) |
|
| 178 | 178 | : $value; |
| 179 | 179 | } |
| 180 | 180 | return $result; |
@@ -187,14 +187,14 @@ discard block |
||
| 187 | 187 | * @param mixed $value |
| 188 | 188 | * @return array |
| 189 | 189 | */ |
| 190 | - public static function set(array $data, $path, $value) |
|
| 190 | + public static function set( array $data, $path, $value ) |
|
| 191 | 191 | { |
| 192 | - $token = strtok($path, '.'); |
|
| 192 | + $token = strtok( $path, '.' ); |
|
| 193 | 193 | $ref = &$data; |
| 194 | - while (false !== $token) { |
|
| 195 | - $ref = static::consolidateArray($ref); |
|
| 194 | + while( false !== $token ) { |
|
| 195 | + $ref = static::consolidateArray( $ref ); |
|
| 196 | 196 | $ref = &$ref[$token]; |
| 197 | - $token = strtok('.'); |
|
| 197 | + $token = strtok( '.' ); |
|
| 198 | 198 | } |
| 199 | 199 | $ref = $value; |
| 200 | 200 | return $data; |
@@ -203,16 +203,16 @@ discard block |
||
| 203 | 203 | /** |
| 204 | 204 | * @return array |
| 205 | 205 | */ |
| 206 | - public static function unique(array $values) |
|
| 206 | + public static function unique( array $values ) |
|
| 207 | 207 | { |
| 208 | - return array_filter(array_unique($values)); |
|
| 208 | + return array_filter( array_unique( $values ) ); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | 212 | * @return array |
| 213 | 213 | */ |
| 214 | - public static function unprefixArrayKeys(array $values) |
|
| 214 | + public static function unprefixArrayKeys( array $values ) |
|
| 215 | 215 | { |
| 216 | - return static::prefixArrayKeys($values, false); |
|
| 216 | + return static::prefixArrayKeys( $values, false ); |
|
| 217 | 217 | } |
| 218 | 218 | } |