Completed
Push — master ( 84bf61...3e58cb )
by Stephanie
03:20
created
classes/models/FrmEntryValidate.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -43,6 +43,9 @@
 block discarded – undo
43 43
 		}
44 44
 	}
45 45
 
46
+	/**
47
+	 * @param boolean $exclude
48
+	 */
46 49
 	private static function get_fields_to_validate( $values, $exclude ) {
47 50
 		$where = apply_filters( 'frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) );
48 51
 
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 class FrmEntryValidate {
4
-    public static function validate( $values, $exclude = false ) {
5
-        FrmEntry::sanitize_entry_post( $values );
6
-        $errors = array();
4
+	public static function validate( $values, $exclude = false ) {
5
+		FrmEntry::sanitize_entry_post( $values );
6
+		$errors = array();
7 7
 
8
-        if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) {
9
-            $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' );
10
-            return $errors;
11
-        }
8
+		if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) {
9
+			$errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' );
10
+			return $errors;
11
+		}
12 12
 
13 13
 		if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) {
14
-            $errors['form'] = __( 'You do not have permission to do that', 'formidable' );
15
-        }
14
+			$errors['form'] = __( 'You do not have permission to do that', 'formidable' );
15
+		}
16 16
 
17 17
 		self::set_item_key( $values );
18 18
 
@@ -57,24 +57,24 @@  discard block
 block discarded – undo
57 57
 		return FrmField::getAll( $where, 'field_order' );
58 58
 	}
59 59
 
60
-    public static function validate_field( $posted_field, &$errors, $values, $args = array() ) {
61
-        $defaults = array(
62
-            'id'              => $posted_field->id,
63
-            'parent_field_id' => '', // the id of the repeat or embed form
64
-            'key_pointer'     => '', // the pointer in the posted array
65
-            'exclude'         => array(), // exclude these field types from validation
66
-        );
67
-        $args = wp_parse_args( $args, $defaults );
60
+	public static function validate_field( $posted_field, &$errors, $values, $args = array() ) {
61
+		$defaults = array(
62
+			'id'              => $posted_field->id,
63
+			'parent_field_id' => '', // the id of the repeat or embed form
64
+			'key_pointer'     => '', // the pointer in the posted array
65
+			'exclude'         => array(), // exclude these field types from validation
66
+		);
67
+		$args = wp_parse_args( $args, $defaults );
68 68
 
69
-        if ( empty($args['parent_field_id']) ) {
69
+		if ( empty($args['parent_field_id']) ) {
70 70
 			$value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : '';
71
-        } else {
72
-            // value is from a nested form
73
-            $value = $values;
74
-        }
71
+		} else {
72
+			// value is from a nested form
73
+			$value = $values;
74
+		}
75 75
 
76
-        // Check for values in "Other" fields
77
-        FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args );
76
+		// Check for values in "Other" fields
77
+		FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args );
78 78
 
79 79
 		self::maybe_clear_value_for_default_blank_setting( $posted_field, $value );
80 80
 
@@ -87,11 +87,11 @@  discard block
 block discarded – undo
87 87
 			$value = trim( $value );
88 88
 		}
89 89
 
90
-        if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) {
90
+		if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) {
91 91
 			$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' );
92
-        } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) {
93
-            $_POST['item_name'] = $value;
94
-        }
92
+		} else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) {
93
+			$_POST['item_name'] = $value;
94
+		}
95 95
 
96 96
 		FrmEntriesHelper::set_posted_value( $posted_field, $value, $args );
97 97
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 
104 104
 		$errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args );
105 105
 		$errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args );
106
-    }
106
+	}
107 107
 
108 108
 	private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) {
109 109
 		$is_default = ( FrmField::is_option_true_in_object( $field, 'default_blank' ) && $value == $field->default_value );
@@ -239,34 +239,34 @@  discard block
 block discarded – undo
239 239
 		}
240 240
 
241 241
 		self::validate_field_types( $errors, $field, $value, $args );
242
-    }
243
-
244
-    /**
245
-     * check for spam
246
-     * @param boolean $exclude
247
-     * @param array $values
248
-     * @param array $errors by reference
249
-     */
250
-    public static function spam_check( $exclude, $values, &$errors ) {
251
-        if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
252
-            // only check spam if there are no other errors
253
-            return;
254
-        }
242
+	}
243
+
244
+	/**
245
+	 * check for spam
246
+	 * @param boolean $exclude
247
+	 * @param array $values
248
+	 * @param array $errors by reference
249
+	 */
250
+	public static function spam_check( $exclude, $values, &$errors ) {
251
+		if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
252
+			// only check spam if there are no other errors
253
+			return;
254
+		}
255 255
 
256 256
 		if ( self::is_honeypot_spam() || self::is_spam_bot() ) {
257 257
 			$errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
258 258
 		}
259 259
 
260
-    	if ( self::blacklist_check( $values ) ) {
261
-            $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' );
262
-    	}
260
+		if ( self::blacklist_check( $values ) ) {
261
+			$errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' );
262
+		}
263 263
 
264
-        if ( self::is_akismet_spam( $values ) ) {
264
+		if ( self::is_akismet_spam( $values ) ) {
265 265
 			if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) {
266 266
 				$errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
267 267
 			}
268
-	    }
269
-    }
268
+		}
269
+	}
270 270
 
271 271
 	private static function is_honeypot_spam() {
272 272
 		$honeypot_value = FrmAppHelper::get_param( 'frm_verify', '', 'get', 'sanitize_text_field' );
@@ -288,15 +288,15 @@  discard block
 block discarded – undo
288 288
 		return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) );
289 289
 	}
290 290
 
291
-    public static function blacklist_check( $values ) {
292
-        if ( ! apply_filters('frm_check_blacklist', true, $values) ) {
293
-            return false;
294
-        }
291
+	public static function blacklist_check( $values ) {
292
+		if ( ! apply_filters('frm_check_blacklist', true, $values) ) {
293
+			return false;
294
+		}
295 295
 
296
-    	$mod_keys = trim( get_option( 'blacklist_keys' ) );
297
-    	if ( empty( $mod_keys ) ) {
298
-    		return false;
299
-    	}
296
+		$mod_keys = trim( get_option( 'blacklist_keys' ) );
297
+		if ( empty( $mod_keys ) ) {
298
+			return false;
299
+		}
300 300
 
301 301
 		$content = FrmEntriesHelper::entry_array_to_string( $values );
302 302
 		if ( empty( $content ) ) {
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 		$user_info = self::get_spam_check_user_info( $values );
309 309
 
310 310
 		return wp_blacklist_check( $user_info['comment_author'], $user_info['comment_author_email'], $user_info['comment_author_url'], $content, $ip, $user_agent );
311
-    }
311
+	}
312 312
 
313 313
 	/**
314 314
 	 * Check entries for Akismet spam
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@  discard block
 block discarded – undo
5 5
         FrmEntry::sanitize_entry_post( $values );
6 6
         $errors = array();
7 7
 
8
-        if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) {
8
+        if ( ! isset( $values['form_id'] ) || ! isset( $values['item_meta'] ) ) {
9 9
             $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' );
10 10
             return $errors;
11 11
         }
12 12
 
13
-		if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) {
13
+		if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values['frm_submit_entry_' . $values['form_id']] ) || ! wp_verify_nonce( $values['frm_submit_entry_' . $values['form_id']], 'frm_submit_entry_nonce' ) ) ) {
14 14
             $errors['form'] = __( 'You do not have permission to do that', 'formidable' );
15 15
         }
16 16
 
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
         );
67 67
         $args = wp_parse_args( $args, $defaults );
68 68
 
69
-        if ( empty($args['parent_field_id']) ) {
70
-			$value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : '';
69
+        if ( empty( $args['parent_field_id'] ) ) {
70
+			$value = isset( $values['item_meta'][$args['id']] ) ? $values['item_meta'][$args['id']] : '';
71 71
         } else {
72 72
             // value is from a nested form
73 73
             $value = $values;
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 		self::maybe_clear_value_for_default_blank_setting( $posted_field, $value );
80 80
 
81 81
 		// Reset arrays with only one value if it's not a field where array keys need to be preserved
82
-		if ( is_array($value) && count( $value ) == 1 && isset( $value[0] ) ) {
83
-			$value = reset($value);
82
+		if ( is_array( $value ) && count( $value ) == 1 && isset( $value[0] ) ) {
83
+			$value = reset( $value );
84 84
 		}
85 85
 
86 86
 		if ( ! is_array( $value ) ) {
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 		}
89 89
 
90 90
         if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) {
91
-			$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' );
91
+			$errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' );
92 92
         } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) {
93 93
             $_POST['item_name'] = $value;
94 94
         }
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 			$pattern = self::phone_format( $field );
172 172
 
173 173
 			if ( ! preg_match( $pattern, $value ) ) {
174
-				$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
174
+				$errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
175 175
 			}
176 176
 		}
177 177
 	}
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 
281 281
 	private static function is_akismet_spam( $values ) {
282 282
 		global $wpcom_api_key;
283
-		return ( is_callable('Akismet::http_post') && ( get_option('wordpress_api_key') || $wpcom_api_key ) && self::akismet( $values ) );
283
+		return ( is_callable( 'Akismet::http_post' ) && ( get_option( 'wordpress_api_key' ) || $wpcom_api_key ) && self::akismet( $values ) );
284 284
 	}
285 285
 
286 286
 	private static function is_akismet_enabled_for_user( $form_id ) {
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 	}
290 290
 
291 291
     public static function blacklist_check( $values ) {
292
-        if ( ! apply_filters('frm_check_blacklist', true, $values) ) {
292
+        if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) {
293 293
             return false;
294 294
         }
295 295
 
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 		$datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' );
349 349
 		$datas['referrer'] = isset( $_SERVER['HTTP_REFERER'] ) ? FrmAppHelper::get_server_value( 'HTTP_REFERER' ) : false;
350 350
 		$datas['blog_lang'] = get_locale();
351
-		$datas['blog_charset'] = get_option('blog_charset');
351
+		$datas['blog_charset'] = get_option( 'blog_charset' );
352 352
 
353 353
 		if ( akismet_test_mode() ) {
354 354
 			$datas['is_test'] = 'true';
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 
403 403
 			// Send any potentially useful $_SERVER vars, but avoid sending junk we don't need.
404 404
 			if ( $include_value ) {
405
-				$datas[ $key ] = $value;
405
+				$datas[$key] = $value;
406 406
 			}
407 407
 			unset( $key, $value );
408 408
 		}
Please login to merge, or discard this patch.