| @@ -1,149 +1,134 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Text Field Class | |
| 5 | - */ | |
| 6 | -class WeForms_Form_Field_Textarea extends WeForms_Field_Contract { | |
| 7 | - | |
| 8 | - public function __construct() { | |
| 9 | - $this->name = __( 'Textarea', 'weforms' ); | |
| 10 | - $this->input_type = 'textarea_field'; | |
| 11 | - $this->icon = 'paragraph'; | |
| 12 | - } | |
| 13 | - | |
| 14 | - /** | |
| 15 | - * Render the text field | |
| 16 | - * | |
| 17 | - * @param array $field_settings | |
| 18 | - * @param int $form_id | |
| 19 | - * | |
| 20 | - * @return void | |
| 21 | - */ | |
| 22 | - public function render( $field_settings, $form_id ) { | |
| 23 | - $req_class = ( $field_settings['required'] == 'yes' ) ? 'required' : 'rich-editor'; | |
| 24 | - $value = $field_settings['default']; | |
| 25 | - $textarea_id = $field_settings['name'] ? $field_settings['name'] . '_' . $form_id : 'textarea_'; | |
| 26 | - $form_settings = weforms()->form->get( $form_id )->get_settings(); | |
| 27 | - $use_theme_css = isset( $form_settings['use_theme_css'] ) ? $form_settings['use_theme_css'] : 'wpuf-style'; | |
| 28 | - ?> | |
| 29 | - <li <?php $this->print_list_attributes( $field_settings ); ?>> | |
| 30 | - <?php $this->print_label( $field_settings, $form_id ); ?> | |
| 31 | - <?php if ( in_array( $field_settings['rich'], array( 'yes', 'teeny' ) ) ) { ?> | |
| 32 | - <div | |
| 33 | - class="wpuf-fields wpuf-rich-validation <?php printf( wp_kses_post( 'wpuf_%s_%s', $field_settings['name'], $form_id ) ); ?>" | |
| 34 | - data-type="rich" | |
| 35 | - data-required="<?php echo esc_attr( $field_settings['required'] ); ?>" | |
| 36 | - data-id="<?php echo esc_attr( $field_settings['name'] ) . '_' . esc_attr( $form_id ); ?>" | |
| 37 | - data-name="<?php echo esc_attr( $field_settings['name'] ); ?>" | |
| 38 | - data-style="<?php echo esc_attr( $use_theme_css ); ?>" | |
| 39 | - > | |
| 40 | - <?php } else { ?> | |
| 41 | - <div class="wpuf-fields"> | |
| 42 | - <?php } ?> | |
| 43 | - | |
| 44 | - <?php | |
| 45 | - | |
| 46 | - if ( $field_settings['rich'] == 'yes' ) { | |
| 47 | - $editor_settings = [ | |
| 48 | - 'textarea_rows' => $field_settings['rows'], | |
| 49 | - 'quicktags' => false, | |
| 50 | - 'media_buttons' => false, | |
| 51 | - 'editor_class' => $req_class, | |
| 52 | - 'textarea_name' => $field_settings['name'], | |
| 53 | - ]; | |
| 54 | - | |
| 55 | - $editor_settings = apply_filters( 'wpuf_textarea_editor_args', $editor_settings ); | |
| 56 | - wp_editor( $value, $textarea_id, $editor_settings ); | |
| 57 | - } elseif ( $field_settings['rich'] == 'teeny' ) { | |
| 58 | - $editor_settings = [ | |
| 59 | - 'textarea_rows' => $field_settings['rows'], | |
| 60 | - 'quicktags' => false, | |
| 61 | - 'media_buttons' => false, | |
| 62 | - 'teeny' => true, | |
| 63 | - 'editor_class' => $req_class, | |
| 64 | - 'textarea_name' => $field_settings['name'], | |
| 65 | - ]; | |
| 66 | - | |
| 67 | - $editor_settings = apply_filters( 'wpuf_textarea_editor_args', $editor_settings ); | |
| 68 | - wp_editor( $value, $textarea_id, $editor_settings ); | |
| 69 | - } else { | |
| 70 | - ?> | |
| 71 | - <textarea | |
| 72 | - class="textareafield <?php echo ' wpuf_'. esc_attr( $field_settings['name'] ).'_'. esc_attr( $form_id ); ?>" | |
| 73 | - id="<?php echo esc_attr( $field_settings['name'] ) . '_' . esc_attr( $form_id ); ?>" | |
| 74 | - name="<?php echo esc_attr( $field_settings['name'] ); ?>" | |
| 75 | - data-required="<?php echo esc_attr( $field_settings['required'] ) ?>" | |
| 76 | - data-type="textarea" | |
| 77 | - placeholder="<?php echo esc_attr( $field_settings['placeholder'] ); ?>" | |
| 78 | - rows="<?php echo esc_attr($field_settings['rows']); ?>" | |
| 79 | - cols="<?php echo esc_attr($field_settings['cols']); ?>" | |
| 80 | - ><?php echo esc_textarea( $value ) ?></textarea> | |
| 81 | - <span class="wpuf-wordlimit-message wpuf-help"></span> | |
| 82 | - | |
| 83 | - <?php | |
| 84 | - } ?> | |
| 85 | - | |
| 86 | - <?php | |
| 87 | - $this->help_text( $field_settings ); | |
| 88 | - | |
| 89 | - if ( isset( $field_settings['word_restriction'] ) && $field_settings['word_restriction'] ) { | |
| 90 | - $this->check_word_restriction_func( | |
| 91 | - $field_settings['word_restriction'], | |
| 92 | - $field_settings['rich'], | |
| 93 | - $field_settings['name'] . '_' . $form_id | |
| 94 | - ); | |
| 95 | - } ?> | |
| 96 | - </li> | |
| 97 | - <?php | |
| 98 | - } | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * Get field options setting | |
| 102 | - * | |
| 103 | - * @return array | |
| 104 | - */ | |
| 105 | - public function get_options_settings() { | |
| 106 | - $default_options = $this->get_default_option_settings(); | |
| 107 | - $default_text_options = $this->get_default_textarea_option_settings(); | |
| 108 | - | |
| 109 | - return array_merge( $default_options, $default_text_options ); | |
| 110 | - } | |
| 111 | - | |
| 112 | - /** | |
| 113 | - * Get the field props | |
| 114 | - * | |
| 115 | - * @return array | |
| 116 | - */ | |
| 117 | - public function get_field_props() { | |
| 118 | - $defaults = $this->default_attributes(); | |
| 119 | - $props = [ | |
| 120 | - 'word_restriction' => '', | |
| 121 | - 'rows' => 5, | |
| 122 | - 'cols' => 25, | |
| 123 | - 'rich' => 'no', | |
| 124 | - ]; | |
| 125 | - | |
| 126 | - return array_merge( $defaults, $props ); | |
| 127 | - } | |
| 128 | - | |
| 129 | - /** | |
| 130 | - * Prepare entry | |
| 131 | - * | |
| 132 | - * @param $field | |
| 133 | - * | |
| 134 | - * @return mixed | |
| 135 | - */ | |
| 136 | - public function prepare_entry( $field, $args = [] ) { | |
| 137 | - if( empty( $_POST['_wpnonce'] ) ) { | |
| 138 | - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) ); | |
| 139 | - } | |
| 140 | - | |
| 141 | - if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_form_add' ) ) { | |
| 142 | - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) ); | |
| 143 | - } | |
| 144 | - | |
| 145 | - $args = ! empty( $args ) ? $args : weforms_clean( $_POST ); | |
| 146 | - | |
| 147 | - return wp_kses_post( $args[$field['name']] ); | |
| 148 | - } | |
| 149 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Text Field Class | |
| 5 | + */ | |
| 6 | +class WeForms_Form_Field_Textarea extends WeForms_Field_Contract { | |
| 7 | + | |
| 8 | + function __construct() { | |
| 9 | + $this->name = __( 'Textarea', 'weforms' ); | |
| 10 | + $this->input_type = 'textarea_field'; | |
| 11 | + $this->icon = 'paragraph'; | |
| 12 | + } | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * Render the text field | |
| 16 | + * | |
| 17 | + * @param array $field_settings | |
| 18 | + * @param integer $form_id | |
| 19 | + * | |
| 20 | + * @return void | |
| 21 | + */ | |
| 22 | + public function render( $field_settings, $form_id ) { | |
| 23 | + $req_class = ( $field_settings['required'] == 'yes' ) ? 'required' : 'rich-editor'; | |
| 24 | + $value = $field_settings['default']; | |
| 25 | + $textarea_id = $field_settings['name'] ? $field_settings['name'] . '_' . $form_id : 'textarea_'; | |
| 26 | + ?> | |
| 27 | + <li <?php $this->print_list_attributes( $field_settings ); ?>> | |
| 28 | + <?php $this->print_label( $field_settings, $form_id ); ?> | |
| 29 | + | |
| 30 | + <?php if ( in_array( $field_settings['rich'], array( 'yes', 'teeny' ) ) ) { ?> | |
| 31 | + <div class="wpuf-fields wpuf-rich-validation <?php printf( 'wpuf_%s_%s', $field_settings['name'], $form_id ); ?>" data-type="rich" data-required="<?php echo esc_attr( $field_settings['required'] ); ?>" data-id="<?php echo esc_attr( $field_settings['name'] ) . '_' . $form_id; ?>" data-name="<?php echo esc_attr( $field_settings['name'] ); ?>"> | |
| 32 | + <?php } else { ?> | |
| 33 | + <div class="wpuf-fields"> | |
| 34 | + <?php } ?> | |
| 35 | + | |
| 36 | + <?php | |
| 37 | + | |
| 38 | + if ( $field_settings['rich'] == 'yes' ) { | |
| 39 | + $editor_settings = array( | |
| 40 | + 'textarea_rows' => $field_settings['rows'], | |
| 41 | + 'quicktags' => false, | |
| 42 | + 'media_buttons' => false, | |
| 43 | + 'editor_class' => $req_class, | |
| 44 | + 'textarea_name' => $field_settings['name'] | |
| 45 | + ); | |
| 46 | + | |
| 47 | + $editor_settings = apply_filters( 'wpuf_textarea_editor_args' , $editor_settings ); | |
| 48 | + wp_editor( $value, $textarea_id, $editor_settings ); | |
| 49 | + | |
| 50 | + } elseif( $field_settings['rich'] == 'teeny' ) { | |
| 51 | + | |
| 52 | + $editor_settings = array( | |
| 53 | + 'textarea_rows' => $field_settings['rows'], | |
| 54 | + 'quicktags' => false, | |
| 55 | + 'media_buttons' => false, | |
| 56 | + 'teeny' => true, | |
| 57 | + 'editor_class' => $req_class, | |
| 58 | + 'textarea_name' => $field_settings['name'] | |
| 59 | + ); | |
| 60 | + | |
| 61 | + $editor_settings = apply_filters( 'wpuf_textarea_editor_args' , $editor_settings ); | |
| 62 | + wp_editor( $value, $textarea_id, $editor_settings ); | |
| 63 | + | |
| 64 | + } else { | |
| 65 | + ?> | |
| 66 | + <textarea | |
| 67 | + class="textareafield <?php echo ' wpuf_'.$field_settings['name'].'_'.$form_id; ?>" | |
| 68 | + id="<?php echo $field_settings['name'] . '_' . $form_id; ?>" | |
| 69 | + name="<?php echo $field_settings['name']; ?>" | |
| 70 | + data-required="<?php echo $field_settings['required'] ?>" | |
| 71 | + data-type="textarea" | |
| 72 | + placeholder="<?php echo esc_attr( $field_settings['placeholder'] ); ?>" | |
| 73 | + rows="<?php echo $field_settings['rows']; ?>" | |
| 74 | + cols="<?php echo $field_settings['cols']; ?>" | |
| 75 | + ><?php echo esc_textarea( $value ) ?></textarea> | |
| 76 | + <span class="wpuf-wordlimit-message wpuf-help"></span> | |
| 77 | + | |
| 78 | + <?php } ?> | |
| 79 | + | |
| 80 | + <?php | |
| 81 | + $this->help_text( $field_settings ); | |
| 82 | + if ( isset( $field_settings['word_restriction'] ) && $field_settings['word_restriction'] ) { | |
| 83 | + $this->check_word_restriction_func( | |
| 84 | + $field_settings['word_restriction'], | |
| 85 | + $field_settings['rich'], | |
| 86 | + $field_settings['name'] . '_' . $form_id | |
| 87 | + ); | |
| 88 | + } | |
| 89 | + | |
| 90 | + ?> | |
| 91 | + </li> | |
| 92 | + <?php | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Get field options setting | |
| 97 | + * | |
| 98 | + * @return array | |
| 99 | + */ | |
| 100 | + public function get_options_settings() { | |
| 101 | + $default_options = $this->get_default_option_settings(); | |
| 102 | + $default_text_options = $this->get_default_textarea_option_settings(); | |
| 103 | + | |
| 104 | + return array_merge( $default_options, $default_text_options ); | |
| 105 | + } | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * Get the field props | |
| 109 | + * | |
| 110 | + * @return array | |
| 111 | + */ | |
| 112 | + public function get_field_props() { | |
| 113 | + $defaults = $this->default_attributes(); | |
| 114 | + $props = array( | |
| 115 | + 'word_restriction' => '', | |
| 116 | + 'rows' => 5, | |
| 117 | + 'cols' => 25, | |
| 118 | + 'rich' => 'no', | |
| 119 | + ); | |
| 120 | + | |
| 121 | + return array_merge( $defaults, $props ); | |
| 122 | + } | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * Prepare entry | |
| 126 | + * | |
| 127 | + * @param $field | |
| 128 | + * | |
| 129 | + * @return mixed | |
| 130 | + */ | |
| 131 | + public function prepare_entry( $field ) { | |
| 132 | + return wp_kses_post( $_POST[$field['name']] ); | |
| 133 | + } | |
| 134 | +} | |