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
blizeH
✭✭
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:
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.
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.
0
This discussion has been closed.
Comments
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.Many thanks
eg. $Configuration['EXTENSION_PATH'].'/extension/file.txt';
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.
<?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.
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 } ?>