Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Countdown Calendar: Here's what I have so far, Help?!?
My mother-in-law wanted some sort of calendar that would alert her to upcoming dates on our family website (flavored by Vanilla, of course). I had an idea running through my head, so I took my superior newbie php skills and set forth. Here's what I have so far:
I am awfully tired right now, but it seems to work pretty well. It shows the number of days until a certain event, and then below that it shows the events origination date and how many years it's been since that date. Works well for anniversaries and birthdays.
I'd really like some help with a few things so that maybe others would / could use if they really wanted...
1. the data is stored in this file, which is no good. what would be a good way to store the data outside of this file?
2. I use the Panel AddListItem method (it's called a method right) to add things because they are styled up real cool-lookin'. The fact that it's a clickable link really doesn't matter to me, but maybe someone with some superior wizard skills could code up a more-better CSS'd version. Or something.
3. If the upcoming event is a one-time-deal, then I shouldn't display the XX numbers of years since the origination date, right? that's a little bit of extra code.
Here's a screenshot in case that's your sort of thing. I should get some sleep...
Extension Name: Countdown Calendar
Extension Url: http://www.funkystew.com
Description: Shows upcoming dates
Version: 1.0
Author: Joel D Telling
Author Url: http://www.joeltelling.com
*/
$CurrentYear = date("Y");
$DanBirthday = "9/26/1978/Dan's Birthday";
$JoelBirthday = "8/4/1976/Joel's Birthday";
$MickeyBirthday = "2/20/1980/Mickey's Birthday";
$JoelMickeyAnniversary = "8/23/2003/Joel and Mickey's Anniversary";
$AprilBirthday = "4/24/1983/April's Birthday";
$HollyBirthday = "2/19/1980/Holly's Birthday";
$DonBirthday = "2/20/1950/Don's Birthday";
$arr = array( $DanBirthday, $JoelBirthday, $MickeyBirthday, $JoelMickeyAnniversary, $AprilBirthday, $HollyBirthday, $DonBirthday );
if ( in_array( $Context->SelfUrl, array( "index.php", "categories.php", "comments.php" ) ) && $Context->Session->UserID > 0 )
{
$ListName = "Countdown Calendar";
$Panel->AddList( $ListName );
foreach ( $arr as $Dates )
{
$currentyear = $CurrentYear;
$pieces = explode( "/", $Dates );
$month = $pieces[0];
$day = $pieces[1];
$year = $pieces[2];
$event = $pieces[3];
$diff = mktime( 0, 0, 0, $month, $day, $currentyear ) - time();
if ( 0 > $diff )
{
$currentyear++;
$diff = mktime( 0, 0, 0, $month, $day, $currentyear ) - time();
}
$days = floor( $diff / ( 24 * 60 * 60 ) ) + 1;
$numofyears = $currentyear - $year;
if ( $days == "1" )
{
$Panel->AddListItem( $ListName, $days." day until ".$event, "", $month."/".$day."/".$year." - ".$numofyears." years" );
}
elseif ( $days == "365" )
{
$Panel->AddListItem( $ListName, "Today is ".$event."!", "", $month."/".$day."/".$year." - ".$numofyears." years" );
}
else if ( $days < "31" )
{
$Panel->AddListItem( $ListName, $days." days until ".$event, "", $month."/".$day."/".$year." - ".$numofyears." years" );
}
}
}
?>
I am awfully tired right now, but it seems to work pretty well. It shows the number of days until a certain event, and then below that it shows the events origination date and how many years it's been since that date. Works well for anniversaries and birthdays.
I'd really like some help with a few things so that maybe others would / could use if they really wanted...
1. the data is stored in this file, which is no good. what would be a good way to store the data outside of this file?
2. I use the Panel AddListItem method (it's called a method right) to add things because they are styled up real cool-lookin'. The fact that it's a clickable link really doesn't matter to me, but maybe someone with some superior wizard skills could code up a more-better CSS'd version. Or something.
3. If the upcoming event is a one-time-deal, then I shouldn't display the XX numbers of years since the origination date, right? that's a little bit of extra code.
Here's a screenshot in case that's your sort of thing. I should get some sleep...
0
This discussion has been closed.
Comments
<?php /* Extension Name: Countdown Calendar Extension Url: http://www.funkystew.com Description: Shows upcoming dates Version: 1.0 Author: Joel D Telling Author Url: http://www.joeltelling.com */ $CurrentYear = date("Y"); $DaysOutLimit = "30"; $ListName = "Countdown Calendar"; include( "eventsdata.php" ); foreach ( $arr as $Dates ) { $currentyear = $CurrentYear; $pieces = explode( "/", $Dates ); $month = $pieces[0]; $day = $pieces[1]; $year = $pieces[2]; $event = $pieces[3]; $diff = mktime( 0, 0, 0, $month, $day, $currentyear ) - time(); if ( 0 > $diff ) { $currentyear++; $diff = mktime( 0, 0, 0, $month, $day, $currentyear ) - time(); } $days = floor( $diff / ( 24 * 60 * 60 ) ) + 1; $sortarray[$days] = $month."/".$day."/".$year."/".$event; } ksort( $sortarray ); if ( in_array( $Context->SelfUrl, array( "index.php", "categories.php", "comments.php" ) ) && $Context->Session->UserID > 0 ) { $Panel->AddList( $ListName ); foreach ( $sortarray as $key => $val ) { // echo $key." = ".$val."\n<br/>"; $days = $key; $pieces = explode( "/", $val ); $month = $pieces[0]; $day = $pieces[1]; $year = $pieces[2]; $event = $pieces[3]; $currentyear = $CurrentYear; $diff = mktime( 0, 0, 0, $month, $day, $currentyear ) - time(); if ( 0 > $diff ) { $currentyear++; } $numofyears = $currentyear - $year; // // the "tagline" is the little bit of text that shows // up in red under the linked text // $tagline = $month."/".$day."/".$year; if ( $numofyears == "1" ) { $tagline = $tagline." - ".$numofyears." year"; } elseif ( $numofyears > "1" && stristr( $event, "birthday" ) ) { $tagline = $tagline." - ".$numofyears." years old"; } elseif ( $numofyears > "1" ) { $tagline = $tagline." - ".$numofyears." years"; } // // gotta be grammatically correct, eh? // if ( $days == "1" ) { $eventline = $days." day until ".$event; } elseif ( $days == "365" || $days == "366" ) { $eventline = "<b>Today is ".$event."!</b>"; } else { $eventline = $days." days until ".$event; } if ( $days <= $DaysOutLimit || ( stristr( $event, "wedding" ) && $numofyears == "0" ) ) { $Panel->AddListItem( $ListName, $eventline, "", $tagline ); } } } ?>
looks for an "eventsdata.php" file, which looks something like this:
<?php $arr = array( "8/4/1976/Joel's Birthday", "2/20/1980/Mickey's Birthday", "10/22/1976/JB's Birthday", "8/23/2003/Joel & Mickey's Wedding Anniversary", "12/8/1975/Jenn's Birthday", "3/12/2001/Jenn's SMCU Anniversary", "3/22/1976/Trina's Birthday", "10/15/1975/David Wark's Birthday", "10/29/2005/Trina & David's Wedding", "6/22/1974/Steve's Birthday", "3/21/2006/Steve & Airi's Wedding", "12/23/1978/Jess's Birthday" ); ?>
Anyways, I've currently got this in eventsdata.php:
<?php $arr = array( "08/21/2006/Gig at wherever", "08/30/2006/Gig at wherever", "09/25/2007/Gig at wherever" ); ?>
But for some reason, only one of them is being listed on the page:
Would seem that way unfortunately. I'm dead keen on using it though, and do quite like the idea of having the information stored in a text based way rather than a database, but I've got a few questions:
1) Would it be possible to ammend the code so that it has the actual time, instead of just dates?
2) Is it possible to list things actually on the day? So it'll say "4 hours until so and so".
3) Is it possible to lay it out completely in a text file, instead of a php array one?
Many thanks!