This repository was archived by the owner on Jun 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfergcorp_countdownTimer.php
More file actions
1405 lines (1205 loc) · 52.3 KB
/
fergcorp_countdownTimer.php
File metadata and controls
1405 lines (1205 loc) · 52.3 KB
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
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: Countdown Timer
Plugin URI: http://www.andrewferguson.net/wordpress-plugins/countdown-timer/
Description: Use shortcodes and a widget to count down or up to the years, months, weeks, days, hours, minutes, and/or seconds to a particular event.
Version: 3.0.7
Author: Andrew Ferguson
Author URI: http://www.andrewferguson.net
Countdown Timer - Use shortcodes and a widget to count down the years, months, weeks, days, hours, and minutes to a particular event
Copyright (c) 2005-2017 Andrew Ferguson
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@package Countdown_Timer
@author Andrew Ferguson
@since
@access private
{@internal Missing}
@param type $varname Description
@return type Description
@todo
*/
/**
* Main class for Countdown related activities
*
* @package Countdown_Timer
* @author Andrew Ferguson
* @since 3.0
* @access public
*/
class Fergcorp_Countdown_Timer{
//Per instance
private $eventList;
private $eventsPresent;
private $jsUID = array();
//Settings
private $deleteOneTimeEvents;
private $timeFormat;
private $showYear;
private $showMonth;
private $showWeek;
private $showDay;
private $showHour;
private $showMinute;
private $showSecond;
private $stripZero;
private $enableJS;
private $timeSinceTime;
private $titleSuffix;
private $enableShortcodeExcerpt;
private $version;
/**
* Load settings
*
* @since 3.0.4
* @access public
* @author Andrew Ferguson
*/
public function loadSettings(){
$this->version = get_option("fergcorp_countdownTimer_version");
$this->deleteOneTimeEvents = get_option("fergcorp_countdownTimer_deleteOneTimeEvents");
$this->timeFormat = get_option("fergcorp_countdownTimer_timeFormat");
$this->showYear = get_option("fergcorp_countdownTimer_showYear");
$this->showMonth = get_option("fergcorp_countdownTimer_showMonth");
$this->showWeek = get_option("fergcorp_countdownTimer_showWeek");
$this->showDay = get_option("fergcorp_countdownTimer_showDay");
$this->showHour = get_option("fergcorp_countdownTimer_showHour");
$this->showMinute = get_option("fergcorp_countdownTimer_showMinute");
$this->showSecond = get_option("fergcorp_countdownTimer_showSecond");
$this->stripZero = get_option("fergcorp_countdownTimer_stripZero");
$this->enableJS = get_option("fergcorp_countdownTimer_enableJS");
$this->timeSinceTime = get_option("fergcorp_countdownTimer_timeSinceTime");
$this->titleSuffix = get_option("fergcorp_countdownTimer_titleSuffix");
$this->enableShortcodeExcerpt = get_option("fergcorp_countdownTimer_enableShortcodeExcerpt");
$this->eventList = get_option("fergcorp_countdownTimer_oneTimeEvent"); //Get the events from the WPDB to make sure a fresh copy is being used
}
/**
* Default construct to initialize settings required no matter what
*
* @since 3.0
* @access public
* @author Andrew Ferguson
*/
public function __construct(){
// Load settings
$this->loadSettings();
if(version_compare($this->version, "3.0.6", "<")){
add_action('admin_init', array( &$this, 'install' ) );
add_action('admin_init', array( &$this, 'loadSettings' ) );
}
// Register scripts for the countdown timer
wp_register_script('webkit_sprintf', plugins_url(dirname(plugin_basename(__FILE__)) . "/js/" . 'webtoolkit.sprintf.js'), FALSE, $this->version);
wp_register_script('fergcorp_countdowntimer', plugins_url(dirname(plugin_basename(__FILE__)) . "/js/". 'fergcorp_countdownTimer_java.js'), array('jquery','webkit_sprintf'), $this->version, TRUE );
if($this->enableJS) {
add_action('wp_footer', array ( &$this, 'json' ) );
}
if($this->enableShortcodeExcerpt) {
add_filter('the_excerpt', 'do_shortcode');
}
//Priority needs to be set to 1 so that the scripts can be enqueued before the scripts are printed, since both actions are hooked into the wp_head action.
add_action('wp_head', array( &$this, 'print_countdown_scripts' ), 1);
//Admin hooks
add_action('admin_init', array( &$this, 'register_settings' ) ); //Initialized the options
add_action('admin_menu', array( &$this, 'register_settings_page' ) ); //Add Action for adding the options page to admin panel
add_shortcode('fergcorp_cdt_single', array ( &$this, 'shortcode_singleTimer' ) );
add_shortcode('fergcorp_cdt', array ( &$this, 'shortcode_showTimer' ) );
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", array( &$this, 'settings_link' ) );
$tz = get_option('timezone_string');
if ( $tz ){ //Get and check if we have a valid time zone...
date_default_timezone_set($tz); //...if so, use it
}
}
/**
* Add settings link on plugin page
*
* @since 3.0
* @access public
* @author c.bavota (http://bavotasan.com/2009/a-settings-link-for-your-wordpress-plugins/)
* @codeCoverageIgnore
*/
public function settings_link($links) {
$settings_link = '<a href="options-general.php?page=fergcorp_countdownTimer.php">Settings</a>';
array_unshift($links, $settings_link);
return $links;
}
/**
* Loads the appropriate scripts when in the admin page
*
* @since 2.2
* @access public
* @author Andrew Ferguson
*/
public function print_admin_script() {
wp_enqueue_script('postbox'); //These appear to be new functions in WP 2.5
}
/**
* Loads the appropriate scripts for running the timer
*
* @since 3.0
* @access public
* @author Andrew Ferguson
*/
public function print_countdown_scripts(){
if($this->enableJS) {
wp_enqueue_script('fergcorp_countdowntimer');
wp_enqueue_script('webkit_sprintf');
}
else{
wp_dequeue_script('fergcorp_countdowntimer');
wp_dequeue_script('webkit_sprintf');
}
}
/**
* Adds the management page in the admin menu
*
* @since 3.0
* @access public
* @author Andrew Ferguson
*/
public function register_settings_page(){
$settings_page = add_options_page(__('Countdown Timer Settings', 'fergcorp_countdownTimer'), __('Countdown Timer', 'fergcorp_countdownTimer'), 'manage_options', basename(__FILE__), array(&$this, "settings_page"));
add_action( 'admin_print_scripts-' . $settings_page, array( &$this, 'print_admin_script' ) );
add_action( 'admin_print_scripts-' . $settings_page, array( &$this, 'print_countdown_scripts' ) );
}
/**
* Settings page
*
* @since 3.0
* @access private
* @author Andrew Ferguson
*/
public function settings_page(){ ?>
<script type="text/javascript">
// <![CDATA[
jQuery(document).ready( function($) {
// close postboxes that should be closed
jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
// postboxes setup
postboxes.add_postbox_toggles('fergcorp-countdown-timer'); //For WP2.7 and above
});
function clearField(eventType, fieldNum){ //For deleting events without reloading
var agree=confirm('<?php _e('Are you sure you wish to delete', 'fergcorp_countdownTimer'); ?> '+document.getElementsByName(eventType+'['+fieldNum+'][text]').item(0).value+'?');
if(agree){
var inputID = eventType + '_table' + fieldNum;
document.getElementById(inputID).style.display = 'none';
document.getElementsByName(eventType+'['+fieldNum+'][date]').item(0).value = '';
document.getElementsByName(eventType+'['+fieldNum+'][text]').item(0).value = '';
document.getElementsByName(eventType+'['+fieldNum+'][link]').item(0).value = '';
document.getElementsByName(eventType+'['+fieldNum+'][timeSince]').item(0).value = '';
}
else
return false;
}
function showHideContent(id, show){ //For hiding sections
var elem = document.getElementById(id);
if (elem){
if (show){
elem.style.display = 'block';
elem.style.visibility = 'visible';
}
else{
elem.style.display = 'none';
elem.style.visibility = 'hidden';
}
}
}
// ]]>
</script>
<div class="wrap" id="fergcorp_countdownTimer_div">
<h2>Countdown Timer</h2>
<div id="poststuff">
<?php
add_meta_box('fergcorp_countdownTimer_resources', __('Resources', 'fergcorp_countdownTimer'), array ( &$this, 'resources_meta_box'), 'fergcorp-countdown-timer');
?>
<form method="post" action="options.php">
<input type="hidden" name="fergcorp_countdownTimer_noncename" id="fergcorp_countdownTimer_noncename" value="<?php wp_create_nonce( plugin_basename(__FILE__) );?>" />
<?php
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
settings_fields('fergcorp_countdownTimer_options');
add_meta_box('fergcorp_countdownTimer_installation', __('Installation and Usage Notes', 'fergcorp_countdownTimer'), array ( &$this, 'installation_meta_box' ), 'fergcorp-countdown-timer', 'advanced', 'default');
add_meta_box("fergcorp_countdownTimer_events", __('One Time Events', 'fergcorp_countdownTimer'), array ( &$this, 'events_meta_box' ), "fergcorp-countdown-timer");
add_meta_box("fergcorp_countdownTimer_management", __('Management', 'fergcorp_countdownTimer'), array ( &$this, "management_meta_box" ), "fergcorp-countdown-timer");
add_meta_box("fergcorp_countdownTimer_display_options", __('Countdown Time Display', 'fergcorp_countdownTimer'), array ( &$this, "display_options_meta_box" ), "fergcorp-countdown-timer");
add_meta_box("fergcorp_countdownTimer_onHover_time_format", __('onHover Time Format', 'fergcorp_countdownTimer'), array ( &$this, "onHover_time_format_meta_box" ), "fergcorp-countdown-timer");
add_meta_box("fergcorp_countdownTimer_display_format_options", __('Display Format Options', 'fergcorp_countdownTimer'), array ( &$this, "display_format_options_meta_box" ), "fergcorp-countdown-timer");
add_meta_box("fergcorp_countdownTimer_example_display", __('Example Display', 'fergcorp_countdownTimer'), array ( &$this, "example_display_meta_box" ), "fergcorp-countdown-timer");
do_meta_boxes('fergcorp-countdown-timer','advanced',null);
?>
<div>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes', 'fergcorp_countdownTimer'); ?>»" />
</p>
</div>
</form>
</div>
</div>
<?php
}
/**
* Creates and defines the metabox for the resources box
*
* @package Countdown_Timer
* @author Andrew Ferguson
* @internal 3.0
* @access private
* @codeCoverageIgnore
*
*/
function resources_meta_box(){
?>
<table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><ul><li><a href="http://andrewferguson.net/wordpress-plugins/countdown-timer/" target="_blank"><?php _e('Plugin Homepage','fergcorp_countdownTimer'); ?></a></li></ul></td>
<td><ul><li><a href="http://wordpress.org/tags/countdown-timer" target="_blank"><?php _e('Support Forum','fergcorp_countdownTimer'); ?></a></li></ul></td>
<td><ul><li><a href="http://www.amazon.com/gp/registry/registry.html?ie=UTF8&type=wishlist&id=E7Q6VO0I8XI4" target="_blank"><?php _e('Amazon Wishlist','fergcorp_countdownTimer'); ?></a></li></ul></td>
<td><ul><li><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=38923"><img src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" alt="Donate"/></a></li></ul></td>
</tr>
</table>
<p><?php _e("I've coded and supported this plugin for several years now, however I am a full-time engineer with a real, full-time job and really only do this programming thing on the side for the love of it. If you would like to continue to see updates, please consider donating above.", 'fergcorp_countdownTimer'); ?></p>
<?php
}
/**
* Creates and defines the metabox for the options box
*
* @package Countdown_Timer
* @author Andrew Ferguson
* @internal 3.0
* @access private
*
*/
function display_options_meta_box(){
?>
<p><?php _e('This setting controls what units of time are displayed.', 'fergcorp_countdownTimer'); ?></p>
<ul>
<li><?php echo __('Years:', 'fergcorp_countdownTimer') . $this->build_yes_no("fergcorp_countdownTimer_showYear", $this->showYear); ?></li>
<li><?php echo __('Months:', 'fergcorp_countdownTimer') . $this->build_yes_no("fergcorp_countdownTimer_showMonth", $this->showMonth); ?></li>
<li><?php echo __('Weeks:', 'fergcorp_countdownTimer') . $this->build_yes_no("fergcorp_countdownTimer_showWeek", $this->showWeek); ?></li>
<li><?php echo __('Days:', 'fergcorp_countdownTimer') . $this->build_yes_no("fergcorp_countdownTimer_showDay", $this->showDay); ?></li>
<li><?php echo __('Hours:', 'fergcorp_countdownTimer') . $this->build_yes_no("fergcorp_countdownTimer_showHour", $this->showHour); ?></li>
<li><?php echo __('Minutes:', 'fergcorp_countdownTimer') . $this->build_yes_no("fergcorp_countdownTimer_showMinute", $this->showMinute); ?></li>
<li><?php echo __('Seconds:', 'fergcorp_countdownTimer') . $this->build_yes_no("fergcorp_countdownTimer_showSecond", $this->showSecond); ?></li>
<li><?php echo __('Strip non-significant zeros:', 'fergcorp_countdownTimer') . $this->build_yes_no("fergcorp_countdownTimer_stripZero", $this->stripZero); ?></li>
</ul>
<?php
}
/**
* Creates and defines the metabox for the events box
*
* @package Countdown_Timer
* @author Andrew Ferguson
* @internal 3.0
* @access public
*
*/
public function events_meta_box(){
?>
<table border="0" cellspacing="0" cellpadding="2">
<tr align="center">
<td><strong><?php _e('Delete', 'fergcorp_countdownTimer'); ?></strong></td>
<td><?php _e('Event Date', 'fergcorp_countdownTimer'); ?></td>
<td><?php _e('Event Title', 'fergcorp_countdownTimer'); ?></td>
<td><?php _e('Link', 'fergcorp_countdownTimer'); ?></td>
<td><?php _e('Display "Time since"', 'fergcorp_countdownTimer'); ?></td>
</tr>
<?php
$event_count = 0;
if ( is_array( $this->eventList ) ) {
foreach ( $this->eventList as $thisEvent ) {
//If the user wants, cycle through the array to find out if they have already occured, if so: set them to NULL
if ( ( $this->deleteOneTimeEvents ) && ( $thisEvent->getTimestamp() <= time() ) && ( !$thisEvent->getTimeSince() ) ) {
$thisEvent = NULL;
}
else{
?>
<tr id="fergcorp_countdownTimer_oneTimeEvent_table<?php echo $event_count; ?>" align="center">
<td><a href="javascript:void(0);" onclick="javascript:clearField('fergcorp_countdownTimer_oneTimeEvent','<?php echo $event_count; ?>');">X</a></td>
<?php
echo "<td>".$this->build_input(array(
"type" => "text",
"size" => 30,
"name" => "fergcorp_countdownTimer_oneTimeEvent[{$event_count}][date]",
"value" => ($thisEvent->date("D, d M Y H:i:s T"))
)
)."</td>";
echo "<td>".$this->build_input(array(
"type" => "text",
"size" => 20,
"name" => "fergcorp_countdownTimer_oneTimeEvent[{$event_count}][text]",
"value" => htmlspecialchars(stripslashes($thisEvent->getTitle()))
)
)."</td>";
echo "<td>".$this->build_input(array(
"type" => "text",
"size" => 15,
"name" => "fergcorp_countdownTimer_oneTimeEvent[{$event_count}][link]",
"value" => $thisEvent->getURL()
)
)."</td>";
echo "<td>".$this->build_input(array(
"type" => "checkbox",
"name" => "fergcorp_countdownTimer_oneTimeEvent[{$event_count}][timeSince]",
"value" => 1,
),
checked("1", $thisEvent->getTimeSince(), false)
)."</td>";
?>
</tr>
<?php
$event_count++;
}
}
}
?>
<tr align="center">
<td></td>
<?php
echo "<td>".$this->build_input(array(
"type" => "text",
"size" => 30,
"name" => "fergcorp_countdownTimer_oneTimeEvent[{$event_count}][date]",
)
)."</td>";
echo "<td>".$this->build_input(array(
"type" => "text",
"size" => 20,
"name" => "fergcorp_countdownTimer_oneTimeEvent[{$event_count}][text]",
)
)."</td>";
echo "<td>".$this->build_input(array(
"type" => "text",
"size" => 15,
"name" => "fergcorp_countdownTimer_oneTimeEvent[{$event_count}][link]",
)
)."</td>";
echo "<td>".$this->build_input(array(
"type" => "checkbox",
"name" => "fergcorp_countdownTimer_oneTimeEvent[{$event_count}][timeSince]",
"value" => 1,
)
)."</td>";
?>
</tr>
</table>
<?php echo '<input type="hidden" name="event_count" value="'.($event_count+1).'" />';
echo "<p>".__("Automatically delete 'One Time Events' after they have occured?", 'fergcorp_countdownTimer');
//Yes
echo $this->build_input(array(
"type" => "radio",
"name" => "fergcorp_countdownTimer_deleteOneTimeEvents",
"value" => "1",
),
checked("1", $this->deleteOneTimeEvents, false)
);
_e('Yes', 'fergcorp_countdownTimer');
echo " :: ";
//...or No
echo $this->build_input(array(
"type" => "radio",
"name" => "fergcorp_countdownTimer_deleteOneTimeEvents",
"value" => "0",
),
checked("0", $this->deleteOneTimeEvents, false)
);
_e('No', 'fergcorp_countdownTimer');
echo "</p>";
}
/**
* Creates and defines the metabox for the installation box
*
* @package Countdown_Timer
* @author Andrew Ferguson
* @internal 3.0
* @access private
*
*/
function installation_meta_box () { ?>
<p><?php printf(__("Countdown timer uses <a %s>PHP's strtotime function</a> and will parse about any English textual datetime description.", 'fergcorp_countdownTimer'), "href='http://us2.php.net/strtotime' target='_blank'"); ?></p>
<p><?php _e('Examples of some (but not all) valid dates', 'fergcorp_countdownTimer'); ?>:</p>
<ul style="list-style:inside circle; font-size:11px; margin-left: 20px;">
<li>now</li>
<li>31 january 1986</li>
<li>+1 day</li>
<li>next thursday</li>
<li>last monday</li>
</ul>
<p><?php printf(__("To insert the Countdown Timer into your sidebar, you can use the <a %s>Countdown Timer Widget</a>.", 'fergcorp_countdownTimer'), "href='".admin_url('widgets.php')."'"); ?></p>
<p><?php printf(__("If you want to insert the Countdown Timer into a page or post, you can use the following <abbr %s %s>shortcodes</abbr> to return all or a limited number of Countdown Timers, respectively:", 'fergcorp_countdownTimer'), "title='".__('A shortcode is a WordPress-specific code that lets you do nifty things with very little effort. Shortcodes can embed files or create objects that would normally require lots of complicated, ugly code in just one line. Shortcode = shortcut.', 'fergcorp_countdownTimer')."'", "style='cursor:pointer; border-bottom:1px black dashed'" ); ?></p>
<p>
<code>
[fergcorp_cdt]<br /><br />
[fergcorp_cdt max=##]
</code>
</p>
<p><?php _e("Where <em>##</em> is maximum number of results to be displayed - ordered by date.", 'fergcorp_countdownTimer'); ?></p>
<p><?php _e("If you want to insert individual countdown timers, such as in posts or on pages, you can use the following shortcode:", 'fergcorp_countdownTimer'); ?></p>
<p>
<code><?php _e("Time until my birthday:", 'fergcorp_countdownTimer'); ?><br />
[fergcorp_cdt_single date="<em>ENTER_DATE_HERE</em>"]
</code>
</p>
<p><?php printf(__("Where <em>ENTER_DATE_HERE</em> uses <a %s>PHP's strtotime function</a> and will parse about any English textual datetime description.", 'fergcorp_countdownTimer'), "href='http://us2.php.net/strtotime' target='_blank'"); ?></p>
<?php
}
/**
* Creates and defines the metabox for the management box
*
* @package Countdown_Timer
* @author Andrew Ferguson
* @internal 3.0
* @access private
*
*/
function management_meta_box(){
?>
<p><?php _e("How long the timer remain visable if \"Display 'Time Since'\" is ticked:", 'fergcorp_countdownTimer'); ?><br />
<?php _e("Seconds:", 'fergcorp_countdownTimer');
echo $this->build_input(array(
"type" => "text",
"size" => "10",
"name" => "fergcorp_countdownTimer_timeSinceTime",
"value" => $this->timeSinceTime
));
_e("(0 = infinite; 86400 seconds = 1 day; 604800 seconds = 1 week)", "fergcorp_countdownTimer"); ?></p>
<p><?php _e('Enable JavaScript countdown:', 'fergcorp_countdownTimer');
echo $this->build_yes_no("fergcorp_countdownTimer_enableJS", $this->enableJS);
?>
</p>
<p><?php _e('By default, WordPress does not parse shortcodes that are in excerpts. If you want to enable this functionality, you can do so here. Note that this will enable the parsing of <em>all</em> shortcodes in the excerpt, not just the ones associated with Countdown Timer.', 'fergcorp_countdownTimer'); ?></p>
<p><?php _e('Enable shortcodes in the_excerpt:', 'fergcorp_countdownTimer');
echo $this->build_yes_no("fergcorp_countdownTimer_enableShortcodeExcerpt", $this->enableShortcodeExcerpt);
?>
</p>
<?php
}
/**
* Creates and defines the metabox for the onHover time format box
*
* @package Countdown_Timer
* @author Andrew Ferguson
* @internal 3.0
* @access private
*
*/
function onHover_time_format_meta_box(){
?>
<p><?php printf(__("If you set 'onHover Time Format', hovering over the time left will show the user what the date of the event is. onHover Time Format uses <a %s>PHP's Date() function</a>.", 'fergcorp_countdownTimer'), "href='http://us2.php.net/date' target='_blank'"); ?></p>
<p><?php _e('Examples', 'fergcorp_countdownTimer'); ?>:</p>
<ul>
<li>"<em>j M Y, G:i:s</em>" <?php _e('goes to', 'fergcorp_countdownTimer'); ?> "<strong>17 Mar 2008, 14:50:00</strong>"</li>
<li>"<em>F jS, Y, g:i a</em>" <?php _e('goes to', 'fergcorp_countdownTimer'); ?> "<strong>March 17th, 2008, 2:50 pm</strong>"</li>
</ul>
<p><?php _e('onHover Time Format', 'fergcorp_countdownTimer');
echo $this->build_input(array(
"type" => "text",
"size" => "20",
"name" => "fergcorp_countdownTimer_timeFormat",
"value" => $this->timeFormat
));
echo "</p>";
}
/**
* Creates and defines the metabox for the display format options box
*
* @package Countdown_Timer
* @author Andrew Ferguson
* {@internal since}
* @access private
*
*/
function display_format_options_meta_box(){
?>
<p><?php _e('This setting allows you to customize how each event is styled and wrapped.', 'fergcorp_countdownTimer'); ?></p>
<p><?php _e('<strong>Title Suffix</strong> sets the content that appears immediately after title and before the timer.', 'fergcorp_countdownTimer'); ?></p>
<p><?php _e('Examples/Defaults', 'fergcorp_countdownTimer'); ?>:</p>
<ul>
<li><em><?php _e('Title Suffix', 'fergcorp_countdownTimer'); ?>:</em> <code>:<br /></code></li>
</ul>
<p><?php _e('Title Suffix', 'fergcorp_countdownTimer');
echo $this->build_input(array(
"type" => "text",
"size" => "20",
"name" => "fergcorp_countdownTimer_titleSuffix",
"value" => htmlspecialchars(stripslashes($this->titleSuffix))
));
echo "</p>";
}
/**
* Creates and defines the metabox for the example display box
*
* @package Countdown_Timer
* @author Andrew Ferguson
* @internal 3.0
* @access private
*
*/
function example_display_meta_box(){
echo "<ul>";
$this->showTimer();
echo "</ul>";
if($this->enableJS) {
$this->json();
}
}
/**
* Creates a PHP-based one-off time for use outside the loop
*
* @param $date string Any string parsable by PHP's strtotime function
* @since 2.2
* @access public
* @author Andrew Ferguson
*/
public function singleTimer( $date ){
return $this->formatEvent( new Fergcorp_Countdown_Timer_Event( strtotime( $date ) ) , TRUE );
}
/**
* Returns/echos the formated output for the countdown
*
* @param $eventLimit int The maximum number of events to echo or return, sorted by date
* @param $output boolean If TRUE, will echo the results with no return; If FALSE, will return the results
* @since 3.0
* @access public
* @author Andrew Ferguson
* @return string Formated output ready for display
*/
public function showTimer($eventLimit = -1, $output = TRUE){
$this->eventsPresent = FALSE;
$toReturn = "";
//Make sure there's something to count
if($this->eventList){
$this->eventsPresent = TRUE;
}
$eventCount = count($this->eventList);
if($eventLimit != -1) //If the eventLimit is set
$eventCount = min($eventCount, $eventLimit);
//This is the part that does the actual outputting. If you want to preface data, this an excellent spot to do it in.
if($this->eventsPresent){
$this->eventsPresent = FALSE; //Reset the test
for($i = 0; $i < $eventCount; $i++){
if( ( '' == ( $thisTimer = $this->formatEvent($this->eventList[$i], FALSE ) ) ) && ( $eventCount < count( $this->eventList ) ) ) {
$eventCount++;
}
else{
$toReturn .= $thisTimer;
}
}
}
if(!$this->eventsPresent){
$toReturn = "<li>".__('No dates present', 'fergcorp_countdownTimer')."</li>";
}
//Echo or return
if($output)
echo $toReturn;
else
return $toReturn;
}
/**
* Returns an individual countdown element
*
* @param $text string Text associated with the countdown event
* @param $time int Unix time of the event
* @param $offset int Server offset of the time
* @param $timeSince int If the event should be displayed if it has already passed
* @param $timeSinceTime int If $timeSince is set, how long should it be displayed for in seconds
* @param $link string Link associated with the countdown event
* @param $timeFormat string Forming of the onHover time display
* @param $standalone If true, don't output the li-element
* @since 2.1
* @access private
* @author Andrew Ferguson
* @return string The content of the post with the appropriate dates inserted (if any)
*/
function formatEvent($thisEvent, $standAlone = FALSE){
$time_left = $thisEvent->getTimestamp() - time();
$content = '';
if(!$standAlone)
$content = "<li class = 'fergcorp_countdownTimer_event_li'>";
$eventTitle = "<span class = 'fergcorp_countdownTimer_event_title'>".($thisEvent->getURL()==""?$thisEvent->getTitle():"<a href=\"".$thisEvent->getURL()."\" class = 'fergcorp_countdownTimer_event_linkTitle'>".$thisEvent->getTitle()."</a>").'</span>'.$this->titleSuffix."\n";
if ($this->timeFormat == "") {
$this->timeFormat = get_option('date_format') . ", " . get_option('time_format');
}
$timePrefix = "<abbr title = \"".date_i18n($this->timeFormat, $thisEvent->getTimestamp()+(3600*(get_option('gmt_offset'))), TRUE)."\" id = '".$thisEvent->getUID()."' class = 'fergcorp_countdownTimer_event_time'>";
if ( ( $time_left <= 0 ) &&
( ( ( $thisEvent->getTimeSince() ) &&
( ( ( $time_left + (int) $this->timeSinceTime ) > 0 ) || ( 0 == (int) $this->timeSinceTime ) ) )
|| ( $standAlone) ) ) {
//If the event has already passed and we still want to display the event
$this->eventsPresent = TRUE; //Set to TRUE so we know there's an event to display
if ( $thisEvent->getTitle() ) {
$content .= $eventTitle;
}
$content .= $timePrefix.sprintf(__("%s ago", 'fergcorp_countdownTimer'), $this->fuzzyDate( time(), $thisEvent->getTimestamp() ) )."</abbr>";
}
elseif($time_left > 0){ //If the event has not yet happened yet
$this->eventsPresent = TRUE; //Set to TRUE so we know there's an event to display
if($thisEvent->getTitle()){
$content .= $eventTitle;
}
$content .= $timePrefix.sprintf(__("in %s", 'fergcorp_countdownTimer'), $this->fuzzyDate($thisEvent->getTimestamp(), time() ) )."</abbr>";
}
else{
return NULL;
}
array_push($this->jsUID, $thisEvent);
if(!$standAlone)
$content .= "</li>\r\n";
return $content;
}
/**
* Returns the numerical part of a single countdown element
*
* @param $targetTime
* @param $nowTime
* @param $realTargetTime
* @since 2.1
* @access private
* @author Andrew Ferguson
* @return string The content of the post with the appropriate dates inserted (if any)
*/
function fuzzyDate ( $targetTime, $nowTime ) {
$timeDelta = new Fergcorp_DeltaTime($targetTime, $nowTime);
$rollover = 0;
$s = '';
$sigNumHit = false;
if($timeDelta->s < 0){
$timeDelta->i--;
$timeDelta->s = 60 + $timeDelta->s;
}
if($timeDelta->i < 0){
$timeDelta->h--;
$timeDelta->i = 60 + $timeDelta->i;
}
if($timeDelta->h < 0){
$timeDelta->d--;
$timeDelta->h = 24 + $timeDelta->h;
}
if($timeDelta->d < 0){
$timeDelta->m--;
$timeDelta->d = $timeDelta->d + cal_days_in_month(CAL_GREGORIAN, $timeDelta->nowMonth, $timeDelta->nowYear); //Holy crap! When did they introduce this function and why haven't I heard about it??
}
if($timeDelta->m < 0){
$timeDelta->y--;
$timeDelta->m = $timeDelta->m + 12;
}
//Year
if($this->showYear){
if($sigNumHit || !$this->stripZero || $timeDelta->y){
$s = '<span class="fergcorp_countdownTimer_year fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d year,", "%d years,", $timeDelta->y, "fergcorp_countdownTimer"), $timeDelta->y)."</span> ";
$sigNumHit = true;
}
}
else{
$rollover = $timeDelta->y*31536000;
}
//Month
if($this->showMonth){
if($sigNumHit || !$this->stripZero || intval($timeDelta->m + ($rollover/2628000)) ){
$timeDelta->m = intval($timeDelta->m + ($rollover/2628000));
$s .= '<span class="fergcorp_countdownTimer_month fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d month,", "%d months,", $timeDelta->m, "fergcorp_countdownTimer"), $timeDelta->m)."</span> ";
$rollover = $rollover - intval($rollover/2628000)*2628000; //(12/31536000)
$sigNumHit = true;
}
}
else{
//If we don't want to show months, let's just calculate the exact number of seconds left since all other units of time are fixed (i.e. months are not a fixed unit of time)
//If we showed years, but not months, we need to account for those.
if($this->showYear){
$timeDelta->delta = $timeDelta->delta - $timeDelta->y*31536000;
}
//Re calculate the resultant times
$timeDelta->w = intval( $timeDelta->delta/(86400*7) );
$timeDelta->d = intval( $timeDelta->delta/86400 );
$timeDelta->h = intval( ($timeDelta->delta - $timeDelta->d*86400)/3600 );
$timeDelta->i = intval( ($timeDelta->delta - $timeDelta->d*86400 - $timeDelta->h*3600)/60 );
$timeDelta->s = intval( ($timeDelta->delta - $timeDelta->d*86400 - $timeDelta->h*3600 - $timeDelta->i*60) );
//and clear any rollover time
$rollover = 0;
}
//Week (weeks are counted differently becuase we can just take 7 days and call it a week...so we do that)
if($this->showWeek){
if($sigNumHit || !$this->stripZero || ( ($timeDelta->d + intval($rollover/86400) )/7)){
$timeDelta->w = $timeDelta->w + intval($rollover/86400)/7;
$s .= '<span class="fergcorp_countdownTimer_week fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d week,", "%d weeks,", (intval( ($timeDelta->d + intval($rollover/86400) )/7)), "fergcorp_countdownTimer"), (intval( ($timeDelta->d + intval($rollover/86400) )/7)))."</span> ";
$rollover = $rollover - intval($rollover/86400)*86400;
$timeDelta->d = $timeDelta->d - intval( ($timeDelta->d + intval($rollover/86400) )/7 )*7;
$sigNumHit = true;
}
}
//Day
if($this->showDay){
if($sigNumHit || !$this->stripZero || ($timeDelta->d + intval($rollover/86400)) ){
$timeDelta->d = $timeDelta->d + intval($rollover/86400);
$s .= '<span class="fergcorp_countdownTimer_day fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d day,", "%d days,", $timeDelta->d, "fergcorp_countdownTimer"), $timeDelta->d)."</span> ";
$rollover = $rollover - intval($rollover/86400)*86400;
$sigNumHit = true;
}
}
else{
$rollover = $rollover + $timeDelta->d*86400;
}
//Hour
if($this->showHour){
if($sigNumHit || !$this->stripZero || ($timeDelta->h + intval($rollover/3600)) ){
$timeDelta->h = $timeDelta->h + intval($rollover/3600);
$s .= '<span class="fergcorp_countdownTimer_hour fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d hour,", "%d hours,", $timeDelta->h, "fergcorp_countdownTimer"), $timeDelta->h)."</span> ";
$rollover = $rollover - intval($rollover/3600)*3600;
$sigNumHit = true;
}
}
else{
$rollover = $rollover + $timeDelta->h*3600;
}
//Minute
if($this->showMinute){
if($sigNumHit || !$this->stripZero || ($timeDelta->i + intval($rollover/60)) ){
$timeDelta->i = $timeDelta->i + intval($rollover/60);
$s .= '<span class="fergcorp_countdownTimer_minute fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d minute,", "%d minutes,", $timeDelta->i, "fergcorp_countdownTimer"), $timeDelta->i)."</span> ";
$rollover = $rollover - intval($rollover/60)*60;
$sigNumHit = true;
}
}
else{
$rollover = $rollover + $timeDelta->i*60;
}
//Second
if($this->showSecond){
$timeDelta->s = $timeDelta->s + $rollover;
$s .= '<span class="fergcorp_countdownTimer_second fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d second,", "%d seconds,", $timeDelta->s, "fergcorp_countdownTimer"), $timeDelta->s) . "</span> ";
}
//Catch blank statements
if($s==""){
// @codeCoverageIgnoreStart
if($this->showSecond){
$s = '<span class="fergcorp_countdownTimer_second fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d second,", "%d seconds,", "0", "fergcorp_countdownTimer"), "0") . "</span> ";
}
elseif($this->showMinute){
$s = '<span class="fergcorp_countdownTimer_minute fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d minute,", "%d minutes,", "0", "fergcorp_countdownTimer"), "0") . "</span> ";
}
elseif($this->showHour){
$s = '<span class="fergcorp_countdownTimer_hour fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d hour,", "%d hours,", "0", "fergcorp_countdownTimer"), "0") . "</span> ";
}
elseif($this->showDay){
$s = '<span class="fergcorp_countdownTimer_day fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d day,", "%d days,", "0", "fergcorp_countdownTimer"), "0") . "</span> ";
}
elseif($this->showWeek){
$s = '<span class="fergcorp_countdownTimer_week fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d week,", "%d weeks,", "0", "fergcorp_countdownTimer"), "0") . "</span> ";
}
elseif($this->showMonth){
$s = '<span class="fergcorp_countdownTimer_month fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d month,", "%d months,", "0", "fergcorp_countdownTimer"), "0") . "</span> ";
}
// @codeCoverageIgnoreEnd
else{
$s = '<span class="fergcorp_countdownTimer_year fergcorp_countdownTimer_timeUnit">' . sprintf(_n("%d year,", "%d years,", "0", "fergcorp_countdownTimer"), "0") . "</span> ";
}
}
return preg_replace("/(, ?<\/span> *)$/is", "</span>", $s);
}
/**
* Processes [fergcorp_cdt max=##] shortcode
*
* @param $atts array Attributes of the shortcode
* @since 2.3
* @access public
* @author Andrew Ferguson
* @return string countdown timer(s)
*/
function shortcode_showTimer($atts) {
extract(shortcode_atts(array(
'max' => '-1',
),
$atts));
return $this->showTimer($max, FALSE);
}
/**
* Processes [fergcorp_cdt_single date="_DATE_"] shortcode
*
* @param $atts array Attributes of the shortcode
* @since 2.3
* @access public
* @author Andrew Ferguson
* @return string countdown timer
*/
function shortcode_singleTimer($atts) {
extract(shortcode_atts(array(
'date' => '-1',
), $atts));
return $this->singleTimer( $date );
}
/**
* Initialized the options
*
* @since 3.0
* @access public
* @author Andrew Ferguson
*/
public function register_settings(){ // Init plugin options to white list our options
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_deleteOneTimeEvents');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_timeFormat');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_showYear');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_showMonth');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_showWeek');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_showDay');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_showHour');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_showMinute');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_showSecond');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_stripZero');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_enableJS');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_timeSinceTime');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_titleSuffix');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_enableShortcodeExcerpt');
register_setting('fergcorp_countdownTimer_options', 'fergcorp_countdownTimer_oneTimeEvent', array (&$this, 'sanitize'));
}
public function compare($adate, $bdate)
{
if($adate < $bdate){
return -1;