Crypto.php
1 year ago
DB.php
1 year ago
Helpers.php
1 year ago
PluginImportDataRetriever.php
1 year ago
UI.php
1 year ago
UI.php
119 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPMailSMTP\Helpers; |
| 4 | |
| 5 | /** |
| 6 | * Reusable interface components. |
| 7 | * |
| 8 | * @since 3.10.0 |
| 9 | */ |
| 10 | class UI { |
| 11 | |
| 12 | /** |
| 13 | * Toggle component. |
| 14 | * |
| 15 | * @since 3.10.0 |
| 16 | * |
| 17 | * @param array $args { |
| 18 | * Toggle parameters. |
| 19 | * |
| 20 | * @type string $name Name attribute of the toggle's input element. Default ''. |
| 21 | * @type string $value Value attribute of the toggle's input element. Default 'yes'. |
| 22 | * @type string|string[] $label Single label, or a 2-elements array of on/off labels. Default ''. |
| 23 | * @type string $id ID attribute of the toggle's container element. Default ''. |
| 24 | * @type string $class Class attribute of the toggle's container element. Default ''. |
| 25 | * @type bool $checked Checked attribute of the toggle's input element. Default false. |
| 26 | * @type bool $disabled Disabled attribute of the toggle's input element. Default false. |
| 27 | * } |
| 28 | */ |
| 29 | public static function toggle( $args = [] ) { |
| 30 | |
| 31 | $args = wp_parse_args( |
| 32 | $args, |
| 33 | [ |
| 34 | 'name' => '', |
| 35 | 'value' => 'yes', |
| 36 | 'label' => [ |
| 37 | esc_html__( 'On', 'wp-mail-smtp' ), |
| 38 | esc_html__( 'Off', 'wp-mail-smtp' ), |
| 39 | ], |
| 40 | 'id' => '', |
| 41 | 'class' => '', |
| 42 | 'checked' => false, |
| 43 | 'disabled' => false, |
| 44 | ] |
| 45 | ); |
| 46 | ?> |
| 47 | <label class="wp-mail-smtp-toggle"> |
| 48 | <input type="checkbox" |
| 49 | name="<?php echo esc_attr( $args['name'] ); ?>" |
| 50 | <?php echo empty( $args['class'] ) ? '' : ' class="' . esc_attr( $args['class'] ) . '"'; ?> |
| 51 | <?php echo empty( $args['id'] ) ? '' : ' id="' . esc_attr( $args['id'] ) . '"'; ?> |
| 52 | value="<?php echo esc_attr( $args['value'] ); ?>" |
| 53 | <?php checked( (bool) $args['checked'] ); ?> |
| 54 | <?php disabled( (bool) $args['disabled'] ); ?> /> |
| 55 | <span class="wp-mail-smtp-toggle__switch"></span> |
| 56 | <?php if ( is_array( $args['label'] ) ) : ?> |
| 57 | <?php if ( count( $args['label'] ) > 0 ) : ?> |
| 58 | <span class="wp-mail-smtp-toggle__label wp-mail-smtp-toggle__label--checked"><?php echo esc_html( $args['label'][0] ); ?></span> |
| 59 | <?php endif; ?> |
| 60 | <?php if ( count( $args['label'] ) > 1 ) : ?> |
| 61 | <span class="wp-mail-smtp-toggle__label wp-mail-smtp-toggle__label--unchecked"><?php echo esc_html( $args['label'][1] ); ?></span> |
| 62 | <?php endif; ?> |
| 63 | <?php else : ?> |
| 64 | <span class="wp-mail-smtp-toggle__label wp-mail-smtp-toggle__label--static"><?php echo esc_html( $args['label'] ); ?></span> |
| 65 | <?php endif; ?> |
| 66 | </label> |
| 67 | <?php |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Output an obfuscated password field. |
| 72 | * |
| 73 | * @since 4.1.0 |
| 74 | * |
| 75 | * @param array $args Field attributes. |
| 76 | * |
| 77 | * @return void |
| 78 | */ |
| 79 | public static function hidden_password_field( $args ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh |
| 80 | |
| 81 | $args = wp_parse_args( |
| 82 | $args, |
| 83 | [ |
| 84 | 'name' => '', |
| 85 | 'id' => '', |
| 86 | 'value' => '', |
| 87 | 'clear_text' => esc_html__( 'Remove', 'wp-mail-smtp' ), |
| 88 | ] |
| 89 | ); |
| 90 | |
| 91 | $value = str_repeat( '*', strlen( $args['value'] ) ); |
| 92 | |
| 93 | // phpcs:disable Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace |
| 94 | ?> |
| 95 | |
| 96 | <div class="wp-mail-smtp-input-btn-row"> |
| 97 | |
| 98 | <input type="password" |
| 99 | spellcheck="false" |
| 100 | autocomplete="new-password" |
| 101 | <?php if ( ! empty( $value ) ) : ?>disabled<?php endif; ?> |
| 102 | <?php if ( ! empty( $args['name'] && empty( $value ) ) ) : ?>name="<?php echo esc_attr( $args['name'] ); ?>"<?php endif; ?> |
| 103 | <?php if ( ! empty( $args['name'] ) ) : ?>data-name="<?php echo esc_attr( $args['name'] ); ?>"<?php endif; ?> |
| 104 | <?php if ( ! empty( $args['id'] ) ) : ?>id="<?php echo esc_attr( $args['id'] ); ?>"<?php endif; ?> |
| 105 | <?php if ( ! empty( $value ) ) : ?>value="<?php echo esc_attr( $value ); ?>"<?php endif; ?>/> |
| 106 | |
| 107 | <?php if ( ! empty( $value ) ) : ?> |
| 108 | |
| 109 | <button type="button" |
| 110 | class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-grey" |
| 111 | data-clear-field="<?php echo esc_attr( $args['id'] ); ?>"><?php echo esc_html( $args['clear_text'] ); ?></button> |
| 112 | |
| 113 | <?php endif; ?> |
| 114 | </div> |
| 115 | <?php |
| 116 | // phpcs:enable Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace |
| 117 | } |
| 118 | } |
| 119 |