PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.83
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.83
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / Flip_Countdown / Flip_Countdown.php

Flip_Countdown.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.83, at includes/widgets/Flip_Countdown/Flip_Countdown.php

427 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /** @noinspection SpellCheckingInspection, DuplicatedCode, PhpUnused */
2
3 namespace King_Addons;
4
5 use Elementor\Controls_Manager;
6 use Elementor\Group_Control_Box_Shadow;
7 use Elementor\Group_Control_Typography;
8 use Elementor\Widget_Base;
9
10 if (!defined('ABSPATH')) {
11 exit; // Exit if accessed directly.
12 }
13
14
15
16 class Flip_Countdown extends Widget_Base
17 {
18
19
20 public function get_name(): string
21 {
22 return 'king-addons-flip-countdown';
23 }
24
25 public function get_title(): string
26 {
27 return esc_html__('Flip Countdown & Timer', 'king-addons');
28 }
29
30 public function get_icon(): string
31 {
32 return 'king-addons-icon king-addons-flip-countdown';
33 }
34
35 public function get_script_depends(): array
36 {
37 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-flipclock-flipclock'];
38 }
39
40 public function get_style_depends(): array
41 {
42 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-flipclock-flipclock'];
43 }
44
45 public function get_categories(): array
46 {
47 return ['king-addons'];
48 }
49
50 public function get_keywords(): array
51 {
52 return ['flip countdown', 'flipping countdown', 'flipping', 'flip', 'countdown', 'clock', 'time', 'event',
53 'timer', 'classic', 'circle', 'rotate', 'flip clock', 'flip', 'rounded', '24', '12', 'day', 'daily', 'days',
54 'hour', 'hours', 'minute', 'minutes', 'second', 'seconds', 'counter', 'digits',
55 'flip-countdown', 'king addons', 'king', 'addons', 'kingaddons', 'king-addons'];
56 }
57
58 public function get_custom_help_url()
59 {
60 return 'mailto:bug@kingaddons.com?subject=Bug Report - King Addons&body=Please describe the issue';
61 }
62
63 protected function register_controls(): void
64 {
65 $this->start_controls_section(
66 'king_addons_flip_countdown_section',
67 [
68 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Flip Countdown', 'king-addons'),
69 'tab' => Controls_Manager::TAB_CONTENT,
70 ]
71 );
72
73 $this->add_control(
74 'king_addons_flip_countdown_date_time_notice',
75 [
76 'type' => Controls_Manager::NOTICE,
77 'notice_type' => 'warning',
78 'dismissible' => false,
79 'heading' => esc_html__('Notice', 'king-addons'),
80 'content' => esc_html__('If the current time looks wrong please check Timezone settings in WordPress Dashboard -> Settings -> General -> Timezone.', 'king-addons'),
81 'condition' => array(
82 'king_addons_flip_countdown_type' => 'fixed',
83 ),
84 ]
85 );
86
87 $this->add_control(
88 'king_addons_flip_countdown_type',
89 array(
90 'label' => esc_html__('Type', 'king-addons'),
91 'type' => Controls_Manager::SELECT,
92 'options' => array(
93 'fixed' => esc_html__('Fixed Timer', 'king-addons'),
94 'evergreen' => esc_html__('Evergreen Timer', 'king-addons'),
95 ),
96 'render_type' => 'template',
97 'default' => 'evergreen',
98 )
99 );
100
101 $this->add_control(
102 'king_addons_flip_countdown_date_time',
103 array(
104 'label' => esc_html__('Due Date', 'king-addons'),
105 'type' => Controls_Manager::DATE_TIME,
106 'condition' => array(
107 'king_addons_flip_countdown_type' => 'fixed',
108 ),
109 )
110 );
111
112 $this->add_control(
113 'king_addons_flip_countdown_evergreen_days',
114 array(
115 'label' => esc_html__('Days', 'king-addons'),
116 'type' => Controls_Manager::NUMBER,
117 'min' => 0,
118 'dynamic' => array('active' => true),
119 'render_type' => 'template',
120 'default' => 0,
121 'condition' => array(
122 'king_addons_flip_countdown_type' => 'evergreen',
123 ),
124 )
125 );
126
127 $this->add_control(
128 'king_addons_flip_countdown_evergreen_hours',
129 array(
130 'label' => esc_html__('Hours', 'king-addons'),
131 'type' => Controls_Manager::NUMBER,
132 'min' => 0,
133 'max' => 23,
134 'dynamic' => array('active' => true),
135 'render_type' => 'template',
136 'default' => 1,
137 'condition' => array(
138 'king_addons_flip_countdown_type' => 'evergreen',
139 ),
140 )
141 );
142
143 $this->add_control(
144 'king_addons_flip_countdown_evergreen_minutes',
145 array(
146 'label' => esc_html__('Minutes', 'king-addons'),
147 'type' => Controls_Manager::NUMBER,
148 'min' => 0,
149 'max' => 59,
150 'dynamic' => array('active' => true),
151 'render_type' => 'template',
152 'default' => 1,
153 'condition' => array(
154 'king_addons_flip_countdown_type' => 'evergreen',
155 ),
156 )
157 );
158
159 $this->add_control(
160 'king_addons_flip_countdown_evergreen_seconds',
161 array(
162 'label' => esc_html__('Seconds', 'king-addons'),
163 'type' => Controls_Manager::NUMBER,
164 'min' => 0,
165 'max' => 59,
166 'dynamic' => array('active' => true),
167 'render_type' => 'template',
168 'default' => 0,
169 'condition' => array(
170 'king_addons_flip_countdown_type' => 'evergreen',
171 ),
172 )
173 );
174
175 $this->add_control(
176 'king_addons_flip_clock_face',
177 array(
178 'label' => esc_html__('Clock Face', 'king-addons'),
179 'type' => Controls_Manager::SELECT,
180 'options' => array(
181 'DailyCounter' => esc_html__('Daily Counter', 'king-addons'),
182 'HourlyCounter' => esc_html__('Hourly Counter', 'king-addons'),
183 'MinuteCounter' => esc_html__('Minutes Counter', 'king-addons'),
184 'Counter' => esc_html__('Seconds Counter', 'king-addons'),
185 ),
186 'default' => 'HourlyCounter',
187 )
188 );
189
190 $this->add_control(
191 'king_addons_flip_countdown_show_seconds',
192 array(
193 'label' => esc_html__('Show Seconds', 'king-addons'),
194 'type' => Controls_Manager::SWITCHER,
195 'default' => true,
196 'return_value' => true,
197 'condition' => array(
198 'king_addons_flip_clock_face' => 'DailyCounter',
199 ),
200 )
201 );
202
203 $this->add_control(
204 'king_addons_flip_language',
205 array(
206 'label' => esc_html__('Language', 'king-addons'),
207 'type' => Controls_Manager::SELECT,
208 'options' => array(
209 'ar' => esc_html__('Arabic', 'king-addons'),
210 'zh' => esc_html__('Chinese', 'king-addons'),
211 'da' => esc_html__('Danish', 'king-addons'),
212 'nl' => esc_html__('Dutch', 'king-addons'),
213 'en' => esc_html__('English', 'king-addons'),
214 'fi' => esc_html__('Finnish', 'king-addons'),
215 'fr' => esc_html__('French', 'king-addons'),
216 'de' => esc_html__('German', 'king-addons'),
217 'it' => esc_html__('Italian', 'king-addons'),
218 'lv' => esc_html__('Latvian', 'king-addons'),
219 'no' => esc_html__('Norwegian', 'king-addons'),
220 'pt' => esc_html__('Portuguese', 'king-addons'),
221 'ru' => esc_html__('Russian', 'king-addons'),
222 'es' => esc_html__('Spanish', 'king-addons'),
223 'sv' => esc_html__('Swedish', 'king-addons'),
224 ),
225 'default' => 'en',
226 )
227 );
228
229 $this->end_controls_section();
230
231 /** TAB STYLE */
232
233 $this->start_controls_section(
234 'king_addons_flip_countdown_f_cardsection',
235 [
236 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Flip Card', 'king-addons'),
237 'tab' => Controls_Manager::TAB_STYLE,
238 ]
239 );
240
241 $this->add_control(
242 'king_addons_flip_countdown_bg_color',
243 [
244 'label' => esc_html__('Background Color', 'king-addons'),
245 'type' => Controls_Manager::COLOR,
246 'default' => '#333333',
247 'selectors' => [
248 '{{WRAPPER}} .king-addons-flip-clock-wrapper ul li a div div.inn' => 'background-color: {{VALUE}}',
249 ],
250 ]
251 );
252
253 $this->add_group_control(
254 Group_Control_Box_Shadow::get_type(),
255 [
256 'name' => 'king_addons_flip_countdown_shadow',
257 'selector' => '{{WRAPPER}} .king-addons-flip-clock-wrapper .king-addons-flip',
258 ]
259 );
260
261 $this->end_controls_section();
262
263 $this->start_controls_section(
264 'king_addons_flip_countdown_titles_section',
265 [
266 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Titles', 'king-addons'),
267 'tab' => Controls_Manager::TAB_STYLE,
268 ]
269 );
270
271 $this->add_group_control(
272 Group_Control_Typography::get_type(),
273 [
274 'name' => 'king_addons_flip_countdown_titles_typography',
275 'selector' => '{{WRAPPER}} .king-addons-flip-clock-divider .king-addons-flip-clock-label',
276 ]
277 );
278
279 $this->add_control(
280 'king_addons_flip_countdown_titles_typography_color',
281 [
282 'label' => esc_html__('Color', 'king-addons'),
283 'type' => Controls_Manager::COLOR,
284 'default' => '#000000',
285 'selectors' => [
286 '{{WRAPPER}} .king-addons-flip-clock-divider .king-addons-flip-clock-label' => 'color: {{VALUE}}',
287 ],
288 ]
289 );
290
291 $this->end_controls_section();
292
293 $this->start_controls_section(
294 'king_addons_flip_countdown_numbers_section',
295 [
296 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Numbers', 'king-addons'),
297 'tab' => Controls_Manager::TAB_STYLE,
298 ]
299 );
300
301 $this->add_group_control(
302 Group_Control_Typography::get_type(),
303 [
304 'name' => 'king_addons_flip_countdown_numbers_typography',
305 'selector' => '{{WRAPPER}} .king-addons-flip-clock-wrapper ul li a div div.inn',
306 ]
307 );
308
309 $this->add_control(
310 'king_addons_flip_countdown_numbers_typography_color',
311 [
312 'label' => esc_html__('Color', 'king-addons'),
313 'type' => Controls_Manager::COLOR,
314 'default' => '#CCCCCC',
315 'selectors' => [
316 '{{WRAPPER}} .king-addons-flip-clock-wrapper ul li a div div.inn' => 'color: {{VALUE}}',
317 ],
318 ]
319 );
320
321 $this->end_controls_section();
322
323 $this->start_controls_section(
324 'king_addons_flip_countdown_dots_section',
325 [
326 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Dots', 'king-addons'),
327 'tab' => Controls_Manager::TAB_STYLE,
328 ]
329 );
330
331 $this->add_control(
332 'king_addons_flip_countdown_dots_bg_color',
333 [
334 'label' => esc_html__('Color', 'king-addons'),
335 'type' => Controls_Manager::COLOR,
336 'default' => '#333333',
337 'selectors' => [
338 '{{WRAPPER}} .king-addons-flip-clock-dot' => 'background-color: {{VALUE}}',
339 ],
340 ]
341 );
342
343 $this->add_group_control(
344 Group_Control_Box_Shadow::get_type(),
345 [
346 'name' => 'king_addons_flip_countdown_dots_shadow',
347 'selector' => '{{WRAPPER}} .king-addons-flip-clock-dot',
348 ]
349 );
350
351 $this->end_controls_section();
352
353 $this->start_controls_section(
354 'king_addons_flip_countdown_separator_section',
355 [
356 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Separator', 'king-addons'),
357 'tab' => Controls_Manager::TAB_STYLE,
358 ]
359 );
360
361 $this->add_control(
362 'king_addons_flip_countdown_separator_bg_color',
363 [
364 'label' => esc_html__('Color', 'king-addons'),
365 'type' => Controls_Manager::COLOR,
366 'default' => 'rgba(0, 0, 0, 0.4)',
367 'selectors' => [
368 '{{WRAPPER}} .king-addons-flip-clock-wrapper ul li a div.up:after' => 'background-color: {{VALUE}}',
369 ],
370 ]
371 );
372
373
374
375
376 $this->end_controls_section();
377
378
379
380 }
381
382 protected function render(): void
383 {
384 $settings = Core::displaySettings($this);
385 $id = $this->get_id();
386
387 if ($settings['king_addons_flip_countdown_type'] == 'evergreen') {
388 $days = (int) Core::jsNumber($settings, 'king_addons_flip_countdown_evergreen_days', 0);
389 $hours = (int) Core::jsNumber($settings, 'king_addons_flip_countdown_evergreen_hours', 1);
390 $minutes = (int) Core::jsNumber($settings, 'king_addons_flip_countdown_evergreen_minutes', 1);
391 $seconds = (int) Core::jsNumber($settings, 'king_addons_flip_countdown_evergreen_seconds', 0);
392 $time = $seconds + $minutes * 60 + $hours * 60 * 60 + $days * 24 * 60 * 60;
393 } else {
394 $time = strtotime($settings['king_addons_flip_countdown_date_time']) - current_time('timestamp');
395 }
396
397 echo '<div class="king-addons-countdown-' . esc_attr($id) . '"></div>';
398
399 $inline_js = "(function ($) {
400 function doFlipCountdown() {
401
402 // Grab the current date
403 let currentDate = new Date();
404 // Set some date in the future. In this case, it's always Jan 1
405 let futureDate = new Date(currentDate.getFullYear() + 1, 0, 1);
406 // Calculate the difference in seconds between the future and current date
407 let diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000;
408 // Instantiate a coutdown FlipClock
409 let clock = $('.king-addons-countdown-" . esc_js($id) . "').FlipClock(" . esc_js($time) . ", {
410 clockFace: '" . esc_js($settings['king_addons_flip_clock_face']) . "',
411 language: '" . esc_js($settings['king_addons_flip_language']) . "',
412 autoStart: true,
413 countdown: true,
414 showSeconds: " . esc_js(($settings['king_addons_flip_countdown_show_seconds']) ? 'true' : 'false') . "
415 });
416 }
417
418 if (document.readyState === 'complete') {
419 doFlipCountdown();
420 } else {
421 document.addEventListener('DOMContentLoaded', doFlipCountdown);
422 }
423 })(jQuery);";
424
425 wp_print_inline_script_tag($inline_js);
426 }
427 }