Completed
Push — master ( 7403e5...de348d )
by Stephanie
02:55
created
classes/helpers/FrmAppHelper.php 1 patch
Indentation   +548 added lines, -548 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@  discard block
 block discarded – undo
13 13
 	 */
14 14
 	public static $plug_version = '3.06';
15 15
 
16
-    /**
17
-     * @since 1.07.02
18
-     *
19
-     * @param none
20
-     * @return string The version of this plugin
21
-     */
22
-    public static function plugin_version() {
23
-        return self::$plug_version;
24
-    }
16
+	/**
17
+	 * @since 1.07.02
18
+	 *
19
+	 * @param none
20
+	 * @return string The version of this plugin
21
+	 */
22
+	public static function plugin_version() {
23
+		return self::$plug_version;
24
+	}
25 25
 
26 26
 	public static function plugin_folder() {
27 27
 		return basename( self::plugin_path() );
@@ -31,29 +31,29 @@  discard block
 block discarded – undo
31 31
 		return dirname( dirname( dirname( __FILE__ ) ) );
32 32
 	}
33 33
 
34
-    public static function plugin_url() {
35
-        //prevously FRM_URL constant
34
+	public static function plugin_url() {
35
+		//prevously FRM_URL constant
36 36
 		return plugins_url( '', self::plugin_path() . '/formidable.php' );
37
-    }
37
+	}
38 38
 
39 39
 	public static function relative_plugin_url() {
40 40
 		return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() );
41 41
 	}
42 42
 
43
-    /**
44
-     * @return string Site URL
45
-     */
46
-    public static function site_url() {
47
-        return site_url();
48
-    }
49
-
50
-    /**
51
-     * Get the name of this site
52
-     * Used for [sitename] shortcode
53
-     *
54
-     * @since 2.0
55
-     * @return string
56
-     */
43
+	/**
44
+	 * @return string Site URL
45
+	 */
46
+	public static function site_url() {
47
+		return site_url();
48
+	}
49
+
50
+	/**
51
+	 * Get the name of this site
52
+	 * Used for [sitename] shortcode
53
+	 *
54
+	 * @since 2.0
55
+	 * @return string
56
+	 */
57 57
 	public static function site_name() {
58 58
 		return get_option( 'blogname' );
59 59
 	}
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
 		return add_query_arg( $query_args, $page ) . $anchor;
108 108
 	}
109 109
 
110
-    /**
111
-     * Get the Formidable settings
112
-     *
113
-     * @since 2.0
114
-     *
115
-     * @param None
116
-     * @return FrmSettings $frm_setings
117
-     */
110
+	/**
111
+	 * Get the Formidable settings
112
+	 *
113
+	 * @since 2.0
114
+	 *
115
+	 * @param None
116
+	 * @return FrmSettings $frm_setings
117
+	 */
118 118
 	public static function get_settings() {
119 119
 		global $frm_settings;
120 120
 		if ( empty( $frm_settings ) ) {
@@ -175,50 +175,50 @@  discard block
 block discarded – undo
175 175
 		return $is_formidable;
176 176
 	}
177 177
 
178
-    /**
179
-     * Check for certain page in Formidable settings
180
-     *
181
-     * @since 2.0
182
-     *
183
-     * @param string $page The name of the page to check
184
-     * @return boolean
185
-     */
178
+	/**
179
+	 * Check for certain page in Formidable settings
180
+	 *
181
+	 * @since 2.0
182
+	 *
183
+	 * @param string $page The name of the page to check
184
+	 * @return boolean
185
+	 */
186 186
 	public static function is_admin_page( $page = 'formidable' ) {
187
-        global $pagenow;
187
+		global $pagenow;
188 188
 		$get_page = self::simple_get( 'page', 'sanitize_title' );
189
-        if ( $pagenow ) {
189
+		if ( $pagenow ) {
190 190
 			// allow this to be true during ajax load i.e. ajax form builder loading
191 191
 			return ( $pagenow == 'admin.php' || $pagenow == 'admin-ajax.php' ) && $get_page == $page;
192
-        }
192
+		}
193 193
 
194 194
 		return is_admin() && $get_page == $page;
195
-    }
196
-
197
-    /**
198
-     * Check for the form preview page
199
-     *
200
-     * @since 2.0
201
-     *
202
-     * @param None
203
-     * @return boolean
204
-     */
205
-    public static function is_preview_page() {
206
-        global $pagenow;
195
+	}
196
+
197
+	/**
198
+	 * Check for the form preview page
199
+	 *
200
+	 * @since 2.0
201
+	 *
202
+	 * @param None
203
+	 * @return boolean
204
+	 */
205
+	public static function is_preview_page() {
206
+		global $pagenow;
207 207
 		$action = self::simple_get( 'action', 'sanitize_title' );
208 208
 		return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview';
209
-    }
210
-
211
-    /**
212
-     * Check for ajax except the form preview page
213
-     *
214
-     * @since 2.0
215
-     *
216
-     * @param None
217
-     * @return boolean
218
-     */
219
-    public static function doing_ajax() {
220
-        return self::wp_doing_ajax() && ! self::is_preview_page();
221
-    }
209
+	}
210
+
211
+	/**
212
+	 * Check for ajax except the form preview page
213
+	 *
214
+	 * @since 2.0
215
+	 *
216
+	 * @param None
217
+	 * @return boolean
218
+	 */
219
+	public static function doing_ajax() {
220
+		return self::wp_doing_ajax() && ! self::is_preview_page();
221
+	}
222 222
 
223 223
 	public static function js_suffix() {
224 224
 		return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
@@ -246,81 +246,81 @@  discard block
 block discarded – undo
246 246
 		return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
247 247
 	}
248 248
 
249
-    /**
250
-     * Check if on an admin page
251
-     *
252
-     * @since 2.0
253
-     *
254
-     * @param None
255
-     * @return boolean
256
-     */
257
-    public static function is_admin() {
258
-        return is_admin() && ! self::wp_doing_ajax();
259
-    }
260
-
261
-    /**
262
-     * Check if value contains blank value or empty array
263
-     *
264
-     * @since 2.0
265
-     * @param mixed $value - value to check
249
+	/**
250
+	 * Check if on an admin page
251
+	 *
252
+	 * @since 2.0
253
+	 *
254
+	 * @param None
255
+	 * @return boolean
256
+	 */
257
+	public static function is_admin() {
258
+		return is_admin() && ! self::wp_doing_ajax();
259
+	}
260
+
261
+	/**
262
+	 * Check if value contains blank value or empty array
263
+	 *
264
+	 * @since 2.0
265
+	 * @param mixed $value - value to check
266 266
 	 * @param string
267
-     * @return boolean
268
-     */
269
-    public static function is_empty_value( $value, $empty = '' ) {
270
-        return ( is_array( $value ) && empty( $value ) ) || $value === $empty;
271
-    }
272
-
273
-    public static function is_not_empty_value( $value, $empty = '' ) {
274
-        return ! self::is_empty_value( $value, $empty );
275
-    }
276
-
277
-    /**
278
-     * Get any value from the $_SERVER
279
-     *
280
-     * @since 2.0
281
-     * @param string $value
282
-     * @return string
283
-     */
267
+	 * @return boolean
268
+	 */
269
+	public static function is_empty_value( $value, $empty = '' ) {
270
+		return ( is_array( $value ) && empty( $value ) ) || $value === $empty;
271
+	}
272
+
273
+	public static function is_not_empty_value( $value, $empty = '' ) {
274
+		return ! self::is_empty_value( $value, $empty );
275
+	}
276
+
277
+	/**
278
+	 * Get any value from the $_SERVER
279
+	 *
280
+	 * @since 2.0
281
+	 * @param string $value
282
+	 * @return string
283
+	 */
284 284
 	public static function get_server_value( $value ) {
285
-        return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
286
-    }
287
-
288
-    /**
289
-     * Check for the IP address in several places
290
-     * Used by [ip] shortcode
291
-     *
292
-     * @return string The IP address of the current user
293
-     */
294
-    public static function get_ip_address() {
285
+		return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
286
+	}
287
+
288
+	/**
289
+	 * Check for the IP address in several places
290
+	 * Used by [ip] shortcode
291
+	 *
292
+	 * @return string The IP address of the current user
293
+	 */
294
+	public static function get_ip_address() {
295 295
 		$ip = '';
296 296
 		foreach ( array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
297
-            if ( ! isset( $_SERVER[ $key ] ) ) {
298
-                continue;
299
-            }
297
+			if ( ! isset( $_SERVER[ $key ] ) ) {
298
+				continue;
299
+			}
300 300
 
301
-            foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
301
+			foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
302 302
 				$ip = trim( $ip ); // just to be safe
303 303
 
304 304
 				if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
305
-                    return sanitize_text_field( $ip );
306
-                }
307
-            }
308
-        }
305
+					return sanitize_text_field( $ip );
306
+				}
307
+			}
308
+		}
309 309
 
310 310
 		return sanitize_text_field( $ip );
311
-    }
311
+	}
312 312
 
313
-    public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
313
+	public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
314 314
 		if ( strpos( $param, '[' ) ) {
315 315
 			$params = explode( '[', $param );
316
-            $param = $params[0];
317
-        }
316
+			$param = $params[0];
317
+		}
318 318
 
319 319
 		if ( $src == 'get' ) {
320
-            $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
321
-            if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
322
-                $value = stripslashes_deep( htmlspecialchars_decode( $_GET[ $param ] ) );
323
-            }
320
+			$value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
321
+			if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
322
+				$value = stripslashes_deep( htmlspecialchars_decode( $_GET[ $param ] ) );
323
+			}
324 324
 			self::sanitize_value( $sanitize, $value );
325 325
 		} else {
326 326
 			$value = self::get_simple_request(
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
 			}
345 345
 		}
346 346
 
347
-        return $value;
348
-    }
347
+		return $value;
348
+	}
349 349
 
350 350
 	public static function get_post_param( $param, $default = '', $sanitize = '' ) {
351 351
 		return self::get_simple_request(
@@ -413,12 +413,12 @@  discard block
 block discarded – undo
413 413
 	}
414 414
 
415 415
 	/**
416
-	* Preserve backslashes in a value, but make sure value doesn't get compounding slashes
417
-	*
418
-	* @since 2.0.8
419
-	* @param string $value
420
-	* @return string $value
421
-	*/
416
+	 * Preserve backslashes in a value, but make sure value doesn't get compounding slashes
417
+	 *
418
+	 * @since 2.0.8
419
+	 * @param string $value
420
+	 * @return string $value
421
+	 */
422 422
 	public static function preserve_backslashes( $value ) {
423 423
 		// If backslashes have already been added, don't add them again
424 424
 		if ( strpos( $value, '\\\\' ) === false ) {
@@ -440,14 +440,14 @@  discard block
 block discarded – undo
440 440
 		}
441 441
 	}
442 442
 
443
-    public static function sanitize_request( $sanitize_method, &$values ) {
444
-        $temp_values = $values;
445
-        foreach ( $temp_values as $k => $val ) {
446
-            if ( isset( $sanitize_method[ $k ] ) ) {
443
+	public static function sanitize_request( $sanitize_method, &$values ) {
444
+		$temp_values = $values;
445
+		foreach ( $temp_values as $k => $val ) {
446
+			if ( isset( $sanitize_method[ $k ] ) ) {
447 447
 				$values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
448
-            }
449
-        }
450
-    }
448
+			}
449
+		}
450
+	}
451 451
 
452 452
 	/**
453 453
 	 * Sanitize the value, and allow some HTML
@@ -584,40 +584,40 @@  discard block
 block discarded – undo
584 584
 		);
585 585
 	}
586 586
 
587
-    /**
588
-     * Used when switching the action for a bulk action
587
+	/**
588
+	 * Used when switching the action for a bulk action
589 589
 	 *
590
-     * @since 2.0
591
-     */
590
+	 * @since 2.0
591
+	 */
592 592
 	public static function remove_get_action() {
593 593
 		if ( ! isset( $_GET ) ) {
594 594
 			return;
595 595
 		}
596 596
 
597
-        $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
598
-        if ( ! empty( $new_action ) ) {
597
+		$new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
598
+		if ( ! empty( $new_action ) ) {
599 599
 			$_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', self::get_server_value( 'REQUEST_URI' ) );
600
-        }
601
-    }
600
+		}
601
+	}
602 602
 
603
-    /**
604
-     * Check the WP query for a parameter
605
-     *
606
-     * @since 2.0
607
-     * @return string|array
608
-     */
609
-    public static function get_query_var( $value, $param ) {
610
-        if ( $value != '' ) {
611
-            return $value;
612
-        }
603
+	/**
604
+	 * Check the WP query for a parameter
605
+	 *
606
+	 * @since 2.0
607
+	 * @return string|array
608
+	 */
609
+	public static function get_query_var( $value, $param ) {
610
+		if ( $value != '' ) {
611
+			return $value;
612
+		}
613 613
 
614
-        global $wp_query;
615
-        if ( isset( $wp_query->query_vars[ $param ] ) ) {
616
-            $value = $wp_query->query_vars[ $param ];
617
-        }
614
+		global $wp_query;
615
+		if ( isset( $wp_query->query_vars[ $param ] ) ) {
616
+			$value = $wp_query->query_vars[ $param ];
617
+		}
618 618
 
619
-        return $value;
620
-    }
619
+		return $value;
620
+	}
621 621
 
622 622
 	/**
623 623
 	 * @since 3.0
@@ -669,16 +669,16 @@  discard block
 block discarded – undo
669 669
 		<?php
670 670
 	}
671 671
 
672
-    /**
673
-     * @param string $type
674
-     */
675
-    public static function trigger_hook_load( $type, $object = null ) {
676
-        // only load the form hooks once
672
+	/**
673
+	 * @param string $type
674
+	 */
675
+	public static function trigger_hook_load( $type, $object = null ) {
676
+		// only load the form hooks once
677 677
 		$hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
678
-        if ( ! $hooks_loaded ) {
678
+		if ( ! $hooks_loaded ) {
679 679
 			do_action( 'frm_load_' . $type . '_hooks' );
680
-        }
681
-    }
680
+		}
681
+	}
682 682
 
683 683
 	/**
684 684
 	 * Save all front-end js scripts into a single file
@@ -703,18 +703,18 @@  discard block
 block discarded – undo
703 703
 		$new_file->combine_files( $files );
704 704
 	}
705 705
 
706
-    /**
707
-     * Check a value from a shortcode to see if true or false.
708
-     * True when value is 1, true, 'true', 'yes'
709
-     *
710
-     * @since 1.07.10
711
-     *
712
-     * @param string $value The value to compare
713
-     * @return boolean True or False
714
-     */
706
+	/**
707
+	 * Check a value from a shortcode to see if true or false.
708
+	 * True when value is 1, true, 'true', 'yes'
709
+	 *
710
+	 * @since 1.07.10
711
+	 *
712
+	 * @param string $value The value to compare
713
+	 * @return boolean True or False
714
+	 */
715 715
 	public static function is_true( $value ) {
716
-        return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
717
-    }
716
+		return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
717
+	}
718 718
 
719 719
 	public static function get_pages() {
720 720
 		$query = array(
@@ -727,10 +727,10 @@  discard block
 block discarded – undo
727 727
 		return get_posts( $query );
728 728
 	}
729 729
 
730
-    public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
731
-        $pages = self::get_pages();
730
+	public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
731
+		$pages = self::get_pages();
732 732
 		$selected = self::get_post_param( $field_name, $page_id, 'absint' );
733
-    ?>
733
+	?>
734 734
 		<select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" class="frm-pages-dropdown">
735 735
             <option value=""> </option>
736 736
             <?php foreach ( $pages as $page ) { ?>
@@ -740,16 +740,16 @@  discard block
 block discarded – undo
740 740
             <?php } ?>
741 741
         </select>
742 742
     <?php
743
-    }
743
+	}
744 744
 
745 745
 	public static function post_edit_link( $post_id ) {
746 746
 		$post = get_post( $post_id );
747
-        if ( $post ) {
747
+		if ( $post ) {
748 748
 			$post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
749 749
 			return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
750
-        }
751
-        return '';
752
-    }
750
+		}
751
+		return '';
752
+	}
753 753
 
754 754
 	public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
755 755
 		?>
@@ -760,73 +760,73 @@  discard block
 block discarded – undo
760 760
 	}
761 761
 
762 762
 	public static function roles_options( $capability ) {
763
-        global $frm_vars;
763
+		global $frm_vars;
764 764
 		if ( isset( $frm_vars['editable_roles'] ) ) {
765
-            $editable_roles = $frm_vars['editable_roles'];
766
-        } else {
767
-            $editable_roles = get_editable_roles();
768
-            $frm_vars['editable_roles'] = $editable_roles;
769
-        }
765
+			$editable_roles = $frm_vars['editable_roles'];
766
+		} else {
767
+			$editable_roles = get_editable_roles();
768
+			$frm_vars['editable_roles'] = $editable_roles;
769
+		}
770 770
 
771
-        foreach ( $editable_roles as $role => $details ) {
771
+		foreach ( $editable_roles as $role => $details ) {
772 772
 			$name = translate_user_role( $details['name'] );
773 773
 			?>
774 774
 		<option value="<?php echo esc_attr( $role ); ?>" <?php echo in_array( $role, (array) $capability ) ? ' selected="selected"' : ''; ?>><?php echo esc_attr( $name ); ?> </option>
775 775
 <?php
776 776
 			unset( $role, $details );
777
-        }
778
-    }
777
+		}
778
+	}
779 779
 
780 780
 	public static function frm_capabilities( $type = 'auto' ) {
781
-        $cap = array(
782
-            'frm_view_forms'        => __( 'View Forms and Templates', 'formidable' ),
783
-            'frm_edit_forms'        => __( 'Add/Edit Forms and Templates', 'formidable' ),
784
-            'frm_delete_forms'      => __( 'Delete Forms and Templates', 'formidable' ),
785
-            'frm_change_settings'   => __( 'Access this Settings Page', 'formidable' ),
786
-            'frm_view_entries'      => __( 'View Entries from Admin Area', 'formidable' ),
787
-            'frm_delete_entries'    => __( 'Delete Entries from Admin Area', 'formidable' ),
788
-        );
781
+		$cap = array(
782
+			'frm_view_forms'        => __( 'View Forms and Templates', 'formidable' ),
783
+			'frm_edit_forms'        => __( 'Add/Edit Forms and Templates', 'formidable' ),
784
+			'frm_delete_forms'      => __( 'Delete Forms and Templates', 'formidable' ),
785
+			'frm_change_settings'   => __( 'Access this Settings Page', 'formidable' ),
786
+			'frm_view_entries'      => __( 'View Entries from Admin Area', 'formidable' ),
787
+			'frm_delete_entries'    => __( 'Delete Entries from Admin Area', 'formidable' ),
788
+		);
789 789
 
790 790
 		if ( ! self::pro_is_installed() && 'pro' != $type ) {
791
-            return $cap;
792
-        }
791
+			return $cap;
792
+		}
793 793
 
794
-        $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
795
-        $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
796
-        $cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
797
-        $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
794
+		$cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
795
+		$cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
796
+		$cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
797
+		$cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
798 798
 
799
-        return $cap;
800
-    }
799
+		return $cap;
800
+	}
801 801
 
802 802
 	public static function user_has_permission( $needed_role ) {
803
-        if ( $needed_role == '-1' ) {
804
-            return false;
803
+		if ( $needed_role == '-1' ) {
804
+			return false;
805 805
 		}
806 806
 
807
-        // $needed_role will be equal to blank if "Logged-in users" is selected
808
-        if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
809
-            return true;
810
-        }
807
+		// $needed_role will be equal to blank if "Logged-in users" is selected
808
+		if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
809
+			return true;
810
+		}
811 811
 
812
-        $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
813
-        foreach ( $roles as $role ) {
812
+		$roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
813
+		foreach ( $roles as $role ) {
814 814
 			if ( current_user_can( $role ) ) {
815
-        		return true;
815
+				return true;
816 816
 			}
817
-        	if ( $role == $needed_role ) {
818
-        		break;
817
+			if ( $role == $needed_role ) {
818
+				break;
819 819
 			}
820
-        }
821
-        return false;
822
-    }
823
-
824
-    /**
825
-     * Make sure administrators can see Formidable menu
826
-     *
827
-     * @since 2.0
828
-     */
829
-    public static function maybe_add_permissions() {
820
+		}
821
+		return false;
822
+	}
823
+
824
+	/**
825
+	 * Make sure administrators can see Formidable menu
826
+	 *
827
+	 * @since 2.0
828
+	 */
829
+	public static function maybe_add_permissions() {
830 830
 		self::force_capability( 'frm_view_entries' );
831 831
 
832 832
 		if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) {
@@ -835,12 +835,12 @@  discard block
 block discarded – undo
835 835
 
836 836
 		$user_id = get_current_user_id();
837 837
 		$user = new WP_User( $user_id );
838
-        $frm_roles = self::frm_capabilities();
839
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
838
+		$frm_roles = self::frm_capabilities();
839
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
840 840
 			$user->add_cap( $frm_role );
841 841
 			unset( $frm_role, $frm_role_description );
842
-        }
843
-    }
842
+		}
843
+	}
844 844
 
845 845
 	/**
846 846
 	 * Make sure admins have permission to see the menu items
@@ -857,30 +857,30 @@  discard block
 block discarded – undo
857 857
 		}
858 858
 	}
859 859
 
860
-    /**
861
-     * Check if the user has permision for action.
862
-     * Return permission message and stop the action if no permission
860
+	/**
861
+	 * Check if the user has permision for action.
862
+	 * Return permission message and stop the action if no permission
863 863
 	 *
864
-     * @since 2.0
865
-     * @param string $permission
866
-     */
864
+	 * @since 2.0
865
+	 * @param string $permission
866
+	 */
867 867
 	public static function permission_check( $permission, $show_message = 'show' ) {
868 868
 		$permission_error = self::permission_nonce_error( $permission );
869
-        if ( $permission_error !== false ) {
870
-            if ( 'hide' == $show_message ) {
871
-                $permission_error = '';
872
-            }
869
+		if ( $permission_error !== false ) {
870
+			if ( 'hide' == $show_message ) {
871
+				$permission_error = '';
872
+			}
873 873
 			wp_die( esc_html( $permission_error ) );
874
-        }
875
-    }
874
+		}
875
+	}
876 876
 
877
-    /**
878
-     * Check user permission and nonce
877
+	/**
878
+	 * Check user permission and nonce
879 879
 	 *
880
-     * @since 2.0
881
-     * @param string $permission
882
-     * @return false|string The permission message or false if allowed
883
-     */
880
+	 * @since 2.0
881
+	 * @param string $permission
882
+	 * @return false|string The permission message or false if allowed
883
+	 */
884 884
 	public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
885 885
 		if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
886 886
 			$frm_settings = self::get_settings();
@@ -889,22 +889,22 @@  discard block
 block discarded – undo
889 889
 
890 890
 		$error = false;
891 891
 		if ( empty( $nonce_name ) ) {
892
-            return $error;
893
-        }
892
+			return $error;
893
+		}
894 894
 
895
-        if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
896
-            $frm_settings = self::get_settings();
897
-            $error = $frm_settings->admin_permission;
898
-        }
895
+		if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
896
+			$frm_settings = self::get_settings();
897
+			$error = $frm_settings->admin_permission;
898
+		}
899 899
 
900
-        return $error;
901
-    }
900
+		return $error;
901
+	}
902 902
 
903
-    public static function checked( $values, $current ) {
903
+	public static function checked( $values, $current ) {
904 904
 		if ( self::check_selected( $values, $current ) ) {
905
-            echo ' checked="checked"';
905
+			echo ' checked="checked"';
906 906
 		}
907
-    }
907
+	}
908 908
 
909 909
 	public static function check_selected( $values, $current ) {
910 910
 		$values = self::recursive_function_map( $values, 'trim' );
@@ -942,24 +942,24 @@  discard block
 block discarded – undo
942 942
 		return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
943 943
 	}
944 944
 
945
-    /**
946
-     * Flatten a multi-dimensional array
947
-     */
945
+	/**
946
+	 * Flatten a multi-dimensional array
947
+	 */
948 948
 	public static function array_flatten( $array, $keys = 'keep' ) {
949
-        $return = array();
950
-        foreach ( $array as $key => $value ) {
949
+		$return = array();
950
+		foreach ( $array as $key => $value ) {
951 951
 			if ( is_array( $value ) ) {
952 952
 				$return = array_merge( $return, self::array_flatten( $value, $keys ) );
953
-            } else {
953
+			} else {
954 954
 				if ( $keys == 'keep' ) {
955 955
 					$return[ $key ] = $value;
956 956
 				} else {
957 957
 					$return[] = $value;
958 958
 				}
959
-            }
960
-        }
961
-        return $return;
962
-    }
959
+			}
960
+		}
961
+		return $return;
962
+	}
963 963
 
964 964
 	public static function esc_textarea( $text, $is_rich_text = false ) {
965 965
 		$safe_text = str_replace( '&quot;', '"', $text );
@@ -970,11 +970,11 @@  discard block
 block discarded – undo
970 970
 		return apply_filters( 'esc_textarea', $safe_text, $text );
971 971
 	}
972 972
 
973
-    /**
974
-     * Add auto paragraphs to text areas
973
+	/**
974
+	 * Add auto paragraphs to text areas
975 975
 	 *
976
-     * @since 2.0
977
-     */
976
+	 * @since 2.0
977
+	 */
978 978
 	public static function use_wpautop( $content ) {
979 979
 		if ( apply_filters( 'frm_use_wpautop', true ) ) {
980 980
 			$content = wpautop( str_replace( '<br>', '<br />', $content ) );
@@ -983,26 +983,26 @@  discard block
 block discarded – undo
983 983
 	}
984 984
 
985 985
 	public static function replace_quotes( $val ) {
986
-        //Replace double quotes
986
+		//Replace double quotes
987 987
 		$val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
988
-        //Replace single quotes
989
-        $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
990
-        return $val;
991
-    }
992
-
993
-    /**
994
-     * @since 2.0
995
-     * @return string The base Google APIS url for the current version of jQuery UI
996
-     */
997
-    public static function jquery_ui_base_url() {
988
+		//Replace single quotes
989
+		$val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
990
+		return $val;
991
+	}
992
+
993
+	/**
994
+	 * @since 2.0
995
+	 * @return string The base Google APIS url for the current version of jQuery UI
996
+	 */
997
+	public static function jquery_ui_base_url() {
998 998
 		$url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core', '1.11.4' );
999 999
 		$url = apply_filters( 'frm_jquery_ui_base_url', $url );
1000
-        return $url;
1001
-    }
1000
+		return $url;
1001
+	}
1002 1002
 
1003
-    /**
1004
-     * @param string $handle
1005
-     */
1003
+	/**
1004
+	 * @param string $handle
1005
+	 */
1006 1006
 	public static function script_version( $handle, $default = 0 ) {
1007 1007
 		global $wp_scripts;
1008 1008
 		if ( ! $wp_scripts ) {
@@ -1024,12 +1024,12 @@  discard block
 block discarded – undo
1024 1024
 
1025 1025
 	public static function js_redirect( $url ) {
1026 1026
 		return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
1027
-    }
1027
+	}
1028 1028
 
1029 1029
 	public static function get_user_id_param( $user_id ) {
1030 1030
 		if ( ! $user_id || empty( $user_id ) || is_numeric( $user_id ) ) {
1031
-            return $user_id;
1032
-        }
1031
+			return $user_id;
1032
+		}
1033 1033
 
1034 1034
 		$user_id = sanitize_text_field( $user_id );
1035 1035
 		if ( $user_id == 'current' ) {
@@ -1041,14 +1041,14 @@  discard block
 block discarded – undo
1041 1041
 				$user = get_user_by( 'login', $user_id );
1042 1042
 			}
1043 1043
 
1044
-            if ( $user ) {
1045
-                $user_id = $user->ID;
1046
-            }
1044
+			if ( $user ) {
1045
+				$user_id = $user->ID;
1046
+			}
1047 1047
 			unset( $user );
1048
-        }
1048
+		}
1049 1049
 
1050
-        return $user_id;
1051
-    }
1050
+		return $user_id;
1051
+	}
1052 1052
 
1053 1053
 	public static function get_file_contents( $filename, $atts = array() ) {
1054 1054
 		if ( ! is_file( $filename ) ) {
@@ -1063,28 +1063,28 @@  discard block
 block discarded – undo
1063 1063
 		return $contents;
1064 1064
 	}
1065 1065
 
1066
-    /**
1067
-     * @param string $table_name
1068
-     * @param string $column
1066
+	/**
1067
+	 * @param string $table_name
1068
+	 * @param string $column
1069 1069
 	 * @param int $id
1070 1070
 	 * @param int $num_chars
1071
-     */
1072
-    public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
1073
-        $key = '';
1071
+	 */
1072
+	public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
1073
+		$key = '';
1074 1074
 
1075
-        if ( ! empty( $name ) ) {
1075
+		if ( ! empty( $name ) ) {
1076 1076
 			$key = sanitize_key( $name );
1077
-        }
1077
+		}
1078 1078
 
1079 1079
 		if ( empty( $key ) ) {
1080 1080
 			$max_slug_value = pow( 36, $num_chars );
1081
-            $min_slug_value = 37; // we want to have at least 2 characters in the slug
1081
+			$min_slug_value = 37; // we want to have at least 2 characters in the slug
1082 1082
 			$key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
1083
-        }
1083
+		}
1084 1084
 
1085 1085
 		if ( is_numeric( $key ) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
1086 1086
 			$key = $key . 'a';
1087
-        }
1087
+		}
1088 1088
 
1089 1089
 		$key_check = FrmDb::get_var(
1090 1090
 			$table_name,
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
 		);
1097 1097
 
1098 1098
 		if ( $key_check || is_numeric( $key_check ) ) {
1099
-            $suffix = 2;
1099
+			$suffix = 2;
1100 1100
 			do {
1101 1101
 				$alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
1102 1102
 				$key_check = FrmDb::get_var(
@@ -1110,20 +1110,20 @@  discard block
 block discarded – undo
1110 1110
 				$suffix++;
1111 1111
 			} while ( $key_check || is_numeric( $key_check ) );
1112 1112
 			$key = $alt_post_name;
1113
-        }
1114
-        return $key;
1115
-    }
1113
+		}
1114
+		return $key;
1115
+	}
1116 1116
 
1117
-    /**
1118
-     * Editing a Form or Entry
1117
+	/**
1118
+	 * Editing a Form or Entry
1119 1119
 	 *
1120
-     * @param string $table
1121
-     * @return bool|array
1122
-     */
1123
-    public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
1124
-        if ( ! $record ) {
1125
-            return false;
1126
-        }
1120
+	 * @param string $table
1121
+	 * @return bool|array
1122
+	 */
1123
+	public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
1124
+		if ( ! $record ) {
1125
+			return false;
1126
+		}
1127 1127
 
1128 1128
 		if ( empty( $post_values ) ) {
1129 1129
 			$post_values = stripslashes_deep( $_POST );
@@ -1146,14 +1146,14 @@  discard block
 block discarded – undo
1146 1146
 
1147 1147
 		self::prepare_field_arrays( $fields, $record, $values, array_merge( $args, compact( 'default', 'post_values' ) ) );
1148 1148
 
1149
-        if ( $table == 'entries' ) {
1150
-            $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
1151
-        } else if ( $table == 'forms' ) {
1152
-            $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
1153
-        }
1149
+		if ( $table == 'entries' ) {
1150
+			$values = FrmEntriesHelper::setup_edit_vars( $values, $record );
1151
+		} else if ( $table == 'forms' ) {
1152
+			$values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
1153
+		}
1154 1154
 
1155
-        return $values;
1156
-    }
1155
+		return $values;
1156
+	}
1157 1157
 
1158 1158
 	private static function prepare_field_arrays( $fields, $record, array &$values, $args ) {
1159 1159
 		if ( ! empty( $fields ) ) {
@@ -1166,15 +1166,15 @@  discard block
 block discarded – undo
1166 1166
 	}
1167 1167
 
1168 1168
 	private static function fill_field_defaults( $field, $record, array &$values, $args ) {
1169
-        $post_values = $args['post_values'];
1169
+		$post_values = $args['post_values'];
1170 1170
 
1171
-        if ( $args['default'] ) {
1172
-            $meta_value = $field->default_value;
1173
-        } else {
1171
+		if ( $args['default'] ) {
1172
+			$meta_value = $field->default_value;
1173
+		} else {
1174 1174
 			if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) {
1175 1175
 				if ( ! isset( $field->field_options['custom_field'] ) ) {
1176
-                    $field->field_options['custom_field'] = '';
1177
-                }
1176
+					$field->field_options['custom_field'] = '';
1177
+				}
1178 1178
 				$meta_value = FrmProEntryMetaHelper::get_post_value(
1179 1179
 					$record->post_id,
1180 1180
 					$field->field_options['post_field'],
@@ -1186,31 +1186,31 @@  discard block
 block discarded – undo
1186 1186
 						'field' => $field,
1187 1187
 					)
1188 1188
 				);
1189
-            } else {
1189
+			} else {
1190 1190
 				$meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
1191
-            }
1192
-        }
1191
+			}
1192
+		}
1193 1193
 
1194 1194
 		$field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1195
-        $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1195
+		$new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1196 1196
 
1197 1197
 		$field_array = self::start_field_array( $field );
1198 1198
 		$field_array['value'] = $new_value;
1199 1199
 		$field_array['type']  = apply_filters( 'frm_field_type', $field_type, $field, $new_value );
1200 1200
 		$field_array['parent_form_id'] = $args['parent_form_id'];
1201 1201
 
1202
-        $args['field_type'] = $field_type;
1202
+		$args['field_type'] = $field_type;
1203 1203
 
1204 1204
 		FrmFieldsHelper::prepare_edit_front_field( $field_array, $field, $values['id'], $args );
1205 1205
 
1206 1206
 		if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) {
1207
-            $field_array['unique_msg'] = '';
1208
-        }
1207
+			$field_array['unique_msg'] = '';
1208
+		}
1209 1209
 
1210
-        $field_array = array_merge( $field->field_options, $field_array );
1210
+		$field_array = array_merge( $field->field_options, $field_array );
1211 1211
 
1212
-        $values['fields'][ $field->id ] = $field_array;
1213
-    }
1212
+		$values['fields'][ $field->id ] = $field_array;
1213
+	}
1214 1214
 
1215 1215
 	/**
1216 1216
 	 * @since 3.0
@@ -1231,20 +1231,20 @@  discard block
 block discarded – undo
1231 1231
 		);
1232 1232
 	}
1233 1233
 
1234
-    /**
1235
-     * @param string $table
1236
-     */
1234
+	/**
1235
+	 * @param string $table
1236
+	 */
1237 1237
 	private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
1238
-        if ( $table == 'entries' ) {
1239
-            $form = $record->form_id;
1238
+		if ( $table == 'entries' ) {
1239
+			$form = $record->form_id;
1240 1240
 			FrmForm::maybe_get_form( $form );
1241
-        } else {
1242
-            $form = $record;
1243
-        }
1241
+		} else {
1242
+			$form = $record;
1243
+		}
1244 1244
 
1245
-        if ( ! $form ) {
1246
-            return;
1247
-        }
1245
+		if ( ! $form ) {
1246
+			return;
1247
+		}
1248 1248
 
1249 1249
 		$values['form_name'] = isset( $record->form_id ) ? $form->name : '';
1250 1250
 		$values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
@@ -1253,26 +1253,26 @@  discard block
 block discarded – undo
1253 1253
 			return;
1254 1254
 		}
1255 1255
 
1256
-        foreach ( $form->options as $opt => $value ) {
1257
-            $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1258
-        }
1256
+		foreach ( $form->options as $opt => $value ) {
1257
+			$values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1258
+		}
1259 1259
 
1260 1260
 		self::fill_form_defaults( $post_values, $values );
1261
-    }
1261
+	}
1262 1262
 
1263
-    /**
1264
-     * Set to POST value or default
1265
-     */
1263
+	/**
1264
+	 * Set to POST value or default
1265
+	 */
1266 1266
 	private static function fill_form_defaults( $post_values, array &$values ) {
1267
-        $form_defaults = FrmFormsHelper::get_default_opts();
1267
+		$form_defaults = FrmFormsHelper::get_default_opts();
1268 1268
 
1269
-        foreach ( $form_defaults as $opt => $default ) {
1270
-            if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1269
+		foreach ( $form_defaults as $opt => $default ) {
1270
+			if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1271 1271
 				$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1272
-            }
1272
+			}
1273 1273
 
1274 1274
 			unset( $opt, $default );
1275
-        }
1275
+		}
1276 1276
 
1277 1277
 		if ( ! isset( $values['custom_style'] ) ) {
1278 1278
 			$values['custom_style'] = self::custom_style_value( $post_values );
@@ -1281,10 +1281,10 @@  discard block
 block discarded – undo
1281 1281
 		foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1282 1282
 			if ( ! isset( $values[ $h . '_html' ] ) ) {
1283 1283
 				$values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1284
-            }
1284
+			}
1285 1285
 			unset( $h );
1286
-        }
1287
-    }
1286
+		}
1287
+	}
1288 1288
 
1289 1289
 	/**
1290 1290
 	 * @since 2.2.10
@@ -1307,33 +1307,33 @@  discard block
 block discarded – undo
1307 1307
 		if ( $possible_email_field ) {
1308 1308
 			$class .= 'show_frm_not_email_to';
1309 1309
 		}
1310
-    ?>
1310
+	?>
1311 1311
 <li>
1312 1312
 	<a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['id'] ); ?>" >[<?php echo esc_attr( $args['id'] ); ?>]</a>
1313 1313
 	<a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['key'] ); ?>" >[<?php echo esc_attr( self::truncate( $args['key'], 10 ) ); ?>]</a>
1314 1314
 	<a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['id'] ); ?>" ><?php echo esc_attr( self::truncate( $args['name'], 60 ) ); ?></a>
1315 1315
 </li>
1316 1316
     <?php
1317
-    }
1317
+	}
1318 1318
 
1319 1319
 	public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
1320
-        if ( is_array( $str ) ) {
1321
-            return '';
1320
+		if ( is_array( $str ) ) {
1321
+			return '';
1322 1322
 		}
1323 1323
 
1324
-        $length = (int) $length;
1324
+		$length = (int) $length;
1325 1325
 		$str = wp_strip_all_tags( $str );
1326 1326
 		$original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
1327 1327
 
1328 1328
 		if ( $length == 0 ) {
1329
-            return '';
1330
-        } else if ( $length <= 10 ) {
1329
+			return '';
1330
+		} else if ( $length <= 10 ) {
1331 1331
 			$sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
1332 1332
 			return $sub . ( ( $length < $original_len ) ? $continue : '' );
1333
-        }
1333
+		}
1334 1334
 
1335
-        $sub = '';
1336
-        $len = 0;
1335
+		$sub = '';
1336
+		$len = 0;
1337 1337
 
1338 1338
 		$words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1339 1339
 
@@ -1341,21 +1341,21 @@  discard block
 block discarded – undo
1341 1341
 			$part = ( ( $sub != '' ) ? ' ' : '' ) . $word;
1342 1342
 			$total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1343 1343
 			if ( $total_len > $length && substr_count( $sub, ' ' ) ) {
1344
-                break;
1345
-            }
1344
+				break;
1345
+			}
1346 1346
 
1347
-            $sub .= $part;
1347
+			$sub .= $part;
1348 1348
 			$len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1349 1349
 
1350 1350
 			if ( substr_count( $sub, ' ' ) > $minword && $total_len >= $length ) {
1351
-                break;
1352
-            }
1351
+				break;
1352
+			}
1353 1353
 
1354 1354
 			unset( $total_len, $word );
1355
-        }
1355
+		}
1356 1356
 
1357 1357
 		return $sub . ( ( $len < $original_len ) ? $continue : '' );
1358
-    }
1358
+	}
1359 1359
 
1360 1360
 	public static function mb_function( $function_names, $args ) {
1361 1361
 		$mb_function_name = $function_names[0];
@@ -1368,17 +1368,17 @@  discard block
 block discarded – undo
1368 1368
 
1369 1369
 	public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1370 1370
 		if ( empty( $date ) ) {
1371
-            return $date;
1372
-        }
1371
+			return $date;
1372
+		}
1373 1373
 
1374 1374
 		if ( empty( $date_format ) ) {
1375 1375
 			$date_format = get_option( 'date_format' );
1376 1376
 		}
1377 1377
 
1378 1378
 		if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) {
1379
-            $frmpro_settings = new FrmProSettings();
1379
+			$frmpro_settings = new FrmProSettings();
1380 1380
 			$date = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' );
1381
-        }
1381
+		}
1382 1382
 
1383 1383
 		$formatted = self::get_localized_date( $date_format, $date );
1384 1384
 
@@ -1387,8 +1387,8 @@  discard block
 block discarded – undo
1387 1387
 			$formatted .= self::add_time_to_date( $time_format, $date );
1388 1388
 		}
1389 1389
 
1390
-        return $formatted;
1391
-    }
1390
+		return $formatted;
1391
+	}
1392 1392
 
1393 1393
 	private static function add_time_to_date( $time_format, $date ) {
1394 1394
 		if ( empty( $time_format ) ) {
@@ -1470,32 +1470,32 @@  discard block
 block discarded – undo
1470 1470
 		);
1471 1471
 	}
1472 1472
 
1473
-    // Pagination Methods
1473
+	// Pagination Methods
1474 1474
 
1475
-    /**
1476
-     * @param integer $current_p
1477
-     */
1475
+	/**
1476
+	 * @param integer $current_p
1477
+	 */
1478 1478
 	public static function get_last_record_num( $r_count, $current_p, $p_size ) {
1479 1479
 		return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
1480 1480
 	}
1481 1481
 
1482
-    /**
1483
-     * @param integer $current_p
1484
-     */
1485
-    public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1486
-        if ( $current_p == 1 ) {
1487
-            return 1;
1488
-        } else {
1489
-            return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1490
-        }
1491
-    }
1482
+	/**
1483
+	 * @param integer $current_p
1484
+	 */
1485
+	public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1486
+		if ( $current_p == 1 ) {
1487
+			return 1;
1488
+		} else {
1489
+			return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1490
+		}
1491
+	}
1492 1492
 
1493 1493
 	/**
1494 1494
 	 * @return array
1495 1495
 	 */
1496 1496
 	public static function json_to_array( $json_vars ) {
1497
-        $vars = array();
1498
-        foreach ( $json_vars as $jv ) {
1497
+		$vars = array();
1498
+		foreach ( $json_vars as $jv ) {
1499 1499
 			$jv_name = explode( '[', $jv['name'] );
1500 1500
 			$last = count( $jv_name ) - 1;
1501 1501
 			foreach ( $jv_name as $p => $n ) {
@@ -1512,77 +1512,77 @@  discard block
 block discarded – undo
1512 1512
 					$l3 = $name;
1513 1513
 				}
1514 1514
 
1515
-                $this_val = ( $p == $last ) ? $jv['value'] : array();
1515
+				$this_val = ( $p == $last ) ? $jv['value'] : array();
1516 1516
 
1517
-                switch ( $p ) {
1518
-                    case 0:
1519
-                        $l1 = $name;
1520
-                        self::add_value_to_array( $name, $l1, $this_val, $vars );
1517
+				switch ( $p ) {
1518
+					case 0:
1519
+						$l1 = $name;
1520
+						self::add_value_to_array( $name, $l1, $this_val, $vars );
1521 1521
 						break;
1522 1522
 
1523
-                    case 1:
1524
-                        $l2 = $name;
1525
-                        self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1523
+					case 1:
1524
+						$l2 = $name;
1525
+						self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1526 1526
 						break;
1527 1527
 
1528
-                    case 2:
1529
-                        $l3 = $name;
1530
-                        self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1528
+					case 2:
1529
+						$l3 = $name;
1530
+						self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1531 1531
 						break;
1532 1532
 
1533
-                    case 3:
1534
-                        $l4 = $name;
1535
-                        self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1536
-                }
1533
+					case 3:
1534
+						$l4 = $name;
1535
+						self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1536
+				}
1537 1537
 
1538 1538
 				unset( $this_val, $n );
1539
-            }
1539
+			}
1540 1540
 
1541 1541
 			unset( $last, $jv );
1542
-        }
1543
-
1544
-        return $vars;
1545
-    }
1546
-
1547
-    /**
1548
-     * @param string $name
1549
-     * @param string $l1
1550
-     */
1551
-    public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1552
-        if ( $name == '' ) {
1553
-            $vars[] = $val;
1554
-        } else if ( ! isset( $vars[ $l1 ] ) ) {
1555
-            $vars[ $l1 ] = $val;
1556
-        }
1557
-    }
1542
+		}
1543
+
1544
+		return $vars;
1545
+	}
1546
+
1547
+	/**
1548
+	 * @param string $name
1549
+	 * @param string $l1
1550
+	 */
1551
+	public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1552
+		if ( $name == '' ) {
1553
+			$vars[] = $val;
1554
+		} else if ( ! isset( $vars[ $l1 ] ) ) {
1555
+			$vars[ $l1 ] = $val;
1556
+		}
1557
+	}
1558 1558
 
1559 1559
 	public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
1560
-        $tooltips = array(
1561
-            'action_title'  => __( 'Give this action a label for easy reference.', 'formidable' ),
1562
-            'email_to'      => __( 'Add one or more recipient addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].  [admin_email] is the address set in WP General Settings.', 'formidable' ),
1563
-            'cc'            => __( 'Add CC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1564
-            'bcc'           => __( 'Add BCC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1565
-            'reply_to'      => __( 'If you would like a different reply to address than the "from" address, add a single address here.  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1566
-            'from'          => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ),
1567
-            'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
1568
-        );
1569
-
1570
-        if ( ! isset( $tooltips[ $name ] ) ) {
1571
-            return;
1572
-        }
1573
-
1574
-        if ( 'open' == $class ) {
1575
-            echo ' frm_help"';
1576
-        } else {
1577
-            echo ' class="frm_help"';
1578
-        }
1560
+		$tooltips = array(
1561
+			'action_title'  => __( 'Give this action a label for easy reference.', 'formidable' ),
1562
+			'email_to'      => __( 'Add one or more recipient addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].  [admin_email] is the address set in WP General Settings.', 'formidable' ),
1563
+			'cc'            => __( 'Add CC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1564
+			'bcc'           => __( 'Add BCC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1565
+			'reply_to'      => __( 'If you would like a different reply to address than the "from" address, add a single address here.  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1566
+			'from'          => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ),
1567
+			'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
1568
+		);
1569
+
1570
+		if ( ! isset( $tooltips[ $name ] ) ) {
1571
+			return;
1572
+		}
1573
+
1574
+		if ( 'open' == $class ) {
1575
+			echo ' frm_help"';
1576
+		} else {
1577
+			echo ' class="frm_help"';
1578
+		}
1579 1579
 
1580 1580
 		echo ' title="' . esc_attr( $tooltips[ $name ] );
1581 1581
 
1582
-        if ( 'open' != $class ) {
1583
-            echo '"';
1584
-        }
1585
-    }
1582
+		if ( 'open' != $class ) {
1583
+			echo '"';
1584
+		}
1585
+	}
1586 1586
 
1587 1587
 	/**
1588 1588
 	 * Add the current_page class to that page in the form nav
@@ -1598,35 +1598,35 @@  discard block
 block discarded – undo
1598 1598
 		}
1599 1599
 	}
1600 1600
 
1601
-    /**
1602
-     * Prepare and json_encode post content
1603
-     *
1604
-     * @since 2.0
1605
-     *
1606
-     * @param array $post_content
1607
-     * @return string $post_content ( json encoded array )
1608
-     */
1609
-    public static function prepare_and_encode( $post_content ) {
1610
-        //Loop through array to strip slashes and add only the needed ones
1601
+	/**
1602
+	 * Prepare and json_encode post content
1603
+	 *
1604
+	 * @since 2.0
1605
+	 *
1606
+	 * @param array $post_content
1607
+	 * @return string $post_content ( json encoded array )
1608
+	 */
1609
+	public static function prepare_and_encode( $post_content ) {
1610
+		//Loop through array to strip slashes and add only the needed ones
1611 1611
 		foreach ( $post_content as $key => $val ) {
1612 1612
 			// Replace problematic characters (like &quot;)
1613 1613
 			$val = str_replace( '&quot;', '"', $val );
1614 1614
 
1615 1615
 			self::prepare_action_slashes( $val, $key, $post_content );
1616
-            unset( $key, $val );
1617
-        }
1616
+			unset( $key, $val );
1617
+		}
1618 1618
 
1619
-        // json_encode the array
1620
-        $post_content = json_encode( $post_content );
1619
+		// json_encode the array
1620
+		$post_content = json_encode( $post_content );
1621 1621
 
1622
-	    // add extra slashes for \r\n since WP strips them
1622
+		// add extra slashes for \r\n since WP strips them
1623 1623
 		$post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
1624 1624
 
1625
-        // allow for &quot
1626
-	    $post_content = str_replace( '&quot;', '\\"', $post_content );
1625
+		// allow for &quot
1626
+		$post_content = str_replace( '&quot;', '\\"', $post_content );
1627 1627
 
1628
-        return $post_content;
1629
-    }
1628
+		return $post_content;
1629
+	}
1630 1630
 
1631 1631
 	private static function prepare_action_slashes( $val, $key, &$post_content ) {
1632 1632
 		if ( ! isset( $post_content[ $key ] ) ) {
@@ -1649,55 +1649,55 @@  discard block
 block discarded – undo
1649 1649
 
1650 1650
 	public static function maybe_json_decode( $string ) {
1651 1651
 		if ( is_array( $string ) ) {
1652
-            return $string;
1653
-        }
1652
+			return $string;
1653
+		}
1654 1654
 
1655 1655
 		$new_string = json_decode( $string, true );
1656 1656
 		if ( function_exists( 'json_last_error' ) ) {
1657 1657
 			// php 5.3+
1658
-            if ( json_last_error() == JSON_ERROR_NONE ) {
1659
-                $string = $new_string;
1660
-            }
1658
+			if ( json_last_error() == JSON_ERROR_NONE ) {
1659
+				$string = $new_string;
1660
+			}
1661 1661
 		} elseif ( isset( $new_string ) ) {
1662 1662
 			// php < 5.3 fallback
1663
-            $string = $new_string;
1664
-        }
1665
-        return $string;
1666
-    }
1667
-
1668
-    /**
1669
-     * @since 1.07.10
1670
-     *
1671
-     * @param string $post_type The name of the post type that may need to be highlighted
1672
-     * echo The javascript to open and highlight the Formidable menu
1673
-     */
1663
+			$string = $new_string;
1664
+		}
1665
+		return $string;
1666
+	}
1667
+
1668
+	/**
1669
+	 * @since 1.07.10
1670
+	 *
1671
+	 * @param string $post_type The name of the post type that may need to be highlighted
1672
+	 * echo The javascript to open and highlight the Formidable menu
1673
+	 */
1674 1674
 	public static function maybe_highlight_menu( $post_type ) {
1675
-        global $post;
1675
+		global $post;
1676 1676
 
1677 1677
 		if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) {
1678
-            return;
1679
-        }
1678
+			return;
1679
+		}
1680 1680
 
1681 1681
 		if ( is_object( $post ) && $post->post_type != $post_type ) {
1682
-            return;
1683
-        }
1682
+			return;
1683
+		}
1684 1684
 
1685
-        self::load_admin_wide_js();
1686
-        echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1687
-    }
1685
+		self::load_admin_wide_js();
1686
+		echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1687
+	}
1688 1688
 
1689
-    /**
1690
-     * Load the JS file on non-Formidable pages in the admin area
1689
+	/**
1690
+	 * Load the JS file on non-Formidable pages in the admin area
1691 1691
 	 *
1692
-     * @since 2.0
1693
-     */
1692
+	 * @since 2.0
1693
+	 */
1694 1694
 	public static function load_admin_wide_js( $load = true ) {
1695 1695
 		$version = self::plugin_version();
1696 1696
 		wp_register_script( 'formidable_admin_global', self::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
1697 1697
 
1698 1698
 		$global_strings = array(
1699 1699
 			'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
1700
-            'deauthorize'  => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1700
+			'deauthorize'  => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1701 1701
 			'url'          => self::plugin_url(),
1702 1702
 			'loading'      => __( 'Loading&hellip;', 'formidable' ),
1703 1703
 			'nonce'        => wp_create_nonce( 'frm_ajax' ),
@@ -1707,7 +1707,7 @@  discard block
 block discarded – undo
1707 1707
 		if ( $load ) {
1708 1708
 			wp_enqueue_script( 'formidable_admin_global' );
1709 1709
 		}
1710
-    }
1710
+	}
1711 1711
 
1712 1712
 	/**
1713 1713
 	 * @since 2.0.9
@@ -1716,9 +1716,9 @@  discard block
 block discarded – undo
1716 1716
 		wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
1717 1717
 	}
1718 1718
 
1719
-    /**
1720
-     * @param string $location
1721
-     */
1719
+	/**
1720
+	 * @param string $location
1721
+	 */
1722 1722
 	public static function localize_script( $location ) {
1723 1723
 		$ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
1724 1724
 		$ajax_url = apply_filters( 'frm_ajax_url', $ajax_url );
@@ -1784,28 +1784,28 @@  discard block
 block discarded – undo
1784 1784
 		}
1785 1785
 	}
1786 1786
 
1787
-    /**
1787
+	/**
1788 1788
 	 * Echo the message on the plugins listing page
1789 1789
 	 *
1790
-     * @since 1.07.10
1791
-     *
1792
-     * @param float $min_version The version the add-on requires
1793
-     */
1790
+	 * @since 1.07.10
1791
+	 *
1792
+	 * @param float $min_version The version the add-on requires
1793
+	 */
1794 1794
 	public static function min_version_notice( $min_version ) {
1795
-        $frm_version = self::plugin_version();
1795
+		$frm_version = self::plugin_version();
1796 1796
 
1797
-        // check if Formidable meets minimum requirements
1797
+		// check if Formidable meets minimum requirements
1798 1798
 		if ( version_compare( $frm_version, $min_version, '>=' ) ) {
1799
-            return;
1800
-        }
1799
+			return;
1800
+		}
1801 1801
 
1802 1802
 		$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
1803 1803
 		echo '<tr class="plugin-update-tr active"><th colspan="' . absint( $wp_list_table->get_column_count() ) . '" class="check-column plugin-update colspanchange"><div class="update-message">' .
1804
-        esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1805
-        '</div></td></tr>';
1806
-    }
1804
+		esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1805
+		'</div></td></tr>';
1806
+	}
1807 1807
 
1808
-    public static function locales( $type = 'date' ) {
1808
+	public static function locales( $type = 'date' ) {
1809 1809
 		$locales = array(
1810 1810
 			'en' => __( 'English', 'formidable' ),
1811 1811
 			'af' => __( 'Afrikaans', 'formidable' ),
@@ -1883,8 +1883,8 @@  discard block
 block discarded – undo
1883 1883
 		$locales = array_diff_key( $locales, array_flip( $unset ) );
1884 1884
 		$locales = apply_filters( 'frm_locales', $locales );
1885 1885
 
1886
-        return $locales;
1887
-    }
1886
+		return $locales;
1887
+	}
1888 1888
 
1889 1889
 	/**
1890 1890
 	 * Used to filter shortcode in text widgets
Please login to merge, or discard this patch.