PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.0
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.0
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / addons / basic / ma-countdown-timer / ma-countdown-timer.php

ma-countdown-timer.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.0, at addons/basic/ma-countdown-timer/ma-countdown-timer.php

1,110 lines 31.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MasterAddons\Addons;
4
5 /**
6 * Author Name: Liton Arefin
7 * Author URL : https: //jeweltheme.com
8 * Date : 6/27/19
9 */
10
11 use \Elementor\Controls_Manager;
12 use \Elementor\Group_Control_Border;
13 use \Elementor\Group_Control_Typography;
14 use \Elementor\Core\Kits\Documents\Tabs\Global_Typography;
15 use \Elementor\Group_Control_Background;
16 use \Elementor\Group_Control_Box_Shadow;
17 use \Elementor\Group_Control_Text_Shadow;
18
19 use MasterAddons\Inc\Admin\Config;
20 use MasterAddons\Inc\Classes\Helper;
21 use MasterAddons\Inc\Classes\Base\Master_Widget;
22
23 if (!defined('ABSPATH')) exit; // If this file is called directly, abort.
24
25 class Countdown_Timer extends Master_Widget
26 {
27 use \MasterAddons\Inc\Traits\Widget_Notice;
28 use \MasterAddons\Inc\Traits\Widget_Assets_Trait;
29
30 public function get_name()
31 {
32 return 'ma-el-countdown-timer';
33 }
34 public function get_title()
35 {
36 return esc_html__('Countdown Timer', 'master-addons' );
37 }
38 public function get_icon()
39 {
40 return 'jltma-icon ' . Config::get_addon_icon('ma-countdown-timer');
41 }
42
43
44 protected function register_controls()
45 {
46
47 /**
48 * Master Addons: Countdown Timer Settings
49 */
50 $this->start_controls_section(
51 'ma_el_section_countdown_settings_general',
52 [
53 'label' => esc_html__('Timer', 'master-addons' )
54 ]
55 );
56
57 $this->add_control(
58 'ma_el_countdown_time',
59 [
60 'label' => esc_html__('Countdown Date & Time', 'master-addons' ),
61 'type' => Controls_Manager::DATE_TIME,
62 'default' => wp_date("Y-m-d H:i:s", strtotime("+ 52 week")),
63 'description' => esc_html__('Set Datetime here', 'master-addons' ),
64 ]
65 );
66 // Repeat countdown feature - Pro version overrides via filter
67 $repeat_countdown_controls = apply_filters('master_addons/addons/countdown/repeat', [
68 [
69 'control_id' => 'ma_el_countdown_repeat_pro',
70 'args' => [
71 'type' => Controls_Manager::RAW_HTML,
72 'raw' => Helper::upgrade_to_pro('Repeat Countdown available on'),
73 'content_classes' => 'jltma-editor-doc-links',
74 ],
75 ],
76 ]);
77
78 // Add all controls from the filter
79 foreach ($repeat_countdown_controls as $control) {
80 $this->add_control($control['control_id'], $control['args']);
81 }
82
83
84 $this->end_controls_section();
85
86 $this->start_controls_section(
87 'ma_el_countdown_settings_general',
88 [
89 'label' => esc_html__('Countdown Settings', 'master-addons' )
90 ]
91 );
92
93 $this->add_control(
94 'ma_el_countdown_style',
95 [
96 'label' => esc_html__('Style Preset', 'master-addons' ),
97 'type' => Controls_Manager::SELECT,
98 'default' => 'block',
99 'options' => [
100 'block' => esc_html__('Block', 'master-addons' ),
101 'inline' => esc_html__('Inline', 'master-addons' ),
102 'block-table' => esc_html__('Block Table', 'master-addons' ),
103 'inline-table+' => esc_html__('Inline Table', 'master-addons' ),
104 ],
105 ]
106 );
107
108 $this->add_control(
109 'ma_el_seperator',
110 array(
111 'label' => __('Seperator', 'master-addons' ),
112 'type' => Controls_Manager::TEXT,
113 'default' => '/',
114 'condition' => [
115 'ma_el_countdown_style!' => 'inline-table+',
116 ],
117 )
118 );
119
120 $this->add_control(
121 'ma_el_show_year',
122 array(
123 'label' => __('Show Years?', 'master-addons' ),
124 'type' => Controls_Manager::SWITCHER,
125 'label_on' => __('On', 'master-addons' ),
126 'label_off' => __('Off', 'master-addons' ),
127 'return_value' => '1',
128 'default' => '1'
129 )
130 );
131
132 $this->add_control(
133 'ma_el_label_year',
134 array(
135 'label' => __('Years Label', 'master-addons' ),
136 'type' => Controls_Manager::TEXT,
137 'default' => esc_html__( 'Years', 'master-addons' ),
138 'description' => __('Set the label for years.', 'master-addons'),
139 'condition' => [
140 'ma_el_show_year' => '1',
141 ],
142 )
143 );
144
145 $this->add_control(
146 'ma_el_show_month',
147 array(
148 'label' => __('Show Month?', 'master-addons' ),
149 'type' => Controls_Manager::SWITCHER,
150 'label_on' => __('On', 'master-addons' ),
151 'label_off' => __('Off', 'master-addons' ),
152 'return_value' => '1',
153 'default' => '1'
154 )
155 );
156
157 $this->add_control(
158 'ma_el_label_month',
159 array(
160 'label' => __('Month Label', 'master-addons' ),
161 'type' => Controls_Manager::TEXT,
162 'default' => esc_html__( 'Month', 'master-addons' ),
163 'description' => __('Set the label for month.', 'master-addons'),
164 'condition' => [
165 'ma_el_show_month' => '1',
166 ],
167 )
168 );
169
170 $this->add_control(
171 'ma_el_show_day',
172 array(
173 'label' => __('Show Days?', 'master-addons' ),
174 'type' => Controls_Manager::SWITCHER,
175 'label_on' => __('On', 'master-addons' ),
176 'label_off' => __('Off', 'master-addons' ),
177 'return_value' => '1',
178 'default' => '1'
179 )
180 );
181
182 $this->add_control(
183 'ma_el_label_day',
184 array(
185 'label' => __('Days Label', 'master-addons' ),
186 'type' => Controls_Manager::TEXT,
187 'default' => esc_html__( 'Days', 'master-addons' ),
188 'description' => __('Set the label for days.', 'master-addons'),
189 'condition' => [
190 'ma_el_show_day' => '1',
191 ],
192 )
193 );
194
195 $this->add_control(
196 'ma_el_show_hour',
197 array(
198 'label' => __('Show Hours?', 'master-addons' ),
199 'type' => Controls_Manager::SWITCHER,
200 'label_on' => __('On', 'master-addons' ),
201 'label_off' => __('Off', 'master-addons' ),
202 'return_value' => '1',
203 'default' => '1'
204 )
205 );
206
207 $this->add_control(
208 'ma_el_label_hour',
209 array(
210 'label' => __('Hour Label', 'master-addons' ),
211 'type' => Controls_Manager::TEXT,
212 'default' => esc_html__( 'Hours', 'master-addons' ),
213 'description' => __('Set the label for hours.', 'master-addons'),
214 'condition' => [
215 'ma_el_show_hour' => '1',
216 ],
217 )
218 );
219
220 $this->add_control(
221 'ma_el_show_min',
222 array(
223 'label' => __('Show Minutes?', 'master-addons' ),
224 'type' => Controls_Manager::SWITCHER,
225 'label_on' => __('On', 'master-addons' ),
226 'label_off' => __('Off', 'master-addons' ),
227 'return_value' => '1',
228 'default' => '1'
229 )
230 );
231
232 $this->add_control(
233 'ma_el_label_min',
234 array(
235 'label' => __('Minutes Label', 'master-addons' ),
236 'type' => Controls_Manager::TEXT,
237 'default' => esc_html__( 'Minutes', 'master-addons' ),
238 'description' => __('Set the label for minutes.', 'master-addons'),
239 'condition' => [
240 'ma_el_show_min' => '1',
241 ],
242 )
243 );
244
245 $this->add_control(
246 'ma_el_show_sec',
247 array(
248 'label' => __('Show Seconds?', 'master-addons' ),
249 'type' => Controls_Manager::SWITCHER,
250 'label_on' => __('On', 'master-addons' ),
251 'label_off' => __('Off', 'master-addons' ),
252 'return_value' => '1',
253 'default' => '1'
254 )
255 );
256
257 $this->add_control(
258 'ma_el_label_sec',
259 array(
260 'label' => __('Seconds Label', 'master-addons' ),
261 'type' => Controls_Manager::TEXT,
262 'default' => esc_html__( 'Seconds', 'master-addons' ),
263 'description' => __('Set the label for seconds.', 'master-addons'),
264 'condition' => [
265 'ma_el_show_sec' => '1',
266 ],
267 )
268 );
269
270 $this->end_controls_section();
271
272 // Help Docs section (links from config.php)
273 $this->jltma_help_docs();
274
275 $this->upgrade_to_pro_message();
276
277 /*
278 * Countdown Timer Styling Section
279 */
280
281 $this->start_controls_section(
282 'ma_el_section_countdown_item_wrapper',
283 [
284 'label' => esc_html__('Common Style', 'master-addons' ),
285 'tab' => Controls_Manager::TAB_STYLE
286 ]
287 );
288
289 $this->add_control(
290 'jltma_countdown_item_width',
291 [
292 'label' => esc_html__( 'Width', 'master-addons' ),
293 'type' => Controls_Manager::SLIDER,
294 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
295 'range' => [
296 'px' => [
297 'min' => 0,
298 'max' => 1000,
299 'step' => 5,
300 ],
301 '%' => [
302 'min' => 0,
303 'max' => 100,
304 ],
305 ],
306 'default' => [
307 'unit' => 'px',
308 'size' => '',
309 ],
310 'selectors' => [
311 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item' => 'width: {{SIZE}}{{UNIT}};',
312 ],
313 ]
314 );
315
316 $this->add_control(
317 'jltma_countdown_item_height',
318 [
319 'label' => esc_html__( 'Height', 'master-addons' ),
320 'type' => Controls_Manager::SLIDER,
321 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
322 'range' => [
323 'px' => [
324 'min' => 0,
325 'max' => 1000,
326 'step' => 5,
327 ],
328 '%' => [
329 'min' => 0,
330 'max' => 100,
331 ],
332 ],
333 'default' => [
334 'unit' => 'px',
335 'size' => '',
336 ],
337 'selectors' => [
338 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item' => 'height: {{SIZE}}{{UNIT}};',
339 ],
340 ]
341 );
342
343 $this->add_responsive_control(
344 'ma_el_countdown_alignment',
345 [
346 'label' => esc_html__('Alignment', 'master-addons' ),
347 'type' => Controls_Manager::CHOOSE,
348 'label_block' => false,
349 'options' => Helper::jltma_content_alignment(),
350 'default' => 'center',
351 'selectors' => [
352 '{{WRAPPER}} .jltma-widget-countdown .jltma-countdown-wrapper.jltma-countdown-block' => 'justify-content: {{VALUE}};',
353 ],
354 ]
355 );
356
357 $this->add_group_control(
358 Group_Control_Box_Shadow::get_type(),
359 [
360 'name' => 'jltma_section_item_box_shadow',
361 'label' => __('Box Shadow', 'master-addons' ),
362 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item',
363 ]
364 );
365
366 $this->add_group_control(
367 Group_Control_Background::get_type(),
368 [
369 'name' => 'ma_el_section_item_wrapper_background',
370 'label' => __('Background', 'master-addons' ),
371 'types' => ['classic', 'gradient'],
372 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item'
373 ]
374 );
375
376 $this->add_responsive_control(
377 'ma_el_item_wrapper_border_radius',
378 array(
379 'label' => __('Border Radius', 'master-addons' ),
380 'type' => Controls_Manager::DIMENSIONS,
381 'size_units' => array('px', '%'),
382 'selectors' => array(
383 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
384 )
385 )
386 );
387
388 $this->add_responsive_control(
389 'ma_el_item_wrapper_margin',
390 array(
391 'label' => __('Margin', 'master-addons' ),
392 'type' => Controls_Manager::DIMENSIONS,
393 'size_units' => array('px', '%'),
394 'selectors' => array(
395 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
396 )
397 )
398 );
399
400 $this->add_responsive_control(
401 'ma_el_item_wrapper_padding',
402 array(
403 'label' => __('Padding', 'master-addons' ),
404 'type' => Controls_Manager::DIMENSIONS,
405 'size_units' => array('px', '%'),
406 'selectors' => array(
407 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
408 )
409 )
410 );
411
412 $this->end_controls_section();
413
414 /*
415 * Value Style
416 */
417
418 $this->start_controls_section(
419 'ma_el_value_style_section',
420 array(
421 'label' => __('Counter Style', 'master-addons' ),
422 'tab' => Controls_Manager::TAB_STYLE
423 )
424 );
425
426 // Year Item
427 $this->add_control(
428 'jltma_countdown_item_yrs_bg_heading',
429 [
430 'label' => __('Years Background', 'master-addons'),
431 'type' => Controls_Manager::HEADING,
432 'condition' => [
433 'ma_el_show_year' => '1',
434 ],
435 ]
436 );
437 $this->add_group_control(
438 Group_Control_Background::get_type(),
439 [
440 'name' => 'jltma_countdown_item_yrs_bg',
441 'label' => __('Years Background', 'master-addons' ),
442 'types' => ['classic', 'gradient'],
443 'separator' => 'after',
444 'condition' => [
445 'ma_el_show_year' => '1',
446 ],
447 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item-year'
448 ]
449 );
450
451 // Month Item
452 $this->add_control(
453 'jltma_countdown_item_month_bg_heading',
454 [
455 'label' => __('Month Background', 'master-addons'),
456 'type' => Controls_Manager::HEADING,
457 'separator' => 'before',
458 'condition' => [
459 'ma_el_show_month' => '1',
460 ],
461 ]
462 );
463 $this->add_group_control(
464 Group_Control_Background::get_type(),
465 [
466 'name' => 'jltma_countdown_item_month_bg',
467 'label' => __('Month Background', 'master-addons' ),
468 'types' => ['classic', 'gradient'],
469 'separator' => 'after',
470 'condition' => [
471 'ma_el_show_month' => '1',
472 ],
473 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item-month'
474 ]
475 );
476
477 // Day Item
478 $this->add_control(
479 'jltma_countdown_item_day_bg_heading',
480 [
481 'label' => __('Day Background', 'master-addons'),
482 'type' => Controls_Manager::HEADING,
483 'separator' => 'before',
484 'condition' => [
485 'ma_el_show_day' => '1',
486 ],
487 ]
488 );
489 $this->add_group_control(
490 Group_Control_Background::get_type(),
491 [
492 'name' => 'jltma_countdown_item_day_bg',
493 'label' => __('Day Background', 'master-addons' ),
494 'types' => ['classic', 'gradient'],
495 'separator' => 'after',
496 'condition' => [
497 'ma_el_show_day' => '1',
498 ],
499 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item-day'
500 ]
501 );
502
503 // Hour Item
504 $this->add_control(
505 'jltma_countdown_item_hour_bg_heading',
506 [
507 'label' => __('Hour Background', 'master-addons'),
508 'type' => Controls_Manager::HEADING,
509 'separator' => 'before',
510 'condition' => [
511 'ma_el_show_hour' => '1',
512 ],
513 ]
514 );
515 $this->add_group_control(
516 Group_Control_Background::get_type(),
517 [
518 'name' => 'jltma_countdown_item_hour_bg',
519 'label' => __('Hour Background', 'master-addons' ),
520 'types' => ['classic', 'gradient'],
521 'separator' => 'after',
522 'condition' => [
523 'ma_el_show_hour' => '1',
524 ],
525 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item-hour'
526 ]
527 );
528
529 // Minute Item
530 $this->add_control(
531 'jltma_countdown_item_mins_bg_heading',
532 [
533 'label' => __('Minute Background', 'master-addons'),
534 'type' => Controls_Manager::HEADING,
535 'separator' => 'before',
536 'condition' => [
537 'ma_el_show_min' => '1',
538 ],
539 ]
540 );
541 $this->add_group_control(
542 Group_Control_Background::get_type(),
543 [
544 'name' => 'jltma_countdown_item_mins_bg',
545 'label' => __('Minute Background', 'master-addons' ),
546 'types' => ['classic', 'gradient'],
547 'separator' => 'after',
548 'condition' => [
549 'ma_el_show_min' => '1',
550 ],
551 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item-min'
552 ]
553 );
554
555 // Second Item
556 $this->add_control(
557 'jltma_countdown_item_sec_bg_heading',
558 [
559 'label' => __('Second Background', 'master-addons'),
560 'type' => Controls_Manager::HEADING,
561 'separator' => 'before',
562 'condition' => [
563 'ma_el_show_sec' => '1',
564 ],
565 ]
566 );
567
568 $this->add_group_control(
569 Group_Control_Background::get_type(),
570 [
571 'name' => 'jltma_countdown_item_sec_bg',
572 'label' => __('Second Background', 'master-addons' ),
573 'types' => ['classic', 'gradient'],
574 'separator' => 'after',
575 'condition' => [
576 'ma_el_show_sec' => '1',
577 ],
578 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-item-sec'
579 ]
580 );
581
582 $this->start_controls_tabs('ma_el_value_colors', array( 'separator' => 'before', ));
583
584 $this->start_controls_tab(
585 'ma_el_value_color_normal',
586 array(
587 'label' => __('Normal', 'master-addons' ),
588 )
589 );
590
591 $this->add_control(
592 'ma_el_value_color',
593 array(
594 'label' => __('Color', 'master-addons' ),
595 'type' => Controls_Manager::COLOR,
596 'selectors' => array(
597 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-value' => 'color: {{VALUE}} !important;',
598 ),
599 )
600 );
601
602 $this->end_controls_tab();
603
604 $this->start_controls_tab(
605 'ma_el_value_color_hover',
606 array(
607 'label' => __('Hover', 'master-addons' ),
608 )
609 );
610
611 $this->add_control(
612 'ma_el_value_hover_color',
613 array(
614 'label' => __('Color', 'master-addons' ),
615 'type' => Controls_Manager::COLOR,
616 'selectors' => array(
617 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-value:hover' => 'color: {{VALUE}} !important;',
618 ),
619 )
620 );
621
622 $this->end_controls_tab();
623
624 $this->end_controls_tabs();
625
626 $this->add_group_control(
627 Group_Control_Typography::get_type(),
628 array(
629 'name' => 'ma_el_value_typography',
630 'global' => [
631 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
632 ],
633 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-value',
634 )
635 );
636
637 $this->add_group_control(
638 Group_Control_Text_Shadow::get_type(),
639 [
640 'name' => 'ma_el_value_shadow',
641 'label' => __('Text Shadow', 'master-addons' ),
642 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-value',
643 ]
644 );
645
646 $this->end_controls_section();
647
648 /*
649 * Separator Style
650 */
651
652 $this->start_controls_section(
653 'ma_el_seperator_style_section',
654 array(
655 'label' => __('Seperator', 'master-addons' ),
656 'tab' => Controls_Manager::TAB_STYLE
657 )
658 );
659
660 $this->start_controls_tabs('ma_el_seperator_colors');
661
662 $this->start_controls_tab(
663 'ma_el_seperator_color_normal',
664 array(
665 'label' => __('Normal', 'master-addons' ),
666 )
667 );
668
669 $this->add_control(
670 'ma_el_seperator_color',
671 array(
672 'label' => __('Color', 'master-addons' ),
673 'type' => Controls_Manager::COLOR,
674 'selectors' => array(
675 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-seperator' => 'color: {{VALUE}} !important;',
676 ),
677 )
678 );
679
680 $this->end_controls_tab();
681
682 $this->start_controls_tab(
683 'ma_el_seperator_color_hover',
684 array(
685 'label' => __('Hover', 'master-addons' ),
686 )
687 );
688
689 $this->add_control(
690 'ma_el_seperator_hover_color',
691 array(
692 'label' => __('Color', 'master-addons' ),
693 'type' => Controls_Manager::COLOR,
694 'selectors' => array(
695 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-seperator:hover' => 'color: {{VALUE}} !important;',
696 ),
697 )
698 );
699
700 $this->end_controls_tab();
701
702 $this->end_controls_tabs();
703
704 $this->add_group_control(
705 Group_Control_Typography::get_type(),
706 array(
707 'name' => 'ma_el_seperator_typography',
708 'global' => [
709 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
710 ],
711 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-seperator',
712 )
713 );
714
715 $this->add_group_control(
716 Group_Control_Text_Shadow::get_type(),
717 [
718 'name' => 'ma_el_seperator_shadow',
719 'label' => __('Text Shadow', 'master-addons' ),
720 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-seperator',
721 ]
722 );
723
724 $this->add_responsive_control(
725 'ma_el_seperator_padding',
726 array(
727 'label' => __('Padding', 'master-addons' ),
728 'type' => Controls_Manager::DIMENSIONS,
729 'size_units' => array('px', '%'),
730 'selectors' => array(
731 '{{WRAPPER}} .jltma-countdown-wrapper.jltma-countdown-inline .jltma-countdown-seperator' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
732 ),
733 'condition' => array(
734 'ma_el_countdown_style' => ['inline']
735 )
736 )
737 );
738
739 $this->add_responsive_control(
740 'ma_el_seperator_margin',
741 array(
742 'label' => __('Margin', 'master-addons' ),
743 'type' => Controls_Manager::DIMENSIONS,
744 'size_units' => array('px', '%'),
745 'selectors' => array(
746 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-seperator' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
747 )
748 )
749 );
750
751 $this->end_controls_section();
752
753 /*
754 * Box Style
755 */
756
757 $this->start_controls_section(
758 'ma_el_section_countdown_box_style',
759 [
760 'label' => esc_html__('Box Style', 'master-addons' ),
761 'tab' => Controls_Manager::TAB_STYLE,
762 'condition' => [
763 'ma_el_countdown_preset' => 'block',
764 ],
765 ]
766 );
767
768 $this->add_group_control(
769 Group_Control_Background::get_type(),
770 [
771 'name' => 'ma_el_countdown_background',
772 'label' => __('Background', 'master-addons' ),
773 'types' => ['classic', 'gradient'],
774 'selector' => '{{WRAPPER}} .jltma-countdown.block .jltma-countdown-container',
775 'condition' => [
776 'ma_el_countdown_preset' => 'block',
777 ],
778 ]
779 );
780
781 $this->add_group_control(
782 Group_Control_Box_Shadow::get_type(),
783 [
784 'name' => 'box_shadow',
785 'label' => __('Box Shadow', 'master-addons' ),
786 'selector' => '{{WRAPPER}} .jltma-countdown-container',
787 'condition' => [
788 'ma_el_countdown_preset' => 'block',
789 ],
790 ]
791 );
792
793 $this->add_control(
794 'ma_el_before_border',
795 [
796 'type' => Controls_Manager::DIVIDER,
797 'style' => 'thin',
798 'condition' => [
799 'ma_el_countdown_preset' => 'block',
800 ],
801 ]
802 );
803
804 $this->add_group_control(
805 Group_Control_Border::get_type(),
806 [
807 'name' => 'border',
808 'label' => __('Border', 'master-addons' ),
809 'selector' => '{{WRAPPER}} .jltma-countdown.block .jltma-countdown-container',
810 'condition' => [
811 'ma_el_countdown_preset' => 'style-1',
812 ],
813 ]
814 );
815
816 $this->add_control(
817 'ma_el_countdown_image_border_radius',
818 [
819 'label' => esc_html__('Border Radius', 'master-addons' ),
820 'type' => Controls_Manager::DIMENSIONS,
821 'selectors' => [
822 '{{WRAPPER}} .jltma-countdown.style-1 .jltma-countdown-container' => 'border-radius: {{TOP}}px {{RIGHT}}px {{BOTTOM}}px {{LEFT}}px;',
823 ],
824 'default' => [
825 'top' => 4,
826 'right' => 4,
827 'bottom' => 4,
828 'left' => 4,
829 'unit' => 'px',
830 'isLinked' => true,
831 ],
832 'condition' => [
833 'ma_el_countdown_preset' => 'style-1',
834 ],
835 ]
836 );
837
838 $this->end_controls_section();
839
840 $this->start_controls_section(
841 'ma_el_title_style_section',
842 array(
843 'label' => __('Label', 'master-addons' ),
844 'tab' => Controls_Manager::TAB_STYLE
845 )
846 );
847
848 $this->start_controls_tabs('ma_el_title_colors');
849
850 $this->start_controls_tab(
851 'ma_el_title_color_normal',
852 array(
853 'label' => __('Normal', 'master-addons' ),
854 )
855 );
856
857 $this->add_control(
858 'ma_el_title_color',
859 array(
860 'label' => __('Color', 'master-addons' ),
861 'type' => Controls_Manager::COLOR,
862 'selectors' => array(
863 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-title' => 'color: {{VALUE}} !important;',
864 ),
865 )
866 );
867
868 $this->end_controls_tab();
869
870 $this->start_controls_tab(
871 'ma_el_title_color_hover',
872 array(
873 'label' => __('Hover', 'master-addons' ),
874 )
875 );
876
877 $this->add_control(
878 'ma_el_title_hover_color',
879 array(
880 'label' => __('Color', 'master-addons' ),
881 'type' => Controls_Manager::COLOR,
882 'selectors' => array(
883 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-title:hover' => 'color: {{VALUE}} !important;',
884 ),
885 )
886 );
887
888 $this->end_controls_tab();
889
890 $this->end_controls_tabs();
891
892 $this->add_group_control(
893 Group_Control_Typography::get_type(),
894 array(
895 'name' => 'ma_el_title_typography',
896 'global' => [
897 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
898 ],
899 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-title',
900 )
901 );
902
903 $this->add_group_control(
904 Group_Control_Text_Shadow::get_type(),
905 [
906 'name' => 'ma_el_title_shadow',
907 'label' => __('Text Shadow', 'master-addons' ),
908 'selector' => '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-title',
909 ]
910 );
911
912 $this->add_responsive_control(
913 'ma_el_title_margin',
914 array(
915 'label' => __('Margin', 'master-addons' ),
916 'type' => Controls_Manager::DIMENSIONS,
917 'size_units' => array('px', '%'),
918 'selectors' => array(
919 '{{WRAPPER}} .jltma-countdown-wrapper .jltma-countdown-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
920 )
921 )
922 );
923
924 $this->end_controls_section();
925
926 }
927
928 /**
929 * Calculate current interval end time for repeating countdown
930 * Shows only the interval duration (e.g., 20 seconds) repeatedly until original time is reached
931 */
932 private function calculate_current_interval_end($original_datetime, $reset_duration_seconds, $widget_id) {
933 // Parse the datetime string properly accounting for WordPress timezone
934 $datetime_obj = new \DateTime($original_datetime, wp_timezone());
935 $original_timestamp = $datetime_obj->getTimestamp();
936
937 // Get current timestamp in WordPress timezone
938 $current_datetime = new \DateTime('now', wp_timezone());
939 $current_timestamp = $current_datetime->getTimestamp();
940
941 // If we've passed the original end time, return current time (will show as 0)
942 if ($current_timestamp >= $original_timestamp) {
943 return $current_timestamp;
944 }
945
946 // Get or set the start time for this widget's current interval
947 $transient_key = 'jltma_countdown_interval_' . $widget_id;
948 $interval_start = get_transient($transient_key);
949
950 // If no interval is set or the interval has expired
951 if ($interval_start === false || $current_timestamp >= ($interval_start + $reset_duration_seconds)) {
952 // Start a new interval from current time
953 $interval_start = $current_timestamp;
954 set_transient($transient_key, $interval_start, $reset_duration_seconds + 10);
955 }
956
957 // Calculate the end time of the current interval
958 // This will be current time + interval duration
959 $interval_end = $interval_start + $reset_duration_seconds;
960
961 // Make sure we don't go past the original end time
962 if ($interval_end > $original_timestamp) {
963 $interval_end = $original_timestamp;
964 }
965
966 return $interval_end;
967 }
968
969 protected function render()
970 {
971 $settings = $this->get_settings_for_display();
972
973 $countdown_style = $settings['ma_el_countdown_style'];
974 $countdown_time = $settings['ma_el_countdown_time'];
975 $seperator = $settings['ma_el_seperator'];
976
977 $data_value = '';
978 $attr_markup = '';
979 $date_attr = array();
980 $data_attr = '';
981
982 // Check if infinite countdown is enabled
983 $is_infinite = !empty($settings['ma_el_countdown_time_infinitive']) && $settings['ma_el_countdown_time_infinitive'] === 'yes';
984
985 // Calculate server-side interval for infinite countdown
986 if ($is_infinite) {
987 // Calculate reset duration in seconds
988 $reset_years = isset($settings['ma_el_countdown_reset_years']) ? intval($settings['ma_el_countdown_reset_years']) : 0;
989 $reset_months = isset($settings['ma_el_countdown_reset_months']) ? intval($settings['ma_el_countdown_reset_months']) : 0;
990 $reset_days = isset($settings['ma_el_countdown_reset_days']) ? intval($settings['ma_el_countdown_reset_days']) : 0;
991 $reset_hours = isset($settings['ma_el_countdown_reset_hour']) ? intval($settings['ma_el_countdown_reset_hour']) : 0;
992 $reset_minutes = isset($settings['ma_el_countdown_reset_minute']) ? intval($settings['ma_el_countdown_reset_minute']) : 0;
993 $reset_seconds = isset($settings['ma_el_countdown_reset_second']) ? intval($settings['ma_el_countdown_reset_second']) : 0;
994
995 // Convert to seconds (approximate for months/years)
996 $reset_duration_seconds = ($reset_years * 365 * 24 * 60 * 60) +
997 ($reset_months * 30 * 24 * 60 * 60) +
998 ($reset_days * 24 * 60 * 60) +
999 ($reset_hours * 60 * 60) +
1000 ($reset_minutes * 60) +
1001 $reset_seconds;
1002
1003 // Calculate current interval end time on server
1004 // Use widget ID to track intervals per widget instance
1005 $widget_id = $this->get_id();
1006 $current_interval_end = $this->calculate_current_interval_end($countdown_time, $reset_duration_seconds, $widget_id);
1007
1008 $datetime_for_display = new \DateTime('@' . $current_interval_end);
1009 $datetime_for_display->setTimezone(wp_timezone());
1010 $countdown_time = $datetime_for_display->format('Y-m-d H:i:s');
1011 }
1012
1013 $datetime = explode(" ", $countdown_time);
1014
1015 $date = $datetime[0];
1016 $time = !empty($datetime[1]) ? $datetime[1] : '';
1017
1018 $date = explode("-", $date);
1019 $time = explode(":", $time);
1020
1021 $date_attr = array(
1022 'year' => array(
1023 'value' => $date[0],
1024 'display' => $settings['ma_el_show_year'],
1025 'title' => $settings['ma_el_label_year'] ?? __('Years', 'master-addons'),
1026 ),
1027 'month' => array(
1028 'value' => !empty($date[1]) ? $date[1] - 1 : '',
1029 'display' => $settings['ma_el_show_month'],
1030 'title' => $settings['ma_el_label_month'] ?? __('Month', 'master-addons'),
1031 ),
1032 'day' => array(
1033 'value' => !empty($date[2]) ? $date[2] : '',
1034 'display' => $settings['ma_el_show_day'],
1035 'title' => $settings['ma_el_label_day'] ?? __('Days', 'master-addons'),
1036 ),
1037 'hour' => array(
1038 'value' => !empty($time[0]) ? $time[0] : '',
1039 'display' => $settings['ma_el_show_hour'],
1040 'title' =>$settings['ma_el_label_hour'] ?? __('Hours', 'master-addons' ),
1041 ),
1042 'min' => array(
1043 'value' => !empty($time[1]) ? $time[1] : '',
1044 'display' => $settings['ma_el_show_min'],
1045 'title' => $settings['ma_el_label_min'] ?? __('Minutes','master-addons'),
1046 ),
1047 'sec' => array(
1048 'value' => !empty($time[2]) ? $time[2] : '',
1049 'display' => $settings['ma_el_show_sec'],
1050 'title' => $settings['ma_el_label_sec'] ?? __('Seconds','master-addons')
1051 ),
1052 );
1053
1054 // remove last item separator
1055 $visible_units = array_filter($date_attr, fn($unit) => !empty($unit['display']));
1056 $last_unit_key = array_key_last($visible_units);
1057
1058 foreach ($date_attr as $attr => $key) {
1059
1060 $this->add_render_attribute(
1061 'jltma_countdown_keys',
1062 [
1063 'data-countdown-' . $attr => $key['value'],
1064 ]
1065 );
1066
1067 if ($key['display']) {
1068 $is_last_item = ($attr === $last_unit_key);
1069
1070 $attr_markup .= '<div class="jltma-countdown-item jltma-countdown-item-' . esc_attr( $attr ) . '">';
1071 $attr_markup .= '<span class="jltma-countdown-value jltma-countdown-' . esc_attr($attr) . '">' . __('0', 'master-addons' ) . '</span>';
1072 $attr_markup .= ('inline' === $countdown_style || 'inline-table' === $countdown_style) && !empty($seperator) ? '<span class="jltma-countdown-seperator">' . esc_attr($seperator) . '</span>' : '';
1073 $attr_markup .= '<span class="jltma-countdown-title">' . esc_html($key['title']) . '</span>';
1074 $attr_markup .= '</div>';
1075
1076 if (
1077 !empty($seperator) &&
1078 ('block' === $countdown_style || 'block-table' === $countdown_style) &&
1079 !$is_last_item
1080 ) {
1081 $attr_markup .= '<span class="jltma-countdown-seperator">' . esc_html($seperator) . '</span>';
1082 }
1083 }
1084 }
1085 // Add infinite countdown flag (server handles interval calculation)
1086 // The current interval end time is already calculated server-side above
1087 if (!empty($settings['ma_el_countdown_time_infinitive']) && $settings['ma_el_countdown_time_infinitive'] === 'yes') {
1088 $this->add_render_attribute('jltma_countdown_keys', 'data-countdown-infinite', 'yes');
1089 }
1090
1091 $this->add_render_attribute(
1092 'ma_el_countdown_timer',
1093 [
1094 'class' => [
1095 'jltma-countdown-wrapper',
1096 'jltma-countdown',
1097 'jltma-countdown-' . esc_attr($countdown_style),
1098 ],
1099 'id' => 'jltma-countdown-' . esc_attr($this->get_id()),
1100 ]
1101 );
1102
1103 $output = '<section class="widget-container jltma-widget-countdown"><div ' . $this->get_render_attribute_string('ma_el_countdown_timer') . ' ' . $this->get_render_attribute_string('jltma_countdown_keys') . '>';
1104 $output .= $attr_markup;
1105 $output .= '</div></section>';
1106
1107 echo wp_kses_post($output);
1108 }
1109 }
1110