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