PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.6
ShopBuilder – WooCommerce Builder For Elementor v3.2.6
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Elementor / Widgets / General / CountDown / Render.php

Render.php in ShopBuilder – WooCommerce Builder For Elementor 3.2.6, at app/Elementor/Widgets/General/CountDown/Render.php

205 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Render class for Advanced Heading widget.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Elementor\Widgets\General\CountDown;
9
10 use DateTime;
11 use DateTimeZone;
12 use RadiusTheme\SB\Elementor\Helper\RenderHelpers;
13 use RadiusTheme\SB\Helpers\Fns;
14 use RadiusTheme\SB\Elementor\Render\GeneralAddons;
15
16 // Do not allow directly accessing this file.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit( 'This script cannot be accessed directly.' );
19 }
20
21 /**
22 * Render class.
23 *
24 * @package RadiusTheme\SB
25 */
26 class Render extends GeneralAddons {
27 /**
28 * Main render function for displaying content.
29 *
30 * @param array $data Data to be passed to the template.
31 * @param array $settings Widget settings.
32 *
33 * @return string
34 */
35 public function display_content( $data, $settings ) {
36 $this->settings = $settings;
37 $data = wp_parse_args( $this->get_template_args( $data['id'] ), $data );
38 $data = apply_filters( 'rtsb/general/countdown/args/' . $data['unique_name'], $data );
39 $data['content'] = Fns::load_template( $data['template'], $data, true );
40
41 return $this->addon_view( $data, $settings );
42 }
43 /**
44 * Retrieves template arguments based on widget settings.
45 *
46 * @return array
47 */
48 private function get_template_args( $id ) {
49 return [
50 'countdown_expire_time' => $this->format_date_time( $this->settings['countdown_date_time'] ),
51 'has_countdown_days' => ! empty( $this->settings['display_days'] ),
52 'has_countdown_hours' => ! empty( $this->settings['display_hours'] ),
53 'has_countdown_minutes' => ! empty( $this->settings['display_minutes'] ),
54 'has_countdown_seconds' => ! empty( $this->settings['display_seconds'] ),
55 'countdown_days_label' => $this->settings['countdown_days_label'] ?? '',
56 'countdown_hours_label' => $this->settings['countdown_hours_label'] ?? '',
57 'countdown_minutes_label' => $this->settings['countdown_minutes_label'] ?? '',
58 'countdown_seconds_label' => $this->settings['countdown_seconds_label'] ?? '',
59 'countdown_layout' => $this->settings['layout_style'] ?? 'rtsb-countdown-layout1',
60 'has_countdown_circle' => ! empty( $this->settings['layout_style'] ) && 'rtsb-countdown-layout5' === $this->settings['layout_style'] ? 'rtsb-countdown-circle' : '',
61 'circle_stroke_width' => $this->settings['countdown_circle_stroke']['size'] ?? 10,
62 'rtsb_countdown_layout6_html' => $this->render_countdown_layout6(),
63 ];
64 }
65 public function format_date_time( $date_time ) {
66 $timezone_string = get_option( 'timezone_string' );
67 $gmt_offset = get_option( 'gmt_offset' );
68 if ( $timezone_string ) {
69 $timezone = new DateTimeZone( $timezone_string );
70 } else {
71 $timezone = new DateTimeZone( sprintf( 'Etc/GMT%s', $gmt_offset >= 0 ? "-$gmt_offset" : '+' . abs( $gmt_offset ) ) );
72 }
73 $date = new DateTime( $date_time, $timezone );
74 return $date->getTimestamp() * 1000;
75 }
76 /**
77 * Function to render countdown.
78 *
79 * @param string $class countdown class name.
80 * @param string $countdown_label countdown label text.
81 *
82 * @return string
83 */
84 public static function render_countdown( $class, $countdown_label, $layout, $circle_stroke_width ) {
85 ob_start();
86 ?>
87 <div class="rtsb-countdown-item <?php echo esc_attr( $class ); ?>">
88 <span class="rtsb-countdown-count">00</span>
89 <span class="rtsb-countdown-count-text"><?php echo esc_html( $countdown_label ); ?></span>
90 <?php if ( 'rtsb-countdown-layout4' === $layout ) { ?>
91 <span class="rtsb-ex-shape rtsb-ex-shape-one">
92 <span></span>
93 </span>
94 <span class="rtsb-ex-shape rtsb-ex-shape-two">
95 <span></span>
96 </span>
97 <?php } ?>
98 <?php if ( 'rtsb-countdown-layout5' === $layout ) { ?>
99 <div class="rtsb-circle-canvas">
100 <svg width="200" height="200">
101 <circle r="<?php echo esc_attr( ( ( 200 / 2 ) - ( ( absint( $circle_stroke_width ) ) / 2 ) ) ); ?>" cx="<?php echo esc_attr( ( 200 / 2 ) ); ?>" cy="<?php echo ( ( ( 200 ) / 2 ) ); ?>" class="rtsbCircleTrack rtsbCircleTrackDown <?php echo esc_attr( $class ); ?>">
102 </circle>
103 <circle r="<?php echo esc_attr( ( ( 200 / 2 ) - ( ( absint( $circle_stroke_width ) ) / 2 ) ) ); ?>" cx="<?php echo esc_attr( ( 200 / 2 ) ); ?>" cy="<?php echo esc_attr( ( 200 / 2 ) ); ?>" class="rtsbCircleTrack rtsbCircleTrackUp <?php echo esc_attr( $class ); ?>">
104 </circle>
105 </svg>
106 </div>
107 <?php } ?>
108 </div>
109 <?php
110 return ob_get_clean();
111 }
112 /**
113 * Function to render countdown layout 6.
114 *
115 * @return string
116 */
117 public function render_countdown_layout6() {
118 ob_start();
119
120 $number_of_days = $this->calculate_days_from_timestamp( $this->format_date_time( $this->settings['countdown_date_time'] ?? '' ) );
121 $digit_count = strlen( (string) $number_of_days );
122 ?>
123 <?php if ( ! empty( $this->settings['display_days'] ) ) { ?>
124 <div class="rtsb-countdown-item rtsb-day">
125
126 <?php if ( ! empty( $this->settings['countdown_days_label'] ) ) { ?>
127 <span class="rtsb-countdown-count-text"><?php echo esc_html( $this->settings['countdown_days_label'] ); ?></span>
128 <?php } ?>
129
130 <span class="rtsb-countdown-count">
131 <?php
132 for ( $i = 1; $i <= $digit_count; $i++ ) {
133 echo '<span class="rtsb-countdown-single-digit rtsb-d' . absint( $i ) . '">0</span>';
134 }
135 ?>
136 </span>
137
138 </div>
139 <?php } ?>
140
141 <?php if ( ! empty( $this->settings['display_hours'] ) ) { ?>
142 <div class="rtsb-countdown-item rtsb-hr">
143 <?php if ( ! empty( $this->settings['countdown_hours_label'] ) ) : ?>
144 <span class="rtsb-countdown-count-text"><?php echo esc_html( $this->settings['countdown_hours_label'] ); ?></span>
145 <?php endif; ?>
146
147 <span class="rtsb-countdown-count">
148 <span class="rtsb-countdown-single-digit rtsb-h1">0</span>
149 <span class="rtsb-countdown-single-digit rtsb-h2">0</span>
150 </span>
151 </div>
152 <?php } ?>
153
154 <?php if ( ! empty( $this->settings['display_minutes'] ) ) { ?>
155 <div class="rtsb-countdown-item rtsb-min">
156 <?php if ( ! empty( $this->settings['countdown_minutes_label'] ) ) { ?>
157 <span class="rtsb-countdown-count-text"><?php echo esc_html( $this->settings['countdown_minutes_label'] ); ?></span>
158 <?php } ?>
159
160 <span class="rtsb-countdown-count">
161 <span class="rtsb-countdown-single-digit rtsb-m1">0</span>
162 <span class="rtsb-countdown-single-digit rtsb-m2">0</span>
163 </span>
164 </div>
165 <?php } ?>
166
167
168 <?php if ( ! empty( $this->settings['display_seconds'] ) ) { ?>
169 <div class="rtsb-countdown-item rtsb-sec">
170
171 <?php if ( ! empty( $this->settings['countdown_seconds_label'] ) ) { ?>
172 <span class="rtsb-countdown-count-text"><?php echo esc_html( $this->settings['countdown_seconds_label'] ); ?></span>
173 <?php } ?>
174
175 <span class="rtsb-countdown-count">
176 <span class="rtsb-countdown-single-digit rtsb-s1">0</span>
177 <span class="rtsb-countdown-single-digit rtsb-s2">0</span>
178 </span>
179 </div>
180 <?php } ?>
181 <?php
182 return ob_get_clean();
183 }
184
185 /**
186 * Calculate days from timestamp.
187 *
188 * @param int $millis_timestamp Timestamp in milliseconds.
189 *
190 * @return float|int
191 */
192 public function calculate_days_from_timestamp( $millis_timestamp ) {
193 if ( empty( $millis_timestamp ) ) {
194 return 0;
195 }
196
197 $millis_timestamp = (float) $millis_timestamp;
198 $timestamp_seconds = $millis_timestamp / 1000;
199 $current_time = time();
200 $difference_in_seconds = $timestamp_seconds - $current_time;
201
202 return abs( floor( $difference_in_seconds / 86400 ) );
203 }
204 }
205