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

Help needed with Countdown Calendar extension

blizeHblizeH ✭✭
edited April 2007 in Vanilla 1.0 Help
I've developed a small countdown calendar that I want placed on the sidebar to be released on the site as a proper extension as it will be very easy to customise and use for anyone else who's interested (i.e. it isn't specific to birthdays, weddings etc like the other one, plus that one was never released) - but I've encountered a problem, or four ;o

Here's the code I've got thus far:

<?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. */ if ( in_array( $Context->SelfUrl, array( "index.php", "categories.php", "comments.php" ) ) && $Context->Session->UserID > 0 ) { $Panel->AddList( $ListName ); $fp = fopen('cal.txt', 'rb'); // Reads the text file while ($row = fgetcsv($fp, 1000)) { list($title, $date, $venue, $url, $diff) = $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); echo "<a href=\"{$url}\">{$title}</a><br />{$diff} days @ {$venue} <br /><br />"; } else if ($diff < 86400) // 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); echo "<a href=\"{$url}\">{$title}</a><br />{$diff} hours @ {$venue} <br /><br />"; } else { // Date has already passed, do nothing } } else { // Not logged in, do nothing } ?>

The main problems are:
1) It throws up an error (which can be seen here)
2) I've no idea how to make it look nice in Vanilla
3) Ideally I'm after a way to let users have the option to turn it on or off in their control panel, no idea if this is hard to do.
4) The else statement at the end isn't working, it's throwing up past dates that it shouldn't! (ignore this, I'm dumb)

You can check out the original code here - Calendar03 pretty much works as a standalone thing, it's just when I try and integrate it into Vanilla it breaks.
«1345

Comments

  • Options
    The error is because you're not closing this bracket:while ($row = fgetcsv($fp, 1000)) { And having as a preference is quite easy, just take a look through Vanilla.Control.PreferencesForm.php and themes/account_preferences_form.php and you should be able to figure out how to add one.
  • Options
    Many thanks, have closed that bracket but I'm still not having much luck :(
  • Options
    Hmm, I cna't seem to point it to the file! If I do /extensions/Calendar/cal.txt it works fine from the root, but when I'm in /discussions/ or whatever it doesn't work.
  • Options
    Use an absolute path.
  • Options
    Fair enough, I guess (was trying to make it easy for anyone to use as an extension, but I guess it's easy to edit that one line anywyas).

    Many thanks
  • Options
    Argh, I've broke it even more now! :D
  • Options
    You should be using the vanilla configuration paths to create absolute paths, nick.

    eg. $Configuration['EXTENSION_PATH'].'/extension/file.txt';
  • Options
    blizeHblizeH ✭✭
    edited August 2006
    I've tried that but it breaks, thanks anyway :(

    Parse error: syntax error, unexpected T_STRING in /home/glosunit/public_html/extensions/Calendar/default.php on line 12

    Have set it back to an absolute path again.
  • Options
    Anyone know how to remove the errors on the home page and place the items nicely into the sidebar please? http://www.glosunit.co.uk
  • Options
    edited August 2006
    You need to be using $Panel->AddList instead of your echos. Check out the documentation: http://lussumo.com/docs/doku.php?id=vanilla:development:controlpanel
  • Options
    blizeHblizeH ✭✭
    edited August 2006
    Have just changed to AddList but still not having any luck, I'm getting the exact same error actually which is odd.
  • Options
    Can you post what you have so far?
  • Options
    blizeHblizeH ✭✭
    edited August 2006
    Sure:

    <?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. */ AddList($ListName, $Position = '0', $ForcePosition = '0') $fp = fopen('cal.txt', 'rb'); // Reads the text file while ($row = fgetcsv($fp, 1000)) { list($title, $date, $venue, $url, $diff) = $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 "<a href=\"{$url}\">{$title}</a><br />{$diff} days @ {$venue} <br /><br />"; } else if ($diff < 86400) // 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 "<a href=\"{$url}\">{$title}</a><br />{$diff} hours @ {$venue} <br /><br />"; } else { // Date has already passed, do nothing } } ?>
    I was going to update it with the dictionary definitions, but couldn't since there's no defined number of items to be added to the sidepanel unfortunately.

    Apologies for my newbieness, it's the first time I've ever done anything php-related.
  • Options
    Try this:
    <?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.
    */
    
    if(!isset($Panel)) return;
    $Panel->AddList('Gigs');
    
    $fp = fopen('cal.txt', 'rb'); // Reads the text file
    if(!$fp) return;
    
    while ($row = fgetcsv($fp, 1000))
    {
    	list($title, $date, $venue, $url, $diff) = $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('Gigs', '<b>'.$title.'</b><br><i>'.$diff.' days @ '.$venue.'</i>', $url);
    	}
    	
    	else if ($diff < 86400) // 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('Gigs', '<b>'.$title.'</b><br><i>'.$diff.' hours @ '.$venue.'</i>', $url);
    	}
    	else
    	{
    		// Date has already passed, do nothing
    	}
    }
    
    fclose($fp);
    
    ?>
  • Options
    You need parentheses around the data sent to Panel->AddlistItem( xxxxx ).
  • Options
    blizeHblizeH ✭✭
    edited August 2006
    Oh ho! Absolutely fantastic, thank you so much for all of your help chaps, especially you SirNot! I've also managed to fix my if statement so it doesn't display past gigs, but unfortunately I'm still getting the following error everytime it outputs something: Notice: Undefined offset: 4 in /home/glosunit/public_html/extensions/Calendar/default.php on line 20 And one final thing before it's totally finished (sorry!) - is there anyway of placing it at the bottom of the sidebar, but just about the Lussumo/Vanilla disclaimer thing ;o
  • Options
    NickENickE New
    edited August 2006
    Try taking out the $diff variable from the list, and see if that eliminates the notice. And to change its position pass the Panel::AddList function a second parameter specifying the position (something like 200 will probably force it down to the bottom).
  • Options
    Yessssssssss! Absolute legend, removing $diff worked a treat, as did adding in a second parameter, thank you so much!
  • Options
    blizeHblizeH ✭✭
    edited August 2006
    Last time I ask anything, I promise!

    I'm getting critical error again preventing the page to load after trying to add an option in the user menu:

    <?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 SirNot and the guys from #php on Efnet for making this possible. */ CreateArrayEntry($Context->Dictionary, 'EnableCalendar', 'Enable the gig calendar?'); $PreferencesForm->AddPreference('Calendar', 'EnableCalendar', 'CalendarEnabled'); if $Context->Session->User->Preference('NotifyOnNewWhisper') { 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); } else { // Date has already passed, do nothing } } fclose($fp); } else { // User does not have calendar enabled, do nothing } ?>
  • Options
    I have your extension working. The dates (hours) didn't come out, so I hade to add the following to calculate the correct date: $pieces = explode("/",$date); $month = $pieces[0]; $day = $pieces[1]; $year = $pieces[2]; $curdate = mktime( 0, 0, 0, $month, $day, $year ); $diff = $curdate - time(); And for the fopen, I only use 'extensions/Calendar/cal.txt'.
This discussion has been closed.