@@ -1,26 +1,26 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FrmEntryValidate { |
| 4 | - public static function validate( $values, $exclude = false ) { |
|
| 5 | - global $wpdb; |
|
| 4 | + public static function validate( $values, $exclude = false ) { |
|
| 5 | + global $wpdb; |
|
| 6 | 6 | |
| 7 | - FrmEntry::sanitize_entry_post( $values ); |
|
| 8 | - $errors = array(); |
|
| 7 | + FrmEntry::sanitize_entry_post( $values ); |
|
| 8 | + $errors = array(); |
|
| 9 | 9 | |
| 10 | - if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
| 11 | - $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
| 12 | - return $errors; |
|
| 13 | - } |
|
| 10 | + if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
| 11 | + $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
| 12 | + return $errors; |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | 15 | 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' ) ) ) { |
| 16 | - $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
| 17 | - } |
|
| 16 | + $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - if ( ! isset($values['item_key']) || $values['item_key'] == '' ) { |
|
| 19 | + if ( ! isset($values['item_key']) || $values['item_key'] == '' ) { |
|
| 20 | 20 | $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
| 21 | - } |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
| 23 | + $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
| 24 | 24 | // Don't get subfields |
| 25 | 25 | $where['fr.parent_form_id'] = array( null, 0 ); |
| 26 | 26 | // Don't get excluded fields (like file upload fields in the ajax validation) |
@@ -28,46 +28,46 @@ discard block |
||
| 28 | 28 | $where['fi.type not'] = $exclude; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - $posted_fields = FrmField::getAll($where, 'field_order'); |
|
| 31 | + $posted_fields = FrmField::getAll($where, 'field_order'); |
|
| 32 | 32 | |
| 33 | - // Pass exclude value to validate_field function so it can be used for repeating sections |
|
| 34 | - $args = array( 'exclude' => $exclude ); |
|
| 33 | + // Pass exclude value to validate_field function so it can be used for repeating sections |
|
| 34 | + $args = array( 'exclude' => $exclude ); |
|
| 35 | 35 | |
| 36 | - foreach ( $posted_fields as $posted_field ) { |
|
| 37 | - self::validate_field($posted_field, $errors, $values, $args); |
|
| 38 | - unset($posted_field); |
|
| 39 | - } |
|
| 36 | + foreach ( $posted_fields as $posted_field ) { |
|
| 37 | + self::validate_field($posted_field, $errors, $values, $args); |
|
| 38 | + unset($posted_field); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - // check for spam |
|
| 42 | - self::spam_check( $exclude, $values, $errors ); |
|
| 41 | + // check for spam |
|
| 42 | + self::spam_check( $exclude, $values, $errors ); |
|
| 43 | 43 | |
| 44 | - $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
| 44 | + $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
| 45 | 45 | |
| 46 | - return $errors; |
|
| 47 | - } |
|
| 46 | + return $errors; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
| 50 | - $defaults = array( |
|
| 51 | - 'id' => $posted_field->id, |
|
| 52 | - 'parent_field_id' => '', // the id of the repeat or embed form |
|
| 53 | - 'key_pointer' => '', // the pointer in the posted array |
|
| 54 | - 'exclude' => array(), // exclude these field types from validation |
|
| 55 | - ); |
|
| 56 | - $args = wp_parse_args( $args, $defaults ); |
|
| 49 | + public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
| 50 | + $defaults = array( |
|
| 51 | + 'id' => $posted_field->id, |
|
| 52 | + 'parent_field_id' => '', // the id of the repeat or embed form |
|
| 53 | + 'key_pointer' => '', // the pointer in the posted array |
|
| 54 | + 'exclude' => array(), // exclude these field types from validation |
|
| 55 | + ); |
|
| 56 | + $args = wp_parse_args( $args, $defaults ); |
|
| 57 | 57 | |
| 58 | - if ( empty($args['parent_field_id']) ) { |
|
| 58 | + if ( empty($args['parent_field_id']) ) { |
|
| 59 | 59 | $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
| 60 | - } else { |
|
| 61 | - // value is from a nested form |
|
| 62 | - $value = $values; |
|
| 63 | - } |
|
| 60 | + } else { |
|
| 61 | + // value is from a nested form |
|
| 62 | + $value = $values; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - // Check for values in "Other" fields |
|
| 66 | - FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
| 65 | + // Check for values in "Other" fields |
|
| 66 | + FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
| 67 | 67 | |
| 68 | - if ( isset($posted_field->field_options['default_blank']) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value ) { |
|
| 69 | - $value = ''; |
|
| 70 | - } |
|
| 68 | + if ( isset($posted_field->field_options['default_blank']) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value ) { |
|
| 69 | + $value = ''; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | 72 | // Check for an array with only one value |
| 73 | 73 | // Don't reset values in "Other" fields because array keys need to be preserved |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | $value = reset($value); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
| 78 | + if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
| 79 | 79 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
| 80 | - } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
| 81 | - $_POST['item_name'] = $value; |
|
| 82 | - } |
|
| 80 | + } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
| 81 | + $_POST['item_name'] = $value; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | 84 | if ( $value != '' ) { |
| 85 | 85 | self::validate_url_field( $errors, $posted_field, $value, $args ); |
@@ -88,42 +88,42 @@ discard block |
||
| 88 | 88 | self::validate_phone_field( $errors, $posted_field, $value, $args ); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
| 91 | + FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
| 92 | 92 | |
| 93 | - self::validate_recaptcha($errors, $posted_field, $args); |
|
| 93 | + self::validate_recaptcha($errors, $posted_field, $args); |
|
| 94 | 94 | |
| 95 | - $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value, $args); |
|
| 95 | + $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value, $args); |
|
| 96 | 96 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | public static function validate_url_field( &$errors, $field, &$value, $args ) { |
| 100 | 100 | if ( $value == '' || ! in_array( $field->type, array( 'website', 'url', 'image' ) ) ) { |
| 101 | - return; |
|
| 102 | - } |
|
| 101 | + return; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - if ( trim($value) == 'http://' ) { |
|
| 105 | - $value = ''; |
|
| 106 | - } else { |
|
| 107 | - $value = esc_url_raw( $value ); |
|
| 104 | + if ( trim($value) == 'http://' ) { |
|
| 105 | + $value = ''; |
|
| 106 | + } else { |
|
| 107 | + $value = esc_url_raw( $value ); |
|
| 108 | 108 | $value = preg_match( '/^(https?|ftps?|mailto|news|feed|telnet):/is', $value ) ? $value : 'http://' . $value; |
| 109 | - } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - //validate the url format |
|
| 112 | - if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) { |
|
| 111 | + //validate the url format |
|
| 112 | + if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) { |
|
| 113 | 113 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
| 114 | - } |
|
| 115 | - } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | public static function validate_email_field( &$errors, $field, $value, $args ) { |
| 118 | - if ( $value == '' || $field->type != 'email' ) { |
|
| 119 | - return; |
|
| 120 | - } |
|
| 118 | + if ( $value == '' || $field->type != 'email' ) { |
|
| 119 | + return; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - //validate the email format |
|
| 123 | - if ( ! is_email($value) ) { |
|
| 122 | + //validate the email format |
|
| 123 | + if ( ! is_email($value) ) { |
|
| 124 | 124 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
| 125 | - } |
|
| 126 | - } |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | 128 | public static function validate_number_field( &$errors, $field, $value, $args ) { |
| 129 | 129 | //validate the number format |
@@ -200,9 +200,9 @@ discard block |
||
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | public static function validate_recaptcha( &$errors, $field, $args ) { |
| 203 | - if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) { |
|
| 204 | - return; |
|
| 205 | - } |
|
| 203 | + if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) { |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | 207 | $frm_settings = FrmAppHelper::get_settings(); |
| 208 | 208 | if ( empty( $frm_settings->pubkey ) ) { |
@@ -210,57 +210,57 @@ discard block |
||
| 210 | 210 | return; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
| 214 | - // If captcha is missing, check if it was already verified |
|
| 213 | + if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
| 214 | + // If captcha is missing, check if it was already verified |
|
| 215 | 215 | if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) { |
| 216 | - // There was no captcha submitted |
|
| 216 | + // There was no captcha submitted |
|
| 217 | 217 | $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' ); |
| 218 | - } |
|
| 219 | - return; |
|
| 220 | - } |
|
| 218 | + } |
|
| 219 | + return; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - $arg_array = array( |
|
| 223 | - 'body' => array( |
|
| 222 | + $arg_array = array( |
|
| 223 | + 'body' => array( |
|
| 224 | 224 | 'secret' => $frm_settings->privkey, |
| 225 | 225 | 'response' => $_POST['g-recaptcha-response'], |
| 226 | 226 | 'remoteip' => FrmAppHelper::get_ip_address(), |
| 227 | 227 | ), |
| 228 | 228 | ); |
| 229 | - $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
|
| 230 | - $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
| 229 | + $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
|
| 230 | + $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
| 231 | 231 | |
| 232 | - if ( isset( $response['success'] ) && ! $response['success'] ) { |
|
| 233 | - // What happens when the CAPTCHA was entered incorrectly |
|
| 232 | + if ( isset( $response['success'] ) && ! $response['success'] ) { |
|
| 233 | + // What happens when the CAPTCHA was entered incorrectly |
|
| 234 | 234 | $errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
| 235 | - } else if ( is_wp_error( $resp ) ) { |
|
| 235 | + } else if ( is_wp_error( $resp ) ) { |
|
| 236 | 236 | $error_string = $resp->get_error_message(); |
| 237 | 237 | $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
| 238 | 238 | $errors[ 'field' . $args['id'] ] .= ' ' . $error_string; |
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * check for spam |
|
| 244 | - * @param boolean $exclude |
|
| 245 | - * @param array $values |
|
| 246 | - * @param array $errors by reference |
|
| 247 | - */ |
|
| 248 | - public static function spam_check( $exclude, $values, &$errors ) { |
|
| 249 | - if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
| 250 | - // only check spam if there are no other errors |
|
| 251 | - return; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - if ( self::is_akismet_spam( $values ) ) { |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * check for spam |
|
| 244 | + * @param boolean $exclude |
|
| 245 | + * @param array $values |
|
| 246 | + * @param array $errors by reference |
|
| 247 | + */ |
|
| 248 | + public static function spam_check( $exclude, $values, &$errors ) { |
|
| 249 | + if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
| 250 | + // only check spam if there are no other errors |
|
| 251 | + return; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + if ( self::is_akismet_spam( $values ) ) { |
|
| 255 | 255 | if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) { |
| 256 | 256 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
| 257 | 257 | } |
| 258 | - } |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - if ( self::blacklist_check( $values ) ) { |
|
| 261 | - $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
|
| 262 | - } |
|
| 263 | - } |
|
| 260 | + if ( self::blacklist_check( $values ) ) { |
|
| 261 | + $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | 265 | private static function is_akismet_spam( $values ) { |
| 266 | 266 | global $wpcom_api_key; |
@@ -272,54 +272,54 @@ discard block |
||
| 272 | 272 | return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) ); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - public static function blacklist_check( $values ) { |
|
| 276 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
| 277 | - return false; |
|
| 278 | - } |
|
| 275 | + public static function blacklist_check( $values ) { |
|
| 276 | + if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
| 277 | + return false; |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
| 280 | + $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
| 281 | 281 | |
| 282 | - if ( empty( $mod_keys ) ) { |
|
| 283 | - return false; |
|
| 284 | - } |
|
| 282 | + if ( empty( $mod_keys ) ) { |
|
| 283 | + return false; |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - $content = FrmEntriesHelper::entry_array_to_string($values); |
|
| 286 | + $content = FrmEntriesHelper::entry_array_to_string($values); |
|
| 287 | 287 | |
| 288 | 288 | if ( empty($content) ) { |
| 289 | - return false; |
|
| 289 | + return false; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $words = explode( "\n", $mod_keys ); |
|
| 292 | + $words = explode( "\n", $mod_keys ); |
|
| 293 | 293 | |
| 294 | - foreach ( (array) $words as $word ) { |
|
| 295 | - $word = trim( $word ); |
|
| 294 | + foreach ( (array) $words as $word ) { |
|
| 295 | + $word = trim( $word ); |
|
| 296 | 296 | |
| 297 | - if ( empty($word) ) { |
|
| 298 | - continue; |
|
| 299 | - } |
|
| 297 | + if ( empty($word) ) { |
|
| 298 | + continue; |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - if ( preg_match('#' . preg_quote( $word, '#' ) . '#', $content) ) { |
|
| 302 | - return true; |
|
| 303 | - } |
|
| 304 | - } |
|
| 301 | + if ( preg_match('#' . preg_quote( $word, '#' ) . '#', $content) ) { |
|
| 302 | + return true; |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - return false; |
|
| 307 | - } |
|
| 306 | + return false; |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * Check entries for spam |
|
| 311 | - * |
|
| 312 | - * @return boolean true if is spam |
|
| 313 | - */ |
|
| 314 | - public static function akismet( $values ) { |
|
| 315 | - $content = FrmEntriesHelper::entry_array_to_string( $values ); |
|
| 309 | + /** |
|
| 310 | + * Check entries for spam |
|
| 311 | + * |
|
| 312 | + * @return boolean true if is spam |
|
| 313 | + */ |
|
| 314 | + public static function akismet( $values ) { |
|
| 315 | + $content = FrmEntriesHelper::entry_array_to_string( $values ); |
|
| 316 | 316 | |
| 317 | 317 | if ( empty( $content ) ) { |
| 318 | - return false; |
|
| 318 | + return false; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - $datas = array(); |
|
| 322 | - self::parse_akismet_array( $datas, $content ); |
|
| 321 | + $datas = array(); |
|
| 322 | + self::parse_akismet_array( $datas, $content ); |
|
| 323 | 323 | |
| 324 | 324 | $query_string = ''; |
| 325 | 325 | foreach ( $datas as $key => $data ) { |
@@ -327,35 +327,35 @@ discard block |
||
| 327 | 327 | unset( $key, $data ); |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - $response = Akismet::http_post($query_string, 'comment-check'); |
|
| 330 | + $response = Akismet::http_post($query_string, 'comment-check'); |
|
| 331 | 331 | |
| 332 | 332 | return ( is_array( $response ) && $response[1] == 'true' ); |
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @since 2.0 |
|
| 337 | - * @param string $content |
|
| 338 | - */ |
|
| 339 | - private static function parse_akismet_array( &$datas, $content ) { |
|
| 340 | - $datas['blog'] = FrmAppHelper::site_url(); |
|
| 341 | - $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() ); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * @since 2.0 |
|
| 337 | + * @param string $content |
|
| 338 | + */ |
|
| 339 | + private static function parse_akismet_array( &$datas, $content ) { |
|
| 340 | + $datas['blog'] = FrmAppHelper::site_url(); |
|
| 341 | + $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() ); |
|
| 342 | 342 | $datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ); |
| 343 | 343 | $datas['referrer'] = isset( $_SERVER['HTTP_REFERER'] ) ? FrmAppHelper::get_server_value( 'HTTP_REFERER' ) : false; |
| 344 | - $datas['comment_type'] = 'formidable'; |
|
| 345 | - $datas['comment_content'] = $content; |
|
| 344 | + $datas['comment_type'] = 'formidable'; |
|
| 345 | + $datas['comment_content'] = $content; |
|
| 346 | 346 | |
| 347 | - if ( $permalink = get_permalink() ) { |
|
| 348 | - $datas['permalink'] = $permalink; |
|
| 349 | - } |
|
| 347 | + if ( $permalink = get_permalink() ) { |
|
| 348 | + $datas['permalink'] = $permalink; |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | - foreach ( $_SERVER as $key => $value ) { |
|
| 351 | + foreach ( $_SERVER as $key => $value ) { |
|
| 352 | 352 | if ( ! in_array( $key, array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ) ) && is_string( $value ) ) { |
| 353 | 353 | $datas[ $key ] = wp_strip_all_tags( $value ); |
| 354 | - } else { |
|
| 354 | + } else { |
|
| 355 | 355 | $datas[ $key ] = ''; |
| 356 | - } |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - unset($key, $value); |
|
| 359 | - } |
|
| 360 | - } |
|
| 358 | + unset($key, $value); |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | 361 | } |
@@ -7,20 +7,20 @@ discard block |
||
| 7 | 7 | FrmEntry::sanitize_entry_post( $values ); |
| 8 | 8 | $errors = array(); |
| 9 | 9 | |
| 10 | - if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
| 10 | + if ( ! isset( $values['form_id'] ) || ! isset( $values['item_meta'] ) ) { |
|
| 11 | 11 | $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
| 12 | 12 | return $errors; |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | - 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' ) ) ) { |
|
| 15 | + 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' ) ) ) { |
|
| 16 | 16 | $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - if ( ! isset($values['item_key']) || $values['item_key'] == '' ) { |
|
| 19 | + if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) { |
|
| 20 | 20 | $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
| 23 | + $where = apply_filters( 'frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
|
| 24 | 24 | // Don't get subfields |
| 25 | 25 | $where['fr.parent_form_id'] = array( null, 0 ); |
| 26 | 26 | // Don't get excluded fields (like file upload fields in the ajax validation) |
@@ -28,20 +28,20 @@ discard block |
||
| 28 | 28 | $where['fi.type not'] = $exclude; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - $posted_fields = FrmField::getAll($where, 'field_order'); |
|
| 31 | + $posted_fields = FrmField::getAll( $where, 'field_order' ); |
|
| 32 | 32 | |
| 33 | 33 | // Pass exclude value to validate_field function so it can be used for repeating sections |
| 34 | 34 | $args = array( 'exclude' => $exclude ); |
| 35 | 35 | |
| 36 | 36 | foreach ( $posted_fields as $posted_field ) { |
| 37 | - self::validate_field($posted_field, $errors, $values, $args); |
|
| 38 | - unset($posted_field); |
|
| 37 | + self::validate_field( $posted_field, $errors, $values, $args ); |
|
| 38 | + unset( $posted_field ); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // check for spam |
| 42 | 42 | self::spam_check( $exclude, $values, $errors ); |
| 43 | 43 | |
| 44 | - $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') ); |
|
| 44 | + $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact( 'exclude' ) ); |
|
| 45 | 45 | |
| 46 | 46 | return $errors; |
| 47 | 47 | } |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | ); |
| 56 | 56 | $args = wp_parse_args( $args, $defaults ); |
| 57 | 57 | |
| 58 | - if ( empty($args['parent_field_id']) ) { |
|
| 59 | - $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
|
| 58 | + if ( empty( $args['parent_field_id'] ) ) { |
|
| 59 | + $value = isset( $values['item_meta'][$args['id']] ) ? $values['item_meta'][$args['id']] : ''; |
|
| 60 | 60 | } else { |
| 61 | 61 | // value is from a nested form |
| 62 | 62 | $value = $values; |
@@ -65,18 +65,18 @@ discard block |
||
| 65 | 65 | // Check for values in "Other" fields |
| 66 | 66 | FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
| 67 | 67 | |
| 68 | - if ( isset($posted_field->field_options['default_blank']) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value ) { |
|
| 68 | + if ( isset( $posted_field->field_options['default_blank'] ) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value ) { |
|
| 69 | 69 | $value = ''; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | // Check for an array with only one value |
| 73 | 73 | // Don't reset values in "Other" fields because array keys need to be preserved |
| 74 | - if ( is_array($value) && count( $value ) == 1 && $args['other'] !== true ) { |
|
| 75 | - $value = reset($value); |
|
| 74 | + if ( is_array( $value ) && count( $value ) == 1 && $args['other'] !== true ) { |
|
| 75 | + $value = reset( $value ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
| 79 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
| 79 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
| 80 | 80 | } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
| 81 | 81 | $_POST['item_name'] = $value; |
| 82 | 82 | } |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | self::validate_phone_field( $errors, $posted_field, $value, $args ); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - FrmEntriesHelper::set_posted_value($posted_field, $value, $args); |
|
| 91 | + FrmEntriesHelper::set_posted_value( $posted_field, $value, $args ); |
|
| 92 | 92 | |
| 93 | - self::validate_recaptcha($errors, $posted_field, $args); |
|
| 93 | + self::validate_recaptcha( $errors, $posted_field, $args ); |
|
| 94 | 94 | |
| 95 | - $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value, $args); |
|
| 95 | + $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
|
| 96 | 96 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | return; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - if ( trim($value) == 'http://' ) { |
|
| 104 | + if ( trim( $value ) == 'http://' ) { |
|
| 105 | 105 | $value = ''; |
| 106 | 106 | } else { |
| 107 | 107 | $value = esc_url_raw( $value ); |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | //validate the url format |
| 112 | - if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) { |
|
| 113 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
| 112 | + if ( ! preg_match( '/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value ) ) { |
|
| 113 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | //validate the email format |
| 123 | - if ( ! is_email($value) ) { |
|
| 124 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
| 123 | + if ( ! is_email( $value ) ) { |
|
| 124 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | return; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - if ( ! is_numeric( $value) ) { |
|
| 135 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
| 134 | + if ( ! is_numeric( $value ) ) { |
|
| 135 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // validate number settings |
@@ -142,9 +142,9 @@ discard block |
||
| 142 | 142 | if ( $frm_settings->use_html && isset( $field->field_options['minnum'] ) && isset( $field->field_options['maxnum'] ) ) { |
| 143 | 143 | //minnum maxnum |
| 144 | 144 | if ( (float) $value < $field->field_options['minnum'] ) { |
| 145 | - $errors[ 'field' . $args['id'] ] = __( 'Please select a higher number', 'formidable' ); |
|
| 145 | + $errors['field' . $args['id']] = __( 'Please select a higher number', 'formidable' ); |
|
| 146 | 146 | } else if ( (float) $value > $field->field_options['maxnum'] ) { |
| 147 | - $errors[ 'field' . $args['id'] ] = __( 'Please select a lower number', 'formidable' ); |
|
| 147 | + $errors['field' . $args['id']] = __( 'Please select a lower number', 'formidable' ); |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $pattern = self::phone_format( $field ); |
| 159 | 159 | |
| 160 | 160 | if ( ! preg_match( $pattern, $value ) ) { |
| 161 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
| 161 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
@@ -210,11 +210,11 @@ discard block |
||
| 210 | 210 | return; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if ( ! isset($_POST['g-recaptcha-response']) ) { |
|
| 213 | + if ( ! isset( $_POST['g-recaptcha-response'] ) ) { |
|
| 214 | 214 | // If captcha is missing, check if it was already verified |
| 215 | 215 | if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) { |
| 216 | 216 | // There was no captcha submitted |
| 217 | - $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' ); |
|
| 217 | + $errors['field' . $args['id']] = __( 'The captcha is missing from this form', 'formidable' ); |
|
| 218 | 218 | } |
| 219 | 219 | return; |
| 220 | 220 | } |
@@ -227,15 +227,15 @@ discard block |
||
| 227 | 227 | ), |
| 228 | 228 | ); |
| 229 | 229 | $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array ); |
| 230 | - $response = json_decode(wp_remote_retrieve_body( $resp ), true); |
|
| 230 | + $response = json_decode( wp_remote_retrieve_body( $resp ), true ); |
|
| 231 | 231 | |
| 232 | 232 | if ( isset( $response['success'] ) && ! $response['success'] ) { |
| 233 | 233 | // What happens when the CAPTCHA was entered incorrectly |
| 234 | - $errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
|
| 234 | + $errors['field' . $args['id']] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid']; |
|
| 235 | 235 | } else if ( is_wp_error( $resp ) ) { |
| 236 | 236 | $error_string = $resp->get_error_message(); |
| 237 | - $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
|
| 238 | - $errors[ 'field' . $args['id'] ] .= ' ' . $error_string; |
|
| 237 | + $errors['field' . $args['id']] = __( 'There was a problem verifying your recaptcha', 'formidable' ); |
|
| 238 | + $errors['field' . $args['id']] .= ' ' . $error_string; |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | |
| 265 | 265 | private static function is_akismet_spam( $values ) { |
| 266 | 266 | global $wpcom_api_key; |
| 267 | - return ( is_callable('Akismet::http_post') && ( get_option('wordpress_api_key') || $wpcom_api_key ) && self::akismet( $values ) ); |
|
| 267 | + return ( is_callable( 'Akismet::http_post' ) && ( get_option( 'wordpress_api_key' ) || $wpcom_api_key ) && self::akismet( $values ) ); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | private static function is_akismet_enabled_for_user( $form_id ) { |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | public static function blacklist_check( $values ) { |
| 276 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
| 276 | + if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) { |
|
| 277 | 277 | return false; |
| 278 | 278 | } |
| 279 | 279 | |
@@ -283,9 +283,9 @@ discard block |
||
| 283 | 283 | return false; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $content = FrmEntriesHelper::entry_array_to_string($values); |
|
| 286 | + $content = FrmEntriesHelper::entry_array_to_string( $values ); |
|
| 287 | 287 | |
| 288 | - if ( empty($content) ) { |
|
| 288 | + if ( empty( $content ) ) { |
|
| 289 | 289 | return false; |
| 290 | 290 | } |
| 291 | 291 | |
@@ -294,11 +294,11 @@ discard block |
||
| 294 | 294 | foreach ( (array) $words as $word ) { |
| 295 | 295 | $word = trim( $word ); |
| 296 | 296 | |
| 297 | - if ( empty($word) ) { |
|
| 297 | + if ( empty( $word ) ) { |
|
| 298 | 298 | continue; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if ( preg_match('#' . preg_quote( $word, '#' ) . '#', $content) ) { |
|
| 301 | + if ( preg_match( '#' . preg_quote( $word, '#' ) . '#', $content ) ) { |
|
| 302 | 302 | return true; |
| 303 | 303 | } |
| 304 | 304 | } |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | unset( $key, $data ); |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - $response = Akismet::http_post($query_string, 'comment-check'); |
|
| 330 | + $response = Akismet::http_post( $query_string, 'comment-check' ); |
|
| 331 | 331 | |
| 332 | 332 | return ( is_array( $response ) && $response[1] == 'true' ); |
| 333 | 333 | } |
@@ -350,12 +350,12 @@ discard block |
||
| 350 | 350 | |
| 351 | 351 | foreach ( $_SERVER as $key => $value ) { |
| 352 | 352 | if ( ! in_array( $key, array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ) ) && is_string( $value ) ) { |
| 353 | - $datas[ $key ] = wp_strip_all_tags( $value ); |
|
| 353 | + $datas[$key] = wp_strip_all_tags( $value ); |
|
| 354 | 354 | } else { |
| 355 | - $datas[ $key ] = ''; |
|
| 355 | + $datas[$key] = ''; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - unset($key, $value); |
|
| 358 | + unset( $key, $value ); |
|
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | 361 | } |