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.

Help needed with Countdown Calendar extension

124

Comments

  • Oh nope, 1.0!

    If I leave it as it is, will it work in both 1.0 and 1.0.1? If so, I'd like to keep it that way if possible I think ;o
  • edited August 2006
    yep, but it an easy update, just some bug fixes and some delegation added (and some property added). There is no reason for not updating vanilla 1.0.0 to 1.0.1

    I add that to my extensions to to be sure people know they need Vanilla 1.0.1:
    // check if you have the right version of vanilla for this add-on if (!version_compare(APPLICATION_VERSION, '1.0.1', '>=')) { //Language definitions for vanilla 1.0 $Context->Dictionary['EmailVerification_ErrVanillaVersion'] = 'Vanilla 1.0.1 or higher is required for the Applicant Email Verification'; //display an error message on the extension page and registration page when the extension is used with Vanilla 1.0.0 if ( $Context->SelfUrl == 'settings.php' && in_array(ForceIncomingString('PostBackAction', ''), array('Extensions', 'RegistrationChange')) ) $Context->WarningCollector->Add($Context->GetDefinition('EmailVerification_ErrVanillaVersion')); } else { ... // my script here
  • Seem to be having a small problem with this, I've got a line set to:

    "Taking Names, BWP and All City Uproar", 1161070200, "Le Pub, Newport", "http://www.glosunit.co.uk/discussion/1758/"

    Which of course should show up today @ 7:30pm, and give me a nice countdown to it, but for some reason it's not appearing at all and I can't see a problem in either that line of csv, nor the code itself:

    <?php /* Extension Name: Gig Calendar Extension Url: http://lussumo.com/community/discussion/3446/ Description: Shows upcoming gigs Version: 1.0 Author: Nick Drew Author Url: http://www.glosunit.co.uk Comments: Huge thanks to SirNot, jimw, Minisweeper ... etc */ $Context->Configuration['PREFERENCE_CalendarEnabled'] = 1; $Context->Dictionary['EnableCalendar'] = 'Enable the gig calendar?'; $Context->AddToDelegate('PreferencesForm', 'Constructor', 'GigCalender_Preferences'); function GigCalender_Preferences(&$Prefs) { if($Prefs->IsPostBack) $Prefs->AddPreference('Calendar', 'EnableCalendar', 'CalendarEnabled'); } if($Context->Session->User->Preference('CalendarEnabled')) { if(!isset($Panel)) return; $Panel->AddList('Gig Calendar', 200); $fp = fopen('extensions/Calendar/cal.txt', 'rb'); // Reads the text file if(!$fp) return; while ($row = fgetcsv($fp, 1000)) { list($title, $date, $venue, $url) = $row; $diff = $date - time(); $diff = $diff + 3600; // Ammendment made due to server being one hour out of synch if ($diff >= 2592000) // Checks if the time difference is more than a month (roughly translated as 30 days) { $diff = $diff / 2592000; $diff = round($diff); if ($diff < 2) // if there's only one month left, will remove the 's' after month $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>1 month left, at '.$venue.'</i></font>', $url); else $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>'.$diff.' months left, at '.$venue.'</i></font>', $url); } else if ($diff >= 86400 and $diff < 2592000) // Checks if the time difference is more than a day { $diff = $diff / 86400; $diff = round($diff); if ($diff < 2) // if there's only one day left, will remove the 's' after day $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>1 day left, at '.$venue.'</i></font>', $url); else $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>'.$diff.' days left, at '.$venue.'</i></font>', $url); } else if ($diff > 0 and $diff < 86400 ) // Checks if the time difference is less than a day { $diff = $diff / 3600; $diff = round($diff); if ($diff < 2) // if there's only one hour left, will remove the 's' after hour $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>1 hour left, at '.$venue.'</i></font>', $url); else $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>'.$diff.' hours left, at '.$venue.'</i></font>', $url); } } fclose($fp); } ?>
  • I could never get the extension to work correctly with unix timestamps. I did get it to display the hours to the event by using SirNot's suggestion. This is what I have:

    list($month, $day, $year, $hour, $minute, $second ) = sscanf($date, "%d/%d/%d %d:%d:%d");
    $curdate = mktime( $hour, $minute, $second, $month, $day, $year );
    $diff = $curdate - time(); // the number of hours

    In the cal.txt file, I would have the event time in the format like 10/17/06 15:30.
  • blizeHblizeH ✭✭
    edited October 2006
    That sounds like a much better way of doing it, where exactly do I place that? Do I just change it so that ..

    list($title, $date, $venue, $url) = $row; $diff = $date - time();
    Reads...

    list($month, $day, $year, $hour, $minute, $second ) = sscanf($date, "%d/%d/%d %d:%d:%d"); $curdate = mktime( $hour, $minute, $second, $month, $day, $year ); $diff = $curdate - time(); // the number of hours
    Thanks!
  • Leave the list() = $row. Then replace the $diff = $date - time() with the new 3 lines of code.
  • Absolutely fantastic, thanks jimw!
  • Is there any way to allow forum users to submit events? Id love to have a calendar on my forum but I dont want to have to constantly maintain and update it, and a lot of events come up with short (under 1 week) notice.
  • You would have to add an admin page to allow a user (controlled by role, I think) to update the events. Right now, all the data is in a file. I don't think you want to let your users edit that file.
  • well.. i humbly request that be added in a future version :). id do it myself but my programming skills are beyond weak.
  • Apologies for the lack of admin page, I really struggled enough with it in it's current state anyway and only ended up with it working thanks to some fantastic advice from people on here! :-) Chuffed it works with 1.0.3 though, had a feeling for some reason it might of broken.
  • I've hacked this for a couple of reasons - the forum I run could do with something like this for events and competition deadlines (it's a forum for writers). I've changed the name from Gig Calendar to Countdown Calendar - which is more appropriate for my usage. And since the competition deadlines don't have a venue as such, I've done the following: 1: insert "." as venue 2: find: $diff = $curdate - time(); // the number of hours immediately beneath this line, insert: if ($venue == ".") { $at = ""; } else { $at = ", at "; } 3: find every instance of: , at '.$venue and replace with: '.$at.$venue All usual disclaimers apply, and it's probably not the best way of doing it, but it works for me. Figure this might be interesting for someone else as well.
  • Hmm, for some reason I'm having a bit of a nightmare with the dates at the moment. There's something less than a month away, and it's showing up as being 2 months? What's the deal with that? :(
  • Does your code look like what is in the post above? Has it been modified?
  • Yup, I believe it's the same as above:

    <?php /* Extension Name: Gig Calendar Extension Url: http://lussumo.com/community/discussion/3446/ Description: Shows upcoming gigs Version: 1.0 Author: Nick Drew Author Url: http://www.glosunit.co.uk Comments: Huge thanks to SirNot, jimw, Minisweeper and the guys from #php on Efnet for making this possible. */ $Context->Configuration['PREFERENCE_CalendarEnabled'] = 1; $Context->Dictionary['EnableCalendar'] = 'Enable the gig calendar?'; $Context->AddToDelegate('PreferencesForm', 'Constructor', 'GigCalender_Preferences'); function GigCalender_Preferences(&$Prefs) { if($Prefs->IsPostBack) $Prefs->AddPreference('Calendar', 'EnableCalendar', 'CalendarEnabled'); } if($Context->Session->User->Preference('CalendarEnabled')) { if(!isset($Panel)) return; $Panel->AddList('Gig Calendar', 200); $fp = fopen('extensions/Calendar/cal.txt', 'rb'); // Reads the text file if(!$fp) return; while ($row = fgetcsv($fp, 1000)) { list($title, $date, $venue, $url) = $row; list($month, $day, $year, $hour, $minute, $second ) = sscanf($date, "%d/%d/%d %d:%d:%d"); $curdate = mktime( $hour, $minute, $second, $month, $day, $year ); $diff = $curdate - time(); // the number of hours if ($diff >= 2592000) // Checks if the time difference is more than a month (roughly translated as 30 days) { $diff = $diff / 2592000; $diff = round($diff); if ($diff < 2) // if there's only one month left, will remove the 's' after month, got to be grammatically correct eh? $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>1 month left, at '.$venue.'</i></font>', $url); else $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>'.$diff.' months left, at '.$venue.'</i></font>', $url); } else if ($diff >= 86400 and $diff < 2592000) // Checks if the time difference is more than a day { $diff = $diff / 86400; $diff = round($diff); if ($diff < 2) // if there's only one day left, will remove the 's' after day, got to be grammatically correct eh? $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>1 day left, at '.$venue.'</i></font>', $url); else $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>'.$diff.' days left, at '.$venue.'</i></font>', $url); } else if ($diff > 0 and $diff < 86400 ) // Checks if the time difference is less than a day { $diff = $diff / 3600; $diff = round($diff); if ($diff < 2) // if there's only one hour left, will remove the 's' after hour, got to be grammatically correct eh? $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>1 hour left, at '.$venue.'</i></font>', $url); else $Panel->AddListItem('Gig Calendar', ''.$title.'<br><font color="#999999"><i>'.$diff.' hours left, at '.$venue.'</i></font>', $url); } } fclose($fp); } ?>
  • edited February 2007
    What is the date for that event? I just tested with an event on 4/5/7. This showed 2 months. It's not getting the actual difference but using the hard-coded amounts. You would probably want to see something like 1 month 20 days until the event, right?
  • Aww jeez, huge thanks for the reply, just triggered in my mind what the problem was. I'd entered it allowing for English dates and not US dates :(
  • International date and time format.

    One of my own personal little crusades ;) By all means allow the display in whatever format you like, but please make sure your extensions use this internally so that it can at least talk to other things in a universally understood format.
  • This extension requires the date to be entered in the text file in a certain format (mm/dd/yy). I don't know of an easy way to check the entered date for any valid date format. Do you know of a way to do this? Or maybe I am missing your point? Sorry if I am.
  • what about php's strtotime function?
This discussion has been closed.