-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy patht-countdown.php
981 lines (861 loc) · 39.3 KB
/
t-countdown.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
<?php
/*
Plugin Name: T(-) Countdown
Text Domain: t-countdown
Plugin URI: https://pluginoven.com/plugins/t-countdown/
Description: Display and configure multiple countdown timers in years, months, weeks, days, hours and seconds in a number of different styles.
Version: 2.4.8
Author: twinpictures
Author URI: hhttps://pluginoven.com/
License: GPL2
*/
class WP_TMinus {
var $plugin_name = 'T(-) Countdown';
var $version = '2.4.8';
var $domain = 'tminus';
var $plguin_options_page_title = 'T(-) Countdown Options';
var $plugin_options_menue_title = 'T(-) Countdown';
var $plugin_options_slug = 't-countdown';
var $options_name = 'WP_TMC_options';
/**
* @var array
*/
var $options = array(
'omityears' => 'false',
'omitmonths' => 'false',
'omitweeks' => 'false',
'omitseconds' => 'false',
'yearlabel' => 'Years',
'monthlabel' => 'Months',
'weeklabel' => 'Weeks',
'daylabel' => 'Days',
'hourlabel' => 'Hours',
'minutelabel' => 'Minutes',
'secondlabel' => 'Seconds',
'custom_css' => '',
);
var $license_group = 'tminus_countdown_licenseing';
var $license_name = 'WP_tminus_countdown_license';
var $license_options = array(
'tminus_event_license_key' => '',
'tminus_event_license_status' => '',
);
function __construct() {
$this->_set_options();
// add actions
add_action( 'init', array( $this, 'register_tminus_block' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'plugin_actions' ) );
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'wp_head', array( $this, 'plugin_head_inject' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'countdown_scripts' ) );
//add_action( 'enqueue_block_assets', array( $this, 'countdown_scripts' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'block_assets' ) );
add_action( 'plugins_loaded', array( $this, 'tminus_load_textdomain' ) );
add_action( 'wp_ajax_tminusevents', array( $this, 'tminusevents_callback' ) );
add_action( 'wp_ajax_nopriv_tminusevents', array( $this, 'tminusevents_callback') );
//rest endpoints
add_action( 'rest_api_init', array( $this, 'rest_tminus_endpoints' ) );
// the shortcode
add_shortcode('tminus', array( $this, 'tminus_shortcode') );
}
/**
* Callback admin_menu
*/
function admin_menu() {
if ( function_exists( 'add_options_page' ) AND current_user_can( 'manage_options' ) ) {
// add options page
$options_page = add_options_page($this->plguin_options_page_title, $this->plugin_options_menue_title, 'manage_options', $this->plugin_options_slug, array( $this, 'options_page' ));
}
}
/**
* Callback admin_init
*/
function admin_init() {
register_setting( $this->domain, $this->options_name );
//deactivate legacy version if installed
if( is_plugin_active( 'jquery-t-countdown-widget/countdown-timer.php' ) ){
deactivate_plugins( 'jquery-t-countdown-widget/countdown-timer.php' );
}
if( is_plugin_active( 't-countdown-events/t-countdown-events.php' ) ){
register_setting( $this->license_group, $this->license_name, array('WP_TminusEvents', 'edd_sanitize_license') );
}
}
/**
* Load textdomain.
*
* @since 2.5.6
*/
function tminus_load_textdomain() {
load_plugin_textdomain( 't-countdown' );
}
static function folder_array($path, $exclude = ".|..") {
if(is_dir($path)){
$dh = opendir($path);
$exclude_array = explode("|", $exclude);
$result = array();
while(false !==($file = readdir($dh))) {
if( !in_array(strtolower($file), $exclude_array) && substr($file, 0, 1) != '.' ){
$result[] = $file;
}
}
closedir($dh);
return $result;
}
}
/**
* Register tminus block
*/
function register_tminus_block() {
if ( ! function_exists( 'register_block_type' ) ) {
// Gutenberg is not active.
return;
}
wp_register_script(
'tminus-block',
plugin_dir_url(__FILE__) . 'block.js',
array(
'wp-blocks',
'wp-element',
'wp-components',
'wp-i18n',
'wp-editor',
),
'0.2',
true
);
$styles_arr = $this->folder_array(WP_PLUGIN_DIR.'/'. dirname( plugin_basename(__FILE__) ).'/css');
if( !empty( $this->options['custom_css'] ) ){
preg_match_all("/.(\w+)-dashboard/", $this->options['custom_css'], $custom_styles);
$styles_arr = array_merge($styles_arr, $custom_styles[1]);
}
natcasesort($styles_arr);
$tminus_style = array();
foreach($styles_arr as $style){
$tminus_style[] = array(
'value' => $style,
'label' => __($style, 't-countdown')
);
}
$tminus_options = array(
'styles' => $tminus_style,
'omityears' => $this->options['omityears'],
'omitmonths' => $this->options['omitmonths'],
'omitweeks' => $this->options['omitweeks'],
'omitseconds' => $this->options['omitseconds'],
'yearlabel' => $this->options['yearlabel'],
'monthlabel' => $this->options['monthlabel'],
'weeklabel' => $this->options['weeklabel'],
'daylabel' => $this->options['daylabel'],
'hourlabel' => $this->options['hourlabel'],
'minutelabel' => $this->options['minutelabel'],
'secondlabel' => $this->options['secondlabel']
);
//pass default options to js
wp_localize_script('tminus-block', 'tminus_options', $tminus_options );
register_block_type( 'tminus/countdown', array(
'editor_script' => 'tminus-block',
'render_callback' => [$this, 'tminus_callback'],
'attributes' => array(
'content' => array('type' => 'string'),
'id' => array ('type' => 'string'),
'style' => array ('type' => 'string', 'default' => 'jedi'),
't' => array ('type' => 'number'),
'timestr' => array ('type' => 'string'),
'launchtarget' => array ('type' => 'string'),
'secs' => array ('type' => 'string', 'default' => '00'),
'omityears' => array ('type' => 'boolean', 'default' => $this->options['omityears']),
'omitmonths' => array ('type' => 'boolean', 'default' => $this->options['omitmonths']),
'omitweeks' => array ('type' => 'boolean', 'default' => $this->options['omitweeks']),
'omitseconds' => array ('type' => 'boolean', 'default' => $this->options['omitseconds']),
'yearlabel' => array ('type' => 'string', 'default' => $this->options['yearlabel']),
'monthlabel' => array ('type' => 'string', 'default' => $this->options['monthlabel']),
'weeklabel' => array ('type' => 'string', 'default' => $this->options['weeklabel']),
'daylabel' => array ('type' => 'string', 'default' => $this->options['daylabel']),
'hourlabel' => array ('type' => 'string', 'default' => $this->options['hourlabel']),
'minutelabel' => array ('type' => 'string', 'default' => $this->options['minutelabel']),
'secondlabel' => array ('type' => 'string', 'default' => $this->options['secondlabel']),
)
) );
}
//rest endpoints: /wp-json/tminus/v1/now
function rest_tminus_endpoints() {
$namespace = 'tminus/v1';
register_rest_route( $namespace, '/now', array(
'methods' => 'GET',
'callback' => array( $this, 'rest_now_handler'),
'permission_callback' => '__return_true'
) );
}
function rest_now_handler( ) {
$now = new DateTime( null, $this->get_wp_timezone() );
$result = new WP_REST_Response( $now, 200 );
$result->set_headers(array('Cache-Control' => 'no-cache'));
return $result;
}
// Add link to options page from plugin list
function plugin_actions($links) {
$new_links = array();
$new_links[] = '<a href="options-general.php?page='.$this->plugin_options_slug.'">' . __('Settings', 't-countdown') . '</a>';
return array_merge($new_links, $links);
}
//plugin header inject
function plugin_head_inject(){
// custom css
if( !empty( $this->options['custom_css'] ) ){
echo "<style>\n";
echo $this->options['custom_css'];
echo "\n</style>\n";
}
}
// load editor only styles
function block_assets(){
$styles_arr = $this->folder_array(WP_PLUGIN_DIR.'/'. dirname( plugin_basename(__FILE__) ).'/css');
foreach($styles_arr as $style){
if (! wp_style_is( 'countdown-'.$style.'-css', 'registered' )) {
$style_file_url = plugins_url('/css/'.$style.'/style.css', __FILE__);
wp_register_style( 'countdown-'.$style.'-css', $style_file_url, array(), '2.0');
}
wp_enqueue_style( 'countdown-'.$style.'-css' );
}
}
//load front-end countdown scripts
function countdown_scripts(){
$plugin_url = plugins_url() .'/'. dirname( plugin_basename(__FILE__) );
//tCountdown script
//wp_register_script('countdown-script', $plugin_url.'/js/jquery.t-countdown.js', array ('jquery'), '2.4.6', 'true');
wp_register_script('countdown-script', $plugin_url.'/js/jquery.t-countdown.min.js', array ('jquery'), '2.4.6', 'true');
// callback for t(-) events
$response = array( 'now' => date( 'n/j/Y H:i:s', strtotime(current_time('mysql'))));
wp_localize_script( 'countdown-script', 'tCountAjax', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'api_nonce' => wp_create_nonce( 'wp_rest' ),
'api_url' => site_url('/wp-json/tminus/v1/'),
'countdownNonce' => wp_create_nonce( 'tountajax-countdownonce-nonce' ),
'tminusnow' => json_encode($response)
));
wp_enqueue_script('countdown-script');
}
/**
* Admin options page
*/
function options_page() {
$like_it_arr = array(
__('made you feel all warm and fuzzy on the inside', 't-countdown'),
__('restored your faith in humanity... even if only for a fleeting second', 't-countdown'),
__('rocked your world', 'provided a positive vision of future living', 't-countdown'),
__('inspired you to commit a random act of kindness', 't-countdown'),
__('encouraged more regular flossing of the teeth', 't-countdown'),
__('helped organize your life in the small ways that matter', 't-countdown'),
__('saved your minutes--if not tens of minutes--writing your own solution', 't-countdown'),
__('brightened your day... or darkened it if sleeping in', 't-countdown'),
__('caused you to dance a little jig of joy and joyousness', 't-countdown'),
__('inspired you to tweet a little @twinpictues social love', 't-countdown'),
__('tasted great, while also being less filling', 't-countdown'),
__('caused you to shout: "everybody spread love, give me some mo!"', 't-countdown'),
__('really tied the room together, Dude', 't-countdown'),
__('helped you keep the funk alive', 't-countdown'),
__('<a href="https://www.youtube.com/watch?v=dvQ28F5fOdU" target="_blank">soften hands while you do dishes</a>', 't-countdown'),
__('helped that little old lady <a href="https://www.youtube.com/watch?v=Ug75diEyiA0" target="_blank">find the beef</a>', 't-countdown')
);
$rand_key = array_rand($like_it_arr);
$like_it = $like_it_arr[$rand_key];
$share_it_arr = array(
'https://www.facebook.com/twinpictures',
'https://twitter.com/twinpictures',
'https://wordpress.org/plugins/t-countdown/#reviews'
);
$rand_key = array_rand($share_it_arr);
$share_it = $share_it_arr[$rand_key];
?>
<div class="wrap">
<h2><?php echo $this->plguin_options_page_title; ?></h2>
</div>
<div class="postbox-container metabox-holder meta-box-sortables" style="width: 69%">
<div style="margin:0 5px;">
<div class="postbox">
<div class="handlediv" title="<?php _e( 'Click to toggle', 't-countdown' ) ?>"><br/></div>
<h3 class="handle"><?php _e( 'T(-) Countdown Settings', 't-countdown' ) ?></h3>
<div class="inside">
<form method="post" action="options.php">
<?php
settings_fields( $this->domain );
$options = $this->options;
?>
<table class="form-table">
<tr>
<th><?php _e( 'Omit Years', 't-countdown' ) ?>:</th>
<td><label><input type="radio" name="<?php echo $this->options_name ?>[omityears][]" value="false" <?php echo checked( $options['omityears'], 'false' ); ?> /> <?php _e('Display', 't-countdown'); ?></label>
<label><input type="radio" name="<?php echo $this->options_name ?>[omityears][]" value="true" <?php echo checked( $options['omityears'], 'true' ); ?> /> <?php _e('Hide', 't-countdown'); ?></label>
<br /><span class="description"><?php _e('Display or hide years from countdowns', 't-countdown'); ?></span>
</td>
</tr>
<tr>
<th><?php _e( 'Omit Months', 't-countdown' ) ?>:</th>
<td><label><input type="radio" name="<?php echo $this->options_name ?>[omitmonths][]" value="false" <?php echo checked( $options['omitmonths'], 'false' ); ?> /> <?php _e('Display', 't-countdown'); ?></label>
<label><input type="radio" name="<?php echo $this->options_name ?>[omitmonths][]" value="true" <?php echo checked( $options['omitmonths'], 'true' ); ?> /> <?php _e('Hide', 't-countdown'); ?></label>
<br /><span class="description"><?php _e('Display or hide months from countdowns', 't-countdown'); ?></span>
</td>
</tr>
<tr>
<th><?php _e( 'Omit Weeks', 't-countdown' ) ?>:</th>
<td><label><input type="radio" name="<?php echo $this->options_name ?>[omitweeks][]" value="false" <?php echo checked( $options['omitweeks'], 'false' ); ?> /> <?php _e('Display', 't-countdown'); ?></label>
<label><input type="radio" name="<?php echo $this->options_name ?>[omitweeks][]" value="true" <?php echo checked( $options['omitweeks'], 'true' ); ?> /> <?php _e('Hide', 't-countdown'); ?></label>
<br /><span class="description"><?php _e('Display or hide weeks from countdowns', 't-countdown'); ?></span>
</td>
</tr>
<tr>
<th><?php _e( 'Omit Seconds', 't-countdown' ) ?>:</th>
<td><label><input type="radio" name="<?php echo $this->options_name ?>[omitseconds][]" value="false" <?php echo checked( $options['omitseconds'], 'false' ); ?> /> <?php _e('Display', 't-countdown'); ?></label>
<label><input type="radio" name="<?php echo $this->options_name ?>[omitseconds][]" value="true" <?php echo checked( $options['omitseconds'], 'true' ); ?> /> <?php _e('Hide', 't-countdown'); ?></label>
<br /><span class="description"><?php _e('Display or hide seconds from countdowns', 't-countdown'); ?></span>
</td>
</tr>
<tr>
<th><?php _e( 'Years Label', 't-countdown' ) ?>:</th>
<td><label><input type="text" id="<?php echo $this->options_name ?>[yearlabel]" name="<?php echo $this->options_name ?>[yearlabel]" value="<?php echo esc_attr($options['yearlabel']); ?>" />
<br /><span class="description"><?php _e( 'Default label for years.', 't-countdown' ) ?></span></label>
</td>
</tr>
<tr>
<th><?php _e( 'Months Label', 't-countdown' ) ?>:</th>
<td><label><input type="text" id="<?php echo $this->options_name ?>[monthlabel]" name="<?php echo $this->options_name ?>[monthlabel]" value="<?php echo esc_attr($options['monthlabel']); ?>" />
<br /><span class="description"><?php _e( 'Default label for months.', 't-countdown' ) ?></span></label>
</td>
</tr>
<tr>
<th><?php _e( 'Weeks Label', 't-countdown' ) ?>:</th>
<td><label><input type="text" id="<?php echo $this->options_name ?>[weeklabel]" name="<?php echo $this->options_name ?>[weeklabel]" value="<?php echo esc_attr($options['weeklabel']); ?>" />
<br /><span class="description"><?php _e( 'Default label for weeks.', 't-countdown' ) ?></span></label>
</td>
</tr>
<tr>
<th><?php _e( 'Days Label', 't-countdown' ) ?>:</th>
<td><label><input type="text" id="<?php echo $this->options_name ?>[daylabel]" name="<?php echo $this->options_name ?>[daylabel]" value="<?php echo esc_attr($options['daylabel']); ?>" />
<br /><span class="description"><?php _e( 'Default label for days.', 't-countdown' ) ?></span></label>
</td>
</tr>
<tr>
<th><?php _e( 'Hours Label', 't-countdown' ) ?>:</th>
<td><label><input type="text" id="<?php echo $this->options_name ?>[hourlabel]" name="<?php echo $this->options_name ?>[hourlabel]" value="<?php echo esc_attr($options['hourlabel']); ?>" />
<br /><span class="description"><?php _e( 'Default label for hours.', 't-countdown' ) ?></span></label>
</td>
</tr>
<tr>
<th><?php _e( 'Minutes Label', 't-countdown' ) ?>:</th>
<td><label><input type="text" id="<?php echo $this->options_name ?>[minutelabel]" name="<?php echo $this->options_name ?>[minutelabel]" value="<?php echo esc_attr($options['minutelabel']); ?>" />
<br /><span class="description"><?php _e( 'Default label for minutes.', 't-countdown' ) ?></span></label>
</td>
</tr>
<tr>
<th><?php _e( 'Seconds Label', 't-countdown' ) ?>:</th>
<td><label><input type="text" id="<?php echo $this->options_name ?>[secondlabel]" name="<?php echo $this->options_name ?>[secondlabel]" value="<?php echo esc_attr($options['secondlabel']); ?>" />
<br /><span class="description"><?php _e( 'Default label for seconds.', 't-countdown' ) ?></span></label>
</td>
</tr>
<tr>
<th><?php _e( 'Custom CSS', 't-countdown' ) ?>:</th>
<td><label><textarea id="<?php echo $this->options_name ?>[custom_css]" name="<?php echo $this->options_name ?>[custom_css]" style="width: 100%; height: 537px;"><?php echo esc_attr($options['custom_css']); ?></textarea>
<br /><span class="description"><?php _e( 'Custom CSS style for <em>ultimate flexibility</em>', 't-countdown' ) ?></span></label>
</td>
</tr>
</table>
<p class="submit" style="margin-bottom: 20px;">
<input class="button-primary" type="submit" value="<?php _e( 'Save Changes', 't-countdown' ) ?>" style="float: right;" />
</p>
</form>
</div>
</div>
</div>
</div>
<div class="postbox-container side metabox-holder" style="width:29%;">
<div style="margin:0 5px;">
<div class="postbox">
<h3><?php _e( 'About' ) ?></h3>
<div class="inside">
<h4><?php echo $this->plugin_name; ?> <?php _e('Version', 't-countdown'); ?> <?php echo $this->version; ?></h4>
<p><?php _e( 'T(-) Countdown is a highly customizable, HTML5 countdown timer that can be displayed in a post or page using a shortcode.', 't-countdown') ?></p>
<ul>
<li><?php printf( __( '%sDetailed documentation%s, complete with working demonstrations of all shortcode attributes, is available for your instructional enjoyment.', 't-countdown'), '<a href="https://pluginoven.com/plugins/t-countdown/documentation/" target="_blank">', '</a>'); ?></li>
<li><?php printf( __( 'A %sCommunity translation%s tool has been set up that allows anyone to assist in translating T(-) Countdown.', 't-countdown'), '<a href="https://translate.wordpress.org/projects/wp-plugins/t-countdown/" target="_blank">', '</a>' ); ?></li>
<li><?php printf( __( 'If this plugin %s, please consider %ssharing your story%s with others.', 't-countdown'), $like_it, '<a href="'.$share_it.'" target="_blank">', '</a>' ) ?></li>
<li><a href="https://wordpress.org/plugins/t-countdown/" target="_blank">WordPress.org</a> | <a href="https://pluginoven.com/plugins/t-countdown/" target="_blank">Twinpictues Plugin Oven</a></li>
</ul>
</ul>
</div>
</div>
</div>
</div>
<div class="postbox-container side metabox-holder meta-box-sortables" style="width:29%;">
<div style="margin:0 5px;">
<div class="postbox">
<div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
<h3 class="handle"><?php _e( 'T(-) Countdown Control' ) ?></h3>
<div class="inside">
<p><?php printf(__( '%sT(-) Countdown Control%s is our premium plugin that manages and schedules multiple recurring countdown timers for repeating events.', 't-countdown' ), '<a href="https://plugins.twinpictures.de/premium-plugins/t-countdown-control/?utm_source=t-countdown&utm_medium=plugin-settings-page&utm_content=t-countdown&utm_campaign=t-control-sidebar">', '</a>'); ?></p>
<h4><?php _e('Reasons To Go Pro', 't-countdown'); ?></h4>
<ol>
<li><?php _e('Schedule and manage multiple recurring countdowns', 't-countdown'); ?></li>
<li><?php _e('Highly responsive professional support', 't-countdown'); ?></li>
<li><?php printf(__('%sT(-) Countdown Control Testimonials%s', 't-countdown'), '<a href="https://plugins.twinpictures.de/testimonial/t-countdown-control-testimonias/" target="_blank">', '</a>'); ?></li>
</ol>
</div>
</div>
</div>
<div class="clear"></div>
</div>
<?php if( is_plugin_active( 't-countdown-events/t-countdown-events.php' ) ) : ?>
<div class="postbox-container side metabox-holder" style="width:29%;">
<div style="margin:0 5px;">
<div class="postbox">
<h3 class="handle"><?php _e( 'Register T(-) Countdown Events', 't-countdown') ?></h3>
<div class="inside">
<p><?php printf( __('To receive plugin updates you must register your plugin. Enter your T(-) Countdown Events licence key below. Licence keys may be viewed and managed by logging into %syour account%s.', 't-countdown'), '<a href="https://plugins.twinpictures.de/your-account/" target="_blank">', '</a>'); ?></p>
<form method="post" action="options.php">
<?php
settings_fields( $this->license_group );
$options = get_option($this->license_name);
$tce_licence = ( !isset( $options['tminus_event_license_key'] ) ) ? '' : $options['tminus_event_license_key'];
?>
<fieldset>
<table style="width: 100%">
<tbody>
<tr>
<th><?php _e( 'License Key', 't-countdown' ) ?>:</th>
<td><label for="<?php echo $this->license_name ?>[tminus_event_license_key]"><input type="password" id="<?php echo $this->license_name ?>[tminus_event_license_key]" name="<?php echo $this->license_name ?>[tminus_event_license_key]" value="<?php esc_attr_e( $tce_licence ); ?>" style="width: 100%" />
<br /><span class="description"><?php _e('Enter your license key', 't-countdown'); ?></span></label>
</td>
</tr>
<?php if( isset($options['tminus_event_license_key']) ) { ?>
<tr valign="top">
<th><?php _e('License Status', 't-countdown'); ?>:</th>
<td>
<?php if( isset($options['tminus_event_license_status']) && $options['tminus_event_license_status'] == 'valid' ) { ?>
<span style="color:green;"><?php _e('active'); ?></span><br/>
<input type="submit" class="button-secondary" name="edd_tce_license_deactivate" value="<?php _e('Deactivate License'); ?>"/>
<?php } else {
if( isset($options['tminus_event_license_status'])){ ?>
<span style="color: red"><?php echo $options['tminus_event_license_status']; ?></span><br/>
<?php } else { ?>
<span style="color: grey">inactive</span><br/>
<?php } ?>
<input type="submit" class="button-secondary" name="edd_tce_license_activate" value="<?php _e('Activate License'); ?>"/>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</fieldset>
<?php submit_button( __( 'Register', 't-countdown') ); ?>
</form>
</div>
</div>
</div>
</div>
<?php else: ?>
<div class="postbox-container side metabox-holder meta-box-sortables" style="width:29%;">
<div style="margin:0 5px;">
<div class="postbox">
<div class="handlediv" title="<?php _e( 'Click to toggle', 'colomat' ) ?>"><br/></div>
<h3 class="hndle">T(-) Countdown Events</h3>
<div class="inside">
<p><?php printf( __('%sT(-) Countdown Events%s is a new add-on plugin for T(-) Countdown Control that adds multiple event scheduling. Trigger events, such as changing content or firing a javascript function at specific times while the countdown is running.', 't-countdown'), '<a href="https://plugins.twinpictures.de/premium-plugins/t-countdown-events/?utm_source=t-countdown&utm_medium=plugin-settings-page&utm_content=t-countdown&utm_campaign=t-events-sidebar" target="_blank">', '</a>'); ?></p>
</div>
</div>
</div>
<div class="clear"></div>
</div>
<?php endif; ?>
<?php
}
function _set_options() {
// set options
$saved_options = get_option( $this->options_name );
// set all options
if ( ! empty( $saved_options ) ) {
foreach ( $this->options AS $key => $option ) {
if(isset($saved_options[ $key ])){
if(is_array($saved_options[ $key ])){
$this->options[ $key ] = ( empty( $saved_options[ $key ][0] ) ) ? '' : $saved_options[ $key ][0];
}
else{
$this->options[ $key ] = ( empty( $saved_options[ $key ] ) ) ? '' : $saved_options[ $key ];
}
}
}
}
}
function get_wp_timezone() {
$tzstring = get_option( 'timezone_string' );
$offset = get_option( 'gmt_offset' );
if( empty( $tzstring ) && 0 != $offset && floor( $offset ) == $offset ){
$offset_st = $offset > 0 ? "-$offset" : '+'.absint( $offset );
$tzstring = 'Etc/GMT'.$offset_st;
}
if( empty( $tzstring ) ){
$tzstring = 'UTC';
}
$timezone = new DateTimeZone( $tzstring );
return $timezone;
}
function tminus_callback($atts) {
//return 'Hey dude...';
if(empty($atts['content'])){
$atts['content'] = '';
}
if(empty($atts['launchtarget'])){
$atts['launchtarget'] = 'countdown';
}
$style = $atts['style'];
$timestamp = new DateTime( null, $this->get_wp_timezone() );
/*
$timezone = get_option('timezone_string');
if(!empty($atts['timezone'])){
$timezone = $atts['timezone'];
}
*/
if(!empty($atts['timestr'])){
$t = $atts['timestr'];
}
else if(!empty($atts['t'])){
$timestamp->setTimestamp($atts['t']);
$t = $timestamp->format('Y-m-d H:i').':'.$atts['secs'];
}
else{
$t = '+ 1 day';
}
$omit_str = '';
if($atts['omityears'] === true){
$omit_str .= 'omityears="true"';
}
if($atts['omitmonths'] === true){
$omit_str .= ' omitmonths="true"';
}
if($atts['omitweeks'] === true){
$omit_str .= ' omitweeks="true"';
}
if($atts['omitseconds'] === true){
$omit_str .= ' omitseconds="true"';
}
//var_dump($omit_str);
return do_shortcode('[tminus t="'.$t.'" style="'.$style.'" '.$omit_str.' years="'.$atts['yearlabel'].'" months="'.$atts['monthlabel'].'" weeks="'.$atts['weeklabel'].'" days="'.$atts['daylabel'].'" hours="'.$atts['hourlabel'].'" minutes="'.$atts['minutelabel'].'" seconds="'.$atts['secondlabel'].'" launchtarget="'.$atts['launchtarget'].'"]'.$atts['content'].'[/tminus]');
}
//the shortcode
function tminus_shortcode($atts, $content=null) {
//find a random number, if no id was assigned
$ran = uniqid();
extract(shortcode_atts(array(
'id' => $ran,
't' => '',
'years' => $this->options['yearlabel'],
'months' => $this->options['monthlabel'],
'weeks' => $this->options['weeklabel'],
'days' => $this->options['daylabel'],
'hours' => $this->options['hourlabel'],
'minutes' => $this->options['minutelabel'],
'seconds' => $this->options['secondlabel'],
'omityears' => $this->options['omityears'],
'omitmonths' => $this->options['omitmonths'],
'omitweeks' => $this->options['omitweeks'],
'omitseconds' => $this->options['omitseconds'],
'style' => 'jedi',
'before' => '',
'after' => '',
'width' => 'auto',
'height' => 'auto',
'launchwidth' => 'auto',
'launchheight' => 'auto',
'launchtarget' => 'countdown',
'event_id' => '',
'debug' => '',
), $atts, 'tminus' ));
if(empty($t)){
return;
}
//insert some style into your life
$style_file_url = plugins_url('/css/'.$style.'/style.css', __FILE__);
if ( file_exists( __DIR__ .'/css/'.$style.'/style.css' ) ) {
if (! wp_style_is( 'countdown-'.$style.'-css', 'registered' )) {
wp_register_style( 'countdown-'.$style.'-css', $style_file_url, array(), '2.0');
}
wp_enqueue_style( 'countdown-'.$style.'-css' );
}
//$now = new DateTime( );
$now = new DateTime( null, $this->get_wp_timezone() );
$UTC = new DateTimeZone("UTC");
$now_utc = new DateTime( null, $UTC);
// deal with this_year and this_easter
if(stristr($t, '%') != FALSE){
$scode = array('%this_year%', '%this_easter%');
$swap = array(date('Y'), date('Y-m-d', easter_date(date('Y'))));
if( strtotime( str_replace($scode, $swap, $t)) < strtotime("now") ){
$swap = array(date('Y', strtotime('+1 year')), date('Y-m-d', easter_date(date('Y', strtotime('+1 year')))));
}
$t = str_replace($scode, $swap, $t);
}
$target = new DateTime( $t, $this->get_wp_timezone() );
$target_utc = new DateTime( $t, $UTC );
$tomorrow_target = $target;
$diffSecs = $target->getTimestamp() - $now->getTimestamp();
$day = $target->format('d');
$month = $target->format('m');
$year = $target->format('Y');
$hour = $target->format('H');
$min = $target->format('i');
$sec = $target->format('s');
// interval
$interval = $now->diff($target);
$interval_utc = $now_utc->diff($target_utc);
// next digits
$pop_day = new DateInterval('P1D');
$tomorrow_target->sub($pop_day);
$tomorrow_interval = $now->diff($tomorrow_target);
// countdown digits
$date_arr = array(
'secs' => $interval->s,
'mins' => $interval->i,
'hours' => $interval->h,
'days' => $interval->d,
'months' => $interval->m,
'years' => $interval->y,
);
$current_hours = $interval->h;
$current_minutes = $interval->i;
$next_arr = array(
'next_day' => $tomorrow_interval->d
);
if($interval->m != $tomorrow_interval->m){
$next_arr['next_month'] = $tomorrow_interval->m;
}
if($interval->y != $tomorrow_interval->y){
$next_arr['next_year'] = $tomorrow_interval->y;
}
// deal with omit years
if(!empty($interval->y) && $omityears != 'false'){
// if no months, calculate everyting with total days
if($omitmonths != 'false'){
$date_arr['days'] = $interval->days;
$next_arr['next_day'] = $tomorrow_interval->days;
}
// add years to months.
else{
$date_arr['months'] = $date_arr['months'] + ($interval->y * 12);
if(isset($next_arr['next_month'])){
$next_arr['next_month'] = $next_arr['next_month'] + ($tomorrow_interval->y * 12);
}
else{
$next_arr['next_month'] = ($tomorrow_interval->y * 12);
}
}
}
// deal with omit months
if(!empty($date_arr['months']) && $omitmonths != 'false'){
if(!empty($interval->y) && $omityears == 'false'){
$pop_years = new DateInterval('P'.$interval->y.'Y');
$adjusted_target = $target->sub($pop_years);
$interval = $now->diff($adjusted_target);
if(!empty($next_arr['next_year'])){
$pop_tomorrow_time = new DateInterval('P'.$interval->y.'Y1D');
$adjusted_tomorrow = $target->sub($pop_tomorrow_time);
$tomorrow_interval = $now->diff($adjusted_tomorrow);
}
}
$date_arr['days'] = $interval->days;
$next_arr['next_day'] = $tomorrow_interval->days;
}
//but what if months where empty, but next day we have months...
else if(!empty($next_arr['next_month']) && $omitmonths != 'false'){
$next_arr['next_day'] = $tomorrow_interval->days;
}
// adjust days if weeks are being displayed
if($omitweeks == 'false'){
$date_arr['weeks'] = (int) floor( $date_arr['days'] / 7 );
$date_arr['days'] = (int) floor($date_arr['days'] %7);
$next_week = (int) floor( $next_arr['next_day'] / 7 );
if($date_arr['weeks'] != $next_week ){
$next_arr['next_week'] = $next_week;
}
$next_arr['next_day'] = (int) floor($next_arr['next_day'] %7);
}
if( $diffSecs <= 0 && $launchtarget != 'countup'){
$date_arr = array(
'secs' => 0,
'mins' => 0,
'hours' => 0,
'days' => 0,
'weeks' => 0,
'months' => 0,
'years' => 0,
);
}
// break numbers into digit elements
foreach ($date_arr as $i => $d) {
if($i == 'days' && $next_arr['next_day'] > 99){
if($d > 9){
$d = sprintf("%02d", $d);
}
if($d < 10){
$d = sprintf("%03d", $d);
}
}
//single digits get a padding zero
else if($d < 10){
$d = sprintf("%02d", $d);
}
$date_arr[$i] = array_map('intval', str_split($d));
}
if(is_numeric($width)){
$width .= 'px';
}
if(is_numeric($height)){
$height .= 'px';
}
$tminus = '<div id="'.$id.'-countdown" class="tminus_countdown" style="width:'.$width.'; height:'.$height.';">';
$tminus .= '<div class="'.$style.'-countdown">';
$tminus .= '<div id="'.$id.'-tophtml" class="'.$style.'-tophtml">';
if($before){
$tminus .= htmlspecialchars_decode($before);
}
$tminus .= '</div>';
//drop in the dashboard
$tminus .= '<div id="'.$id.'-dashboard" class="'.$style.'-dashboard">';
if(!empty($date_arr['years']) && $omityears == 'false'){
$class = $style.'-dash '.$style.'-years_dash';
$next_year = '';
if(isset($next_arr['next_year'])){
$next_year = 'data-next="'.$next_arr['next_year'].'"';
}
$tminus .= '<div class="'.$class.'" '.$next_year.'"><div class="'.$style.'-dash_title">'.$years.'</div>';
foreach( $date_arr['years'] AS $digit ){
$tminus .= '<div class="'.$style.'-digit" data-digit="'.$digit.'">'.$digit.'</div>';
}
$tminus .= '</div>';
}
if(!empty($date_arr['months']) && $omitmonths == 'false'){
$class = $style.'-dash '.$style.'-months_dash';
$next_month = '';
if(isset($next_arr['next_month'])){
$next_month = 'data-next="'.$next_arr['next_month'].'"';
}
$tminus .= '<div class="'.$class.'" '.$next_month.'><div class="'.$style.'-dash_title">'.$months.'</div>';
foreach( $date_arr['months'] AS $digit ){
$tminus .= '<div class="'.$style.'-digit" data-digit="'.$digit.'">'.$digit.'</div>';
}
$tminus .= '</div>';
}
if($omitweeks == 'false'){
$wclass = $style.'-dash '.$style.'-weeks_dash';
$next_week = '';
if(isset($next_arr['next_week'])){
$next_week = 'data-next="'.$next_arr['next_week'].'"';
}
$tminus .= '<div class="'.$wclass.'" '.$next_week.'><div class="'.$style.'-dash_title">'.$weeks.'</div>';
foreach( $date_arr['weeks'] AS $digit ){
$tminus .= '<div class="'.$style.'-digit" data-digit="'.$digit.'">'.$digit.'</div>';
}
$tminus .= '</div>';
}
$dclass = $style.'-dash '.$style.'-days_dash';
$tminus .= '<div class="'.$dclass.'" data-next="'.$next_arr['next_day'].'"><div class="'.$style.'-dash_title">'.$days.'</div>';
foreach( $date_arr['days'] AS $digit ){
$tminus .= '<div class="'.$style.'-digit" data-digit="'.$digit.'">'.$digit.'</div>';
}
$tminus .= '</div>';
$tminus .= '<div class="'.$style.'-dash '.$style.'-hours_dash" data-current="'.$current_hours.'">';
$tminus .= '<div class="'.$style.'-dash_title">'.$hours.'</div>';
foreach( $date_arr['hours'] AS $digit ){
$tminus .= '<div class="'.$style.'-digit" data-digit="'.$digit.'">'.$digit.'</div>';
}
$tminus .= '</div>';
$tminus .= '<div class="'.$style.'-dash '.$style.'-minutes_dash" data-current="'.$current_minutes.'">';
$tminus .= '<div class="'.$style.'-dash_title">'.$minutes.'</div>';
foreach( $date_arr['mins'] AS $digit ){
$tminus .= '<div class="'.$style.'-digit" data-digit="'.$digit.'">'.$digit.'</div>';
}
$tminus .= '</div>';
//var_dump($omitseconds);
if($omitseconds == 'false'){
$tminus .= '<div class="'.$style.'-dash '.$style.'-seconds_dash">';
$tminus .= '<div class="'.$style.'-dash_title">'.$seconds.'</div>';
foreach( $date_arr['secs'] AS $digit ){
$tminus .= '<div class="'.$style.'-digit" data-digit="'.$digit.'">'.$digit.'</div>';
}
$tminus .= '</div>';
}
$tminus .= '</div>'; //close the dashboard
$tminus .= '<div id="'.$id.'-bothtml" class="'.$style.'-bothtml">';
if($after){
$tminus .= htmlspecialchars_decode($after);
}
$tminus .= '</div></div></div>';
$lt = date( 'n/j/Y H:i:s', strtotime(current_time('mysql')) );
if(is_numeric($launchwidth)){
$launchwidth .= 'px';
}
if(is_numeric($launchheight)){
$launchheight .= 'px';
}
$content = json_encode(do_shortcode($content));
$content = str_replace(array('\r\n', '\r', '\n<p>', '\n', '""'), '', $content);
$formated_target = new DateTime($t, $this->get_wp_timezone());
$tminus .= "<script language='javascript' type='text/javascript'>
jQuery(document).ready(function($) {
$('#".$id."-dashboard').tminusCountDown({
targetDate: {
'day': ".$day.",
'month': ".$month.",
'year': ".$year.",
'hour': ".$hour.",
'min': ".$min.",
'sec': ".$sec.",
'target': '". $formated_target->format('D M d Y H:i:s O') ."',
'localtime': '".$lt."'
},
style: '".$style."',
id: '".$id."',
event_id: '".$event_id."',
debug: '".$debug."',
launchtarget: '".$launchtarget."'";
if(!empty($content)){
$tminus .= ", onComplete: function() {
if($('".$launchtarget."').length){
$('".$launchtarget."').css({'width' : '".$launchwidth."', 'height' : '".$launchheight."'}).html(".$content.");
}
else{
$('#".$id."-".$launchtarget."').css({'width' : '".$launchwidth."', 'height' : '".$launchheight."'});
$('#".$id."-".$launchtarget."').html(".$content.");
}
}";
}
$tminus .= "});
});
</script>";
if(!empty($debug)){
$tminus .= '<pre>Now: ' . $now->format('Y-m-d H:i:s e');
$tminus .= '<br/>Target: ' . $formated_target->format('Y-m-d H:i:s e');
$interval = $formated_target->diff($now);
$tminus .= '<br/>Time to Target: ' . $interval->format('%a days %h hours %i mins. %s secs.');
$tminus .= '<br/>Time to Target UTC: ' . $interval_utc->format('%a days %h hours %i mins. %s secs.');
//rest now values
$tminus .= '<br/>Browser Now (JS): <span id="'.$id.'-jsnow">loading...</span>';
$tminus .= '<br/>Browser Target (JS): <span id="'.$id.'-jstarg">loading...</span>';
$tminus .= '<br/>Timezone Delta: <span id="'.$id.'-jstzone">loading...</span>';
$tminus .= '<br/>Rest Now (JS): <span id="'.$id.'-jstime">loading...</span>';
$tminus .= '<br/>Time to Target (Rest): <span id="'.$id.'-restdiff">loading...</span>';
$tminus .= '<br/>Time Cached: <span id="'.$id.'-jscached">loading...</span>';
$tminus .= '</pre>';
}
return $tminus;
}
function tminusevents_callback() {
$nonce = $_POST['countdownNonce'];
if ( ! wp_verify_nonce( $nonce, 'tountajax-countdownonce-nonce' ) ){
die ( 'Busted!');
}
esc_attr( WP_TminusEvents::tminusEvents( $_POST['event_id'] ));
wp_die();
}
}
$WP_TMinus = new WP_TMinus;
?>