| @@ -1,163 +1,120 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Date Field Class | |
| 5 | - */ | |
| 6 | -class WeForms_Form_Field_Date_Free extends WeForms_Field_Contract { | |
| 7 | - | |
| 8 | - public function __construct() { | |
| 9 | - $this->name = __( 'Date / Time', 'weforms' ); | |
| 10 | - $this->input_type = 'date_field'; | |
| 11 | - $this->icon = 'calendar-o'; | |
| 12 | - } | |
| 13 | - | |
| 14 | - /** | |
| 15 | - * Render the date 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 | - $use_theme_css = isset( $form_settings['use_theme_css'] ) ? $form_settings['use_theme_css'] : 'wpuf-style'; | |
| 24 | - $value = ''; | |
| 25 | - ?> | |
| 26 | - <li <?php $this->print_list_attributes( $field_settings ); ?>> | |
| 27 | - <?php $this->print_label( $field_settings ); ?> | |
| 28 | - | |
| 29 | - <div class="wpuf-fields"> | |
| 30 | - <input | |
| 31 | - id="wpuf-date-<?php echo esc_attr( $field_settings['name'] ); ?>" | |
| 32 | - type="text" | |
| 33 | - <?php | |
| 34 | - $field_settings['enforce_format'] = ! isset( $field_settings['enforce_format'] ) ? '' : $field_settings['enforce_format']; | |
| 35 | - echo esc_attr( $field_settings['enforce_format'] !== 'yes' ) ? '' : 'readonly'; | |
| 36 | - ?> | |
| 37 | - class="datepicker <?php echo ' wpuf_'.esc_attr( $field_settings['name'] ).'_'. esc_attr($form_id); ?>" | |
| 38 | - data-required="<?php echo esc_attr($field_settings['required']) ?>" | |
| 39 | - data-type="text" | |
| 40 | - data-style="<?php echo esc_attr( $use_theme_css ); ?>" | |
| 41 | - name="<?php echo esc_attr( $field_settings['name'] ); ?>" | |
| 42 | - placeholder="<?php echo esc_attr( $field_settings['format'] ); ?>" | |
| 43 | - value="<?php echo esc_attr( $value ) ?>" | |
| 44 | - size="30" | |
| 45 | - /> | |
| 46 | - <?php $this->help_text( $field_settings ); ?> | |
| 47 | - </div> | |
| 48 | - </li> | |
| 49 | - <?php | |
| 50 | - | |
| 51 | - $name = $field_settings['name']; | |
| 52 | - $format = $field_settings["format"]; | |
| 53 | - | |
| 54 | - if ( $field_settings['time'] == 'yes' ) { | |
| 55 | - $script = "jQuery(function($) { | |
| 56 | - $('#wpuf-date-{$name}').datetimepicker({ dateFormat: '{$format}' }); | |
| 57 | - });"; | |
| 58 | - } else { | |
| 59 | - $script = "jQuery(function($) { | |
| 60 | - $('#wpuf-date-{$name}').datepicker({ dateFormat: '{$format}' }); | |
| 61 | - });"; | |
| 62 | - } | |
| 63 | - | |
| 64 | - wp_add_inline_script( 'wpuf-form', $script ); | |
| 65 | - } | |
| 66 | - | |
| 67 | - /** | |
| 68 | - * Get field options setting | |
| 69 | - * | |
| 70 | - * @return array | |
| 71 | - */ | |
| 72 | - public function get_options_settings() { | |
| 73 | - $default_options = $this->get_default_option_settings(); | |
| 74 | - | |
| 75 | - $settings = [ | |
| 76 | - [ | |
| 77 | - 'name' => 'format', | |
| 78 | - 'title' => esc_html__( 'Date Format', 'weforms' ), | |
| 79 | - 'type' => 'text', | |
| 80 | - 'section' => 'advanced', | |
| 81 | - 'priority' => 23, | |
| 82 | - 'help_text' => esc_html__( 'The date format', 'weforms' ), | |
| 83 | - ], | |
| 84 | - [ | |
| 85 | - 'name' => 'time', | |
| 86 | - 'title' => '', | |
| 87 | - 'type' => 'checkbox', | |
| 88 | - 'is_single_opt' => true, | |
| 89 | - 'options' => [ | |
| 90 | - 'yes' => esc_html__( 'Enable time input', 'weforms' ), | |
| 91 | - ], | |
| 92 | - 'section' => 'advanced', | |
| 93 | - 'priority' => 24, | |
| 94 | - 'help_text' => '', | |
| 95 | - ], | |
| 96 | - [ | |
| 97 | - 'name' => 'is_publish_time', | |
| 98 | - 'title' => '', | |
| 99 | - 'type' => 'checkbox', | |
| 100 | - 'is_single_opt' => true, | |
| 101 | - 'options' => [ | |
| 102 | - 'yes' => esc_html__( 'Set this as publish time input', 'weforms' ), | |
| 103 | - ], | |
| 104 | - 'section' => 'advanced', | |
| 105 | - 'priority' => 24, | |
| 106 | - 'help_text' => '', | |
| 107 | - ], | |
| 108 | - [ | |
| 109 | - 'name' => 'enforce_format', | |
| 110 | - 'title' => __( 'Toggle Keyboard input for Date', 'weforms' ), | |
| 111 | - 'type' => 'checkbox', | |
| 112 | - 'section' => 'advanced', | |
| 113 | - 'is_single_opt' => true, | |
| 114 | - 'options' => [ | |
| 115 | - 'yes' => esc_html__( 'Force Datepicker Input', 'weforms' ), | |
| 116 | - ], | |
| 117 | - 'default' => 'yes', | |
| 118 | - 'priority' => 24, | |
| 119 | - 'help_text' => esc_html__( 'Disables Keyboard Input and uses the Datepicker Format', 'weforms' ), | |
| 120 | - ], | |
| 121 | - ]; | |
| 122 | - | |
| 123 | - return array_merge( $default_options, $settings ); | |
| 124 | - } | |
| 125 | - | |
| 126 | - /** | |
| 127 | - * Get the field props | |
| 128 | - * | |
| 129 | - * @return array | |
| 130 | - */ | |
| 131 | - public function get_field_props() { | |
| 132 | - $defaults = $this->default_attributes(); | |
| 133 | - $props = [ | |
| 134 | - 'format' => 'dd/mm/yy', | |
| 135 | - 'time' => '', | |
| 136 | - 'is_publish_time' => '', | |
| 137 | - 'enforce_format' => '', | |
| 138 | - ]; | |
| 139 | - | |
| 140 | - return array_merge( $defaults, $props ); | |
| 141 | - } | |
| 142 | - | |
| 143 | - /** | |
| 144 | - * Prepare entry | |
| 145 | - * | |
| 146 | - * @param $field | |
| 147 | - * | |
| 148 | - * @return mixed | |
| 149 | - */ | |
| 150 | - public function prepare_entry( $field, $args = [] ) { | |
| 151 | - if( empty( $_POST['_wpnonce'] ) ) { | |
| 152 | - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) ); | |
| 153 | - } | |
| 154 | - | |
| 155 | - if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_form_add' ) ) { | |
| 156 | - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) ); | |
| 157 | - } | |
| 158 | - | |
| 159 | - $args = ! empty( $args ) ? $args : weforms_clean( $_POST ); | |
| 160 | - | |
| 161 | - return sanitize_text_field( trim( $args[$field['name']] ) ); | |
| 162 | - } | |
| 163 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Date Field Class | |
| 5 | + */ | |
| 6 | +class WeForms_Form_Field_Date_Free extends WeForms_Field_Contract { | |
| 7 | + | |
| 8 | + function __construct() { | |
| 9 | + $this->name = __( 'Date / Time', 'weforms' ); | |
| 10 | + $this->input_type = 'date_field'; | |
| 11 | + $this->icon = 'calendar-o'; | |
| 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 | + $value = ''; | |
| 24 | + ?> | |
| 25 | + <li <?php $this->print_list_attributes( $field_settings ); ?>> | |
| 26 | + <?php $this->print_label( $field_settings ); ?> | |
| 27 | + | |
| 28 | + <div class="wpuf-fields"> | |
| 29 | + <input id="wpuf-date-<?php echo $field_settings['name']; ?>" type="text" class="datepicker <?php echo ' wpuf_'.$field_settings['name'].'_'.$form_id; ?>" data-required="<?php echo $field_settings['required'] ?>" data-type="text" name="<?php echo esc_attr( $field_settings['name'] ); ?>" placeholder="<?php echo esc_attr( $field_settings['format'] ); ?>" value="<?php echo esc_attr( $value ) ?>" size="30" /> | |
| 30 | + <?php $this->help_text( $field_settings ); ?> | |
| 31 | + </div> | |
| 32 | + <script type="text/javascript"> | |
| 33 | + jQuery(function($) { | |
| 34 | + <?php if ( $field_settings['time'] == 'yes' ) { ?> | |
| 35 | + $("#wpuf-date-<?php echo $field_settings['name']; ?>").datetimepicker({ dateFormat: '<?php echo $field_settings["format"]; ?>' }); | |
| 36 | + <?php } else { ?> | |
| 37 | + $("#wpuf-date-<?php echo $field_settings['name']; ?>").datepicker({ dateFormat: '<?php echo $field_settings["format"]; ?>' }); | |
| 38 | + <?php } ?> | |
| 39 | + }); | |
| 40 | + </script> | |
| 41 | + | |
| 42 | + </li> | |
| 43 | + <?php | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Get field options setting | |
| 48 | + * | |
| 49 | + * @return array | |
| 50 | + */ | |
| 51 | + public function get_options_settings() { | |
| 52 | + $default_options = $this->get_default_option_settings(); | |
| 53 | + | |
| 54 | + $settings = array( | |
| 55 | + array( | |
| 56 | + 'name' => 'format', | |
| 57 | + 'title' => __( 'Date Format', 'weforms' ), | |
| 58 | + 'type' => 'text', | |
| 59 | + 'section' => 'advanced', | |
| 60 | + 'priority' => 23, | |
| 61 | + 'help_text' => __( 'The date format', 'weforms' ), | |
| 62 | + ), | |
| 63 | + | |
| 64 | + array( | |
| 65 | + 'name' => 'time', | |
| 66 | + 'title' => '', | |
| 67 | + 'type' => 'checkbox', | |
| 68 | + 'is_single_opt' => true, | |
| 69 | + 'options' => array( | |
| 70 | + 'yes' => __( 'Enable time input', 'weforms' ) | |
| 71 | + ), | |
| 72 | + 'section' => 'advanced', | |
| 73 | + 'priority' => 24, | |
| 74 | + 'help_text' => '', | |
| 75 | + ), | |
| 76 | + | |
| 77 | + array( | |
| 78 | + 'name' => 'is_publish_time', | |
| 79 | + 'title' => '', | |
| 80 | + 'type' => 'checkbox', | |
| 81 | + 'is_single_opt' => true, | |
| 82 | + 'options' => array( | |
| 83 | + 'yes' => __( 'Set this as publish time input', 'weforms' ) | |
| 84 | + ), | |
| 85 | + 'section' => 'advanced', | |
| 86 | + 'priority' => 24, | |
| 87 | + 'help_text' => '', | |
| 88 | + ), | |
| 89 | + ); | |
| 90 | + | |
| 91 | + return array_merge( $default_options, $settings ); | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Get the field props | |
| 96 | + * | |
| 97 | + * @return array | |
| 98 | + */ | |
| 99 | + public function get_field_props() { | |
| 100 | + $defaults = $this->default_attributes(); | |
| 101 | + $props = array( | |
| 102 | + 'format' => 'dd/mm/yy', | |
| 103 | + 'time' => '', | |
| 104 | + 'is_publish_time' => '', | |
| 105 | + ); | |
| 106 | + | |
| 107 | + return array_merge( $defaults, $props ); | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * Prepare entry | |
| 112 | + * | |
| 113 | + * @param $field | |
| 114 | + * | |
| 115 | + * @return mixed | |
| 116 | + */ | |
| 117 | + public function prepare_entry( $field ) { | |
| 118 | + return sanitize_text_field( trim( $_POST[$field['name']] ) ); | |
| 119 | + } | |
| 120 | +} | |