Ho costruito un sito in PHP 5 e MySQL con una tabella che tiene traccia dei servizi fotografici programmati. Voglio spingere un feed di quegli "eventi" programmati in un file ical.Dynamic ical creato dal database non funzionante
Originariamente asked this question e ho ottenuto una buona risposta da S. Gehrig. Ho ottenuto un file ical di esempio e sto aggiornando regolarmente in Google Calendar ogni volta che ho regolato manualmente il file in Dreamweaver. Tuttavia, ora che ho aggiunto il PHP dinamico che tira dal database, non funzionerà.
Ecco il 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;
?>
L'output di questo file è esattamente lo stesso come il manuale, versione hard-coded che ho a lavorare, per quanto posso dire. Qualcuno può vedere perché questo non funziona ????
PS Ecco il codice del file che funziona: l'ho appena pubblicato sul mio server e sottoscritto tramite URL in Google Calendar. Quando ero codificato nel secondo evento, si presentava a breve in Google Calendar da solo.
<?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;
?>
AIUTO!
Un commentatore mi ha suggerito di provare rimuovendo le intestazioni e facendo eco alla variabile $ ical. Ecco i risultati di questo test, con le interruzioni di riga aggiunte per comodità:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:20090929T212141Z
DTSTART:20091001T230000Z
DTEND:20091001T230000Z
SUMMARY:little title
END:VEVENT
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:20090929T212141Z
DTSTART:20090926T230000Z
DTEND:20090927T010000Z
SUMMARY:A big photo shoot
END:VEVENT
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:20090929T212141Z
DTSTART:20091003T230000Z
DTEND:20091004T010000Z
SUMMARY:A big photo shoot
END:VEVENT
END:VCALENDAR
Grazie!
In Google Calendar, viene visualizzato un errore con il titolo "Errore impostazioni" e il testo: "Non è stato possibile analizzare il calendario all'URL richiesto." – rhodesjason
Entourage non lo aprirà affatto e iCal dice "Questo file di calendario è illeggibile. Nessun evento è stato aggiunto al tuo calendario iCal." – rhodesjason