SteamLUG / steamlug.org

SteamLUG
https://steamlug.org
9 stars 11 forks source link

iCal downloads for events #4

Closed swordfischer closed 11 years ago

swordfischer commented 11 years ago

I've created some mock-up code:

This is for next event

<?php

include('/var/www/steamlug.org/steameventparser.php');

$parser = new SteamEventParser();
$eventarr = $parser->genData("steamlug");

$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:http://steamlug.org
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@steamlug.org
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:" . date('Ymd', strtotime($eventarr["events"][0]["date"])) . 'T' . date('His', strtotime($eventarr["events"][0]["time"])) . "Z
DTEND:" . date('Ymd', strtotime($eventarr["events"][0]["date"])) . 'T' . date('His', strtotime($eventarr["events"][0]["time"])+7200) . "Z
SUMMARY:". $eventarr["events"][0]["title"] . "
END:VEVENT
END:VCALENDAR";

header('Content-type: text/calendar; charset=utf-8');
header("Content-Disposition: inline; filename=" . str_replace(' ', '_', $eventarr["events"][0]["title"]) . ".ics" );
echo $ical;
exit;

?>

This is for custom event and MUST be sanitized

<?php

include('/var/www/steamlug.org/steameventparser.php');
$parser = new SteamEventParser();
$eventarr = $parser->genData("steamlug");

$dtstart = $_GET["dtstart"];
$dttime  = $_GET["dttime"];
$summary = $_GET["title"];

$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:http://steamlug.org
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@steamlug.org
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:" . date('Ymd', strtotime($dtstart)) . 'T' . date('His', strtotime($dttime)) . "Z
DTEND:" . date('Ymd', strtotime($dtstart)) . 'T' . date('His', strtotime($dttime)+7200) . "Z
SUMMARY:". $summary . "
END:VEVENT
END:VCALENDAR";

header('Content-type: text/calendar; charset=utf-8');
header("Content-Disposition: inline; filename=" . str_replace(' ', '_', $summary) . ".ics" );
echo $ical;
exit;
?>
swordfischer commented 11 years ago

I've been using this for some time now, and it works as I intended, and solves my issues with ical downloads for each event dev.steamlug swordfischer_icalfeed/feed/calendar.php

Cheeseness commented 11 years ago

I've been subscribed to it as well, and it seems to have been working fine (although I can't recall if there have been new events added since).

Should we get some more testing done before pushing it live, or are we good with it as is?

swordfischer commented 11 years ago

It is live now. https://steamlug.org/feed/calendar.php

johndrinkwater commented 9 years ago

Edited swordfischer’s post above so that robots don’t query swordfischer_icalfeed/feed/calendar.php on the old dev site.