Completed
Push — master ( 4a11e4...de9f07 )
by Stephanie
03:38
created
classes/models/FrmEntry.php 2 patches
Indentation   +377 added lines, -377 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,46 +125,46 @@  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;
137
-        $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
138
-        $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
139
-        $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
135
+		$new_values['name'] = $values->name;
136
+		$new_values['is_draft'] = $values->is_draft;
137
+		$new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
138
+		$new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
139
+		$new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
140 140
 
141 141
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
142
-        if ( ! $query_results ) {
143
-            return false;
144
-        }
142
+		if ( ! $query_results ) {
143
+			return false;
144
+		}
145 145
 
146
-        $entry_id = $wpdb->insert_id;
146
+		$entry_id = $wpdb->insert_id;
147 147
 
148
-        global $frm_vars;
149
-        if ( ! isset($frm_vars['saved_entries']) ) {
150
-            $frm_vars['saved_entries'] = array();
151
-        }
152
-        $frm_vars['saved_entries'][] = (int) $entry_id;
148
+		global $frm_vars;
149
+		if ( ! isset($frm_vars['saved_entries']) ) {
150
+			$frm_vars['saved_entries'] = array();
151
+		}
152
+		$frm_vars['saved_entries'][] = (int) $entry_id;
153 153
 
154
-        FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
154
+		FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
155 155
 		self::clear_cache();
156 156
 
157 157
 		do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
158
-        return $entry_id;
159
-    }
158
+		return $entry_id;
159
+	}
160 160
 
161 161
 	/**
162
-	* Update an entry (not via XML)
163
-	*
164
-	* @param int $id
165
-	* @param array $values
166
-	* @return boolean|int $update_results
167
-	*/
162
+	 * Update an entry (not via XML)
163
+	 *
164
+	 * @param int $id
165
+	 * @param array $values
166
+	 * @return boolean|int $update_results
167
+	 */
168 168
 	public static function update( $id, $values ) {
169 169
 		$update_results = self::update_entry( $id, $values, 'standard' );
170 170
 
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
 	}
173 173
 
174 174
 	/**
175
-	* Update an entry with some differences depending on the update type
176
-	*
177
-	* @since 2.0.16
178
-	*
179
-	* @param int $id
180
-	* @param array $values
181
-	* @return boolean|int $query_results
182
-	*/
175
+	 * Update an entry with some differences depending on the update type
176
+	 *
177
+	 * @since 2.0.16
178
+	 *
179
+	 * @param int $id
180
+	 * @param array $values
181
+	 * @return boolean|int $query_results
182
+	 */
183 183
 	private static function update_entry( $id, $values, $update_type ) {
184 184
 		global $wpdb;
185 185
 
@@ -198,34 +198,34 @@  discard block
 block discarded – undo
198 198
 	}
199 199
 
200 200
 	public static function &destroy( $id ) {
201
-        global $wpdb;
202
-        $id = (int) $id;
201
+		global $wpdb;
202
+		$id = (int) $id;
203 203
 
204 204
 		$entry = self::getOne( $id );
205
-        if ( ! $entry ) {
206
-            $result = false;
207
-            return $result;
208
-        }
205
+		if ( ! $entry ) {
206
+			$result = false;
207
+			return $result;
208
+		}
209 209
 
210
-        do_action('frm_before_destroy_entry', $id, $entry);
210
+		do_action('frm_before_destroy_entry', $id, $entry);
211 211
 
212 212
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
213 213
 		$result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
214 214
 
215 215
 		self::clear_cache();
216 216
 
217
-        return $result;
218
-    }
217
+		return $result;
218
+	}
219 219
 
220 220
 	public static function &update_form( $id, $value, $form_id ) {
221
-        global $wpdb;
222
-        $form_id = isset($value) ? $form_id : null;
221
+		global $wpdb;
222
+		$form_id = isset($value) ? $form_id : null;
223 223
 		$result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
224 224
 		if ( $result ) {
225 225
 			self::clear_cache();
226 226
 		}
227
-        return $result;
228
-    }
227
+		return $result;
228
+	}
229 229
 
230 230
 	/**
231 231
 	 * Clear entry caching
@@ -261,161 +261,161 @@  discard block
 block discarded – undo
261 261
 	}
262 262
 
263 263
 	public static function getOne( $id, $meta = false ) {
264
-        global $wpdb;
264
+		global $wpdb;
265 265
 
266
-        $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
266
+		$query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
267 267
                   LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
268 268
 
269
-        $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
270
-        $query_args = array( $id );
271
-        $query = $wpdb->prepare( $query, $query_args );
269
+		$query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
270
+		$query_args = array( $id );
271
+		$query = $wpdb->prepare( $query, $query_args );
272 272
 
273
-        if ( ! $meta ) {
273
+		if ( ! $meta ) {
274 274
 			$entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
275
-            return stripslashes_deep($entry);
276
-        }
275
+			return stripslashes_deep($entry);
276
+		}
277 277
 
278
-        $entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
279
-        if ( $entry !== false ) {
280
-            return stripslashes_deep($entry);
281
-        }
278
+		$entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
279
+		if ( $entry !== false ) {
280
+			return stripslashes_deep($entry);
281
+		}
282 282
 
283
-        $entry = $wpdb->get_row( $query );
284
-        $entry = self::get_meta($entry);
283
+		$entry = $wpdb->get_row( $query );
284
+		$entry = self::get_meta($entry);
285 285
 
286
-        return stripslashes_deep($entry);
287
-    }
286
+		return stripslashes_deep($entry);
287
+	}
288 288
 
289 289
 	public static function get_meta( $entry ) {
290
-        if ( ! $entry ) {
291
-            return $entry;
292
-        }
290
+		if ( ! $entry ) {
291
+			return $entry;
292
+		}
293 293
 
294
-        global $wpdb;
294
+		global $wpdb;
295 295
 		$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' );
296 296
 
297
-        $entry->metas = array();
297
+		$entry->metas = array();
298 298
 
299 299
 		$include_key = apply_filters( 'frm_include_meta_keys', false );
300
-        foreach ( $metas as $meta_val ) {
301
-            if ( $meta_val->item_id == $entry->id ) {
300
+		foreach ( $metas as $meta_val ) {
301
+			if ( $meta_val->item_id == $entry->id ) {
302 302
 				$entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
303 303
 				if ( $include_key ) {
304 304
 					$entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
305 305
 				}
306
-                 continue;
307
-            }
306
+				 continue;
307
+			}
308 308
 
309
-            // include sub entries in an array
309
+			// include sub entries in an array
310 310
 			if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
311 311
 				$entry->metas[ $meta_val->field_id ] = array();
312
-            }
312
+			}
313 313
 
314 314
 			$entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
315 315
 
316
-            unset($meta_val);
317
-        }
318
-        unset($metas);
316
+			unset($meta_val);
317
+		}
318
+		unset($metas);
319 319
 
320
-        wp_cache_set( $entry->id, $entry, 'frm_entry');
320
+		wp_cache_set( $entry->id, $entry, 'frm_entry');
321 321
 
322
-        return $entry;
323
-    }
322
+		return $entry;
323
+	}
324 324
 
325
-    /**
326
-     * @param string $id
327
-     */
325
+	/**
326
+	 * @param string $id
327
+	 */
328 328
 	public static function &exists( $id ) {
329
-        global $wpdb;
330
-
331
-        if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
332
-            $exists = true;
333
-            return $exists;
334
-        }
335
-
336
-        if ( is_numeric($id) ) {
337
-            $where = array( 'id' => $id );
338
-        } else {
339
-            $where = array( 'item_key' => $id );
340
-        }
329
+		global $wpdb;
330
+
331
+		if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
332
+			$exists = true;
333
+			return $exists;
334
+		}
335
+
336
+		if ( is_numeric($id) ) {
337
+			$where = array( 'id' => $id );
338
+		} else {
339
+			$where = array( 'item_key' => $id );
340
+		}
341 341
 		$id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
342 342
 
343
-        $exists = ($id && $id > 0) ? true : false;
344
-        return $exists;
345
-    }
343
+		$exists = ($id && $id > 0) ? true : false;
344
+		return $exists;
345
+	}
346 346
 
347
-    public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
347
+	public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
348 348
 		global $wpdb;
349 349
 
350
-        $limit = FrmAppHelper::esc_limit($limit);
350
+		$limit = FrmAppHelper::esc_limit($limit);
351 351
 
352
-        $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
353
-        $entries = wp_cache_get($cache_key, 'frm_entry');
352
+		$cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
353
+		$entries = wp_cache_get($cache_key, 'frm_entry');
354 354
 
355
-        if ( false === $entries ) {
356
-            $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';
355
+		if ( false === $entries ) {
356
+			$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 357
 			$table = $wpdb->prefix . 'frm_items it ';
358 358
 
359
-            if ( $inc_form ) {
360
-                $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
361
-                $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
362
-            }
359
+			if ( $inc_form ) {
360
+				$fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
361
+				$table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
362
+			}
363 363
 
364
-            if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
365
-    		    // sort by a requested field
366
-                $field_id = (int) $order_matches[1];
364
+			if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
365
+				// sort by a requested field
366
+				$field_id = (int) $order_matches[1];
367 367
 				$fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id;
368 368
 				unset( $order_matches, $field_id );
369
-		    }
369
+			}
370 370
 
371 371
 			// prepare the query
372 372
 			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
373 373
 
374
-            $entries = $wpdb->get_results($query, OBJECT_K);
375
-            unset($query);
374
+			$entries = $wpdb->get_results($query, OBJECT_K);
375
+			unset($query);
376 376
 
377 377
 			if ( ! FrmAppHelper::prevent_caching() ) {
378 378
 				wp_cache_set( $cache_key, $entries, 'frm_entry', 300 );
379 379
 			}
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   +67 added lines, -67 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
 
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
         $new_values['name'] = $values->name;
136 136
         $new_values['is_draft'] = $values->is_draft;
137 137
         $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
138
-        $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
139
-        $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
138
+        $new_values['form_id'] = $values->form_id ? (int) $values->form_id : null;
139
+        $new_values['created_at'] = $new_values['updated_at'] = current_time( 'mysql', 1 );
140 140
 
141 141
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
142 142
         if ( ! $query_results ) {
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
         $entry_id = $wpdb->insert_id;
147 147
 
148 148
         global $frm_vars;
149
-        if ( ! isset($frm_vars['saved_entries']) ) {
149
+        if ( ! isset( $frm_vars['saved_entries'] ) ) {
150 150
             $frm_vars['saved_entries'] = array();
151 151
         }
152 152
         $frm_vars['saved_entries'][] = (int) $entry_id;
153 153
 
154
-        FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
154
+        FrmEntryMeta::duplicate_entry_metas( $id, $entry_id );
155 155
 		self::clear_cache();
156 156
 
157 157
 		do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 
191 191
 		$new_values = self::package_entry_to_update( $id, $values );
192 192
 
193
-		$query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact('id') );
193
+		$query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact( 'id' ) );
194 194
 
195 195
 		self::after_update_entry( $query_results, $id, $values, $new_values );
196 196
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
             return $result;
208 208
         }
209 209
 
210
-        do_action('frm_before_destroy_entry', $id, $entry);
210
+        do_action( 'frm_before_destroy_entry', $id, $entry );
211 211
 
212 212
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
213 213
 		$result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 
220 220
 	public static function &update_form( $id, $value, $form_id ) {
221 221
         global $wpdb;
222
-        $form_id = isset($value) ? $form_id : null;
222
+        $form_id = isset( $value ) ? $form_id : null;
223 223
 		$result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
224 224
 		if ( $result ) {
225 225
 			self::clear_cache();
@@ -266,24 +266,24 @@  discard block
 block discarded – undo
266 266
         $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
267 267
                   LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
268 268
 
269
-        $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
269
+        $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
270 270
         $query_args = array( $id );
271 271
         $query = $wpdb->prepare( $query, $query_args );
272 272
 
273 273
         if ( ! $meta ) {
274 274
 			$entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
275
-            return stripslashes_deep($entry);
275
+            return stripslashes_deep( $entry );
276 276
         }
277 277
 
278 278
         $entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
279 279
         if ( $entry !== false ) {
280
-            return stripslashes_deep($entry);
280
+            return stripslashes_deep( $entry );
281 281
         }
282 282
 
283 283
         $entry = $wpdb->get_row( $query );
284
-        $entry = self::get_meta($entry);
284
+        $entry = self::get_meta( $entry );
285 285
 
286
-        return stripslashes_deep($entry);
286
+        return stripslashes_deep( $entry );
287 287
     }
288 288
 
289 289
 	public static function get_meta( $entry ) {
@@ -299,25 +299,25 @@  discard block
 block discarded – undo
299 299
 		$include_key = apply_filters( 'frm_include_meta_keys', false );
300 300
         foreach ( $metas as $meta_val ) {
301 301
             if ( $meta_val->item_id == $entry->id ) {
302
-				$entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
302
+				$entry->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value );
303 303
 				if ( $include_key ) {
304
-					$entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
304
+					$entry->metas[$meta_val->field_key] = $entry->metas[$meta_val->field_id];
305 305
 				}
306 306
                  continue;
307 307
             }
308 308
 
309 309
             // include sub entries in an array
310
-			if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
311
-				$entry->metas[ $meta_val->field_id ] = array();
310
+			if ( ! isset( $entry_metas[$meta_val->field_id] ) ) {
311
+				$entry->metas[$meta_val->field_id] = array();
312 312
             }
313 313
 
314
-			$entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
314
+			$entry->metas[$meta_val->field_id][] = maybe_unserialize( $meta_val->meta_value );
315 315
 
316
-            unset($meta_val);
316
+            unset( $meta_val );
317 317
         }
318
-        unset($metas);
318
+        unset( $metas );
319 319
 
320
-        wp_cache_set( $entry->id, $entry, 'frm_entry');
320
+        wp_cache_set( $entry->id, $entry, 'frm_entry' );
321 321
 
322 322
         return $entry;
323 323
     }
@@ -333,24 +333,24 @@  discard block
 block discarded – undo
333 333
             return $exists;
334 334
         }
335 335
 
336
-        if ( is_numeric($id) ) {
336
+        if ( is_numeric( $id ) ) {
337 337
             $where = array( 'id' => $id );
338 338
         } else {
339 339
             $where = array( 'item_key' => $id );
340 340
         }
341 341
 		$id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
342 342
 
343
-        $exists = ($id && $id > 0) ? true : false;
343
+        $exists = ( $id && $id > 0 ) ? true : false;
344 344
         return $exists;
345 345
     }
346 346
 
347 347
     public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
348 348
 		global $wpdb;
349 349
 
350
-        $limit = FrmAppHelper::esc_limit($limit);
350
+        $limit = FrmAppHelper::esc_limit( $limit );
351 351
 
352
-        $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
353
-        $entries = wp_cache_get($cache_key, 'frm_entry');
352
+        $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form;
353
+        $entries = wp_cache_get( $cache_key, 'frm_entry' );
354 354
 
355 355
         if ( false === $entries ) {
356 356
             $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';
@@ -369,10 +369,10 @@  discard block
 block discarded – undo
369 369
 		    }
370 370
 
371 371
 			// prepare the query
372
-			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
372
+			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
373 373
 
374
-            $entries = $wpdb->get_results($query, OBJECT_K);
375
-            unset($query);
374
+            $entries = $wpdb->get_results( $query, OBJECT_K );
375
+            unset( $query );
376 376
 
377 377
 			if ( ! FrmAppHelper::prevent_caching() ) {
378 378
 				wp_cache_set( $cache_key, $entries, 'frm_entry', 300 );
@@ -380,16 +380,16 @@  discard block
 block discarded – undo
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
 	}
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
 	* @return int
572 572
 	*/
573 573
 	private static function get_is_draft_value( $values ) {
574
-		return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) ||  ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
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
 	/**
@@ -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.