PluginProbe
Uji Countdown / trunk
Uji Countdown vtrunk
3.0 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.6.1 1.0.7 1.0.8 1.0.9 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 36 releases
uji-countdown / classes / class-uji-countdown-front.php

class-uji-countdown-front.php in Uji Countdown trunk, at classes/class-uji-countdown-front.php

316 lines 12.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Uji Countdown Front
4 *
5 * Handles front-end/shorcodes
6 *
7 * @author WPmanage
8 * @category Front
9 * @package Uji-Countdown/Classes
10 * @version 2.1
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 class UjiCountdown extends Uji_Countdown {
18
19 /**
20 * Countdown data printed in the footer for frontend scripts.
21 *
22 * @var array
23 */
24 protected $valscript = array();
25
26 /**
27 * Init vars
28 *
29 * @since 2.0
30 */
31 public static function uji_vars() {
32 return array(
33 'class' => 'ujic_pos',
34 'ujic_style' => 'ujic_style',
35 'ujic_txt_size' => 'ujic_size',
36 'ujic_col_dw' => 'ujic_col_dw',
37 'ujic_col_up' => 'ujic_col_up',
38 'ujic_col_txt' => 'ujic_col_txt',
39 'ujic_col_sw' => 'ujic_col_sw',
40 'ujic_col_lab' => 'ujic_col_lab',
41 'ujic_lab_sz' => 'ujic_lab_sz',
42 'ujic_thick' => 'ujic_thick',
43 'ujic_txt' => 'ujic_txt',
44 'ujic_ani' => 'ujic_ani',
45 'ujic_no_box_color' => 'ujic_no_box_color',
46 'ujic_no_text_shadow' => 'ujic_no_text_shadow',
47 'ujic_d' => 'ujic_d',
48 'ujic_h' => 'ujic_h',
49 'ujic_m' => 'ujic_m',
50 'ujic_s' => 'ujic_s',
51 'ujic_y' => 'ujic_y',
52 'ujic_o' => 'ujic_o',
53 'ujic_w' => 'ujic_w',
54 'ujic_goof' => 'ujic_goof',
55 'ujic_post' => 'time',
56 );
57 }
58
59 /**
60 * Initialize the plugin frontend.
61 *
62 * @since 2.0
63 */
64 public function __construct() {
65 $this->valscript = array();
66 // add the shortcode
67 add_shortcode( 'ujicountdown', array( $this, 'ujic_shortcode' ) );
68 // add scripts/styles
69 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_ujic_scripts' ) );
70 // add JavaScript variable
71 add_action( 'wp_footer', array( $this, 'ujic_append_js' ), 1 );
72 }
73
74 /**
75 * Code will only be added if the script is already in the queue.
76 * With new block themes
77 *
78 * @since 2.3
79 */
80 public function ujic_append_js() {
81 if ( ! empty( $this->valscript ) ) {
82 foreach ( $this->valscript as $key => $val ) {
83 $val = apply_filters( 'ujic_front_localize_script', $val );
84 printf( '<script type="text/javascript">var ujiCount' . esc_attr( $key ) . '= %s</script>', ujic_esc_json( wp_json_encode( $val ), true ) );
85 }
86 }
87 }
88
89 /**
90 * Enqueue scripts/styles
91 *
92 * @since 2.3
93 */
94 public function enqueue_ujic_scripts() {
95 // Grab the global $post object.
96 global $post;
97
98 $has_shortcode = isset( $post->post_content ) && has_shortcode( $post->post_content, 'ujicountdown' );
99
100 if ( ! $has_shortcode && isset( $post->ID ) ) {
101 $elementor_data = get_post_meta( $post->ID, '_elementor_data', true );
102 $has_shortcode = is_string( $elementor_data ) && has_shortcode( $elementor_data, 'ujicountdown' );
103 }
104
105 // See if the post has our shortcode in content or Elementor widget data.
106 if ( $has_shortcode ) {
107 wp_enqueue_style( 'ujicountdown-uji-countdown' );
108 wp_enqueue_script( $this->ujic_pro_sx() . '-core' );
109
110 wp_enqueue_script( 'ujicirc-js' );
111 wp_enqueue_script( $this->ujic_pro_sx() . '-init' );
112 }
113 }
114
115 /**
116 * The shortcode
117 *
118 * @since 2.0
119 */
120 public function ujic_shortcode( $atts, $content = null ) {
121 extract(
122 shortcode_atts(
123 array(
124 // 'style' => "classic",
125 'id' => '',
126 'expire' => '',
127 'timer' => '',
128 'hide' => '',
129 'url' => '',
130 'subscr' => '',
131 'recurring' => '',
132 'rectype' => '',
133 'repeats' => '',
134 ),
135 $atts
136 )
137 );
138
139 $id = sanitize_text_field( $id );
140 $expire = sanitize_text_field( $expire );
141 $timer = sanitize_text_field( $timer );
142 $hide = sanitize_text_field( $hide );
143 $url = esc_url_raw( $url );
144 $subscr = sanitize_text_field( $subscr );
145 $recurring = sanitize_text_field( $recurring );
146 $rectype = sanitize_text_field( $rectype );
147 $repeats = sanitize_text_field( $repeats );
148
149 // Increment counters
150 static $ujic_count = 0;
151 $ujic_count++;
152
153 $rectime = false;
154
155 // 2015/03/24 05:05
156 $unx_time = strtotime( $expire . ':00' );
157 $now_time = (int) current_time( 'timestamp' );
158
159 $expired = ( $now_time > $unx_time ) ? true : false;
160
161 // Reccuring time
162 if ( $expired && $rectype && $recurring && is_numeric( $recurring ) ) {
163 // add multiple hour -> hours
164 $rectype = intval( $recurring ) > 1 ? $rectype . 's' : $rectype;
165
166 // Repeats
167 if ( $repeats && intval( $repeats ) > 0 ) {
168 // add time
169 for ( $t = 1; $t <= intval( $repeats ); $t++ ) {
170 $ujictime = strtotime( '+' . $t . ' ' . $rectype, $unx_time );
171 if ( $now_time < $ujictime ) {
172 $rectime = true;
173 break;
174 }
175 }
176 } else {
177 // init time
178 $ujictime = strtotime( '+' . $recurring . ' ' . $rectype, $unx_time );
179 $t = 1;
180 // repeat unlimited times
181 while ( $now_time > $ujictime ) {
182 $ujictime = strtotime( '+' . ( $recurring * $t ) . ' ' . $rectype, $unx_time );
183 $t++;
184 }
185 $rectime = true;
186 }
187 } else {
188 if ( $expired && $url ) {
189 $this->expired_redirect( $url );
190 }
191 }
192
193 // End Reccuring
194
195 if ( ( $hide == 'true' && $now_time > $unx_time && ! $rectime && ! $timer ) || ( $ujic_count > 1 && ! $this->ujic_pro() ) ) {
196
197 return $content;
198
199 } else {
200
201 // reccuring time
202 if ( $rectime ) {
203 $expire = date( 'Y/m/d H:i', $ujictime ); // 2015/03/24 05:05
204 }
205
206 $uji_mc = apply_filters( 'ujic_count_timers', $ujic_count );
207
208 // get all vars
209 $get_vars = self::uji_vars();
210
211 foreach ( $get_vars as $nm => $var ) {
212 ${$nm} = $this->sel_ujic_db( $id, $var );
213 $storeVal[ $nm ] = ${$nm};
214 }
215
216 $ujic_id = ( $uji_mc ) ? 'ujiCountdown' . $ujic_count : 'ujiCountdown';
217 $classh = ! empty( $ujic_style ) ? ' ujic-' . $ujic_style : '';
218 $hclass = ! empty( $class ) ? ' ujic_' . $class . '' : '';
219
220 // Days Cicle
221 $exp_time = strtotime( $expire );
222 $post_time = strtotime( $ujic_post );
223 $difference = $exp_time - $post_time;
224 $difference = ( $difference < 0 ) ? $difference = 0 : $difference;
225 $exp_d = floor( $difference / 60 / 60 / 24 );
226 $exp_days = ! empty( $exp_d ) ? $exp_d : '2000';
227
228 $ujic_count = ( esc_attr( $uji_mc ) ) ? esc_attr ( $ujic_count ) : '';
229 $timer_settings = get_option( 'ujic_set', array() );
230
231 $this->valscript[ $ujic_count ] = array(
232 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
233 'uji_plugin' => plugins_url(),
234 'uji_style' => esc_attr ( $ujic_style ),
235 'ujic_id' => esc_attr ( $ujic_id ),
236 'expire' => esc_attr ( $expire ),
237 'timer' => esc_attr ( $timer ),
238 'exp_days' => esc_attr ( $exp_days ),
239 'Years' => ( $this->ujic_get_option( 'ujic_years', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_years', $timer_settings ) : __( 'Years', 'ujicountdown' ),
240 'Year' => ( $this->ujic_get_option( 'ujic_year', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_year', $timer_settings ) : __( 'Year', 'ujicountdown' ),
241 'Months' => ( $this->ujic_get_option( 'ujic_months', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_months', $timer_settings ) : __( 'Months', 'ujicountdown' ),
242 'Month' => ( $this->ujic_get_option( 'ujic_month', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_month', $timer_settings ) : __( 'Month', 'ujicountdown' ),
243 'Weeks' => ( $this->ujic_get_option( 'ujic_weeks', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_weeks', $timer_settings ) : __( 'Weeks', 'ujicountdown' ),
244 'Week' => ( $this->ujic_get_option( 'ujic_week', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_week', $timer_settings ) : __( 'Week', 'ujicountdown' ),
245 'Days' => ( $this->ujic_get_option( 'ujic_days', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_days', $timer_settings ) : __( 'Days', 'ujicountdown' ),
246 'Day' => ( $this->ujic_get_option( 'ujic_day', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_day', $timer_settings ) : __( 'Day', 'ujicountdown' ),
247 'Hours' => ( $this->ujic_get_option( 'ujic_hours', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_hours', $timer_settings ) : __( 'Hours', 'ujicountdown' ),
248 'Hour' => ( $this->ujic_get_option( 'ujic_hour', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_hour', $timer_settings ) : __( 'Hour', 'ujicountdown' ),
249 'Minutes' => ( $this->ujic_get_option( 'ujic_minutes', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_minutes', $timer_settings ) : __( 'Minutes', 'ujicountdown' ),
250 'Minute' => ( $this->ujic_get_option( 'ujic_minute', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_minute', $timer_settings ) : __( 'Minute', 'ujicountdown' ),
251 'Seconds' => ( $this->ujic_get_option( 'ujic_seconds', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_seconds', $timer_settings ) : __( 'Seconds', 'ujicountdown' ),
252 'Second' => ( $this->ujic_get_option( 'ujic_second', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_second', $timer_settings ) : __( 'Second', 'ujicountdown' ),
253 'ujic_txt_size' => esc_attr ( $ujic_txt_size ),
254 'ujic_thick' => esc_attr ( $ujic_thick ),
255 'ujic_col_dw' => esc_attr ( $ujic_col_dw ),
256 'ujic_col_up' => esc_attr ( $ujic_col_up ),
257 'ujic_col_txt' => esc_attr ( $ujic_col_txt ),
258 'ujic_col_sw' => esc_attr ( $ujic_col_sw ),
259 'ujic_col_lab' => esc_attr ( $ujic_col_lab ),
260 'ujic_lab_sz' => esc_attr ( $ujic_lab_sz ),
261 'ujic_txt' => esc_attr ( $ujic_txt ),
262 'ujic_ani' => esc_attr ( $ujic_ani ),
263 'ujic_no_box_color' => esc_attr ( $ujic_no_box_color ),
264 'ujic_no_text_shadow' => esc_attr ( $ujic_no_text_shadow ),
265 'ujic_url' => esc_url ( $url ),
266 'ujic_goof' => esc_attr ( $ujic_goof ),
267 'uji_center' => esc_attr ( $classh ),
268 'ujic_d' => esc_attr ( $ujic_d ), // Main format: Days
269 'ujic_h' => esc_attr ( $ujic_h ), // Main format: Hours
270 'ujic_m' => esc_attr ( $ujic_m ), // Main format: Minutes
271 'ujic_s' => esc_attr ( $ujic_s ), // Main format: Seconds
272 'ujic_y' => esc_attr ( $ujic_y ), // Secondary format: Years
273 'ujic_o' => esc_attr ( $ujic_o ), // Secondary format: Months
274 'ujic_w' => esc_attr ( $ujic_w ), // Secondary format: Weeks
275 'uji_time' => date_i18n( 'M j, Y H:i:s' ) . '+0000',
276 'uji_hide' => ( $hide == 'true' ) ? 'true' : 'false',
277 'ujic_rtl' => ( $this->ujic_get_option( 'ujic_rtl', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_rtl', $timer_settings ) : false,
278 'uji_utime' => ( $this->ujic_get_option( 'ujic_utime', $timer_settings ) ) ? $this->ujic_get_option( 'ujic_utime', $timer_settings ) : false,
279 );
280
281 // ExtendStyle
282 $extStyle = '';
283 if ( has_filter( 'ujic_shortcode_extendStyle' ) ) {
284 $extStyle .= apply_filters( 'ujic_shortcode_extendStyle', $ujic_style, $storeVal );
285 }
286
287 // Filter shortcode
288 $ujicvars = array(
289 'id' => esc_attr( $id ),
290 'hclass' => esc_attr( $hclass ),
291 'subscr' => esc_html( $subscr ),
292 );
293 $formHtmlCode = apply_filters( 'ujic_shortcode_extend', $ujicvars );
294 if ( ! $formHtmlCode ) {
295 return strip_shortcodes( '<div class="ujic-hold' . esc_attr( $hclass ) . '"> <div class="ujiCountdown' . esc_attr( $classh ) . '" id="' . esc_attr( $ujic_id ) . '">' . wp_kses_post( $extStyle ) . '</div></div>' . $content );
296 }
297 // Else with extension
298
299 $formHtmlCode = ( is_array( $formHtmlCode ) ) ? '' : $formHtmlCode;
300
301 $htmlCode = strip_shortcodes( '<div class="ujic-hold' . esc_attr( $hclass ) . '"> <div id = "uji-wrapper" class = "ujicf"> <div class="ujicf ujiCountdown' . esc_attr( $classh ) . '" id="' . esc_attr( $ujic_id ) . '">' . wp_kses_post( $extStyle ) . '</div>' . wp_kses_post( $formHtmlCode ) . '</div></div>' . $content );
302
303 return $htmlCode;
304 }
305 }
306
307
308 public function expired_redirect( $url ) {
309 wp_enqueue_script( 'ujiCountRedirect' );
310 $script = 'ujiCountRedirect = ' . esc_url( $url ) . '; ';
311 wp_add_inline_script( 'ujiCountRedirect', wp_json_encode( $script ) , 'before' );
312 }
313
314
315 }
316