0

まず、私は 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 に設定されているため、シカゴのように変更すると役立つと思いましたが、そうでもありませんでした。

4

1 に答える 1