我首先要说我不是 PHP 开发人员。所以我让另一个开发人员创建了一个插件,它从 Wordpress 插件 CalendarizeIt 中获取开始和结束时间,并将其输出到格式化的 ICS url。问题是 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,所以我认为将其更改为像芝加哥会有所帮助,但它也没有。