dtwvr26066 2013-08-07 18:25
浏览 29
已采纳

ICS URL输出落后5个小时

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
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:".date("Ymd\THis\Z",$start)."
DTEND:".date("Ymd\THis\Z",$end)."
LOCATION:".$location."
TRANSP: OPAQUE
SEQUENCE:0
UID:".$uid."
DTSTAMP:".date("Ymd\THis\Z")."
SUMMARY:".$name."
DESCRIPTION:".$description."
PRIORITY:1
CLASS:PUBLIC
END:VEVENT
END: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条回答 默认 最新

  • dongshedan4672 2013-08-07 18:29
    关注

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

    $data = "BEGIN:VCALENDAR VERSION:2.0 METHOD:PUBLISH X-WR-TIMEZONE:America/New_York

    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
    VERSION:2.0
    METHOD:PUBLISH
    X-WR-TIMEZONE:America/New_York
    BEGIN:VEVENT
    DTSTART;VALUE=DATE:".date("Ymd\THis",$start)."
    DTEND;VALUE=DATE:".date("Ymd\THis",$end)."
    LOCATION:".$location."
    TRANSP: OPAQUE
    SEQUENCE:0
    UID:".$uid."
    DTSTAMP:".date("Ymd\THis\Z")."
    SUMMARY:".$name."
    DESCRIPTION:".$description."
    PRIORITY:1
    CLASS:PUBLIC
    END:VEVENT
    END:VCALENDAR";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭