Completed
Push — master ( 807d29...7c5184 )
by Stephanie
06:58
created
classes/models/FrmForm.php 1 patch
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-    die( 'You are not allowed to call this page directly.' );
3
+	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
6 6
 class FrmForm {
7 7
 
8
-    /**
9
-     * @return int|boolean id on success or false on failure
10
-     */
11
-    public static function create( $values ) {
12
-        global $wpdb;
8
+	/**
9
+	 * @return int|boolean id on success or false on failure
10
+	 */
11
+	public static function create( $values ) {
12
+		global $wpdb;
13 13
 
14 14
 		$new_values = array(
15 15
 			'form_key'      => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
@@ -34,52 +34,52 @@  discard block
 block discarded – undo
34 34
 		$options = apply_filters( 'frm_form_options_before_update', $options, $values );
35 35
 		$new_values['options'] = serialize( $options );
36 36
 
37
-        //if(isset($values['id']) && is_numeric($values['id']))
38
-        //    $new_values['id'] = $values['id'];
37
+		//if(isset($values['id']) && is_numeric($values['id']))
38
+		//    $new_values['id'] = $values['id'];
39 39
 
40 40
 		$wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
41 41
 
42
-        $id = $wpdb->insert_id;
42
+		$id = $wpdb->insert_id;
43 43
 
44 44
 		// Clear form caching
45 45
 		self::clear_form_cache();
46 46
 
47
-        return $id;
48
-    }
47
+		return $id;
48
+	}
49 49
 
50
-    /**
51
-     * @return int|boolean ID on success or false on failure
52
-     */
53
-    public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
-        global $wpdb;
50
+	/**
51
+	 * @return int|boolean ID on success or false on failure
52
+	 */
53
+	public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
+		global $wpdb;
55 55
 
56
-        $values = self::getOne( $id, $blog_id );
57
-        if ( ! $values ) {
58
-            return false;
59
-        }
56
+		$values = self::getOne( $id, $blog_id );
57
+		if ( ! $values ) {
58
+			return false;
59
+		}
60 60
 
61
-        $new_key = $copy_keys ? $values->form_key : '';
61
+		$new_key = $copy_keys ? $values->form_key : '';
62 62
 
63
-        $new_values = array(
63
+		$new_values = array(
64 64
 			'form_key'      => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ),
65
-            'name'          => $values->name,
66
-            'description'   => $values->description,
67
-            'status'        => $template ? 'published' : 'draft',
68
-            'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
-            'editable'      => $values->editable ? $values->editable : 0,
65
+			'name'          => $values->name,
66
+			'description'   => $values->description,
67
+			'status'        => $template ? 'published' : 'draft',
68
+			'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
+			'editable'      => $values->editable ? $values->editable : 0,
70 70
 			'created_at'    => current_time( 'mysql', 1 ),
71
-            'is_template'   => $template ? 1 : 0,
72
-        );
71
+			'is_template'   => $template ? 1 : 0,
72
+		);
73 73
 
74
-        if ( $blog_id ) {
75
-            $new_values['status'] = 'published';
74
+		if ( $blog_id ) {
75
+			$new_values['status'] = 'published';
76 76
 			$new_options = maybe_unserialize( $values->options );
77 77
 			$new_options['email_to'] = get_option( 'admin_email' );
78
-            $new_options['copy'] = false;
79
-            $new_values['options'] = $new_options;
80
-        } else {
81
-            $new_values['options'] = $values->options;
82
-        }
78
+			$new_options['copy'] = false;
79
+			$new_values['options'] = $new_options;
80
+		} else {
81
+			$new_values['options'] = $values->options;
82
+		}
83 83
 
84 84
 		if ( is_array( $new_values['options'] ) ) {
85 85
 			$new_values['options'] = serialize( $new_values['options'] );
@@ -87,20 +87,20 @@  discard block
 block discarded – undo
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
89 89
 
90
-        if ( $query_results ) {
90
+		if ( $query_results ) {
91 91
 			// Clear form caching
92 92
 			self::clear_form_cache();
93 93
 
94
-            $form_id = $wpdb->insert_id;
94
+			$form_id = $wpdb->insert_id;
95 95
 			FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id );
96 96
 
97
-            // update form settings after fields are created
97
+			// update form settings after fields are created
98 98
 			do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
99
-            return $form_id;
100
-        }
99
+			return $form_id;
100
+		}
101 101
 
102
-        return false;
103
-    }
102
+		return false;
103
+	}
104 104
 
105 105
 	public static function after_duplicate( $form_id, $values ) {
106 106
 		$new_opts = maybe_unserialize( $values['options'] );
@@ -112,48 +112,48 @@  discard block
 block discarded – undo
112 112
 
113 113
 		$new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id );
114 114
 
115
-        if ( $new_opts != $values['options'] ) {
116
-            global $wpdb;
115
+		if ( $new_opts != $values['options'] ) {
116
+			global $wpdb;
117 117
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
118
-        }
119
-    }
118
+		}
119
+	}
120 120
 
121
-    /**
122
-     * @return int|boolean
123
-     */
124
-    public static function update( $id, $values, $create_link = false ) {
125
-        global $wpdb;
121
+	/**
122
+	 * @return int|boolean
123
+	 */
124
+	public static function update( $id, $values, $create_link = false ) {
125
+		global $wpdb;
126 126
 
127
-        if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
128
-            $values['status'] = 'published';
129
-        }
127
+		if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
128
+			$values['status'] = 'published';
129
+		}
130 130
 
131 131
 		if ( isset( $values['form_key'] ) ) {
132 132
 			$values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
133
-        }
133
+		}
134 134
 
135 135
 		$form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
136 136
 
137 137
 		$new_values = self::set_update_options( array(), $values );
138 138
 
139
-        foreach ( $values as $value_key => $value ) {
139
+		foreach ( $values as $value_key => $value ) {
140 140
 			if ( $value_key && in_array( $value_key, $form_fields ) ) {
141 141
 				$new_values[ $value_key ] = $value;
142
-            }
143
-        }
142
+			}
143
+		}
144 144
 
145
-        if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
146
-            $new_values['status'] = $values['new_status'];
147
-        }
145
+		if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
146
+			$new_values['status'] = $values['new_status'];
147
+		}
148 148
 
149
-        if ( ! empty( $new_values ) ) {
149
+		if ( ! empty( $new_values ) ) {
150 150
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) );
151
-            if ( $query_results ) {
151
+			if ( $query_results ) {
152 152
 				self::clear_form_cache();
153
-            }
154
-        } else {
155
-            $query_results = true;
156
-        }
153
+			}
154
+		} else {
155
+			$query_results = true;
156
+		}
157 157
 		unset( $new_values );
158 158
 
159 159
 		$values = self::update_fields( $id, $values );
@@ -161,16 +161,16 @@  discard block
 block discarded – undo
161 161
 		do_action( 'frm_update_form', $id, $values );
162 162
 		do_action( 'frm_update_form_' . $id, $values );
163 163
 
164
-        return $query_results;
165
-    }
164
+		return $query_results;
165
+	}
166 166
 
167
-    /**
168
-     * @return array
169
-     */
167
+	/**
168
+	 * @return array
169
+	 */
170 170
 	public static function set_update_options( $new_values, $values ) {
171 171
 		if ( ! isset( $values['options'] ) ) {
172
-            return $new_values;
173
-        }
172
+			return $new_values;
173
+		}
174 174
 
175 175
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
176 176
 		FrmFormsHelper::fill_form_options( $options, $values );
@@ -184,17 +184,17 @@  discard block
 block discarded – undo
184 184
 		$new_values['options'] = serialize( $options );
185 185
 
186 186
 		return $new_values;
187
-    }
187
+	}
188 188
 
189 189
 
190
-    /**
191
-     * @return array
192
-     */
190
+	/**
191
+	 * @return array
192
+	 */
193 193
 	public static function update_fields( $id, $values ) {
194 194
 
195 195
 		if ( ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) {
196
-            return $values;
197
-        }
196
+			return $values;
197
+		}
198 198
 
199 199
 		$all_fields = FrmField::get_all_for_form( $id );
200 200
 		if ( empty( $all_fields ) ) {
@@ -205,26 +205,26 @@  discard block
 block discarded – undo
205 205
 			$values['item_meta'] = array();
206 206
 		}
207 207
 
208
-        $field_array = array();
209
-        $existing_keys = array_keys( $values['item_meta'] );
210
-        foreach ( $all_fields as $fid ) {
208
+		$field_array = array();
209
+		$existing_keys = array_keys( $values['item_meta'] );
210
+		foreach ( $all_fields as $fid ) {
211 211
 			if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) {
212 212
 				$values['item_meta'][ $fid->id ] = '';
213
-            }
213
+			}
214 214
 			$field_array[ $fid->id ] = $fid;
215
-        }
215
+		}
216 216
 		unset( $all_fields );
217 217
 
218
-        foreach ( $values['item_meta'] as $field_id => $default_value ) {
218
+		foreach ( $values['item_meta'] as $field_id => $default_value ) {
219 219
 			if ( isset( $field_array[ $field_id ] ) ) {
220 220
 				$field = $field_array[ $field_id ];
221
-            } else {
221
+			} else {
222 222
 				$field = FrmField::getOne( $field_id );
223
-            }
223
+			}
224 224
 
225
-            if ( ! $field ) {
226
-                continue;
227
-            }
225
+			if ( ! $field ) {
226
+				continue;
227
+			}
228 228
 
229 229
 			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
230 230
 			if ( $is_settings_page ) {
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 				if ( is_string( $field->field_options[ $opt ] ) ) {
246 246
 					$field->field_options[ $opt ] = trim( FrmAppHelper::kses( $field->field_options[ $opt ], 'all' ) );
247 247
 				}
248
-            }
248
+			}
249 249
 
250 250
 			$field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
251 251
 			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
 			FrmField::update( $field_id, $new_field );
261 261
 
262 262
 			FrmField::delete_form_transient( $field->form_id );
263
-        }
263
+		}
264 264
 		self::clear_form_cache();
265 265
 
266
-        return $values;
267
-    }
266
+		return $values;
267
+	}
268 268
 
269 269
 	/**
270 270
 	 * updating the settings page
@@ -301,21 +301,21 @@  discard block
 block discarded – undo
301 301
 		}
302 302
 	}
303 303
 
304
-    /**
305
-     * @param string $status
306
-     * @return int|boolean
307
-     */
304
+	/**
305
+	 * @param string $status
306
+	 * @return int|boolean
307
+	 */
308 308
 	public static function set_status( $id, $status ) {
309
-        if ( 'trash' == $status ) {
309
+		if ( 'trash' == $status ) {
310 310
 			return self::trash( $id );
311
-        }
311
+		}
312 312
 
313 313
 		$statuses  = array( 'published', 'draft', 'trash' );
314
-        if ( ! in_array( $status, $statuses ) ) {
315
-            return false;
316
-        }
314
+		if ( ! in_array( $status, $statuses ) ) {
315
+			return false;
316
+		}
317 317
 
318
-        global $wpdb;
318
+		global $wpdb;
319 319
 
320 320
 		if ( is_array( $id ) ) {
321 321
 			$where = array(
@@ -327,33 +327,33 @@  discard block
 block discarded – undo
327 327
 			array_unshift( $where['values'], $status );
328 328
 
329 329
 			$query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // WPCS: unprepared SQL ok.
330
-        } else {
330
+		} else {
331 331
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
332 332
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) );
333
-        }
333
+		}
334 334
 
335
-        if ( $query_results ) {
335
+		if ( $query_results ) {
336 336
 			self::clear_form_cache();
337
-        }
337
+		}
338 338
 
339
-        return $query_results;
340
-    }
339
+		return $query_results;
340
+	}
341 341
 
342
-    /**
343
-     * @return int|boolean
344
-     */
342
+	/**
343
+	 * @return int|boolean
344
+	 */
345 345
 	public static function trash( $id ) {
346
-        if ( ! EMPTY_TRASH_DAYS ) {
347
-            return self::destroy( $id );
348
-        }
346
+		if ( ! EMPTY_TRASH_DAYS ) {
347
+			return self::destroy( $id );
348
+		}
349 349
 
350 350
 		$form = self::getOne( $id );
351
-        if ( ! $form ) {
352
-            return false;
353
-        }
351
+		if ( ! $form ) {
352
+			return false;
353
+		}
354 354
 
355
-        $options = $form->options;
356
-        $options['trash_time'] = time();
355
+		$options = $form->options;
356
+		$options['trash_time'] = time();
357 357
 
358 358
 		global $wpdb;
359 359
 		$query_results = $wpdb->update(
@@ -378,39 +378,39 @@  discard block
 block discarded – undo
378 378
 			)
379 379
 		);
380 380
 
381
-        if ( $query_results ) {
381
+		if ( $query_results ) {
382 382
 			self::clear_form_cache();
383
-        }
383
+		}
384 384
 
385
-        return $query_results;
386
-    }
385
+		return $query_results;
386
+	}
387 387
 
388
-    /**
389
-     * @return int|boolean
390
-     */
388
+	/**
389
+	 * @return int|boolean
390
+	 */
391 391
 	public static function destroy( $id ) {
392
-        global $wpdb;
392
+		global $wpdb;
393 393
 
394 394
 		$form = self::getOne( $id );
395
-        if ( ! $form ) {
396
-            return false;
397
-        }
395
+		if ( ! $form ) {
396
+			return false;
397
+		}
398 398
 		$id = $form->id;
399 399
 
400
-        // Disconnect the entries from this form
400
+		// Disconnect the entries from this form
401 401
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
402 402
 		foreach ( $entries as $entry_id ) {
403 403
 			FrmEntry::destroy( $entry_id );
404 404
 			unset( $entry_id );
405 405
 		}
406 406
 
407
-        // Disconnect the fields from this form
407
+		// Disconnect the fields from this form
408 408
 		$wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) );
409 409
 
410 410
 		$query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
411
-        if ( $query_results ) {
412
-            // Delete all form actions linked to this form
413
-            $action_control = FrmFormActionsController::get_form_actions( 'email' );
411
+		if ( $query_results ) {
412
+			// Delete all form actions linked to this form
413
+			$action_control = FrmFormActionsController::get_form_actions( 'email' );
414 414
 			$action_control->destroy( $id, 'all' );
415 415
 
416 416
 			// Clear form caching
@@ -418,10 +418,10 @@  discard block
 block discarded – undo
418 418
 
419 419
 			do_action( 'frm_destroy_form', $id );
420 420
 			do_action( 'frm_destroy_form_' . $id );
421
-        }
421
+		}
422 422
 
423
-        return $query_results;
424
-    }
423
+		return $query_results;
424
+	}
425 425
 
426 426
 	/**
427 427
 	 * Delete trashed forms based on how long they have been trashed
@@ -453,60 +453,60 @@  discard block
 block discarded – undo
453 453
 		return $count;
454 454
 	}
455 455
 
456
-    /**
457
-     * @return string form name
458
-     */
459
-    public static function getName( $id ) {
456
+	/**
457
+	 * @return string form name
458
+	 */
459
+	public static function getName( $id ) {
460 460
 		$form = FrmDb::check_cache( $id, 'frm_form' );
461
-        if ( $form ) {
461
+		if ( $form ) {
462 462
 			$r = stripslashes( $form->name );
463
-            return $r;
464
-        }
463
+			return $r;
464
+		}
465 465
 
466
-        $query_key = is_numeric( $id ) ? 'id' : 'form_key';
467
-        $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
466
+		$query_key = is_numeric( $id ) ? 'id' : 'form_key';
467
+		$r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
468 468
 		$r = stripslashes( $r );
469 469
 
470
-        return $r;
471
-    }
470
+		return $r;
471
+	}
472 472
 
473
-    /**
473
+	/**
474 474
 	 * @since 3.0
475
-     * @param string $key
476
-     * @return int form id
477
-     */
475
+	 * @param string $key
476
+	 * @return int form id
477
+	 */
478 478
 	public static function get_id_by_key( $key ) {
479 479
 		return (int) FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
480
-    }
480
+	}
481 481
 
482 482
 	/**
483 483
 	 * @deprecated 3.0
484 484
 	 * @codeCoverageIgnore
485 485
 	 *
486
-     * @param string $key
487
-     * @return int form id
488
-     */
486
+	 * @param string $key
487
+	 * @return int form id
488
+	 */
489 489
 	public static function getIdByKey( $key ) {
490 490
 		_deprecated_function( __METHOD__, '3.0', 'FrmForm::get_id_by_key' );
491 491
 		return self::get_id_by_key( $key );
492
-    }
492
+	}
493 493
 
494
-    /**
494
+	/**
495 495
 	 * @since 3.0
496
-     * @param int $id
497
-     * @return string form key
498
-     */
496
+	 * @param int $id
497
+	 * @return string form key
498
+	 */
499 499
 	public static function get_key_by_id( $id ) {
500
-        $id = (int) $id;
500
+		$id = (int) $id;
501 501
 		$cache = FrmDb::check_cache( $id, 'frm_form' );
502
-        if ( $cache ) {
503
-            return $cache->form_key;
504
-        }
502
+		if ( $cache ) {
503
+			return $cache->form_key;
504
+		}
505 505
 
506
-        $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
506
+		$key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
507 507
 
508
-        return $key;
509
-    }
508
+		return $key;
509
+	}
510 510
 
511 511
 	/**
512 512
 	 * @deprecated 3.0
@@ -528,47 +528,47 @@  discard block
 block discarded – undo
528 528
 		}
529 529
 	}
530 530
 
531
-    /**
532
-     * @return object form
533
-     */
534
-    public static function getOne( $id, $blog_id = false ) {
535
-        global $wpdb;
531
+	/**
532
+	 * @return object form
533
+	 */
534
+	public static function getOne( $id, $blog_id = false ) {
535
+		global $wpdb;
536 536
 
537
-        if ( $blog_id && is_multisite() ) {
538
-            global $wpmuBaseTablePrefix;
537
+		if ( $blog_id && is_multisite() ) {
538
+			global $wpmuBaseTablePrefix;
539 539
 			$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id );
540 540
 
541 541
 			$table_name = $prefix . 'frm_forms';
542
-        } else {
542
+		} else {
543 543
 			$table_name = $wpdb->prefix . 'frm_forms';
544 544
 			$cache = wp_cache_get( $id, 'frm_form' );
545
-            if ( $cache ) {
545
+			if ( $cache ) {
546 546
 				if ( isset( $cache->options ) ) {
547 547
 					$cache->options = maybe_unserialize( $cache->options );
548
-                }
548
+				}
549 549
 
550 550
 				return stripslashes_deep( $cache );
551
-            }
552
-        }
551
+			}
552
+		}
553 553
 
554 554
 		if ( is_numeric( $id ) ) {
555
-            $where = array( 'id' => $id );
556
-        } else {
557
-            $where = array( 'form_key' => $id );
558
-        }
555
+			$where = array( 'id' => $id );
556
+		} else {
557
+			$where = array( 'form_key' => $id );
558
+		}
559 559
 
560
-        $results = FrmDb::get_row( $table_name, $where );
560
+		$results = FrmDb::get_row( $table_name, $where );
561 561
 
562 562
 		if ( isset( $results->options ) ) {
563 563
 			FrmDb::set_cache( $results->id, $results, 'frm_form' );
564 564
 			$results->options = maybe_unserialize( $results->options );
565
-        }
565
+		}
566 566
 		return stripslashes_deep( $results );
567
-    }
567
+	}
568 568
 
569
-    /**
570
-     * @return object|array of objects
571
-     */
569
+	/**
570
+	 * @return object|array of objects
571
+	 */
572 572
 	public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
573 573
 		if ( is_array( $where ) && ! empty( $where ) ) {
574 574
 			if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) ) {
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 		}
602 602
 
603 603
 		return stripslashes_deep( $results );
604
-    }
604
+	}
605 605
 
606 606
 	/**
607 607
 	 * Get all published forms
@@ -619,18 +619,18 @@  discard block
 block discarded – undo
619 619
 		return $forms;
620 620
 	}
621 621
 
622
-    /**
623
-     * @return int count of forms
624
-     */
625
-    public static function get_count() {
626
-    	global $wpdb;
622
+	/**
623
+	 * @return int count of forms
624
+	 */
625
+	public static function get_count() {
626
+		global $wpdb;
627 627
 
628
-    	$cache_key = 'frm_form_counts';
628
+		$cache_key = 'frm_form_counts';
629 629
 
630
-    	$counts = wp_cache_get( $cache_key, 'frm_form' );
631
-    	if ( false !== $counts ) {
632
-    	    return $counts;
633
-    	}
630
+		$counts = wp_cache_get( $cache_key, 'frm_form' );
631
+		if ( false !== $counts ) {
632
+			return $counts;
633
+		}
634 634
 
635 635
 		$results = (array) FrmDb::get_results( 'frm_forms', array(
636 636
 			'or' => 1,
@@ -639,31 +639,31 @@  discard block
 block discarded – undo
639 639
 		), 'status, is_template' );
640 640
 
641 641
 		$statuses = array( 'published', 'draft', 'template', 'trash' );
642
-    	$counts = array_fill_keys( $statuses, 0 );
642
+		$counts = array_fill_keys( $statuses, 0 );
643 643
 
644
-    	foreach ( $results as $row ) {
645
-            if ( 'trash' != $row->status ) {
646
-    	        if ( $row->is_template ) {
644
+		foreach ( $results as $row ) {
645
+			if ( 'trash' != $row->status ) {
646
+				if ( $row->is_template ) {
647 647
 					$counts['template']++;
648
-    	        } else {
648
+				} else {
649 649
 					$counts['published']++;
650
-    	        }
651
-    	    } else {
650
+				}
651
+			} else {
652 652
 				$counts['trash']++;
653
-        	}
653
+			}
654 654
 
655
-    	    if ( 'draft' == $row->status ) {
655
+			if ( 'draft' == $row->status ) {
656 656
 				$counts['draft']++;
657
-    	    }
657
+			}
658 658
 
659 659
 			unset( $row );
660
-    	}
660
+		}
661 661
 
662
-    	$counts = (object) $counts;
662
+		$counts = (object) $counts;
663 663
 		FrmDb::set_cache( $cache_key, $counts, 'frm_form' );
664 664
 
665
-    	return $counts;
666
-    }
665
+		return $counts;
666
+	}
667 667
 
668 668
 	/**
669 669
 	 * Clear form caching
@@ -676,14 +676,14 @@  discard block
 block discarded – undo
676 676
 		FrmDb::cache_delete_group( 'frm_form' );
677 677
 	}
678 678
 
679
-    /**
680
-     * @return array of errors
681
-     */
679
+	/**
680
+	 * @return array of errors
681
+	 */
682 682
 	public static function validate( $values ) {
683
-        $errors = array();
683
+		$errors = array();
684 684
 
685 685
 		return apply_filters( 'frm_validate_form', $errors, $values );
686
-    }
686
+	}
687 687
 
688 688
 	public static function get_params( $form = null ) {
689 689
 		global $frm_vars;
Please login to merge, or discard this patch.
classes/helpers/FrmFormsListHelper.php 2 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -43,28 +43,28 @@  discard block
 block discarded – undo
43 43
 			),
44 44
 		);
45 45
 		switch ( $this->status ) {
46
-		    case 'template':
47
-                $s_query['is_template'] = 1;
48
-                $s_query['status !'] = 'trash';
49
-		        break;
50
-		    case 'draft':
51
-                $s_query['is_template'] = 0;
52
-                $s_query['status'] = 'draft';
53
-		        break;
54
-		    case 'trash':
55
-                $s_query['status'] = 'trash';
56
-		        break;
57
-		    default:
58
-                $s_query['is_template'] = 0;
59
-                $s_query['status !'] = 'trash';
60
-		        break;
46
+			case 'template':
47
+				$s_query['is_template'] = 1;
48
+				$s_query['status !'] = 'trash';
49
+				break;
50
+			case 'draft':
51
+				$s_query['is_template'] = 0;
52
+				$s_query['status'] = 'draft';
53
+				break;
54
+			case 'trash':
55
+				$s_query['status'] = 'trash';
56
+				break;
57
+			default:
58
+				$s_query['is_template'] = 0;
59
+				$s_query['status !'] = 'trash';
60
+				break;
61 61
 		}
62 62
 
63 63
 		$s = self::get_param( array(
64 64
 			'param' => 's',
65 65
 			'sanitize' => 'sanitize_text_field',
66 66
 		) );
67
-	    if ( $s != '' ) {
67
+		if ( $s != '' ) {
68 68
 			preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
69 69
 			$search_terms = array_map( 'trim', $matches[0] );
70 70
 			foreach ( (array) $search_terms as $term ) {
@@ -76,10 +76,10 @@  discard block
 block discarded – undo
76 76
 				);
77 77
 				unset( $term );
78 78
 			}
79
-	    }
79
+		}
80 80
 
81 81
 		$this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
82
-        $total_items = FrmDb::get_count( 'frm_forms', $s_query );
82
+		$total_items = FrmDb::get_count( 'frm_forms', $s_query );
83 83
 
84 84
 		$this->set_pagination_args( array(
85 85
 			'total_items' => $total_items,
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	}
89 89
 
90 90
 	public function no_items() {
91
-	    if ( 'template' == $this->status ) {
91
+		if ( 'template' == $this->status ) {
92 92
 			esc_html_e( 'No Templates Found.', 'formidable' );
93 93
 		} else {
94 94
 			esc_html_e( 'No Forms Found.', 'formidable' );
@@ -99,29 +99,29 @@  discard block
 block discarded – undo
99 99
 	}
100 100
 
101 101
 	public function get_bulk_actions() {
102
-	    $actions = array();
102
+		$actions = array();
103 103
 
104
-	    if ( 'trash' == $this->status ) {
104
+		if ( 'trash' == $this->status ) {
105 105
 			if ( current_user_can( 'frm_edit_forms' ) ) {
106
-	            $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
107
-	        }
106
+				$actions['bulk_untrash'] = __( 'Restore', 'formidable' );
107
+			}
108 108
 
109 109
 			if ( current_user_can( 'frm_delete_forms' ) ) {
110
-	            $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
111
-	        }
110
+				$actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
111
+			}
112 112
 		} elseif ( EMPTY_TRASH_DAYS && current_user_can( 'frm_delete_forms' ) ) {
113
-	        $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
113
+			$actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
114 114
 		} elseif ( current_user_can( 'frm_delete_forms' ) ) {
115 115
 			$actions['bulk_delete'] = __( 'Delete' );
116
-	    }
116
+		}
117 117
 
118
-        return $actions;
119
-    }
118
+		return $actions;
119
+	}
120 120
 
121 121
 	public function extra_tablenav( $which ) {
122
-        if ( 'top' != $which ) {
123
-            return;
124
-        }
122
+		if ( 'top' != $which ) {
123
+			return;
124
+		}
125 125
 
126 126
 		if ( 'trash' == $this->status && current_user_can( 'frm_delete_forms' ) ) {
127 127
 ?>
@@ -129,21 +129,21 @@  discard block
 block discarded – undo
129 129
 			<?php submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); ?>
130 130
             </div>
131 131
 <?php
132
-            return;
133
-        }
132
+			return;
133
+		}
134 134
 
135
-        if ( 'template' != $this->status ) {
136
-            return;
137
-        }
135
+		if ( 'template' != $this->status ) {
136
+			return;
137
+		}
138 138
 
139 139
 		$where = apply_filters( 'frm_forms_dropdown', array(), '' );
140 140
 		$forms = FrmForm::get_published_forms( $where );
141 141
 
142 142
 		$base = admin_url( 'admin.php?page=formidable&form_type=template' );
143
-        $args = array(
144
-            'frm_action'    => 'duplicate',
145
-            'template'      => true,
146
-        );
143
+		$args = array(
144
+			'frm_action'    => 'duplicate',
145
+			'template'      => true,
146
+		);
147 147
 
148 148
 ?>
149 149
     <div class="alignleft actions frm_visible_overflow">
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
 		?>
156 156
 			<li class="frm_dropdown_li"><?php esc_html_e( 'You have not created any forms yet. You must create a form before you can make a template.', 'formidable' ) ?></li>
157 157
         <?php
158
-        } else {
159
-            foreach ( $forms as $form ) {
158
+		} else {
159
+			foreach ( $forms as $form ) {
160 160
 				$args['id'] = $form->id;
161 161
 				?>
162 162
 			<li><a href="<?php echo esc_url( add_query_arg( $args, $base ) ); ?>" tabindex="-1"><?php echo esc_html( empty( $form->name ) ? __( '(no title)' ) : FrmAppHelper::truncate( $form->name, 33 ) ); ?></a></li>
163 163
 			<?php
164 164
 				unset( $form );
165 165
 			}
166
-        }
167
-        ?>
166
+		}
167
+		?>
168 168
 		</ul>
169 169
 	</div>
170 170
 	</div>
@@ -174,33 +174,33 @@  discard block
 block discarded – undo
174 174
 	public function get_views() {
175 175
 
176 176
 		$statuses = array(
177
-		    'published' => __( 'My Forms', 'formidable' ),
178
-		    'template'  => __( 'Templates', 'formidable' ),
179
-		    'draft'     => __( 'Drafts', 'formidable' ),
180
-		    'trash'     => __( 'Trash', 'formidable' ),
177
+			'published' => __( 'My Forms', 'formidable' ),
178
+			'template'  => __( 'Templates', 'formidable' ),
179
+			'draft'     => __( 'Drafts', 'formidable' ),
180
+			'trash'     => __( 'Trash', 'formidable' ),
181 181
 		);
182 182
 
183
-	    $links = array();
184
-	    $counts = FrmForm::get_count();
183
+		$links = array();
184
+		$counts = FrmForm::get_count();
185 185
 		$form_type = self::get_param( array(
186 186
 			'param' => 'form_type',
187 187
 			'default' => 'published',
188 188
 		) );
189 189
 
190
-	    foreach ( $statuses as $status => $name ) {
190
+		foreach ( $statuses as $status => $name ) {
191 191
 
192
-	        if ( $status == $form_type ) {
193
-    			$class = ' class="current"';
194
-    		} else {
195
-    		    $class = '';
196
-    		}
192
+			if ( $status == $form_type ) {
193
+				$class = ' class="current"';
194
+			} else {
195
+				$class = '';
196
+			}
197 197
 
198
-    		if ( $counts->{$status} || 'published' == $status || 'template' == $status ) {
198
+			if ( $counts->{$status} || 'published' == $status || 'template' == $status ) {
199 199
 				$links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>';
200
-		    }
200
+			}
201 201
 
202 202
 			unset( $status, $name );
203
-	    }
203
+		}
204 204
 
205 205
 		return $links;
206 206
 	}
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	}
217 217
 
218 218
 	public function single_row( $item, $style = '' ) {
219
-	    global $frm_vars, $mode;
219
+		global $frm_vars, $mode;
220 220
 
221 221
 		// Set up the hover actions for this user
222 222
 		$actions = array();
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 
225 225
 		$this->get_actions( $actions, $item, $edit_link );
226 226
 
227
-        $action_links = $this->row_actions( $actions );
227
+		$action_links = $this->row_actions( $actions );
228 228
 
229 229
 		// Set up the checkbox ( because the user is editable, otherwise its empty )
230 230
 		$checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 
234 234
 		list( $columns, $hidden ) = $this->get_column_info();
235 235
 
236
-        $format = 'Y/m/d';
237
-        if ( 'list' != $mode ) {
238
-            $format .= ' \<\b\r \/\> g:i:s a';
236
+		$format = 'Y/m/d';
237
+		if ( 'list' != $mode ) {
238
+			$format .= ' \<\b\r \/\> g:i:s a';
239 239
 		}
240 240
 
241 241
 		foreach ( $columns as $column_name => $column_display_name ) {
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 
244 244
 			$style = '';
245 245
 			if ( in_array( $column_name, $hidden ) ) {
246
-                $class .= ' frm_hidden';
246
+				$class .= ' frm_hidden';
247 247
 			}
248 248
 
249 249
 			$class = 'class="' . esc_attr( $class ) . '"';
@@ -256,24 +256,24 @@  discard block
 block discarded – undo
256 256
 					break;
257 257
 				case 'id':
258 258
 				case 'form_key':
259
-				    $val = $item->{$column_name};
260
-				    break;
259
+					$val = $item->{$column_name};
260
+					break;
261 261
 				case 'name':
262
-				    $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
263
-			        $val .= $action_links;
262
+					$val = $this->get_form_name( $item, $actions, $edit_link, $mode );
263
+					$val .= $action_links;
264 264
 
265
-				    break;
265
+					break;
266 266
 				case 'created_at':
267 267
 					$date = date( $format, strtotime( $item->created_at ) );
268 268
 					$val = '<abbr title="' . esc_attr( date( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
269 269
 					break;
270 270
 				case 'shortcode':
271 271
 					$val = '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable id=' . $item->id . ']' ) . '" /><br/>';
272
-				    if ( 'excerpt' == $mode ) {
272
+					if ( 'excerpt' == $mode ) {
273 273
 						$val .= '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable key=' . $item->form_key . ']' ) . '" />';
274
-				    }
275
-			        break;
276
-			    case 'entries':
274
+					}
275
+					break;
276
+				case 'entries':
277 277
 					if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
278 278
 						$val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="' . esc_attr( 'Saving entries is disabled for this form', 'formidable' ) . '"></i>';
279 279
 					} else {
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 						$val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
282 282
 						unset( $text );
283 283
 					}
284
-			        break;
285
-                case 'type':
286
-                    $val = ( $item->is_template && $item->default_template ) ? __( 'Default', 'formidable' ) : __( 'Custom', 'formidable' );
287
-                    break;
284
+					break;
285
+				case 'type':
286
+					$val = ( $item->is_template && $item->default_template ) ? __( 'Default', 'formidable' ) : __( 'Custom', 'formidable' );
287
+					break;
288 288
 			}
289 289
 
290 290
 			if ( isset( $val ) ) {
291
-			    $r .= "<td $attributes>";
292
-			    $r .= $val;
293
-			    $r .= '</td>';
291
+				$r .= "<td $attributes>";
292
+				$r .= $val;
293
+				$r .= '</td>';
294 294
 			}
295 295
 			unset( $val );
296 296
 		}
@@ -299,9 +299,9 @@  discard block
 block discarded – undo
299 299
 		return $r;
300 300
 	}
301 301
 
302
-    /**
303
-     * @param string $edit_link
304
-     */
302
+	/**
303
+	 * @param string $edit_link
304
+	 */
305 305
 	private function get_actions( &$actions, $item, $edit_link ) {
306 306
 		$new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
307 307
 		foreach ( $new_actions as $link => $action ) {
@@ -325,13 +325,13 @@  discard block
 block discarded – undo
325 325
 
326 326
 		$actions = array_merge( $actions, $new_actions );
327 327
 		$actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview' ) . '</a>';
328
-    }
328
+	}
329 329
 
330
-    /**
331
-     * @param string $edit_link
332
-     */
330
+	/**
331
+	 * @param string $edit_link
332
+	 */
333 333
 	private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
334
-        $form_name = $item->name;
334
+		$form_name = $item->name;
335 335
 		if ( trim( $form_name ) == '' ) {
336 336
 			$form_name = __( '(no title)' );
337 337
 		}
@@ -340,37 +340,37 @@  discard block
 block discarded – undo
340 340
 			$form_name = FrmAppHelper::truncate( $form_name, 50 );
341 341
 		}
342 342
 
343
-        $val = '<strong>';
344
-        if ( 'trash' == $this->status ) {
345
-            $val .= $form_name;
346
-        } else {
343
+		$val = '<strong>';
344
+		if ( 'trash' == $this->status ) {
345
+			$val .= $form_name;
346
+		} else {
347 347
 			$val .= '<a href="' . esc_url( isset( $actions['frm_edit'] ) ? $edit_link : FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" class="row-title">' . FrmAppHelper::kses( $form_name ) . '</a> ';
348
-        }
348
+		}
349 349
 
350
-        $this->add_draft_label( $item, $val );
351
-        $val .= '</strong>';
350
+		$this->add_draft_label( $item, $val );
351
+		$val .= '</strong>';
352 352
 
353
-        $this->add_form_description( $item, $val );
353
+		$this->add_form_description( $item, $val );
354 354
 
355
-        return $val;
356
-    }
355
+		return $val;
356
+	}
357 357
 
358
-    /**
359
-     * @param string $val
360
-     */
361
-    private function add_draft_label( $item, &$val ) {
362
-        if ( 'draft' == $item->status && 'draft' != $this->status ) {
358
+	/**
359
+	 * @param string $val
360
+	 */
361
+	private function add_draft_label( $item, &$val ) {
362
+		if ( 'draft' == $item->status && 'draft' != $this->status ) {
363 363
 			$val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
364
-        }
365
-    }
366
-
367
-    /**
368
-     * @param string $val
369
-     */
370
-    private function add_form_description( $item, &$val ) {
371
-        global $mode;
372
-        if ( 'excerpt' == $mode ) {
364
+		}
365
+	}
366
+
367
+	/**
368
+	 * @param string $val
369
+	 */
370
+	private function add_form_description( $item, &$val ) {
371
+		global $mode;
372
+		if ( 'excerpt' == $mode ) {
373 373
 			$val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
374
-        }
375
-    }
374
+		}
375
+	}
376 376
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 		$page = $this->get_pagenum();
19 19
 		$per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
20 20
 
21
-		$mode    = self::get_param( array(
21
+		$mode = self::get_param( array(
22 22
 			'param'   => 'mode',
23 23
 			'default' => 'list',
24 24
 		) );
@@ -26,11 +26,11 @@  discard block
 block discarded – undo
26 26
 			'param'   => 'orderby',
27 27
 			'default' => 'name',
28 28
 		) );
29
-		$order   = self::get_param( array(
29
+		$order = self::get_param( array(
30 30
 			'param'   => 'order',
31 31
 			'default' => 'ASC',
32 32
 		) );
33
-		$start   = self::get_param( array(
33
+		$start = self::get_param( array(
34 34
 			'param'   => 'start',
35 35
 			'default' => ( $page - 1 ) * $per_page,
36 36
 		) );
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
     		}
197 197
 
198 198
     		if ( $counts->{$status} || 'published' == $status || 'template' == $status ) {
199
-				$links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>';
199
+				$links[$status] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>';
200 200
 		    }
201 201
 
202 202
 			unset( $status, $name );
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 	private function get_actions( &$actions, $item, $edit_link ) {
306 306
 		$new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
307 307
 		foreach ( $new_actions as $link => $action ) {
308
-			$new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
308
+			$new_actions[$link] = FrmFormsHelper::format_link_html( $action, 'short' );
309 309
 		}
310 310
 
311 311
 		if ( 'trash' == $this->status ) {
Please login to merge, or discard this patch.