Completed
Push — master ( a3d5d3...b2640f )
by Jamie
03:42
created
classes/models/FrmEntry.php 1 patch
Indentation   +398 added lines, -398 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 = 60;
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
@@ -127,46 +127,46 @@  discard block
 block discarded – undo
127 127
 		return true;
128 128
 	}
129 129
 
130
-    public static function duplicate( $id ) {
131
-        global $wpdb;
130
+	public static function duplicate( $id ) {
131
+		global $wpdb;
132 132
 
133
-        $values = self::getOne( $id );
133
+		$values = self::getOne( $id );
134 134
 
135
-        $new_values = array();
136
-        $new_values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
137
-        $new_values['name'] = $values->name;
138
-        $new_values['is_draft'] = $values->is_draft;
139
-        $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
140
-        $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
141
-        $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
135
+		$new_values = array();
136
+		$new_values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
137
+		$new_values['name'] = $values->name;
138
+		$new_values['is_draft'] = $values->is_draft;
139
+		$new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
140
+		$new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
141
+		$new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
142 142
 
143
-        $query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
144
-        if ( ! $query_results ) {
145
-            return false;
146
-        }
143
+		$query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
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
-        $wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_item_metas WHERE item_id=%d', $id) );
215
-        $result = $wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_items WHERE id=%d', $id) );
214
+		$wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_item_metas WHERE item_id=%d', $id) );
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,161 +263,161 @@  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 ) {
276
-            $entry = FrmAppHelper::check_cache( $id .'_nometa', 'frm_entry', $query, 'get_row' );
277
-            return stripslashes_deep($entry);
278
-        }
275
+		if ( ! $meta ) {
276
+			$entry = FrmAppHelper::check_cache( $id .'_nometa', 'frm_entry', $query, 'get_row' );
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 );
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
-        wp_cache_set( $entry->id, $entry, 'frm_entry');
322
+		wp_cache_set( $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;
331
+		global $wpdb;
332 332
 
333
-        if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
334
-            $exists = true;
335
-            return $exists;
336
-        }
333
+		if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
334
+			$exists = true;
335
+			return $exists;
336
+		}
337 337
 
338
-        if ( is_numeric($id) ) {
339
-            $where = array( 'id' => $id );
340
-        } else {
341
-            $where = array( 'item_key' => $id );
342
-        }
343
-        $id = FrmDb::get_var( $wpdb->prefix .'frm_items', $where );
338
+		if ( is_numeric($id) ) {
339
+			$where = array( 'id' => $id );
340
+		} else {
341
+			$where = array( 'item_key' => $id );
342
+		}
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';
359
-            $table = $wpdb->prefix .'frm_items it ';
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
+			$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
 			if ( ! FrmAppHelper::prevent_caching() ) {
380 380
 				wp_cache_set( $cache_key, $entries, 'frm_entry', 300 );
381 381
 			}
382
-        }
382
+		}
383 383
 
384
-        if ( ! $meta || ! $entries ) {
385
-            return stripslashes_deep($entries);
386
-        }
387
-        unset($meta);
384
+		if ( ! $meta || ! $entries ) {
385
+			return stripslashes_deep($entries);
386
+		}
387
+		unset($meta);
388 388
 
389
-        if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
389
+		if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
390 390
 			$where = array( 'it.form_id' => substr( $where, 11 ) );
391
-        }
391
+		}
392 392
 
393
-        $meta_where = array( 'field_id !' => 0 );
394
-        if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
395
-            $meta_where['fi.form_id'] = $where['it.form_id'];
396
-        } else {
397
-            $meta_where['item_id'] = array_keys( $entries );
398
-        }
393
+		$meta_where = array( 'field_id !' => 0 );
394
+		if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
395
+			$meta_where['fi.form_id'] = $where['it.form_id'];
396
+		} else {
397
+			$meta_where['item_id'] = array_keys( $entries );
398
+		}
399 399
 
400
-        $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' );
400
+		$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' );
401 401
 
402
-        unset( $meta_where );
402
+		unset( $meta_where );
403 403
 
404
-        if ( ! $metas ) {
405
-            return stripslashes_deep($entries);
406
-        }
404
+		if ( ! $metas ) {
405
+			return stripslashes_deep($entries);
406
+		}
407 407
 
408
-        foreach ( $metas as $m_key => $meta_val ) {
409
-            if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
410
-                continue;
411
-            }
408
+		foreach ( $metas as $m_key => $meta_val ) {
409
+			if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
410
+				continue;
411
+			}
412 412
 
413
-            if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
413
+			if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
414 414
 				$entries[ $meta_val->item_id ]->metas = array();
415
-            }
415
+			}
416 416
 
417 417
 			$entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
418 418
 
419
-            unset($m_key, $meta_val);
420
-        }
419
+			unset($m_key, $meta_val);
420
+		}
421 421
 
422 422
 		if ( ! FrmAppHelper::prevent_caching() ) {
423 423
 			foreach ( $entries as $entry ) {
@@ -426,46 +426,46 @@  discard block
 block discarded – undo
426 426
 			}
427 427
 		}
428 428
 
429
-        return stripslashes_deep($entries);
430
-    }
431
-
432
-    // Pagination Methods
433
-    public static function getRecordCount( $where = '' ) {
434
-        global $wpdb;
435
-        $table_join = $wpdb->prefix .'frm_items it LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON it.form_id=fr.id';
436
-
437
-        if ( is_numeric($where) ) {
438
-            $table_join = 'frm_items';
439
-            $where = array( 'form_id' => $where );
440
-        }
441
-
442
-        if ( is_array( $where ) ) {
443
-            $count = FrmDb::get_count( $table_join, $where );
444
-        } else {
445
-            $cache_key = 'count_'. maybe_serialize($where);
446
-            $query = 'SELECT COUNT(*) FROM '. $table_join . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
447
-            $count = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var');
448
-        }
449
-
450
-        return $count;
451
-    }
452
-
453
-    public static function getPageCount( $p_size, $where = '' ) {
454
-        if ( is_numeric($where) ) {
455
-            return ceil( (int) $where / (int) $p_size );
456
-        } else {
457
-            return ceil( (int) self::getRecordCount($where) / (int) $p_size );
458
-        }
459
-    }
460
-
461
-	/**
462
-	* Prepare the data before inserting it into the database
463
-	*
464
-	* @since 2.0.16
465
-	* @param array $values
466
-	* @param string $type
467
-	* @return array $new_values
468
-	*/
429
+		return stripslashes_deep($entries);
430
+	}
431
+
432
+	// Pagination Methods
433
+	public static function getRecordCount( $where = '' ) {
434
+		global $wpdb;
435
+		$table_join = $wpdb->prefix .'frm_items it LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON it.form_id=fr.id';
436
+
437
+		if ( is_numeric($where) ) {
438
+			$table_join = 'frm_items';
439
+			$where = array( 'form_id' => $where );
440
+		}
441
+
442
+		if ( is_array( $where ) ) {
443
+			$count = FrmDb::get_count( $table_join, $where );
444
+		} else {
445
+			$cache_key = 'count_'. maybe_serialize($where);
446
+			$query = 'SELECT COUNT(*) FROM '. $table_join . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
447
+			$count = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var');
448
+		}
449
+
450
+		return $count;
451
+	}
452
+
453
+	public static function getPageCount( $p_size, $where = '' ) {
454
+		if ( is_numeric($where) ) {
455
+			return ceil( (int) $where / (int) $p_size );
456
+		} else {
457
+			return ceil( (int) self::getRecordCount($where) / (int) $p_size );
458
+		}
459
+	}
460
+
461
+	/**
462
+	 * Prepare the data before inserting it into the database
463
+	 *
464
+	 * @since 2.0.16
465
+	 * @param array $values
466
+	 * @param string $type
467
+	 * @return array $new_values
468
+	 */
469 469
 	private static function before_insert_entry_in_database( &$values, $type ) {
470 470
 
471 471
 		self::sanitize_entry_post( $values );
@@ -480,13 +480,13 @@  discard block
 block discarded – undo
480 480
 	}
481 481
 
482 482
 	/**
483
-	* Create an entry and perform after create actions
484
-	*
485
-	* @since 2.0.16
486
-	* @param array $values
487
-	* @param array $new_values
488
-	* @return boolean|int $entry_id
489
-	*/
483
+	 * Create an entry and perform after create actions
484
+	 *
485
+	 * @since 2.0.16
486
+	 * @param array $values
487
+	 * @param array $new_values
488
+	 * @return boolean|int $entry_id
489
+	 */
490 490
 	private static function continue_to_create_entry( $values, $new_values ) {
491 491
 		$entry_id = self::insert_entry_into_database( $new_values );
492 492
 		if ( ! $entry_id ) {
@@ -498,37 +498,37 @@  discard block
 block discarded – undo
498 498
 		return $entry_id;
499 499
 	}
500 500
 
501
-    /**
502
-     * Sanitize the POST values before we use them
503
-     *
504
-     * @since 2.0
505
-     * @param array $values The POST values by reference
506
-     */
507
-    public static function sanitize_entry_post( &$values ) {
508
-        $sanitize_method = array(
509
-            'form_id'       => 'absint',
510
-            'frm_action'    => 'sanitize_title',
511
-            'form_key'      => 'sanitize_title',
512
-            'item_key'      => 'sanitize_title',
513
-            'item_name'     => 'sanitize_text_field',
514
-            'frm_saving_draft' => 'absint',
515
-            'is_draft'      => 'absint',
516
-            'post_id'       => 'absint',
517
-            'parent_item_id' => 'absint',
518
-            'created_at'    => 'sanitize_text_field',
519
-            'updated_at'    => 'sanitize_text_field',
520
-        );
521
-
522
-        FrmAppHelper::sanitize_request( $sanitize_method, $values );
523
-    }
524
-
525
-	/**
526
-	* Prepare the new values for inserting into the database
527
-	*
528
-	* @since 2.0.16
529
-	* @param array $values
530
-	* @return array $new_values
531
-	*/
501
+	/**
502
+	 * Sanitize the POST values before we use them
503
+	 *
504
+	 * @since 2.0
505
+	 * @param array $values The POST values by reference
506
+	 */
507
+	public static function sanitize_entry_post( &$values ) {
508
+		$sanitize_method = array(
509
+			'form_id'       => 'absint',
510
+			'frm_action'    => 'sanitize_title',
511
+			'form_key'      => 'sanitize_title',
512
+			'item_key'      => 'sanitize_title',
513
+			'item_name'     => 'sanitize_text_field',
514
+			'frm_saving_draft' => 'absint',
515
+			'is_draft'      => 'absint',
516
+			'post_id'       => 'absint',
517
+			'parent_item_id' => 'absint',
518
+			'created_at'    => 'sanitize_text_field',
519
+			'updated_at'    => 'sanitize_text_field',
520
+		);
521
+
522
+		FrmAppHelper::sanitize_request( $sanitize_method, $values );
523
+	}
524
+
525
+	/**
526
+	 * Prepare the new values for inserting into the database
527
+	 *
528
+	 * @since 2.0.16
529
+	 * @param array $values
530
+	 * @return array $new_values
531
+	 */
532 532
 	private static function package_entry_data( &$values ) {
533 533
 		global $wpdb;
534 534
 
@@ -561,67 +561,67 @@  discard block
 block discarded – undo
561 561
 	}
562 562
 
563 563
 	/**
564
-	* Get the is_draft value for a new entry
565
-	*
566
-	* @since 2.0.16
567
-	* @param array $values
568
-	* @return int
569
-	*/
564
+	 * Get the is_draft value for a new entry
565
+	 *
566
+	 * @since 2.0.16
567
+	 * @param array $values
568
+	 * @return int
569
+	 */
570 570
 	private static function get_is_draft_value( $values ) {
571 571
 		return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) ||  ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
572 572
 	}
573 573
 
574 574
 	/**
575
-	* Get the form_id value for a new entry
576
-	*
577
-	* @since 2.0.16
578
-	* @param array $values
579
-	* @return int|null
580
-	*/
575
+	 * Get the form_id value for a new entry
576
+	 *
577
+	 * @since 2.0.16
578
+	 * @param array $values
579
+	 * @return int|null
580
+	 */
581 581
 	private static function get_form_id( $values ) {
582 582
 		return isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
583 583
 	}
584 584
 
585 585
 	/**
586
-	* Get the post_id value for a new entry
587
-	*
588
-	* @since 2.0.16
589
-	* @param array $values
590
-	* @return int
591
-	*/
586
+	 * Get the post_id value for a new entry
587
+	 *
588
+	 * @since 2.0.16
589
+	 * @param array $values
590
+	 * @return int
591
+	 */
592 592
 	private static function get_post_id( $values ) {
593 593
 		return isset( $values['post_id'] ) ? (int) $values['post_id']: 0;
594 594
 	}
595 595
 
596 596
 	/**
597
-	* Get the parent_item_id value for a new entry
598
-	*
599
-	* @since 2.0.16
600
-	* @param array $values
601
-	* @return int
602
-	*/
597
+	 * Get the parent_item_id value for a new entry
598
+	 *
599
+	 * @since 2.0.16
600
+	 * @param array $values
601
+	 * @return int
602
+	 */
603 603
 	private static function get_parent_item_id( $values ) {
604 604
 		return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id']: 0;
605 605
 	}
606 606
 
607 607
 	/**
608
-	* Get the created_at value for a new entry
609
-	*
610
-	* @since 2.0.16
611
-	* @param array $values
612
-	* @return string
613
-	*/
608
+	 * Get the created_at value for a new entry
609
+	 *
610
+	 * @since 2.0.16
611
+	 * @param array $values
612
+	 * @return string
613
+	 */
614 614
 	private static function get_created_at( $values ) {
615 615
 		return isset( $values['created_at'] ) ? $values['created_at']: current_time('mysql', 1);
616 616
 	}
617 617
 
618 618
 	/**
619
-	* Get the updated_at value for a new entry
620
-	*
621
-	* @since 2.0.16
622
-	* @param array $values
623
-	* @return string
624
-	*/
619
+	 * Get the updated_at value for a new entry
620
+	 *
621
+	 * @since 2.0.16
622
+	 * @param array $values
623
+	 * @return string
624
+	 */
625 625
 	private static function get_updated_at( $values ) {
626 626
 		if ( isset( $values['updated_at'] ) ) {
627 627
 			$updated_at = $values['updated_at'];
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
 	}
634 634
 
635 635
 	/**
636
-	* Get the description value for a new entry
637
-	*
638
-	* @since 2.0.16
639
-	* @param array $values
640
-	* @return string
641
-	*/
636
+	 * Get the description value for a new entry
637
+	 *
638
+	 * @since 2.0.16
639
+	 * @param array $values
640
+	 * @return string
641
+	 */
642 642
 	private static function get_entry_description( $values ) {
643 643
 		if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
644 644
 			$description = maybe_serialize( $values['description'] );
@@ -653,12 +653,12 @@  discard block
 block discarded – undo
653 653
 	}
654 654
 
655 655
 	/**
656
-	* Get the user_id value for a new entry
657
-	*
658
-	* @since 2.0.16
659
-	* @param array $values
660
-	* @return int
661
-	*/
656
+	 * Get the user_id value for a new entry
657
+	 *
658
+	 * @since 2.0.16
659
+	 * @param array $values
660
+	 * @return int
661
+	 */
662 662
 	private static function get_entry_user_id( $values ) {
663 663
 		if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) {
664 664
 			$user_id = $values['frm_user_id'];
@@ -671,12 +671,12 @@  discard block
 block discarded – undo
671 671
 	}
672 672
 
673 673
 	/**
674
-	* Insert new entry into the database
675
-	*
676
-	* @since 2.0.16
677
-	* @param array $new_values
678
-	* @return int | boolean $entry_id
679
-	*/
674
+	 * Insert new entry into the database
675
+	 *
676
+	 * @since 2.0.16
677
+	 * @param array $new_values
678
+	 * @return int | boolean $entry_id
679
+	 */
680 680
 	private static function insert_entry_into_database( $new_values ) {
681 681
 		global $wpdb;
682 682
 
@@ -692,11 +692,11 @@  discard block
 block discarded – undo
692 692
 	}
693 693
 
694 694
 	/**
695
-	* Add the new entry to global $frm_vars
696
-	*
697
-	* @since 2.0.16
698
-	* @param int $entry_id
699
-	*/
695
+	 * Add the new entry to global $frm_vars
696
+	 *
697
+	 * @since 2.0.16
698
+	 * @param int $entry_id
699
+	 */
700 700
 	private static function add_new_entry_to_frm_vars( $entry_id ) {
701 701
 		global $frm_vars;
702 702
 
@@ -708,12 +708,12 @@  discard block
 block discarded – undo
708 708
 	}
709 709
 
710 710
 	/**
711
-	* Add entry metas, if there are any
712
-	*
713
-	* @since 2.0.16
714
-	* @param array $values
715
-	* @param int $entry_id
716
-	*/
711
+	 * Add entry metas, if there are any
712
+	 *
713
+	 * @since 2.0.16
714
+	 * @param array $values
715
+	 * @param int $entry_id
716
+	 */
717 717
 	private static function maybe_add_entry_metas( $values, $entry_id ) {
718 718
 		if ( isset($values['item_meta']) ) {
719 719
 			FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
@@ -721,12 +721,12 @@  discard block
 block discarded – undo
721 721
 	}
722 722
 
723 723
 	/**
724
-	* Trigger frm_after_create_entry hooks
725
-	*
726
-	* @since 2.0.16
727
-	* @param int $entry_id
728
-	* @param array $new_values
729
-	*/
724
+	 * Trigger frm_after_create_entry hooks
725
+	 *
726
+	 * @since 2.0.16
727
+	 * @param int $entry_id
728
+	 * @param array $new_values
729
+	 */
730 730
 	private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
731 731
 		// this is a child entry
732 732
 		$is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
@@ -736,13 +736,13 @@  discard block
 block discarded – undo
736 736
 	}
737 737
 
738 738
 	/**
739
-	* Actions to perform immediately after an entry is inserted in the frm_items database
740
-	*
741
-	* @since 2.0.16
742
-	* @param array $values
743
-	* @param array $new_values
744
-	* @param int $entry_id
745
-	*/
739
+	 * Actions to perform immediately after an entry is inserted in the frm_items database
740
+	 *
741
+	 * @since 2.0.16
742
+	 * @param array $values
743
+	 * @param array $new_values
744
+	 * @param int $entry_id
745
+	 */
746 746
 	private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
747 747
 
748 748
 		self::add_new_entry_to_frm_vars( $entry_id );
@@ -755,14 +755,14 @@  discard block
 block discarded – undo
755 755
 	}
756 756
 
757 757
 	/**
758
-	* Perform some actions right before updating an entry
759
-	*
760
-	* @since 2.0.16
761
-	* @param int $id
762
-	* @param array $values
763
-	* @param string $update_type
764
-	* @return boolean $update
765
-	*/
758
+	 * Perform some actions right before updating an entry
759
+	 *
760
+	 * @since 2.0.16
761
+	 * @param int $id
762
+	 * @param array $values
763
+	 * @param string $update_type
764
+	 * @return boolean $update
765
+	 */
766 766
 	private static function before_update_entry( $id, &$values, $update_type ) {
767 767
 		$update = true;
768 768
 
@@ -780,13 +780,13 @@  discard block
 block discarded – undo
780 780
 	}
781 781
 
782 782
 	/**
783
-	* Package the entry data for updating
784
-	*
785
-	* @since 2.0.16
786
-	* @param int $id
787
-	* @param array $values
788
-	* @return array $new_values
789
-	*/
783
+	 * Package the entry data for updating
784
+	 *
785
+	 * @since 2.0.16
786
+	 * @param int $id
787
+	 * @param array $values
788
+	 * @return array $new_values
789
+	 */
790 790
 	private static function package_entry_to_update( $id, $values ) {
791 791
 		global $wpdb;
792 792
 
@@ -820,14 +820,14 @@  discard block
 block discarded – undo
820 820
 	}
821 821
 
822 822
 	/**
823
-	* Perform some actions right after updating an entry
824
-	*
825
-	* @since 2.0.16
826
-	* @param boolean|int $query_results
827
-	* @param int $id
828
-	* @param array $values
829
-	* @param array $new_values
830
-	*/
823
+	 * Perform some actions right after updating an entry
824
+	 *
825
+	 * @since 2.0.16
826
+	 * @param boolean|int $query_results
827
+	 * @param int $id
828
+	 * @param array $values
829
+	 * @param array $new_values
830
+	 */
831 831
 	private static function after_update_entry( $query_results, $id, $values, $new_values ) {
832 832
 		if ( $query_results ) {
833 833
 			self::clear_cache();
@@ -849,13 +849,13 @@  discard block
 block discarded – undo
849 849
 	}
850 850
 
851 851
 	/**
852
-	* Create entry from an XML import
853
-	* Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
854
-	*
855
-	* @since 2.0.16
856
-	* @param array $values
857
-	* @return int | boolean $entry_id
858
-	*/
852
+	 * Create entry from an XML import
853
+	 * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
854
+	 *
855
+	 * @since 2.0.16
856
+	 * @param array $values
857
+	 * @return int | boolean $entry_id
858
+	 */
859 859
 	public static function create_entry_from_xml( $values ) {
860 860
 		$entry_id = self::create_entry( $values, 'xml' );
861 861
 
@@ -863,28 +863,28 @@  discard block
 block discarded – undo
863 863
 	}
864 864
 
865 865
 	/**
866
-	* Update entry from an XML import
867
-	* Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
868
-	*
869
-	* @since 2.0.16
870
-	* @param int $id
871
-	* @param array $values
872
-	* @return int | boolean $updated
873
-	*/
866
+	 * Update entry from an XML import
867
+	 * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
868
+	 *
869
+	 * @since 2.0.16
870
+	 * @param int $id
871
+	 * @param array $values
872
+	 * @return int | boolean $updated
873
+	 */
874 874
 	public static function update_entry_from_xml( $id, $values ) {
875 875
 		$updated = self::update_entry( $id, $values, 'xml' );
876 876
 
877 877
 		return $updated;
878 878
 	}
879 879
 
880
-    /**
881
-     * @param string $key
882
-     * @return int entry_id
883
-     */
880
+	/**
881
+	 * @param string $key
882
+	 * @return int entry_id
883
+	 */
884 884
 	public static function get_id_by_key( $key ) {
885
-        $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
886
-        return $entry_id;
887
-    }
885
+		$entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
886
+		return $entry_id;
887
+	}
888 888
 
889 889
 	public static function validate( $values, $exclude = false ) {
890 890
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryValidate::validate' );
Please login to merge, or discard this patch.