PluginProbe
HTML Forms – Simple WordPress Forms Plugin / 1.3.21
HTML Forms – Simple WordPress Forms Plugin v1.3.21
trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 All 66 releases
← All changes | src/functions.php +9 -83 trunk1.3.21 View file →
@@ -77,10 +77,8 @@
77 77 'success' => __( 'Thank you! We will be in touch soon.', 'html-forms' ),
78 78 'invalid_email' => __( 'Sorry, that email address looks invalid.', 'html-forms' ),
79 79 'required_field_missing' => __( 'Please fill in the required fields.', 'html-forms' ),
80 80 'error' => __( 'Oops. An error occurred.', 'html-forms' ),
81 - 'recaptcha_failed' => __( 'reCAPTCHA verification failed. Please try again.', 'html-forms' ),
82 - 'recaptcha_low_score' => __( 'Your submission appears to be spam. Please try again.', 'html-forms' ),
83 81 );
84 82 $default_messages = apply_filters( 'hf_form_default_messages', $default_messages );
85 83 $messages = array();
86 84 foreach ( $post_meta as $meta_key => $meta_values ) {
@@ -102,19 +100,8 @@
102 100 }
103 101
104 102 /**
105 103 * @param $form_id
106 - * @return int
107 - */
108 -function hf_count_form_submissions( $form_id ) {
109 - global $wpdb;
110 - $table = $wpdb->prefix . 'hf_submissions';
111 - $result = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$table} s WHERE s.form_id = %d;", $form_id ) );
112 - return (int) $result;
113 -}
114 -
115 -/**
116 - * @param $form_id
117 104 * @param array $args
118 105 * @return Submission[]
119 106 */
120 107 function hf_get_form_submissions( $form_id, array $args = array() ) {
@@ -150,15 +137,9 @@
150 137 * @return array
151 138 */
152 139 function hf_get_settings() {
153 140 $default_settings = array(
154 - 'enable_nonce' => 0,
155 141 'load_stylesheet' => 0,
156 - 'wrapper_tag' => 'p',
157 - 'google_recaptcha' => array(
158 - 'site_key' => '',
159 - 'secret_key' => '',
160 - ),
161 142 );
162 143
163 144 $settings = get_option( 'hf_settings', null );
164 145
@@ -169,16 +150,8 @@
169 150 }
170 151
171 152 // merge with default settings
172 153 $settings = array_merge( $default_settings, $settings );
173 -
174 - // Ensure nested arrays are properly merged
175 - if ( isset( $default_settings['google_recaptcha'] ) ) {
176 - $settings['google_recaptcha'] = array_merge(
177 - $default_settings['google_recaptcha'],
178 - isset( $settings['google_recaptcha'] ) ? $settings['google_recaptcha'] : array()
179 - );
180 - }
181 154
182 155 /**
183 156 * Filters the global HTML Forms hf_settings
184 157 *
@@ -268,44 +241,17 @@
268 241 * @param array $data
269 242 * @param Closure|string $escape_function
270 243 * @return string
271 244 */
272 -function hf_replace_data_variables( $string, Submission $submission, $escape_function = null ) {
273 - $data = ( !empty( $submission->data ) ? $submission->data : array() );
274 - $submission_fields = array( 'HF_TIMESTAMP', 'HF_USER_AGENT', 'HF_IP_ADDRESS', 'HF_REFERRER_URL' );
275 -
245 +function hf_replace_data_variables( $string, $data = array(), $escape_function = null ) {
276 246 return preg_replace_callback(
277 247 '/\[(.+?)\]/',
278 - function( $matches ) use ( $submission, $submission_fields, $escape_function ) {
248 + function( $matches ) use ( $data, $escape_function ) {
279 249 $key = $matches[1];
280 -
281 - if ( in_array( $key, $submission_fields ) ) {
282 - $replacement = '';
283 -
284 - switch ( $key ) {
285 - case 'HF_TIMESTAMP' :
286 - $replacement = $submission->submitted_at;
287 - break;
288 - case 'HF_USER_AGENT' :
289 - $replacement = $submission->user_agent;
290 - break;
291 - case 'HF_IP_ADDRESS' :
292 - $replacement = $submission->ip_address;
293 - break;
294 - case 'HF_REFERRER_URL' :
295 - $replacement = $submission->referer_url;
296 - break;
297 - default :
298 - $replacement = '';
299 - break;
300 - }
301 - } else {
302 - // replace spaces in name with underscores to match PHP requirement for keys in $_POST superglobal
303 - $key = str_replace( ' ', '_', $key );
304 - $replacement = hf_array_get( $submission->data, $key, '' );
305 - $replacement = hf_field_value( $replacement, 0, $escape_function );
306 - }
307 -
250 + // replace spaces in name with underscores to match PHP requirement for keys in $_POST superglobal
251 + $key = str_replace( ' ', '_', $key );
252 + $replacement = hf_array_get( $data, $key, '' );
253 + $replacement = hf_field_value( $replacement, 0, $escape_function );
308 254 return $replacement;
309 255 },
310 256 $string
311 257 );
@@ -327,33 +273,20 @@
327 273 return $value;
328 274 }
329 275
330 276 if ( hf_is_file( $value ) ) {
331 - if ( ! is_array( $value )
332 - || ! isset( $value['name'] )
333 - || ! isset( $value['size'] )
334 - || ! isset( $value['type'] ) ) {
335 - return false;
336 - }
337 -
338 - // Verify attachment exists
339 - if ( isset( $value['attachment_id'] ) && get_post( $value['attachment_id'] ) == null ) {
340 - return __( 'File not found', 'html-forms' );
341 - }
342 -
343 277 $file_url = isset( $value['url'] ) ? $value['url'] : '';
344 278 if ( isset( $value['attachment_id'] ) && apply_filters( 'hf_file_upload_use_direct_links', false ) === false ) {
345 279 $file_url = admin_url( sprintf( 'post.php?action=edit&post=%d', $value['attachment_id'] ) );
346 280 }
347 -
348 281 $short_name = substr( $value['name'], 0, 20 );
349 282 $suffix = strlen( $value['name'] ) > 20 ? '...' : '';
350 - return sprintf( '<a href="%s">%s%s</a> (%s)', esc_url( $file_url ), esc_html( $short_name ), esc_html( $suffix ), hf_human_filesize( $value['size'] ) );
283 + return sprintf( '<a href="%s">%s%s</a> (%s)', esc_attr( $file_url ), esc_html( $short_name ), esc_html( $suffix ), hf_human_filesize( $value['size'] ) );
351 284 }
352 285
353 286 if ( hf_is_date( $value ) ) {
354 287 $date_format = get_option( 'date_format' );
355 - return gmdate( $date_format, strtotime( str_replace( '/', '-', $value ) ) );
288 + return gmdate( $date_format, strtotime( $value ) );
356 289 }
357 290
358 291 // join array-values with comma
359 292 if ( is_array( $value ) ) {
@@ -374,13 +307,8 @@
374 307 if ( $escape_function !== null && is_callable( $escape_function ) ) {
375 308 $value = $escape_function( $value );
376 309 }
377 310
378 - // add line breaks, if not string limited to certain length
379 - if ( $limit === 0 ) {
380 - $value = nl2br( $value );
381 - }
382 -
383 311 return $value;
384 312 }
385 313
386 314 /**
@@ -495,10 +423,8 @@
495 423 function _hf_create_submissions_table() {
496 424 /** @var wpdb */
497 425 global $wpdb;
498 426
499 - $charset_collate = $wpdb->get_charset_collate();
500 -
501 427 // create table for storing submissions
502 428 $table = $wpdb->prefix . 'hf_submissions';
503 429 $wpdb->query(
504 430 "CREATE TABLE IF NOT EXISTS {$table}(
@@ -508,9 +434,9 @@
508 434 `user_agent` TEXT NULL,
509 435 `ip_address` VARCHAR(255) NULL,
510 436 `referer_url` TEXT NULL,
511 437 `submitted_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
512 -) {$charset_collate};"
438 +) ENGINE=INNODB CHARACTER SET={$wpdb->charset};"
513 439 );
514 440 }
515 441
516 442 function _hf_on_add_user_to_blog( $user_id, $role, $blog_id ) {