strtotime($_POST["oneTimeEvent_date$i"]), //Date of the event converted to UNIX time "text" => $_POST["oneTimeEvent_text$i"], //Text associated with the event (i.e. event label) "timeSince" => $_POST["oneTimeEvent_timeSince$i"], //After the event has occured, should "Time Since" be displayed? Boolean value (0 0 for no or 1 for yes) "link" => $_POST["oneTimeEvent_link$i"], //Where should the text link to (this can be null) ); //For every field, create an array. Then stick that array into the master array $j++; } } /*End One Time Events*/ /*Begin sorting events by time*/ for($x=0; $x<$oneTimeEvent_count; $x++){ for($z=0; $z<$oneTimeEvent_count-1; $z++){ if(($results["oneTime"][$z+1]["date"] < $results["oneTime"][$z]["date"]) && (array_key_exists($z+1, $results["oneTime"]))){ $temp = $results["oneTime"][$z]; $results["oneTime"][$z] = $results["oneTime"][$z+1]; $results["oneTime"][$z+1] = $temp; } } } /*End sorting events by time*/ $afdnOptions = array( "deleteOneTimeEvents" => $_POST['deleteOneTimeEvents'], //Should One Time Events be deleted after the happen (boolean) "checkUpdate" => $_POST['checkUpdate'], //Should the plugin check for updates (boolean) "timeOffset" => $_POST['timeOffset'], //What is the time format "enableTheLoop" => $_POST['enableTheLoop'], //Should the timer be allowed within the loop (boolean) "displayFormatPrefix" => $_POST['displayFormatPrefix'], "displayFormatSuffix" => $_POST['displayFormatSuffix'], "displayStyle" => $_POST['displayStyle'], "showYear" => $_POST['showYear'], "showMonth" => $_POST['showMonth'], "showWeek" => $_POST['showWeek'], "showDay" => $_POST['showDay'], "showHour" => $_POST['showHour'], "showMinute" => $_POST['showMinute'], "showSecond" => $_POST['showSecond'], ); //Create the array to store the countdown options update_option("afdn_countdowntracker", $results); //Update the WPDB for the data update_option("afdn_countdownOptions", $afdnOptions);//Update the WPDB for the options echo '

'. __('Options updated successfully.', 'afdn_countdownTimer') .'

'; //Report to the user that the data has been updated successfully } $dates = get_option("afdn_countdowntracker"); //Get the events from the WPDB to make sure a fresh copy is being used $getOptions = get_option("afdn_countdownOptions");//Get the options from the WPDB to make sure a fresh copy is being used /*If the user wants, cycle through the array to find out if they have already occured, if so: set them to NULL*/ if($getOptions["deleteOneTimeEvents"] && (count($dates["oneTime"][0])!=0) ){ foreach($dates["oneTime"] as $key => $value){ if(($value["date"]<=time())&&($value["timeSince"]=="")){ $dates["oneTime"][$key]["text"]=NULL; } } } ?>

Countdown Timer

:

<li id='countdown'><h2>Countdown:</h2>
<ul>
<?php afdn_countdownTimer(); ?>
</ul>
</li>


<!--afdn_countdownTimer_single("ENTER_DATE_HERE")-->

\"ENTER_DATE_HERE\" uses PHP's strtodate function and will parse about any English textual datetime description. If you do this, be sure to enable the \"Enable CountdownTimer within The Loop\" option below.", 'afdn_countdownTimer'); ?>

really like my plugins (and/or me) you might consider making a donation. I've been spending more and more time writing and supporting plugins. I'm a college student and really only do this programming thing on the side for the love of it.", 'afdn_countdownTimer'); ?>

PHP's strtodate function and will parse about any English textual datetime description.", 'afdn_countdownTimer'); ?>

:

  • now
  • 31 january 1986
  • +1 day
  • next thursday
  • last monday
X " /> " /> " /> />
'; ?>

/> :: />

/> :: />
"; echo ""; } ?>

: <!--afdn_countdownTimer-->

<!--afdn_countdownTimer_single("ENTER_DATE_HERE")-->

/> :: />

/> :: />

/> :: />

/> :: />

/> :: />

/> :: />

/> :: />

/> :: />

PHP's Date() function.

:

  • "j M Y, G:i:s" "17 Mar 2008, 14:50:00"
  • "F jS, Y, g:i a" "March 17th, 2008, 2:50 pm"

" name="timeOffset" />

Display Style sets the HTML Style attribute for each timer.', 'afdn_countdownTimer'); ?>

Display Format Prefix/Suffix sets any leading or trailing HTML (or text).', 'afdn_countdownTimer'); ?>

:

  • : cursor:pointer; border-bottom:1px black dashed
  • : <li>
  • : </li>

" name="displayStyle" />

" name="displayFormatPrefix" />

" name="displayFormatSuffix" />

", $theContent)){ //If the string is found within the loop, replace it $theContent = preg_replace("//e", "afdn_countdownTimer('return', $2)", $theContent); //The actual replacement of the string with the timer } elseif(preg_match("", $theContent)){ //If the string is found within the loop, replace it $theContent = preg_replace("//e", "afdn_countdownTimer('return', -1)", $theContent); //The actual replacement of the string with the timer } if(preg_match("", $theContent)){ $theContent = preg_replace("//e", "fergcorp_countdownTimer_format('', strtotime('$2'), ".( date('Z') - (get_settings('gmt_offset') * 3600) ).", 'true', '', '".$getOptions['timeOffset']."', '', '', '')", $theContent); } return $theContent; //Return theContent } function afdn_countdownTimer_optionsPage(){ //Action function for adding the configuration panel to the Management Page if(function_exists('add_management_page')){ add_management_page('Countdown Timer', 'Countdown Timer', 10, basename(__FILE__), 'afdn_countdownTimer_myOptionsSubpanel'); } } /*This function is called from your page to output the actual data*/ function afdn_countdownTimer($output = "echo", $eventLimit = -1){ //'echo' will print the results, 'return' will just return them $dates = get_option("afdn_countdowntracker");//Get our text, times, and settings from the database $getOptions = get_option("afdn_countdownOptions");//Get the options from the WPDB if(count($dates["oneTime"][0])!=0){ foreach($dates["oneTime"] as $key => $value){ if(($value["date"]<=time())&&($value["timeSince"]=="")){ $dates["oneTime"][$key]["text"]=NULL; } } } //There are two sets of arrays, 'onetime' and 'recurring', which need to be combined these next lines do that... $numOneTimeDates = count($dates["oneTime"]); $numRecurringDates = count($dates["recurring"]); //Putting the 'onetime' events into a new array for($i = 0; $i < $numOneTimeDates; $i++){ $thisDate[$i] = array( "text" => $dates["oneTime"][$i]["text"], "date" => $dates["oneTime"][$i]["date"], "timeSince" => $dates["oneTime"][$i]["timeSince"], "link" => $dates["oneTime"][$i]["link"], ); } //Putting the 'recurring' events into the array for($i = 0; $i < $numRecurringDates; $i++){ $thisDate[$i+$numOneTimeDates] = array( "text" => $dates["recurring"][$i]["text"], "date" => $dates["recurring"][$i]["nextOccurance"], "timeSince" => $dates["recurring"][$i]["timeSince"], "link" => $dates["recurring"][$i]["link"], ); } /*Now that all the events are in the same array, we need to sort them by date. This is actually the same code used above for the admin page. At some point, I plan to make this into a function; but for, this will do... And what it does is this: The number of elements in the array are counted. Then for array is gone through x^(x-1) times. This allows for all posible date permuations to be sorted out and ordered correctly. Genious, yes? */ $eventCount = count($thisDate); for($x=0; $x<$eventCount; $x++){ for($z=0; $z<$eventCount-1; $z++){ if(($thisDate[$z+1]["date"] < $thisDate[$z]["date"]) && (array_key_exists($z+1, $thisDate))){ $temp = $thisDate[$z]; $thisDate[$z] = $thisDate[$z+1]; $thisDate[$z+1] = $temp; } } } if($eventLimit != -1) //If the eventLimit is set $eventCount = $eventLimit; global $fergcorp_countdownTimer_noEventsPresent; $fergcorp_countdownTimer_noEventsPresent = TRUE; //This is the part that does the actual outputting. If you want to preface data, this an excellent spot to do it in. for($i = 0; $i < $eventCount; $i++){ if($output == "echo") echo fergcorp_countdownTimer_format(stripslashes($thisDate[$i]["text"]), $thisDate[$i]["date"], (date("Z") - (get_settings('gmt_offset') * 3600)), $thisDate[$i]["timeSince"], $thisDate[$i]["link"], $getOptions["timeOffset"], $getOptions["displayFormatPrefix"], $getOptions["displayFormatSuffix"], $getOptions["displayStyle"]); elseif($output == "return"){ $toReturn .= fergcorp_countdownTimer_format(stripslashes($thisDate[$i]["text"]), $thisDate[$i]["date"], (date("Z") - (get_settings('gmt_offset') * 3600)), $thisDate[$i]["timeSince"], $thisDate[$i]["link"], $getOptions["timeOffset"], $getOptions["displayFormatPrefix"], $getOptions["displayFormatSuffix"], $getOptions["displayStyle"]); } if(($thisDate[$i]["text"]==NULL) && (isset($thisDate[$i]))){ $eventCount++; } } if($output == "return") return $toReturn; if($fergcorp_countdownTimer_noEventsPresent == TRUE){ echo $getOptions["displayFormatPrefix"].__('No dates present', 'afdn_countdownTimer').$getOptions["displayFormatSuffix"]; } } /*PLUGIN-WIDE FUNCTIONS*/ /*fergcorp_countdownTimer_format takes four variables and returns a single strong for the output of the plugin $text is a string with just the text associated with a given date, for example "My 20th Birthday!" HTML formatting is allowed, just be sure to close your tags $time is an integer formated in UNIX time. $offset is a signed integer (i.e. it has both positive and negitive values) and represents the sum of many timezone offsets to make sure that the correct time is displayed, no matter what timezone you are in, your server is in, or your blog is in. $timeSince is a single integer representitive of a boolean value. 1 = True; 0 = False. This really should be passed along as a boolean value, so it's on the to do list to fix. In any event, if this value is set to "True", after an event has passed, the text will count up from the time the even happened. If it is set to "False, it will not count and the event will not be displayed. Simple enough? */ function fergcorp_countdownTimer_format($text, $time, $offset, $timeSince=0, $link=NULL, $timeFormat = "j M Y, G:i:s", $displayFormatPrefix = "
  • ", $displayFormatSuffix = "
  • ", $displayStyle = "cursor:pointer; border-bottom:1px black dashed"){ global $fergcorp_countdownTimer_noEventsPresent, $getOptions; $time_left = $time - time() + $offset; if(($time_left < 0)&&($timeSince==1)){ $fergcorp_countdownTimer_noEventsPresent = FALSE; if($text) $content = $displayFormatPrefix.($link==""?$text.":":"".$text.":")."
    \n"; if($timeFormat == "") $content .= fergcorp_countdownTimer_fuzzyDate((time() + $offset), $time)." ago".$displayFormatSuffix; else $content .= "".fergcorp_countdownTimer_fuzzyDate((time() + $offset), $time)." ago".$displayFormatSuffix; //echo $content; return $content; } elseif($time_left > 0){ $fergcorp_countdownTimer_noEventsPresent = FALSE; if($text) $content = $displayFormatPrefix.($link==""?$text.":":"".$text.":")."
    \n"; if($timeFormat == "") $content .= fergcorp_countdownTimer_fuzzyDate($time, (time() + $offset)).$displayFormatSuffix; else $content .= "in ".fergcorp_countdownTimer_fuzzyDate($time, (time() + $offset))."".$displayFormatSuffix; //echo $content; return $content; } else{ return NULL; } } //It's amazing how hard counting can really be. function fergcorp_countdownTimer_fuzzyDate($targetTime, $nowTime){ global $getOptions; $rollover = 0; $s = ''; $nowYear = date("Y", $nowTime); $nowMonth = date("m", $nowTime); $nowDay = date("d", $nowTime); $nowHour = date("H", $nowTime); $nowMinute = date("i", $nowTime); $nowSecond = date("s", $nowTime); $targetYear = date("Y", $targetTime); $targetMonth = date("m", $targetTime); $targetDay = date("d", $targetTime); $targetHour = date("H", $targetTime); $targetMinute = date("i", $targetTime); $targetSecond = date("s", $targetTime); $resultantYear = $targetYear - $nowYear; $resultantMonth = $targetMonth - $nowMonth; $resultantDay = $targetDay - $nowDay; $resultantHour = $targetHour - $nowHour; $resultantMinute = $targetMinute - $nowMinute; $resultantSecond = $targetSecond - $nowSecond; if($resultantSecond < 0){ $resultantMinute--; $resultantSecond = 60 + $resultantSecond; } if($resultantMinute < 0){ $resultantHour--; $resultantMinute = 60 + $resultantMinute; } if($resultantHour < 0){ $resultantDay--; $resultantHour = 24 + $resultantHour; } if($resultantDay < 0){ $resultantMonth--; $resultantDay = $resultantDay + date("t", $targetMonth); } if($resultantMonth < 0){ $resultantYear--; $resultantMonth = $resultantMonth + 12; } load_plugin_textdomain('afdn_countdownTimer', 'wp-content/plugins'); //Year if($getOptions['showYear'] && ($resultantYear)){ $s = $resultantYear.' '.($resultantYear==1?__("year", "afdn_countdownTimer"):__("years", "afdn_countdownTimer")).', ';; } else{ $rollover = $resultantYear*31536000; } //Month if($getOptions['showMonth']){ $s = $s.($resultantMonth + intval($rollover/2592000)).' '.($resultantMonth==1?__("month", "afdn_countdownTimer"):__("months", "afdn_countdownTimer")).', '; $rollover = $rollover - intval($rollover/2592000)*2592000; } else{ $rollover = $rollover + $resultantMonth*2592000; } //Week (weeks are counted differently becuase we can just take 7 days and call it a week...so we do that) if($getOptions['showWeek']){ $s = $s.intval( ($resultantDay + intval($rollover/86400) )/7 ).' '.((intval( ($resultantDay + intval($rollover/86400) )/7))==1?__("week", "afdn_countdownTimer"):__("weeks", "afdn_countdownTimer")).', '; $rollover = $rollover - intval($rollover/86400)*86400; $resultantDay = $resultantDay - intval( ($resultantDay + intval($rollover/86400) )/7 )*7; } //Day if($getOptions['showDay']){ $s = $s.($resultantDay + intval($rollover/86400)).' '.($resultantDay==1?__("day", "afdn_countdownTimer"):__("days", "afdn_countdownTimer")).', '; $rollover = $rollover - intval($rollover/86400)*86400; } else{ $rollover = $rollover + $resultantDay*86400; } //Hour if($getOptions['showHour']){ $s = $s.($resultantHour + intval($rollover/3600)).' '.($resultantHour==1?__("hour", "afdn_countdownTimer"):__("hours", "afdn_countdownTimer")).', '; $rollover = $rollover - intval($rollover/3600)*3600; } else{ $rollover = $rollover + $resultantHour*3600; } //Minute if($getOptions['showMinute']){ $s = $s.($resultantMinute + intval($rollover/60)).' '.($resultantMinute==1?__("minute", "afdn_countdownTimer"):__("minutes", "afdn_countdownTimer")).', '; $rollover = $rollover - intval($rollover/60)*60; } else{ $rollover = $rollover + $resultantMinute*60; } //Second if($getOptions['showSecond']){ $s = $s.($resultantSecond + $rollover).' '.($resultantSecond==1?__("second", "afdn_countdownTimer"):__("seconds", "afdn_countdownTimer")).', '; } return rtrim($s,", "); //...and return the result (a string) } add_action('admin_menu', 'afdn_countdownTimer_optionsPage'); //Add Action for adding the options page to admin panel add_action('activate_'.plugin_basename(__FILE__), 'afdn_countdownTimer_install'); function afdn_countdownTimer_install(){ $version = get_option("fergcorp_countdownTimer_version"); update_option("widget_fergcorp_countdown", array("title"=>"Countdown Timer", "count"=>"-1")); $getOptions = get_option("afdn_countdownOptions"); if($version == NULL){ //Version < 1.8 if($getOptions == NULL){ //No Previous Install (i.e. first time user) $afdnOptions = array( "deleteOneTimeEvents" => "0", //Should One Time Events be deleted after the happen (boolean) "checkUpdate" => "1", //Should the plugin check for updates (boolean) "timeOffset" => "F jS, Y, g:i a", //What is the time format "enableTheLoop" => "0", //Should the timer be allowed within the loop (boolean) "displayFormatPrefix" => "
  • ", "displayFormatSuffix" => "
  • ", "displayStyle" => "cursor:pointer; border-bottom:1px black dashed", "showYear" => "1", "showMonth" => "1", "showWeek" => "0", "showDay" => "1", "showHour" => "1", "showMinute" => "1", "showSecond" => "0", ); //Create the array to store the countdown options } else{ //Previously installed, but < version 1.8 $afdnOptions = array( "deleteOneTimeEvents" => $getOptions['deleteOneTimeEvents'], //Should One Time Events be deleted after the happen (boolean) "checkUpdate" => $getOptions['checkUpdate'], //Should the plugin check for updates (boolean) "timeOffset" => $getOptions['timeOffset'], //What is the time format "enableTheLoop" => $getOptions['enableTheLoop'], //Should the timer be allowed within the loop (boolean) "displayFormatPrefix" => $getOptions['displayFormatPrefix'], "displayFormatSuffix" => $getOptions['displayFormatSuffix'], "displayStyle" => "cursor:pointer; border-bottom:1px black dashed", "showYear" => "1", "showMonth" => "1", "showWeek" => "0", "showDay" => "1", "showHour" => "1", "showMinute" => "1", "showSecond" => "0", ); //Create the array to store the countdown options } } elseif($version < 1.9){ $afdnOptions = array( "deleteOneTimeEvents" => $getOptions['deleteOneTimeEvents'], //Should One Time Events be deleted after the happen (boolean) "checkUpdate" => $getOptions['checkUpdate'], //Should the plugin check for updates (boolean) "timeOffset" => $getOptions['timeOffset'], //What is the time format "enableTheLoop" => $getOptions['enableTheLoop'], //Should the timer be allowed within the loop (boolean) "displayFormatPrefix" => $getOptions['displayFormatPrefix'], "displayFormatSuffix" => $getOptions['displayFormatSuffix'], "displayStyle" => "cursor:pointer; border-bottom:1px black dashed", "showYear" => $getOptions['showYear'], "showMonth" => $getOptions['showMonth'], "showWeek" => "0", "showDay" => $getOptions['showDay'], "showHour" => $getOptions['showHour'], "showMinute" => $getOptions['showMinute'], "showSecond" => $getOptions['showSecond'], ); } update_option("afdn_countdownOptions", $afdnOptions);//Update the WPDB for the options*/ update_option("fergcorp_countdownTimer_version", "1.9"); } $getOptions = get_option("afdn_countdownOptions"); //Get the options from the WPDB (this is actually pretty sloppy on my part and should be fixed) if($getOptions["enableTheLoop"]){ //If the timer is to be allowed in The Loop, run this add_filter('the_content', 'afdn_countdownTimer_loop', 1); } // Put functions into one big function we'll call at the plugins_loaded // action. This ensures that all required plugin functions are defined. if(!function_exists('widget_fergcorp_countdown_init')){ function widget_fergcorp_countdown_init() { // Check for the required plugin functions. This will prevent fatal // errors occurring when you deactivate the dynamic-sidebar plugin. if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') ) return; // This saves options and prints the widget's config form. function widget_fergcorp_countdown_control() { $options = $newoptions = get_option('widget_fergcorp_countdown'); if ( $_POST['countdown-submit'] ) { $newoptions['title'] = strip_tags(stripslashes($_POST['countdown-title'])); $newoptions['count'] = (int) $_POST['countdown-count']; } if ( $options != $newoptions ) { $options = $newoptions; update_option('widget_fergcorp_countdown', $options); } ?>