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 '
'; //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
}
function afdn_countdownTimer_loop($theContent){
global $getOptions;
//Filter function for including the countdown with The Loop
if(preg_match("", $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 = "
",
"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);
}
?>