7

スケジュールされた写真撮影を追跡するテーブルを使用して、PHP5とMySQLでサイトを構築しました。スケジュールされた「イベント」のフィードをicalファイルにプッシュしたいと思います。

私はもともとこの質問をし、 S。Gehrigから良い答えを得ました。サンプルのicalファイルが機能し、Dreamweaverでファイルを手動で調整するたびにGoogleカレンダーで定期的に更新されました。ただし、データベースから動的PHPプルを追加したため、機能しません。

PHPは次のとおりです。

<?php
require_once('../../_includes/initialize.php');

$ical = " BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN ";

$slots = Slot::find_all();
foreach($slots as $slot) {
    $job = Job::find_by_id($slot->job_id);

    $start_stamp = strtotime($slot->start);
    $end_stamp = strtotime($slot->endtime);
    $dtstart = gmdate('Ymd', $start_stamp).'T'. gmdate('His', $start_stamp) . "Z"; // converts to UTC time
    $dtend = gmdate('Ymd', $end_stamp).'T'. gmdate('His', $end_stamp) . "Z"; // converts to UTC time

    $summary = $job->title;

    $ical .= " BEGIN:VEVENT
    UID:" . $slot->id . "@homewoodphoto.jhu.edu
    DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
    DTSTART:" . $dtstart . "
    DTEND:" . $dtend . "
    SUMMARY:" . $summary . "
    END:VEVENT ";
}

$ical .= " END:VCALENDAR";

//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=homewoodphoto_master.ics');
echo $ical;
exit;

?>

このファイルの出力は、私が知る限り、私が作業している手動のハードコードされたバージョンとまったく同じです。なぜこれが機能しないのか誰かがわかりますか????

PSこれが機能しているファイルのコードです-私はちょうどそれを私のサーバーに投稿し、GoogleカレンダーのURLを介してサブスクライブしました。2番目のイベントでハードコーディングしたとき、それはまもなくGoogleカレンダーに表示されました。

<?php

$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN

BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)); . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:20090925T170000Z
DTEND:20090928T035959Z
SUMMARY:Bastille Day Party
END:VEVENT

BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)); . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:20090929T170000Z
DTEND:20090930T035959Z
SUMMARY:Camping Trip
END:VEVENT

END:VCALENDAR";

//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');

echo $ical;

exit;

?>

ヘルプ!

コメント投稿者は、ヘッダーを削除して$icalvarをエコーすることでテストすることを提案しました。そのテストの結果は次のとおりです。便宜上、改行が追加されています。

BEGIN:VCALENDAR 
VERSION:2.0 
PRODID:-//hacksw/handcal//NONSGML v1.0//EN 
BEGIN:VEVENT 
UID:21@homewoodphoto.jhu.edu 
DTSTAMP:20090929T212141Z 
DTSTART:20091001T230000Z 
DTEND:20091001T230000Z 
SUMMARY:little title 
END:VEVENT 
BEGIN:VEVENT 
UID:22@homewoodphoto.jhu.edu 
DTSTAMP:20090929T212141Z 
DTSTART:20090926T230000Z 
DTEND:20090927T010000Z 
SUMMARY:A big photo shoot 
END:VEVENT 
BEGIN:VEVENT 
UID:23@homewoodphoto.jhu.edu 
DTSTAMP:20090929T212141Z 
DTSTART:20091003T230000Z 
DTEND:20091004T010000Z 
SUMMARY:A big photo shoot 
END:VEVENT 
END:VCALENDAR

ありがとう!

4

3 に答える 3

20

検索でこれに遭遇した人にとっては、問題がどのように解決されたかが明確でない場合があります。基本的に、iCal仕様では、改行に\ r \ nが必要であり、行の先頭に空白はありません。これは、スクリプトで機能するように修正されたものです。

icalを使用する場合、次の3つのバリデーターが最も役立つことがわかりました。

最も基本的な(空白がない):http ://severinghaus.org/projects/icv/?url =

これは空白をキャッチします:http://icalvalid.cloudapp.net/Default.aspx

これは他の人が捕まえなかったものを捕らえるでしょうが、ほとんど厳しすぎます:http: //arnout.engelen.eu/icalendar-validator

また、すべての異なる要素に関する最高のドキュメント:http ://www.kanzaki.com/docs/ical/

于 2010-11-04T19:42:52.500 に答える
2

最初の推測では、アレイが正しく設定されていません。だからそれをテストするために私は削除することから始めます

//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=homewoodphoto_master.ics');

$ slot = Slot :: find_all();を変更します。に

$slots = Slot::find_all();
print_r($slots); 

オブジェクトの配列が設定されていることを確認します。

次に、コマンドラインまたはブラウザから実行して、Googleに送信する前に期待どおりに出力されることを確認します。

空白を避けるために、次のコードを試してください。

<?php
require_once('../../_includes/initialize.php');

$ical = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//hacksw/handcal//NONSGML v1.0//EN";

$slots = Slot::find_all();
foreach($slots as $slot) {
    $job = Job::find_by_id($slot->job_id);

    $start_stamp = strtotime($slot->start);
    $end_stamp = strtotime($slot->endtime);
    $dtstart = gmdate('Ymd', $start_stamp).'T'. gmdate('His', $start_stamp) . "Z"; // converts to UTC time
    $dtend = gmdate('Ymd', $end_stamp).'T'. gmdate('His', $end_stamp) . "Z"; // converts to UTC time

    $summary = $job->title;

    $ical .= "BEGIN:VEVENT\n";
    $ical .= "UID:" . $slot->id . "@homewoodphoto.jhu.edu\n";
    $ical .= "DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z\n";
    $ical .= "DTSTART:" . $dtstart . "\n";
    $ical .= "DTEND:" . $dtend . "\n";
    $ical .= "SUMMARY:" . $summary . "\n";
    $ical .= "END:VEVENT\n";
}

$ical .= "\nEND:VCALENDAR";

//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=homewoodphoto_master.ics');
echo $ical;
exit;

?>
于 2009-09-29T21:16:04.250 に答える
1

Mohammadの助けを借りて、エラーの原因はicsファイルに空白を追加するインデントされたコードであると推測しました。改行を使用するというMの提案は機能しませんでしたが、手動でEnterキーを押して改行を作成しましたが、次の行をインデントせずに、それを実行したようです。動作するコードは次のとおりです。

<?php
require_once('../../_includes/initialize.php');

$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
";

$slots = Slot::find_all();
foreach($slots as $slot) {
$job = Job::find_by_id($slot->job_id);

$start_stamp = strtotime($slot->start);
$end_stamp = strtotime($slot->endtime);
$dtstart = gmdate('Ymd', $start_stamp).'T'. gmdate('His', $start_stamp) . "Z"; // converts to UTC time
$dtend = gmdate('Ymd', $end_stamp).'T'. gmdate('His', $end_stamp) . "Z"; // converts to UTC time

$summary = $job->title;

$ical .= "BEGIN:VEVENT
UID:" . $slot->id . "@homewoodphoto.jhu.edu
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:" . $dtstart . "
DTEND:" . $dtend . "
SUMMARY:" . $summary . "
END:VEVENT
";
}

$ical .= "END:VCALENDAR";

//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=homewoodphoto_master.ics');
echo $ical;
exit;
?>
于 2009-09-30T12:40:43.810 に答える