0

I'll start off by saying that I am not a PHP developer. So I had another developer create a plugin that takes the start and end time from the Wordpress plugin CalendarizeIt and outputs that into a formatted ICS url. The problem is that the url is outputting a start and end time 5 hours earlier than it should.

Here's the plugin PHP:

<?php
// Original script from http://jamiebicknell.tumblr.com/post/413492676/ics-generator-php-class#_=_
// Modified by Sean Carruthers

$start          = $_GET['start'];
$end            = $_GET['end'];
$name           = $_GET['name'];
$description    = $_GET['description'];
$location       = $_GET['location'];
$uid            = "kaneko" . strtotime("now");

$data = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nMETHOD:PUBLISH\r\nBEGIN:VEVENT\r\nDTSTART:".date("Ymd\THis\Z",$start)."\r\nDTEND:".date("Ymd\THis\Z",$end)."\r\nLOCATION:".$location."\r\nTRANSP: OPAQUE\r\nSEQUENCE:0\r\nUID:".$uid."\r\nDTSTAMP:".date("Ymd\THis\Z")."\r\nSUMMARY:".$name."\r\nDESCRIPTION:".$description."\r\nPRIORITY:1\r\nCLASS:PUBLIC\r\nEND:VEVENT\r\nEND:VCALENDAR";

header("Content-type:text/calendar; charset=utf-8");
header('Content-Disposition: inline; filename="'.$name.'.ics"');
echo $data;
?>

Then in the Wordpress theme file:

<?php

$start_date = get_post_meta($post->ID, "fc_start", true);
$c_start_date = date("M j, Y",strtotime($start_date));

$end_date = get_post_meta($post->ID, "fc_end", true);
$c_end_date = date("M j, Y",strtotime($end_date));

$start_time = get_post_meta($post->ID, "fc_start_time", true);
$end_time = get_post_meta($post->ID, "fc_end_time", true);

$ics_args['start'] = strtotime($start_date . " " . $start_time);
$ics_args['end'] = strtotime($end_date . " " . $end_time);

$ics_args['name'] = get_the_title();
$ics_args['description'] = get_the_content();

$ics_args['location'] = get_post_meta($post->ID, "location", true);

$ics_url = plugins_url('kaneko/calendarize-it-mods/ics_event.php') . "?";
foreach($ics_args as $key => $value) {
   $ics_url .= "$key=$value&";
}

if($c_start_date == $c_end_date) {
   echo $c_start_date;
} else {
   echo $c_start_date . " - <br />" . $c_end_date;
}

?>

And finally the $ics_url variable is getting echoed in an anchor tag like so:

<a href="<?php echo $ics_url; ?>">

I've tried changing the strtotime in the $uid variable of the plugin to something like +5 hours but it does not seem to work.

Any help would be greatly appreciated.

Oh and I also played around with changing the timezone in the Wordpress settings. It is currently set to UTC-5, so I thought changing it to like Chicago would help but it did not either.

1 Answer 1

0

In the line below add X-WR-TIMEZONE:America/New_York

$data = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nMETHOD:PUBLISH\r\nX-WR-TIMEZONE:America/New_York\r\n

UPDATE: i have updated the whole line of code, its using DTSTART;VALUE=DATE: with out the Z and the same for DTEND

$data = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nMETHOD:PUBLISH\r\nX-WR-TIMEZONE:America/New_York\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:".date("Ymd\THis",$start)."\r\nDTEND;VALUE=DATE:".date("Ymd\THis",$end)."\r\nLOCATION:".$location."\r\nTRANSP: OPAQUE\r\nSEQUENCE:0\r\nUID:".$uid."\r\nDTSTAMP:".date("Ymd\THis\Z")."\r\nSUMMARY:".$name."\r\nDESCRIPTION:".$description."\r\nPRIORITY:1\r\nCLASS:PUBLIC\r\nEND:VEVENT\r\nEND:VCALENDAR";
4
  • Thanks for the quick answer. That didn't seem to be working though. Aug 7, 2013 at 18:35
  • can you supply us with the output from your feed?
    – cmorrissey
    Aug 7, 2013 at 19:21
  • Sure thing: http://thekaneko.org/wp-content/plugins/kaneko/calendarize-it-mods/ics_event.php?start=1376388000&end=1376409600&name=The%20Millennial%20Trains%20Project&description=&location=KANEKO%20|%201111%20Jones%20St& Aug 7, 2013 at 19:36
  • 1
    I have updated the answer above try the new line I have given you
    – cmorrissey
    Aug 7, 2013 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.