| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | class FrmForm { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * @param array $values |
| 10 | - * @return int|bool 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 | |
| @@ -32,18 +32,9 @@ | ||
| 32 | 32 | $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' ); |
| 33 | 33 | $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' ); |
| 34 | 34 | $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); |
| 35 | 35 | |
| 36 | - /** | |
| 37 | - * Allows modifying form options before updating or creating. | |
| 38 | - * | |
| 39 | - * @since 5.4 Add the third param. | |
| 40 | - * | |
| 41 | - * @param array $options Form options. | |
| 42 | - * @param array $values Form data. | |
| 43 | - * @param bool $update Is form updating or creating. It's `true` if is updating. | |
| 44 | - */ | |
| 45 | - $options = apply_filters( 'frm_form_options_before_update', $options, $values, false ); | |
| 36 | + $options = apply_filters( 'frm_form_options_before_update', $options, $values ); | |
| 46 | 37 | $options = self::maybe_filter_form_options( $options ); |
| 47 | 38 | $new_values['options'] = serialize( $options ); |
| 48 | 39 | |
| 49 | 40 | $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
| @@ -62,12 +53,9 @@ | ||
| 62 | 53 | * @param array $options |
| 63 | 54 | * @return array |
| 64 | 55 | */ |
| 65 | 56 | private static function maybe_filter_form_options( $options ) { |
| 66 | - if ( ! FrmAppHelper::allow_unfiltered_html() && ! empty( $options['submit_html'] ) ) { | |
| 67 | - $options['submit_html'] = FrmAppHelper::kses_submit_button( $options['submit_html'] ); | |
| 68 | - } | |
| 69 | - return FrmAppHelper::maybe_filter_array( $options, array( 'submit_value', 'success_msg', 'before_html', 'after_html' ) ); | |
| 57 | + return FrmAppHelper::maybe_filter_array( $options, array( 'submit_value', 'success_msg', 'before_html', 'after_html', 'submit_html' ) ); | |
| 70 | 58 | } |
| 71 | 59 | |
| 72 | 60 | /** |
| 73 | 61 | * @return int|boolean ID on success or false on failure |
| @@ -140,86 +128,11 @@ | ||
| 140 | 128 | if ( $new_opts != $values['options'] ) { |
| 141 | 129 | global $wpdb; |
| 142 | 130 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) ); |
| 143 | 131 | } |
| 144 | - | |
| 145 | - self::switch_field_ids_in_fields( $form_id ); | |
| 146 | 132 | } |
| 147 | 133 | |
| 148 | 134 | /** |
| 149 | - * Switches field ID in fields. | |
| 150 | - * | |
| 151 | - * @since 5.3 | |
| 152 | - * | |
| 153 | - * @param int $form_id Form ID. | |
| 154 | - */ | |
| 155 | - private static function switch_field_ids_in_fields( $form_id ) { | |
| 156 | - global $wpdb; | |
| 157 | - | |
| 158 | - // Keys of fields that you want to check to replace field ID. | |
| 159 | - $keys = array( 'default_value', 'field_options' ); | |
| 160 | - $sql_cols = 'fi.id'; | |
| 161 | - foreach ( $keys as $key ) { | |
| 162 | - $sql_cols .= ( ',fi.' . $key ); | |
| 163 | - } | |
| 164 | - | |
| 165 | - $fields = FrmDb::get_results( | |
| 166 | - "{$wpdb->prefix}frm_fields AS fi LEFT OUTER JOIN {$wpdb->prefix}frm_forms AS fr ON fi.form_id = fr.id", | |
| 167 | - array( | |
| 168 | - 'or' => 1, | |
| 169 | - 'fi.form_id' => $form_id, | |
| 170 | - 'fr.parent_form_id' => $form_id, | |
| 171 | - ), | |
| 172 | - $sql_cols | |
| 173 | - ); | |
| 174 | - | |
| 175 | - if ( ! $fields || ! is_array( $fields ) ) { | |
| 176 | - return; | |
| 177 | - } | |
| 178 | - | |
| 179 | - foreach ( $fields as $field ) { | |
| 180 | - self::switch_field_ids_in_field( (array) $field ); | |
| 181 | - } | |
| 182 | - } | |
| 183 | - | |
| 184 | - /** | |
| 185 | - * Switches field ID in a field. | |
| 186 | - * | |
| 187 | - * @since 5.3 | |
| 188 | - * | |
| 189 | - * @param array $field Field array. | |
| 190 | - */ | |
| 191 | - private static function switch_field_ids_in_field( $field ) { | |
| 192 | - $new_values = array(); | |
| 193 | - foreach ( $field as $key => $value ) { | |
| 194 | - if ( 'id' === $key || ! $value ) { | |
| 195 | - continue; | |
| 196 | - } | |
| 197 | - | |
| 198 | - if ( ! is_string( $value ) && ! is_array( $value ) ) { | |
| 199 | - continue; | |
| 200 | - } | |
| 201 | - | |
| 202 | - if ( 'field_options' === $key ) { | |
| 203 | - // Need to loop through field_options to prevent breaking serialized string when length changed. | |
| 204 | - FrmAppHelper::unserialize_or_decode( $value ); | |
| 205 | - $new_val = FrmFieldsHelper::switch_field_ids( $value ); | |
| 206 | - $new_val = serialize( $new_val ); | |
| 207 | - } else { | |
| 208 | - $new_val = FrmFieldsHelper::switch_field_ids( $value ); | |
| 209 | - } | |
| 210 | - | |
| 211 | - if ( $new_val !== $value ) { | |
| 212 | - $new_values[ $key ] = $new_val; | |
| 213 | - } | |
| 214 | - } | |
| 215 | - | |
| 216 | - if ( ! empty( $new_values ) ) { | |
| 217 | - FrmField::update( $field['id'], $new_values ); | |
| 218 | - } | |
| 219 | - } | |
| 220 | - | |
| 221 | - /** | |
| 222 | 135 | * @return int|boolean |
| 223 | 136 | */ |
| 224 | 137 | public static function update( $id, $values, $create_link = false ) { |
| 225 | 138 | global $wpdb; |
| @@ -235,9 +148,9 @@ | ||
| 235 | 148 | } |
| 236 | 149 | |
| 237 | 150 | $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' ); |
| 238 | 151 | |
| 239 | - $new_values = self::set_update_options( array(), $values, array( 'form_id' => $id ) ); | |
| 152 | + $new_values = self::set_update_options( array(), $values ); | |
| 240 | 153 | |
| 241 | 154 | foreach ( $values as $value_key => $value ) { |
| 242 | 155 | if ( $value_key && in_array( $value_key, $form_fields ) ) { |
| 243 | 156 | $new_values[ $value_key ] = $value; |
| @@ -266,14 +179,11 @@ | ||
| 266 | 179 | return $query_results; |
| 267 | 180 | } |
| 268 | 181 | |
| 269 | 182 | /** |
| 270 | - * @param array $new_values | |
| 271 | - * @param array $values | |
| 272 | - * @param array $args | |
| 273 | 183 | * @return array |
| 274 | 184 | */ |
| 275 | - public static function set_update_options( $new_values, $values, $args = array() ) { | |
| 185 | + public static function set_update_options( $new_values, $values ) { | |
| 276 | 186 | if ( ! isset( $values['options'] ) ) { |
| 277 | 187 | return $new_values; |
| 278 | 188 | } |
| 279 | 189 | |
| @@ -284,18 +194,9 @@ | ||
| 284 | 194 | $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' ); |
| 285 | 195 | $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' ); |
| 286 | 196 | $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); |
| 287 | 197 | |
| 288 | - /** | |
| 289 | - * Allows modifying form options before updating or creating. | |
| 290 | - * | |
| 291 | - * @since 5.4 Added the third param. | |
| 292 | - * | |
| 293 | - * @param array $options Form options. | |
| 294 | - * @param array $values Form data. | |
| 295 | - * @param bool $update Is form updating or creating. It's `true` if is updating. | |
| 296 | - */ | |
| 297 | - $options = apply_filters( 'frm_form_options_before_update', $options, $values, true ); | |
| 198 | + $options = apply_filters( 'frm_form_options_before_update', $options, $values ); | |
| 298 | 199 | $options = self::maybe_filter_form_options( $options ); |
| 299 | 200 | $new_values['options'] = serialize( $options ); |
| 300 | 201 | |
| 301 | 202 | return $new_values; |
| @@ -365,18 +266,8 @@ | ||
| 365 | 266 | 'field_options' => $field->field_options, |
| 366 | 267 | 'default_value' => isset( $values[ 'default_value_' . $field_id ] ) ? FrmAppHelper::maybe_json_encode( $values[ 'default_value_' . $field_id ] ) : '', |
| 367 | 268 | ); |
| 368 | 269 | |
| 369 | - if ( ! FrmAppHelper::allow_unfiltered_html() && isset( $values['field_options'][ 'options_' . $field_id ] ) && is_array( $values['field_options'][ 'options_' . $field_id ] ) ) { | |
| 370 | - foreach ( $values['field_options'][ 'options_' . $field_id ] as $option_key => $option ) { | |
| 371 | - if ( is_array( $option ) ) { | |
| 372 | - foreach ( $option as $key => $item ) { | |
| 373 | - $values['field_options'][ 'options_' . $field_id ][ $option_key ][ $key ] = FrmAppHelper::kses( $item, 'all' ); | |
| 374 | - } | |
| 375 | - } | |
| 376 | - } | |
| 377 | - } | |
| 378 | - | |
| 379 | 270 | self::prepare_field_update_values( $field, $values, $new_field ); |
| 380 | 271 | |
| 381 | 272 | FrmField::update( $field_id, $new_field ); |
| 382 | 273 | |
| @@ -386,40 +277,17 @@ | ||
| 386 | 277 | |
| 387 | 278 | return $values; |
| 388 | 279 | } |
| 389 | 280 | |
| 390 | - /** | |
| 391 | - * @param string $opt | |
| 392 | - * @param mixed $value | |
| 393 | - * @return void | |
| 394 | - */ | |
| 395 | 281 | private static function sanitize_field_opt( $opt, &$value ) { |
| 396 | - if ( ! is_string( $value ) ) { | |
| 397 | - return; | |
| 282 | + if ( is_string( $value ) ) { | |
| 283 | + if ( $opt === 'calc' ) { | |
| 284 | + $value = self::sanitize_calc( $value ); | |
| 285 | + } else { | |
| 286 | + $value = FrmAppHelper::kses( $value, 'all' ); | |
| 287 | + } | |
| 288 | + $value = trim( $value ); | |
| 398 | 289 | } |
| 399 | - | |
| 400 | - /** | |
| 401 | - * Allow the option to turn off sanitization for a field. This way a custom rule can be used instead. | |
| 402 | - * Make sure to add custom sanitization using the frm_update_field_options filter as the data will no longer be sanitized. | |
| 403 | - * | |
| 404 | - * @since 6.0 | |
| 405 | - * | |
| 406 | - * @param bool $should_sanitize | |
| 407 | - * @param string $opt | |
| 408 | - */ | |
| 409 | - $should_sanitize = apply_filters( 'frm_should_sanitize_field_opt_string', true, $opt ); | |
| 410 | - | |
| 411 | - if ( ! $should_sanitize ) { | |
| 412 | - return; | |
| 413 | - } | |
| 414 | - | |
| 415 | - if ( $opt === 'calc' ) { | |
| 416 | - $value = self::sanitize_calc( $value ); | |
| 417 | - } else { | |
| 418 | - $value = FrmAppHelper::kses( $value, 'all' ); | |
| 419 | - } | |
| 420 | - | |
| 421 | - $value = trim( $value ); | |
| 422 | 290 | } |
| 423 | 291 | |
| 424 | 292 | /** |
| 425 | 293 | * @param string $value |
| @@ -510,12 +378,8 @@ | ||
| 510 | 378 | 'description', |
| 511 | 379 | 'submit_value', |
| 512 | 380 | 'submit_msg', |
| 513 | 381 | 'success_msg', |
| 514 | - 'invalid_msg', | |
| 515 | - 'failed_msg', | |
| 516 | - 'login_msg', | |
| 517 | - 'admin_permission', | |
| 518 | 382 | ); |
| 519 | 383 | |
| 520 | 384 | return apply_filters( 'frm_form_strings', $strings, $form ); |
| 521 | 385 | } |
| @@ -545,9 +409,9 @@ | ||
| 545 | 409 | ); |
| 546 | 410 | FrmDb::get_where_clause_and_values( $where ); |
| 547 | 411 | array_unshift( $where['values'], $status ); |
| 548 | 412 | |
| 549 | - $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 413 | + $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // WPCS: unprepared SQL ok. | |
| 550 | 414 | } else { |
| 551 | 415 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) ); |
| 552 | 416 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) ); |
| 553 | 417 | } |
| @@ -653,9 +517,9 @@ | ||
| 653 | 517 | |
| 654 | 518 | $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, options' ); |
| 655 | 519 | |
| 656 | 520 | if ( ! $trash_forms ) { |
| 657 | - return 0; | |
| 521 | + return; | |
| 658 | 522 | } |
| 659 | 523 | |
| 660 | 524 | if ( empty( $delete_timestamp ) ) { |
| 661 | 525 | $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
| @@ -754,9 +618,9 @@ | ||
| 754 | 618 | if ( isset( $cache->options ) ) { |
| 755 | 619 | FrmAppHelper::unserialize_or_decode( $cache->options ); |
| 756 | 620 | } |
| 757 | 621 | |
| 758 | - return apply_filters( 'frm_form_object', wp_unslash( $cache ) ); | |
| 622 | + return wp_unslash( $cache ); | |
| 759 | 623 | } |
| 760 | 624 | } |
| 761 | 625 | |
| 762 | 626 | if ( is_numeric( $id ) ) { |
| @@ -790,9 +654,9 @@ | ||
| 790 | 654 | global $wpdb; |
| 791 | 655 | |
| 792 | 656 | // the query has already been prepared if this is not an array |
| 793 | 657 | $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit ); |
| 794 | - $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 658 | + $results = $wpdb->get_results( $query ); // WPCS: unprepared SQL ok. | |
| 795 | 659 | } |
| 796 | 660 | |
| 797 | 661 | if ( $results ) { |
| 798 | 662 | foreach ( $results as $result ) { |
| @@ -812,13 +676,9 @@ | ||
| 812 | 676 | /** |
| 813 | 677 | * Get all published forms |
| 814 | 678 | * |
| 815 | 679 | * @since 2.0 |
| 816 | - * | |
| 817 | - * @param array $query | |
| 818 | - * @param int $limit | |
| 819 | - * @param string $inc_children | |
| 820 | - * @return array|object of forms A single form object would be passed if $limit was set to 1. | |
| 680 | + * @return array of forms | |
| 821 | 681 | */ |
| 822 | 682 | public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) { |
| 823 | 683 | $query['is_template'] = 0; |
| 824 | 684 | $query['status'] = array( null, '', 'published' ); |
| @@ -913,9 +773,9 @@ | ||
| 913 | 773 | if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) { |
| 914 | 774 | return $frm_vars['form_params'][ $form->id ]; |
| 915 | 775 | } |
| 916 | 776 | |
| 917 | - $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 777 | + $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; // WPCS: CSRF ok. | |
| 918 | 778 | $action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form ); |
| 919 | 779 | |
| 920 | 780 | $default_values = array( |
| 921 | 781 | 'id' => '', |
| @@ -953,9 +813,9 @@ | ||
| 953 | 813 | } |
| 954 | 814 | } |
| 955 | 815 | |
| 956 | 816 | if ( in_array( $values['action'], array( 'create', 'update' ) ) && |
| 957 | - ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 817 | + ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) // WPCS: CSRF ok. | |
| 958 | 818 | ) { |
| 959 | 819 | $values['action'] = 'new'; |
| 960 | 820 | } |
| 961 | 821 | |
| @@ -1118,39 +978,23 @@ | ||
| 1118 | 978 | return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ); |
| 1119 | 979 | } |
| 1120 | 980 | |
| 1121 | 981 | /** |
| 1122 | - * Check if the "Submit this form with AJAX" setting is toggled on. | |
| 1123 | - * | |
| 1124 | - * @since 6.2 | |
| 1125 | - * | |
| 1126 | - * @param stdClass $form | |
| 1127 | - * @return bool | |
| 1128 | - */ | |
| 1129 | - public static function is_ajax_on( $form ) { | |
| 1130 | - return ! empty( $form->options['ajax_submit'] ); | |
| 1131 | - } | |
| 1132 | - | |
| 1133 | - /** | |
| 1134 | - * @deprecated 2.03.05 This is still referenced in a few add ons (API, locations). | |
| 982 | + * @deprecated 3.0 | |
| 1135 | 983 | * @codeCoverageIgnore |
| 1136 | 984 | * |
| 1137 | 985 | * @param string $key |
| 986 | + * | |
| 1138 | 987 | * @return int form id |
| 1139 | 988 | */ |
| 1140 | 989 | public static function getIdByKey( $key ) { |
| 1141 | - _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_id_by_key' ); | |
| 1142 | - return self::get_id_by_key( $key ); | |
| 990 | + return FrmFormDeprecated::getIdByKey( $key ); | |
| 1143 | 991 | } |
| 1144 | 992 | |
| 1145 | 993 | /** |
| 1146 | - * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13. | |
| 994 | + * @deprecated 3.0 | |
| 1147 | 995 | * @codeCoverageIgnore |
| 1148 | - * | |
| 1149 | - * @param string|int $id | |
| 1150 | - * @return string | |
| 1151 | 996 | */ |
| 1152 | 997 | public static function getKeyById( $id ) { |
| 1153 | - _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_key_by_id' ); | |
| 1154 | - return self::get_key_by_id( $id ); | |
| 998 | + return FrmFormDeprecated::getKeyById( $id ); | |
| 1155 | 999 | } |
| 1156 | 1000 | } |