Completed
Pull Request — master (#54)
by Jamie
03:26
created
classes/models/FrmEntryMeta.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -281,6 +281,7 @@
 block discarded – undo
281 281
      * @param string|array $where
282 282
      * @param string $order_by
283 283
      * @param string $limit
284
+     * @param boolean $unique
284 285
      */
285 286
 	private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) {
286 287
         global $wpdb;
Please login to merge, or discard this patch.
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -5,25 +5,25 @@  discard block
 block discarded – undo
5 5
 
6 6
 class FrmEntryMeta {
7 7
 
8
-    /**
9
-     * @param string $meta_key
10
-     */
8
+	/**
9
+	 * @param string $meta_key
10
+	 */
11 11
 	public static function add_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
12
-        global $wpdb;
12
+		global $wpdb;
13 13
 
14
-        if ( FrmAppHelper::is_empty_value( $meta_value ) ) {
15
-            // don't save blank fields
16
-            return 0;
17
-        }
14
+		if ( FrmAppHelper::is_empty_value( $meta_value ) ) {
15
+			// don't save blank fields
16
+			return 0;
17
+		}
18 18
 
19
-        $new_values = array(
19
+		$new_values = array(
20 20
 			'meta_value'    => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ),
21
-            'item_id'       => $entry_id,
22
-            'field_id'      => $field_id,
23
-            'created_at'    => current_time('mysql', 1),
24
-        );
21
+			'item_id'       => $entry_id,
22
+			'field_id'      => $field_id,
23
+			'created_at'    => current_time('mysql', 1),
24
+		);
25 25
 
26
-        $new_values = apply_filters('frm_add_entry_meta', $new_values);
26
+		$new_values = apply_filters('frm_add_entry_meta', $new_values);
27 27
 
28 28
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_item_metas', $new_values );
29 29
 
@@ -34,40 +34,40 @@  discard block
 block discarded – undo
34 34
 			$id = 0;
35 35
 		}
36 36
 
37
-        return $id;
38
-    }
37
+		return $id;
38
+	}
39 39
 
40
-    /**
41
-     * @param string $meta_key
42
-     */
40
+	/**
41
+	 * @param string $meta_key
42
+	 */
43 43
 	public static function update_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
44
-        if ( ! $field_id ) {
45
-            return false;
46
-        }
44
+		if ( ! $field_id ) {
45
+			return false;
46
+		}
47 47
 
48
-        global $wpdb;
48
+		global $wpdb;
49 49
 
50 50
 		$values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
51 51
 		$where_values = $values;
52
-        $values['meta_value'] = $meta_value;
53
-        $values = apply_filters('frm_update_entry_meta', $values);
52
+		$values['meta_value'] = $meta_value;
53
+		$values = apply_filters('frm_update_entry_meta', $values);
54 54
 		if ( is_array($values['meta_value']) ) {
55 55
 			$values['meta_value'] = array_filter( $values['meta_value'], 'FrmAppHelper::is_not_empty_value' );
56 56
 		}
57
-        $meta_value = maybe_serialize($values['meta_value']);
57
+		$meta_value = maybe_serialize($values['meta_value']);
58 58
 
59
-        wp_cache_delete( $entry_id, 'frm_entry');
59
+		wp_cache_delete( $entry_id, 'frm_entry');
60 60
 		self::clear_cache();
61 61
 
62 62
 		return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
63
-    }
63
+	}
64 64
 
65 65
 	public static function update_entry_metas( $entry_id, $values ) {
66
-        global $wpdb;
66
+		global $wpdb;
67 67
 
68 68
 		$prev_values = FrmDb::get_col( $wpdb->prefix . 'frm_item_metas', array( 'item_id' => $entry_id, 'field_id !' => 0 ), 'field_id' );
69 69
 
70
-        foreach ( $values as $field_id => $meta_value ) {
70
+		foreach ( $values as $field_id => $meta_value ) {
71 71
 			$field = false;
72 72
 			if ( ! empty( $field_id ) ) {
73 73
 				$field = FrmField::getOne( $field_id );
@@ -91,39 +91,39 @@  discard block
 block discarded – undo
91 91
 			}
92 92
 		}
93 93
 
94
-        if ( empty($prev_values) ) {
95
-            return;
96
-        }
94
+		if ( empty($prev_values) ) {
95
+			return;
96
+		}
97 97
 
98
-        $prev_values = array_diff($prev_values, array_keys($values));
98
+		$prev_values = array_diff($prev_values, array_keys($values));
99 99
 
100
-        if ( empty($prev_values) ) {
101
-            return;
102
-        }
100
+		if ( empty($prev_values) ) {
101
+			return;
102
+		}
103 103
 
104 104
 		// prepare the query
105 105
 		$where = array( 'item_id' => $entry_id, 'field_id' => $prev_values );
106 106
 		FrmDb::get_where_clause_and_values( $where );
107 107
 
108
-        // Delete any leftovers
109
-        $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) );
108
+		// Delete any leftovers
109
+		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) );
110 110
 		self::clear_cache();
111
-    }
111
+	}
112 112
 
113 113
 	public static function duplicate_entry_metas( $old_id, $new_id ) {
114
-        $metas = self::get_entry_meta_info($old_id);
115
-        foreach ( $metas as $meta ) {
116
-            self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
117
-            unset($meta);
118
-        }
114
+		$metas = self::get_entry_meta_info($old_id);
115
+		foreach ( $metas as $meta ) {
116
+			self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
117
+			unset($meta);
118
+		}
119 119
 		self::clear_cache();
120
-    }
120
+	}
121 121
 
122 122
 	public static function delete_entry_meta( $entry_id, $field_id ) {
123
-        global $wpdb;
123
+		global $wpdb;
124 124
 		self::clear_cache();
125
-        return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
126
-    }
125
+		return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
126
+	}
127 127
 
128 128
 	/**
129 129
 	 * Clear entry meta caching
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	}
149 149
 
150 150
 	public static function get_entry_meta_by_field( $entry_id, $field_id ) {
151
-        global $wpdb;
151
+		global $wpdb;
152 152
 
153 153
 		if ( is_object( $entry_id ) ) {
154 154
 			$entry = $entry_id;
@@ -161,130 +161,130 @@  discard block
 block discarded – undo
161 161
 
162 162
 		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
163 163
 			$result = $cached->metas[ $field_id ];
164
-            return stripslashes_deep($result);
165
-        }
164
+			return stripslashes_deep($result);
165
+		}
166 166
 
167 167
 		$get_table = $wpdb->prefix . 'frm_item_metas';
168 168
 		$query = array( 'item_id' => $entry_id );
169
-        if ( is_numeric($field_id) ) {
169
+		if ( is_numeric($field_id) ) {
170 170
 			$query['field_id'] = $field_id;
171
-        } else {
171
+		} else {
172 172
 			$get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
173 173
 			$query['fi.field_key'] = $field_id;
174
-        }
174
+		}
175 175
 
176 176
 		$result = FrmDb::get_var( $get_table, $query, 'meta_value' );
177
-        $result = maybe_unserialize($result);
178
-        $result = stripslashes_deep($result);
177
+		$result = maybe_unserialize($result);
178
+		$result = stripslashes_deep($result);
179 179
 
180
-        return $result;
181
-    }
180
+		return $result;
181
+	}
182 182
 
183
-    public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
183
+	public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
184 184
 		$defaults = array( 'value' => false, 'unique' => false, 'stripslashes' => true, 'is_draft' => false );
185
-        $args = wp_parse_args( $args, $defaults );
185
+		$args = wp_parse_args( $args, $defaults );
186 186
 
187
-        $query = array();
188
-        self::meta_field_query($field_id, $order, $limit, $args, $query);
189
-        $query = implode(' ', $query);
187
+		$query = array();
188
+		self::meta_field_query($field_id, $order, $limit, $args, $query);
189
+		$query = implode(' ', $query);
190 190
 
191 191
 		$cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args );
192
-        $values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col');
192
+		$values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col');
193 193
 
194
-        if ( ! $args['stripslashes'] ) {
195
-            return $values;
196
-        }
194
+		if ( ! $args['stripslashes'] ) {
195
+			return $values;
196
+		}
197 197
 
198 198
 		foreach ( $values as $k => $v ) {
199 199
 			$values[ $k ] = maybe_unserialize( $v );
200
-            unset($k, $v);
201
-        }
200
+			unset($k, $v);
201
+		}
202 202
 
203
-        return stripslashes_deep($values);
204
-    }
203
+		return stripslashes_deep($values);
204
+	}
205 205
 
206
-    /**
207
-     * @param string $order
208
-     * @param string $limit
209
-     */
206
+	/**
207
+	 * @param string $order
208
+	 * @param string $limit
209
+	 */
210 210
 	private static function meta_field_query( $field_id, $order, $limit, $args, array &$query ) {
211
-        global $wpdb;
212
-        $query[] = 'SELECT';
213
-        $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
211
+		global $wpdb;
212
+		$query[] = 'SELECT';
213
+		$query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
214 214
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas em ';
215 215
 
216
-        if ( ! $args['is_draft'] ) {
216
+		if ( ! $args['is_draft'] ) {
217 217
 			$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)';
218
-        }
218
+		}
219 219
 
220
-        if ( is_numeric($field_id) ) {
221
-            $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
222
-        } else {
220
+		if ( is_numeric($field_id) ) {
221
+			$query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
222
+		} else {
223 223
 			$query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id );
224
-        }
224
+		}
225 225
 
226
-        if ( ! $args['is_draft'] ) {
227
-            $query[] = 'AND e.is_draft=0';
228
-        }
226
+		if ( ! $args['is_draft'] ) {
227
+			$query[] = 'AND e.is_draft=0';
228
+		}
229 229
 
230
-        if ( $args['value'] ) {
231
-            $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
232
-        }
233
-        $query[] = $order . $limit;
234
-    }
230
+		if ( $args['value'] ) {
231
+			$query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
232
+		}
233
+		$query[] = $order . $limit;
234
+	}
235 235
 
236 236
 	public static function get_entry_meta_info( $entry_id ) {
237 237
 		return FrmDb::get_results( 'frm_item_metas', array( 'item_id' => $entry_id ) );
238
-    }
238
+	}
239 239
 
240 240
 	public static function getAll( $where = array(), $order_by = '', $limit = '', $stripslashes = false ) {
241
-        global $wpdb;
242
-        $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
241
+		global $wpdb;
242
+		$query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
243 243
             fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
244 244
 			FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' .
245
-            FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
245
+			FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
246 246
 
247 247
 		$cache_key = 'all_' . maybe_serialize( $where ) . $order_by . $limit;
248
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
248
+		$results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
249 249
 
250
-        if ( ! $results || ! $stripslashes ) {
251
-            return $results;
252
-        }
250
+		if ( ! $results || ! $stripslashes ) {
251
+			return $results;
252
+		}
253 253
 
254
-        foreach ( $results as $k => $result ) {
254
+		foreach ( $results as $k => $result ) {
255 255
 			$results[ $k ]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) );
256
-            unset($k, $result);
257
-        }
256
+			unset($k, $result);
257
+		}
258 258
 
259
-        return $results;
260
-    }
259
+		return $results;
260
+	}
261 261
 
262
-    public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
262
+	public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
263 263
 		$defaults = array(
264 264
 			'is_draft' => false,
265 265
 			'user_id'  => '',
266 266
 			'group_by' => '',
267 267
 		);
268
-        $args = wp_parse_args($args, $defaults);
268
+		$args = wp_parse_args($args, $defaults);
269 269
 
270
-        $query = array();
271
-        self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
272
-        $query = implode(' ', $query);
270
+		$query = array();
271
+		self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
272
+		$query = implode(' ', $query);
273 273
 
274 274
 		$cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args );
275
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
275
+		$results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
276 276
 
277
-        return $results;
278
-    }
277
+		return $results;
278
+	}
279 279
 
280
-    /**
281
-     * @param string|array $where
282
-     * @param string $order_by
283
-     * @param string $limit
284
-     */
280
+	/**
281
+	 * @param string|array $where
282
+	 * @param string $order_by
283
+	 * @param string $limit
284
+	 */
285 285
 	private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) {
286
-        global $wpdb;
287
-        $query[] = 'SELECT';
286
+		global $wpdb;
287
+		$query[] = 'SELECT';
288 288
 
289 289
 		$defaults = array( 'return_parent_id' => false );
290 290
 		$args = array_merge( $defaults, $args );
@@ -298,89 +298,89 @@  discard block
 block discarded – undo
298 298
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
299 299
 
300 300
 		$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)';
301
-        if ( is_array($where) ) {
302
-            if ( ! $args['is_draft'] ) {
303
-                $where['e.is_draft'] = 0;
304
-            } else if ( $args['is_draft'] == 1 ) {
305
-                $where['e.is_draft'] = 1;
306
-            }
307
-
308
-            if ( ! empty($args['user_id']) ) {
309
-                $where['e.user_id'] = $args['user_id'];
310
-            }
311
-            $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
301
+		if ( is_array($where) ) {
302
+			if ( ! $args['is_draft'] ) {
303
+				$where['e.is_draft'] = 0;
304
+			} else if ( $args['is_draft'] == 1 ) {
305
+				$where['e.is_draft'] = 1;
306
+			}
307
+
308
+			if ( ! empty($args['user_id']) ) {
309
+				$where['e.user_id'] = $args['user_id'];
310
+			}
311
+			$query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
312 312
 
313 313
 			if ( $args['group_by'] ) {
314 314
 				$query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] );
315 315
 			}
316
-            return;
317
-        }
316
+			return;
317
+		}
318 318
 
319 319
 		$draft_where = '';
320 320
 		$user_where = '';
321
-        if ( ! $args['is_draft'] ) {
321
+		if ( ! $args['is_draft'] ) {
322 322
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 0 );
323
-        } else if ( $args['is_draft'] == 1 ) {
323
+		} else if ( $args['is_draft'] == 1 ) {
324 324
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
325
-        }
325
+		}
326 326
 
327
-        if ( ! empty($args['user_id']) ) {
328
-            $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
329
-        }
327
+		if ( ! empty($args['user_id']) ) {
328
+			$user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
329
+		}
330 330
 
331
-        if ( strpos($where, ' GROUP BY ') ) {
332
-            // don't inject WHERE filtering after GROUP BY
333
-            $parts = explode(' GROUP BY ', $where);
334
-            $where = $parts[0];
335
-            $where .= $draft_where . $user_where;
331
+		if ( strpos($where, ' GROUP BY ') ) {
332
+			// don't inject WHERE filtering after GROUP BY
333
+			$parts = explode(' GROUP BY ', $where);
334
+			$where = $parts[0];
335
+			$where .= $draft_where . $user_where;
336 336
 			$where .= ' GROUP BY ' . $parts[1];
337
-        } else {
338
-            $where .= $draft_where . $user_where;
339
-        }
337
+		} else {
338
+			$where .= $draft_where . $user_where;
339
+		}
340 340
 
341 341
 		// The query has already been prepared
342 342
 		$query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
343
-    }
343
+	}
344 344
 
345
-    public static function search_entry_metas( $search, $field_id = '', $operator ) {
345
+	public static function search_entry_metas( $search, $field_id = '', $operator ) {
346 346
 		$cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator;
347
-        $results = wp_cache_get($cache_key, 'frm_entry');
348
-        if ( false !== $results ) {
349
-            return $results;
350
-        }
347
+		$results = wp_cache_get($cache_key, 'frm_entry');
348
+		if ( false !== $results ) {
349
+			return $results;
350
+		}
351 351
 
352
-        global $wpdb;
352
+		global $wpdb;
353 353
 		if ( is_array( $search ) ) {
354
-            $where = '';
354
+			$where = '';
355 355
 			foreach ( $search as $field => $value ) {
356 356
 				if ( $value <= 0 || ! in_array( $field, array( 'year', 'month', 'day' ) ) ) {
357
-                    continue;
358
-                }
357
+					continue;
358
+				}
359 359
 
360
-                switch ( $field ) {
361
-                    case 'year':
360
+				switch ( $field ) {
361
+					case 'year':
362 362
 						$value = '%' . $value;
363
-                    break;
364
-                    case 'month':
365
-                        $value .= '%';
366
-                    break;
367
-                    case 'day':
363
+					break;
364
+					case 'month':
365
+						$value .= '%';
366
+					break;
367
+					case 'day':
368 368
 						$value = '%' . $value . '%';
369
-                }
369
+				}
370 370
 				$where .= $wpdb->prepare(' meta_value ' . $operator . ' %s and', $value );
371
-            }
372
-            $where .= $wpdb->prepare(' field_id=%d', $field_id);
371
+			}
372
+			$where .= $wpdb->prepare(' field_id=%d', $field_id);
373 373
 			$query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where );
374
-        } else {
374
+		} else {
375 375
 			if ( $operator == 'LIKE' ) {
376
-                $search = '%' . $search . '%';
376
+				$search = '%' . $search . '%';
377 377
 			}
378
-            $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
379
-        }
378
+			$query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
379
+		}
380 380
 
381
-        $results = $wpdb->get_col($query, 0);
381
+		$results = $wpdb->get_col($query, 0);
382 382
 		FrmAppHelper::set_cache( $cache_key, $results, 'frm_entry' );
383 383
 
384
-        return $results;
385
-    }
384
+		return $results;
385
+	}
386 386
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -20,10 +20,10 @@  discard block
 block discarded – undo
20 20
 			'meta_value'    => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ),
21 21
             'item_id'       => $entry_id,
22 22
             'field_id'      => $field_id,
23
-            'created_at'    => current_time('mysql', 1),
23
+            'created_at'    => current_time( 'mysql', 1 ),
24 24
         );
25 25
 
26
-        $new_values = apply_filters('frm_add_entry_meta', $new_values);
26
+        $new_values = apply_filters( 'frm_add_entry_meta', $new_values );
27 27
 
28 28
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_item_metas', $new_values );
29 29
 
@@ -50,13 +50,13 @@  discard block
 block discarded – undo
50 50
 		$values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
51 51
 		$where_values = $values;
52 52
         $values['meta_value'] = $meta_value;
53
-        $values = apply_filters('frm_update_entry_meta', $values);
54
-		if ( is_array($values['meta_value']) ) {
53
+        $values = apply_filters( 'frm_update_entry_meta', $values );
54
+		if ( is_array( $values['meta_value'] ) ) {
55 55
 			$values['meta_value'] = array_filter( $values['meta_value'], 'FrmAppHelper::is_not_empty_value' );
56 56
 		}
57
-        $meta_value = maybe_serialize($values['meta_value']);
57
+        $meta_value = maybe_serialize( $values['meta_value'] );
58 58
 
59
-        wp_cache_delete( $entry_id, 'frm_entry');
59
+        wp_cache_delete( $entry_id, 'frm_entry' );
60 60
 		self::clear_cache();
61 61
 
62 62
 		return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
 			// set the value for the file upload field and add new tags (in Pro version)
77 77
 			$meta_value = apply_filters( 'frm_prepare_data_before_db', $meta_value, $field_id, $entry_id, compact( 'field' ) );
78 78
 
79
-			if ( $prev_values && in_array($field_id, $prev_values) ) {
79
+			if ( $prev_values && in_array( $field_id, $prev_values ) ) {
80 80
 
81 81
 				if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) {
82 82
 					// remove blank fields
83
-					unset( $values[ $field_id ] );
83
+					unset( $values[$field_id] );
84 84
 				} else {
85 85
 					// if value exists, then update it
86 86
 					self::update_entry_meta( $entry_id, $field_id, '', $meta_value );
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
 			}
92 92
 		}
93 93
 
94
-        if ( empty($prev_values) ) {
94
+        if ( empty( $prev_values ) ) {
95 95
             return;
96 96
         }
97 97
 
98
-        $prev_values = array_diff($prev_values, array_keys($values));
98
+        $prev_values = array_diff( $prev_values, array_keys( $values ) );
99 99
 
100
-        if ( empty($prev_values) ) {
100
+        if ( empty( $prev_values ) ) {
101 101
             return;
102 102
         }
103 103
 
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
     }
112 112
 
113 113
 	public static function duplicate_entry_metas( $old_id, $new_id ) {
114
-        $metas = self::get_entry_meta_info($old_id);
114
+        $metas = self::get_entry_meta_info( $old_id );
115 115
         foreach ( $metas as $meta ) {
116
-            self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
117
-            unset($meta);
116
+            self::add_entry_meta( $new_id, $meta->field_id, null, $meta->meta_value );
117
+            unset( $meta );
118 118
         }
119 119
 		self::clear_cache();
120 120
     }
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	public static function delete_entry_meta( $entry_id, $field_id ) {
123 123
         global $wpdb;
124 124
 		self::clear_cache();
125
-        return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
125
+        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id ) );
126 126
     }
127 127
 
128 128
 	/**
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 */
142 142
 	public static function get_meta_value( $entry, $field_id ) {
143 143
 		if ( isset( $entry->metas ) ) {
144
-			return isset( $entry->metas[ $field_id ] ) ? $entry->metas[ $field_id ] : false;
144
+			return isset( $entry->metas[$field_id] ) ? $entry->metas[$field_id] : false;
145 145
 		} else {
146 146
 			return self::get_entry_meta_by_field( $entry->id, $field_id );
147 147
 		}
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
 			$cached = FrmAppHelper::check_cache( $entry_id, 'frm_entry' );
160 160
 		}
161 161
 
162
-		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
163
-			$result = $cached->metas[ $field_id ];
164
-            return stripslashes_deep($result);
162
+		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[$field_id] ) ) {
163
+			$result = $cached->metas[$field_id];
164
+            return stripslashes_deep( $result );
165 165
         }
166 166
 
167 167
 		$get_table = $wpdb->prefix . 'frm_item_metas';
168 168
 		$query = array( 'item_id' => $entry_id );
169
-        if ( is_numeric($field_id) ) {
169
+        if ( is_numeric( $field_id ) ) {
170 170
 			$query['field_id'] = $field_id;
171 171
         } else {
172 172
 			$get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
         }
175 175
 
176 176
 		$result = FrmDb::get_var( $get_table, $query, 'meta_value' );
177
-        $result = maybe_unserialize($result);
178
-        $result = stripslashes_deep($result);
177
+        $result = maybe_unserialize( $result );
178
+        $result = stripslashes_deep( $result );
179 179
 
180 180
         return $result;
181 181
     }
@@ -185,22 +185,22 @@  discard block
 block discarded – undo
185 185
         $args = wp_parse_args( $args, $defaults );
186 186
 
187 187
         $query = array();
188
-        self::meta_field_query($field_id, $order, $limit, $args, $query);
189
-        $query = implode(' ', $query);
188
+        self::meta_field_query( $field_id, $order, $limit, $args, $query );
189
+        $query = implode( ' ', $query );
190 190
 
191 191
 		$cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args );
192
-        $values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col');
192
+        $values = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, 'get_col' );
193 193
 
194 194
         if ( ! $args['stripslashes'] ) {
195 195
             return $values;
196 196
         }
197 197
 
198 198
 		foreach ( $values as $k => $v ) {
199
-			$values[ $k ] = maybe_unserialize( $v );
200
-            unset($k, $v);
199
+			$values[$k] = maybe_unserialize( $v );
200
+            unset( $k, $v );
201 201
         }
202 202
 
203
-        return stripslashes_deep($values);
203
+        return stripslashes_deep( $values );
204 204
     }
205 205
 
206 206
     /**
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
 			$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)';
218 218
         }
219 219
 
220
-        if ( is_numeric($field_id) ) {
221
-            $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
220
+        if ( is_numeric( $field_id ) ) {
221
+            $query[] = $wpdb->prepare( 'WHERE em.field_id=%d', $field_id );
222 222
         } else {
223 223
 			$query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id );
224 224
         }
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
         }
229 229
 
230 230
         if ( $args['value'] ) {
231
-            $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
231
+            $query[] = $wpdb->prepare( ' AND meta_value=%s', $args['value'] );
232 232
         }
233 233
         $query[] = $order . $limit;
234 234
     }
@@ -242,18 +242,18 @@  discard block
 block discarded – undo
242 242
         $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
243 243
             fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
244 244
 			FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' .
245
-            FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
245
+            FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
246 246
 
247 247
 		$cache_key = 'all_' . maybe_serialize( $where ) . $order_by . $limit;
248
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
248
+        $results = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_row' : 'get_results' ) );
249 249
 
250 250
         if ( ! $results || ! $stripslashes ) {
251 251
             return $results;
252 252
         }
253 253
 
254 254
         foreach ( $results as $k => $result ) {
255
-			$results[ $k ]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) );
256
-            unset($k, $result);
255
+			$results[$k]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) );
256
+            unset( $k, $result );
257 257
         }
258 258
 
259 259
         return $results;
@@ -265,14 +265,14 @@  discard block
 block discarded – undo
265 265
 			'user_id'  => '',
266 266
 			'group_by' => '',
267 267
 		);
268
-        $args = wp_parse_args($args, $defaults);
268
+        $args = wp_parse_args( $args, $defaults );
269 269
 
270 270
         $query = array();
271
-        self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
272
-        $query = implode(' ', $query);
271
+        self::get_ids_query( $where, $order_by, $limit, $unique, $args, $query );
272
+        $query = implode( ' ', $query );
273 273
 
274 274
 		$cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args );
275
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
275
+        $results = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_var' : 'get_col' ) );
276 276
 
277 277
         return $results;
278 278
     }
@@ -298,17 +298,17 @@  discard block
 block discarded – undo
298 298
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
299 299
 
300 300
 		$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)';
301
-        if ( is_array($where) ) {
301
+        if ( is_array( $where ) ) {
302 302
             if ( ! $args['is_draft'] ) {
303 303
                 $where['e.is_draft'] = 0;
304 304
             } else if ( $args['is_draft'] == 1 ) {
305 305
                 $where['e.is_draft'] = 1;
306 306
             }
307 307
 
308
-            if ( ! empty($args['user_id']) ) {
308
+            if ( ! empty( $args['user_id'] ) ) {
309 309
                 $where['e.user_id'] = $args['user_id'];
310 310
             }
311
-            $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
311
+            $query[] = FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
312 312
 
313 313
 			if ( $args['group_by'] ) {
314 314
 				$query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] );
@@ -324,13 +324,13 @@  discard block
 block discarded – undo
324 324
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
325 325
         }
326 326
 
327
-        if ( ! empty($args['user_id']) ) {
328
-            $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
327
+        if ( ! empty( $args['user_id'] ) ) {
328
+            $user_where = $wpdb->prepare( ' AND e.user_id=%d', $args['user_id'] );
329 329
         }
330 330
 
331
-        if ( strpos($where, ' GROUP BY ') ) {
331
+        if ( strpos( $where, ' GROUP BY ' ) ) {
332 332
             // don't inject WHERE filtering after GROUP BY
333
-            $parts = explode(' GROUP BY ', $where);
333
+            $parts = explode( ' GROUP BY ', $where );
334 334
             $where = $parts[0];
335 335
             $where .= $draft_where . $user_where;
336 336
 			$where .= ' GROUP BY ' . $parts[1];
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
         }
340 340
 
341 341
 		// The query has already been prepared
342
-		$query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
342
+		$query[] = FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
343 343
     }
344 344
 
345 345
     public static function search_entry_metas( $search, $field_id = '', $operator ) {
346 346
 		$cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator;
347
-        $results = wp_cache_get($cache_key, 'frm_entry');
347
+        $results = wp_cache_get( $cache_key, 'frm_entry' );
348 348
         if ( false !== $results ) {
349 349
             return $results;
350 350
         }
@@ -367,18 +367,18 @@  discard block
 block discarded – undo
367 367
                     case 'day':
368 368
 						$value = '%' . $value . '%';
369 369
                 }
370
-				$where .= $wpdb->prepare(' meta_value ' . $operator . ' %s and', $value );
370
+				$where .= $wpdb->prepare( ' meta_value ' . $operator . ' %s and', $value );
371 371
             }
372
-            $where .= $wpdb->prepare(' field_id=%d', $field_id);
372
+            $where .= $wpdb->prepare( ' field_id=%d', $field_id );
373 373
 			$query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where );
374 374
         } else {
375 375
 			if ( $operator == 'LIKE' ) {
376 376
                 $search = '%' . $search . '%';
377 377
 			}
378
-            $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
378
+            $query = $wpdb->prepare( "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id );
379 379
         }
380 380
 
381
-        $results = $wpdb->get_col($query, 0);
381
+        $results = $wpdb->get_col( $query, 0 );
382 382
 		FrmAppHelper::set_cache( $cache_key, $results, 'frm_entry' );
383 383
 
384 384
         return $results;
Please login to merge, or discard this patch.
classes/models/FrmFieldOption.php 1 patch
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -31,6 +31,10 @@
 block discarded – undo
31 31
 	 */
32 32
 	protected $option_label = '';
33 33
 
34
+	/**
35
+	 * @param string $option_key
36
+	 * @param string $option
37
+	 */
34 38
 	public function __construct( $option_key, $option, $args = array() ) {
35 39
 		$this->option_key = $option_key;
36 40
 		$this->option = $option;
Please login to merge, or discard this patch.
classes/models/FrmFieldValueSelector.php 1 patch
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@
 block discarded – undo
75 75
 	/**
76 76
 	 * FrmFieldValueSelector constructor
77 77
 	 *
78
-	 * @param int|string $field_id
78
+	 * @param integer $field_id
79 79
 	 */
80 80
 	public function __construct( $field_id, $args ) {
81 81
 		$this->set_html_name( $args );
Please login to merge, or discard this patch.
classes/models/FrmForm.php 2 patches
Indentation   +324 added lines, -324 removed lines patch added patch discarded remove patch
@@ -1,262 +1,262 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('ABSPATH') ) {
3
-    die('You are not allowed to call this page directly.');
3
+	die('You are not allowed to call this page directly.');
4 4
 }
5 5
 
6 6
 class FrmForm {
7 7
 
8
-    /**
9
-     * @return int|boolean id on success or false on failure
10
-     */
11
-    public static function create( $values ) {
12
-        global $wpdb;
8
+	/**
9
+	 * @return int|boolean id on success or false on failure
10
+	 */
11
+	public static function create( $values ) {
12
+		global $wpdb;
13 13
 
14
-        $new_values = array(
14
+		$new_values = array(
15 15
 			'form_key'      => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16
-            'name'          => $values['name'],
17
-            'description'   => $values['description'],
18
-            'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
-            'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
-            'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
16
+			'name'          => $values['name'],
17
+			'description'   => $values['description'],
18
+			'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
+			'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
+			'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
21 21
 			'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
-            'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
-            'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
-            'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
-        );
22
+			'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
+			'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
+			'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
+		);
26 26
 
27 27
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
28 28
 		FrmFormsHelper::fill_form_options( $options, $values );
29 29
 
30
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
-        $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
30
+		$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
+		$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
+		$options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
33 33
 
34
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
35
-        $new_values['options'] = serialize($options);
34
+		$options = apply_filters('frm_form_options_before_update', $options, $values);
35
+		$new_values['options'] = serialize($options);
36 36
 
37
-        //if(isset($values['id']) && is_numeric($values['id']))
38
-        //    $new_values['id'] = $values['id'];
37
+		//if(isset($values['id']) && is_numeric($values['id']))
38
+		//    $new_values['id'] = $values['id'];
39 39
 
40 40
 		$wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
41 41
 
42
-        $id = $wpdb->insert_id;
42
+		$id = $wpdb->insert_id;
43 43
 
44 44
 		// Clear form caching
45 45
 		self::clear_form_cache();
46 46
 
47
-        return $id;
48
-    }
47
+		return $id;
48
+	}
49 49
 
50
-    /**
51
-     * @return int|boolean ID on success or false on failure
52
-     */
53
-    public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
-        global $wpdb;
50
+	/**
51
+	 * @return int|boolean ID on success or false on failure
52
+	 */
53
+	public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
+		global $wpdb;
55 55
 
56
-        $values = self::getOne( $id, $blog_id );
57
-        if ( ! $values ) {
58
-            return false;
59
-        }
56
+		$values = self::getOne( $id, $blog_id );
57
+		if ( ! $values ) {
58
+			return false;
59
+		}
60 60
 
61
-        $new_key = $copy_keys ? $values->form_key : '';
61
+		$new_key = $copy_keys ? $values->form_key : '';
62 62
 
63
-        $new_values = array(
63
+		$new_values = array(
64 64
 			'form_key'      => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ),
65
-            'name'          => $values->name,
66
-            'description'   => $values->description,
67
-            'status'        => $template ? 'published' : 'draft',
68
-            'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
-            'editable'      => $values->editable ? $values->editable : 0,
70
-            'created_at'    => current_time('mysql', 1),
71
-            'is_template'   => $template ? 1 : 0,
72
-        );
73
-
74
-        if ( $blog_id ) {
75
-            $new_values['status'] = 'published';
76
-            $new_options = maybe_unserialize($values->options);
77
-            $new_options['email_to'] = get_option('admin_email');
78
-            $new_options['copy'] = false;
79
-            $new_values['options'] = $new_options;
80
-        } else {
81
-            $new_values['options'] = $values->options;
82
-        }
83
-
84
-        if ( is_array($new_values['options']) ) {
85
-            $new_values['options'] = serialize($new_values['options']);
86
-        }
65
+			'name'          => $values->name,
66
+			'description'   => $values->description,
67
+			'status'        => $template ? 'published' : 'draft',
68
+			'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
+			'editable'      => $values->editable ? $values->editable : 0,
70
+			'created_at'    => current_time('mysql', 1),
71
+			'is_template'   => $template ? 1 : 0,
72
+		);
73
+
74
+		if ( $blog_id ) {
75
+			$new_values['status'] = 'published';
76
+			$new_options = maybe_unserialize($values->options);
77
+			$new_options['email_to'] = get_option('admin_email');
78
+			$new_options['copy'] = false;
79
+			$new_values['options'] = $new_options;
80
+		} else {
81
+			$new_values['options'] = $values->options;
82
+		}
83
+
84
+		if ( is_array($new_values['options']) ) {
85
+			$new_values['options'] = serialize($new_values['options']);
86
+		}
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
89 89
 
90
-        if ( $query_results ) {
90
+		if ( $query_results ) {
91 91
 			// Clear form caching
92 92
 			self::clear_form_cache();
93 93
 
94
-            $form_id = $wpdb->insert_id;
95
-            FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
94
+			$form_id = $wpdb->insert_id;
95
+			FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
96 96
 
97
-            // update form settings after fields are created
97
+			// update form settings after fields are created
98 98
 			do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
99
-            return $form_id;
100
-        }
99
+			return $form_id;
100
+		}
101 101
 
102
-        return false;
103
-    }
102
+		return false;
103
+	}
104 104
 
105 105
 	public static function after_duplicate( $form_id, $values ) {
106 106
 		$new_opts = maybe_unserialize( $values['options'] );
107 107
 		$values['options'] = $new_opts;
108 108
 
109
-        if ( isset($new_opts['success_msg']) ) {
110
-            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
111
-        }
109
+		if ( isset($new_opts['success_msg']) ) {
110
+			$new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
111
+		}
112 112
 
113
-        $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
113
+		$new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
114 114
 
115
-        if ( $new_opts != $values['options'] ) {
116
-            global $wpdb;
115
+		if ( $new_opts != $values['options'] ) {
116
+			global $wpdb;
117 117
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
118
-        }
119
-    }
118
+		}
119
+	}
120 120
 
121
-    /**
122
-     * @return int|boolean
123
-     */
124
-    public static function update( $id, $values, $create_link = false ) {
125
-        global $wpdb;
121
+	/**
122
+	 * @return int|boolean
123
+	 */
124
+	public static function update( $id, $values, $create_link = false ) {
125
+		global $wpdb;
126 126
 
127
-        if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
128
-            $values['status'] = 'published';
129
-        }
127
+		if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
128
+			$values['status'] = 'published';
129
+		}
130 130
 
131
-        if ( isset($values['form_key']) ) {
131
+		if ( isset($values['form_key']) ) {
132 132
 			$values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
133
-        }
133
+		}
134 134
 
135 135
 		$form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
136 136
 
137
-        $new_values = self::set_update_options( array(), $values);
137
+		$new_values = self::set_update_options( array(), $values);
138 138
 
139
-        foreach ( $values as $value_key => $value ) {
139
+		foreach ( $values as $value_key => $value ) {
140 140
 			if ( $value_key && in_array( $value_key, $form_fields ) ) {
141 141
 				$new_values[ $value_key ] = $value;
142
-            }
143
-        }
142
+			}
143
+		}
144 144
 
145
-        if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
146
-            $new_values['status'] = $values['new_status'];
147
-        }
145
+		if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
146
+			$new_values['status'] = $values['new_status'];
147
+		}
148 148
 
149
-        if ( ! empty( $new_values ) ) {
149
+		if ( ! empty( $new_values ) ) {
150 150
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) );
151
-            if ( $query_results ) {
151
+			if ( $query_results ) {
152 152
 				self::clear_form_cache();
153
-            }
154
-        } else {
155
-            $query_results = true;
156
-        }
157
-        unset($new_values);
153
+			}
154
+		} else {
155
+			$query_results = true;
156
+		}
157
+		unset($new_values);
158 158
 
159
-        $values = self::update_fields($id, $values);
159
+		$values = self::update_fields($id, $values);
160 160
 
161 161
 		do_action( 'frm_update_form', $id, $values );
162 162
 		do_action( 'frm_update_form_' . $id, $values );
163 163
 
164
-        return $query_results;
165
-    }
164
+		return $query_results;
165
+	}
166 166
 
167
-    /**
168
-     * @return array
169
-     */
167
+	/**
168
+	 * @return array
169
+	 */
170 170
 	public static function set_update_options( $new_values, $values ) {
171
-        if ( ! isset($values['options']) ) {
172
-            return $new_values;
173
-        }
171
+		if ( ! isset($values['options']) ) {
172
+			return $new_values;
173
+		}
174 174
 
175 175
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
176 176
 		FrmFormsHelper::fill_form_options( $options, $values );
177 177
 
178
-        $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
179
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
180
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
181
-        $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
178
+		$options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
179
+		$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
180
+		$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
181
+		$options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
182 182
 
183
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
184
-        $new_values['options'] = serialize($options);
183
+		$options = apply_filters('frm_form_options_before_update', $options, $values);
184
+		$new_values['options'] = serialize($options);
185 185
 
186
-        return $new_values;
187
-    }
186
+		return $new_values;
187
+	}
188 188
 
189 189
 
190
-    /**
191
-     * @return array
192
-     */
190
+	/**
191
+	 * @return array
192
+	 */
193 193
 	public static function update_fields( $id, $values ) {
194 194
 
195
-        if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
196
-            return $values;
197
-        }
195
+		if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
196
+			return $values;
197
+		}
198 198
 
199
-        $all_fields = FrmField::get_all_for_form($id);
200
-        if ( empty($all_fields) ) {
201
-            return $values;
202
-        }
199
+		$all_fields = FrmField::get_all_for_form($id);
200
+		if ( empty($all_fields) ) {
201
+			return $values;
202
+		}
203 203
 
204
-        if ( ! isset($values['item_meta']) ) {
205
-            $values['item_meta'] = array();
206
-        }
204
+		if ( ! isset($values['item_meta']) ) {
205
+			$values['item_meta'] = array();
206
+		}
207 207
 
208
-        $field_array = array();
209
-        $existing_keys = array_keys($values['item_meta']);
210
-        foreach ( $all_fields as $fid ) {
211
-            if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
208
+		$field_array = array();
209
+		$existing_keys = array_keys($values['item_meta']);
210
+		foreach ( $all_fields as $fid ) {
211
+			if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
212 212
 				$values['item_meta'][ $fid->id ] = '';
213
-            }
213
+			}
214 214
 			$field_array[ $fid->id ] = $fid;
215
-        }
216
-        unset($all_fields);
215
+		}
216
+		unset($all_fields);
217 217
 
218
-        foreach ( $values['item_meta'] as $field_id => $default_value ) {
218
+		foreach ( $values['item_meta'] as $field_id => $default_value ) {
219 219
 			if ( isset( $field_array[ $field_id ] ) ) {
220 220
 				$field = $field_array[ $field_id ];
221
-            } else {
222
-                $field = FrmField::getOne($field_id);
223
-            }
221
+			} else {
222
+				$field = FrmField::getOne($field_id);
223
+			}
224 224
 
225
-            if ( ! $field ) {
226
-                continue;
227
-            }
225
+			if ( ! $field ) {
226
+				continue;
227
+			}
228 228
 
229 229
 			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
230 230
 			if ( $is_settings_page ) {
231
-                //updating the settings page
231
+				//updating the settings page
232 232
 				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
233 233
 					$field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
234
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
234
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
235 235
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
236
-                } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
237
-                    $prev_opts = $field->field_options;
238
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
239
-                    if ( $prev_opts != $field->field_options ) {
236
+				} else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
237
+					$prev_opts = $field->field_options;
238
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
239
+					if ( $prev_opts != $field->field_options ) {
240 240
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
241
-                    }
242
-                    unset($prev_opts);
243
-                }
244
-            }
241
+					}
242
+					unset($prev_opts);
243
+				}
244
+			}
245 245
 
246 246
 			if ( $is_settings_page && ! defined( 'WP_IMPORTING' ) ) {
247
-                continue;
248
-            }
247
+				continue;
248
+			}
249 249
 
250
-            //updating the form
250
+			//updating the form
251 251
 			$update_options = FrmFieldsHelper::get_default_field_opts( $field->type, $field, true );
252 252
 			unset( $update_options['custom_html'] ); // don't check for POST html
253 253
 			$update_options = apply_filters( 'frm_field_options_to_update', $update_options );
254 254
 
255 255
 			foreach ( $update_options as $opt => $default ) {
256 256
 				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default;
257
-            }
257
+			}
258 258
 
259
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
259
+			$field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
260 260
 			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
261 261
 
262 262
 			$new_field = array(
@@ -268,12 +268,12 @@  discard block
 block discarded – undo
268 268
 
269 269
 			FrmField::update( $field_id, $new_field );
270 270
 
271
-            FrmField::delete_form_transient($field->form_id);
272
-        }
271
+			FrmField::delete_form_transient($field->form_id);
272
+		}
273 273
 		self::clear_form_cache();
274 274
 
275
-        return $values;
276
-    }
275
+		return $values;
276
+	}
277 277
 
278 278
 	private static function prepare_field_update_values( $field, $values, &$new_field ) {
279 279
 		$field_cols = array(
@@ -286,113 +286,113 @@  discard block
 block discarded – undo
286 286
 		}
287 287
 	}
288 288
 
289
-    /**
290
-     * @param string $status
291
-     * @return int|boolean
292
-     */
289
+	/**
290
+	 * @param string $status
291
+	 * @return int|boolean
292
+	 */
293 293
 	public static function set_status( $id, $status ) {
294
-        if ( 'trash' == $status ) {
295
-            return self::trash($id);
296
-        }
294
+		if ( 'trash' == $status ) {
295
+			return self::trash($id);
296
+		}
297 297
 
298 298
 		$statuses  = array( 'published', 'draft', 'trash' );
299
-        if ( ! in_array( $status, $statuses ) ) {
300
-            return false;
301
-        }
299
+		if ( ! in_array( $status, $statuses ) ) {
300
+			return false;
301
+		}
302 302
 
303
-        global $wpdb;
303
+		global $wpdb;
304 304
 
305
-        if ( is_array($id) ) {
305
+		if ( is_array($id) ) {
306 306
 			$where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 );
307 307
 			FrmDb::get_where_clause_and_values( $where );
308 308
 			array_unshift( $where['values'], $status );
309 309
 
310 310
 			$query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) );
311
-        } else {
311
+		} else {
312 312
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
313 313
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) );
314
-        }
314
+		}
315 315
 
316
-        if ( $query_results ) {
316
+		if ( $query_results ) {
317 317
 			self::clear_form_cache();
318
-        }
318
+		}
319 319
 
320
-        return $query_results;
321
-    }
320
+		return $query_results;
321
+	}
322 322
 
323
-    /**
324
-     * @return int|boolean
325
-     */
323
+	/**
324
+	 * @return int|boolean
325
+	 */
326 326
 	public static function trash( $id ) {
327
-        if ( ! EMPTY_TRASH_DAYS ) {
328
-            return self::destroy( $id );
329
-        }
327
+		if ( ! EMPTY_TRASH_DAYS ) {
328
+			return self::destroy( $id );
329
+		}
330 330
 
331
-        $form = self::getOne($id);
332
-        if ( ! $form ) {
333
-            return false;
334
-        }
331
+		$form = self::getOne($id);
332
+		if ( ! $form ) {
333
+			return false;
334
+		}
335 335
 
336
-        $options = $form->options;
337
-        $options['trash_time'] = time();
336
+		$options = $form->options;
337
+		$options['trash_time'] = time();
338 338
 
339
-        global $wpdb;
340
-        $query_results = $wpdb->update(
339
+		global $wpdb;
340
+		$query_results = $wpdb->update(
341 341
 			$wpdb->prefix . 'frm_forms',
342 342
 			array( 'status' => 'trash', 'options' => serialize( $options ) ),
343 343
 			array( 'id' => $id )
344
-        );
344
+		);
345 345
 
346
-        $wpdb->update(
346
+		$wpdb->update(
347 347
 			$wpdb->prefix . 'frm_forms',
348 348
 			array( 'status' => 'trash', 'options' => serialize( $options ) ),
349 349
 			array( 'parent_form_id' => $id )
350
-        );
350
+		);
351 351
 
352
-        if ( $query_results ) {
352
+		if ( $query_results ) {
353 353
 			self::clear_form_cache();
354
-        }
354
+		}
355 355
 
356
-        return $query_results;
357
-    }
356
+		return $query_results;
357
+	}
358 358
 
359
-    /**
360
-     * @return int|boolean
361
-     */
359
+	/**
360
+	 * @return int|boolean
361
+	 */
362 362
 	public static function destroy( $id ) {
363
-        global $wpdb;
363
+		global $wpdb;
364 364
 
365
-        $form = self::getOne($id);
366
-        if ( ! $form ) {
367
-            return false;
368
-        }
365
+		$form = self::getOne($id);
366
+		if ( ! $form ) {
367
+			return false;
368
+		}
369 369
 		$id = $form->id;
370 370
 
371
-        // Disconnect the entries from this form
371
+		// Disconnect the entries from this form
372 372
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
373
-        foreach ( $entries as $entry_id ) {
374
-            FrmEntry::destroy($entry_id);
375
-            unset($entry_id);
376
-        }
373
+		foreach ( $entries as $entry_id ) {
374
+			FrmEntry::destroy($entry_id);
375
+			unset($entry_id);
376
+		}
377 377
 
378
-        // Disconnect the fields from this form
378
+		// Disconnect the fields from this form
379 379
 		$wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) );
380 380
 
381 381
 		$query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
382
-        if ( $query_results ) {
383
-            // Delete all form actions linked to this form
384
-            $action_control = FrmFormActionsController::get_form_actions( 'email' );
385
-            $action_control->destroy($id, 'all');
382
+		if ( $query_results ) {
383
+			// Delete all form actions linked to this form
384
+			$action_control = FrmFormActionsController::get_form_actions( 'email' );
385
+			$action_control->destroy($id, 'all');
386 386
 
387 387
 			// Clear form caching
388 388
 			self::clear_form_cache();
389 389
 
390 390
 			do_action( 'frm_destroy_form', $id );
391 391
 			do_action( 'frm_destroy_form_' . $id );
392
-        }
392
+		}
393 393
 
394
-        return $query_results;
395
-    }
394
+		return $query_results;
395
+	}
396 396
 
397 397
 	/**
398 398
 	 * Delete trashed forms based on how long they have been trashed
@@ -424,47 +424,47 @@  discard block
 block discarded – undo
424 424
 		return $count;
425 425
 	}
426 426
 
427
-    /**
428
-     * @return string form name
429
-     */
430
-    public static function getName( $id ) {
431
-        $form = FrmAppHelper::check_cache($id, 'frm_form');
432
-        if ( $form ) {
433
-            $r = stripslashes($form->name);
434
-            return $r;
435
-        }
436
-
437
-        $query_key = is_numeric( $id ) ? 'id' : 'form_key';
438
-        $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
439
-        $r = stripslashes($r);
440
-
441
-        return $r;
442
-    }
443
-
444
-    /**
445
-     * @param string $key
446
-     * @return int form id
447
-     */
427
+	/**
428
+	 * @return string form name
429
+	 */
430
+	public static function getName( $id ) {
431
+		$form = FrmAppHelper::check_cache($id, 'frm_form');
432
+		if ( $form ) {
433
+			$r = stripslashes($form->name);
434
+			return $r;
435
+		}
436
+
437
+		$query_key = is_numeric( $id ) ? 'id' : 'form_key';
438
+		$r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
439
+		$r = stripslashes($r);
440
+
441
+		return $r;
442
+	}
443
+
444
+	/**
445
+	 * @param string $key
446
+	 * @return int form id
447
+	 */
448 448
 	public static function getIdByKey( $key ) {
449
-        $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
450
-        return $id;
451
-    }
452
-
453
-    /**
454
-     * @param int $id
455
-     * @return string form key
456
-     */
449
+		$id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
450
+		return $id;
451
+	}
452
+
453
+	/**
454
+	 * @param int $id
455
+	 * @return string form key
456
+	 */
457 457
 	public static function getKeyById( $id ) {
458
-        $id = (int) $id;
459
-        $cache = FrmAppHelper::check_cache($id, 'frm_form');
460
-        if ( $cache ) {
461
-            return $cache->form_key;
462
-        }
458
+		$id = (int) $id;
459
+		$cache = FrmAppHelper::check_cache($id, 'frm_form');
460
+		if ( $cache ) {
461
+			return $cache->form_key;
462
+		}
463 463
 
464
-        $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
464
+		$key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
465 465
 
466
-        return $key;
467
-    }
466
+		return $key;
467
+	}
468 468
 
469 469
 	/**
470 470
 	 * If $form is numeric, get the form object
@@ -477,47 +477,47 @@  discard block
 block discarded – undo
477 477
 		}
478 478
 	}
479 479
 
480
-    /**
481
-     * @return object form
482
-     */
483
-    public static function getOne( $id, $blog_id = false ) {
484
-        global $wpdb;
480
+	/**
481
+	 * @return object form
482
+	 */
483
+	public static function getOne( $id, $blog_id = false ) {
484
+		global $wpdb;
485 485
 
486
-        if ( $blog_id && is_multisite() ) {
487
-            global $wpmuBaseTablePrefix;
486
+		if ( $blog_id && is_multisite() ) {
487
+			global $wpmuBaseTablePrefix;
488 488
 			$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id );
489 489
 
490 490
 			$table_name = $prefix . 'frm_forms';
491
-        } else {
491
+		} else {
492 492
 			$table_name = $wpdb->prefix . 'frm_forms';
493
-            $cache = wp_cache_get($id, 'frm_form');
494
-            if ( $cache ) {
495
-                if ( isset($cache->options) ) {
496
-                    $cache->options = maybe_unserialize($cache->options);
497
-                }
493
+			$cache = wp_cache_get($id, 'frm_form');
494
+			if ( $cache ) {
495
+				if ( isset($cache->options) ) {
496
+					$cache->options = maybe_unserialize($cache->options);
497
+				}
498 498
 
499
-                return stripslashes_deep($cache);
500
-            }
501
-        }
499
+				return stripslashes_deep($cache);
500
+			}
501
+		}
502 502
 
503
-        if ( is_numeric($id) ) {
504
-            $where = array( 'id' => $id );
505
-        } else {
506
-            $where = array( 'form_key' => $id );
507
-        }
503
+		if ( is_numeric($id) ) {
504
+			$where = array( 'id' => $id );
505
+		} else {
506
+			$where = array( 'form_key' => $id );
507
+		}
508 508
 
509
-        $results = FrmDb::get_row( $table_name, $where );
509
+		$results = FrmDb::get_row( $table_name, $where );
510 510
 
511
-        if ( isset($results->options) ) {
511
+		if ( isset($results->options) ) {
512 512
 			FrmAppHelper::set_cache( $results->id, $results, 'frm_form' );
513
-            $results->options = maybe_unserialize($results->options);
514
-        }
515
-        return stripslashes_deep($results);
516
-    }
517
-
518
-    /**
519
-     * @return object|array of objects
520
-     */
513
+			$results->options = maybe_unserialize($results->options);
514
+		}
515
+		return stripslashes_deep($results);
516
+	}
517
+
518
+	/**
519
+	 * @return object|array of objects
520
+	 */
521 521
 	public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
522 522
 		if ( is_array( $where ) && ! empty( $where ) ) {
523 523
 			$results = FrmDb::get_results( 'frm_forms', $where, '*', array( 'order_by' => $order_by, 'limit' => $limit ) );
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
 			$results = reset( $results );
542 542
 		}
543 543
 
544
-        return stripslashes_deep($results);
545
-    }
544
+		return stripslashes_deep($results);
545
+	}
546 546
 
547 547
 	/**
548 548
 	 * Get all published forms
@@ -560,47 +560,47 @@  discard block
 block discarded – undo
560 560
 		return $forms;
561 561
 	}
562 562
 
563
-    /**
564
-     * @return int count of forms
565
-     */
566
-    public static function get_count() {
567
-    	global $wpdb;
563
+	/**
564
+	 * @return int count of forms
565
+	 */
566
+	public static function get_count() {
567
+		global $wpdb;
568 568
 
569
-    	$cache_key = 'frm_form_counts';
569
+		$cache_key = 'frm_form_counts';
570 570
 
571
-    	$counts = wp_cache_get( $cache_key, 'frm_form' );
572
-    	if ( false !== $counts ) {
573
-    	    return $counts;
574
-    	}
571
+		$counts = wp_cache_get( $cache_key, 'frm_form' );
572
+		if ( false !== $counts ) {
573
+			return $counts;
574
+		}
575 575
 
576
-        $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
576
+		$results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
577 577
 
578 578
 		$statuses = array( 'published', 'draft', 'template', 'trash' );
579
-    	$counts = array_fill_keys( $statuses, 0 );
579
+		$counts = array_fill_keys( $statuses, 0 );
580 580
 
581
-    	foreach ( $results as $row ) {
582
-            if ( 'trash' != $row->status ) {
583
-    	        if ( $row->is_template ) {
581
+		foreach ( $results as $row ) {
582
+			if ( 'trash' != $row->status ) {
583
+				if ( $row->is_template ) {
584 584
 					$counts['template']++;
585
-    	        } else {
585
+				} else {
586 586
 					$counts['published']++;
587
-    	        }
588
-    	    } else {
587
+				}
588
+			} else {
589 589
 				$counts['trash']++;
590
-        	}
590
+			}
591 591
 
592
-    	    if ( 'draft' == $row->status ) {
592
+			if ( 'draft' == $row->status ) {
593 593
 				$counts['draft']++;
594
-    	    }
594
+			}
595 595
 
596
-    		unset($row);
597
-    	}
596
+			unset($row);
597
+		}
598 598
 
599
-    	$counts = (object) $counts;
599
+		$counts = (object) $counts;
600 600
 		FrmAppHelper::set_cache( $cache_key, $counts, 'frm_form' );
601 601
 
602
-    	return $counts;
603
-    }
602
+		return $counts;
603
+	}
604 604
 
605 605
 	/**
606 606
 	 * Clear form caching
@@ -613,14 +613,14 @@  discard block
 block discarded – undo
613 613
 		FrmAppHelper::cache_delete_group( 'frm_form' );
614 614
 	}
615 615
 
616
-    /**
617
-     * @return array of errors
618
-     */
616
+	/**
617
+	 * @return array of errors
618
+	 */
619 619
 	public static function validate( $values ) {
620
-        $errors = array();
620
+		$errors = array();
621 621
 
622
-        return apply_filters('frm_validate_form', $errors, $values);
623
-    }
622
+		return apply_filters('frm_validate_form', $errors, $values);
623
+	}
624 624
 
625 625
 	public static function get_params( $form = null ) {
626 626
 		global $frm_vars;
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
3
-    die('You are not allowed to call this page directly.');
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+    die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
6 6
 class FrmForm {
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 			'form_key'      => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16 16
             'name'          => $values['name'],
17 17
             'description'   => $values['description'],
18
-            'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
-            'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
-            'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
18
+            'status'        => isset( $values['status'] ) ? $values['status'] : 'draft',
19
+            'logged_in'     => isset( $values['logged_in'] ) ? $values['logged_in'] : 0,
20
+            'is_template'   => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0,
21 21
 			'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
-            'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
-            'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
-            'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
22
+            'editable'      => isset( $values['editable'] ) ? (int) $values['editable'] : 0,
23
+            'default_template' => isset( $values['default_template'] ) ? (int) $values['default_template'] : 0,
24
+            'created_at'    => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ),
25 25
         );
26 26
 
27 27
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
28 28
 		FrmFormsHelper::fill_form_options( $options, $values );
29 29
 
30
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
-        $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
30
+        $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
31
+        $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
32
+        $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
33 33
 
34
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
35
-        $new_values['options'] = serialize($options);
34
+        $options = apply_filters( 'frm_form_options_before_update', $options, $values );
35
+        $new_values['options'] = serialize( $options );
36 36
 
37 37
         //if(isset($values['id']) && is_numeric($values['id']))
38 38
         //    $new_values['id'] = $values['id'];
@@ -67,22 +67,22 @@  discard block
 block discarded – undo
67 67
             'status'        => $template ? 'published' : 'draft',
68 68
             'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69 69
             'editable'      => $values->editable ? $values->editable : 0,
70
-            'created_at'    => current_time('mysql', 1),
70
+            'created_at'    => current_time( 'mysql', 1 ),
71 71
             'is_template'   => $template ? 1 : 0,
72 72
         );
73 73
 
74 74
         if ( $blog_id ) {
75 75
             $new_values['status'] = 'published';
76
-            $new_options = maybe_unserialize($values->options);
77
-            $new_options['email_to'] = get_option('admin_email');
76
+            $new_options = maybe_unserialize( $values->options );
77
+            $new_options['email_to'] = get_option( 'admin_email' );
78 78
             $new_options['copy'] = false;
79 79
             $new_values['options'] = $new_options;
80 80
         } else {
81 81
             $new_values['options'] = $values->options;
82 82
         }
83 83
 
84
-        if ( is_array($new_values['options']) ) {
85
-            $new_values['options'] = serialize($new_values['options']);
84
+        if ( is_array( $new_values['options'] ) ) {
85
+            $new_values['options'] = serialize( $new_values['options'] );
86 86
         }
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			self::clear_form_cache();
93 93
 
94 94
             $form_id = $wpdb->insert_id;
95
-            FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
95
+            FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id );
96 96
 
97 97
             // update form settings after fields are created
98 98
 			do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 		$new_opts = maybe_unserialize( $values['options'] );
107 107
 		$values['options'] = $new_opts;
108 108
 
109
-        if ( isset($new_opts['success_msg']) ) {
110
-            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
109
+        if ( isset( $new_opts['success_msg'] ) ) {
110
+            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids( $new_opts['success_msg'] );
111 111
         }
112 112
 
113
-        $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
113
+        $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id );
114 114
 
115 115
         if ( $new_opts != $values['options'] ) {
116 116
             global $wpdb;
@@ -128,17 +128,17 @@  discard block
 block discarded – undo
128 128
             $values['status'] = 'published';
129 129
         }
130 130
 
131
-        if ( isset($values['form_key']) ) {
131
+        if ( isset( $values['form_key'] ) ) {
132 132
 			$values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
133 133
         }
134 134
 
135 135
 		$form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
136 136
 
137
-        $new_values = self::set_update_options( array(), $values);
137
+        $new_values = self::set_update_options( array(), $values );
138 138
 
139 139
         foreach ( $values as $value_key => $value ) {
140 140
 			if ( $value_key && in_array( $value_key, $form_fields ) ) {
141
-				$new_values[ $value_key ] = $value;
141
+				$new_values[$value_key] = $value;
142 142
             }
143 143
         }
144 144
 
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
         } else {
155 155
             $query_results = true;
156 156
         }
157
-        unset($new_values);
157
+        unset( $new_values );
158 158
 
159
-        $values = self::update_fields($id, $values);
159
+        $values = self::update_fields( $id, $values );
160 160
 
161 161
 		do_action( 'frm_update_form', $id, $values );
162 162
 		do_action( 'frm_update_form_' . $id, $values );
@@ -168,20 +168,20 @@  discard block
 block discarded – undo
168 168
      * @return array
169 169
      */
170 170
 	public static function set_update_options( $new_values, $values ) {
171
-        if ( ! isset($values['options']) ) {
171
+        if ( ! isset( $values['options'] ) ) {
172 172
             return $new_values;
173 173
         }
174 174
 
175 175
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
176 176
 		FrmFormsHelper::fill_form_options( $options, $values );
177 177
 
178
-        $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
179
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
180
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
181
-        $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
178
+        $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0;
179
+        $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
180
+        $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
181
+        $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && $values['options']['submit_html'] != '' ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
182 182
 
183
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
184
-        $new_values['options'] = serialize($options);
183
+        $options = apply_filters( 'frm_form_options_before_update', $options, $values );
184
+        $new_values['options'] = serialize( $options );
185 185
 
186 186
         return $new_values;
187 187
     }
@@ -192,54 +192,54 @@  discard block
 block discarded – undo
192 192
      */
193 193
 	public static function update_fields( $id, $values ) {
194 194
 
195
-        if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
195
+        if ( ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) {
196 196
             return $values;
197 197
         }
198 198
 
199
-        $all_fields = FrmField::get_all_for_form($id);
200
-        if ( empty($all_fields) ) {
199
+        $all_fields = FrmField::get_all_for_form( $id );
200
+        if ( empty( $all_fields ) ) {
201 201
             return $values;
202 202
         }
203 203
 
204
-        if ( ! isset($values['item_meta']) ) {
204
+        if ( ! isset( $values['item_meta'] ) ) {
205 205
             $values['item_meta'] = array();
206 206
         }
207 207
 
208 208
         $field_array = array();
209
-        $existing_keys = array_keys($values['item_meta']);
209
+        $existing_keys = array_keys( $values['item_meta'] );
210 210
         foreach ( $all_fields as $fid ) {
211
-            if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
212
-				$values['item_meta'][ $fid->id ] = '';
211
+            if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) {
212
+				$values['item_meta'][$fid->id] = '';
213 213
             }
214
-			$field_array[ $fid->id ] = $fid;
214
+			$field_array[$fid->id] = $fid;
215 215
         }
216
-        unset($all_fields);
216
+        unset( $all_fields );
217 217
 
218 218
         foreach ( $values['item_meta'] as $field_id => $default_value ) {
219
-			if ( isset( $field_array[ $field_id ] ) ) {
220
-				$field = $field_array[ $field_id ];
219
+			if ( isset( $field_array[$field_id] ) ) {
220
+				$field = $field_array[$field_id];
221 221
             } else {
222
-                $field = FrmField::getOne($field_id);
222
+                $field = FrmField::getOne( $field_id );
223 223
             }
224 224
 
225 225
             if ( ! $field ) {
226 226
                 continue;
227 227
             }
228 228
 
229
-			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
229
+			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) );
230 230
 			if ( $is_settings_page ) {
231 231
                 //updating the settings page
232
-				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
233
-					$field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
234
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
232
+				if ( isset( $values['field_options']['custom_html_' . $field_id] ) ) {
233
+					$field->field_options['custom_html'] = isset( $values['field_options']['custom_html_' . $field_id] ) ? $values['field_options']['custom_html_' . $field_id] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
234
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
235 235
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
236 236
                 } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
237 237
                     $prev_opts = $field->field_options;
238
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
238
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
239 239
                     if ( $prev_opts != $field->field_options ) {
240 240
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
241 241
                     }
242
-                    unset($prev_opts);
242
+                    unset( $prev_opts );
243 243
                 }
244 244
             }
245 245
 
@@ -253,11 +253,11 @@  discard block
 block discarded – undo
253 253
 			$update_options = apply_filters( 'frm_field_options_to_update', $update_options );
254 254
 
255 255
 			foreach ( $update_options as $opt => $default ) {
256
-				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default;
256
+				$field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? trim( sanitize_text_field( $values['field_options'][$opt . '_' . $field_id] ) ) : $default;
257 257
             }
258 258
 
259
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
260
-			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
259
+            $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
260
+			$default_value = maybe_serialize( $values['item_meta'][$field_id] );
261 261
 
262 262
 			$new_field = array(
263 263
 				'field_options' => $field->field_options,
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 
269 269
 			FrmField::update( $field_id, $new_field );
270 270
 
271
-            FrmField::delete_form_transient($field->form_id);
271
+            FrmField::delete_form_transient( $field->form_id );
272 272
         }
273 273
 		self::clear_form_cache();
274 274
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 		);
283 283
 		foreach ( $field_cols as $col => $default ) {
284 284
 			$default = ( $default === '' ) ? $field->{$col} : $default;
285
-			$new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default;
285
+			$new_field[$col] = isset( $values['field_options'][$col . '_' . $field->id] ) ? $values['field_options'][$col . '_' . $field->id] : $default;
286 286
 		}
287 287
 	}
288 288
 
@@ -292,17 +292,17 @@  discard block
 block discarded – undo
292 292
      */
293 293
 	public static function set_status( $id, $status ) {
294 294
         if ( 'trash' == $status ) {
295
-            return self::trash($id);
295
+            return self::trash( $id );
296 296
         }
297 297
 
298
-		$statuses  = array( 'published', 'draft', 'trash' );
298
+		$statuses = array( 'published', 'draft', 'trash' );
299 299
         if ( ! in_array( $status, $statuses ) ) {
300 300
             return false;
301 301
         }
302 302
 
303 303
         global $wpdb;
304 304
 
305
-        if ( is_array($id) ) {
305
+        if ( is_array( $id ) ) {
306 306
 			$where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 );
307 307
 			FrmDb::get_where_clause_and_values( $where );
308 308
 			array_unshift( $where['values'], $status );
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
             return self::destroy( $id );
329 329
         }
330 330
 
331
-        $form = self::getOne($id);
331
+        $form = self::getOne( $id );
332 332
         if ( ! $form ) {
333 333
             return false;
334 334
         }
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 	public static function destroy( $id ) {
363 363
         global $wpdb;
364 364
 
365
-        $form = self::getOne($id);
365
+        $form = self::getOne( $id );
366 366
         if ( ! $form ) {
367 367
             return false;
368 368
         }
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
         // Disconnect the entries from this form
372 372
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
373 373
         foreach ( $entries as $entry_id ) {
374
-            FrmEntry::destroy($entry_id);
375
-            unset($entry_id);
374
+            FrmEntry::destroy( $entry_id );
375
+            unset( $entry_id );
376 376
         }
377 377
 
378 378
         // Disconnect the fields from this form
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
         if ( $query_results ) {
383 383
             // Delete all form actions linked to this form
384 384
             $action_control = FrmFormActionsController::get_form_actions( 'email' );
385
-            $action_control->destroy($id, 'all');
385
+            $action_control->destroy( $id, 'all' );
386 386
 
387 387
 			// Clear form caching
388 388
 			self::clear_form_cache();
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 			$form->options = maybe_unserialize( $form->options );
417 417
 			if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
418 418
 				self::destroy( $form->id );
419
-				$count++;
419
+				$count ++;
420 420
 			}
421 421
 
422 422
 			unset( $form );
@@ -428,15 +428,15 @@  discard block
 block discarded – undo
428 428
      * @return string form name
429 429
      */
430 430
     public static function getName( $id ) {
431
-        $form = FrmAppHelper::check_cache($id, 'frm_form');
431
+        $form = FrmAppHelper::check_cache( $id, 'frm_form' );
432 432
         if ( $form ) {
433
-            $r = stripslashes($form->name);
433
+            $r = stripslashes( $form->name );
434 434
             return $r;
435 435
         }
436 436
 
437 437
         $query_key = is_numeric( $id ) ? 'id' : 'form_key';
438 438
         $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
439
-        $r = stripslashes($r);
439
+        $r = stripslashes( $r );
440 440
 
441 441
         return $r;
442 442
     }
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
      */
457 457
 	public static function getKeyById( $id ) {
458 458
         $id = (int) $id;
459
-        $cache = FrmAppHelper::check_cache($id, 'frm_form');
459
+        $cache = FrmAppHelper::check_cache( $id, 'frm_form' );
460 460
         if ( $cache ) {
461 461
             return $cache->form_key;
462 462
         }
@@ -490,17 +490,17 @@  discard block
 block discarded – undo
490 490
 			$table_name = $prefix . 'frm_forms';
491 491
         } else {
492 492
 			$table_name = $wpdb->prefix . 'frm_forms';
493
-            $cache = wp_cache_get($id, 'frm_form');
493
+            $cache = wp_cache_get( $id, 'frm_form' );
494 494
             if ( $cache ) {
495
-                if ( isset($cache->options) ) {
496
-                    $cache->options = maybe_unserialize($cache->options);
495
+                if ( isset( $cache->options ) ) {
496
+                    $cache->options = maybe_unserialize( $cache->options );
497 497
                 }
498 498
 
499
-                return stripslashes_deep($cache);
499
+                return stripslashes_deep( $cache );
500 500
             }
501 501
         }
502 502
 
503
-        if ( is_numeric($id) ) {
503
+        if ( is_numeric( $id ) ) {
504 504
             $where = array( 'id' => $id );
505 505
         } else {
506 506
             $where = array( 'form_key' => $id );
@@ -508,11 +508,11 @@  discard block
 block discarded – undo
508 508
 
509 509
         $results = FrmDb::get_row( $table_name, $where );
510 510
 
511
-        if ( isset($results->options) ) {
511
+        if ( isset( $results->options ) ) {
512 512
 			FrmAppHelper::set_cache( $results->id, $results, 'frm_form' );
513
-            $results->options = maybe_unserialize($results->options);
513
+            $results->options = maybe_unserialize( $results->options );
514 514
         }
515
-        return stripslashes_deep($results);
515
+        return stripslashes_deep( $results );
516 516
     }
517 517
 
518 518
     /**
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
 			$results = reset( $results );
542 542
 		}
543 543
 
544
-        return stripslashes_deep($results);
544
+        return stripslashes_deep( $results );
545 545
     }
546 546
 
547 547
 	/**
@@ -581,19 +581,19 @@  discard block
 block discarded – undo
581 581
     	foreach ( $results as $row ) {
582 582
             if ( 'trash' != $row->status ) {
583 583
     	        if ( $row->is_template ) {
584
-					$counts['template']++;
584
+					$counts['template'] ++;
585 585
     	        } else {
586
-					$counts['published']++;
586
+					$counts['published'] ++;
587 587
     	        }
588 588
     	    } else {
589
-				$counts['trash']++;
589
+				$counts['trash'] ++;
590 590
         	}
591 591
 
592 592
     	    if ( 'draft' == $row->status ) {
593
-				$counts['draft']++;
593
+				$counts['draft'] ++;
594 594
     	    }
595 595
 
596
-    		unset($row);
596
+    		unset( $row );
597 597
     	}
598 598
 
599 599
     	$counts = (object) $counts;
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
 	public static function validate( $values ) {
620 620
         $errors = array();
621 621
 
622
-        return apply_filters('frm_validate_form', $errors, $values);
622
+        return apply_filters( 'frm_validate_form', $errors, $values );
623 623
     }
624 624
 
625 625
 	public static function get_params( $form = null ) {
@@ -631,11 +631,11 @@  discard block
 block discarded – undo
631 631
 			self::maybe_get_form( $form );
632 632
 		}
633 633
 
634
-		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
635
-			return $frm_vars['form_params'][ $form->id ];
634
+		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) {
635
+			return $frm_vars['form_params'][$form->id];
636 636
 		}
637 637
 
638
-		$action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
638
+		$action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
639 639
 		$action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form );
640 640
 
641 641
 		$default_values = array(
@@ -653,15 +653,15 @@  discard block
 block discarded – undo
653 653
 			//if there are two forms on the same page, make sure not to submit both
654 654
 			foreach ( $default_values as $var => $default ) {
655 655
 				if ( $var == 'action' ) {
656
-					$values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
656
+					$values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
657 657
 				} else {
658
-					$values[ $var ] = FrmAppHelper::get_param( $var, $default );
658
+					$values[$var] = FrmAppHelper::get_param( $var, $default );
659 659
 				}
660 660
 				unset( $var, $default );
661 661
 			}
662 662
 		} else {
663 663
 			foreach ( $default_values as $var => $default ) {
664
-				$values[ $var ] = $default;
664
+				$values[$var] = $default;
665 665
 				unset( $var, $default );
666 666
 			}
667 667
 		}
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 	public static function list_page_params() {
677 677
 		$values = array();
678 678
 		foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '' ) as $var => $default ) {
679
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default );
679
+			$values[$var] = FrmAppHelper::get_param( $var, $default );
680 680
 		}
681 681
 
682 682
 		return $values;
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
 			'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '',
697 697
 			'keep_post' => '',
698 698
 		) as $var => $default ) {
699
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default );
699
+			$values[$var] = FrmAppHelper::get_param( $var, $default );
700 700
 		}
701 701
 
702 702
 		return $values;
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
 		$small_form = new stdClass();
754 754
 		foreach ( array( 'id', 'form_key', 'name' ) as $var ) {
755 755
 			$small_form->{$var} = $form->{$var};
756
-			unset($var);
756
+			unset( $var );
757 757
 		}
758 758
 
759 759
 		$frm_vars['forms_loaded'][] = $small_form;
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 			$frm_vars['load_css'] = true;
764 764
 		}
765 765
 
766
-		return ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load );
766
+		return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load );
767 767
 	}
768 768
 
769 769
 	public static function show_submit( $form ) {
@@ -777,6 +777,6 @@  discard block
 block discarded – undo
777 777
 	 */
778 778
 	public static function get_option( $atts ) {
779 779
 		$form = $atts['form'];
780
-		return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $atts['default'];
780
+		return isset( $form->options[$atts['option']] ) ? $form->options[$atts['option']] : $atts['default'];
781 781
 	}
782 782
 }
Please login to merge, or discard this patch.
classes/models/FrmField.php 2 patches
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 
6 6
 class FrmField {
7 7
 
8
-    static $use_cache = true;
8
+	static $use_cache = true;
9 9
 	static $transient_size = 200;
10 10
 
11 11
 	public static function field_selection() {
@@ -52,39 +52,39 @@  discard block
 block discarded – undo
52 52
 		));
53 53
 	}
54 54
 
55
-    public static function create( $values, $return = true ) {
56
-        global $wpdb, $frm_duplicate_ids;
55
+	public static function create( $values, $return = true ) {
56
+		global $wpdb, $frm_duplicate_ids;
57 57
 
58
-        $new_values = array();
59
-        $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
58
+		$new_values = array();
59
+		$key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
60 60
 		$new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
61 61
 
62 62
 		foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
63 63
 			$new_values[ $col ] = $values[ $col ];
64
-        }
64
+		}
65 65
 
66
-        $new_values['options'] = $values['options'];
66
+		$new_values['options'] = $values['options'];
67 67
 
68
-        $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
-        $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
-        $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
71
-        $new_values['field_options'] = $values['field_options'];
72
-        $new_values['created_at'] = current_time('mysql', 1);
68
+		$new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
+		$new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
+		$new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
71
+		$new_values['field_options'] = $values['field_options'];
72
+		$new_values['created_at'] = current_time('mysql', 1);
73 73
 
74 74
 		if ( isset( $values['id'] ) ) {
75 75
 			$frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
76
-            $new_values = apply_filters('frm_duplicated_field', $new_values);
77
-        }
76
+			$new_values = apply_filters('frm_duplicated_field', $new_values);
77
+		}
78 78
 
79 79
 		foreach ( $new_values as $k => $v ) {
80
-            if ( is_array( $v ) ) {
80
+			if ( is_array( $v ) ) {
81 81
 				$new_values[ $k ] = serialize( $v );
82 82
 			}
83
-            unset( $k, $v );
84
-        }
83
+			unset( $k, $v );
84
+		}
85 85
 
86
-        //if(isset($values['id']) and is_numeric($values['id']))
87
-        //    $new_values['id'] = $values['id'];
86
+		//if(isset($values['id']) and is_numeric($values['id']))
87
+		//    $new_values['id'] = $values['id'];
88 88
 
89 89
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values );
90 90
 		$new_id = 0;
@@ -105,22 +105,22 @@  discard block
 block discarded – undo
105 105
 		} else {
106 106
 			return false;
107 107
 		}
108
-    }
108
+	}
109 109
 
110
-    public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
111
-        global $frm_duplicate_ids;
110
+	public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
111
+		global $frm_duplicate_ids;
112 112
 
113 113
 		$where = array( array( 'or' => 1, 'fi.form_id' => $old_form_id, 'fr.parent_form_id' => $old_form_id ) );
114 114
 		$fields = self::getAll( $where, 'field_order', '', $blog_id );
115 115
 
116
-        foreach ( (array) $fields as $field ) {
117
-            $new_key = ($copy_keys) ? $field->field_key : '';
118
-            if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
119
-                $new_key = rtrim($new_key, 2);
120
-            }
116
+		foreach ( (array) $fields as $field ) {
117
+			$new_key = ($copy_keys) ? $field->field_key : '';
118
+			if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
119
+				$new_key = rtrim($new_key, 2);
120
+			}
121 121
 
122
-            $values = array();
123
-            FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
122
+			$values = array();
123
+			FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
124 124
 
125 125
 			// If this is a repeating section, create new form
126 126
 			if ( self::is_repeating_field( $field ) ) {
@@ -139,16 +139,16 @@  discard block
 block discarded – undo
139 139
 				$values['form_id'] = $new_repeat_form_id;
140 140
 			}
141 141
 
142
-            $values = apply_filters('frm_duplicated_field', $values);
143
-            $new_id = self::create($values);
144
-            $frm_duplicate_ids[ $field->id ] = $new_id;
145
-            $frm_duplicate_ids[ $field->field_key ] = $new_id;
146
-            unset($field);
147
-        }
148
-    }
142
+			$values = apply_filters('frm_duplicated_field', $values);
143
+			$new_id = self::create($values);
144
+			$frm_duplicate_ids[ $field->id ] = $new_id;
145
+			$frm_duplicate_ids[ $field->field_key ] = $new_id;
146
+			unset($field);
147
+		}
148
+	}
149 149
 
150 150
 	public static function update( $id, $values ) {
151
-        global $wpdb;
151
+		global $wpdb;
152 152
 
153 153
 		$id = absint( $id );
154 154
 
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 			$values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id );
157 157
 		}
158 158
 
159
-        if ( isset($values['required']) ) {
160
-            $values['required'] = (int) $values['required'];
161
-        }
159
+		if ( isset($values['required']) ) {
160
+			$values['required'] = (int) $values['required'];
161
+		}
162 162
 
163 163
 		self::preserve_format_option_backslashes( $values );
164 164
 
@@ -175,41 +175,41 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) );
177 177
 
178
-        $form_id = 0;
178
+		$form_id = 0;
179 179
 		if ( isset( $values['form_id'] ) ) {
180
-            $form_id = absint( $values['form_id'] );
180
+			$form_id = absint( $values['form_id'] );
181 181
 		} else {
182
-            $field = self::getOne($id);
183
-            if ( $field ) {
184
-                $form_id = $field->form_id;
185
-            }
186
-            unset($field);
187
-        }
188
-        unset($values);
182
+			$field = self::getOne($id);
183
+			if ( $field ) {
184
+				$form_id = $field->form_id;
185
+			}
186
+			unset($field);
187
+		}
188
+		unset($values);
189 189
 
190 190
 		if ( $query_results ) {
191
-            wp_cache_delete( $id, 'frm_field' );
192
-            if ( $form_id ) {
193
-                self::delete_form_transient( $form_id );
194
-            }
195
-        }
191
+			wp_cache_delete( $id, 'frm_field' );
192
+			if ( $form_id ) {
193
+				self::delete_form_transient( $form_id );
194
+			}
195
+		}
196 196
 
197
-        return $query_results;
198
-    }
197
+		return $query_results;
198
+	}
199 199
 
200 200
 	/**
201
-	* Keep backslashes in the phone format option
202
-	*
203
-	* @since 2.0.8
204
-	* @param $values array - pass by reference
205
-	*/
201
+	 * Keep backslashes in the phone format option
202
+	 *
203
+	 * @since 2.0.8
204
+	 * @param $values array - pass by reference
205
+	 */
206 206
 	private static function preserve_format_option_backslashes( &$values ) {
207 207
 		if ( isset( $values['field_options']['format'] ) ) {
208 208
 			$values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
209 209
 		}
210 210
 	}
211 211
 
212
-    public static function destroy( $id ) {
212
+	public static function destroy( $id ) {
213 213
 		global $wpdb;
214 214
 
215 215
 		do_action( 'frm_before_destroy_field', $id );
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 
225 225
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
226 226
 		return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
227
-    }
227
+	}
228 228
 
229 229
 	public static function delete_form_transient( $form_id ) {
230 230
 		$form_id = absint( $form_id );
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
 
239 239
 		FrmAppHelper::cache_delete_group( 'frm_field' );
240 240
 
241
-        $form = FrmForm::getOne($form_id);
242
-        if ( $form && $form->parent_form_id && $form->parent_form_id != $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 && $form->parent_form_id != $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 null;
259 259
 		}
260 260
 
261
-        global $wpdb;
261
+		global $wpdb;
262 262
 
263
-        $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
263
+		$where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
264 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) ) {
272
+		if ( is_numeric($id) ) {
273 273
 			FrmAppHelper::set_cache( $results->field_key, $results, 'frm_field' );
274
-        } else if ( $results ) {
274
+		} else if ( $results ) {
275 275
 			FrmAppHelper::set_cache( $results->id, $results, 'frm_field' );
276
-        }
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 || empty( $results ) ) {
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 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 ) {
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 436
 				$prefix = $wpmuBaseTablePrefix . $blog_id . '_';
437
-            } else {
438
-                $prefix = $wpdb->get_blog_prefix( $blog_id );
439
-            }
437
+			} else {
438
+				$prefix = $wpdb->get_blog_prefix( $blog_id );
439
+			}
440 440
 
441 441
 			$table_name = $prefix . 'frm_fields';
442 442
 			$form_table_name = $prefix . 'frm_forms';
443 443
 		} else {
444 444
 			$table_name = $wpdb->prefix . 'frm_fields';
445 445
 			$form_table_name = $wpdb->prefix . 'frm_forms';
446
-        }
446
+		}
447 447
 
448 448
 		if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
449 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
 
@@ -701,8 +701,8 @@  discard block
 block discarded – undo
701 701
 	}
702 702
 
703 703
 	/**
704
-	* @since 2.0.09
705
-	*/
704
+	 * @since 2.0.09
705
+	 */
706 706
 	public static function is_repeating_field( $field ) {
707 707
 		if ( is_array( $field ) ) {
708 708
 			$is_repeating_field = ( 'divider' == $field['type'] );
@@ -712,14 +712,14 @@  discard block
 block discarded – undo
712 712
 		return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
713 713
 	}
714 714
 
715
-    /**
716
-     * @param string $key
717
-     * @return int field id
718
-     */
715
+	/**
716
+	 * @param string $key
717
+	 * @return int field id
718
+	 */
719 719
 	public static function get_id_by_key( $key ) {
720
-        $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
721
-        return $id;
722
-    }
720
+		$id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
721
+		return $id;
722
+	}
723 723
 
724 724
 	/**
725 725
 	 * @param string $id
Please login to merge, or discard this patch.
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 	static $transient_size = 200;
10 10
 
11 11
 	public static function field_selection() {
12
-		$fields = apply_filters('frm_available_fields', array(
12
+		$fields = apply_filters( 'frm_available_fields', array(
13 13
 			'text'      => __( 'Single Line Text', 'formidable' ),
14 14
 			'textarea'  => __( 'Paragraph Text', 'formidable' ),
15 15
 			'checkbox'  => __( 'Checkboxes', 'formidable' ),
@@ -18,13 +18,13 @@  discard block
 block discarded – undo
18 18
 			'email'     => __( 'Email Address', 'formidable' ),
19 19
 			'url'       => __( 'Website/URL', 'formidable' ),
20 20
 			'captcha'   => __( 'reCAPTCHA', 'formidable' ),
21
-		));
21
+		) );
22 22
 
23 23
 		return $fields;
24 24
 	}
25 25
 
26 26
 	public static function pro_field_selection() {
27
-		return apply_filters('frm_pro_available_fields', array(
27
+		return apply_filters( 'frm_pro_available_fields', array(
28 28
 			'end_divider' => array(
29 29
 				'name'  => __( 'End Section', 'formidable' ),
30 30
 				'switch_from' => 'divider',
@@ -49,36 +49,36 @@  discard block
 block discarded – undo
49 49
 			'tag'       => __( 'Tags', 'formidable' ),
50 50
 			'credit_card' => __( 'Credit Card', 'formidable' ),
51 51
 			'address'   => __( 'Address', 'formidable' ),
52
-		));
52
+		) );
53 53
 	}
54 54
 
55 55
     public static function create( $values, $return = true ) {
56 56
         global $wpdb, $frm_duplicate_ids;
57 57
 
58 58
         $new_values = array();
59
-        $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
59
+        $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name'];
60 60
 		$new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
61 61
 
62 62
 		foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
63
-			$new_values[ $col ] = $values[ $col ];
63
+			$new_values[$col] = $values[$col];
64 64
         }
65 65
 
66 66
         $new_values['options'] = $values['options'];
67 67
 
68
-        $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
-        $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
-        $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
68
+        $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
69
+        $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0;
70
+        $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
71 71
         $new_values['field_options'] = $values['field_options'];
72
-        $new_values['created_at'] = current_time('mysql', 1);
72
+        $new_values['created_at'] = current_time( 'mysql', 1 );
73 73
 
74 74
 		if ( isset( $values['id'] ) ) {
75
-			$frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
76
-            $new_values = apply_filters('frm_duplicated_field', $new_values);
75
+			$frm_duplicate_ids[$values['field_key']] = $new_values['field_key'];
76
+            $new_values = apply_filters( 'frm_duplicated_field', $new_values );
77 77
         }
78 78
 
79 79
 		foreach ( $new_values as $k => $v ) {
80 80
             if ( is_array( $v ) ) {
81
-				$new_values[ $k ] = serialize( $v );
81
+				$new_values[$k] = serialize( $v );
82 82
 			}
83 83
             unset( $k, $v );
84 84
         }
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 
100 100
 		if ( $query_results ) {
101 101
 			if ( isset( $values['id'] ) ) {
102
-				$frm_duplicate_ids[ $values['id'] ] = $new_id;
102
+				$frm_duplicate_ids[$values['id']] = $new_id;
103 103
 			}
104 104
 			return $new_id;
105 105
 		} else {
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 		$fields = self::getAll( $where, 'field_order', '', $blog_id );
115 115
 
116 116
         foreach ( (array) $fields as $field ) {
117
-            $new_key = ($copy_keys) ? $field->field_key : '';
118
-            if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
119
-                $new_key = rtrim($new_key, 2);
117
+            $new_key = ( $copy_keys ) ? $field->field_key : '';
118
+            if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) {
119
+                $new_key = rtrim( $new_key, 2 );
120 120
             }
121 121
 
122 122
             $values = array();
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
 				$values['form_id'] = $new_repeat_form_id;
140 140
 			}
141 141
 
142
-            $values = apply_filters('frm_duplicated_field', $values);
143
-            $new_id = self::create($values);
144
-            $frm_duplicate_ids[ $field->id ] = $new_id;
145
-            $frm_duplicate_ids[ $field->field_key ] = $new_id;
146
-            unset($field);
142
+            $values = apply_filters( 'frm_duplicated_field', $values );
143
+            $new_id = self::create( $values );
144
+            $frm_duplicate_ids[$field->id] = $new_id;
145
+            $frm_duplicate_ids[$field->field_key] = $new_id;
146
+            unset( $field );
147 147
         }
148 148
     }
149 149
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 			$values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id );
157 157
 		}
158 158
 
159
-        if ( isset($values['required']) ) {
159
+        if ( isset( $values['required'] ) ) {
160 160
             $values['required'] = (int) $values['required'];
161 161
         }
162 162
 
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 
169 169
 		// serialize array values
170 170
 		foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) {
171
-			if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) {
172
-				$values[ $opt ] = serialize( $values[ $opt ] );
171
+			if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) {
172
+				$values[$opt] = serialize( $values[$opt] );
173 173
 			}
174 174
 		}
175 175
 
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 		if ( isset( $values['form_id'] ) ) {
180 180
             $form_id = absint( $values['form_id'] );
181 181
 		} else {
182
-            $field = self::getOne($id);
182
+            $field = self::getOne( $id );
183 183
             if ( $field ) {
184 184
                 $form_id = $field->form_id;
185 185
             }
186
-            unset($field);
186
+            unset( $field );
187 187
         }
188
-        unset($values);
188
+        unset( $values );
189 189
 
190 190
 		if ( $query_results ) {
191 191
             wp_cache_delete( $id, 'frm_field' );
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 
239 239
 		FrmAppHelper::cache_delete_group( 'frm_field' );
240 240
 
241
-        $form = FrmForm::getOne($form_id);
241
+        $form = FrmForm::getOne( $form_id );
242 242
         if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
243 243
             self::delete_form_transient( $form->parent_form_id );
244 244
         }
@@ -260,16 +260,16 @@  discard block
 block discarded – undo
260 260
 
261 261
         global $wpdb;
262 262
 
263
-        $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
263
+        $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s';
264 264
 		$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id );
265 265
 
266 266
         $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
267 267
 
268
-        if ( empty($results) ) {
268
+        if ( empty( $results ) ) {
269 269
             return $results;
270 270
         }
271 271
 
272
-        if ( is_numeric($id) ) {
272
+        if ( is_numeric( $id ) ) {
273 273
 			FrmAppHelper::set_cache( $results->field_key, $results, 'frm_field' );
274 274
         } else if ( $results ) {
275 275
 			FrmAppHelper::set_cache( $results->id, $results, 'frm_field' );
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 
278 278
 		self::prepare_options( $results );
279 279
 
280
-        return stripslashes_deep($results);
280
+        return stripslashes_deep( $results );
281 281
     }
282 282
 
283 283
     /**
@@ -310,20 +310,20 @@  discard block
 block discarded – undo
310 310
                     continue;
311 311
                 }
312 312
 
313
-				$fields[ $result->id ] = $result;
314
-                $count++;
313
+				$fields[$result->id] = $result;
314
+                $count ++;
315 315
                 if ( $limit == 1 ) {
316 316
                     $fields = $result;
317 317
                     break;
318 318
                 }
319 319
 
320
-                if ( ! empty($limit) && $count >= $limit ) {
320
+                if ( ! empty( $limit ) && $count >= $limit ) {
321 321
                     break;
322 322
                 }
323 323
 
324
-                unset($result);
324
+                unset( $result );
325 325
             }
326
-            return stripslashes_deep($fields);
326
+            return stripslashes_deep( $fields );
327 327
         }
328 328
 
329 329
         self::$use_cache = false;
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 		self::maybe_include_repeating_fields( $inc_sub, $where );
333 333
 		$results = self::getAll( $where, 'field_order', $limit );
334 334
         self::$use_cache = true;
335
-        self::include_sub_fields($results, $inc_sub, $type);
335
+        self::include_sub_fields( $results, $inc_sub, $type );
336 336
 
337 337
         return $results;
338 338
     }
@@ -344,15 +344,15 @@  discard block
 block discarded – undo
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 351
             $fields = array();
352 352
             $count = 0;
353 353
             foreach ( $results as $result ) {
354
-				$fields[ $result->id ] = $result;
355
-                if ( ! empty($limit) && $count >= $limit ) {
354
+				$fields[$result->id] = $result;
355
+                if ( ! empty( $limit ) && $count >= $limit ) {
356 356
                     break;
357 357
                 }
358 358
             }
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
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
 
@@ -399,22 +399,22 @@  discard block
 block discarded – undo
399 399
         $form_fields = $results;
400 400
 		$index_offset = 1;
401 401
         foreach ( $form_fields as $k => $field ) {
402
-            if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
402
+            if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
403 403
                 continue;
404 404
             }
405 405
 
406 406
             if ( $type == 'all' ) {
407 407
                 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
408 408
             } else {
409
-                $sub_fields = self::get_all_types_in_form($field->form_id, $type);
409
+                $sub_fields = self::get_all_types_in_form( $field->form_id, $type );
410 410
             }
411 411
 
412
-            if ( ! empty($sub_fields) ) {
412
+            if ( ! empty( $sub_fields ) ) {
413 413
 				$index = $k + $index_offset;
414 414
 				$index_offset += count( $sub_fields );
415
-				array_splice($results, $index, 0, $sub_fields);
415
+				array_splice( $results, $index, 0, $sub_fields );
416 416
             }
417
-            unset($field, $sub_fields);
417
+            unset( $field, $sub_fields );
418 418
         }
419 419
     }
420 420
 
@@ -422,9 +422,9 @@  discard block
 block discarded – undo
422 422
 		$cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
423 423
         if ( self::$use_cache ) {
424 424
             // make sure old cache doesn't get saved as a transient
425
-            $results = wp_cache_get($cache_key, 'frm_field');
425
+            $results = wp_cache_get( $cache_key, 'frm_field' );
426 426
             if ( false !== $results ) {
427
-                return stripslashes_deep($results);
427
+                return stripslashes_deep( $results );
428 428
             }
429 429
         }
430 430
 
@@ -449,16 +449,16 @@  discard block
 block discarded – undo
449 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 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 455
         $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
456 456
 
457
-        if ( is_array($where) ) {
457
+        if ( is_array( $where ) ) {
458 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 );
@@ -481,9 +481,9 @@  discard block
 block discarded – undo
481 481
 				FrmAppHelper::set_cache( $result->id, $result, 'frm_field' );
482 482
 				FrmAppHelper::set_cache( $result->field_key, $result, 'frm_field' );
483 483
 
484
-				$results[ $r_key ]->field_options = maybe_unserialize( $result->field_options );
485
-				$results[ $r_key ]->options = maybe_unserialize( $result->options );
486
-				$results[ $r_key ]->default_value = maybe_unserialize( $result->default_value );
484
+				$results[$r_key]->field_options = maybe_unserialize( $result->field_options );
485
+				$results[$r_key]->options = maybe_unserialize( $result->options );
486
+				$results[$r_key]->default_value = maybe_unserialize( $result->default_value );
487 487
 
488 488
 				unset( $r_key, $result );
489 489
 			}
@@ -502,8 +502,8 @@  discard block
 block discarded – undo
502 502
 	private static function prepare_options( &$results ) {
503 503
 		$results->field_options = maybe_unserialize( $results->field_options );
504 504
 
505
-		$results->options = maybe_unserialize($results->options);
506
-		$results->default_value = maybe_unserialize($results->default_value);
505
+		$results->options = maybe_unserialize( $results->options );
506
+		$results->default_value = maybe_unserialize( $results->default_value );
507 507
 	}
508 508
 
509 509
 	/**
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 
531 531
 			if ( count( $next_fields ) >= self::$transient_size ) {
532 532
 				// if this transient is full, check for another
533
-				$next++;
533
+				$next ++;
534 534
 				self::get_next_transient( $fields, $base_name, $next );
535 535
 			}
536 536
 		}
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
 				return;
557 557
 			}
558 558
 
559
-			$next++;
559
+			$next ++;
560 560
 		}
561 561
 	}
562 562
 
@@ -586,8 +586,8 @@  discard block
 block discarded – undo
586 586
 			$is_multi_value_field = (
587 587
 				$field['type'] == 'checkbox' ||
588 588
 				$field['type'] == 'address' ||
589
-				( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) ||
590
-				( $field['type'] == 'lookup' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) ||
589
+				( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'checkbox' ) ||
590
+				( $field['type'] == 'lookup' && isset( $field['data_type'] ) && $field['data_type'] == 'checkbox' ) ||
591 591
 				self::is_multiple_select( $field )
592 592
 			);
593 593
 
@@ -612,9 +612,9 @@  discard block
 block discarded – undo
612 612
 	 */
613 613
 	public static function is_multiple_select( $field ) {
614 614
 		if ( is_array( $field ) ) {
615
-			return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select') ) );
615
+			return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select' ) ) );
616 616
 		} else {
617
-			return self::is_option_true( $field, 'multiple' ) && ( ( $field->type == 'select' || ( $field->type == 'data' && isset($field->field_options['data_type'] ) && $field->field_options['data_type'] == 'select') ) );
617
+			return self::is_option_true( $field, 'multiple' ) && ( ( $field->type == 'select' || ( $field->type == 'data' && isset( $field->field_options['data_type'] ) && $field->field_options['data_type'] == 'select' ) ) );
618 618
 		}
619 619
 	}
620 620
 
@@ -661,23 +661,23 @@  discard block
 block discarded – undo
661 661
 	}
662 662
 
663 663
 	public static function is_option_true_in_array( $field, $option ) {
664
-		return isset( $field[ $option ] ) && $field[ $option ];
664
+		return isset( $field[$option] ) && $field[$option];
665 665
 	}
666 666
 
667 667
 	public static function is_option_true_in_object( $field, $option ) {
668
-		return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
668
+		return isset( $field->field_options[$option] ) && $field->field_options[$option];
669 669
 	}
670 670
 
671 671
 	public static function is_option_empty_in_array( $field, $option ) {
672
-		return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
672
+		return ! isset( $field[$option] ) || empty( $field[$option] );
673 673
 	}
674 674
 
675 675
 	public static function is_option_empty_in_object( $field, $option ) {
676
-		return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
676
+		return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] );
677 677
 	}
678 678
 
679 679
 	public static function is_option_value_in_object( $field, $option ) {
680
-		return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
680
+		return isset( $field->field_options[$option] ) && $field->field_options[$option] != '';
681 681
 	}
682 682
 
683 683
 	/**
@@ -693,11 +693,11 @@  discard block
 block discarded – undo
693 693
 	}
694 694
 
695 695
 	public static function get_option_in_array( $field, $option ) {
696
-		return $field[ $option ];
696
+		return $field[$option];
697 697
 	}
698 698
 
699 699
 	public static function get_option_in_object( $field, $option ) {
700
-		return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
700
+		return isset( $field->field_options[$option] ) ? $field->field_options[$option] : '';
701 701
 	}
702 702
 
703 703
 	/**
Please login to merge, or discard this patch.
classes/models/FrmEntry.php 2 patches
Indentation   +374 added lines, -374 removed lines patch added patch discarded remove patch
@@ -6,11 +6,11 @@  discard block
 block discarded – undo
6 6
 class FrmEntry {
7 7
 
8 8
 	/**
9
-	* Create a new entry
10
-	*
11
-	* @param array $values
12
-	* @return int | boolean $entry_id
13
-	*/
9
+	 * Create a new entry
10
+	 *
11
+	 * @param array $values
12
+	 * @return int | boolean $entry_id
13
+	 */
14 14
 	public static function create( $values ) {
15 15
 		$entry_id = self::create_entry( $values, 'standard' );
16 16
 
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	/**
21
-	* Create a new entry with some differences depending on type
22
-	*
23
-	* @param array $values
24
-	* @param string $type
25
-	* @return int | boolean $entry_id
26
-	*/
21
+	 * Create a new entry with some differences depending on type
22
+	 *
23
+	 * @param array $values
24
+	 * @param string $type
25
+	 * @return int | boolean $entry_id
26
+	 */
27 27
 	private static function create_entry( $values, $type ) {
28 28
 		$new_values = self::before_insert_entry_in_database( $values, $type );
29 29
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 		return $entry_id;
38 38
 	}
39 39
 
40
-    /**
41
-     * check for duplicate entries created in the last minute
42
-     * @return boolean
43
-     */
40
+	/**
41
+	 * check for duplicate entries created in the last minute
42
+	 * @return boolean
43
+	 */
44 44
 	public static function is_duplicate( $new_values, $values ) {
45 45
 		$duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values );
46 46
 
@@ -48,55 +48,55 @@  discard block
 block discarded – undo
48 48
 			return false;
49 49
 		}
50 50
 
51
-        $check_val = $new_values;
51
+		$check_val = $new_values;
52 52
 		$check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) );
53 53
 
54 54
 		unset( $check_val['created_at'], $check_val['updated_at'] );
55 55
 		unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
56 56
 
57
-        if ( $new_values['item_key'] == $new_values['name'] ) {
58
-            unset($check_val['name']);
59
-        }
57
+		if ( $new_values['item_key'] == $new_values['name'] ) {
58
+			unset($check_val['name']);
59
+		}
60 60
 
61
-        global $wpdb;
61
+		global $wpdb;
62 62
 		$entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
63 63
 
64
-        if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
65
-            return false;
66
-        }
64
+		if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
65
+			return false;
66
+		}
67 67
 
68
-        $is_duplicate = false;
69
-        foreach ( $entry_exists as $entry_exist ) {
70
-            $is_duplicate = true;
68
+		$is_duplicate = false;
69
+		foreach ( $entry_exists as $entry_exist ) {
70
+			$is_duplicate = true;
71 71
 
72
-            //add more checks here to make sure it's a duplicate
73
-            $metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
74
-            $field_metas = array();
75
-            foreach ( $metas as $meta ) {
72
+			//add more checks here to make sure it's a duplicate
73
+			$metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
74
+			$field_metas = array();
75
+			foreach ( $metas as $meta ) {
76 76
 				$field_metas[ $meta->field_id ] = $meta->meta_value;
77
-            }
78
-
79
-            // If prev entry is empty and current entry is not, they are not duplicates
80
-            $filtered_vals = array_filter( $values['item_meta'] );
81
-            if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
82
-                return false;
83
-            }
84
-
85
-            $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
86
-            foreach ( $diff as $field_id => $meta_value ) {
87
-                if ( ! empty($meta_value) ) {
88
-                    $is_duplicate = false;
89
-                    continue;
90
-                }
91
-            }
92
-
93
-            if ( $is_duplicate ) {
77
+			}
78
+
79
+			// If prev entry is empty and current entry is not, they are not duplicates
80
+			$filtered_vals = array_filter( $values['item_meta'] );
81
+			if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
82
+				return false;
83
+			}
84
+
85
+			$diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
86
+			foreach ( $diff as $field_id => $meta_value ) {
87
+				if ( ! empty($meta_value) ) {
88
+					$is_duplicate = false;
89
+					continue;
90
+				}
91
+			}
92
+
93
+			if ( $is_duplicate ) {
94 94
 				break;
95
-            }
96
-        }
95
+			}
96
+		}
97 97
 
98
-        return $is_duplicate;
99
-    }
98
+		return $is_duplicate;
99
+	}
100 100
 
101 101
 	/**
102 102
 	 * Determine if an entry needs to be checked as a possible duplicate
@@ -125,48 +125,48 @@  discard block
 block discarded – undo
125 125
 		return true;
126 126
 	}
127 127
 
128
-    public static function duplicate( $id ) {
129
-        global $wpdb;
128
+	public static function duplicate( $id ) {
129
+		global $wpdb;
130 130
 
131
-        $values = self::getOne( $id );
131
+		$values = self::getOne( $id );
132 132
 
133
-        $new_values = array();
133
+		$new_values = array();
134 134
 		$new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
135
-        $new_values['name'] = $values->name;
136
-        $new_values['is_draft'] = $values->is_draft;
135
+		$new_values['name'] = $values->name;
136
+		$new_values['is_draft'] = $values->is_draft;
137 137
 		$new_values['user_id'] = (int) $values->user_id;
138 138
 		$new_values['updated_by'] = (int) $values->user_id;
139
-        $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
139
+		$new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
140 140
 		$new_values['created_at'] = current_time( 'mysql', 1 );
141 141
 		$new_values['updated_at'] = $new_values['created_at'];
142 142
 
143 143
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
144
-        if ( ! $query_results ) {
145
-            return false;
146
-        }
144
+		if ( ! $query_results ) {
145
+			return false;
146
+		}
147 147
 
148
-        $entry_id = $wpdb->insert_id;
148
+		$entry_id = $wpdb->insert_id;
149 149
 
150
-        global $frm_vars;
151
-        if ( ! isset($frm_vars['saved_entries']) ) {
152
-            $frm_vars['saved_entries'] = array();
153
-        }
154
-        $frm_vars['saved_entries'][] = (int) $entry_id;
150
+		global $frm_vars;
151
+		if ( ! isset($frm_vars['saved_entries']) ) {
152
+			$frm_vars['saved_entries'] = array();
153
+		}
154
+		$frm_vars['saved_entries'][] = (int) $entry_id;
155 155
 
156
-        FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
156
+		FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
157 157
 		self::clear_cache();
158 158
 
159 159
 		do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
160
-        return $entry_id;
161
-    }
160
+		return $entry_id;
161
+	}
162 162
 
163 163
 	/**
164
-	* Update an entry (not via XML)
165
-	*
166
-	* @param int $id
167
-	* @param array $values
168
-	* @return boolean|int $update_results
169
-	*/
164
+	 * Update an entry (not via XML)
165
+	 *
166
+	 * @param int $id
167
+	 * @param array $values
168
+	 * @return boolean|int $update_results
169
+	 */
170 170
 	public static function update( $id, $values ) {
171 171
 		$update_results = self::update_entry( $id, $values, 'standard' );
172 172
 
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 	}
175 175
 
176 176
 	/**
177
-	* Update an entry with some differences depending on the update type
178
-	*
179
-	* @since 2.0.16
180
-	*
181
-	* @param int $id
182
-	* @param array $values
183
-	* @return boolean|int $query_results
184
-	*/
177
+	 * Update an entry with some differences depending on the update type
178
+	 *
179
+	 * @since 2.0.16
180
+	 *
181
+	 * @param int $id
182
+	 * @param array $values
183
+	 * @return boolean|int $query_results
184
+	 */
185 185
 	private static function update_entry( $id, $values, $update_type ) {
186 186
 		global $wpdb;
187 187
 
@@ -200,34 +200,34 @@  discard block
 block discarded – undo
200 200
 	}
201 201
 
202 202
 	public static function destroy( $id ) {
203
-        global $wpdb;
204
-        $id = (int) $id;
203
+		global $wpdb;
204
+		$id = (int) $id;
205 205
 
206 206
 		$entry = self::getOne( $id );
207
-        if ( ! $entry ) {
208
-            $result = false;
209
-            return $result;
210
-        }
207
+		if ( ! $entry ) {
208
+			$result = false;
209
+			return $result;
210
+		}
211 211
 
212
-        do_action('frm_before_destroy_entry', $id, $entry);
212
+		do_action('frm_before_destroy_entry', $id, $entry);
213 213
 
214 214
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
215 215
 		$result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
216 216
 
217 217
 		self::clear_cache();
218 218
 
219
-        return $result;
220
-    }
219
+		return $result;
220
+	}
221 221
 
222 222
 	public static function update_form( $id, $value, $form_id ) {
223
-        global $wpdb;
224
-        $form_id = isset($value) ? $form_id : null;
223
+		global $wpdb;
224
+		$form_id = isset($value) ? $form_id : null;
225 225
 		$result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
226 226
 		if ( $result ) {
227 227
 			self::clear_cache();
228 228
 		}
229
-        return $result;
230
-    }
229
+		return $result;
230
+	}
231 231
 
232 232
 	/**
233 233
 	 * Clear entry caching
@@ -263,159 +263,159 @@  discard block
 block discarded – undo
263 263
 	}
264 264
 
265 265
 	public static function getOne( $id, $meta = false ) {
266
-        global $wpdb;
266
+		global $wpdb;
267 267
 
268
-        $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
268
+		$query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
269 269
                   LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
270 270
 
271
-        $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
272
-        $query_args = array( $id );
273
-        $query = $wpdb->prepare( $query, $query_args );
271
+		$query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
272
+		$query_args = array( $id );
273
+		$query = $wpdb->prepare( $query, $query_args );
274 274
 
275
-        if ( ! $meta ) {
275
+		if ( ! $meta ) {
276 276
 			$entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
277
-            return stripslashes_deep($entry);
278
-        }
277
+			return stripslashes_deep($entry);
278
+		}
279 279
 
280
-        $entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
281
-        if ( $entry !== false ) {
282
-            return stripslashes_deep($entry);
283
-        }
280
+		$entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
281
+		if ( $entry !== false ) {
282
+			return stripslashes_deep($entry);
283
+		}
284 284
 
285
-        $entry = $wpdb->get_row( $query );
286
-        $entry = self::get_meta($entry);
285
+		$entry = $wpdb->get_row( $query );
286
+		$entry = self::get_meta($entry);
287 287
 
288
-        return stripslashes_deep($entry);
289
-    }
288
+		return stripslashes_deep($entry);
289
+	}
290 290
 
291 291
 	public static function get_meta( $entry ) {
292
-        if ( ! $entry ) {
293
-            return $entry;
294
-        }
292
+		if ( ! $entry ) {
293
+			return $entry;
294
+		}
295 295
 
296
-        global $wpdb;
296
+		global $wpdb;
297 297
 		$metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id', array( 'item_id' => $entry->id, 'field_id !' => 0 ), 'field_id, meta_value, field_key, item_id' );
298 298
 
299
-        $entry->metas = array();
299
+		$entry->metas = array();
300 300
 
301 301
 		$include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
302
-        foreach ( $metas as $meta_val ) {
303
-            if ( $meta_val->item_id == $entry->id ) {
302
+		foreach ( $metas as $meta_val ) {
303
+			if ( $meta_val->item_id == $entry->id ) {
304 304
 				$entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
305 305
 				if ( $include_key ) {
306 306
 					$entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
307 307
 				}
308
-                 continue;
309
-            }
308
+				 continue;
309
+			}
310 310
 
311
-            // include sub entries in an array
311
+			// include sub entries in an array
312 312
 			if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
313 313
 				$entry->metas[ $meta_val->field_id ] = array();
314
-            }
314
+			}
315 315
 
316 316
 			$entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
317 317
 
318
-            unset($meta_val);
319
-        }
320
-        unset($metas);
318
+			unset($meta_val);
319
+		}
320
+		unset($metas);
321 321
 
322 322
 		FrmAppHelper::set_cache( $entry->id, $entry, 'frm_entry' );
323 323
 
324
-        return $entry;
325
-    }
324
+		return $entry;
325
+	}
326 326
 
327
-    /**
328
-     * @param string $id
329
-     */
327
+	/**
328
+	 * @param string $id
329
+	 */
330 330
 	public static function exists( $id ) {
331
-        global $wpdb;
332
-
333
-        if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
334
-            $exists = true;
335
-            return $exists;
336
-        }
337
-
338
-        if ( is_numeric($id) ) {
339
-            $where = array( 'id' => $id );
340
-        } else {
341
-            $where = array( 'item_key' => $id );
342
-        }
331
+		global $wpdb;
332
+
333
+		if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
334
+			$exists = true;
335
+			return $exists;
336
+		}
337
+
338
+		if ( is_numeric($id) ) {
339
+			$where = array( 'id' => $id );
340
+		} else {
341
+			$where = array( 'item_key' => $id );
342
+		}
343 343
 		$id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
344 344
 
345
-        $exists = ($id && $id > 0) ? true : false;
346
-        return $exists;
347
-    }
345
+		$exists = ($id && $id > 0) ? true : false;
346
+		return $exists;
347
+	}
348 348
 
349
-    public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
349
+	public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
350 350
 		global $wpdb;
351 351
 
352
-        $limit = FrmAppHelper::esc_limit($limit);
352
+		$limit = FrmAppHelper::esc_limit($limit);
353 353
 
354
-        $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
355
-        $entries = wp_cache_get($cache_key, 'frm_entry');
354
+		$cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
355
+		$entries = wp_cache_get($cache_key, 'frm_entry');
356 356
 
357
-        if ( false === $entries ) {
358
-            $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
357
+		if ( false === $entries ) {
358
+			$fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
359 359
 			$table = $wpdb->prefix . 'frm_items it ';
360 360
 
361
-            if ( $inc_form ) {
362
-                $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
363
-                $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
364
-            }
361
+			if ( $inc_form ) {
362
+				$fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
363
+				$table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
364
+			}
365 365
 
366
-            if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
367
-    		    // sort by a requested field
368
-                $field_id = (int) $order_matches[1];
366
+			if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
367
+				// sort by a requested field
368
+				$field_id = (int) $order_matches[1];
369 369
 				$fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id;
370 370
 				unset( $order_matches, $field_id );
371
-		    }
371
+			}
372 372
 
373 373
 			// prepare the query
374 374
 			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
375 375
 
376
-            $entries = $wpdb->get_results($query, OBJECT_K);
377
-            unset($query);
376
+			$entries = $wpdb->get_results($query, OBJECT_K);
377
+			unset($query);
378 378
 
379 379
 			FrmAppHelper::set_cache( $cache_key, $entries, 'frm_entry' );
380
-        }
380
+		}
381 381
 
382
-        if ( ! $meta || ! $entries ) {
383
-            return stripslashes_deep($entries);
384
-        }
385
-        unset($meta);
382
+		if ( ! $meta || ! $entries ) {
383
+			return stripslashes_deep($entries);
384
+		}
385
+		unset($meta);
386 386
 
387
-        if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
387
+		if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
388 388
 			$where = array( 'it.form_id' => substr( $where, 11 ) );
389
-        }
389
+		}
390 390
 
391
-        $meta_where = array( 'field_id !' => 0 );
392
-        if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
393
-            $meta_where['fi.form_id'] = $where['it.form_id'];
394
-        } else {
395
-            $meta_where['item_id'] = array_keys( $entries );
396
-        }
391
+		$meta_where = array( 'field_id !' => 0 );
392
+		if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
393
+			$meta_where['fi.form_id'] = $where['it.form_id'];
394
+		} else {
395
+			$meta_where['item_id'] = array_keys( $entries );
396
+		}
397 397
 
398
-        $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
398
+		$metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
399 399
 
400
-        unset( $meta_where );
400
+		unset( $meta_where );
401 401
 
402
-        if ( ! $metas ) {
403
-            return stripslashes_deep($entries);
404
-        }
402
+		if ( ! $metas ) {
403
+			return stripslashes_deep($entries);
404
+		}
405 405
 
406
-        foreach ( $metas as $m_key => $meta_val ) {
407
-            if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
408
-                continue;
409
-            }
406
+		foreach ( $metas as $m_key => $meta_val ) {
407
+			if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
408
+				continue;
409
+			}
410 410
 
411
-            if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
411
+			if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
412 412
 				$entries[ $meta_val->item_id ]->metas = array();
413
-            }
413
+			}
414 414
 
415 415
 			$entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
416 416
 
417
-            unset($m_key, $meta_val);
418
-        }
417
+			unset($m_key, $meta_val);
418
+		}
419 419
 
420 420
 		if ( ! FrmAppHelper::prevent_caching() ) {
421 421
 			foreach ( $entries as $entry ) {
@@ -424,31 +424,31 @@  discard block
 block discarded – undo
424 424
 			}
425 425
 		}
426 426
 
427
-        return stripslashes_deep($entries);
428
-    }
427
+		return stripslashes_deep($entries);
428
+	}
429 429
 
430
-    // Pagination Methods
431
-    public static function getRecordCount( $where = '' ) {
432
-        global $wpdb;
430
+	// Pagination Methods
431
+	public static function getRecordCount( $where = '' ) {
432
+		global $wpdb;
433 433
 		$table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
434 434
 
435
-        if ( is_numeric($where) ) {
436
-            $table_join = 'frm_items';
437
-            $where = array( 'form_id' => $where );
438
-        }
435
+		if ( is_numeric($where) ) {
436
+			$table_join = 'frm_items';
437
+			$where = array( 'form_id' => $where );
438
+		}
439 439
 
440
-        if ( is_array( $where ) ) {
441
-            $count = FrmDb::get_count( $table_join, $where );
442
-        } else {
440
+		if ( is_array( $where ) ) {
441
+			$count = FrmDb::get_count( $table_join, $where );
442
+		} else {
443 443
 			$cache_key = 'count_' . maybe_serialize( $where );
444 444
 			$query = 'SELECT COUNT(*) FROM ' . $table_join . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where );
445 445
 			$count = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, 'get_var' );
446
-        }
446
+		}
447 447
 
448
-        return $count;
449
-    }
448
+		return $count;
449
+	}
450 450
 
451
-    public static function getPageCount( $p_size, $where = '' ) {
451
+	public static function getPageCount( $p_size, $where = '' ) {
452 452
 		$p_size = (int) $p_size;
453 453
 		$count = 1;
454 454
 		if ( $p_size ) {
@@ -459,16 +459,16 @@  discard block
 block discarded – undo
459 459
 		}
460 460
 
461 461
 		return $count;
462
-    }
462
+	}
463 463
 
464 464
 	/**
465
-	* Prepare the data before inserting it into the database
466
-	*
467
-	* @since 2.0.16
468
-	* @param array $values
469
-	* @param string $type
470
-	* @return array $new_values
471
-	*/
465
+	 * Prepare the data before inserting it into the database
466
+	 *
467
+	 * @since 2.0.16
468
+	 * @param array $values
469
+	 * @param string $type
470
+	 * @return array $new_values
471
+	 */
472 472
 	private static function before_insert_entry_in_database( &$values, $type ) {
473 473
 
474 474
 		self::sanitize_entry_post( $values );
@@ -483,13 +483,13 @@  discard block
 block discarded – undo
483 483
 	}
484 484
 
485 485
 	/**
486
-	* Create an entry and perform after create actions
487
-	*
488
-	* @since 2.0.16
489
-	* @param array $values
490
-	* @param array $new_values
491
-	* @return boolean|int $entry_id
492
-	*/
486
+	 * Create an entry and perform after create actions
487
+	 *
488
+	 * @since 2.0.16
489
+	 * @param array $values
490
+	 * @param array $new_values
491
+	 * @return boolean|int $entry_id
492
+	 */
493 493
 	private static function continue_to_create_entry( $values, $new_values ) {
494 494
 		$entry_id = self::insert_entry_into_database( $new_values );
495 495
 		if ( ! $entry_id ) {
@@ -501,37 +501,37 @@  discard block
 block discarded – undo
501 501
 		return $entry_id;
502 502
 	}
503 503
 
504
-    /**
505
-     * Sanitize the POST values before we use them
506
-     *
507
-     * @since 2.0
508
-     * @param array $values The POST values by reference
509
-     */
510
-    public static function sanitize_entry_post( &$values ) {
511
-        $sanitize_method = array(
512
-            'form_id'       => 'absint',
513
-            'frm_action'    => 'sanitize_title',
514
-            'form_key'      => 'sanitize_title',
515
-            'item_key'      => 'sanitize_title',
516
-            'item_name'     => 'sanitize_text_field',
517
-            'frm_saving_draft' => 'absint',
518
-            'is_draft'      => 'absint',
519
-            'post_id'       => 'absint',
520
-            'parent_item_id' => 'absint',
521
-            'created_at'    => 'sanitize_text_field',
522
-            'updated_at'    => 'sanitize_text_field',
523
-        );
524
-
525
-        FrmAppHelper::sanitize_request( $sanitize_method, $values );
526
-    }
527
-
528
-	/**
529
-	* Prepare the new values for inserting into the database
530
-	*
531
-	* @since 2.0.16
532
-	* @param array $values
533
-	* @return array $new_values
534
-	*/
504
+	/**
505
+	 * Sanitize the POST values before we use them
506
+	 *
507
+	 * @since 2.0
508
+	 * @param array $values The POST values by reference
509
+	 */
510
+	public static function sanitize_entry_post( &$values ) {
511
+		$sanitize_method = array(
512
+			'form_id'       => 'absint',
513
+			'frm_action'    => 'sanitize_title',
514
+			'form_key'      => 'sanitize_title',
515
+			'item_key'      => 'sanitize_title',
516
+			'item_name'     => 'sanitize_text_field',
517
+			'frm_saving_draft' => 'absint',
518
+			'is_draft'      => 'absint',
519
+			'post_id'       => 'absint',
520
+			'parent_item_id' => 'absint',
521
+			'created_at'    => 'sanitize_text_field',
522
+			'updated_at'    => 'sanitize_text_field',
523
+		);
524
+
525
+		FrmAppHelper::sanitize_request( $sanitize_method, $values );
526
+	}
527
+
528
+	/**
529
+	 * Prepare the new values for inserting into the database
530
+	 *
531
+	 * @since 2.0.16
532
+	 * @param array $values
533
+	 * @return array $new_values
534
+	 */
535 535
 	private static function package_entry_data( &$values ) {
536 536
 		global $wpdb;
537 537
 
@@ -564,67 +564,67 @@  discard block
 block discarded – undo
564 564
 	}
565 565
 
566 566
 	/**
567
-	* Get the is_draft value for a new entry
568
-	*
569
-	* @since 2.0.16
570
-	* @param array $values
571
-	* @return int
572
-	*/
567
+	 * Get the is_draft value for a new entry
568
+	 *
569
+	 * @since 2.0.16
570
+	 * @param array $values
571
+	 * @return int
572
+	 */
573 573
 	private static function get_is_draft_value( $values ) {
574 574
 		return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
575 575
 	}
576 576
 
577 577
 	/**
578
-	* Get the form_id value for a new entry
579
-	*
580
-	* @since 2.0.16
581
-	* @param array $values
582
-	* @return int|null
583
-	*/
578
+	 * Get the form_id value for a new entry
579
+	 *
580
+	 * @since 2.0.16
581
+	 * @param array $values
582
+	 * @return int|null
583
+	 */
584 584
 	private static function get_form_id( $values ) {
585 585
 		return isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
586 586
 	}
587 587
 
588 588
 	/**
589
-	* Get the post_id value for a new entry
590
-	*
591
-	* @since 2.0.16
592
-	* @param array $values
593
-	* @return int
594
-	*/
589
+	 * Get the post_id value for a new entry
590
+	 *
591
+	 * @since 2.0.16
592
+	 * @param array $values
593
+	 * @return int
594
+	 */
595 595
 	private static function get_post_id( $values ) {
596 596
 		return isset( $values['post_id'] ) ? (int) $values['post_id']: 0;
597 597
 	}
598 598
 
599 599
 	/**
600
-	* Get the parent_item_id value for a new entry
601
-	*
602
-	* @since 2.0.16
603
-	* @param array $values
604
-	* @return int
605
-	*/
600
+	 * Get the parent_item_id value for a new entry
601
+	 *
602
+	 * @since 2.0.16
603
+	 * @param array $values
604
+	 * @return int
605
+	 */
606 606
 	private static function get_parent_item_id( $values ) {
607 607
 		return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id']: 0;
608 608
 	}
609 609
 
610 610
 	/**
611
-	* Get the created_at value for a new entry
612
-	*
613
-	* @since 2.0.16
614
-	* @param array $values
615
-	* @return string
616
-	*/
611
+	 * Get the created_at value for a new entry
612
+	 *
613
+	 * @since 2.0.16
614
+	 * @param array $values
615
+	 * @return string
616
+	 */
617 617
 	private static function get_created_at( $values ) {
618 618
 		return isset( $values['created_at'] ) ? $values['created_at']: current_time('mysql', 1);
619 619
 	}
620 620
 
621 621
 	/**
622
-	* Get the updated_at value for a new entry
623
-	*
624
-	* @since 2.0.16
625
-	* @param array $values
626
-	* @return string
627
-	*/
622
+	 * Get the updated_at value for a new entry
623
+	 *
624
+	 * @since 2.0.16
625
+	 * @param array $values
626
+	 * @return string
627
+	 */
628 628
 	private static function get_updated_at( $values ) {
629 629
 		if ( isset( $values['updated_at'] ) ) {
630 630
 			$updated_at = $values['updated_at'];
@@ -636,12 +636,12 @@  discard block
 block discarded – undo
636 636
 	}
637 637
 
638 638
 	/**
639
-	* Get the description value for a new entry
640
-	*
641
-	* @since 2.0.16
642
-	* @param array $values
643
-	* @return string
644
-	*/
639
+	 * Get the description value for a new entry
640
+	 *
641
+	 * @since 2.0.16
642
+	 * @param array $values
643
+	 * @return string
644
+	 */
645 645
 	private static function get_entry_description( $values ) {
646 646
 		if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
647 647
 			$description = maybe_serialize( $values['description'] );
@@ -656,12 +656,12 @@  discard block
 block discarded – undo
656 656
 	}
657 657
 
658 658
 	/**
659
-	* Get the user_id value for a new entry
660
-	*
661
-	* @since 2.0.16
662
-	* @param array $values
663
-	* @return int
664
-	*/
659
+	 * Get the user_id value for a new entry
660
+	 *
661
+	 * @since 2.0.16
662
+	 * @param array $values
663
+	 * @return int
664
+	 */
665 665
 	private static function get_entry_user_id( $values ) {
666 666
 		if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) {
667 667
 			$user_id = $values['frm_user_id'];
@@ -674,12 +674,12 @@  discard block
 block discarded – undo
674 674
 	}
675 675
 
676 676
 	/**
677
-	* Insert new entry into the database
678
-	*
679
-	* @since 2.0.16
680
-	* @param array $new_values
681
-	* @return int | boolean $entry_id
682
-	*/
677
+	 * Insert new entry into the database
678
+	 *
679
+	 * @since 2.0.16
680
+	 * @param array $new_values
681
+	 * @return int | boolean $entry_id
682
+	 */
683 683
 	private static function insert_entry_into_database( $new_values ) {
684 684
 		global $wpdb;
685 685
 
@@ -695,11 +695,11 @@  discard block
 block discarded – undo
695 695
 	}
696 696
 
697 697
 	/**
698
-	* Add the new entry to global $frm_vars
699
-	*
700
-	* @since 2.0.16
701
-	* @param int $entry_id
702
-	*/
698
+	 * Add the new entry to global $frm_vars
699
+	 *
700
+	 * @since 2.0.16
701
+	 * @param int $entry_id
702
+	 */
703 703
 	private static function add_new_entry_to_frm_vars( $entry_id ) {
704 704
 		global $frm_vars;
705 705
 
@@ -711,12 +711,12 @@  discard block
 block discarded – undo
711 711
 	}
712 712
 
713 713
 	/**
714
-	* Add entry metas, if there are any
715
-	*
716
-	* @since 2.0.16
717
-	* @param array $values
718
-	* @param int $entry_id
719
-	*/
714
+	 * Add entry metas, if there are any
715
+	 *
716
+	 * @since 2.0.16
717
+	 * @param array $values
718
+	 * @param int $entry_id
719
+	 */
720 720
 	private static function maybe_add_entry_metas( $values, $entry_id ) {
721 721
 		if ( isset($values['item_meta']) ) {
722 722
 			FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
@@ -724,12 +724,12 @@  discard block
 block discarded – undo
724 724
 	}
725 725
 
726 726
 	/**
727
-	* Trigger frm_after_create_entry hooks
728
-	*
729
-	* @since 2.0.16
730
-	* @param int $entry_id
731
-	* @param array $new_values
732
-	*/
727
+	 * Trigger frm_after_create_entry hooks
728
+	 *
729
+	 * @since 2.0.16
730
+	 * @param int $entry_id
731
+	 * @param array $new_values
732
+	 */
733 733
 	private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
734 734
 		// this is a child entry
735 735
 		$is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
@@ -739,13 +739,13 @@  discard block
 block discarded – undo
739 739
 	}
740 740
 
741 741
 	/**
742
-	* Actions to perform immediately after an entry is inserted in the frm_items database
743
-	*
744
-	* @since 2.0.16
745
-	* @param array $values
746
-	* @param array $new_values
747
-	* @param int $entry_id
748
-	*/
742
+	 * Actions to perform immediately after an entry is inserted in the frm_items database
743
+	 *
744
+	 * @since 2.0.16
745
+	 * @param array $values
746
+	 * @param array $new_values
747
+	 * @param int $entry_id
748
+	 */
749 749
 	private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
750 750
 
751 751
 		self::add_new_entry_to_frm_vars( $entry_id );
@@ -758,14 +758,14 @@  discard block
 block discarded – undo
758 758
 	}
759 759
 
760 760
 	/**
761
-	* Perform some actions right before updating an entry
762
-	*
763
-	* @since 2.0.16
764
-	* @param int $id
765
-	* @param array $values
766
-	* @param string $update_type
767
-	* @return boolean $update
768
-	*/
761
+	 * Perform some actions right before updating an entry
762
+	 *
763
+	 * @since 2.0.16
764
+	 * @param int $id
765
+	 * @param array $values
766
+	 * @param string $update_type
767
+	 * @return boolean $update
768
+	 */
769 769
 	private static function before_update_entry( $id, &$values, $update_type ) {
770 770
 		$update = true;
771 771
 
@@ -783,13 +783,13 @@  discard block
 block discarded – undo
783 783
 	}
784 784
 
785 785
 	/**
786
-	* Package the entry data for updating
787
-	*
788
-	* @since 2.0.16
789
-	* @param int $id
790
-	* @param array $values
791
-	* @return array $new_values
792
-	*/
786
+	 * Package the entry data for updating
787
+	 *
788
+	 * @since 2.0.16
789
+	 * @param int $id
790
+	 * @param array $values
791
+	 * @return array $new_values
792
+	 */
793 793
 	private static function package_entry_to_update( $id, $values ) {
794 794
 		global $wpdb;
795 795
 
@@ -823,14 +823,14 @@  discard block
 block discarded – undo
823 823
 	}
824 824
 
825 825
 	/**
826
-	* Perform some actions right after updating an entry
827
-	*
828
-	* @since 2.0.16
829
-	* @param boolean|int $query_results
830
-	* @param int $id
831
-	* @param array $values
832
-	* @param array $new_values
833
-	*/
826
+	 * Perform some actions right after updating an entry
827
+	 *
828
+	 * @since 2.0.16
829
+	 * @param boolean|int $query_results
830
+	 * @param int $id
831
+	 * @param array $values
832
+	 * @param array $new_values
833
+	 */
834 834
 	private static function after_update_entry( $query_results, $id, $values, $new_values ) {
835 835
 		if ( $query_results ) {
836 836
 			self::clear_cache();
@@ -852,13 +852,13 @@  discard block
 block discarded – undo
852 852
 	}
853 853
 
854 854
 	/**
855
-	* Create entry from an XML import
856
-	* Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
857
-	*
858
-	* @since 2.0.16
859
-	* @param array $values
860
-	* @return int | boolean $entry_id
861
-	*/
855
+	 * Create entry from an XML import
856
+	 * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
857
+	 *
858
+	 * @since 2.0.16
859
+	 * @param array $values
860
+	 * @return int | boolean $entry_id
861
+	 */
862 862
 	public static function create_entry_from_xml( $values ) {
863 863
 		$entry_id = self::create_entry( $values, 'xml' );
864 864
 
@@ -866,28 +866,28 @@  discard block
 block discarded – undo
866 866
 	}
867 867
 
868 868
 	/**
869
-	* Update entry from an XML import
870
-	* Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
871
-	*
872
-	* @since 2.0.16
873
-	* @param int $id
874
-	* @param array $values
875
-	* @return int | boolean $updated
876
-	*/
869
+	 * Update entry from an XML import
870
+	 * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
871
+	 *
872
+	 * @since 2.0.16
873
+	 * @param int $id
874
+	 * @param array $values
875
+	 * @return int | boolean $updated
876
+	 */
877 877
 	public static function update_entry_from_xml( $id, $values ) {
878 878
 		$updated = self::update_entry( $id, $values, 'xml' );
879 879
 
880 880
 		return $updated;
881 881
 	}
882 882
 
883
-    /**
884
-     * @param string $key
885
-     * @return int entry_id
886
-     */
883
+	/**
884
+	 * @param string $key
885
+	 * @return int entry_id
886
+	 */
887 887
 	public static function get_id_by_key( $key ) {
888
-        $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
889
-        return $entry_id;
890
-    }
888
+		$entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
889
+		return $entry_id;
890
+	}
891 891
 
892 892
 	public static function validate( $values, $exclude = false ) {
893 893
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryValidate::validate' );
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
 		unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
56 56
 
57 57
         if ( $new_values['item_key'] == $new_values['name'] ) {
58
-            unset($check_val['name']);
58
+            unset( $check_val['name'] );
59 59
         }
60 60
 
61 61
         global $wpdb;
62 62
 		$entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
63 63
 
64
-        if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
64
+        if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) {
65 65
             return false;
66 66
         }
67 67
 
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
             $is_duplicate = true;
71 71
 
72 72
             //add more checks here to make sure it's a duplicate
73
-            $metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
73
+            $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist );
74 74
             $field_metas = array();
75 75
             foreach ( $metas as $meta ) {
76
-				$field_metas[ $meta->field_id ] = $meta->meta_value;
76
+				$field_metas[$meta->field_id] = $meta->meta_value;
77 77
             }
78 78
 
79 79
             // If prev entry is empty and current entry is not, they are not duplicates
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
                 return false;
83 83
             }
84 84
 
85
-            $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
85
+            $diff = array_diff_assoc( $field_metas, array_map( 'maybe_serialize', $values['item_meta'] ) );
86 86
             foreach ( $diff as $field_id => $meta_value ) {
87
-                if ( ! empty($meta_value) ) {
87
+                if ( ! empty( $meta_value ) ) {
88 88
                     $is_duplicate = false;
89 89
                     continue;
90 90
                 }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		}
114 114
 
115 115
 		// If CSV is importing, don't check for duplicates
116
-		if ( defined('WP_IMPORTING') && WP_IMPORTING ) {
116
+		if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
117 117
 			return false;
118 118
 		}
119 119
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         $new_values['is_draft'] = $values->is_draft;
137 137
 		$new_values['user_id'] = (int) $values->user_id;
138 138
 		$new_values['updated_by'] = (int) $values->user_id;
139
-        $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
139
+        $new_values['form_id'] = $values->form_id ? (int) $values->form_id : null;
140 140
 		$new_values['created_at'] = current_time( 'mysql', 1 );
141 141
 		$new_values['updated_at'] = $new_values['created_at'];
142 142
 
@@ -148,12 +148,12 @@  discard block
 block discarded – undo
148 148
         $entry_id = $wpdb->insert_id;
149 149
 
150 150
         global $frm_vars;
151
-        if ( ! isset($frm_vars['saved_entries']) ) {
151
+        if ( ! isset( $frm_vars['saved_entries'] ) ) {
152 152
             $frm_vars['saved_entries'] = array();
153 153
         }
154 154
         $frm_vars['saved_entries'][] = (int) $entry_id;
155 155
 
156
-        FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
156
+        FrmEntryMeta::duplicate_entry_metas( $id, $entry_id );
157 157
 		self::clear_cache();
158 158
 
159 159
 		do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
 		$new_values = self::package_entry_to_update( $id, $values );
194 194
 
195
-		$query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact('id') );
195
+		$query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact( 'id' ) );
196 196
 
197 197
 		self::after_update_entry( $query_results, $id, $values, $new_values );
198 198
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
             return $result;
210 210
         }
211 211
 
212
-        do_action('frm_before_destroy_entry', $id, $entry);
212
+        do_action( 'frm_before_destroy_entry', $id, $entry );
213 213
 
214 214
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
215 215
 		$result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 
222 222
 	public static function update_form( $id, $value, $form_id ) {
223 223
         global $wpdb;
224
-        $form_id = isset($value) ? $form_id : null;
224
+        $form_id = isset( $value ) ? $form_id : null;
225 225
 		$result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
226 226
 		if ( $result ) {
227 227
 			self::clear_cache();
@@ -268,24 +268,24 @@  discard block
 block discarded – undo
268 268
         $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
269 269
                   LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
270 270
 
271
-        $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
271
+        $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
272 272
         $query_args = array( $id );
273 273
         $query = $wpdb->prepare( $query, $query_args );
274 274
 
275 275
         if ( ! $meta ) {
276 276
 			$entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
277
-            return stripslashes_deep($entry);
277
+            return stripslashes_deep( $entry );
278 278
         }
279 279
 
280 280
         $entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
281 281
         if ( $entry !== false ) {
282
-            return stripslashes_deep($entry);
282
+            return stripslashes_deep( $entry );
283 283
         }
284 284
 
285 285
         $entry = $wpdb->get_row( $query );
286
-        $entry = self::get_meta($entry);
286
+        $entry = self::get_meta( $entry );
287 287
 
288
-        return stripslashes_deep($entry);
288
+        return stripslashes_deep( $entry );
289 289
     }
290 290
 
291 291
 	public static function get_meta( $entry ) {
@@ -301,23 +301,23 @@  discard block
 block discarded – undo
301 301
 		$include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
302 302
         foreach ( $metas as $meta_val ) {
303 303
             if ( $meta_val->item_id == $entry->id ) {
304
-				$entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
304
+				$entry->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value );
305 305
 				if ( $include_key ) {
306
-					$entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
306
+					$entry->metas[$meta_val->field_key] = $entry->metas[$meta_val->field_id];
307 307
 				}
308 308
                  continue;
309 309
             }
310 310
 
311 311
             // include sub entries in an array
312
-			if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
313
-				$entry->metas[ $meta_val->field_id ] = array();
312
+			if ( ! isset( $entry_metas[$meta_val->field_id] ) ) {
313
+				$entry->metas[$meta_val->field_id] = array();
314 314
             }
315 315
 
316
-			$entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
316
+			$entry->metas[$meta_val->field_id][] = maybe_unserialize( $meta_val->meta_value );
317 317
 
318
-            unset($meta_val);
318
+            unset( $meta_val );
319 319
         }
320
-        unset($metas);
320
+        unset( $metas );
321 321
 
322 322
 		FrmAppHelper::set_cache( $entry->id, $entry, 'frm_entry' );
323 323
 
@@ -335,24 +335,24 @@  discard block
 block discarded – undo
335 335
             return $exists;
336 336
         }
337 337
 
338
-        if ( is_numeric($id) ) {
338
+        if ( is_numeric( $id ) ) {
339 339
             $where = array( 'id' => $id );
340 340
         } else {
341 341
             $where = array( 'item_key' => $id );
342 342
         }
343 343
 		$id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
344 344
 
345
-        $exists = ($id && $id > 0) ? true : false;
345
+        $exists = ( $id && $id > 0 ) ? true : false;
346 346
         return $exists;
347 347
     }
348 348
 
349 349
     public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
350 350
 		global $wpdb;
351 351
 
352
-        $limit = FrmAppHelper::esc_limit($limit);
352
+        $limit = FrmAppHelper::esc_limit( $limit );
353 353
 
354
-        $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
355
-        $entries = wp_cache_get($cache_key, 'frm_entry');
354
+        $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form;
355
+        $entries = wp_cache_get( $cache_key, 'frm_entry' );
356 356
 
357 357
         if ( false === $entries ) {
358 358
             $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
@@ -371,25 +371,25 @@  discard block
 block discarded – undo
371 371
 		    }
372 372
 
373 373
 			// prepare the query
374
-			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
374
+			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
375 375
 
376
-            $entries = $wpdb->get_results($query, OBJECT_K);
377
-            unset($query);
376
+            $entries = $wpdb->get_results( $query, OBJECT_K );
377
+            unset( $query );
378 378
 
379 379
 			FrmAppHelper::set_cache( $cache_key, $entries, 'frm_entry' );
380 380
         }
381 381
 
382 382
         if ( ! $meta || ! $entries ) {
383
-            return stripslashes_deep($entries);
383
+            return stripslashes_deep( $entries );
384 384
         }
385
-        unset($meta);
385
+        unset( $meta );
386 386
 
387
-        if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
387
+        if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) {
388 388
 			$where = array( 'it.form_id' => substr( $where, 11 ) );
389 389
         }
390 390
 
391 391
         $meta_where = array( 'field_id !' => 0 );
392
-        if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
392
+        if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) {
393 393
             $meta_where['fi.form_id'] = $where['it.form_id'];
394 394
         } else {
395 395
             $meta_where['item_id'] = array_keys( $entries );
@@ -400,21 +400,21 @@  discard block
 block discarded – undo
400 400
         unset( $meta_where );
401 401
 
402 402
         if ( ! $metas ) {
403
-            return stripslashes_deep($entries);
403
+            return stripslashes_deep( $entries );
404 404
         }
405 405
 
406 406
         foreach ( $metas as $m_key => $meta_val ) {
407
-            if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
407
+            if ( ! isset( $entries[$meta_val->item_id] ) ) {
408 408
                 continue;
409 409
             }
410 410
 
411
-            if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
412
-				$entries[ $meta_val->item_id ]->metas = array();
411
+            if ( ! isset( $entries[$meta_val->item_id]->metas ) ) {
412
+				$entries[$meta_val->item_id]->metas = array();
413 413
             }
414 414
 
415
-			$entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
415
+			$entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value );
416 416
 
417
-            unset($m_key, $meta_val);
417
+            unset( $m_key, $meta_val );
418 418
         }
419 419
 
420 420
 		if ( ! FrmAppHelper::prevent_caching() ) {
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 			}
425 425
 		}
426 426
 
427
-        return stripslashes_deep($entries);
427
+        return stripslashes_deep( $entries );
428 428
     }
429 429
 
430 430
     // Pagination Methods
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
         global $wpdb;
433 433
 		$table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
434 434
 
435
-        if ( is_numeric($where) ) {
435
+        if ( is_numeric( $where ) ) {
436 436
             $table_join = 'frm_items';
437 437
             $where = array( 'form_id' => $where );
438 438
         }
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 		self::sanitize_entry_post( $values );
475 475
 
476 476
 		if ( $type != 'xml' ) {
477
-			$values = apply_filters('frm_pre_create_entry', $values);
477
+			$values = apply_filters( 'frm_pre_create_entry', $values );
478 478
 		}
479 479
 
480 480
 		$new_values = self::package_entry_data( $values );
@@ -554,11 +554,11 @@  discard block
 block discarded – undo
554 554
 			'user_id' => self::get_entry_user_id( $values ),
555 555
 		);
556 556
 
557
-		if ( is_array($new_values['name']) ) {
558
-			$new_values['name'] = reset($new_values['name']);
557
+		if ( is_array( $new_values['name'] ) ) {
558
+			$new_values['name'] = reset( $new_values['name'] );
559 559
 		}
560 560
 
561
-		$new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id'];
561
+		$new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id'];
562 562
 
563 563
 		return $new_values;
564 564
 	}
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
 	* @return int
594 594
 	*/
595 595
 	private static function get_post_id( $values ) {
596
-		return isset( $values['post_id'] ) ? (int) $values['post_id']: 0;
596
+		return isset( $values['post_id'] ) ? (int) $values['post_id'] : 0;
597 597
 	}
598 598
 
599 599
 	/**
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
 	* @return int
605 605
 	*/
606 606
 	private static function get_parent_item_id( $values ) {
607
-		return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id']: 0;
607
+		return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id'] : 0;
608 608
 	}
609 609
 
610 610
 	/**
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
 	* @return string
616 616
 	*/
617 617
 	private static function get_created_at( $values ) {
618
-		return isset( $values['created_at'] ) ? $values['created_at']: current_time('mysql', 1);
618
+		return isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 );
619 619
 	}
620 620
 
621 621
 	/**
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 	private static function add_new_entry_to_frm_vars( $entry_id ) {
704 704
 		global $frm_vars;
705 705
 
706
-		if ( ! isset($frm_vars['saved_entries']) ) {
706
+		if ( ! isset( $frm_vars['saved_entries'] ) ) {
707 707
 			$frm_vars['saved_entries'] = array();
708 708
 		}
709 709
 
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
 	* @param int $entry_id
719 719
 	*/
720 720
 	private static function maybe_add_entry_metas( $values, $entry_id ) {
721
-		if ( isset($values['item_meta']) ) {
721
+		if ( isset( $values['item_meta'] ) ) {
722 722
 			FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
723 723
 		}
724 724
 	}
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
 		$is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
736 736
 
737 737
 		do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) );
738
-		do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id , compact( 'is_child' ) );
738
+		do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) );
739 739
 	}
740 740
 
741 741
 	/**
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
 		}
777 777
 
778 778
 		if ( $update && $update_type != 'xml' ) {
779
-			$values = apply_filters('frm_pre_update_entry', $values, $id);
779
+			$values = apply_filters( 'frm_pre_update_entry', $values, $id );
780 780
 		}
781 781
 
782 782
 		return $update;
@@ -797,27 +797,27 @@  discard block
 block discarded – undo
797 797
 			'name'      => self::get_new_entry_name( $values ),
798 798
 			'form_id'   => self::get_form_id( $values ),
799 799
 			'is_draft'  => self::get_is_draft_value( $values ),
800
-			'updated_at' => current_time('mysql', 1),
801
-			'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : get_current_user_id(),
800
+			'updated_at' => current_time( 'mysql', 1 ),
801
+			'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(),
802 802
 		);
803 803
 
804
-		if ( isset($values['post_id']) ) {
804
+		if ( isset( $values['post_id'] ) ) {
805 805
 			$new_values['post_id'] = (int) $values['post_id'];
806 806
 		}
807 807
 
808
-		if ( isset($values['item_key']) ) {
808
+		if ( isset( $values['item_key'] ) ) {
809 809
 			$new_values['item_key'] = FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key', $id );
810 810
 		}
811 811
 
812
-		if ( isset($values['parent_item_id']) ) {
812
+		if ( isset( $values['parent_item_id'] ) ) {
813 813
 			$new_values['parent_item_id'] = (int) $values['parent_item_id'];
814 814
 		}
815 815
 
816
-		if ( isset($values['frm_user_id']) && is_numeric($values['frm_user_id']) ) {
816
+		if ( isset( $values['frm_user_id'] ) && is_numeric( $values['frm_user_id'] ) ) {
817 817
 			$new_values['user_id'] = $values['frm_user_id'];
818 818
 		}
819 819
 
820
-		$new_values = apply_filters('frm_update_entry', $new_values, $id);
820
+		$new_values = apply_filters( 'frm_update_entry', $new_values, $id );
821 821
 
822 822
 		return $new_values;
823 823
 	}
Please login to merge, or discard this patch.
classes/models/FrmDb.php 2 patches
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -1,66 +1,66 @@  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
-	    do_action( 'frm_before_install' );
23
-
24
-        global $wpdb;
25
-        //$frm_db_version is the version of the database we're moving to
26
-        $frm_db_version = FrmAppHelper::$db_version;
27
-        $old_db_version = (float) $old_db_version;
28
-        if ( ! $old_db_version ) {
29
-            $old_db_version = get_option('frm_db_version');
30
-        }
31
-
32
-        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
+		do_action( 'frm_before_install' );
23
+
24
+		global $wpdb;
25
+		//$frm_db_version is the version of the database we're moving to
26
+		$frm_db_version = FrmAppHelper::$db_version;
27
+		$old_db_version = (float) $old_db_version;
28
+		if ( ! $old_db_version ) {
29
+			$old_db_version = get_option('frm_db_version');
30
+		}
31
+
32
+		if ( $frm_db_version != $old_db_version ) {
33 33
 			// update rewrite rules for views and other custom post types
34 34
 			flush_rewrite_rules();
35 35
 
36 36
 			require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
37 37
 
38
-            $this->create_tables();
39
-            $this->migrate_data($frm_db_version, $old_db_version);
38
+			$this->create_tables();
39
+			$this->migrate_data($frm_db_version, $old_db_version);
40 40
 
41
-            /***** SAVE DB VERSION *****/
42
-            update_option('frm_db_version', $frm_db_version);
41
+			/***** SAVE DB VERSION *****/
42
+			update_option('frm_db_version', $frm_db_version);
43 43
 
44
-            /**** ADD/UPDATE DEFAULT TEMPLATES ****/
45
-            FrmXMLController::add_default_templates();
46
-        }
44
+			/**** ADD/UPDATE DEFAULT TEMPLATES ****/
45
+			FrmXMLController::add_default_templates();
46
+		}
47 47
 
48
-        do_action('frm_after_install');
48
+		do_action('frm_after_install');
49 49
 
50
-        /**** update the styling settings ****/
50
+		/**** update the styling settings ****/
51 51
 		if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
52 52
 			$frm_style = new FrmStyle();
53 53
 			$frm_style->update( 'default' );
54 54
 		}
55
-    }
55
+	}
56 56
 
57
-    public function collation() {
58
-        global $wpdb;
59
-        if ( ! $wpdb->has_cap( 'collation' ) ) {
60
-            return '';
61
-        }
57
+	public function collation() {
58
+		global $wpdb;
59
+		if ( ! $wpdb->has_cap( 'collation' ) ) {
60
+			return '';
61
+		}
62 62
 
63
-        $charset_collate = '';
63
+		$charset_collate = '';
64 64
 		if ( ! empty( $wpdb->charset ) ) {
65 65
 			$charset_collate .= ' DEFAULT CHARACTER SET ' . $wpdb->charset;
66 66
 		}
@@ -69,14 +69,14 @@  discard block
 block discarded – undo
69 69
 			$charset_collate .= ' COLLATE ' . $wpdb->collate;
70 70
 		}
71 71
 
72
-        return $charset_collate;
73
-    }
72
+		return $charset_collate;
73
+	}
74 74
 
75
-    private function create_tables() {
76
-        $charset_collate = $this->collation();
77
-        $sql = array();
75
+	private function create_tables() {
76
+		$charset_collate = $this->collation();
77
+		$sql = array();
78 78
 
79
-        /* Create/Upgrade Fields Table */
79
+		/* Create/Upgrade Fields Table */
80 80
 		$sql[] = 'CREATE TABLE ' . $this->fields . ' (
81 81
 				id BIGINT(20) NOT NULL auto_increment,
82 82
 				field_key varchar(100) default NULL,
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
                 UNIQUE KEY field_key (field_key)
96 96
         )';
97 97
 
98
-        /* Create/Upgrade Forms Table */
98
+		/* Create/Upgrade Forms Table */
99 99
 		$sql[] = 'CREATE TABLE ' . $this->forms . ' (
100 100
                 id int(11) NOT NULL auto_increment,
101 101
 				form_key varchar(100) default NULL,
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
                 UNIQUE KEY form_key (form_key)
114 114
         )';
115 115
 
116
-        /* Create/Upgrade Items Table */
116
+		/* Create/Upgrade Items Table */
117 117
 		$sql[] = 'CREATE TABLE ' . $this->entries . ' (
118 118
 				id BIGINT(20) NOT NULL auto_increment,
119 119
 				item_key varchar(100) default NULL,
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
                 UNIQUE KEY item_key (item_key)
137 137
         )';
138 138
 
139
-        /* Create/Upgrade Meta Table */
139
+		/* Create/Upgrade Meta Table */
140 140
 		$sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
141 141
 				id BIGINT(20) NOT NULL auto_increment,
142 142
 				meta_value longtext default NULL,
@@ -148,43 +148,43 @@  discard block
 block discarded – undo
148 148
                 KEY item_id (item_id)
149 149
         )';
150 150
 
151
-        foreach ( $sql as $q ) {
151
+		foreach ( $sql as $q ) {
152 152
 			if ( function_exists( 'dbDelta' ) ) {
153 153
 				dbDelta( $q . $charset_collate . ';' );
154 154
 			} else {
155 155
 				global $wpdb;
156 156
 				$wpdb->query( $q . $charset_collate );
157 157
 			}
158
-            unset($q);
159
-        }
160
-    }
158
+			unset($q);
159
+		}
160
+	}
161 161
 
162
-    /**
163
-     * @param integer $frm_db_version
162
+	/**
163
+	 * @param integer $frm_db_version
164 164
 	 * @param int $old_db_version
165
-     */
165
+	 */
166 166
 	private function migrate_data( $frm_db_version, $old_db_version ) {
167 167
 		$migrations = array( 4, 6, 11, 16, 17, 23, 25 );
168
-        foreach ( $migrations as $migration ) {
169
-            if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
168
+		foreach ( $migrations as $migration ) {
169
+			if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
170 170
 				$function_name = 'migrate_to_' . $migration;
171
-                $this->$function_name();
172
-            }
173
-        }
174
-    }
171
+				$this->$function_name();
172
+			}
173
+		}
174
+	}
175 175
 
176
-    /**
177
-     * Change array into format $wpdb->prepare can use
176
+	/**
177
+	 * Change array into format $wpdb->prepare can use
178 178
 	 *
179 179
 	 * @param array $args
180 180
 	 * @param string $starts_with
181
-     */
182
-    public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
183
-        if ( empty($args) ) {
181
+	 */
182
+	public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
183
+		if ( empty($args) ) {
184 184
 			// add an arg to prevent prepare from failing
185 185
 			$args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
186 186
 			return;
187
-        }
187
+		}
188 188
 
189 189
 		$where = '';
190 190
 		$values = array();
@@ -195,64 +195,64 @@  discard block
 block discarded – undo
195 195
 		}
196 196
 
197 197
 		$args = compact( 'where', 'values' );
198
-    }
198
+	}
199 199
 
200
-    /**
200
+	/**
201 201
 	 * @param array $args
202
-     * @param string $base_where
203
-     * @param string $where
202
+	 * @param string $base_where
203
+	 * @param string $where
204 204
 	 * @param array $values
205
-     */
206
-    public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
207
-        $condition = ' AND';
208
-        if ( isset( $args['or'] ) ) {
209
-            $condition = ' OR';
210
-            unset( $args['or'] );
211
-        }
212
-
213
-        foreach ( $args as $key => $value ) {
214
-            $where .= empty( $where ) ? $base_where : $condition;
215
-            $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
216
-            if ( is_numeric( $key ) || $array_inc_null ) {
217
-                $where .= ' ( ';
218
-                $nested_where = '';
219
-                if ( $array_inc_null ) {
220
-                    foreach ( $value as $val ) {
221
-                        self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
222
-                    }
223
-                } else {
224
-                    self::parse_where_from_array( $value, '', $nested_where, $values );
225
-                }
226
-                $where .= $nested_where;
227
-                $where .= ' ) ';
228
-            } else {
229
-                self::interpret_array_to_sql( $key, $value, $where, $values );
230
-            }
231
-        }
232
-    }
233
-
234
-    /**
235
-     * @param string $key
205
+	 */
206
+	public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
207
+		$condition = ' AND';
208
+		if ( isset( $args['or'] ) ) {
209
+			$condition = ' OR';
210
+			unset( $args['or'] );
211
+		}
212
+
213
+		foreach ( $args as $key => $value ) {
214
+			$where .= empty( $where ) ? $base_where : $condition;
215
+			$array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
216
+			if ( is_numeric( $key ) || $array_inc_null ) {
217
+				$where .= ' ( ';
218
+				$nested_where = '';
219
+				if ( $array_inc_null ) {
220
+					foreach ( $value as $val ) {
221
+						self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
222
+					}
223
+				} else {
224
+					self::parse_where_from_array( $value, '', $nested_where, $values );
225
+				}
226
+				$where .= $nested_where;
227
+				$where .= ' ) ';
228
+			} else {
229
+				self::interpret_array_to_sql( $key, $value, $where, $values );
230
+			}
231
+		}
232
+	}
233
+
234
+	/**
235
+	 * @param string $key
236 236
 	 * @param string|array $value
237
-     * @param string $where
237
+	 * @param string $where
238 238
 	 * @param array $values
239
-     */
240
-    private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
239
+	 */
240
+	private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
241 241
 		$key = trim( $key );
242 242
 
243 243
 		if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
244
-            $k = explode(' ', $key);
245
-            $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
246
-            $values[] = '%Y-%m-%d %H:%i:%s';
247
-        } else {
244
+			$k = explode(' ', $key);
245
+			$where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
246
+			$values[] = '%Y-%m-%d %H:%i:%s';
247
+		} else {
248 248
 			$where .= ' ' . $key;
249
-        }
249
+		}
250 250
 
251 251
 		$lowercase_key = explode( ' ', strtolower( $key ) );
252 252
 		$lowercase_key = end( $lowercase_key );
253 253
 
254
-        if ( is_array( $value ) ) {
255
-            // translate array of values to "in"
254
+		if ( is_array( $value ) ) {
255
+			// translate array of values to "in"
256 256
 			if ( strpos( $lowercase_key, 'like' ) !== false ) {
257 257
 				$where = preg_replace('/' . $key . '$/', '', $where);
258 258
 				$where .= '(';
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 				$where .= ' in (' . FrmAppHelper::prepare_array_values( $value, '%s' ) . ')';
271 271
 				$values = array_merge( $values, $value );
272 272
 			}
273
-        } else if ( strpos( $lowercase_key, 'like' ) !== false ) {
273
+		} else if ( strpos( $lowercase_key, 'like' ) !== false ) {
274 274
 			/**
275 275
 			 * Allow string to start or end with the value
276 276
 			 * If the key is like% then skip the first % for starts with
@@ -290,9 +290,9 @@  discard block
 block discarded – undo
290 290
 			$where .= ' %s';
291 291
 			$values[] = $start . FrmAppHelper::esc_like( $value ) . $end;
292 292
 
293
-        } else if ( $value === null ) {
294
-            $where .= ' IS NULL';
295
-        } else {
293
+		} else if ( $value === null ) {
294
+			$where .= ' IS NULL';
295
+		} else {
296 296
 			// allow a - to prevent = from being added
297 297
 			if ( substr( $key, -1 ) == '-' ) {
298 298
 				$where = rtrim( $where, '-' );
@@ -302,9 +302,9 @@  discard block
 block discarded – undo
302 302
 
303 303
 			self::add_query_placeholder( $key, $value, $where );
304 304
 
305
-            $values[] = $value;
306
-        }
307
-    }
305
+			$values[] = $value;
306
+		}
307
+	}
308 308
 
309 309
 	/**
310 310
 	 * Add %d, or %s to query
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 * @param int|string $value
315 315
 	 * @param string $where
316 316
 	 */
317
-    private static function add_query_placeholder( $key, $value, &$where ) {
317
+	private static function add_query_placeholder( $key, $value, &$where ) {
318 318
 		if ( is_numeric( $value ) && strpos( $key, 'meta_value' ) === false ) {
319 319
 			$where .= '%d';
320 320
 		} else {
@@ -322,16 +322,16 @@  discard block
 block discarded – undo
322 322
 		}
323 323
 	}
324 324
 
325
-    /**
326
-     * @param string $table
325
+	/**
326
+	 * @param string $table
327 327
 	 * @param array $where
328 328
 	 * @param array $args
329 329
 	 * @return int
330
-     */
331
-    public static function get_count( $table, $where = array(), $args = array() ) {
332
-        $count = self::get_var( $table, $where, 'COUNT(*)', $args );
333
-        return $count;
334
-    }
330
+	 */
331
+	public static function get_count( $table, $where = array(), $args = array() ) {
332
+		$count = self::get_var( $table, $where, 'COUNT(*)', $args );
333
+		return $count;
334
+	}
335 335
 
336 336
 	/**
337 337
 	 * @param string $table
@@ -342,56 +342,56 @@  discard block
 block discarded – undo
342 342
 	 * @param string $type
343 343
 	 * @return array|null|string|object
344 344
 	 */
345
-    public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
346
-        $group = '';
347
-        self::get_group_and_table_name( $table, $group );
345
+	public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
346
+		$group = '';
347
+		self::get_group_and_table_name( $table, $group );
348 348
 		self::convert_options_to_array( $args, '', $limit );
349 349
 
350 350
 		$query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
351 351
 
352 352
 		$cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field . '_' . $type, ' WHERE' ) );
353 353
 		$results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_' . $type );
354
-        return $results;
355
-    }
354
+		return $results;
355
+	}
356 356
 
357
-    /**
358
-     * @param string $table
359
-     * @param array $where
357
+	/**
358
+	 * @param string $table
359
+	 * @param array $where
360 360
 	 * @param string $field
361 361
 	 * @param array $args
362 362
 	 * @param string $limit
363 363
 	 * @return mixed
364
-     */
365
-    public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
366
-        return self::get_var( $table, $where, $field, $args, $limit, 'col' );
367
-    }
368
-
369
-    /**
370
-     * @since 2.0
371
-     * @param string $table
364
+	 */
365
+	public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
366
+		return self::get_var( $table, $where, $field, $args, $limit, 'col' );
367
+	}
368
+
369
+	/**
370
+	 * @since 2.0
371
+	 * @param string $table
372 372
 	 * @param array $where
373 373
 	 * @param string $fields
374 374
 	 * @param array $args
375 375
 	 * @return mixed
376
-     */
377
-    public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
378
-        $args['limit'] = 1;
379
-        return self::get_var( $table, $where, $fields, $args, '', 'row' );
380
-    }
381
-
382
-    /**
383
-     * Prepare a key/value array before DB call
376
+	 */
377
+	public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
378
+		$args['limit'] = 1;
379
+		return self::get_var( $table, $where, $fields, $args, '', 'row' );
380
+	}
381
+
382
+	/**
383
+	 * Prepare a key/value array before DB call
384 384
 	 *
385
-     * @since 2.0
386
-     * @param string $table
385
+	 * @since 2.0
386
+	 * @param string $table
387 387
 	 * @param array $where
388 388
 	 * @param string $fields
389 389
 	 * @param array $args
390 390
 	 * @return mixed
391
-     */
392
-    public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
393
-        return self::get_var( $table, $where, $fields, $args, '', 'results' );
394
-    }
391
+	 */
392
+	public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
393
+		return self::get_var( $table, $where, $fields, $args, '', 'results' );
394
+	}
395 395
 
396 396
 	/**
397 397
 	 * Check for like, not like, in, not in, =, !=, >, <, <=, >=
@@ -428,59 +428,59 @@  discard block
 block discarded – undo
428 428
 		return '';
429 429
 	}
430 430
 
431
-    /**
432
-     * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
433
-     * Also add the wpdb->prefix to the table if it's missing
434
-     *
435
-     * @param string $table
436
-     * @param string $group
437
-     */
438
-    private static function get_group_and_table_name( &$table, &$group ) {
431
+	/**
432
+	 * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
433
+	 * Also add the wpdb->prefix to the table if it's missing
434
+	 *
435
+	 * @param string $table
436
+	 * @param string $group
437
+	 */
438
+	private static function get_group_and_table_name( &$table, &$group ) {
439 439
 		global $wpdb, $wpmuBaseTablePrefix;
440 440
 
441
-        $table_parts = explode(' ', $table);
442
-        $group = reset($table_parts);
443
-        $group = str_replace( $wpdb->prefix, '', $group );
441
+		$table_parts = explode(' ', $table);
442
+		$group = reset($table_parts);
443
+		$group = str_replace( $wpdb->prefix, '', $group );
444 444
 
445 445
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
446 446
 		$group = str_replace( $prefix, '', $group );
447 447
 
448
-        if ( $group == $table ) {
449
-            $table = $wpdb->prefix . $table;
450
-        }
448
+		if ( $group == $table ) {
449
+			$table = $wpdb->prefix . $table;
450
+		}
451 451
 
452 452
 		// switch to singular group name
453 453
 		$group = rtrim( $group, 's' );
454
-    }
454
+	}
455 455
 
456
-    private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
457
-        if ( ! is_array($args) ) {
456
+	private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
457
+		if ( ! is_array($args) ) {
458 458
 			$args = array( 'order_by' => $args );
459
-        }
459
+		}
460 460
 
461
-        if ( ! empty( $order_by ) ) {
462
-            $args['order_by'] = $order_by;
463
-        }
461
+		if ( ! empty( $order_by ) ) {
462
+			$args['order_by'] = $order_by;
463
+		}
464 464
 
465
-        if ( ! empty( $limit ) ) {
466
-            $args['limit'] = $limit;
467
-        }
465
+		if ( ! empty( $limit ) ) {
466
+			$args['limit'] = $limit;
467
+		}
468 468
 
469
-        $temp_args = $args;
470
-        foreach ( $temp_args as $k => $v ) {
471
-            if ( $v == '' ) {
469
+		$temp_args = $args;
470
+		foreach ( $temp_args as $k => $v ) {
471
+			if ( $v == '' ) {
472 472
 				unset( $args[ $k ] );
473
-                continue;
474
-            }
473
+				continue;
474
+			}
475 475
 
476
-            if ( $k == 'limit' ) {
476
+			if ( $k == 'limit' ) {
477 477
 				$args[ $k ] = FrmAppHelper::esc_limit( $v );
478
-            }
479
-            $db_name = strtoupper( str_replace( '_', ' ', $k ) );
480
-            if ( strpos( $v, $db_name ) === false ) {
478
+			}
479
+			$db_name = strtoupper( str_replace( '_', ' ', $k ) );
480
+			if ( strpos( $v, $db_name ) === false ) {
481 481
 				$args[ $k ] = $db_name . ' ' . $v;
482
-            }
483
-        }
482
+			}
483
+		}
484 484
 
485 485
 		// Make sure LIMIT is the last argument
486 486
 		if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 			unset( $args['limit'] );
489 489
 			$args['limit'] = $temp_limit;
490 490
 		}
491
-    }
491
+	}
492 492
 
493 493
 	/**
494 494
 	 * Get the associative array results for the given columns, table, and where query
@@ -541,31 +541,31 @@  discard block
 block discarded – undo
541 541
 		return $query;
542 542
 	}
543 543
 
544
-    public function uninstall() {
544
+	public function uninstall() {
545 545
 		if ( ! current_user_can( 'administrator' ) ) {
546
-            $frm_settings = FrmAppHelper::get_settings();
547
-            wp_die($frm_settings->admin_permission);
548
-        }
546
+			$frm_settings = FrmAppHelper::get_settings();
547
+			wp_die($frm_settings->admin_permission);
548
+		}
549 549
 
550
-        global $wpdb, $wp_roles;
550
+		global $wpdb, $wp_roles;
551 551
 
552 552
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields );
553 553
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms );
554 554
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries );
555 555
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas );
556 556
 
557
-        delete_option('frm_options');
558
-        delete_option('frm_db_version');
557
+		delete_option('frm_options');
558
+		delete_option('frm_db_version');
559 559
 
560
-        //delete roles
561
-        $frm_roles = FrmAppHelper::frm_capabilities();
562
-        $roles = get_editable_roles();
563
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
564
-            foreach ( $roles as $role => $details ) {
565
-                $wp_roles->remove_cap( $role, $frm_role );
566
-                unset($role, $details);
567
-    		}
568
-    		unset($frm_role, $frm_role_description);
560
+		//delete roles
561
+		$frm_roles = FrmAppHelper::frm_capabilities();
562
+		$roles = get_editable_roles();
563
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
564
+			foreach ( $roles as $role => $details ) {
565
+				$wp_roles->remove_cap( $role, $frm_role );
566
+				unset($role, $details);
567
+			}
568
+			unset($frm_role, $frm_role_description);
569 569
 		}
570 570
 		unset($roles, $frm_roles);
571 571
 
@@ -589,9 +589,9 @@  discard block
 block discarded – undo
589 589
 
590 590
 		$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_%' ) );
591 591
 
592
-        do_action('frm_after_uninstall');
593
-        return true;
594
-    }
592
+		do_action('frm_after_uninstall');
593
+		return true;
594
+	}
595 595
 
596 596
 	/**
597 597
 	 * Migrate old styling settings. If sites are using the old
@@ -630,150 +630,150 @@  discard block
 block discarded – undo
630 630
 		}
631 631
 	}
632 632
 
633
-    /**
634
-     * Change field size from character to pixel -- Multiply by 9
635
-     */
636
-    private function migrate_to_17() {
637
-        global $wpdb;
633
+	/**
634
+	 * Change field size from character to pixel -- Multiply by 9
635
+	 */
636
+	private function migrate_to_17() {
637
+		global $wpdb;
638 638
 		$pixel_conversion = 9;
639 639
 
640
-        // Get query arguments
640
+		// Get query arguments
641 641
 		$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
642 642
 		$query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' );
643 643
 
644
-        // Get results
644
+		// Get results
645 645
 		$fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
646 646
 
647
-        $updated = 0;
648
-        foreach ( $fields as $f ) {
649
-            $f->field_options = maybe_unserialize($f->field_options);
650
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
651
-                continue;
652
-            }
647
+		$updated = 0;
648
+		foreach ( $fields as $f ) {
649
+			$f->field_options = maybe_unserialize($f->field_options);
650
+			if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
651
+				continue;
652
+			}
653 653
 
654 654
 			$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] );
655
-            $f->field_options['size'] .= 'px';
656
-            $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
657
-            if ( $u ) {
658
-                $updated++;
659
-            }
660
-            unset($f);
661
-        }
662
-
663
-        // Change the characters in widgets to pixels
664
-        $widgets = get_option('widget_frm_show_form');
665
-        if ( empty($widgets) ) {
666
-            return;
667
-        }
668
-
669
-        $widgets = maybe_unserialize($widgets);
670
-        foreach ( $widgets as $k => $widget ) {
671
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
672
-                continue;
673
-            }
655
+			$f->field_options['size'] .= 'px';
656
+			$u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
657
+			if ( $u ) {
658
+				$updated++;
659
+			}
660
+			unset($f);
661
+		}
662
+
663
+		// Change the characters in widgets to pixels
664
+		$widgets = get_option('widget_frm_show_form');
665
+		if ( empty($widgets) ) {
666
+			return;
667
+		}
668
+
669
+		$widgets = maybe_unserialize($widgets);
670
+		foreach ( $widgets as $k => $widget ) {
671
+			if ( ! is_array($widget) || ! isset($widget['size']) ) {
672
+				continue;
673
+			}
674 674
 			$size = round( $pixel_conversion * (int) $widget['size'] );
675
-            $size .= 'px';
675
+			$size .= 'px';
676 676
 			$widgets[ $k ]['size'] = $size;
677
-        }
678
-        update_option('widget_frm_show_form', $widgets);
679
-    }
680
-
681
-    /**
682
-     * Migrate post and email notification settings into actions
683
-     */
684
-    private function migrate_to_16() {
685
-        global $wpdb;
686
-
687
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
688
-
689
-        /**
690
-        * Old email settings format:
691
-        * email_to: Email or field id
692
-        * also_email_to: array of fields ids
693
-        * reply_to: Email, field id, 'custom'
694
-        * cust_reply_to: string
695
-        * reply_to_name: field id, 'custom'
696
-        * cust_reply_to_name: string
697
-        * plain_text: 0|1
698
-        * email_message: string or ''
699
-        * email_subject: string or ''
700
-        * inc_user_info: 0|1
701
-        * update_email: 0, 1, 2
702
-        *
703
-        * Old autoresponder settings format:
704
-        * auto_responder: 0|1
705
-        * ar_email_message: string or ''
706
-        * ar_email_to: field id
707
-        * ar_plain_text: 0|1
708
-        * ar_reply_to_name: string
709
-        * ar_reply_to: string
710
-        * ar_email_subject: string
711
-        * ar_update_email: 0, 1, 2
712
-        *
713
-        * New email settings:
714
-        * post_content: json settings
715
-        * post_title: form id
716
-        * post_excerpt: message
717
-        *
718
-        */
719
-
720
-        foreach ( $forms as $form ) {
677
+		}
678
+		update_option('widget_frm_show_form', $widgets);
679
+	}
680
+
681
+	/**
682
+	 * Migrate post and email notification settings into actions
683
+	 */
684
+	private function migrate_to_16() {
685
+		global $wpdb;
686
+
687
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
688
+
689
+		/**
690
+		 * Old email settings format:
691
+		 * email_to: Email or field id
692
+		 * also_email_to: array of fields ids
693
+		 * reply_to: Email, field id, 'custom'
694
+		 * cust_reply_to: string
695
+		 * reply_to_name: field id, 'custom'
696
+		 * cust_reply_to_name: string
697
+		 * plain_text: 0|1
698
+		 * email_message: string or ''
699
+		 * email_subject: string or ''
700
+		 * inc_user_info: 0|1
701
+		 * update_email: 0, 1, 2
702
+		 *
703
+		 * Old autoresponder settings format:
704
+		 * auto_responder: 0|1
705
+		 * ar_email_message: string or ''
706
+		 * ar_email_to: field id
707
+		 * ar_plain_text: 0|1
708
+		 * ar_reply_to_name: string
709
+		 * ar_reply_to: string
710
+		 * ar_email_subject: string
711
+		 * ar_update_email: 0, 1, 2
712
+		 *
713
+		 * New email settings:
714
+		 * post_content: json settings
715
+		 * post_title: form id
716
+		 * post_excerpt: message
717
+		 *
718
+		 */
719
+
720
+		foreach ( $forms as $form ) {
721 721
 			if ( $form->is_template && $form->default_template ) {
722 722
 				// don't migrate the default templates since the email will be added anyway
723 723
 				continue;
724 724
 			}
725 725
 
726
-            // Format form options
727
-            $form_options = maybe_unserialize($form->options);
726
+			// Format form options
727
+			$form_options = maybe_unserialize($form->options);
728 728
 
729
-            // Migrate settings to actions
730
-            FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
731
-        }
732
-    }
729
+			// Migrate settings to actions
730
+			FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
731
+		}
732
+	}
733 733
 
734
-    private function migrate_to_11() {
735
-        global $wpdb;
734
+	private function migrate_to_11() {
735
+		global $wpdb;
736 736
 
737
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
737
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options');
738 738
 
739
-        $sending = __( 'Sending', 'formidable' );
739
+		$sending = __( 'Sending', 'formidable' );
740 740
 		$img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
741
-        $old_default_html = <<<DEFAULT_HTML
741
+		$old_default_html = <<<DEFAULT_HTML
742 742
 <div class="frm_submit">
743 743
 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
744 744
 <input type="submit" value="[button_label]" [button_action] />
745 745
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
746 746
 </div>
747 747
 DEFAULT_HTML;
748
-        unset($sending, $img);
748
+		unset($sending, $img);
749 749
 
750
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
751
-        $draft_link = FrmFormsHelper::get_draft_link();
750
+		$new_default_html = FrmFormsHelper::get_default_html('submit');
751
+		$draft_link = FrmFormsHelper::get_draft_link();
752 752
 		foreach ( $forms as $form ) {
753
-            $form->options = maybe_unserialize($form->options);
754
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
755
-                continue;
756
-            }
753
+			$form->options = maybe_unserialize($form->options);
754
+			if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
755
+				continue;
756
+			}
757 757
 
758
-            if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
759
-                $form->options['submit_html'] = $new_default_html;
758
+			if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
759
+				$form->options['submit_html'] = $new_default_html;
760 760
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
761 761
 			} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
762 762
 				$form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
763 763
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
764
-            }
765
-            unset($form);
766
-        }
767
-        unset($forms);
768
-    }
764
+			}
765
+			unset($form);
766
+		}
767
+		unset($forms);
768
+	}
769 769
 
770
-    private function migrate_to_6() {
771
-        global $wpdb;
770
+	private function migrate_to_6() {
771
+		global $wpdb;
772 772
 
773 773
 		$no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
774 774
 		$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' );
775 775
 
776
-        $default_html = <<<DEFAULT_HTML
776
+		$default_html = <<<DEFAULT_HTML
777 777
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
778 778
     <label class="frm_pos_[label_position]">[field_name]
779 779
         <span class="frm_required">[required_label]</span>
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
 </div>
784 784
 DEFAULT_HTML;
785 785
 
786
-        $old_default_html = <<<DEFAULT_HTML
786
+		$old_default_html = <<<DEFAULT_HTML
787 787
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
788 788
     <label class="frm_pos_[label_position]">[field_name]
789 789
         <span class="frm_required">[required_label]</span>
@@ -793,23 +793,23 @@  discard block
 block discarded – undo
793 793
 </div>
794 794
 DEFAULT_HTML;
795 795
 
796
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
797
-        foreach ( $fields as $field ) {
798
-            $field->field_options = maybe_unserialize($field->field_options);
796
+		$new_default_html = FrmFieldsHelper::get_default_html('text');
797
+		foreach ( $fields as $field ) {
798
+			$field->field_options = maybe_unserialize($field->field_options);
799 799
 			if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
800
-                $field->field_options['custom_html'] = $new_default_html;
800
+				$field->field_options['custom_html'] = $new_default_html;
801 801
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
802
-            }
803
-            unset($field);
804
-        }
805
-        unset($default_html, $old_default_html, $fields);
806
-    }
807
-
808
-    private function migrate_to_4() {
809
-        global $wpdb;
802
+			}
803
+			unset($field);
804
+		}
805
+		unset($default_html, $old_default_html, $fields);
806
+	}
807
+
808
+	private function migrate_to_4() {
809
+		global $wpdb;
810 810
 		$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
811
-        foreach ( $user_ids as $user_id ) {
811
+		foreach ( $user_ids as $user_id ) {
812 812
 			$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) );
813
-        }
814
-    }
813
+		}
814
+	}
815 815
 }
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
     var $entry_metas;
8 8
 
9 9
     public function __construct() {
10
-        if ( ! defined('ABSPATH') ) {
11
-            die('You are not allowed to call this page directly.');
10
+        if ( ! defined( 'ABSPATH' ) ) {
11
+            die( 'You are not allowed to call this page directly.' );
12 12
         }
13 13
 
14 14
         global $wpdb;
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         $frm_db_version = FrmAppHelper::$db_version;
27 27
         $old_db_version = (float) $old_db_version;
28 28
         if ( ! $old_db_version ) {
29
-            $old_db_version = get_option('frm_db_version');
29
+            $old_db_version = get_option( 'frm_db_version' );
30 30
         }
31 31
 
32 32
         if ( $frm_db_version != $old_db_version ) {
@@ -36,16 +36,16 @@  discard block
 block discarded – undo
36 36
 			require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
37 37
 
38 38
             $this->create_tables();
39
-            $this->migrate_data($frm_db_version, $old_db_version);
39
+            $this->migrate_data( $frm_db_version, $old_db_version );
40 40
 
41 41
             /***** SAVE DB VERSION *****/
42
-            update_option('frm_db_version', $frm_db_version);
42
+            update_option( 'frm_db_version', $frm_db_version );
43 43
 
44 44
             /**** ADD/UPDATE DEFAULT TEMPLATES ****/
45 45
             FrmXMLController::add_default_templates();
46 46
         }
47 47
 
48
-        do_action('frm_after_install');
48
+        do_action( 'frm_after_install' );
49 49
 
50 50
         /**** update the styling settings ****/
51 51
 		if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 				global $wpdb;
156 156
 				$wpdb->query( $q . $charset_collate );
157 157
 			}
158
-            unset($q);
158
+            unset( $q );
159 159
         }
160 160
     }
161 161
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 * @param string $starts_with
181 181
      */
182 182
     public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
183
-        if ( empty($args) ) {
183
+        if ( empty( $args ) ) {
184 184
 			// add an arg to prevent prepare from failing
185 185
 			$args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
186 186
 			return;
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 		$key = trim( $key );
242 242
 
243 243
 		if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
244
-            $k = explode(' ', $key);
244
+            $k = explode( ' ', $key );
245 245
             $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
246 246
             $values[] = '%Y-%m-%d %H:%i:%s';
247 247
         } else {
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
         if ( is_array( $value ) ) {
255 255
             // translate array of values to "in"
256 256
 			if ( strpos( $lowercase_key, 'like' ) !== false ) {
257
-				$where = preg_replace('/' . $key . '$/', '', $where);
257
+				$where = preg_replace( '/' . $key . '$/', '', $where );
258 258
 				$where .= '(';
259 259
 				$start = true;
260 260
 				foreach ( $value as $v ) {
@@ -415,8 +415,8 @@  discard block
 block discarded – undo
415 415
 		);
416 416
 
417 417
 		$where_is = strtolower( $where_is );
418
-		if ( isset( $switch_to[ $where_is ] ) ) {
419
-			return ' ' . $switch_to[ $where_is ];
418
+		if ( isset( $switch_to[$where_is] ) ) {
419
+			return ' ' . $switch_to[$where_is];
420 420
 		}
421 421
 
422 422
 		// > and < need a little more work since we don't want them switched to >= and <=
@@ -438,8 +438,8 @@  discard block
 block discarded – undo
438 438
     private static function get_group_and_table_name( &$table, &$group ) {
439 439
 		global $wpdb, $wpmuBaseTablePrefix;
440 440
 
441
-        $table_parts = explode(' ', $table);
442
-        $group = reset($table_parts);
441
+        $table_parts = explode( ' ', $table );
442
+        $group = reset( $table_parts );
443 443
         $group = str_replace( $wpdb->prefix, '', $group );
444 444
 
445 445
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     }
455 455
 
456 456
     private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
457
-        if ( ! is_array($args) ) {
457
+        if ( ! is_array( $args ) ) {
458 458
 			$args = array( 'order_by' => $args );
459 459
         }
460 460
 
@@ -469,16 +469,16 @@  discard block
 block discarded – undo
469 469
         $temp_args = $args;
470 470
         foreach ( $temp_args as $k => $v ) {
471 471
             if ( $v == '' ) {
472
-				unset( $args[ $k ] );
472
+				unset( $args[$k] );
473 473
                 continue;
474 474
             }
475 475
 
476 476
             if ( $k == 'limit' ) {
477
-				$args[ $k ] = FrmAppHelper::esc_limit( $v );
477
+				$args[$k] = FrmAppHelper::esc_limit( $v );
478 478
             }
479 479
             $db_name = strtoupper( str_replace( '_', ' ', $k ) );
480 480
             if ( strpos( $v, $db_name ) === false ) {
481
-				$args[ $k ] = $db_name . ' ' . $v;
481
+				$args[$k] = $db_name . ' ' . $v;
482 482
             }
483 483
         }
484 484
 
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
 
506 506
 		$query = self::generate_query_string_from_pieces( $columns, $table, $where );
507 507
 
508
-		$cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . $columns . '_results_ARRAY_A' , ' WHERE' ) );
508
+		$cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . $columns . '_results_ARRAY_A', ' WHERE' ) );
509 509
 		$results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_associative_results' );
510 510
 
511 511
 		return $results;
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
     public function uninstall() {
545 545
 		if ( ! current_user_can( 'administrator' ) ) {
546 546
             $frm_settings = FrmAppHelper::get_settings();
547
-            wp_die($frm_settings->admin_permission);
547
+            wp_die( $frm_settings->admin_permission );
548 548
         }
549 549
 
550 550
         global $wpdb, $wp_roles;
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries );
555 555
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas );
556 556
 
557
-        delete_option('frm_options');
558
-        delete_option('frm_db_version');
557
+        delete_option( 'frm_options' );
558
+        delete_option( 'frm_db_version' );
559 559
 
560 560
         //delete roles
561 561
         $frm_roles = FrmAppHelper::frm_capabilities();
@@ -563,11 +563,11 @@  discard block
 block discarded – undo
563 563
         foreach ( $frm_roles as $frm_role => $frm_role_description ) {
564 564
             foreach ( $roles as $role => $details ) {
565 565
                 $wp_roles->remove_cap( $role, $frm_role );
566
-                unset($role, $details);
566
+                unset( $role, $details );
567 567
     		}
568
-    		unset($frm_role, $frm_role_description);
568
+    		unset( $frm_role, $frm_role_description );
569 569
 		}
570
-		unset($roles, $frm_roles);
570
+		unset( $roles, $frm_roles );
571 571
 
572 572
 		// delete actions, views, and styles
573 573
 
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 
590 590
 		$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_%' ) );
591 591
 
592
-        do_action('frm_after_uninstall');
592
+        do_action( 'frm_after_uninstall' );
593 593
         return true;
594 594
     }
595 595
 
@@ -646,8 +646,8 @@  discard block
 block discarded – undo
646 646
 
647 647
         $updated = 0;
648 648
         foreach ( $fields as $f ) {
649
-            $f->field_options = maybe_unserialize($f->field_options);
650
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
649
+            $f->field_options = maybe_unserialize( $f->field_options );
650
+            if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
651 651
                 continue;
652 652
             }
653 653
 
@@ -655,27 +655,27 @@  discard block
 block discarded – undo
655 655
             $f->field_options['size'] .= 'px';
656 656
             $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
657 657
             if ( $u ) {
658
-                $updated++;
658
+                $updated ++;
659 659
             }
660
-            unset($f);
660
+            unset( $f );
661 661
         }
662 662
 
663 663
         // Change the characters in widgets to pixels
664
-        $widgets = get_option('widget_frm_show_form');
665
-        if ( empty($widgets) ) {
664
+        $widgets = get_option( 'widget_frm_show_form' );
665
+        if ( empty( $widgets ) ) {
666 666
             return;
667 667
         }
668 668
 
669
-        $widgets = maybe_unserialize($widgets);
669
+        $widgets = maybe_unserialize( $widgets );
670 670
         foreach ( $widgets as $k => $widget ) {
671
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
671
+            if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
672 672
                 continue;
673 673
             }
674 674
 			$size = round( $pixel_conversion * (int) $widget['size'] );
675 675
             $size .= 'px';
676
-			$widgets[ $k ]['size'] = $size;
676
+			$widgets[$k]['size'] = $size;
677 677
         }
678
-        update_option('widget_frm_show_form', $widgets);
678
+        update_option( 'widget_frm_show_form', $widgets );
679 679
     }
680 680
 
681 681
     /**
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
 			}
725 725
 
726 726
             // Format form options
727
-            $form_options = maybe_unserialize($form->options);
727
+            $form_options = maybe_unserialize( $form->options );
728 728
 
729 729
             // Migrate settings to actions
730 730
             FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
     private function migrate_to_11() {
735 735
         global $wpdb;
736 736
 
737
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
737
+        $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
738 738
 
739 739
         $sending = __( 'Sending', 'formidable' );
740 740
 		$img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
@@ -745,13 +745,13 @@  discard block
 block discarded – undo
745 745
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
746 746
 </div>
747 747
 DEFAULT_HTML;
748
-        unset($sending, $img);
748
+        unset( $sending, $img );
749 749
 
750
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
750
+        $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
751 751
         $draft_link = FrmFormsHelper::get_draft_link();
752 752
 		foreach ( $forms as $form ) {
753
-            $form->options = maybe_unserialize($form->options);
754
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
753
+            $form->options = maybe_unserialize( $form->options );
754
+            if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) {
755 755
                 continue;
756 756
             }
757 757
 
@@ -762,9 +762,9 @@  discard block
 block discarded – undo
762 762
 				$form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
763 763
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
764 764
             }
765
-            unset($form);
765
+            unset( $form );
766 766
         }
767
-        unset($forms);
767
+        unset( $forms );
768 768
     }
769 769
 
770 770
     private function migrate_to_6() {
@@ -793,16 +793,16 @@  discard block
 block discarded – undo
793 793
 </div>
794 794
 DEFAULT_HTML;
795 795
 
796
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
796
+        $new_default_html = FrmFieldsHelper::get_default_html( 'text' );
797 797
         foreach ( $fields as $field ) {
798
-            $field->field_options = maybe_unserialize($field->field_options);
798
+            $field->field_options = maybe_unserialize( $field->field_options );
799 799
 			if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
800 800
                 $field->field_options['custom_html'] = $new_default_html;
801 801
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
802 802
             }
803
-            unset($field);
803
+            unset( $field );
804 804
         }
805
-        unset($default_html, $old_default_html, $fields);
805
+        unset( $default_html, $old_default_html, $fields );
806 806
     }
807 807
 
808 808
     private function migrate_to_4() {
Please login to merge, or discard this patch.
classes/helpers/FrmFieldsHelper.php 1 patch
Indentation   +691 added lines, -691 removed lines patch added patch discarded remove patch
@@ -7,71 +7,71 @@  discard block
 block discarded – undo
7 7
 
8 8
 	public static function setup_new_vars( $type = '', $form_id = '' ) {
9 9
 
10
-        if ( strpos($type, '|') ) {
11
-            list($type, $setting) = explode('|', $type);
12
-        }
13
-
14
-        $defaults = self::get_default_field_opts($type, $form_id);
15
-        $defaults['field_options']['custom_html'] = self::get_default_html($type);
16
-
17
-        $values = array();
18
-
19
-        foreach ( $defaults as $var => $default ) {
20
-            if ( $var == 'field_options' ) {
21
-                $values['field_options'] = array();
22
-                foreach ( $default as $opt_var => $opt_default ) {
23
-                    $values['field_options'][ $opt_var ] = $opt_default;
24
-                    unset($opt_var, $opt_default);
25
-                }
26
-            } else {
27
-                $values[ $var ] = $default;
28
-            }
29
-            unset($var, $default);
30
-        }
31
-
32
-        if ( isset( $setting ) && ! empty( $setting ) ) {
33
-            if ( in_array( $type, array( 'data', 'lookup' ) ) ) {
34
-                $values['field_options']['data_type'] = $setting;
35
-            } else {
36
-                $values['field_options'][ $setting ] = 1;
37
-            }
38
-        }
39
-
40
-        if ( $type == 'radio' || $type == 'checkbox' ) {
41
-            $values['options'] = serialize( array(
42
-                __( 'Option 1', 'formidable' ),
43
-                __( 'Option 2', 'formidable' ),
44
-            ) );
45
-        } else if ( $type == 'select' ) {
46
-            $values['options'] = serialize( array(
47
-                '', __( 'Option 1', 'formidable' ),
48
-            ) );
49
-        } else if ( $type == 'textarea' ) {
50
-            $values['field_options']['max'] = '5';
51
-        } else if ( $type == 'captcha' ) {
52
-            $frm_settings = FrmAppHelper::get_settings();
53
-            $values['invalid'] = $frm_settings->re_msg;
54
-        } else if ( 'url' == $type ) {
55
-            $values['name'] = __( 'Website', 'formidable' );
56
-        }
10
+		if ( strpos($type, '|') ) {
11
+			list($type, $setting) = explode('|', $type);
12
+		}
13
+
14
+		$defaults = self::get_default_field_opts($type, $form_id);
15
+		$defaults['field_options']['custom_html'] = self::get_default_html($type);
16
+
17
+		$values = array();
18
+
19
+		foreach ( $defaults as $var => $default ) {
20
+			if ( $var == 'field_options' ) {
21
+				$values['field_options'] = array();
22
+				foreach ( $default as $opt_var => $opt_default ) {
23
+					$values['field_options'][ $opt_var ] = $opt_default;
24
+					unset($opt_var, $opt_default);
25
+				}
26
+			} else {
27
+				$values[ $var ] = $default;
28
+			}
29
+			unset($var, $default);
30
+		}
31
+
32
+		if ( isset( $setting ) && ! empty( $setting ) ) {
33
+			if ( in_array( $type, array( 'data', 'lookup' ) ) ) {
34
+				$values['field_options']['data_type'] = $setting;
35
+			} else {
36
+				$values['field_options'][ $setting ] = 1;
37
+			}
38
+		}
39
+
40
+		if ( $type == 'radio' || $type == 'checkbox' ) {
41
+			$values['options'] = serialize( array(
42
+				__( 'Option 1', 'formidable' ),
43
+				__( 'Option 2', 'formidable' ),
44
+			) );
45
+		} else if ( $type == 'select' ) {
46
+			$values['options'] = serialize( array(
47
+				'', __( 'Option 1', 'formidable' ),
48
+			) );
49
+		} else if ( $type == 'textarea' ) {
50
+			$values['field_options']['max'] = '5';
51
+		} else if ( $type == 'captcha' ) {
52
+			$frm_settings = FrmAppHelper::get_settings();
53
+			$values['invalid'] = $frm_settings->re_msg;
54
+		} else if ( 'url' == $type ) {
55
+			$values['name'] = __( 'Website', 'formidable' );
56
+		}
57 57
 
58 58
 		$fields = FrmField::field_selection();
59
-        $fields = array_merge($fields, FrmField::pro_field_selection());
59
+		$fields = array_merge($fields, FrmField::pro_field_selection());
60 60
 
61
-        if ( isset( $fields[ $type ] ) ) {
62
-            $values['name'] = is_array( $fields[ $type ] ) ? $fields[ $type ]['name'] : $fields[ $type ];
63
-        }
61
+		if ( isset( $fields[ $type ] ) ) {
62
+			$values['name'] = is_array( $fields[ $type ] ) ? $fields[ $type ]['name'] : $fields[ $type ];
63
+		}
64 64
 
65
-        unset($fields);
65
+		unset($fields);
66 66
 
67
-        return $values;
68
-    }
67
+		return $values;
68
+	}
69 69
 
70 70
 	public static function get_html_id( $field, $plus = '' ) {
71 71
 		return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field );
72
-    }
72
+	}
73 73
 
74
-    public static function setup_edit_vars( $record, $doing_ajax = false ) {
74
+	public static function setup_edit_vars( $record, $doing_ajax = false ) {
75 75
 		$values = array( 'id' => $record->id, 'form_id' => $record->form_id );
76 76
 		$defaults = array(
77 77
 			'name'          => $record->name,
@@ -84,86 +84,86 @@  discard block
 block discarded – undo
84 84
 		);
85 85
 
86 86
 		if ( $doing_ajax ) {
87
-            $values = $values + $defaults;
88
-            $values['form_name'] = '';
87
+			$values = $values + $defaults;
88
+			$values['form_name'] = '';
89 89
 		} else {
90 90
 			foreach ( $defaults as $var => $default ) {
91
-                $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'htmlspecialchars' );
92
-                unset($var, $default);
93
-            }
91
+				$values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'htmlspecialchars' );
92
+				unset($var, $default);
93
+			}
94 94
 
95 95
 			$values['form_name'] = $record->form_id ? FrmForm::getName( $record->form_id ) : '';
96
-        }
96
+		}
97 97
 
98 98
 		unset( $defaults );
99 99
 
100
-        $values['options'] = $record->options;
101
-        $values['field_options'] = $record->field_options;
100
+		$values['options'] = $record->options;
101
+		$values['field_options'] = $record->field_options;
102 102
 
103
-        $defaults = self::get_default_field_opts($values['type'], $record, true);
103
+		$defaults = self::get_default_field_opts($values['type'], $record, true);
104 104
 
105 105
 		if ( $values['type'] == 'captcha' ) {
106
-            $frm_settings = FrmAppHelper::get_settings();
107
-            $defaults['invalid'] = $frm_settings->re_msg;
108
-        }
106
+			$frm_settings = FrmAppHelper::get_settings();
107
+			$defaults['invalid'] = $frm_settings->re_msg;
108
+		}
109 109
 
110 110
 		foreach ( $defaults as $opt => $default ) {
111
-            $values[ $opt ] = isset( $record->field_options[ $opt ] ) ? $record->field_options[ $opt ] : $default;
112
-            unset($opt, $default);
113
-        }
111
+			$values[ $opt ] = isset( $record->field_options[ $opt ] ) ? $record->field_options[ $opt ] : $default;
112
+			unset($opt, $default);
113
+		}
114 114
 
115
-        $values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type);
115
+		$values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type);
116 116
 
117 117
 		return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) );
118
-    }
118
+	}
119 119
 
120
-    public static function get_default_field_opts( $type, $field, $limit = false ) {
121
-        $field_options = array(
122
-            'size' => '', 'max' => '', 'label' => '', 'blank' => '',
123
-            'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0,
124
-            'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '',
120
+	public static function get_default_field_opts( $type, $field, $limit = false ) {
121
+		$field_options = array(
122
+			'size' => '', 'max' => '', 'label' => '', 'blank' => '',
123
+			'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0,
124
+			'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '',
125 125
 			'custom_html' => '', 'captcha_size' => 'normal', 'captcha_theme' => 'light',
126
-        );
126
+		);
127 127
 
128 128
 		if ( $limit ) {
129
-            return $field_options;
129
+			return $field_options;
130 130
 		}
131 131
 
132
-        global $wpdb;
132
+		global $wpdb;
133 133
 
134
-        $form_id = (is_numeric($field)) ? $field : $field->form_id;
134
+		$form_id = (is_numeric($field)) ? $field : $field->form_id;
135 135
 
136 136
 		$key = is_numeric( $field ) ? FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' ) : $field->field_key;
137 137
 
138
-        $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) );
138
+		$field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) );
139 139
 
140
-        $frm_settings = FrmAppHelper::get_settings();
141
-        return array(
142
-            'name' => __( 'Untitled', 'formidable' ), 'description' => '',
140
+		$frm_settings = FrmAppHelper::get_settings();
141
+		return array(
142
+			'name' => __( 'Untitled', 'formidable' ), 'description' => '',
143 143
 			'field_key' => $key, 'type' => $type, 'options' => '', 'default_value' => '',
144 144
 			'field_order' => $field_count + 1, 'required' => false,
145
-            'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg,
146
-            'invalid' => __( 'This field is invalid', 'formidable' ), 'form_id' => $form_id,
145
+			'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg,
146
+			'invalid' => __( 'This field is invalid', 'formidable' ), 'form_id' => $form_id,
147 147
 			'field_options' => $field_options,
148
-        );
149
-    }
148
+		);
149
+	}
150 150
 
151
-    public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
152
-        global $wpdb;
151
+	public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
152
+		global $wpdb;
153 153
 
154 154
 		$values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' );
155
-        $values['form_id'] = $form_id;
156
-        $values['options'] = maybe_serialize($field->options);
157
-        $values['default_value'] = maybe_serialize($field->default_value);
158
-
159
-        foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) {
160
-            $values[ $col ] = $field->{$col};
161
-        }
162
-    }
163
-
164
-    /**
165
-     * @since 2.0
166
-     */
155
+		$values['form_id'] = $form_id;
156
+		$values['options'] = maybe_serialize($field->options);
157
+		$values['default_value'] = maybe_serialize($field->default_value);
158
+
159
+		foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) {
160
+			$values[ $col ] = $field->{$col};
161
+		}
162
+	}
163
+
164
+	/**
165
+	 * @since 2.0
166
+	 */
167 167
 	public static function get_error_msg( $field, $error ) {
168 168
 		$frm_settings = FrmAppHelper::get_settings();
169 169
 		$default_settings = $frm_settings->default_options();
@@ -192,12 +192,12 @@  discard block
 block discarded – undo
192 192
 	public static function get_default_html( $type = 'text' ) {
193 193
 		if ( apply_filters( 'frm_normal_field_type_html', true, $type ) ) {
194 194
 			$input = ( in_array( $type, array( 'radio', 'checkbox', 'data' ) ) ) ? '<div class="frm_opt_container">[input]</div>' : '[input]';
195
-            $for = '';
195
+			$for = '';
196 196
 			if ( ! in_array( $type, array( 'radio', 'checkbox', 'data', 'scale' ) ) ) {
197
-                $for = 'for="field_[key]"';
198
-            }
197
+				$for = 'for="field_[key]"';
198
+			}
199 199
 
200
-            $default_html = <<<DEFAULT_HTML
200
+			$default_html = <<<DEFAULT_HTML
201 201
 <div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]">
202 202
     <label $for class="frm_primary_label">[field_name]
203 203
         <span class="frm_required">[required_label]</span>
@@ -207,82 +207,82 @@  discard block
 block discarded – undo
207 207
     [if error]<div class="frm_error">[error]</div>[/if error]
208 208
 </div>
209 209
 DEFAULT_HTML;
210
-        } else {
210
+		} else {
211 211
 			$default_html = apply_filters('frm_other_custom_html', '', $type);
212
-        }
212
+		}
213 213
 
214
-        return apply_filters('frm_custom_html', $default_html, $type);
215
-    }
214
+		return apply_filters('frm_custom_html', $default_html, $type);
215
+	}
216 216
 
217 217
 	public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) {
218
-        $html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form);
218
+		$html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form);
219 219
 
220
-        $defaults = array(
220
+		$defaults = array(
221 221
 			'field_name'    => 'item_meta[' . $field['id'] . ']',
222 222
 			'field_id'      => $field['id'],
223
-            'field_plus_id' => '',
224
-            'section_id'    => '',
225
-        );
226
-        $args = wp_parse_args($args, $defaults);
227
-        $field_name = $args['field_name'];
228
-        $field_id = $args['field_id'];
229
-        $html_id = self::get_html_id($field, $args['field_plus_id']);
223
+			'field_plus_id' => '',
224
+			'section_id'    => '',
225
+		);
226
+		$args = wp_parse_args($args, $defaults);
227
+		$field_name = $args['field_name'];
228
+		$field_id = $args['field_id'];
229
+		$html_id = self::get_html_id($field, $args['field_plus_id']);
230 230
 
231
-        if ( FrmField::is_multiple_select($field) ) {
232
-            $field_name .= '[]';
233
-        }
231
+		if ( FrmField::is_multiple_select($field) ) {
232
+			$field_name .= '[]';
233
+		}
234 234
 
235
-        //replace [id]
236
-        $html = str_replace('[id]', $field_id, $html);
235
+		//replace [id]
236
+		$html = str_replace('[id]', $field_id, $html);
237 237
 
238
-        // Remove the for attribute for captcha
239
-        if ( $field['type'] == 'captcha' ) {
240
-            $html = str_replace(' for="field_[key]"', '', $html);
241
-        }
238
+		// Remove the for attribute for captcha
239
+		if ( $field['type'] == 'captcha' ) {
240
+			$html = str_replace(' for="field_[key]"', '', $html);
241
+		}
242 242
 
243
-        // set the label for
244
-        $html = str_replace('field_[key]', $html_id, $html);
243
+		// set the label for
244
+		$html = str_replace('field_[key]', $html_id, $html);
245 245
 
246
-        //replace [key]
247
-        $html = str_replace('[key]', $field['field_key'], $html);
246
+		//replace [key]
247
+		$html = str_replace('[key]', $field['field_key'], $html);
248 248
 
249
-        //replace [description] and [required_label] and [error]
249
+		//replace [description] and [required_label] and [error]
250 250
 		$required = FrmField::is_required( $field ) ? $field['required_indicator'] : '';
251
-        if ( ! is_array( $errors ) ) {
252
-            $errors = array();
253
-        }
251
+		if ( ! is_array( $errors ) ) {
252
+			$errors = array();
253
+		}
254 254
 		$error = isset( $errors[ 'field' . $field_id ] ) ? $errors[ 'field' . $field_id ] : false;
255 255
 
256
-        //If field type is section heading, add class so a bottom margin can be added to either the h3 or description
257
-        if ( $field['type'] == 'divider' ) {
258
-            if ( FrmField::is_option_true( $field, 'description' ) ) {
259
-                $html = str_replace( 'frm_description', 'frm_description frm_section_spacing', $html );
260
-            } else {
261
-                $html = str_replace('[label_position]', '[label_position] frm_section_spacing', $html);
262
-            }
263
-        }
256
+		//If field type is section heading, add class so a bottom margin can be added to either the h3 or description
257
+		if ( $field['type'] == 'divider' ) {
258
+			if ( FrmField::is_option_true( $field, 'description' ) ) {
259
+				$html = str_replace( 'frm_description', 'frm_description frm_section_spacing', $html );
260
+			} else {
261
+				$html = str_replace('[label_position]', '[label_position] frm_section_spacing', $html);
262
+			}
263
+		}
264 264
 
265 265
 		foreach ( array( 'description' => $field['description'], 'required_label' => $required, 'error' => $error ) as $code => $value ) {
266
-            self::remove_inline_conditions( ( $value && $value != '' ), $code, $value, $html );
267
-        }
266
+			self::remove_inline_conditions( ( $value && $value != '' ), $code, $value, $html );
267
+		}
268 268
 
269
-        //replace [required_class]
269
+		//replace [required_class]
270 270
 		$required_class = FrmField::is_required( $field ) ? ' frm_required_field' : '';
271
-        $html = str_replace('[required_class]', $required_class, $html);
271
+		$html = str_replace('[required_class]', $required_class, $html);
272 272
 
273
-        //replace [label_position]
274
-        $field['label'] = apply_filters('frm_html_label_position', $field['label'], $field, $form);
275
-        $field['label'] = ( $field['label'] && $field['label'] != '' ) ? $field['label'] : 'top';
273
+		//replace [label_position]
274
+		$field['label'] = apply_filters('frm_html_label_position', $field['label'], $field, $form);
275
+		$field['label'] = ( $field['label'] && $field['label'] != '' ) ? $field['label'] : 'top';
276 276
 		$html = str_replace( '[label_position]', ( ( in_array( $field['type'], array( 'divider', 'end_divider', 'break' ) ) ) ? $field['label'] : ' frm_primary_label' ), $html );
277 277
 
278
-        //replace [field_name]
279
-        $html = str_replace('[field_name]', $field['name'], $html);
278
+		//replace [field_name]
279
+		$html = str_replace('[field_name]', $field['name'], $html);
280 280
 
281 281
 		self::add_field_div_classes( $field_id, $field, $errors, $html );
282 282
 
283
-        //replace [entry_key]
284
-        $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' );
285
-        $html = str_replace('[entry_key]', $entry_key, $html);
283
+		//replace [entry_key]
284
+		$entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' );
285
+		$html = str_replace('[entry_key]', $entry_key, $html);
286 286
 
287 287
 		if ( $form ) {
288 288
 			$form = (array) $form;
@@ -296,57 +296,57 @@  discard block
 block discarded – undo
296 296
 
297 297
 		self::process_wp_shortcodes( $html );
298 298
 
299
-        //replace [input]
300
-        preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER);
301
-        global $frm_vars;
302
-        $frm_settings = FrmAppHelper::get_settings();
299
+		//replace [input]
300
+		preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER);
301
+		global $frm_vars;
302
+		$frm_settings = FrmAppHelper::get_settings();
303 303
 
304
-        foreach ( $shortcodes[0] as $short_key => $tag ) {
305
-            $atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
304
+		foreach ( $shortcodes[0] as $short_key => $tag ) {
305
+			$atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
306 306
 			$tag = self::get_shortcode_tag( $shortcodes, $short_key, array( 'conditional' => false, 'conditional_check' => false ) );
307 307
 
308
-            $replace_with = '';
308
+			$replace_with = '';
309 309
 
310
-            if ( $tag == 'input' ) {
311
-                if ( isset($atts['opt']) ) {
312
-                    $atts['opt']--;
313
-                }
310
+			if ( $tag == 'input' ) {
311
+				if ( isset($atts['opt']) ) {
312
+					$atts['opt']--;
313
+				}
314 314
 
315
-                $field['input_class'] = isset($atts['class']) ? $atts['class'] : '';
316
-                if ( isset($atts['class']) ) {
317
-                    unset($atts['class']);
318
-                }
315
+				$field['input_class'] = isset($atts['class']) ? $atts['class'] : '';
316
+				if ( isset($atts['class']) ) {
317
+					unset($atts['class']);
318
+				}
319 319
 
320
-                $field['shortcodes'] = $atts;
321
-                ob_start();
320
+				$field['shortcodes'] = $atts;
321
+				ob_start();
322 322
 				include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/input.php' );
323
-                $replace_with = ob_get_contents();
324
-                ob_end_clean();
325
-            } else if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) {
326
-                $replace_with = FrmProEntriesController::entry_delete_link($atts);
327
-            }
323
+				$replace_with = ob_get_contents();
324
+				ob_end_clean();
325
+			} else if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) {
326
+				$replace_with = FrmProEntriesController::entry_delete_link($atts);
327
+			}
328 328
 
329
-            $html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $html );
330
-        }
329
+			$html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $html );
330
+		}
331 331
 
332
-        $html .= "\n";
332
+		$html .= "\n";
333 333
 
334
-        //Return html if conf_field to prevent loop
335
-        if ( isset($field['conf_field']) && $field['conf_field'] == 'stop' ) {
336
-            return $html;
337
-        }
334
+		//Return html if conf_field to prevent loop
335
+		if ( isset($field['conf_field']) && $field['conf_field'] == 'stop' ) {
336
+			return $html;
337
+		}
338 338
 
339
-        //If field is in repeating section
340
-        if ( $args['section_id'] ) {
341
-            $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form, 'field_name' => $field_name, 'field_id' => $field_id, 'field_plus_id' => $args['field_plus_id'], 'section_id' => $args['section_id'] ));
342
-        } else {
343
-            $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form ));
344
-        }
339
+		//If field is in repeating section
340
+		if ( $args['section_id'] ) {
341
+			$html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form, 'field_name' => $field_name, 'field_id' => $field_id, 'field_plus_id' => $args['field_plus_id'], 'section_id' => $args['section_id'] ));
342
+		} else {
343
+			$html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form ));
344
+		}
345 345
 
346 346
 		self::remove_collapse_shortcode( $html );
347 347
 
348
-        return $html;
349
-    }
348
+		return $html;
349
+	}
350 350
 
351 351
 	/**
352 352
 	 * This filters shortcodes in the field HTML
@@ -411,46 +411,46 @@  discard block
 block discarded – undo
411 411
 		return $classes;
412 412
 	}
413 413
 
414
-    public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
415
-        if ( $no_vars ) {
414
+	public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
415
+		if ( $no_vars ) {
416 416
 			$html = str_replace( '[if ' . $code . ']', '', $html );
417 417
 			$html = str_replace( '[/if ' . $code . ']', '', $html );
418
-        } else {
418
+		} else {
419 419
 			$html = preg_replace( '/(\[if\s+' . $code . '\])(.*?)(\[\/if\s+' . $code . '\])/mis', '', $html );
420
-        }
420
+		}
421 421
 
422 422
 		$html = str_replace( '[' . $code . ']', $replace_with, $html );
423
-    }
423
+	}
424 424
 
425 425
 	public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
426 426
 		$args = wp_parse_args( $args, array( 'conditional' => false, 'conditional_check' => false, 'foreach' => false ) );
427
-        if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) {
428
-            $args['conditional_check'] = true;
429
-        }
430
-
431
-        $prefix = '';
432
-        if ( $args['conditional_check'] ) {
433
-            if ( $args['conditional'] ) {
434
-                $prefix = 'if ';
435
-            } else if ( $args['foreach'] ) {
436
-                $prefix = 'foreach ';
437
-            }
438
-        }
439
-
440
-        $with_tags = $args['conditional_check'] ? 3 : 2;
441
-        if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) {
442
-            $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] );
443
-            $tag = str_replace(']', '', $tag);
444
-            $tags = explode(' ', $tag);
445
-            if ( is_array($tags) ) {
446
-                $tag = $tags[0];
447
-            }
448
-        } else {
449
-            $tag = $shortcodes[ $with_tags - 1 ][ $short_key ];
450
-        }
451
-
452
-        return $tag;
453
-    }
427
+		if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) {
428
+			$args['conditional_check'] = true;
429
+		}
430
+
431
+		$prefix = '';
432
+		if ( $args['conditional_check'] ) {
433
+			if ( $args['conditional'] ) {
434
+				$prefix = 'if ';
435
+			} else if ( $args['foreach'] ) {
436
+				$prefix = 'foreach ';
437
+			}
438
+		}
439
+
440
+		$with_tags = $args['conditional_check'] ? 3 : 2;
441
+		if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) {
442
+			$tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] );
443
+			$tag = str_replace(']', '', $tag);
444
+			$tags = explode(' ', $tag);
445
+			if ( is_array($tags) ) {
446
+				$tag = $tags[0];
447
+			}
448
+		} else {
449
+			$tag = $shortcodes[ $with_tags - 1 ][ $short_key ];
450
+		}
451
+
452
+		return $tag;
453
+	}
454 454
 
455 455
 	/**
456 456
 	 * Remove [collapse_this] if it's still included after all processing
@@ -488,8 +488,8 @@  discard block
 block discarded – undo
488 488
 		}
489 489
 		$api_js_url = apply_filters( 'frm_recaptcha_js_url', $api_js_url );
490 490
 
491
-        wp_register_script( 'recaptcha-api', $api_js_url, '', true );
492
-        wp_enqueue_script( 'recaptcha-api' );
491
+		wp_register_script( 'recaptcha-api', $api_js_url, '', true );
492
+		wp_enqueue_script( 'recaptcha-api' );
493 493
 
494 494
 		// for reverse compatability
495 495
 		$field['captcha_size'] = ( $field['captcha_size'] == 'default' ) ? 'normal' : $field['captcha_size'];
@@ -497,40 +497,40 @@  discard block
 block discarded – undo
497 497
 ?>
498 498
 <div id="field_<?php echo esc_attr( $field['field_key'] ) ?>" class="<?php echo esc_attr( $class_prefix ) ?>g-recaptcha" data-sitekey="<?php echo esc_attr( $frm_settings->pubkey ) ?>" data-size="<?php echo esc_attr( $field['captcha_size'] ) ?>" data-theme="<?php echo esc_attr( $field['captcha_theme'] ) ?>"></div>
499 499
 <?php
500
-    }
500
+	}
501 501
 
502 502
 	public static function show_single_option( $field ) {
503
-        $field_name = $field['name'];
504
-        $html_id = self::get_html_id($field);
505
-        foreach ( $field['options'] as $opt_key => $opt ) {
506
-            $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
507
-            $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
503
+		$field_name = $field['name'];
504
+		$html_id = self::get_html_id($field);
505
+		foreach ( $field['options'] as $opt_key => $opt ) {
506
+			$field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
507
+			$opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
508 508
 
509
-            // If this is an "Other" option, get the HTML for it
509
+			// If this is an "Other" option, get the HTML for it
510 510
 			if ( self::is_other_opt( $opt_key ) ) {
511
-                // Get string for Other text field, if needed
511
+				// Get string for Other text field, if needed
512 512
 				$other_val = self::get_other_val( compact( 'opt_key', 'field' ) );
513 513
 				require( FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php' );
514
-            } else {
514
+			} else {
515 515
 				require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
516
-            }
517
-        }
518
-    }
516
+			}
517
+		}
518
+	}
519 519
 
520 520
 	public static function get_term_link( $tax_id ) {
521
-        $tax = get_taxonomy($tax_id);
522
-        if ( ! $tax ) {
523
-            return;
524
-        }
521
+		$tax = get_taxonomy($tax_id);
522
+		if ( ! $tax ) {
523
+			return;
524
+		}
525 525
 
526
-        $link = sprintf(
527
-            __( 'Please add options from the WordPress "%1$s" page', 'formidable' ),
526
+		$link = sprintf(
527
+			__( 'Please add options from the WordPress "%1$s" page', 'formidable' ),
528 528
 			'<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">' . ( empty( $tax->labels->name ) ? __( 'Categories' ) : $tax->labels->name ) . '</a>'
529
-        );
530
-        unset($tax);
529
+		);
530
+		unset($tax);
531 531
 
532
-        return $link;
533
-    }
532
+		return $link;
533
+	}
534 534
 
535 535
 	public static function value_meets_condition( $observed_value, $cond, $hide_opt ) {
536 536
 		// Remove white space from hide_opt
@@ -541,195 +541,195 @@  discard block
 block discarded – undo
541 541
 		$observed_value = wp_kses_post( $observed_value );
542 542
 		$hide_opt = wp_kses_post( $hide_opt );
543 543
 
544
-        if ( is_array($observed_value) ) {
545
-            return self::array_value_condition($observed_value, $cond, $hide_opt);
546
-        }
547
-
548
-        $m = false;
549
-        if ( $cond == '==' ) {
550
-            $m = $observed_value == $hide_opt;
551
-        } else if ( $cond == '!=' ) {
552
-            $m = $observed_value != $hide_opt;
553
-        } else if ( $cond == '>' ) {
554
-            $m = $observed_value > $hide_opt;
555
-        } else if ( $cond == '<' ) {
556
-            $m = $observed_value < $hide_opt;
557
-        } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
558
-            $m = stripos($observed_value, $hide_opt);
559
-            if ( $cond == 'not LIKE' ) {
560
-                $m = ( $m === false ) ? true : false;
561
-            } else {
562
-                $m = ( $m === false ) ? false : true;
563
-            }
564
-        }
565
-        return $m;
566
-    }
544
+		if ( is_array($observed_value) ) {
545
+			return self::array_value_condition($observed_value, $cond, $hide_opt);
546
+		}
547
+
548
+		$m = false;
549
+		if ( $cond == '==' ) {
550
+			$m = $observed_value == $hide_opt;
551
+		} else if ( $cond == '!=' ) {
552
+			$m = $observed_value != $hide_opt;
553
+		} else if ( $cond == '>' ) {
554
+			$m = $observed_value > $hide_opt;
555
+		} else if ( $cond == '<' ) {
556
+			$m = $observed_value < $hide_opt;
557
+		} else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
558
+			$m = stripos($observed_value, $hide_opt);
559
+			if ( $cond == 'not LIKE' ) {
560
+				$m = ( $m === false ) ? true : false;
561
+			} else {
562
+				$m = ( $m === false ) ? false : true;
563
+			}
564
+		}
565
+		return $m;
566
+	}
567 567
 
568 568
 	public static function array_value_condition( $observed_value, $cond, $hide_opt ) {
569
-        $m = false;
570
-        if ( $cond == '==' ) {
571
-            if ( is_array($hide_opt) ) {
572
-                $m = array_intersect($hide_opt, $observed_value);
573
-                $m = empty($m) ? false : true;
574
-            } else {
575
-                $m = in_array($hide_opt, $observed_value);
576
-            }
577
-        } else if ( $cond == '!=' ) {
578
-            $m = ! in_array($hide_opt, $observed_value);
579
-        } else if ( $cond == '>' ) {
580
-            $min = min($observed_value);
581
-            $m = $min > $hide_opt;
582
-        } else if ( $cond == '<' ) {
583
-            $max = max($observed_value);
584
-            $m = $max < $hide_opt;
585
-        } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
586
-            foreach ( $observed_value as $ob ) {
587
-                $m = strpos($ob, $hide_opt);
588
-                if ( $m !== false ) {
589
-                    $m = true;
590
-                    break;
591
-                }
592
-            }
593
-
594
-            if ( $cond == 'not LIKE' ) {
595
-                $m = ( $m === false ) ? true : false;
596
-            }
597
-        }
598
-
599
-        return $m;
600
-    }
601
-
602
-    /**
603
-     * Replace a few basic shortcodes and field ids
604
-     * @since 2.0
605
-     * @return string
606
-     */
569
+		$m = false;
570
+		if ( $cond == '==' ) {
571
+			if ( is_array($hide_opt) ) {
572
+				$m = array_intersect($hide_opt, $observed_value);
573
+				$m = empty($m) ? false : true;
574
+			} else {
575
+				$m = in_array($hide_opt, $observed_value);
576
+			}
577
+		} else if ( $cond == '!=' ) {
578
+			$m = ! in_array($hide_opt, $observed_value);
579
+		} else if ( $cond == '>' ) {
580
+			$min = min($observed_value);
581
+			$m = $min > $hide_opt;
582
+		} else if ( $cond == '<' ) {
583
+			$max = max($observed_value);
584
+			$m = $max < $hide_opt;
585
+		} else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
586
+			foreach ( $observed_value as $ob ) {
587
+				$m = strpos($ob, $hide_opt);
588
+				if ( $m !== false ) {
589
+					$m = true;
590
+					break;
591
+				}
592
+			}
593
+
594
+			if ( $cond == 'not LIKE' ) {
595
+				$m = ( $m === false ) ? true : false;
596
+			}
597
+		}
598
+
599
+		return $m;
600
+	}
601
+
602
+	/**
603
+	 * Replace a few basic shortcodes and field ids
604
+	 * @since 2.0
605
+	 * @return string
606
+	 */
607 607
 	public static function basic_replace_shortcodes( $value, $form, $entry ) {
608
-        if ( strpos($value, '[sitename]') !== false ) {
609
-            $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
610
-            $value = str_replace('[sitename]', $new_value, $value);
611
-        }
608
+		if ( strpos($value, '[sitename]') !== false ) {
609
+			$new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
610
+			$value = str_replace('[sitename]', $new_value, $value);
611
+		}
612 612
 
613
-        $value = apply_filters('frm_content', $value, $form, $entry);
614
-        $value = do_shortcode($value);
613
+		$value = apply_filters('frm_content', $value, $form, $entry);
614
+		$value = do_shortcode($value);
615 615
 
616
-        return $value;
617
-    }
616
+		return $value;
617
+	}
618 618
 
619 619
 	public static function get_shortcodes( $content, $form_id ) {
620
-        if ( FrmAppHelper::pro_is_installed() ) {
621
-            return FrmProDisplaysHelper::get_shortcodes($content, $form_id);
622
-        }
620
+		if ( FrmAppHelper::pro_is_installed() ) {
621
+			return FrmProDisplaysHelper::get_shortcodes($content, $form_id);
622
+		}
623 623
 
624
-        $fields = FrmField::getAll( array( 'fi.form_id' => (int) $form_id, 'fi.type not' => FrmField::no_save_fields() ) );
624
+		$fields = FrmField::getAll( array( 'fi.form_id' => (int) $form_id, 'fi.type not' => FrmField::no_save_fields() ) );
625 625
 
626
-        $tagregexp = self::allowed_shortcodes($fields);
626
+		$tagregexp = self::allowed_shortcodes($fields);
627 627
 
628
-        preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER);
628
+		preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER);
629 629
 
630
-        return $matches;
631
-    }
630
+		return $matches;
631
+	}
632 632
 
633 633
 	public static function allowed_shortcodes( $fields = array() ) {
634
-        $tagregexp = array(
635
-            'editlink', 'id', 'key', 'ip',
636
-            'siteurl', 'sitename', 'admin_email',
637
-            'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by',
634
+		$tagregexp = array(
635
+			'editlink', 'id', 'key', 'ip',
636
+			'siteurl', 'sitename', 'admin_email',
637
+			'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by',
638 638
 			'parent[-|_]id',
639
-        );
639
+		);
640 640
 
641
-        foreach ( $fields as $field ) {
642
-            $tagregexp[] = $field->id;
643
-            $tagregexp[] = $field->field_key;
644
-        }
641
+		foreach ( $fields as $field ) {
642
+			$tagregexp[] = $field->id;
643
+			$tagregexp[] = $field->field_key;
644
+		}
645 645
 
646
-        $tagregexp = implode('|', $tagregexp);
647
-        return $tagregexp;
648
-    }
646
+		$tagregexp = implode('|', $tagregexp);
647
+		return $tagregexp;
648
+	}
649 649
 
650 650
 	public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
651
-        $shortcode_values = array(
652
-           'id'     => $entry->id,
653
-           'key'    => $entry->item_key,
654
-           'ip'     => $entry->ip,
655
-        );
651
+		$shortcode_values = array(
652
+		   'id'     => $entry->id,
653
+		   'key'    => $entry->item_key,
654
+		   'ip'     => $entry->ip,
655
+		);
656 656
 
657
-        foreach ( $shortcodes[0] as $short_key => $tag ) {
658
-            $atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] );
657
+		foreach ( $shortcodes[0] as $short_key => $tag ) {
658
+			$atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] );
659 659
 
660
-            if ( ! empty( $shortcodes[3][ $short_key ] ) ) {
660
+			if ( ! empty( $shortcodes[3][ $short_key ] ) ) {
661 661
 				$tag = str_replace( array( '[', ']' ), '', $shortcodes[0][ $short_key ] );
662
-                $tags = explode(' ', $tag);
663
-                if ( is_array($tags) ) {
664
-                    $tag = $tags[0];
665
-                }
666
-            } else {
667
-                $tag = $shortcodes[2][ $short_key ];
668
-            }
669
-
670
-            switch ( $tag ) {
671
-                case 'id':
672
-                case 'key':
673
-                case 'ip':
674
-                    $replace_with = $shortcode_values[ $tag ];
675
-                break;
676
-
677
-                case 'user_agent':
678
-                case 'user-agent':
679
-                    $entry->description = maybe_unserialize($entry->description);
662
+				$tags = explode(' ', $tag);
663
+				if ( is_array($tags) ) {
664
+					$tag = $tags[0];
665
+				}
666
+			} else {
667
+				$tag = $shortcodes[2][ $short_key ];
668
+			}
669
+
670
+			switch ( $tag ) {
671
+				case 'id':
672
+				case 'key':
673
+				case 'ip':
674
+					$replace_with = $shortcode_values[ $tag ];
675
+				break;
676
+
677
+				case 'user_agent':
678
+				case 'user-agent':
679
+					$entry->description = maybe_unserialize($entry->description);
680 680
 					$replace_with = FrmEntryFormat::get_browser( $entry->description['browser'] );
681
-                break;
682
-
683
-                case 'created_at':
684
-                case 'created-at':
685
-                case 'updated_at':
686
-                case 'updated-at':
687
-                    if ( isset($atts['format']) ) {
688
-                        $time_format = ' ';
689
-                    } else {
690
-                        $atts['format'] = get_option('date_format');
691
-                        $time_format = '';
692
-                    }
693
-
694
-                    $this_tag = str_replace('-', '_', $tag);
695
-                    $replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format);
696
-                    unset($this_tag);
697
-                break;
698
-
699
-                case 'created_by':
700
-                case 'created-by':
701
-                case 'updated_by':
702
-                case 'updated-by':
703
-                    $this_tag = str_replace('-', '_', $tag);
681
+				break;
682
+
683
+				case 'created_at':
684
+				case 'created-at':
685
+				case 'updated_at':
686
+				case 'updated-at':
687
+					if ( isset($atts['format']) ) {
688
+						$time_format = ' ';
689
+					} else {
690
+						$atts['format'] = get_option('date_format');
691
+						$time_format = '';
692
+					}
693
+
694
+					$this_tag = str_replace('-', '_', $tag);
695
+					$replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format);
696
+					unset($this_tag);
697
+				break;
698
+
699
+				case 'created_by':
700
+				case 'created-by':
701
+				case 'updated_by':
702
+				case 'updated-by':
703
+					$this_tag = str_replace('-', '_', $tag);
704 704
 					$replace_with = self::get_display_value( $entry->{$this_tag}, (object) array( 'type' => 'user_id' ), $atts );
705
-                    unset($this_tag);
706
-                break;
707
-
708
-                case 'admin_email':
709
-                case 'siteurl':
710
-                case 'frmurl':
711
-                case 'sitename':
712
-                case 'get':
713
-                    $replace_with = self::dynamic_default_values( $tag, $atts );
714
-                break;
715
-
716
-                default:
717
-                    $field = FrmField::getOne( $tag );
718
-                    if ( ! $field ) {
719
-                        break;
720
-                    }
721
-
722
-                    $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
723
-
724
-                    $replace_with = FrmEntryMeta::get_meta_value( $entry, $field->id );
725
-
726
-                    $atts['entry_id'] = $entry->id;
727
-                    $atts['entry_key'] = $entry->item_key;
728
-
729
-                    if ( isset($atts['show']) && $atts['show'] == 'field_label' ) {
730
-                        $replace_with = $field->name;
731
-                    } else if ( isset($atts['show']) && $atts['show'] == 'description' ) {
732
-                        $replace_with = $field->description;
705
+					unset($this_tag);
706
+				break;
707
+
708
+				case 'admin_email':
709
+				case 'siteurl':
710
+				case 'frmurl':
711
+				case 'sitename':
712
+				case 'get':
713
+					$replace_with = self::dynamic_default_values( $tag, $atts );
714
+				break;
715
+
716
+				default:
717
+					$field = FrmField::getOne( $tag );
718
+					if ( ! $field ) {
719
+						break;
720
+					}
721
+
722
+					$sep = isset($atts['sep']) ? $atts['sep'] : ', ';
723
+
724
+					$replace_with = FrmEntryMeta::get_meta_value( $entry, $field->id );
725
+
726
+					$atts['entry_id'] = $entry->id;
727
+					$atts['entry_key'] = $entry->item_key;
728
+
729
+					if ( isset($atts['show']) && $atts['show'] == 'field_label' ) {
730
+						$replace_with = $field->name;
731
+					} else if ( isset($atts['show']) && $atts['show'] == 'description' ) {
732
+						$replace_with = $field->description;
733 733
 					} else {
734 734
 						$string_value = $replace_with;
735 735
 						if ( is_array( $replace_with ) ) {
@@ -743,82 +743,82 @@  discard block
 block discarded – undo
743 743
 						}
744 744
 					}
745 745
 
746
-                    unset($field);
747
-                break;
748
-            }
746
+					unset($field);
747
+				break;
748
+			}
749 749
 
750
-            if ( isset($replace_with) ) {
751
-                $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content );
752
-            }
750
+			if ( isset($replace_with) ) {
751
+				$content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content );
752
+			}
753 753
 
754
-            unset($atts, $conditional, $replace_with);
754
+			unset($atts, $conditional, $replace_with);
755 755
 		}
756 756
 
757 757
 		return $content;
758
-    }
759
-
760
-    /**
761
-     * Get the value to replace a few standard shortcodes
762
-     *
763
-     * @since 2.0
764
-     * @return string
765
-     */
766
-    public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
767
-        $new_value = '';
768
-        switch ( $tag ) {
769
-            case 'admin_email':
770
-                $new_value = get_option('admin_email');
771
-                break;
772
-            case 'siteurl':
773
-                $new_value = FrmAppHelper::site_url();
774
-                break;
775
-            case 'frmurl':
776
-                $new_value = FrmAppHelper::plugin_url();
777
-                break;
778
-            case 'sitename':
779
-                $new_value = FrmAppHelper::site_name();
780
-                break;
781
-            case 'get':
782
-                $new_value = self::process_get_shortcode( $atts, $return_array );
783
-                break;
784
-        }
785
-
786
-        return $new_value;
787
-    }
788
-
789
-    /**
790
-     * Process the [get] shortcode
791
-     *
792
-     * @since 2.0
793
-     * @return string|array
794
-     */
795
-    public static function process_get_shortcode( $atts, $return_array = false ) {
796
-        if ( ! isset($atts['param']) ) {
797
-            return '';
798
-        }
799
-
800
-        if ( strpos($atts['param'], '&#91;') ) {
801
-            $atts['param'] = str_replace('&#91;', '[', $atts['param']);
802
-            $atts['param'] = str_replace('&#93;', ']', $atts['param']);
803
-        }
804
-
805
-        $new_value = FrmAppHelper::get_param($atts['param'], '');
806
-        $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
807
-
808
-        if ( $new_value == '' ) {
809
-            if ( ! isset($atts['prev_val']) ) {
810
-                $atts['prev_val'] = '';
811
-            }
812
-
813
-            $new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val'];
814
-        }
815
-
816
-        if ( is_array($new_value) && ! $return_array ) {
817
-            $new_value = implode(', ', $new_value);
818
-        }
819
-
820
-        return $new_value;
821
-    }
758
+	}
759
+
760
+	/**
761
+	 * Get the value to replace a few standard shortcodes
762
+	 *
763
+	 * @since 2.0
764
+	 * @return string
765
+	 */
766
+	public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
767
+		$new_value = '';
768
+		switch ( $tag ) {
769
+			case 'admin_email':
770
+				$new_value = get_option('admin_email');
771
+				break;
772
+			case 'siteurl':
773
+				$new_value = FrmAppHelper::site_url();
774
+				break;
775
+			case 'frmurl':
776
+				$new_value = FrmAppHelper::plugin_url();
777
+				break;
778
+			case 'sitename':
779
+				$new_value = FrmAppHelper::site_name();
780
+				break;
781
+			case 'get':
782
+				$new_value = self::process_get_shortcode( $atts, $return_array );
783
+				break;
784
+		}
785
+
786
+		return $new_value;
787
+	}
788
+
789
+	/**
790
+	 * Process the [get] shortcode
791
+	 *
792
+	 * @since 2.0
793
+	 * @return string|array
794
+	 */
795
+	public static function process_get_shortcode( $atts, $return_array = false ) {
796
+		if ( ! isset($atts['param']) ) {
797
+			return '';
798
+		}
799
+
800
+		if ( strpos($atts['param'], '&#91;') ) {
801
+			$atts['param'] = str_replace('&#91;', '[', $atts['param']);
802
+			$atts['param'] = str_replace('&#93;', ']', $atts['param']);
803
+		}
804
+
805
+		$new_value = FrmAppHelper::get_param($atts['param'], '');
806
+		$new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
807
+
808
+		if ( $new_value == '' ) {
809
+			if ( ! isset($atts['prev_val']) ) {
810
+				$atts['prev_val'] = '';
811
+			}
812
+
813
+			$new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val'];
814
+		}
815
+
816
+		if ( is_array($new_value) && ! $return_array ) {
817
+			$new_value = implode(', ', $new_value);
818
+		}
819
+
820
+		return $new_value;
821
+	}
822 822
 
823 823
 	public static function get_display_value( $replace_with, $field, $atts = array() ) {
824 824
 		$sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
@@ -826,14 +826,14 @@  discard block
 block discarded – undo
826 826
 		$replace_with = apply_filters( 'frm_get_' . $field->type . '_display_value', $replace_with, $field, $atts );
827 827
 		$replace_with = apply_filters( 'frm_get_display_value', $replace_with, $field, $atts );
828 828
 
829
-        if ( $field->type == 'textarea' || $field->type == 'rte' ) {
830
-            $autop = isset($atts['wpautop']) ? $atts['wpautop'] : true;
831
-            if ( apply_filters('frm_use_wpautop', $autop) ) {
832
-                if ( is_array($replace_with) ) {
833
-                    $replace_with = implode("\n", $replace_with);
834
-                }
835
-                $replace_with = wpautop($replace_with);
836
-            }
829
+		if ( $field->type == 'textarea' || $field->type == 'rte' ) {
830
+			$autop = isset($atts['wpautop']) ? $atts['wpautop'] : true;
831
+			if ( apply_filters('frm_use_wpautop', $autop) ) {
832
+				if ( is_array($replace_with) ) {
833
+					$replace_with = implode("\n", $replace_with);
834
+				}
835
+				$replace_with = wpautop($replace_with);
836
+			}
837 837
 			unset( $autop );
838 838
 		} else if ( is_array( $replace_with ) ) {
839 839
 			$replace_with = implode( $sep, $replace_with );
@@ -843,37 +843,37 @@  discard block
 block discarded – undo
843 843
 	}
844 844
 
845 845
 	public static function get_field_types( $type ) {
846
-        $single_input = array(
847
-            'text', 'textarea', 'rte', 'number', 'email', 'url',
848
-            'image', 'file', 'date', 'phone', 'hidden', 'time',
849
-            'user_id', 'tag', 'password',
850
-        );
846
+		$single_input = array(
847
+			'text', 'textarea', 'rte', 'number', 'email', 'url',
848
+			'image', 'file', 'date', 'phone', 'hidden', 'time',
849
+			'user_id', 'tag', 'password',
850
+		);
851 851
 		$multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'lookup' );
852 852
 		$other_type = array( 'html', 'break' );
853 853
 
854 854
 		$field_selection = array_merge( FrmField::pro_field_selection(), FrmField::field_selection() );
855 855
 
856
-        $field_types = array();
857
-        if ( in_array($type, $single_input) ) {
858
-            self::field_types_for_input( $single_input, $field_selection, $field_types );
859
-        } else if ( in_array($type, $multiple_input) ) {
860
-            self::field_types_for_input( $multiple_input, $field_selection, $field_types );
861
-        } else if ( in_array($type, $other_type) ) {
862
-            self::field_types_for_input( $other_type, $field_selection, $field_types );
856
+		$field_types = array();
857
+		if ( in_array($type, $single_input) ) {
858
+			self::field_types_for_input( $single_input, $field_selection, $field_types );
859
+		} else if ( in_array($type, $multiple_input) ) {
860
+			self::field_types_for_input( $multiple_input, $field_selection, $field_types );
861
+		} else if ( in_array($type, $other_type) ) {
862
+			self::field_types_for_input( $other_type, $field_selection, $field_types );
863 863
 		} else if ( isset( $field_selection[ $type ] ) ) {
864
-            $field_types[ $type ] = $field_selection[ $type ];
865
-        }
864
+			$field_types[ $type ] = $field_selection[ $type ];
865
+		}
866 866
 
867 867
 		$field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) );
868
-        return $field_types;
869
-    }
868
+		return $field_types;
869
+	}
870 870
 
871
-    private static function field_types_for_input( $inputs, $fields, &$field_types ) {
872
-        foreach ( $inputs as $input ) {
873
-            $field_types[ $input ] = $fields[ $input ];
874
-            unset($input);
875
-        }
876
-    }
871
+	private static function field_types_for_input( $inputs, $fields, &$field_types ) {
872
+		foreach ( $inputs as $input ) {
873
+			$field_types[ $input ] = $fields[ $input ];
874
+			unset($input);
875
+		}
876
+	}
877 877
 
878 878
 	/**
879 879
 	 * Check if current field option is an "other" option
@@ -887,14 +887,14 @@  discard block
 block discarded – undo
887 887
 		return $opt_key && strpos( $opt_key, 'other_' ) === 0;
888 888
 	}
889 889
 
890
-    /**
891
-    * Get value that belongs in "Other" text box
892
-    *
893
-    * @since 2.0.6
894
-    *
895
-    * @param array $args
896
-    */
897
-    public static function get_other_val( $args ) {
890
+	/**
891
+	 * Get value that belongs in "Other" text box
892
+	 *
893
+	 * @since 2.0.6
894
+	 *
895
+	 * @param array $args
896
+	 */
897
+	public static function get_other_val( $args ) {
898 898
 		$defaults = array(
899 899
 			'opt_key' => 0, 'field' => array(),
900 900
 			'parent' => false, 'pointer' => false,
@@ -970,20 +970,20 @@  discard block
 block discarded – undo
970 970
 		}
971 971
 
972 972
 		return $other_val;
973
-    }
974
-
975
-    /**
976
-    * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
977
-    * Intended for front-end use
978
-    *
979
-    * @since 2.0.6
980
-    *
981
-    * @param array $args should include field, opt_key and field name
982
-    * @param boolean $other_opt
983
-    * @param string $checked
984
-    * @return string $other_val
985
-    */
986
-    public static function prepare_other_input( $args, &$other_opt, &$checked ) {
973
+	}
974
+
975
+	/**
976
+	 * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
977
+	 * Intended for front-end use
978
+	 *
979
+	 * @since 2.0.6
980
+	 *
981
+	 * @param array $args should include field, opt_key and field name
982
+	 * @param boolean $other_opt
983
+	 * @param string $checked
984
+	 * @return string $other_val
985
+	 */
986
+	public static function prepare_other_input( $args, &$other_opt, &$checked ) {
987 987
 		//Check if this is an "Other" option
988 988
 		if ( ! self::is_other_opt( $args['opt_key'] ) ) {
989 989
 			return;
@@ -999,8 +999,8 @@  discard block
 block discarded – undo
999 999
 			$checked = 'checked="checked" ';
1000 1000
 		}
1001 1001
 
1002
-        return $other_args;
1003
-    }
1002
+		return $other_args;
1003
+	}
1004 1004
 
1005 1005
 	/**
1006 1006
 	 * @param array $args
@@ -1050,8 +1050,8 @@  discard block
 block discarded – undo
1050 1050
 	 * @since 2.0.6
1051 1051
 	 */
1052 1052
 	public static function include_other_input( $args ) {
1053
-        if ( ! $args['other_opt'] ) {
1054
-        	return;
1053
+		if ( ! $args['other_opt'] ) {
1054
+			return;
1055 1055
 		}
1056 1056
 
1057 1057
 		$classes = array( 'frm_other_input' );
@@ -1072,15 +1072,15 @@  discard block
 block discarded – undo
1072 1072
 	}
1073 1073
 
1074 1074
 	/**
1075
-	* Get the HTML id for an "Other" text field
1076
-	* Note: This does not affect fields in repeating sections
1077
-	*
1078
-	* @since 2.0.08
1079
-	* @param string $type - field type
1080
-	* @param string $html_id
1081
-	* @param string|boolean $opt_key
1082
-	* @return string $other_id
1083
-	*/
1075
+	 * Get the HTML id for an "Other" text field
1076
+	 * Note: This does not affect fields in repeating sections
1077
+	 *
1078
+	 * @since 2.0.08
1079
+	 * @param string $type - field type
1080
+	 * @param string $html_id
1081
+	 * @param string|boolean $opt_key
1082
+	 * @return string $other_id
1083
+	 */
1084 1084
 	public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1085 1085
 		$other_id = $html_id;
1086 1086
 
@@ -1138,10 +1138,10 @@  discard block
 block discarded – undo
1138 1138
 	}
1139 1139
 
1140 1140
 	public static function switch_field_ids( $val ) {
1141
-        global $frm_duplicate_ids;
1142
-        $replace = array();
1143
-        $replace_with = array();
1144
-        foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1141
+		global $frm_duplicate_ids;
1142
+		$replace = array();
1143
+		$replace_with = array();
1144
+		foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1145 1145
 			$replace[] = '[if ' . $old . ']';
1146 1146
 			$replace_with[] = '[if ' . $new . ']';
1147 1147
 			$replace[] = '[if ' . $old . ' ';
@@ -1156,153 +1156,153 @@  discard block
 block discarded – undo
1156 1156
 			$replace_with[] = '[' . $new . ']';
1157 1157
 			$replace[] = '[' . $old . ' ';
1158 1158
 			$replace_with[] = '[' . $new . ' ';
1159
-            unset($old, $new);
1160
-        }
1159
+			unset($old, $new);
1160
+		}
1161 1161
 		if ( is_array( $val ) ) {
1162 1162
 			foreach ( $val as $k => $v ) {
1163
-                $val[ $k ] = str_replace( $replace, $replace_with, $v );
1164
-                unset($k, $v);
1165
-            }
1166
-        } else {
1167
-            $val = str_replace($replace, $replace_with, $val);
1168
-        }
1169
-
1170
-        return $val;
1171
-    }
1172
-
1173
-    public static function get_us_states() {
1174
-        return apply_filters( 'frm_us_states', array(
1175
-            'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', 'AZ' => 'Arizona',
1176
-            'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware',
1177
-            'DC' => 'District of Columbia',
1178
-            'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho',
1179
-            'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas',
1180
-            'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland',
1181
-            'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi',
1182
-            'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada',
1183
-            'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York',
1184
-            'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma',
1185
-            'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina',
1186
-            'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah',
1187
-            'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia',
1188
-            'WI' => 'Wisconsin', 'WY' => 'Wyoming',
1189
-        ) );
1190
-    }
1191
-
1192
-    public static function get_countries() {
1193
-        return apply_filters( 'frm_countries', array(
1194
-            __( 'Afghanistan', 'formidable' ), __( 'Albania', 'formidable' ), __( 'Algeria', 'formidable' ),
1195
-            __( 'American Samoa', 'formidable' ), __( 'Andorra', 'formidable' ), __( 'Angola', 'formidable' ),
1196
-            __( 'Anguilla', 'formidable' ), __( 'Antarctica', 'formidable' ), __( 'Antigua and Barbuda', 'formidable' ),
1197
-            __( 'Argentina', 'formidable' ), __( 'Armenia', 'formidable' ), __( 'Aruba', 'formidable' ),
1198
-            __( 'Australia', 'formidable' ), __( 'Austria', 'formidable' ), __( 'Azerbaijan', 'formidable' ),
1199
-            __( 'Bahamas', 'formidable' ), __( 'Bahrain', 'formidable' ), __( 'Bangladesh', 'formidable' ),
1200
-            __( 'Barbados', 'formidable' ), __( 'Belarus', 'formidable' ), __( 'Belgium', 'formidable' ),
1201
-            __( 'Belize', 'formidable' ), __( 'Benin', 'formidable' ), __( 'Bermuda', 'formidable' ),
1202
-            __( 'Bhutan', 'formidable' ), __( 'Bolivia', 'formidable' ), __( 'Bosnia and Herzegovina', 'formidable' ),
1203
-            __( 'Botswana', 'formidable' ), __( 'Brazil', 'formidable' ), __( 'Brunei', 'formidable' ),
1204
-            __( 'Bulgaria', 'formidable' ), __( 'Burkina Faso', 'formidable' ), __( 'Burundi', 'formidable' ),
1205
-            __( 'Cambodia', 'formidable' ), __( 'Cameroon', 'formidable' ), __( 'Canada', 'formidable' ),
1206
-            __( 'Cape Verde', 'formidable' ), __( 'Cayman Islands', 'formidable' ), __( 'Central African Republic', 'formidable' ),
1207
-            __( 'Chad', 'formidable' ), __( 'Chile', 'formidable' ), __( 'China', 'formidable' ),
1208
-            __( 'Colombia', 'formidable' ), __( 'Comoros', 'formidable' ), __( 'Congo', 'formidable' ),
1209
-            __( 'Costa Rica', 'formidable' ), __( 'C&ocirc;te d\'Ivoire', 'formidable' ), __( 'Croatia', 'formidable' ),
1210
-            __( 'Cuba', 'formidable' ), __( 'Cyprus', 'formidable' ), __( 'Czech Republic', 'formidable' ),
1211
-            __( 'Denmark', 'formidable' ), __( 'Djibouti', 'formidable' ), __( 'Dominica', 'formidable' ),
1212
-            __( 'Dominican Republic', 'formidable' ), __( 'East Timor', 'formidable' ), __( 'Ecuador', 'formidable' ),
1213
-            __( 'Egypt', 'formidable' ), __( 'El Salvador', 'formidable' ), __( 'Equatorial Guinea', 'formidable' ),
1214
-            __( 'Eritrea', 'formidable' ), __( 'Estonia', 'formidable' ), __( 'Ethiopia', 'formidable' ),
1215
-            __( 'Fiji', 'formidable' ), __( 'Finland', 'formidable' ), __( 'France', 'formidable' ),
1216
-            __( 'French Guiana', 'formidable' ), __( 'French Polynesia', 'formidable' ), __( 'Gabon', 'formidable' ),
1217
-            __( 'Gambia', 'formidable' ), __( 'Georgia', 'formidable' ), __( 'Germany', 'formidable' ),
1218
-            __( 'Ghana', 'formidable' ), __( 'Gibraltar', 'formidable' ), __( 'Greece', 'formidable' ),
1219
-            __( 'Greenland', 'formidable' ), __( 'Grenada', 'formidable' ), __( 'Guam', 'formidable' ),
1220
-            __( 'Guatemala', 'formidable' ), __( 'Guinea', 'formidable' ), __( 'Guinea-Bissau', 'formidable' ),
1221
-            __( 'Guyana', 'formidable' ), __( 'Haiti', 'formidable' ), __( 'Honduras', 'formidable' ),
1222
-            __( 'Hong Kong', 'formidable' ), __( 'Hungary', 'formidable' ), __( 'Iceland', 'formidable' ),
1223
-            __( 'India', 'formidable' ), __( 'Indonesia', 'formidable' ), __( 'Iran', 'formidable' ),
1224
-            __( 'Iraq', 'formidable' ), __( 'Ireland', 'formidable' ), __( 'Israel', 'formidable' ),
1225
-            __( 'Italy', 'formidable' ), __( 'Jamaica', 'formidable' ), __( 'Japan', 'formidable' ),
1226
-            __( 'Jordan', 'formidable' ), __( 'Kazakhstan', 'formidable' ), __( 'Kenya', 'formidable' ),
1227
-            __( 'Kiribati', 'formidable' ), __( 'North Korea', 'formidable' ), __( 'South Korea', 'formidable' ),
1228
-            __( 'Kuwait', 'formidable' ), __( 'Kyrgyzstan', 'formidable' ), __( 'Laos', 'formidable' ),
1229
-            __( 'Latvia', 'formidable' ), __( 'Lebanon', 'formidable' ), __( 'Lesotho', 'formidable' ),
1230
-            __( 'Liberia', 'formidable' ), __( 'Libya', 'formidable' ), __( 'Liechtenstein', 'formidable' ),
1231
-            __( 'Lithuania', 'formidable' ), __( 'Luxembourg', 'formidable' ), __( 'Macedonia', 'formidable' ),
1232
-            __( 'Madagascar', 'formidable' ), __( 'Malawi', 'formidable' ), __( 'Malaysia', 'formidable' ),
1233
-            __( 'Maldives', 'formidable' ), __( 'Mali', 'formidable' ), __( 'Malta', 'formidable' ),
1234
-            __( 'Marshall Islands', 'formidable' ), __( 'Mauritania', 'formidable' ), __( 'Mauritius', 'formidable' ),
1235
-            __( 'Mexico', 'formidable' ), __( 'Micronesia', 'formidable' ), __( 'Moldova', 'formidable' ),
1236
-            __( 'Monaco', 'formidable' ), __( 'Mongolia', 'formidable' ), __( 'Montenegro', 'formidable' ),
1237
-            __( 'Montserrat', 'formidable' ), __( 'Morocco', 'formidable' ), __( 'Mozambique', 'formidable' ),
1238
-            __( 'Myanmar', 'formidable' ), __( 'Namibia', 'formidable' ), __( 'Nauru', 'formidable' ),
1239
-            __( 'Nepal', 'formidable' ), __( 'Netherlands', 'formidable' ), __( 'New Zealand', 'formidable' ),
1240
-            __( 'Nicaragua', 'formidable' ), __( 'Niger', 'formidable' ), __( 'Nigeria', 'formidable' ),
1241
-            __( 'Norway', 'formidable' ), __( 'Northern Mariana Islands', 'formidable' ), __( 'Oman', 'formidable' ),
1242
-            __( 'Pakistan', 'formidable' ), __( 'Palau', 'formidable' ), __( 'Palestine', 'formidable' ),
1243
-            __( 'Panama', 'formidable' ), __( 'Papua New Guinea', 'formidable' ), __( 'Paraguay', 'formidable' ),
1244
-            __( 'Peru', 'formidable' ), __( 'Philippines', 'formidable' ), __( 'Poland', 'formidable' ),
1245
-            __( 'Portugal', 'formidable' ), __( 'Puerto Rico', 'formidable' ), __( 'Qatar', 'formidable' ),
1246
-            __( 'Romania', 'formidable' ), __( 'Russia', 'formidable' ), __( 'Rwanda', 'formidable' ),
1247
-            __( 'Saint Kitts and Nevis', 'formidable' ), __( 'Saint Lucia', 'formidable' ),
1248
-            __( 'Saint Vincent and the Grenadines', 'formidable' ), __( 'Samoa', 'formidable' ),
1249
-            __( 'San Marino', 'formidable' ), __( 'Sao Tome and Principe', 'formidable' ), __( 'Saudi Arabia', 'formidable' ),
1250
-            __( 'Senegal', 'formidable' ), __( 'Serbia and Montenegro', 'formidable' ), __( 'Seychelles', 'formidable' ),
1251
-            __( 'Sierra Leone', 'formidable' ), __( 'Singapore', 'formidable' ), __( 'Slovakia', 'formidable' ),
1252
-            __( 'Slovenia', 'formidable' ), __( 'Solomon Islands', 'formidable' ), __( 'Somalia', 'formidable' ),
1253
-            __( 'South Africa', 'formidable' ), __( 'South Sudan', 'formidable' ),
1254
-            __( 'Spain', 'formidable' ), __( 'Sri Lanka', 'formidable' ),
1255
-            __( 'Sudan', 'formidable' ), __( 'Suriname', 'formidable' ), __( 'Swaziland', 'formidable' ),
1256
-            __( 'Sweden', 'formidable' ), __( 'Switzerland', 'formidable' ), __( 'Syria', 'formidable' ),
1257
-            __( 'Taiwan', 'formidable' ), __( 'Tajikistan', 'formidable' ), __( 'Tanzania', 'formidable' ),
1258
-            __( 'Thailand', 'formidable' ), __( 'Togo', 'formidable' ), __( 'Tonga', 'formidable' ),
1259
-            __( 'Trinidad and Tobago', 'formidable' ), __( 'Tunisia', 'formidable' ), __( 'Turkey', 'formidable' ),
1260
-            __( 'Turkmenistan', 'formidable' ), __( 'Tuvalu', 'formidable' ), __( 'Uganda', 'formidable' ),
1261
-            __( 'Ukraine', 'formidable' ), __( 'United Arab Emirates', 'formidable' ), __( 'United Kingdom', 'formidable' ),
1262
-            __( 'United States', 'formidable' ), __( 'Uruguay', 'formidable' ), __( 'Uzbekistan', 'formidable' ),
1263
-            __( 'Vanuatu', 'formidable' ), __( 'Vatican City', 'formidable' ), __( 'Venezuela', 'formidable' ),
1264
-            __( 'Vietnam', 'formidable' ), __( 'Virgin Islands, British', 'formidable' ),
1265
-            __( 'Virgin Islands, U.S.', 'formidable' ), __( 'Yemen', 'formidable' ), __( 'Zambia', 'formidable' ),
1266
-            __( 'Zimbabwe', 'formidable' ),
1267
-        ) );
1268
-    }
1163
+				$val[ $k ] = str_replace( $replace, $replace_with, $v );
1164
+				unset($k, $v);
1165
+			}
1166
+		} else {
1167
+			$val = str_replace($replace, $replace_with, $val);
1168
+		}
1169
+
1170
+		return $val;
1171
+	}
1172
+
1173
+	public static function get_us_states() {
1174
+		return apply_filters( 'frm_us_states', array(
1175
+			'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', 'AZ' => 'Arizona',
1176
+			'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware',
1177
+			'DC' => 'District of Columbia',
1178
+			'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho',
1179
+			'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas',
1180
+			'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland',
1181
+			'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi',
1182
+			'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada',
1183
+			'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York',
1184
+			'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma',
1185
+			'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina',
1186
+			'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah',
1187
+			'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia',
1188
+			'WI' => 'Wisconsin', 'WY' => 'Wyoming',
1189
+		) );
1190
+	}
1191
+
1192
+	public static function get_countries() {
1193
+		return apply_filters( 'frm_countries', array(
1194
+			__( 'Afghanistan', 'formidable' ), __( 'Albania', 'formidable' ), __( 'Algeria', 'formidable' ),
1195
+			__( 'American Samoa', 'formidable' ), __( 'Andorra', 'formidable' ), __( 'Angola', 'formidable' ),
1196
+			__( 'Anguilla', 'formidable' ), __( 'Antarctica', 'formidable' ), __( 'Antigua and Barbuda', 'formidable' ),
1197
+			__( 'Argentina', 'formidable' ), __( 'Armenia', 'formidable' ), __( 'Aruba', 'formidable' ),
1198
+			__( 'Australia', 'formidable' ), __( 'Austria', 'formidable' ), __( 'Azerbaijan', 'formidable' ),
1199
+			__( 'Bahamas', 'formidable' ), __( 'Bahrain', 'formidable' ), __( 'Bangladesh', 'formidable' ),
1200
+			__( 'Barbados', 'formidable' ), __( 'Belarus', 'formidable' ), __( 'Belgium', 'formidable' ),
1201
+			__( 'Belize', 'formidable' ), __( 'Benin', 'formidable' ), __( 'Bermuda', 'formidable' ),
1202
+			__( 'Bhutan', 'formidable' ), __( 'Bolivia', 'formidable' ), __( 'Bosnia and Herzegovina', 'formidable' ),
1203
+			__( 'Botswana', 'formidable' ), __( 'Brazil', 'formidable' ), __( 'Brunei', 'formidable' ),
1204
+			__( 'Bulgaria', 'formidable' ), __( 'Burkina Faso', 'formidable' ), __( 'Burundi', 'formidable' ),
1205
+			__( 'Cambodia', 'formidable' ), __( 'Cameroon', 'formidable' ), __( 'Canada', 'formidable' ),
1206
+			__( 'Cape Verde', 'formidable' ), __( 'Cayman Islands', 'formidable' ), __( 'Central African Republic', 'formidable' ),
1207
+			__( 'Chad', 'formidable' ), __( 'Chile', 'formidable' ), __( 'China', 'formidable' ),
1208
+			__( 'Colombia', 'formidable' ), __( 'Comoros', 'formidable' ), __( 'Congo', 'formidable' ),
1209
+			__( 'Costa Rica', 'formidable' ), __( 'C&ocirc;te d\'Ivoire', 'formidable' ), __( 'Croatia', 'formidable' ),
1210
+			__( 'Cuba', 'formidable' ), __( 'Cyprus', 'formidable' ), __( 'Czech Republic', 'formidable' ),
1211
+			__( 'Denmark', 'formidable' ), __( 'Djibouti', 'formidable' ), __( 'Dominica', 'formidable' ),
1212
+			__( 'Dominican Republic', 'formidable' ), __( 'East Timor', 'formidable' ), __( 'Ecuador', 'formidable' ),
1213
+			__( 'Egypt', 'formidable' ), __( 'El Salvador', 'formidable' ), __( 'Equatorial Guinea', 'formidable' ),
1214
+			__( 'Eritrea', 'formidable' ), __( 'Estonia', 'formidable' ), __( 'Ethiopia', 'formidable' ),
1215
+			__( 'Fiji', 'formidable' ), __( 'Finland', 'formidable' ), __( 'France', 'formidable' ),
1216
+			__( 'French Guiana', 'formidable' ), __( 'French Polynesia', 'formidable' ), __( 'Gabon', 'formidable' ),
1217
+			__( 'Gambia', 'formidable' ), __( 'Georgia', 'formidable' ), __( 'Germany', 'formidable' ),
1218
+			__( 'Ghana', 'formidable' ), __( 'Gibraltar', 'formidable' ), __( 'Greece', 'formidable' ),
1219
+			__( 'Greenland', 'formidable' ), __( 'Grenada', 'formidable' ), __( 'Guam', 'formidable' ),
1220
+			__( 'Guatemala', 'formidable' ), __( 'Guinea', 'formidable' ), __( 'Guinea-Bissau', 'formidable' ),
1221
+			__( 'Guyana', 'formidable' ), __( 'Haiti', 'formidable' ), __( 'Honduras', 'formidable' ),
1222
+			__( 'Hong Kong', 'formidable' ), __( 'Hungary', 'formidable' ), __( 'Iceland', 'formidable' ),
1223
+			__( 'India', 'formidable' ), __( 'Indonesia', 'formidable' ), __( 'Iran', 'formidable' ),
1224
+			__( 'Iraq', 'formidable' ), __( 'Ireland', 'formidable' ), __( 'Israel', 'formidable' ),
1225
+			__( 'Italy', 'formidable' ), __( 'Jamaica', 'formidable' ), __( 'Japan', 'formidable' ),
1226
+			__( 'Jordan', 'formidable' ), __( 'Kazakhstan', 'formidable' ), __( 'Kenya', 'formidable' ),
1227
+			__( 'Kiribati', 'formidable' ), __( 'North Korea', 'formidable' ), __( 'South Korea', 'formidable' ),
1228
+			__( 'Kuwait', 'formidable' ), __( 'Kyrgyzstan', 'formidable' ), __( 'Laos', 'formidable' ),
1229
+			__( 'Latvia', 'formidable' ), __( 'Lebanon', 'formidable' ), __( 'Lesotho', 'formidable' ),
1230
+			__( 'Liberia', 'formidable' ), __( 'Libya', 'formidable' ), __( 'Liechtenstein', 'formidable' ),
1231
+			__( 'Lithuania', 'formidable' ), __( 'Luxembourg', 'formidable' ), __( 'Macedonia', 'formidable' ),
1232
+			__( 'Madagascar', 'formidable' ), __( 'Malawi', 'formidable' ), __( 'Malaysia', 'formidable' ),
1233
+			__( 'Maldives', 'formidable' ), __( 'Mali', 'formidable' ), __( 'Malta', 'formidable' ),
1234
+			__( 'Marshall Islands', 'formidable' ), __( 'Mauritania', 'formidable' ), __( 'Mauritius', 'formidable' ),
1235
+			__( 'Mexico', 'formidable' ), __( 'Micronesia', 'formidable' ), __( 'Moldova', 'formidable' ),
1236
+			__( 'Monaco', 'formidable' ), __( 'Mongolia', 'formidable' ), __( 'Montenegro', 'formidable' ),
1237
+			__( 'Montserrat', 'formidable' ), __( 'Morocco', 'formidable' ), __( 'Mozambique', 'formidable' ),
1238
+			__( 'Myanmar', 'formidable' ), __( 'Namibia', 'formidable' ), __( 'Nauru', 'formidable' ),
1239
+			__( 'Nepal', 'formidable' ), __( 'Netherlands', 'formidable' ), __( 'New Zealand', 'formidable' ),
1240
+			__( 'Nicaragua', 'formidable' ), __( 'Niger', 'formidable' ), __( 'Nigeria', 'formidable' ),
1241
+			__( 'Norway', 'formidable' ), __( 'Northern Mariana Islands', 'formidable' ), __( 'Oman', 'formidable' ),
1242
+			__( 'Pakistan', 'formidable' ), __( 'Palau', 'formidable' ), __( 'Palestine', 'formidable' ),
1243
+			__( 'Panama', 'formidable' ), __( 'Papua New Guinea', 'formidable' ), __( 'Paraguay', 'formidable' ),
1244
+			__( 'Peru', 'formidable' ), __( 'Philippines', 'formidable' ), __( 'Poland', 'formidable' ),
1245
+			__( 'Portugal', 'formidable' ), __( 'Puerto Rico', 'formidable' ), __( 'Qatar', 'formidable' ),
1246
+			__( 'Romania', 'formidable' ), __( 'Russia', 'formidable' ), __( 'Rwanda', 'formidable' ),
1247
+			__( 'Saint Kitts and Nevis', 'formidable' ), __( 'Saint Lucia', 'formidable' ),
1248
+			__( 'Saint Vincent and the Grenadines', 'formidable' ), __( 'Samoa', 'formidable' ),
1249
+			__( 'San Marino', 'formidable' ), __( 'Sao Tome and Principe', 'formidable' ), __( 'Saudi Arabia', 'formidable' ),
1250
+			__( 'Senegal', 'formidable' ), __( 'Serbia and Montenegro', 'formidable' ), __( 'Seychelles', 'formidable' ),
1251
+			__( 'Sierra Leone', 'formidable' ), __( 'Singapore', 'formidable' ), __( 'Slovakia', 'formidable' ),
1252
+			__( 'Slovenia', 'formidable' ), __( 'Solomon Islands', 'formidable' ), __( 'Somalia', 'formidable' ),
1253
+			__( 'South Africa', 'formidable' ), __( 'South Sudan', 'formidable' ),
1254
+			__( 'Spain', 'formidable' ), __( 'Sri Lanka', 'formidable' ),
1255
+			__( 'Sudan', 'formidable' ), __( 'Suriname', 'formidable' ), __( 'Swaziland', 'formidable' ),
1256
+			__( 'Sweden', 'formidable' ), __( 'Switzerland', 'formidable' ), __( 'Syria', 'formidable' ),
1257
+			__( 'Taiwan', 'formidable' ), __( 'Tajikistan', 'formidable' ), __( 'Tanzania', 'formidable' ),
1258
+			__( 'Thailand', 'formidable' ), __( 'Togo', 'formidable' ), __( 'Tonga', 'formidable' ),
1259
+			__( 'Trinidad and Tobago', 'formidable' ), __( 'Tunisia', 'formidable' ), __( 'Turkey', 'formidable' ),
1260
+			__( 'Turkmenistan', 'formidable' ), __( 'Tuvalu', 'formidable' ), __( 'Uganda', 'formidable' ),
1261
+			__( 'Ukraine', 'formidable' ), __( 'United Arab Emirates', 'formidable' ), __( 'United Kingdom', 'formidable' ),
1262
+			__( 'United States', 'formidable' ), __( 'Uruguay', 'formidable' ), __( 'Uzbekistan', 'formidable' ),
1263
+			__( 'Vanuatu', 'formidable' ), __( 'Vatican City', 'formidable' ), __( 'Venezuela', 'formidable' ),
1264
+			__( 'Vietnam', 'formidable' ), __( 'Virgin Islands, British', 'formidable' ),
1265
+			__( 'Virgin Islands, U.S.', 'formidable' ), __( 'Yemen', 'formidable' ), __( 'Zambia', 'formidable' ),
1266
+			__( 'Zimbabwe', 'formidable' ),
1267
+		) );
1268
+	}
1269 1269
 
1270 1270
 	public static function get_bulk_prefilled_opts( array &$prepop ) {
1271 1271
 		$prepop[ __( 'Countries', 'formidable' ) ] = FrmFieldsHelper::get_countries();
1272 1272
 
1273
-        $states = FrmFieldsHelper::get_us_states();
1274
-        $state_abv = array_keys($states);
1275
-        sort($state_abv);
1273
+		$states = FrmFieldsHelper::get_us_states();
1274
+		$state_abv = array_keys($states);
1275
+		sort($state_abv);
1276 1276
 		$prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv;
1277 1277
 
1278
-        $states = array_values($states);
1279
-        sort($states);
1278
+		$states = array_values($states);
1279
+		sort($states);
1280 1280
 		$prepop[ __( 'U.S. States', 'formidable' ) ] = $states;
1281
-        unset($state_abv, $states);
1281
+		unset($state_abv, $states);
1282 1282
 
1283 1283
 		$prepop[ __( 'Age', 'formidable' ) ] = array(
1284
-            __( 'Under 18', 'formidable' ), __( '18-24', 'formidable' ), __( '25-34', 'formidable' ),
1285
-            __( '35-44', 'formidable' ), __( '45-54', 'formidable' ), __( '55-64', 'formidable' ),
1286
-            __( '65 or Above', 'formidable' ), __( 'Prefer Not to Answer', 'formidable' ),
1287
-        );
1284
+			__( 'Under 18', 'formidable' ), __( '18-24', 'formidable' ), __( '25-34', 'formidable' ),
1285
+			__( '35-44', 'formidable' ), __( '45-54', 'formidable' ), __( '55-64', 'formidable' ),
1286
+			__( '65 or Above', 'formidable' ), __( 'Prefer Not to Answer', 'formidable' ),
1287
+		);
1288 1288
 
1289 1289
 		$prepop[ __( 'Satisfaction', 'formidable' ) ] = array(
1290
-            __( 'Very Satisfied', 'formidable' ), __( 'Satisfied', 'formidable' ), __( 'Neutral', 'formidable' ),
1291
-            __( 'Unsatisfied', 'formidable' ), __( 'Very Unsatisfied', 'formidable' ), __( 'N/A', 'formidable' ),
1292
-        );
1290
+			__( 'Very Satisfied', 'formidable' ), __( 'Satisfied', 'formidable' ), __( 'Neutral', 'formidable' ),
1291
+			__( 'Unsatisfied', 'formidable' ), __( 'Very Unsatisfied', 'formidable' ), __( 'N/A', 'formidable' ),
1292
+		);
1293 1293
 
1294 1294
 		$prepop[ __( 'Importance', 'formidable' ) ] = array(
1295
-            __( 'Very Important', 'formidable' ), __( 'Important', 'formidable' ), __( 'Neutral', 'formidable' ),
1296
-            __( 'Somewhat Important', 'formidable' ), __( 'Not at all Important', 'formidable' ), __( 'N/A', 'formidable' ),
1297
-        );
1295
+			__( 'Very Important', 'formidable' ), __( 'Important', 'formidable' ), __( 'Neutral', 'formidable' ),
1296
+			__( 'Somewhat Important', 'formidable' ), __( 'Not at all Important', 'formidable' ), __( 'N/A', 'formidable' ),
1297
+		);
1298 1298
 
1299 1299
 		$prepop[ __( 'Agreement', 'formidable' ) ] = array(
1300
-            __( 'Strongly Agree', 'formidable' ), __( 'Agree', 'formidable' ), __( 'Neutral', 'formidable' ),
1301
-            __( 'Disagree', 'formidable' ), __( 'Strongly Disagree', 'formidable' ), __( 'N/A', 'formidable' ),
1302
-        );
1300
+			__( 'Strongly Agree', 'formidable' ), __( 'Agree', 'formidable' ), __( 'Neutral', 'formidable' ),
1301
+			__( 'Disagree', 'formidable' ), __( 'Strongly Disagree', 'formidable' ), __( 'N/A', 'formidable' ),
1302
+		);
1303 1303
 
1304 1304
 		$prepop = apply_filters( 'frm_bulk_field_choices', $prepop );
1305
-    }
1305
+	}
1306 1306
 
1307 1307
 	/**
1308 1308
 	 * Display a field value selector
@@ -1312,10 +1312,10 @@  discard block
 block discarded – undo
1312 1312
 	 * @param int $selector_field_id
1313 1313
 	 * @param array $selector_args
1314 1314
 	 */
1315
-    public static function display_field_value_selector( $selector_field_id, $selector_args ) {
1316
-	    $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
1317
-	    $field_value_selector->display();
1318
-    }
1315
+	public static function display_field_value_selector( $selector_field_id, $selector_args ) {
1316
+		$field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
1317
+		$field_value_selector->display();
1318
+	}
1319 1319
 
1320 1320
 	/**
1321 1321
 	 * Convert a field object to a flat array
@@ -1368,10 +1368,10 @@  discard block
 block discarded – undo
1368 1368
 		return FrmField::is_required( $field );
1369 1369
 	}
1370 1370
 
1371
-    public static function maybe_get_field( &$field ) {
1371
+	public static function maybe_get_field( &$field ) {
1372 1372
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmField::maybe_get_field' );
1373 1373
 		FrmField::maybe_get_field( $field );
1374
-    }
1374
+	}
1375 1375
 
1376 1376
 	public static function dropdown_categories( $args ) {
1377 1377
 		_deprecated_function( __FUNCTION__, '2.02.07', 'FrmProPost::get_category_dropdown' );
Please login to merge, or discard this patch.