Completed
Push — master ( af4004...c351ef )
by Jamie
03:28
created
classes/controllers/FrmSettingsController.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -2,78 +2,78 @@
 block discarded – undo
2 2
 
3 3
 class FrmSettingsController {
4 4
 
5
-    public static function menu() {
5
+	public static function menu() {
6 6
 		// Make sure admins can see the menu items
7 7
 		FrmAppHelper::force_capability( 'frm_change_settings' );
8 8
 
9
-        add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' );
10
-    }
9
+		add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' );
10
+	}
11 11
 
12
-    public static function license_box() {
12
+	public static function license_box() {
13 13
 		$a = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' );
14
-        include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/license_box.php' );
15
-    }
14
+		include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/license_box.php' );
15
+	}
16 16
 
17
-    public static function display_form( $errors = array(), $message = '' ) {
18
-        global $frm_vars;
17
+	public static function display_form( $errors = array(), $message = '' ) {
18
+		global $frm_vars;
19 19
 
20
-        $frm_settings = FrmAppHelper::get_settings();
21
-        $frm_roles = FrmAppHelper::frm_capabilities();
20
+		$frm_settings = FrmAppHelper::get_settings();
21
+		$frm_roles = FrmAppHelper::frm_capabilities();
22 22
 
23
-        $uploads = wp_upload_dir();
24
-        $target_path = $uploads['basedir'] . '/formidable/css';
23
+		$uploads = wp_upload_dir();
24
+		$target_path = $uploads['basedir'] . '/formidable/css';
25 25
 
26 26
 		$sections = array();
27 27
 		if ( apply_filters( 'frm_include_addon_page', false ) ) {
28 28
 			$sections['licenses'] = array( 'class' => 'FrmAddonsController', 'function' => 'show_addons' );
29 29
 		}
30
-        $sections = apply_filters( 'frm_add_settings_section', $sections );
30
+		$sections = apply_filters( 'frm_add_settings_section', $sections );
31 31
 
32
-        $captcha_lang = FrmAppHelper::locales( 'captcha' );
32
+		$captcha_lang = FrmAppHelper::locales( 'captcha' );
33 33
 
34
-        require( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/form.php' );
35
-    }
34
+		require( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/form.php' );
35
+	}
36 36
 
37
-    public static function process_form( $stop_load = false ) {
38
-        global $frm_vars;
37
+	public static function process_form( $stop_load = false ) {
38
+		global $frm_vars;
39 39
 
40
-        $frm_settings = FrmAppHelper::get_settings();
40
+		$frm_settings = FrmAppHelper::get_settings();
41 41
 
42 42
 		$process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
43 43
 		if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
44
-            wp_die( $frm_settings->admin_permission );
45
-        }
44
+			wp_die( $frm_settings->admin_permission );
45
+		}
46 46
 
47
-        $errors = array();
48
-        $message = '';
47
+		$errors = array();
48
+		$message = '';
49 49
 
50
-        if ( ! isset( $frm_vars['settings_routed'] ) || ! $frm_vars['settings_routed'] ) {
51
-            //$errors = $frm_settings->validate($_POST,array());
52
-            $frm_settings->update( stripslashes_deep( $_POST ) );
50
+		if ( ! isset( $frm_vars['settings_routed'] ) || ! $frm_vars['settings_routed'] ) {
51
+			//$errors = $frm_settings->validate($_POST,array());
52
+			$frm_settings->update( stripslashes_deep( $_POST ) );
53 53
 
54
-            if ( empty( $errors ) ) {
55
-                $frm_settings->store();
56
-                $message = __( 'Settings Saved', 'formidable' );
57
-            }
58
-        } else {
59
-            $message = __( 'Settings Saved', 'formidable' );
60
-        }
54
+			if ( empty( $errors ) ) {
55
+				$frm_settings->store();
56
+				$message = __( 'Settings Saved', 'formidable' );
57
+			}
58
+		} else {
59
+			$message = __( 'Settings Saved', 'formidable' );
60
+		}
61 61
 
62 62
 		if ( $stop_load == 'stop_load' ) {
63
-            $frm_vars['settings_routed'] = true;
64
-            return;
65
-        }
63
+			$frm_vars['settings_routed'] = true;
64
+			return;
65
+		}
66 66
 
67
-        self::display_form( $errors, $message );
68
-    }
67
+		self::display_form( $errors, $message );
68
+	}
69 69
 
70
-    public static function route( $stop_load = false ) {
71
-        $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
70
+	public static function route( $stop_load = false ) {
71
+		$action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
72 72
 		$action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
73
-        if ( $action == 'process-form' ) {
74
-            return self::process_form( $stop_load );
75
-        } else if ( $stop_load != 'stop_load' ) {
76
-            return self::display_form();
77
-        }
78
-    }
73
+		if ( $action == 'process-form' ) {
74
+			return self::process_form( $stop_load );
75
+		} else if ( $stop_load != 'stop_load' ) {
76
+			return self::display_form();
77
+		}
78
+	}
79 79
 }
Please login to merge, or discard this patch.
classes/helpers/FrmEntriesHelper.php 1 patch
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -5,68 +5,68 @@  discard block
 block discarded – undo
5 5
 
6 6
 class FrmEntriesHelper {
7 7
 
8
-    public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) {
9
-        global $frm_vars;
10
-        $values = array();
8
+	public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) {
9
+		global $frm_vars;
10
+		$values = array();
11 11
 		foreach ( array( 'name' => '', 'description' => '', 'item_key' => '' ) as $var => $default ) {
12
-            $values[ $var ] = FrmAppHelper::get_post_param( $var, $default );
13
-        }
14
-
15
-        $values['fields'] = array();
16
-        if ( empty($fields) ) {
17
-            return apply_filters('frm_setup_new_entry', $values);
18
-        }
19
-
20
-        foreach ( (array) $fields as $field ) {
21
-            $new_value = self::get_field_value_for_new_entry( $field, $reset );
22
-
23
-            $field_array = array(
24
-                'id' => $field->id,
25
-                'value' => $new_value,
26
-                'default_value' => $field->default_value,
27
-                'name' => $field->name,
28
-                'description' => $field->description,
29
-                'type' => apply_filters('frm_field_type', $field->type, $field, $new_value),
30
-                'options' => $field->options,
31
-                'required' => $field->required,
32
-                'field_key' => $field->field_key,
33
-                'field_order' => $field->field_order,
34
-                'form_id' => $field->form_id,
12
+			$values[ $var ] = FrmAppHelper::get_post_param( $var, $default );
13
+		}
14
+
15
+		$values['fields'] = array();
16
+		if ( empty($fields) ) {
17
+			return apply_filters('frm_setup_new_entry', $values);
18
+		}
19
+
20
+		foreach ( (array) $fields as $field ) {
21
+			$new_value = self::get_field_value_for_new_entry( $field, $reset );
22
+
23
+			$field_array = array(
24
+				'id' => $field->id,
25
+				'value' => $new_value,
26
+				'default_value' => $field->default_value,
27
+				'name' => $field->name,
28
+				'description' => $field->description,
29
+				'type' => apply_filters('frm_field_type', $field->type, $field, $new_value),
30
+				'options' => $field->options,
31
+				'required' => $field->required,
32
+				'field_key' => $field->field_key,
33
+				'field_order' => $field->field_order,
34
+				'form_id' => $field->form_id,
35 35
 				'parent_form_id' => isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id,
36
-            );
36
+			);
37 37
 
38
-            $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
39
-            $opt_defaults['required_indicator'] = '';
38
+			$opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
39
+			$opt_defaults['required_indicator'] = '';
40 40
 			$opt_defaults['original_type'] = $field->type;
41 41
 
42 42
 			foreach ( $opt_defaults as $opt => $default_opt ) {
43
-                $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt;
44
-                unset($opt, $default_opt);
45
-            }
43
+				$field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt;
44
+				unset($opt, $default_opt);
45
+			}
46 46
 
47
-            unset($opt_defaults);
47
+			unset($opt_defaults);
48 48
 
49
-            if ( $field_array['custom_html'] == '' ) {
50
-                $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type);
51
-            }
49
+			if ( $field_array['custom_html'] == '' ) {
50
+				$field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type);
51
+			}
52 52
 
53
-            $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field);
54
-            $field_array = array_merge( $field->field_options, $field_array );
53
+			$field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field);
54
+			$field_array = array_merge( $field->field_options, $field_array );
55 55
 
56
-            $values['fields'][] = $field_array;
56
+			$values['fields'][] = $field_array;
57 57
 
58
-            if ( ! $form || ! isset($form->id) ) {
59
-                $form = FrmForm::getOne($field->form_id);
60
-            }
61
-        }
58
+			if ( ! $form || ! isset($form->id) ) {
59
+				$form = FrmForm::getOne($field->form_id);
60
+			}
61
+		}
62 62
 
63
-        $form->options = maybe_unserialize($form->options);
64
-        if ( is_array($form->options) ) {
65
-            foreach ( $form->options as $opt => $value ) {
66
-                $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value );
67
-                unset($opt, $value);
68
-            }
69
-        }
63
+		$form->options = maybe_unserialize($form->options);
64
+		if ( is_array($form->options) ) {
65
+			foreach ( $form->options as $opt => $value ) {
66
+				$values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value );
67
+				unset($opt, $value);
68
+			}
69
+		}
70 70
 
71 71
 		$form_defaults = FrmFormsHelper::get_default_opts();
72 72
 
@@ -76,18 +76,18 @@  discard block
 block discarded – undo
76 76
 		$values = array_merge( $form_defaults, $values );
77 77
 
78 78
 		return apply_filters( 'frm_setup_new_entry', $values );
79
-    }
79
+	}
80 80
 
81 81
 	/**
82
-	* Set the value for each field
83
-	* This function is used when the form is first loaded and on all page turns *for a new entry*
84
-	*
85
-	* @since 2.0.13
86
-	*
87
-	* @param object $field - this is passed by reference since it is an object
88
-	* @param boolean $reset
89
-	* @return string|array $new_value
90
-	*/
82
+	 * Set the value for each field
83
+	 * This function is used when the form is first loaded and on all page turns *for a new entry*
84
+	 *
85
+	 * @since 2.0.13
86
+	 *
87
+	 * @param object $field - this is passed by reference since it is an object
88
+	 * @param boolean $reset
89
+	 * @return string|array $new_value
90
+	 */
91 91
 	private static function get_field_value_for_new_entry( $field, $reset ) {
92 92
 		//If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array
93 93
 		$return_array = FrmField::is_field_with_multiple_values( $field );
@@ -118,15 +118,15 @@  discard block
 block discarded – undo
118 118
 
119 119
 	public static function setup_edit_vars( $values, $record ) {
120 120
 		$values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' );
121
-        $values['form_id'] = $record->form_id;
122
-        $values['is_draft'] = $record->is_draft;
123
-        return apply_filters('frm_setup_edit_entry_vars', $values, $record);
124
-    }
121
+		$values['form_id'] = $record->form_id;
122
+		$values['is_draft'] = $record->is_draft;
123
+		return apply_filters('frm_setup_edit_entry_vars', $values, $record);
124
+	}
125 125
 
126
-    public static function get_admin_params( $form = null ) {
126
+	public static function get_admin_params( $form = null ) {
127 127
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_admin_params' );
128 128
 		return FrmForm::set_current_form( $form );
129
-    }
129
+	}
130 130
 
131 131
 	public static function set_current_form( $form_id ) {
132 132
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::set_current_form' );
@@ -138,280 +138,280 @@  discard block
 block discarded – undo
138 138
 		return FrmForm::get_current_form( $form_id );
139 139
 	}
140 140
 
141
-    public static function get_current_form_id() {
141
+	public static function get_current_form_id() {
142 142
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_current_form_id' );
143 143
 		return FrmForm::get_current_form_id();
144
-    }
144
+	}
145 145
 
146
-    public static function maybe_get_entry( &$entry ) {
146
+	public static function maybe_get_entry( &$entry ) {
147 147
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntry::maybe_get_entry' );
148 148
 		FrmEntry::maybe_get_entry( $entry );
149
-    }
149
+	}
150 150
 
151 151
 	public static function replace_default_message( $message, $atts ) {
152
-        if ( strpos($message, '[default-message') === false &&
153
-            strpos($message, '[default_message') === false &&
154
-            ! empty( $message ) ) {
155
-            return $message;
156
-        }
157
-
158
-        if ( empty($message) ) {
159
-            $message = '[default-message]';
160
-        }
161
-
162
-        preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER);
163
-
164
-        foreach ( $shortcodes[0] as $short_key => $tag ) {
165
-            $add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] );
166
-            if ( $add_atts ) {
167
-                $this_atts = array_merge($atts, $add_atts);
168
-            } else {
169
-                $this_atts = $atts;
170
-            }
152
+		if ( strpos($message, '[default-message') === false &&
153
+			strpos($message, '[default_message') === false &&
154
+			! empty( $message ) ) {
155
+			return $message;
156
+		}
157
+
158
+		if ( empty($message) ) {
159
+			$message = '[default-message]';
160
+		}
161
+
162
+		preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER);
163
+
164
+		foreach ( $shortcodes[0] as $short_key => $tag ) {
165
+			$add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] );
166
+			if ( $add_atts ) {
167
+				$this_atts = array_merge($atts, $add_atts);
168
+			} else {
169
+				$this_atts = $atts;
170
+			}
171 171
 
172 172
 			$default = FrmEntryFormat::show_entry( $this_atts );
173 173
 
174
-            // Add the default message
175
-            $message = str_replace( $shortcodes[0][ $short_key ], $default, $message );
176
-        }
174
+			// Add the default message
175
+			$message = str_replace( $shortcodes[0][ $short_key ], $default, $message );
176
+		}
177 177
 
178
-        return $message;
179
-    }
178
+		return $message;
179
+	}
180 180
 
181 181
 	public static function prepare_display_value( $entry, $field, $atts ) {
182 182
 		$field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
183
-        if ( FrmAppHelper::pro_is_installed() ) {
183
+		if ( FrmAppHelper::pro_is_installed() ) {
184 184
 			FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value );
185
-        }
185
+		}
186 186
 
187
-        if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) {
188
-            return self::display_value($field_value, $field, $atts);
189
-        }
187
+		if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) {
188
+			return self::display_value($field_value, $field, $atts);
189
+		}
190 190
 
191
-        // this is an embeded form
192
-        $val = '';
191
+		// this is an embeded form
192
+		$val = '';
193 193
 
194
-	    if ( strpos($atts['embedded_field_id'], 'form') === 0 ) {
195
-            //this is a repeating section
194
+		if ( strpos($atts['embedded_field_id'], 'form') === 0 ) {
195
+			//this is a repeating section
196 196
 			$child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) );
197
-        } else {
198
-            // get all values for this field
199
-	        $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
197
+		} else {
198
+			// get all values for this field
199
+			$child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
200 200
 
201
-            if ( $child_values ) {
202
-	            $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
203
-	        }
204
-	    }
201
+			if ( $child_values ) {
202
+				$child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
203
+			}
204
+		}
205 205
 
206
-	    $field_value = array();
206
+		$field_value = array();
207 207
 
208
-        if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) {
209
-            return $val;
210
-        }
208
+		if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) {
209
+			return $val;
210
+		}
211 211
 
212
-        foreach ( $child_entries as $child_entry ) {
213
-            $atts['item_id'] = $child_entry->id;
214
-            $atts['post_id'] = $child_entry->post_id;
212
+		foreach ( $child_entries as $child_entry ) {
213
+			$atts['item_id'] = $child_entry->id;
214
+			$atts['post_id'] = $child_entry->post_id;
215 215
 
216
-            // get the value for this field -- check for post values as well
217
-            $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field);
216
+			// get the value for this field -- check for post values as well
217
+			$entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field);
218 218
 
219
-            if ( $entry_val ) {
220
-                // foreach entry get display_value
221
-                $field_value[] = self::display_value($entry_val, $field, $atts);
222
-            }
219
+			if ( $entry_val ) {
220
+				// foreach entry get display_value
221
+				$field_value[] = self::display_value($entry_val, $field, $atts);
222
+			}
223 223
 
224
-            unset($child_entry);
225
-        }
224
+			unset($child_entry);
225
+		}
226 226
 
227
-        $val = implode(', ', (array) $field_value );
227
+		$val = implode(', ', (array) $field_value );
228 228
 		$val = wp_kses_post( $val );
229 229
 
230
-        return $val;
231
-    }
230
+		return $val;
231
+	}
232 232
 
233
-    /**
234
-     * Prepare the saved value for display
235
-     * @return string
236
-     */
233
+	/**
234
+	 * Prepare the saved value for display
235
+	 * @return string
236
+	 */
237 237
 	public static function display_value( $value, $field, $atts = array() ) {
238 238
 
239
-        $defaults = array(
240
-            'type' => '', 'html' => false, 'show_filename' => true,
241
-            'truncate' => false, 'sep' => ', ', 'post_id' => 0,
242
-            'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0,
239
+		$defaults = array(
240
+			'type' => '', 'html' => false, 'show_filename' => true,
241
+			'truncate' => false, 'sep' => ', ', 'post_id' => 0,
242
+			'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0,
243 243
 			'return_array' => false,
244
-        );
244
+		);
245 245
 
246
-        $atts = wp_parse_args( $atts, $defaults );
247
-        $atts = apply_filters('frm_display_value_atts', $atts, $field, $value);
246
+		$atts = wp_parse_args( $atts, $defaults );
247
+		$atts = apply_filters('frm_display_value_atts', $atts, $field, $value);
248 248
 
249
-        if ( ! isset($field->field_options['post_field']) ) {
250
-            $field->field_options['post_field'] = '';
251
-        }
249
+		if ( ! isset($field->field_options['post_field']) ) {
250
+			$field->field_options['post_field'] = '';
251
+		}
252 252
 
253
-        if ( ! isset($field->field_options['custom_field']) ) {
254
-            $field->field_options['custom_field'] = '';
255
-        }
253
+		if ( ! isset($field->field_options['custom_field']) ) {
254
+			$field->field_options['custom_field'] = '';
255
+		}
256 256
 
257
-        if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) {
258
-            $atts['pre_truncate'] = $atts['truncate'];
259
-            $atts['truncate'] = true;
260
-            $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0;
257
+		if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) {
258
+			$atts['pre_truncate'] = $atts['truncate'];
259
+			$atts['truncate'] = true;
260
+			$atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0;
261 261
 
262
-            $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts);
263
-            $atts['truncate'] = $atts['pre_truncate'];
264
-        }
262
+			$value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts);
263
+			$atts['truncate'] = $atts['pre_truncate'];
264
+		}
265 265
 
266
-        if ( $value == '' ) {
267
-            return $value;
268
-        }
266
+		if ( $value == '' ) {
267
+			return $value;
268
+		}
269 269
 
270
-        $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts);
270
+		$value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts);
271 271
 
272
-        $new_value = '';
272
+		$new_value = '';
273 273
 
274
-        if ( is_array($value) && $atts['type'] != 'file' ) {
275
-            foreach ( $value as $val ) {
276
-                if ( is_array($val) ) {
274
+		if ( is_array($value) && $atts['type'] != 'file' ) {
275
+			foreach ( $value as $val ) {
276
+				if ( is_array($val) ) {
277 277
 					//TODO: add options for display (li or ,)
278
-                    $new_value .= implode($atts['sep'], $val);
279
-                    if ( $atts['type'] != 'data' ) {
280
-                        $new_value .= '<br/>';
281
-                    }
282
-                }
283
-                unset($val);
284
-            }
285
-        }
286
-
287
-        if ( ! empty($new_value) ) {
288
-            $value = $new_value;
289
-        } else if ( is_array($value) && $atts['type'] != 'file' && ! $atts['return_array'] ) {
290
-            $value = implode($atts['sep'], $value);
291
-        }
292
-
293
-        if ( $atts['truncate'] && $atts['type'] != 'image' ) {
294
-            $value = FrmAppHelper::truncate($value, 50);
295
-        }
278
+					$new_value .= implode($atts['sep'], $val);
279
+					if ( $atts['type'] != 'data' ) {
280
+						$new_value .= '<br/>';
281
+					}
282
+				}
283
+				unset($val);
284
+			}
285
+		}
286
+
287
+		if ( ! empty($new_value) ) {
288
+			$value = $new_value;
289
+		} else if ( is_array($value) && $atts['type'] != 'file' && ! $atts['return_array'] ) {
290
+			$value = implode($atts['sep'], $value);
291
+		}
292
+
293
+		if ( $atts['truncate'] && $atts['type'] != 'image' ) {
294
+			$value = FrmAppHelper::truncate($value, 50);
295
+		}
296 296
 
297 297
 		if ( ! $atts['keepjs'] && ! is_array( $value ) ) {
298 298
 			$value = wp_kses_post( $value );
299 299
 		}
300 300
 
301
-        return apply_filters('frm_display_value', $value, $field, $atts);
302
-    }
301
+		return apply_filters('frm_display_value', $value, $field, $atts);
302
+	}
303 303
 
304 304
 	public static function set_posted_value( $field, $value, $args ) {
305
-        // If validating a field with "other" opt, set back to prev value now
306
-        if ( isset( $args['other'] ) && $args['other'] ) {
307
-            $value = $args['temp_value'];
308
-        }
309
-        if ( empty($args['parent_field_id']) ) {
310
-            $_POST['item_meta'][ $field->id ] = $value;
311
-        } else {
312
-            $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value;
313
-        }
314
-    }
305
+		// If validating a field with "other" opt, set back to prev value now
306
+		if ( isset( $args['other'] ) && $args['other'] ) {
307
+			$value = $args['temp_value'];
308
+		}
309
+		if ( empty($args['parent_field_id']) ) {
310
+			$_POST['item_meta'][ $field->id ] = $value;
311
+		} else {
312
+			$_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value;
313
+		}
314
+	}
315 315
 
316 316
 	public static function get_posted_value( $field, &$value, $args ) {
317 317
 		$field_id = is_object( $field ) ? $field->id : $field;
318 318
 
319
-        if ( empty($args['parent_field_id']) ) {
320
-            $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : '';
321
-        } else {
322
-            $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : '';
323
-        }
324
-    }
325
-
326
-    /**
327
-    * Check if field has an "Other" option and if any other values are posted
328
-    *
329
-    * @since 2.0
330
-    *
331
-    * @param object $field
332
-    * @param string|array $value
333
-    * @param array $args
334
-    */
335
-    public static function maybe_set_other_validation( $field, &$value, &$args ) {
336
-        $args['other'] = false;
337
-        if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) {
338
-            return;
339
-        }
340
-
341
-        // Get other value for fields in repeating section
342
-        self::set_other_repeating_vals( $field, $value, $args );
343
-
344
-        // Check if there are any posted "Other" values
319
+		if ( empty($args['parent_field_id']) ) {
320
+			$value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : '';
321
+		} else {
322
+			$value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : '';
323
+		}
324
+	}
325
+
326
+	/**
327
+	 * Check if field has an "Other" option and if any other values are posted
328
+	 *
329
+	 * @since 2.0
330
+	 *
331
+	 * @param object $field
332
+	 * @param string|array $value
333
+	 * @param array $args
334
+	 */
335
+	public static function maybe_set_other_validation( $field, &$value, &$args ) {
336
+		$args['other'] = false;
337
+		if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) {
338
+			return;
339
+		}
340
+
341
+		// Get other value for fields in repeating section
342
+		self::set_other_repeating_vals( $field, $value, $args );
343
+
344
+		// Check if there are any posted "Other" values
345 345
 		if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) {
346 346
 
347
-            // Save original value
348
-            $args['temp_value'] = $value;
349
-            $args['other'] = true;
350
-            $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] );
351
-
352
-            // Set the validation value now
353
-            self::set_other_validation_val( $value, $other_vals, $field, $args );
354
-        }
355
-    }
356
-
357
-    /**
358
-    * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
359
-    *
360
-    * @since 2.0
361
-    *
362
-    * @param object $field
363
-    * @param string|array $value
364
-    * @param array $args
365
-    */
366
-    public static function set_other_repeating_vals( $field, &$value, &$args ) {
367
-        if ( ! $args['parent_field_id'] ) {
368
-            return;
369
-        }
370
-
371
-        // Check if there are any other posted "other" values for this field
347
+			// Save original value
348
+			$args['temp_value'] = $value;
349
+			$args['other'] = true;
350
+			$other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] );
351
+
352
+			// Set the validation value now
353
+			self::set_other_validation_val( $value, $other_vals, $field, $args );
354
+		}
355
+	}
356
+
357
+	/**
358
+	 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
359
+	 *
360
+	 * @since 2.0
361
+	 *
362
+	 * @param object $field
363
+	 * @param string|array $value
364
+	 * @param array $args
365
+	 */
366
+	public static function set_other_repeating_vals( $field, &$value, &$args ) {
367
+		if ( ! $args['parent_field_id'] ) {
368
+			return;
369
+		}
370
+
371
+		// Check if there are any other posted "other" values for this field
372 372
 		if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) {
373
-            // Save original value
374
-            $args['temp_value'] = $value;
375
-            $args['other'] = true;
376
-
377
-            $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ];
378
-
379
-            // Set the validation value now
380
-            self::set_other_validation_val( $value, $other_vals, $field, $args );
381
-        }
382
-    }
383
-
384
-    /**
385
-    * Modify value used for validation
386
-    * This function essentially removes the "Other" radio or checkbox value from the $value being validated.
387
-    * It also adds any text from the free text fields to the value
388
-    *
389
-    * Needs to accommodate for times when other opt is selected, but no other free text is entered
390
-    *
391
-    * @since 2.0
392
-    *
393
-    * @param string|array $value
394
-    * @param string|array $other_vals (usually of posted values)
395
-    * @param object $field
396
-    * @param array $args
397
-    */
398
-    public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
399
-        // Checkboxes and multi-select dropdowns
400
-        if ( is_array( $value ) && $field->type == 'checkbox' ) {
401
-            // Combine "Other" values with checked values. "Other" values will override checked box values.
402
-            $value = array_merge( $value, $other_vals );
403
-            $value = array_filter( $value );
404
-            if ( count( $value ) == 0 ) {
405
-                $value = '';
406
-            }
407
-        } else {
373
+			// Save original value
374
+			$args['temp_value'] = $value;
375
+			$args['other'] = true;
376
+
377
+			$other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ];
378
+
379
+			// Set the validation value now
380
+			self::set_other_validation_val( $value, $other_vals, $field, $args );
381
+		}
382
+	}
383
+
384
+	/**
385
+	 * Modify value used for validation
386
+	 * This function essentially removes the "Other" radio or checkbox value from the $value being validated.
387
+	 * It also adds any text from the free text fields to the value
388
+	 *
389
+	 * Needs to accommodate for times when other opt is selected, but no other free text is entered
390
+	 *
391
+	 * @since 2.0
392
+	 *
393
+	 * @param string|array $value
394
+	 * @param string|array $other_vals (usually of posted values)
395
+	 * @param object $field
396
+	 * @param array $args
397
+	 */
398
+	public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
399
+		// Checkboxes and multi-select dropdowns
400
+		if ( is_array( $value ) && $field->type == 'checkbox' ) {
401
+			// Combine "Other" values with checked values. "Other" values will override checked box values.
402
+			$value = array_merge( $value, $other_vals );
403
+			$value = array_filter( $value );
404
+			if ( count( $value ) == 0 ) {
405
+				$value = '';
406
+			}
407
+		} else {
408 408
 			// Radio and dropdowns
409
-            $other_key = array_filter( array_keys($field->options), 'is_string');
410
-            $other_key = reset( $other_key );
409
+			$other_key = array_filter( array_keys($field->options), 'is_string');
410
+			$other_key = reset( $other_key );
411 411
 
412
-            // Multi-select dropdown
413
-            if ( is_array( $value ) ) {
414
-                $o_key = array_search( $field->options[ $other_key ], $value );
412
+			// Multi-select dropdown
413
+			if ( is_array( $value ) ) {
414
+				$o_key = array_search( $field->options[ $other_key ], $value );
415 415
 
416 416
 				if ( $o_key !== false ) {
417 417
 					// Modify the original value so other key will be preserved
@@ -426,20 +426,20 @@  discard block
 block discarded – undo
426 426
 					$args['temp_value'] = $value;
427 427
 					$value[ $other_key ] = reset( $other_vals );
428 428
 				}
429
-            } else if ( $field->options[ $other_key ] == $value ) {
430
-                $value = $other_vals;
431
-            }
432
-        }
433
-    }
429
+			} else if ( $field->options[ $other_key ] == $value ) {
430
+				$value = $other_vals;
431
+			}
432
+		}
433
+	}
434 434
 
435 435
 	public static function enqueue_scripts( $params ) {
436 436
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmFormsController::enqueue_scripts' );
437 437
 		return FrmFormsController::enqueue_scripts( $params );
438 438
 	}
439 439
 
440
-    // Add submitted values to a string for spam checking
440
+	// Add submitted values to a string for spam checking
441 441
 	public static function entry_array_to_string( $values ) {
442
-        $content = '';
442
+		$content = '';
443 443
 		foreach ( $values['item_meta'] as $val ) {
444 444
 			if ( $content != '' ) {
445 445
 				$content .= "\n\n";
@@ -447,14 +447,14 @@  discard block
 block discarded – undo
447 447
 
448 448
 			if ( is_array($val) ) {
449 449
 				$val = FrmAppHelper::array_flatten( $val );
450
-			    $val = implode(',', $val);
450
+				$val = implode(',', $val);
451 451
 			}
452 452
 
453 453
 			$content .= $val;
454 454
 		}
455 455
 
456 456
 		return $content;
457
-    }
457
+	}
458 458
 
459 459
 	public static function fill_entry_values( $atts, $f, array &$values ) {
460 460
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryFormat::fill_entry_values' );
Please login to merge, or discard this patch.
classes/helpers/FrmEntriesListHelper.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -6,46 +6,46 @@  discard block
 block discarded – undo
6 6
 	protected $field;
7 7
 
8 8
 	public function prepare_items() {
9
-        global $wpdb, $per_page;
9
+		global $wpdb, $per_page;
10 10
 
11 11
 		$per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' );
12 12
 
13
-        $form_id = $this->params['form'];
14
-        if ( ! $form_id ) {
15
-            $this->items = array();
16
-    		$this->set_pagination_args( array(
17
-    			'total_items' => 0,
13
+		$form_id = $this->params['form'];
14
+		if ( ! $form_id ) {
15
+			$this->items = array();
16
+			$this->set_pagination_args( array(
17
+				'total_items' => 0,
18 18
 				'per_page' => $per_page,
19
-    		) );
20
-            return;
21
-        }
19
+			) );
20
+			return;
21
+		}
22 22
 
23 23
 		$default_orderby = 'id';
24 24
 		$default_order = 'DESC';
25 25
 
26
-	    $s_query = array( 'it.form_id' => $form_id );
26
+		$s_query = array( 'it.form_id' => $form_id );
27 27
 
28 28
 		$s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
29 29
 
30
-	    if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
31
-	        $fid = isset( $_REQUEST['fid'] ) ? sanitize_title( $_REQUEST['fid'] ) : '';
32
-	        $s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid);
33
-	    }
30
+		if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
31
+			$fid = isset( $_REQUEST['fid'] ) ? sanitize_title( $_REQUEST['fid'] ) : '';
32
+			$s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid);
33
+		}
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
-        $this->items = FrmEntry::getAll($s_query, $order, ' LIMIT '. $start .','. $per_page, true, false);
48
-        $total_items = FrmEntry::getRecordCount($s_query);
47
+		$this->items = FrmEntry::getAll($s_query, $order, ' LIMIT '. $start .','. $per_page, true, false);
48
+		$total_items = FrmEntry::getRecordCount($s_query);
49 49
 
50 50
 		$this->set_pagination_args( array(
51 51
 			'total_items' => $total_items,
@@ -54,19 +54,19 @@  discard block
 block discarded – undo
54 54
 	}
55 55
 
56 56
 	public function no_items() {
57
-        $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
58
-	    if ( ! empty($s) ) {
59
-            _e( 'No Entries Found', 'formidable' );
60
-            return;
61
-        }
62
-
63
-        $form_id = $form = $this->params['form'];
64
-        if ( $form_id ) {
65
-            $form = FrmForm::getOne($form_id);
66
-        }
67
-        $colspan = $this->get_column_count();
68
-
69
-        include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/no_entries.php');
57
+		$s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
58
+		if ( ! empty($s) ) {
59
+			_e( 'No Entries Found', 'formidable' );
60
+			return;
61
+		}
62
+
63
+		$form_id = $form = $this->params['form'];
64
+		if ( $form_id ) {
65
+			$form = FrmForm::getOne($form_id);
66
+		}
67
+		$colspan = $this->get_column_count();
68
+
69
+		include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/no_entries.php');
70 70
 	}
71 71
 
72 72
 	public function search_box( $text, $input_id ) {
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
 	}
75 75
 
76 76
 	/**
77
-	* Gets the name of the primary column in the Entries screen
78
-	*
79
-	* @since 2.0.14
80
-	*
81
-	* @return string $primary_column
82
-	*/
77
+	 * Gets the name of the primary column in the Entries screen
78
+	 *
79
+	 * @since 2.0.14
80
+	 *
81
+	 * @return string $primary_column
82
+	 */
83 83
 	protected function get_primary_column_name() {
84 84
 		$columns = get_column_headers( $this->screen );
85 85
 		$hidden = get_hidden_columns( $this->screen );
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 
104 104
 		$this->get_actions( $actions, $item, $view_link );
105 105
 
106
-        $action_links = $this->row_actions( $actions );
106
+		$action_links = $this->row_actions( $actions );
107 107
 
108 108
 		// Set up the checkbox ( because the user is editable, otherwise its empty )
109 109
 		$checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		$r = "<tr id='item-action-{$item->id}'$style>";
112 112
 
113 113
 		list( $columns, $hidden, , $primary ) = $this->get_column_info();
114
-        $action_col = false;
114
+		$action_col = false;
115 115
 
116 116
 		foreach ( $columns as $column_name => $column_display_name ) {
117 117
 			$class = $column_name .' column-'. $column_name;
@@ -123,14 +123,14 @@  discard block
 block discarded – undo
123 123
 			if ( in_array( $column_name, $hidden ) ) {
124 124
 				$class .= ' frm_hidden';
125 125
 			} else if ( ! $action_col && ! in_array( $column_name, array( 'cb', 'id', 'form_id', 'post_id' ) ) ) {
126
-			    $action_col = $column_name;
127
-            }
126
+				$action_col = $column_name;
127
+			}
128 128
 
129 129
 			$attributes = 'class="' . esc_attr( $class ) . '"';
130 130
 			unset($class);
131 131
 			$attributes .= ' data-colname="' . $column_display_name  . '"';
132 132
 
133
-            $col_name = preg_replace('/^('. $this->params['form'] .'_)/', '', $column_name);
133
+			$col_name = preg_replace('/^('. $this->params['form'] .'_)/', '', $column_name);
134 134
 			$this->column_name = $col_name;
135 135
 
136 136
 			switch ( $col_name ) {
@@ -140,30 +140,30 @@  discard block
 block discarded – undo
140 140
 				case 'ip':
141 141
 				case 'id':
142 142
 				case 'item_key':
143
-				    $val = $item->{$col_name};
144
-				    break;
143
+					$val = $item->{$col_name};
144
+					break;
145 145
 				case 'name':
146 146
 				case 'description':
147
-				    $val = FrmAppHelper::truncate(strip_tags($item->{$col_name}), 100);
148
-				    break;
147
+					$val = FrmAppHelper::truncate(strip_tags($item->{$col_name}), 100);
148
+					break;
149 149
 				case 'created_at':
150 150
 				case 'updated_at':
151
-				    $date = FrmAppHelper::get_formatted_time($item->{$col_name});
151
+					$date = FrmAppHelper::get_formatted_time($item->{$col_name});
152 152
 					$val = '<abbr title="' . esc_attr( FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) ) . '">' . $date . '</abbr>';
153 153
 					break;
154 154
 				case 'is_draft':
155
-				    $val = empty($item->is_draft) ? __( 'No') : __( 'Yes');
156
-			        break;
155
+					$val = empty($item->is_draft) ? __( 'No') : __( 'Yes');
156
+					break;
157 157
 				case 'form_id':
158
-				    $val = FrmFormsHelper::edit_form_link($item->form_id);
159
-    				break;
158
+					$val = FrmFormsHelper::edit_form_link($item->form_id);
159
+					break;
160 160
 				case 'post_id':
161
-				    $val = FrmAppHelper::post_edit_link($item->post_id);
162
-				    break;
161
+					$val = FrmAppHelper::post_edit_link($item->post_id);
162
+					break;
163 163
 				case 'user_id':
164
-				    $user = get_userdata($item->user_id);
165
-				    $val = $user->user_login;
166
-				    break;
164
+					$user = get_userdata($item->user_id);
165
+					$val = $user->user_login;
166
+					break;
167 167
 				default:
168 168
 					$val = apply_filters( 'frm_entries_' . $col_name . '_column', false, compact( 'item' ) );
169 169
 					if ( $val === false ) {
@@ -173,15 +173,15 @@  discard block
 block discarded – undo
173 173
 			}
174 174
 
175 175
 			if ( isset( $val ) ) {
176
-			    $r .= "<td $attributes>";
176
+				$r .= "<td $attributes>";
177 177
 				if ( $column_name == $action_col ) {
178 178
 					$edit_link = '?page=formidable-entries&frm_action=edit&id='. $item->id;
179 179
 					$r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> ';
180
-			        $r .= $action_links;
180
+					$r .= $action_links;
181 181
 				} else {
182
-			        $r .= $val;
183
-			    }
184
-			    $r .= '</td>';
182
+					$r .= $val;
183
+				}
184
+				$r .= '</td>';
185 185
 			}
186 186
 			unset($val);
187 187
 		}
@@ -190,19 +190,19 @@  discard block
 block discarded – undo
190 190
 		return $r;
191 191
 	}
192 192
 
193
-    /**
194
-     * @param string $view_link
195
-     */
196
-    private function get_actions( &$actions, $item, $view_link ) {
193
+	/**
194
+	 * @param string $view_link
195
+	 */
196
+	private function get_actions( &$actions, $item, $view_link ) {
197 197
 		$actions['view'] = '<a href="' . esc_url( $view_link ) . '">'. __( 'View', 'formidable' ) .'</a>';
198 198
 
199
-        if ( current_user_can('frm_delete_entries') ) {
200
-            $delete_link = '?page=formidable-entries&frm_action=destroy&id='. $item->id .'&form='. $this->params['form'];
199
+		if ( current_user_can('frm_delete_entries') ) {
200
+			$delete_link = '?page=formidable-entries&frm_action=destroy&id='. $item->id .'&form='. $this->params['form'];
201 201
 			$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>';
202
-	    }
202
+		}
203 203
 
204
-        $actions = apply_filters('frm_row_actions', $actions, $item);
205
-    }
204
+		$actions = apply_filters('frm_row_actions', $actions, $item);
205
+	}
206 206
 
207 207
 	private function get_column_value( $item, &$val ) {
208 208
 		$col_name = $this->column_name;
Please login to merge, or discard this patch.
classes/helpers/FrmStylesHelper.php 1 patch
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -1,67 +1,67 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class FrmStylesHelper {
3 3
 
4
-    public static function jquery_themes() {
5
-        $themes = array(
6
-            'ui-lightness'  => 'UI Lightness',
7
-            'ui-darkness'   => 'UI Darkness',
8
-            'smoothness'    => 'Smoothness',
9
-            'start'         => 'Start',
10
-            'redmond'       => 'Redmond',
11
-            'sunny'         => 'Sunny',
12
-            'overcast'      => 'Overcast',
13
-            'le-frog'       => 'Le Frog',
14
-            'flick'         => 'Flick',
4
+	public static function jquery_themes() {
5
+		$themes = array(
6
+			'ui-lightness'  => 'UI Lightness',
7
+			'ui-darkness'   => 'UI Darkness',
8
+			'smoothness'    => 'Smoothness',
9
+			'start'         => 'Start',
10
+			'redmond'       => 'Redmond',
11
+			'sunny'         => 'Sunny',
12
+			'overcast'      => 'Overcast',
13
+			'le-frog'       => 'Le Frog',
14
+			'flick'         => 'Flick',
15 15
 			'pepper-grinder' => 'Pepper Grinder',
16
-            'eggplant'      => 'Eggplant',
17
-            'dark-hive'     => 'Dark Hive',
18
-            'cupertino'     => 'Cupertino',
19
-            'south-street'  => 'South Street',
20
-            'blitzer'       => 'Blitzer',
21
-            'humanity'      => 'Humanity',
22
-            'hot-sneaks'    => 'Hot Sneaks',
23
-            'excite-bike'   => 'Excite Bike',
24
-            'vader'         => 'Vader',
25
-            'dot-luv'       => 'Dot Luv',
26
-            'mint-choc'     => 'Mint Choc',
27
-            'black-tie'     => 'Black Tie',
28
-            'trontastic'    => 'Trontastic',
29
-            'swanky-purse'  => 'Swanky Purse',
30
-        );
31
-
32
-        $themes = apply_filters('frm_jquery_themes', $themes);
33
-        return $themes;
34
-    }
16
+			'eggplant'      => 'Eggplant',
17
+			'dark-hive'     => 'Dark Hive',
18
+			'cupertino'     => 'Cupertino',
19
+			'south-street'  => 'South Street',
20
+			'blitzer'       => 'Blitzer',
21
+			'humanity'      => 'Humanity',
22
+			'hot-sneaks'    => 'Hot Sneaks',
23
+			'excite-bike'   => 'Excite Bike',
24
+			'vader'         => 'Vader',
25
+			'dot-luv'       => 'Dot Luv',
26
+			'mint-choc'     => 'Mint Choc',
27
+			'black-tie'     => 'Black Tie',
28
+			'trontastic'    => 'Trontastic',
29
+			'swanky-purse'  => 'Swanky Purse',
30
+		);
31
+
32
+		$themes = apply_filters('frm_jquery_themes', $themes);
33
+		return $themes;
34
+	}
35 35
 
36 36
 	public static function jquery_css_url( $theme_css ) {
37
-        if ( $theme_css == -1 ) {
38
-            return;
39
-        }
40
-
41
-        if ( ! $theme_css || $theme_css == '' || $theme_css == 'ui-lightness' ) {
42
-            $css_file = FrmAppHelper::plugin_url() . '/css/ui-lightness/jquery-ui.css';
43
-        } else if ( preg_match('/^http.?:\/\/.*\..*$/', $theme_css) ) {
44
-            $css_file = $theme_css;
45
-        } else {
46
-            $uploads = self::get_upload_base();
47
-            $file_path = '/formidable/css/'. $theme_css . '/jquery-ui.css';
48
-            if ( file_exists($uploads['basedir'] . $file_path) ) {
49
-                $css_file = $uploads['baseurl'] . $file_path;
50
-            } else {
51
-                $css_file = FrmAppHelper::jquery_ui_base_url() .'/themes/'. $theme_css . '/jquery-ui.min.css';
52
-            }
53
-        }
54
-
55
-        return $css_file;
56
-    }
57
-
58
-    public static function enqueue_jquery_css() {
37
+		if ( $theme_css == -1 ) {
38
+			return;
39
+		}
40
+
41
+		if ( ! $theme_css || $theme_css == '' || $theme_css == 'ui-lightness' ) {
42
+			$css_file = FrmAppHelper::plugin_url() . '/css/ui-lightness/jquery-ui.css';
43
+		} else if ( preg_match('/^http.?:\/\/.*\..*$/', $theme_css) ) {
44
+			$css_file = $theme_css;
45
+		} else {
46
+			$uploads = self::get_upload_base();
47
+			$file_path = '/formidable/css/'. $theme_css . '/jquery-ui.css';
48
+			if ( file_exists($uploads['basedir'] . $file_path) ) {
49
+				$css_file = $uploads['baseurl'] . $file_path;
50
+			} else {
51
+				$css_file = FrmAppHelper::jquery_ui_base_url() .'/themes/'. $theme_css . '/jquery-ui.min.css';
52
+			}
53
+		}
54
+
55
+		return $css_file;
56
+	}
57
+
58
+	public static function enqueue_jquery_css() {
59 59
 		$form = self::get_form_for_page();
60 60
 		$theme_css = FrmStylesController::get_style_val( 'theme_css', $form );
61
-        if ( $theme_css != -1 ) {
62
-            wp_enqueue_style('jquery-theme', self::jquery_css_url($theme_css), array(), FrmAppHelper::plugin_version());
63
-        }
64
-    }
61
+		if ( $theme_css != -1 ) {
62
+			wp_enqueue_style('jquery-theme', self::jquery_css_url($theme_css), array(), FrmAppHelper::plugin_version());
63
+		}
64
+	}
65 65
 
66 66
 	public static function get_form_for_page() {
67 67
 		global $frm_vars;
@@ -77,14 +77,14 @@  discard block
 block discarded – undo
77 77
 		return $form_id;
78 78
 	}
79 79
 
80
-    public static function get_upload_base() {
81
-        $uploads = wp_upload_dir();
82
-        if ( is_ssl() && ! preg_match('/^https:\/\/.*\..*$/', $uploads['baseurl']) ) {
83
-            $uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']);
84
-        }
80
+	public static function get_upload_base() {
81
+		$uploads = wp_upload_dir();
82
+		if ( is_ssl() && ! preg_match('/^https:\/\/.*\..*$/', $uploads['baseurl']) ) {
83
+			$uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']);
84
+		}
85 85
 
86
-        return $uploads;
87
-    }
86
+		return $uploads;
87
+	}
88 88
 
89 89
 	public static function style_menu( $active = '' ) {
90 90
 ?>
@@ -94,22 +94,22 @@  discard block
 block discarded – undo
94 94
 			<a href="<?php echo esc_url( admin_url('admin.php?page=formidable-styles&frm_action=custom_css' ) ) ?>" class="nav-tab <?php echo ( 'custom_css' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Custom CSS', 'formidable' ) ?></a>
95 95
         </h2>
96 96
 <?php
97
-    }
97
+	}
98 98
 
99
-    public static function minus_icons() {
100
-        return array(
99
+	public static function minus_icons() {
100
+		return array(
101 101
 			0 => array( '-' => '62e', '+' => '62f' ),
102 102
 			1 => array( '-' => '600', '+' => '602' ),
103 103
 			2 => array( '-' => '604', '+' => '603' ),
104 104
 			3 => array( '-' => '633', '+' => '632' ),
105 105
 			4 => array( '-' => '613', '+' => '60f' ),
106
-        );
107
-    }
106
+		);
107
+	}
108 108
 
109
-    public static function arrow_icons() {
110
-        $minus_icons = self::minus_icons();
109
+	public static function arrow_icons() {
110
+		$minus_icons = self::minus_icons();
111 111
 
112
-        return array(
112
+		return array(
113 113
 			6 => array( '-' => '62d', '+' => '62a' ),
114 114
 			0 => array( '-' => '60d', '+' => '609' ),
115 115
 			1 => array( '-' => '60e', '+' => '60c' ),
@@ -117,44 +117,44 @@  discard block
 block discarded – undo
117 117
 			3 => array( '-' => '62b', '+' => '628' ),
118 118
 			4 => array( '-' => '62c', '+' => '629' ),
119 119
 			5 => array( '-' => '635', '+' => '634' ),
120
-            'p0' => $minus_icons[0],
121
-            'p1' => $minus_icons[1],
122
-            'p2' => $minus_icons[2],
123
-            'p3' => $minus_icons[3],
124
-            'p4' => $minus_icons[4],
125
-        );
126
-    }
127
-
128
-    /**
129
-     * @since 2.0
130
-     * @return The class for this icon
131
-     */
120
+			'p0' => $minus_icons[0],
121
+			'p1' => $minus_icons[1],
122
+			'p2' => $minus_icons[2],
123
+			'p3' => $minus_icons[3],
124
+			'p4' => $minus_icons[4],
125
+		);
126
+	}
127
+
128
+	/**
129
+	 * @since 2.0
130
+	 * @return The class for this icon
131
+	 */
132 132
 	public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) {
133
-        if ( 'arrow' == $type && is_numeric($key) ) {
134
-            //frm_arrowup6_icon
133
+		if ( 'arrow' == $type && is_numeric($key) ) {
134
+			//frm_arrowup6_icon
135 135
 			$arrow = array( '-' => 'down', '+' => 'up' );
136 136
 			$class = 'frm_arrow' . $arrow[ $icon ];
137
-        } else {
138
-            //frm_minus1_icon
139
-            $key = str_replace('p', '', $key);
137
+		} else {
138
+			//frm_minus1_icon
139
+			$key = str_replace('p', '', $key);
140 140
 			$plus = array( '-' => 'minus', '+' => 'plus' );
141 141
 			$class = 'frm_' . $plus[ $icon ];
142
-        }
142
+		}
143 143
 
144
-        if ( $key ) {
145
-            $class .= $key;
146
-        }
147
-        $class .= '_icon';
144
+		if ( $key ) {
145
+			$class .= $key;
146
+		}
147
+		$class .= '_icon';
148 148
 
149
-        return $class;
150
-    }
149
+		return $class;
150
+	}
151 151
 
152 152
 	public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) {
153 153
 		$function_name = $type . '_icons';
154 154
 		$icons = self::$function_name();
155 155
 		unset( $function_name );
156 156
 
157
-        $name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
157
+		$name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
158 158
 ?>
159 159
     	<select name="<?php echo esc_attr( $frm_style->get_field_name($name) ) ?>" id="frm_<?php echo esc_attr( $name ) ?>" class="frm_icon_font frm_multiselect hide-if-js">
160 160
             <?php foreach ( $icons as $key => $icon ) { ?>
@@ -187,22 +187,22 @@  discard block
 block discarded – undo
187 187
             </ul>
188 188
         </div>
189 189
 <?php
190
-    }
190
+	}
191 191
 
192 192
 	public static function hex2rgb( $hex ) {
193
-        $hex = str_replace('#', '', $hex);
194
-
195
-        if ( strlen($hex) == 3 ) {
196
-            $r = hexdec( substr($hex,0,1).substr($hex,0,1) );
197
-            $g = hexdec( substr($hex,1,1).substr($hex,1,1) );
198
-            $b = hexdec( substr($hex,2,1).substr($hex,2,1) );
199
-        } else {
200
-            $r = hexdec( substr($hex,0,2) );
201
-            $g = hexdec( substr($hex,2,2) );
202
-            $b = hexdec( substr($hex,4,2) );
203
-        }
193
+		$hex = str_replace('#', '', $hex);
194
+
195
+		if ( strlen($hex) == 3 ) {
196
+			$r = hexdec( substr($hex,0,1).substr($hex,0,1) );
197
+			$g = hexdec( substr($hex,1,1).substr($hex,1,1) );
198
+			$b = hexdec( substr($hex,2,1).substr($hex,2,1) );
199
+		} else {
200
+			$r = hexdec( substr($hex,0,2) );
201
+			$g = hexdec( substr($hex,2,2) );
202
+			$b = hexdec( substr($hex,4,2) );
203
+		}
204 204
 		$rgb = array( $r, $g, $b );
205
-        return implode(',', $rgb); // returns the rgb values separated by commas
206
-        //return $rgb; // returns an array with the rgb values
207
-    }
205
+		return implode(',', $rgb); // returns the rgb values separated by commas
206
+		//return $rgb; // returns an array with the rgb values
207
+	}
208 208
 }
Please login to merge, or discard this patch.
classes/models/FrmDb.php 1 patch
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -1,81 +1,81 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 class FrmDb {
4
-    var $fields;
5
-    var $forms;
6
-    var $entries;
7
-    var $entry_metas;
8
-
9
-    public function __construct() {
10
-        if ( ! defined('ABSPATH') ) {
11
-            die('You are not allowed to call this page directly.');
12
-        }
13
-
14
-        global $wpdb;
15
-        $this->fields         = $wpdb->prefix . 'frm_fields';
16
-        $this->forms          = $wpdb->prefix . 'frm_forms';
17
-        $this->entries        = $wpdb->prefix . 'frm_items';
18
-        $this->entry_metas    = $wpdb->prefix . 'frm_item_metas';
19
-    }
20
-
21
-    public function upgrade( $old_db_version = false ) {
22
-        global $wpdb;
23
-        //$frm_db_version is the version of the database we're moving to
24
-        $frm_db_version = FrmAppHelper::$db_version;
25
-        $old_db_version = (float) $old_db_version;
26
-        if ( ! $old_db_version ) {
27
-            $old_db_version = get_option('frm_db_version');
28
-        }
29
-
30
-        if ( $frm_db_version != $old_db_version ) {
4
+	var $fields;
5
+	var $forms;
6
+	var $entries;
7
+	var $entry_metas;
8
+
9
+	public function __construct() {
10
+		if ( ! defined('ABSPATH') ) {
11
+			die('You are not allowed to call this page directly.');
12
+		}
13
+
14
+		global $wpdb;
15
+		$this->fields         = $wpdb->prefix . 'frm_fields';
16
+		$this->forms          = $wpdb->prefix . 'frm_forms';
17
+		$this->entries        = $wpdb->prefix . 'frm_items';
18
+		$this->entry_metas    = $wpdb->prefix . 'frm_item_metas';
19
+	}
20
+
21
+	public function upgrade( $old_db_version = false ) {
22
+		global $wpdb;
23
+		//$frm_db_version is the version of the database we're moving to
24
+		$frm_db_version = FrmAppHelper::$db_version;
25
+		$old_db_version = (float) $old_db_version;
26
+		if ( ! $old_db_version ) {
27
+			$old_db_version = get_option('frm_db_version');
28
+		}
29
+
30
+		if ( $frm_db_version != $old_db_version ) {
31 31
 			// update rewrite rules for views and other custom post types
32 32
 			flush_rewrite_rules();
33 33
 
34 34
 			require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
35 35
 
36
-            $this->create_tables();
37
-            $this->migrate_data($frm_db_version, $old_db_version);
36
+			$this->create_tables();
37
+			$this->migrate_data($frm_db_version, $old_db_version);
38 38
 
39
-            /***** SAVE DB VERSION *****/
40
-            update_option('frm_db_version', $frm_db_version);
39
+			/***** SAVE DB VERSION *****/
40
+			update_option('frm_db_version', $frm_db_version);
41 41
 
42
-            /**** ADD/UPDATE DEFAULT TEMPLATES ****/
43
-            FrmXMLController::add_default_templates();
44
-        }
42
+			/**** ADD/UPDATE DEFAULT TEMPLATES ****/
43
+			FrmXMLController::add_default_templates();
44
+		}
45 45
 
46
-        do_action('frm_after_install');
46
+		do_action('frm_after_install');
47 47
 
48
-        /**** update the styling settings ****/
48
+		/**** update the styling settings ****/
49 49
 		if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
50 50
 			$frm_style = new FrmStyle();
51 51
 			$frm_style->update( 'default' );
52 52
 		}
53
-    }
53
+	}
54 54
 
55
-    public function collation() {
56
-        global $wpdb;
57
-        if ( ! $wpdb->has_cap( 'collation' ) ) {
58
-            return '';
59
-        }
55
+	public function collation() {
56
+		global $wpdb;
57
+		if ( ! $wpdb->has_cap( 'collation' ) ) {
58
+			return '';
59
+		}
60 60
 
61
-        $charset_collate = '';
61
+		$charset_collate = '';
62 62
 		if ( ! empty( $wpdb->charset ) ) {
63 63
 			$charset_collate .= ' DEFAULT CHARACTER SET '. $wpdb->charset;
64 64
 		}
65 65
 
66
-        if ( ! empty($wpdb->collate) ) {
67
-            $charset_collate .= ' COLLATE '. $wpdb->collate;
68
-        }
66
+		if ( ! empty($wpdb->collate) ) {
67
+			$charset_collate .= ' COLLATE '. $wpdb->collate;
68
+		}
69 69
 
70
-        return $charset_collate;
71
-    }
70
+		return $charset_collate;
71
+	}
72 72
 
73
-    private function create_tables() {
74
-        $charset_collate = $this->collation();
75
-        $sql = array();
73
+	private function create_tables() {
74
+		$charset_collate = $this->collation();
75
+		$sql = array();
76 76
 
77
-        /* Create/Upgrade Fields Table */
78
-        $sql[] = 'CREATE TABLE '. $this->fields .' (
77
+		/* Create/Upgrade Fields Table */
78
+		$sql[] = 'CREATE TABLE '. $this->fields .' (
79 79
                 id int(11) NOT NULL auto_increment,
80 80
 				field_key varchar(100) default NULL,
81 81
                 name text default NULL,
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
                 UNIQUE KEY field_key (field_key)
94 94
         )';
95 95
 
96
-        /* Create/Upgrade Forms Table */
97
-        $sql[] = 'CREATE TABLE '. $this->forms .' (
96
+		/* Create/Upgrade Forms Table */
97
+		$sql[] = 'CREATE TABLE '. $this->forms .' (
98 98
                 id int(11) NOT NULL auto_increment,
99 99
 				form_key varchar(100) default NULL,
100 100
                 name varchar(255) default NULL,
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
                 UNIQUE KEY form_key (form_key)
112 112
         )';
113 113
 
114
-        /* Create/Upgrade Items Table */
115
-        $sql[] = 'CREATE TABLE '. $this->entries .' (
114
+		/* Create/Upgrade Items Table */
115
+		$sql[] = 'CREATE TABLE '. $this->entries .' (
116 116
                 id int(11) NOT NULL auto_increment,
117 117
 				item_key varchar(100) default NULL,
118 118
                 name varchar(255) default NULL,
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
                 UNIQUE KEY item_key (item_key)
135 135
         )';
136 136
 
137
-        /* Create/Upgrade Meta Table */
138
-        $sql[] = 'CREATE TABLE '. $this->entry_metas .' (
137
+		/* Create/Upgrade Meta Table */
138
+		$sql[] = 'CREATE TABLE '. $this->entry_metas .' (
139 139
                 id int(11) NOT NULL auto_increment,
140 140
                 meta_value longtext default NULL,
141 141
                 field_id int(11) NOT NULL,
@@ -146,39 +146,39 @@  discard block
 block discarded – undo
146 146
                 KEY item_id (item_id)
147 147
         )';
148 148
 
149
-        foreach ( $sql as $q ) {
149
+		foreach ( $sql as $q ) {
150 150
 			if ( function_exists( 'dbDelta' ) ) {
151 151
 				dbDelta( $q . $charset_collate .';' );
152 152
 			} else {
153 153
 				global $wpdb;
154 154
 				$wpdb->query( $q . $charset_collate );
155 155
 			}
156
-            unset($q);
157
-        }
158
-    }
156
+			unset($q);
157
+		}
158
+	}
159 159
 
160
-    /**
161
-     * @param integer $frm_db_version
162
-     */
160
+	/**
161
+	 * @param integer $frm_db_version
162
+	 */
163 163
 	private function migrate_data( $frm_db_version, $old_db_version ) {
164 164
 		$migrations = array( 4, 6, 11, 16, 17, 23, 25 );
165
-        foreach ( $migrations as $migration ) {
166
-            if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
167
-                $function_name = 'migrate_to_'. $migration;
168
-                $this->$function_name();
169
-            }
170
-        }
171
-    }
172
-
173
-    /**
174
-     * Change array into format $wpdb->prepare can use
175
-     */
176
-    public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
177
-        if ( empty($args) ) {
165
+		foreach ( $migrations as $migration ) {
166
+			if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
167
+				$function_name = 'migrate_to_'. $migration;
168
+				$this->$function_name();
169
+			}
170
+		}
171
+	}
172
+
173
+	/**
174
+	 * Change array into format $wpdb->prepare can use
175
+	 */
176
+	public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
177
+		if ( empty($args) ) {
178 178
 			// add an arg to prevent prepare from failing
179 179
 			$args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
180 180
 			return;
181
-        }
181
+		}
182 182
 
183 183
 		$where = '';
184 184
 		$values = array();
@@ -189,60 +189,60 @@  discard block
 block discarded – undo
189 189
 		}
190 190
 
191 191
 		$args = compact( 'where', 'values' );
192
-    }
193
-
194
-    /**
195
-     * @param string $base_where
196
-     * @param string $where
197
-     */
198
-    public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
199
-        $condition = ' AND';
200
-        if ( isset( $args['or'] ) ) {
201
-            $condition = ' OR';
202
-            unset( $args['or'] );
203
-        }
204
-
205
-        foreach ( $args as $key => $value ) {
206
-            $where .= empty( $where ) ? $base_where : $condition;
207
-            $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
208
-            if ( is_numeric( $key ) || $array_inc_null ) {
209
-                $where .= ' ( ';
210
-                $nested_where = '';
211
-                if ( $array_inc_null ) {
212
-                    foreach ( $value as $val ) {
213
-                        self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
214
-                    }
215
-                } else {
216
-                    self::parse_where_from_array( $value, '', $nested_where, $values );
217
-                }
218
-                $where .= $nested_where;
219
-                $where .= ' ) ';
220
-            } else {
221
-                self::interpret_array_to_sql( $key, $value, $where, $values );
222
-            }
223
-        }
224
-    }
225
-
226
-    /**
227
-     * @param string $key
228
-     * @param string $where
229
-     */
230
-    private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
192
+	}
193
+
194
+	/**
195
+	 * @param string $base_where
196
+	 * @param string $where
197
+	 */
198
+	public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
199
+		$condition = ' AND';
200
+		if ( isset( $args['or'] ) ) {
201
+			$condition = ' OR';
202
+			unset( $args['or'] );
203
+		}
204
+
205
+		foreach ( $args as $key => $value ) {
206
+			$where .= empty( $where ) ? $base_where : $condition;
207
+			$array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
208
+			if ( is_numeric( $key ) || $array_inc_null ) {
209
+				$where .= ' ( ';
210
+				$nested_where = '';
211
+				if ( $array_inc_null ) {
212
+					foreach ( $value as $val ) {
213
+						self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
214
+					}
215
+				} else {
216
+					self::parse_where_from_array( $value, '', $nested_where, $values );
217
+				}
218
+				$where .= $nested_where;
219
+				$where .= ' ) ';
220
+			} else {
221
+				self::interpret_array_to_sql( $key, $value, $where, $values );
222
+			}
223
+		}
224
+	}
225
+
226
+	/**
227
+	 * @param string $key
228
+	 * @param string $where
229
+	 */
230
+	private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
231 231
 		$key = trim( $key );
232 232
 
233
-        if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false  ) {
234
-            $k = explode(' ', $key);
235
-            $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
236
-            $values[] = '%Y-%m-%d %H:%i:%s';
237
-        } else {
238
-            $where .= ' '. $key;
239
-        }
233
+		if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false  ) {
234
+			$k = explode(' ', $key);
235
+			$where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
236
+			$values[] = '%Y-%m-%d %H:%i:%s';
237
+		} else {
238
+			$where .= ' '. $key;
239
+		}
240 240
 
241 241
 		$lowercase_key = explode( ' ', strtolower( $key ) );
242 242
 		$lowercase_key = end( $lowercase_key );
243 243
 
244
-        if ( is_array( $value ) ) {
245
-            // translate array of values to "in"
244
+		if ( is_array( $value ) ) {
245
+			// translate array of values to "in"
246 246
 			if ( strpos( $lowercase_key, 'like' ) !== false ) {
247 247
 				$where = rtrim( $where, $key );
248 248
 				$where .= '(';
@@ -257,10 +257,10 @@  discard block
 block discarded – undo
257 257
 				}
258 258
 				$where .= ')';
259 259
 			} else if ( ! empty( $value ) ) {
260
-            	$where .= ' in ('. FrmAppHelper::prepare_array_values( $value, '%s' ) .')';
260
+				$where .= ' in ('. FrmAppHelper::prepare_array_values( $value, '%s' ) .')';
261 261
 				$values = array_merge( $values, $value );
262 262
 			}
263
-        } else if ( strpos( $lowercase_key, 'like' ) !== false ) {
263
+		} else if ( strpos( $lowercase_key, 'like' ) !== false ) {
264 264
 			/**
265 265
 			 * Allow string to start or end with the value
266 266
 			 * If the key is like% then skip the first % for starts with
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 			$where .= ' %s';
280 280
 			$values[] = $start . FrmAppHelper::esc_like( $value ) . $end;
281 281
 
282
-        } else if ( $value === null ) {
283
-            $where .= ' IS NULL';
284
-        } else {
282
+		} else if ( $value === null ) {
283
+			$where .= ' IS NULL';
284
+		} else {
285 285
 			// allow a - to prevent = from being added
286 286
 			if ( substr( $key, -1 ) == '-' ) {
287 287
 				$where = rtrim( $where, '-' );
@@ -289,28 +289,28 @@  discard block
 block discarded – undo
289 289
 				$where .= '=';
290 290
 			}
291 291
 
292
-            $where .= is_numeric( $value ) ? ( strpos( $value, '.' ) !== false ? '%f' : '%d' ) : '%s';
293
-            $values[] = $value;
294
-        }
295
-    }
296
-
297
-    /**
298
-     * @param string $table
299
-     */
300
-    public static function get_count( $table, $where = array(), $args = array() ) {
301
-        $count = self::get_var( $table, $where, 'COUNT(*)', $args );
302
-        return $count;
303
-    }
304
-
305
-    public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
306
-        $group = '';
307
-        self::get_group_and_table_name( $table, $group );
292
+			$where .= is_numeric( $value ) ? ( strpos( $value, '.' ) !== false ? '%f' : '%d' ) : '%s';
293
+			$values[] = $value;
294
+		}
295
+	}
296
+
297
+	/**
298
+	 * @param string $table
299
+	 */
300
+	public static function get_count( $table, $where = array(), $args = array() ) {
301
+		$count = self::get_var( $table, $where, 'COUNT(*)', $args );
302
+		return $count;
303
+	}
304
+
305
+	public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
306
+		$group = '';
307
+		self::get_group_and_table_name( $table, $group );
308 308
 		self::convert_options_to_array( $args, '', $limit );
309 309
 
310 310
 		$query = 'SELECT ' . $field . ' FROM ' . $table;
311 311
 		if ( is_array( $where ) || empty( $where ) ) {
312 312
 			// only separate into array values and query string if is array
313
-        	self::get_where_clause_and_values( $where );
313
+			self::get_where_clause_and_values( $where );
314 314
 			global $wpdb;
315 315
 			$query = $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] );
316 316
 		} else {
@@ -322,49 +322,49 @@  discard block
 block discarded – undo
322 322
 			$query .= $where . ' ' . implode( ' ', $args );
323 323
 		}
324 324
 
325
-        $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode('_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field .'_'. $type, ' WHERE' ) );
326
-        $results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_'. $type );
327
-        return $results;
328
-    }
329
-
330
-    /**
331
-     * @param string $table
332
-     * @param array $where
333
-     */
334
-    public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
335
-        return self::get_var( $table, $where, $field, $args, $limit, 'col' );
336
-    }
337
-
338
-    /**
339
-     * @since 2.0
340
-     * @param string $table
341
-     */
342
-    public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
343
-        $args['limit'] = 1;
344
-        return self::get_var( $table, $where, $fields, $args, '', 'row' );
345
-    }
346
-
347
-    /**
348
-     * @param string $table
349
-     */
350
-    public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
351
-        _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
325
+		$cache_key = str_replace( array( ' ', ',' ), '_', trim( implode('_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field .'_'. $type, ' WHERE' ) );
326
+		$results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_'. $type );
327
+		return $results;
328
+	}
329
+
330
+	/**
331
+	 * @param string $table
332
+	 * @param array $where
333
+	 */
334
+	public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
335
+		return self::get_var( $table, $where, $field, $args, $limit, 'col' );
336
+	}
337
+
338
+	/**
339
+	 * @since 2.0
340
+	 * @param string $table
341
+	 */
342
+	public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
343
+		$args['limit'] = 1;
344
+		return self::get_var( $table, $where, $fields, $args, '', 'row' );
345
+	}
346
+
347
+	/**
348
+	 * @param string $table
349
+	 */
350
+	public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
351
+		_deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
352 352
 		return self::get_var( $table, $args, $fields, array( 'order_by' => $order_by, 'limit' => 1 ), '', 'row' );
353
-    }
354
-
355
-    public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) {
356
-        _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' );
357
-        return self::get_results( $table, $args, $fields, compact('order_by', 'limit') );
358
-    }
359
-
360
-    /**
361
-     * Prepare a key/value array before DB call
362
-     * @since 2.0
363
-     * @param string $table
364
-     */
365
-    public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
366
-        return self::get_var( $table, $where, $fields, $args, '', 'results' );
367
-    }
353
+	}
354
+
355
+	public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) {
356
+		_deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' );
357
+		return self::get_results( $table, $args, $fields, compact('order_by', 'limit') );
358
+	}
359
+
360
+	/**
361
+	 * Prepare a key/value array before DB call
362
+	 * @since 2.0
363
+	 * @param string $table
364
+	 */
365
+	public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
366
+		return self::get_var( $table, $where, $fields, $args, '', 'results' );
367
+	}
368 368
 
369 369
 	/**
370 370
 	 * Check for like, not like, in, not in, =, !=, >, <, <=, >=
@@ -400,86 +400,86 @@  discard block
 block discarded – undo
400 400
 		return '';
401 401
 	}
402 402
 
403
-    /**
404
-     * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
405
-     * Also add the wpdb->prefix to the table if it's missing
406
-     *
407
-     * @param string $table
408
-     * @param string $group
409
-     */
410
-    private static function get_group_and_table_name( &$table, &$group ) {
403
+	/**
404
+	 * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
405
+	 * Also add the wpdb->prefix to the table if it's missing
406
+	 *
407
+	 * @param string $table
408
+	 * @param string $group
409
+	 */
410
+	private static function get_group_and_table_name( &$table, &$group ) {
411 411
 		global $wpdb, $wpmuBaseTablePrefix;
412 412
 
413
-        $table_parts = explode(' ', $table);
414
-        $group = reset($table_parts);
415
-        $group = str_replace( $wpdb->prefix, '', $group );
413
+		$table_parts = explode(' ', $table);
414
+		$group = reset($table_parts);
415
+		$group = str_replace( $wpdb->prefix, '', $group );
416 416
 
417 417
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
418 418
 		$group = str_replace( $prefix, '', $group );
419 419
 
420
-        if ( $group == $table ) {
421
-            $table = $wpdb->prefix . $table;
422
-        }
420
+		if ( $group == $table ) {
421
+			$table = $wpdb->prefix . $table;
422
+		}
423 423
 
424 424
 		// switch to singular group name
425 425
 		$group = rtrim( $group, 's' );
426
-    }
426
+	}
427 427
 
428
-    private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
429
-        if ( ! is_array($args) ) {
428
+	private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
429
+		if ( ! is_array($args) ) {
430 430
 			$args = array( 'order_by' => $args );
431
-        }
431
+		}
432 432
 
433
-        if ( ! empty( $order_by ) ) {
434
-            $args['order_by'] = $order_by;
435
-        }
433
+		if ( ! empty( $order_by ) ) {
434
+			$args['order_by'] = $order_by;
435
+		}
436 436
 
437
-        if ( ! empty( $limit ) ) {
438
-            $args['limit'] = $limit;
439
-        }
437
+		if ( ! empty( $limit ) ) {
438
+			$args['limit'] = $limit;
439
+		}
440 440
 
441
-        $temp_args = $args;
442
-        foreach ( $temp_args as $k => $v ) {
443
-            if ( $v == '' ) {
441
+		$temp_args = $args;
442
+		foreach ( $temp_args as $k => $v ) {
443
+			if ( $v == '' ) {
444 444
 				unset( $args[ $k ] );
445
-                continue;
446
-            }
445
+				continue;
446
+			}
447 447
 
448
-            if ( $k == 'limit' ) {
448
+			if ( $k == 'limit' ) {
449 449
 				$args[ $k ] = FrmAppHelper::esc_limit( $v );
450
-            }
451
-            $db_name = strtoupper( str_replace( '_', ' ', $k ) );
452
-            if ( strpos( $v, $db_name ) === false ) {
450
+			}
451
+			$db_name = strtoupper( str_replace( '_', ' ', $k ) );
452
+			if ( strpos( $v, $db_name ) === false ) {
453 453
 				$args[ $k ] = $db_name . ' ' . $v;
454
-            }
455
-        }
456
-    }
454
+			}
455
+		}
456
+	}
457 457
 
458
-    public function uninstall() {
458
+	public function uninstall() {
459 459
 		if ( ! current_user_can( 'administrator' ) ) {
460
-            $frm_settings = FrmAppHelper::get_settings();
461
-            wp_die($frm_settings->admin_permission);
462
-        }
463
-
464
-        global $wpdb, $wp_roles;
465
-
466
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->fields );
467
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->forms );
468
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->entries );
469
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->entry_metas );
470
-
471
-        delete_option('frm_options');
472
-        delete_option('frm_db_version');
473
-
474
-        //delete roles
475
-        $frm_roles = FrmAppHelper::frm_capabilities();
476
-        $roles = get_editable_roles();
477
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
478
-            foreach ( $roles as $role => $details ) {
479
-                $wp_roles->remove_cap( $role, $frm_role );
480
-                unset($role, $details);
481
-    		}
482
-    		unset($frm_role, $frm_role_description);
460
+			$frm_settings = FrmAppHelper::get_settings();
461
+			wp_die($frm_settings->admin_permission);
462
+		}
463
+
464
+		global $wpdb, $wp_roles;
465
+
466
+		$wpdb->query( 'DROP TABLE IF EXISTS '. $this->fields );
467
+		$wpdb->query( 'DROP TABLE IF EXISTS '. $this->forms );
468
+		$wpdb->query( 'DROP TABLE IF EXISTS '. $this->entries );
469
+		$wpdb->query( 'DROP TABLE IF EXISTS '. $this->entry_metas );
470
+
471
+		delete_option('frm_options');
472
+		delete_option('frm_db_version');
473
+
474
+		//delete roles
475
+		$frm_roles = FrmAppHelper::frm_capabilities();
476
+		$roles = get_editable_roles();
477
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
478
+			foreach ( $roles as $role => $details ) {
479
+				$wp_roles->remove_cap( $role, $frm_role );
480
+				unset($role, $details);
481
+			}
482
+			unset($frm_role, $frm_role_description);
483 483
 		}
484 484
 		unset($roles, $frm_roles);
485 485
 
@@ -503,9 +503,9 @@  discard block
 block discarded – undo
503 503
 
504 504
 		$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_%' ) );
505 505
 
506
-        do_action('frm_after_uninstall');
507
-        return true;
508
-    }
506
+		do_action('frm_after_uninstall');
507
+		return true;
508
+	}
509 509
 
510 510
 	/**
511 511
 	 * Migrate old styling settings. If sites are using the old
@@ -544,150 +544,150 @@  discard block
 block discarded – undo
544 544
 		}
545 545
 	}
546 546
 
547
-    /**
548
-     * Change field size from character to pixel -- Multiply by 9
549
-     */
550
-    private function migrate_to_17() {
551
-        global $wpdb;
547
+	/**
548
+	 * Change field size from character to pixel -- Multiply by 9
549
+	 */
550
+	private function migrate_to_17() {
551
+		global $wpdb;
552 552
 		$pixel_conversion = 9;
553 553
 
554
-        // Get query arguments
554
+		// Get query arguments
555 555
 		$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
556 556
 		$query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' );
557 557
 
558
-        // Get results
558
+		// Get results
559 559
 		$fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
560 560
 
561
-        $updated = 0;
562
-        foreach ( $fields as $f ) {
563
-            $f->field_options = maybe_unserialize($f->field_options);
564
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
565
-                continue;
566
-            }
561
+		$updated = 0;
562
+		foreach ( $fields as $f ) {
563
+			$f->field_options = maybe_unserialize($f->field_options);
564
+			if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
565
+				continue;
566
+			}
567 567
 
568 568
 			$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] );
569
-            $f->field_options['size'] .= 'px';
570
-            $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
571
-            if ( $u ) {
572
-                $updated++;
573
-            }
574
-            unset($f);
575
-        }
576
-
577
-        // Change the characters in widgets to pixels
578
-        $widgets = get_option('widget_frm_show_form');
579
-        if ( empty($widgets) ) {
580
-            return;
581
-        }
582
-
583
-        $widgets = maybe_unserialize($widgets);
584
-        foreach ( $widgets as $k => $widget ) {
585
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
586
-                continue;
587
-            }
569
+			$f->field_options['size'] .= 'px';
570
+			$u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
571
+			if ( $u ) {
572
+				$updated++;
573
+			}
574
+			unset($f);
575
+		}
576
+
577
+		// Change the characters in widgets to pixels
578
+		$widgets = get_option('widget_frm_show_form');
579
+		if ( empty($widgets) ) {
580
+			return;
581
+		}
582
+
583
+		$widgets = maybe_unserialize($widgets);
584
+		foreach ( $widgets as $k => $widget ) {
585
+			if ( ! is_array($widget) || ! isset($widget['size']) ) {
586
+				continue;
587
+			}
588 588
 			$size = round( $pixel_conversion * (int) $widget['size'] );
589
-            $size .= 'px';
589
+			$size .= 'px';
590 590
 			$widgets[ $k ]['size'] = $size;
591
-        }
592
-        update_option('widget_frm_show_form', $widgets);
593
-    }
594
-
595
-    /**
596
-     * Migrate post and email notification settings into actions
597
-     */
598
-    private function migrate_to_16() {
599
-        global $wpdb;
600
-
601
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
602
-
603
-        /**
604
-        * Old email settings format:
605
-        * email_to: Email or field id
606
-        * also_email_to: array of fields ids
607
-        * reply_to: Email, field id, 'custom'
608
-        * cust_reply_to: string
609
-        * reply_to_name: field id, 'custom'
610
-        * cust_reply_to_name: string
611
-        * plain_text: 0|1
612
-        * email_message: string or ''
613
-        * email_subject: string or ''
614
-        * inc_user_info: 0|1
615
-        * update_email: 0, 1, 2
616
-        *
617
-        * Old autoresponder settings format:
618
-        * auto_responder: 0|1
619
-        * ar_email_message: string or ''
620
-        * ar_email_to: field id
621
-        * ar_plain_text: 0|1
622
-        * ar_reply_to_name: string
623
-        * ar_reply_to: string
624
-        * ar_email_subject: string
625
-        * ar_update_email: 0, 1, 2
626
-        *
627
-        * New email settings:
628
-        * post_content: json settings
629
-        * post_title: form id
630
-        * post_excerpt: message
631
-        *
632
-        */
633
-
634
-        foreach ( $forms as $form ) {
591
+		}
592
+		update_option('widget_frm_show_form', $widgets);
593
+	}
594
+
595
+	/**
596
+	 * Migrate post and email notification settings into actions
597
+	 */
598
+	private function migrate_to_16() {
599
+		global $wpdb;
600
+
601
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
602
+
603
+		/**
604
+		 * Old email settings format:
605
+		 * email_to: Email or field id
606
+		 * also_email_to: array of fields ids
607
+		 * reply_to: Email, field id, 'custom'
608
+		 * cust_reply_to: string
609
+		 * reply_to_name: field id, 'custom'
610
+		 * cust_reply_to_name: string
611
+		 * plain_text: 0|1
612
+		 * email_message: string or ''
613
+		 * email_subject: string or ''
614
+		 * inc_user_info: 0|1
615
+		 * update_email: 0, 1, 2
616
+		 *
617
+		 * Old autoresponder settings format:
618
+		 * auto_responder: 0|1
619
+		 * ar_email_message: string or ''
620
+		 * ar_email_to: field id
621
+		 * ar_plain_text: 0|1
622
+		 * ar_reply_to_name: string
623
+		 * ar_reply_to: string
624
+		 * ar_email_subject: string
625
+		 * ar_update_email: 0, 1, 2
626
+		 *
627
+		 * New email settings:
628
+		 * post_content: json settings
629
+		 * post_title: form id
630
+		 * post_excerpt: message
631
+		 *
632
+		 */
633
+
634
+		foreach ( $forms as $form ) {
635 635
 			if ( $form->is_template && $form->default_template ) {
636 636
 				// don't migrate the default templates since the email will be added anyway
637 637
 				continue;
638 638
 			}
639 639
 
640
-            // Format form options
641
-            $form_options = maybe_unserialize($form->options);
640
+			// Format form options
641
+			$form_options = maybe_unserialize($form->options);
642 642
 
643
-            // Migrate settings to actions
644
-            FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
645
-        }
646
-    }
643
+			// Migrate settings to actions
644
+			FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
645
+		}
646
+	}
647 647
 
648
-    private function migrate_to_11() {
649
-        global $wpdb;
648
+	private function migrate_to_11() {
649
+		global $wpdb;
650 650
 
651
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
651
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options');
652 652
 
653
-        $sending = __( 'Sending', 'formidable' );
654
-        $img = FrmAppHelper::plugin_url() .'/images/ajax_loader.gif';
655
-        $old_default_html = <<<DEFAULT_HTML
653
+		$sending = __( 'Sending', 'formidable' );
654
+		$img = FrmAppHelper::plugin_url() .'/images/ajax_loader.gif';
655
+		$old_default_html = <<<DEFAULT_HTML
656 656
 <div class="frm_submit">
657 657
 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
658 658
 <input type="submit" value="[button_label]" [button_action] />
659 659
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
660 660
 </div>
661 661
 DEFAULT_HTML;
662
-        unset($sending, $img);
662
+		unset($sending, $img);
663 663
 
664
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
665
-        $draft_link = FrmFormsHelper::get_draft_link();
664
+		$new_default_html = FrmFormsHelper::get_default_html('submit');
665
+		$draft_link = FrmFormsHelper::get_draft_link();
666 666
 		foreach ( $forms as $form ) {
667
-            $form->options = maybe_unserialize($form->options);
668
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
669
-                continue;
670
-            }
667
+			$form->options = maybe_unserialize($form->options);
668
+			if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
669
+				continue;
670
+			}
671 671
 
672
-            if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
673
-                $form->options['submit_html'] = $new_default_html;
672
+			if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
673
+				$form->options['submit_html'] = $new_default_html;
674 674
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
675 675
 			} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
676
-                $form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
676
+				$form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
677 677
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
678
-            }
679
-            unset($form);
680
-        }
681
-        unset($forms);
682
-    }
678
+			}
679
+			unset($form);
680
+		}
681
+		unset($forms);
682
+	}
683 683
 
684
-    private function migrate_to_6() {
685
-        global $wpdb;
684
+	private function migrate_to_6() {
685
+		global $wpdb;
686 686
 
687 687
 		$no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
688 688
 		$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' );
689 689
 
690
-        $default_html = <<<DEFAULT_HTML
690
+		$default_html = <<<DEFAULT_HTML
691 691
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
692 692
     <label class="frm_pos_[label_position]">[field_name]
693 693
         <span class="frm_required">[required_label]</span>
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 </div>
698 698
 DEFAULT_HTML;
699 699
 
700
-        $old_default_html = <<<DEFAULT_HTML
700
+		$old_default_html = <<<DEFAULT_HTML
701 701
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
702 702
     <label class="frm_pos_[label_position]">[field_name]
703 703
         <span class="frm_required">[required_label]</span>
@@ -707,23 +707,23 @@  discard block
 block discarded – undo
707 707
 </div>
708 708
 DEFAULT_HTML;
709 709
 
710
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
711
-        foreach ( $fields as $field ) {
712
-            $field->field_options = maybe_unserialize($field->field_options);
710
+		$new_default_html = FrmFieldsHelper::get_default_html('text');
711
+		foreach ( $fields as $field ) {
712
+			$field->field_options = maybe_unserialize($field->field_options);
713 713
 			if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
714
-                $field->field_options['custom_html'] = $new_default_html;
714
+				$field->field_options['custom_html'] = $new_default_html;
715 715
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
716
-            }
717
-            unset($field);
718
-        }
719
-        unset($default_html, $old_default_html, $fields);
720
-    }
721
-
722
-    private function migrate_to_4() {
723
-        global $wpdb;
716
+			}
717
+			unset($field);
718
+		}
719
+		unset($default_html, $old_default_html, $fields);
720
+	}
721
+
722
+	private function migrate_to_4() {
723
+		global $wpdb;
724 724
 		$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
725
-        foreach ( $user_ids as $user_id ) {
725
+		foreach ( $user_ids as $user_id ) {
726 726
 			$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) );
727
-        }
728
-    }
727
+		}
728
+	}
729 729
 }
Please login to merge, or discard this patch.
classes/models/FrmEntryFormat.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -126,19 +126,19 @@
 block discarded – undo
126 126
 	}
127 127
 
128 128
 	/**
129
-	* Flatten multi-dimensional array for multi-file upload fields
130
-	* @since 2.0.9
131
-	*/
129
+	 * Flatten multi-dimensional array for multi-file upload fields
130
+	 * @since 2.0.9
131
+	 */
132 132
 	public static function flatten_multi_file_upload( $field, &$val ) {
133 133
 		if ( $field->type == 'file' && FrmField::is_option_true( $field, 'multiple' ) ) {
134 134
 			$val = FrmAppHelper::array_flatten( $val );
135 135
 		}
136 136
 	}
137 137
 
138
-    /**
139
-     * Replace returns with HTML line breaks for display
140
-     * @since 2.0.9
141
-     */
138
+	/**
139
+	 * Replace returns with HTML line breaks for display
140
+	 * @since 2.0.9
141
+	 */
142 142
 	public static function textarea_display_value( $type, $plain_text, &$value ) {
143 143
 		if ( $type == 'textarea' && ! $plain_text ) {
144 144
 			$value = str_replace( array( "\r\n", "\r", "\n" ), ' <br/>', $value );
Please login to merge, or discard this patch.
classes/models/FrmField.php 1 patch
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 }
5 5
 
6 6
 class FrmField {
7
-    static $use_cache = true;
7
+	static $use_cache = true;
8 8
 	static $transient_size = 200;
9 9
 
10 10
 	public static function field_selection() {
@@ -52,41 +52,41 @@  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'];
60
-        $new_values['field_key'] = FrmAppHelper::get_unique_key($key, $wpdb->prefix .'frm_fields', 'field_key');
58
+		$new_values = array();
59
+		$key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
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
-        $query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values );
89
+		$query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values );
90 90
 		$new_id = 0;
91 91
 		if ( $query_results ) {
92 92
 			self::delete_form_transient( $new_values['form_id'] );
@@ -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,26 +139,26 @@  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
 
155 155
 		if ( isset( $values['field_key'] ) ) {
156
-            $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id);
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_phone_format_backslashes( $values );
164 164
 
@@ -169,43 +169,43 @@  discard block
 block discarded – undo
169 169
 			}
170 170
 		}
171 171
 
172
-        $query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) );
172
+		$query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) );
173 173
 
174
-        $form_id = 0;
174
+		$form_id = 0;
175 175
 		if ( isset( $values['form_id'] ) ) {
176
-            $form_id = absint( $values['form_id'] );
176
+			$form_id = absint( $values['form_id'] );
177 177
 		} else {
178
-            $field = self::getOne($id);
179
-            if ( $field ) {
180
-                $form_id = $field->form_id;
181
-            }
182
-            unset($field);
183
-        }
184
-        unset($values);
178
+			$field = self::getOne($id);
179
+			if ( $field ) {
180
+				$form_id = $field->form_id;
181
+			}
182
+			unset($field);
183
+		}
184
+		unset($values);
185 185
 
186 186
 		if ( $query_results ) {
187
-            wp_cache_delete( $id, 'frm_field' );
188
-            if ( $form_id ) {
189
-                self::delete_form_transient($form_id);
190
-            }
191
-        }
187
+			wp_cache_delete( $id, 'frm_field' );
188
+			if ( $form_id ) {
189
+				self::delete_form_transient($form_id);
190
+			}
191
+		}
192 192
 
193
-        return $query_results;
194
-    }
193
+		return $query_results;
194
+	}
195 195
 
196 196
 	/**
197
-	* Keep backslashes in the phone format option
198
-	*
199
-	* @since 2.0.8
200
-	* @param $values array - pass by reference
201
-	*/
197
+	 * Keep backslashes in the phone format option
198
+	 *
199
+	 * @since 2.0.8
200
+	 * @param $values array - pass by reference
201
+	 */
202 202
 	private static function preserve_phone_format_backslashes( &$values ) {
203 203
 		if ( isset( $values['field_options']['format'] ) ) {
204 204
 			$values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
205 205
 		}
206 206
 	}
207 207
 
208
-    public static function destroy( $id ) {
208
+	public static function destroy( $id ) {
209 209
 		global $wpdb;
210 210
 
211 211
 		do_action( 'frm_before_destroy_field', $id );
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 
221 221
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
222 222
 		return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
223
-    }
223
+	}
224 224
 
225 225
 	public static function delete_form_transient( $form_id ) {
226 226
 		$form_id = absint( $form_id );
@@ -233,16 +233,16 @@  discard block
 block discarded – undo
233 233
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM '. $wpdb->options .' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id .'ex%', '_transient_frm_form_fields_' . $form_id .'ex%', '_transient_timeout_frm_form_fields_' . $form_id .'in%', '_transient_frm_form_fields_' . $form_id .'in%' ) );
234 234
 
235 235
 		$cache_key = serialize( array( 'fi.form_id' => $form_id ) ) . 'field_orderlb';
236
-        wp_cache_delete($cache_key, 'frm_field');
236
+		wp_cache_delete($cache_key, 'frm_field');
237 237
 
238 238
 		// this cache key is autogenerated in FrmDb::get_var
239 239
 		wp_cache_delete( '(__fi.form_id=%d_OR_fr.parent_form_id=%d_)__' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field' );
240 240
 
241
-        $form = FrmForm::getOne($form_id);
242
-        if ( $form && $form->parent_form_id ) {
243
-            self::delete_form_transient( $form->parent_form_id );
244
-        }
245
-    }
241
+		$form = FrmForm::getOne($form_id);
242
+		if ( $form && $form->parent_form_id ) {
243
+			self::delete_form_transient( $form->parent_form_id );
244
+		}
245
+	}
246 246
 
247 247
 	/**
248 248
 	 * If $field is numeric, get the field object
@@ -258,131 +258,131 @@  discard block
 block discarded – undo
258 258
 			return;
259 259
 		}
260 260
 
261
-        global $wpdb;
261
+		global $wpdb;
262 262
 
263
-        $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
264
-        $query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_fields WHERE '. $where, $id);
263
+		$where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
264
+		$query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_fields WHERE '. $where, $id);
265 265
 
266
-        $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
266
+		$results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
267 267
 
268
-        if ( empty($results) ) {
269
-            return $results;
270
-        }
268
+		if ( empty($results) ) {
269
+			return $results;
270
+		}
271 271
 
272
-        if ( is_numeric($id) ) {
273
-            wp_cache_set( $results->field_key, $results, 'frm_field' );
274
-        } else if ( $results ) {
275
-            wp_cache_set( $results->id, $results, 'frm_field' );
276
-        }
272
+		if ( is_numeric($id) ) {
273
+			wp_cache_set( $results->field_key, $results, 'frm_field' );
274
+		} else if ( $results ) {
275
+			wp_cache_set( $results->id, $results, 'frm_field' );
276
+		}
277 277
 
278 278
 		self::prepare_options( $results );
279 279
 
280
-        return stripslashes_deep($results);
281
-    }
280
+		return stripslashes_deep($results);
281
+	}
282 282
 
283
-    /**
284
-     * Get the field type by key or id
285
-     * @param int|string The field id or key
283
+	/**
284
+	 * Get the field type by key or id
285
+	 * @param int|string The field id or key
286 286
 	 * @param mixed $col The name of the column in the fields database table
287
-     */
288
-    public static function &get_type( $id, $col = 'type' ) {
289
-        $field = FrmAppHelper::check_cache( $id, 'frm_field' );
290
-        if ( $field ) {
291
-            $type = $field->{$col};
292
-        } else {
293
-            $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col );
294
-        }
295
-
296
-        return $type;
297
-    }
287
+	 */
288
+	public static function &get_type( $id, $col = 'type' ) {
289
+		$field = FrmAppHelper::check_cache( $id, 'frm_field' );
290
+		if ( $field ) {
291
+			$type = $field->{$col};
292
+		} else {
293
+			$type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col );
294
+		}
295
+
296
+		return $type;
297
+	}
298 298
 
299 299
 	public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
300
-        if ( ! $form_id ) {
301
-            return array();
302
-        }
300
+		if ( ! $form_id ) {
301
+			return array();
302
+		}
303 303
 
304 304
 		$results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_sub, 'inc_repeat' => $inc_sub ) );
305 305
 		if ( ! empty( $results ) ) {
306
-            $fields = array();
307
-            $count = 0;
308
-            foreach ( $results as $result ) {
309
-                if ( $type != $result->type ) {
310
-                    continue;
311
-                }
306
+			$fields = array();
307
+			$count = 0;
308
+			foreach ( $results as $result ) {
309
+				if ( $type != $result->type ) {
310
+					continue;
311
+				}
312 312
 
313 313
 				$fields[ $result->id ] = $result;
314
-                $count++;
315
-                if ( $limit == 1 ) {
316
-                    $fields = $result;
317
-                    break;
318
-                }
314
+				$count++;
315
+				if ( $limit == 1 ) {
316
+					$fields = $result;
317
+					break;
318
+				}
319 319
 
320
-                if ( ! empty($limit) && $count >= $limit ) {
321
-                    break;
322
-                }
320
+				if ( ! empty($limit) && $count >= $limit ) {
321
+					break;
322
+				}
323 323
 
324
-                unset($result);
325
-            }
326
-            return stripslashes_deep($fields);
327
-        }
324
+				unset($result);
325
+			}
326
+			return stripslashes_deep($fields);
327
+		}
328 328
 
329
-        self::$use_cache = false;
329
+		self::$use_cache = false;
330 330
 
331 331
 		$where = array( 'fi.form_id' => (int) $form_id, 'fi.type' => $type );
332 332
 		self::maybe_include_repeating_fields( $inc_sub, $where );
333 333
 		$results = self::getAll( $where, 'field_order', $limit );
334
-        self::$use_cache = true;
335
-        self::include_sub_fields($results, $inc_sub, $type);
334
+		self::$use_cache = true;
335
+		self::include_sub_fields($results, $inc_sub, $type);
336 336
 
337
-        return $results;
338
-    }
337
+		return $results;
338
+	}
339 339
 
340 340
 	public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
341
-        if ( ! (int) $form_id ) {
342
-            return array();
343
-        }
341
+		if ( ! (int) $form_id ) {
342
+			return array();
343
+		}
344 344
 
345 345
 		$results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
346 346
 		if ( ! empty( $results ) ) {
347
-            if ( empty($limit) ) {
347
+			if ( empty($limit) ) {
348 348
 				return $results;
349
-            }
349
+			}
350 350
 
351
-            $fields = array();
352
-            $count = 0;
353
-            foreach ( $results as $result ) {
351
+			$fields = array();
352
+			$count = 0;
353
+			foreach ( $results as $result ) {
354 354
 				$fields[ $result->id ] = $result;
355
-                if ( ! empty($limit) && $count >= $limit ) {
356
-                    break;
357
-                }
358
-            }
355
+				if ( ! empty($limit) && $count >= $limit ) {
356
+					break;
357
+				}
358
+			}
359 359
 
360 360
 			return $fields;
361
-        }
361
+		}
362 362
 
363
-        self::$use_cache = false;
363
+		self::$use_cache = false;
364 364
 
365 365
 		$where = array( 'fi.form_id' => absint( $form_id ) );
366 366
 		self::maybe_include_repeating_fields( $inc_repeat, $where );
367 367
 		$results = self::getAll( $where, 'field_order', $limit );
368 368
 
369
-        self::$use_cache = true;
369
+		self::$use_cache = true;
370 370
 
371 371
 		self::include_sub_fields( $results, $inc_embed, 'all' );
372 372
 
373
-        if ( empty($limit) ) {
373
+		if ( empty($limit) ) {
374 374
 			self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
375
-        }
375
+		}
376 376
 
377 377
 		return $results;
378
-    }
378
+	}
379 379
 
380 380
 	/**
381
-	* If repeating fields should be included, adjust $where accordingly
382
-	*
383
-	* @param string $inc_repeat
384
-	* @param array $where - pass by reference
385
-	*/
381
+	 * If repeating fields should be included, adjust $where accordingly
382
+	 *
383
+	 * @param string $inc_repeat
384
+	 * @param array $where - pass by reference
385
+	 */
386 386
 	private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
387 387
 		if ( $inc_repeat == 'include' ) {
388 388
 			$form_id = $where['fi.form_id'];
@@ -393,77 +393,77 @@  discard block
 block discarded – undo
393 393
 
394 394
 	public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) {
395 395
 		if ( 'include' != $inc_embed ) {
396
-            return;
397
-        }
396
+			return;
397
+		}
398 398
 
399
-        $form_fields = $results;
399
+		$form_fields = $results;
400 400
 		$index_offset = 1;
401
-        foreach ( $form_fields as $k => $field ) {
402
-            if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
403
-                continue;
404
-            }
405
-
406
-            if ( $type == 'all' ) {
407
-                $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
408
-            } else {
409
-                $sub_fields = self::get_all_types_in_form($field->form_id, $type);
410
-            }
411
-
412
-            if ( ! empty($sub_fields) ) {
401
+		foreach ( $form_fields as $k => $field ) {
402
+			if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
403
+				continue;
404
+			}
405
+
406
+			if ( $type == 'all' ) {
407
+				$sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
408
+			} else {
409
+				$sub_fields = self::get_all_types_in_form($field->form_id, $type);
410
+			}
411
+
412
+			if ( ! empty($sub_fields) ) {
413 413
 				$index = $k + $index_offset;
414 414
 				$index_offset += count( $sub_fields );
415 415
 				array_splice($results, $index, 0, $sub_fields);
416
-            }
417
-            unset($field, $sub_fields);
418
-        }
419
-    }
416
+			}
417
+			unset($field, $sub_fields);
418
+		}
419
+	}
420 420
 
421 421
 	public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) {
422
-        $cache_key = maybe_serialize($where) . $order_by .'l'. $limit .'b'. $blog_id;
423
-        if ( self::$use_cache ) {
424
-            // make sure old cache doesn't get saved as a transient
425
-            $results = wp_cache_get($cache_key, 'frm_field');
426
-            if ( false !== $results ) {
427
-                return stripslashes_deep($results);
428
-            }
429
-        }
430
-
431
-        global $wpdb;
432
-
433
-        if ( $blog_id && is_multisite() ) {
434
-            global $wpmuBaseTablePrefix;
435
-            if ( $wpmuBaseTablePrefix ) {
436
-                $prefix = $wpmuBaseTablePrefix . $blog_id .'_';
437
-            } else {
438
-                $prefix = $wpdb->get_blog_prefix( $blog_id );
439
-            }
440
-
441
-            $table_name = $prefix .'frm_fields';
442
-            $form_table_name = $prefix .'frm_forms';
422
+		$cache_key = maybe_serialize($where) . $order_by .'l'. $limit .'b'. $blog_id;
423
+		if ( self::$use_cache ) {
424
+			// make sure old cache doesn't get saved as a transient
425
+			$results = wp_cache_get($cache_key, 'frm_field');
426
+			if ( false !== $results ) {
427
+				return stripslashes_deep($results);
428
+			}
429
+		}
430
+
431
+		global $wpdb;
432
+
433
+		if ( $blog_id && is_multisite() ) {
434
+			global $wpmuBaseTablePrefix;
435
+			if ( $wpmuBaseTablePrefix ) {
436
+				$prefix = $wpmuBaseTablePrefix . $blog_id .'_';
437
+			} else {
438
+				$prefix = $wpdb->get_blog_prefix( $blog_id );
439
+			}
440
+
441
+			$table_name = $prefix .'frm_fields';
442
+			$form_table_name = $prefix .'frm_forms';
443 443
 		} else {
444
-            $table_name = $wpdb->prefix .'frm_fields';
445
-            $form_table_name = $wpdb->prefix .'frm_forms';
446
-        }
444
+			$table_name = $wpdb->prefix .'frm_fields';
445
+			$form_table_name = $wpdb->prefix .'frm_forms';
446
+		}
447 447
 
448 448
 		if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
449
-            $order_by = ' ORDER BY '. $order_by;
449
+			$order_by = ' ORDER BY '. $order_by;
450 450
 		}
451 451
 
452
-        $limit = FrmAppHelper::esc_limit($limit);
452
+		$limit = FrmAppHelper::esc_limit($limit);
453 453
 
454
-        $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";
455
-        $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
454
+		$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";
455
+		$query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
456 456
 
457
-        if ( is_array($where) ) {
458
-            $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 );
457
+		if ( is_array($where) ) {
458
+			$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 );
459 459
 		} else {
460 460
 			// if the query is not an array, then it has already been prepared
461
-            $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
461
+			$query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
462 462
 
463 463
 			$function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
464 464
 			$results = $wpdb->$function_name( $query );
465
-        }
466
-        unset( $where );
465
+		}
466
+		unset( $where );
467 467
 
468 468
 		self::format_field_results( $results );
469 469
 
@@ -562,21 +562,21 @@  discard block
 block discarded – undo
562 562
 
563 563
 	public static function getIds( $where = '', $order_by = '', $limit = '' ) {
564 564
 		_deprecated_function( __FUNCTION__, '2.0' );
565
-        global $wpdb;
566
-        if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) {
567
-            $order_by = ' ORDER BY '. $order_by;
568
-        }
565
+		global $wpdb;
566
+		if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) {
567
+			$order_by = ' ORDER BY '. $order_by;
568
+		}
569 569
 
570
-        $query = 'SELECT fi.id  FROM '. $wpdb->prefix .'frm_fields fi ' .
571
-                 'LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON fi.form_id=fr.id' .
572
-                 FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
570
+		$query = 'SELECT fi.id  FROM '. $wpdb->prefix .'frm_fields fi ' .
571
+				 'LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON fi.form_id=fr.id' .
572
+				 FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
573 573
 
574
-        $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col';
575
-        $cache_key = 'getIds_'. maybe_serialize($where) . $order_by . $limit;
576
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
574
+		$method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col';
575
+		$cache_key = 'getIds_'. maybe_serialize($where) . $order_by . $limit;
576
+		$results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
577 577
 
578
-        return $results;
579
-    }
578
+		return $results;
579
+	}
580 580
 
581 581
 	public static function is_no_save_field( $type ) {
582 582
 		return in_array( $type, self::no_save_fields() );
@@ -681,8 +681,8 @@  discard block
 block discarded – undo
681 681
 	}
682 682
 
683 683
 	/**
684
-	* @since 2.0.09
685
-	*/
684
+	 * @since 2.0.09
685
+	 */
686 686
 	public static function is_repeating_field( $field ) {
687 687
 		if ( is_array( $field ) ) {
688 688
 			$is_repeating_field = ( 'divider' == $field['type'] );
@@ -692,12 +692,12 @@  discard block
 block discarded – undo
692 692
 		return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
693 693
 	}
694 694
 
695
-    /**
696
-     * @param string $key
697
-     * @return int field id
698
-     */
695
+	/**
696
+	 * @param string $key
697
+	 * @return int field id
698
+	 */
699 699
 	public static function get_id_by_key( $key ) {
700
-        $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
701
-        return $id;
702
-    }
700
+		$id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
701
+		return $id;
702
+	}
703 703
 }
Please login to merge, or discard this patch.
classes/models/FrmForm.php 1 patch
Indentation   +365 added lines, -365 removed lines patch added patch discarded remove patch
@@ -1,376 +1,376 @@  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;
13
-
14
-        $new_values = array(
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,
8
+	/**
9
+	 * @return int|boolean id on success or false on failure
10
+	 */
11
+	public static function create( $values ) {
12
+		global $wpdb;
13
+
14
+		$new_values = array(
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,
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
-        $options = array();
27
+		$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
-        $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
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
-    }
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;
55
-
56
-        $values = self::getOne( $id, $blog_id );
57
-        if ( ! $values ) {
58
-            return false;
59
-        }
60
-
61
-        $new_key = $copy_keys ? $values->form_key : '';
62
-
63
-        $new_values = array(
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
-        }
87
-
88
-        $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
89
-
90
-        if ( $query_results ) {
47
+		return $id;
48
+	}
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;
55
+
56
+		$values = self::getOne( $id, $blog_id );
57
+		if ( ! $values ) {
58
+			return false;
59
+		}
60
+
61
+		$new_key = $copy_keys ? $values->form_key : '';
62
+
63
+		$new_values = array(
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
+		}
87
+
88
+		$query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
89
+
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
-        $new_opts = $values['options'] = maybe_unserialize($values['options']);
106
+		$new_opts = $values['options'] = maybe_unserialize($values['options']);
107 107
 
108
-        if ( isset($new_opts['success_msg']) ) {
109
-            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
110
-        }
108
+		if ( isset($new_opts['success_msg']) ) {
109
+			$new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
110
+		}
111 111
 
112
-        $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
112
+		$new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
113 113
 
114
-        if ( $new_opts != $values['options'] ) {
115
-            global $wpdb;
114
+		if ( $new_opts != $values['options'] ) {
115
+			global $wpdb;
116 116
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
117
-        }
118
-    }
117
+		}
118
+	}
119 119
 
120
-    /**
121
-     * @return int|boolean
122
-     */
123
-    public static function update( $id, $values, $create_link = false ) {
124
-        global $wpdb;
120
+	/**
121
+	 * @return int|boolean
122
+	 */
123
+	public static function update( $id, $values, $create_link = false ) {
124
+		global $wpdb;
125 125
 
126
-        if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
127
-            $values['status'] = 'published';
128
-        }
126
+		if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
127
+			$values['status'] = 'published';
128
+		}
129 129
 
130
-        if ( isset($values['form_key']) ) {
131
-            $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id);
132
-        }
130
+		if ( isset($values['form_key']) ) {
131
+			$values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id);
132
+		}
133 133
 
134
-        $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
134
+		$form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
135 135
 
136
-        $new_values = self::set_update_options( array(), $values);
136
+		$new_values = self::set_update_options( array(), $values);
137 137
 
138
-        foreach ( $values as $value_key => $value ) {
139
-            if ( in_array($value_key, $form_fields) ) {
138
+		foreach ( $values as $value_key => $value ) {
139
+			if ( in_array($value_key, $form_fields) ) {
140 140
 				$new_values[ $value_key ] = $value;
141
-            }
142
-        }
141
+			}
142
+		}
143 143
 
144
-        if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
145
-            $new_values['status'] = $values['new_status'];
146
-        }
144
+		if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
145
+			$new_values['status'] = $values['new_status'];
146
+		}
147 147
 
148
-        if ( ! empty( $new_values ) ) {
149
-            $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) );
150
-            if ( $query_results ) {
148
+		if ( ! empty( $new_values ) ) {
149
+			$query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) );
150
+			if ( $query_results ) {
151 151
 				self::clear_form_cache();
152
-            }
153
-        } else {
154
-            $query_results = true;
155
-        }
156
-        unset($new_values);
152
+			}
153
+		} else {
154
+			$query_results = true;
155
+		}
156
+		unset($new_values);
157 157
 
158
-        $values = self::update_fields($id, $values);
158
+		$values = self::update_fields($id, $values);
159 159
 
160
-        do_action('frm_update_form', $id, $values);
161
-        do_action('frm_update_form_'. $id, $values);
160
+		do_action('frm_update_form', $id, $values);
161
+		do_action('frm_update_form_'. $id, $values);
162 162
 
163
-        return $query_results;
164
-    }
163
+		return $query_results;
164
+	}
165 165
 
166
-    /**
167
-     * @return array
168
-     */
166
+	/**
167
+	 * @return array
168
+	 */
169 169
 	public static function set_update_options( $new_values, $values ) {
170
-        if ( ! isset($values['options']) ) {
171
-            return $new_values;
172
-        }
170
+		if ( ! isset($values['options']) ) {
171
+			return $new_values;
172
+		}
173 173
 
174
-        $options = array();
174
+		$options = array();
175 175
 		FrmFormsHelper::fill_form_options( $options, $values );
176 176
 
177
-        $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
178
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
179
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
180
-        $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
177
+		$options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
178
+		$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
179
+		$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
180
+		$options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
181 181
 
182
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
183
-        $new_values['options'] = serialize($options);
182
+		$options = apply_filters('frm_form_options_before_update', $options, $values);
183
+		$new_values['options'] = serialize($options);
184 184
 
185
-        return $new_values;
186
-    }
185
+		return $new_values;
186
+	}
187 187
 
188 188
 
189
-    /**
190
-     * @return array
191
-     */
189
+	/**
190
+	 * @return array
191
+	 */
192 192
 	public static function update_fields( $id, $values ) {
193 193
 
194
-        if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
195
-            return $values;
196
-        }
194
+		if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
195
+			return $values;
196
+		}
197 197
 
198
-        $all_fields = FrmField::get_all_for_form($id);
199
-        if ( empty($all_fields) ) {
200
-            return $values;
201
-        }
198
+		$all_fields = FrmField::get_all_for_form($id);
199
+		if ( empty($all_fields) ) {
200
+			return $values;
201
+		}
202 202
 
203
-        if ( ! isset($values['item_meta']) ) {
204
-            $values['item_meta'] = array();
205
-        }
203
+		if ( ! isset($values['item_meta']) ) {
204
+			$values['item_meta'] = array();
205
+		}
206 206
 
207
-        $field_array = array();
208
-        $existing_keys = array_keys($values['item_meta']);
209
-        foreach ( $all_fields as $fid ) {
210
-            if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
207
+		$field_array = array();
208
+		$existing_keys = array_keys($values['item_meta']);
209
+		foreach ( $all_fields as $fid ) {
210
+			if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
211 211
 				$values['item_meta'][ $fid->id ] = '';
212
-            }
212
+			}
213 213
 			$field_array[ $fid->id ] = $fid;
214
-        }
215
-        unset($all_fields);
214
+		}
215
+		unset($all_fields);
216 216
 
217
-        foreach ( $values['item_meta'] as $field_id => $default_value ) {
217
+		foreach ( $values['item_meta'] as $field_id => $default_value ) {
218 218
 			if ( isset( $field_array[ $field_id ] ) ) {
219 219
 				$field = $field_array[ $field_id ];
220
-            } else {
221
-                $field = FrmField::getOne($field_id);
222
-            }
220
+			} else {
221
+				$field = FrmField::getOne($field_id);
222
+			}
223 223
 
224
-            if ( ! $field ) {
225
-                continue;
226
-            }
224
+			if ( ! $field ) {
225
+				continue;
226
+			}
227 227
 
228 228
 			if ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
229
-                //updating the settings page
229
+				//updating the settings page
230 230
 				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
231 231
 					$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 ) );
232
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
232
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
233 233
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
234
-                } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
235
-                    $prev_opts = $field->field_options;
236
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
237
-                    if ( $prev_opts != $field->field_options ) {
234
+				} else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
235
+					$prev_opts = $field->field_options;
236
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
237
+					if ( $prev_opts != $field->field_options ) {
238 238
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
239
-                    }
240
-                    unset($prev_opts);
241
-                }
242
-            }
239
+					}
240
+					unset($prev_opts);
241
+				}
242
+			}
243 243
 
244 244
 			if ( ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) && ! defined( 'WP_IMPORTING' ) ) {
245
-                continue;
246
-            }
245
+				continue;
246
+			}
247 247
 
248
-            //updating the form
248
+			//updating the form
249 249
 			foreach ( array( 'size', 'max', 'label', 'invalid', 'blank', 'classes', 'captcha_size' ) as $opt ) {
250 250
 				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( $values['field_options'][ $opt . '_' . $field_id ] ) : '';
251
-            }
251
+			}
252 252
 
253 253
 			$field->field_options['required_indicator'] = isset( $values['field_options'][ 'required_indicator_' . $field_id ] ) ? trim( $values['field_options'][ 'required_indicator_' . $field_id ] ) : '*';
254 254
 			$field->field_options['separate_value'] = isset( $values['field_options'][ 'separate_value_' . $field_id ] ) ? trim( $values['field_options'][ 'separate_value_' . $field_id ] ) : 0;
255 255
 
256
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
256
+			$field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
257 257
 			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
258 258
 			$field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key;
259 259
 			$required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false;
260 260
 			$field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type;
261 261
 			$field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description;
262 262
 
263
-            FrmField::update($field_id, array(
264
-                'field_key' => $field_key, 'type' => $field_type,
265
-                'default_value' => $default_value, 'field_options' => $field->field_options,
266
-                'description' => $field_description, 'required' => $required,
267
-            ) );
263
+			FrmField::update($field_id, array(
264
+				'field_key' => $field_key, 'type' => $field_type,
265
+				'default_value' => $default_value, 'field_options' => $field->field_options,
266
+				'description' => $field_description, 'required' => $required,
267
+			) );
268 268
 
269
-            FrmField::delete_form_transient($field->form_id);
270
-        }
269
+			FrmField::delete_form_transient($field->form_id);
270
+		}
271 271
 
272
-        return $values;
273
-    }
272
+		return $values;
273
+	}
274 274
 
275
-    /**
276
-     * @param string $status
277
-     * @return int|boolean
278
-     */
275
+	/**
276
+	 * @param string $status
277
+	 * @return int|boolean
278
+	 */
279 279
 	public static function set_status( $id, $status ) {
280
-        if ( 'trash' == $status ) {
281
-            return self::trash($id);
282
-        }
280
+		if ( 'trash' == $status ) {
281
+			return self::trash($id);
282
+		}
283 283
 
284 284
 		$statuses  = array( 'published', 'draft', 'trash' );
285
-        if ( ! in_array( $status, $statuses ) ) {
286
-            return false;
287
-        }
285
+		if ( ! in_array( $status, $statuses ) ) {
286
+			return false;
287
+		}
288 288
 
289
-        global $wpdb;
289
+		global $wpdb;
290 290
 
291
-        if ( is_array($id) ) {
291
+		if ( is_array($id) ) {
292 292
 			$where = array( 'id' => $id );
293 293
 			FrmDb::get_where_clause_and_values( $where );
294 294
 			array_unshift( $where['values'], $status );
295 295
 
296 296
 			$query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) );
297
-        } else {
297
+		} else {
298 298
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
299
-        }
299
+		}
300 300
 
301
-        if ( $query_results ) {
301
+		if ( $query_results ) {
302 302
 			self::clear_form_cache();
303
-        }
303
+		}
304 304
 
305
-        return $query_results;
306
-    }
305
+		return $query_results;
306
+	}
307 307
 
308
-    /**
309
-     * @return int|boolean
310
-     */
308
+	/**
309
+	 * @return int|boolean
310
+	 */
311 311
 	public static function trash( $id ) {
312
-        if ( ! EMPTY_TRASH_DAYS ) {
313
-            return self::destroy( $id );
314
-        }
312
+		if ( ! EMPTY_TRASH_DAYS ) {
313
+			return self::destroy( $id );
314
+		}
315 315
 
316
-        $form = self::getOne($id);
317
-        if ( ! $form ) {
318
-            return false;
319
-        }
316
+		$form = self::getOne($id);
317
+		if ( ! $form ) {
318
+			return false;
319
+		}
320 320
 
321
-        $options = $form->options;
322
-        $options['trash_time'] = time();
321
+		$options = $form->options;
322
+		$options['trash_time'] = time();
323 323
 
324
-        global $wpdb;
325
-        $query_results = $wpdb->update(
326
-            $wpdb->prefix .'frm_forms',
324
+		global $wpdb;
325
+		$query_results = $wpdb->update(
326
+			$wpdb->prefix .'frm_forms',
327 327
 			array( 'status' => 'trash', 'options' => serialize( $options ) ),
328 328
 			array( 'id' => $id )
329
-        );
329
+		);
330 330
 
331
-        if ( $query_results ) {
331
+		if ( $query_results ) {
332 332
 			self::clear_form_cache();
333
-        }
333
+		}
334 334
 
335
-        return $query_results;
336
-    }
335
+		return $query_results;
336
+	}
337 337
 
338
-    /**
339
-     * @return int|boolean
340
-     */
338
+	/**
339
+	 * @return int|boolean
340
+	 */
341 341
 	public static function destroy( $id ) {
342
-        global $wpdb;
342
+		global $wpdb;
343 343
 
344
-        $form = self::getOne($id);
345
-        if ( ! $form ) {
346
-            return false;
347
-        }
344
+		$form = self::getOne($id);
345
+		if ( ! $form ) {
346
+			return false;
347
+		}
348 348
 
349
-        // Disconnect the entries from this form
349
+		// Disconnect the entries from this form
350 350
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
351
-        foreach ( $entries as $entry_id ) {
352
-            FrmEntry::destroy($entry_id);
353
-            unset($entry_id);
354
-        }
351
+		foreach ( $entries as $entry_id ) {
352
+			FrmEntry::destroy($entry_id);
353
+			unset($entry_id);
354
+		}
355 355
 
356
-        // Disconnect the fields from this form
357
-        $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));
356
+		// Disconnect the fields from this form
357
+		$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));
358 358
 
359
-        $query_results = $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id));
360
-        if ( $query_results ) {
361
-            // Delete all form actions linked to this form
362
-            $action_control = FrmFormActionsController::get_form_actions( 'email' );
363
-            $action_control->destroy($id, 'all');
359
+		$query_results = $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id));
360
+		if ( $query_results ) {
361
+			// Delete all form actions linked to this form
362
+			$action_control = FrmFormActionsController::get_form_actions( 'email' );
363
+			$action_control->destroy($id, 'all');
364 364
 
365 365
 			// Clear form caching
366 366
 			self::clear_form_cache();
367 367
 
368
-            do_action('frm_destroy_form', $id);
369
-            do_action('frm_destroy_form_'. $id);
370
-        }
368
+			do_action('frm_destroy_form', $id);
369
+			do_action('frm_destroy_form_'. $id);
370
+		}
371 371
 
372
-        return $query_results;
373
-    }
372
+		return $query_results;
373
+	}
374 374
 
375 375
 	/**
376 376
 	 * Delete trashed forms based on how long they have been trashed
@@ -402,49 +402,49 @@  discard block
 block discarded – undo
402 402
 		return $count;
403 403
 	}
404 404
 
405
-    /**
406
-     * @return string form name
407
-     */
408
-    public static function &getName( $id ) {
409
-        global $wpdb;
410
-
411
-        $form = FrmAppHelper::check_cache($id, 'frm_form');
412
-        if ( $form ) {
413
-            $r = stripslashes($form->name);
414
-            return $r;
415
-        }
416
-
417
-        $query_key = is_numeric( $id ) ? 'id' : 'form_key';
418
-        $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
419
-        $r = stripslashes($r);
420
-
421
-        return $r;
422
-    }
423
-
424
-    /**
425
-     * @param string $key
426
-     * @return int form id
427
-     */
405
+	/**
406
+	 * @return string form name
407
+	 */
408
+	public static function &getName( $id ) {
409
+		global $wpdb;
410
+
411
+		$form = FrmAppHelper::check_cache($id, 'frm_form');
412
+		if ( $form ) {
413
+			$r = stripslashes($form->name);
414
+			return $r;
415
+		}
416
+
417
+		$query_key = is_numeric( $id ) ? 'id' : 'form_key';
418
+		$r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
419
+		$r = stripslashes($r);
420
+
421
+		return $r;
422
+	}
423
+
424
+	/**
425
+	 * @param string $key
426
+	 * @return int form id
427
+	 */
428 428
 	public static function &getIdByKey( $key ) {
429
-        $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
430
-        return $id;
431
-    }
432
-
433
-    /**
434
-     * @param int $id
435
-     * @return string form key
436
-     */
429
+		$id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
430
+		return $id;
431
+	}
432
+
433
+	/**
434
+	 * @param int $id
435
+	 * @return string form key
436
+	 */
437 437
 	public static function &getKeyById( $id ) {
438
-        $id = (int) $id;
439
-        $cache = FrmAppHelper::check_cache($id, 'frm_form');
440
-        if ( $cache ) {
441
-            return $cache->form_key;
442
-        }
438
+		$id = (int) $id;
439
+		$cache = FrmAppHelper::check_cache($id, 'frm_form');
440
+		if ( $cache ) {
441
+			return $cache->form_key;
442
+		}
443 443
 
444
-        $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
444
+		$key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
445 445
 
446
-        return $key;
447
-    }
446
+		return $key;
447
+	}
448 448
 
449 449
 	/**
450 450
 	 * If $form is numeric, get the form object
@@ -457,47 +457,47 @@  discard block
 block discarded – undo
457 457
 		}
458 458
 	}
459 459
 
460
-    /**
461
-     * @return object form
462
-     */
463
-    public static function getOne( $id, $blog_id = false ) {
464
-        global $wpdb;
465
-
466
-        if ( $blog_id && is_multisite() ) {
467
-            global $wpmuBaseTablePrefix;
468
-            $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id .'_' : $wpdb->get_blog_prefix( $blog_id );
469
-
470
-            $table_name = $prefix .'frm_forms';
471
-        } else {
472
-            $table_name = $wpdb->prefix .'frm_forms';
473
-            $cache = wp_cache_get($id, 'frm_form');
474
-            if ( $cache ) {
475
-                if ( isset($cache->options) ) {
476
-                    $cache->options = maybe_unserialize($cache->options);
477
-                }
478
-
479
-                return stripslashes_deep($cache);
480
-            }
481
-        }
482
-
483
-        if ( is_numeric($id) ) {
484
-            $where = array( 'id' => $id );
485
-        } else {
486
-            $where = array( 'form_key' => $id );
487
-        }
488
-
489
-        $results = FrmDb::get_row( $table_name, $where );
490
-
491
-        if ( isset($results->options) ) {
492
-            wp_cache_set($results->id, $results, 'frm_form');
493
-            $results->options = maybe_unserialize($results->options);
494
-        }
495
-        return stripslashes_deep($results);
496
-    }
497
-
498
-    /**
499
-     * @return object|array of objects
500
-     */
460
+	/**
461
+	 * @return object form
462
+	 */
463
+	public static function getOne( $id, $blog_id = false ) {
464
+		global $wpdb;
465
+
466
+		if ( $blog_id && is_multisite() ) {
467
+			global $wpmuBaseTablePrefix;
468
+			$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id .'_' : $wpdb->get_blog_prefix( $blog_id );
469
+
470
+			$table_name = $prefix .'frm_forms';
471
+		} else {
472
+			$table_name = $wpdb->prefix .'frm_forms';
473
+			$cache = wp_cache_get($id, 'frm_form');
474
+			if ( $cache ) {
475
+				if ( isset($cache->options) ) {
476
+					$cache->options = maybe_unserialize($cache->options);
477
+				}
478
+
479
+				return stripslashes_deep($cache);
480
+			}
481
+		}
482
+
483
+		if ( is_numeric($id) ) {
484
+			$where = array( 'id' => $id );
485
+		} else {
486
+			$where = array( 'form_key' => $id );
487
+		}
488
+
489
+		$results = FrmDb::get_row( $table_name, $where );
490
+
491
+		if ( isset($results->options) ) {
492
+			wp_cache_set($results->id, $results, 'frm_form');
493
+			$results->options = maybe_unserialize($results->options);
494
+		}
495
+		return stripslashes_deep($results);
496
+	}
497
+
498
+	/**
499
+	 * @return object|array of objects
500
+	 */
501 501
 	public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
502 502
 		if ( is_array( $where ) && ! empty( $where ) ) {
503 503
 			$results = FrmDb::get_results( 'frm_forms', $where, '*', array( 'order_by' => $order_by, 'limit' => $limit ) );
@@ -521,8 +521,8 @@  discard block
 block discarded – undo
521 521
 			$results = reset( $results );
522 522
 		}
523 523
 
524
-        return stripslashes_deep($results);
525
-    }
524
+		return stripslashes_deep($results);
525
+	}
526 526
 
527 527
 	/**
528 528
 	 * Get all published forms
@@ -540,47 +540,47 @@  discard block
 block discarded – undo
540 540
 		return $forms;
541 541
 	}
542 542
 
543
-    /**
544
-     * @return int count of forms
545
-     */
546
-    public static function &get_count() {
547
-    	global $wpdb;
543
+	/**
544
+	 * @return int count of forms
545
+	 */
546
+	public static function &get_count() {
547
+		global $wpdb;
548 548
 
549
-    	$cache_key = 'frm_form_counts';
549
+		$cache_key = 'frm_form_counts';
550 550
 
551
-    	$counts = wp_cache_get( $cache_key, 'counts' );
552
-    	if ( false !== $counts ) {
553
-    	    return $counts;
554
-    	}
551
+		$counts = wp_cache_get( $cache_key, 'counts' );
552
+		if ( false !== $counts ) {
553
+			return $counts;
554
+		}
555 555
 
556
-        $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
556
+		$results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
557 557
 
558 558
 		$statuses = array( 'published', 'draft', 'template', 'trash' );
559
-    	$counts = array_fill_keys( $statuses, 0 );
559
+		$counts = array_fill_keys( $statuses, 0 );
560 560
 
561
-    	foreach ( $results as $row ) {
562
-            if ( 'trash' != $row->status ) {
563
-    	        if ( $row->is_template ) {
561
+		foreach ( $results as $row ) {
562
+			if ( 'trash' != $row->status ) {
563
+				if ( $row->is_template ) {
564 564
 					$counts['template']++;
565
-    	        } else {
565
+				} else {
566 566
 					$counts['published']++;
567
-    	        }
568
-    	    } else {
567
+				}
568
+			} else {
569 569
 				$counts['trash']++;
570
-        	}
570
+			}
571 571
 
572
-    	    if ( 'draft' == $row->status ) {
572
+			if ( 'draft' == $row->status ) {
573 573
 				$counts['draft']++;
574
-    	    }
574
+			}
575 575
 
576
-    		unset($row);
577
-    	}
576
+			unset($row);
577
+		}
578 578
 
579
-    	$counts = (object) $counts;
580
-    	wp_cache_set( $cache_key, $counts, 'counts' );
579
+		$counts = (object) $counts;
580
+		wp_cache_set( $cache_key, $counts, 'counts' );
581 581
 
582
-    	return $counts;
583
-    }
582
+		return $counts;
583
+	}
584 584
 
585 585
 	/**
586 586
 	 * Clear form caching
@@ -593,14 +593,14 @@  discard block
 block discarded – undo
593 593
 		FrmAppHelper::cache_delete_group( 'frm_form' );
594 594
 	}
595 595
 
596
-    /**
597
-     * @return array of errors
598
-     */
596
+	/**
597
+	 * @return array of errors
598
+	 */
599 599
 	public static function validate( $values ) {
600
-        $errors = array();
600
+		$errors = array();
601 601
 
602
-        return apply_filters('frm_validate_form', $errors, $values);
603
-    }
602
+		return apply_filters('frm_validate_form', $errors, $values);
603
+	}
604 604
 
605 605
 	public static function get_params( $form = null ) {
606 606
 		global $frm_vars;
Please login to merge, or discard this patch.
classes/models/FrmFormAction.php 1 patch
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 	public $action_options;     // Option array passed to wp_register_sidebar_widget()
9 9
 	public $control_options;	// Option array passed to wp_register_widget_control()
10 10
 
11
-    public $form_id;        // The ID of the form to evaluate
11
+	public $form_id;        // The ID of the form to evaluate
12 12
 	public $number = false;	// Unique ID number of the current instance.
13 13
 	public $id = '';		// Unique ID string of the current instance (id_base-number)
14 14
 	public $updated = false;	// Set true when we update the data after a POST submit - makes sure we don't do it twice.
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	}
30 30
 
31 31
 	/**
32
-     * Echo the settings update form
32
+	 * Echo the settings update form
33 33
 	 *
34 34
 	 * @param array $instance Current settings
35 35
 	 */
@@ -42,15 +42,15 @@  discard block
 block discarded – undo
42 42
 	 * @return array of the default options
43 43
 	 */
44 44
 	public function get_defaults() {
45
-	    return array();
45
+		return array();
46 46
 	}
47 47
 
48 48
 	public function get_switch_fields() {
49
-	    return array();
49
+		return array();
50 50
 	}
51 51
 
52 52
 	public function migrate_values( $action, $form ) {
53
-	    return $action;
53
+		return $action;
54 54
 	}
55 55
 
56 56
 	// Functions you'll need to call.
@@ -69,24 +69,24 @@  discard block
 block discarded – undo
69 69
 	 *	 - height: currently not used but may be needed in the future
70 70
 	 */
71 71
 	public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
72
-	    if ( ! defined('ABSPATH') ) {
73
-            die('You are not allowed to call this page directly.');
74
-        }
72
+		if ( ! defined('ABSPATH') ) {
73
+			die('You are not allowed to call this page directly.');
74
+		}
75 75
 
76 76
 		$this->id_base = strtolower($id_base);
77 77
 		$this->name = $name;
78 78
 		$this->option_name = 'frm_' . $this->id_base .'_action';
79 79
 
80
-        $default_options = array(
81
-            'classes'   => '',
82
-            'active'    => true,
80
+		$default_options = array(
81
+			'classes'   => '',
82
+			'active'    => true,
83 83
 			'event'     => array( 'create' ),
84
-            'limit'     => 1,
85
-            'force_event' => false,
86
-            'priority'  => 20,
87
-            'ajax_load' => true,
88
-            'tooltip'   => $name,
89
-        );
84
+			'limit'     => 1,
85
+			'force_event' => false,
86
+			'priority'  => 20,
87
+			'ajax_load' => true,
88
+			'tooltip'   => $name,
89
+		);
90 90
 
91 91
 		$action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
92 92
 		$this->action_options = wp_parse_args( $action_options, $default_options );
@@ -132,132 +132,132 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 
134 134
 	public function prepare_new( $form_id = false ) {
135
-        if ( $form_id ) {
136
-            $this->form_id = $form_id;
137
-        }
138
-
139
-        $post_content = array();
140
-        $default_values = $this->get_global_defaults();
141
-
142
-        // fill default values
143
-        $post_content = wp_parse_args( $post_content, $default_values);
144
-
145
-        if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
146
-            $post_content['event'] = array( reset($this->action_options['event']) );
147
-        }
148
-
149
-        $form_action = array(
150
-            'post_title'    => $this->name,
151
-            'post_content'  => $post_content,
152
-            'post_excerpt'  => $this->id_base,
153
-            'ID'            => '',
154
-            'post_status'   => 'publish',
155
-            'post_type'     => FrmFormActionsController::$action_post_type,
156
-            'post_name'     => $this->form_id .'_'. $this->id_base .'_'. $this->number,
157
-            'menu_order'    => $this->form_id,
158
-        );
159
-        unset($post_content);
160
-
161
-        return (object) $form_action;
162
-    }
135
+		if ( $form_id ) {
136
+			$this->form_id = $form_id;
137
+		}
138
+
139
+		$post_content = array();
140
+		$default_values = $this->get_global_defaults();
141
+
142
+		// fill default values
143
+		$post_content = wp_parse_args( $post_content, $default_values);
144
+
145
+		if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
146
+			$post_content['event'] = array( reset($this->action_options['event']) );
147
+		}
148
+
149
+		$form_action = array(
150
+			'post_title'    => $this->name,
151
+			'post_content'  => $post_content,
152
+			'post_excerpt'  => $this->id_base,
153
+			'ID'            => '',
154
+			'post_status'   => 'publish',
155
+			'post_type'     => FrmFormActionsController::$action_post_type,
156
+			'post_name'     => $this->form_id .'_'. $this->id_base .'_'. $this->number,
157
+			'menu_order'    => $this->form_id,
158
+		);
159
+		unset($post_content);
160
+
161
+		return (object) $form_action;
162
+	}
163 163
 
164 164
 	public function create( $form_id ) {
165
-        $this->form_id = $form_id;
165
+		$this->form_id = $form_id;
166 166
 
167
-        $action = $this->prepare_new();
167
+		$action = $this->prepare_new();
168 168
 
169
-        return $this->save_settings($action);
170
-    }
169
+		return $this->save_settings($action);
170
+	}
171 171
 
172 172
 	public function duplicate_form_actions( $form_id, $old_id ) {
173
-        if ( $form_id == $old_id ) {
174
-            // don't duplicate the actions if this is a template getting updated
175
-            return;
176
-        }
177
-
178
-        $this->form_id = $old_id;
179
-        $actions = $this->get_all( $old_id );
180
-
181
-        $this->form_id = $form_id;
182
-        foreach ( $actions as $action ) {
183
-            $this->duplicate_one($action, $form_id);
184
-            unset($action);
185
-        }
186
-    }
187
-
188
-    /* Check if imported action should be created or updated
173
+		if ( $form_id == $old_id ) {
174
+			// don't duplicate the actions if this is a template getting updated
175
+			return;
176
+		}
177
+
178
+		$this->form_id = $old_id;
179
+		$actions = $this->get_all( $old_id );
180
+
181
+		$this->form_id = $form_id;
182
+		foreach ( $actions as $action ) {
183
+			$this->duplicate_one($action, $form_id);
184
+			unset($action);
185
+		}
186
+	}
187
+
188
+	/* Check if imported action should be created or updated
189 189
     *
190 190
     * Since 2.0
191 191
     *
192 192
     * @param array $action
193 193
     * @return integer $post_id
194 194
     */
195
-    public function maybe_create_action( $action, $forms ) {
195
+	public function maybe_create_action( $action, $forms ) {
196 196
 		if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
197
-            // Update action only
198
-            $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
199
-            $post_id = $this->save_settings( $action );
200
-        } else {
201
-            // Create action
202
-            $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
203
-            $post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
204
-        }
205
-        return $post_id;
206
-    }
197
+			// Update action only
198
+			$action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
199
+			$post_id = $this->save_settings( $action );
200
+		} else {
201
+			// Create action
202
+			$action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
203
+			$post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
204
+		}
205
+		return $post_id;
206
+	}
207 207
 
208 208
 	public function duplicate_one( $action, $form_id ) {
209
-        global $frm_duplicate_ids;
209
+		global $frm_duplicate_ids;
210 210
 
211
-        $action->menu_order = $form_id;
212
-        $switch = $this->get_global_switch_fields();
213
-        foreach ( (array) $action->post_content as $key => $val ) {
211
+		$action->menu_order = $form_id;
212
+		$switch = $this->get_global_switch_fields();
213
+		foreach ( (array) $action->post_content as $key => $val ) {
214 214
 			if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
215 215
 				$action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
216
-            } else if ( ! is_array( $val ) ) {
216
+			} else if ( ! is_array( $val ) ) {
217 217
 				$action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
218 218
 			} else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
219
-                // loop through each value if empty
219
+				// loop through each value if empty
220 220
 				if ( empty( $switch[ $key ] ) ) {
221 221
 					$switch[ $key ] = array_keys( $val );
222 222
 				}
223 223
 
224 224
 				foreach ( $switch[ $key ] as $subkey ) {
225 225
 					$action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
226
-                }
227
-            }
226
+				}
227
+			}
228 228
 
229
-            unset($key, $val);
230
-        }
231
-        unset($action->ID);
229
+			unset($key, $val);
230
+		}
231
+		unset($action->ID);
232 232
 
233
-        return $this->save_settings($action);
234
-    }
233
+		return $this->save_settings($action);
234
+	}
235 235
 
236 236
 	private function duplicate_array_walk( $action, $subkey, $val ) {
237
-        global $frm_duplicate_ids;
237
+		global $frm_duplicate_ids;
238 238
 
239
-        if ( is_array($subkey) ) {
240
-            foreach ( $subkey as $subkey2 ) {
241
-                foreach ( (array) $val as $ck => $cv ) {
242
-                    if ( is_array($cv) ) {
239
+		if ( is_array($subkey) ) {
240
+			foreach ( $subkey as $subkey2 ) {
241
+				foreach ( (array) $val as $ck => $cv ) {
242
+					if ( is_array($cv) ) {
243 243
 						$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
244 244
 					} else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
245 245
 						$action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
246
-                    }
247
-                }
248
-            }
249
-        } else {
250
-            foreach ( (array) $val as $ck => $cv ) {
251
-                if ( is_array($cv) ) {
246
+					}
247
+				}
248
+			}
249
+		} else {
250
+			foreach ( (array) $val as $ck => $cv ) {
251
+				if ( is_array($cv) ) {
252 252
 					$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
253 253
 				} else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
254 254
 					$action[ $ck ] = $frm_duplicate_ids[ $cv ];
255
-                }
256
-            }
257
-        }
255
+				}
256
+			}
257
+		}
258 258
 
259
-        return $action;
260
-    }
259
+		return $action;
260
+	}
261 261
 
262 262
 	/**
263 263
 	 * Deal with changed settings.
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 	 *
267 267
 	 */
268 268
  	public function update_callback( $form_id ) {
269
-        $this->form_id = $form_id;
269
+		$this->form_id = $form_id;
270 270
 
271 271
  		$all_instances = $this->get_settings();
272 272
 
@@ -281,25 +281,25 @@  discard block
 block discarded – undo
281 281
  			return;
282 282
  		}
283 283
 
284
-        $action_ids = array();
284
+		$action_ids = array();
285 285
 
286 286
  		foreach ( $settings as $number => $new_instance ) {
287 287
  			$this->_set($number);
288 288
 
289 289
  			if ( ! isset($new_instance['post_title']) ) {
290
- 			    // settings were never opened, so don't update
291
- 			    $action_ids[] = $new_instance['ID'];
292
-         		$this->updated = true;
293
-         		continue;
290
+ 				// settings were never opened, so don't update
291
+ 				$action_ids[] = $new_instance['ID'];
292
+		 		$this->updated = true;
293
+		 		continue;
294 294
  			}
295 295
 
296 296
 			$old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
297 297
 
298 298
  			$new_instance['post_type']  = FrmFormActionsController::$action_post_type;
299
-            $new_instance['post_name']    = $this->form_id .'_'. $this->id_base .'_'. $this->number;
300
-            $new_instance['menu_order']   = $this->form_id;
301
-            $new_instance['post_status']  = 'publish';
302
-            $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
299
+			$new_instance['post_name']    = $this->form_id .'_'. $this->id_base .'_'. $this->number;
300
+			$new_instance['menu_order']   = $this->form_id;
301
+			$new_instance['post_status']  = 'publish';
302
+			$new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
303 303
 
304 304
  			$instance = $this->update( $new_instance, $old_instance );
305 305
 
@@ -319,15 +319,15 @@  discard block
 block discarded – undo
319 319
 			$instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
320 320
 
321 321
 			$instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this);
322
-            $instance['post_content'] = apply_filters('frm_before_save_'. $this->id_base .'_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this);
322
+			$instance['post_content'] = apply_filters('frm_before_save_'. $this->id_base .'_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this);
323 323
 
324 324
 			if ( false !== $instance ) {
325 325
 				$all_instances[ $number ] = $instance;
326 326
 			}
327 327
 
328
-            $action_ids[] = $this->save_settings($instance);
328
+			$action_ids[] = $this->save_settings($instance);
329 329
 
330
-     		$this->updated = true;
330
+	 		$this->updated = true;
331 331
  		}
332 332
 
333 333
  		return $action_ids;
@@ -338,100 +338,100 @@  discard block
 block discarded – undo
338 338
 	}
339 339
 
340 340
 	public function get_single_action( $id ) {
341
-	    $action = get_post($id);
341
+		$action = get_post($id);
342 342
 		if ( $action ) {
343 343
 			$action = $this->prepare_action( $action );
344 344
 			$this->_set( $id );
345 345
 		}
346
-	    return $action;
346
+		return $action;
347 347
 	}
348 348
 
349 349
 	public function get_one( $form_id ) {
350
-	    return $this->get_all($form_id, 1);
350
+		return $this->get_all($form_id, 1);
351 351
 	}
352 352
 
353
-    public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) {
354
-        $action_controls = FrmFormActionsController::get_form_actions( $type );
355
-        if ( empty($action_controls) ) {
356
-            // don't continue if there are no available actions
357
-            return array();
358
-        }
353
+	public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) {
354
+		$action_controls = FrmFormActionsController::get_form_actions( $type );
355
+		if ( empty($action_controls) ) {
356
+			// don't continue if there are no available actions
357
+			return array();
358
+		}
359 359
 
360
-        if ( 'all' != $type ) {
361
-            return $action_controls->get_all( $form_id, $limit );
362
-        }
360
+		if ( 'all' != $type ) {
361
+			return $action_controls->get_all( $form_id, $limit );
362
+		}
363 363
 
364 364
 		$args = self::action_args( $form_id, $limit );
365 365
 		$actions = FrmAppHelper::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
366 366
 
367
-        if ( ! $actions ) {
368
-            return array();
369
-        }
367
+		if ( ! $actions ) {
368
+			return array();
369
+		}
370 370
 
371
-        $settings = array();
372
-        foreach ( $actions as $action ) {
371
+		$settings = array();
372
+		foreach ( $actions as $action ) {
373 373
 			// some plugins/themes are formatting the post_excerpt
374 374
 			$action->post_excerpt = sanitize_title( $action->post_excerpt );
375 375
 
376 376
 			if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
377
-                continue;
378
-            }
377
+				continue;
378
+			}
379 379
 
380
-            $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
380
+			$action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
381 381
 			$settings[ $action->ID ] = $action;
382 382
 
383 383
 			if ( count( $settings ) >= $limit ) {
384 384
 				break;
385 385
 			}
386
-        }
386
+		}
387 387
 
388
-        if ( 1 === $limit ) {
389
-            $settings = reset($settings);
390
-        }
388
+		if ( 1 === $limit ) {
389
+			$settings = reset($settings);
390
+		}
391 391
 
392
-        return $settings;
393
-    }
392
+		return $settings;
393
+	}
394 394
 
395 395
 	public function get_all( $form_id = false, $limit = 99 ) {
396
-	    if ( $form_id ) {
397
-	        $this->form_id = $form_id;
398
-	    }
396
+		if ( $form_id ) {
397
+			$this->form_id = $form_id;
398
+		}
399 399
 
400
-	    $type = $this->id_base;
400
+		$type = $this->id_base;
401 401
 
402
-	    global $frm_vars;
403
-	    $frm_vars['action_type'] = $type;
402
+		global $frm_vars;
403
+		$frm_vars['action_type'] = $type;
404 404
 
405
-	    add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
405
+		add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
406 406
 		$query = self::action_args( $form_id, $limit );
407
-        $query['post_status']      = 'any';
408
-        $query['suppress_filters'] = false;
407
+		$query['post_status']      = 'any';
408
+		$query['suppress_filters'] = false;
409 409
 
410 410
 		$actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
411
-        unset($query);
411
+		unset($query);
412 412
 
413
-        remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
413
+		remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
414 414
 
415
-        if ( empty($actions) ) {
416
-            return array();
417
-        }
415
+		if ( empty($actions) ) {
416
+			return array();
417
+		}
418 418
 
419
-        $settings = array();
420
-        foreach ( $actions as $action ) {
421
-            if ( count($settings) >= $limit ) {
422
-                continue;
423
-            }
419
+		$settings = array();
420
+		foreach ( $actions as $action ) {
421
+			if ( count($settings) >= $limit ) {
422
+				continue;
423
+			}
424 424
 
425
-            $action = $this->prepare_action($action);
425
+			$action = $this->prepare_action($action);
426 426
 
427 427
 			$settings[ $action->ID ] = $action;
428
-        }
428
+		}
429 429
 
430
-        if ( 1 === $limit ) {
431
-            $settings = reset($settings);
432
-        }
430
+		if ( 1 === $limit ) {
431
+			$settings = reset($settings);
432
+		}
433 433
 
434
-        return $settings;
434
+		return $settings;
435 435
 	}
436 436
 
437 437
 	public static function action_args( $form_id = 0, $limit = 99 ) {
@@ -454,45 +454,45 @@  discard block
 block discarded – undo
454 454
 		$action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content);
455 455
 		$action->post_excerpt = sanitize_title( $action->post_excerpt );
456 456
 
457
-        $default_values = $this->get_global_defaults();
457
+		$default_values = $this->get_global_defaults();
458 458
 
459
-        // fill default values
460
-        $action->post_content += $default_values;
459
+		// fill default values
460
+		$action->post_content += $default_values;
461 461
 
462
-        foreach ( $default_values as $k => $vals ) {
463
-            if ( is_array($vals) && ! empty($vals) ) {
462
+		foreach ( $default_values as $k => $vals ) {
463
+			if ( is_array($vals) && ! empty($vals) ) {
464 464
 				if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
465
-                    continue;
466
-                }
465
+					continue;
466
+				}
467 467
 				$action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
468
-            }
469
-        }
468
+			}
469
+		}
470 470
 
471
-        if ( ! is_array($action->post_content['event']) ) {
472
-            $action->post_content['event'] = explode(',', $action->post_content['event']);
473
-        }
471
+		if ( ! is_array($action->post_content['event']) ) {
472
+			$action->post_content['event'] = explode(',', $action->post_content['event']);
473
+		}
474 474
 
475
-        return $action;
475
+		return $action;
476 476
 	}
477 477
 
478 478
 	public function destroy( $form_id = false, $type = 'default' ) {
479
-	    global $wpdb;
479
+		global $wpdb;
480 480
 
481
-	    $this->form_id = $form_id;
481
+		$this->form_id = $form_id;
482 482
 
483
-	    $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
484
-	    if ( $form_id ) {
485
-	        $query['menu_order'] = $form_id;
486
-	    }
487
-	    if ( 'all' != $type ) {
488
-	        $query['post_excerpt'] = $this->id_base;
489
-	    }
483
+		$query = array( 'post_type' => FrmFormActionsController::$action_post_type );
484
+		if ( $form_id ) {
485
+			$query['menu_order'] = $form_id;
486
+		}
487
+		if ( 'all' != $type ) {
488
+			$query['post_excerpt'] = $this->id_base;
489
+		}
490 490
 
491
-        $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
491
+		$post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
492 492
 
493
-        foreach ( $post_ids as $id ) {
494
-            wp_delete_post($id);
495
-        }
493
+		foreach ( $post_ids as $id ) {
494
+			wp_delete_post($id);
495
+		}
496 496
 		self::clear_cache();
497 497
 	}
498 498
 
@@ -510,69 +510,69 @@  discard block
 block discarded – undo
510 510
 	}
511 511
 
512 512
 	public function get_global_defaults() {
513
-	    $defaults = $this->get_defaults();
513
+		$defaults = $this->get_defaults();
514 514
 
515
-	    if ( ! isset($defaults['event']) ) {
515
+		if ( ! isset($defaults['event']) ) {
516 516
 			$defaults['event'] = array( 'create' );
517
-	    }
517
+		}
518 518
 
519
-	    if ( ! isset($defaults['conditions']) ) {
520
-	        $defaults['conditions'] = array(
521
-                'send_stop' => '',
522
-                'any_all'   => '',
523
-            );
524
-        }
519
+		if ( ! isset($defaults['conditions']) ) {
520
+			$defaults['conditions'] = array(
521
+				'send_stop' => '',
522
+				'any_all'   => '',
523
+			);
524
+		}
525 525
 
526
-        return $defaults;
526
+		return $defaults;
527 527
 	}
528 528
 
529 529
 	public function get_global_switch_fields() {
530
-	    $switch = $this->get_switch_fields();
530
+		$switch = $this->get_switch_fields();
531 531
 		$switch['conditions'] = array( 'hide_field' );
532
-	    return $switch;
532
+		return $switch;
533 533
 	}
534 534
 
535 535
 	/**
536 536
 	 * Migrate settings from form->options into new action.
537 537
 	 */
538 538
 	public function migrate_to_2( $form, $update = 'update' ) {
539
-        $action = $this->prepare_new($form->id);
540
-        $form->options = maybe_unserialize($form->options);
539
+		$action = $this->prepare_new($form->id);
540
+		$form->options = maybe_unserialize($form->options);
541 541
 
542
-        // fill with existing options
543
-        foreach ( $action->post_content as $name => $val ) {
542
+		// fill with existing options
543
+		foreach ( $action->post_content as $name => $val ) {
544 544
 			if ( isset( $form->options[ $name ] ) ) {
545 545
 				$action->post_content[ $name ] = $form->options[ $name ];
546 546
 				unset( $form->options[ $name ] );
547
-            }
548
-        }
547
+			}
548
+		}
549 549
 
550
-        $action = $this->migrate_values($action, $form);
550
+		$action = $this->migrate_values($action, $form);
551 551
 
552
-        // check if action already exists
553
-        $post_id = get_posts( array(
554
-            'name'          => $action->post_name,
555
-            'post_type'     => FrmFormActionsController::$action_post_type,
556
-            'post_status'   => $action->post_status,
557
-            'numberposts'   => 1,
558
-        ) );
552
+		// check if action already exists
553
+		$post_id = get_posts( array(
554
+			'name'          => $action->post_name,
555
+			'post_type'     => FrmFormActionsController::$action_post_type,
556
+			'post_status'   => $action->post_status,
557
+			'numberposts'   => 1,
558
+		) );
559 559
 
560
-        if ( empty($post_id) ) {
561
-            // create action now
562
-            $post_id = $this->save_settings($action);
563
-        }
560
+		if ( empty($post_id) ) {
561
+			// create action now
562
+			$post_id = $this->save_settings($action);
563
+		}
564 564
 
565
-        if ( $post_id && 'update' == $update ) {
566
-            global $wpdb;
567
-            $form->options = maybe_serialize($form->options);
565
+		if ( $post_id && 'update' == $update ) {
566
+			global $wpdb;
567
+			$form->options = maybe_serialize($form->options);
568 568
 
569
-            // update form options
569
+			// update form options
570 570
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
571
-            wp_cache_delete( $form->id, 'frm_form');
572
-        }
571
+			wp_cache_delete( $form->id, 'frm_form');
572
+		}
573 573
 
574
-        return $post_id;
575
-    }
574
+		return $post_id;
575
+	}
576 576
 
577 577
 	public static function action_conditions_met( $action, $entry ) {
578 578
 		$notification = $action->post_content;
Please login to merge, or discard this patch.