ICS URL输出落后5个小时

时间:2013-08-07 18:25:54

标签: php wordpress strtotime icalendar

我首先要说的是我不是PHP开发人员。所以我让另一个开发人员创建了一个插件,它从Wordpress插件CalendarizeIt获取开始和结束时间,并将其输出到格式化的ICS URL。问题是网址输出比它应该提前5小时的开始和结束时间。

这是插件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;
?>

然后在Wordpress主题文件中:

<?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;
}

?>

最后,$ics_url变量将在锚标记中回显,如下所示:

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

我已尝试将插件的$uid变量中的strtotime更改为类似+5 hours的内容,但似乎无效。

非常感谢任何帮助。

哦,我也在改变Wordpress设置中的时区。它目前设置为UTC-5,所以我认为改变它就像芝加哥会有所帮助,但它也没有。

1 个答案:

答案 0 :(得分:0)

在下面的行中添加X-WR-TIMEZONE:America/New_York

  

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

更新:我更新了整行代码,其中DTSTART;VALUE=DATE:使用了ZDTEND使用了$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";

{{1}}