| @@ -5,8 +5,17 @@ | ||
| 5 | 5 | |
| 6 | 6 | class FrmFormsHelper { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | + * Store and re-use field type data for the insert_opt_html function (to avoid multiple calls to FrmField::all_field_selection). | |
| 10 | + * | |
| 11 | + * @since 6.10 | |
| 12 | + * | |
| 13 | + * @var array|null | |
| 14 | + */ | |
| 15 | + private static $field_type_data_for_insert_opt_html; | |
| 16 | + | |
| 17 | + /** | |
| 9 | 18 | * @since 2.2.10 |
| 10 | 19 | */ |
| 11 | 20 | public static function form_error_class() { |
| 12 | 21 | return apply_filters( 'frm_form_error_class', 'frm_error_style' ); |
| @@ -49,9 +58,9 @@ | ||
| 49 | 58 | <select name="<?php echo esc_attr( $field_name ); ?>" |
| 50 | 59 | id="<?php echo esc_attr( $args['field_id'] ); ?>" |
| 51 | 60 | <?php echo wp_strip_all_tags( implode( ' ', $add_html ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> |
| 52 | 61 | <?php if ( $args['blank'] ) { ?> |
| 53 | - <option value=""><?php echo ( $args['blank'] == 1 ) ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option> | |
| 62 | + <option value=""><?php echo $args['blank'] == 1 ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option> | |
| 54 | 63 | <?php } ?> |
| 55 | 64 | <?php foreach ( $forms as $form ) { ?> |
| 56 | 65 | <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>> |
| 57 | 66 | <?php echo esc_html( '' === $form->name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?> |
| @@ -61,13 +70,12 @@ | ||
| 61 | 70 | <?php |
| 62 | 71 | } |
| 63 | 72 | |
| 64 | 73 | /** |
| 74 | + * @since 2.0.6 | |
| 65 | 75 | * @param string $class |
| 66 | 76 | * @param string $param |
| 67 | - * @param array $add_html | |
| 68 | - * | |
| 69 | - * @since 2.0.6 | |
| 77 | + * @param array $add_html | |
| 70 | 78 | */ |
| 71 | 79 | public static function add_html_attr( $class, $param, &$add_html ) { |
| 72 | 80 | if ( ! empty( $class ) ) { |
| 73 | 81 | $add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( trim( sanitize_text_field( $class ) ) ) . '"'; |
| @@ -74,9 +82,9 @@ | ||
| 74 | 82 | } |
| 75 | 83 | } |
| 76 | 84 | |
| 77 | 85 | /** |
| 78 | - * @param string|object|false $selected - The label for the placeholder, or the form object. | |
| 86 | + * @param false|object|string $selected - The label for the placeholder, or the form object. | |
| 79 | 87 | */ |
| 80 | 88 | public static function form_switcher( $selected = false ) { |
| 81 | 89 | $where = apply_filters( 'frm_forms_dropdown', array(), '' ); |
| 82 | 90 | $forms = FrmForm::get_published_forms( $where ); |
| @@ -91,15 +99,16 @@ | ||
| 91 | 99 | unset( $args['id'] ); |
| 92 | 100 | } |
| 93 | 101 | |
| 94 | 102 | $frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
| 95 | - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy', 'destroy_all' ) ) ) { | |
| 103 | + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy', 'destroy_all' ), true ) ) { | |
| 96 | 104 | $args['frm_action'] = 'list'; |
| 97 | 105 | $args['form'] = 0; |
| 98 | - } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ) ) ) { | |
| 106 | + } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ), true ) ) { | |
| 99 | 107 | $args['frm_action'] = 'edit'; |
| 100 | 108 | } elseif ( FrmAppHelper::is_style_editor_page() ) { |
| 101 | - unset( $args['id'] ); // Avoid passing style into form switcher on style page. | |
| 109 | + // Avoid passing style into form switcher on style page. | |
| 110 | + unset( $args['id'] ); | |
| 102 | 111 | $query_args = array( |
| 103 | 112 | 'page' => 'formidable-styles', |
| 104 | 113 | ); |
| 105 | 114 | if ( $frm_action ) { |
| @@ -116,10 +125,10 @@ | ||
| 116 | 125 | $form_id = $selected->id; |
| 117 | 126 | $selected = $selected->name; |
| 118 | 127 | } |
| 119 | 128 | |
| 120 | - $name = ( $selected === false ) ? __( 'Switch Form', 'formidable' ) : $selected; | |
| 121 | - $name = '' === $name ? __( '(no title)', 'formidable' ) : strip_tags( $name ); | |
| 129 | + $name = $selected === false ? __( 'Switch Form', 'formidable' ) : $selected; | |
| 130 | + $name = '' === $name ? __( '(no title)', 'formidable' ) : strip_tags( $name ); | |
| 122 | 131 | $truncated_name = FrmAppHelper::truncate( $name, 25 ); |
| 123 | 132 | |
| 124 | 133 | if ( count( $forms ) < 2 ) { |
| 125 | 134 | ?> |
| @@ -151,8 +160,10 @@ | ||
| 151 | 160 | array( |
| 152 | 161 | 'input_id' => 'dropform', |
| 153 | 162 | 'placeholder' => __( 'Search Forms', 'formidable' ), |
| 154 | 163 | 'tosearch' => 'frm-dropdown-form', |
| 164 | + // Specify a value to avoid the $_REQUEST['s'] default value. | |
| 165 | + 'value' => '', | |
| 155 | 166 | ) |
| 156 | 167 | ); |
| 157 | 168 | ?> |
| 158 | 169 | </li> |
| @@ -190,9 +201,9 @@ | ||
| 190 | 201 | </a> |
| 191 | 202 | </li> |
| 192 | 203 | <?php |
| 193 | 204 | unset( $form ); |
| 194 | - } | |
| 205 | + }//end foreach | |
| 195 | 206 | ?> |
| 196 | 207 | </ul> |
| 197 | 208 | </div> |
| 198 | 209 | <?php |
| @@ -197,21 +208,11 @@ | ||
| 197 | 208 | </div> |
| 198 | 209 | <?php |
| 199 | 210 | } |
| 200 | 211 | |
| 201 | - /** | |
| 202 | - * @since 3.05 | |
| 203 | - * @deprecated 4.0 | |
| 204 | - * | |
| 205 | - * @param array $values - The form array | |
| 206 | - */ | |
| 207 | - public static function builder_submit_button( $values ) { | |
| 208 | - FrmDeprecated::builder_submit_button( $values ); | |
| 209 | - } | |
| 210 | - | |
| 211 | 212 | public static function get_sortable_classes( $col, $sort_col, $sort_dir ) { |
| 212 | - echo ( $sort_col == $col ) ? 'sorted' : 'sortable'; | |
| 213 | - echo ( $sort_col == $col && $sort_dir == 'desc' ) ? ' asc' : ' desc'; | |
| 213 | + echo $sort_col == $col ? 'sorted' : 'sortable'; | |
| 214 | + echo $sort_col == $col && $sort_dir === 'desc' ? ' asc' : ' desc'; | |
| 214 | 215 | } |
| 215 | 216 | |
| 216 | 217 | /** |
| 217 | 218 | * @since 3.0 |
| @@ -254,14 +255,16 @@ | ||
| 254 | 255 | $settings_args['current_form'] = $args['form']->id; |
| 255 | 256 | } |
| 256 | 257 | |
| 257 | 258 | $frm_settings = FrmAppHelper::get_settings( $settings_args ); |
| 258 | - $invalid_msg = do_shortcode( $frm_settings->invalid_msg ); | |
| 259 | + $invalid_msg = do_shortcode( $frm_settings->invalid_msg ); | |
| 259 | 260 | return apply_filters( 'frm_invalid_error_message', $invalid_msg, $args ); |
| 260 | 261 | } |
| 261 | 262 | |
| 262 | 263 | /** |
| 263 | 264 | * @param array $atts { |
| 265 | + * The success message details. | |
| 266 | + * | |
| 264 | 267 | * @type string $message |
| 265 | 268 | * @type stdClass $form |
| 266 | 269 | * @type int $entry_id |
| 267 | 270 | * @type string $class |
| @@ -284,9 +287,9 @@ | ||
| 284 | 287 | if ( ! empty( $values ) ) { |
| 285 | 288 | $post_values = $values; |
| 286 | 289 | } else { |
| 287 | 290 | $values = array(); |
| 288 | - $post_values = isset( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 291 | + $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 289 | 292 | } |
| 290 | 293 | |
| 291 | 294 | $defaults = array( |
| 292 | 295 | 'name' => '', |
| @@ -315,9 +318,9 @@ | ||
| 315 | 318 | } |
| 316 | 319 | unset( $defaults ); |
| 317 | 320 | |
| 318 | 321 | if ( ! isset( $values['form_key'] ) ) { |
| 319 | - $values['form_key'] = ( $post_values && isset( $post_values['form_key'] ) ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' ); | |
| 322 | + $values['form_key'] = $post_values && isset( $post_values['form_key'] ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' ); | |
| 320 | 323 | } |
| 321 | 324 | |
| 322 | 325 | $values = self::fill_default_opts( $values, false, $post_values ); |
| 323 | 326 | $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values ); |
| @@ -347,17 +350,17 @@ | ||
| 347 | 350 | $defaults = self::get_default_opts(); |
| 348 | 351 | foreach ( $defaults as $var => $default ) { |
| 349 | 352 | if ( is_array( $default ) ) { |
| 350 | 353 | if ( ! isset( $values[ $var ] ) ) { |
| 351 | - $values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array(); | |
| 354 | + $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array(); | |
| 352 | 355 | } |
| 353 | 356 | |
| 354 | 357 | foreach ( $default as $k => $v ) { |
| 355 | - $values[ $var ][ $k ] = ( $post_values && isset( $post_values[ $var ][ $k ] ) ) ? $post_values[ $var ][ $k ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ) ? $record->options[ $var ][ $k ] : $v ); | |
| 358 | + $values[ $var ][ $k ] = $post_values && isset( $post_values[ $var ][ $k ] ) ? $post_values[ $var ][ $k ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ? $record->options[ $var ][ $k ] : $v ); | |
| 356 | 359 | |
| 357 | 360 | if ( is_array( $v ) ) { |
| 358 | 361 | foreach ( $v as $k1 => $v1 ) { |
| 359 | - $values[ $var ][ $k ][ $k1 ] = ( $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ) ? $post_values[ $var ][ $k ][ $k1 ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 ); | |
| 362 | + $values[ $var ][ $k ][ $k1 ] = $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ? $post_values[ $var ][ $k ][ $k1 ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 ); | |
| 360 | 363 | unset( $k1, $v1 ); |
| 361 | 364 | } |
| 362 | 365 | } |
| 363 | 366 | |
| @@ -363,13 +366,13 @@ | ||
| 363 | 366 | |
| 364 | 367 | unset( $k, $v ); |
| 365 | 368 | } |
| 366 | 369 | } else { |
| 367 | - $values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default ); | |
| 370 | + $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default ); | |
| 368 | 371 | } |
| 369 | 372 | |
| 370 | 373 | unset( $var, $default ); |
| 371 | - } | |
| 374 | + }//end foreach | |
| 372 | 375 | |
| 373 | 376 | return $values; |
| 374 | 377 | } |
| 375 | 378 | |
| @@ -401,12 +404,11 @@ | ||
| 401 | 404 | ); |
| 402 | 405 | } |
| 403 | 406 | |
| 404 | 407 | /** |
| 408 | + * @since 2.0.6 | |
| 405 | 409 | * @param array $options |
| 406 | 410 | * @param array $values |
| 407 | - * | |
| 408 | - * @since 2.0.6 | |
| 409 | 411 | */ |
| 410 | 412 | public static function fill_form_options( &$options, $values ) { |
| 411 | 413 | $defaults = self::get_default_opts(); |
| 412 | 414 | foreach ( $defaults as $var => $default ) { |
| @@ -418,20 +420,20 @@ | ||
| 418 | 420 | /** |
| 419 | 421 | * @param string $loc |
| 420 | 422 | */ |
| 421 | 423 | public static function get_default_html( $loc ) { |
| 422 | - if ( $loc == 'submit' ) { | |
| 424 | + if ( $loc === 'submit' ) { | |
| 423 | 425 | $draft_link = self::get_draft_link(); |
| 424 | 426 | $start_over = self::get_start_over_shortcode(); |
| 425 | 427 | $default_html = <<<SUBMIT_HTML |
| 426 | -<div class="frm_submit"> | |
| 428 | +<div class="frm_submit frm_flex"> | |
| 429 | +<button class="frm_button_submit" type="submit" [button_action]>[button_label]</button> | |
| 427 | 430 | [if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button] |
| 428 | -<button class="frm_button_submit" type="submit" [button_action]>[button_label]</button> | |
| 429 | 431 | $draft_link |
| 430 | 432 | $start_over |
| 431 | 433 | </div> |
| 432 | 434 | SUBMIT_HTML; |
| 433 | - } elseif ( $loc == 'before' ) { | |
| 435 | + } elseif ( $loc === 'before' ) { | |
| 434 | 436 | $default_html = <<<BEFORE_HTML |
| 435 | 437 | <legend class="frm_screen_reader">[form_name]</legend> |
| 436 | 438 | [if form_name]<h3 class="frm_form_title">[form_name]</h3>[/if form_name] |
| 437 | 439 | [if form_description]<div class="frm_description">[form_description]</div>[/if form_description] |
| @@ -443,9 +445,9 @@ | ||
| 443 | 445 | return $default_html; |
| 444 | 446 | } |
| 445 | 447 | |
| 446 | 448 | public static function get_draft_link() { |
| 447 | - $link = '[if save_draft]<a href="#" tabindex="0" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]'; | |
| 449 | + $link = '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]'; | |
| 448 | 450 | |
| 449 | 451 | return $link; |
| 450 | 452 | } |
| 451 | 453 | |
| @@ -478,10 +480,10 @@ | ||
| 478 | 480 | |
| 479 | 481 | $classes = apply_filters( 'frm_submit_button_class', array(), $form ); |
| 480 | 482 | if ( ! empty( $classes ) ) { |
| 481 | 483 | $classes = implode( ' ', $classes ); |
| 482 | - $button_class = ' class="frm_button_submit'; | |
| 483 | - if ( strpos( $button_parts[0], $button_class ) !== false ) { | |
| 484 | + $button_class = 'frm_button_submit'; | |
| 485 | + if ( preg_match( '/\bclass="[^"]*?\b' . preg_quote( $button_class, '/' ) . '\b[^"]*?"/', $button_parts[0] ) ) { | |
| 484 | 486 | $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] ); |
| 485 | 487 | } else { |
| 486 | 488 | $button_parts[0] .= ' class="' . esc_attr( $classes ) . '"'; |
| 487 | 489 | } |
| @@ -496,51 +498,51 @@ | ||
| 496 | 498 | * @since 4.0 |
| 497 | 499 | */ |
| 498 | 500 | public static function html_shortcodes() { |
| 499 | 501 | $codes = array( |
| 500 | - 'id' => array( | |
| 502 | + 'id' => array( | |
| 501 | 503 | 'label' => __( 'Field ID', 'formidable' ), |
| 502 | 504 | 'class' => 'show_field_custom_html', |
| 503 | 505 | ), |
| 504 | - 'key' => array( | |
| 506 | + 'key' => array( | |
| 505 | 507 | 'label' => __( 'Field Key', 'formidable' ), |
| 506 | 508 | 'class' => 'show_field_custom_html', |
| 507 | 509 | ), |
| 508 | - 'field_name' => array( | |
| 510 | + 'field_name' => array( | |
| 509 | 511 | 'label' => __( 'Field Name', 'formidable' ), |
| 510 | 512 | 'class' => 'show_field_custom_html', |
| 511 | 513 | ), |
| 512 | - 'description' => array( | |
| 514 | + 'description' => array( | |
| 513 | 515 | 'label' => __( 'Field Description', 'formidable' ), |
| 514 | 516 | 'class' => 'show_field_custom_html', |
| 515 | 517 | ), |
| 516 | - 'label_position' => array( | |
| 518 | + 'label_position' => array( | |
| 517 | 519 | 'label' => __( 'Label Position', 'formidable' ), |
| 518 | 520 | 'class' => 'show_field_custom_html', |
| 519 | 521 | ), |
| 520 | - 'required_label' => array( | |
| 522 | + 'required_label' => array( | |
| 521 | 523 | 'label' => __( 'Required Label', 'formidable' ), |
| 522 | 524 | 'class' => 'show_field_custom_html', |
| 523 | 525 | ), |
| 524 | - 'input' => array( | |
| 526 | + 'input' => array( | |
| 525 | 527 | 'label' => __( 'Input Field', 'formidable' ), |
| 526 | 528 | 'class' => 'show_field_custom_html', |
| 527 | 529 | ), |
| 528 | - 'input opt=1' => array( | |
| 530 | + 'input opt=1' => array( | |
| 529 | 531 | 'label' => __( 'Single Option', 'formidable' ), |
| 530 | 532 | 'title' => __( 'Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable' ), |
| 531 | 533 | 'class' => 'show_field_custom_html', |
| 532 | 534 | ), |
| 533 | - 'input label=0' => array( | |
| 535 | + 'input label=0' => array( | |
| 534 | 536 | 'label' => __( 'Hide Option Label', 'formidable' ), |
| 535 | 537 | 'class' => 'show_field_custom_html', |
| 536 | 538 | ), |
| 537 | - 'required_class' => array( | |
| 539 | + 'required_class' => array( | |
| 538 | 540 | 'label' => __( 'Required Class', 'formidable' ), |
| 539 | 541 | 'title' => __( 'Add class name if field is required', 'formidable' ), |
| 540 | 542 | 'class' => 'show_field_custom_html', |
| 541 | 543 | ), |
| 542 | - 'error_class' => array( | |
| 544 | + 'error_class' => array( | |
| 543 | 545 | 'label' => __( 'Error Class', 'formidable' ), |
| 544 | 546 | 'title' => __( 'Add class name if field has an error on form submit', 'formidable' ), |
| 545 | 547 | 'class' => 'show_field_custom_html', |
| 546 | 548 | ), |
| @@ -561,13 +563,13 @@ | ||
| 561 | 563 | 'label' => __( 'Delete Entry Link', 'formidable' ), |
| 562 | 564 | 'class' => 'show_before_html show_after_html', |
| 563 | 565 | ), |
| 564 | 566 | |
| 565 | - 'button_label' => array( | |
| 567 | + 'button_label' => array( | |
| 566 | 568 | 'label' => __( 'Button Label', 'formidable' ), |
| 567 | 569 | 'class' => 'show_submit_html', |
| 568 | 570 | ), |
| 569 | - 'button_action' => array( | |
| 571 | + 'button_action' => array( | |
| 570 | 572 | 'label' => __( 'Button Hook', 'formidable' ), |
| 571 | 573 | 'class' => 'show_submit_html', |
| 572 | 574 | ), |
| 573 | 575 | ); |
| @@ -579,13 +581,15 @@ | ||
| 579 | 581 | } |
| 580 | 582 | |
| 581 | 583 | /** |
| 582 | 584 | * @since 4.0 |
| 585 | + * | |
| 583 | 586 | * @param array $args |
| 587 | + * @return void | |
| 584 | 588 | */ |
| 585 | 589 | public static function insert_opt_html( $args ) { |
| 586 | 590 | $class = isset( $args['class'] ) ? $args['class'] : ''; |
| 587 | - $fields = FrmField::all_field_selection(); | |
| 591 | + $fields = self::get_field_type_data_for_insert_opt_html(); | |
| 588 | 592 | $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array(); |
| 589 | 593 | |
| 590 | 594 | self::prepare_field_type( $field ); |
| 591 | 595 | |
| @@ -600,22 +604,35 @@ | ||
| 600 | 604 | |
| 601 | 605 | if ( 'url' === $args['type'] ) { |
| 602 | 606 | $class .= ' frm_insert_url'; |
| 603 | 607 | } |
| 608 | + | |
| 609 | + $truncated_name = FrmAppHelper::truncate( $args['name'], 60 ); | |
| 610 | + if ( isset( $field['icon'] ) ) { | |
| 611 | + $icon = FrmAppHelper::icon_by_class( | |
| 612 | + $field['icon'], | |
| 613 | + array( | |
| 614 | + 'aria-hidden' => 'true', | |
| 615 | + 'echo' => false, | |
| 616 | + ) | |
| 617 | + ); | |
| 618 | + } else { | |
| 619 | + $icon = ''; | |
| 620 | + } | |
| 604 | 621 | ?> |
| 605 | 622 | <li class="<?php echo esc_attr( $class ); ?>"> |
| 606 | - <a href="javascript:void(0)" class="frmids frm_insert_code" | |
| 607 | - data-code="<?php echo esc_attr( $args['id'] ); ?>"> | |
| 608 | - <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?> | |
| 609 | - <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?> | |
| 623 | + <a href="javascript:void(0)" class="frmids frm_insert_code" data-code="<?php echo esc_attr( $args['id'] ); ?>"> | |
| 624 | + <?php | |
| 625 | + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 626 | + echo esc_html( $truncated_name ); | |
| 627 | + ?> | |
| 610 | 628 | <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span> |
| 611 | 629 | </a> |
| 612 | - <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" | |
| 613 | - data-code="<?php echo esc_attr( $args['key'] ); ?>"> | |
| 614 | - <?php if ( isset( $field['icon'] ) ) { ?> | |
| 615 | - <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?> | |
| 616 | - <?php } ?> | |
| 617 | - <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?> | |
| 630 | + <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" data-code="<?php echo esc_attr( $args['key'] ); ?>"> | |
| 631 | + <?php | |
| 632 | + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 633 | + echo esc_html( $truncated_name ); | |
| 634 | + ?> | |
| 618 | 635 | <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span> |
| 619 | 636 | </a> |
| 620 | 637 | </li> |
| 621 | 638 | <?php |
| @@ -621,8 +638,23 @@ | ||
| 621 | 638 | <?php |
| 622 | 639 | } |
| 623 | 640 | |
| 624 | 641 | /** |
| 642 | + * Store and re-use field selection data for use when outputting shortcodes options in shortcode pop up. | |
| 643 | + * This significantly improves performance by avoiding repeat calls to FrmField::all_field_selection. | |
| 644 | + * | |
| 645 | + * @since 6.10 | |
| 646 | + * | |
| 647 | + * @return array | |
| 648 | + */ | |
| 649 | + private static function get_field_type_data_for_insert_opt_html() { | |
| 650 | + if ( ! isset( self::$field_type_data_for_insert_opt_html ) ) { | |
| 651 | + self::$field_type_data_for_insert_opt_html = FrmField::all_field_selection(); | |
| 652 | + } | |
| 653 | + return self::$field_type_data_for_insert_opt_html; | |
| 654 | + } | |
| 655 | + | |
| 656 | + /** | |
| 625 | 657 | * @since 4.0 |
| 626 | 658 | * @param array $args |
| 627 | 659 | */ |
| 628 | 660 | public static function insert_code_html( $args ) { |
| @@ -654,8 +686,11 @@ | ||
| 654 | 686 | * Some field types in add-ons may have been added with only |
| 655 | 687 | * a field type and name. |
| 656 | 688 | * |
| 657 | 689 | * @since 4.0 |
| 690 | + * | |
| 691 | + * @param array|string $field | |
| 692 | + * @return void | |
| 658 | 693 | */ |
| 659 | 694 | public static function prepare_field_type( &$field ) { |
| 660 | 695 | if ( ! is_array( $field ) ) { |
| 661 | 696 | $field = array( |
| @@ -669,9 +704,11 @@ | ||
| 669 | 704 | * Automatically add end section fields if they don't exist (2.0 migration) |
| 670 | 705 | * |
| 671 | 706 | * @since 2.0 |
| 672 | 707 | * |
| 673 | - * @param boolean $reset_fields | |
| 708 | + * @param object $form | |
| 709 | + * @param array $fields | |
| 710 | + * @param bool $reset_fields | |
| 674 | 711 | */ |
| 675 | 712 | public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) { |
| 676 | 713 | if ( empty( $fields ) ) { |
| 677 | 714 | return; |
| @@ -683,9 +720,9 @@ | ||
| 683 | 720 | $add_order = 0; |
| 684 | 721 | $last_field = false; |
| 685 | 722 | foreach ( $fields as $field ) { |
| 686 | 723 | if ( $prev_order === $field->field_order ) { |
| 687 | - $add_order ++; | |
| 724 | + ++$add_order; | |
| 688 | 725 | } |
| 689 | 726 | |
| 690 | 727 | if ( $add_order ) { |
| 691 | 728 | $reset_fields = true; |
| @@ -712,14 +749,14 @@ | ||
| 712 | 749 | } |
| 713 | 750 | |
| 714 | 751 | // There is already an end section here, so there is no need to create one. |
| 715 | 752 | $open = false; |
| 716 | - } | |
| 753 | + }//end switch | |
| 717 | 754 | $prev_order = $field->field_order; |
| 718 | 755 | |
| 719 | 756 | $last_field = $field; |
| 720 | 757 | unset( $field ); |
| 721 | - } | |
| 758 | + }//end foreach | |
| 722 | 759 | |
| 723 | 760 | self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $last_field ); |
| 724 | 761 | } |
| 725 | 762 | |
| @@ -735,14 +772,14 @@ | ||
| 735 | 772 | $end_section_values['field_order'] = $field->field_order + 1; |
| 736 | 773 | |
| 737 | 774 | FrmField::create( $end_section_values ); |
| 738 | 775 | |
| 739 | - if ( $move == 'move' ) { | |
| 776 | + if ( $move === 'move' ) { | |
| 740 | 777 | // bump the order of current field unless we're at the end of the form |
| 741 | 778 | FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) ); |
| 742 | 779 | } |
| 743 | 780 | |
| 744 | - $add_order += 2; | |
| 781 | + $add_order += 2; | |
| 745 | 782 | $open = false; |
| 746 | 783 | $reset_fields = true; |
| 747 | 784 | } |
| 748 | 785 | |
| @@ -756,9 +793,9 @@ | ||
| 756 | 793 | if ( $code === 'form_name' ) { |
| 757 | 794 | $replace_with = $form->name; |
| 758 | 795 | } elseif ( $code === 'form_description' ) { |
| 759 | 796 | $replace_with = FrmAppHelper::use_wpautop( $form->description ); |
| 760 | - } elseif ( $code === 'entry_key' && isset( $_GET ) && isset( $_GET['entry'] ) ) { | |
| 797 | + } elseif ( $code === 'entry_key' && ! empty( $_GET ) && isset( $_GET['entry'] ) ) { | |
| 761 | 798 | $replace_with = FrmAppHelper::simple_get( 'entry' ); |
| 762 | 799 | } else { |
| 763 | 800 | $replace_with = ''; |
| 764 | 801 | } |
| @@ -765,12 +802,12 @@ | ||
| 765 | 802 | |
| 766 | 803 | FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html ); |
| 767 | 804 | } |
| 768 | 805 | |
| 769 | - //replace [form_key] | |
| 806 | + // Replace [form_key]. | |
| 770 | 807 | $html = str_replace( '[form_key]', $form->form_key, $html ); |
| 771 | 808 | |
| 772 | - //replace [frmurl] | |
| 809 | + // Replace [frmurl]. | |
| 773 | 810 | $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html ); |
| 774 | 811 | |
| 775 | 812 | if ( strpos( $html, '[button_label]' ) ) { |
| 776 | 813 | add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 ); |
| @@ -813,18 +850,23 @@ | ||
| 813 | 850 | * If the Formidable styling isn't being loaded, |
| 814 | 851 | * use inline styling to hide the element |
| 815 | 852 | * |
| 816 | 853 | * @since 2.03.05 |
| 854 | + * | |
| 855 | + * @return void | |
| 817 | 856 | */ |
| 818 | 857 | public static function maybe_hide_inline() { |
| 819 | 858 | $frm_settings = FrmAppHelper::get_settings(); |
| 820 | - if ( $frm_settings->load_style == 'none' ) { | |
| 859 | + if ( $frm_settings->load_style === 'none' ) { | |
| 821 | 860 | echo ' style="display:none;"'; |
| 822 | - } elseif ( $frm_settings->load_style == 'dynamic' ) { | |
| 861 | + } elseif ( $frm_settings->load_style === 'dynamic' ) { | |
| 823 | 862 | FrmStylesController::enqueue_style(); |
| 824 | 863 | } |
| 825 | 864 | } |
| 826 | 865 | |
| 866 | + /** | |
| 867 | + * @return string|null | |
| 868 | + */ | |
| 827 | 869 | public static function get_form_style_class( $form = false ) { |
| 828 | 870 | $style = self::get_form_style( $form ); |
| 829 | 871 | $class = ' with_frm_style'; |
| 830 | 872 | |
| @@ -830,11 +872,10 @@ | ||
| 830 | 872 | |
| 831 | 873 | if ( empty( $style ) ) { |
| 832 | 874 | if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) { |
| 833 | 875 | return $class; |
| 834 | - } else { | |
| 835 | - return; | |
| 836 | 876 | } |
| 877 | + return; | |
| 837 | 878 | } |
| 838 | 879 | |
| 839 | 880 | // If submit button needs to be inline or centered. |
| 840 | 881 | if ( is_object( $form ) ) { |
| @@ -879,9 +920,9 @@ | ||
| 879 | 920 | |
| 880 | 921 | /** |
| 881 | 922 | * Returns appropriate class if form has top labels |
| 882 | 923 | * |
| 883 | - * @param $form | |
| 924 | + * @param array $form | |
| 884 | 925 | * |
| 885 | 926 | * @return string |
| 886 | 927 | */ |
| 887 | 928 | private static function maybe_align_fields_top( $form ) { |
| @@ -890,9 +931,9 @@ | ||
| 890 | 931 | |
| 891 | 932 | /** |
| 892 | 933 | * Determine if a form has fields with top labels so submit button can be aligned properly |
| 893 | 934 | * |
| 894 | - * @param $form | |
| 935 | + * @param array $form | |
| 895 | 936 | * |
| 896 | 937 | * @return bool |
| 897 | 938 | */ |
| 898 | 939 | private static function form_has_top_labels( $form ) { |
| @@ -904,9 +945,10 @@ | ||
| 904 | 945 | if ( count( $fields ) <= 0 ) { |
| 905 | 946 | return false; |
| 906 | 947 | } |
| 907 | 948 | |
| 908 | - $fields = array_reverse( $fields ); // start from the fields closest to the submit button | |
| 949 | + // Start from the fields closest to the submit button. | |
| 950 | + $fields = array_reverse( $fields ); | |
| 909 | 951 | foreach ( $fields as $field ) { |
| 910 | 952 | $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type']; |
| 911 | 953 | $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' ); |
| 912 | 954 | if ( $has_input ) { |
| @@ -919,10 +961,10 @@ | ||
| 919 | 961 | |
| 920 | 962 | /** |
| 921 | 963 | * Check if a field's label position is set to "top" |
| 922 | 964 | * |
| 923 | - * @param $field | |
| 924 | - * @param $form | |
| 965 | + * @param array $field | |
| 966 | + * @param bool|object|string $form | |
| 925 | 967 | * |
| 926 | 968 | * @return bool |
| 927 | 969 | */ |
| 928 | 970 | private static function field_has_top_label( $field, $form ) { |
| @@ -931,10 +973,9 @@ | ||
| 931 | 973 | return in_array( $label_position, array( 'top', 'inside', 'hidden' ) ); |
| 932 | 974 | } |
| 933 | 975 | |
| 934 | 976 | /** |
| 935 | - * @param object|string|boolean $form | |
| 936 | - * | |
| 977 | + * @param array|bool|object|string $form | |
| 937 | 978 | * @return string |
| 938 | 979 | */ |
| 939 | 980 | public static function get_form_style( $form ) { |
| 940 | 981 | $style = 1; |
| @@ -939,12 +980,14 @@ | ||
| 939 | 980 | public static function get_form_style( $form ) { |
| 940 | 981 | $style = 1; |
| 941 | 982 | if ( empty( $form ) || 'default' === $form ) { |
| 942 | 983 | return $style; |
| 943 | - } elseif ( is_object( $form ) && $form->parent_form_id ) { | |
| 984 | + } | |
| 985 | + | |
| 986 | + if ( is_object( $form ) && $form->parent_form_id ) { | |
| 944 | 987 | // get the parent form if this is a child |
| 945 | 988 | $form = $form->parent_form_id; |
| 946 | - } elseif ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) { | |
| 989 | + } elseif ( is_array( $form ) && ! empty( $form['parent_form_id'] ) ) { | |
| 947 | 990 | $form = $form['parent_form_id']; |
| 948 | 991 | } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) { |
| 949 | 992 | $style = $form['custom_style']; |
| 950 | 993 | } |
| @@ -952,9 +995,9 @@ | ||
| 952 | 995 | if ( $form && is_string( $form ) ) { |
| 953 | 996 | $form = FrmForm::getOne( $form ); |
| 954 | 997 | } |
| 955 | 998 | |
| 956 | - $style = ( $form && is_object( $form ) && isset( $form->options['custom_style'] ) ) ? $form->options['custom_style'] : $style; | |
| 999 | + $style = $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style; | |
| 957 | 1000 | |
| 958 | 1001 | return $style; |
| 959 | 1002 | } |
| 960 | 1003 | |
| @@ -960,11 +1003,10 @@ | ||
| 960 | 1003 | |
| 961 | 1004 | /** |
| 962 | 1005 | * Display the validation error messages when an entry is submitted |
| 963 | 1006 | * |
| 964 | - * @param array $args - includes img, errors | |
| 965 | - * | |
| 966 | 1007 | * @since 2.0.6 |
| 1008 | + * @param array $args Includes img, errors. | |
| 967 | 1009 | */ |
| 968 | 1010 | public static function show_errors( $args ) { |
| 969 | 1011 | $invalid_msg = self::get_invalid_error_message( $args ); |
| 970 | 1012 | |
| @@ -988,11 +1030,10 @@ | ||
| 988 | 1030 | * Display the error message in the front-end along with the image if set |
| 989 | 1031 | * The image was removed from the styling settings, but it may still be set with a hook |
| 990 | 1032 | * If the message in the global settings is empty, show every validation message in the error box |
| 991 | 1033 | * |
| 992 | - * @param array $args - includes img, errors, and show_img | |
| 993 | - * | |
| 994 | 1034 | * @since 2.0.6 |
| 1035 | + * @param array $args Includes img, errors, and show_img. | |
| 995 | 1036 | */ |
| 996 | 1037 | public static function show_error( $args ) { |
| 997 | 1038 | // remove any blank messages |
| 998 | 1039 | $args['errors'] = array_filter( (array) $args['errors'] ); |
| @@ -998,9 +1039,9 @@ | ||
| 998 | 1039 | $args['errors'] = array_filter( (array) $args['errors'] ); |
| 999 | 1040 | |
| 1000 | 1041 | $line_break_first = $args['show_img']; |
| 1001 | 1042 | foreach ( $args['errors'] as $error_key => $error ) { |
| 1002 | - if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key == 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) { | |
| 1043 | + if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) { | |
| 1003 | 1044 | continue; |
| 1004 | 1045 | } |
| 1005 | 1046 | |
| 1006 | 1047 | $id = str_replace( 'field', 'field_', $error_key ); |
| @@ -1006,9 +1047,9 @@ | ||
| 1006 | 1047 | $id = str_replace( 'field', 'field_', $error_key ); |
| 1007 | 1048 | echo '<div id="' . esc_attr( $id ) . '_error">'; |
| 1008 | 1049 | |
| 1009 | 1050 | if ( $args['show_img'] && ! empty( $args['img'] ) ) { |
| 1010 | - echo '<img src="' . esc_attr( $args['img'] ) . '" alt="" />'; | |
| 1051 | + echo '<img src="' . esc_url( $args['img'] ) . '" alt="" />'; | |
| 1011 | 1052 | } else { |
| 1012 | 1053 | $args['show_img'] = true; |
| 1013 | 1054 | } |
| 1014 | 1055 | |
| @@ -1031,21 +1072,8 @@ | ||
| 1031 | 1072 | |
| 1032 | 1073 | /** |
| 1033 | 1074 | * @since 3.0 |
| 1034 | 1075 | */ |
| 1035 | - public static function actions_dropdown( $atts ) { | |
| 1036 | - if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { | |
| 1037 | - $status = $atts['status']; | |
| 1038 | - $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); | |
| 1039 | - $trash_link = self::delete_trash_info( $form_id, $status ); | |
| 1040 | - $links = self::get_action_links( $form_id, $status ); | |
| 1041 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php' ); | |
| 1042 | - } | |
| 1043 | - } | |
| 1044 | - | |
| 1045 | - /** | |
| 1046 | - * @since 3.0 | |
| 1047 | - */ | |
| 1048 | 1076 | public static function get_action_links( $form_id, $form ) { |
| 1049 | 1077 | if ( ! is_object( $form ) ) { |
| 1050 | 1078 | $form = FrmForm::getOne( $form_id ); |
| 1051 | 1079 | } |
| @@ -1074,9 +1102,9 @@ | ||
| 1074 | 1102 | ); |
| 1075 | 1103 | } |
| 1076 | 1104 | |
| 1077 | 1105 | $actions['trash'] = self::delete_trash_info( $form_id, $form->status ); |
| 1078 | - } | |
| 1106 | + }//end if | |
| 1079 | 1107 | |
| 1080 | 1108 | return $actions; |
| 1081 | 1109 | } |
| 1082 | 1110 | |
| @@ -1100,9 +1128,9 @@ | ||
| 1100 | 1128 | return FrmAppHelper::truncate( $name, 40 ); |
| 1101 | 1129 | } |
| 1102 | 1130 | |
| 1103 | 1131 | /** |
| 1104 | - * @param mixed data | |
| 1132 | + * @param mixed $data | |
| 1105 | 1133 | * @return int |
| 1106 | 1134 | */ |
| 1107 | 1135 | private static function get_form_id_from_data( $data ) { |
| 1108 | 1136 | if ( is_object( $data ) ) { |
| @@ -1148,11 +1176,11 @@ | ||
| 1148 | 1176 | $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"'; |
| 1149 | 1177 | } |
| 1150 | 1178 | |
| 1151 | 1179 | $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] ); |
| 1152 | - if ( $length == 'icon' && isset( $link_details[ $length ] ) ) { | |
| 1180 | + if ( $length === 'icon' && isset( $link_details[ $length ] ) ) { | |
| 1153 | 1181 | $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>'; |
| 1154 | - $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"'; | |
| 1182 | + $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"'; | |
| 1155 | 1183 | } |
| 1156 | 1184 | |
| 1157 | 1185 | $link .= '>' . $label . '</a>'; |
| 1158 | 1186 | } |
| @@ -1165,9 +1193,9 @@ | ||
| 1165 | 1193 | */ |
| 1166 | 1194 | public static function delete_trash_info( $id, $status ) { |
| 1167 | 1195 | $labels = self::delete_trash_links( $id ); |
| 1168 | 1196 | |
| 1169 | - if ( 'trash' == $status ) { | |
| 1197 | + if ( 'trash' === $status ) { | |
| 1170 | 1198 | $info = $labels['restore']; |
| 1171 | 1199 | } elseif ( current_user_can( 'frm_delete_forms' ) ) { |
| 1172 | 1200 | if ( EMPTY_TRASH_DAYS ) { |
| 1173 | 1201 | $info = $labels['trash']; |
| @@ -1183,9 +1211,9 @@ | ||
| 1183 | 1211 | |
| 1184 | 1212 | /** |
| 1185 | 1213 | * @since 3.0 |
| 1186 | 1214 | */ |
| 1187 | - private static function delete_trash_links( $id ) { | |
| 1215 | + public static function delete_trash_links( $id ) { | |
| 1188 | 1216 | $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) ); |
| 1189 | 1217 | $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id; |
| 1190 | 1218 | |
| 1191 | 1219 | return array( |
| @@ -1222,33 +1250,33 @@ | ||
| 1222 | 1250 | * @since 3.0 |
| 1223 | 1251 | */ |
| 1224 | 1252 | public static function css_classes() { |
| 1225 | 1253 | $classes = array( |
| 1226 | - 'frm_total' => array( | |
| 1254 | + 'frm_total' => array( | |
| 1227 | 1255 | 'label' => __( 'Total', 'formidable' ), |
| 1228 | 1256 | 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ), |
| 1229 | 1257 | ), |
| 1230 | - 'frm_total_big' => array( | |
| 1258 | + 'frm_total_big' => array( | |
| 1231 | 1259 | 'label' => __( 'Big Total', 'formidable' ), |
| 1232 | 1260 | 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ), |
| 1233 | 1261 | ), |
| 1234 | - 'frm_scroll_box' => array( | |
| 1262 | + 'frm_scroll_box' => array( | |
| 1235 | 1263 | 'label' => __( 'Scroll Box', 'formidable' ), |
| 1236 | 1264 | 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ), |
| 1237 | 1265 | ), |
| 1238 | - 'frm_first' => array( | |
| 1266 | + 'frm_first' => array( | |
| 1239 | 1267 | 'label' => __( 'First', 'formidable' ), |
| 1240 | 1268 | 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ), |
| 1241 | 1269 | ), |
| 1242 | - 'frm_alignright' => __( 'Right', 'formidable' ), | |
| 1243 | - 'frm_grid_first' => __( 'First Grid Row', 'formidable' ), | |
| 1244 | - 'frm_grid' => __( 'Even Grid Row', 'formidable' ), | |
| 1245 | - 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ), | |
| 1270 | + 'frm_alignright' => __( 'Right', 'formidable' ), | |
| 1271 | + 'frm_grid_first' => __( 'First Grid Row', 'formidable' ), | |
| 1272 | + 'frm_grid' => __( 'Even Grid Row', 'formidable' ), | |
| 1273 | + 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ), | |
| 1246 | 1274 | 'frm_color_block' => array( |
| 1247 | 1275 | 'label' => __( 'Color Block', 'formidable' ), |
| 1248 | 1276 | 'title' => __( 'Add a background color to the field or section.', 'formidable' ), |
| 1249 | 1277 | ), |
| 1250 | - 'frm_capitalize' => array( | |
| 1278 | + 'frm_capitalize' => array( | |
| 1251 | 1279 | 'label' => __( 'Capitalize', 'formidable' ), |
| 1252 | 1280 | 'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ), |
| 1253 | 1281 | ), |
| 1254 | 1282 | ); |
| @@ -1291,9 +1319,9 @@ | ||
| 1291 | 1319 | 'trash' => __( 'Trash', 'formidable' ), |
| 1292 | 1320 | 'publish' => __( 'Published', 'formidable' ), |
| 1293 | 1321 | ); |
| 1294 | 1322 | |
| 1295 | - if ( ! in_array( $status, array_keys( $nice_names ) ) ) { | |
| 1323 | + if ( ! in_array( $status, array_keys( $nice_names ), true ) ) { | |
| 1296 | 1324 | $status = 'publish'; |
| 1297 | 1325 | } |
| 1298 | 1326 | |
| 1299 | 1327 | $name = $nice_names[ $status ]; |
| @@ -1301,94 +1329,92 @@ | ||
| 1301 | 1329 | return $name; |
| 1302 | 1330 | } |
| 1303 | 1331 | |
| 1304 | 1332 | /** |
| 1305 | - * @param array $categories | |
| 1333 | + * Renders a template icon based on the given categories. | |
| 1334 | + * | |
| 1335 | + * @param array $categories The categories to render the icon for. | |
| 1306 | 1336 | * @param array $atts { |
| 1307 | - * @type string $html 'span' or 'div'. | |
| 1308 | - * @type boolean $bg Whether to add a bg color or not. | |
| 1337 | + * Optional. An array of attributes for rendering. | |
| 1338 | + * @type string $html 'span' or 'div'. Default 'span'. | |
| 1339 | + * @type bool $bg Whether to add a background color or not. Default false. | |
| 1309 | 1340 | * } |
| 1310 | 1341 | * |
| 1311 | 1342 | * @return void |
| 1312 | 1343 | */ |
| 1313 | 1344 | public static function template_icon( $categories, $atts = array() ) { |
| 1345 | + // Define defaults. | |
| 1314 | 1346 | $defaults = array( |
| 1315 | - 'html' => 'span', | |
| 1316 | - 'bg' => false, | |
| 1347 | + 'bg' => true, | |
| 1317 | 1348 | ); |
| 1318 | - $atts = array_merge( $defaults, $atts ); | |
| 1349 | + $atts = array_merge( $defaults, $atts ); | |
| 1319 | 1350 | |
| 1351 | + // Filter out ignored categories. | |
| 1320 | 1352 | $ignore = self::ignore_template_categories(); |
| 1321 | 1353 | $categories = array_diff( $categories, $ignore ); |
| 1322 | 1354 | |
| 1355 | + // Define icons mapping. | |
| 1323 | 1356 | $icons = array( |
| 1324 | - 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ), | |
| 1325 | - 'Post' => array( 'wordpress', 'rgb(0,160,210)' ), | |
| 1326 | - 'User Registration' => array( 'register', 'var(--pink)' ), | |
| 1357 | + 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ), | |
| 1358 | + 'Post' => array( 'wordpress', 'rgb(0,160,210)' ), | |
| 1359 | + 'User Registration' => array( 'register', 'var(--pink)' ), | |
| 1327 | 1360 | 'Registration and Signup' => array( 'register', 'var(--pink)' ), |
| 1328 | - 'PayPal' => array( 'paypal' ), | |
| 1329 | - 'Stripe' => array( 'credit_card', 'var(--green)' ), | |
| 1330 | - 'Twilio' => array( 'sms' ), | |
| 1331 | - 'Payment' => array( 'credit_card' ), | |
| 1332 | - 'Order Form' => array( 'product' ), | |
| 1333 | - 'Finance' => array( 'total' ), | |
| 1334 | - 'Health and Wellness' => array( 'heart', 'var(--pink)' ), | |
| 1335 | - 'Event Planning' => array( 'calendar', 'var(--orange)' ), | |
| 1336 | - 'Real Estate' => array( 'house' ), | |
| 1337 | - 'Nonprofit' => array( 'heart_solid' ), | |
| 1338 | - 'Calculator' => array( 'calculator', 'var(--purple)' ), | |
| 1339 | - 'Quiz' => array( 'percent' ), | |
| 1340 | - 'Registrations' => array( 'address_card' ), | |
| 1341 | - 'Customer Service' => array( 'users_solid' ), | |
| 1342 | - 'Education' => array( 'pencil' ), | |
| 1343 | - 'Marketing' => array( 'eye' ), | |
| 1344 | - 'Feedback' => array( 'smile' ), | |
| 1345 | - 'Business Operations' => array( 'case' ), | |
| 1346 | - 'Contact Form' => array( 'email' ), | |
| 1347 | - 'Conversational Forms' => array( 'chat_forms' ), | |
| 1348 | - 'Survey' => array( 'chat_forms', 'var(--orange)' ), | |
| 1349 | - 'Application' => array( 'align_right' ), | |
| 1350 | - 'Signature' => array( 'signature' ), | |
| 1351 | - '' => array( 'align_right' ), | |
| 1361 | + 'PayPal' => array( 'paypal' ), | |
| 1362 | + 'Stripe' => array( 'credit_card', 'var(--green)' ), | |
| 1363 | + 'Twilio' => array( 'sms' ), | |
| 1364 | + 'Payment' => array( 'credit_card' ), | |
| 1365 | + 'Order Form' => array( 'product' ), | |
| 1366 | + 'Finance' => array( 'total' ), | |
| 1367 | + 'Health and Wellness' => array( 'heart', 'var(--pink)' ), | |
| 1368 | + 'Event Planning' => array( 'calendar', 'var(--orange)' ), | |
| 1369 | + 'Real Estate' => array( 'house' ), | |
| 1370 | + 'Nonprofit' => array( 'heart_solid' ), | |
| 1371 | + 'Calculator' => array( 'calculator', 'var(--purple)' ), | |
| 1372 | + 'Quiz' => array( 'percent' ), | |
| 1373 | + 'Registrations' => array( 'address_card' ), | |
| 1374 | + 'Customer Service' => array( 'users_solid' ), | |
| 1375 | + 'Education' => array( 'pencil' ), | |
| 1376 | + 'Marketing' => array( 'eye' ), | |
| 1377 | + 'Feedback' => array( 'smile' ), | |
| 1378 | + 'Business Operations' => array( 'case' ), | |
| 1379 | + 'Contact Form' => array( 'email' ), | |
| 1380 | + 'Conversational Forms' => array( 'chat_forms' ), | |
| 1381 | + 'Survey' => array( 'chat_forms', 'var(--orange)' ), | |
| 1382 | + 'Application' => array( 'align_right' ), | |
| 1383 | + 'Signature' => array( 'signature' ), | |
| 1384 | + '' => array( 'align_right' ), | |
| 1352 | 1385 | ); |
| 1353 | 1386 | |
| 1354 | - $icons[ __( 'My Templates', 'formidable' ) ] = array( 'user', 'var(--orange)' ); | |
| 1355 | - | |
| 1387 | + // Determine the icon to be used. | |
| 1356 | 1388 | $icon = $icons['']; |
| 1357 | - | |
| 1358 | 1389 | if ( count( $categories ) === 1 ) { |
| 1359 | 1390 | $category = reset( $categories ); |
| 1360 | 1391 | $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon; |
| 1361 | 1392 | } elseif ( ! empty( $categories ) ) { |
| 1362 | - foreach ( $icons as $cat => $icon ) { | |
| 1363 | - if ( ! in_array( $cat, $categories ) ) { | |
| 1364 | - unset( $icons[ $cat ] ); | |
| 1365 | - } | |
| 1366 | - } | |
| 1367 | - $icon = reset( $icons ); | |
| 1393 | + $icons = array_intersect_key( $icons, array_flip( $categories ) ); | |
| 1394 | + $icon = reset( $icons ); | |
| 1368 | 1395 | } |
| 1369 | 1396 | |
| 1370 | - $bg = isset( $icon[1] ) ? $icon[1] : ''; | |
| 1397 | + // Prepare variables for output. | |
| 1398 | + $icon_name = $icon[0]; | |
| 1399 | + $bg_color = isset( $icon[1] ) ? $icon[1] : ''; | |
| 1371 | 1400 | |
| 1372 | - if ( $atts['html'] === 'div' ) { | |
| 1373 | - echo '<div class="frm-category-icon frm-icon-wrapper" role="button"'; | |
| 1374 | - } else { | |
| 1375 | - echo '<span class="frm-inner-circle"'; | |
| 1401 | + // Render the icon. | |
| 1402 | + echo '<span class="frm-category-icon frm-icon-wrapper"'; | |
| 1403 | + if ( $bg_color && $atts['bg'] ) { | |
| 1404 | + echo ' style="background-color:' . esc_attr( $bg_color ) . '"'; | |
| 1376 | 1405 | } |
| 1377 | - echo empty( $bg ) || empty( $atts['bg'] ) ? '' : ' style="background-color:' . esc_attr( $bg ) . '"'; | |
| 1378 | 1406 | echo '>'; |
| 1379 | - | |
| 1380 | - FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon[0] . '_icon' ); | |
| 1381 | - echo '<span class="frm_hidden">'; | |
| 1382 | - FrmAppHelper::icon_by_class( 'frmfont frm_lock_icon' ); | |
| 1407 | + FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' ); | |
| 1383 | 1408 | echo '</span>'; |
| 1384 | - echo '</' . esc_attr( $atts['html'] ) . '>'; | |
| 1385 | 1409 | } |
| 1386 | 1410 | |
| 1387 | 1411 | /** |
| 1412 | + * Retrieves the list of template categories to ignore. | |
| 1413 | + * | |
| 1388 | 1414 | * @since 4.03.01 |
| 1389 | 1415 | * |
| 1390 | - * @return array<string> | |
| 1416 | + * @return string[] Array of categories to ignore. | |
| 1391 | 1417 | */ |
| 1392 | 1418 | public static function ignore_template_categories() { |
| 1393 | 1419 | return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' ); |
| 1394 | 1420 | } |
| @@ -1393,9 +1419,15 @@ | ||
| 1393 | 1419 | return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' ); |
| 1394 | 1420 | } |
| 1395 | 1421 | |
| 1396 | 1422 | /** |
| 1423 | + * Get template install link. | |
| 1424 | + * | |
| 1397 | 1425 | * @since 4.02 |
| 1426 | + * | |
| 1427 | + * @param array $template Template details. | |
| 1428 | + * @param array $args Additional arguments. | |
| 1429 | + * @return array The link attributes. | |
| 1398 | 1430 | */ |
| 1399 | 1431 | public static function get_template_install_link( $template, $args ) { |
| 1400 | 1432 | $defaults = array( |
| 1401 | 1433 | 'class' => 'install-now', |
| @@ -1431,9 +1463,8 @@ | ||
| 1431 | 1463 | * |
| 1432 | 1464 | * @since 4.02.02 |
| 1433 | 1465 | * |
| 1434 | 1466 | * @param array $args |
| 1435 | - * | |
| 1436 | 1467 | * @return bool |
| 1437 | 1468 | */ |
| 1438 | 1469 | public static function plan_is_allowed( $args ) { |
| 1439 | 1470 | if ( empty( $args['license_type'] ) ) { |
| @@ -1439,20 +1470,22 @@ | ||
| 1439 | 1470 | if ( empty( $args['license_type'] ) ) { |
| 1440 | 1471 | return false; |
| 1441 | 1472 | } |
| 1442 | 1473 | |
| 1443 | - $included = $args['license_type'] === strtolower( $args['plan_required'] ); | |
| 1474 | + $plans = array( 'free', 'personal', 'business', 'elite' ); | |
| 1475 | + $license_type = strtolower( $args['license_type'] ); | |
| 1476 | + $plan_required = strtolower( $args['plan_required'] ); | |
| 1477 | + $included = $license_type === $plan_required; | |
| 1444 | 1478 | |
| 1445 | - $plans = array( 'free', 'personal', 'business', 'elite' ); | |
| 1446 | - if ( $included || ! in_array( strtolower( $args['plan_required'] ), $plans, true ) ) { | |
| 1479 | + if ( $included || ! in_array( $plan_required, $plans, true ) ) { | |
| 1447 | 1480 | return $included; |
| 1448 | 1481 | } |
| 1449 | 1482 | |
| 1450 | 1483 | foreach ( $plans as $plan ) { |
| 1451 | - if ( $included || $plan === $args['license_type'] ) { | |
| 1484 | + if ( $included || $plan === $license_type ) { | |
| 1452 | 1485 | break; |
| 1453 | 1486 | } |
| 1454 | - $included = $plan === strtolower( $args['plan_required'] ); | |
| 1487 | + $included = $plan === $plan_required; | |
| 1455 | 1488 | } |
| 1456 | 1489 | |
| 1457 | 1490 | return $included; |
| 1458 | 1491 | } |
| @@ -1457,16 +1490,8 @@ | ||
| 1457 | 1490 | return $included; |
| 1458 | 1491 | } |
| 1459 | 1492 | |
| 1460 | 1493 | /** |
| 1461 | - * @since 4.02 | |
| 1462 | - */ | |
| 1463 | - public static function template_install_html( $link, $class = '' ) { | |
| 1464 | - $link['class'] .= ' ' . $class; | |
| 1465 | - echo '<a ' . esc_attr( $link['href'] ) . '="' . esc_url( $link['url'] ) . '" class="' . esc_attr( $link['class'] ) . ' " aria-label="' . esc_attr( $link['label'] ) . '"' . ( $link['atts'] ? ' target="_blank" rel="noopener"' : '' ) . '>'; | |
| 1466 | - } | |
| 1467 | - | |
| 1468 | - /** | |
| 1469 | 1494 | * If a template or add-on cannot be installed, show a message |
| 1470 | 1495 | * about which plan is required. |
| 1471 | 1496 | * |
| 1472 | 1497 | * @since 4.0 |
| @@ -1489,9 +1514,9 @@ | ||
| 1489 | 1514 | /** |
| 1490 | 1515 | * @since 4.0 |
| 1491 | 1516 | * |
| 1492 | 1517 | * @param array $item |
| 1493 | - * @return string|false | |
| 1518 | + * @return false|string | |
| 1494 | 1519 | */ |
| 1495 | 1520 | public static function get_plan_required( &$item ) { |
| 1496 | 1521 | if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) { |
| 1497 | 1522 | return false; |
| @@ -1552,9 +1577,9 @@ | ||
| 1552 | 1577 | |
| 1553 | 1578 | $options = $values['options']; |
| 1554 | 1579 | FrmAppHelper::sanitize_with_html( $options ); |
| 1555 | 1580 | |
| 1556 | - if ( ( ! isset( $options['success_action'] ) ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) { | |
| 1581 | + if ( ! isset( $options['success_action'] ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) { | |
| 1557 | 1582 | return false; |
| 1558 | 1583 | } |
| 1559 | 1584 | |
| 1560 | 1585 | $unsafe_params_in_redirect = self::get_unsafe_params( $options['success_url'] ); |
| @@ -1671,34 +1696,8 @@ | ||
| 1671 | 1696 | ); |
| 1672 | 1697 | } |
| 1673 | 1698 | |
| 1674 | 1699 | /** |
| 1675 | - * Check an array of templates, determine how many the logged in user can use | |
| 1676 | - * | |
| 1677 | - * @param array $templates | |
| 1678 | - * @param array $args | |
| 1679 | - * @return int | |
| 1680 | - */ | |
| 1681 | - public static function available_count( $templates, $args ) { | |
| 1682 | - return array_reduce( | |
| 1683 | - $templates, | |
| 1684 | - function( $total, $template ) use ( $args ) { | |
| 1685 | - if ( ! empty( $template['url'] ) ) { | |
| 1686 | - return $total + 1; | |
| 1687 | - } | |
| 1688 | - | |
| 1689 | - $args['plan_required'] = self::get_plan_required( $template ); | |
| 1690 | - if ( self::plan_is_allowed( $args ) ) { | |
| 1691 | - return $total + 1; | |
| 1692 | - } | |
| 1693 | - | |
| 1694 | - return $total; | |
| 1695 | - }, | |
| 1696 | - 0 | |
| 1697 | - ); | |
| 1698 | - } | |
| 1699 | - | |
| 1700 | - /** | |
| 1701 | 1700 | * Make sure the field shortcodes in a url always add the sanitize_url=1 option if nothing is defined. |
| 1702 | 1701 | * This is to prevent some field characters like ', @, and | from being stripped from the redirect URL. |
| 1703 | 1702 | * |
| 1704 | 1703 | * @since 5.0.16 |
| @@ -1747,9 +1746,9 @@ | ||
| 1747 | 1746 | } |
| 1748 | 1747 | $new_shortcode .= ' sanitize_url=1]'; |
| 1749 | 1748 | |
| 1750 | 1749 | $query = str_replace( $shortcode, $new_shortcode, $query ); |
| 1751 | - } | |
| 1750 | + }//end foreach | |
| 1752 | 1751 | |
| 1753 | 1752 | if ( $query === $original_query ) { |
| 1754 | 1753 | return $url; |
| 1755 | 1754 | } |
| @@ -1766,6 +1765,43 @@ | ||
| 1766 | 1765 | * @return bool |
| 1767 | 1766 | */ |
| 1768 | 1767 | public static function should_use_pro_for_ajax_submit() { |
| 1769 | 1768 | return is_callable( 'FrmProForm::is_ajax_on' ) && ! is_callable( 'FrmProFormsHelper::lite_supports_ajax_submit' ); |
| 1769 | + } | |
| 1770 | + | |
| 1771 | + /** | |
| 1772 | + * Outputs the appropriate button text in the publish box. | |
| 1773 | + * | |
| 1774 | + * @return void | |
| 1775 | + */ | |
| 1776 | + public static function publish_box_button_text() { | |
| 1777 | + $is_new_template = FrmAppHelper::simple_get( 'new_template' ); | |
| 1778 | + $action = FrmAppHelper::simple_get( 'frm_action' ); | |
| 1779 | + | |
| 1780 | + if ( ( 'edit' === $action || 'settings' === $action ) && $is_new_template ) { | |
| 1781 | + esc_html_e( 'Save', 'formidable' ); | |
| 1782 | + } else { | |
| 1783 | + esc_html_e( 'Update', 'formidable' ); | |
| 1784 | + } | |
| 1785 | + } | |
| 1786 | + | |
| 1787 | + /** | |
| 1788 | + * @since 3.0 | |
| 1789 | + * @deprecated 6.11 | |
| 1790 | + * | |
| 1791 | + * @param array $atts | |
| 1792 | + * @return void | |
| 1793 | + */ | |
| 1794 | + public static function actions_dropdown( $atts ) { | |
| 1795 | + _deprecated_function( __METHOD__, '6.11' ); | |
| 1796 | + | |
| 1797 | + if ( ! FrmAppHelper::is_admin_page( 'formidable' ) ) { | |
| 1798 | + return; | |
| 1799 | + } | |
| 1800 | + | |
| 1801 | + $status = $atts['status']; | |
| 1802 | + $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); | |
| 1803 | + $trash_link = self::delete_trash_info( $form_id, $status ); | |
| 1804 | + $links = self::get_action_links( $form_id, $status ); | |
| 1805 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php'; | |
| 1770 | 1806 | } |
| 1771 | 1807 | } |