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

245

Comments

  • blizeHblizeH ✭✭
    edited August 2006
    I don't really understand that code above, does it just make it into months and years as well? That's pretty neat and something I'd like to add to mine, I was going to use if statements but your way seems a lot cleaner, hmm...

    Think I'll delay the extension release until it's 100% too ;o
  • I don't know if you need that bit of code that jimw posted, but anyways:
    <?php
    /*
    Extension Name: Gig Calendar
    Extension Url: http://www.glosunit.co.uk
    Description: Shows upcoming gigs
    Version: 1.0
    Author: Nick Drew
    Author Url: http://www.glosunit.co.uk
    Comments: Huge thanks to 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('http://www.glosunit.co.uk/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();
    		
    		if ($diff >= 86400) // Checks if the time difference is more than a day
    		{
    			$diff = $diff + 3600; // Ammendment made due to server being one hour out of synch
    			$diff = $diff / 86400;
    			$diff = round($diff);
    			$Panel->AddListItem('Gig Calendar', '<b>'.$title.'</b><br><i>'.$diff.' days @ '.$venue.'</i>', $url);
    		}
    		else if ($diff < 86400 and $diff > 0) // Checks if the time difference is less than a day
    		{
    			$diff = $diff + 3600; // Ammendment made due to server being one hour out of synch
    			$diff = $diff / 3600;
    			$diff = round($diff); 
    			$Panel->AddListItem('Gig Calendar', '<b>'.$title.'</b><br><i>'.$diff.' hours @ '.$venue.'</i>', $url);
    		}
    	}
    	
    	fclose($fp);
    }
    
    ?>
  • I honestly can't thank you enough SirNot/jimw/Mini, I really really appreciate it and hopefully the users of my forum will do too!

    I'll wait for an answer from jimw regarding the dates etc, and possibly make the ammendments before releasing it.
  • edited August 2006
    On my server, without my additions, I got -312432 hours to the event. After I made this change (because I did it for another script), I got the correct 7 days until the event. I think if you add it, your extension will work on all servers. Try it and see. Basically you would replace your line of code: $diff = $date - time(); with what I suggested. (I modified a countdown plugin for WordPress and learned a little.)
  • Do I literally just remove that line of code and replace it with yours then? Also, what is the stance on using the font tag? :E /would like to change the venue/date colour slightly
  • Yes, just replace or what I would do is comment out the existing line with // at the beginning of the line. Then you can always put it back. Concerning the font tag, it sounds fine to me.
  • Many thanks, just gave that a try though and I'm getting that same silly error! :( http://www.glosunit.co.uk/ Code uploaded @ http://nopaste.php-q.net/234783 Huge(!) thanks :)
  • How are you entering your dates in the cal.txt file?
  • The Unix format, since it seemed easiest to work with at the time! http://www.glosunit.co.uk/extensions/Calendar/cal.txt
  • Any idea please? :)
  • Then my code won't work with this. You'll have to put your code back. In my cal.txt, I entered the date as 08/25/06.
  • That's fine, I'd rather enter it like that anyway since I won't have to run everything through an SQL query everytime I want to use something :P Would you mind if I could either see a line of your csv file, or just the exact way you entered the date/time please so I can use it for my own? Many thanks
  • blizeHblizeH ✭✭
    edited August 2006
    One final question before I release it properly (after it's fixed, haha). Should I make it so that the title only shows a certain amount of characters (so it's only on one line) and if you hover over it, it's got a <a title"$title">?
  • Here is what my data looks like: test1,9/1/6,philadelphia,http://www.xxxxx.us/wordpress/ test2,9/15/6,trenton,http://www.xxxxx.ws/wordpress/ Concerning changing the look, I would leave that up to the individual.
  • Good call, thank you. Just out of interest, that method you devised doesn't work with hours then? In that case I'm better off going with the Unix timestamp unfortunately :(
  • blizeh, I would recommend taking a look at either the strtotime function or sscanf/mktime functions. Either one of those would allow you to store the date in a more universal format but with more detail.
  • Well, there is obviously a difference between your server and mine. I just tested my code locally and changed the event date to today and got "-6 hours" to the event. This is an interesting problem. I'll have to do a little research on dates and see what I can find.
  • Yeah, I fixed that on mine by changing it so if the date has passed, it won't do anything. SirNot, would they work my existing code though? I might I might stick with what I have at the moment and just use some online php command thing that'll let me convert dates into unix format like I did with the current ones, absolute nightmare in the longrun but at least it works :D
  • Those functions would allow you to enter the dates into the file in a human-readable format (eg. "hh:mm:ss yyyy-mm-dd"), then convert them the timestamps in order to compare. For instance, if you used the aforementioned format to store the date, then you could probably do something like the following to turn it into a timestamp:list($hour, $minute, $second, $year, $month, $day) = sscanf($str, "%d:%d:%d %d-%d-%d"); $timestamp = mktime($hour, $minute, $second, $month, $day, $year);Where $str contains the date string.
  • blizeHblizeH ✭✭
    edited August 2006
    Why do I keep breaking things? I've tried to make things gramatically correct, but it's completely screwed up now. http://www.glosunit.co.uk/ For example: Why is it saying 15 day, 6 hour etc? Why has it placed an extra event at the bottom with a time of 1 hour? Arghhhhhhh! http://nopaste.php-q.net/234864
This discussion has been closed.