Completed
Push — develop ( d5d4b9...69e663 )
by Zack
16:25
created
includes/helper-functions.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -32,19 +32,19 @@  discard block
 block discarded – undo
32 32
 	// If there's an overriding CSS file in the current template folder, use it.
33 33
 	$template_css_path = trailingslashit( get_stylesheet_directory() ) . 'gravityview/css/' . $css_file;
34 34
 
35
-	if( file_exists( $template_css_path ) ) {
35
+	if ( file_exists( $template_css_path ) ) {
36 36
 		$path = trailingslashit( get_stylesheet_directory_uri() ) . 'gravityview/css/' . $css_file;
37 37
 		gravityview()->log->debug( 'Stylesheet override ({css_file})', array( 'css_file' => esc_attr( $css_file ) ) );
38 38
 	} else {
39 39
 		// Default: use GravityView CSS file
40 40
 
41 41
 		// If no path is provided, assume default plugin templates CSS folder
42
-		if( '' === $dir_path ) {
42
+		if ( '' === $dir_path ) {
43 43
 			$dir_path = GRAVITYVIEW_DIR . 'templates/css/';
44 44
 		}
45 45
 		
46 46
 		// plugins_url() expects a path to a file, not directory. We append a file to be stripped.
47
-		$path = plugins_url( $css_file, trailingslashit( $dir_path )  . 'stripped-by-plugin_basename.php' );
47
+		$path = plugins_url( $css_file, trailingslashit( $dir_path ) . 'stripped-by-plugin_basename.php' );
48 48
 	}
49 49
 
50 50
 	return $path;
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 
83 83
 	$parsed_permalink = parse_url( get_permalink( $id ) );
84 84
 
85
-	$permalink_args =  isset( $parsed_permalink['query'] ) ? $parsed_permalink['query'] : false;
85
+	$permalink_args = isset( $parsed_permalink[ 'query' ] ) ? $parsed_permalink[ 'query' ] : false;
86 86
 
87
-	if( empty( $permalink_args ) ) {
87
+	if ( empty( $permalink_args ) ) {
88 88
 		return array();
89 89
 	}
90 90
 
@@ -109,15 +109,15 @@  discard block
 block discarded – undo
109 109
 function gv_selected( $value, $current, $echo = true, $type = 'selected' ) {
110 110
 
111 111
 	$output = '';
112
-	if( is_array( $current ) ) {
113
-		if( in_array( $value, $current ) ) {
112
+	if ( is_array( $current ) ) {
113
+		if ( in_array( $value, $current ) ) {
114 114
 			$output = __checked_selected_helper( true, true, false, $type );
115 115
 		}
116 116
 	} else {
117 117
 		$output = __checked_selected_helper( $value, $current, false, $type );
118 118
 	}
119 119
 
120
-	if( $echo ) {
120
+	if ( $echo ) {
121 121
 		echo $output;
122 122
 	}
123 123
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 }
126 126
 
127 127
 
128
-if( ! function_exists( 'gravityview_sanitize_html_class' ) ) {
128
+if ( ! function_exists( 'gravityview_sanitize_html_class' ) ) {
129 129
 
130 130
 	/**
131 131
 	 * sanitize_html_class doesn't handle spaces (multiple classes). We remedy that.
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
  */
172 172
 function gravityview_strip_whitespace( $string ) {
173 173
 	$string = normalize_whitespace( $string );
174
-	return preg_replace('/[\r\n\t ]+/', ' ', $string );
174
+	return preg_replace( '/[\r\n\t ]+/', ' ', $string );
175 175
 }
176 176
 
177 177
 /**
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
  * @return string Included file contents
186 186
  */
187 187
 function gravityview_ob_include( $file_path, $object = NULL ) {
188
-	if( ! file_exists( $file_path ) ) {
188
+	if ( ! file_exists( $file_path ) ) {
189 189
 		gravityview()->log->error( 'File path does not exist. {path}', array( 'path' => $file_path ) );
190 190
 		return '';
191 191
 	}
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 
210 210
 	$width = $height * 0.7586206897;
211 211
 
212
-	if( function_exists('is_rtl') && is_rtl() ) {
212
+	if ( function_exists( 'is_rtl' ) && is_rtl() ) {
213 213
 		$style = 'margin:10px 10px 10px 0;';
214 214
 		$css_class = is_string( $css_class ) ? $css_class : 'alignright';
215 215
 	} else {
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 		$css_class = is_string( $css_class ) ? $css_class : 'alignleft';
218 218
 	}
219 219
 
220
-	return '<img src="'. esc_url( plugins_url( 'assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE ) ) .'" class="'. gravityview_sanitize_html_class( $css_class ).'" height="'.intval( $height ).'" width="'.round( $width, 2 ).'" alt="The GravityView Astronaut Says:" style="'.$style.'" />';
220
+	return '<img src="' . esc_url( plugins_url( 'assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE ) ) . '" class="' . gravityview_sanitize_html_class( $css_class ) . '" height="' . intval( $height ) . '" width="' . round( $width, 2 ) . '" alt="The GravityView Astronaut Says:" style="' . $style . '" />';
221 221
 }
222 222
 
223 223
 /**
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
 function gravityview_number_format( $number, $decimals = '' ) {
241 241
 	global $wp_locale;
242 242
 
243
-	if( '' === $decimals ) {
243
+	if ( '' === $decimals ) {
244 244
 
245
-		$decimal_point = isset( $wp_locale ) ? $wp_locale->number_format['decimal_point'] : '.';
245
+		$decimal_point = isset( $wp_locale ) ? $wp_locale->number_format[ 'decimal_point' ] : '.';
246 246
 
247 247
 		/**
248 248
 		 * Calculate the position of the decimal point in the number
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	$parts = parse_url( $value );
272 272
 
273 273
 	// No domain? Strange...show the original text.
274
-	if( empty( $parts['host'] ) ) {
274
+	if ( empty( $parts[ 'host' ] ) ) {
275 275
 		return $value;
276 276
 	}
277 277
 
@@ -284,16 +284,16 @@  discard block
 block discarded – undo
284 284
 	 * @param boolean $enable Whether to strip the scheme. Return false to show scheme. (default: true)\n
285 285
 	 * If true: `http://example.com => example.com`
286 286
 	 */
287
-	if( false === apply_filters('gravityview_anchor_text_striphttp', true) ) {
287
+	if ( false === apply_filters( 'gravityview_anchor_text_striphttp', true ) ) {
288 288
 
289
-		if( isset( $parts['scheme'] ) ) {
290
-			$return .= $parts['scheme'];
289
+		if ( isset( $parts[ 'scheme' ] ) ) {
290
+			$return .= $parts[ 'scheme' ];
291 291
 		}
292 292
 
293 293
 	}
294 294
 
295 295
 	// The domain, which may contain a subdomain
296
-	$domain = $parts['host'];
296
+	$domain = $parts[ 'host' ];
297 297
 
298 298
 	/**
299 299
 	 * @filter `gravityview_anchor_text_stripwww` Strip www from the domain?
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
 	 * @param boolean $enable Whether to strip www. Return false to show www. (default: true)\n
302 302
 	 * If true: `www.example.com => example.com`
303 303
 	 */
304
-	$strip_www = apply_filters('gravityview_anchor_text_stripwww', true );
304
+	$strip_www = apply_filters( 'gravityview_anchor_text_stripwww', true );
305 305
 
306
-	if( $strip_www ) {
307
-		$domain = str_replace('www.', '', $domain );
306
+	if ( $strip_www ) {
307
+		$domain = str_replace( 'www.', '', $domain );
308 308
 	}
309 309
 
310 310
 	/**
@@ -314,11 +314,11 @@  discard block
 block discarded – undo
314 314
 	 * If true: `http://demo.example.com => example.com` \n
315 315
 	 * If false: `http://demo.example.com => demo.example.com`
316 316
 	 */
317
-	$strip_subdomains = apply_filters('gravityview_anchor_text_nosubdomain', true);
317
+	$strip_subdomains = apply_filters( 'gravityview_anchor_text_nosubdomain', true );
318 318
 
319
-	if( $strip_subdomains ) {
319
+	if ( $strip_subdomains ) {
320 320
 
321
-		$domain = _gravityview_strip_subdomain( $parts['host'] );
321
+		$domain = _gravityview_strip_subdomain( $parts[ 'host' ] );
322 322
 
323 323
 	}
324 324
 
@@ -332,12 +332,12 @@  discard block
 block discarded – undo
332 332
 	 * If true: `http://example.com/sub/directory/page.html => example.com`  \n
333 333
 	 * If false: `http://example.com/sub/directory/page.html => example.com/sub/directory/page.html`
334 334
 	 */
335
-	$root_only = apply_filters('gravityview_anchor_text_rootonly', true);
335
+	$root_only = apply_filters( 'gravityview_anchor_text_rootonly', true );
336 336
 
337
-	if( empty( $root_only ) ) {
337
+	if ( empty( $root_only ) ) {
338 338
 
339
-		if( isset( $parts['path'] ) ) {
340
-			$return .= $parts['path'];
339
+		if ( isset( $parts[ 'path' ] ) ) {
340
+			$return .= $parts[ 'path' ];
341 341
 		}
342 342
 	}
343 343
 
@@ -347,12 +347,12 @@  discard block
 block discarded – undo
347 347
 	 * @param boolean $enable Whether to enable "root only". Return false to show full path. (default: true)\n
348 348
 	 * If true: `http://example.com/?query=example => example.com`
349 349
 	 */
350
-	$strip_query_string = apply_filters('gravityview_anchor_text_noquerystring', true );
350
+	$strip_query_string = apply_filters( 'gravityview_anchor_text_noquerystring', true );
351 351
 
352
-	if( empty( $strip_query_string ) ) {
352
+	if ( empty( $strip_query_string ) ) {
353 353
 
354
-		if( isset( $parts['query'] ) ) {
355
-			$return .= '?'.$parts['query'];
354
+		if ( isset( $parts[ 'query' ] ) ) {
355
+			$return .= '?' . $parts[ 'query' ];
356 356
 		}
357 357
 
358 358
 	}
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
  */
370 370
 function _gravityview_strip_subdomain( $string_maybe_has_subdomain ) {
371 371
 
372
-	if( preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.(?:com\.|co\.|net\.|org\.|firm\.|me\.|school\.|law\.|gov\.|mod\.|msk\.|irkutsks\.|sa\.|act\.|police\.|plc\.|ac\.|tm\.|asso\.|biz\.|pro\.|cg\.|telememo\.)?[a-z\.]{2,6})$/i", $string_maybe_has_subdomain, $matches ) ) {
373
-		return $matches['domain'];
372
+	if ( preg_match( "/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.(?:com\.|co\.|net\.|org\.|firm\.|me\.|school\.|law\.|gov\.|mod\.|msk\.|irkutsks\.|sa\.|act\.|police\.|plc\.|ac\.|tm\.|asso\.|biz\.|pro\.|cg\.|telememo\.)?[a-z\.]{2,6})$/i", $string_maybe_has_subdomain, $matches ) ) {
373
+		return $matches[ 'domain' ];
374 374
 	} else {
375 375
 		return $string_maybe_has_subdomain;
376 376
 	}
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 
440 440
 		if ( in_array( $value, array( 'yes', 'true' ), true ) ) {
441 441
 			$value = true;
442
-		} else if( in_array( $value, array( 'no', 'false' ), true ) ) {
442
+		} else if ( in_array( $value, array( 'no', 'false' ), true ) ) {
443 443
 			$value = false;
444 444
 		}
445 445
 	}
@@ -468,19 +468,19 @@  discard block
 block discarded – undo
468 468
  */
469 469
 function gv_maybe_json_decode( $value, $assoc = false, $depth = 512, $options = 0 ) {
470 470
 
471
-	if( ! is_string( $value ) ) {
471
+	if ( ! is_string( $value ) ) {
472 472
 		return $value;
473 473
 	}
474 474
 
475 475
 	$decoded = json_decode( $value, $assoc, $depth, $options );
476 476
 
477 477
 	// There was a JSON error (PHP 5.3+)
478
-	if( function_exists('json_last_error') && JSON_ERROR_NONE !== json_last_error() ) {
478
+	if ( function_exists( 'json_last_error' ) && JSON_ERROR_NONE !== json_last_error() ) {
479 479
 		return $value;
480 480
 	}
481 481
 
482 482
 	// It wasn't JSON (PHP < 5.3 fallback)
483
-	if( is_null( $decoded ) ) {
483
+	if ( is_null( $decoded ) ) {
484 484
 		return $value;
485 485
 	}
486 486
 
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 
504 504
 	// Use the original function, if exists.
505 505
 	// Requires WP 4.4+
506
-	if( function_exists( 'map_deep') ) {
506
+	if ( function_exists( 'map_deep' ) ) {
507 507
 		return map_deep( $value, $callback );
508 508
 	}
509 509
 
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
 
569 569
 	$exploded = explode( '.', "{$field_id}" );
570 570
 
571
-	return isset( $exploded[1] ) ? intval( $exploded[1] ) : false;
571
+	return isset( $exploded[ 1 ] ) ? intval( $exploded[ 1 ] ) : false;
572 572
 }
573 573
 
574 574
 /**
@@ -609,13 +609,13 @@  discard block
 block discarded – undo
609 609
 	 */
610 610
 	$args = apply_filters( 'gravityview_get_terms_choices_args', $args );
611 611
 
612
-	$terms = get_terms( $args['taxonomy'], $args );
612
+	$terms = get_terms( $args[ 'taxonomy' ], $args );
613 613
 
614 614
 	$choices = array();
615 615
 
616 616
 	if ( is_array( $terms ) ) {
617 617
 		foreach ( $terms as $term_id => $term_name ) {
618
-			$choices[] = array(
618
+			$choices[ ] = array(
619 619
 				'text'  => $term_name,
620 620
 				'value' => $term_id
621 621
 			);
@@ -639,21 +639,21 @@  discard block
 block discarded – undo
639 639
 function _gravityview_process_posted_fields() {
640 640
 	$fields = array();
641 641
 
642
-	if( !empty( $_POST['gv_fields'] ) ) {
643
-		if ( ! is_array( $_POST['gv_fields'] ) ) {
642
+	if ( ! empty( $_POST[ 'gv_fields' ] ) ) {
643
+		if ( ! is_array( $_POST[ 'gv_fields' ] ) ) {
644 644
 
645 645
 			// We are not using parse_str() due to max_input_vars limitation with large View configurations
646 646
 			$fields_holder = array();
647
-			GVCommon::gv_parse_str( $_POST['gv_fields'], $fields_holder );
647
+			GVCommon::gv_parse_str( $_POST[ 'gv_fields' ], $fields_holder );
648 648
 
649
-			if ( isset( $fields_holder['fields'] ) ) {
650
-				$fields = $fields_holder['fields'];
649
+			if ( isset( $fields_holder[ 'fields' ] ) ) {
650
+				$fields = $fields_holder[ 'fields' ];
651 651
 			} else {
652 652
 				gravityview()->log->error( 'No `fields` key was found after parsing $fields string', array( 'data' => $fields_holder ) );
653 653
 			}
654 654
 
655 655
 		} else {
656
-			$fields = $_POST['gv_fields'];
656
+			$fields = $_POST[ 'gv_fields' ];
657 657
 		}
658 658
 	}
659 659
 
Please login to merge, or discard this patch.