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?!?

edited August 2006 in Vanilla 1.0 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:

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...

image
«1

Comments

  • Whoa, that is very nice. Maybe someone could take that code and add a some way to add new dates and an option how many dates are displayed. I'd love to use that on my game dev forum where we post ETAs on mods and games.
  • I just thought of something: 4. when it's a countdown to someone's birthday, the link should point to that person's Vanilla user profile page. since it's all complete manual right now, that would be too hard to do.
  • That's looking nice. Very nice actually.
  • Yeah, nice. I'd store dates in a database but depending how many there are people would probably say a flatfile would be better. Either wouldnt be too difficult to implement and you could probably even have an option. Unless theres a reason you havent (presumably cause you did it all manually) i'm pretty sure it'd make a lot more sense to store the data as timestamps or date-times instead of the method you're using here. That way you could even have down-to-the-second timers. Might have a bash at this shortly...
  • edited September 2005
    added sort. yes I know, it's not pretty, but it's what I did in my spare spare time. plus, I was hungry.

    <?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" ); ?>
  • minisweeper - yeah, did it all manually and really, just wanted to prove to myself I could. if someone out there can make this more better AND wants to, by all means!
  • if i can just work out how to make an extension deeley for the admin/users pages...
  • Guys, is there a way at present to add a textbox or something as a user preference? I've flicked through the docs and i can work out how to add a checkbox but ideally i'd want the user to be able to choose how many upcoming events to display (or have this as a global setting, either of which i cant find an option for)?
  • Hey all you UBER coders! is there a way we can make this a real extension? I really like the idea... or point me to the docs minisweeper was talking about... I'll give it a whirl... be done in 4.32 years.
  • wtf. I said I'd do this?!
  • blizeHblizeH ✭✭
    edited August 2006
    Do it mini! \o/ This extension oozes potential imho, if I could find a way to convert it into something useable for gig dates I'd be absolutely in heaven :E "10 days until <insert random gig here>" "<price> - <venue> - <time>" mmmmmmmm! MMMMMMMMMMMM!
  • Okay, so I've decided I want to use this on my site. I assume that uploading the default.php and eventsdata.php into say extensions/calendar will work a treat? Is there anyway to let users easily edit and add to the eventsdata.php for now? Temporarily until I sorts something better out.
  • @mini, you could insert it in the user identity form quite easily (ie. with only a couple lines of code). Mark's flickrizer extension is a good example.
  • @mini: I have a script that I added to a WordPress countdown plugin that calculated how old a person would be in years and added that to the display, as well as a function to send an email as a reminder the event was approaching. If this would be useful, let me know.
  • Can anyone help me set this up please? I'll admit it's no where near like what I'm after just yet, but it's a great basis to work with and I love the layout of it.

    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:

    image
  • Doesnt it just list the next one?
  • I'll be using the countdown calendar too, if it becomes an extension!
  • "Doesnt it just list the next one?"

    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!
  • edited August 2006
    I got your extension working fine. I fixed one problem I had with multiple events on the same day. Since you use the days as the key, only one event is picked up and listed. You solved this in your sample data by adding the event descriptions on one entry in the data file. To make this a little more flexible, I added the $year to the key to make the key unique. Then in the foreach loop, I subtracted the $year from the $days variable. It works in case anyone else needs this mod. And now I also see someone making a gig calendar. Maybe you two should work together on this project.
  • I'm really glad that this made it to being a real extension... sorry I'm already looking for version 1.1 with input fields actually in vanilla so i don't have to modify a text file also the ability to see days and hours until a specific time of day... Thanks you Guys rock!
This discussion has been closed.