Completed
Push — master ( 9e736e...81fa44 )
by Stephanie
02:35
created
classes/helpers/FrmAppHelper.php 3 patches
Doc Comments   +15 added lines patch added patch discarded remove patch
@@ -57,6 +57,9 @@  discard block
 block discarded – undo
57 57
         return get_option('blogname');
58 58
     }
59 59
 
60
+	/**
61
+	 * @param string $url
62
+	 */
60 63
 	public static function make_affiliate_url( $url ) {
61 64
 		$affiliate_id = self::get_affiliate();
62 65
 		if ( ! empty( $affiliate_id ) ) {
@@ -66,6 +69,9 @@  discard block
 block discarded – undo
66 69
 		return $url;
67 70
 	}
68 71
 
72
+	/**
73
+	 * @return string
74
+	 */
69 75
 	public static function get_affiliate() {
70 76
 		return absint( apply_filters( 'frm_affiliate_id', 0 ) );
71 77
 	}
@@ -769,6 +775,9 @@  discard block
 block discarded – undo
769 775
 		return FrmFieldsHelper::prepare_other_input( $args, $other_opt, $checked );
770 776
     }
771 777
 
778
+	/**
779
+	 * @param string $function
780
+	 */
772 781
 	public static function recursive_function_map( $value, $function ) {
773 782
 		if ( is_array( $value ) ) {
774 783
 			$original_function = $function;
@@ -1202,6 +1211,9 @@  discard block
 block discarded – undo
1202 1211
         return $sub . (($len < $original_len) ? $continue : '');
1203 1212
     }
1204 1213
 
1214
+	/**
1215
+	 * @param string[] $function_names
1216
+	 */
1205 1217
 	public static function mb_function( $function_names, $args ) {
1206 1218
 		$mb_function_name = $function_names[0];
1207 1219
 		$function_name = $function_names[1];
@@ -1235,6 +1247,9 @@  discard block
 block discarded – undo
1235 1247
         return $formatted;
1236 1248
     }
1237 1249
 
1250
+	/**
1251
+	 * @param string $time_format
1252
+	 */
1238 1253
 	private static function add_time_to_date( $time_format, $date ) {
1239 1254
 		if ( empty( $time_format ) ) {
1240 1255
 			$time_format = get_option('time_format');
Please login to merge, or discard this patch.
Indentation   +904 added lines, -904 removed lines patch added patch discarded remove patch
@@ -12,50 +12,50 @@  discard block
 block discarded – undo
12 12
 	 */
13 13
 	public static $plug_version = '2.05.05';
14 14
 
15
-    /**
16
-     * @since 1.07.02
17
-     *
18
-     * @param none
19
-     * @return string The version of this plugin
20
-     */
21
-    public static function plugin_version() {
22
-        return self::$plug_version;
23
-    }
24
-
25
-    public static function plugin_folder() {
26
-        return basename(self::plugin_path());
27
-    }
28
-
29
-    public static function plugin_path() {
30
-        return dirname(dirname(dirname(__FILE__)));
31
-    }
32
-
33
-    public static function plugin_url() {
34
-        //prevously FRM_URL constant
15
+	/**
16
+	 * @since 1.07.02
17
+	 *
18
+	 * @param none
19
+	 * @return string The version of this plugin
20
+	 */
21
+	public static function plugin_version() {
22
+		return self::$plug_version;
23
+	}
24
+
25
+	public static function plugin_folder() {
26
+		return basename(self::plugin_path());
27
+	}
28
+
29
+	public static function plugin_path() {
30
+		return dirname(dirname(dirname(__FILE__)));
31
+	}
32
+
33
+	public static function plugin_url() {
34
+		//prevously FRM_URL constant
35 35
 		return plugins_url( '', self::plugin_path() . '/formidable.php' );
36
-    }
36
+	}
37 37
 
38 38
 	public static function relative_plugin_url() {
39 39
 		return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() );
40 40
 	}
41 41
 
42
-    /**
43
-     * @return string Site URL
44
-     */
45
-    public static function site_url() {
46
-        return site_url();
47
-    }
48
-
49
-    /**
50
-     * Get the name of this site
51
-     * Used for [sitename] shortcode
52
-     *
53
-     * @since 2.0
54
-     * @return string
55
-     */
56
-    public static function site_name() {
57
-        return get_option('blogname');
58
-    }
42
+	/**
43
+	 * @return string Site URL
44
+	 */
45
+	public static function site_url() {
46
+		return site_url();
47
+	}
48
+
49
+	/**
50
+	 * Get the name of this site
51
+	 * Used for [sitename] shortcode
52
+	 *
53
+	 * @since 2.0
54
+	 * @return string
55
+	 */
56
+	public static function site_name() {
57
+		return get_option('blogname');
58
+	}
59 59
 
60 60
 	public static function make_affiliate_url( $url ) {
61 61
 		$affiliate_id = self::get_affiliate();
@@ -70,21 +70,21 @@  discard block
 block discarded – undo
70 70
 		return absint( apply_filters( 'frm_affiliate_id', 0 ) );
71 71
 	}
72 72
 
73
-    /**
74
-     * Get the Formidable settings
75
-     *
76
-     * @since 2.0
77
-     *
78
-     * @param None
79
-     * @return FrmSettings $frm_setings
80
-     */
81
-    public static function get_settings() {
82
-        global $frm_settings;
83
-        if ( empty($frm_settings) ) {
84
-            $frm_settings = new FrmSettings();
85
-        }
86
-        return $frm_settings;
87
-    }
73
+	/**
74
+	 * Get the Formidable settings
75
+	 *
76
+	 * @since 2.0
77
+	 *
78
+	 * @param None
79
+	 * @return FrmSettings $frm_setings
80
+	 */
81
+	public static function get_settings() {
82
+		global $frm_settings;
83
+		if ( empty($frm_settings) ) {
84
+			$frm_settings = new FrmSettings();
85
+		}
86
+		return $frm_settings;
87
+	}
88 88
 
89 89
 	public static function get_menu_name() {
90 90
 		$frm_settings = FrmAppHelper::get_settings();
@@ -99,62 +99,62 @@  discard block
 block discarded – undo
99 99
 		return ! $frm_settings->no_ips;
100 100
 	}
101 101
 
102
-    /**
103
-     * Show a message in place of pro features
104
-     *
105
-     * @since 2.0
106
-     */
102
+	/**
103
+	 * Show a message in place of pro features
104
+	 *
105
+	 * @since 2.0
106
+	 */
107 107
 	public static function update_message() {
108 108
 		_deprecated_function( __FUNCTION__, '2.0.19' );
109
-    }
110
-
111
-    public static function pro_is_installed() {
112
-        return apply_filters('frm_pro_installed', false);
113
-    }
114
-
115
-    /**
116
-     * Check for certain page in Formidable settings
117
-     *
118
-     * @since 2.0
119
-     *
120
-     * @param string $page The name of the page to check
121
-     * @return boolean
122
-     */
109
+	}
110
+
111
+	public static function pro_is_installed() {
112
+		return apply_filters('frm_pro_installed', false);
113
+	}
114
+
115
+	/**
116
+	 * Check for certain page in Formidable settings
117
+	 *
118
+	 * @since 2.0
119
+	 *
120
+	 * @param string $page The name of the page to check
121
+	 * @return boolean
122
+	 */
123 123
 	public static function is_admin_page( $page = 'formidable' ) {
124
-        global $pagenow;
124
+		global $pagenow;
125 125
 		$get_page = self::simple_get( 'page', 'sanitize_title' );
126
-        if ( $pagenow ) {
126
+		if ( $pagenow ) {
127 127
 			return $pagenow == 'admin.php' && $get_page == $page;
128
-        }
128
+		}
129 129
 
130 130
 		return is_admin() && $get_page == $page;
131
-    }
132
-
133
-    /**
134
-     * Check for the form preview page
135
-     *
136
-     * @since 2.0
137
-     *
138
-     * @param None
139
-     * @return boolean
140
-     */
141
-    public static function is_preview_page() {
142
-        global $pagenow;
131
+	}
132
+
133
+	/**
134
+	 * Check for the form preview page
135
+	 *
136
+	 * @since 2.0
137
+	 *
138
+	 * @param None
139
+	 * @return boolean
140
+	 */
141
+	public static function is_preview_page() {
142
+		global $pagenow;
143 143
 		$action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
144 144
 		return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview';
145
-    }
145
+	}
146 146
 
147
-    /**
148
-     * Check for ajax except the form preview page
149
-     *
150
-     * @since 2.0
151
-     *
152
-     * @param None
153
-     * @return boolean
154
-     */
155
-    public static function doing_ajax() {
156
-        return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
157
-    }
147
+	/**
148
+	 * Check for ajax except the form preview page
149
+	 *
150
+	 * @since 2.0
151
+	 *
152
+	 * @param None
153
+	 * @return boolean
154
+	 */
155
+	public static function doing_ajax() {
156
+		return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
157
+	}
158 158
 
159 159
 	/**
160 160
 	 * @since 2.0.8
@@ -164,102 +164,102 @@  discard block
 block discarded – undo
164 164
 		return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
165 165
 	}
166 166
 
167
-    /**
168
-     * Check if on an admin page
169
-     *
170
-     * @since 2.0
171
-     *
172
-     * @param None
173
-     * @return boolean
174
-     */
175
-    public static function is_admin() {
176
-        return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX );
177
-    }
178
-
179
-    /**
180
-     * Check if value contains blank value or empty array
181
-     *
182
-     * @since 2.0
183
-     * @param mixed $value - value to check
167
+	/**
168
+	 * Check if on an admin page
169
+	 *
170
+	 * @since 2.0
171
+	 *
172
+	 * @param None
173
+	 * @return boolean
174
+	 */
175
+	public static function is_admin() {
176
+		return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX );
177
+	}
178
+
179
+	/**
180
+	 * Check if value contains blank value or empty array
181
+	 *
182
+	 * @since 2.0
183
+	 * @param mixed $value - value to check
184 184
 	 * @param string
185
-     * @return boolean
186
-     */
187
-    public static function is_empty_value( $value, $empty = '' ) {
188
-        return ( is_array( $value ) && empty( $value ) ) || $value == $empty;
189
-    }
190
-
191
-    public static function is_not_empty_value( $value, $empty = '' ) {
192
-        return ! self::is_empty_value( $value, $empty );
193
-    }
194
-
195
-    /**
196
-     * Get any value from the $_SERVER
197
-     *
198
-     * @since 2.0
199
-     * @param string $value
200
-     * @return string
201
-     */
185
+	 * @return boolean
186
+	 */
187
+	public static function is_empty_value( $value, $empty = '' ) {
188
+		return ( is_array( $value ) && empty( $value ) ) || $value == $empty;
189
+	}
190
+
191
+	public static function is_not_empty_value( $value, $empty = '' ) {
192
+		return ! self::is_empty_value( $value, $empty );
193
+	}
194
+
195
+	/**
196
+	 * Get any value from the $_SERVER
197
+	 *
198
+	 * @since 2.0
199
+	 * @param string $value
200
+	 * @return string
201
+	 */
202 202
 	public static function get_server_value( $value ) {
203
-        return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
204
-    }
205
-
206
-    /**
207
-     * Check for the IP address in several places
208
-     * Used by [ip] shortcode
209
-     *
210
-     * @return string The IP address of the current user
211
-     */
212
-    public static function get_ip_address() {
203
+		return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
204
+	}
205
+
206
+	/**
207
+	 * Check for the IP address in several places
208
+	 * Used by [ip] shortcode
209
+	 *
210
+	 * @return string The IP address of the current user
211
+	 */
212
+	public static function get_ip_address() {
213 213
 		$ip = '';
214
-        foreach ( array(
215
-            'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP',
216
-            'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR',
217
-        ) as $key ) {
218
-            if ( ! isset( $_SERVER[ $key ] ) ) {
219
-                continue;
220
-            }
221
-
222
-            foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
223
-                $ip = trim($ip); // just to be safe
224
-
225
-                if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
226
-                    return $ip;
227
-                }
228
-            }
229
-        }
214
+		foreach ( array(
215
+			'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP',
216
+			'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR',
217
+		) as $key ) {
218
+			if ( ! isset( $_SERVER[ $key ] ) ) {
219
+				continue;
220
+			}
221
+
222
+			foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
223
+				$ip = trim($ip); // just to be safe
224
+
225
+				if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
226
+					return $ip;
227
+				}
228
+			}
229
+		}
230 230
 
231 231
 		return sanitize_text_field( $ip );
232
-    }
232
+	}
233 233
 
234
-    public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
235
-        if ( strpos($param, '[') ) {
236
-            $params = explode('[', $param);
237
-            $param = $params[0];
238
-        }
234
+	public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
235
+		if ( strpos($param, '[') ) {
236
+			$params = explode('[', $param);
237
+			$param = $params[0];
238
+		}
239 239
 
240 240
 		if ( $src == 'get' ) {
241
-            $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
242
-            if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
243
-                $value = stripslashes_deep( htmlspecialchars_decode( $_GET[ $param ] ) );
244
-            }
241
+			$value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
242
+			if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
243
+				$value = stripslashes_deep( htmlspecialchars_decode( $_GET[ $param ] ) );
244
+			}
245 245
 			self::sanitize_value( $sanitize, $value );
246 246
 		} else {
247
-            $value = self::get_simple_request( array( 'type' => $src, 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
248
-        }
247
+			$value = self::get_simple_request( array( 'type' => $src, 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
248
+		}
249 249
 
250 250
 		if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
251
-            foreach ( $params as $k => $p ) {
252
-                if ( ! $k || ! is_array($value) ) {
253
-                    continue;
254
-                }
251
+			foreach ( $params as $k => $p ) {
252
+				if ( ! $k || ! is_array($value) ) {
253
+					continue;
254
+				}
255 255
 
256
-                $p = trim($p, ']');
257
-                $value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
258
-            }
259
-        }
256
+				$p = trim($p, ']');
257
+				$value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
258
+			}
259
+		}
260 260
 
261
-        return $value;
262
-    }
261
+		return $value;
262
+	}
263 263
 
264 264
 	public static function get_post_param( $param, $default = '', $sanitize = '' ) {
265 265
 		return self::get_simple_request( array( 'type' => 'post', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	 */
276 276
 	public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) {
277 277
 		return self::get_simple_request( array( 'type' => 'get', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
278
-    }
278
+	}
279 279
 
280 280
 	/**
281 281
 	 * Get a GET/POST/REQUEST value and sanitize it
@@ -311,12 +311,12 @@  discard block
 block discarded – undo
311 311
 	}
312 312
 
313 313
 	/**
314
-	* Preserve backslashes in a value, but make sure value doesn't get compounding slashes
315
-	*
316
-	* @since 2.0.8
317
-	* @param string $value
318
-	* @return string $value
319
-	*/
314
+	 * Preserve backslashes in a value, but make sure value doesn't get compounding slashes
315
+	 *
316
+	 * @since 2.0.8
317
+	 * @param string $value
318
+	 * @return string $value
319
+	 */
320 320
 	public static function preserve_backslashes( $value ) {
321 321
 		// If backslashes have already been added, don't add them again
322 322
 		if ( strpos( $value, '\\\\' ) === false ) {
@@ -338,14 +338,14 @@  discard block
 block discarded – undo
338 338
 		}
339 339
 	}
340 340
 
341
-    public static function sanitize_request( $sanitize_method, &$values ) {
342
-        $temp_values = $values;
343
-        foreach ( $temp_values as $k => $val ) {
344
-            if ( isset( $sanitize_method[ $k ] ) ) {
341
+	public static function sanitize_request( $sanitize_method, &$values ) {
342
+		$temp_values = $values;
343
+		foreach ( $temp_values as $k => $val ) {
344
+			if ( isset( $sanitize_method[ $k ] ) ) {
345 345
 				$values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
346
-            }
347
-        }
348
-    }
346
+			}
347
+		}
348
+	}
349 349
 
350 350
 	public static function sanitize_array( &$values ) {
351 351
 		$temp_values = $values;
@@ -469,80 +469,80 @@  discard block
 block discarded – undo
469 469
 		);
470 470
 	}
471 471
 
472
-    /**
473
-     * Used when switching the action for a bulk action
474
-     * @since 2.0
475
-     */
476
-    public static function remove_get_action() {
477
-        if ( ! isset($_GET) ) {
478
-            return;
479
-        }
472
+	/**
473
+	 * Used when switching the action for a bulk action
474
+	 * @since 2.0
475
+	 */
476
+	public static function remove_get_action() {
477
+		if ( ! isset($_GET) ) {
478
+			return;
479
+		}
480 480
 
481
-        $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
482
-        if ( ! empty( $new_action ) ) {
481
+		$new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
482
+		if ( ! empty( $new_action ) ) {
483 483
 			$_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
484
-        }
485
-    }
486
-
487
-    /**
488
-     * Check the WP query for a parameter
489
-     *
490
-     * @since 2.0
491
-     * @return string|array
492
-     */
493
-    public static function get_query_var( $value, $param ) {
494
-        if ( $value != '' ) {
495
-            return $value;
496
-        }
497
-
498
-        global $wp_query;
499
-        if ( isset( $wp_query->query_vars[ $param ] ) ) {
500
-            $value = $wp_query->query_vars[ $param ];
501
-        }
502
-
503
-        return $value;
504
-    }
505
-
506
-    /**
507
-     * @param string $type
508
-     */
509
-    public static function trigger_hook_load( $type, $object = null ) {
510
-        // only load the form hooks once
484
+		}
485
+	}
486
+
487
+	/**
488
+	 * Check the WP query for a parameter
489
+	 *
490
+	 * @since 2.0
491
+	 * @return string|array
492
+	 */
493
+	public static function get_query_var( $value, $param ) {
494
+		if ( $value != '' ) {
495
+			return $value;
496
+		}
497
+
498
+		global $wp_query;
499
+		if ( isset( $wp_query->query_vars[ $param ] ) ) {
500
+			$value = $wp_query->query_vars[ $param ];
501
+		}
502
+
503
+		return $value;
504
+	}
505
+
506
+	/**
507
+	 * @param string $type
508
+	 */
509
+	public static function trigger_hook_load( $type, $object = null ) {
510
+		// only load the form hooks once
511 511
 		$hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
512
-        if ( ! $hooks_loaded ) {
512
+		if ( ! $hooks_loaded ) {
513 513
 			do_action( 'frm_load_' . $type . '_hooks' );
514
-        }
515
-    }
516
-
517
-    /**
518
-     * Check a value from a shortcode to see if true or false.
519
-     * True when value is 1, true, 'true', 'yes'
520
-     *
521
-     * @since 1.07.10
522
-     *
523
-     * @param string $value The value to compare
524
-     * @return boolean True or False
525
-     */
514
+		}
515
+	}
516
+
517
+	/**
518
+	 * Check a value from a shortcode to see if true or false.
519
+	 * True when value is 1, true, 'true', 'yes'
520
+	 *
521
+	 * @since 1.07.10
522
+	 *
523
+	 * @param string $value The value to compare
524
+	 * @return boolean True or False
525
+	 */
526 526
 	public static function is_true( $value ) {
527
-        return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
528
-    }
527
+		return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
528
+	}
529 529
 
530
-    /**
531
-     * Used to filter shortcode in text widgets
532
-     */
533
-    public static function widget_text_filter_callback( $matches ) {
530
+	/**
531
+	 * Used to filter shortcode in text widgets
532
+	 */
533
+	public static function widget_text_filter_callback( $matches ) {
534 534
 		_deprecated_function( __METHOD__, '2.5.4' );
535
-        return do_shortcode( $matches[0] );
536
-    }
535
+		return do_shortcode( $matches[0] );
536
+	}
537 537
 
538
-    public static function get_pages() {
538
+	public static function get_pages() {
539 539
 		return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ) );
540
-    }
540
+	}
541 541
 
542
-    public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
543
-        $pages = self::get_pages();
542
+	public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
543
+		$pages = self::get_pages();
544 544
 		$selected = self::get_post_param( $field_name, $page_id, 'absint' );
545
-    ?>
545
+	?>
546 546
         <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" class="frm-pages-dropdown">
547 547
             <option value=""> </option>
548 548
             <?php foreach ( $pages as $page ) { ?>
@@ -552,108 +552,108 @@  discard block
 block discarded – undo
552 552
             <?php } ?>
553 553
         </select>
554 554
     <?php
555
-    }
555
+	}
556 556
 
557 557
 	public static function post_edit_link( $post_id ) {
558
-        $post = get_post($post_id);
559
-        if ( $post ) {
558
+		$post = get_post($post_id);
559
+		if ( $post ) {
560 560
 			$post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
561 561
 			return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
562
-        }
563
-        return '';
564
-    }
562
+		}
563
+		return '';
564
+	}
565 565
 
566 566
 	public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
567
-    ?>
567
+	?>
568 568
         <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" <?php
569
-            echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : '';
570
-            ?> class="frm_multiselect">
569
+			echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : '';
570
+			?> class="frm_multiselect">
571 571
             <?php self::roles_options($capability); ?>
572 572
         </select>
573 573
     <?php
574
-    }
574
+	}
575 575
 
576 576
 	public static function roles_options( $capability ) {
577
-        global $frm_vars;
578
-        if ( isset($frm_vars['editable_roles']) ) {
579
-            $editable_roles = $frm_vars['editable_roles'];
580
-        } else {
581
-            $editable_roles = get_editable_roles();
582
-            $frm_vars['editable_roles'] = $editable_roles;
583
-        }
584
-
585
-        foreach ( $editable_roles as $role => $details ) {
586
-            $name = translate_user_role($details['name'] ); ?>
577
+		global $frm_vars;
578
+		if ( isset($frm_vars['editable_roles']) ) {
579
+			$editable_roles = $frm_vars['editable_roles'];
580
+		} else {
581
+			$editable_roles = get_editable_roles();
582
+			$frm_vars['editable_roles'] = $editable_roles;
583
+		}
584
+
585
+		foreach ( $editable_roles as $role => $details ) {
586
+			$name = translate_user_role($details['name'] ); ?>
587 587
         <option value="<?php echo esc_attr($role) ?>" <?php echo in_array($role, (array) $capability) ? ' selected="selected"' : ''; ?>><?php echo esc_attr($name) ?> </option>
588 588
 <?php
589
-            unset($role, $details);
590
-        }
591
-    }
589
+			unset($role, $details);
590
+		}
591
+	}
592 592
 
593 593
 	public static function frm_capabilities( $type = 'auto' ) {
594
-        $cap = array(
595
-            'frm_view_forms'        => __( 'View Forms and Templates', 'formidable' ),
596
-            'frm_edit_forms'        => __( 'Add/Edit Forms and Templates', 'formidable' ),
597
-            'frm_delete_forms'      => __( 'Delete Forms and Templates', 'formidable' ),
598
-            'frm_change_settings'   => __( 'Access this Settings Page', 'formidable' ),
599
-            'frm_view_entries'      => __( 'View Entries from Admin Area', 'formidable' ),
600
-            'frm_delete_entries'    => __( 'Delete Entries from Admin Area', 'formidable' ),
601
-        );
594
+		$cap = array(
595
+			'frm_view_forms'        => __( 'View Forms and Templates', 'formidable' ),
596
+			'frm_edit_forms'        => __( 'Add/Edit Forms and Templates', 'formidable' ),
597
+			'frm_delete_forms'      => __( 'Delete Forms and Templates', 'formidable' ),
598
+			'frm_change_settings'   => __( 'Access this Settings Page', 'formidable' ),
599
+			'frm_view_entries'      => __( 'View Entries from Admin Area', 'formidable' ),
600
+			'frm_delete_entries'    => __( 'Delete Entries from Admin Area', 'formidable' ),
601
+		);
602 602
 
603 603
 		if ( ! self::pro_is_installed() && 'pro' != $type ) {
604
-            return $cap;
605
-        }
604
+			return $cap;
605
+		}
606 606
 
607
-        $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
608
-        $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
609
-        $cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
610
-        $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
607
+		$cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
608
+		$cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
609
+		$cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
610
+		$cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
611 611
 
612
-        return $cap;
613
-    }
612
+		return $cap;
613
+	}
614 614
 
615 615
 	public static function user_has_permission( $needed_role ) {
616
-        if ( $needed_role == '-1' ) {
617
-            return false;
616
+		if ( $needed_role == '-1' ) {
617
+			return false;
618 618
 		}
619 619
 
620
-        // $needed_role will be equal to blank if "Logged-in users" is selected
621
-        if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
622
-            return true;
623
-        }
620
+		// $needed_role will be equal to blank if "Logged-in users" is selected
621
+		if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
622
+			return true;
623
+		}
624 624
 
625
-        $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
626
-        foreach ( $roles as $role ) {
625
+		$roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
626
+		foreach ( $roles as $role ) {
627 627
 			if ( current_user_can( $role ) ) {
628
-        		return true;
628
+				return true;
629 629
 			}
630
-        	if ( $role == $needed_role ) {
631
-        		break;
630
+			if ( $role == $needed_role ) {
631
+				break;
632 632
 			}
633
-        }
634
-        return false;
635
-    }
636
-
637
-    /**
638
-     * Make sure administrators can see Formidable menu
639
-     *
640
-     * @since 2.0
641
-     */
642
-    public static function maybe_add_permissions() {
633
+		}
634
+		return false;
635
+	}
636
+
637
+	/**
638
+	 * Make sure administrators can see Formidable menu
639
+	 *
640
+	 * @since 2.0
641
+	 */
642
+	public static function maybe_add_permissions() {
643 643
 		self::force_capability( 'frm_view_entries' );
644 644
 
645
-        if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) {
646
-            return;
647
-        }
645
+		if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) {
646
+			return;
647
+		}
648 648
 
649 649
 		$user_id = get_current_user_id();
650 650
 		$user = new WP_User( $user_id );
651
-        $frm_roles = self::frm_capabilities();
652
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
651
+		$frm_roles = self::frm_capabilities();
652
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
653 653
 			$user->add_cap( $frm_role );
654
-            unset($frm_role, $frm_role_description);
655
-        }
656
-    }
654
+			unset($frm_role, $frm_role_description);
655
+		}
656
+	}
657 657
 
658 658
 	/**
659 659
 	 * Make sure admins have permission to see the menu items
@@ -669,28 +669,28 @@  discard block
 block discarded – undo
669 669
 		}
670 670
 	}
671 671
 
672
-    /**
673
-     * Check if the user has permision for action.
674
-     * Return permission message and stop the action if no permission
675
-     * @since 2.0
676
-     * @param string $permission
677
-     */
672
+	/**
673
+	 * Check if the user has permision for action.
674
+	 * Return permission message and stop the action if no permission
675
+	 * @since 2.0
676
+	 * @param string $permission
677
+	 */
678 678
 	public static function permission_check( $permission, $show_message = 'show' ) {
679
-        $permission_error = self::permission_nonce_error($permission);
680
-        if ( $permission_error !== false ) {
681
-            if ( 'hide' == $show_message ) {
682
-                $permission_error = '';
683
-            }
684
-            wp_die($permission_error);
685
-        }
686
-    }
687
-
688
-    /**
689
-     * Check user permission and nonce
690
-     * @since 2.0
691
-     * @param string $permission
692
-     * @return false|string The permission message or false if allowed
693
-     */
679
+		$permission_error = self::permission_nonce_error($permission);
680
+		if ( $permission_error !== false ) {
681
+			if ( 'hide' == $show_message ) {
682
+				$permission_error = '';
683
+			}
684
+			wp_die($permission_error);
685
+		}
686
+	}
687
+
688
+	/**
689
+	 * Check user permission and nonce
690
+	 * @since 2.0
691
+	 * @param string $permission
692
+	 * @return false|string The permission message or false if allowed
693
+	 */
694 694
 	public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
695 695
 		if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
696 696
 			$frm_settings = self::get_settings();
@@ -698,23 +698,23 @@  discard block
 block discarded – undo
698 698
 		}
699 699
 
700 700
 		$error = false;
701
-        if ( empty($nonce_name) ) {
702
-            return $error;
703
-        }
701
+		if ( empty($nonce_name) ) {
702
+			return $error;
703
+		}
704 704
 
705
-        if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
706
-            $frm_settings = self::get_settings();
707
-            $error = $frm_settings->admin_permission;
708
-        }
705
+		if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
706
+			$frm_settings = self::get_settings();
707
+			$error = $frm_settings->admin_permission;
708
+		}
709 709
 
710
-        return $error;
711
-    }
710
+		return $error;
711
+	}
712 712
 
713
-    public static function checked( $values, $current ) {
713
+	public static function checked( $values, $current ) {
714 714
 		if ( self::check_selected( $values, $current ) ) {
715
-            echo ' checked="checked"';
715
+			echo ' checked="checked"';
716 716
 		}
717
-    }
717
+	}
718 718
 
719 719
 	public static function check_selected( $values, $current ) {
720 720
 		$values = self::recursive_function_map( $values, 'trim' );
@@ -724,50 +724,50 @@  discard block
 block discarded – undo
724 724
 		return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current );
725 725
 	}
726 726
 
727
-    /**
728
-    * Check if current field option is an "other" option
729
-    *
730
-    * @since 2.0
731
-    *
732
-    * @param string $opt_key
733
-    * @return boolean Returns true if current field option is an "Other" option
734
-    */
735
-    public static function is_other_opt( $opt_key ) {
736
-        _deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::is_other_opt' );
737
-        return FrmFieldsHelper::is_other_opt( $opt_key );
738
-    }
739
-
740
-    /**
741
-    * Get value that belongs in "Other" text box
742
-    *
743
-    * @since 2.0
744
-    *
745
-    * @param string $opt_key
746
-    * @param array $field
747
-    * @return string $other_val
748
-    */
749
-    public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) {
727
+	/**
728
+	 * Check if current field option is an "other" option
729
+	 *
730
+	 * @since 2.0
731
+	 *
732
+	 * @param string $opt_key
733
+	 * @return boolean Returns true if current field option is an "Other" option
734
+	 */
735
+	public static function is_other_opt( $opt_key ) {
736
+		_deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::is_other_opt' );
737
+		return FrmFieldsHelper::is_other_opt( $opt_key );
738
+	}
739
+
740
+	/**
741
+	 * Get value that belongs in "Other" text box
742
+	 *
743
+	 * @since 2.0
744
+	 *
745
+	 * @param string $opt_key
746
+	 * @param array $field
747
+	 * @return string $other_val
748
+	 */
749
+	public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) {
750 750
 		_deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::get_other_val' );
751 751
 		return FrmFieldsHelper::get_other_val( compact( 'opt_key', 'field', 'parent', 'pointer' ) );
752
-    }
753
-
754
-    /**
755
-    * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
756
-    * Intended for front-end use
757
-    *
758
-    * @since 2.0
759
-    *
760
-    * @param array $field
761
-    * @param boolean $other_opt
762
-    * @param string $checked
763
-    * @param array $args should include opt_key and field name
764
-    * @return string $other_val
765
-    */
766
-    public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ) {
752
+	}
753
+
754
+	/**
755
+	 * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
756
+	 * Intended for front-end use
757
+	 *
758
+	 * @since 2.0
759
+	 *
760
+	 * @param array $field
761
+	 * @param boolean $other_opt
762
+	 * @param string $checked
763
+	 * @param array $args should include opt_key and field name
764
+	 * @return string $other_val
765
+	 */
766
+	public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ) {
767 767
 		_deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::prepare_other_input' );
768 768
 		$args['field'] = $field;
769 769
 		return FrmFieldsHelper::prepare_other_input( $args, $other_opt, $checked );
770
-    }
770
+	}
771 771
 
772 772
 	public static function recursive_function_map( $value, $function ) {
773 773
 		if ( is_array( $value ) ) {
@@ -797,24 +797,24 @@  discard block
 block discarded – undo
797 797
 		return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
798 798
 	}
799 799
 
800
-    /**
801
-     * Flatten a multi-dimensional array
802
-     */
800
+	/**
801
+	 * Flatten a multi-dimensional array
802
+	 */
803 803
 	public static function array_flatten( $array, $keys = 'keep' ) {
804
-        $return = array();
805
-        foreach ( $array as $key => $value ) {
806
-            if ( is_array($value) ) {
804
+		$return = array();
805
+		foreach ( $array as $key => $value ) {
806
+			if ( is_array($value) ) {
807 807
 				$return = array_merge( $return, self::array_flatten( $value, $keys ) );
808
-            } else {
808
+			} else {
809 809
 				if ( $keys == 'keep' ) {
810 810
 					$return[ $key ] = $value;
811 811
 				} else {
812 812
 					$return[] = $value;
813 813
 				}
814
-            }
815
-        }
816
-        return $return;
817
-    }
814
+			}
815
+		}
816
+		return $return;
817
+	}
818 818
 
819 819
 	public static function esc_textarea( $text, $is_rich_text = false ) {
820 820
 		$safe_text = str_replace( '&quot;', '"', $text );
@@ -825,38 +825,38 @@  discard block
 block discarded – undo
825 825
 		return apply_filters( 'esc_textarea', $safe_text, $text );
826 826
 	}
827 827
 
828
-    /**
829
-     * Add auto paragraphs to text areas
830
-     * @since 2.0
831
-     */
828
+	/**
829
+	 * Add auto paragraphs to text areas
830
+	 * @since 2.0
831
+	 */
832 832
 	public static function use_wpautop( $content ) {
833
-        if ( apply_filters('frm_use_wpautop', true) ) {
834
-            $content = wpautop(str_replace( '<br>', '<br />', $content));
835
-        }
836
-        return $content;
837
-    }
833
+		if ( apply_filters('frm_use_wpautop', true) ) {
834
+			$content = wpautop(str_replace( '<br>', '<br />', $content));
835
+		}
836
+		return $content;
837
+	}
838 838
 
839 839
 	public static function replace_quotes( $val ) {
840
-        //Replace double quotes
840
+		//Replace double quotes
841 841
 		$val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
842
-        //Replace single quotes
843
-        $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
844
-        return $val;
845
-    }
846
-
847
-    /**
848
-     * @since 2.0
849
-     * @return string The base Google APIS url for the current version of jQuery UI
850
-     */
851
-    public static function jquery_ui_base_url() {
842
+		//Replace single quotes
843
+		$val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
844
+		return $val;
845
+	}
846
+
847
+	/**
848
+	 * @since 2.0
849
+	 * @return string The base Google APIS url for the current version of jQuery UI
850
+	 */
851
+	public static function jquery_ui_base_url() {
852 852
 		$url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core', '1.11.4' );
853
-        $url = apply_filters('frm_jquery_ui_base_url', $url);
854
-        return $url;
855
-    }
853
+		$url = apply_filters('frm_jquery_ui_base_url', $url);
854
+		return $url;
855
+	}
856 856
 
857
-    /**
858
-     * @param string $handle
859
-     */
857
+	/**
858
+	 * @param string $handle
859
+	 */
860 860
 	public static function script_version( $handle, $default = 0 ) {
861 861
 		global $wp_scripts;
862 862
 		if ( ! $wp_scripts ) {
@@ -878,242 +878,242 @@  discard block
 block discarded – undo
878 878
 
879 879
 	public static function js_redirect( $url ) {
880 880
 		return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
881
-    }
881
+	}
882 882
 
883 883
 	public static function get_user_id_param( $user_id ) {
884
-        if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) {
885
-            return $user_id;
886
-        }
884
+		if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) {
885
+			return $user_id;
886
+		}
887 887
 
888 888
 		$user_id = sanitize_text_field( $user_id );
889 889
 		if ( $user_id == 'current' ) {
890 890
 			$user_id = get_current_user_id();
891 891
 		} else {
892
-            if ( is_email($user_id) ) {
893
-                $user = get_user_by('email', $user_id);
894
-            } else {
895
-                $user = get_user_by('login', $user_id);
896
-            }
892
+			if ( is_email($user_id) ) {
893
+				$user = get_user_by('email', $user_id);
894
+			} else {
895
+				$user = get_user_by('login', $user_id);
896
+			}
897 897
 
898
-            if ( $user ) {
899
-                $user_id = $user->ID;
900
-            }
901
-            unset($user);
902
-        }
898
+			if ( $user ) {
899
+				$user_id = $user->ID;
900
+			}
901
+			unset($user);
902
+		}
903 903
 
904
-        return $user_id;
905
-    }
904
+		return $user_id;
905
+	}
906 906
 
907 907
 	public static function get_file_contents( $filename, $atts = array() ) {
908
-        if ( ! is_file($filename) ) {
909
-            return false;
910
-        }
911
-
912
-        extract($atts);
913
-        ob_start();
914
-        include($filename);
915
-        $contents = ob_get_contents();
916
-        ob_end_clean();
917
-        return $contents;
918
-    }
919
-
920
-    /**
921
-     * @param string $table_name
922
-     * @param string $column
908
+		if ( ! is_file($filename) ) {
909
+			return false;
910
+		}
911
+
912
+		extract($atts);
913
+		ob_start();
914
+		include($filename);
915
+		$contents = ob_get_contents();
916
+		ob_end_clean();
917
+		return $contents;
918
+	}
919
+
920
+	/**
921
+	 * @param string $table_name
922
+	 * @param string $column
923 923
 	 * @param int $id
924 924
 	 * @param int $num_chars
925
-     */
926
-    public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
927
-        $key = '';
925
+	 */
926
+	public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
927
+		$key = '';
928 928
 
929
-        if ( ! empty( $name ) ) {
930
-            $key = sanitize_key($name);
931
-        }
929
+		if ( ! empty( $name ) ) {
930
+			$key = sanitize_key($name);
931
+		}
932 932
 
933 933
 		if ( empty( $key ) ) {
934
-            $max_slug_value = pow(36, $num_chars);
935
-            $min_slug_value = 37; // we want to have at least 2 characters in the slug
936
-            $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
937
-        }
934
+			$max_slug_value = pow(36, $num_chars);
935
+			$min_slug_value = 37; // we want to have at least 2 characters in the slug
936
+			$key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
937
+		}
938 938
 
939 939
 		if ( is_numeric($key) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
940 940
 			$key = $key . 'a';
941
-        }
941
+		}
942 942
 
943 943
 		$key_check = FrmDb::get_var( $table_name, array( $column => $key, 'ID !' => $id ), $column );
944 944
 
945
-        if ( $key_check || is_numeric($key_check) ) {
946
-            $suffix = 2;
945
+		if ( $key_check || is_numeric($key_check) ) {
946
+			$suffix = 2;
947 947
 			do {
948 948
 				$alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
949 949
 				$key_check = FrmDb::get_var( $table_name, array( $column => $alt_post_name, 'ID !' => $id ), $column );
950 950
 				$suffix++;
951 951
 			} while ( $key_check || is_numeric( $key_check ) );
952 952
 			$key = $alt_post_name;
953
-        }
954
-        return $key;
955
-    }
956
-
957
-    /**
958
-     * Editing a Form or Entry
959
-     * @param string $table
960
-     * @return bool|array
961
-     */
962
-    public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
963
-        if ( ! $record ) {
964
-            return false;
965
-        }
966
-
967
-        if ( empty($post_values) ) {
968
-            $post_values = stripslashes_deep($_POST);
969
-        }
953
+		}
954
+		return $key;
955
+	}
956
+
957
+	/**
958
+	 * Editing a Form or Entry
959
+	 * @param string $table
960
+	 * @return bool|array
961
+	 */
962
+	public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
963
+		if ( ! $record ) {
964
+			return false;
965
+		}
966
+
967
+		if ( empty($post_values) ) {
968
+			$post_values = stripslashes_deep($_POST);
969
+		}
970 970
 
971 971
 		$values = array( 'id' => $record->id, 'fields' => array() );
972 972
 
973 973
 		foreach ( array( 'name', 'description' ) as $var ) {
974
-            $default_val = isset($record->{$var}) ? $record->{$var} : '';
974
+			$default_val = isset($record->{$var}) ? $record->{$var} : '';
975 975
 			$values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
976
-            unset($var, $default_val);
977
-        }
978
-
979
-        $values['description'] = self::use_wpautop($values['description']);
980
-        $frm_settings = self::get_settings();
981
-        $is_form_builder = self::is_admin_page('formidable' );
982
-
983
-        foreach ( (array) $fields as $field ) {
984
-            // Make sure to filter default values (for placeholder text), but not on the form builder page
985
-            if ( ! $is_form_builder ) {
986
-                $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
987
-            }
976
+			unset($var, $default_val);
977
+		}
978
+
979
+		$values['description'] = self::use_wpautop($values['description']);
980
+		$frm_settings = self::get_settings();
981
+		$is_form_builder = self::is_admin_page('formidable' );
982
+
983
+		foreach ( (array) $fields as $field ) {
984
+			// Make sure to filter default values (for placeholder text), but not on the form builder page
985
+			if ( ! $is_form_builder ) {
986
+				$field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
987
+			}
988 988
 			$parent_form_id = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
989 989
 			self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings', 'parent_form_id' ) );
990
-        }
990
+		}
991 991
 
992
-        self::fill_form_opts($record, $table, $post_values, $values);
992
+		self::fill_form_opts($record, $table, $post_values, $values);
993 993
 
994
-        if ( $table == 'entries' ) {
995
-            $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
996
-        } else if ( $table == 'forms' ) {
997
-            $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
998
-        }
994
+		if ( $table == 'entries' ) {
995
+			$values = FrmEntriesHelper::setup_edit_vars( $values, $record );
996
+		} else if ( $table == 'forms' ) {
997
+			$values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
998
+		}
999 999
 
1000
-        return $values;
1001
-    }
1000
+		return $values;
1001
+	}
1002 1002
 
1003 1003
 	private static function fill_field_defaults( $field, $record, array &$values, $args ) {
1004
-        $post_values = $args['post_values'];
1005
-
1006
-        if ( $args['default'] ) {
1007
-            $meta_value = $field->default_value;
1008
-        } else {
1009
-            if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) {
1010
-                if ( ! isset($field->field_options['custom_field']) ) {
1011
-                    $field->field_options['custom_field'] = '';
1012
-                }
1004
+		$post_values = $args['post_values'];
1005
+
1006
+		if ( $args['default'] ) {
1007
+			$meta_value = $field->default_value;
1008
+		} else {
1009
+			if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) {
1010
+				if ( ! isset($field->field_options['custom_field']) ) {
1011
+					$field->field_options['custom_field'] = '';
1012
+				}
1013 1013
 				$meta_value = FrmProEntryMetaHelper::get_post_value( $record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array( 'truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field ) );
1014
-            } else {
1014
+			} else {
1015 1015
 				$meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
1016
-            }
1017
-        }
1016
+			}
1017
+		}
1018 1018
 
1019 1019
 		$field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1020
-        $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1021
-
1022
-        $field_array = array(
1023
-            'id'            => $field->id,
1024
-            'value'         => $new_value,
1025
-            'default_value' => $field->default_value,
1026
-            'name'          => $field->name,
1027
-            'description'   => $field->description,
1028
-            'type'          => apply_filters('frm_field_type', $field_type, $field, $new_value),
1029
-            'options'       => $field->options,
1030
-            'required'      => $field->required,
1031
-            'field_key'     => $field->field_key,
1032
-            'field_order'   => $field->field_order,
1033
-            'form_id'       => $field->form_id,
1020
+		$new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1021
+
1022
+		$field_array = array(
1023
+			'id'            => $field->id,
1024
+			'value'         => $new_value,
1025
+			'default_value' => $field->default_value,
1026
+			'name'          => $field->name,
1027
+			'description'   => $field->description,
1028
+			'type'          => apply_filters('frm_field_type', $field_type, $field, $new_value),
1029
+			'options'       => $field->options,
1030
+			'required'      => $field->required,
1031
+			'field_key'     => $field->field_key,
1032
+			'field_order'   => $field->field_order,
1033
+			'form_id'       => $field->form_id,
1034 1034
 			'parent_form_id' => $args['parent_form_id'],
1035
-        );
1035
+		);
1036 1036
 
1037
-        $args['field_type'] = $field_type;
1038
-        self::fill_field_opts($field, $field_array, $args);
1037
+		$args['field_type'] = $field_type;
1038
+		self::fill_field_opts($field, $field_array, $args);
1039 1039
 		// Track the original field's type
1040 1040
 		$field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type;
1041 1041
 
1042
-        $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $values['id'], array() );
1042
+		$field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $values['id'], array() );
1043 1043
 
1044
-        if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) {
1045
-            $field_array['unique_msg'] = '';
1046
-        }
1044
+		if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) {
1045
+			$field_array['unique_msg'] = '';
1046
+		}
1047 1047
 
1048
-        $field_array = array_merge( $field->field_options, $field_array );
1048
+		$field_array = array_merge( $field->field_options, $field_array );
1049 1049
 
1050
-        $values['fields'][ $field->id ] = $field_array;
1051
-    }
1050
+		$values['fields'][ $field->id ] = $field_array;
1051
+	}
1052 1052
 
1053 1053
 	private static function fill_field_opts( $field, array &$field_array, $args ) {
1054
-        $post_values = $args['post_values'];
1055
-        $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
1054
+		$post_values = $args['post_values'];
1055
+		$opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
1056 1056
 
1057
-        foreach ( $opt_defaults as $opt => $default_opt ) {
1057
+		foreach ( $opt_defaults as $opt => $default_opt ) {
1058 1058
 			$field_array[ $opt ] = ( $post_values && isset( $post_values['field_options'][ $opt . '_' . $field->id ] ) ) ? maybe_unserialize( $post_values['field_options'][ $opt . '_' . $field->id ] ) : ( isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default_opt );
1059
-            if ( $opt == 'blank' && $field_array[ $opt ] == '' ) {
1060
-                $field_array[ $opt ] = $args['frm_settings']->blank_msg;
1061
-            } else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) {
1062
-                if ( $args['field_type'] == 'captcha' ) {
1063
-                    $field_array[ $opt ] = $args['frm_settings']->re_msg;
1064
-                } else {
1065
-                    $field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
1066
-                }
1067
-            }
1068
-        }
1069
-
1070
-        if ( $field_array['custom_html'] == '' ) {
1071
-            $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']);
1072
-        }
1073
-    }
1074
-
1075
-    /**
1076
-     * @param string $table
1077
-     */
1059
+			if ( $opt == 'blank' && $field_array[ $opt ] == '' ) {
1060
+				$field_array[ $opt ] = $args['frm_settings']->blank_msg;
1061
+			} else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) {
1062
+				if ( $args['field_type'] == 'captcha' ) {
1063
+					$field_array[ $opt ] = $args['frm_settings']->re_msg;
1064
+				} else {
1065
+					$field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
1066
+				}
1067
+			}
1068
+		}
1069
+
1070
+		if ( $field_array['custom_html'] == '' ) {
1071
+			$field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']);
1072
+		}
1073
+	}
1074
+
1075
+	/**
1076
+	 * @param string $table
1077
+	 */
1078 1078
 	private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
1079
-        if ( $table == 'entries' ) {
1080
-            $form = $record->form_id;
1079
+		if ( $table == 'entries' ) {
1080
+			$form = $record->form_id;
1081 1081
 			FrmForm::maybe_get_form( $form );
1082
-        } else {
1083
-            $form = $record;
1084
-        }
1082
+		} else {
1083
+			$form = $record;
1084
+		}
1085 1085
 
1086
-        if ( ! $form ) {
1087
-            return;
1088
-        }
1086
+		if ( ! $form ) {
1087
+			return;
1088
+		}
1089 1089
 
1090
-        $values['form_name'] = isset($record->form_id) ? $form->name : '';
1090
+		$values['form_name'] = isset($record->form_id) ? $form->name : '';
1091 1091
 		$values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
1092 1092
 
1093
-        if ( ! is_array($form->options) ) {
1094
-            return;
1095
-        }
1093
+		if ( ! is_array($form->options) ) {
1094
+			return;
1095
+		}
1096 1096
 
1097
-        foreach ( $form->options as $opt => $value ) {
1098
-            $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1099
-        }
1097
+		foreach ( $form->options as $opt => $value ) {
1098
+			$values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1099
+		}
1100 1100
 
1101
-        self::fill_form_defaults($post_values, $values);
1102
-    }
1101
+		self::fill_form_defaults($post_values, $values);
1102
+	}
1103 1103
 
1104
-    /**
1105
-     * Set to POST value or default
1106
-     */
1104
+	/**
1105
+	 * Set to POST value or default
1106
+	 */
1107 1107
 	private static function fill_form_defaults( $post_values, array &$values ) {
1108
-        $form_defaults = FrmFormsHelper::get_default_opts();
1108
+		$form_defaults = FrmFormsHelper::get_default_opts();
1109 1109
 
1110
-        foreach ( $form_defaults as $opt => $default ) {
1111
-            if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1110
+		foreach ( $form_defaults as $opt => $default ) {
1111
+			if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1112 1112
 				$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1113
-            }
1113
+			}
1114 1114
 
1115
-            unset($opt, $defaut);
1116
-        }
1115
+			unset($opt, $defaut);
1116
+		}
1117 1117
 
1118 1118
 		if ( ! isset( $values['custom_style'] ) ) {
1119 1119
 			$values['custom_style'] = self::custom_style_value( $post_values );
@@ -1122,10 +1122,10 @@  discard block
 block discarded – undo
1122 1122
 		foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1123 1123
 			if ( ! isset( $values[ $h . '_html' ] ) ) {
1124 1124
 				$values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1125
-            }
1126
-            unset($h);
1127
-        }
1128
-    }
1125
+			}
1126
+			unset($h);
1127
+		}
1128
+	}
1129 1129
 
1130 1130
 	/**
1131 1131
 	 * @since 2.2.10
@@ -1148,59 +1148,59 @@  discard block
 block discarded – undo
1148 1148
 	}
1149 1149
 
1150 1150
 	public static function insert_opt_html( $args ) {
1151
-        $class = '';
1152
-        if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) {
1153
-            $class .= 'show_frm_not_email_to';
1154
-        }
1155
-    ?>
1151
+		$class = '';
1152
+		if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) {
1153
+			$class .= 'show_frm_not_email_to';
1154
+		}
1155
+	?>
1156 1156
 <li>
1157 1157
     <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>
1158 1158
     <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>
1159 1159
     <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>
1160 1160
 </li>
1161 1161
     <?php
1162
-    }
1162
+	}
1163 1163
 
1164 1164
 	public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
1165
-        if ( is_array( $str ) ) {
1166
-            return '';
1165
+		if ( is_array( $str ) ) {
1166
+			return '';
1167 1167
 		}
1168 1168
 
1169
-        $length = (int) $length;
1169
+		$length = (int) $length;
1170 1170
 		$str = wp_strip_all_tags( $str );
1171 1171
 		$original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
1172 1172
 
1173 1173
 		if ( $length == 0 ) {
1174
-            return '';
1175
-        } else if ( $length <= 10 ) {
1174
+			return '';
1175
+		} else if ( $length <= 10 ) {
1176 1176
 			$sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
1177
-            return $sub . (($length < $original_len) ? $continue : '');
1178
-        }
1177
+			return $sub . (($length < $original_len) ? $continue : '');
1178
+		}
1179 1179
 
1180
-        $sub = '';
1181
-        $len = 0;
1180
+		$sub = '';
1181
+		$len = 0;
1182 1182
 
1183 1183
 		$words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1184 1184
 
1185 1185
 		foreach ( $words as $word ) {
1186
-            $part = (($sub != '') ? ' ' : '') . $word;
1186
+			$part = (($sub != '') ? ' ' : '') . $word;
1187 1187
 			$total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1188
-            if ( $total_len > $length && str_word_count($sub) ) {
1189
-                break;
1190
-            }
1188
+			if ( $total_len > $length && str_word_count($sub) ) {
1189
+				break;
1190
+			}
1191 1191
 
1192
-            $sub .= $part;
1192
+			$sub .= $part;
1193 1193
 			$len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1194 1194
 
1195
-            if ( str_word_count($sub) > $minword && $total_len >= $length ) {
1196
-                break;
1197
-            }
1195
+			if ( str_word_count($sub) > $minword && $total_len >= $length ) {
1196
+				break;
1197
+			}
1198 1198
 
1199
-            unset($total_len, $word);
1200
-        }
1199
+			unset($total_len, $word);
1200
+		}
1201 1201
 
1202
-        return $sub . (($len < $original_len) ? $continue : '');
1203
-    }
1202
+		return $sub . (($len < $original_len) ? $continue : '');
1203
+	}
1204 1204
 
1205 1205
 	public static function mb_function( $function_names, $args ) {
1206 1206
 		$mb_function_name = $function_names[0];
@@ -1212,18 +1212,18 @@  discard block
 block discarded – undo
1212 1212
 	}
1213 1213
 
1214 1214
 	public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1215
-        if ( empty($date) ) {
1216
-            return $date;
1217
-        }
1215
+		if ( empty($date) ) {
1216
+			return $date;
1217
+		}
1218 1218
 
1219
-        if ( empty($date_format) ) {
1220
-            $date_format = get_option('date_format');
1221
-        }
1219
+		if ( empty($date_format) ) {
1220
+			$date_format = get_option('date_format');
1221
+		}
1222 1222
 
1223
-        if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) {
1224
-            $frmpro_settings = new FrmProSettings();
1225
-            $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
1226
-        }
1223
+		if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) {
1224
+			$frmpro_settings = new FrmProSettings();
1225
+			$date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
1226
+		}
1227 1227
 
1228 1228
 		$formatted = self::get_localized_date( $date_format, $date );
1229 1229
 
@@ -1232,8 +1232,8 @@  discard block
 block discarded – undo
1232 1232
 			$formatted .= self::add_time_to_date( $time_format, $date );
1233 1233
 		}
1234 1234
 
1235
-        return $formatted;
1236
-    }
1235
+		return $formatted;
1236
+	}
1237 1237
 
1238 1238
 	private static function add_time_to_date( $time_format, $date ) {
1239 1239
 		if ( empty( $time_format ) ) {
@@ -1315,120 +1315,120 @@  discard block
 block discarded – undo
1315 1315
 		);
1316 1316
 	}
1317 1317
 
1318
-    // Pagination Methods
1318
+	// Pagination Methods
1319 1319
 
1320
-    /**
1321
-     * @param integer $current_p
1322
-     */
1320
+	/**
1321
+	 * @param integer $current_p
1322
+	 */
1323 1323
 	public static function get_last_record_num( $r_count, $current_p, $p_size ) {
1324 1324
 		return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
1325 1325
 	}
1326 1326
 
1327
-    /**
1328
-     * @param integer $current_p
1329
-     */
1330
-    public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1331
-        if ( $current_p == 1 ) {
1332
-            return 1;
1333
-        } else {
1334
-            return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1335
-        }
1336
-    }
1327
+	/**
1328
+	 * @param integer $current_p
1329
+	 */
1330
+	public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1331
+		if ( $current_p == 1 ) {
1332
+			return 1;
1333
+		} else {
1334
+			return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1335
+		}
1336
+	}
1337 1337
 
1338 1338
 	/**
1339 1339
 	 * @return array
1340 1340
 	 */
1341 1341
 	public static function json_to_array( $json_vars ) {
1342
-        $vars = array();
1343
-        foreach ( $json_vars as $jv ) {
1344
-            $jv_name = explode('[', $jv['name']);
1345
-            $last = count($jv_name) - 1;
1346
-            foreach ( $jv_name as $p => $n ) {
1347
-                $name = trim($n, ']');
1348
-                if ( ! isset($l1) ) {
1349
-                    $l1 = $name;
1350
-                }
1351
-
1352
-                if ( ! isset($l2) ) {
1353
-                    $l2 = $name;
1354
-                }
1355
-
1356
-                if ( ! isset($l3) ) {
1357
-                    $l3 = $name;
1358
-                }
1359
-
1360
-                $this_val = ( $p == $last ) ? $jv['value'] : array();
1361
-
1362
-                switch ( $p ) {
1363
-                    case 0:
1364
-                        $l1 = $name;
1365
-                        self::add_value_to_array( $name, $l1, $this_val, $vars );
1366
-                    break;
1367
-
1368
-                    case 1:
1369
-                        $l2 = $name;
1370
-                        self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1371
-                    break;
1372
-
1373
-                    case 2:
1374
-                        $l3 = $name;
1375
-                        self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1376
-                    break;
1377
-
1378
-                    case 3:
1379
-                        $l4 = $name;
1380
-                        self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1381
-                    break;
1382
-                }
1383
-
1384
-                unset($this_val, $n);
1385
-            }
1386
-
1387
-            unset($last, $jv);
1388
-        }
1389
-
1390
-        return $vars;
1391
-    }
1392
-
1393
-    /**
1394
-     * @param string $name
1395
-     * @param string $l1
1396
-     */
1397
-    public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1398
-        if ( $name == '' ) {
1399
-            $vars[] = $val;
1400
-        } else if ( ! isset( $vars[ $l1 ] ) ) {
1401
-            $vars[ $l1 ] = $val;
1402
-        }
1403
-    }
1342
+		$vars = array();
1343
+		foreach ( $json_vars as $jv ) {
1344
+			$jv_name = explode('[', $jv['name']);
1345
+			$last = count($jv_name) - 1;
1346
+			foreach ( $jv_name as $p => $n ) {
1347
+				$name = trim($n, ']');
1348
+				if ( ! isset($l1) ) {
1349
+					$l1 = $name;
1350
+				}
1351
+
1352
+				if ( ! isset($l2) ) {
1353
+					$l2 = $name;
1354
+				}
1355
+
1356
+				if ( ! isset($l3) ) {
1357
+					$l3 = $name;
1358
+				}
1359
+
1360
+				$this_val = ( $p == $last ) ? $jv['value'] : array();
1361
+
1362
+				switch ( $p ) {
1363
+					case 0:
1364
+						$l1 = $name;
1365
+						self::add_value_to_array( $name, $l1, $this_val, $vars );
1366
+					break;
1367
+
1368
+					case 1:
1369
+						$l2 = $name;
1370
+						self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1371
+					break;
1372
+
1373
+					case 2:
1374
+						$l3 = $name;
1375
+						self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1376
+					break;
1377
+
1378
+					case 3:
1379
+						$l4 = $name;
1380
+						self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1381
+					break;
1382
+				}
1383
+
1384
+				unset($this_val, $n);
1385
+			}
1386
+
1387
+			unset($last, $jv);
1388
+		}
1389
+
1390
+		return $vars;
1391
+	}
1392
+
1393
+	/**
1394
+	 * @param string $name
1395
+	 * @param string $l1
1396
+	 */
1397
+	public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1398
+		if ( $name == '' ) {
1399
+			$vars[] = $val;
1400
+		} else if ( ! isset( $vars[ $l1 ] ) ) {
1401
+			$vars[ $l1 ] = $val;
1402
+		}
1403
+	}
1404 1404
 
1405 1405
 	public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
1406
-        $tooltips = array(
1407
-            'action_title'  => __( 'Give this action a label for easy reference.', 'formidable' ),
1408
-            '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' ),
1409
-            'cc'            => __( 'Add CC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1410
-            'bcc'           => __( 'Add BCC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1411
-            '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' ),
1412
-            'from'          => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ),
1413
-            '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() ) ),
1414
-        );
1415
-
1416
-        if ( ! isset( $tooltips[ $name ] ) ) {
1417
-            return;
1418
-        }
1419
-
1420
-        if ( 'open' == $class ) {
1421
-            echo ' frm_help"';
1422
-        } else {
1423
-            echo ' class="frm_help"';
1424
-        }
1406
+		$tooltips = array(
1407
+			'action_title'  => __( 'Give this action a label for easy reference.', 'formidable' ),
1408
+			'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' ),
1409
+			'cc'            => __( 'Add CC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1410
+			'bcc'           => __( 'Add BCC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1411
+			'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' ),
1412
+			'from'          => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ),
1413
+			'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() ) ),
1414
+		);
1415
+
1416
+		if ( ! isset( $tooltips[ $name ] ) ) {
1417
+			return;
1418
+		}
1419
+
1420
+		if ( 'open' == $class ) {
1421
+			echo ' frm_help"';
1422
+		} else {
1423
+			echo ' class="frm_help"';
1424
+		}
1425 1425
 
1426 1426
 		echo ' title="' . esc_attr( $tooltips[ $name ] );
1427 1427
 
1428
-        if ( 'open' != $class ) {
1429
-            echo '"';
1430
-        }
1431
-    }
1428
+		if ( 'open' != $class ) {
1429
+			echo '"';
1430
+		}
1431
+	}
1432 1432
 
1433 1433
 	/**
1434 1434
 	 * Add the current_page class to that page in the form nav
@@ -1444,35 +1444,35 @@  discard block
 block discarded – undo
1444 1444
 		}
1445 1445
 	}
1446 1446
 
1447
-    /**
1448
-     * Prepare and json_encode post content
1449
-     *
1450
-     * @since 2.0
1451
-     *
1452
-     * @param array $post_content
1453
-     * @return string $post_content ( json encoded array )
1454
-     */
1455
-    public static function prepare_and_encode( $post_content ) {
1456
-        //Loop through array to strip slashes and add only the needed ones
1447
+	/**
1448
+	 * Prepare and json_encode post content
1449
+	 *
1450
+	 * @since 2.0
1451
+	 *
1452
+	 * @param array $post_content
1453
+	 * @return string $post_content ( json encoded array )
1454
+	 */
1455
+	public static function prepare_and_encode( $post_content ) {
1456
+		//Loop through array to strip slashes and add only the needed ones
1457 1457
 		foreach ( $post_content as $key => $val ) {
1458 1458
 			// Replace problematic characters (like &quot;)
1459 1459
 			$val = str_replace( '&quot;', '"', $val );
1460 1460
 
1461 1461
 			self::prepare_action_slashes( $val, $key, $post_content );
1462
-            unset( $key, $val );
1463
-        }
1462
+			unset( $key, $val );
1463
+		}
1464 1464
 
1465
-        // json_encode the array
1466
-        $post_content = json_encode( $post_content );
1465
+		// json_encode the array
1466
+		$post_content = json_encode( $post_content );
1467 1467
 
1468
-	    // add extra slashes for \r\n since WP strips them
1468
+		// add extra slashes for \r\n since WP strips them
1469 1469
 		$post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
1470 1470
 
1471
-        // allow for &quot
1472
-	    $post_content = str_replace( '&quot;', '\\"', $post_content );
1471
+		// allow for &quot
1472
+		$post_content = str_replace( '&quot;', '\\"', $post_content );
1473 1473
 
1474
-        return $post_content;
1475
-    }
1474
+		return $post_content;
1475
+	}
1476 1476
 
1477 1477
 	private static function prepare_action_slashes( $val, $key, &$post_content ) {
1478 1478
 		if ( ! isset( $post_content[ $key ] ) ) {
@@ -1494,64 +1494,64 @@  discard block
 block discarded – undo
1494 1494
 	}
1495 1495
 
1496 1496
 	public static function maybe_json_decode( $string ) {
1497
-        if ( is_array($string) ) {
1498
-            return $string;
1499
-        }
1497
+		if ( is_array($string) ) {
1498
+			return $string;
1499
+		}
1500 1500
 
1501
-        $new_string = json_decode($string, true);
1502
-        if ( function_exists('json_last_error') ) {
1501
+		$new_string = json_decode($string, true);
1502
+		if ( function_exists('json_last_error') ) {
1503 1503
 			// php 5.3+
1504
-            if ( json_last_error() == JSON_ERROR_NONE ) {
1505
-                $string = $new_string;
1506
-            }
1507
-        } else if ( isset($new_string) ) {
1504
+			if ( json_last_error() == JSON_ERROR_NONE ) {
1505
+				$string = $new_string;
1506
+			}
1507
+		} else if ( isset($new_string) ) {
1508 1508
 			// php < 5.3 fallback
1509
-            $string = $new_string;
1510
-        }
1511
-        return $string;
1512
-    }
1513
-
1514
-    /**
1515
-     * @since 1.07.10
1516
-     *
1517
-     * @param string $post_type The name of the post type that may need to be highlighted
1518
-     * echo The javascript to open and highlight the Formidable menu
1519
-     */
1509
+			$string = $new_string;
1510
+		}
1511
+		return $string;
1512
+	}
1513
+
1514
+	/**
1515
+	 * @since 1.07.10
1516
+	 *
1517
+	 * @param string $post_type The name of the post type that may need to be highlighted
1518
+	 * echo The javascript to open and highlight the Formidable menu
1519
+	 */
1520 1520
 	public static function maybe_highlight_menu( $post_type ) {
1521
-        global $post;
1521
+		global $post;
1522 1522
 
1523
-        if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
1524
-            return;
1525
-        }
1523
+		if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
1524
+			return;
1525
+		}
1526 1526
 
1527
-        if ( is_object($post) && $post->post_type != $post_type ) {
1528
-            return;
1529
-        }
1527
+		if ( is_object($post) && $post->post_type != $post_type ) {
1528
+			return;
1529
+		}
1530 1530
 
1531
-        self::load_admin_wide_js();
1532
-        echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1533
-    }
1531
+		self::load_admin_wide_js();
1532
+		echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1533
+	}
1534 1534
 
1535
-    /**
1536
-     * Load the JS file on non-Formidable pages in the admin area
1537
-     * @since 2.0
1538
-     */
1535
+	/**
1536
+	 * Load the JS file on non-Formidable pages in the admin area
1537
+	 * @since 2.0
1538
+	 */
1539 1539
 	public static function load_admin_wide_js( $load = true ) {
1540
-        $version = FrmAppHelper::plugin_version();
1540
+		$version = FrmAppHelper::plugin_version();
1541 1541
 		wp_register_script( 'formidable_admin_global', FrmAppHelper::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
1542 1542
 
1543
-        wp_localize_script( 'formidable_admin_global', 'frmGlobal', array(
1543
+		wp_localize_script( 'formidable_admin_global', 'frmGlobal', array(
1544 1544
 			'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
1545
-            'deauthorize'  => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1545
+			'deauthorize'  => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1546 1546
 			'url'          => FrmAppHelper::plugin_url(),
1547 1547
 			'loading'      => __( 'Loading&hellip;' ),
1548 1548
 			'nonce'        => wp_create_nonce( 'frm_ajax' ),
1549
-        ) );
1549
+		) );
1550 1550
 
1551 1551
 		if ( $load ) {
1552 1552
 			wp_enqueue_script( 'formidable_admin_global' );
1553 1553
 		}
1554
-    }
1554
+	}
1555 1555
 
1556 1556
 	/**
1557 1557
 	 * @since 2.0.9
@@ -1560,9 +1560,9 @@  discard block
 block discarded – undo
1560 1560
 		wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
1561 1561
 	}
1562 1562
 
1563
-    /**
1564
-     * @param string $location
1565
-     */
1563
+	/**
1564
+	 * @param string $location
1565
+	 */
1566 1566
 	public static function localize_script( $location ) {
1567 1567
 		$ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
1568 1568
 		$ajax_url = apply_filters( 'frm_ajax_url', $ajax_url );
@@ -1618,83 +1618,83 @@  discard block
 block discarded – undo
1618 1618
 		}
1619 1619
 	}
1620 1620
 
1621
-    /**
1621
+	/**
1622 1622
 	 * echo the message on the plugins listing page
1623
-     * @since 1.07.10
1624
-     *
1625
-     * @param float $min_version The version the add-on requires
1626
-     */
1623
+	 * @since 1.07.10
1624
+	 *
1625
+	 * @param float $min_version The version the add-on requires
1626
+	 */
1627 1627
 	public static function min_version_notice( $min_version ) {
1628
-        $frm_version = self::plugin_version();
1628
+		$frm_version = self::plugin_version();
1629 1629
 
1630
-        // check if Formidable meets minimum requirements
1631
-        if ( version_compare($frm_version, $min_version, '>=') ) {
1632
-            return;
1633
-        }
1630
+		// check if Formidable meets minimum requirements
1631
+		if ( version_compare($frm_version, $min_version, '>=') ) {
1632
+			return;
1633
+		}
1634 1634
 
1635
-        $wp_list_table = _get_list_table('WP_Plugins_List_Table');
1635
+		$wp_list_table = _get_list_table('WP_Plugins_List_Table');
1636 1636
 		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">' .
1637
-        __( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1638
-        '</div></td></tr>';
1639
-    }
1640
-
1641
-    public static function locales( $type = 'date' ) {
1642
-        $locales = array(
1643
-            'en' => __( 'English', 'formidable' ),    '' => __( 'English/Western', 'formidable' ),
1644
-            'af' => __( 'Afrikaans', 'formidable' ),  'sq' => __( 'Albanian', 'formidable' ),
1645
-            'ar' => __( 'Arabic', 'formidable' ),     'hy' => __( 'Armenian', 'formidable' ),
1646
-            'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ),
1647
-            'bs' => __( 'Bosnian', 'formidable' ),    'bg' => __( 'Bulgarian', 'formidable' ),
1648
-            'ca' => __( 'Catalan', 'formidable' ),    'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1649
-            'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1650
-            'hr' => __( 'Croatian', 'formidable' ),   'cs' => __( 'Czech', 'formidable' ),
1651
-            'da' => __( 'Danish', 'formidable' ),     'nl' => __( 'Dutch', 'formidable' ),
1652
-            'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ),
1653
-            'et' => __( 'Estonian', 'formidable' ),   'fo' => __( 'Faroese', 'formidable' ),
1654
-            'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ),
1655
-            'fi' => __( 'Finnish', 'formidable' ),    'fr' => __( 'French', 'formidable' ),
1656
-            'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ),
1657
-            'de' => __( 'German', 'formidable' ),     'de-AT' => __( 'German/Austria', 'formidable' ),
1658
-            'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ),
1659
-            'he' => __( 'Hebrew', 'formidable' ),     'iw' => __( 'Hebrew', 'formidable' ),
1660
-            'hi' => __( 'Hindi', 'formidable' ),      'hu' => __( 'Hungarian', 'formidable' ),
1661
-            'is' => __( 'Icelandic', 'formidable' ),  'id' => __( 'Indonesian', 'formidable' ),
1662
-            'it' => __( 'Italian', 'formidable' ),    'ja' => __( 'Japanese', 'formidable' ),
1663
-            'ko' => __( 'Korean', 'formidable' ),     'lv' => __( 'Latvian', 'formidable' ),
1664
-            'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ),
1665
-            'no' => __( 'Norwegian', 'formidable' ),  'pl' => __( 'Polish', 'formidable' ),
1666
-            'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1667
-            'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ),
1668
-            'ru' => __( 'Russian', 'formidable' ),    'sr' => __( 'Serbian', 'formidable' ),
1669
-            'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ),
1670
-            'sl' => __( 'Slovenian', 'formidable' ),  'es' => __( 'Spanish', 'formidable' ),
1671
-            'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ),
1672
-            'ta' => __( 'Tamil', 'formidable' ),      'th' => __( 'Thai', 'formidable' ),
1673
-            'tu' => __( 'Turkish', 'formidable' ),    'tr' => __( 'Turkish', 'formidable' ),
1674
-            'uk' => __( 'Ukranian', 'formidable' ),   'vi' => __( 'Vietnamese', 'formidable' ),
1675
-        );
1676
-
1677
-        if ( $type == 'captcha' ) {
1678
-            // remove the languages unavailable for the captcha
1679
-            $unset = array(
1680
-                '', 'af', 'sq', 'hy', 'az', 'eu', 'bs',
1681
-                'zh-HK', 'eo', 'et', 'fo', 'fr-CH',
1682
-                'he', 'is', 'ms', 'sr-SR', 'ta', 'tu',
1683
-            );
1684
-        } else {
1685
-            // remove the languages unavailable for the datepicker
1686
-            $unset = array(
1687
-                'en', 'fil', 'fr-CA', 'de-AT', 'de-AT',
1688
-                'de-CH', 'iw', 'hi', 'pt', 'pt-PT',
1689
-                'es-419', 'tr',
1690
-            );
1691
-        }
1692
-
1693
-        $locales = array_diff_key($locales, array_flip($unset));
1694
-        $locales = apply_filters('frm_locales', $locales);
1695
-
1696
-        return $locales;
1697
-    }
1637
+		__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1638
+		'</div></td></tr>';
1639
+	}
1640
+
1641
+	public static function locales( $type = 'date' ) {
1642
+		$locales = array(
1643
+			'en' => __( 'English', 'formidable' ),    '' => __( 'English/Western', 'formidable' ),
1644
+			'af' => __( 'Afrikaans', 'formidable' ),  'sq' => __( 'Albanian', 'formidable' ),
1645
+			'ar' => __( 'Arabic', 'formidable' ),     'hy' => __( 'Armenian', 'formidable' ),
1646
+			'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ),
1647
+			'bs' => __( 'Bosnian', 'formidable' ),    'bg' => __( 'Bulgarian', 'formidable' ),
1648
+			'ca' => __( 'Catalan', 'formidable' ),    'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1649
+			'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1650
+			'hr' => __( 'Croatian', 'formidable' ),   'cs' => __( 'Czech', 'formidable' ),
1651
+			'da' => __( 'Danish', 'formidable' ),     'nl' => __( 'Dutch', 'formidable' ),
1652
+			'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ),
1653
+			'et' => __( 'Estonian', 'formidable' ),   'fo' => __( 'Faroese', 'formidable' ),
1654
+			'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ),
1655
+			'fi' => __( 'Finnish', 'formidable' ),    'fr' => __( 'French', 'formidable' ),
1656
+			'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ),
1657
+			'de' => __( 'German', 'formidable' ),     'de-AT' => __( 'German/Austria', 'formidable' ),
1658
+			'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ),
1659
+			'he' => __( 'Hebrew', 'formidable' ),     'iw' => __( 'Hebrew', 'formidable' ),
1660
+			'hi' => __( 'Hindi', 'formidable' ),      'hu' => __( 'Hungarian', 'formidable' ),
1661
+			'is' => __( 'Icelandic', 'formidable' ),  'id' => __( 'Indonesian', 'formidable' ),
1662
+			'it' => __( 'Italian', 'formidable' ),    'ja' => __( 'Japanese', 'formidable' ),
1663
+			'ko' => __( 'Korean', 'formidable' ),     'lv' => __( 'Latvian', 'formidable' ),
1664
+			'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ),
1665
+			'no' => __( 'Norwegian', 'formidable' ),  'pl' => __( 'Polish', 'formidable' ),
1666
+			'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1667
+			'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ),
1668
+			'ru' => __( 'Russian', 'formidable' ),    'sr' => __( 'Serbian', 'formidable' ),
1669
+			'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ),
1670
+			'sl' => __( 'Slovenian', 'formidable' ),  'es' => __( 'Spanish', 'formidable' ),
1671
+			'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ),
1672
+			'ta' => __( 'Tamil', 'formidable' ),      'th' => __( 'Thai', 'formidable' ),
1673
+			'tu' => __( 'Turkish', 'formidable' ),    'tr' => __( 'Turkish', 'formidable' ),
1674
+			'uk' => __( 'Ukranian', 'formidable' ),   'vi' => __( 'Vietnamese', 'formidable' ),
1675
+		);
1676
+
1677
+		if ( $type == 'captcha' ) {
1678
+			// remove the languages unavailable for the captcha
1679
+			$unset = array(
1680
+				'', 'af', 'sq', 'hy', 'az', 'eu', 'bs',
1681
+				'zh-HK', 'eo', 'et', 'fo', 'fr-CH',
1682
+				'he', 'is', 'ms', 'sr-SR', 'ta', 'tu',
1683
+			);
1684
+		} else {
1685
+			// remove the languages unavailable for the datepicker
1686
+			$unset = array(
1687
+				'en', 'fil', 'fr-CA', 'de-AT', 'de-AT',
1688
+				'de-CH', 'iw', 'hi', 'pt', 'pt-PT',
1689
+				'es-419', 'tr',
1690
+			);
1691
+		}
1692
+
1693
+		$locales = array_diff_key($locales, array_flip($unset));
1694
+		$locales = apply_filters('frm_locales', $locales);
1695
+
1696
+		return $locales;
1697
+	}
1698 1698
 
1699 1699
 	/**
1700 1700
 	 * Prepare and save settings in styles and actions
@@ -1725,19 +1725,19 @@  discard block
 block discarded – undo
1725 1725
 		return FrmDb::save_json_post( $settings );
1726 1726
 	}
1727 1727
 
1728
-    /**
1729
-     * Check cache before fetching values and saving to cache
1730
-     *
1731
-     * @since 2.0
1728
+	/**
1729
+	 * Check cache before fetching values and saving to cache
1730
+	 *
1731
+	 * @since 2.0
1732 1732
 	 * @deprecated 2.06
1733
-     *
1734
-     * @param string $cache_key The unique name for this cache
1735
-     * @param string $group The name of the cache group
1736
-     * @param string $query If blank, don't run a db call
1737
-     * @param string $type The wpdb function to use with this query
1738
-     * @return mixed $results The cache or query results
1739
-     */
1740
-    public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
1733
+	 *
1734
+	 * @param string $cache_key The unique name for this cache
1735
+	 * @param string $group The name of the cache group
1736
+	 * @param string $query If blank, don't run a db call
1737
+	 * @param string $type The wpdb function to use with this query
1738
+	 * @return mixed $results The cache or query results
1739
+	 */
1740
+	public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
1741 1741
 		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1742 1742
 		return FrmDb::check_cache( $cache_key, $group, $query, $type, $time );
1743 1743
 	}
@@ -1765,32 +1765,32 @@  discard block
 block discarded – undo
1765 1765
 		return FrmDb::get_group_cached_keys( $group );
1766 1766
 	}
1767 1767
 
1768
-    /**
1769
-     * @since 2.0
1768
+	/**
1769
+	 * @since 2.0
1770 1770
 	 * @deprecated 2.06
1771
-     * @return mixed The cached value or false
1772
-     */
1771
+	 * @return mixed The cached value or false
1772
+	 */
1773 1773
 	public static function check_cache_and_transient( $cache_key ) {
1774 1774
 		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1775
-        return FrmDb::check_cache_and_transient( $cache_key );
1776
-    }
1775
+		return FrmDb::check_cache_and_transient( $cache_key );
1776
+	}
1777 1777
 
1778
-    /**
1779
-     * @since 2.0
1778
+	/**
1779
+	 * @since 2.0
1780 1780
 	 * @deprecated 2.06
1781
-     * @param string $cache_key
1782
-     */
1781
+	 * @param string $cache_key
1782
+	 */
1783 1783
 	public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
1784 1784
 		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1785 1785
 		FrmDb::delete_cache_and_transient( $cache_key, $group );
1786 1786
 	}
1787 1787
 
1788
-    /**
1789
-     * @since 2.0
1788
+	/**
1789
+	 * @since 2.0
1790 1790
 	 * @deprecated 2.06
1791
-     *
1792
-     * @param string $group The name of the cache group
1793
-     */
1791
+	 *
1792
+	 * @param string $group The name of the cache group
1793
+	 */
1794 1794
 	public static function cache_delete_group( $group ) {
1795 1795
 		_deprecated_function( __METHOD__, '2.06', 'FrmDb::' . __FUNCTION__ );
1796 1796
 		FrmDb::cache_delete_group( $group );
Please login to merge, or discard this patch.
Spacing   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
     }
24 24
 
25 25
     public static function plugin_folder() {
26
-        return basename(self::plugin_path());
26
+        return basename( self::plugin_path() );
27 27
     }
28 28
 
29 29
     public static function plugin_path() {
30
-        return dirname(dirname(dirname(__FILE__)));
30
+        return dirname( dirname( dirname( __FILE__ ) ) );
31 31
     }
32 32
 
33 33
     public static function plugin_url() {
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
      * @return string
55 55
      */
56 56
     public static function site_name() {
57
-        return get_option('blogname');
57
+        return get_option( 'blogname' );
58 58
     }
59 59
 
60 60
 	public static function make_affiliate_url( $url ) {
61 61
 		$affiliate_id = self::get_affiliate();
62 62
 		if ( ! empty( $affiliate_id ) ) {
63 63
 			$url = str_replace( array( 'http://', 'https://' ), '', $url );
64
-			$url = 'http://www.shareasale.com/r.cfm?u='. absint( $affiliate_id ) .'&b=841990&m=64739&afftrack=plugin&urllink=' . urlencode( $url );
64
+			$url = 'http://www.shareasale.com/r.cfm?u=' . absint( $affiliate_id ) . '&b=841990&m=64739&afftrack=plugin&urllink=' . urlencode( $url );
65 65
 		}
66 66
 		return $url;
67 67
 	}
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public static function get_settings() {
82 82
         global $frm_settings;
83
-        if ( empty($frm_settings) ) {
83
+        if ( empty( $frm_settings ) ) {
84 84
             $frm_settings = new FrmSettings();
85 85
         }
86 86
         return $frm_settings;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     }
110 110
 
111 111
     public static function pro_is_installed() {
112
-        return apply_filters('frm_pro_installed', false);
112
+        return apply_filters( 'frm_pro_installed', false );
113 113
     }
114 114
 
115 115
     /**
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      * @return boolean
154 154
      */
155 155
     public static function doing_ajax() {
156
-        return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
156
+        return defined( 'DOING_AJAX' ) && DOING_AJAX && ! self::is_preview_page();
157 157
     }
158 158
 
159 159
 	/**
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
      * @return boolean
174 174
      */
175 175
     public static function is_admin() {
176
-        return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX );
176
+        return is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX );
177 177
     }
178 178
 
179 179
     /**
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
      * @return string
201 201
      */
202 202
 	public static function get_server_value( $value ) {
203
-        return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
203
+        return isset( $_SERVER[$value] ) ? wp_strip_all_tags( $_SERVER[$value] ) : '';
204 204
     }
205 205
 
206 206
     /**
@@ -215,14 +215,14 @@  discard block
 block discarded – undo
215 215
             'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP',
216 216
             'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR',
217 217
         ) as $key ) {
218
-            if ( ! isset( $_SERVER[ $key ] ) ) {
218
+            if ( ! isset( $_SERVER[$key] ) ) {
219 219
                 continue;
220 220
             }
221 221
 
222
-            foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
223
-                $ip = trim($ip); // just to be safe
222
+            foreach ( explode( ',', $_SERVER[$key] ) as $ip ) {
223
+                $ip = trim( $ip ); // just to be safe
224 224
 
225
-                if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
225
+                if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
226 226
                     return $ip;
227 227
                 }
228 228
             }
@@ -232,15 +232,15 @@  discard block
 block discarded – undo
232 232
     }
233 233
 
234 234
     public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
235
-        if ( strpos($param, '[') ) {
236
-            $params = explode('[', $param);
235
+        if ( strpos( $param, '[' ) ) {
236
+            $params = explode( '[', $param );
237 237
             $param = $params[0];
238 238
         }
239 239
 
240 240
 		if ( $src == 'get' ) {
241
-            $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
242
-            if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
243
-                $value = stripslashes_deep( htmlspecialchars_decode( $_GET[ $param ] ) );
241
+            $value = isset( $_POST[$param] ) ? stripslashes_deep( $_POST[$param] ) : ( isset( $_GET[$param] ) ? stripslashes_deep( $_GET[$param] ) : $default );
242
+            if ( ! isset( $_POST[$param] ) && isset( $_GET[$param] ) && ! is_array( $value ) ) {
243
+                $value = stripslashes_deep( htmlspecialchars_decode( $_GET[$param] ) );
244 244
             }
245 245
 			self::sanitize_value( $sanitize, $value );
246 246
 		} else {
@@ -249,12 +249,12 @@  discard block
 block discarded – undo
249 249
 
250 250
 		if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
251 251
             foreach ( $params as $k => $p ) {
252
-                if ( ! $k || ! is_array($value) ) {
252
+                if ( ! $k || ! is_array( $value ) ) {
253 253
                     continue;
254 254
                 }
255 255
 
256
-                $p = trim($p, ']');
257
-                $value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
256
+                $p = trim( $p, ']' );
257
+                $value = isset( $value[$p] ) ? $value[$p] : $default;
258 258
             }
259 259
         }
260 260
 
@@ -293,16 +293,16 @@  discard block
 block discarded – undo
293 293
 
294 294
 		$value = $args['default'];
295 295
 		if ( $args['type'] == 'get' ) {
296
-			if ( $_GET && isset( $_GET[ $args['param'] ] ) ) {
297
-				$value = $_GET[ $args['param'] ];
296
+			if ( $_GET && isset( $_GET[$args['param']] ) ) {
297
+				$value = $_GET[$args['param']];
298 298
 			}
299 299
 		} else if ( $args['type'] == 'post' ) {
300
-			if ( isset( $_POST[ $args['param'] ] ) ) {
301
-				$value = stripslashes_deep( maybe_unserialize( $_POST[ $args['param'] ] ) );
300
+			if ( isset( $_POST[$args['param']] ) ) {
301
+				$value = stripslashes_deep( maybe_unserialize( $_POST[$args['param']] ) );
302 302
 			}
303 303
 		} else {
304
-			if ( isset( $_REQUEST[ $args['param'] ] ) ) {
305
-				$value = $_REQUEST[ $args['param'] ];
304
+			if ( isset( $_REQUEST[$args['param']] ) ) {
305
+				$value = $_REQUEST[$args['param']];
306 306
 			}
307 307
 		}
308 308
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 			if ( is_array( $value ) ) {
331 331
 				$temp_values = $value;
332 332
 				foreach ( $temp_values as $k => $v ) {
333
-					FrmAppHelper::sanitize_value( $sanitize, $value[ $k ] );
333
+					FrmAppHelper::sanitize_value( $sanitize, $value[$k] );
334 334
 				}
335 335
 			} else {
336 336
 				$value = call_user_func( $sanitize, $value );
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
     public static function sanitize_request( $sanitize_method, &$values ) {
342 342
         $temp_values = $values;
343 343
         foreach ( $temp_values as $k => $val ) {
344
-            if ( isset( $sanitize_method[ $k ] ) ) {
345
-				$values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
344
+            if ( isset( $sanitize_method[$k] ) ) {
345
+				$values[$k] = call_user_func( $sanitize_method[$k], $val );
346 346
             }
347 347
         }
348 348
     }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 	public static function sanitize_array( &$values ) {
351 351
 		$temp_values = $values;
352 352
 		foreach ( $temp_values as $k => $val ) {
353
-			$values[ $k ] = wp_kses_post( $val );
353
+			$values[$k] = wp_kses_post( $val );
354 354
 		}
355 355
 	}
356 356
 
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 			$allowed_html = $html;
378 378
 		} else {
379 379
 			foreach ( $allowed as $a ) {
380
-				$allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array();
380
+				$allowed_html[$a] = isset( $html[$a] ) ? $html[$a] : array();
381 381
 			}
382 382
 		}
383 383
 
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
      * @since 2.0
475 475
      */
476 476
     public static function remove_get_action() {
477
-        if ( ! isset($_GET) ) {
477
+        if ( ! isset( $_GET ) ) {
478 478
             return;
479 479
         }
480 480
 
@@ -496,8 +496,8 @@  discard block
 block discarded – undo
496 496
         }
497 497
 
498 498
         global $wp_query;
499
-        if ( isset( $wp_query->query_vars[ $param ] ) ) {
500
-            $value = $wp_query->query_vars[ $param ];
499
+        if ( isset( $wp_query->query_vars[$param] ) ) {
500
+            $value = $wp_query->query_vars[$param];
501 501
         }
502 502
 
503 503
         return $value;
@@ -536,17 +536,17 @@  discard block
 block discarded – undo
536 536
     }
537 537
 
538 538
     public static function get_pages() {
539
-		return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ) );
539
+		return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => - 1, 'orderby' => 'title', 'order' => 'ASC' ) );
540 540
     }
541 541
 
542 542
     public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
543 543
         $pages = self::get_pages();
544 544
 		$selected = self::get_post_param( $field_name, $page_id, 'absint' );
545 545
     ?>
546
-        <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" class="frm-pages-dropdown">
546
+        <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" class="frm-pages-dropdown">
547 547
             <option value=""> </option>
548 548
             <?php foreach ( $pages as $page ) { ?>
549
-				<option value="<?php echo esc_attr($page->ID); ?>" <?php selected( $selected, $page->ID ) ?>>
549
+				<option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( $selected, $page->ID ) ?>>
550 550
 					<?php echo esc_html( $truncate ? self::truncate( $page->post_title, $truncate ) : $page->post_title ); ?>
551 551
 				</option>
552 552
             <?php } ?>
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
     }
556 556
 
557 557
 	public static function post_edit_link( $post_id ) {
558
-        $post = get_post($post_id);
558
+        $post = get_post( $post_id );
559 559
         if ( $post ) {
560 560
 			$post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
561 561
 			return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
@@ -565,17 +565,17 @@  discard block
 block discarded – undo
565 565
 
566 566
 	public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
567 567
     ?>
568
-        <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" <?php
568
+        <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" <?php
569 569
             echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : '';
570 570
             ?> class="frm_multiselect">
571
-            <?php self::roles_options($capability); ?>
571
+            <?php self::roles_options( $capability ); ?>
572 572
         </select>
573 573
     <?php
574 574
     }
575 575
 
576 576
 	public static function roles_options( $capability ) {
577 577
         global $frm_vars;
578
-        if ( isset($frm_vars['editable_roles']) ) {
578
+        if ( isset( $frm_vars['editable_roles'] ) ) {
579 579
             $editable_roles = $frm_vars['editable_roles'];
580 580
         } else {
581 581
             $editable_roles = get_editable_roles();
@@ -583,10 +583,10 @@  discard block
 block discarded – undo
583 583
         }
584 584
 
585 585
         foreach ( $editable_roles as $role => $details ) {
586
-            $name = translate_user_role($details['name'] ); ?>
587
-        <option value="<?php echo esc_attr($role) ?>" <?php echo in_array($role, (array) $capability) ? ' selected="selected"' : ''; ?>><?php echo esc_attr($name) ?> </option>
586
+            $name = translate_user_role( $details['name'] ); ?>
587
+        <option value="<?php echo esc_attr( $role ) ?>" <?php echo in_array( $role, (array) $capability ) ? ' selected="selected"' : ''; ?>><?php echo esc_attr( $name ) ?> </option>
588 588
 <?php
589
-            unset($role, $details);
589
+            unset( $role, $details );
590 590
         }
591 591
     }
592 592
 
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
     public static function maybe_add_permissions() {
643 643
 		self::force_capability( 'frm_view_entries' );
644 644
 
645
-        if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) {
645
+        if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) {
646 646
             return;
647 647
         }
648 648
 
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
         $frm_roles = self::frm_capabilities();
652 652
         foreach ( $frm_roles as $frm_role => $frm_role_description ) {
653 653
 			$user->add_cap( $frm_role );
654
-            unset($frm_role, $frm_role_description);
654
+            unset( $frm_role, $frm_role_description );
655 655
         }
656 656
     }
657 657
 
@@ -676,12 +676,12 @@  discard block
 block discarded – undo
676 676
      * @param string $permission
677 677
      */
678 678
 	public static function permission_check( $permission, $show_message = 'show' ) {
679
-        $permission_error = self::permission_nonce_error($permission);
679
+        $permission_error = self::permission_nonce_error( $permission );
680 680
         if ( $permission_error !== false ) {
681 681
             if ( 'hide' == $show_message ) {
682 682
                 $permission_error = '';
683 683
             }
684
-            wp_die($permission_error);
684
+            wp_die( $permission_error );
685 685
         }
686 686
     }
687 687
 
@@ -698,11 +698,11 @@  discard block
 block discarded – undo
698 698
 		}
699 699
 
700 700
 		$error = false;
701
-        if ( empty($nonce_name) ) {
701
+        if ( empty( $nonce_name ) ) {
702 702
             return $error;
703 703
         }
704 704
 
705
-        if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
705
+        if ( $_REQUEST && ( ! isset( $_REQUEST[$nonce_name] ) || ! wp_verify_nonce( $_REQUEST[$nonce_name], $nonce ) ) ) {
706 706
             $frm_settings = self::get_settings();
707 707
             $error = $frm_settings->admin_permission;
708 708
         }
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
 			} else {
783 783
 				foreach ( $value as $k => $v ) {
784 784
 					if ( ! is_array( $v ) ) {
785
-						$value[ $k ] = call_user_func( $original_function, $v );
785
+						$value[$k] = call_user_func( $original_function, $v );
786 786
 					}
787 787
 				}
788 788
 			}
@@ -803,11 +803,11 @@  discard block
 block discarded – undo
803 803
 	public static function array_flatten( $array, $keys = 'keep' ) {
804 804
         $return = array();
805 805
         foreach ( $array as $key => $value ) {
806
-            if ( is_array($value) ) {
806
+            if ( is_array( $value ) ) {
807 807
 				$return = array_merge( $return, self::array_flatten( $value, $keys ) );
808 808
             } else {
809 809
 				if ( $keys == 'keep' ) {
810
-					$return[ $key ] = $value;
810
+					$return[$key] = $value;
811 811
 				} else {
812 812
 					$return[] = $value;
813 813
 				}
@@ -830,8 +830,8 @@  discard block
 block discarded – undo
830 830
      * @since 2.0
831 831
      */
832 832
 	public static function use_wpautop( $content ) {
833
-        if ( apply_filters('frm_use_wpautop', true) ) {
834
-            $content = wpautop(str_replace( '<br>', '<br />', $content));
833
+        if ( apply_filters( 'frm_use_wpautop', true ) ) {
834
+            $content = wpautop( str_replace( '<br>', '<br />', $content ) );
835 835
         }
836 836
         return $content;
837 837
     }
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
      */
851 851
     public static function jquery_ui_base_url() {
852 852
 		$url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core', '1.11.4' );
853
-        $url = apply_filters('frm_jquery_ui_base_url', $url);
853
+        $url = apply_filters( 'frm_jquery_ui_base_url', $url );
854 854
         return $url;
855 855
     }
856 856
 
@@ -864,11 +864,11 @@  discard block
 block discarded – undo
864 864
 		}
865 865
 
866 866
 		$ver = $default;
867
-		if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
867
+		if ( ! isset( $wp_scripts->registered[$handle] ) ) {
868 868
 			return $ver;
869 869
 		}
870 870
 
871
-		$query = $wp_scripts->registered[ $handle ];
871
+		$query = $wp_scripts->registered[$handle];
872 872
 		if ( is_object( $query ) && ! empty( $query->ver ) ) {
873 873
 			$ver = $query->ver;
874 874
 		}
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
     }
882 882
 
883 883
 	public static function get_user_id_param( $user_id ) {
884
-        if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) {
884
+        if ( ! $user_id || empty( $user_id ) || is_numeric( $user_id ) ) {
885 885
             return $user_id;
886 886
         }
887 887
 
@@ -889,29 +889,29 @@  discard block
 block discarded – undo
889 889
 		if ( $user_id == 'current' ) {
890 890
 			$user_id = get_current_user_id();
891 891
 		} else {
892
-            if ( is_email($user_id) ) {
893
-                $user = get_user_by('email', $user_id);
892
+            if ( is_email( $user_id ) ) {
893
+                $user = get_user_by( 'email', $user_id );
894 894
             } else {
895
-                $user = get_user_by('login', $user_id);
895
+                $user = get_user_by( 'login', $user_id );
896 896
             }
897 897
 
898 898
             if ( $user ) {
899 899
                 $user_id = $user->ID;
900 900
             }
901
-            unset($user);
901
+            unset( $user );
902 902
         }
903 903
 
904 904
         return $user_id;
905 905
     }
906 906
 
907 907
 	public static function get_file_contents( $filename, $atts = array() ) {
908
-        if ( ! is_file($filename) ) {
908
+        if ( ! is_file( $filename ) ) {
909 909
             return false;
910 910
         }
911 911
 
912
-        extract($atts);
912
+        extract( $atts );
913 913
         ob_start();
914
-        include($filename);
914
+        include( $filename );
915 915
         $contents = ob_get_contents();
916 916
         ob_end_clean();
917 917
         return $contents;
@@ -927,27 +927,27 @@  discard block
 block discarded – undo
927 927
         $key = '';
928 928
 
929 929
         if ( ! empty( $name ) ) {
930
-            $key = sanitize_key($name);
930
+            $key = sanitize_key( $name );
931 931
         }
932 932
 
933 933
 		if ( empty( $key ) ) {
934
-            $max_slug_value = pow(36, $num_chars);
934
+            $max_slug_value = pow( 36, $num_chars );
935 935
             $min_slug_value = 37; // we want to have at least 2 characters in the slug
936
-            $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
936
+            $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
937 937
         }
938 938
 
939
-		if ( is_numeric($key) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
939
+		if ( is_numeric( $key ) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
940 940
 			$key = $key . 'a';
941 941
         }
942 942
 
943 943
 		$key_check = FrmDb::get_var( $table_name, array( $column => $key, 'ID !' => $id ), $column );
944 944
 
945
-        if ( $key_check || is_numeric($key_check) ) {
945
+        if ( $key_check || is_numeric( $key_check ) ) {
946 946
             $suffix = 2;
947 947
 			do {
948 948
 				$alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
949 949
 				$key_check = FrmDb::get_var( $table_name, array( $column => $alt_post_name, 'ID !' => $id ), $column );
950
-				$suffix++;
950
+				$suffix ++;
951 951
 			} while ( $key_check || is_numeric( $key_check ) );
952 952
 			$key = $alt_post_name;
953 953
         }
@@ -964,32 +964,32 @@  discard block
 block discarded – undo
964 964
             return false;
965 965
         }
966 966
 
967
-        if ( empty($post_values) ) {
968
-            $post_values = stripslashes_deep($_POST);
967
+        if ( empty( $post_values ) ) {
968
+            $post_values = stripslashes_deep( $_POST );
969 969
         }
970 970
 
971 971
 		$values = array( 'id' => $record->id, 'fields' => array() );
972 972
 
973 973
 		foreach ( array( 'name', 'description' ) as $var ) {
974
-            $default_val = isset($record->{$var}) ? $record->{$var} : '';
975
-			$values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
976
-            unset($var, $default_val);
974
+            $default_val = isset( $record->{$var}) ? $record->{$var} : '';
975
+			$values[$var] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
976
+            unset( $var, $default_val );
977 977
         }
978 978
 
979
-        $values['description'] = self::use_wpautop($values['description']);
979
+        $values['description'] = self::use_wpautop( $values['description'] );
980 980
         $frm_settings = self::get_settings();
981
-        $is_form_builder = self::is_admin_page('formidable' );
981
+        $is_form_builder = self::is_admin_page( 'formidable' );
982 982
 
983 983
         foreach ( (array) $fields as $field ) {
984 984
             // Make sure to filter default values (for placeholder text), but not on the form builder page
985 985
             if ( ! $is_form_builder ) {
986
-                $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
986
+                $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
987 987
             }
988 988
 			$parent_form_id = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
989
-			self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings', 'parent_form_id' ) );
989
+			self::fill_field_defaults( $field, $record, $values, compact( 'default', 'post_values', 'frm_settings', 'parent_form_id' ) );
990 990
         }
991 991
 
992
-        self::fill_form_opts($record, $table, $post_values, $values);
992
+        self::fill_form_opts( $record, $table, $post_values, $values );
993 993
 
994 994
         if ( $table == 'entries' ) {
995 995
             $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
@@ -1006,8 +1006,8 @@  discard block
 block discarded – undo
1006 1006
         if ( $args['default'] ) {
1007 1007
             $meta_value = $field->default_value;
1008 1008
         } else {
1009
-            if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) {
1010
-                if ( ! isset($field->field_options['custom_field']) ) {
1009
+            if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) {
1010
+                if ( ! isset( $field->field_options['custom_field'] ) ) {
1011 1011
                     $field->field_options['custom_field'] = '';
1012 1012
                 }
1013 1013
 				$meta_value = FrmProEntryMetaHelper::get_post_value( $record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array( 'truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field ) );
@@ -1016,8 +1016,8 @@  discard block
 block discarded – undo
1016 1016
             }
1017 1017
         }
1018 1018
 
1019
-		$field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1020
-        $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1019
+		$field_type = isset( $post_values['field_options']['type_' . $field->id] ) ? $post_values['field_options']['type_' . $field->id] : $field->type;
1020
+        $new_value = isset( $post_values['item_meta'][$field->id] ) ? maybe_unserialize( $post_values['item_meta'][$field->id] ) : $meta_value;
1021 1021
 
1022 1022
         $field_array = array(
1023 1023
             'id'            => $field->id,
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
             'default_value' => $field->default_value,
1026 1026
             'name'          => $field->name,
1027 1027
             'description'   => $field->description,
1028
-            'type'          => apply_filters('frm_field_type', $field_type, $field, $new_value),
1028
+            'type'          => apply_filters( 'frm_field_type', $field_type, $field, $new_value ),
1029 1029
             'options'       => $field->options,
1030 1030
             'required'      => $field->required,
1031 1031
             'field_key'     => $field->field_key,
@@ -1035,40 +1035,40 @@  discard block
 block discarded – undo
1035 1035
         );
1036 1036
 
1037 1037
         $args['field_type'] = $field_type;
1038
-        self::fill_field_opts($field, $field_array, $args);
1038
+        self::fill_field_opts( $field, $field_array, $args );
1039 1039
 		// Track the original field's type
1040 1040
 		$field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type;
1041 1041
 
1042 1042
         $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $values['id'], array() );
1043 1043
 
1044
-        if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) {
1044
+        if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) {
1045 1045
             $field_array['unique_msg'] = '';
1046 1046
         }
1047 1047
 
1048 1048
         $field_array = array_merge( $field->field_options, $field_array );
1049 1049
 
1050
-        $values['fields'][ $field->id ] = $field_array;
1050
+        $values['fields'][$field->id] = $field_array;
1051 1051
     }
1052 1052
 
1053 1053
 	private static function fill_field_opts( $field, array &$field_array, $args ) {
1054 1054
         $post_values = $args['post_values'];
1055
-        $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
1055
+        $opt_defaults = FrmFieldsHelper::get_default_field_opts( $field_array['type'], $field, true );
1056 1056
 
1057 1057
         foreach ( $opt_defaults as $opt => $default_opt ) {
1058
-			$field_array[ $opt ] = ( $post_values && isset( $post_values['field_options'][ $opt . '_' . $field->id ] ) ) ? maybe_unserialize( $post_values['field_options'][ $opt . '_' . $field->id ] ) : ( isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default_opt );
1059
-            if ( $opt == 'blank' && $field_array[ $opt ] == '' ) {
1060
-                $field_array[ $opt ] = $args['frm_settings']->blank_msg;
1061
-            } else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) {
1058
+			$field_array[$opt] = ( $post_values && isset( $post_values['field_options'][$opt . '_' . $field->id] ) ) ? maybe_unserialize( $post_values['field_options'][$opt . '_' . $field->id] ) : ( isset( $field->field_options[$opt] ) ? $field->field_options[$opt] : $default_opt );
1059
+            if ( $opt == 'blank' && $field_array[$opt] == '' ) {
1060
+                $field_array[$opt] = $args['frm_settings']->blank_msg;
1061
+            } else if ( $opt == 'invalid' && $field_array[$opt] == '' ) {
1062 1062
                 if ( $args['field_type'] == 'captcha' ) {
1063
-                    $field_array[ $opt ] = $args['frm_settings']->re_msg;
1063
+                    $field_array[$opt] = $args['frm_settings']->re_msg;
1064 1064
                 } else {
1065
-                    $field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
1065
+                    $field_array[$opt] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
1066 1066
                 }
1067 1067
             }
1068 1068
         }
1069 1069
 
1070 1070
         if ( $field_array['custom_html'] == '' ) {
1071
-            $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']);
1071
+            $field_array['custom_html'] = FrmFieldsHelper::get_default_html( $args['field_type'] );
1072 1072
         }
1073 1073
     }
1074 1074
 
@@ -1087,18 +1087,18 @@  discard block
 block discarded – undo
1087 1087
             return;
1088 1088
         }
1089 1089
 
1090
-        $values['form_name'] = isset($record->form_id) ? $form->name : '';
1090
+        $values['form_name'] = isset( $record->form_id ) ? $form->name : '';
1091 1091
 		$values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
1092 1092
 
1093
-        if ( ! is_array($form->options) ) {
1093
+        if ( ! is_array( $form->options ) ) {
1094 1094
             return;
1095 1095
         }
1096 1096
 
1097 1097
         foreach ( $form->options as $opt => $value ) {
1098
-            $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1098
+            $values[$opt] = isset( $post_values[$opt] ) ? maybe_unserialize( $post_values[$opt] ) : $value;
1099 1099
         }
1100 1100
 
1101
-        self::fill_form_defaults($post_values, $values);
1101
+        self::fill_form_defaults( $post_values, $values );
1102 1102
     }
1103 1103
 
1104 1104
     /**
@@ -1108,11 +1108,11 @@  discard block
 block discarded – undo
1108 1108
         $form_defaults = FrmFormsHelper::get_default_opts();
1109 1109
 
1110 1110
         foreach ( $form_defaults as $opt => $default ) {
1111
-            if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1112
-				$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1111
+            if ( ! isset( $values[$opt] ) || $values[$opt] == '' ) {
1112
+				$values[$opt] = ( $post_values && isset( $post_values['options'][$opt] ) ) ? $post_values['options'][$opt] : $default;
1113 1113
             }
1114 1114
 
1115
-            unset($opt, $defaut);
1115
+            unset( $opt, $defaut );
1116 1116
         }
1117 1117
 
1118 1118
 		if ( ! isset( $values['custom_style'] ) ) {
@@ -1120,10 +1120,10 @@  discard block
 block discarded – undo
1120 1120
 		}
1121 1121
 
1122 1122
 		foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1123
-			if ( ! isset( $values[ $h . '_html' ] ) ) {
1124
-				$values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1123
+			if ( ! isset( $values[$h . '_html'] ) ) {
1124
+				$values[$h . '_html'] = ( isset( $post_values['options'][$h . '_html'] ) ? $post_values['options'][$h . '_html'] : FrmFormsHelper::get_default_html( $h ) );
1125 1125
             }
1126
-            unset($h);
1126
+            unset( $h );
1127 1127
         }
1128 1128
     }
1129 1129
 
@@ -1154,9 +1154,9 @@  discard block
 block discarded – undo
1154 1154
         }
1155 1155
     ?>
1156 1156
 <li>
1157
-    <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>
1158
-    <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>
1159
-    <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>
1157
+    <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>
1158
+    <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>
1159
+    <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>
1160 1160
 </li>
1161 1161
     <?php
1162 1162
     }
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
             return '';
1175 1175
         } else if ( $length <= 10 ) {
1176 1176
 			$sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
1177
-            return $sub . (($length < $original_len) ? $continue : '');
1177
+            return $sub . ( ( $length < $original_len ) ? $continue : '' );
1178 1178
         }
1179 1179
 
1180 1180
         $sub = '';
@@ -1183,23 +1183,23 @@  discard block
 block discarded – undo
1183 1183
 		$words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1184 1184
 
1185 1185
 		foreach ( $words as $word ) {
1186
-            $part = (($sub != '') ? ' ' : '') . $word;
1186
+            $part = ( ( $sub != '' ) ? ' ' : '' ) . $word;
1187 1187
 			$total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1188
-            if ( $total_len > $length && str_word_count($sub) ) {
1188
+            if ( $total_len > $length && str_word_count( $sub ) ) {
1189 1189
                 break;
1190 1190
             }
1191 1191
 
1192 1192
             $sub .= $part;
1193 1193
 			$len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1194 1194
 
1195
-            if ( str_word_count($sub) > $minword && $total_len >= $length ) {
1195
+            if ( str_word_count( $sub ) > $minword && $total_len >= $length ) {
1196 1196
                 break;
1197 1197
             }
1198 1198
 
1199
-            unset($total_len, $word);
1199
+            unset( $total_len, $word );
1200 1200
         }
1201 1201
 
1202
-        return $sub . (($len < $original_len) ? $continue : '');
1202
+        return $sub . ( ( $len < $original_len ) ? $continue : '' );
1203 1203
     }
1204 1204
 
1205 1205
 	public static function mb_function( $function_names, $args ) {
@@ -1212,17 +1212,17 @@  discard block
 block discarded – undo
1212 1212
 	}
1213 1213
 
1214 1214
 	public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1215
-        if ( empty($date) ) {
1215
+        if ( empty( $date ) ) {
1216 1216
             return $date;
1217 1217
         }
1218 1218
 
1219
-        if ( empty($date_format) ) {
1220
-            $date_format = get_option('date_format');
1219
+        if ( empty( $date_format ) ) {
1220
+            $date_format = get_option( 'date_format' );
1221 1221
         }
1222 1222
 
1223
-        if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) {
1223
+        if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) {
1224 1224
             $frmpro_settings = new FrmProSettings();
1225
-            $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
1225
+            $date = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' );
1226 1226
         }
1227 1227
 
1228 1228
 		$formatted = self::get_localized_date( $date_format, $date );
@@ -1237,7 +1237,7 @@  discard block
 block discarded – undo
1237 1237
 
1238 1238
 	private static function add_time_to_date( $time_format, $date ) {
1239 1239
 		if ( empty( $time_format ) ) {
1240
-			$time_format = get_option('time_format');
1240
+			$time_format = get_option( 'time_format' );
1241 1241
 		}
1242 1242
 
1243 1243
 		$trimmed_format = trim( $time_format );
@@ -1283,10 +1283,10 @@  discard block
 block discarded – undo
1283 1283
 		$time_strings = self::get_time_strings();
1284 1284
 
1285 1285
 		foreach ( $time_strings as $k => $v ) {
1286
-			if ( $diff[ $k ] ) {
1287
-				$time_strings[ $k ] = $diff[ $k ] . ' ' . ( $diff[ $k ] > 1 ? $v[1] : $v[0] );
1286
+			if ( $diff[$k] ) {
1287
+				$time_strings[$k] = $diff[$k] . ' ' . ( $diff[$k] > 1 ? $v[1] : $v[0] );
1288 1288
 			} else {
1289
-				unset( $time_strings[ $k ] );
1289
+				unset( $time_strings[$k] );
1290 1290
 			}
1291 1291
 		}
1292 1292
 
@@ -1341,19 +1341,19 @@  discard block
 block discarded – undo
1341 1341
 	public static function json_to_array( $json_vars ) {
1342 1342
         $vars = array();
1343 1343
         foreach ( $json_vars as $jv ) {
1344
-            $jv_name = explode('[', $jv['name']);
1345
-            $last = count($jv_name) - 1;
1344
+            $jv_name = explode( '[', $jv['name'] );
1345
+            $last = count( $jv_name ) - 1;
1346 1346
             foreach ( $jv_name as $p => $n ) {
1347
-                $name = trim($n, ']');
1348
-                if ( ! isset($l1) ) {
1347
+                $name = trim( $n, ']' );
1348
+                if ( ! isset( $l1 ) ) {
1349 1349
                     $l1 = $name;
1350 1350
                 }
1351 1351
 
1352
-                if ( ! isset($l2) ) {
1352
+                if ( ! isset( $l2 ) ) {
1353 1353
                     $l2 = $name;
1354 1354
                 }
1355 1355
 
1356
-                if ( ! isset($l3) ) {
1356
+                if ( ! isset( $l3 ) ) {
1357 1357
                     $l3 = $name;
1358 1358
                 }
1359 1359
 
@@ -1367,24 +1367,24 @@  discard block
 block discarded – undo
1367 1367
 
1368 1368
                     case 1:
1369 1369
                         $l2 = $name;
1370
-                        self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1370
+                        self::add_value_to_array( $name, $l2, $this_val, $vars[$l1] );
1371 1371
                     break;
1372 1372
 
1373 1373
                     case 2:
1374 1374
                         $l3 = $name;
1375
-                        self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1375
+                        self::add_value_to_array( $name, $l3, $this_val, $vars[$l1][$l2] );
1376 1376
                     break;
1377 1377
 
1378 1378
                     case 3:
1379 1379
                         $l4 = $name;
1380
-                        self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1380
+                        self::add_value_to_array( $name, $l4, $this_val, $vars[$l1][$l2][$l3] );
1381 1381
                     break;
1382 1382
                 }
1383 1383
 
1384
-                unset($this_val, $n);
1384
+                unset( $this_val, $n );
1385 1385
             }
1386 1386
 
1387
-            unset($last, $jv);
1387
+            unset( $last, $jv );
1388 1388
         }
1389 1389
 
1390 1390
         return $vars;
@@ -1397,8 +1397,8 @@  discard block
 block discarded – undo
1397 1397
     public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1398 1398
         if ( $name == '' ) {
1399 1399
             $vars[] = $val;
1400
-        } else if ( ! isset( $vars[ $l1 ] ) ) {
1401
-            $vars[ $l1 ] = $val;
1400
+        } else if ( ! isset( $vars[$l1] ) ) {
1401
+            $vars[$l1] = $val;
1402 1402
         }
1403 1403
     }
1404 1404
 
@@ -1413,7 +1413,7 @@  discard block
 block discarded – undo
1413 1413
             '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() ) ),
1414 1414
         );
1415 1415
 
1416
-        if ( ! isset( $tooltips[ $name ] ) ) {
1416
+        if ( ! isset( $tooltips[$name] ) ) {
1417 1417
             return;
1418 1418
         }
1419 1419
 
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
             echo ' class="frm_help"';
1424 1424
         }
1425 1425
 
1426
-		echo ' title="' . esc_attr( $tooltips[ $name ] );
1426
+		echo ' title="' . esc_attr( $tooltips[$name] );
1427 1427
 
1428 1428
         if ( 'open' != $class ) {
1429 1429
             echo '"';
@@ -1475,13 +1475,13 @@  discard block
 block discarded – undo
1475 1475
     }
1476 1476
 
1477 1477
 	private static function prepare_action_slashes( $val, $key, &$post_content ) {
1478
-		if ( ! isset( $post_content[ $key ] ) ) {
1478
+		if ( ! isset( $post_content[$key] ) ) {
1479 1479
 			return;
1480 1480
 		}
1481 1481
 
1482 1482
 		if ( is_array( $val ) ) {
1483 1483
 			foreach ( $val as $k1 => $v1 ) {
1484
-				self::prepare_action_slashes( $v1, $k1, $post_content[ $key ] );
1484
+				self::prepare_action_slashes( $v1, $k1, $post_content[$key] );
1485 1485
 				unset( $k1, $v1 );
1486 1486
 			}
1487 1487
 		} else {
@@ -1489,22 +1489,22 @@  discard block
 block discarded – undo
1489 1489
 			$val = stripslashes( $val );
1490 1490
 
1491 1491
 			// Add backslashes before double quotes and forward slashes only
1492
-			$post_content[ $key ] = addcslashes( $val, '"\\/' );
1492
+			$post_content[$key] = addcslashes( $val, '"\\/' );
1493 1493
 		}
1494 1494
 	}
1495 1495
 
1496 1496
 	public static function maybe_json_decode( $string ) {
1497
-        if ( is_array($string) ) {
1497
+        if ( is_array( $string ) ) {
1498 1498
             return $string;
1499 1499
         }
1500 1500
 
1501
-        $new_string = json_decode($string, true);
1502
-        if ( function_exists('json_last_error') ) {
1501
+        $new_string = json_decode( $string, true );
1502
+        if ( function_exists( 'json_last_error' ) ) {
1503 1503
 			// php 5.3+
1504 1504
             if ( json_last_error() == JSON_ERROR_NONE ) {
1505 1505
                 $string = $new_string;
1506 1506
             }
1507
-        } else if ( isset($new_string) ) {
1507
+        } else if ( isset( $new_string ) ) {
1508 1508
 			// php < 5.3 fallback
1509 1509
             $string = $new_string;
1510 1510
         }
@@ -1520,11 +1520,11 @@  discard block
 block discarded – undo
1520 1520
 	public static function maybe_highlight_menu( $post_type ) {
1521 1521
         global $post;
1522 1522
 
1523
-        if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
1523
+        if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) {
1524 1524
             return;
1525 1525
         }
1526 1526
 
1527
-        if ( is_object($post) && $post->post_type != $post_type ) {
1527
+        if ( is_object( $post ) && $post->post_type != $post_type ) {
1528 1528
             return;
1529 1529
         }
1530 1530
 
@@ -1628,11 +1628,11 @@  discard block
 block discarded – undo
1628 1628
         $frm_version = self::plugin_version();
1629 1629
 
1630 1630
         // check if Formidable meets minimum requirements
1631
-        if ( version_compare($frm_version, $min_version, '>=') ) {
1631
+        if ( version_compare( $frm_version, $min_version, '>=' ) ) {
1632 1632
             return;
1633 1633
         }
1634 1634
 
1635
-        $wp_list_table = _get_list_table('WP_Plugins_List_Table');
1635
+        $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
1636 1636
 		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">' .
1637 1637
         __( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1638 1638
         '</div></td></tr>';
@@ -1640,38 +1640,38 @@  discard block
 block discarded – undo
1640 1640
 
1641 1641
     public static function locales( $type = 'date' ) {
1642 1642
         $locales = array(
1643
-            'en' => __( 'English', 'formidable' ),    '' => __( 'English/Western', 'formidable' ),
1644
-            'af' => __( 'Afrikaans', 'formidable' ),  'sq' => __( 'Albanian', 'formidable' ),
1645
-            'ar' => __( 'Arabic', 'formidable' ),     'hy' => __( 'Armenian', 'formidable' ),
1643
+            'en' => __( 'English', 'formidable' ), '' => __( 'English/Western', 'formidable' ),
1644
+            'af' => __( 'Afrikaans', 'formidable' ), 'sq' => __( 'Albanian', 'formidable' ),
1645
+            'ar' => __( 'Arabic', 'formidable' ), 'hy' => __( 'Armenian', 'formidable' ),
1646 1646
             'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ),
1647
-            'bs' => __( 'Bosnian', 'formidable' ),    'bg' => __( 'Bulgarian', 'formidable' ),
1648
-            'ca' => __( 'Catalan', 'formidable' ),    'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1647
+            'bs' => __( 'Bosnian', 'formidable' ), 'bg' => __( 'Bulgarian', 'formidable' ),
1648
+            'ca' => __( 'Catalan', 'formidable' ), 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1649 1649
             'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1650
-            'hr' => __( 'Croatian', 'formidable' ),   'cs' => __( 'Czech', 'formidable' ),
1651
-            'da' => __( 'Danish', 'formidable' ),     'nl' => __( 'Dutch', 'formidable' ),
1650
+            'hr' => __( 'Croatian', 'formidable' ), 'cs' => __( 'Czech', 'formidable' ),
1651
+            'da' => __( 'Danish', 'formidable' ), 'nl' => __( 'Dutch', 'formidable' ),
1652 1652
             'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ),
1653
-            'et' => __( 'Estonian', 'formidable' ),   'fo' => __( 'Faroese', 'formidable' ),
1653
+            'et' => __( 'Estonian', 'formidable' ), 'fo' => __( 'Faroese', 'formidable' ),
1654 1654
             'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ),
1655
-            'fi' => __( 'Finnish', 'formidable' ),    'fr' => __( 'French', 'formidable' ),
1655
+            'fi' => __( 'Finnish', 'formidable' ), 'fr' => __( 'French', 'formidable' ),
1656 1656
             'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ),
1657
-            'de' => __( 'German', 'formidable' ),     'de-AT' => __( 'German/Austria', 'formidable' ),
1657
+            'de' => __( 'German', 'formidable' ), 'de-AT' => __( 'German/Austria', 'formidable' ),
1658 1658
             'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ),
1659
-            'he' => __( 'Hebrew', 'formidable' ),     'iw' => __( 'Hebrew', 'formidable' ),
1660
-            'hi' => __( 'Hindi', 'formidable' ),      'hu' => __( 'Hungarian', 'formidable' ),
1661
-            'is' => __( 'Icelandic', 'formidable' ),  'id' => __( 'Indonesian', 'formidable' ),
1662
-            'it' => __( 'Italian', 'formidable' ),    'ja' => __( 'Japanese', 'formidable' ),
1663
-            'ko' => __( 'Korean', 'formidable' ),     'lv' => __( 'Latvian', 'formidable' ),
1659
+            'he' => __( 'Hebrew', 'formidable' ), 'iw' => __( 'Hebrew', 'formidable' ),
1660
+            'hi' => __( 'Hindi', 'formidable' ), 'hu' => __( 'Hungarian', 'formidable' ),
1661
+            'is' => __( 'Icelandic', 'formidable' ), 'id' => __( 'Indonesian', 'formidable' ),
1662
+            'it' => __( 'Italian', 'formidable' ), 'ja' => __( 'Japanese', 'formidable' ),
1663
+            'ko' => __( 'Korean', 'formidable' ), 'lv' => __( 'Latvian', 'formidable' ),
1664 1664
             'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ),
1665
-            'no' => __( 'Norwegian', 'formidable' ),  'pl' => __( 'Polish', 'formidable' ),
1665
+            'no' => __( 'Norwegian', 'formidable' ), 'pl' => __( 'Polish', 'formidable' ),
1666 1666
             'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1667 1667
             'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ),
1668
-            'ru' => __( 'Russian', 'formidable' ),    'sr' => __( 'Serbian', 'formidable' ),
1668
+            'ru' => __( 'Russian', 'formidable' ), 'sr' => __( 'Serbian', 'formidable' ),
1669 1669
             'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ),
1670
-            'sl' => __( 'Slovenian', 'formidable' ),  'es' => __( 'Spanish', 'formidable' ),
1670
+            'sl' => __( 'Slovenian', 'formidable' ), 'es' => __( 'Spanish', 'formidable' ),
1671 1671
             'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ),
1672
-            'ta' => __( 'Tamil', 'formidable' ),      'th' => __( 'Thai', 'formidable' ),
1673
-            'tu' => __( 'Turkish', 'formidable' ),    'tr' => __( 'Turkish', 'formidable' ),
1674
-            'uk' => __( 'Ukranian', 'formidable' ),   'vi' => __( 'Vietnamese', 'formidable' ),
1672
+            'ta' => __( 'Tamil', 'formidable' ), 'th' => __( 'Thai', 'formidable' ),
1673
+            'tu' => __( 'Turkish', 'formidable' ), 'tr' => __( 'Turkish', 'formidable' ),
1674
+            'uk' => __( 'Ukranian', 'formidable' ), 'vi' => __( 'Vietnamese', 'formidable' ),
1675 1675
         );
1676 1676
 
1677 1677
         if ( $type == 'captcha' ) {
@@ -1690,8 +1690,8 @@  discard block
 block discarded – undo
1690 1690
             );
1691 1691
         }
1692 1692
 
1693
-        $locales = array_diff_key($locales, array_flip($unset));
1694
-        $locales = apply_filters('frm_locales', $locales);
1693
+        $locales = array_diff_key( $locales, array_flip( $unset ) );
1694
+        $locales = apply_filters( 'frm_locales', $locales );
1695 1695
 
1696 1696
         return $locales;
1697 1697
     }
Please login to merge, or discard this patch.
classes/helpers/FrmEntriesListHelper.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -6,10 +6,10 @@  discard block
 block discarded – undo
6 6
 	protected $field;
7 7
 
8 8
 	public function prepare_items() {
9
-        global $per_page;
9
+		global $per_page;
10 10
 
11 11
 		$per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' );
12
-        $form_id = $this->params['form'];
12
+		$form_id = $this->params['form'];
13 13
 
14 14
 		$default_orderby = 'id';
15 15
 		$default_order = 'DESC';
@@ -25,28 +25,28 @@  discard block
 block discarded – undo
25 25
 
26 26
 		$s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
27 27
 
28
-	    if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
29
-	        $fid = isset( $_REQUEST['fid'] ) ? sanitize_title( $_REQUEST['fid'] ) : '';
30
-	        $s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid );
31
-	    }
28
+		if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
29
+			$fid = isset( $_REQUEST['fid'] ) ? sanitize_title( $_REQUEST['fid'] ) : '';
30
+			$s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid );
31
+		}
32 32
 
33 33
 		$s_query = apply_filters( 'frm_entries_list_query', $s_query, compact( 'form_id' ) );
34 34
 
35
-        $orderby = isset( $_REQUEST['orderby'] ) ? sanitize_title( $_REQUEST['orderby'] ) : $default_orderby;
36
-        if ( strpos($orderby, 'meta') !== false ) {
37
-            $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
35
+		$orderby = isset( $_REQUEST['orderby'] ) ? sanitize_title( $_REQUEST['orderby'] ) : $default_orderby;
36
+		if ( strpos($orderby, 'meta') !== false ) {
37
+			$order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
38 38
 			$orderby .= in_array( $order_field_type, array( 'number', 'scale' ) ) ? ' +0 ' : '';
39
-        }
39
+		}
40 40
 
41 41
 		$order = isset( $_REQUEST['order'] ) ? sanitize_title( $_REQUEST['order'] ) : $default_order;
42 42
 		$order = ' ORDER BY ' . $orderby . ' ' . $order;
43 43
 
44
-        $page = $this->get_pagenum();
44
+		$page = $this->get_pagenum();
45 45
 		$start = (int) isset( $_REQUEST['start'] ) ? absint( $_REQUEST['start'] ) : ( ( $page - 1 ) * $per_page );
46 46
 
47 47
 		$limit = FrmDb::esc_limit( $start . ',' . $per_page );
48 48
 		$this->items = FrmEntry::getAll( $s_query, $order, $limit, true, $join_form_in_query );
49
-        $total_items = FrmEntry::getRecordCount($s_query);
49
+		$total_items = FrmEntry::getRecordCount($s_query);
50 50
 
51 51
 		$this->set_pagination_args( array(
52 52
 			'total_items' => $total_items,
@@ -55,19 +55,19 @@  discard block
 block discarded – undo
55 55
 	}
56 56
 
57 57
 	public function no_items() {
58
-        $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
59
-	    if ( ! empty($s) ) {
60
-            _e( 'No Entries Found', 'formidable' );
61
-            return;
62
-        }
58
+		$s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
59
+		if ( ! empty($s) ) {
60
+			_e( 'No Entries Found', 'formidable' );
61
+			return;
62
+		}
63 63
 
64 64
 		$form_id = $this->params['form'];
65 65
 		$form = $this->params['form'];
66 66
 
67
-        if ( $form_id ) {
68
-            $form = FrmForm::getOne($form_id);
69
-        }
70
-        $colspan = $this->get_column_count();
67
+		if ( $form_id ) {
68
+			$form = FrmForm::getOne($form_id);
69
+		}
70
+		$colspan = $this->get_column_count();
71 71
 
72 72
 		include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/no_entries.php' );
73 73
 	}
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
 	}
88 88
 
89 89
 	/**
90
-	* Gets the name of the primary column in the Entries screen
91
-	*
92
-	* @since 2.0.14
93
-	*
94
-	* @return string $primary_column
95
-	*/
90
+	 * Gets the name of the primary column in the Entries screen
91
+	 *
92
+	 * @since 2.0.14
93
+	 *
94
+	 * @return string $primary_column
95
+	 */
96 96
 	protected function get_primary_column_name() {
97 97
 		$columns = get_column_headers( $this->screen );
98 98
 		$hidden = get_hidden_columns( $this->screen );
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 
117 117
 		$this->get_actions( $actions, $item, $view_link );
118 118
 
119
-        $action_links = $this->row_actions( $actions );
119
+		$action_links = $this->row_actions( $actions );
120 120
 
121 121
 		// Set up the checkbox ( because the user is editable, otherwise its empty )
122 122
 		$checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		$r = "<tr id='item-action-{$item->id}'$style>";
125 125
 
126 126
 		list( $columns, $hidden, , $primary ) = $this->get_column_info();
127
-        $action_col = false;
127
+		$action_col = false;
128 128
 
129 129
 		foreach ( $columns as $column_name => $column_display_name ) {
130 130
 			$class = $column_name . ' column-' . $column_name;
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 			if ( in_array( $column_name, $hidden ) ) {
137 137
 				$class .= ' frm_hidden';
138 138
 			} else if ( ! $action_col && ! in_array( $column_name, array( 'cb', 'id', 'form_id', 'post_id' ) ) ) {
139
-			    $action_col = $column_name;
140
-            }
139
+				$action_col = $column_name;
140
+			}
141 141
 
142 142
 			$attributes = 'class="' . esc_attr( $class ) . '"';
143 143
 			unset($class);
@@ -155,15 +155,15 @@  discard block
 block discarded – undo
155 155
 					$val = $this->column_value( $item );
156 156
 				}
157 157
 
158
-			    $r .= "<td $attributes>";
158
+				$r .= "<td $attributes>";
159 159
 				if ( $column_name == $action_col ) {
160 160
 					$edit_link = '?page=formidable-entries&frm_action=edit&id=' . $item->id;
161 161
 					$r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> ';
162
-			        $r .= $action_links;
162
+					$r .= $action_links;
163 163
 				} else {
164
-			        $r .= $val;
165
-			    }
166
-			    $r .= '</td>';
164
+					$r .= $val;
165
+				}
166
+				$r .= '</td>';
167 167
 			}
168 168
 			unset($val);
169 169
 		}
@@ -216,19 +216,19 @@  discard block
 block discarded – undo
216 216
 		return $val;
217 217
 	}
218 218
 
219
-    /**
220
-     * @param string $view_link
221
-     */
222
-    private function get_actions( &$actions, $item, $view_link ) {
219
+	/**
220
+	 * @param string $view_link
221
+	 */
222
+	private function get_actions( &$actions, $item, $view_link ) {
223 223
 		$actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . __( 'View', 'formidable' ) . '</a>';
224 224
 
225
-        if ( current_user_can('frm_delete_entries') ) {
225
+		if ( current_user_can('frm_delete_entries') ) {
226 226
 			$delete_link = '?page=formidable-entries&frm_action=destroy&id=' . $item->id . '&form=' . $this->params['form'];
227 227
 			$actions['delete'] = '<a href="' . esc_url( wp_nonce_url( $delete_link ) ) . '" class="submitdelete" onclick="return confirm(\'' . esc_attr( __( 'Are you sure you want to delete that?', 'formidable' ) ) . '\')">' . __( 'Delete' ) . '</a>';
228
-	    }
228
+		}
229 229
 
230
-        $actions = apply_filters('frm_row_actions', $actions, $item);
231
-    }
230
+		$actions = apply_filters('frm_row_actions', $actions, $item);
231
+	}
232 232
 
233 233
 	private function get_column_value( $item, &$val ) {
234 234
 		$col_name = $this->column_name;
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 			$join_form_in_query = true;
24 24
 		}
25 25
 
26
-		$s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
26
+		$s = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
27 27
 
28 28
 	    if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
29 29
 	        $fid = isset( $_REQUEST['fid'] ) ? sanitize_title( $_REQUEST['fid'] ) : '';
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 		$s_query = apply_filters( 'frm_entries_list_query', $s_query, compact( 'form_id' ) );
34 34
 
35 35
         $orderby = isset( $_REQUEST['orderby'] ) ? sanitize_title( $_REQUEST['orderby'] ) : $default_orderby;
36
-        if ( strpos($orderby, 'meta') !== false ) {
36
+        if ( strpos( $orderby, 'meta' ) !== false ) {
37 37
             $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
38 38
 			$orderby .= in_array( $order_field_type, array( 'number', 'scale' ) ) ? ' +0 ' : '';
39 39
         }
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
 		$limit = FrmDb::esc_limit( $start . ',' . $per_page );
48 48
 		$this->items = FrmEntry::getAll( $s_query, $order, $limit, true, $join_form_in_query );
49
-        $total_items = FrmEntry::getRecordCount($s_query);
49
+        $total_items = FrmEntry::getRecordCount( $s_query );
50 50
 
51 51
 		$this->set_pagination_args( array(
52 52
 			'total_items' => $total_items,
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 
57 57
 	public function no_items() {
58 58
         $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
59
-	    if ( ! empty($s) ) {
59
+	    if ( ! empty( $s ) ) {
60 60
             _e( 'No Entries Found', 'formidable' );
61 61
             return;
62 62
         }
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		$form = $this->params['form'];
66 66
 
67 67
         if ( $form_id ) {
68
-            $form = FrmForm::getOne($form_id);
68
+            $form = FrmForm::getOne( $form_id );
69 69
         }
70 70
         $colspan = $this->get_column_count();
71 71
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 
124 124
 		$r = "<tr id='item-action-{$item->id}'$style>";
125 125
 
126
-		list( $columns, $hidden, , $primary ) = $this->get_column_info();
126
+		list( $columns, $hidden,, $primary ) = $this->get_column_info();
127 127
         $action_col = false;
128 128
 
129 129
 		foreach ( $columns as $column_name => $column_display_name ) {
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
             }
141 141
 
142 142
 			$attributes = 'class="' . esc_attr( $class ) . '"';
143
-			unset($class);
143
+			unset( $class );
144 144
 			$attributes .= ' data-colname="' . $column_display_name . '"';
145 145
 
146 146
 			$form_id = $this->params['form'] ? $this->params['form'] : 0;
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 			    }
166 166
 			    $r .= '</td>';
167 167
 			}
168
-			unset($val);
168
+			unset( $val );
169 169
 		}
170 170
 		$r .= '</tr>';
171 171
 
@@ -222,12 +222,12 @@  discard block
 block discarded – undo
222 222
     private function get_actions( &$actions, $item, $view_link ) {
223 223
 		$actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . __( 'View', 'formidable' ) . '</a>';
224 224
 
225
-        if ( current_user_can('frm_delete_entries') ) {
225
+        if ( current_user_can( 'frm_delete_entries' ) ) {
226 226
 			$delete_link = '?page=formidable-entries&frm_action=destroy&id=' . $item->id . '&form=' . $this->params['form'];
227 227
 			$actions['delete'] = '<a href="' . esc_url( wp_nonce_url( $delete_link ) ) . '" class="submitdelete" onclick="return confirm(\'' . esc_attr( __( 'Are you sure you want to delete that?', 'formidable' ) ) . '\')">' . __( 'Delete' ) . '</a>';
228 228
 	    }
229 229
 
230
-        $actions = apply_filters('frm_row_actions', $actions, $item);
230
+        $actions = apply_filters( 'frm_row_actions', $actions, $item );
231 231
     }
232 232
 
233 233
 	private function get_column_value( $item, &$val ) {
Please login to merge, or discard this patch.
classes/models/FrmStyle.php 2 patches
Indentation   +271 added lines, -271 removed lines patch added patch discarded remove patch
@@ -1,52 +1,52 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class FrmStyle {
3
-    public $number = false;	// Unique ID number of the current instance.
3
+	public $number = false;	// Unique ID number of the current instance.
4 4
 	public $id = 0; // the id of the post
5 5
 
6 6
 	/**
7 7
 	 * @param int|string $id The id of the stylsheet or 'default'
8 8
 	 */
9 9
 	public function __construct( $id = 0 ) {
10
-        $this->id = $id;
11
-    }
10
+		$this->id = $id;
11
+	}
12 12
 
13
-    public function get_new() {
13
+	public function get_new() {
14 14
 		$this->id = 0;
15 15
 
16
-        $max_slug_value = 2147483647;
17
-        $min_slug_value = 37; // we want to have at least 2 characters in the slug
18
-        $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
19
-
20
-        $style = array(
21
-            'post_type'     => FrmStylesController::$post_type,
22
-            'ID'            => '',
23
-            'post_title'    => __( 'New Style', 'formidable' ),
24
-            'post_name'     => $key,
25
-            'post_content'  => $this->get_defaults(),
26
-            'menu_order'    => '',
27
-            'post_status'   => 'publish',
28
-        );
16
+		$max_slug_value = 2147483647;
17
+		$min_slug_value = 37; // we want to have at least 2 characters in the slug
18
+		$key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
19
+
20
+		$style = array(
21
+			'post_type'     => FrmStylesController::$post_type,
22
+			'ID'            => '',
23
+			'post_title'    => __( 'New Style', 'formidable' ),
24
+			'post_name'     => $key,
25
+			'post_content'  => $this->get_defaults(),
26
+			'menu_order'    => '',
27
+			'post_status'   => 'publish',
28
+		);
29 29
 
30
-        return (object) $style;
31
-    }
30
+		return (object) $style;
31
+	}
32 32
 
33 33
 	public function save( $settings ) {
34 34
 		return FrmAppHelper::save_settings( $settings, 'frm_styles' );
35
-    }
35
+	}
36 36
 
37 37
 	public function duplicate( $id ) {
38
-        // duplicating is a pro feature
39
-    }
38
+		// duplicating is a pro feature
39
+	}
40 40
 
41
-    public function update( $id = 'default' ) {
41
+	public function update( $id = 'default' ) {
42 42
  		$all_instances = $this->get_all();
43 43
 
44 44
  		if ( empty($id) ) {
45
- 		     $new_style = (array) $this->get_new();
46
- 		     $all_instances[] = $new_style;
45
+ 			 $new_style = (array) $this->get_new();
46
+ 			 $all_instances[] = $new_style;
47 47
  		}
48 48
 
49
-        $action_ids = array();
49
+		$action_ids = array();
50 50
 
51 51
  		foreach ( $all_instances as $number => $new_instance ) {
52 52
  			$new_instance = stripslashes_deep( (array) $new_instance);
@@ -54,46 +54,46 @@  discard block
 block discarded – undo
54 54
  			if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) {
55 55
 				$all_instances[ $number ] = $new_instance;
56 56
 
57
- 			    if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) {
58
- 			        // this style was set to default, so remove default setting on previous default style
59
- 			        $new_instance['menu_order'] = 0;
60
- 			        $action_ids[] = $this->save($new_instance);
61
- 			    }
57
+ 				if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) {
58
+ 					// this style was set to default, so remove default setting on previous default style
59
+ 					$new_instance['menu_order'] = 0;
60
+ 					$action_ids[] = $this->save($new_instance);
61
+ 				}
62 62
 
63
- 			    // don't continue if not saving this style
64
- 			    continue;
63
+ 				// don't continue if not saving this style
64
+ 				continue;
65 65
  			}
66 66
 
67 67
  			$new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] );
68 68
  			$new_instance['post_content'] = $_POST['frm_style_setting']['post_content'];
69 69
  			$new_instance['post_type']  = FrmStylesController::$post_type;
70
-            $new_instance['post_status']  = 'publish';
70
+			$new_instance['post_status']  = 'publish';
71 71
 			$new_instance['menu_order']  = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0;
72 72
 
73
-            if ( empty($id) ) {
74
-                $new_instance['post_name'] = $new_instance['post_title'];
75
-            }
73
+			if ( empty($id) ) {
74
+				$new_instance['post_name'] = $new_instance['post_title'];
75
+			}
76 76
 
77
-            $default_settings = $this->get_defaults();
77
+			$default_settings = $this->get_defaults();
78 78
 
79
-            foreach ( $default_settings as $setting => $default ) {
79
+			foreach ( $default_settings as $setting => $default ) {
80 80
 				if ( ! isset( $new_instance['post_content'][ $setting ] ) ) {
81 81
 					$new_instance['post_content'][ $setting ] = $default;
82 82
 				}
83 83
 
84 84
 				if ( strpos( $setting, 'color' ) !== false || in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ) ) ) {
85
-                    //if is a color
85
+					//if is a color
86 86
 					$new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] );
87 87
 				} else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) {
88 88
 					$new_instance['post_content'][ $setting ] = 0;
89
-                } else if ( $setting == 'font' ) {
90
-                	$new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
91
-                }
92
-            }
89
+				} else if ( $setting == 'font' ) {
90
+					$new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
91
+				}
92
+			}
93 93
 
94 94
 			$all_instances[ $number ] = $new_instance;
95 95
 
96
-            $action_ids[] = $this->save($new_instance);
96
+			$action_ids[] = $this->save($new_instance);
97 97
 
98 98
  		}
99 99
 
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
  		return $action_ids;
103 103
  	}
104 104
 
105
-    /**
106
-     * Create static css file
107
-     */
105
+	/**
106
+	 * Create static css file
107
+	 */
108 108
 	public function save_settings() {
109 109
 		$filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php';
110 110
 		update_option( 'frm_last_style_update', date('njGi') );
111 111
 
112
-        if ( ! is_file($filename) ) {
113
-            return;
114
-        }
112
+		if ( ! is_file($filename) ) {
113
+			return;
114
+		}
115 115
 
116 116
 		$this->clear_cache();
117 117
 
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 		$create_file = new FrmCreateFile( array( 'folder_name' => 'formidable/css', 'file_name' => 'formidablepro.css' ) );
121 121
 		$create_file->create_file( $css );
122 122
 
123
-        update_option('frmpro_css', $css);
123
+		update_option('frmpro_css', $css);
124 124
 
125
-        set_transient('frmpro_css', $css);
125
+		set_transient('frmpro_css', $css);
126 126
 	}
127 127
 
128 128
 	private function get_css_content( $filename ) {
@@ -131,10 +131,10 @@  discard block
 block discarded – undo
131 131
 		$saving = true;
132 132
 		$frm_style = $this;
133 133
 
134
-        ob_start();
135
-        include( $filename );
134
+		ob_start();
135
+		include( $filename );
136 136
 		$css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", '    ' ), '', ob_get_contents() ) );
137
-        ob_end_clean();
137
+		ob_end_clean();
138 138
 
139 139
 		return $css;
140 140
 	}
@@ -154,269 +154,269 @@  discard block
 block discarded – undo
154 154
 	}
155 155
 
156 156
 	public function destroy( $id ) {
157
-        return wp_delete_post($id);
158
-    }
157
+		return wp_delete_post($id);
158
+	}
159 159
 
160
-    public function get_one() {
161
-        if ( 'default' == $this->id ) {
162
-            $style = $this->get_default_style();
163
-            if ( $style ) {
164
-                $this->id = $style->ID;
165
-            } else {
166
-                $this->id = 0;
167
-            }
168
-            return $style;
169
-        }
160
+	public function get_one() {
161
+		if ( 'default' == $this->id ) {
162
+			$style = $this->get_default_style();
163
+			if ( $style ) {
164
+				$this->id = $style->ID;
165
+			} else {
166
+				$this->id = 0;
167
+			}
168
+			return $style;
169
+		}
170 170
 
171
-        $style = get_post($this->id);
171
+		$style = get_post($this->id);
172 172
 
173
-        if ( ! $style ) {
174
-            return $style;
175
-        }
173
+		if ( ! $style ) {
174
+			return $style;
175
+		}
176 176
 
177
-        $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
177
+		$style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
178 178
 
179
-        $default_values = $this->get_defaults();
179
+		$default_values = $this->get_defaults();
180 180
 
181
-        // fill default values
182
-        $style->post_content = $this->override_defaults($style->post_content);
183
-        $style->post_content = wp_parse_args( $style->post_content, $default_values);
181
+		// fill default values
182
+		$style->post_content = $this->override_defaults($style->post_content);
183
+		$style->post_content = wp_parse_args( $style->post_content, $default_values);
184 184
 
185
-        return $style;
186
-    }
185
+		return $style;
186
+	}
187 187
 
188
-    public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
189
-        $post_atts = array(
188
+	public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
189
+		$post_atts = array(
190 190
 			'post_type'   => FrmStylesController::$post_type,
191 191
 			'post_status' => 'publish',
192 192
 			'numberposts' => $limit,
193 193
 			'orderby'     => $orderby,
194 194
 			'order'       => $order,
195
-        );
195
+		);
196 196
 
197 197
 		$temp_styles = FrmDb::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
198 198
 
199
-        if ( empty($temp_styles) ) {
200
-            global $wpdb;
201
-            // make sure there wasn't a conflict with the query
199
+		if ( empty($temp_styles) ) {
200
+			global $wpdb;
201
+			// make sure there wasn't a conflict with the query
202 202
 			$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' );
203
-            $temp_styles = FrmDb::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results');
203
+			$temp_styles = FrmDb::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results');
204 204
 
205
-            if ( empty($temp_styles) ) {
206
-                // create a new style if there are none
207
-         		$new = $this->get_new();
205
+			if ( empty($temp_styles) ) {
206
+				// create a new style if there are none
207
+		 		$new = $this->get_new();
208 208
 				$new->post_title = __( 'Formidable Style', 'formidable' );
209 209
 				$new->post_name = $new->post_title;
210
-         		$new->menu_order = 1;
211
-         		$new = $this->save( (array) $new);
212
-         		$this->update('default');
213
-
214
-                $post_atts['include'] = $new;
215
-
216
-                $temp_styles = get_posts( $post_atts );
217
-            }
218
-        }
219
-
220
-        $default_values = $this->get_defaults();
221
-        $default_style = false;
222
-
223
-        $styles = array();
224
-        foreach ( $temp_styles as $style ) {
225
-            $this->id = $style->ID;
226
-            if ( $style->menu_order ) {
227
-                if ( $default_style ) {
228
-                    // only return one default
229
-                    $style->menu_order = 0;
230
-                } else {
231
-                    // check for a default style
232
-                    $default_style = $style->ID;
233
-                }
234
-            }
235
-
236
-            $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
237
-
238
-            // fill default values
239
-            $style->post_content = $this->override_defaults($style->post_content);
240
-            $style->post_content = wp_parse_args( $style->post_content, $default_values);
210
+		 		$new->menu_order = 1;
211
+		 		$new = $this->save( (array) $new);
212
+		 		$this->update('default');
213
+
214
+				$post_atts['include'] = $new;
215
+
216
+				$temp_styles = get_posts( $post_atts );
217
+			}
218
+		}
219
+
220
+		$default_values = $this->get_defaults();
221
+		$default_style = false;
222
+
223
+		$styles = array();
224
+		foreach ( $temp_styles as $style ) {
225
+			$this->id = $style->ID;
226
+			if ( $style->menu_order ) {
227
+				if ( $default_style ) {
228
+					// only return one default
229
+					$style->menu_order = 0;
230
+				} else {
231
+					// check for a default style
232
+					$default_style = $style->ID;
233
+				}
234
+			}
235
+
236
+			$style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
237
+
238
+			// fill default values
239
+			$style->post_content = $this->override_defaults($style->post_content);
240
+			$style->post_content = wp_parse_args( $style->post_content, $default_values);
241 241
 
242 242
 			$styles[ $style->ID ] = $style;
243
-        }
243
+		}
244 244
 
245
-        if ( ! $default_style ) {
246
-            $default_style = reset($styles);
245
+		if ( ! $default_style ) {
246
+			$default_style = reset($styles);
247 247
 			$styles[ $default_style->ID ]->menu_order = 1;
248
-        }
248
+		}
249 249
 
250
-        return $styles;
251
-    }
250
+		return $styles;
251
+	}
252 252
 
253 253
 	public function get_default_style( $styles = null ) {
254
-        if ( ! isset($styles) ) {
254
+		if ( ! isset($styles) ) {
255 255
 			$styles = $this->get_all( 'menu_order', 'DESC', 1 );
256
-        }
256
+		}
257 257
 
258
-        foreach ( $styles as $style ) {
259
-            if ( $style->menu_order ) {
260
-                return $style;
261
-            }
262
-        }
263
-    }
258
+		foreach ( $styles as $style ) {
259
+			if ( $style->menu_order ) {
260
+				return $style;
261
+			}
262
+		}
263
+	}
264 264
 
265 265
 	public function override_defaults( $settings ) {
266
-	    if ( ! is_array($settings) ) {
267
-	        return $settings;
268
-	    }
269
-
270
-	    $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height'];
271
-
272
-	    if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) {
273
-	        $settings['form_desc_size'] = $settings['description_font_size'];
274
-	        $settings['form_desc_color'] = $settings['description_color'];
275
-	        $settings['title_color'] = $settings['label_color'];
276
-	    }
277
-
278
-	    if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) {
279
-	        $settings['section_color'] = $settings['label_color'];
280
-	        $settings['section_border_color'] = $settings['border_color'];
281
-	    }
282
-
283
-	    if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) {
284
-	        $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
285
-	        $settings['submit_hover_color'] = $settings['submit_text_color'];
286
-	        $settings['submit_hover_border_color'] = $settings['submit_border_color'];
287
-
288
-	        $settings['submit_active_bg_color'] = $settings['submit_bg_color'];
289
-	        $settings['submit_active_color'] = $settings['submit_text_color'];
290
-            $settings['submit_active_border_color'] = $settings['submit_border_color'];
291
-	    }
292
-
293
-	    return $settings;
266
+		if ( ! is_array($settings) ) {
267
+			return $settings;
268
+		}
269
+
270
+		$settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height'];
271
+
272
+		if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) {
273
+			$settings['form_desc_size'] = $settings['description_font_size'];
274
+			$settings['form_desc_color'] = $settings['description_color'];
275
+			$settings['title_color'] = $settings['label_color'];
276
+		}
277
+
278
+		if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) {
279
+			$settings['section_color'] = $settings['label_color'];
280
+			$settings['section_border_color'] = $settings['border_color'];
281
+		}
282
+
283
+		if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) {
284
+			$settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
285
+			$settings['submit_hover_color'] = $settings['submit_text_color'];
286
+			$settings['submit_hover_border_color'] = $settings['submit_border_color'];
287
+
288
+			$settings['submit_active_bg_color'] = $settings['submit_bg_color'];
289
+			$settings['submit_active_color'] = $settings['submit_text_color'];
290
+			$settings['submit_active_border_color'] = $settings['submit_border_color'];
291
+		}
292
+
293
+		return $settings;
294 294
 	}
295 295
 
296 296
 	public function get_defaults() {
297
-        return array(
298
-            'theme_css'         => 'ui-lightness',
299
-            'theme_name'        => 'UI Lightness',
297
+		return array(
298
+			'theme_css'         => 'ui-lightness',
299
+			'theme_name'        => 'UI Lightness',
300 300
 
301 301
 			'center_form'		=> '',
302
-            'form_width'        => '100%',
303
-            'form_align'        => 'left',
304
-            'direction'         => is_rtl() ? 'rtl' : 'ltr',
305
-            'fieldset'          => '0px',
306
-            'fieldset_color'    => '000000',
307
-            'fieldset_padding'  => '0 0 15px 0',
308
-            'fieldset_bg_color' => '',
309
-
310
-            'title_size'        => '20px',
311
-            'title_color'       => '444444',
302
+			'form_width'        => '100%',
303
+			'form_align'        => 'left',
304
+			'direction'         => is_rtl() ? 'rtl' : 'ltr',
305
+			'fieldset'          => '0px',
306
+			'fieldset_color'    => '000000',
307
+			'fieldset_padding'  => '0 0 15px 0',
308
+			'fieldset_bg_color' => '',
309
+
310
+			'title_size'        => '20px',
311
+			'title_color'       => '444444',
312 312
 			'title_margin_top'  => '10px',
313 313
 			'title_margin_bottom' => '10px',
314
-            'form_desc_size'    => '14px',
315
-            'form_desc_color'   => '666666',
314
+			'form_desc_size'    => '14px',
315
+			'form_desc_color'   => '666666',
316 316
 			'form_desc_margin_top' => '10px',
317 317
 			'form_desc_margin_bottom' => '25px',
318 318
 
319
-            'font'              => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif',
320
-            'font_size'         => '14px',
321
-            'label_color'       => '444444',
322
-            'weight'            => 'bold',
323
-            'position'          => 'none',
324
-            'align'             => 'left',
325
-            'width'             => '150px',
326
-            'required_color'    => 'B94A48',
327
-            'required_weight'   => 'bold',
328
-            'label_padding'     => '0 0 3px 0',
329
-
330
-            'description_font_size' => '12px',
331
-            'description_color' => '666666',
332
-            'description_weight' => 'normal',
333
-            'description_style' => 'normal',
334
-            'description_align' => 'left',
319
+			'font'              => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif',
320
+			'font_size'         => '14px',
321
+			'label_color'       => '444444',
322
+			'weight'            => 'bold',
323
+			'position'          => 'none',
324
+			'align'             => 'left',
325
+			'width'             => '150px',
326
+			'required_color'    => 'B94A48',
327
+			'required_weight'   => 'bold',
328
+			'label_padding'     => '0 0 3px 0',
329
+
330
+			'description_font_size' => '12px',
331
+			'description_color' => '666666',
332
+			'description_weight' => 'normal',
333
+			'description_style' => 'normal',
334
+			'description_align' => 'left',
335 335
 			'description_margin' => '0',
336 336
 
337
-            'field_font_size'   => '14px',
338
-            'field_height' 		=> '32px',
339
-            'line_height'		=> 'normal',
340
-            'field_width'       => '100%',
341
-            'auto_width'        => false,
342
-            'field_pad'         => '6px 10px',
343
-            'field_margin'      => '20px',
337
+			'field_font_size'   => '14px',
338
+			'field_height' 		=> '32px',
339
+			'line_height'		=> 'normal',
340
+			'field_width'       => '100%',
341
+			'auto_width'        => false,
342
+			'field_pad'         => '6px 10px',
343
+			'field_margin'      => '20px',
344 344
 			'field_weight' => 'normal',
345
-            'text_color'        => '555555',
346
-            //'border_color_hv'   => 'cccccc',
347
-            'border_color'      => 'cccccc',
348
-            'field_border_width' => '1px',
349
-            'field_border_style' => 'solid',
350
-
351
-            'bg_color'          => 'ffffff',
352
-            //'bg_color_hv'       => 'ffffff',
345
+			'text_color'        => '555555',
346
+			//'border_color_hv'   => 'cccccc',
347
+			'border_color'      => 'cccccc',
348
+			'field_border_width' => '1px',
349
+			'field_border_style' => 'solid',
350
+
351
+			'bg_color'          => 'ffffff',
352
+			//'bg_color_hv'       => 'ffffff',
353 353
 			'remove_box_shadow' => '',
354
-            'bg_color_active'   => 'ffffff',
354
+			'bg_color_active'   => 'ffffff',
355 355
 			'border_color_active' => '66afe9',
356 356
 			'remove_box_shadow_active' => '',
357
-            'text_color_error'  => '444444',
358
-            'bg_color_error'    => 'ffffff',
357
+			'text_color_error'  => '444444',
358
+			'bg_color_error'    => 'ffffff',
359 359
 			'border_color_error' => 'B94A48',
360 360
 			'border_width_error' => '1px',
361 361
 			'border_style_error' => 'solid',
362
-            'bg_color_disabled' => 'ffffff',
363
-            'border_color_disabled' => 'E5E5E5',
364
-            'text_color_disabled' => 'A1A1A1',
365
-
366
-            'radio_align'       => 'block',
367
-            'check_align'       => 'block',
368
-            'check_font_size'   => '13px',
369
-            'check_label_color' => '444444',
370
-            'check_weight'      => 'normal',
371
-
372
-            'section_font_size' => '18px',
373
-            'section_color'     => '444444',
374
-            'section_weight'    => 'bold',
375
-            'section_pad'       => '15px 0 3px 0',
376
-            'section_mar_top'   => '15px',
362
+			'bg_color_disabled' => 'ffffff',
363
+			'border_color_disabled' => 'E5E5E5',
364
+			'text_color_disabled' => 'A1A1A1',
365
+
366
+			'radio_align'       => 'block',
367
+			'check_align'       => 'block',
368
+			'check_font_size'   => '13px',
369
+			'check_label_color' => '444444',
370
+			'check_weight'      => 'normal',
371
+
372
+			'section_font_size' => '18px',
373
+			'section_color'     => '444444',
374
+			'section_weight'    => 'bold',
375
+			'section_pad'       => '15px 0 3px 0',
376
+			'section_mar_top'   => '15px',
377 377
 			'section_mar_bottom' => '12px',
378
-            'section_bg_color'  => '',
379
-            'section_border_color' => 'e8e8e8',
380
-            'section_border_width' => '2px',
381
-            'section_border_style' => 'solid',
382
-            'section_border_loc' => '-top',
383
-            'collapse_icon'     => '6',
384
-            'collapse_pos'      => 'after',
385
-            'repeat_icon'       => '1',
386
-
387
-            'submit_style'      => false,
388
-            'submit_font_size'  => '14px',
389
-            'submit_width'      => 'auto',
390
-            'submit_height'     => 'auto',
391
-            'submit_bg_color'   => 'ffffff',
392
-            'submit_border_color' => 'cccccc',
393
-            'submit_border_width' => '1px',
394
-            'submit_text_color' => '444444',
395
-            'submit_weight'     => 'normal',
396
-            'submit_border_radius' => '4px',
397
-            'submit_bg_img'     => '',
398
-            'submit_margin'     => '10px',
399
-            'submit_padding'    => '6px 11px',
400
-            'submit_shadow_color' => 'eeeeee',
401
-            'submit_hover_bg_color' => 'efefef',
402
-            'submit_hover_color' => '444444',
403
-            'submit_hover_border_color' => 'cccccc',
404
-            'submit_active_bg_color' => 'efefef',
405
-            'submit_active_color' => '444444',
406
-            'submit_active_border_color' => 'cccccc',
407
-
408
-            'border_radius'     => '4px',
409
-            'error_bg'          => 'F2DEDE',
410
-            'error_border'      => 'EBCCD1',
411
-            'error_text'        => 'B94A48',
412
-            'error_font_size'   => '14px',
413
-
414
-            'success_bg_color'  => 'DFF0D8',
415
-            'success_border_color' => 'D6E9C6',
416
-            'success_text_color' => '468847',
417
-            'success_font_size' => '14px',
418
-
419
-            'important_style'   => false,
378
+			'section_bg_color'  => '',
379
+			'section_border_color' => 'e8e8e8',
380
+			'section_border_width' => '2px',
381
+			'section_border_style' => 'solid',
382
+			'section_border_loc' => '-top',
383
+			'collapse_icon'     => '6',
384
+			'collapse_pos'      => 'after',
385
+			'repeat_icon'       => '1',
386
+
387
+			'submit_style'      => false,
388
+			'submit_font_size'  => '14px',
389
+			'submit_width'      => 'auto',
390
+			'submit_height'     => 'auto',
391
+			'submit_bg_color'   => 'ffffff',
392
+			'submit_border_color' => 'cccccc',
393
+			'submit_border_width' => '1px',
394
+			'submit_text_color' => '444444',
395
+			'submit_weight'     => 'normal',
396
+			'submit_border_radius' => '4px',
397
+			'submit_bg_img'     => '',
398
+			'submit_margin'     => '10px',
399
+			'submit_padding'    => '6px 11px',
400
+			'submit_shadow_color' => 'eeeeee',
401
+			'submit_hover_bg_color' => 'efefef',
402
+			'submit_hover_color' => '444444',
403
+			'submit_hover_border_color' => 'cccccc',
404
+			'submit_active_bg_color' => 'efefef',
405
+			'submit_active_color' => '444444',
406
+			'submit_active_border_color' => 'cccccc',
407
+
408
+			'border_radius'     => '4px',
409
+			'error_bg'          => 'F2DEDE',
410
+			'error_border'      => 'EBCCD1',
411
+			'error_text'        => 'B94A48',
412
+			'error_font_size'   => '14px',
413
+
414
+			'success_bg_color'  => 'DFF0D8',
415
+			'success_border_color' => 'D6E9C6',
416
+			'success_text_color' => '468847',
417
+			'success_font_size' => '14px',
418
+
419
+			'important_style'   => false,
420 420
 
421 421
 			'progress_bg_color'     => 'dddddd',
422 422
 			'progress_active_color' => 'ffffff',
@@ -426,9 +426,9 @@  discard block
 block discarded – undo
426 426
 			'progress_border_size'  => '2px',
427 427
 			'progress_size'         => '30px',
428 428
 
429
-            'custom_css'        => '',
430
-        );
431
-    }
429
+			'custom_css'        => '',
430
+		);
431
+	}
432 432
 
433 433
 	public function get_field_name( $field_name, $post_field = 'post_content' ) {
434 434
 		return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class FrmStyle {
3
-    public $number = false;	// Unique ID number of the current instance.
3
+    public $number = false; // Unique ID number of the current instance.
4 4
 	public $id = 0; // the id of the post
5 5
 
6 6
 	/**
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
         $max_slug_value = 2147483647;
17 17
         $min_slug_value = 37; // we want to have at least 2 characters in the slug
18
-        $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
18
+        $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
19 19
 
20 20
         $style = array(
21 21
             'post_type'     => FrmStylesController::$post_type,
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     public function update( $id = 'default' ) {
42 42
  		$all_instances = $this->get_all();
43 43
 
44
- 		if ( empty($id) ) {
44
+ 		if ( empty( $id ) ) {
45 45
  		     $new_style = (array) $this->get_new();
46 46
  		     $all_instances[] = $new_style;
47 47
  		}
@@ -49,15 +49,15 @@  discard block
 block discarded – undo
49 49
         $action_ids = array();
50 50
 
51 51
  		foreach ( $all_instances as $number => $new_instance ) {
52
- 			$new_instance = stripslashes_deep( (array) $new_instance);
52
+ 			$new_instance = stripslashes_deep( (array) $new_instance );
53 53
  			$this->id = $new_instance['ID'];
54
- 			if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) {
55
-				$all_instances[ $number ] = $new_instance;
54
+ 			if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) {
55
+				$all_instances[$number] = $new_instance;
56 56
 
57
- 			    if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) {
57
+ 			    if ( $new_instance['menu_order'] && $_POST && empty( $_POST['prev_menu_order'] ) && isset( $_POST['frm_style_setting']['menu_order'] ) ) {
58 58
  			        // this style was set to default, so remove default setting on previous default style
59 59
  			        $new_instance['menu_order'] = 0;
60
- 			        $action_ids[] = $this->save($new_instance);
60
+ 			        $action_ids[] = $this->save( $new_instance );
61 61
  			    }
62 62
 
63 63
  			    // don't continue if not saving this style
@@ -67,33 +67,33 @@  discard block
 block discarded – undo
67 67
  			$new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] );
68 68
  			$new_instance['post_content'] = $_POST['frm_style_setting']['post_content'];
69 69
  			$new_instance['post_type']  = FrmStylesController::$post_type;
70
-            $new_instance['post_status']  = 'publish';
70
+            $new_instance['post_status'] = 'publish';
71 71
 			$new_instance['menu_order']  = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0;
72 72
 
73
-            if ( empty($id) ) {
73
+            if ( empty( $id ) ) {
74 74
                 $new_instance['post_name'] = $new_instance['post_title'];
75 75
             }
76 76
 
77 77
             $default_settings = $this->get_defaults();
78 78
 
79 79
             foreach ( $default_settings as $setting => $default ) {
80
-				if ( ! isset( $new_instance['post_content'][ $setting ] ) ) {
81
-					$new_instance['post_content'][ $setting ] = $default;
80
+				if ( ! isset( $new_instance['post_content'][$setting] ) ) {
81
+					$new_instance['post_content'][$setting] = $default;
82 82
 				}
83 83
 
84 84
 				if ( strpos( $setting, 'color' ) !== false || in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ) ) ) {
85 85
                     //if is a color
86
-					$new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] );
87
-				} else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) {
88
-					$new_instance['post_content'][ $setting ] = 0;
86
+					$new_instance['post_content'][$setting] = str_replace( '#', '', $new_instance['post_content'][$setting] );
87
+				} else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][$setting] ) ) {
88
+					$new_instance['post_content'][$setting] = 0;
89 89
                 } else if ( $setting == 'font' ) {
90
-                	$new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
90
+                	$new_instance['post_content'][$setting] = $this->force_balanced_quotation( $new_instance['post_content'][$setting] );
91 91
                 }
92 92
             }
93 93
 
94
-			$all_instances[ $number ] = $new_instance;
94
+			$all_instances[$number] = $new_instance;
95 95
 
96
-            $action_ids[] = $this->save($new_instance);
96
+            $action_ids[] = $this->save( $new_instance );
97 97
 
98 98
  		}
99 99
 
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
      */
108 108
 	public function save_settings() {
109 109
 		$filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php';
110
-		update_option( 'frm_last_style_update', date('njGi') );
110
+		update_option( 'frm_last_style_update', date( 'njGi' ) );
111 111
 
112
-        if ( ! is_file($filename) ) {
112
+        if ( ! is_file( $filename ) ) {
113 113
             return;
114 114
         }
115 115
 
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 		$create_file = new FrmCreateFile( array( 'folder_name' => 'formidable/css', 'file_name' => 'formidablepro.css' ) );
121 121
 		$create_file->create_file( $css );
122 122
 
123
-        update_option('frmpro_css', $css);
123
+        update_option( 'frmpro_css', $css );
124 124
 
125
-        set_transient('frmpro_css', $css);
125
+        set_transient( 'frmpro_css', $css );
126 126
 	}
127 127
 
128 128
 	private function get_css_content( $filename ) {
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	}
155 155
 
156 156
 	public function destroy( $id ) {
157
-        return wp_delete_post($id);
157
+        return wp_delete_post( $id );
158 158
     }
159 159
 
160 160
     public function get_one() {
@@ -168,19 +168,19 @@  discard block
 block discarded – undo
168 168
             return $style;
169 169
         }
170 170
 
171
-        $style = get_post($this->id);
171
+        $style = get_post( $this->id );
172 172
 
173 173
         if ( ! $style ) {
174 174
             return $style;
175 175
         }
176 176
 
177
-        $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
177
+        $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
178 178
 
179 179
         $default_values = $this->get_defaults();
180 180
 
181 181
         // fill default values
182
-        $style->post_content = $this->override_defaults($style->post_content);
183
-        $style->post_content = wp_parse_args( $style->post_content, $default_values);
182
+        $style->post_content = $this->override_defaults( $style->post_content );
183
+        $style->post_content = wp_parse_args( $style->post_content, $default_values );
184 184
 
185 185
         return $style;
186 186
     }
@@ -196,20 +196,20 @@  discard block
 block discarded – undo
196 196
 
197 197
 		$temp_styles = FrmDb::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
198 198
 
199
-        if ( empty($temp_styles) ) {
199
+        if ( empty( $temp_styles ) ) {
200 200
             global $wpdb;
201 201
             // make sure there wasn't a conflict with the query
202 202
 			$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' );
203
-            $temp_styles = FrmDb::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results');
203
+            $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
204 204
 
205
-            if ( empty($temp_styles) ) {
205
+            if ( empty( $temp_styles ) ) {
206 206
                 // create a new style if there are none
207 207
          		$new = $this->get_new();
208 208
 				$new->post_title = __( 'Formidable Style', 'formidable' );
209 209
 				$new->post_name = $new->post_title;
210 210
          		$new->menu_order = 1;
211
-         		$new = $this->save( (array) $new);
212
-         		$this->update('default');
211
+         		$new = $this->save( (array) $new );
212
+         		$this->update( 'default' );
213 213
 
214 214
                 $post_atts['include'] = $new;
215 215
 
@@ -233,25 +233,25 @@  discard block
 block discarded – undo
233 233
                 }
234 234
             }
235 235
 
236
-            $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
236
+            $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
237 237
 
238 238
             // fill default values
239
-            $style->post_content = $this->override_defaults($style->post_content);
240
-            $style->post_content = wp_parse_args( $style->post_content, $default_values);
239
+            $style->post_content = $this->override_defaults( $style->post_content );
240
+            $style->post_content = wp_parse_args( $style->post_content, $default_values );
241 241
 
242
-			$styles[ $style->ID ] = $style;
242
+			$styles[$style->ID] = $style;
243 243
         }
244 244
 
245 245
         if ( ! $default_style ) {
246
-            $default_style = reset($styles);
247
-			$styles[ $default_style->ID ]->menu_order = 1;
246
+            $default_style = reset( $styles );
247
+			$styles[$default_style->ID]->menu_order = 1;
248 248
         }
249 249
 
250 250
         return $styles;
251 251
     }
252 252
 
253 253
 	public function get_default_style( $styles = null ) {
254
-        if ( ! isset($styles) ) {
254
+        if ( ! isset( $styles ) ) {
255 255
 			$styles = $this->get_all( 'menu_order', 'DESC', 1 );
256 256
         }
257 257
 
@@ -263,24 +263,24 @@  discard block
 block discarded – undo
263 263
     }
264 264
 
265 265
 	public function override_defaults( $settings ) {
266
-	    if ( ! is_array($settings) ) {
266
+	    if ( ! is_array( $settings ) ) {
267 267
 	        return $settings;
268 268
 	    }
269 269
 
270
-	    $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height'];
270
+	    $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height'];
271 271
 
272
-	    if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) {
272
+	    if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
273 273
 	        $settings['form_desc_size'] = $settings['description_font_size'];
274 274
 	        $settings['form_desc_color'] = $settings['description_color'];
275 275
 	        $settings['title_color'] = $settings['label_color'];
276 276
 	    }
277 277
 
278
-	    if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) {
278
+	    if ( ! isset( $settings['section_color'] ) && isset( $settings['label_color'] ) ) {
279 279
 	        $settings['section_color'] = $settings['label_color'];
280 280
 	        $settings['section_border_color'] = $settings['border_color'];
281 281
 	    }
282 282
 
283
-	    if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) {
283
+	    if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) {
284 284
 	        $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
285 285
 	        $settings['submit_hover_color'] = $settings['submit_text_color'];
286 286
 	        $settings['submit_hover_border_color'] = $settings['submit_border_color'];
Please login to merge, or discard this patch.
classes/models/FrmEntry.php 2 patches
Indentation   +354 added lines, -354 removed lines patch added patch discarded remove patch
@@ -6,11 +6,11 @@  discard block
 block discarded – undo
6 6
 class FrmEntry {
7 7
 
8 8
 	/**
9
-	* Create a new entry
10
-	*
11
-	* @param array $values
12
-	* @return int | boolean $entry_id
13
-	*/
9
+	 * Create a new entry
10
+	 *
11
+	 * @param array $values
12
+	 * @return int | boolean $entry_id
13
+	 */
14 14
 	public static function create( $values ) {
15 15
 		$entry_id = self::create_entry( $values, 'standard' );
16 16
 
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	/**
21
-	* Create a new entry with some differences depending on type
22
-	*
23
-	* @param array $values
24
-	* @param string $type
25
-	* @return int | boolean $entry_id
26
-	*/
21
+	 * Create a new entry with some differences depending on type
22
+	 *
23
+	 * @param array $values
24
+	 * @param string $type
25
+	 * @return int | boolean $entry_id
26
+	 */
27 27
 	private static function create_entry( $values, $type ) {
28 28
 		$new_values = self::before_insert_entry_in_database( $values, $type );
29 29
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 		return $entry_id;
38 38
 	}
39 39
 
40
-    /**
41
-     * check for duplicate entries created in the last minute
42
-     * @return boolean
43
-     */
40
+	/**
41
+	 * check for duplicate entries created in the last minute
42
+	 * @return boolean
43
+	 */
44 44
 	public static function is_duplicate( $new_values, $values ) {
45 45
 		$duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values );
46 46
 
@@ -48,55 +48,55 @@  discard block
 block discarded – undo
48 48
 			return false;
49 49
 		}
50 50
 
51
-        $check_val = $new_values;
51
+		$check_val = $new_values;
52 52
 		$check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) );
53 53
 
54 54
 		unset( $check_val['created_at'], $check_val['updated_at'] );
55 55
 		unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
56 56
 
57
-        if ( $new_values['item_key'] == $new_values['name'] ) {
58
-            unset($check_val['name']);
59
-        }
57
+		if ( $new_values['item_key'] == $new_values['name'] ) {
58
+			unset($check_val['name']);
59
+		}
60 60
 
61
-        global $wpdb;
61
+		global $wpdb;
62 62
 		$entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
63 63
 
64
-        if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
65
-            return false;
66
-        }
64
+		if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
65
+			return false;
66
+		}
67 67
 
68
-        $is_duplicate = false;
69
-        foreach ( $entry_exists as $entry_exist ) {
70
-            $is_duplicate = true;
68
+		$is_duplicate = false;
69
+		foreach ( $entry_exists as $entry_exist ) {
70
+			$is_duplicate = true;
71 71
 
72
-            //add more checks here to make sure it's a duplicate
73
-            $metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
74
-            $field_metas = array();
75
-            foreach ( $metas as $meta ) {
72
+			//add more checks here to make sure it's a duplicate
73
+			$metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
74
+			$field_metas = array();
75
+			foreach ( $metas as $meta ) {
76 76
 				$field_metas[ $meta->field_id ] = $meta->meta_value;
77
-            }
78
-
79
-            // If prev entry is empty and current entry is not, they are not duplicates
80
-            $filtered_vals = array_filter( $values['item_meta'] );
81
-            if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
82
-                return false;
83
-            }
84
-
85
-            $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
86
-            foreach ( $diff as $field_id => $meta_value ) {
87
-                if ( ! empty($meta_value) ) {
88
-                    $is_duplicate = false;
89
-                    continue;
90
-                }
91
-            }
92
-
93
-            if ( $is_duplicate ) {
77
+			}
78
+
79
+			// If prev entry is empty and current entry is not, they are not duplicates
80
+			$filtered_vals = array_filter( $values['item_meta'] );
81
+			if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
82
+				return false;
83
+			}
84
+
85
+			$diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
86
+			foreach ( $diff as $field_id => $meta_value ) {
87
+				if ( ! empty($meta_value) ) {
88
+					$is_duplicate = false;
89
+					continue;
90
+				}
91
+			}
92
+
93
+			if ( $is_duplicate ) {
94 94
 				break;
95
-            }
96
-        }
95
+			}
96
+		}
97 97
 
98
-        return $is_duplicate;
99
-    }
98
+		return $is_duplicate;
99
+	}
100 100
 
101 101
 	/**
102 102
 	 * Determine if an entry needs to be checked as a possible duplicate
@@ -125,48 +125,48 @@  discard block
 block discarded – undo
125 125
 		return true;
126 126
 	}
127 127
 
128
-    public static function duplicate( $id ) {
129
-        global $wpdb;
128
+	public static function duplicate( $id ) {
129
+		global $wpdb;
130 130
 
131
-        $values = self::getOne( $id );
131
+		$values = self::getOne( $id );
132 132
 
133
-        $new_values = array();
133
+		$new_values = array();
134 134
 		$new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
135
-        $new_values['name'] = $values->name;
136
-        $new_values['is_draft'] = $values->is_draft;
135
+		$new_values['name'] = $values->name;
136
+		$new_values['is_draft'] = $values->is_draft;
137 137
 		$new_values['user_id'] = (int) $values->user_id;
138 138
 		$new_values['updated_by'] = (int) $values->user_id;
139
-        $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
139
+		$new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
140 140
 		$new_values['created_at'] = current_time( 'mysql', 1 );
141 141
 		$new_values['updated_at'] = $new_values['created_at'];
142 142
 
143 143
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
144
-        if ( ! $query_results ) {
145
-            return false;
146
-        }
144
+		if ( ! $query_results ) {
145
+			return false;
146
+		}
147 147
 
148
-        $entry_id = $wpdb->insert_id;
148
+		$entry_id = $wpdb->insert_id;
149 149
 
150
-        global $frm_vars;
151
-        if ( ! isset($frm_vars['saved_entries']) ) {
152
-            $frm_vars['saved_entries'] = array();
153
-        }
154
-        $frm_vars['saved_entries'][] = (int) $entry_id;
150
+		global $frm_vars;
151
+		if ( ! isset($frm_vars['saved_entries']) ) {
152
+			$frm_vars['saved_entries'] = array();
153
+		}
154
+		$frm_vars['saved_entries'][] = (int) $entry_id;
155 155
 
156
-        FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
156
+		FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
157 157
 		self::clear_cache();
158 158
 
159 159
 		do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
160
-        return $entry_id;
161
-    }
160
+		return $entry_id;
161
+	}
162 162
 
163 163
 	/**
164
-	* Update an entry (not via XML)
165
-	*
166
-	* @param int $id
167
-	* @param array $values
168
-	* @return boolean|int $update_results
169
-	*/
164
+	 * Update an entry (not via XML)
165
+	 *
166
+	 * @param int $id
167
+	 * @param array $values
168
+	 * @return boolean|int $update_results
169
+	 */
170 170
 	public static function update( $id, $values ) {
171 171
 		$update_results = self::update_entry( $id, $values, 'standard' );
172 172
 
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 	}
175 175
 
176 176
 	/**
177
-	* Update an entry with some differences depending on the update type
178
-	*
179
-	* @since 2.0.16
180
-	*
181
-	* @param int $id
182
-	* @param array $values
183
-	* @return boolean|int $query_results
184
-	*/
177
+	 * Update an entry with some differences depending on the update type
178
+	 *
179
+	 * @since 2.0.16
180
+	 *
181
+	 * @param int $id
182
+	 * @param array $values
183
+	 * @return boolean|int $query_results
184
+	 */
185 185
 	private static function update_entry( $id, $values, $update_type ) {
186 186
 		global $wpdb;
187 187
 
@@ -200,34 +200,34 @@  discard block
 block discarded – undo
200 200
 	}
201 201
 
202 202
 	public static function destroy( $id ) {
203
-        global $wpdb;
204
-        $id = (int) $id;
203
+		global $wpdb;
204
+		$id = (int) $id;
205 205
 
206 206
 		$entry = self::getOne( $id );
207
-        if ( ! $entry ) {
208
-            $result = false;
209
-            return $result;
210
-        }
207
+		if ( ! $entry ) {
208
+			$result = false;
209
+			return $result;
210
+		}
211 211
 
212
-        do_action('frm_before_destroy_entry', $id, $entry);
212
+		do_action('frm_before_destroy_entry', $id, $entry);
213 213
 
214 214
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
215 215
 		$result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
216 216
 
217 217
 		self::clear_cache();
218 218
 
219
-        return $result;
220
-    }
219
+		return $result;
220
+	}
221 221
 
222 222
 	public static function update_form( $id, $value, $form_id ) {
223
-        global $wpdb;
224
-        $form_id = isset($value) ? $form_id : null;
223
+		global $wpdb;
224
+		$form_id = isset($value) ? $form_id : null;
225 225
 		$result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
226 226
 		if ( $result ) {
227 227
 			self::clear_cache();
228 228
 		}
229
-        return $result;
230
-    }
229
+		return $result;
230
+	}
231 231
 
232 232
 	/**
233 233
 	 * Clear entry caching
@@ -263,159 +263,159 @@  discard block
 block discarded – undo
263 263
 	}
264 264
 
265 265
 	public static function getOne( $id, $meta = false ) {
266
-        global $wpdb;
266
+		global $wpdb;
267 267
 
268
-        $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
268
+		$query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
269 269
                   LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
270 270
 
271
-        $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
272
-        $query_args = array( $id );
273
-        $query = $wpdb->prepare( $query, $query_args );
271
+		$query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
272
+		$query_args = array( $id );
273
+		$query = $wpdb->prepare( $query, $query_args );
274 274
 
275
-        if ( ! $meta ) {
275
+		if ( ! $meta ) {
276 276
 			$entry = FrmDb::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
277
-            return stripslashes_deep($entry);
278
-        }
277
+			return stripslashes_deep($entry);
278
+		}
279 279
 
280
-        $entry = FrmDb::check_cache( $id, 'frm_entry' );
281
-        if ( $entry !== false ) {
282
-            return stripslashes_deep($entry);
283
-        }
280
+		$entry = FrmDb::check_cache( $id, 'frm_entry' );
281
+		if ( $entry !== false ) {
282
+			return stripslashes_deep($entry);
283
+		}
284 284
 
285
-        $entry = $wpdb->get_row( $query );
286
-        $entry = self::get_meta($entry);
285
+		$entry = $wpdb->get_row( $query );
286
+		$entry = self::get_meta($entry);
287 287
 
288
-        return stripslashes_deep($entry);
289
-    }
288
+		return stripslashes_deep($entry);
289
+	}
290 290
 
291 291
 	public static function get_meta( $entry ) {
292
-        if ( ! $entry ) {
293
-            return $entry;
294
-        }
292
+		if ( ! $entry ) {
293
+			return $entry;
294
+		}
295 295
 
296
-        global $wpdb;
296
+		global $wpdb;
297 297
 		$metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id', array( 'item_id' => $entry->id, 'field_id !' => 0 ), 'field_id, meta_value, field_key, item_id' );
298 298
 
299
-        $entry->metas = array();
299
+		$entry->metas = array();
300 300
 
301 301
 		$include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
302
-        foreach ( $metas as $meta_val ) {
303
-            if ( $meta_val->item_id == $entry->id ) {
302
+		foreach ( $metas as $meta_val ) {
303
+			if ( $meta_val->item_id == $entry->id ) {
304 304
 				$entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
305 305
 				if ( $include_key ) {
306 306
 					$entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
307 307
 				}
308
-                 continue;
309
-            }
308
+				 continue;
309
+			}
310 310
 
311
-            // include sub entries in an array
311
+			// include sub entries in an array
312 312
 			if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
313 313
 				$entry->metas[ $meta_val->field_id ] = array();
314
-            }
314
+			}
315 315
 
316 316
 			$entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
317 317
 
318
-            unset($meta_val);
319
-        }
320
-        unset($metas);
318
+			unset($meta_val);
319
+		}
320
+		unset($metas);
321 321
 
322 322
 		FrmDb::set_cache( $entry->id, $entry, 'frm_entry' );
323 323
 
324
-        return $entry;
325
-    }
324
+		return $entry;
325
+	}
326 326
 
327
-    /**
328
-     * @param string $id
329
-     */
327
+	/**
328
+	 * @param string $id
329
+	 */
330 330
 	public static function exists( $id ) {
331
-        global $wpdb;
332
-
333
-        if ( FrmDb::check_cache( $id, 'frm_entry' ) ) {
334
-            $exists = true;
335
-            return $exists;
336
-        }
337
-
338
-        if ( is_numeric($id) ) {
339
-            $where = array( 'id' => $id );
340
-        } else {
341
-            $where = array( 'item_key' => $id );
342
-        }
331
+		global $wpdb;
332
+
333
+		if ( FrmDb::check_cache( $id, 'frm_entry' ) ) {
334
+			$exists = true;
335
+			return $exists;
336
+		}
337
+
338
+		if ( is_numeric($id) ) {
339
+			$where = array( 'id' => $id );
340
+		} else {
341
+			$where = array( 'item_key' => $id );
342
+		}
343 343
 		$id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
344 344
 
345
-        $exists = ($id && $id > 0) ? true : false;
346
-        return $exists;
347
-    }
345
+		$exists = ($id && $id > 0) ? true : false;
346
+		return $exists;
347
+	}
348 348
 
349
-    public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
349
+	public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
350 350
 		global $wpdb;
351 351
 
352
-        $limit = FrmDb::esc_limit($limit);
352
+		$limit = FrmDb::esc_limit($limit);
353 353
 
354
-        $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
355
-        $entries = wp_cache_get($cache_key, 'frm_entry');
354
+		$cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
355
+		$entries = wp_cache_get($cache_key, 'frm_entry');
356 356
 
357
-        if ( false === $entries ) {
358
-            $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
357
+		if ( false === $entries ) {
358
+			$fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
359 359
 			$table = $wpdb->prefix . 'frm_items it ';
360 360
 
361
-            if ( $inc_form ) {
362
-                $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
363
-                $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
364
-            }
361
+			if ( $inc_form ) {
362
+				$fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
363
+				$table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
364
+			}
365 365
 
366
-            if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
367
-    		    // sort by a requested field
368
-                $field_id = (int) $order_matches[1];
366
+			if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
367
+				// sort by a requested field
368
+				$field_id = (int) $order_matches[1];
369 369
 				$fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id;
370 370
 				unset( $order_matches, $field_id );
371
-		    }
371
+			}
372 372
 
373 373
 			// prepare the query
374 374
 			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
375 375
 
376
-            $entries = $wpdb->get_results($query, OBJECT_K);
377
-            unset($query);
376
+			$entries = $wpdb->get_results($query, OBJECT_K);
377
+			unset($query);
378 378
 
379 379
 			FrmDb::set_cache( $cache_key, $entries, 'frm_entry' );
380
-        }
380
+		}
381 381
 
382
-        if ( ! $meta || ! $entries ) {
383
-            return stripslashes_deep($entries);
384
-        }
385
-        unset($meta);
382
+		if ( ! $meta || ! $entries ) {
383
+			return stripslashes_deep($entries);
384
+		}
385
+		unset($meta);
386 386
 
387
-        if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
387
+		if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
388 388
 			$where = array( 'it.form_id' => substr( $where, 11 ) );
389
-        }
389
+		}
390 390
 
391
-        $meta_where = array( 'field_id !' => 0 );
392
-        if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
393
-            $meta_where['fi.form_id'] = $where['it.form_id'];
394
-        } else {
395
-            $meta_where['item_id'] = array_keys( $entries );
396
-        }
391
+		$meta_where = array( 'field_id !' => 0 );
392
+		if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
393
+			$meta_where['fi.form_id'] = $where['it.form_id'];
394
+		} else {
395
+			$meta_where['item_id'] = array_keys( $entries );
396
+		}
397 397
 
398
-        $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
398
+		$metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
399 399
 
400
-        unset( $meta_where );
400
+		unset( $meta_where );
401 401
 
402
-        if ( ! $metas ) {
403
-            return stripslashes_deep($entries);
404
-        }
402
+		if ( ! $metas ) {
403
+			return stripslashes_deep($entries);
404
+		}
405 405
 
406
-        foreach ( $metas as $m_key => $meta_val ) {
407
-            if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
408
-                continue;
409
-            }
406
+		foreach ( $metas as $m_key => $meta_val ) {
407
+			if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
408
+				continue;
409
+			}
410 410
 
411
-            if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
411
+			if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
412 412
 				$entries[ $meta_val->item_id ]->metas = array();
413
-            }
413
+			}
414 414
 
415 415
 			$entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
416 416
 
417
-            unset($m_key, $meta_val);
418
-        }
417
+			unset($m_key, $meta_val);
418
+		}
419 419
 
420 420
 		if ( ! FrmAppHelper::prevent_caching() ) {
421 421
 			foreach ( $entries as $entry ) {
@@ -424,31 +424,31 @@  discard block
 block discarded – undo
424 424
 			}
425 425
 		}
426 426
 
427
-        return stripslashes_deep($entries);
428
-    }
427
+		return stripslashes_deep($entries);
428
+	}
429 429
 
430
-    // Pagination Methods
431
-    public static function getRecordCount( $where = '' ) {
432
-        global $wpdb;
430
+	// Pagination Methods
431
+	public static function getRecordCount( $where = '' ) {
432
+		global $wpdb;
433 433
 		$table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
434 434
 
435
-        if ( is_numeric($where) ) {
436
-            $table_join = 'frm_items';
437
-            $where = array( 'form_id' => $where );
438
-        }
435
+		if ( is_numeric($where) ) {
436
+			$table_join = 'frm_items';
437
+			$where = array( 'form_id' => $where );
438
+		}
439 439
 
440
-        if ( is_array( $where ) ) {
441
-            $count = FrmDb::get_count( $table_join, $where );
442
-        } else {
440
+		if ( is_array( $where ) ) {
441
+			$count = FrmDb::get_count( $table_join, $where );
442
+		} else {
443 443
 			$cache_key = 'count_' . maybe_serialize( $where );
444 444
 			$query = 'SELECT COUNT(*) FROM ' . $table_join . FrmDb::prepend_and_or_where( ' WHERE ', $where );
445 445
 			$count = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_var' );
446
-        }
446
+		}
447 447
 
448
-        return $count;
449
-    }
448
+		return $count;
449
+	}
450 450
 
451
-    public static function getPageCount( $p_size, $where = '' ) {
451
+	public static function getPageCount( $p_size, $where = '' ) {
452 452
 		$p_size = (int) $p_size;
453 453
 		$count = 1;
454 454
 		if ( $p_size ) {
@@ -459,16 +459,16 @@  discard block
 block discarded – undo
459 459
 		}
460 460
 
461 461
 		return $count;
462
-    }
462
+	}
463 463
 
464 464
 	/**
465
-	* Prepare the data before inserting it into the database
466
-	*
467
-	* @since 2.0.16
468
-	* @param array $values
469
-	* @param string $type
470
-	* @return array $new_values
471
-	*/
465
+	 * Prepare the data before inserting it into the database
466
+	 *
467
+	 * @since 2.0.16
468
+	 * @param array $values
469
+	 * @param string $type
470
+	 * @return array $new_values
471
+	 */
472 472
 	private static function before_insert_entry_in_database( &$values, $type ) {
473 473
 
474 474
 		self::sanitize_entry_post( $values );
@@ -483,13 +483,13 @@  discard block
 block discarded – undo
483 483
 	}
484 484
 
485 485
 	/**
486
-	* Create an entry and perform after create actions
487
-	*
488
-	* @since 2.0.16
489
-	* @param array $values
490
-	* @param array $new_values
491
-	* @return boolean|int $entry_id
492
-	*/
486
+	 * Create an entry and perform after create actions
487
+	 *
488
+	 * @since 2.0.16
489
+	 * @param array $values
490
+	 * @param array $new_values
491
+	 * @return boolean|int $entry_id
492
+	 */
493 493
 	private static function continue_to_create_entry( $values, $new_values ) {
494 494
 		$entry_id = self::insert_entry_into_database( $new_values );
495 495
 		if ( ! $entry_id ) {
@@ -501,37 +501,37 @@  discard block
 block discarded – undo
501 501
 		return $entry_id;
502 502
 	}
503 503
 
504
-    /**
505
-     * Sanitize the POST values before we use them
506
-     *
507
-     * @since 2.0
508
-     * @param array $values The POST values by reference
509
-     */
510
-    public static function sanitize_entry_post( &$values ) {
511
-        $sanitize_method = array(
512
-            'form_id'       => 'absint',
513
-            'frm_action'    => 'sanitize_title',
514
-            'form_key'      => 'sanitize_title',
515
-            'item_key'      => 'sanitize_title',
516
-            'item_name'     => 'sanitize_text_field',
517
-            'frm_saving_draft' => 'absint',
518
-            'is_draft'      => 'absint',
519
-            'post_id'       => 'absint',
520
-            'parent_item_id' => 'absint',
521
-            'created_at'    => 'sanitize_text_field',
522
-            'updated_at'    => 'sanitize_text_field',
523
-        );
524
-
525
-        FrmAppHelper::sanitize_request( $sanitize_method, $values );
526
-    }
504
+	/**
505
+	 * Sanitize the POST values before we use them
506
+	 *
507
+	 * @since 2.0
508
+	 * @param array $values The POST values by reference
509
+	 */
510
+	public static function sanitize_entry_post( &$values ) {
511
+		$sanitize_method = array(
512
+			'form_id'       => 'absint',
513
+			'frm_action'    => 'sanitize_title',
514
+			'form_key'      => 'sanitize_title',
515
+			'item_key'      => 'sanitize_title',
516
+			'item_name'     => 'sanitize_text_field',
517
+			'frm_saving_draft' => 'absint',
518
+			'is_draft'      => 'absint',
519
+			'post_id'       => 'absint',
520
+			'parent_item_id' => 'absint',
521
+			'created_at'    => 'sanitize_text_field',
522
+			'updated_at'    => 'sanitize_text_field',
523
+		);
524
+
525
+		FrmAppHelper::sanitize_request( $sanitize_method, $values );
526
+	}
527 527
 
528 528
 	/**
529
-	* Prepare the new values for inserting into the database
530
-	*
531
-	* @since 2.0.16
532
-	* @param array $values
533
-	* @return array $new_values
534
-	*/
529
+	 * Prepare the new values for inserting into the database
530
+	 *
531
+	 * @since 2.0.16
532
+	 * @param array $values
533
+	 * @return array $new_values
534
+	 */
535 535
 	private static function package_entry_data( &$values ) {
536 536
 		global $wpdb;
537 537
 
@@ -588,34 +588,34 @@  discard block
 block discarded – undo
588 588
 	}
589 589
 
590 590
 	/**
591
-	* Get the is_draft value for a new entry
592
-	*
593
-	* @since 2.0.16
594
-	* @param array $values
595
-	* @return int
596
-	*/
591
+	 * Get the is_draft value for a new entry
592
+	 *
593
+	 * @since 2.0.16
594
+	 * @param array $values
595
+	 * @return int
596
+	 */
597 597
 	private static function get_is_draft_value( $values ) {
598 598
 		return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
599 599
 	}
600 600
 
601 601
 	/**
602
-	* Get the created_at value for a new entry
603
-	*
604
-	* @since 2.0.16
605
-	* @param array $values
606
-	* @return string
607
-	*/
602
+	 * Get the created_at value for a new entry
603
+	 *
604
+	 * @since 2.0.16
605
+	 * @param array $values
606
+	 * @return string
607
+	 */
608 608
 	private static function get_created_at( $values ) {
609 609
 		return self::get_entry_value( $values, 'created_at', current_time( 'mysql', 1 ) );
610 610
 	}
611 611
 
612 612
 	/**
613
-	* Get the updated_at value for a new entry
614
-	*
615
-	* @since 2.0.16
616
-	* @param array $values
617
-	* @return string
618
-	*/
613
+	 * Get the updated_at value for a new entry
614
+	 *
615
+	 * @since 2.0.16
616
+	 * @param array $values
617
+	 * @return string
618
+	 */
619 619
 	private static function get_updated_at( $values ) {
620 620
 		if ( isset( $values['updated_at'] ) ) {
621 621
 			$updated_at = $values['updated_at'];
@@ -627,12 +627,12 @@  discard block
 block discarded – undo
627 627
 	}
628 628
 
629 629
 	/**
630
-	* Get the description value for a new entry
631
-	*
632
-	* @since 2.0.16
633
-	* @param array $values
634
-	* @return string
635
-	*/
630
+	 * Get the description value for a new entry
631
+	 *
632
+	 * @since 2.0.16
633
+	 * @param array $values
634
+	 * @return string
635
+	 */
636 636
 	private static function get_entry_description( $values ) {
637 637
 		if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
638 638
 			$description = maybe_serialize( $values['description'] );
@@ -647,12 +647,12 @@  discard block
 block discarded – undo
647 647
 	}
648 648
 
649 649
 	/**
650
-	* Get the user_id value for a new entry
651
-	*
652
-	* @since 2.0.16
653
-	* @param array $values
654
-	* @return int
655
-	*/
650
+	 * Get the user_id value for a new entry
651
+	 *
652
+	 * @since 2.0.16
653
+	 * @param array $values
654
+	 * @return int
655
+	 */
656 656
 	private static function get_entry_user_id( $values ) {
657 657
 		if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) {
658 658
 			$user_id = $values['frm_user_id'];
@@ -665,12 +665,12 @@  discard block
 block discarded – undo
665 665
 	}
666 666
 
667 667
 	/**
668
-	* Insert new entry into the database
669
-	*
670
-	* @since 2.0.16
671
-	* @param array $new_values
672
-	* @return int | boolean $entry_id
673
-	*/
668
+	 * Insert new entry into the database
669
+	 *
670
+	 * @since 2.0.16
671
+	 * @param array $new_values
672
+	 * @return int | boolean $entry_id
673
+	 */
674 674
 	private static function insert_entry_into_database( $new_values ) {
675 675
 		global $wpdb;
676 676
 
@@ -686,11 +686,11 @@  discard block
 block discarded – undo
686 686
 	}
687 687
 
688 688
 	/**
689
-	* Add the new entry to global $frm_vars
690
-	*
691
-	* @since 2.0.16
692
-	* @param int $entry_id
693
-	*/
689
+	 * Add the new entry to global $frm_vars
690
+	 *
691
+	 * @since 2.0.16
692
+	 * @param int $entry_id
693
+	 */
694 694
 	private static function add_new_entry_to_frm_vars( $entry_id ) {
695 695
 		global $frm_vars;
696 696
 
@@ -702,12 +702,12 @@  discard block
 block discarded – undo
702 702
 	}
703 703
 
704 704
 	/**
705
-	* Add entry metas, if there are any
706
-	*
707
-	* @since 2.0.16
708
-	* @param array $values
709
-	* @param int $entry_id
710
-	*/
705
+	 * Add entry metas, if there are any
706
+	 *
707
+	 * @since 2.0.16
708
+	 * @param array $values
709
+	 * @param int $entry_id
710
+	 */
711 711
 	private static function maybe_add_entry_metas( $values, $entry_id ) {
712 712
 		if ( isset($values['item_meta']) ) {
713 713
 			FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
@@ -715,12 +715,12 @@  discard block
 block discarded – undo
715 715
 	}
716 716
 
717 717
 	/**
718
-	* Trigger frm_after_create_entry hooks
719
-	*
720
-	* @since 2.0.16
721
-	* @param int $entry_id
722
-	* @param array $new_values
723
-	*/
718
+	 * Trigger frm_after_create_entry hooks
719
+	 *
720
+	 * @since 2.0.16
721
+	 * @param int $entry_id
722
+	 * @param array $new_values
723
+	 */
724 724
 	private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
725 725
 		// this is a child entry
726 726
 		$is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
@@ -730,13 +730,13 @@  discard block
 block discarded – undo
730 730
 	}
731 731
 
732 732
 	/**
733
-	* Actions to perform immediately after an entry is inserted in the frm_items database
734
-	*
735
-	* @since 2.0.16
736
-	* @param array $values
737
-	* @param array $new_values
738
-	* @param int $entry_id
739
-	*/
733
+	 * Actions to perform immediately after an entry is inserted in the frm_items database
734
+	 *
735
+	 * @since 2.0.16
736
+	 * @param array $values
737
+	 * @param array $new_values
738
+	 * @param int $entry_id
739
+	 */
740 740
 	private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
741 741
 
742 742
 		self::add_new_entry_to_frm_vars( $entry_id );
@@ -749,14 +749,14 @@  discard block
 block discarded – undo
749 749
 	}
750 750
 
751 751
 	/**
752
-	* Perform some actions right before updating an entry
753
-	*
754
-	* @since 2.0.16
755
-	* @param int $id
756
-	* @param array $values
757
-	* @param string $update_type
758
-	* @return boolean $update
759
-	*/
752
+	 * Perform some actions right before updating an entry
753
+	 *
754
+	 * @since 2.0.16
755
+	 * @param int $id
756
+	 * @param array $values
757
+	 * @param string $update_type
758
+	 * @return boolean $update
759
+	 */
760 760
 	private static function before_update_entry( $id, &$values, $update_type ) {
761 761
 		$update = true;
762 762
 
@@ -774,13 +774,13 @@  discard block
 block discarded – undo
774 774
 	}
775 775
 
776 776
 	/**
777
-	* Package the entry data for updating
778
-	*
779
-	* @since 2.0.16
780
-	* @param int $id
781
-	* @param array $values
782
-	* @return array $new_values
783
-	*/
777
+	 * Package the entry data for updating
778
+	 *
779
+	 * @since 2.0.16
780
+	 * @param int $id
781
+	 * @param array $values
782
+	 * @return array $new_values
783
+	 */
784 784
 	private static function package_entry_to_update( $id, $values ) {
785 785
 		global $wpdb;
786 786
 
@@ -814,14 +814,14 @@  discard block
 block discarded – undo
814 814
 	}
815 815
 
816 816
 	/**
817
-	* Perform some actions right after updating an entry
818
-	*
819
-	* @since 2.0.16
820
-	* @param boolean|int $query_results
821
-	* @param int $id
822
-	* @param array $values
823
-	* @param array $new_values
824
-	*/
817
+	 * Perform some actions right after updating an entry
818
+	 *
819
+	 * @since 2.0.16
820
+	 * @param boolean|int $query_results
821
+	 * @param int $id
822
+	 * @param array $values
823
+	 * @param array $new_values
824
+	 */
825 825
 	private static function after_update_entry( $query_results, $id, $values, $new_values ) {
826 826
 		if ( $query_results ) {
827 827
 			self::clear_cache();
@@ -843,13 +843,13 @@  discard block
 block discarded – undo
843 843
 	}
844 844
 
845 845
 	/**
846
-	* Create entry from an XML import
847
-	* Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
848
-	*
849
-	* @since 2.0.16
850
-	* @param array $values
851
-	* @return int | boolean $entry_id
852
-	*/
846
+	 * Create entry from an XML import
847
+	 * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
848
+	 *
849
+	 * @since 2.0.16
850
+	 * @param array $values
851
+	 * @return int | boolean $entry_id
852
+	 */
853 853
 	public static function create_entry_from_xml( $values ) {
854 854
 		$entry_id = self::create_entry( $values, 'xml' );
855 855
 
@@ -857,28 +857,28 @@  discard block
 block discarded – undo
857 857
 	}
858 858
 
859 859
 	/**
860
-	* Update entry from an XML import
861
-	* Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
862
-	*
863
-	* @since 2.0.16
864
-	* @param int $id
865
-	* @param array $values
866
-	* @return int | boolean $updated
867
-	*/
860
+	 * Update entry from an XML import
861
+	 * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
862
+	 *
863
+	 * @since 2.0.16
864
+	 * @param int $id
865
+	 * @param array $values
866
+	 * @return int | boolean $updated
867
+	 */
868 868
 	public static function update_entry_from_xml( $id, $values ) {
869 869
 		$updated = self::update_entry( $id, $values, 'xml' );
870 870
 
871 871
 		return $updated;
872 872
 	}
873 873
 
874
-    /**
875
-     * @param string $key
876
-     * @return int entry_id
877
-     */
874
+	/**
875
+	 * @param string $key
876
+	 * @return int entry_id
877
+	 */
878 878
 	public static function get_id_by_key( $key ) {
879
-        $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
880
-        return $entry_id;
881
-    }
879
+		$entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
880
+		return $entry_id;
881
+	}
882 882
 
883 883
 	public static function validate( $values, $exclude = false ) {
884 884
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryValidate::validate' );
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
 		unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
56 56
 
57 57
         if ( $new_values['item_key'] == $new_values['name'] ) {
58
-            unset($check_val['name']);
58
+            unset( $check_val['name'] );
59 59
         }
60 60
 
61 61
         global $wpdb;
62 62
 		$entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
63 63
 
64
-        if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
64
+        if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) {
65 65
             return false;
66 66
         }
67 67
 
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
             $is_duplicate = true;
71 71
 
72 72
             //add more checks here to make sure it's a duplicate
73
-            $metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
73
+            $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist );
74 74
             $field_metas = array();
75 75
             foreach ( $metas as $meta ) {
76
-				$field_metas[ $meta->field_id ] = $meta->meta_value;
76
+				$field_metas[$meta->field_id] = $meta->meta_value;
77 77
             }
78 78
 
79 79
             // If prev entry is empty and current entry is not, they are not duplicates
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
                 return false;
83 83
             }
84 84
 
85
-            $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
85
+            $diff = array_diff_assoc( $field_metas, array_map( 'maybe_serialize', $values['item_meta'] ) );
86 86
             foreach ( $diff as $field_id => $meta_value ) {
87
-                if ( ! empty($meta_value) ) {
87
+                if ( ! empty( $meta_value ) ) {
88 88
                     $is_duplicate = false;
89 89
                     continue;
90 90
                 }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		}
114 114
 
115 115
 		// If CSV is importing, don't check for duplicates
116
-		if ( defined('WP_IMPORTING') && WP_IMPORTING ) {
116
+		if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
117 117
 			return false;
118 118
 		}
119 119
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         $new_values['is_draft'] = $values->is_draft;
137 137
 		$new_values['user_id'] = (int) $values->user_id;
138 138
 		$new_values['updated_by'] = (int) $values->user_id;
139
-        $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
139
+        $new_values['form_id'] = $values->form_id ? (int) $values->form_id : null;
140 140
 		$new_values['created_at'] = current_time( 'mysql', 1 );
141 141
 		$new_values['updated_at'] = $new_values['created_at'];
142 142
 
@@ -148,12 +148,12 @@  discard block
 block discarded – undo
148 148
         $entry_id = $wpdb->insert_id;
149 149
 
150 150
         global $frm_vars;
151
-        if ( ! isset($frm_vars['saved_entries']) ) {
151
+        if ( ! isset( $frm_vars['saved_entries'] ) ) {
152 152
             $frm_vars['saved_entries'] = array();
153 153
         }
154 154
         $frm_vars['saved_entries'][] = (int) $entry_id;
155 155
 
156
-        FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
156
+        FrmEntryMeta::duplicate_entry_metas( $id, $entry_id );
157 157
 		self::clear_cache();
158 158
 
159 159
 		do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
 		$new_values = self::package_entry_to_update( $id, $values );
194 194
 
195
-		$query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact('id') );
195
+		$query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact( 'id' ) );
196 196
 
197 197
 		self::after_update_entry( $query_results, $id, $values, $new_values );
198 198
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
             return $result;
210 210
         }
211 211
 
212
-        do_action('frm_before_destroy_entry', $id, $entry);
212
+        do_action( 'frm_before_destroy_entry', $id, $entry );
213 213
 
214 214
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
215 215
 		$result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 
222 222
 	public static function update_form( $id, $value, $form_id ) {
223 223
         global $wpdb;
224
-        $form_id = isset($value) ? $form_id : null;
224
+        $form_id = isset( $value ) ? $form_id : null;
225 225
 		$result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
226 226
 		if ( $result ) {
227 227
 			self::clear_cache();
@@ -268,24 +268,24 @@  discard block
 block discarded – undo
268 268
         $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
269 269
                   LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
270 270
 
271
-        $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
271
+        $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
272 272
         $query_args = array( $id );
273 273
         $query = $wpdb->prepare( $query, $query_args );
274 274
 
275 275
         if ( ! $meta ) {
276 276
 			$entry = FrmDb::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
277
-            return stripslashes_deep($entry);
277
+            return stripslashes_deep( $entry );
278 278
         }
279 279
 
280 280
         $entry = FrmDb::check_cache( $id, 'frm_entry' );
281 281
         if ( $entry !== false ) {
282
-            return stripslashes_deep($entry);
282
+            return stripslashes_deep( $entry );
283 283
         }
284 284
 
285 285
         $entry = $wpdb->get_row( $query );
286
-        $entry = self::get_meta($entry);
286
+        $entry = self::get_meta( $entry );
287 287
 
288
-        return stripslashes_deep($entry);
288
+        return stripslashes_deep( $entry );
289 289
     }
290 290
 
291 291
 	public static function get_meta( $entry ) {
@@ -301,23 +301,23 @@  discard block
 block discarded – undo
301 301
 		$include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
302 302
         foreach ( $metas as $meta_val ) {
303 303
             if ( $meta_val->item_id == $entry->id ) {
304
-				$entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
304
+				$entry->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value );
305 305
 				if ( $include_key ) {
306
-					$entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
306
+					$entry->metas[$meta_val->field_key] = $entry->metas[$meta_val->field_id];
307 307
 				}
308 308
                  continue;
309 309
             }
310 310
 
311 311
             // include sub entries in an array
312
-			if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
313
-				$entry->metas[ $meta_val->field_id ] = array();
312
+			if ( ! isset( $entry_metas[$meta_val->field_id] ) ) {
313
+				$entry->metas[$meta_val->field_id] = array();
314 314
             }
315 315
 
316
-			$entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
316
+			$entry->metas[$meta_val->field_id][] = maybe_unserialize( $meta_val->meta_value );
317 317
 
318
-            unset($meta_val);
318
+            unset( $meta_val );
319 319
         }
320
-        unset($metas);
320
+        unset( $metas );
321 321
 
322 322
 		FrmDb::set_cache( $entry->id, $entry, 'frm_entry' );
323 323
 
@@ -335,24 +335,24 @@  discard block
 block discarded – undo
335 335
             return $exists;
336 336
         }
337 337
 
338
-        if ( is_numeric($id) ) {
338
+        if ( is_numeric( $id ) ) {
339 339
             $where = array( 'id' => $id );
340 340
         } else {
341 341
             $where = array( 'item_key' => $id );
342 342
         }
343 343
 		$id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
344 344
 
345
-        $exists = ($id && $id > 0) ? true : false;
345
+        $exists = ( $id && $id > 0 ) ? true : false;
346 346
         return $exists;
347 347
     }
348 348
 
349 349
     public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
350 350
 		global $wpdb;
351 351
 
352
-        $limit = FrmDb::esc_limit($limit);
352
+        $limit = FrmDb::esc_limit( $limit );
353 353
 
354
-        $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
355
-        $entries = wp_cache_get($cache_key, 'frm_entry');
354
+        $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form;
355
+        $entries = wp_cache_get( $cache_key, 'frm_entry' );
356 356
 
357 357
         if ( false === $entries ) {
358 358
             $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
@@ -371,25 +371,25 @@  discard block
 block discarded – undo
371 371
 		    }
372 372
 
373 373
 			// prepare the query
374
-			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
374
+			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
375 375
 
376
-            $entries = $wpdb->get_results($query, OBJECT_K);
377
-            unset($query);
376
+            $entries = $wpdb->get_results( $query, OBJECT_K );
377
+            unset( $query );
378 378
 
379 379
 			FrmDb::set_cache( $cache_key, $entries, 'frm_entry' );
380 380
         }
381 381
 
382 382
         if ( ! $meta || ! $entries ) {
383
-            return stripslashes_deep($entries);
383
+            return stripslashes_deep( $entries );
384 384
         }
385
-        unset($meta);
385
+        unset( $meta );
386 386
 
387
-        if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
387
+        if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) {
388 388
 			$where = array( 'it.form_id' => substr( $where, 11 ) );
389 389
         }
390 390
 
391 391
         $meta_where = array( 'field_id !' => 0 );
392
-        if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
392
+        if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) {
393 393
             $meta_where['fi.form_id'] = $where['it.form_id'];
394 394
         } else {
395 395
             $meta_where['item_id'] = array_keys( $entries );
@@ -400,21 +400,21 @@  discard block
 block discarded – undo
400 400
         unset( $meta_where );
401 401
 
402 402
         if ( ! $metas ) {
403
-            return stripslashes_deep($entries);
403
+            return stripslashes_deep( $entries );
404 404
         }
405 405
 
406 406
         foreach ( $metas as $m_key => $meta_val ) {
407
-            if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
407
+            if ( ! isset( $entries[$meta_val->item_id] ) ) {
408 408
                 continue;
409 409
             }
410 410
 
411
-            if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
412
-				$entries[ $meta_val->item_id ]->metas = array();
411
+            if ( ! isset( $entries[$meta_val->item_id]->metas ) ) {
412
+				$entries[$meta_val->item_id]->metas = array();
413 413
             }
414 414
 
415
-			$entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
415
+			$entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value );
416 416
 
417
-            unset($m_key, $meta_val);
417
+            unset( $m_key, $meta_val );
418 418
         }
419 419
 
420 420
 		if ( ! FrmAppHelper::prevent_caching() ) {
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 			}
425 425
 		}
426 426
 
427
-        return stripslashes_deep($entries);
427
+        return stripslashes_deep( $entries );
428 428
     }
429 429
 
430 430
     // Pagination Methods
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
         global $wpdb;
433 433
 		$table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
434 434
 
435
-        if ( is_numeric($where) ) {
435
+        if ( is_numeric( $where ) ) {
436 436
             $table_join = 'frm_items';
437 437
             $where = array( 'form_id' => $where );
438 438
         }
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 		self::sanitize_entry_post( $values );
475 475
 
476 476
 		if ( $type != 'xml' ) {
477
-			$values = apply_filters('frm_pre_create_entry', $values);
477
+			$values = apply_filters( 'frm_pre_create_entry', $values );
478 478
 		}
479 479
 
480 480
 		$new_values = self::package_entry_data( $values );
@@ -554,17 +554,17 @@  discard block
 block discarded – undo
554 554
 			'user_id' => self::get_entry_user_id( $values ),
555 555
 		);
556 556
 
557
-		if ( is_array($new_values['name']) ) {
558
-			$new_values['name'] = reset($new_values['name']);
557
+		if ( is_array( $new_values['name'] ) ) {
558
+			$new_values['name'] = reset( $new_values['name'] );
559 559
 		}
560 560
 
561
-		$new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id'];
561
+		$new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id'];
562 562
 
563 563
 		return $new_values;
564 564
 	}
565 565
 
566 566
 	private static function get_entry_value( $values, $name, $default ) {
567
-		return isset( $values[ $name ] ) ? $values[ $name ] : $default;
567
+		return isset( $values[$name] ) ? $values[$name] : $default;
568 568
 	}
569 569
 
570 570
 	/**
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 		}
582 582
 
583 583
 		$ip = FrmAppHelper::get_ip_address();
584
-		if ( defined('WP_IMPORTING') && WP_IMPORTING ) {
584
+		if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
585 585
 			$ip = self::get_entry_value( $values, 'ip', $ip );
586 586
 		}
587 587
 		return $ip;
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
 	private static function add_new_entry_to_frm_vars( $entry_id ) {
695 695
 		global $frm_vars;
696 696
 
697
-		if ( ! isset($frm_vars['saved_entries']) ) {
697
+		if ( ! isset( $frm_vars['saved_entries'] ) ) {
698 698
 			$frm_vars['saved_entries'] = array();
699 699
 		}
700 700
 
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
 	* @param int $entry_id
710 710
 	*/
711 711
 	private static function maybe_add_entry_metas( $values, $entry_id ) {
712
-		if ( isset($values['item_meta']) ) {
712
+		if ( isset( $values['item_meta'] ) ) {
713 713
 			FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
714 714
 		}
715 715
 	}
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 		$is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
727 727
 
728 728
 		do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) );
729
-		do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id , compact( 'is_child' ) );
729
+		do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) );
730 730
 	}
731 731
 
732 732
 	/**
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
 		}
768 768
 
769 769
 		if ( $update && $update_type != 'xml' ) {
770
-			$values = apply_filters('frm_pre_update_entry', $values, $id);
770
+			$values = apply_filters( 'frm_pre_update_entry', $values, $id );
771 771
 		}
772 772
 
773 773
 		return $update;
@@ -788,27 +788,27 @@  discard block
 block discarded – undo
788 788
 			'name'      => self::get_new_entry_name( $values ),
789 789
 			'form_id'   => (int) self::get_entry_value( $values, 'form_id', null ),
790 790
 			'is_draft'  => self::get_is_draft_value( $values ),
791
-			'updated_at' => current_time('mysql', 1),
792
-			'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : get_current_user_id(),
791
+			'updated_at' => current_time( 'mysql', 1 ),
792
+			'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(),
793 793
 		);
794 794
 
795
-		if ( isset($values['post_id']) ) {
795
+		if ( isset( $values['post_id'] ) ) {
796 796
 			$new_values['post_id'] = (int) $values['post_id'];
797 797
 		}
798 798
 
799
-		if ( isset($values['item_key']) ) {
799
+		if ( isset( $values['item_key'] ) ) {
800 800
 			$new_values['item_key'] = FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key', $id );
801 801
 		}
802 802
 
803
-		if ( isset($values['parent_item_id']) ) {
803
+		if ( isset( $values['parent_item_id'] ) ) {
804 804
 			$new_values['parent_item_id'] = (int) $values['parent_item_id'];
805 805
 		}
806 806
 
807
-		if ( isset($values['frm_user_id']) && is_numeric($values['frm_user_id']) ) {
807
+		if ( isset( $values['frm_user_id'] ) && is_numeric( $values['frm_user_id'] ) ) {
808 808
 			$new_values['user_id'] = $values['frm_user_id'];
809 809
 		}
810 810
 
811
-		$new_values = apply_filters('frm_update_entry', $new_values, $id);
811
+		$new_values = apply_filters( 'frm_update_entry', $new_values, $id );
812 812
 
813 813
 		return $new_values;
814 814
 	}
Please login to merge, or discard this patch.
classes/models/FrmDb.php 2 patches
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -1,36 +1,36 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 class FrmDb {
4
-    public $fields;
5
-    public $forms;
6
-    public $entries;
7
-    public $entry_metas;
8
-
9
-    public function __construct() {
10
-        if ( ! defined('ABSPATH') ) {
11
-            die('You are not allowed to call this page directly.');
12
-        }
4
+	public $fields;
5
+	public $forms;
6
+	public $entries;
7
+	public $entry_metas;
8
+
9
+	public function __construct() {
10
+		if ( ! defined('ABSPATH') ) {
11
+			die('You are not allowed to call this page directly.');
12
+		}
13 13
 
14 14
 		_deprecated_function( __METHOD__, '2.06', 'FrmMigrate' );
15
-        global $wpdb;
16
-        $this->fields         = $wpdb->prefix . 'frm_fields';
17
-        $this->forms          = $wpdb->prefix . 'frm_forms';
18
-        $this->entries        = $wpdb->prefix . 'frm_items';
19
-        $this->entry_metas    = $wpdb->prefix . 'frm_item_metas';
20
-    }
21
-
22
-    /**
23
-     * Change array into format $wpdb->prepare can use
15
+		global $wpdb;
16
+		$this->fields         = $wpdb->prefix . 'frm_fields';
17
+		$this->forms          = $wpdb->prefix . 'frm_forms';
18
+		$this->entries        = $wpdb->prefix . 'frm_items';
19
+		$this->entry_metas    = $wpdb->prefix . 'frm_item_metas';
20
+	}
21
+
22
+	/**
23
+	 * Change array into format $wpdb->prepare can use
24 24
 	 *
25 25
 	 * @param array $args
26 26
 	 * @param string $starts_with
27
-     */
28
-    public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
29
-        if ( empty($args) ) {
27
+	 */
28
+	public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
29
+		if ( empty($args) ) {
30 30
 			// add an arg to prevent prepare from failing
31 31
 			$args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
32 32
 			return;
33
-        }
33
+		}
34 34
 
35 35
 		$where = '';
36 36
 		$values = array();
@@ -41,64 +41,64 @@  discard block
 block discarded – undo
41 41
 		}
42 42
 
43 43
 		$args = compact( 'where', 'values' );
44
-    }
44
+	}
45 45
 
46
-    /**
46
+	/**
47 47
 	 * @param array $args
48
-     * @param string $base_where
49
-     * @param string $where
48
+	 * @param string $base_where
49
+	 * @param string $where
50 50
 	 * @param array $values
51
-     */
52
-    public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
53
-        $condition = ' AND';
54
-        if ( isset( $args['or'] ) ) {
55
-            $condition = ' OR';
56
-            unset( $args['or'] );
57
-        }
58
-
59
-        foreach ( $args as $key => $value ) {
60
-            $where .= empty( $where ) ? $base_where : $condition;
61
-            $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
62
-            if ( is_numeric( $key ) || $array_inc_null ) {
63
-                $where .= ' ( ';
64
-                $nested_where = '';
65
-                if ( $array_inc_null ) {
66
-                    foreach ( $value as $val ) {
67
-                        self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
68
-                    }
69
-                } else {
70
-                    self::parse_where_from_array( $value, '', $nested_where, $values );
71
-                }
72
-                $where .= $nested_where;
73
-                $where .= ' ) ';
74
-            } else {
75
-                self::interpret_array_to_sql( $key, $value, $where, $values );
76
-            }
77
-        }
78
-    }
79
-
80
-    /**
81
-     * @param string $key
51
+	 */
52
+	public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
53
+		$condition = ' AND';
54
+		if ( isset( $args['or'] ) ) {
55
+			$condition = ' OR';
56
+			unset( $args['or'] );
57
+		}
58
+
59
+		foreach ( $args as $key => $value ) {
60
+			$where .= empty( $where ) ? $base_where : $condition;
61
+			$array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
62
+			if ( is_numeric( $key ) || $array_inc_null ) {
63
+				$where .= ' ( ';
64
+				$nested_where = '';
65
+				if ( $array_inc_null ) {
66
+					foreach ( $value as $val ) {
67
+						self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
68
+					}
69
+				} else {
70
+					self::parse_where_from_array( $value, '', $nested_where, $values );
71
+				}
72
+				$where .= $nested_where;
73
+				$where .= ' ) ';
74
+			} else {
75
+				self::interpret_array_to_sql( $key, $value, $where, $values );
76
+			}
77
+		}
78
+	}
79
+
80
+	/**
81
+	 * @param string $key
82 82
 	 * @param string|array $value
83
-     * @param string $where
83
+	 * @param string $where
84 84
 	 * @param array $values
85
-     */
86
-    private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
85
+	 */
86
+	private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
87 87
 		$key = trim( $key );
88 88
 
89 89
 		if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
90
-            $k = explode(' ', $key);
91
-            $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
92
-            $values[] = '%Y-%m-%d %H:%i:%s';
93
-        } else {
90
+			$k = explode(' ', $key);
91
+			$where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
92
+			$values[] = '%Y-%m-%d %H:%i:%s';
93
+		} else {
94 94
 			$where .= ' ' . $key;
95
-        }
95
+		}
96 96
 
97 97
 		$lowercase_key = explode( ' ', strtolower( $key ) );
98 98
 		$lowercase_key = end( $lowercase_key );
99 99
 
100
-        if ( is_array( $value ) ) {
101
-            // translate array of values to "in"
100
+		if ( is_array( $value ) ) {
101
+			// translate array of values to "in"
102 102
 			if ( strpos( $lowercase_key, 'like' ) !== false ) {
103 103
 				$where = preg_replace('/' . $key . '$/', '', $where);
104 104
 				$where .= '(';
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 				$where .= ' in (' . self::prepare_array_values( $value, '%s' ) . ')';
117 117
 				$values = array_merge( $values, $value );
118 118
 			}
119
-        } else if ( strpos( $lowercase_key, 'like' ) !== false ) {
119
+		} else if ( strpos( $lowercase_key, 'like' ) !== false ) {
120 120
 			/**
121 121
 			 * Allow string to start or end with the value
122 122
 			 * If the key is like% then skip the first % for starts with
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
 			$where .= ' %s';
137 137
 			$values[] = $start . self::esc_like( $value ) . $end;
138 138
 
139
-        } else if ( $value === null ) {
140
-            $where .= ' IS NULL';
141
-        } else {
139
+		} else if ( $value === null ) {
140
+			$where .= ' IS NULL';
141
+		} else {
142 142
 			// allow a - to prevent = from being added
143 143
 			if ( substr( $key, -1 ) == '-' ) {
144 144
 				$where = rtrim( $where, '-' );
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 
149 149
 			self::add_query_placeholder( $key, $value, $where );
150 150
 
151
-            $values[] = $value;
152
-        }
153
-    }
151
+			$values[] = $value;
152
+		}
153
+	}
154 154
 
155 155
 	/**
156 156
 	 * Add %d, or %s to query
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	 * @param int|string $value
161 161
 	 * @param string $where
162 162
 	 */
163
-    private static function add_query_placeholder( $key, $value, &$where ) {
163
+	private static function add_query_placeholder( $key, $value, &$where ) {
164 164
 		if ( is_numeric( $value ) && ( strpos( $key, 'meta_value' ) === false || strpos( $key, '+0' ) !== false ) ) {
165 165
 			$where .= '%d';
166 166
 		} else {
@@ -168,16 +168,16 @@  discard block
 block discarded – undo
168 168
 		}
169 169
 	}
170 170
 
171
-    /**
172
-     * @param string $table
171
+	/**
172
+	 * @param string $table
173 173
 	 * @param array $where
174 174
 	 * @param array $args
175 175
 	 * @return int
176
-     */
177
-    public static function get_count( $table, $where = array(), $args = array() ) {
178
-        $count = self::get_var( $table, $where, 'COUNT(*)', $args );
179
-        return $count;
180
-    }
176
+	 */
177
+	public static function get_count( $table, $where = array(), $args = array() ) {
178
+		$count = self::get_var( $table, $where, 'COUNT(*)', $args );
179
+		return $count;
180
+	}
181 181
 
182 182
 	/**
183 183
 	 * @param string $table
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
 	 * @param string $type
189 189
 	 * @return array|null|string|object
190 190
 	 */
191
-    public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
192
-        $group = '';
193
-        self::get_group_and_table_name( $table, $group );
191
+	public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
192
+		$group = '';
193
+		self::get_group_and_table_name( $table, $group );
194 194
 		self::convert_options_to_array( $args, '', $limit );
195 195
 
196 196
 		$query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
197 197
 
198 198
 		$cache_key = self::generate_cache_key( $where, $args, $field, $type );
199 199
 		$results = self::check_cache( $cache_key, $group, $query, 'get_' . $type );
200
-        return $results;
201
-    }
200
+		return $results;
201
+	}
202 202
 
203 203
 	/**
204 204
 	 * Generate a cache key from the where query, field, type, and other arguments
@@ -224,44 +224,44 @@  discard block
 block discarded – undo
224 224
 		return $cache_key;
225 225
 	}
226 226
 
227
-    /**
228
-     * @param string $table
229
-     * @param array $where
227
+	/**
228
+	 * @param string $table
229
+	 * @param array $where
230 230
 	 * @param string $field
231 231
 	 * @param array $args
232 232
 	 * @param string $limit
233 233
 	 * @return mixed
234
-     */
235
-    public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
236
-        return self::get_var( $table, $where, $field, $args, $limit, 'col' );
237
-    }
238
-
239
-    /**
240
-     * @since 2.0
241
-     * @param string $table
234
+	 */
235
+	public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
236
+		return self::get_var( $table, $where, $field, $args, $limit, 'col' );
237
+	}
238
+
239
+	/**
240
+	 * @since 2.0
241
+	 * @param string $table
242 242
 	 * @param array $where
243 243
 	 * @param string $fields
244 244
 	 * @param array $args
245 245
 	 * @return mixed
246
-     */
247
-    public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
248
-        $args['limit'] = 1;
249
-        return self::get_var( $table, $where, $fields, $args, '', 'row' );
250
-    }
251
-
252
-    /**
253
-     * Prepare a key/value array before DB call
246
+	 */
247
+	public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
248
+		$args['limit'] = 1;
249
+		return self::get_var( $table, $where, $fields, $args, '', 'row' );
250
+	}
251
+
252
+	/**
253
+	 * Prepare a key/value array before DB call
254 254
 	 *
255
-     * @since 2.0
256
-     * @param string $table
255
+	 * @since 2.0
256
+	 * @param string $table
257 257
 	 * @param array $where
258 258
 	 * @param string $fields
259 259
 	 * @param array $args
260 260
 	 * @return mixed
261
-     */
262
-    public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
263
-        return self::get_var( $table, $where, $fields, $args, '', 'results' );
264
-    }
261
+	 */
262
+	public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
263
+		return self::get_var( $table, $where, $fields, $args, '', 'results' );
264
+	}
265 265
 
266 266
 	/**
267 267
 	 * Check for like, not like, in, not in, =, !=, >, <, <=, >=
@@ -298,59 +298,59 @@  discard block
 block discarded – undo
298 298
 		return '';
299 299
 	}
300 300
 
301
-    /**
302
-     * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
303
-     * Also add the wpdb->prefix to the table if it's missing
304
-     *
305
-     * @param string $table
306
-     * @param string $group
307
-     */
308
-    private static function get_group_and_table_name( &$table, &$group ) {
301
+	/**
302
+	 * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
303
+	 * Also add the wpdb->prefix to the table if it's missing
304
+	 *
305
+	 * @param string $table
306
+	 * @param string $group
307
+	 */
308
+	private static function get_group_and_table_name( &$table, &$group ) {
309 309
 		global $wpdb, $wpmuBaseTablePrefix;
310 310
 
311
-        $table_parts = explode(' ', $table);
312
-        $group = reset($table_parts);
313
-        $group = str_replace( $wpdb->prefix, '', $group );
311
+		$table_parts = explode(' ', $table);
312
+		$group = reset($table_parts);
313
+		$group = str_replace( $wpdb->prefix, '', $group );
314 314
 
315 315
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
316 316
 		$group = str_replace( $prefix, '', $group );
317 317
 
318
-        if ( $group == $table ) {
319
-            $table = $wpdb->prefix . $table;
320
-        }
318
+		if ( $group == $table ) {
319
+			$table = $wpdb->prefix . $table;
320
+		}
321 321
 
322 322
 		// switch to singular group name
323 323
 		$group = rtrim( $group, 's' );
324
-    }
324
+	}
325 325
 
326
-    private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
327
-        if ( ! is_array($args) ) {
326
+	private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
327
+		if ( ! is_array($args) ) {
328 328
 			$args = array( 'order_by' => $args );
329
-        }
329
+		}
330 330
 
331
-        if ( ! empty( $order_by ) ) {
332
-            $args['order_by'] = $order_by;
333
-        }
331
+		if ( ! empty( $order_by ) ) {
332
+			$args['order_by'] = $order_by;
333
+		}
334 334
 
335
-        if ( ! empty( $limit ) ) {
336
-            $args['limit'] = $limit;
337
-        }
335
+		if ( ! empty( $limit ) ) {
336
+			$args['limit'] = $limit;
337
+		}
338 338
 
339
-        $temp_args = $args;
340
-        foreach ( $temp_args as $k => $v ) {
341
-            if ( $v == '' ) {
339
+		$temp_args = $args;
340
+		foreach ( $temp_args as $k => $v ) {
341
+			if ( $v == '' ) {
342 342
 				unset( $args[ $k ] );
343
-                continue;
344
-            }
343
+				continue;
344
+			}
345 345
 
346
-            if ( $k == 'limit' ) {
346
+			if ( $k == 'limit' ) {
347 347
 				$args[ $k ] = self::esc_limit( $v );
348
-            }
349
-            $db_name = strtoupper( str_replace( '_', ' ', $k ) );
350
-            if ( strpos( $v, $db_name ) === false ) {
348
+			}
349
+			$db_name = strtoupper( str_replace( '_', ' ', $k ) );
350
+			if ( strpos( $v, $db_name ) === false ) {
351 351
 				$args[ $k ] = $db_name . ' ' . $v;
352
-            }
353
-        }
352
+			}
353
+		}
354 354
 
355 355
 		// Make sure LIMIT is the last argument
356 356
 		if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 			unset( $args['limit'] );
359 359
 			$args['limit'] = $temp_limit;
360 360
 		}
361
-    }
361
+	}
362 362
 
363 363
 	/**
364 364
 	 * Get the associative array results for the given columns, table, and where query
@@ -411,62 +411,62 @@  discard block
 block discarded – undo
411 411
 		return $query;
412 412
 	}
413 413
 
414
-    /**
415
-     * Added for < WP 4.0 compatability
416
-     *
417
-     * @since 2.06
418
-     *
419
-     * @param string $term The value to escape
420
-     * @return string The escaped value
421
-     */
414
+	/**
415
+	 * Added for < WP 4.0 compatability
416
+	 *
417
+	 * @since 2.06
418
+	 *
419
+	 * @param string $term The value to escape
420
+	 * @return string The escaped value
421
+	 */
422 422
 	public static function esc_like( $term ) {
423
-        global $wpdb;
424
-        if ( method_exists( $wpdb, 'esc_like' ) ) {
423
+		global $wpdb;
424
+		if ( method_exists( $wpdb, 'esc_like' ) ) {
425 425
 			// WP 4.0
426
-            $term = $wpdb->esc_like( $term );
427
-        } else {
428
-            $term = like_escape( $term );
429
-        }
426
+			$term = $wpdb->esc_like( $term );
427
+		} else {
428
+			$term = like_escape( $term );
429
+		}
430 430
 
431
-        return $term;
432
-    }
431
+		return $term;
432
+	}
433 433
 
434
-    /**
434
+	/**
435 435
 	 * @since 2.06
436
-     * @param string $order_query
437
-     */
436
+	 * @param string $order_query
437
+	 */
438 438
 	public static function esc_order( $order_query ) {
439
-        if ( empty( $order_query ) ) {
440
-            return '';
441
-        }
442
-
443
-        // remove ORDER BY before santizing
444
-        $order_query = strtolower( $order_query );
445
-        if ( strpos( $order_query, 'order by' ) !== false ) {
446
-            $order_query = str_replace( 'order by', '', $order_query );
447
-        }
448
-
449
-        $order_query = explode( ' ', trim( $order_query ) );
450
-
451
-        $order_fields = array(
452
-            'id', 'form_key', 'name', 'description',
453
-            'parent_form_id', 'logged_in', 'is_template',
454
-            'default_template', 'status', 'created_at',
455
-        );
456
-
457
-        $order = trim( trim( reset( $order_query ), ',' ) );
458
-        if ( ! in_array( $order, $order_fields ) ) {
459
-            return '';
460
-        }
461
-
462
-        $order_by = '';
463
-        if ( count( $order_query ) > 1 ) {
439
+		if ( empty( $order_query ) ) {
440
+			return '';
441
+		}
442
+
443
+		// remove ORDER BY before santizing
444
+		$order_query = strtolower( $order_query );
445
+		if ( strpos( $order_query, 'order by' ) !== false ) {
446
+			$order_query = str_replace( 'order by', '', $order_query );
447
+		}
448
+
449
+		$order_query = explode( ' ', trim( $order_query ) );
450
+
451
+		$order_fields = array(
452
+			'id', 'form_key', 'name', 'description',
453
+			'parent_form_id', 'logged_in', 'is_template',
454
+			'default_template', 'status', 'created_at',
455
+		);
456
+
457
+		$order = trim( trim( reset( $order_query ), ',' ) );
458
+		if ( ! in_array( $order, $order_fields ) ) {
459
+			return '';
460
+		}
461
+
462
+		$order_by = '';
463
+		if ( count( $order_query ) > 1 ) {
464 464
 			$order_by = end( $order_query );
465 465
 			self::esc_order_by( $order_by );
466
-        }
466
+		}
467 467
 
468 468
 		return ' ORDER BY ' . $order . ' ' . $order_by;
469
-    }
469
+	}
470 470
 
471 471
 	/**
472 472
 	 * Make sure this is ordering by either ASC or DESC
@@ -504,18 +504,18 @@  discard block
 block discarded – undo
504 504
 		return ' LIMIT ' . $limit;
505 505
 	}
506 506
 
507
-    /**
508
-     * Get an array of values ready to go through $wpdb->prepare
509
-     * @since 2.06
510
-     */
507
+	/**
508
+	 * Get an array of values ready to go through $wpdb->prepare
509
+	 * @since 2.06
510
+	 */
511 511
 	public static function prepare_array_values( $array, $type = '%s' ) {
512 512
 		$placeholders = array_fill( 0, count( $array ), $type );
513 513
 		return implode( ', ', $placeholders );
514 514
 	}
515 515
 
516
-    /**
517
-     * @since 2.06
518
-     */
516
+	/**
517
+	 * @since 2.06
518
+	 */
519 519
 	public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
520 520
 		if ( empty( $where ) ) {
521 521
 			return '';
@@ -578,17 +578,17 @@  discard block
 block discarded – undo
578 578
 		return $post;
579 579
 	}
580 580
 
581
-    /**
582
-     * Check cache before fetching values and saving to cache
583
-     *
584
-     * @since 2.06
585
-     *
586
-     * @param string $cache_key The unique name for this cache
587
-     * @param string $group The name of the cache group
588
-     * @param string $query If blank, don't run a db call
589
-     * @param string $type The wpdb function to use with this query
590
-     * @return mixed $results The cache or query results
591
-     */
581
+	/**
582
+	 * Check cache before fetching values and saving to cache
583
+	 *
584
+	 * @since 2.06
585
+	 *
586
+	 * @param string $cache_key The unique name for this cache
587
+	 * @param string $group The name of the cache group
588
+	 * @param string $query If blank, don't run a db call
589
+	 * @param string $type The wpdb function to use with this query
590
+	 * @return mixed $results The cache or query results
591
+	 */
592 592
 	public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
593 593
 		$results = wp_cache_get( $cache_key, $group );
594 594
 		if ( ! FrmAppHelper::is_empty_value( $results, false ) || empty( $query ) ) {
@@ -643,13 +643,13 @@  discard block
 block discarded – undo
643 643
 		return $cached;
644 644
 	}
645 645
 
646
-    /**
647
-     * Data that should be stored for a long time can be stored in a transient.
648
-     * First check the cache, then check the transient
646
+	/**
647
+	 * Data that should be stored for a long time can be stored in a transient.
648
+	 * First check the cache, then check the transient
649 649
 	 *
650
-     * @since 2.06
651
-     * @return mixed The cached value or false
652
-     */
650
+	 * @since 2.06
651
+	 * @return mixed The cached value or false
652
+	 */
653 653
 	public static function check_cache_and_transient( $cache_key ) {
654 654
 		// check caching layer first
655 655
 		$results = self::check_cache( $cache_key );
@@ -666,22 +666,22 @@  discard block
 block discarded – undo
666 666
 		return $results;
667 667
 	}
668 668
 
669
-    /**
670
-     * @since 2.06
671
-     * @param string $cache_key
672
-     */
669
+	/**
670
+	 * @since 2.06
671
+	 * @param string $cache_key
672
+	 */
673 673
 	public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
674 674
 		delete_transient( $cache_key );
675 675
 		wp_cache_delete( $cache_key, $group );
676 676
 	}
677 677
 
678
-    /**
679
-     * Delete all caching in a single group
680
-     *
681
-     * @since 2.06
682
-     *
683
-     * @param string $group The name of the cache group
684
-     */
678
+	/**
679
+	 * Delete all caching in a single group
680
+	 *
681
+	 * @since 2.06
682
+	 *
683
+	 * @param string $group The name of the cache group
684
+	 */
685 685
 	public static function cache_delete_group( $group ) {
686 686
 		$cached_keys = self::get_group_cached_keys( $group );
687 687
 
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
     public $entry_metas;
8 8
 
9 9
     public function __construct() {
10
-        if ( ! defined('ABSPATH') ) {
11
-            die('You are not allowed to call this page directly.');
10
+        if ( ! defined( 'ABSPATH' ) ) {
11
+            die( 'You are not allowed to call this page directly.' );
12 12
         }
13 13
 
14 14
 		_deprecated_function( __METHOD__, '2.06', 'FrmMigrate' );
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * @param string $starts_with
27 27
      */
28 28
     public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
29
-        if ( empty($args) ) {
29
+        if ( empty( $args ) ) {
30 30
 			// add an arg to prevent prepare from failing
31 31
 			$args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
32 32
 			return;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 		$key = trim( $key );
88 88
 
89 89
 		if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
90
-            $k = explode(' ', $key);
90
+            $k = explode( ' ', $key );
91 91
             $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
92 92
             $values[] = '%Y-%m-%d %H:%i:%s';
93 93
         } else {
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
         if ( is_array( $value ) ) {
101 101
             // translate array of values to "in"
102 102
 			if ( strpos( $lowercase_key, 'like' ) !== false ) {
103
-				$where = preg_replace('/' . $key . '$/', '', $where);
103
+				$where = preg_replace( '/' . $key . '$/', '', $where );
104 104
 				$where .= '(';
105 105
 				$start = true;
106 106
 				foreach ( $value as $v ) {
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 		);
286 286
 
287 287
 		$where_is = strtolower( $where_is );
288
-		if ( isset( $switch_to[ $where_is ] ) ) {
289
-			return ' ' . $switch_to[ $where_is ];
288
+		if ( isset( $switch_to[$where_is] ) ) {
289
+			return ' ' . $switch_to[$where_is];
290 290
 		}
291 291
 
292 292
 		// > and < need a little more work since we don't want them switched to >= and <=
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
     private static function get_group_and_table_name( &$table, &$group ) {
309 309
 		global $wpdb, $wpmuBaseTablePrefix;
310 310
 
311
-        $table_parts = explode(' ', $table);
312
-        $group = reset($table_parts);
311
+        $table_parts = explode( ' ', $table );
312
+        $group = reset( $table_parts );
313 313
         $group = str_replace( $wpdb->prefix, '', $group );
314 314
 
315 315
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
     }
325 325
 
326 326
     private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
327
-        if ( ! is_array($args) ) {
327
+        if ( ! is_array( $args ) ) {
328 328
 			$args = array( 'order_by' => $args );
329 329
         }
330 330
 
@@ -339,16 +339,16 @@  discard block
 block discarded – undo
339 339
         $temp_args = $args;
340 340
         foreach ( $temp_args as $k => $v ) {
341 341
             if ( $v == '' ) {
342
-				unset( $args[ $k ] );
342
+				unset( $args[$k] );
343 343
                 continue;
344 344
             }
345 345
 
346 346
             if ( $k == 'limit' ) {
347
-				$args[ $k ] = self::esc_limit( $v );
347
+				$args[$k] = self::esc_limit( $v );
348 348
             }
349 349
             $db_name = strtoupper( str_replace( '_', ' ', $k ) );
350 350
             if ( strpos( $v, $db_name ) === false ) {
351
-				$args[ $k ] = $db_name . ' ' . $v;
351
+				$args[$k] = $db_name . ' ' . $v;
352 352
             }
353 353
         }
354 354
 
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 
376 376
 		$query = self::generate_query_string_from_pieces( $columns, $table, $where );
377 377
 
378
-		$cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . $columns . '_results_ARRAY_A' , ' WHERE' ) );
378
+		$cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . $columns . '_results_ARRAY_A', ' WHERE' ) );
379 379
 		$results = self::check_cache( $cache_key, $group, $query, 'get_associative_results' );
380 380
 
381 381
 		return $results;
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
 		$limit = explode( ',', trim( $limit ) );
497 497
 		foreach ( $limit as $k => $l ) {
498 498
 			if ( is_numeric( $l ) ) {
499
-				$limit[ $k ] = $l;
499
+				$limit[$k] = $l;
500 500
 			}
501 501
 		}
502 502
 
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 	 */
628 628
 	public static function add_key_to_group_cache( $key, $group ) {
629 629
 		$cached = self::get_group_cached_keys( $group );
630
-		$cached[ $key ] = $key;
630
+		$cached[$key] = $key;
631 631
 		wp_cache_set( 'cached_keys', $cached, $group, 300 );
632 632
 	}
633 633
 
Please login to merge, or discard this patch.
classes/models/FrmField.php 2 patches
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 
6 6
 class FrmField {
7 7
 
8
-    static $use_cache = true;
8
+	static $use_cache = true;
9 9
 	static $transient_size = 200;
10 10
 
11 11
 	public static function field_selection() {
@@ -52,39 +52,39 @@  discard block
 block discarded – undo
52 52
 		));
53 53
 	}
54 54
 
55
-    public static function create( $values, $return = true ) {
56
-        global $wpdb, $frm_duplicate_ids;
55
+	public static function create( $values, $return = true ) {
56
+		global $wpdb, $frm_duplicate_ids;
57 57
 
58
-        $new_values = array();
59
-        $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
58
+		$new_values = array();
59
+		$key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
60 60
 		$new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
61 61
 
62 62
 		foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
63 63
 			$new_values[ $col ] = $values[ $col ];
64
-        }
64
+		}
65 65
 
66
-        $new_values['options'] = $values['options'];
66
+		$new_values['options'] = $values['options'];
67 67
 
68
-        $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
-        $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
-        $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
71
-        $new_values['field_options'] = $values['field_options'];
72
-        $new_values['created_at'] = current_time('mysql', 1);
68
+		$new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
+		$new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
+		$new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
71
+		$new_values['field_options'] = $values['field_options'];
72
+		$new_values['created_at'] = current_time('mysql', 1);
73 73
 
74 74
 		if ( isset( $values['id'] ) ) {
75 75
 			$frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
76
-            $new_values = apply_filters('frm_duplicated_field', $new_values);
77
-        }
76
+			$new_values = apply_filters('frm_duplicated_field', $new_values);
77
+		}
78 78
 
79 79
 		foreach ( $new_values as $k => $v ) {
80
-            if ( is_array( $v ) ) {
80
+			if ( is_array( $v ) ) {
81 81
 				$new_values[ $k ] = serialize( $v );
82 82
 			}
83
-            unset( $k, $v );
84
-        }
83
+			unset( $k, $v );
84
+		}
85 85
 
86
-        //if(isset($values['id']) and is_numeric($values['id']))
87
-        //    $new_values['id'] = $values['id'];
86
+		//if(isset($values['id']) and is_numeric($values['id']))
87
+		//    $new_values['id'] = $values['id'];
88 88
 
89 89
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values );
90 90
 		$new_id = 0;
@@ -105,22 +105,22 @@  discard block
 block discarded – undo
105 105
 		} else {
106 106
 			return false;
107 107
 		}
108
-    }
108
+	}
109 109
 
110
-    public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
111
-        global $frm_duplicate_ids;
110
+	public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
111
+		global $frm_duplicate_ids;
112 112
 
113 113
 		$where = array( array( 'or' => 1, 'fi.form_id' => $old_form_id, 'fr.parent_form_id' => $old_form_id ) );
114 114
 		$fields = self::getAll( $where, 'field_order', '', $blog_id );
115 115
 
116
-        foreach ( (array) $fields as $field ) {
117
-            $new_key = ($copy_keys) ? $field->field_key : '';
118
-            if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
119
-                $new_key = rtrim($new_key, 2);
120
-            }
116
+		foreach ( (array) $fields as $field ) {
117
+			$new_key = ($copy_keys) ? $field->field_key : '';
118
+			if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
119
+				$new_key = rtrim($new_key, 2);
120
+			}
121 121
 
122
-            $values = array();
123
-            FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
122
+			$values = array();
123
+			FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
124 124
 
125 125
 			// If this is a repeating section, create new form
126 126
 			if ( self::is_repeating_field( $field ) ) {
@@ -139,16 +139,16 @@  discard block
 block discarded – undo
139 139
 				$values['form_id'] = $new_repeat_form_id;
140 140
 			}
141 141
 
142
-            $values = apply_filters('frm_duplicated_field', $values);
143
-            $new_id = self::create($values);
144
-            $frm_duplicate_ids[ $field->id ] = $new_id;
145
-            $frm_duplicate_ids[ $field->field_key ] = $new_id;
146
-            unset($field);
147
-        }
148
-    }
142
+			$values = apply_filters('frm_duplicated_field', $values);
143
+			$new_id = self::create($values);
144
+			$frm_duplicate_ids[ $field->id ] = $new_id;
145
+			$frm_duplicate_ids[ $field->field_key ] = $new_id;
146
+			unset($field);
147
+		}
148
+	}
149 149
 
150 150
 	public static function update( $id, $values ) {
151
-        global $wpdb;
151
+		global $wpdb;
152 152
 
153 153
 		$id = absint( $id );
154 154
 
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 			$values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id );
157 157
 		}
158 158
 
159
-        if ( isset($values['required']) ) {
160
-            $values['required'] = (int) $values['required'];
161
-        }
159
+		if ( isset($values['required']) ) {
160
+			$values['required'] = (int) $values['required'];
161
+		}
162 162
 
163 163
 		self::preserve_format_option_backslashes( $values );
164 164
 
@@ -180,41 +180,41 @@  discard block
 block discarded – undo
180 180
 
181 181
 		$query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) );
182 182
 
183
-        $form_id = 0;
183
+		$form_id = 0;
184 184
 		if ( isset( $values['form_id'] ) ) {
185
-            $form_id = absint( $values['form_id'] );
185
+			$form_id = absint( $values['form_id'] );
186 186
 		} else {
187
-            $field = self::getOne($id);
188
-            if ( $field ) {
189
-                $form_id = $field->form_id;
190
-            }
191
-            unset($field);
192
-        }
193
-        unset($values);
187
+			$field = self::getOne($id);
188
+			if ( $field ) {
189
+				$form_id = $field->form_id;
190
+			}
191
+			unset($field);
192
+		}
193
+		unset($values);
194 194
 
195 195
 		if ( $query_results ) {
196
-            wp_cache_delete( $id, 'frm_field' );
197
-            if ( $form_id ) {
198
-                self::delete_form_transient( $form_id );
199
-            }
200
-        }
196
+			wp_cache_delete( $id, 'frm_field' );
197
+			if ( $form_id ) {
198
+				self::delete_form_transient( $form_id );
199
+			}
200
+		}
201 201
 
202
-        return $query_results;
203
-    }
202
+		return $query_results;
203
+	}
204 204
 
205 205
 	/**
206
-	* Keep backslashes in the phone format option
207
-	*
208
-	* @since 2.0.8
209
-	* @param $values array - pass by reference
210
-	*/
206
+	 * Keep backslashes in the phone format option
207
+	 *
208
+	 * @since 2.0.8
209
+	 * @param $values array - pass by reference
210
+	 */
211 211
 	private static function preserve_format_option_backslashes( &$values ) {
212 212
 		if ( isset( $values['field_options']['format'] ) ) {
213 213
 			$values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
214 214
 		}
215 215
 	}
216 216
 
217
-    public static function destroy( $id ) {
217
+	public static function destroy( $id ) {
218 218
 		global $wpdb;
219 219
 
220 220
 		do_action( 'frm_before_destroy_field', $id );
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 
230 230
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
231 231
 		return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
232
-    }
232
+	}
233 233
 
234 234
 	public static function delete_form_transient( $form_id ) {
235 235
 		$form_id = absint( $form_id );
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
 
244 244
 		FrmDb::cache_delete_group( 'frm_field' );
245 245
 
246
-        $form = FrmForm::getOne($form_id);
247
-        if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
248
-            self::delete_form_transient( $form->parent_form_id );
249
-        }
250
-    }
246
+		$form = FrmForm::getOne($form_id);
247
+		if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
248
+			self::delete_form_transient( $form->parent_form_id );
249
+		}
250
+	}
251 251
 
252 252
 	/**
253 253
 	 * If $field is numeric, get the field object
@@ -263,131 +263,131 @@  discard block
 block discarded – undo
263 263
 			return null;
264 264
 		}
265 265
 
266
-        global $wpdb;
266
+		global $wpdb;
267 267
 
268
-        $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
268
+		$where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
269 269
 		$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id );
270 270
 
271
-        $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
271
+		$results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
272 272
 
273
-        if ( empty($results) ) {
274
-            return $results;
275
-        }
273
+		if ( empty($results) ) {
274
+			return $results;
275
+		}
276 276
 
277
-        if ( is_numeric($id) ) {
277
+		if ( is_numeric($id) ) {
278 278
 			FrmDb::set_cache( $results->field_key, $results, 'frm_field' );
279
-        } else if ( $results ) {
279
+		} else if ( $results ) {
280 280
 			FrmDb::set_cache( $results->id, $results, 'frm_field' );
281
-        }
281
+		}
282 282
 
283 283
 		self::prepare_options( $results );
284 284
 
285
-        return stripslashes_deep($results);
286
-    }
285
+		return stripslashes_deep($results);
286
+	}
287 287
 
288
-    /**
289
-     * Get the field type by key or id
290
-     * @param int|string The field id or key
288
+	/**
289
+	 * Get the field type by key or id
290
+	 * @param int|string The field id or key
291 291
 	 * @param mixed $col The name of the column in the fields database table
292
-     */
293
-    public static function get_type( $id, $col = 'type' ) {
294
-        $field = FrmDb::check_cache( $id, 'frm_field' );
295
-        if ( $field ) {
296
-            $type = $field->{$col};
297
-        } else {
298
-            $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col );
299
-        }
300
-
301
-        return $type;
302
-    }
292
+	 */
293
+	public static function get_type( $id, $col = 'type' ) {
294
+		$field = FrmDb::check_cache( $id, 'frm_field' );
295
+		if ( $field ) {
296
+			$type = $field->{$col};
297
+		} else {
298
+			$type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col );
299
+		}
300
+
301
+		return $type;
302
+	}
303 303
 
304 304
 	public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
305
-        if ( ! $form_id ) {
306
-            return array();
307
-        }
305
+		if ( ! $form_id ) {
306
+			return array();
307
+		}
308 308
 
309 309
 		$results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_sub, 'inc_repeat' => $inc_sub ) );
310 310
 		if ( ! empty( $results ) ) {
311
-            $fields = array();
312
-            $count = 0;
313
-            foreach ( $results as $result ) {
314
-                if ( $type != $result->type ) {
315
-                    continue;
316
-                }
311
+			$fields = array();
312
+			$count = 0;
313
+			foreach ( $results as $result ) {
314
+				if ( $type != $result->type ) {
315
+					continue;
316
+				}
317 317
 
318 318
 				$fields[ $result->id ] = $result;
319
-                $count++;
320
-                if ( $limit == 1 ) {
321
-                    $fields = $result;
322
-                    break;
323
-                }
319
+				$count++;
320
+				if ( $limit == 1 ) {
321
+					$fields = $result;
322
+					break;
323
+				}
324 324
 
325
-                if ( ! empty($limit) && $count >= $limit ) {
326
-                    break;
327
-                }
325
+				if ( ! empty($limit) && $count >= $limit ) {
326
+					break;
327
+				}
328 328
 
329
-                unset($result);
330
-            }
331
-            return stripslashes_deep($fields);
332
-        }
329
+				unset($result);
330
+			}
331
+			return stripslashes_deep($fields);
332
+		}
333 333
 
334
-        self::$use_cache = false;
334
+		self::$use_cache = false;
335 335
 
336 336
 		$where = array( 'fi.form_id' => (int) $form_id, 'fi.type' => $type );
337 337
 		self::maybe_include_repeating_fields( $inc_sub, $where );
338 338
 		$results = self::getAll( $where, 'field_order', $limit );
339
-        self::$use_cache = true;
340
-        self::include_sub_fields($results, $inc_sub, $type);
339
+		self::$use_cache = true;
340
+		self::include_sub_fields($results, $inc_sub, $type);
341 341
 
342
-        return $results;
343
-    }
342
+		return $results;
343
+	}
344 344
 
345 345
 	public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
346
-        if ( ! (int) $form_id ) {
347
-            return array();
348
-        }
346
+		if ( ! (int) $form_id ) {
347
+			return array();
348
+		}
349 349
 
350 350
 		$results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
351 351
 		if ( ! empty( $results ) ) {
352
-            if ( empty($limit) ) {
352
+			if ( empty($limit) ) {
353 353
 				return $results;
354
-            }
354
+			}
355 355
 
356
-            $fields = array();
357
-            $count = 0;
358
-            foreach ( $results as $result ) {
356
+			$fields = array();
357
+			$count = 0;
358
+			foreach ( $results as $result ) {
359 359
 				$fields[ $result->id ] = $result;
360
-                if ( ! empty($limit) && $count >= $limit ) {
361
-                    break;
362
-                }
363
-            }
360
+				if ( ! empty($limit) && $count >= $limit ) {
361
+					break;
362
+				}
363
+			}
364 364
 
365 365
 			return $fields;
366
-        }
366
+		}
367 367
 
368
-        self::$use_cache = false;
368
+		self::$use_cache = false;
369 369
 
370 370
 		$where = array( 'fi.form_id' => absint( $form_id ) );
371 371
 		self::maybe_include_repeating_fields( $inc_repeat, $where );
372 372
 		$results = self::getAll( $where, 'field_order', $limit );
373 373
 
374
-        self::$use_cache = true;
374
+		self::$use_cache = true;
375 375
 
376 376
 		self::include_sub_fields( $results, $inc_embed, 'all' );
377 377
 
378
-        if ( empty($limit) ) {
378
+		if ( empty($limit) ) {
379 379
 			self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
380
-        }
380
+		}
381 381
 
382 382
 		return $results;
383
-    }
383
+	}
384 384
 
385 385
 	/**
386
-	* If repeating fields should be included, adjust $where accordingly
387
-	*
388
-	* @param string $inc_repeat
389
-	* @param array $where - pass by reference
390
-	*/
386
+	 * If repeating fields should be included, adjust $where accordingly
387
+	 *
388
+	 * @param string $inc_repeat
389
+	 * @param array $where - pass by reference
390
+	 */
391 391
 	private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
392 392
 		if ( $inc_repeat == 'include' ) {
393 393
 			$form_id = $where['fi.form_id'];
@@ -398,57 +398,57 @@  discard block
 block discarded – undo
398 398
 
399 399
 	public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) {
400 400
 		if ( 'include' != $inc_embed || empty( $results ) ) {
401
-            return;
402
-        }
401
+			return;
402
+		}
403 403
 
404
-        $form_fields = $results;
404
+		$form_fields = $results;
405 405
 		$index_offset = 1;
406
-        foreach ( $form_fields as $k => $field ) {
407
-            if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
408
-                continue;
409
-            }
410
-
411
-            if ( $type == 'all' ) {
412
-                $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
413
-            } else {
414
-                $sub_fields = self::get_all_types_in_form($field->form_id, $type);
415
-            }
416
-
417
-            if ( ! empty($sub_fields) ) {
406
+		foreach ( $form_fields as $k => $field ) {
407
+			if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
408
+				continue;
409
+			}
410
+
411
+			if ( $type == 'all' ) {
412
+				$sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
413
+			} else {
414
+				$sub_fields = self::get_all_types_in_form($field->form_id, $type);
415
+			}
416
+
417
+			if ( ! empty($sub_fields) ) {
418 418
 				$index = $k + $index_offset;
419 419
 				$index_offset += count( $sub_fields );
420 420
 				array_splice($results, $index, 0, $sub_fields);
421
-            }
422
-            unset($field, $sub_fields);
423
-        }
424
-    }
421
+			}
422
+			unset($field, $sub_fields);
423
+		}
424
+	}
425 425
 
426 426
 	public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) {
427 427
 		$cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
428
-        if ( self::$use_cache ) {
429
-            // make sure old cache doesn't get saved as a transient
430
-            $results = wp_cache_get($cache_key, 'frm_field');
431
-            if ( false !== $results ) {
432
-                return stripslashes_deep($results);
433
-            }
434
-        }
435
-
436
-        global $wpdb;
437
-
438
-        if ( $blog_id && is_multisite() ) {
439
-            global $wpmuBaseTablePrefix;
440
-            if ( $wpmuBaseTablePrefix ) {
428
+		if ( self::$use_cache ) {
429
+			// make sure old cache doesn't get saved as a transient
430
+			$results = wp_cache_get($cache_key, 'frm_field');
431
+			if ( false !== $results ) {
432
+				return stripslashes_deep($results);
433
+			}
434
+		}
435
+
436
+		global $wpdb;
437
+
438
+		if ( $blog_id && is_multisite() ) {
439
+			global $wpmuBaseTablePrefix;
440
+			if ( $wpmuBaseTablePrefix ) {
441 441
 				$prefix = $wpmuBaseTablePrefix . $blog_id . '_';
442
-            } else {
443
-                $prefix = $wpdb->get_blog_prefix( $blog_id );
444
-            }
442
+			} else {
443
+				$prefix = $wpdb->get_blog_prefix( $blog_id );
444
+			}
445 445
 
446 446
 			$table_name = $prefix . 'frm_fields';
447 447
 			$form_table_name = $prefix . 'frm_forms';
448 448
 		} else {
449 449
 			$table_name = $wpdb->prefix . 'frm_fields';
450 450
 			$form_table_name = $wpdb->prefix . 'frm_forms';
451
-        }
451
+		}
452 452
 
453 453
 		if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
454 454
 			$order_by = ' ORDER BY ' . $order_by;
@@ -456,19 +456,19 @@  discard block
 block discarded – undo
456 456
 
457 457
 		$limit = FrmDb::esc_limit( $limit );
458 458
 
459
-        $query = "SELECT fi.*, fr.name as form_name  FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
460
-        $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
459
+		$query = "SELECT fi.*, fr.name as form_name  FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
460
+		$query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
461 461
 
462
-        if ( is_array($where) ) {
463
-            $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type );
462
+		if ( is_array($where) ) {
463
+			$results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type );
464 464
 		} else {
465 465
 			// if the query is not an array, then it has already been prepared
466 466
 			$query .= FrmDb::prepend_and_or_where(' WHERE ', $where ) . $order_by . $limit;
467 467
 
468 468
 			$function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
469 469
 			$results = $wpdb->$function_name( $query );
470
-        }
471
-        unset( $where );
470
+		}
471
+		unset( $where );
472 472
 
473 473
 		self::format_field_results( $results );
474 474
 
@@ -701,8 +701,8 @@  discard block
 block discarded – undo
701 701
 	}
702 702
 
703 703
 	/**
704
-	* @since 2.0.09
705
-	*/
704
+	 * @since 2.0.09
705
+	 */
706 706
 	public static function is_repeating_field( $field ) {
707 707
 		if ( is_array( $field ) ) {
708 708
 			$is_repeating_field = ( 'divider' == $field['type'] );
@@ -712,14 +712,14 @@  discard block
 block discarded – undo
712 712
 		return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
713 713
 	}
714 714
 
715
-    /**
716
-     * @param string $key
717
-     * @return int field id
718
-     */
715
+	/**
716
+	 * @param string $key
717
+	 * @return int field id
718
+	 */
719 719
 	public static function get_id_by_key( $key ) {
720
-        $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
721
-        return $id;
722
-    }
720
+		$id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
721
+		return $id;
722
+	}
723 723
 
724 724
 	/**
725 725
 	 * @param string $id
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 	static $transient_size = 200;
10 10
 
11 11
 	public static function field_selection() {
12
-		$fields = apply_filters('frm_available_fields', array(
12
+		$fields = apply_filters( 'frm_available_fields', array(
13 13
 			'text'      => __( 'Single Line Text', 'formidable' ),
14 14
 			'textarea'  => __( 'Paragraph Text', 'formidable' ),
15 15
 			'checkbox'  => __( 'Checkboxes', 'formidable' ),
@@ -18,13 +18,13 @@  discard block
 block discarded – undo
18 18
 			'email'     => __( 'Email Address', 'formidable' ),
19 19
 			'url'       => __( 'Website/URL', 'formidable' ),
20 20
 			'captcha'   => __( 'reCAPTCHA', 'formidable' ),
21
-		));
21
+		) );
22 22
 
23 23
 		return $fields;
24 24
 	}
25 25
 
26 26
 	public static function pro_field_selection() {
27
-		return apply_filters('frm_pro_available_fields', array(
27
+		return apply_filters( 'frm_pro_available_fields', array(
28 28
 			'end_divider' => array(
29 29
 				'name'  => __( 'End Section', 'formidable' ),
30 30
 				'switch_from' => 'divider',
@@ -49,36 +49,36 @@  discard block
 block discarded – undo
49 49
 			'tag'       => __( 'Tags', 'formidable' ),
50 50
 			'credit_card' => __( 'Credit Card', 'formidable' ),
51 51
 			'address'   => __( 'Address', 'formidable' ),
52
-		));
52
+		) );
53 53
 	}
54 54
 
55 55
     public static function create( $values, $return = true ) {
56 56
         global $wpdb, $frm_duplicate_ids;
57 57
 
58 58
         $new_values = array();
59
-        $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
59
+        $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name'];
60 60
 		$new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
61 61
 
62 62
 		foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
63
-			$new_values[ $col ] = $values[ $col ];
63
+			$new_values[$col] = $values[$col];
64 64
         }
65 65
 
66 66
         $new_values['options'] = $values['options'];
67 67
 
68
-        $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
-        $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
-        $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
68
+        $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
69
+        $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0;
70
+        $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
71 71
         $new_values['field_options'] = $values['field_options'];
72
-        $new_values['created_at'] = current_time('mysql', 1);
72
+        $new_values['created_at'] = current_time( 'mysql', 1 );
73 73
 
74 74
 		if ( isset( $values['id'] ) ) {
75
-			$frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
76
-            $new_values = apply_filters('frm_duplicated_field', $new_values);
75
+			$frm_duplicate_ids[$values['field_key']] = $new_values['field_key'];
76
+            $new_values = apply_filters( 'frm_duplicated_field', $new_values );
77 77
         }
78 78
 
79 79
 		foreach ( $new_values as $k => $v ) {
80 80
             if ( is_array( $v ) ) {
81
-				$new_values[ $k ] = serialize( $v );
81
+				$new_values[$k] = serialize( $v );
82 82
 			}
83 83
             unset( $k, $v );
84 84
         }
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 
100 100
 		if ( $query_results ) {
101 101
 			if ( isset( $values['id'] ) ) {
102
-				$frm_duplicate_ids[ $values['id'] ] = $new_id;
102
+				$frm_duplicate_ids[$values['id']] = $new_id;
103 103
 			}
104 104
 			return $new_id;
105 105
 		} else {
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 		$fields = self::getAll( $where, 'field_order', '', $blog_id );
115 115
 
116 116
         foreach ( (array) $fields as $field ) {
117
-            $new_key = ($copy_keys) ? $field->field_key : '';
118
-            if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
119
-                $new_key = rtrim($new_key, 2);
117
+            $new_key = ( $copy_keys ) ? $field->field_key : '';
118
+            if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) {
119
+                $new_key = rtrim( $new_key, 2 );
120 120
             }
121 121
 
122 122
             $values = array();
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
 				$values['form_id'] = $new_repeat_form_id;
140 140
 			}
141 141
 
142
-            $values = apply_filters('frm_duplicated_field', $values);
143
-            $new_id = self::create($values);
144
-            $frm_duplicate_ids[ $field->id ] = $new_id;
145
-            $frm_duplicate_ids[ $field->field_key ] = $new_id;
146
-            unset($field);
142
+            $values = apply_filters( 'frm_duplicated_field', $values );
143
+            $new_id = self::create( $values );
144
+            $frm_duplicate_ids[$field->id] = $new_id;
145
+            $frm_duplicate_ids[$field->field_key] = $new_id;
146
+            unset( $field );
147 147
         }
148 148
     }
149 149
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 			$values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id );
157 157
 		}
158 158
 
159
-        if ( isset($values['required']) ) {
159
+        if ( isset( $values['required'] ) ) {
160 160
             $values['required'] = (int) $values['required'];
161 161
         }
162 162
 
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
 
174 174
 		// serialize array values
175 175
 		foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) {
176
-			if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) {
177
-				$values[ $opt ] = serialize( $values[ $opt ] );
176
+			if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) {
177
+				$values[$opt] = serialize( $values[$opt] );
178 178
 			}
179 179
 		}
180 180
 
@@ -184,13 +184,13 @@  discard block
 block discarded – undo
184 184
 		if ( isset( $values['form_id'] ) ) {
185 185
             $form_id = absint( $values['form_id'] );
186 186
 		} else {
187
-            $field = self::getOne($id);
187
+            $field = self::getOne( $id );
188 188
             if ( $field ) {
189 189
                 $form_id = $field->form_id;
190 190
             }
191
-            unset($field);
191
+            unset( $field );
192 192
         }
193
-        unset($values);
193
+        unset( $values );
194 194
 
195 195
 		if ( $query_results ) {
196 196
             wp_cache_delete( $id, 'frm_field' );
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 
244 244
 		FrmDb::cache_delete_group( 'frm_field' );
245 245
 
246
-        $form = FrmForm::getOne($form_id);
246
+        $form = FrmForm::getOne( $form_id );
247 247
         if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
248 248
             self::delete_form_transient( $form->parent_form_id );
249 249
         }
@@ -265,16 +265,16 @@  discard block
 block discarded – undo
265 265
 
266 266
         global $wpdb;
267 267
 
268
-        $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
268
+        $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s';
269 269
 		$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id );
270 270
 
271 271
         $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
272 272
 
273
-        if ( empty($results) ) {
273
+        if ( empty( $results ) ) {
274 274
             return $results;
275 275
         }
276 276
 
277
-        if ( is_numeric($id) ) {
277
+        if ( is_numeric( $id ) ) {
278 278
 			FrmDb::set_cache( $results->field_key, $results, 'frm_field' );
279 279
         } else if ( $results ) {
280 280
 			FrmDb::set_cache( $results->id, $results, 'frm_field' );
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 
283 283
 		self::prepare_options( $results );
284 284
 
285
-        return stripslashes_deep($results);
285
+        return stripslashes_deep( $results );
286 286
     }
287 287
 
288 288
     /**
@@ -315,20 +315,20 @@  discard block
 block discarded – undo
315 315
                     continue;
316 316
                 }
317 317
 
318
-				$fields[ $result->id ] = $result;
319
-                $count++;
318
+				$fields[$result->id] = $result;
319
+                $count ++;
320 320
                 if ( $limit == 1 ) {
321 321
                     $fields = $result;
322 322
                     break;
323 323
                 }
324 324
 
325
-                if ( ! empty($limit) && $count >= $limit ) {
325
+                if ( ! empty( $limit ) && $count >= $limit ) {
326 326
                     break;
327 327
                 }
328 328
 
329
-                unset($result);
329
+                unset( $result );
330 330
             }
331
-            return stripslashes_deep($fields);
331
+            return stripslashes_deep( $fields );
332 332
         }
333 333
 
334 334
         self::$use_cache = false;
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 		self::maybe_include_repeating_fields( $inc_sub, $where );
338 338
 		$results = self::getAll( $where, 'field_order', $limit );
339 339
         self::$use_cache = true;
340
-        self::include_sub_fields($results, $inc_sub, $type);
340
+        self::include_sub_fields( $results, $inc_sub, $type );
341 341
 
342 342
         return $results;
343 343
     }
@@ -349,15 +349,15 @@  discard block
 block discarded – undo
349 349
 
350 350
 		$results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
351 351
 		if ( ! empty( $results ) ) {
352
-            if ( empty($limit) ) {
352
+            if ( empty( $limit ) ) {
353 353
 				return $results;
354 354
             }
355 355
 
356 356
             $fields = array();
357 357
             $count = 0;
358 358
             foreach ( $results as $result ) {
359
-				$fields[ $result->id ] = $result;
360
-                if ( ! empty($limit) && $count >= $limit ) {
359
+				$fields[$result->id] = $result;
360
+                if ( ! empty( $limit ) && $count >= $limit ) {
361 361
                     break;
362 362
                 }
363 363
             }
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 
376 376
 		self::include_sub_fields( $results, $inc_embed, 'all' );
377 377
 
378
-        if ( empty($limit) ) {
378
+        if ( empty( $limit ) ) {
379 379
 			self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
380 380
         }
381 381
 
@@ -404,22 +404,22 @@  discard block
 block discarded – undo
404 404
         $form_fields = $results;
405 405
 		$index_offset = 1;
406 406
         foreach ( $form_fields as $k => $field ) {
407
-            if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
407
+            if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
408 408
                 continue;
409 409
             }
410 410
 
411 411
             if ( $type == 'all' ) {
412 412
                 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
413 413
             } else {
414
-                $sub_fields = self::get_all_types_in_form($field->form_id, $type);
414
+                $sub_fields = self::get_all_types_in_form( $field->form_id, $type );
415 415
             }
416 416
 
417
-            if ( ! empty($sub_fields) ) {
417
+            if ( ! empty( $sub_fields ) ) {
418 418
 				$index = $k + $index_offset;
419 419
 				$index_offset += count( $sub_fields );
420
-				array_splice($results, $index, 0, $sub_fields);
420
+				array_splice( $results, $index, 0, $sub_fields );
421 421
             }
422
-            unset($field, $sub_fields);
422
+            unset( $field, $sub_fields );
423 423
         }
424 424
     }
425 425
 
@@ -427,9 +427,9 @@  discard block
 block discarded – undo
427 427
 		$cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
428 428
         if ( self::$use_cache ) {
429 429
             // make sure old cache doesn't get saved as a transient
430
-            $results = wp_cache_get($cache_key, 'frm_field');
430
+            $results = wp_cache_get( $cache_key, 'frm_field' );
431 431
             if ( false !== $results ) {
432
-                return stripslashes_deep($results);
432
+                return stripslashes_deep( $results );
433 433
             }
434 434
         }
435 435
 
@@ -459,11 +459,11 @@  discard block
 block discarded – undo
459 459
         $query = "SELECT fi.*, fr.name as form_name  FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
460 460
         $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
461 461
 
462
-        if ( is_array($where) ) {
462
+        if ( is_array( $where ) ) {
463 463
             $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type );
464 464
 		} else {
465 465
 			// if the query is not an array, then it has already been prepared
466
-			$query .= FrmDb::prepend_and_or_where(' WHERE ', $where ) . $order_by . $limit;
466
+			$query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
467 467
 
468 468
 			$function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
469 469
 			$results = $wpdb->$function_name( $query );
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
 				FrmDb::set_cache( $result->id, $result, 'frm_field' );
487 487
 				FrmDb::set_cache( $result->field_key, $result, 'frm_field' );
488 488
 
489
-				$results[ $r_key ]->field_options = maybe_unserialize( $result->field_options );
490
-				$results[ $r_key ]->options = maybe_unserialize( $result->options );
491
-				$results[ $r_key ]->default_value = maybe_unserialize( $result->default_value );
489
+				$results[$r_key]->field_options = maybe_unserialize( $result->field_options );
490
+				$results[$r_key]->options = maybe_unserialize( $result->options );
491
+				$results[$r_key]->default_value = maybe_unserialize( $result->default_value );
492 492
 
493 493
 				unset( $r_key, $result );
494 494
 			}
@@ -507,8 +507,8 @@  discard block
 block discarded – undo
507 507
 	private static function prepare_options( &$results ) {
508 508
 		$results->field_options = maybe_unserialize( $results->field_options );
509 509
 
510
-		$results->options = maybe_unserialize($results->options);
511
-		$results->default_value = maybe_unserialize($results->default_value);
510
+		$results->options = maybe_unserialize( $results->options );
511
+		$results->default_value = maybe_unserialize( $results->default_value );
512 512
 	}
513 513
 
514 514
 	/**
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
 
536 536
 			if ( count( $next_fields ) >= self::$transient_size ) {
537 537
 				// if this transient is full, check for another
538
-				$next++;
538
+				$next ++;
539 539
 				self::get_next_transient( $fields, $base_name, $next );
540 540
 			}
541 541
 		}
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 				return;
562 562
 			}
563 563
 
564
-			$next++;
564
+			$next ++;
565 565
 		}
566 566
 	}
567 567
 
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
 		$field_type = is_array( $field ) ? $field['type'] : $field->type;
616 616
 		$data_type = self::get_option( $field, 'data_type' );
617 617
 
618
-		return self::is_option_true( $field, 'multiple' ) && ( ( $field_type == 'select' || ( $field_type == 'data' && $data_type == 'select') ) );
618
+		return self::is_option_true( $field, 'multiple' ) && ( ( $field_type == 'select' || ( $field_type == 'data' && $data_type == 'select' ) ) );
619 619
 	}
620 620
 
621 621
 	/**
@@ -661,23 +661,23 @@  discard block
 block discarded – undo
661 661
 	}
662 662
 
663 663
 	public static function is_option_true_in_array( $field, $option ) {
664
-		return isset( $field[ $option ] ) && $field[ $option ];
664
+		return isset( $field[$option] ) && $field[$option];
665 665
 	}
666 666
 
667 667
 	public static function is_option_true_in_object( $field, $option ) {
668
-		return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
668
+		return isset( $field->field_options[$option] ) && $field->field_options[$option];
669 669
 	}
670 670
 
671 671
 	public static function is_option_empty_in_array( $field, $option ) {
672
-		return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
672
+		return ! isset( $field[$option] ) || empty( $field[$option] );
673 673
 	}
674 674
 
675 675
 	public static function is_option_empty_in_object( $field, $option ) {
676
-		return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
676
+		return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] );
677 677
 	}
678 678
 
679 679
 	public static function is_option_value_in_object( $field, $option ) {
680
-		return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
680
+		return isset( $field->field_options[$option] ) && $field->field_options[$option] != '';
681 681
 	}
682 682
 
683 683
 	/**
@@ -693,11 +693,11 @@  discard block
 block discarded – undo
693 693
 	}
694 694
 
695 695
 	public static function get_option_in_array( $field, $option ) {
696
-		return isset( $field[ $option ] ) ? $field[ $option ] : '';
696
+		return isset( $field[$option] ) ? $field[$option] : '';
697 697
 	}
698 698
 
699 699
 	public static function get_option_in_object( $field, $option ) {
700
-		return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
700
+		return isset( $field->field_options[$option] ) ? $field->field_options[$option] : '';
701 701
 	}
702 702
 
703 703
 	/**
Please login to merge, or discard this patch.
classes/models/FrmForm.php 2 patches
Indentation   +319 added lines, -319 removed lines patch added patch discarded remove patch
@@ -1,262 +1,262 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('ABSPATH') ) {
3
-    die('You are not allowed to call this page directly.');
3
+	die('You are not allowed to call this page directly.');
4 4
 }
5 5
 
6 6
 class FrmForm {
7 7
 
8
-    /**
9
-     * @return int|boolean id on success or false on failure
10
-     */
11
-    public static function create( $values ) {
12
-        global $wpdb;
8
+	/**
9
+	 * @return int|boolean id on success or false on failure
10
+	 */
11
+	public static function create( $values ) {
12
+		global $wpdb;
13 13
 
14
-        $new_values = array(
14
+		$new_values = array(
15 15
 			'form_key'      => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16
-            'name'          => $values['name'],
17
-            'description'   => $values['description'],
18
-            'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
-            'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
-            'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
16
+			'name'          => $values['name'],
17
+			'description'   => $values['description'],
18
+			'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
+			'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
+			'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
21 21
 			'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
-            'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
-            'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
-            'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
-        );
22
+			'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
+			'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
+			'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
+		);
26 26
 
27 27
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
28 28
 		FrmFormsHelper::fill_form_options( $options, $values );
29 29
 
30
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
-        $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
30
+		$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
+		$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
+		$options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
33 33
 
34
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
35
-        $new_values['options'] = serialize($options);
34
+		$options = apply_filters('frm_form_options_before_update', $options, $values);
35
+		$new_values['options'] = serialize($options);
36 36
 
37
-        //if(isset($values['id']) && is_numeric($values['id']))
38
-        //    $new_values['id'] = $values['id'];
37
+		//if(isset($values['id']) && is_numeric($values['id']))
38
+		//    $new_values['id'] = $values['id'];
39 39
 
40 40
 		$wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
41 41
 
42
-        $id = $wpdb->insert_id;
42
+		$id = $wpdb->insert_id;
43 43
 
44 44
 		// Clear form caching
45 45
 		self::clear_form_cache();
46 46
 
47
-        return $id;
48
-    }
47
+		return $id;
48
+	}
49 49
 
50
-    /**
51
-     * @return int|boolean ID on success or false on failure
52
-     */
53
-    public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
-        global $wpdb;
50
+	/**
51
+	 * @return int|boolean ID on success or false on failure
52
+	 */
53
+	public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
+		global $wpdb;
55 55
 
56
-        $values = self::getOne( $id, $blog_id );
57
-        if ( ! $values ) {
58
-            return false;
59
-        }
56
+		$values = self::getOne( $id, $blog_id );
57
+		if ( ! $values ) {
58
+			return false;
59
+		}
60 60
 
61
-        $new_key = $copy_keys ? $values->form_key : '';
61
+		$new_key = $copy_keys ? $values->form_key : '';
62 62
 
63
-        $new_values = array(
63
+		$new_values = array(
64 64
 			'form_key'      => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ),
65
-            'name'          => $values->name,
66
-            'description'   => $values->description,
67
-            'status'        => $template ? 'published' : 'draft',
68
-            'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
-            'editable'      => $values->editable ? $values->editable : 0,
70
-            'created_at'    => current_time('mysql', 1),
71
-            'is_template'   => $template ? 1 : 0,
72
-        );
73
-
74
-        if ( $blog_id ) {
75
-            $new_values['status'] = 'published';
76
-            $new_options = maybe_unserialize($values->options);
77
-            $new_options['email_to'] = get_option('admin_email');
78
-            $new_options['copy'] = false;
79
-            $new_values['options'] = $new_options;
80
-        } else {
81
-            $new_values['options'] = $values->options;
82
-        }
83
-
84
-        if ( is_array($new_values['options']) ) {
85
-            $new_values['options'] = serialize($new_values['options']);
86
-        }
65
+			'name'          => $values->name,
66
+			'description'   => $values->description,
67
+			'status'        => $template ? 'published' : 'draft',
68
+			'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
+			'editable'      => $values->editable ? $values->editable : 0,
70
+			'created_at'    => current_time('mysql', 1),
71
+			'is_template'   => $template ? 1 : 0,
72
+		);
73
+
74
+		if ( $blog_id ) {
75
+			$new_values['status'] = 'published';
76
+			$new_options = maybe_unserialize($values->options);
77
+			$new_options['email_to'] = get_option('admin_email');
78
+			$new_options['copy'] = false;
79
+			$new_values['options'] = $new_options;
80
+		} else {
81
+			$new_values['options'] = $values->options;
82
+		}
83
+
84
+		if ( is_array($new_values['options']) ) {
85
+			$new_values['options'] = serialize($new_values['options']);
86
+		}
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
89 89
 
90
-        if ( $query_results ) {
90
+		if ( $query_results ) {
91 91
 			// Clear form caching
92 92
 			self::clear_form_cache();
93 93
 
94
-            $form_id = $wpdb->insert_id;
95
-            FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
94
+			$form_id = $wpdb->insert_id;
95
+			FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
96 96
 
97
-            // update form settings after fields are created
97
+			// update form settings after fields are created
98 98
 			do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
99
-            return $form_id;
100
-        }
99
+			return $form_id;
100
+		}
101 101
 
102
-        return false;
103
-    }
102
+		return false;
103
+	}
104 104
 
105 105
 	public static function after_duplicate( $form_id, $values ) {
106 106
 		$new_opts = maybe_unserialize( $values['options'] );
107 107
 		$values['options'] = $new_opts;
108 108
 
109
-        if ( isset($new_opts['success_msg']) ) {
110
-            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
111
-        }
109
+		if ( isset($new_opts['success_msg']) ) {
110
+			$new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
111
+		}
112 112
 
113
-        $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
113
+		$new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
114 114
 
115
-        if ( $new_opts != $values['options'] ) {
116
-            global $wpdb;
115
+		if ( $new_opts != $values['options'] ) {
116
+			global $wpdb;
117 117
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
118
-        }
119
-    }
118
+		}
119
+	}
120 120
 
121
-    /**
122
-     * @return int|boolean
123
-     */
124
-    public static function update( $id, $values, $create_link = false ) {
125
-        global $wpdb;
121
+	/**
122
+	 * @return int|boolean
123
+	 */
124
+	public static function update( $id, $values, $create_link = false ) {
125
+		global $wpdb;
126 126
 
127
-        if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
128
-            $values['status'] = 'published';
129
-        }
127
+		if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
128
+			$values['status'] = 'published';
129
+		}
130 130
 
131
-        if ( isset($values['form_key']) ) {
131
+		if ( isset($values['form_key']) ) {
132 132
 			$values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
133
-        }
133
+		}
134 134
 
135 135
 		$form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
136 136
 
137
-        $new_values = self::set_update_options( array(), $values);
137
+		$new_values = self::set_update_options( array(), $values);
138 138
 
139
-        foreach ( $values as $value_key => $value ) {
139
+		foreach ( $values as $value_key => $value ) {
140 140
 			if ( $value_key && in_array( $value_key, $form_fields ) ) {
141 141
 				$new_values[ $value_key ] = $value;
142
-            }
143
-        }
142
+			}
143
+		}
144 144
 
145
-        if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
146
-            $new_values['status'] = $values['new_status'];
147
-        }
145
+		if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
146
+			$new_values['status'] = $values['new_status'];
147
+		}
148 148
 
149
-        if ( ! empty( $new_values ) ) {
149
+		if ( ! empty( $new_values ) ) {
150 150
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) );
151
-            if ( $query_results ) {
151
+			if ( $query_results ) {
152 152
 				self::clear_form_cache();
153
-            }
154
-        } else {
155
-            $query_results = true;
156
-        }
157
-        unset($new_values);
153
+			}
154
+		} else {
155
+			$query_results = true;
156
+		}
157
+		unset($new_values);
158 158
 
159
-        $values = self::update_fields($id, $values);
159
+		$values = self::update_fields($id, $values);
160 160
 
161 161
 		do_action( 'frm_update_form', $id, $values );
162 162
 		do_action( 'frm_update_form_' . $id, $values );
163 163
 
164
-        return $query_results;
165
-    }
164
+		return $query_results;
165
+	}
166 166
 
167
-    /**
168
-     * @return array
169
-     */
167
+	/**
168
+	 * @return array
169
+	 */
170 170
 	public static function set_update_options( $new_values, $values ) {
171
-        if ( ! isset($values['options']) ) {
172
-            return $new_values;
173
-        }
171
+		if ( ! isset($values['options']) ) {
172
+			return $new_values;
173
+		}
174 174
 
175 175
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
176 176
 		FrmFormsHelper::fill_form_options( $options, $values );
177 177
 
178
-        $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
179
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
180
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
181
-        $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
178
+		$options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
179
+		$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
180
+		$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
181
+		$options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
182 182
 
183
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
184
-        $new_values['options'] = serialize($options);
183
+		$options = apply_filters('frm_form_options_before_update', $options, $values);
184
+		$new_values['options'] = serialize($options);
185 185
 
186
-        return $new_values;
187
-    }
186
+		return $new_values;
187
+	}
188 188
 
189 189
 
190
-    /**
191
-     * @return array
192
-     */
190
+	/**
191
+	 * @return array
192
+	 */
193 193
 	public static function update_fields( $id, $values ) {
194 194
 
195
-        if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
196
-            return $values;
197
-        }
195
+		if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
196
+			return $values;
197
+		}
198 198
 
199
-        $all_fields = FrmField::get_all_for_form($id);
200
-        if ( empty($all_fields) ) {
201
-            return $values;
202
-        }
199
+		$all_fields = FrmField::get_all_for_form($id);
200
+		if ( empty($all_fields) ) {
201
+			return $values;
202
+		}
203 203
 
204
-        if ( ! isset($values['item_meta']) ) {
205
-            $values['item_meta'] = array();
206
-        }
204
+		if ( ! isset($values['item_meta']) ) {
205
+			$values['item_meta'] = array();
206
+		}
207 207
 
208
-        $field_array = array();
209
-        $existing_keys = array_keys($values['item_meta']);
210
-        foreach ( $all_fields as $fid ) {
211
-            if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
208
+		$field_array = array();
209
+		$existing_keys = array_keys($values['item_meta']);
210
+		foreach ( $all_fields as $fid ) {
211
+			if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
212 212
 				$values['item_meta'][ $fid->id ] = '';
213
-            }
213
+			}
214 214
 			$field_array[ $fid->id ] = $fid;
215
-        }
216
-        unset($all_fields);
215
+		}
216
+		unset($all_fields);
217 217
 
218
-        foreach ( $values['item_meta'] as $field_id => $default_value ) {
218
+		foreach ( $values['item_meta'] as $field_id => $default_value ) {
219 219
 			if ( isset( $field_array[ $field_id ] ) ) {
220 220
 				$field = $field_array[ $field_id ];
221
-            } else {
222
-                $field = FrmField::getOne($field_id);
223
-            }
221
+			} else {
222
+				$field = FrmField::getOne($field_id);
223
+			}
224 224
 
225
-            if ( ! $field ) {
226
-                continue;
227
-            }
225
+			if ( ! $field ) {
226
+				continue;
227
+			}
228 228
 
229 229
 			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
230 230
 			if ( $is_settings_page ) {
231
-                //updating the settings page
231
+				//updating the settings page
232 232
 				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
233 233
 					$field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
234
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
234
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
235 235
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
236
-                } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
237
-                    $prev_opts = $field->field_options;
238
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
239
-                    if ( $prev_opts != $field->field_options ) {
236
+				} else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
237
+					$prev_opts = $field->field_options;
238
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
239
+					if ( $prev_opts != $field->field_options ) {
240 240
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
241
-                    }
242
-                    unset($prev_opts);
243
-                }
244
-            }
241
+					}
242
+					unset($prev_opts);
243
+				}
244
+			}
245 245
 
246 246
 			if ( $is_settings_page && ! defined( 'WP_IMPORTING' ) ) {
247
-                continue;
248
-            }
247
+				continue;
248
+			}
249 249
 
250
-            //updating the form
250
+			//updating the form
251 251
 			$update_options = FrmFieldsHelper::get_default_field_opts( $field->type, $field, true );
252 252
 			unset( $update_options['custom_html'] ); // don't check for POST html
253 253
 			$update_options = apply_filters( 'frm_field_options_to_update', $update_options );
254 254
 
255 255
 			foreach ( $update_options as $opt => $default ) {
256 256
 				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default;
257
-            }
257
+			}
258 258
 
259
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
259
+			$field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
260 260
 			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
261 261
 
262 262
 			$new_field = array(
@@ -268,12 +268,12 @@  discard block
 block discarded – undo
268 268
 
269 269
 			FrmField::update( $field_id, $new_field );
270 270
 
271
-            FrmField::delete_form_transient($field->form_id);
272
-        }
271
+			FrmField::delete_form_transient($field->form_id);
272
+		}
273 273
 		self::clear_form_cache();
274 274
 
275
-        return $values;
276
-    }
275
+		return $values;
276
+	}
277 277
 
278 278
 	private static function prepare_field_update_values( $field, $values, &$new_field ) {
279 279
 		$field_cols = array(
@@ -286,113 +286,113 @@  discard block
 block discarded – undo
286 286
 		}
287 287
 	}
288 288
 
289
-    /**
290
-     * @param string $status
291
-     * @return int|boolean
292
-     */
289
+	/**
290
+	 * @param string $status
291
+	 * @return int|boolean
292
+	 */
293 293
 	public static function set_status( $id, $status ) {
294
-        if ( 'trash' == $status ) {
295
-            return self::trash($id);
296
-        }
294
+		if ( 'trash' == $status ) {
295
+			return self::trash($id);
296
+		}
297 297
 
298 298
 		$statuses  = array( 'published', 'draft', 'trash' );
299
-        if ( ! in_array( $status, $statuses ) ) {
300
-            return false;
301
-        }
299
+		if ( ! in_array( $status, $statuses ) ) {
300
+			return false;
301
+		}
302 302
 
303
-        global $wpdb;
303
+		global $wpdb;
304 304
 
305
-        if ( is_array($id) ) {
305
+		if ( is_array($id) ) {
306 306
 			$where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 );
307 307
 			FrmDb::get_where_clause_and_values( $where );
308 308
 			array_unshift( $where['values'], $status );
309 309
 
310 310
 			$query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) );
311
-        } else {
311
+		} else {
312 312
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
313 313
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) );
314
-        }
314
+		}
315 315
 
316
-        if ( $query_results ) {
316
+		if ( $query_results ) {
317 317
 			self::clear_form_cache();
318
-        }
318
+		}
319 319
 
320
-        return $query_results;
321
-    }
320
+		return $query_results;
321
+	}
322 322
 
323
-    /**
324
-     * @return int|boolean
325
-     */
323
+	/**
324
+	 * @return int|boolean
325
+	 */
326 326
 	public static function trash( $id ) {
327
-        if ( ! EMPTY_TRASH_DAYS ) {
328
-            return self::destroy( $id );
329
-        }
327
+		if ( ! EMPTY_TRASH_DAYS ) {
328
+			return self::destroy( $id );
329
+		}
330 330
 
331
-        $form = self::getOne($id);
332
-        if ( ! $form ) {
333
-            return false;
334
-        }
331
+		$form = self::getOne($id);
332
+		if ( ! $form ) {
333
+			return false;
334
+		}
335 335
 
336
-        $options = $form->options;
337
-        $options['trash_time'] = time();
336
+		$options = $form->options;
337
+		$options['trash_time'] = time();
338 338
 
339
-        global $wpdb;
340
-        $query_results = $wpdb->update(
339
+		global $wpdb;
340
+		$query_results = $wpdb->update(
341 341
 			$wpdb->prefix . 'frm_forms',
342 342
 			array( 'status' => 'trash', 'options' => serialize( $options ) ),
343 343
 			array( 'id' => $id )
344
-        );
344
+		);
345 345
 
346
-        $wpdb->update(
346
+		$wpdb->update(
347 347
 			$wpdb->prefix . 'frm_forms',
348 348
 			array( 'status' => 'trash', 'options' => serialize( $options ) ),
349 349
 			array( 'parent_form_id' => $id )
350
-        );
350
+		);
351 351
 
352
-        if ( $query_results ) {
352
+		if ( $query_results ) {
353 353
 			self::clear_form_cache();
354
-        }
354
+		}
355 355
 
356
-        return $query_results;
357
-    }
356
+		return $query_results;
357
+	}
358 358
 
359
-    /**
360
-     * @return int|boolean
361
-     */
359
+	/**
360
+	 * @return int|boolean
361
+	 */
362 362
 	public static function destroy( $id ) {
363
-        global $wpdb;
363
+		global $wpdb;
364 364
 
365
-        $form = self::getOne($id);
366
-        if ( ! $form ) {
367
-            return false;
368
-        }
365
+		$form = self::getOne($id);
366
+		if ( ! $form ) {
367
+			return false;
368
+		}
369 369
 		$id = $form->id;
370 370
 
371
-        // Disconnect the entries from this form
371
+		// Disconnect the entries from this form
372 372
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
373
-        foreach ( $entries as $entry_id ) {
374
-            FrmEntry::destroy($entry_id);
375
-            unset($entry_id);
376
-        }
373
+		foreach ( $entries as $entry_id ) {
374
+			FrmEntry::destroy($entry_id);
375
+			unset($entry_id);
376
+		}
377 377
 
378
-        // Disconnect the fields from this form
378
+		// Disconnect the fields from this form
379 379
 		$wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) );
380 380
 
381 381
 		$query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
382
-        if ( $query_results ) {
383
-            // Delete all form actions linked to this form
384
-            $action_control = FrmFormActionsController::get_form_actions( 'email' );
385
-            $action_control->destroy($id, 'all');
382
+		if ( $query_results ) {
383
+			// Delete all form actions linked to this form
384
+			$action_control = FrmFormActionsController::get_form_actions( 'email' );
385
+			$action_control->destroy($id, 'all');
386 386
 
387 387
 			// Clear form caching
388 388
 			self::clear_form_cache();
389 389
 
390 390
 			do_action( 'frm_destroy_form', $id );
391 391
 			do_action( 'frm_destroy_form_' . $id );
392
-        }
392
+		}
393 393
 
394
-        return $query_results;
395
-    }
394
+		return $query_results;
395
+	}
396 396
 
397 397
 	/**
398 398
 	 * Delete trashed forms based on how long they have been trashed
@@ -424,46 +424,46 @@  discard block
 block discarded – undo
424 424
 		return $count;
425 425
 	}
426 426
 
427
-    /**
428
-     * @return string form name
429
-     */
430
-    public static function getName( $id ) {
427
+	/**
428
+	 * @return string form name
429
+	 */
430
+	public static function getName( $id ) {
431 431
 		$form = FrmDb::check_cache( $id, 'frm_form' );
432
-        if ( $form ) {
433
-            $r = stripslashes($form->name);
434
-            return $r;
435
-        }
436
-
437
-        $query_key = is_numeric( $id ) ? 'id' : 'form_key';
438
-        $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
439
-        $r = stripslashes($r);
440
-
441
-        return $r;
442
-    }
443
-
444
-    /**
445
-     * @param string $key
446
-     * @return int form id
447
-     */
432
+		if ( $form ) {
433
+			$r = stripslashes($form->name);
434
+			return $r;
435
+		}
436
+
437
+		$query_key = is_numeric( $id ) ? 'id' : 'form_key';
438
+		$r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
439
+		$r = stripslashes($r);
440
+
441
+		return $r;
442
+	}
443
+
444
+	/**
445
+	 * @param string $key
446
+	 * @return int form id
447
+	 */
448 448
 	public static function getIdByKey( $key ) {
449 449
 		return (int) FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
450
-    }
450
+	}
451 451
 
452
-    /**
453
-     * @param int $id
454
-     * @return string form key
455
-     */
452
+	/**
453
+	 * @param int $id
454
+	 * @return string form key
455
+	 */
456 456
 	public static function getKeyById( $id ) {
457
-        $id = (int) $id;
457
+		$id = (int) $id;
458 458
 		$cache = FrmDb::check_cache( $id, 'frm_form' );
459
-        if ( $cache ) {
460
-            return $cache->form_key;
461
-        }
459
+		if ( $cache ) {
460
+			return $cache->form_key;
461
+		}
462 462
 
463
-        $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
463
+		$key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
464 464
 
465
-        return $key;
466
-    }
465
+		return $key;
466
+	}
467 467
 
468 468
 	/**
469 469
 	 * If $form is numeric, get the form object
@@ -476,47 +476,47 @@  discard block
 block discarded – undo
476 476
 		}
477 477
 	}
478 478
 
479
-    /**
480
-     * @return object form
481
-     */
482
-    public static function getOne( $id, $blog_id = false ) {
483
-        global $wpdb;
479
+	/**
480
+	 * @return object form
481
+	 */
482
+	public static function getOne( $id, $blog_id = false ) {
483
+		global $wpdb;
484 484
 
485
-        if ( $blog_id && is_multisite() ) {
486
-            global $wpmuBaseTablePrefix;
485
+		if ( $blog_id && is_multisite() ) {
486
+			global $wpmuBaseTablePrefix;
487 487
 			$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id );
488 488
 
489 489
 			$table_name = $prefix . 'frm_forms';
490
-        } else {
490
+		} else {
491 491
 			$table_name = $wpdb->prefix . 'frm_forms';
492
-            $cache = wp_cache_get($id, 'frm_form');
493
-            if ( $cache ) {
494
-                if ( isset($cache->options) ) {
495
-                    $cache->options = maybe_unserialize($cache->options);
496
-                }
492
+			$cache = wp_cache_get($id, 'frm_form');
493
+			if ( $cache ) {
494
+				if ( isset($cache->options) ) {
495
+					$cache->options = maybe_unserialize($cache->options);
496
+				}
497 497
 
498
-                return stripslashes_deep($cache);
499
-            }
500
-        }
498
+				return stripslashes_deep($cache);
499
+			}
500
+		}
501 501
 
502
-        if ( is_numeric($id) ) {
503
-            $where = array( 'id' => $id );
504
-        } else {
505
-            $where = array( 'form_key' => $id );
506
-        }
502
+		if ( is_numeric($id) ) {
503
+			$where = array( 'id' => $id );
504
+		} else {
505
+			$where = array( 'form_key' => $id );
506
+		}
507 507
 
508
-        $results = FrmDb::get_row( $table_name, $where );
508
+		$results = FrmDb::get_row( $table_name, $where );
509 509
 
510
-        if ( isset($results->options) ) {
510
+		if ( isset($results->options) ) {
511 511
 			FrmDb::set_cache( $results->id, $results, 'frm_form' );
512
-            $results->options = maybe_unserialize($results->options);
513
-        }
514
-        return stripslashes_deep($results);
515
-    }
516
-
517
-    /**
518
-     * @return object|array of objects
519
-     */
512
+			$results->options = maybe_unserialize($results->options);
513
+		}
514
+		return stripslashes_deep($results);
515
+	}
516
+
517
+	/**
518
+	 * @return object|array of objects
519
+	 */
520 520
 	public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
521 521
 		if ( is_array( $where ) && ! empty( $where ) ) {
522 522
 			$results = FrmDb::get_results( 'frm_forms', $where, '*', array( 'order_by' => $order_by, 'limit' => $limit ) );
@@ -540,8 +540,8 @@  discard block
 block discarded – undo
540 540
 			$results = reset( $results );
541 541
 		}
542 542
 
543
-        return stripslashes_deep($results);
544
-    }
543
+		return stripslashes_deep($results);
544
+	}
545 545
 
546 546
 	/**
547 547
 	 * Get all published forms
@@ -559,47 +559,47 @@  discard block
 block discarded – undo
559 559
 		return $forms;
560 560
 	}
561 561
 
562
-    /**
563
-     * @return int count of forms
564
-     */
565
-    public static function get_count() {
566
-    	global $wpdb;
562
+	/**
563
+	 * @return int count of forms
564
+	 */
565
+	public static function get_count() {
566
+		global $wpdb;
567 567
 
568
-    	$cache_key = 'frm_form_counts';
568
+		$cache_key = 'frm_form_counts';
569 569
 
570
-    	$counts = wp_cache_get( $cache_key, 'frm_form' );
571
-    	if ( false !== $counts ) {
572
-    	    return $counts;
573
-    	}
570
+		$counts = wp_cache_get( $cache_key, 'frm_form' );
571
+		if ( false !== $counts ) {
572
+			return $counts;
573
+		}
574 574
 
575
-        $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
575
+		$results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
576 576
 
577 577
 		$statuses = array( 'published', 'draft', 'template', 'trash' );
578
-    	$counts = array_fill_keys( $statuses, 0 );
578
+		$counts = array_fill_keys( $statuses, 0 );
579 579
 
580
-    	foreach ( $results as $row ) {
581
-            if ( 'trash' != $row->status ) {
582
-    	        if ( $row->is_template ) {
580
+		foreach ( $results as $row ) {
581
+			if ( 'trash' != $row->status ) {
582
+				if ( $row->is_template ) {
583 583
 					$counts['template']++;
584
-    	        } else {
584
+				} else {
585 585
 					$counts['published']++;
586
-    	        }
587
-    	    } else {
586
+				}
587
+			} else {
588 588
 				$counts['trash']++;
589
-        	}
589
+			}
590 590
 
591
-    	    if ( 'draft' == $row->status ) {
591
+			if ( 'draft' == $row->status ) {
592 592
 				$counts['draft']++;
593
-    	    }
593
+			}
594 594
 
595
-    		unset($row);
596
-    	}
595
+			unset($row);
596
+		}
597 597
 
598
-    	$counts = (object) $counts;
598
+		$counts = (object) $counts;
599 599
 		FrmDb::set_cache( $cache_key, $counts, 'frm_form' );
600 600
 
601
-    	return $counts;
602
-    }
601
+		return $counts;
602
+	}
603 603
 
604 604
 	/**
605 605
 	 * Clear form caching
@@ -612,14 +612,14 @@  discard block
 block discarded – undo
612 612
 		FrmDb::cache_delete_group( 'frm_form' );
613 613
 	}
614 614
 
615
-    /**
616
-     * @return array of errors
617
-     */
615
+	/**
616
+	 * @return array of errors
617
+	 */
618 618
 	public static function validate( $values ) {
619
-        $errors = array();
619
+		$errors = array();
620 620
 
621
-        return apply_filters('frm_validate_form', $errors, $values);
622
-    }
621
+		return apply_filters('frm_validate_form', $errors, $values);
622
+	}
623 623
 
624 624
 	public static function get_params( $form = null ) {
625 625
 		global $frm_vars;
Please login to merge, or discard this patch.
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
3
-    die('You are not allowed to call this page directly.');
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+    die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
6 6
 class FrmForm {
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 			'form_key'      => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16 16
             'name'          => $values['name'],
17 17
             'description'   => $values['description'],
18
-            'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
-            'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
-            'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
18
+            'status'        => isset( $values['status'] ) ? $values['status'] : 'draft',
19
+            'logged_in'     => isset( $values['logged_in'] ) ? $values['logged_in'] : 0,
20
+            'is_template'   => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0,
21 21
 			'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
-            'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
-            'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
-            'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
22
+            'editable'      => isset( $values['editable'] ) ? (int) $values['editable'] : 0,
23
+            'default_template' => isset( $values['default_template'] ) ? (int) $values['default_template'] : 0,
24
+            'created_at'    => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ),
25 25
         );
26 26
 
27 27
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
28 28
 		FrmFormsHelper::fill_form_options( $options, $values );
29 29
 
30
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
-        $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
30
+        $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
31
+        $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
32
+        $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
33 33
 
34
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
35
-        $new_values['options'] = serialize($options);
34
+        $options = apply_filters( 'frm_form_options_before_update', $options, $values );
35
+        $new_values['options'] = serialize( $options );
36 36
 
37 37
         //if(isset($values['id']) && is_numeric($values['id']))
38 38
         //    $new_values['id'] = $values['id'];
@@ -67,22 +67,22 @@  discard block
 block discarded – undo
67 67
             'status'        => $template ? 'published' : 'draft',
68 68
             'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69 69
             'editable'      => $values->editable ? $values->editable : 0,
70
-            'created_at'    => current_time('mysql', 1),
70
+            'created_at'    => current_time( 'mysql', 1 ),
71 71
             'is_template'   => $template ? 1 : 0,
72 72
         );
73 73
 
74 74
         if ( $blog_id ) {
75 75
             $new_values['status'] = 'published';
76
-            $new_options = maybe_unserialize($values->options);
77
-            $new_options['email_to'] = get_option('admin_email');
76
+            $new_options = maybe_unserialize( $values->options );
77
+            $new_options['email_to'] = get_option( 'admin_email' );
78 78
             $new_options['copy'] = false;
79 79
             $new_values['options'] = $new_options;
80 80
         } else {
81 81
             $new_values['options'] = $values->options;
82 82
         }
83 83
 
84
-        if ( is_array($new_values['options']) ) {
85
-            $new_values['options'] = serialize($new_values['options']);
84
+        if ( is_array( $new_values['options'] ) ) {
85
+            $new_values['options'] = serialize( $new_values['options'] );
86 86
         }
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			self::clear_form_cache();
93 93
 
94 94
             $form_id = $wpdb->insert_id;
95
-            FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
95
+            FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id );
96 96
 
97 97
             // update form settings after fields are created
98 98
 			do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 		$new_opts = maybe_unserialize( $values['options'] );
107 107
 		$values['options'] = $new_opts;
108 108
 
109
-        if ( isset($new_opts['success_msg']) ) {
110
-            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
109
+        if ( isset( $new_opts['success_msg'] ) ) {
110
+            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids( $new_opts['success_msg'] );
111 111
         }
112 112
 
113
-        $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
113
+        $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id );
114 114
 
115 115
         if ( $new_opts != $values['options'] ) {
116 116
             global $wpdb;
@@ -128,17 +128,17 @@  discard block
 block discarded – undo
128 128
             $values['status'] = 'published';
129 129
         }
130 130
 
131
-        if ( isset($values['form_key']) ) {
131
+        if ( isset( $values['form_key'] ) ) {
132 132
 			$values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
133 133
         }
134 134
 
135 135
 		$form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
136 136
 
137
-        $new_values = self::set_update_options( array(), $values);
137
+        $new_values = self::set_update_options( array(), $values );
138 138
 
139 139
         foreach ( $values as $value_key => $value ) {
140 140
 			if ( $value_key && in_array( $value_key, $form_fields ) ) {
141
-				$new_values[ $value_key ] = $value;
141
+				$new_values[$value_key] = $value;
142 142
             }
143 143
         }
144 144
 
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
         } else {
155 155
             $query_results = true;
156 156
         }
157
-        unset($new_values);
157
+        unset( $new_values );
158 158
 
159
-        $values = self::update_fields($id, $values);
159
+        $values = self::update_fields( $id, $values );
160 160
 
161 161
 		do_action( 'frm_update_form', $id, $values );
162 162
 		do_action( 'frm_update_form_' . $id, $values );
@@ -168,20 +168,20 @@  discard block
 block discarded – undo
168 168
      * @return array
169 169
      */
170 170
 	public static function set_update_options( $new_values, $values ) {
171
-        if ( ! isset($values['options']) ) {
171
+        if ( ! isset( $values['options'] ) ) {
172 172
             return $new_values;
173 173
         }
174 174
 
175 175
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
176 176
 		FrmFormsHelper::fill_form_options( $options, $values );
177 177
 
178
-        $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
179
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
180
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
181
-        $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
178
+        $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0;
179
+        $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
180
+        $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
181
+        $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && $values['options']['submit_html'] != '' ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
182 182
 
183
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
184
-        $new_values['options'] = serialize($options);
183
+        $options = apply_filters( 'frm_form_options_before_update', $options, $values );
184
+        $new_values['options'] = serialize( $options );
185 185
 
186 186
         return $new_values;
187 187
     }
@@ -192,54 +192,54 @@  discard block
 block discarded – undo
192 192
      */
193 193
 	public static function update_fields( $id, $values ) {
194 194
 
195
-        if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
195
+        if ( ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) {
196 196
             return $values;
197 197
         }
198 198
 
199
-        $all_fields = FrmField::get_all_for_form($id);
200
-        if ( empty($all_fields) ) {
199
+        $all_fields = FrmField::get_all_for_form( $id );
200
+        if ( empty( $all_fields ) ) {
201 201
             return $values;
202 202
         }
203 203
 
204
-        if ( ! isset($values['item_meta']) ) {
204
+        if ( ! isset( $values['item_meta'] ) ) {
205 205
             $values['item_meta'] = array();
206 206
         }
207 207
 
208 208
         $field_array = array();
209
-        $existing_keys = array_keys($values['item_meta']);
209
+        $existing_keys = array_keys( $values['item_meta'] );
210 210
         foreach ( $all_fields as $fid ) {
211
-            if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
212
-				$values['item_meta'][ $fid->id ] = '';
211
+            if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) {
212
+				$values['item_meta'][$fid->id] = '';
213 213
             }
214
-			$field_array[ $fid->id ] = $fid;
214
+			$field_array[$fid->id] = $fid;
215 215
         }
216
-        unset($all_fields);
216
+        unset( $all_fields );
217 217
 
218 218
         foreach ( $values['item_meta'] as $field_id => $default_value ) {
219
-			if ( isset( $field_array[ $field_id ] ) ) {
220
-				$field = $field_array[ $field_id ];
219
+			if ( isset( $field_array[$field_id] ) ) {
220
+				$field = $field_array[$field_id];
221 221
             } else {
222
-                $field = FrmField::getOne($field_id);
222
+                $field = FrmField::getOne( $field_id );
223 223
             }
224 224
 
225 225
             if ( ! $field ) {
226 226
                 continue;
227 227
             }
228 228
 
229
-			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
229
+			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) );
230 230
 			if ( $is_settings_page ) {
231 231
                 //updating the settings page
232
-				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
233
-					$field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
234
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
232
+				if ( isset( $values['field_options']['custom_html_' . $field_id] ) ) {
233
+					$field->field_options['custom_html'] = isset( $values['field_options']['custom_html_' . $field_id] ) ? $values['field_options']['custom_html_' . $field_id] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
234
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
235 235
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
236 236
                 } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
237 237
                     $prev_opts = $field->field_options;
238
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
238
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
239 239
                     if ( $prev_opts != $field->field_options ) {
240 240
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
241 241
                     }
242
-                    unset($prev_opts);
242
+                    unset( $prev_opts );
243 243
                 }
244 244
             }
245 245
 
@@ -253,11 +253,11 @@  discard block
 block discarded – undo
253 253
 			$update_options = apply_filters( 'frm_field_options_to_update', $update_options );
254 254
 
255 255
 			foreach ( $update_options as $opt => $default ) {
256
-				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default;
256
+				$field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? trim( sanitize_text_field( $values['field_options'][$opt . '_' . $field_id] ) ) : $default;
257 257
             }
258 258
 
259
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
260
-			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
259
+            $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
260
+			$default_value = maybe_serialize( $values['item_meta'][$field_id] );
261 261
 
262 262
 			$new_field = array(
263 263
 				'field_options' => $field->field_options,
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 
269 269
 			FrmField::update( $field_id, $new_field );
270 270
 
271
-            FrmField::delete_form_transient($field->form_id);
271
+            FrmField::delete_form_transient( $field->form_id );
272 272
         }
273 273
 		self::clear_form_cache();
274 274
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 		);
283 283
 		foreach ( $field_cols as $col => $default ) {
284 284
 			$default = ( $default === '' ) ? $field->{$col} : $default;
285
-			$new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default;
285
+			$new_field[$col] = isset( $values['field_options'][$col . '_' . $field->id] ) ? $values['field_options'][$col . '_' . $field->id] : $default;
286 286
 		}
287 287
 	}
288 288
 
@@ -292,17 +292,17 @@  discard block
 block discarded – undo
292 292
      */
293 293
 	public static function set_status( $id, $status ) {
294 294
         if ( 'trash' == $status ) {
295
-            return self::trash($id);
295
+            return self::trash( $id );
296 296
         }
297 297
 
298
-		$statuses  = array( 'published', 'draft', 'trash' );
298
+		$statuses = array( 'published', 'draft', 'trash' );
299 299
         if ( ! in_array( $status, $statuses ) ) {
300 300
             return false;
301 301
         }
302 302
 
303 303
         global $wpdb;
304 304
 
305
-        if ( is_array($id) ) {
305
+        if ( is_array( $id ) ) {
306 306
 			$where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 );
307 307
 			FrmDb::get_where_clause_and_values( $where );
308 308
 			array_unshift( $where['values'], $status );
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
             return self::destroy( $id );
329 329
         }
330 330
 
331
-        $form = self::getOne($id);
331
+        $form = self::getOne( $id );
332 332
         if ( ! $form ) {
333 333
             return false;
334 334
         }
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 	public static function destroy( $id ) {
363 363
         global $wpdb;
364 364
 
365
-        $form = self::getOne($id);
365
+        $form = self::getOne( $id );
366 366
         if ( ! $form ) {
367 367
             return false;
368 368
         }
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
         // Disconnect the entries from this form
372 372
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
373 373
         foreach ( $entries as $entry_id ) {
374
-            FrmEntry::destroy($entry_id);
375
-            unset($entry_id);
374
+            FrmEntry::destroy( $entry_id );
375
+            unset( $entry_id );
376 376
         }
377 377
 
378 378
         // Disconnect the fields from this form
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
         if ( $query_results ) {
383 383
             // Delete all form actions linked to this form
384 384
             $action_control = FrmFormActionsController::get_form_actions( 'email' );
385
-            $action_control->destroy($id, 'all');
385
+            $action_control->destroy( $id, 'all' );
386 386
 
387 387
 			// Clear form caching
388 388
 			self::clear_form_cache();
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 			$form->options = maybe_unserialize( $form->options );
417 417
 			if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
418 418
 				self::destroy( $form->id );
419
-				$count++;
419
+				$count ++;
420 420
 			}
421 421
 
422 422
 			unset( $form );
@@ -430,13 +430,13 @@  discard block
 block discarded – undo
430 430
     public static function getName( $id ) {
431 431
 		$form = FrmDb::check_cache( $id, 'frm_form' );
432 432
         if ( $form ) {
433
-            $r = stripslashes($form->name);
433
+            $r = stripslashes( $form->name );
434 434
             return $r;
435 435
         }
436 436
 
437 437
         $query_key = is_numeric( $id ) ? 'id' : 'form_key';
438 438
         $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
439
-        $r = stripslashes($r);
439
+        $r = stripslashes( $r );
440 440
 
441 441
         return $r;
442 442
     }
@@ -489,17 +489,17 @@  discard block
 block discarded – undo
489 489
 			$table_name = $prefix . 'frm_forms';
490 490
         } else {
491 491
 			$table_name = $wpdb->prefix . 'frm_forms';
492
-            $cache = wp_cache_get($id, 'frm_form');
492
+            $cache = wp_cache_get( $id, 'frm_form' );
493 493
             if ( $cache ) {
494
-                if ( isset($cache->options) ) {
495
-                    $cache->options = maybe_unserialize($cache->options);
494
+                if ( isset( $cache->options ) ) {
495
+                    $cache->options = maybe_unserialize( $cache->options );
496 496
                 }
497 497
 
498
-                return stripslashes_deep($cache);
498
+                return stripslashes_deep( $cache );
499 499
             }
500 500
         }
501 501
 
502
-        if ( is_numeric($id) ) {
502
+        if ( is_numeric( $id ) ) {
503 503
             $where = array( 'id' => $id );
504 504
         } else {
505 505
             $where = array( 'form_key' => $id );
@@ -507,11 +507,11 @@  discard block
 block discarded – undo
507 507
 
508 508
         $results = FrmDb::get_row( $table_name, $where );
509 509
 
510
-        if ( isset($results->options) ) {
510
+        if ( isset( $results->options ) ) {
511 511
 			FrmDb::set_cache( $results->id, $results, 'frm_form' );
512
-            $results->options = maybe_unserialize($results->options);
512
+            $results->options = maybe_unserialize( $results->options );
513 513
         }
514
-        return stripslashes_deep($results);
514
+        return stripslashes_deep( $results );
515 515
     }
516 516
 
517 517
     /**
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 			$results = reset( $results );
541 541
 		}
542 542
 
543
-        return stripslashes_deep($results);
543
+        return stripslashes_deep( $results );
544 544
     }
545 545
 
546 546
 	/**
@@ -580,19 +580,19 @@  discard block
 block discarded – undo
580 580
     	foreach ( $results as $row ) {
581 581
             if ( 'trash' != $row->status ) {
582 582
     	        if ( $row->is_template ) {
583
-					$counts['template']++;
583
+					$counts['template'] ++;
584 584
     	        } else {
585
-					$counts['published']++;
585
+					$counts['published'] ++;
586 586
     	        }
587 587
     	    } else {
588
-				$counts['trash']++;
588
+				$counts['trash'] ++;
589 589
         	}
590 590
 
591 591
     	    if ( 'draft' == $row->status ) {
592
-				$counts['draft']++;
592
+				$counts['draft'] ++;
593 593
     	    }
594 594
 
595
-    		unset($row);
595
+    		unset( $row );
596 596
     	}
597 597
 
598 598
     	$counts = (object) $counts;
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
 	public static function validate( $values ) {
619 619
         $errors = array();
620 620
 
621
-        return apply_filters('frm_validate_form', $errors, $values);
621
+        return apply_filters( 'frm_validate_form', $errors, $values );
622 622
     }
623 623
 
624 624
 	public static function get_params( $form = null ) {
@@ -630,11 +630,11 @@  discard block
 block discarded – undo
630 630
 			self::maybe_get_form( $form );
631 631
 		}
632 632
 
633
-		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
634
-			return $frm_vars['form_params'][ $form->id ];
633
+		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) {
634
+			return $frm_vars['form_params'][$form->id];
635 635
 		}
636 636
 
637
-		$action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
637
+		$action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
638 638
 		$action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form );
639 639
 
640 640
 		$default_values = array(
@@ -652,15 +652,15 @@  discard block
 block discarded – undo
652 652
 			//if there are two forms on the same page, make sure not to submit both
653 653
 			foreach ( $default_values as $var => $default ) {
654 654
 				if ( $var == 'action' ) {
655
-					$values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
655
+					$values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
656 656
 				} else {
657
-					$values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
657
+					$values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
658 658
 				}
659 659
 				unset( $var, $default );
660 660
 			}
661 661
 		} else {
662 662
 			foreach ( $default_values as $var => $default ) {
663
-				$values[ $var ] = $default;
663
+				$values[$var] = $default;
664 664
 				unset( $var, $default );
665 665
 			}
666 666
 		}
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
 	public static function list_page_params() {
676 676
 		$values = array();
677 677
 		foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '' ) as $var => $default ) {
678
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
678
+			$values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
679 679
 		}
680 680
 
681 681
 		return $values;
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 			'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '',
696 696
 			'keep_post' => '',
697 697
 		) as $var => $default ) {
698
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
698
+			$values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
699 699
 		}
700 700
 
701 701
 		return $values;
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 		$small_form = new stdClass();
753 753
 		foreach ( array( 'id', 'form_key', 'name' ) as $var ) {
754 754
 			$small_form->{$var} = $form->{$var};
755
-			unset($var);
755
+			unset( $var );
756 756
 		}
757 757
 
758 758
 		$frm_vars['forms_loaded'][] = $small_form;
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 			$frm_vars['load_css'] = true;
763 763
 		}
764 764
 
765
-		return ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load );
765
+		return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load );
766 766
 	}
767 767
 
768 768
 	public static function show_submit( $form ) {
@@ -776,6 +776,6 @@  discard block
 block discarded – undo
776 776
 	 */
777 777
 	public static function get_option( $atts ) {
778 778
 		$form = $atts['form'];
779
-		return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $atts['default'];
779
+		return isset( $form->options[$atts['option']] ) ? $form->options[$atts['option']] : $atts['default'];
780 780
 	}
781 781
 }
Please login to merge, or discard this patch.
classes/models/FrmEntryMeta.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -5,25 +5,25 @@  discard block
 block discarded – undo
5 5
 
6 6
 class FrmEntryMeta {
7 7
 
8
-    /**
9
-     * @param string $meta_key
10
-     */
8
+	/**
9
+	 * @param string $meta_key
10
+	 */
11 11
 	public static function add_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
12
-        global $wpdb;
12
+		global $wpdb;
13 13
 
14
-        if ( FrmAppHelper::is_empty_value( $meta_value ) ) {
15
-            // don't save blank fields
16
-            return 0;
17
-        }
14
+		if ( FrmAppHelper::is_empty_value( $meta_value ) ) {
15
+			// don't save blank fields
16
+			return 0;
17
+		}
18 18
 
19
-        $new_values = array(
19
+		$new_values = array(
20 20
 			'meta_value'    => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ),
21
-            'item_id'       => $entry_id,
22
-            'field_id'      => $field_id,
23
-            'created_at'    => current_time('mysql', 1),
24
-        );
21
+			'item_id'       => $entry_id,
22
+			'field_id'      => $field_id,
23
+			'created_at'    => current_time('mysql', 1),
24
+		);
25 25
 
26
-        $new_values = apply_filters('frm_add_entry_meta', $new_values);
26
+		$new_values = apply_filters('frm_add_entry_meta', $new_values);
27 27
 
28 28
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_item_metas', $new_values );
29 29
 
@@ -35,40 +35,40 @@  discard block
 block discarded – undo
35 35
 			$id = 0;
36 36
 		}
37 37
 
38
-        return $id;
39
-    }
38
+		return $id;
39
+	}
40 40
 
41
-    /**
42
-     * @param string $meta_key
43
-     */
41
+	/**
42
+	 * @param string $meta_key
43
+	 */
44 44
 	public static function update_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
45
-        if ( ! $field_id ) {
46
-            return false;
47
-        }
45
+		if ( ! $field_id ) {
46
+			return false;
47
+		}
48 48
 
49
-        global $wpdb;
49
+		global $wpdb;
50 50
 
51 51
 		$values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
52 52
 		$where_values = $values;
53
-        $values['meta_value'] = $meta_value;
54
-        $values = apply_filters('frm_update_entry_meta', $values);
53
+		$values['meta_value'] = $meta_value;
54
+		$values = apply_filters('frm_update_entry_meta', $values);
55 55
 		if ( is_array($values['meta_value']) ) {
56 56
 			$values['meta_value'] = array_filter( $values['meta_value'], 'FrmAppHelper::is_not_empty_value' );
57 57
 		}
58
-        $meta_value = maybe_serialize($values['meta_value']);
58
+		$meta_value = maybe_serialize($values['meta_value']);
59 59
 
60
-        wp_cache_delete( $entry_id, 'frm_entry');
60
+		wp_cache_delete( $entry_id, 'frm_entry');
61 61
 		self::clear_cache();
62 62
 
63 63
 		return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
64
-    }
64
+	}
65 65
 
66 66
 	public static function update_entry_metas( $entry_id, $values ) {
67
-        global $wpdb;
67
+		global $wpdb;
68 68
 
69 69
 		$prev_values = FrmDb::get_col( $wpdb->prefix . 'frm_item_metas', array( 'item_id' => $entry_id, 'field_id !' => 0 ), 'field_id' );
70 70
 
71
-        foreach ( $values as $field_id => $meta_value ) {
71
+		foreach ( $values as $field_id => $meta_value ) {
72 72
 			$field = false;
73 73
 			if ( ! empty( $field_id ) ) {
74 74
 				$field = FrmField::getOne( $field_id );
@@ -92,39 +92,39 @@  discard block
 block discarded – undo
92 92
 			}
93 93
 		}
94 94
 
95
-        if ( empty($prev_values) ) {
96
-            return;
97
-        }
95
+		if ( empty($prev_values) ) {
96
+			return;
97
+		}
98 98
 
99
-        $prev_values = array_diff($prev_values, array_keys($values));
99
+		$prev_values = array_diff($prev_values, array_keys($values));
100 100
 
101
-        if ( empty($prev_values) ) {
102
-            return;
103
-        }
101
+		if ( empty($prev_values) ) {
102
+			return;
103
+		}
104 104
 
105 105
 		// prepare the query
106 106
 		$where = array( 'item_id' => $entry_id, 'field_id' => $prev_values );
107 107
 		FrmDb::get_where_clause_and_values( $where );
108 108
 
109
-        // Delete any leftovers
110
-        $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) );
109
+		// Delete any leftovers
110
+		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) );
111 111
 		self::clear_cache();
112
-    }
112
+	}
113 113
 
114 114
 	public static function duplicate_entry_metas( $old_id, $new_id ) {
115
-        $metas = self::get_entry_meta_info($old_id);
116
-        foreach ( $metas as $meta ) {
117
-            self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
118
-            unset($meta);
119
-        }
115
+		$metas = self::get_entry_meta_info($old_id);
116
+		foreach ( $metas as $meta ) {
117
+			self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
118
+			unset($meta);
119
+		}
120 120
 		self::clear_cache();
121
-    }
121
+	}
122 122
 
123 123
 	public static function delete_entry_meta( $entry_id, $field_id ) {
124
-        global $wpdb;
124
+		global $wpdb;
125 125
 		self::clear_cache();
126
-        return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
127
-    }
126
+		return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
127
+	}
128 128
 
129 129
 	/**
130 130
 	 * Clear entry meta caching
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	}
150 150
 
151 151
 	public static function get_entry_meta_by_field( $entry_id, $field_id ) {
152
-        global $wpdb;
152
+		global $wpdb;
153 153
 
154 154
 		if ( is_object( $entry_id ) ) {
155 155
 			$entry = $entry_id;
@@ -162,130 +162,130 @@  discard block
 block discarded – undo
162 162
 
163 163
 		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
164 164
 			$result = $cached->metas[ $field_id ];
165
-            return stripslashes_deep($result);
166
-        }
165
+			return stripslashes_deep($result);
166
+		}
167 167
 
168 168
 		$get_table = $wpdb->prefix . 'frm_item_metas';
169 169
 		$query = array( 'item_id' => $entry_id );
170
-        if ( is_numeric($field_id) ) {
170
+		if ( is_numeric($field_id) ) {
171 171
 			$query['field_id'] = $field_id;
172
-        } else {
172
+		} else {
173 173
 			$get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
174 174
 			$query['fi.field_key'] = $field_id;
175
-        }
175
+		}
176 176
 
177 177
 		$result = FrmDb::get_var( $get_table, $query, 'meta_value' );
178
-        $result = maybe_unserialize($result);
179
-        $result = stripslashes_deep($result);
178
+		$result = maybe_unserialize($result);
179
+		$result = stripslashes_deep($result);
180 180
 
181
-        return $result;
182
-    }
181
+		return $result;
182
+	}
183 183
 
184
-    public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
184
+	public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
185 185
 		$defaults = array( 'value' => false, 'unique' => false, 'stripslashes' => true, 'is_draft' => false );
186
-        $args = wp_parse_args( $args, $defaults );
186
+		$args = wp_parse_args( $args, $defaults );
187 187
 
188
-        $query = array();
189
-        self::meta_field_query($field_id, $order, $limit, $args, $query);
190
-        $query = implode(' ', $query);
188
+		$query = array();
189
+		self::meta_field_query($field_id, $order, $limit, $args, $query);
190
+		$query = implode(' ', $query);
191 191
 
192 192
 		$cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args );
193
-        $values = FrmDb::check_cache($cache_key, 'frm_entry', $query, 'get_col');
193
+		$values = FrmDb::check_cache($cache_key, 'frm_entry', $query, 'get_col');
194 194
 
195
-        if ( ! $args['stripslashes'] ) {
196
-            return $values;
197
-        }
195
+		if ( ! $args['stripslashes'] ) {
196
+			return $values;
197
+		}
198 198
 
199 199
 		foreach ( $values as $k => $v ) {
200 200
 			$values[ $k ] = maybe_unserialize( $v );
201
-            unset($k, $v);
202
-        }
201
+			unset($k, $v);
202
+		}
203 203
 
204
-        return stripslashes_deep($values);
205
-    }
204
+		return stripslashes_deep($values);
205
+	}
206 206
 
207
-    /**
208
-     * @param string $order
209
-     * @param string $limit
210
-     */
207
+	/**
208
+	 * @param string $order
209
+	 * @param string $limit
210
+	 */
211 211
 	private static function meta_field_query( $field_id, $order, $limit, $args, array &$query ) {
212
-        global $wpdb;
213
-        $query[] = 'SELECT';
214
-        $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
212
+		global $wpdb;
213
+		$query[] = 'SELECT';
214
+		$query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
215 215
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas em ';
216 216
 
217
-        if ( ! $args['is_draft'] ) {
217
+		if ( ! $args['is_draft'] ) {
218 218
 			$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)';
219
-        }
219
+		}
220 220
 
221
-        if ( is_numeric($field_id) ) {
222
-            $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
223
-        } else {
221
+		if ( is_numeric($field_id) ) {
222
+			$query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
223
+		} else {
224 224
 			$query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id );
225
-        }
225
+		}
226 226
 
227
-        if ( ! $args['is_draft'] ) {
228
-            $query[] = 'AND e.is_draft=0';
229
-        }
227
+		if ( ! $args['is_draft'] ) {
228
+			$query[] = 'AND e.is_draft=0';
229
+		}
230 230
 
231
-        if ( $args['value'] ) {
232
-            $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
233
-        }
234
-        $query[] = $order . $limit;
235
-    }
231
+		if ( $args['value'] ) {
232
+			$query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
233
+		}
234
+		$query[] = $order . $limit;
235
+	}
236 236
 
237 237
 	public static function get_entry_meta_info( $entry_id ) {
238 238
 		return FrmDb::get_results( 'frm_item_metas', array( 'item_id' => $entry_id ) );
239
-    }
239
+	}
240 240
 
241 241
 	public static function getAll( $where = array(), $order_by = '', $limit = '', $stripslashes = false ) {
242
-        global $wpdb;
243
-        $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
242
+		global $wpdb;
243
+		$query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
244 244
             fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
245 245
 			FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' .
246
-            FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
246
+			FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
247 247
 
248 248
 		$cache_key = 'all_' . maybe_serialize( $where ) . $order_by . $limit;
249
-        $results = FrmDb::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
249
+		$results = FrmDb::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
250 250
 
251
-        if ( ! $results || ! $stripslashes ) {
252
-            return $results;
253
-        }
251
+		if ( ! $results || ! $stripslashes ) {
252
+			return $results;
253
+		}
254 254
 
255
-        foreach ( $results as $k => $result ) {
255
+		foreach ( $results as $k => $result ) {
256 256
 			$results[ $k ]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) );
257
-            unset($k, $result);
258
-        }
257
+			unset($k, $result);
258
+		}
259 259
 
260
-        return $results;
261
-    }
260
+		return $results;
261
+	}
262 262
 
263
-    public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
263
+	public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
264 264
 		$defaults = array(
265 265
 			'is_draft' => false,
266 266
 			'user_id'  => '',
267 267
 			'group_by' => '',
268 268
 		);
269
-        $args = wp_parse_args($args, $defaults);
269
+		$args = wp_parse_args($args, $defaults);
270 270
 
271
-        $query = array();
272
-        self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
273
-        $query = implode(' ', $query);
271
+		$query = array();
272
+		self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
273
+		$query = implode(' ', $query);
274 274
 
275 275
 		$cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args );
276
-        $results = FrmDb::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
276
+		$results = FrmDb::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
277 277
 
278
-        return $results;
279
-    }
278
+		return $results;
279
+	}
280 280
 
281
-    /**
282
-     * @param string|array $where
283
-     * @param string $order_by
284
-     * @param string $limit
285
-     */
281
+	/**
282
+	 * @param string|array $where
283
+	 * @param string $order_by
284
+	 * @param string $limit
285
+	 */
286 286
 	private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) {
287
-        global $wpdb;
288
-        $query[] = 'SELECT';
287
+		global $wpdb;
288
+		$query[] = 'SELECT';
289 289
 
290 290
 		$defaults = array( 'return_parent_id' => false );
291 291
 		$args = array_merge( $defaults, $args );
@@ -299,89 +299,89 @@  discard block
 block discarded – undo
299 299
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
300 300
 
301 301
 		$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)';
302
-        if ( is_array($where) ) {
303
-            if ( ! $args['is_draft'] ) {
304
-                $where['e.is_draft'] = 0;
305
-            } else if ( $args['is_draft'] == 1 ) {
306
-                $where['e.is_draft'] = 1;
307
-            }
308
-
309
-            if ( ! empty($args['user_id']) ) {
310
-                $where['e.user_id'] = $args['user_id'];
311
-            }
312
-            $query[] = FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
302
+		if ( is_array($where) ) {
303
+			if ( ! $args['is_draft'] ) {
304
+				$where['e.is_draft'] = 0;
305
+			} else if ( $args['is_draft'] == 1 ) {
306
+				$where['e.is_draft'] = 1;
307
+			}
308
+
309
+			if ( ! empty($args['user_id']) ) {
310
+				$where['e.user_id'] = $args['user_id'];
311
+			}
312
+			$query[] = FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
313 313
 
314 314
 			if ( $args['group_by'] ) {
315 315
 				$query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] );
316 316
 			}
317
-            return;
318
-        }
317
+			return;
318
+		}
319 319
 
320 320
 		$draft_where = '';
321 321
 		$user_where = '';
322
-        if ( ! $args['is_draft'] ) {
322
+		if ( ! $args['is_draft'] ) {
323 323
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 0 );
324
-        } else if ( $args['is_draft'] == 1 ) {
324
+		} else if ( $args['is_draft'] == 1 ) {
325 325
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
326
-        }
326
+		}
327 327
 
328
-        if ( ! empty($args['user_id']) ) {
329
-            $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
330
-        }
328
+		if ( ! empty($args['user_id']) ) {
329
+			$user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
330
+		}
331 331
 
332
-        if ( strpos($where, ' GROUP BY ') ) {
333
-            // don't inject WHERE filtering after GROUP BY
334
-            $parts = explode(' GROUP BY ', $where);
335
-            $where = $parts[0];
336
-            $where .= $draft_where . $user_where;
332
+		if ( strpos($where, ' GROUP BY ') ) {
333
+			// don't inject WHERE filtering after GROUP BY
334
+			$parts = explode(' GROUP BY ', $where);
335
+			$where = $parts[0];
336
+			$where .= $draft_where . $user_where;
337 337
 			$where .= ' GROUP BY ' . $parts[1];
338
-        } else {
339
-            $where .= $draft_where . $user_where;
340
-        }
338
+		} else {
339
+			$where .= $draft_where . $user_where;
340
+		}
341 341
 
342 342
 		// The query has already been prepared
343 343
 		$query[] = FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
344
-    }
344
+	}
345 345
 
346
-    public static function search_entry_metas( $search, $field_id = '', $operator ) {
346
+	public static function search_entry_metas( $search, $field_id = '', $operator ) {
347 347
 		$cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator;
348
-        $results = wp_cache_get($cache_key, 'frm_entry');
349
-        if ( false !== $results ) {
350
-            return $results;
351
-        }
348
+		$results = wp_cache_get($cache_key, 'frm_entry');
349
+		if ( false !== $results ) {
350
+			return $results;
351
+		}
352 352
 
353
-        global $wpdb;
353
+		global $wpdb;
354 354
 		if ( is_array( $search ) ) {
355
-            $where = '';
355
+			$where = '';
356 356
 			foreach ( $search as $field => $value ) {
357 357
 				if ( $value <= 0 || ! in_array( $field, array( 'year', 'month', 'day' ) ) ) {
358
-                    continue;
359
-                }
358
+					continue;
359
+				}
360 360
 
361
-                switch ( $field ) {
362
-                    case 'year':
361
+				switch ( $field ) {
362
+					case 'year':
363 363
 						$value = '%' . $value;
364
-                    break;
365
-                    case 'month':
366
-                        $value .= '%';
367
-                    break;
368
-                    case 'day':
364
+					break;
365
+					case 'month':
366
+						$value .= '%';
367
+					break;
368
+					case 'day':
369 369
 						$value = '%' . $value . '%';
370
-                }
370
+				}
371 371
 				$where .= $wpdb->prepare(' meta_value ' . $operator . ' %s and', $value );
372
-            }
373
-            $where .= $wpdb->prepare(' field_id=%d', $field_id);
372
+			}
373
+			$where .= $wpdb->prepare(' field_id=%d', $field_id);
374 374
 			$query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmDb::prepend_and_or_where( ' WHERE ', $where );
375
-        } else {
375
+		} else {
376 376
 			if ( $operator == 'LIKE' ) {
377
-                $search = '%' . $search . '%';
377
+				$search = '%' . $search . '%';
378 378
 			}
379
-            $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
380
-        }
379
+			$query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
380
+		}
381 381
 
382
-        $results = $wpdb->get_col($query, 0);
382
+		$results = $wpdb->get_col($query, 0);
383 383
 		FrmDb::set_cache( $cache_key, $results, 'frm_entry' );
384 384
 
385
-        return $results;
386
-    }
385
+		return $results;
386
+	}
387 387
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -20,10 +20,10 @@  discard block
 block discarded – undo
20 20
 			'meta_value'    => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ),
21 21
             'item_id'       => $entry_id,
22 22
             'field_id'      => $field_id,
23
-            'created_at'    => current_time('mysql', 1),
23
+            'created_at'    => current_time( 'mysql', 1 ),
24 24
         );
25 25
 
26
-        $new_values = apply_filters('frm_add_entry_meta', $new_values);
26
+        $new_values = apply_filters( 'frm_add_entry_meta', $new_values );
27 27
 
28 28
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_item_metas', $new_values );
29 29
 
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 		$values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
52 52
 		$where_values = $values;
53 53
         $values['meta_value'] = $meta_value;
54
-        $values = apply_filters('frm_update_entry_meta', $values);
55
-		if ( is_array($values['meta_value']) ) {
54
+        $values = apply_filters( 'frm_update_entry_meta', $values );
55
+		if ( is_array( $values['meta_value'] ) ) {
56 56
 			$values['meta_value'] = array_filter( $values['meta_value'], 'FrmAppHelper::is_not_empty_value' );
57 57
 		}
58
-        $meta_value = maybe_serialize($values['meta_value']);
58
+        $meta_value = maybe_serialize( $values['meta_value'] );
59 59
 
60
-        wp_cache_delete( $entry_id, 'frm_entry');
60
+        wp_cache_delete( $entry_id, 'frm_entry' );
61 61
 		self::clear_cache();
62 62
 
63 63
 		return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
 			// set the value for the file upload field and add new tags (in Pro version)
78 78
 			$meta_value = apply_filters( 'frm_prepare_data_before_db', $meta_value, $field_id, $entry_id, compact( 'field' ) );
79 79
 
80
-			if ( $prev_values && in_array($field_id, $prev_values) ) {
80
+			if ( $prev_values && in_array( $field_id, $prev_values ) ) {
81 81
 
82 82
 				if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) {
83 83
 					// remove blank fields
84
-					unset( $values[ $field_id ] );
84
+					unset( $values[$field_id] );
85 85
 				} else {
86 86
 					// if value exists, then update it
87 87
 					self::update_entry_meta( $entry_id, $field_id, '', $meta_value );
@@ -92,13 +92,13 @@  discard block
 block discarded – undo
92 92
 			}
93 93
 		}
94 94
 
95
-        if ( empty($prev_values) ) {
95
+        if ( empty( $prev_values ) ) {
96 96
             return;
97 97
         }
98 98
 
99
-        $prev_values = array_diff($prev_values, array_keys($values));
99
+        $prev_values = array_diff( $prev_values, array_keys( $values ) );
100 100
 
101
-        if ( empty($prev_values) ) {
101
+        if ( empty( $prev_values ) ) {
102 102
             return;
103 103
         }
104 104
 
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
     }
113 113
 
114 114
 	public static function duplicate_entry_metas( $old_id, $new_id ) {
115
-        $metas = self::get_entry_meta_info($old_id);
115
+        $metas = self::get_entry_meta_info( $old_id );
116 116
         foreach ( $metas as $meta ) {
117
-            self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
118
-            unset($meta);
117
+            self::add_entry_meta( $new_id, $meta->field_id, null, $meta->meta_value );
118
+            unset( $meta );
119 119
         }
120 120
 		self::clear_cache();
121 121
     }
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	public static function delete_entry_meta( $entry_id, $field_id ) {
124 124
         global $wpdb;
125 125
 		self::clear_cache();
126
-        return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
126
+        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id ) );
127 127
     }
128 128
 
129 129
 	/**
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	public static function get_meta_value( $entry, $field_id ) {
144 144
 		if ( isset( $entry->metas ) ) {
145
-			return isset( $entry->metas[ $field_id ] ) ? $entry->metas[ $field_id ] : false;
145
+			return isset( $entry->metas[$field_id] ) ? $entry->metas[$field_id] : false;
146 146
 		} else {
147 147
 			return self::get_entry_meta_by_field( $entry->id, $field_id );
148 148
 		}
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
 			$cached = FrmDb::check_cache( $entry_id, 'frm_entry' );
161 161
 		}
162 162
 
163
-		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
164
-			$result = $cached->metas[ $field_id ];
165
-            return stripslashes_deep($result);
163
+		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[$field_id] ) ) {
164
+			$result = $cached->metas[$field_id];
165
+            return stripslashes_deep( $result );
166 166
         }
167 167
 
168 168
 		$get_table = $wpdb->prefix . 'frm_item_metas';
169 169
 		$query = array( 'item_id' => $entry_id );
170
-        if ( is_numeric($field_id) ) {
170
+        if ( is_numeric( $field_id ) ) {
171 171
 			$query['field_id'] = $field_id;
172 172
         } else {
173 173
 			$get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
         }
176 176
 
177 177
 		$result = FrmDb::get_var( $get_table, $query, 'meta_value' );
178
-        $result = maybe_unserialize($result);
179
-        $result = stripslashes_deep($result);
178
+        $result = maybe_unserialize( $result );
179
+        $result = stripslashes_deep( $result );
180 180
 
181 181
         return $result;
182 182
     }
@@ -186,22 +186,22 @@  discard block
 block discarded – undo
186 186
         $args = wp_parse_args( $args, $defaults );
187 187
 
188 188
         $query = array();
189
-        self::meta_field_query($field_id, $order, $limit, $args, $query);
190
-        $query = implode(' ', $query);
189
+        self::meta_field_query( $field_id, $order, $limit, $args, $query );
190
+        $query = implode( ' ', $query );
191 191
 
192 192
 		$cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args );
193
-        $values = FrmDb::check_cache($cache_key, 'frm_entry', $query, 'get_col');
193
+        $values = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_col' );
194 194
 
195 195
         if ( ! $args['stripslashes'] ) {
196 196
             return $values;
197 197
         }
198 198
 
199 199
 		foreach ( $values as $k => $v ) {
200
-			$values[ $k ] = maybe_unserialize( $v );
201
-            unset($k, $v);
200
+			$values[$k] = maybe_unserialize( $v );
201
+            unset( $k, $v );
202 202
         }
203 203
 
204
-        return stripslashes_deep($values);
204
+        return stripslashes_deep( $values );
205 205
     }
206 206
 
207 207
     /**
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
 			$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)';
219 219
         }
220 220
 
221
-        if ( is_numeric($field_id) ) {
222
-            $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
221
+        if ( is_numeric( $field_id ) ) {
222
+            $query[] = $wpdb->prepare( 'WHERE em.field_id=%d', $field_id );
223 223
         } else {
224 224
 			$query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id );
225 225
         }
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
         }
230 230
 
231 231
         if ( $args['value'] ) {
232
-            $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
232
+            $query[] = $wpdb->prepare( ' AND meta_value=%s', $args['value'] );
233 233
         }
234 234
         $query[] = $order . $limit;
235 235
     }
@@ -243,18 +243,18 @@  discard block
 block discarded – undo
243 243
         $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
244 244
             fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
245 245
 			FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' .
246
-            FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
246
+            FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
247 247
 
248 248
 		$cache_key = 'all_' . maybe_serialize( $where ) . $order_by . $limit;
249
-        $results = FrmDb::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
249
+        $results = FrmDb::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_row' : 'get_results' ) );
250 250
 
251 251
         if ( ! $results || ! $stripslashes ) {
252 252
             return $results;
253 253
         }
254 254
 
255 255
         foreach ( $results as $k => $result ) {
256
-			$results[ $k ]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) );
257
-            unset($k, $result);
256
+			$results[$k]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) );
257
+            unset( $k, $result );
258 258
         }
259 259
 
260 260
         return $results;
@@ -266,14 +266,14 @@  discard block
 block discarded – undo
266 266
 			'user_id'  => '',
267 267
 			'group_by' => '',
268 268
 		);
269
-        $args = wp_parse_args($args, $defaults);
269
+        $args = wp_parse_args( $args, $defaults );
270 270
 
271 271
         $query = array();
272
-        self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
273
-        $query = implode(' ', $query);
272
+        self::get_ids_query( $where, $order_by, $limit, $unique, $args, $query );
273
+        $query = implode( ' ', $query );
274 274
 
275 275
 		$cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args );
276
-        $results = FrmDb::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
276
+        $results = FrmDb::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_var' : 'get_col' ) );
277 277
 
278 278
         return $results;
279 279
     }
@@ -299,17 +299,17 @@  discard block
 block discarded – undo
299 299
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
300 300
 
301 301
 		$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)';
302
-        if ( is_array($where) ) {
302
+        if ( is_array( $where ) ) {
303 303
             if ( ! $args['is_draft'] ) {
304 304
                 $where['e.is_draft'] = 0;
305 305
             } else if ( $args['is_draft'] == 1 ) {
306 306
                 $where['e.is_draft'] = 1;
307 307
             }
308 308
 
309
-            if ( ! empty($args['user_id']) ) {
309
+            if ( ! empty( $args['user_id'] ) ) {
310 310
                 $where['e.user_id'] = $args['user_id'];
311 311
             }
312
-            $query[] = FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
312
+            $query[] = FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
313 313
 
314 314
 			if ( $args['group_by'] ) {
315 315
 				$query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] );
@@ -325,13 +325,13 @@  discard block
 block discarded – undo
325 325
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
326 326
         }
327 327
 
328
-        if ( ! empty($args['user_id']) ) {
329
-            $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
328
+        if ( ! empty( $args['user_id'] ) ) {
329
+            $user_where = $wpdb->prepare( ' AND e.user_id=%d', $args['user_id'] );
330 330
         }
331 331
 
332
-        if ( strpos($where, ' GROUP BY ') ) {
332
+        if ( strpos( $where, ' GROUP BY ' ) ) {
333 333
             // don't inject WHERE filtering after GROUP BY
334
-            $parts = explode(' GROUP BY ', $where);
334
+            $parts = explode( ' GROUP BY ', $where );
335 335
             $where = $parts[0];
336 336
             $where .= $draft_where . $user_where;
337 337
 			$where .= ' GROUP BY ' . $parts[1];
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
         }
341 341
 
342 342
 		// The query has already been prepared
343
-		$query[] = FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
343
+		$query[] = FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
344 344
     }
345 345
 
346 346
     public static function search_entry_metas( $search, $field_id = '', $operator ) {
347 347
 		$cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator;
348
-        $results = wp_cache_get($cache_key, 'frm_entry');
348
+        $results = wp_cache_get( $cache_key, 'frm_entry' );
349 349
         if ( false !== $results ) {
350 350
             return $results;
351 351
         }
@@ -368,18 +368,18 @@  discard block
 block discarded – undo
368 368
                     case 'day':
369 369
 						$value = '%' . $value . '%';
370 370
                 }
371
-				$where .= $wpdb->prepare(' meta_value ' . $operator . ' %s and', $value );
371
+				$where .= $wpdb->prepare( ' meta_value ' . $operator . ' %s and', $value );
372 372
             }
373
-            $where .= $wpdb->prepare(' field_id=%d', $field_id);
373
+            $where .= $wpdb->prepare( ' field_id=%d', $field_id );
374 374
 			$query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmDb::prepend_and_or_where( ' WHERE ', $where );
375 375
         } else {
376 376
 			if ( $operator == 'LIKE' ) {
377 377
                 $search = '%' . $search . '%';
378 378
 			}
379
-            $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
379
+            $query = $wpdb->prepare( "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id );
380 380
         }
381 381
 
382
-        $results = $wpdb->get_col($query, 0);
382
+        $results = $wpdb->get_col( $query, 0 );
383 383
 		FrmDb::set_cache( $cache_key, $results, 'frm_entry' );
384 384
 
385 385
         return $results;
Please login to merge, or discard this patch.
classes/models/FrmMigrate.php 2 patches
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
 		return $charset_collate;
77 77
 	}
78 78
 
79
-    private function create_tables() {
80
-        $charset_collate = $this->collation();
81
-        $sql = array();
79
+	private function create_tables() {
80
+		$charset_collate = $this->collation();
81
+		$sql = array();
82 82
 
83
-        /* Create/Upgrade Fields Table */
83
+		/* Create/Upgrade Fields Table */
84 84
 		$sql[] = 'CREATE TABLE ' . $this->fields . ' (
85 85
 				id BIGINT(20) NOT NULL auto_increment,
86 86
 				field_key varchar(100) default NULL,
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
                 UNIQUE KEY field_key (field_key)
100 100
         )';
101 101
 
102
-        /* Create/Upgrade Forms Table */
102
+		/* Create/Upgrade Forms Table */
103 103
 		$sql[] = 'CREATE TABLE ' . $this->forms . ' (
104 104
                 id int(11) NOT NULL auto_increment,
105 105
 				form_key varchar(100) default NULL,
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                 UNIQUE KEY form_key (form_key)
118 118
         )';
119 119
 
120
-        /* Create/Upgrade Items Table */
120
+		/* Create/Upgrade Items Table */
121 121
 		$sql[] = 'CREATE TABLE ' . $this->entries . ' (
122 122
 				id BIGINT(20) NOT NULL auto_increment,
123 123
 				item_key varchar(100) default NULL,
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
                 UNIQUE KEY item_key (item_key)
141 141
         )';
142 142
 
143
-        /* Create/Upgrade Meta Table */
143
+		/* Create/Upgrade Meta Table */
144 144
 		$sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
145 145
 				id BIGINT(20) NOT NULL auto_increment,
146 146
 				meta_value longtext default NULL,
@@ -152,16 +152,16 @@  discard block
 block discarded – undo
152 152
                 KEY item_id (item_id)
153 153
         )';
154 154
 
155
-        foreach ( $sql as $q ) {
155
+		foreach ( $sql as $q ) {
156 156
 			if ( function_exists( 'dbDelta' ) ) {
157 157
 				dbDelta( $q . $charset_collate . ';' );
158 158
 			} else {
159 159
 				global $wpdb;
160 160
 				$wpdb->query( $q . $charset_collate );
161 161
 			}
162
-            unset($q);
163
-        }
164
-    }
162
+			unset($q);
163
+		}
164
+	}
165 165
 
166 166
 	private function maybe_create_contact_form() {
167 167
 		$template_id = FrmForm::getIdByKey( 'contact' );
@@ -177,45 +177,45 @@  discard block
 block discarded – undo
177 177
 		}
178 178
 	}
179 179
 
180
-    /**
181
-     * @param integer $frm_db_version
180
+	/**
181
+	 * @param integer $frm_db_version
182 182
 	 * @param int $old_db_version
183
-     */
183
+	 */
184 184
 	private function migrate_data( $frm_db_version, $old_db_version ) {
185 185
 		$migrations = array( 4, 6, 11, 16, 17, 23, 25 );
186
-        foreach ( $migrations as $migration ) {
187
-            if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
186
+		foreach ( $migrations as $migration ) {
187
+			if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
188 188
 				$function_name = 'migrate_to_' . $migration;
189
-                $this->$function_name();
190
-            }
191
-        }
192
-    }
189
+				$this->$function_name();
190
+			}
191
+		}
192
+	}
193 193
 
194
-    public function uninstall() {
194
+	public function uninstall() {
195 195
 		if ( ! current_user_can( 'administrator' ) ) {
196
-            $frm_settings = FrmAppHelper::get_settings();
197
-            wp_die($frm_settings->admin_permission);
198
-        }
196
+			$frm_settings = FrmAppHelper::get_settings();
197
+			wp_die($frm_settings->admin_permission);
198
+		}
199 199
 
200
-        global $wpdb, $wp_roles;
200
+		global $wpdb, $wp_roles;
201 201
 
202 202
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields );
203 203
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms );
204 204
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries );
205 205
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas );
206 206
 
207
-        delete_option('frm_options');
208
-        delete_option('frm_db_version');
209
-
210
-        //delete roles
211
-        $frm_roles = FrmAppHelper::frm_capabilities();
212
-        $roles = get_editable_roles();
213
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
214
-            foreach ( $roles as $role => $details ) {
215
-                $wp_roles->remove_cap( $role, $frm_role );
216
-                unset($role, $details);
217
-    		}
218
-    		unset($frm_role, $frm_role_description);
207
+		delete_option('frm_options');
208
+		delete_option('frm_db_version');
209
+
210
+		//delete roles
211
+		$frm_roles = FrmAppHelper::frm_capabilities();
212
+		$roles = get_editable_roles();
213
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
214
+			foreach ( $roles as $role => $details ) {
215
+				$wp_roles->remove_cap( $role, $frm_role );
216
+				unset($role, $details);
217
+			}
218
+			unset($frm_role, $frm_role_description);
219 219
 		}
220 220
 		unset($roles, $frm_roles);
221 221
 
@@ -239,9 +239,9 @@  discard block
 block discarded – undo
239 239
 
240 240
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) );
241 241
 
242
-        do_action('frm_after_uninstall');
243
-        return true;
244
-    }
242
+		do_action('frm_after_uninstall');
243
+		return true;
244
+	}
245 245
 
246 246
 	/**
247 247
 	 * Migrate old styling settings. If sites are using the old
@@ -280,150 +280,150 @@  discard block
 block discarded – undo
280 280
 		}
281 281
 	}
282 282
 
283
-    /**
284
-     * Change field size from character to pixel -- Multiply by 9
285
-     */
286
-    private function migrate_to_17() {
287
-        global $wpdb;
283
+	/**
284
+	 * Change field size from character to pixel -- Multiply by 9
285
+	 */
286
+	private function migrate_to_17() {
287
+		global $wpdb;
288 288
 		$pixel_conversion = 9;
289 289
 
290
-        // Get query arguments
290
+		// Get query arguments
291 291
 		$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
292 292
 		$query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' );
293 293
 
294
-        // Get results
294
+		// Get results
295 295
 		$fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
296 296
 
297
-        $updated = 0;
298
-        foreach ( $fields as $f ) {
299
-            $f->field_options = maybe_unserialize($f->field_options);
300
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
301
-                continue;
302
-            }
297
+		$updated = 0;
298
+		foreach ( $fields as $f ) {
299
+			$f->field_options = maybe_unserialize($f->field_options);
300
+			if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
301
+				continue;
302
+			}
303 303
 
304 304
 			$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] );
305
-            $f->field_options['size'] .= 'px';
306
-            $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
307
-            if ( $u ) {
308
-                $updated++;
309
-            }
310
-            unset($f);
311
-        }
312
-
313
-        // Change the characters in widgets to pixels
314
-        $widgets = get_option('widget_frm_show_form');
315
-        if ( empty($widgets) ) {
316
-            return;
317
-        }
318
-
319
-        $widgets = maybe_unserialize($widgets);
320
-        foreach ( $widgets as $k => $widget ) {
321
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
322
-                continue;
323
-            }
305
+			$f->field_options['size'] .= 'px';
306
+			$u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
307
+			if ( $u ) {
308
+				$updated++;
309
+			}
310
+			unset($f);
311
+		}
312
+
313
+		// Change the characters in widgets to pixels
314
+		$widgets = get_option('widget_frm_show_form');
315
+		if ( empty($widgets) ) {
316
+			return;
317
+		}
318
+
319
+		$widgets = maybe_unserialize($widgets);
320
+		foreach ( $widgets as $k => $widget ) {
321
+			if ( ! is_array($widget) || ! isset($widget['size']) ) {
322
+				continue;
323
+			}
324 324
 			$size = round( $pixel_conversion * (int) $widget['size'] );
325
-            $size .= 'px';
325
+			$size .= 'px';
326 326
 			$widgets[ $k ]['size'] = $size;
327
-        }
328
-        update_option('widget_frm_show_form', $widgets);
329
-    }
330
-
331
-    /**
332
-     * Migrate post and email notification settings into actions
333
-     */
334
-    private function migrate_to_16() {
335
-        global $wpdb;
336
-
337
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
338
-
339
-        /**
340
-        * Old email settings format:
341
-        * email_to: Email or field id
342
-        * also_email_to: array of fields ids
343
-        * reply_to: Email, field id, 'custom'
344
-        * cust_reply_to: string
345
-        * reply_to_name: field id, 'custom'
346
-        * cust_reply_to_name: string
347
-        * plain_text: 0|1
348
-        * email_message: string or ''
349
-        * email_subject: string or ''
350
-        * inc_user_info: 0|1
351
-        * update_email: 0, 1, 2
352
-        *
353
-        * Old autoresponder settings format:
354
-        * auto_responder: 0|1
355
-        * ar_email_message: string or ''
356
-        * ar_email_to: field id
357
-        * ar_plain_text: 0|1
358
-        * ar_reply_to_name: string
359
-        * ar_reply_to: string
360
-        * ar_email_subject: string
361
-        * ar_update_email: 0, 1, 2
362
-        *
363
-        * New email settings:
364
-        * post_content: json settings
365
-        * post_title: form id
366
-        * post_excerpt: message
367
-        *
368
-        */
369
-
370
-        foreach ( $forms as $form ) {
327
+		}
328
+		update_option('widget_frm_show_form', $widgets);
329
+	}
330
+
331
+	/**
332
+	 * Migrate post and email notification settings into actions
333
+	 */
334
+	private function migrate_to_16() {
335
+		global $wpdb;
336
+
337
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
338
+
339
+		/**
340
+		 * Old email settings format:
341
+		 * email_to: Email or field id
342
+		 * also_email_to: array of fields ids
343
+		 * reply_to: Email, field id, 'custom'
344
+		 * cust_reply_to: string
345
+		 * reply_to_name: field id, 'custom'
346
+		 * cust_reply_to_name: string
347
+		 * plain_text: 0|1
348
+		 * email_message: string or ''
349
+		 * email_subject: string or ''
350
+		 * inc_user_info: 0|1
351
+		 * update_email: 0, 1, 2
352
+		 *
353
+		 * Old autoresponder settings format:
354
+		 * auto_responder: 0|1
355
+		 * ar_email_message: string or ''
356
+		 * ar_email_to: field id
357
+		 * ar_plain_text: 0|1
358
+		 * ar_reply_to_name: string
359
+		 * ar_reply_to: string
360
+		 * ar_email_subject: string
361
+		 * ar_update_email: 0, 1, 2
362
+		 *
363
+		 * New email settings:
364
+		 * post_content: json settings
365
+		 * post_title: form id
366
+		 * post_excerpt: message
367
+		 *
368
+		 */
369
+
370
+		foreach ( $forms as $form ) {
371 371
 			if ( $form->is_template && $form->default_template ) {
372 372
 				// don't migrate the default templates since the email will be added anyway
373 373
 				continue;
374 374
 			}
375 375
 
376
-            // Format form options
377
-            $form_options = maybe_unserialize($form->options);
376
+			// Format form options
377
+			$form_options = maybe_unserialize($form->options);
378 378
 
379
-            // Migrate settings to actions
380
-            FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
381
-        }
382
-    }
379
+			// Migrate settings to actions
380
+			FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
381
+		}
382
+	}
383 383
 
384
-    private function migrate_to_11() {
385
-        global $wpdb;
384
+	private function migrate_to_11() {
385
+		global $wpdb;
386 386
 
387
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
387
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options');
388 388
 
389
-        $sending = __( 'Sending', 'formidable' );
389
+		$sending = __( 'Sending', 'formidable' );
390 390
 		$img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
391
-        $old_default_html = <<<DEFAULT_HTML
391
+		$old_default_html = <<<DEFAULT_HTML
392 392
 <div class="frm_submit">
393 393
 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
394 394
 <input type="submit" value="[button_label]" [button_action] />
395 395
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
396 396
 </div>
397 397
 DEFAULT_HTML;
398
-        unset($sending, $img);
398
+		unset($sending, $img);
399 399
 
400
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
401
-        $draft_link = FrmFormsHelper::get_draft_link();
400
+		$new_default_html = FrmFormsHelper::get_default_html('submit');
401
+		$draft_link = FrmFormsHelper::get_draft_link();
402 402
 		foreach ( $forms as $form ) {
403
-            $form->options = maybe_unserialize($form->options);
404
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
405
-                continue;
406
-            }
403
+			$form->options = maybe_unserialize($form->options);
404
+			if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
405
+				continue;
406
+			}
407 407
 
408
-            if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
409
-                $form->options['submit_html'] = $new_default_html;
408
+			if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
409
+				$form->options['submit_html'] = $new_default_html;
410 410
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
411 411
 			} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
412 412
 				$form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
413 413
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
414
-            }
415
-            unset($form);
416
-        }
417
-        unset($forms);
418
-    }
414
+			}
415
+			unset($form);
416
+		}
417
+		unset($forms);
418
+	}
419 419
 
420
-    private function migrate_to_6() {
421
-        global $wpdb;
420
+	private function migrate_to_6() {
421
+		global $wpdb;
422 422
 
423 423
 		$no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
424 424
 		$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' );
425 425
 
426
-        $default_html = <<<DEFAULT_HTML
426
+		$default_html = <<<DEFAULT_HTML
427 427
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
428 428
     <label class="frm_pos_[label_position]">[field_name]
429 429
         <span class="frm_required">[required_label]</span>
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 </div>
434 434
 DEFAULT_HTML;
435 435
 
436
-        $old_default_html = <<<DEFAULT_HTML
436
+		$old_default_html = <<<DEFAULT_HTML
437 437
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
438 438
     <label class="frm_pos_[label_position]">[field_name]
439 439
         <span class="frm_required">[required_label]</span>
@@ -443,24 +443,24 @@  discard block
 block discarded – undo
443 443
 </div>
444 444
 DEFAULT_HTML;
445 445
 
446
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
447
-        foreach ( $fields as $field ) {
448
-            $field->field_options = maybe_unserialize($field->field_options);
446
+		$new_default_html = FrmFieldsHelper::get_default_html('text');
447
+		foreach ( $fields as $field ) {
448
+			$field->field_options = maybe_unserialize($field->field_options);
449 449
 			$html = FrmField::get_option( $field, 'custom_html' );
450 450
 			if ( $html == $default_html || $html == $old_default_html ) {
451
-                $field->field_options['custom_html'] = $new_default_html;
451
+				$field->field_options['custom_html'] = $new_default_html;
452 452
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
453
-            }
454
-            unset($field);
455
-        }
456
-        unset($default_html, $old_default_html, $fields);
457
-    }
458
-
459
-    private function migrate_to_4() {
460
-        global $wpdb;
453
+			}
454
+			unset($field);
455
+		}
456
+		unset($default_html, $old_default_html, $fields);
457
+	}
458
+
459
+	private function migrate_to_4() {
460
+		global $wpdb;
461 461
 		$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
462
-        foreach ( $user_ids as $user_id ) {
462
+		foreach ( $user_ids as $user_id ) {
463 463
 			$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) );
464
-        }
465
-    }
464
+		}
465
+	}
466 466
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
 	public $entry_metas;
8 8
 
9 9
 	public function __construct() {
10
-		if ( ! defined('ABSPATH') ) {
11
-			die('You are not allowed to call this page directly.');
10
+		if ( ! defined( 'ABSPATH' ) ) {
11
+			die( 'You are not allowed to call this page directly.' );
12 12
 		}
13 13
 
14 14
 		global $wpdb;
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 		$frm_db_version = FrmAppHelper::$db_version;
27 27
 		$old_db_version = (float) $old_db_version;
28 28
 		if ( ! $old_db_version ) {
29
-			$old_db_version = get_option('frm_db_version');
29
+			$old_db_version = get_option( 'frm_db_version' );
30 30
 		}
31 31
 
32 32
 		if ( $frm_db_version != $old_db_version ) {
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
 			require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
37 37
 
38 38
 			$this->create_tables();
39
-			$this->migrate_data($frm_db_version, $old_db_version);
39
+			$this->migrate_data( $frm_db_version, $old_db_version );
40 40
 
41 41
 			/***** SAVE DB VERSION *****/
42
-			update_option('frm_db_version', $frm_db_version);
42
+			update_option( 'frm_db_version', $frm_db_version );
43 43
 
44 44
 			/**** ADD/UPDATE DEFAULT TEMPLATES ****/
45 45
 			FrmXMLController::add_default_templates();
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 			}
50 50
 		}
51 51
 
52
-		do_action('frm_after_install');
52
+		do_action( 'frm_after_install' );
53 53
 
54 54
 		/**** update the styling settings ****/
55 55
 		if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 				global $wpdb;
160 160
 				$wpdb->query( $q . $charset_collate );
161 161
 			}
162
-            unset($q);
162
+            unset( $q );
163 163
         }
164 164
     }
165 165
 
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
     public function uninstall() {
195 195
 		if ( ! current_user_can( 'administrator' ) ) {
196 196
             $frm_settings = FrmAppHelper::get_settings();
197
-            wp_die($frm_settings->admin_permission);
197
+            wp_die( $frm_settings->admin_permission );
198 198
         }
199 199
 
200 200
         global $wpdb, $wp_roles;
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries );
205 205
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas );
206 206
 
207
-        delete_option('frm_options');
208
-        delete_option('frm_db_version');
207
+        delete_option( 'frm_options' );
208
+        delete_option( 'frm_db_version' );
209 209
 
210 210
         //delete roles
211 211
         $frm_roles = FrmAppHelper::frm_capabilities();
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
         foreach ( $frm_roles as $frm_role => $frm_role_description ) {
214 214
             foreach ( $roles as $role => $details ) {
215 215
                 $wp_roles->remove_cap( $role, $frm_role );
216
-                unset($role, $details);
216
+                unset( $role, $details );
217 217
     		}
218
-    		unset($frm_role, $frm_role_description);
218
+    		unset( $frm_role, $frm_role_description );
219 219
 		}
220
-		unset($roles, $frm_roles);
220
+		unset( $roles, $frm_roles );
221 221
 
222 222
 		// delete actions, views, and styles
223 223
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 
240 240
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) );
241 241
 
242
-        do_action('frm_after_uninstall');
242
+        do_action( 'frm_after_uninstall' );
243 243
         return true;
244 244
     }
245 245
 
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
 
297 297
         $updated = 0;
298 298
         foreach ( $fields as $f ) {
299
-            $f->field_options = maybe_unserialize($f->field_options);
300
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
299
+            $f->field_options = maybe_unserialize( $f->field_options );
300
+            if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
301 301
                 continue;
302 302
             }
303 303
 
@@ -305,27 +305,27 @@  discard block
 block discarded – undo
305 305
             $f->field_options['size'] .= 'px';
306 306
             $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
307 307
             if ( $u ) {
308
-                $updated++;
308
+                $updated ++;
309 309
             }
310
-            unset($f);
310
+            unset( $f );
311 311
         }
312 312
 
313 313
         // Change the characters in widgets to pixels
314
-        $widgets = get_option('widget_frm_show_form');
315
-        if ( empty($widgets) ) {
314
+        $widgets = get_option( 'widget_frm_show_form' );
315
+        if ( empty( $widgets ) ) {
316 316
             return;
317 317
         }
318 318
 
319
-        $widgets = maybe_unserialize($widgets);
319
+        $widgets = maybe_unserialize( $widgets );
320 320
         foreach ( $widgets as $k => $widget ) {
321
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
321
+            if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
322 322
                 continue;
323 323
             }
324 324
 			$size = round( $pixel_conversion * (int) $widget['size'] );
325 325
             $size .= 'px';
326
-			$widgets[ $k ]['size'] = $size;
326
+			$widgets[$k]['size'] = $size;
327 327
         }
328
-        update_option('widget_frm_show_form', $widgets);
328
+        update_option( 'widget_frm_show_form', $widgets );
329 329
     }
330 330
 
331 331
     /**
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 			}
375 375
 
376 376
             // Format form options
377
-            $form_options = maybe_unserialize($form->options);
377
+            $form_options = maybe_unserialize( $form->options );
378 378
 
379 379
             // Migrate settings to actions
380 380
             FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
     private function migrate_to_11() {
385 385
         global $wpdb;
386 386
 
387
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
387
+        $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
388 388
 
389 389
         $sending = __( 'Sending', 'formidable' );
390 390
 		$img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
@@ -395,13 +395,13 @@  discard block
 block discarded – undo
395 395
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
396 396
 </div>
397 397
 DEFAULT_HTML;
398
-        unset($sending, $img);
398
+        unset( $sending, $img );
399 399
 
400
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
400
+        $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
401 401
         $draft_link = FrmFormsHelper::get_draft_link();
402 402
 		foreach ( $forms as $form ) {
403
-            $form->options = maybe_unserialize($form->options);
404
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
403
+            $form->options = maybe_unserialize( $form->options );
404
+            if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) {
405 405
                 continue;
406 406
             }
407 407
 
@@ -412,9 +412,9 @@  discard block
 block discarded – undo
412 412
 				$form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
413 413
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
414 414
             }
415
-            unset($form);
415
+            unset( $form );
416 416
         }
417
-        unset($forms);
417
+        unset( $forms );
418 418
     }
419 419
 
420 420
     private function migrate_to_6() {
@@ -443,17 +443,17 @@  discard block
 block discarded – undo
443 443
 </div>
444 444
 DEFAULT_HTML;
445 445
 
446
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
446
+        $new_default_html = FrmFieldsHelper::get_default_html( 'text' );
447 447
         foreach ( $fields as $field ) {
448
-            $field->field_options = maybe_unserialize($field->field_options);
448
+            $field->field_options = maybe_unserialize( $field->field_options );
449 449
 			$html = FrmField::get_option( $field, 'custom_html' );
450 450
 			if ( $html == $default_html || $html == $old_default_html ) {
451 451
                 $field->field_options['custom_html'] = $new_default_html;
452 452
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
453 453
             }
454
-            unset($field);
454
+            unset( $field );
455 455
         }
456
-        unset($default_html, $old_default_html, $fields);
456
+        unset( $default_html, $old_default_html, $fields );
457 457
     }
458 458
 
459 459
     private function migrate_to_4() {
Please login to merge, or discard this patch.