Completed
Push — master ( e99607...1466b8 )
by Stephanie
03:12
created
classes/models/FrmEntry.php 1 patch
Indentation   +294 added lines, -294 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
 
@@ -49,40 +49,40 @@  discard block
 block discarded – undo
49 49
 			return false;
50 50
 		}
51 51
 
52
-        $check_val = $new_values;
52
+		$check_val = $new_values;
53 53
 		$check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) );
54 54
 
55 55
 		unset( $check_val['created_at'], $check_val['updated_at'] );
56 56
 		unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
57 57
 
58
-        if ( $new_values['item_key'] == $new_values['name'] ) {
58
+		if ( $new_values['item_key'] == $new_values['name'] ) {
59 59
 			unset( $check_val['name'] );
60
-        }
60
+		}
61 61
 
62
-        global $wpdb;
62
+		global $wpdb;
63 63
 		$entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
64 64
 
65 65
 		if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) {
66
-            return false;
67
-        }
66
+			return false;
67
+		}
68 68
 
69
-        $is_duplicate = false;
70
-        foreach ( $entry_exists as $entry_exist ) {
71
-            $is_duplicate = true;
69
+		$is_duplicate = false;
70
+		foreach ( $entry_exists as $entry_exist ) {
71
+			$is_duplicate = true;
72 72
 
73 73
 			// make sure it's a duplicate
74 74
 			$metas = FrmEntryMeta::get_entry_meta_info( $entry_exist );
75
-            $field_metas = array();
76
-            foreach ( $metas as $meta ) {
75
+			$field_metas = array();
76
+			foreach ( $metas as $meta ) {
77 77
 				$field_metas[ $meta->field_id ] = $meta->meta_value;
78
-            }
78
+			}
79 79
 
80
-            // If prev entry is empty and current entry is not, they are not duplicates
81
-            $filtered_vals = array_filter( $values['item_meta'] );
80
+			// If prev entry is empty and current entry is not, they are not duplicates
81
+			$filtered_vals = array_filter( $values['item_meta'] );
82 82
 			$field_metas   = array_filter( $field_metas );
83
-            if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
84
-                return false;
85
-            }
83
+			if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
84
+				return false;
85
+			}
86 86
 
87 87
 			// compare serialized values and not arrays
88 88
 			$new_meta = array_map( 'maybe_serialize', $filtered_vals );
@@ -99,20 +99,20 @@  discard block
 block discarded – undo
99 99
 			}
100 100
 
101 101
 			$diff = array_diff_assoc( $field_metas, $new_meta );
102
-            foreach ( $diff as $field_id => $meta_value ) {
102
+			foreach ( $diff as $field_id => $meta_value ) {
103 103
 				if ( ! empty( $meta_value ) ) {
104
-                    $is_duplicate = false;
105
-                    continue;
106
-                }
107
-            }
104
+					$is_duplicate = false;
105
+					continue;
106
+				}
107
+			}
108 108
 
109
-            if ( $is_duplicate ) {
109
+			if ( $is_duplicate ) {
110 110
 				break;
111
-            }
112
-        }
111
+			}
112
+		}
113 113
 
114
-        return $is_duplicate;
115
-    }
114
+		return $is_duplicate;
115
+	}
116 116
 
117 117
 	/**
118 118
 	 * Determine if an entry needs to be checked as a possible duplicate
@@ -157,32 +157,32 @@  discard block
 block discarded – undo
157 157
 		$new_values['updated_at'] = $new_values['created_at'];
158 158
 
159 159
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
160
-        if ( ! $query_results ) {
161
-            return false;
162
-        }
160
+		if ( ! $query_results ) {
161
+			return false;
162
+		}
163 163
 
164
-        $entry_id = $wpdb->insert_id;
164
+		$entry_id = $wpdb->insert_id;
165 165
 
166
-        global $frm_vars;
166
+		global $frm_vars;
167 167
 		if ( ! isset( $frm_vars['saved_entries'] ) ) {
168
-            $frm_vars['saved_entries'] = array();
169
-        }
170
-        $frm_vars['saved_entries'][] = (int) $entry_id;
168
+			$frm_vars['saved_entries'] = array();
169
+		}
170
+		$frm_vars['saved_entries'][] = (int) $entry_id;
171 171
 
172 172
 		FrmEntryMeta::duplicate_entry_metas( $id, $entry_id );
173 173
 		self::clear_cache();
174 174
 
175 175
 		do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
176
-        return $entry_id;
177
-    }
176
+		return $entry_id;
177
+	}
178 178
 
179 179
 	/**
180
-	* Update an entry (not via XML)
181
-	*
182
-	* @param int $id
183
-	* @param array $values
184
-	* @return boolean|int $update_results
185
-	*/
180
+	 * Update an entry (not via XML)
181
+	 *
182
+	 * @param int $id
183
+	 * @param array $values
184
+	 * @return boolean|int $update_results
185
+	 */
186 186
 	public static function update( $id, $values ) {
187 187
 		$update_results = self::update_entry( $id, $values, 'standard' );
188 188
 
@@ -190,14 +190,14 @@  discard block
 block discarded – undo
190 190
 	}
191 191
 
192 192
 	/**
193
-	* Update an entry with some differences depending on the update type
194
-	*
195
-	* @since 2.0.16
196
-	*
197
-	* @param int $id
198
-	* @param array $values
199
-	* @return boolean|int $query_results
200
-	*/
193
+	 * Update an entry with some differences depending on the update type
194
+	 *
195
+	 * @since 2.0.16
196
+	 *
197
+	 * @param int $id
198
+	 * @param array $values
199
+	 * @return boolean|int $query_results
200
+	 */
201 201
 	private static function update_entry( $id, $values, $update_type ) {
202 202
 		global $wpdb;
203 203
 
@@ -216,14 +216,14 @@  discard block
 block discarded – undo
216 216
 	}
217 217
 
218 218
 	public static function destroy( $id ) {
219
-        global $wpdb;
220
-        $id = (int) $id;
219
+		global $wpdb;
220
+		$id = (int) $id;
221 221
 
222 222
 		$entry = self::getOne( $id );
223
-        if ( ! $entry ) {
224
-            $result = false;
225
-            return $result;
226
-        }
223
+		if ( ! $entry ) {
224
+			$result = false;
225
+			return $result;
226
+		}
227 227
 
228 228
 		do_action( 'frm_before_destroy_entry', $id, $entry );
229 229
 
@@ -232,18 +232,18 @@  discard block
 block discarded – undo
232 232
 
233 233
 		self::clear_cache();
234 234
 
235
-        return $result;
236
-    }
235
+		return $result;
236
+	}
237 237
 
238 238
 	public static function update_form( $id, $value, $form_id ) {
239
-        global $wpdb;
239
+		global $wpdb;
240 240
 		$form_id = isset( $value ) ? $form_id : null;
241 241
 		$result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
242 242
 		if ( $result ) {
243 243
 			self::clear_cache();
244 244
 		}
245
-        return $result;
246
-    }
245
+		return $result;
246
+	}
247 247
 
248 248
 	/**
249 249
 	 * Clear entry caching
@@ -287,19 +287,19 @@  discard block
 block discarded – undo
287 287
 	}
288 288
 
289 289
 	public static function getOne( $id, $meta = false ) {
290
-        global $wpdb;
290
+		global $wpdb;
291 291
 
292
-        $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
292
+		$query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
293 293
                   LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
294 294
 
295 295
 		$query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
296
-        $query_args = array( $id );
297
-        $query = $wpdb->prepare( $query, $query_args ); // WPCS: unprepared SQL ok.
296
+		$query_args = array( $id );
297
+		$query = $wpdb->prepare( $query, $query_args ); // WPCS: unprepared SQL ok.
298 298
 
299
-        if ( ! $meta ) {
299
+		if ( ! $meta ) {
300 300
 			$entry = FrmDb::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
301 301
 			return stripslashes_deep( $entry );
302
-        }
302
+		}
303 303
 
304 304
 		$entry = FrmDb::check_cache( $id, 'frm_entry' );
305 305
 		if ( $entry !== false ) {
@@ -310,14 +310,14 @@  discard block
 block discarded – undo
310 310
 		$entry = self::get_meta( $entry );
311 311
 
312 312
 		return stripslashes_deep( $entry );
313
-    }
313
+	}
314 314
 
315 315
 	public static function get_meta( $entry ) {
316
-        if ( ! $entry ) {
317
-            return $entry;
318
-        }
316
+		if ( ! $entry ) {
317
+			return $entry;
318
+		}
319 319
 
320
-        global $wpdb;
320
+		global $wpdb;
321 321
 		$metas = FrmDb::get_results(
322 322
 			$wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id',
323 323
 			array(
@@ -327,56 +327,56 @@  discard block
 block discarded – undo
327 327
 			'field_id, meta_value, field_key, item_id'
328 328
 		);
329 329
 
330
-        $entry->metas = array();
330
+		$entry->metas = array();
331 331
 
332 332
 		$include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
333
-        foreach ( $metas as $meta_val ) {
334
-            if ( $meta_val->item_id == $entry->id ) {
333
+		foreach ( $metas as $meta_val ) {
334
+			if ( $meta_val->item_id == $entry->id ) {
335 335
 				$entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
336 336
 				if ( $include_key ) {
337 337
 					$entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
338 338
 				}
339
-                 continue;
340
-            }
339
+				 continue;
340
+			}
341 341
 
342
-            // include sub entries in an array
342
+			// include sub entries in an array
343 343
 			if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
344 344
 				$entry->metas[ $meta_val->field_id ] = array();
345
-            }
345
+			}
346 346
 
347 347
 			$entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
348 348
 
349 349
 			unset( $meta_val );
350
-        }
350
+		}
351 351
 		unset( $metas );
352 352
 
353 353
 		FrmDb::set_cache( $entry->id, $entry, 'frm_entry' );
354 354
 
355
-        return $entry;
356
-    }
355
+		return $entry;
356
+	}
357 357
 
358
-    /**
359
-     * @param string $id
360
-     */
358
+	/**
359
+	 * @param string $id
360
+	 */
361 361
 	public static function exists( $id ) {
362
-        global $wpdb;
362
+		global $wpdb;
363 363
 
364
-        if ( FrmDb::check_cache( $id, 'frm_entry' ) ) {
365
-            $exists = true;
366
-            return $exists;
367
-        }
364
+		if ( FrmDb::check_cache( $id, 'frm_entry' ) ) {
365
+			$exists = true;
366
+			return $exists;
367
+		}
368 368
 
369 369
 		if ( is_numeric( $id ) ) {
370
-            $where = array( 'id' => $id );
371
-        } else {
372
-            $where = array( 'item_key' => $id );
373
-        }
370
+			$where = array( 'id' => $id );
371
+		} else {
372
+			$where = array( 'item_key' => $id );
373
+		}
374 374
 		$id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
375 375
 
376 376
 		return ( $id && $id > 0 );
377
-    }
377
+	}
378 378
 
379
-    public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
379
+	public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
380 380
 		global $wpdb;
381 381
 
382 382
 		$limit = FrmDb::esc_limit( $limit );
@@ -384,21 +384,21 @@  discard block
 block discarded – undo
384 384
 		$cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form;
385 385
 		$entries = wp_cache_get( $cache_key, 'frm_entry' );
386 386
 
387
-        if ( false === $entries ) {
388
-            $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';
387
+		if ( false === $entries ) {
388
+			$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';
389 389
 			$table = $wpdb->prefix . 'frm_items it ';
390 390
 
391
-            if ( $inc_form ) {
392
-                $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
393
-                $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
394
-            }
391
+			if ( $inc_form ) {
392
+				$fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
393
+				$table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
394
+			}
395 395
 
396
-            if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
397
-    		    // sort by a requested field
398
-                $field_id = (int) $order_matches[1];
396
+			if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
397
+				// sort by a requested field
398
+				$field_id = (int) $order_matches[1];
399 399
 				$fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id;
400 400
 				unset( $order_matches, $field_id );
401
-		    }
401
+			}
402 402
 
403 403
 			// prepare the query
404 404
 			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
@@ -407,45 +407,45 @@  discard block
 block discarded – undo
407 407
 			unset( $query );
408 408
 
409 409
 			FrmDb::set_cache( $cache_key, $entries, 'frm_entry' );
410
-        }
410
+		}
411 411
 
412
-        if ( ! $meta || ! $entries ) {
412
+		if ( ! $meta || ! $entries ) {
413 413
 			return stripslashes_deep( $entries );
414
-        }
414
+		}
415 415
 		unset( $meta );
416 416
 
417 417
 		if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) {
418 418
 			$where = array( 'it.form_id' => substr( $where, 11 ) );
419
-        }
419
+		}
420 420
 
421
-        $meta_where = array( 'field_id !' => 0 );
421
+		$meta_where = array( 'field_id !' => 0 );
422 422
 		if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) {
423
-            $meta_where['fi.form_id'] = $where['it.form_id'];
424
-        } else {
425
-            $meta_where['item_id'] = array_keys( $entries );
426
-        }
423
+			$meta_where['fi.form_id'] = $where['it.form_id'];
424
+		} else {
425
+			$meta_where['item_id'] = array_keys( $entries );
426
+		}
427 427
 
428
-        $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' );
428
+		$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' );
429 429
 
430
-        unset( $meta_where );
430
+		unset( $meta_where );
431 431
 
432
-        if ( ! $metas ) {
432
+		if ( ! $metas ) {
433 433
 			return stripslashes_deep( $entries );
434
-        }
434
+		}
435 435
 
436
-        foreach ( $metas as $m_key => $meta_val ) {
437
-            if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
438
-                continue;
439
-            }
436
+		foreach ( $metas as $m_key => $meta_val ) {
437
+			if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
438
+				continue;
439
+			}
440 440
 
441
-            if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
441
+			if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
442 442
 				$entries[ $meta_val->item_id ]->metas = array();
443
-            }
443
+			}
444 444
 
445 445
 			$entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
446 446
 
447 447
 			unset( $m_key, $meta_val );
448
-        }
448
+		}
449 449
 
450 450
 		if ( ! FrmAppHelper::prevent_caching() ) {
451 451
 			foreach ( $entries as $entry ) {
@@ -455,30 +455,30 @@  discard block
 block discarded – undo
455 455
 		}
456 456
 
457 457
 		return stripslashes_deep( $entries );
458
-    }
458
+	}
459 459
 
460
-    // Pagination Methods
461
-    public static function getRecordCount( $where = '' ) {
462
-        global $wpdb;
460
+	// Pagination Methods
461
+	public static function getRecordCount( $where = '' ) {
462
+		global $wpdb;
463 463
 		$table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
464 464
 
465 465
 		if ( is_numeric( $where ) ) {
466
-            $table_join = 'frm_items';
467
-            $where = array( 'form_id' => $where );
468
-        }
466
+			$table_join = 'frm_items';
467
+			$where = array( 'form_id' => $where );
468
+		}
469 469
 
470
-        if ( is_array( $where ) ) {
471
-            $count = FrmDb::get_count( $table_join, $where );
472
-        } else {
470
+		if ( is_array( $where ) ) {
471
+			$count = FrmDb::get_count( $table_join, $where );
472
+		} else {
473 473
 			$cache_key = 'count_' . maybe_serialize( $where );
474 474
 			$query = 'SELECT COUNT(*) FROM ' . $table_join . FrmDb::prepend_and_or_where( ' WHERE ', $where );
475 475
 			$count = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_var' );
476
-        }
476
+		}
477 477
 
478
-        return $count;
479
-    }
478
+		return $count;
479
+	}
480 480
 
481
-    public static function getPageCount( $p_size, $where = '' ) {
481
+	public static function getPageCount( $p_size, $where = '' ) {
482 482
 		$p_size = (int) $p_size;
483 483
 		$count = 1;
484 484
 		if ( $p_size ) {
@@ -489,16 +489,16 @@  discard block
 block discarded – undo
489 489
 		}
490 490
 
491 491
 		return $count;
492
-    }
492
+	}
493 493
 
494 494
 	/**
495
-	* Prepare the data before inserting it into the database
496
-	*
497
-	* @since 2.0.16
498
-	* @param array $values
499
-	* @param string $type
500
-	* @return array $new_values
501
-	*/
495
+	 * Prepare the data before inserting it into the database
496
+	 *
497
+	 * @since 2.0.16
498
+	 * @param array $values
499
+	 * @param string $type
500
+	 * @return array $new_values
501
+	 */
502 502
 	private static function before_insert_entry_in_database( &$values, $type ) {
503 503
 
504 504
 		self::sanitize_entry_post( $values );
@@ -513,13 +513,13 @@  discard block
 block discarded – undo
513 513
 	}
514 514
 
515 515
 	/**
516
-	* Create an entry and perform after create actions
517
-	*
518
-	* @since 2.0.16
519
-	* @param array $values
520
-	* @param array $new_values
521
-	* @return boolean|int $entry_id
522
-	*/
516
+	 * Create an entry and perform after create actions
517
+	 *
518
+	 * @since 2.0.16
519
+	 * @param array $values
520
+	 * @param array $new_values
521
+	 * @return boolean|int $entry_id
522
+	 */
523 523
 	private static function continue_to_create_entry( $values, $new_values ) {
524 524
 		$entry_id = self::insert_entry_into_database( $new_values );
525 525
 		if ( ! $entry_id ) {
@@ -531,37 +531,37 @@  discard block
 block discarded – undo
531 531
 		return $entry_id;
532 532
 	}
533 533
 
534
-    /**
535
-     * Sanitize the POST values before we use them
536
-     *
537
-     * @since 2.0
538
-     * @param array $values The POST values by reference
539
-     */
540
-    public static function sanitize_entry_post( &$values ) {
541
-        $sanitize_method = array(
542
-            'form_id'       => 'absint',
543
-            'frm_action'    => 'sanitize_title',
544
-            'form_key'      => 'sanitize_title',
545
-            'item_key'      => 'sanitize_title',
546
-            'item_name'     => 'sanitize_text_field',
547
-            'frm_saving_draft' => 'absint',
548
-            'is_draft'      => 'absint',
549
-            'post_id'       => 'absint',
550
-            'parent_item_id' => 'absint',
551
-            'created_at'    => 'sanitize_text_field',
552
-            'updated_at'    => 'sanitize_text_field',
553
-        );
554
-
555
-        FrmAppHelper::sanitize_request( $sanitize_method, $values );
556
-    }
534
+	/**
535
+	 * Sanitize the POST values before we use them
536
+	 *
537
+	 * @since 2.0
538
+	 * @param array $values The POST values by reference
539
+	 */
540
+	public static function sanitize_entry_post( &$values ) {
541
+		$sanitize_method = array(
542
+			'form_id'       => 'absint',
543
+			'frm_action'    => 'sanitize_title',
544
+			'form_key'      => 'sanitize_title',
545
+			'item_key'      => 'sanitize_title',
546
+			'item_name'     => 'sanitize_text_field',
547
+			'frm_saving_draft' => 'absint',
548
+			'is_draft'      => 'absint',
549
+			'post_id'       => 'absint',
550
+			'parent_item_id' => 'absint',
551
+			'created_at'    => 'sanitize_text_field',
552
+			'updated_at'    => 'sanitize_text_field',
553
+		);
554
+
555
+		FrmAppHelper::sanitize_request( $sanitize_method, $values );
556
+	}
557 557
 
558 558
 	/**
559
-	* Prepare the new values for inserting into the database
560
-	*
561
-	* @since 2.0.16
562
-	* @param array $values
563
-	* @return array $new_values
564
-	*/
559
+	 * Prepare the new values for inserting into the database
560
+	 *
561
+	 * @since 2.0.16
562
+	 * @param array $values
563
+	 * @return array $new_values
564
+	 */
565 565
 	private static function package_entry_data( &$values ) {
566 566
 		global $wpdb;
567 567
 
@@ -614,34 +614,34 @@  discard block
 block discarded – undo
614 614
 	}
615 615
 
616 616
 	/**
617
-	* Get the is_draft value for a new entry
618
-	*
619
-	* @since 2.0.16
620
-	* @param array $values
621
-	* @return int
622
-	*/
617
+	 * Get the is_draft value for a new entry
618
+	 *
619
+	 * @since 2.0.16
620
+	 * @param array $values
621
+	 * @return int
622
+	 */
623 623
 	private static function get_is_draft_value( $values ) {
624 624
 		return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
625 625
 	}
626 626
 
627 627
 	/**
628
-	* Get the created_at value for a new entry
629
-	*
630
-	* @since 2.0.16
631
-	* @param array $values
632
-	* @return string
633
-	*/
628
+	 * Get the created_at value for a new entry
629
+	 *
630
+	 * @since 2.0.16
631
+	 * @param array $values
632
+	 * @return string
633
+	 */
634 634
 	private static function get_created_at( $values ) {
635 635
 		return self::get_entry_value( $values, 'created_at', current_time( 'mysql', 1 ) );
636 636
 	}
637 637
 
638 638
 	/**
639
-	* Get the updated_at value for a new entry
640
-	*
641
-	* @since 2.0.16
642
-	* @param array $values
643
-	* @return string
644
-	*/
639
+	 * Get the updated_at 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_updated_at( $values ) {
646 646
 		if ( isset( $values['updated_at'] ) ) {
647 647
 			$updated_at = $values['updated_at'];
@@ -653,12 +653,12 @@  discard block
 block discarded – undo
653 653
 	}
654 654
 
655 655
 	/**
656
-	* Get the description value for a new entry
657
-	*
658
-	* @since 2.0.16
659
-	* @param array $values
660
-	* @return string
661
-	*/
656
+	 * Get the description value for a new entry
657
+	 *
658
+	 * @since 2.0.16
659
+	 * @param array $values
660
+	 * @return string
661
+	 */
662 662
 	private static function get_entry_description( $values ) {
663 663
 		if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
664 664
 			$description = maybe_serialize( $values['description'] );
@@ -675,12 +675,12 @@  discard block
 block discarded – undo
675 675
 	}
676 676
 
677 677
 	/**
678
-	* Get the user_id value for a new entry
679
-	*
680
-	* @since 2.0.16
681
-	* @param array $values
682
-	* @return int
683
-	*/
678
+	 * Get the user_id value for a new entry
679
+	 *
680
+	 * @since 2.0.16
681
+	 * @param array $values
682
+	 * @return int
683
+	 */
684 684
 	private static function get_entry_user_id( $values ) {
685 685
 		if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) {
686 686
 			$user_id = $values['frm_user_id'];
@@ -693,12 +693,12 @@  discard block
 block discarded – undo
693 693
 	}
694 694
 
695 695
 	/**
696
-	* Insert new entry into the database
697
-	*
698
-	* @since 2.0.16
699
-	* @param array $new_values
700
-	* @return int | boolean $entry_id
701
-	*/
696
+	 * Insert new entry into the database
697
+	 *
698
+	 * @since 2.0.16
699
+	 * @param array $new_values
700
+	 * @return int | boolean $entry_id
701
+	 */
702 702
 	private static function insert_entry_into_database( $new_values ) {
703 703
 		global $wpdb;
704 704
 
@@ -714,11 +714,11 @@  discard block
 block discarded – undo
714 714
 	}
715 715
 
716 716
 	/**
717
-	* Add the new entry to global $frm_vars
718
-	*
719
-	* @since 2.0.16
720
-	* @param int $entry_id
721
-	*/
717
+	 * Add the new entry to global $frm_vars
718
+	 *
719
+	 * @since 2.0.16
720
+	 * @param int $entry_id
721
+	 */
722 722
 	private static function add_new_entry_to_frm_vars( $entry_id ) {
723 723
 		global $frm_vars;
724 724
 
@@ -730,12 +730,12 @@  discard block
 block discarded – undo
730 730
 	}
731 731
 
732 732
 	/**
733
-	* Add entry metas, if there are any
734
-	*
735
-	* @since 2.0.16
736
-	* @param array $values
737
-	* @param int $entry_id
738
-	*/
733
+	 * Add entry metas, if there are any
734
+	 *
735
+	 * @since 2.0.16
736
+	 * @param array $values
737
+	 * @param int $entry_id
738
+	 */
739 739
 	private static function maybe_add_entry_metas( $values, $entry_id ) {
740 740
 		if ( isset( $values['item_meta'] ) ) {
741 741
 			FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
@@ -743,12 +743,12 @@  discard block
 block discarded – undo
743 743
 	}
744 744
 
745 745
 	/**
746
-	* Trigger frm_after_create_entry hooks
747
-	*
748
-	* @since 2.0.16
749
-	* @param int $entry_id
750
-	* @param array $new_values
751
-	*/
746
+	 * Trigger frm_after_create_entry hooks
747
+	 *
748
+	 * @since 2.0.16
749
+	 * @param int $entry_id
750
+	 * @param array $new_values
751
+	 */
752 752
 	private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
753 753
 		// this is a child entry
754 754
 		$is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
@@ -758,13 +758,13 @@  discard block
 block discarded – undo
758 758
 	}
759 759
 
760 760
 	/**
761
-	* Actions to perform immediately after an entry is inserted in the frm_items database
762
-	*
763
-	* @since 2.0.16
764
-	* @param array $values
765
-	* @param array $new_values
766
-	* @param int $entry_id
767
-	*/
761
+	 * Actions to perform immediately after an entry is inserted in the frm_items database
762
+	 *
763
+	 * @since 2.0.16
764
+	 * @param array $values
765
+	 * @param array $new_values
766
+	 * @param int $entry_id
767
+	 */
768 768
 	private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
769 769
 
770 770
 		self::add_new_entry_to_frm_vars( $entry_id );
@@ -777,14 +777,14 @@  discard block
 block discarded – undo
777 777
 	}
778 778
 
779 779
 	/**
780
-	* Perform some actions right before updating an entry
781
-	*
782
-	* @since 2.0.16
783
-	* @param int $id
784
-	* @param array $values
785
-	* @param string $update_type
786
-	* @return boolean $update
787
-	*/
780
+	 * Perform some actions right before updating an entry
781
+	 *
782
+	 * @since 2.0.16
783
+	 * @param int $id
784
+	 * @param array $values
785
+	 * @param string $update_type
786
+	 * @return boolean $update
787
+	 */
788 788
 	private static function before_update_entry( $id, &$values, $update_type ) {
789 789
 		$update = true;
790 790
 
@@ -802,13 +802,13 @@  discard block
 block discarded – undo
802 802
 	}
803 803
 
804 804
 	/**
805
-	* Package the entry data for updating
806
-	*
807
-	* @since 2.0.16
808
-	* @param int $id
809
-	* @param array $values
810
-	* @return array $new_values
811
-	*/
805
+	 * Package the entry data for updating
806
+	 *
807
+	 * @since 2.0.16
808
+	 * @param int $id
809
+	 * @param array $values
810
+	 * @return array $new_values
811
+	 */
812 812
 	private static function package_entry_to_update( $id, $values ) {
813 813
 		global $wpdb;
814 814
 
@@ -842,14 +842,14 @@  discard block
 block discarded – undo
842 842
 	}
843 843
 
844 844
 	/**
845
-	* Perform some actions right after updating an entry
846
-	*
847
-	* @since 2.0.16
848
-	* @param boolean|int $query_results
849
-	* @param int $id
850
-	* @param array $values
851
-	* @param array $new_values
852
-	*/
845
+	 * Perform some actions right after updating an entry
846
+	 *
847
+	 * @since 2.0.16
848
+	 * @param boolean|int $query_results
849
+	 * @param int $id
850
+	 * @param array $values
851
+	 * @param array $new_values
852
+	 */
853 853
 	private static function after_update_entry( $query_results, $id, $values, $new_values ) {
854 854
 		if ( $query_results ) {
855 855
 			self::clear_cache();
@@ -871,13 +871,13 @@  discard block
 block discarded – undo
871 871
 	}
872 872
 
873 873
 	/**
874
-	* Create entry from an XML import
875
-	* Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
876
-	*
877
-	* @since 2.0.16
878
-	* @param array $values
879
-	* @return int | boolean $entry_id
880
-	*/
874
+	 * Create entry from an XML import
875
+	 * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
876
+	 *
877
+	 * @since 2.0.16
878
+	 * @param array $values
879
+	 * @return int | boolean $entry_id
880
+	 */
881 881
 	public static function create_entry_from_xml( $values ) {
882 882
 		$entry_id = self::create_entry( $values, 'xml' );
883 883
 
@@ -885,14 +885,14 @@  discard block
 block discarded – undo
885 885
 	}
886 886
 
887 887
 	/**
888
-	* Update entry from an XML import
889
-	* Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
890
-	*
891
-	* @since 2.0.16
892
-	* @param int $id
893
-	* @param array $values
894
-	* @return int | boolean $updated
895
-	*/
888
+	 * Update entry from an XML import
889
+	 * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
890
+	 *
891
+	 * @since 2.0.16
892
+	 * @param int $id
893
+	 * @param array $values
894
+	 * @return int | boolean $updated
895
+	 */
896 896
 	public static function update_entry_from_xml( $id, $values ) {
897 897
 		$updated = self::update_entry( $id, $values, 'xml' );
898 898
 
Please login to merge, or discard this patch.
classes/models/FrmField.php 1 patch
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -149,41 +149,41 @@  discard block
 block discarded – undo
149 149
 		return apply_filters( 'frm_pro_available_fields', $fields );
150 150
 	}
151 151
 
152
-    public static function create( $values, $return = true ) {
153
-        global $wpdb, $frm_duplicate_ids;
152
+	public static function create( $values, $return = true ) {
153
+		global $wpdb, $frm_duplicate_ids;
154 154
 
155
-        $new_values = array();
155
+		$new_values = array();
156 156
 		$key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name'];
157 157
 		$new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
158 158
 
159 159
 		foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
160 160
 			$new_values[ $col ] = $values[ $col ];
161
-        }
161
+		}
162 162
 
163
-        $new_values['options'] = $values['options'];
163
+		$new_values['options'] = $values['options'];
164 164
 
165 165
 		$new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
166 166
 		$new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0;
167 167
 		$new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
168
-        $new_values['field_options'] = $values['field_options'];
168
+		$new_values['field_options'] = $values['field_options'];
169 169
 		$new_values['created_at'] = current_time( 'mysql', 1 );
170 170
 
171 171
 		if ( isset( $values['id'] ) ) {
172 172
 			$frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
173 173
 			$new_values = apply_filters( 'frm_duplicated_field', $new_values );
174
-        }
174
+		}
175 175
 
176 176
 		self::preserve_format_option_backslashes( $new_values );
177 177
 
178 178
 		foreach ( $new_values as $k => $v ) {
179
-            if ( is_array( $v ) ) {
179
+			if ( is_array( $v ) ) {
180 180
 				$new_values[ $k ] = serialize( $v );
181 181
 			}
182
-            unset( $k, $v );
183
-        }
182
+			unset( $k, $v );
183
+		}
184 184
 
185
-        //if(isset($values['id']) and is_numeric($values['id']))
186
-        //    $new_values['id'] = $values['id'];
185
+		//if(isset($values['id']) and is_numeric($values['id']))
186
+		//    $new_values['id'] = $values['id'];
187 187
 
188 188
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values );
189 189
 		$new_id = 0;
@@ -204,10 +204,10 @@  discard block
 block discarded – undo
204 204
 		} else {
205 205
 			return false;
206 206
 		}
207
-    }
207
+	}
208 208
 
209
-    public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
210
-        global $frm_duplicate_ids;
209
+	public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
210
+		global $frm_duplicate_ids;
211 211
 
212 212
 		$where = array(
213 213
 			array(
@@ -218,14 +218,14 @@  discard block
 block discarded – undo
218 218
 		);
219 219
 		$fields = self::getAll( $where, 'field_order', '', $blog_id );
220 220
 
221
-        foreach ( (array) $fields as $field ) {
221
+		foreach ( (array) $fields as $field ) {
222 222
 			$new_key = $copy_keys ? $field->field_key : '';
223 223
 			if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) {
224 224
 				$new_key = rtrim( $new_key, 2 );
225 225
 			}
226 226
 
227
-            $values = array();
228
-            FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
227
+			$values = array();
228
+			FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
229 229
 
230 230
 			// If this is a repeating section, create new form
231 231
 			if ( self::is_repeating_field( $field ) ) {
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
 			$frm_duplicate_ids[ $field->id ] = $new_id;
257 257
 			$frm_duplicate_ids[ $field->field_key ] = $new_id;
258 258
 			unset( $field );
259
-        }
260
-    }
259
+		}
260
+	}
261 261
 
262 262
 	public static function update( $id, $values ) {
263
-        global $wpdb;
263
+		global $wpdb;
264 264
 
265 265
 		$id = absint( $id );
266 266
 
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
 		}
270 270
 
271 271
 		if ( isset( $values['required'] ) ) {
272
-            $values['required'] = (int) $values['required'];
273
-        }
272
+			$values['required'] = (int) $values['required'];
273
+		}
274 274
 
275 275
 		self::preserve_format_option_backslashes( $values );
276 276
 
@@ -292,41 +292,41 @@  discard block
 block discarded – undo
292 292
 
293 293
 		$query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) );
294 294
 
295
-        $form_id = 0;
295
+		$form_id = 0;
296 296
 		if ( isset( $values['form_id'] ) ) {
297
-            $form_id = absint( $values['form_id'] );
297
+			$form_id = absint( $values['form_id'] );
298 298
 		} else {
299 299
 			$field = self::getOne( $id );
300
-            if ( $field ) {
301
-                $form_id = $field->form_id;
302
-            }
300
+			if ( $field ) {
301
+				$form_id = $field->form_id;
302
+			}
303 303
 			unset( $field );
304
-        }
304
+		}
305 305
 		unset( $values );
306 306
 
307 307
 		if ( $query_results ) {
308
-            wp_cache_delete( $id, 'frm_field' );
309
-            if ( $form_id ) {
310
-                self::delete_form_transient( $form_id );
311
-            }
312
-        }
308
+			wp_cache_delete( $id, 'frm_field' );
309
+			if ( $form_id ) {
310
+				self::delete_form_transient( $form_id );
311
+			}
312
+		}
313 313
 
314
-        return $query_results;
315
-    }
314
+		return $query_results;
315
+	}
316 316
 
317 317
 	/**
318
-	* Keep backslashes in the phone format option
319
-	*
320
-	* @since 2.0.8
321
-	* @param $values array - pass by reference
322
-	*/
318
+	 * Keep backslashes in the phone format option
319
+	 *
320
+	 * @since 2.0.8
321
+	 * @param $values array - pass by reference
322
+	 */
323 323
 	private static function preserve_format_option_backslashes( &$values ) {
324 324
 		if ( isset( $values['field_options']['format'] ) ) {
325 325
 			$values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
326 326
 		}
327 327
 	}
328 328
 
329
-    public static function destroy( $id ) {
329
+	public static function destroy( $id ) {
330 330
 		global $wpdb;
331 331
 
332 332
 		do_action( 'frm_before_destroy_field', $id );
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 
342 342
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
343 343
 		return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
344
-    }
344
+	}
345 345
 
346 346
 	public static function delete_form_transient( $form_id ) {
347 347
 		$form_id = absint( $form_id );
@@ -356,10 +356,10 @@  discard block
 block discarded – undo
356 356
 		FrmDb::cache_delete_group( 'frm_field' );
357 357
 
358 358
 		$form = FrmForm::getOne( $form_id );
359
-        if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
360
-            self::delete_form_transient( $form->parent_form_id );
361
-        }
362
-    }
359
+		if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
360
+			self::delete_form_transient( $form->parent_form_id );
361
+		}
362
+	}
363 363
 
364 364
 	/**
365 365
 	 * If $field is numeric, get the field object
@@ -375,27 +375,27 @@  discard block
 block discarded – undo
375 375
 			return null;
376 376
 		}
377 377
 
378
-        global $wpdb;
378
+		global $wpdb;
379 379
 
380 380
 		$where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s';
381 381
 		$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); // WPCS: unprepared SQL ok.
382 382
 
383
-        $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
383
+		$results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
384 384
 
385 385
 		if ( empty( $results ) ) {
386
-            return $results;
387
-        }
386
+			return $results;
387
+		}
388 388
 
389 389
 		if ( is_numeric( $id ) ) {
390 390
 			FrmDb::set_cache( $results->field_key, $results, 'frm_field' );
391
-        } else if ( $results ) {
391
+		} else if ( $results ) {
392 392
 			FrmDb::set_cache( $results->id, $results, 'frm_field' );
393
-        }
393
+		}
394 394
 
395 395
 		self::prepare_options( $results );
396 396
 
397 397
 		return stripslashes_deep( $results );
398
-    }
398
+	}
399 399
 
400 400
 	/**
401 401
 	 * Get the field type by key or id
@@ -403,26 +403,26 @@  discard block
 block discarded – undo
403 403
 	 * @param int|string The field id or key
404 404
 	 * @param mixed $col The name of the column in the fields database table
405 405
 	 */
406
-    public static function get_type( $id, $col = 'type' ) {
407
-        $field = FrmDb::check_cache( $id, 'frm_field' );
408
-        if ( $field ) {
409
-            $type = $field->{$col};
410
-        } else {
406
+	public static function get_type( $id, $col = 'type' ) {
407
+		$field = FrmDb::check_cache( $id, 'frm_field' );
408
+		if ( $field ) {
409
+			$type = $field->{$col};
410
+		} else {
411 411
 			$where = array(
412 412
 				'or'        => 1,
413 413
 				'id'        => $id,
414 414
 				'field_key' => $id,
415 415
 			);
416 416
 			$type = FrmDb::get_var( 'frm_fields', $where, $col );
417
-        }
417
+		}
418 418
 
419
-        return $type;
420
-    }
419
+		return $type;
420
+	}
421 421
 
422 422
 	public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
423
-        if ( ! $form_id ) {
424
-            return array();
425
-        }
423
+		if ( ! $form_id ) {
424
+			return array();
425
+		}
426 426
 
427 427
 		$results = self::get_fields_from_transients(
428 428
 			$form_id,
@@ -432,30 +432,30 @@  discard block
 block discarded – undo
432 432
 			)
433 433
 		);
434 434
 		if ( ! empty( $results ) ) {
435
-            $fields = array();
436
-            $count = 0;
437
-            foreach ( $results as $result ) {
438
-                if ( $type != $result->type ) {
439
-                    continue;
440
-                }
435
+			$fields = array();
436
+			$count = 0;
437
+			foreach ( $results as $result ) {
438
+				if ( $type != $result->type ) {
439
+					continue;
440
+				}
441 441
 
442 442
 				$fields[ $result->id ] = $result;
443
-                $count++;
444
-                if ( $limit == 1 ) {
445
-                    $fields = $result;
446
-                    break;
447
-                }
443
+				$count++;
444
+				if ( $limit == 1 ) {
445
+					$fields = $result;
446
+					break;
447
+				}
448 448
 
449 449
 				if ( ! empty( $limit ) && $count >= $limit ) {
450
-                    break;
451
-                }
450
+					break;
451
+				}
452 452
 
453 453
 				unset( $result );
454 454
 			}
455 455
 			return stripslashes_deep( $fields );
456
-        }
456
+		}
457 457
 
458
-        self::$use_cache = false;
458
+		self::$use_cache = false;
459 459
 
460 460
 		$where = array(
461 461
 			'fi.form_id' => (int) $form_id,
@@ -463,59 +463,59 @@  discard block
 block discarded – undo
463 463
 		);
464 464
 		self::maybe_include_repeating_fields( $inc_sub, $where );
465 465
 		$results = self::getAll( $where, 'field_order', $limit );
466
-        self::$use_cache = true;
466
+		self::$use_cache = true;
467 467
 		self::include_sub_fields( $results, $inc_sub, $type );
468 468
 
469
-        return $results;
470
-    }
469
+		return $results;
470
+	}
471 471
 
472 472
 	public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
473
-        if ( ! (int) $form_id ) {
474
-            return array();
475
-        }
473
+		if ( ! (int) $form_id ) {
474
+			return array();
475
+		}
476 476
 
477 477
 		$results = self::get_fields_from_transients( $form_id, compact( 'inc_embed', 'inc_repeat' ) );
478 478
 		if ( ! empty( $results ) ) {
479 479
 			if ( empty( $limit ) ) {
480 480
 				return $results;
481
-            }
481
+			}
482 482
 
483
-            $fields = array();
484
-            $count = 0;
485
-            foreach ( $results as $result ) {
483
+			$fields = array();
484
+			$count = 0;
485
+			foreach ( $results as $result ) {
486 486
 				$count++;
487 487
 				$fields[ $result->id ] = $result;
488 488
 				if ( ! empty( $limit ) && $count >= $limit ) {
489
-                    break;
490
-                }
491
-            }
489
+					break;
490
+				}
491
+			}
492 492
 
493 493
 			return $fields;
494
-        }
494
+		}
495 495
 
496
-        self::$use_cache = false;
496
+		self::$use_cache = false;
497 497
 
498 498
 		$where = array( 'fi.form_id' => absint( $form_id ) );
499 499
 		self::maybe_include_repeating_fields( $inc_repeat, $where );
500 500
 		$results = self::getAll( $where, 'field_order', $limit );
501 501
 
502
-        self::$use_cache = true;
502
+		self::$use_cache = true;
503 503
 
504 504
 		self::include_sub_fields( $results, $inc_embed, 'all' );
505 505
 
506 506
 		if ( empty( $limit ) ) {
507 507
 			self::set_field_transient( $results, $form_id, 0, compact( 'inc_embed', 'inc_repeat' ) );
508
-        }
508
+		}
509 509
 
510 510
 		return $results;
511
-    }
511
+	}
512 512
 
513 513
 	/**
514
-	* If repeating fields should be included, adjust $where accordingly
515
-	*
516
-	* @param string $inc_repeat
517
-	* @param array $where - pass by reference
518
-	*/
514
+	 * If repeating fields should be included, adjust $where accordingly
515
+	 *
516
+	 * @param string $inc_repeat
517
+	 * @param array $where - pass by reference
518
+	 */
519 519
 	private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
520 520
 		if ( $inc_repeat == 'include' ) {
521 521
 			$form_id = $where['fi.form_id'];
@@ -530,21 +530,21 @@  discard block
 block discarded – undo
530 530
 
531 531
 	public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) {
532 532
 		if ( 'include' != $inc_embed || empty( $results ) ) {
533
-            return;
534
-        }
533
+			return;
534
+		}
535 535
 
536
-        $form_fields = $results;
536
+		$form_fields = $results;
537 537
 		$index_offset = 1;
538
-        foreach ( $form_fields as $k => $field ) {
538
+		foreach ( $form_fields as $k => $field ) {
539 539
 			if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
540
-                continue;
541
-            }
540
+				continue;
541
+			}
542 542
 
543
-            if ( $type == 'all' ) {
544
-                $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
545
-            } else {
543
+			if ( $type == 'all' ) {
544
+				$sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
545
+			} else {
546 546
 				$sub_fields = self::get_all_types_in_form( $field->form_id, $type );
547
-            }
547
+			}
548 548
 
549 549
 			if ( ! empty( $sub_fields ) ) {
550 550
 				$index = $k + $index_offset;
@@ -552,35 +552,35 @@  discard block
 block discarded – undo
552 552
 				array_splice( $results, $index, 0, $sub_fields );
553 553
 			}
554 554
 			unset( $field, $sub_fields );
555
-        }
556
-    }
555
+		}
556
+	}
557 557
 
558 558
 	public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) {
559 559
 		$cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
560
-        if ( self::$use_cache ) {
561
-            // make sure old cache doesn't get saved as a transient
560
+		if ( self::$use_cache ) {
561
+			// make sure old cache doesn't get saved as a transient
562 562
 			$results = wp_cache_get( $cache_key, 'frm_field' );
563
-            if ( false !== $results ) {
563
+			if ( false !== $results ) {
564 564
 				return stripslashes_deep( $results );
565
-            }
566
-        }
565
+			}
566
+		}
567 567
 
568
-        global $wpdb;
568
+		global $wpdb;
569 569
 
570
-        if ( $blog_id && is_multisite() ) {
571
-            global $wpmuBaseTablePrefix;
572
-            if ( $wpmuBaseTablePrefix ) {
570
+		if ( $blog_id && is_multisite() ) {
571
+			global $wpmuBaseTablePrefix;
572
+			if ( $wpmuBaseTablePrefix ) {
573 573
 				$prefix = $wpmuBaseTablePrefix . $blog_id . '_';
574
-            } else {
575
-                $prefix = $wpdb->get_blog_prefix( $blog_id );
576
-            }
574
+			} else {
575
+				$prefix = $wpdb->get_blog_prefix( $blog_id );
576
+			}
577 577
 
578 578
 			$table_name = $prefix . 'frm_fields';
579 579
 			$form_table_name = $prefix . 'frm_forms';
580 580
 		} else {
581 581
 			$table_name = $wpdb->prefix . 'frm_fields';
582 582
 			$form_table_name = $wpdb->prefix . 'frm_forms';
583
-        }
583
+		}
584 584
 
585 585
 		if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
586 586
 			$order_by = ' ORDER BY ' . $order_by;
@@ -588,8 +588,8 @@  discard block
 block discarded – undo
588 588
 
589 589
 		$limit = FrmDb::esc_limit( $limit );
590 590
 
591
-        $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";
592
-        $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
591
+		$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";
592
+		$query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
593 593
 
594 594
 		if ( is_array( $where ) ) {
595 595
 			$args = array(
@@ -603,8 +603,8 @@  discard block
 block discarded – undo
603 603
 
604 604
 			$function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
605 605
 			$results = $wpdb->$function_name( $query );
606
-        }
607
-        unset( $where );
606
+		}
607
+		unset( $where );
608 608
 
609 609
 		self::format_field_results( $results );
610 610
 
@@ -857,8 +857,8 @@  discard block
 block discarded – undo
857 857
 	}
858 858
 
859 859
 	/**
860
-	* @since 2.0.09
861
-	*/
860
+	 * @since 2.0.09
861
+	 */
862 862
 	public static function is_repeating_field( $field ) {
863 863
 		if ( is_array( $field ) ) {
864 864
 			$is_repeating_field = ( 'divider' == $field['type'] );
Please login to merge, or discard this patch.