| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | class FrmForm { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * @param array $values |
| 10 | - * @return bool|int id on success or false on failure. | |
| 10 | + * @return int|boolean id on success or false on failure | |
| 11 | 11 | */ |
| 12 | 12 | public static function create( $values ) { |
| 13 | 13 | global $wpdb; |
| 14 | 14 | |
| @@ -17,22 +17,22 @@ | ||
| 17 | 17 | $new_values = array( |
| 18 | 18 | 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ), |
| 19 | 19 | 'name' => $values['name'], |
| 20 | 20 | 'description' => $values['description'], |
| 21 | - 'status' => $values['status'] ?? 'published', | |
| 22 | - 'logged_in' => $values['logged_in'] ?? 0, | |
| 21 | + 'status' => isset( $values['status'] ) ? $values['status'] : 'published', | |
| 22 | + 'logged_in' => isset( $values['logged_in'] ) ? $values['logged_in'] : 0, | |
| 23 | 23 | 'is_template' => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0, |
| 24 | 24 | 'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0, |
| 25 | 25 | 'editable' => isset( $values['editable'] ) ? (int) $values['editable'] : 0, |
| 26 | - 'created_at' => $values['created_at'] ?? current_time( 'mysql', 1 ), | |
| 26 | + 'created_at' => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ), | |
| 27 | 27 | ); |
| 28 | 28 | |
| 29 | 29 | $options = isset( $values['options'] ) ? (array) $values['options'] : array(); |
| 30 | 30 | FrmFormsHelper::fill_form_options( $options, $values ); |
| 31 | 31 | |
| 32 | - $options['before_html'] = $values['options']['before_html'] ?? FrmFormsHelper::get_default_html( 'before' ); | |
| 33 | - $options['after_html'] = $values['options']['after_html'] ?? FrmFormsHelper::get_default_html( 'after' ); | |
| 34 | - $options['submit_html'] = $values['options']['submit_html'] ?? FrmFormsHelper::get_default_html( 'submit' ); | |
| 32 | + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' ); | |
| 33 | + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' ); | |
| 34 | + $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); | |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Allows modifying form options before updating or creating. |
| 38 | 38 | * |
| @@ -69,9 +69,9 @@ | ||
| 69 | 69 | return FrmAppHelper::maybe_filter_array( $options, array( 'submit_value', 'success_msg', 'before_html', 'after_html' ) ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | - * @return bool|int ID on success or false on failure | |
| 73 | + * @return int|boolean ID on success or false on failure | |
| 74 | 74 | */ |
| 75 | 75 | public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
| 76 | 76 | global $wpdb; |
| 77 | 77 | |
| @@ -93,10 +93,10 @@ | ||
| 93 | 93 | 'is_template' => $template ? 1 : 0, |
| 94 | 94 | ); |
| 95 | 95 | |
| 96 | 96 | if ( $blog_id ) { |
| 97 | - $new_values['status'] = 'published'; | |
| 98 | - $new_options = $values->options; | |
| 97 | + $new_values['status'] = 'published'; | |
| 98 | + $new_options = $values->options; | |
| 99 | 99 | FrmAppHelper::unserialize_or_decode( $new_options ); |
| 100 | 100 | $new_options['email_to'] = get_option( 'admin_email' ); |
| 101 | 101 | $new_options['copy'] = false; |
| 102 | 102 | $new_values['options'] = $new_options; |
| @@ -126,9 +126,9 @@ | ||
| 126 | 126 | return false; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | public static function after_duplicate( $form_id, $values ) { |
| 130 | - $new_opts = $values['options']; | |
| 130 | + $new_opts = $values['options']; | |
| 131 | 131 | FrmAppHelper::unserialize_or_decode( $new_opts ); |
| 132 | 132 | $values['options'] = $new_opts; |
| 133 | 133 | |
| 134 | 134 | if ( isset( $new_opts['success_msg'] ) ) { |
| @@ -158,9 +158,9 @@ | ||
| 158 | 158 | // Keys of fields that you want to check to replace field ID. |
| 159 | 159 | $keys = array( 'default_value', 'field_options' ); |
| 160 | 160 | $sql_cols = 'fi.id'; |
| 161 | 161 | foreach ( $keys as $key ) { |
| 162 | - $sql_cols .= ',fi.' . $key; | |
| 162 | + $sql_cols .= ( ',fi.' . $key ); | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | $fields = FrmDb::get_results( |
| 166 | 166 | "{$wpdb->prefix}frm_fields AS fi LEFT OUTER JOIN {$wpdb->prefix}frm_forms AS fr ON fi.form_id = fr.id", |
| @@ -210,9 +210,9 @@ | ||
| 210 | 210 | |
| 211 | 211 | if ( $new_val !== $value ) { |
| 212 | 212 | $new_values[ $key ] = $new_val; |
| 213 | 213 | } |
| 214 | - }//end foreach | |
| 214 | + } | |
| 215 | 215 | |
| 216 | 216 | if ( ! empty( $new_values ) ) { |
| 217 | 217 | FrmField::update( $field['id'], $new_values ); |
| 218 | 218 | } |
| @@ -218,9 +218,9 @@ | ||
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
| 222 | - * @return bool|int | |
| 222 | + * @return int|boolean | |
| 223 | 223 | */ |
| 224 | 224 | public static function update( $id, $values, $create_link = false ) { |
| 225 | 225 | global $wpdb; |
| 226 | 226 | |
| @@ -243,9 +243,9 @@ | ||
| 243 | 243 | $new_values[ $value_key ] = $value; |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - if ( ! empty( $values['new_status'] ) ) { | |
| 247 | + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { | |
| 248 | 248 | $new_values['status'] = $values['new_status']; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | if ( ! empty( $new_values ) ) { |
| @@ -276,16 +276,21 @@ | ||
| 276 | 276 | if ( ! isset( $values['options'] ) ) { |
| 277 | 277 | return $new_values; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - $options = ! empty( $values['options'] ) ? (array) $values['options'] : array(); | |
| 280 | + $options = isset( $values['options'] ) ? (array) $values['options'] : array(); | |
| 281 | 281 | FrmFormsHelper::fill_form_options( $options, $values ); |
| 282 | 282 | |
| 283 | - $options['custom_style'] = $values['options']['custom_style'] ?? 0; | |
| 284 | - $options['before_html'] = $values['options']['before_html'] ?? FrmFormsHelper::get_default_html( 'before' ); | |
| 285 | - $options['after_html'] = $values['options']['after_html'] ?? FrmFormsHelper::get_default_html( 'after' ); | |
| 286 | - $options['submit_html'] = isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); | |
| 283 | + $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0; | |
| 284 | + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' ); | |
| 285 | + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' ); | |
| 286 | + $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); | |
| 287 | 287 | |
| 288 | + if ( ! empty( $options['success_url'] ) && ! empty( $args['form_id'] ) ) { | |
| 289 | + $options['success_url'] = FrmFormsHelper::maybe_add_sanitize_url_attr( $options['success_url'], (int) $args['form_id'] ); | |
| 290 | + $values['options']['success_url'] = $options['success_url']; | |
| 291 | + } | |
| 292 | + | |
| 288 | 293 | /** |
| 289 | 294 | * Allows modifying form options before updating or creating. |
| 290 | 295 | * |
| 291 | 296 | * @since 5.4 Added the third param. |
| @@ -348,20 +353,15 @@ | ||
| 348 | 353 | continue; |
| 349 | 354 | } |
| 350 | 355 | } |
| 351 | 356 | |
| 352 | - // Updating the form. | |
| 357 | + //updating the form | |
| 353 | 358 | $update_options = FrmFieldsHelper::get_default_field_options_from_field( $field ); |
| 354 | - // Don't check for POST html. | |
| 355 | - unset( $update_options['custom_html'] ); | |
| 359 | + unset( $update_options['custom_html'] ); // don't check for POST html | |
| 356 | 360 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
| 357 | 361 | |
| 358 | - if ( ! is_array( $field->field_options ) ) { | |
| 359 | - $field->field_options = array(); | |
| 360 | - } | |
| 361 | - | |
| 362 | 362 | foreach ( $update_options as $opt => $default ) { |
| 363 | - $field->field_options[ $opt ] = $values['field_options'][ $opt . '_' . $field_id ] ?? $default; | |
| 363 | + $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default; | |
| 364 | 364 | self::sanitize_field_opt( $opt, $field->field_options[ $opt ] ); |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
| @@ -370,87 +370,28 @@ | ||
| 370 | 370 | 'field_options' => $field->field_options, |
| 371 | 371 | 'default_value' => isset( $values[ 'default_value_' . $field_id ] ) ? FrmAppHelper::maybe_json_encode( $values[ 'default_value_' . $field_id ] ) : '', |
| 372 | 372 | ); |
| 373 | 373 | |
| 374 | - if ( ! FrmAppHelper::allow_unfiltered_html() && isset( $values['field_options'][ 'options_' . $field_id ] ) && is_array( $values['field_options'][ 'options_' . $field_id ] ) ) { | |
| 375 | - foreach ( $values['field_options'][ 'options_' . $field_id ] as $option_key => $option ) { | |
| 376 | - if ( is_array( $option ) ) { | |
| 377 | - foreach ( $option as $key => $item ) { | |
| 378 | - $values['field_options'][ 'options_' . $field_id ][ $option_key ][ $key ] = FrmAppHelper::kses( $item, 'all' ); | |
| 379 | - } | |
| 380 | - } | |
| 381 | - } | |
| 382 | - } | |
| 383 | - | |
| 384 | 374 | self::prepare_field_update_values( $field, $values, $new_field ); |
| 385 | - self::maybe_update_max_option( $field, $values, $new_field ); | |
| 386 | 375 | |
| 387 | 376 | FrmField::update( $field_id, $new_field ); |
| 388 | 377 | |
| 389 | 378 | FrmField::delete_form_transient( $field->form_id ); |
| 390 | - }//end foreach | |
| 379 | + } | |
| 391 | 380 | self::clear_form_cache(); |
| 392 | 381 | |
| 393 | 382 | return $values; |
| 394 | 383 | } |
| 395 | 384 | |
| 396 | - /** | |
| 397 | - * Resets the 'max' option of a field when changing paragraph field type to other field types like text, email etc. | |
| 398 | - * | |
| 399 | - * @since 6.7 | |
| 400 | - * | |
| 401 | - * @param array $field | |
| 402 | - * @param array $values | |
| 403 | - * @param array $new_field | |
| 404 | - * @return void | |
| 405 | - */ | |
| 406 | - private static function maybe_update_max_option( $field, $values, &$new_field ) { | |
| 407 | - if ( $field->type === 'textarea' && | |
| 408 | - ! empty( $values['field_options'][ 'type_' . $field->id ] ) && | |
| 409 | - in_array( $values['field_options'][ 'type_' . $field->id ], array( 'text', 'email', 'url', 'password', 'phone' ), true ) ) { | |
| 410 | - | |
| 411 | - $new_field['field_options']['max'] = ''; | |
| 412 | - | |
| 413 | - /** | |
| 414 | - * Update posted field setting so that new 'max' option is displayed after form is saved and page reloads. | |
| 415 | - * FrmFieldsHelper::fill_default_field_opts populates field options by calling self::get_posted_field_setting. | |
| 416 | - */ | |
| 417 | - $_POST['field_options'][ 'max_' . $field->id ] = ''; | |
| 418 | - } | |
| 419 | - } | |
| 420 | - | |
| 421 | - /** | |
| 422 | - * @param string $opt | |
| 423 | - * @param mixed $value | |
| 424 | - * @return void | |
| 425 | - */ | |
| 426 | 385 | private static function sanitize_field_opt( $opt, &$value ) { |
| 427 | - if ( ! is_string( $value ) ) { | |
| 428 | - return; | |
| 386 | + if ( is_string( $value ) ) { | |
| 387 | + if ( $opt === 'calc' ) { | |
| 388 | + $value = self::sanitize_calc( $value ); | |
| 389 | + } else { | |
| 390 | + $value = FrmAppHelper::kses( $value, 'all' ); | |
| 391 | + } | |
| 392 | + $value = trim( $value ); | |
| 429 | 393 | } |
| 430 | - | |
| 431 | - /** | |
| 432 | - * Allow the option to turn off sanitization for a field. This way a custom rule can be used instead. | |
| 433 | - * Make sure to add custom sanitization using the frm_update_field_options filter as the data will no longer be sanitized. | |
| 434 | - * | |
| 435 | - * @since 6.0 | |
| 436 | - * | |
| 437 | - * @param bool $should_sanitize | |
| 438 | - * @param string $opt | |
| 439 | - */ | |
| 440 | - $should_sanitize = apply_filters( 'frm_should_sanitize_field_opt_string', true, $opt ); | |
| 441 | - | |
| 442 | - if ( ! $should_sanitize ) { | |
| 443 | - return; | |
| 444 | - } | |
| 445 | - | |
| 446 | - if ( $opt === 'calc' ) { | |
| 447 | - $value = self::sanitize_calc( $value ); | |
| 448 | - } else { | |
| 449 | - $value = FrmAppHelper::kses( $value, 'all' ); | |
| 450 | - } | |
| 451 | - | |
| 452 | - $value = trim( $value ); | |
| 453 | 394 | } |
| 454 | 395 | |
| 455 | 396 | /** |
| 456 | 397 | * @param string $value |
| @@ -459,10 +400,9 @@ | ||
| 459 | 400 | private static function sanitize_calc( $value ) { |
| 460 | 401 | if ( false !== strpos( $value, '<' ) ) { |
| 461 | 402 | $value = self::normalize_calc_spaces( $value ); |
| 462 | 403 | } |
| 463 | - // Allow <= and >=. | |
| 464 | - $allow = array( '<= ', ' >=' ); | |
| 404 | + $allow = array( '<= ', ' >=' ); // Allow <= and >= | |
| 465 | 405 | $temp = array( '< = ', ' > =' ); |
| 466 | 406 | $value = str_replace( $allow, $temp, $value ); |
| 467 | 407 | $value = strip_tags( $value ); |
| 468 | 408 | $value = str_replace( $temp, $allow, $value ); |
| @@ -477,16 +417,14 @@ | ||
| 477 | 417 | * @return string |
| 478 | 418 | */ |
| 479 | 419 | private static function normalize_calc_spaces( $calc ) { |
| 480 | 420 | // Check for a pattern with 5 parts |
| 481 | - // $1 \d|\] the first comparison digit or the end of a comparison shortcode. | |
| 421 | + // $1 \d the first comparison digit. | |
| 482 | 422 | // $2 a space (optional). |
| 483 | 423 | // $3 an equals sign (optional) that follows the < operator for <= comparisons. |
| 484 | 424 | // $4 another space (optional). |
| 485 | - // $5 \d|\[ the second comparison digit or the start of a comparison shortcode. | |
| 486 | - $calc = preg_replace( '/(\d|\])( ){0,1}<(=){0,1}( ){0,1}(\d|\[)/', '$1 <$3 $5', $calc ); | |
| 487 | - | |
| 488 | - return $calc; | |
| 425 | + // $5 \d the second comparison digit. | |
| 426 | + return preg_replace( '/(\d)( ){0,1}<(=){0,1}( ){0,1}(\d)/', '$1 <$3 $5', $calc ); | |
| 489 | 427 | } |
| 490 | 428 | |
| 491 | 429 | /** |
| 492 | 430 | * Updating the settings page |
| @@ -493,12 +431,12 @@ | ||
| 493 | 431 | */ |
| 494 | 432 | private static function get_settings_page_html( $values, &$field ) { |
| 495 | 433 | if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) { |
| 496 | 434 | $prev_opts = array(); |
| 497 | - $fallback_html = $field->field_options['custom_html'] ?? FrmFieldsHelper::get_default_html( $field->type ); | |
| 435 | + $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ); | |
| 498 | 436 | |
| 499 | - $field->field_options['custom_html'] = $values['field_options'][ 'custom_html_' . $field->id ] ?? $fallback_html; | |
| 500 | - } elseif ( $field->type === 'hidden' || $field->type === 'user_id' ) { | |
| 437 | + $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html; | |
| 438 | + } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) { | |
| 501 | 439 | $prev_opts = $field->field_options; |
| 502 | 440 | } |
| 503 | 441 | |
| 504 | 442 | if ( isset( $prev_opts ) ) { |
| @@ -519,14 +457,11 @@ | ||
| 519 | 457 | 'options' => '', |
| 520 | 458 | 'name' => '', |
| 521 | 459 | ); |
| 522 | 460 | foreach ( $field_cols as $col => $default ) { |
| 523 | - $default = $default === '' ? $field->{$col} : $default; | |
| 524 | - $new_field[ $col ] = $values['field_options'][ $col . '_' . $field->id ] ?? $default; | |
| 525 | - } | |
| 461 | + $default = ( $default === '' ) ? $field->{$col} : $default; | |
| 526 | 462 | |
| 527 | - if ( $field->type === 'submit' && isset( $new_field['field_order'] ) && (int) $new_field['field_order'] === FrmSubmitHelper::DEFAULT_ORDER ) { | |
| 528 | - $new_field['field_order'] = $field->field_order; | |
| 463 | + $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default; | |
| 529 | 464 | } |
| 530 | 465 | |
| 531 | 466 | // Don't save the template option. |
| 532 | 467 | if ( is_array( $new_field['options'] ) && isset( $new_field['options']['000'] ) ) { |
| @@ -538,9 +473,9 @@ | ||
| 538 | 473 | * Get a list of all form settings that should be translated |
| 539 | 474 | * on a multilingual site. |
| 540 | 475 | * |
| 541 | 476 | * @since 3.06.01 |
| 542 | - * @param object $form The form object. | |
| 477 | + * @param object $form - The form object | |
| 543 | 478 | */ |
| 544 | 479 | public static function translatable_strings( $form ) { |
| 545 | 480 | $strings = array( |
| 546 | 481 | 'name', |
| @@ -557,12 +492,11 @@ | ||
| 557 | 492 | return apply_filters( 'frm_form_strings', $strings, $form ); |
| 558 | 493 | } |
| 559 | 494 | |
| 560 | 495 | /** |
| 561 | - * @param int $id | |
| 562 | 496 | * @param string $status |
| 563 | 497 | * |
| 564 | - * @return bool|int | |
| 498 | + * @return int|boolean | |
| 565 | 499 | */ |
| 566 | 500 | public static function set_status( $id, $status ) { |
| 567 | 501 | if ( 'trash' == $status ) { |
| 568 | 502 | return self::trash( $id ); |
| @@ -568,9 +502,9 @@ | ||
| 568 | 502 | return self::trash( $id ); |
| 569 | 503 | } |
| 570 | 504 | |
| 571 | 505 | $statuses = array( 'published', 'draft', 'trash' ); |
| 572 | - if ( ! in_array( $status, $statuses, true ) ) { | |
| 506 | + if ( ! in_array( $status, $statuses ) ) { | |
| 573 | 507 | return false; |
| 574 | 508 | } |
| 575 | 509 | |
| 576 | 510 | global $wpdb; |
| @@ -597,9 +531,9 @@ | ||
| 597 | 531 | return $query_results; |
| 598 | 532 | } |
| 599 | 533 | |
| 600 | 534 | /** |
| 601 | - * @return bool|int | |
| 535 | + * @return int|boolean | |
| 602 | 536 | */ |
| 603 | 537 | public static function trash( $id ) { |
| 604 | 538 | if ( ! EMPTY_TRASH_DAYS ) { |
| 605 | 539 | return self::destroy( $id ); |
| @@ -609,12 +543,8 @@ | ||
| 609 | 543 | if ( ! $form ) { |
| 610 | 544 | return false; |
| 611 | 545 | } |
| 612 | 546 | |
| 613 | - if ( $form->status === 'trash' ) { | |
| 614 | - return false; | |
| 615 | - } | |
| 616 | - | |
| 617 | 547 | $options = $form->options; |
| 618 | 548 | $options['trash_time'] = time(); |
| 619 | 549 | |
| 620 | 550 | global $wpdb; |
| @@ -647,9 +577,9 @@ | ||
| 647 | 577 | return $query_results; |
| 648 | 578 | } |
| 649 | 579 | |
| 650 | 580 | /** |
| 651 | - * @return bool|int | |
| 581 | + * @return int|boolean | |
| 652 | 582 | */ |
| 653 | 583 | public static function destroy( $id ) { |
| 654 | 584 | global $wpdb; |
| 655 | 585 | |
| @@ -671,11 +601,8 @@ | ||
| 671 | 601 | |
| 672 | 602 | $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
| 673 | 603 | if ( $query_results ) { |
| 674 | 604 | // Delete all form actions linked to this form |
| 675 | - /** | |
| 676 | - * @var FrmFormAction | |
| 677 | - */ | |
| 678 | 605 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
| 679 | 606 | $action_control->destroy( $id, 'all' ); |
| 680 | 607 | |
| 681 | 608 | // Clear form caching |
| @@ -695,9 +622,9 @@ | ||
| 695 | 622 | */ |
| 696 | 623 | public static function scheduled_delete( $delete_timestamp = '' ) { |
| 697 | 624 | global $wpdb; |
| 698 | 625 | |
| 699 | - $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, parent_form_id, options' ); | |
| 626 | + $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, options' ); | |
| 700 | 627 | |
| 701 | 628 | if ( ! $trash_forms ) { |
| 702 | 629 | return 0; |
| 703 | 630 | } |
| @@ -710,11 +637,9 @@ | ||
| 710 | 637 | foreach ( $trash_forms as $form ) { |
| 711 | 638 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 712 | 639 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
| 713 | 640 | self::destroy( $form->id ); |
| 714 | - if ( empty( $form->parent_form_id ) ) { | |
| 715 | - ++$count; | |
| 716 | - } | |
| 641 | + $count ++; | |
| 717 | 642 | } |
| 718 | 643 | |
| 719 | 644 | unset( $form ); |
| 720 | 645 | } |
| @@ -734,12 +659,10 @@ | ||
| 734 | 659 | } |
| 735 | 660 | |
| 736 | 661 | $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
| 737 | 662 | $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
| 663 | + $r = stripslashes( $r ); | |
| 738 | 664 | |
| 739 | - // An empty form name can result in a null value. | |
| 740 | - $r = is_null( $r ) ? '' : stripslashes( $r ); | |
| 741 | - | |
| 742 | 665 | return $r; |
| 743 | 666 | } |
| 744 | 667 | |
| 745 | 668 | /** |
| @@ -774,10 +697,11 @@ | ||
| 774 | 697 | |
| 775 | 698 | /** |
| 776 | 699 | * If $form is numeric, get the form object |
| 777 | 700 | * |
| 701 | + * @param object|int $form | |
| 702 | + * | |
| 778 | 703 | * @since 2.0.9 |
| 779 | - * @param int|object $form | |
| 780 | 704 | */ |
| 781 | 705 | public static function maybe_get_form( &$form ) { |
| 782 | 706 | if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) { |
| 783 | 707 | $form = self::getOne( $form ); |
| @@ -784,11 +708,9 @@ | ||
| 784 | 708 | } |
| 785 | 709 | } |
| 786 | 710 | |
| 787 | 711 | /** |
| 788 | - * @param int|string $id | |
| 789 | - * @param false|int $blog_id | |
| 790 | - * @return stdClass|null | |
| 712 | + * @return object form | |
| 791 | 713 | */ |
| 792 | 714 | public static function getOne( $id, $blog_id = false ) { |
| 793 | 715 | global $wpdb; |
| 794 | 716 | |
| @@ -803,9 +725,10 @@ | ||
| 803 | 725 | if ( $cache ) { |
| 804 | 726 | if ( isset( $cache->options ) ) { |
| 805 | 727 | FrmAppHelper::unserialize_or_decode( $cache->options ); |
| 806 | 728 | } |
| 807 | - return self::prepare_form_row_data( $cache ); | |
| 729 | + | |
| 730 | + return wp_unslash( $cache ); | |
| 808 | 731 | } |
| 809 | 732 | } |
| 810 | 733 | |
| 811 | 734 | if ( is_numeric( $id ) ) { |
| @@ -820,43 +743,17 @@ | ||
| 820 | 743 | FrmDb::set_cache( $results->id, $results, 'frm_form' ); |
| 821 | 744 | FrmAppHelper::unserialize_or_decode( $results->options ); |
| 822 | 745 | } |
| 823 | 746 | |
| 824 | - return self::prepare_form_row_data( $results ); | |
| 747 | + return apply_filters( 'frm_form_object', wp_unslash( $results ) ); | |
| 825 | 748 | } |
| 826 | 749 | |
| 827 | 750 | /** |
| 828 | - * Make sure that if $row is an object, that $row->options is an array and not a string. | |
| 829 | - * | |
| 830 | - * @since 6.8.3 | |
| 831 | - * | |
| 832 | - * @param stdClass|null $row The database row for a target form. | |
| 833 | - * @return stdClass|null | |
| 751 | + * @return object|array of objects | |
| 834 | 752 | */ |
| 835 | - private static function prepare_form_row_data( $row ) { | |
| 836 | - $row = wp_unslash( $row ); | |
| 837 | - if ( ! is_object( $row ) ) { | |
| 838 | - return $row; | |
| 839 | - } | |
| 840 | - | |
| 841 | - if ( ! is_array( $row->options ) ) { | |
| 842 | - $row->options = FrmFormsHelper::get_default_opts(); | |
| 843 | - } | |
| 844 | - | |
| 845 | - /** | |
| 846 | - * @since 4.03.02 | |
| 847 | - * | |
| 848 | - * @param stdClass $row | |
| 849 | - */ | |
| 850 | - return apply_filters( 'frm_form_object', $row ); | |
| 851 | - } | |
| 852 | - | |
| 853 | - /** | |
| 854 | - * @return array|object of objects | |
| 855 | - */ | |
| 856 | 753 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
| 857 | 754 | if ( is_array( $where ) && ! empty( $where ) ) { |
| 858 | - if ( ! empty( $where['is_template'] ) && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) { | |
| 755 | + if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) { | |
| 859 | 756 | // don't get trashed templates |
| 860 | 757 | $where['status'] = array( null, '', 'published' ); |
| 861 | 758 | } |
| 862 | 759 | |
| @@ -863,9 +760,9 @@ | ||
| 863 | 760 | $results = FrmDb::get_results( 'frm_forms', $where, '*', compact( 'order_by', 'limit' ) ); |
| 864 | 761 | } else { |
| 865 | 762 | global $wpdb; |
| 866 | 763 | |
| 867 | - // The query has already been prepared if this is not an array. | |
| 764 | + // the query has already been prepared if this is not an array | |
| 868 | 765 | $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit ); |
| 869 | 766 | $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 870 | 767 | } |
| 871 | 768 | |
| @@ -875,9 +772,9 @@ | ||
| 875 | 772 | FrmAppHelper::unserialize_or_decode( $result->options ); |
| 876 | 773 | } |
| 877 | 774 | } |
| 878 | 775 | |
| 879 | - if ( $limit === ' LIMIT 1' || $limit == 1 ) { | |
| 776 | + if ( $limit == ' LIMIT 1' || $limit == 1 ) { | |
| 880 | 777 | // return the first form object if we are only getting one form |
| 881 | 778 | $results = reset( $results ); |
| 882 | 779 | } |
| 883 | 780 | |
| @@ -887,18 +784,14 @@ | ||
| 887 | 784 | /** |
| 888 | 785 | * Get all published forms |
| 889 | 786 | * |
| 890 | 787 | * @since 2.0 |
| 891 | - * | |
| 892 | - * @param array $query | |
| 893 | - * @param int $limit | |
| 894 | - * @param string $inc_children | |
| 895 | - * @return array|object of forms A single form object would be passed if $limit was set to 1. | |
| 788 | + * @return array of forms | |
| 896 | 789 | */ |
| 897 | 790 | public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) { |
| 898 | 791 | $query['is_template'] = 0; |
| 899 | 792 | $query['status'] = array( null, '', 'published' ); |
| 900 | - if ( $inc_children === 'exclude' ) { | |
| 793 | + if ( $inc_children == 'exclude' ) { | |
| 901 | 794 | $query['parent_form_id'] = array( null, 0 ); |
| 902 | 795 | } |
| 903 | 796 | |
| 904 | 797 | $forms = self::getAll( $query, 'name', $limit ); |
| @@ -934,18 +827,18 @@ | ||
| 934 | 827 | |
| 935 | 828 | foreach ( $results as $row ) { |
| 936 | 829 | if ( 'trash' != $row->status ) { |
| 937 | 830 | if ( $row->is_template ) { |
| 938 | - ++$counts['template']; | |
| 831 | + $counts['template'] ++; | |
| 939 | 832 | } else { |
| 940 | - ++$counts['published']; | |
| 833 | + $counts['published'] ++; | |
| 941 | 834 | } |
| 942 | 835 | } else { |
| 943 | - ++$counts['trash']; | |
| 836 | + $counts['trash'] ++; | |
| 944 | 837 | } |
| 945 | 838 | |
| 946 | 839 | if ( 'draft' == $row->status ) { |
| 947 | - ++$counts['draft']; | |
| 840 | + $counts['draft'] ++; | |
| 948 | 841 | } |
| 949 | 842 | |
| 950 | 843 | unset( $row ); |
| 951 | 844 | } |
| @@ -1011,11 +904,11 @@ | ||
| 1011 | 904 | $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| 1012 | 905 | } |
| 1013 | 906 | |
| 1014 | 907 | if ( $form->id == $values['posted_form_id'] ) { |
| 1015 | - // If there are two forms on the same page, make sure not to submit both. | |
| 908 | + //if there are two forms on the same page, make sure not to submit both | |
| 1016 | 909 | foreach ( $default_values as $var => $default ) { |
| 1017 | - if ( $var === 'action' ) { | |
| 910 | + if ( $var == 'action' ) { | |
| 1018 | 911 | $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
| 1019 | 912 | } else { |
| 1020 | 913 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 1021 | 914 | } |
| @@ -1083,9 +976,9 @@ | ||
| 1083 | 976 | return $values; |
| 1084 | 977 | } |
| 1085 | 978 | |
| 1086 | 979 | public static function get_current_form_id( $default_form = 'none' ) { |
| 1087 | - if ( 'first' === $default_form ) { | |
| 980 | + if ( 'first' == $default_form ) { | |
| 1088 | 981 | $form = self::get_current_form(); |
| 1089 | 982 | } else { |
| 1090 | 983 | $form = self::maybe_get_current_form(); |
| 1091 | 984 | } |
| @@ -1096,9 +989,9 @@ | ||
| 1096 | 989 | |
| 1097 | 990 | public static function maybe_get_current_form( $form_id = 0 ) { |
| 1098 | 991 | global $frm_vars; |
| 1099 | 992 | |
| 1100 | - if ( ! empty( $frm_vars['current_form'] ) && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) { | |
| 993 | + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) { | |
| 1101 | 994 | return $frm_vars['current_form']; |
| 1102 | 995 | } |
| 1103 | 996 | |
| 1104 | 997 | $form_id = FrmAppHelper::get_param( 'form', $form_id, 'get', 'absint' ); |
| @@ -1145,9 +1038,9 @@ | ||
| 1145 | 1038 | $global_load = true; |
| 1146 | 1039 | $frm_vars['load_css'] = true; |
| 1147 | 1040 | } |
| 1148 | 1041 | |
| 1149 | - return empty( $frm_vars['css_loaded'] ) && $global_load; | |
| 1042 | + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load ); | |
| 1150 | 1043 | } |
| 1151 | 1044 | |
| 1152 | 1045 | /** |
| 1153 | 1046 | * @since 4.06.03 |
| @@ -1162,21 +1055,13 @@ | ||
| 1162 | 1055 | } else { |
| 1163 | 1056 | $visible = true; |
| 1164 | 1057 | } |
| 1165 | 1058 | |
| 1166 | - /** | |
| 1167 | - * @since 6.25 | |
| 1168 | - * | |
| 1169 | - * @param bool $visible | |
| 1170 | - * @param object $form | |
| 1171 | - */ | |
| 1172 | - $visible = (bool) apply_filters( 'frm_form_is_visible', $visible, $form ); | |
| 1173 | - | |
| 1174 | 1059 | return $visible; |
| 1175 | 1060 | } |
| 1176 | 1061 | |
| 1177 | 1062 | public static function show_submit( $form ) { |
| 1178 | - $show = ( ! $form->is_template && $form->status === 'published' && ! FrmAppHelper::is_admin() ); | |
| 1063 | + $show = ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() ); | |
| 1179 | 1064 | $show = apply_filters( 'frm_show_submit_button', $show, $form ); |
| 1180 | 1065 | |
| 1181 | 1066 | return $show; |
| 1182 | 1067 | } |
| @@ -1184,12 +1069,12 @@ | ||
| 1184 | 1069 | /** |
| 1185 | 1070 | * @since 2.3 |
| 1186 | 1071 | */ |
| 1187 | 1072 | public static function get_option( $atts ) { |
| 1188 | - $form = $atts['form']; | |
| 1189 | - $default = $atts['default'] ?? ''; | |
| 1073 | + $form = $atts['form']; | |
| 1074 | + $default = isset( $atts['default'] ) ? $atts['default'] : ''; | |
| 1190 | 1075 | |
| 1191 | - return $form->options[ $atts['option'] ] ?? $default; | |
| 1076 | + return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $default; | |
| 1192 | 1077 | } |
| 1193 | 1078 | |
| 1194 | 1079 | /** |
| 1195 | 1080 | * Get the link to edit this form. |
| @@ -1201,81 +1086,23 @@ | ||
| 1201 | 1086 | return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ); |
| 1202 | 1087 | } |
| 1203 | 1088 | |
| 1204 | 1089 | /** |
| 1205 | - * Check if the "Submit this form with AJAX" setting is toggled on. | |
| 1206 | - * | |
| 1207 | - * @since 6.2 | |
| 1208 | - * | |
| 1209 | - * @param stdClass $form | |
| 1210 | - * @return bool | |
| 1211 | - */ | |
| 1212 | - public static function is_ajax_on( $form ) { | |
| 1213 | - return ! empty( $form->options['ajax_submit'] ); | |
| 1214 | - } | |
| 1215 | - | |
| 1216 | - /** | |
| 1217 | - * Get the latest form available. | |
| 1218 | - * | |
| 1219 | - * @since 6.8 | |
| 1220 | - * @return object | |
| 1221 | - */ | |
| 1222 | - public static function get_latest_form() { | |
| 1223 | - | |
| 1224 | - $args = array( | |
| 1225 | - array( | |
| 1226 | - 'or' => 1, | |
| 1227 | - 'parent_form_id' => null, | |
| 1228 | - 'parent_form_id <' => 1, | |
| 1229 | - ), | |
| 1230 | - 'is_template' => 0, | |
| 1231 | - 'status !' => 'trash', | |
| 1232 | - ); | |
| 1233 | - | |
| 1234 | - return self::getAll( $args, 'created_at desc', 1 ); | |
| 1235 | - } | |
| 1236 | - | |
| 1237 | - /** | |
| 1238 | - * Count and return total forms. | |
| 1239 | - * | |
| 1240 | - * @since 6.8 | |
| 1241 | - * @return int | |
| 1242 | - */ | |
| 1243 | - public static function get_forms_count() { | |
| 1244 | - | |
| 1245 | - $args = array( | |
| 1246 | - array( | |
| 1247 | - 'or' => 1, | |
| 1248 | - 'parent_form_id' => null, | |
| 1249 | - 'parent_form_id <' => 1, | |
| 1250 | - ), | |
| 1251 | - 'is_template' => 0, | |
| 1252 | - 'status !' => 'trash', | |
| 1253 | - ); | |
| 1254 | - | |
| 1255 | - return FrmDb::get_count( 'frm_forms', $args ); | |
| 1256 | - } | |
| 1257 | - | |
| 1258 | - /** | |
| 1259 | - * @deprecated 2.03.05 This is still referenced in a few add ons (API, locations). | |
| 1090 | + * @deprecated 3.0 | |
| 1260 | 1091 | * @codeCoverageIgnore |
| 1261 | 1092 | * |
| 1262 | 1093 | * @param string $key |
| 1094 | + * | |
| 1263 | 1095 | * @return int form id |
| 1264 | 1096 | */ |
| 1265 | 1097 | public static function getIdByKey( $key ) { |
| 1266 | - _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_id_by_key' ); | |
| 1267 | - return self::get_id_by_key( $key ); | |
| 1098 | + return FrmFormDeprecated::getIdByKey( $key ); | |
| 1268 | 1099 | } |
| 1269 | 1100 | |
| 1270 | 1101 | /** |
| 1271 | - * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13. | |
| 1102 | + * @deprecated 3.0 | |
| 1272 | 1103 | * @codeCoverageIgnore |
| 1273 | - * | |
| 1274 | - * @param int|string $id | |
| 1275 | - * @return string | |
| 1276 | 1104 | */ |
| 1277 | 1105 | public static function getKeyById( $id ) { |
| 1278 | - _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_key_by_id' ); | |
| 1279 | - return self::get_key_by_id( $id ); | |
| 1106 | + return FrmFormDeprecated::getKeyById( $id ); | |
| 1280 | 1107 | } |
| 1281 | 1108 | } |