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-widget.php

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

358 lines 16.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Uji Countdown Widget
4 *
5 * Handles front-end/shorcodes Widgets
6 *
7 * @author WPmanage
8 * @category Widget
9 * @package Uji-Countdown/Classes
10 * @version 2.0
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 class ujic_Widget extends WP_Widget {
18 /**
19 * Uji Countdown Init
20 *
21 * @since 2.0
22 *
23 * @var string
24 */
25 public function __construct() {
26 $widget_ops = array(
27 'classname' => 'uji_Widget',
28 'description' => 'Uji Countdown widget.'
29 );
30 //WP 4.3.0
31 parent::__construct( 'uji_Widget', 'Uji Countdown', $widget_ops );
32
33 //actions
34 add_action( 'plugins_loaded', array( &$this, 'load_textdomain' ) );
35 add_action( 'admin_enqueue_scripts', array( &$this, 'admin_widgets_scripts_styles' ) );
36 }
37
38 /**
39 * Uji Countdown Admin Scripts
40 *
41 * @since 2.0
42 *
43 * @var string
44 */
45 public function admin_widgets_scripts_styles( $page ) {
46 if ( $page !== 'widgets.php' )
47 return;
48
49 wp_enqueue_script( 'jquery-ui-datepicker' );
50 wp_enqueue_style( 'jquery-ui', UJICOUNTDOWN_URL . 'assets/css/jquery-ui.min.css' );
51 wp_enqueue_script( 'jquery-widget', UJICOUNTDOWN_URL . 'assets/js/widget.js' );
52 }
53
54 /**
55 * Uji Countdown Form
56 *
57 * @since 2.0
58 *
59 * @var string
60 */
61 public function ujic_forms( $sel = NULL ) {
62 global $wpdb;
63 $table_name = $wpdb->prefix . "uji_counter";
64 $ujic_datas = $wpdb->get_results( "SELECT * FROM $table_name ORDER BY `time` DESC" );
65 if ( !empty( $ujic_datas ) ) {
66 $ujictab = '';
67 foreach ( $ujic_datas as $ujic ) {
68 $type = !empty( $ujic->style ) ? $ujic->style : "classic";
69 $select = (isset( $sel ) && !empty( $sel ) && $sel == $ujic->title ) ? ' selected="selected"' : '';
70 $ujictab .='<option value="' . esc_attr( $ujic->title ) . '" data-type=' . esc_attr( $type ) . ' ' . $select . '> ' . esc_html( $ujic->title ) . ' - ' . esc_html( $type ) . ' </option>';
71 }
72 return $ujictab;
73 } else {
74 return false;
75 }
76 }
77
78 /**
79 * Uji Countdown Time select
80 *
81 * @since 2.0.4
82 *
83 * @var string
84 */
85 public function ujic_times( $sel = NULL ) {
86 $times = array('second'=> 'Second(s)', 'minute'=> 'Minute(s)', 'hour'=> 'Hour(s)', 'day'=> 'Day(s)', 'week'=> 'Week(s)', 'month'=> 'Month(s)');
87 $output = '';
88
89 foreach ( $times as $value => $option ) {
90 $select = (isset( $sel ) && !empty( $sel ) && $sel == $value ) ? ' selected="selected"' : '';
91 $output .= '<option value="' . $value . '" ' . $select . '>' . $option . '</option>' . "\n";
92 }
93
94 return $output;
95 }
96 /**
97 * Uji Countdown Get Time/Date
98 *
99 * @since 2.0
100 *
101 * @var string
102 */
103 public function ujic_sel_datetime( $nr, $sel = null ) {
104 $num = array();
105 for ( $i = 0; $i <= $nr; $i++ ) {
106 $num[sprintf( "%02s", $i )] = sprintf( "%02s", $i );
107 }
108 $numbers = '';
109 foreach ( $num as $n ) {
110 $select = (isset( $sel ) && !empty( $sel ) && $sel == $n) ? ' selected="selected"' : '';
111 $numbers .='<option value="' . $n . '"' . $select . '> ' . $n . ' </option>';
112 }
113
114 return $numbers;
115 }
116
117 /**
118 * Uji Countdown Widget
119 *
120 * @since 2.0
121 *
122 * @var string
123 */
124 public function widget( $args, $instance ) {
125 extract( $args, EXTR_SKIP );
126
127 /* Our variables from the widget settings. */
128 $title = apply_filters( 'widget_UJI_title', $instance['UJI_title'] ?? '', $instance, $this->id_base );
129 $name = isset( $instance['UJI_style'] ) ? $instance['UJI_style'] : false;
130 $date = isset( $instance['UJI_date'] ) ? $instance['UJI_date'] : false;
131 $hour = isset( $instance['UJI_hours'] ) ? $instance['UJI_hours'] : false;
132 $minut = isset( $instance['UJI_minutes'] ) ? $instance['UJI_minutes'] : false;
133 $hide = isset( $instance['UJI_hide'] ) ? $instance['UJI_hide'] : false;
134 $url = isset( $instance['UJI_url'] ) ? $instance['UJI_url'] : false;
135 $subscr = isset( $instance['UJI_subscr'] ) ? $instance['UJI_subscr'] : false;
136 $recurr = isset( $instance['UJI_recurring'] ) ? $instance['UJI_recurring'] : false;
137 $rectyp = isset( $instance['UJI_rectype'] ) ? $instance['UJI_rectype'] : false;
138 $repeat = isset( $instance['UJI_repeats'] ) ? $instance['UJI_repeats'] : false;
139 $type = isset( $instance['UJI_type'] ) ? $instance['UJI_type'] : false;
140 $timer_hr = isset( $instance['UJI_thou'] ) ? $instance['UJI_thou'] : false;
141 $timer_mn = isset( $instance['UJI_tmin'] ) ? $instance['UJI_tmin'] : false;
142 $timer_sc = isset( $instance['UJI_tsec'] ) ? $instance['UJI_tsec'] : false;
143
144 $shtval = '';
145 $shtval .= (!empty( $name ) ) ? ' id="' . $name . '"' : '';
146 if( $type == 'ujic_type_one' ){
147 $shtval .= (!empty( $date ) ) ? ' expire="' . $date . ' ' . $hour . ':' . $minut . '"' : '';
148 }
149 if( $type == 'ujic_type_rep' ){
150 $shtval .= (!empty( $date ) ) ? ' timer="' . $timer_hr . ':' . $timer_mn . ':' . $timer_sc : '';
151 }
152 $shtval .= (!empty( $hide ) ) ? ' hide = "true"' : '';
153 $shtval .= (!empty( $url ) ) ? ' url = "' . $url . '"' : '';
154 $shtval .= (!empty( $subscr ) ) ? ' subscr = "' . trim($subscr) . '"' : '';
155 $shtval .= (!empty( $recurr ) ) ? ' recurring = "' . trim($recurr) . '"' : '';
156 $shtval .= (!empty( $rectyp ) ) ? ' rectype = "' . trim($rectyp) . '"' : '';
157 $shtval .= (!empty( $repeat ) ) ? ' repeats = "' . trim($repeat) . '"' : '';
158
159
160 $shortcode = (!empty( $shtval ) ) ? '[ujicountdown' . $shtval . ']' : '';
161
162
163 if ( !empty( $shortcode ) ) {
164 echo $before_widget;
165 if ( $title )
166 echo $before_title . $title . $after_title;
167 echo do_shortcode( $shortcode );
168 echo $after_widget;
169 }
170 }
171
172 /**
173 * Uji Countdown Update
174 *
175 * @since 2.0
176 *
177 * @var string
178 */
179 public function update( $new_instance, $old_instance ) {
180 $instance = $old_instance;
181 $instance['UJI_title'] = sanitize_text_field( $new_instance['UJI_title'] ?? '' );
182 $instance['UJI_style'] = sanitize_text_field( $new_instance['UJI_style'] ?? '' );
183 $instance['UJI_date'] = sanitize_text_field( $new_instance['UJI_date'] ?? '' );
184 $instance['UJI_hours'] = sanitize_text_field( $new_instance['UJI_hours'] ?? '' );
185 $instance['UJI_minutes'] = sanitize_text_field( $new_instance['UJI_minutes'] ?? '' );
186 $instance['UJI_hide'] = sanitize_text_field( $new_instance['UJI_hide'] ?? '' );
187 $instance['UJI_url'] = esc_url_raw( $new_instance['UJI_url'] ?? '' );
188 $instance['UJI_subscr'] = sanitize_text_field( $new_instance['UJI_subscr'] ?? '' );
189 $instance['UJI_recurring'] = sanitize_text_field( $new_instance['UJI_recurring'] ?? '' );
190 $instance['UJI_rectype'] = sanitize_text_field( $new_instance['UJI_rectype'] ?? '' );
191 $instance['UJI_repeats'] = sanitize_text_field( $new_instance['UJI_repeats'] ?? '' );
192
193 $instance['UJI_type'] = sanitize_text_field( $new_instance['UJI_type'] ?? '' );
194 $instance['UJI_thou'] = sanitize_text_field( $new_instance['UJI_thou'] ?? '' );
195 $instance['UJI_tmin'] = sanitize_text_field( $new_instance['UJI_tmin'] ?? '' );
196 $instance['UJI_tsec'] = sanitize_text_field( $new_instance['UJI_tsec'] ?? '' );
197
198
199 return $instance;
200 }
201
202 /**
203 * Uji Countdown Form
204 *
205 * @since 2.0
206 *
207 * @var string
208 */
209 public function form( $instance ) {
210
211 $defaults = array(
212 'UJI_title' => '',
213 'UJI_style' => false,
214 'UJI_date' => '',
215 'UJI_hours' => 23,
216 'UJI_minutes' => 59,
217 'UJI_hide' => '',
218 'UJI_url' => '',
219 'UJI_subscr' => '',
220 'UJI_recurring' => '',
221 'UJI_rectype' => '',
222 'UJI_repeats' => '',
223 'UJI_type' => '',
224 'UJI_thou' => '',
225 'UJI_tmin' => '',
226 'UJI_tsec' => ''
227 );
228
229 $instance = wp_parse_args( (array) $instance, $defaults );
230
231 if ( ! ujic_is_pro_active() ):
232 ?>
233
234 <div style="font-size:11px">
235 <strong>Only one timer on page is allowed. </strong><br>Check the <a href="http://www.wpmanage.com/uji-countdown" target="_blank">Pro version</a> for multiple countdown timers on the same page.
236 </p>
237
238 <?php endif; ?>
239
240 <!-- Widget Title: Text Input -->
241 <div>
242 <label for="<?php echo $this->get_field_id( 'UJI_title' ); ?>"><?php _e( 'Title (optional):', 'ujicountdown' ); ?></label>
243 <input type="text" name="<?php echo $this->get_field_name( 'UJI_title' ); ?>" value="<?php echo esc_attr( $instance['UJI_title'] ); ?>" class="widefat" id="<?php echo $this->get_field_id( 'UJI_title' ); ?>" />
244 </div>
245
246 <!-- Widget Select Style: Select Input -->
247 <div>
248
249 <?php if ( $this->ujic_forms() ): ?>
250
251 <label for="<?php echo $this->get_field_id( 'UJI_style' ); ?>"><?php _e( 'Select a Style:', 'ujicountdown' ); ?></label>
252 <select name="<?php echo $this->get_field_name( 'UJI_style' ); ?>" class="widefat" id="<?php echo $this->get_field_id( 'UJI_style' ); ?>">
253 <?php
254 echo $this->ujic_forms( $instance['UJI_style'] );
255 ?>
256 </select>
257
258 <?php else: ?>
259
260 <h4 style="color: firebrick"><?php _e( 'Please create new timer style first.', 'ujicountdown' ); ?></h4>
261
262 <?php endif; ?>
263
264 </div>
265 <!-- Widget Type: Radio -->
266 <div>
267 <h4><?php _e( 'Timer Type:', 'ujicountdown' ); ?> </h4>
268 <label style="padding-right:5px"> <input type="radio" name="<?php echo $this->get_field_name( 'UJI_type' ); ?>" class="ujic_type_radio" <?php checked( $instance['UJI_type'], 'ujic_type_one' ) ?> value="ujic_type_one" checked="checked"> One Time Timer</label>
269 <label> <input type="radio" name="<?php echo $this->get_field_name( 'UJI_type' ); ?>" class="ujic_type_radio" <?php checked( $instance['UJI_type'], 'ujic_type_rep' ) ?> value="ujic_type_rep">Repeat Timer </label>
270
271 <small style="display:block; margin:10px 0"><?php _e( '<strong>One Time Timer:</strong> Timer will countinue until expiration time <br> <strong>Repeat Timer:</strong> Timer will restart on page refresh', 'ujicountdown' ); ?></small>
272 </div>
273
274 <!-- Widget Date: Text Input -->
275 <div class="ujict_rep" <?php if ($instance['UJI_type'] == 'ujic_type_one') echo ' style="display:none"'; ?>>
276 <label style="display:block"><?php _e( 'Select Time:', 'ujicountdown' ); ?></label>
277 <input type="text" name="<?php echo $this->get_field_name( 'UJI_thou' ); ?>" value="<?php echo esc_attr( $instance['UJI_thou'] ); ?>" placeholder="Hours" class="small-text" style="min-width: 80px;" id="<?php echo $this->get_field_id( 'UJI_thou' ); ?>" />
278 <input type="text" name="<?php echo $this->get_field_name( 'UJI_tmin' ); ?>" value="<?php echo esc_attr( $instance['UJI_tmin'] ); ?>" placeholder="Minutes" class="small-text" style="min-width: 80px;" id="<?php echo $this->get_field_id( 'UJI_tmin' ); ?>" />
279 <input type="text" name="<?php echo $this->get_field_name( 'UJI_tsec' ); ?>" value="<?php echo esc_attr( $instance['UJI_tsec'] ); ?>" placeholder="Seconds" class="small-text" style="min-width: 80px;" id="<?php echo $this->get_field_id( 'UJI_tsec' ); ?>" />
280 </div>
281
282 <!-- Widget Date: Text Input -->
283 <div class="ujict_one" <?php if ($instance['UJI_type'] == 'ujic_type_rep') echo ' style="display:none"'; ?>>
284 <label for="<?php echo $this->get_field_id( 'UJI_date' ); ?>"><?php _e( 'Expire Date:', 'ujicountdown' ); ?></label>
285 <input type="text" name="<?php echo $this->get_field_name( 'UJI_date' ); ?>" value="<?php echo esc_attr( $instance['UJI_date'] ); ?>" style="background: url('<?php echo UJICOUNTDOWN_URL ?>/assets/images/data-picker.png') no-repeat scroll right top; display:block; width: 100%;" class="widefat ujic_date" id="<?php echo $this->get_field_id( 'UJI_date' ); ?>" />
286 </div>
287
288 <!-- Widget Select Time: Select Input -->
289 <div class="ujict_one" <?php if ($instance['UJI_type'] == 'ujic_type_rep') echo ' style="display:none"'; ?>>
290 <label style="display:block; margin:10px 0"><?php _e( 'Select the Time:', 'ujicountdown' ); ?></label>
291 <div style="display: block;">
292 <div style="display: inline-block;">
293 <h4 style="margin:0"><?php _e( 'Hour:', 'ujicountdown' ); ?> </h4>
294 <select name="<?php echo $this->get_field_name( 'UJI_hours' ); ?>" style="width:50px;" id="<?php echo $this->get_field_id( 'UJI_hours' ); ?>">
295 <?php
296 echo $this->ujic_sel_datetime( 23, $instance['UJI_hours'] );
297 ?>
298 </select>
299 </div>
300 :
301 <div style="display: inline-block;">
302 <h4 style="margin:0"><?php _e( 'Minute:', 'ujicountdown' ); ?> </h4>
303 <select name="<?php echo $this->get_field_name( 'UJI_minutes' ); ?>" style="width:50px;" id="<?php echo $this->get_field_id( 'UJI_minutes' ); ?>">
304 <?php
305 echo $this->ujic_sel_datetime( 59, $instance['UJI_minutes'] );
306 ?>
307 </select>
308 </div>
309 </div>
310 </div>
311 <h4><?php _e( 'After Expiry:', 'ujicountdown' ); ?> </h4>
312 <!-- Widget Hide: Checkbox Input -->
313 <div style="margin:15px 0">
314 <label for="<?php echo $this->get_field_id( 'UJI_hide' ); ?>"><?php _e( 'Hide Countdown:', 'ujicountdown' ); ?></label>
315 <input class="ujic_exp" id="<?php echo $this->get_field_id( 'UJI_hide' ); ?>" name="<?php echo $this->get_field_name( 'UJI_hide' ); ?>" type="checkbox" value="hide" <?php checked( $instance['UJI_hide'], 'hide' ) ?> />
316 </div>
317
318 <!-- Widget Go to Link: Select Input -->
319 <div>
320 <label for="<?php echo $this->get_field_id( 'UJI_url' ); ?>"><?php _e( 'Or go to this link:', 'ujicountdown' ); ?></label><br />
321 <small><?php _e( 'Select URL to send after expire', 'ujicountdown' ); ?></small>
322 <input class="widefat ujic_link" id="<?php echo $this->get_field_id( 'UJI_url' ); ?>" name="<?php echo $this->get_field_name( 'UJI_url' ); ?>" type="text" value="<?php echo esc_url( $instance['UJI_url'] ); ?>" />
323 </div>
324
325 <!-- Widget Select Reccuring Time -->
326 <h4><?php _e( 'Reccuring Time:', 'ujicountdown' ); ?> </h4>
327
328 <div style="display:block; float: none;">
329 <span style="float:left; display: block; line-height: 28px; min-width: 55px; margin-right: 4px;"><?php _e( 'Every:', 'ujicountdown' ); ?> </span><input class="small-text" style="float:left; padding: 3px 5px;" id="<?php echo $this->get_field_id( 'UJI_recurring' ); ?>" name="<?php echo $this->get_field_name( 'UJI_recurring' ); ?>" type="text" value="<?php echo esc_attr( $instance['UJI_recurring'] ); ?>" />
330 <select name="<?php echo $this->get_field_name( 'UJI_rectype' ); ?>" id="<?php echo $this->get_field_id( 'UJI_rectype' ); ?>">
331 <?php
332 echo $this->ujic_times($instance['UJI_rectype']);
333 ?>
334 </select>
335 <div style="display:block; float: none;">
336 <span style="float:left; display: block; line-height: 28px; min-width: 55px; margin-right: 4px;"><?php _e( 'Repeats:', 'ujicountdown' ); ?> </span><input class="small-text" style="float:left; padding: 3px 5px;" id="<?php echo $this->get_field_id( 'UJI_repeats' ); ?>" name="<?php echo $this->get_field_name( 'UJI_repeats' ); ?>" type="text" value="<?php echo esc_attr( $instance['UJI_repeats'] ); ?>" />
337 <span style="display: inline-block; line-height: 28px; margin-left: 4px;"> <?php _e( 'leave it empty for unlimited', 'ujicountdown' ); ?> </span>
338 </div>
339 </div>
340
341 <!-- Widget Campaign name -->
342
343 <?php if ( defined( 'UJICSU_VERS' ) ): ?>
344
345 <h4><?php _e( 'Subscription:', 'ujicountdown' ); ?> </h4>
346 <div>
347 <label for="<?php echo $this->get_field_id( 'UJI_subscr' ); ?>"><?php _e( 'Campaign Name:', 'ujicountdown' ); ?></label><br />
348 <input class="widefat ujic_subscr" id="<?php echo $this->get_field_id( 'UJI_subscr' ); ?>" name="<?php echo $this->get_field_name( 'UJI_subscr' ); ?>" type="text" value="<?php echo esc_attr( $instance['UJI_subscr'] ); ?>" />
349 </div>
350
351 <?php endif; ?>
352
353 <?php
354 }
355
356 }
357 ?>
358