PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / trunk
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster vtrunk
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / elementor / modules / optin / fields / date.php

date.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster trunk, at includes/elementor/modules/optin/fields/date.php

246 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) || die();
4
5 class Sellkit_Elementor_Optin_Field_Date extends Sellkit_Elementor_Optin_Field_Base {
6
7 public static function get_field_type() {
8 return 'date';
9 }
10
11 public function get_input_type() {
12 return $this->field['native_html5'] ? 'date' : 'text';
13 }
14
15 public function get_class() {
16 return 'sellkit-field flatpickr';
17 }
18
19 public function get_style_depends() {
20 return [ 'flatpickr' ];
21 }
22
23 public function get_script_depends() {
24 return [ 'flatpickr' ];
25 }
26
27 public function add_field_render_attribute() {
28 parent::add_field_render_attribute();
29
30 $localization = $this->field['localization'];
31
32 if ( 'yes' === $localization ) {
33 $locale = $this->date_localization();
34 $this->load_localize_script( $locale );
35 $this->widget->add_render_attribute( 'field-' . $this->get_id(), 'data-locale', $locale );
36 }
37
38 $this->widget->add_render_attribute( 'field-' . $this->get_id(), [
39 $this->field['native_html5'] ? 'min' : 'data-min-date' => $this->field['min_date'],
40 $this->field['native_html5'] ? 'max' : 'data-max-date' => $this->field['max_date'],
41 ] );
42 }
43
44 public function render_content() {
45 ?>
46 <input <?php echo $this->widget->get_render_attribute_string( 'field-' . esc_attr( $this->get_id() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor-generated attributes. ?>>
47 <?php
48 }
49
50 public static function get_additional_controls() {
51 $commons = parent::get_common_controls();
52
53 return [
54 'label' => $commons['label'],
55 'field_value' => $commons['field_value'],
56 'placeholder' => $commons['placeholder'],
57 'min_date' => [
58 'label' => esc_html__( 'Min Date', 'sellkit' ),
59 'type' => 'date_time',
60 'label_block' => false,
61 'conditions' => [ 'terms' => [ parent::get_type_condition() ] ],
62 'picker_options' => [
63 'enableTime' => false,
64 'locale' => [
65 'firstDayOfWeek' => 1,
66 ],
67 ],
68 ],
69 'max_date' => [
70 'label' => esc_html__( 'Max Date', 'sellkit' ),
71 'type' => 'date_time',
72 'label_block' => false,
73 'conditions' => [ 'terms' => [ parent::get_type_condition() ] ],
74 'picker_options' => [
75 'enableTime' => false,
76 'locale' => [
77 'firstDayOfWeek' => 1,
78 ],
79 ],
80 ],
81 'localization' => [
82 'label' => esc_html__( 'Localization', 'sellkit' ),
83 'type' => 'switcher',
84 'return_value' => 'yes',
85 'conditions' => [ 'terms' => [ parent::get_type_condition() ] ],
86 ],
87 'native_html5' => [
88 'label' => esc_html__( 'Native HTML5', 'sellkit' ),
89 'type' => 'switcher',
90 'return_value' => 'true',
91 'conditions' => [ 'terms' => [ parent::get_type_condition() ] ],
92 ],
93 'required' => $commons['required'],
94 'width_responsive' => $commons['width_responsive'],
95 ];
96 }
97
98 private function date_localization() {
99 $wp_locale = get_locale();
100
101 $locales = [
102 'af' => '', // 'Afrikaans'
103 'ar' => 'ar', // 'Arabic'
104 'ary' => 'ar', // 'Moroccan Arabic'
105 'as' => '', // 'Assamese'
106 'azb' => 'az', // 'South Azerbaijani'
107 'az' => 'az', // 'Azerbaijani'
108 'bel' => 'be', // 'Belarusian'
109 'bg_BG' => 'bg', // 'Bulgarian'
110 'bn_BD' => 'bn', // 'Bengali (Bangladesh)'
111 'bo' => '', // 'Tibetan'
112 'bs_BA' => 'bs', // 'Bosnian'
113 'ca' => 'cat', // 'Catalan'
114 'ceb' => '', // 'Cebuano'
115 'cs_CZ' => 'cs', // 'Czech'
116 'cy' => 'cy', // 'Welsh'
117 'da_DK' => 'da', // 'Danish'
118 'de_CH_informal' => 'de', // 'German (Switzerland, Informal)'
119 'de_CH' => 'de', // 'German (Switzerland)'
120 'de_DE' => 'de', // 'German'
121 'de_DE_formal' => 'de', // 'German (Formal)'
122 'de_AT' => 'de', // 'German (Austria)'
123 'dzo' => '', // 'Dzongkha'
124 'el' => 'gr', // 'Greek'
125 'en_GB' => 'en', // 'English (UK)'
126 'en_AU' => 'en', // 'English (Australia)'
127 'en_CA' => 'en', // 'English (Canada)'
128 'en_ZA' => 'en', // 'English (South Africa)'
129 'en_NZ' => 'en', // 'English (New Zealand)'
130 'eo' => 'eo', // 'Esperanto'
131 'es_CL' => 'es', // 'Spanish (Chile)'
132 'es_ES' => 'es', // 'Spanish (Spain)'
133 'es_MX' => 'es', // 'Spanish (Mexico)'
134 'es_GT' => 'es', // 'Spanish (Guatemala)'
135 'es_CR' => 'es', // 'Spanish (Costa Rica)'
136 'es_CO' => 'es', // 'Spanish (Colombia)'
137 'es_PE' => 'es', // 'Spanish (Peru)'
138 'es_VE' => 'es', // 'Spanish (Venezuela)'
139 'es_AR' => 'es', // 'Spanish (Argentina)'
140 'et' => 'et', // 'Estonian'
141 'eu' => 'es', // 'Basque'
142 'fa_IR' => 'fa', // 'Persian'
143 'fi' => 'fi', // 'Finnish'
144 'fr_CA' => 'fr', // 'French (Canada)'
145 'fr_FR' => 'fr', // 'French (France)'
146 'fr_BE' => 'fr', // 'French (Belgium)'
147 'fur' => '', // 'Friulian'
148 'gd' => 'ga', // 'Scottish Gaelic'
149 'gl_ES' => 'es', // 'Galician'
150 'gu' => '', // 'Gujarati'
151 'haz' => '', // 'Hazaragi'
152 'he_IL' => 'he', // 'Hebrew'
153 'hi_IN' => 'hi', // 'Hindi'
154 'hr' => 'hr', // 'Croatian'
155 'hsb' => '', // 'Upper Sorbian'
156 'hu_HU' => 'hu', // 'Hungarian'
157 'hy' => '', // 'Armenian'
158 'id_ID' => 'id', // 'Indonesian'
159 'is_IS' => 'is', // 'Icelandic'
160 'it_IT' => 'it', // 'Italian'
161 'ja' => 'ja', // 'Japanese'
162 'jv_ID' => '', // 'Javanese'
163 'ka_GE' => 'ka', // 'Georgian'
164 'kab' => '', // 'Kabyle'
165 'kk' => 'kz', // 'Kazakh'
166 'km' => 'km', // 'Khmer'
167 'kn' => '', // 'Kannada'
168 'ko_KR' => 'ko', // 'Korean'
169 'ckb' => '', // 'Kurdish (Sorani)'
170 'lo' => '', // 'Lao'
171 'lt_LT' => 'lt', // 'Lithuanian'
172 'lv' => 'lv', // 'Latvian'
173 'mk_MK' => 'mk', // 'Macedonian'
174 'ml_IN' => '', // 'Malayalam'
175 'mn' => 'mn', // 'Mongolian'
176 'mr' => '', // 'Marathi'
177 'ms_MY' => 'ms', // 'Malay'
178 'my_MM' => 'my', // 'Myanmar (Burmese)'
179 'nb_NO' => 'no', // 'Norwegian (Bokmål)'
180 'ne_NP' => '', // 'Nepali'
181 'nl_NL' => 'nl', // 'Dutch'
182 'nl_NL_formal' => 'nl', // 'Dutch (Formal)'
183 'nl_BE' => 'nl', // 'Dutch (Belgium)'
184 'nn_NO' => 'no', // 'Norwegian (Nynorsk)'
185 'oci' => '', // 'Occitan'
186 'pa_IN' => 'pa', // 'Punjabi'
187 'pl_PL' => 'pl', // 'Polish'
188 'ps' => '', // 'Pashto'
189 'pt_BR' => 'pt', // 'Portuguese (Brazil)'
190 'pt_AO' => 'pt', // 'Portuguese (Angola)'
191 'pt_PT' => 'pt', // 'Portuguese (Portugal)'
192 'pt_PT_ao90' => 'pt', // 'Portuguese (Portugal, AO90)'
193 'rhg' => '', // 'Rohingya'
194 'ro_RO' => 'ro', // 'Romanian'
195 'ru_RU' => 'ru', // 'Russian'
196 'sah' => '', // 'Sakha'
197 'si_LK' => 'si', // 'Sinhala'
198 'sk_SK' => 'sk', // 'Slovak'
199 'skr' => '', // 'Saraiki'
200 'sl_SI' => 'sl', // 'Slovenian'
201 'sq' => 'sq', // 'Albanian'
202 'sr_RS' => 'sr', // 'Serbian'
203 'sv_SE' => 'sv', // 'Swedish'
204 'sw' => '', // 'Swahili'
205 'szl' => '', // 'Silesian'
206 'ta_IN' => '', // 'Tamil'
207 'te' => '', // 'Telugu'
208 'th' => 'th', // 'Thai'
209 'tl' => '', // 'Tagalog'
210 'tr_TR' => 'tr', // 'Turkish'
211 'tt_RU' => '', // 'Tatar'
212 'tah' => '', // 'Tahitian'
213 'ug_CN' => '', // 'Uighur'
214 'uk' => 'uk', // 'Ukrainian'
215 'ur' => '', // 'Urdu'
216 'uz_UZ' => '', // 'Uzbek'
217 'vi' => 'vn', // 'Vietnamese'
218 'zh_HK' => 'zh', // 'Chinese (Hong Kong)'
219 'zh_TW' => 'zh-tw', // 'Chinese (Taiwan)'
220 'zh_CN' => 'zh', // 'Chinese (China)'
221 ];
222
223 $result = array_key_exists( $wp_locale, $locales ) ? $locales[ $wp_locale ] : 'default';
224
225 if ( 'en' === $result || '' === $result ) {
226 $result = 'default';
227 }
228
229 return $result;
230 }
231
232 private function load_localize_script( $locale ) {
233 if ( 'default' === $locale ) {
234 return;
235 }
236
237 wp_enqueue_script( 'sellkit_flatpickr_localize',
238 sellkit()->plugin_url() . 'assets/lib/flatpickr-locale/' . $locale . '.js',
239 [ 'flatpickr' ],
240 '4.1.4',
241 true
242 );
243 }
244
245 }
246