@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined('ABSPATH') ) { |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | 3 | die( 'You are not allowed to call this page directly.' ); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | static $transient_size = 200; |
| 10 | 10 | |
| 11 | 11 | public static function field_selection() { |
| 12 | - $fields = apply_filters('frm_available_fields', array( |
|
| 12 | + $fields = apply_filters( 'frm_available_fields', array( |
|
| 13 | 13 | 'text' => __( 'Single Line Text', 'formidable' ), |
| 14 | 14 | 'textarea' => __( 'Paragraph Text', 'formidable' ), |
| 15 | 15 | 'checkbox' => __( 'Checkboxes', 'formidable' ), |
@@ -18,13 +18,13 @@ discard block |
||
| 18 | 18 | 'email' => __( 'Email Address', 'formidable' ), |
| 19 | 19 | 'url' => __( 'Website/URL', 'formidable' ), |
| 20 | 20 | 'captcha' => __( 'reCAPTCHA', 'formidable' ), |
| 21 | - )); |
|
| 21 | + ) ); |
|
| 22 | 22 | |
| 23 | 23 | return $fields; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public static function pro_field_selection() { |
| 27 | - return apply_filters('frm_pro_available_fields', array( |
|
| 27 | + return apply_filters( 'frm_pro_available_fields', array( |
|
| 28 | 28 | 'end_divider' => array( |
| 29 | 29 | 'name' => __( 'End Section', 'formidable' ), |
| 30 | 30 | 'switch_from' => 'divider', |
@@ -49,36 +49,36 @@ discard block |
||
| 49 | 49 | 'tag' => __( 'Tags', 'formidable' ), |
| 50 | 50 | 'credit_card' => __( 'Credit Card', 'formidable' ), |
| 51 | 51 | 'address' => __( 'Address', 'formidable' ), |
| 52 | - )); |
|
| 52 | + ) ); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public static function create( $values, $return = true ) { |
| 56 | 56 | global $wpdb, $frm_duplicate_ids; |
| 57 | 57 | |
| 58 | 58 | $new_values = array(); |
| 59 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
| 59 | + $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name']; |
|
| 60 | 60 | $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
| 61 | 61 | |
| 62 | 62 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
| 63 | - $new_values[ $col ] = $values[ $col ]; |
|
| 63 | + $new_values[$col] = $values[$col]; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | $new_values['options'] = $values['options']; |
| 67 | 67 | |
| 68 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
| 69 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
| 70 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
| 68 | + $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null; |
|
| 69 | + $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0; |
|
| 70 | + $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null; |
|
| 71 | 71 | $new_values['field_options'] = $values['field_options']; |
| 72 | - $new_values['created_at'] = current_time('mysql', 1); |
|
| 72 | + $new_values['created_at'] = current_time( 'mysql', 1 ); |
|
| 73 | 73 | |
| 74 | 74 | if ( isset( $values['id'] ) ) { |
| 75 | - $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
|
| 76 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
| 75 | + $frm_duplicate_ids[$values['field_key']] = $new_values['field_key']; |
|
| 76 | + $new_values = apply_filters( 'frm_duplicated_field', $new_values ); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | foreach ( $new_values as $k => $v ) { |
| 80 | 80 | if ( is_array( $v ) ) { |
| 81 | - $new_values[ $k ] = serialize( $v ); |
|
| 81 | + $new_values[$k] = serialize( $v ); |
|
| 82 | 82 | } |
| 83 | 83 | unset( $k, $v ); |
| 84 | 84 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | if ( $query_results ) { |
| 101 | 101 | if ( isset( $values['id'] ) ) { |
| 102 | - $frm_duplicate_ids[ $values['id'] ] = $new_id; |
|
| 102 | + $frm_duplicate_ids[$values['id']] = $new_id; |
|
| 103 | 103 | } |
| 104 | 104 | return $new_id; |
| 105 | 105 | } else { |
@@ -114,9 +114,9 @@ discard block |
||
| 114 | 114 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
| 115 | 115 | |
| 116 | 116 | foreach ( (array) $fields as $field ) { |
| 117 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
| 118 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
| 119 | - $new_key = rtrim($new_key, 2); |
|
| 117 | + $new_key = ( $copy_keys ) ? $field->field_key : ''; |
|
| 118 | + if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) { |
|
| 119 | + $new_key = rtrim( $new_key, 2 ); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | $values = array(); |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | $values['form_id'] = $new_repeat_form_id; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - $values = apply_filters('frm_duplicated_field', $values); |
|
| 143 | - $new_id = self::create($values); |
|
| 144 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
| 145 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
| 146 | - unset($field); |
|
| 142 | + $values = apply_filters( 'frm_duplicated_field', $values ); |
|
| 143 | + $new_id = self::create( $values ); |
|
| 144 | + $frm_duplicate_ids[$field->id] = $new_id; |
|
| 145 | + $frm_duplicate_ids[$field->field_key] = $new_id; |
|
| 146 | + unset( $field ); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id ); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if ( isset($values['required']) ) { |
|
| 159 | + if ( isset( $values['required'] ) ) { |
|
| 160 | 160 | $values['required'] = (int) $values['required']; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | // serialize array values |
| 175 | 175 | foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) { |
| 176 | - if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) { |
|
| 177 | - $values[ $opt ] = serialize( $values[ $opt ] ); |
|
| 176 | + if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) { |
|
| 177 | + $values[$opt] = serialize( $values[$opt] ); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
@@ -184,13 +184,13 @@ discard block |
||
| 184 | 184 | if ( isset( $values['form_id'] ) ) { |
| 185 | 185 | $form_id = absint( $values['form_id'] ); |
| 186 | 186 | } else { |
| 187 | - $field = self::getOne($id); |
|
| 187 | + $field = self::getOne( $id ); |
|
| 188 | 188 | if ( $field ) { |
| 189 | 189 | $form_id = $field->form_id; |
| 190 | 190 | } |
| 191 | - unset($field); |
|
| 191 | + unset( $field ); |
|
| 192 | 192 | } |
| 193 | - unset($values); |
|
| 193 | + unset( $values ); |
|
| 194 | 194 | |
| 195 | 195 | if ( $query_results ) { |
| 196 | 196 | wp_cache_delete( $id, 'frm_field' ); |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | FrmAppHelper::cache_delete_group( 'frm_field' ); |
| 245 | 245 | |
| 246 | - $form = FrmForm::getOne($form_id); |
|
| 246 | + $form = FrmForm::getOne( $form_id ); |
|
| 247 | 247 | if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) { |
| 248 | 248 | self::delete_form_transient( $form->parent_form_id ); |
| 249 | 249 | } |
@@ -265,16 +265,16 @@ discard block |
||
| 265 | 265 | |
| 266 | 266 | global $wpdb; |
| 267 | 267 | |
| 268 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
| 268 | + $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s'; |
|
| 269 | 269 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); |
| 270 | 270 | |
| 271 | 271 | $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
| 272 | 272 | |
| 273 | - if ( empty($results) ) { |
|
| 273 | + if ( empty( $results ) ) { |
|
| 274 | 274 | return $results; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - if ( is_numeric($id) ) { |
|
| 277 | + if ( is_numeric( $id ) ) { |
|
| 278 | 278 | FrmAppHelper::set_cache( $results->field_key, $results, 'frm_field' ); |
| 279 | 279 | } else if ( $results ) { |
| 280 | 280 | FrmAppHelper::set_cache( $results->id, $results, 'frm_field' ); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | |
| 283 | 283 | self::prepare_options( $results ); |
| 284 | 284 | |
| 285 | - return stripslashes_deep($results); |
|
| 285 | + return stripslashes_deep( $results ); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -315,20 +315,20 @@ discard block |
||
| 315 | 315 | continue; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $fields[ $result->id ] = $result; |
|
| 319 | - $count++; |
|
| 318 | + $fields[$result->id] = $result; |
|
| 319 | + $count ++; |
|
| 320 | 320 | if ( $limit == 1 ) { |
| 321 | 321 | $fields = $result; |
| 322 | 322 | break; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 325 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
| 326 | 326 | break; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - unset($result); |
|
| 329 | + unset( $result ); |
|
| 330 | 330 | } |
| 331 | - return stripslashes_deep($fields); |
|
| 331 | + return stripslashes_deep( $fields ); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | self::$use_cache = false; |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
| 338 | 338 | $results = self::getAll( $where, 'field_order', $limit ); |
| 339 | 339 | self::$use_cache = true; |
| 340 | - self::include_sub_fields($results, $inc_sub, $type); |
|
| 340 | + self::include_sub_fields( $results, $inc_sub, $type ); |
|
| 341 | 341 | |
| 342 | 342 | return $results; |
| 343 | 343 | } |
@@ -349,15 +349,15 @@ discard block |
||
| 349 | 349 | |
| 350 | 350 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 351 | 351 | if ( ! empty( $results ) ) { |
| 352 | - if ( empty($limit) ) { |
|
| 352 | + if ( empty( $limit ) ) { |
|
| 353 | 353 | return $results; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | $fields = array(); |
| 357 | 357 | $count = 0; |
| 358 | 358 | foreach ( $results as $result ) { |
| 359 | - $fields[ $result->id ] = $result; |
|
| 360 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 359 | + $fields[$result->id] = $result; |
|
| 360 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
| 361 | 361 | break; |
| 362 | 362 | } |
| 363 | 363 | } |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | |
| 376 | 376 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
| 377 | 377 | |
| 378 | - if ( empty($limit) ) { |
|
| 378 | + if ( empty( $limit ) ) { |
|
| 379 | 379 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 380 | 380 | } |
| 381 | 381 | |
@@ -404,22 +404,22 @@ discard block |
||
| 404 | 404 | $form_fields = $results; |
| 405 | 405 | $index_offset = 1; |
| 406 | 406 | foreach ( $form_fields as $k => $field ) { |
| 407 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
| 407 | + if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) { |
|
| 408 | 408 | continue; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | if ( $type == 'all' ) { |
| 412 | 412 | $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
| 413 | 413 | } else { |
| 414 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
| 414 | + $sub_fields = self::get_all_types_in_form( $field->form_id, $type ); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | - if ( ! empty($sub_fields) ) { |
|
| 417 | + if ( ! empty( $sub_fields ) ) { |
|
| 418 | 418 | $index = $k + $index_offset; |
| 419 | 419 | $index_offset += count( $sub_fields ); |
| 420 | - array_splice($results, $index, 0, $sub_fields); |
|
| 420 | + array_splice( $results, $index, 0, $sub_fields ); |
|
| 421 | 421 | } |
| 422 | - unset($field, $sub_fields); |
|
| 422 | + unset( $field, $sub_fields ); |
|
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | |
@@ -427,9 +427,9 @@ discard block |
||
| 427 | 427 | $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
| 428 | 428 | if ( self::$use_cache ) { |
| 429 | 429 | // make sure old cache doesn't get saved as a transient |
| 430 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
| 430 | + $results = wp_cache_get( $cache_key, 'frm_field' ); |
|
| 431 | 431 | if ( false !== $results ) { |
| 432 | - return stripslashes_deep($results); |
|
| 432 | + return stripslashes_deep( $results ); |
|
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | |
@@ -454,16 +454,16 @@ discard block |
||
| 454 | 454 | $order_by = ' ORDER BY ' . $order_by; |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - $limit = FrmAppHelper::esc_limit($limit); |
|
| 457 | + $limit = FrmAppHelper::esc_limit( $limit ); |
|
| 458 | 458 | |
| 459 | 459 | $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
| 460 | 460 | $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
| 461 | 461 | |
| 462 | - if ( is_array($where) ) { |
|
| 462 | + if ( is_array( $where ) ) { |
|
| 463 | 463 | $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type ); |
| 464 | 464 | } else { |
| 465 | 465 | // if the query is not an array, then it has already been prepared |
| 466 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
| 466 | + $query .= FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
| 467 | 467 | |
| 468 | 468 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
| 469 | 469 | $results = $wpdb->$function_name( $query ); |
@@ -486,9 +486,9 @@ discard block |
||
| 486 | 486 | FrmAppHelper::set_cache( $result->id, $result, 'frm_field' ); |
| 487 | 487 | FrmAppHelper::set_cache( $result->field_key, $result, 'frm_field' ); |
| 488 | 488 | |
| 489 | - $results[ $r_key ]->field_options = maybe_unserialize( $result->field_options ); |
|
| 490 | - $results[ $r_key ]->options = maybe_unserialize( $result->options ); |
|
| 491 | - $results[ $r_key ]->default_value = maybe_unserialize( $result->default_value ); |
|
| 489 | + $results[$r_key]->field_options = maybe_unserialize( $result->field_options ); |
|
| 490 | + $results[$r_key]->options = maybe_unserialize( $result->options ); |
|
| 491 | + $results[$r_key]->default_value = maybe_unserialize( $result->default_value ); |
|
| 492 | 492 | |
| 493 | 493 | unset( $r_key, $result ); |
| 494 | 494 | } |
@@ -507,8 +507,8 @@ discard block |
||
| 507 | 507 | private static function prepare_options( &$results ) { |
| 508 | 508 | $results->field_options = maybe_unserialize( $results->field_options ); |
| 509 | 509 | |
| 510 | - $results->options = maybe_unserialize($results->options); |
|
| 511 | - $results->default_value = maybe_unserialize($results->default_value); |
|
| 510 | + $results->options = maybe_unserialize( $results->options ); |
|
| 511 | + $results->default_value = maybe_unserialize( $results->default_value ); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | |
| 536 | 536 | if ( count( $next_fields ) >= self::$transient_size ) { |
| 537 | 537 | // if this transient is full, check for another |
| 538 | - $next++; |
|
| 538 | + $next ++; |
|
| 539 | 539 | self::get_next_transient( $fields, $base_name, $next ); |
| 540 | 540 | } |
| 541 | 541 | } |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | return; |
| 562 | 562 | } |
| 563 | 563 | |
| 564 | - $next++; |
|
| 564 | + $next ++; |
|
| 565 | 565 | } |
| 566 | 566 | } |
| 567 | 567 | |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | $field_type = is_array( $field ) ? $field['type'] : $field->type; |
| 616 | 616 | $data_type = self::get_option( $field, 'data_type' ); |
| 617 | 617 | |
| 618 | - return self::is_option_true( $field, 'multiple' ) && ( ( $field_type == 'select' || ( $field_type == 'data' && $data_type == 'select') ) ); |
|
| 618 | + return self::is_option_true( $field, 'multiple' ) && ( ( $field_type == 'select' || ( $field_type == 'data' && $data_type == 'select' ) ) ); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
@@ -661,23 +661,23 @@ discard block |
||
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | public static function is_option_true_in_array( $field, $option ) { |
| 664 | - return isset( $field[ $option ] ) && $field[ $option ]; |
|
| 664 | + return isset( $field[$option] ) && $field[$option]; |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | public static function is_option_true_in_object( $field, $option ) { |
| 668 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ]; |
|
| 668 | + return isset( $field->field_options[$option] ) && $field->field_options[$option]; |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | public static function is_option_empty_in_array( $field, $option ) { |
| 672 | - return ! isset( $field[ $option ] ) || empty( $field[ $option ] ); |
|
| 672 | + return ! isset( $field[$option] ) || empty( $field[$option] ); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | public static function is_option_empty_in_object( $field, $option ) { |
| 676 | - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] ); |
|
| 676 | + return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] ); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | public static function is_option_value_in_object( $field, $option ) { |
| 680 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != ''; |
|
| 680 | + return isset( $field->field_options[$option] ) && $field->field_options[$option] != ''; |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | /** |
@@ -693,11 +693,11 @@ discard block |
||
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | public static function get_option_in_array( $field, $option ) { |
| 696 | - return isset( $field[ $option ] ) ? $field[ $option ] : ''; |
|
| 696 | + return isset( $field[$option] ) ? $field[$option] : ''; |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | public static function get_option_in_object( $field, $option ) { |
| 700 | - return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : ''; |
|
| 700 | + return isset( $field->field_options[$option] ) ? $field->field_options[$option] : ''; |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | /** |