2016-04-30 6 views
0

Ich habe eine Frage, ob jemand so nett wäre.Was ist los mit dieser ICS-Datei?

Nun eigentlich sind es zwei voneinander abhängige Fragen.

Ich mache eine Kalenderdatei, ich bin nicht gewohnt, Dateien zu schreiben, obwohl es einfach scheint, dies in eine TXT-Datei zu schreiben.

  1. Muss ich Header für eine .ics-Datei schreiben und wie geht das, wenn ja?

  2. Was ist falsch daran, das nicht in iCal (MacOS) geöffnet wird?

BEGIN:VCALENDAR 
VERSION:2.0 
PRODID:-//hacksw/handcal//NONSGML v1.0//EN 
CALSCALE:GREGORIAN 
BEGIN:VEVENT 
DTEND: 19700101T024640Z 
UID: 5724dce4946da 
DTSTAMP:20160430T162716Z 
LOCATION:Green Park Station 
DESCRIPTION:The Urban Playground Team are the original performance-parkour (2PK) company combining urban & contemporary dance with authentic French Free-Running. The Team have toured their performances and teaching across five continents for clients including the British Council. Since 2006 the team has included co-creator of Parkour Malik Diouf. In 2009 the Team designed and opened the UK’s first permanent parkour site\, and have since launched two more. In 2013 they founded the international performance-parkour network to support the development of 2PK globally. They have appeared on BBC1’s Blue Peter and Sky1’s Got To Dance. <br /> 
Steam is a touring performance\, in which a group of urban explorers discover\, beneath canvas tarps\, the skeletal remains of a machine that changed the world. Inspired\, they shovel coal on the fires of the past. Engineers and drivers hurry to work at the sounds of a whistle’s blast\, and the passengers begin to dance. Inspired by classic movie genre Steam takes the UPG Team on a whistle stop tour through silent movies\, the Wild West\, James Bond\, WWI and the dark future of inner city commuting…<br /> 
Try out your own skills after the show - and you could even become part of the next performance!<br /> 
See also Weds June 1st. 
URL;VALUE=URI:http://bathfringe.co.uk/single-event?u_name=Steam 
SUMMARY:Steam 
DTSTART:19700101T000000Z 
END:VEVENT 
END:VCALENDAR 

die Inhalte werden wie folgt generiert:

$contents = 

'BEGIN:VCALENDAR 
VERSION:2.0 
PRODID:-//hacksw/handcal//NONSGML v1.0//EN 
CALSCALE:GREGORIAN 
BEGIN:VEVENT 
DTEND: '.dateToCal($dateend) .' 
UID: '. uniqid() .' 
DTSTAMP:'. dateToCal(time()) .' 
LOCATION:'. escapeString($address) .' 
DESCRIPTION:'. escapeString($description) .' 
URL;VALUE=URI:'. escapeString($uri) .' 
SUMMARY:'. escapeString($summary) .' 
DTSTART:'.dateToCal($datestart) .' 
END:VEVENT 
END:VCALENDAR ' 
+0

Nur eine Anmerkung; Ich dachte, es könnte das Datum ungültig sein, da es der 1. Januar 1970 oben ist, aber ich habe das mit 'time()' geändert, und das ist es nicht. –

Antwort

2

Ich sehe zwei Probleme:

Ausgabe 1 - zusätzliche weißen Räume

Ihre iCal-Datei enthält ein paar weißen Räume an illegalen Positionen:

DTEND: 19700101T024640Z 
    ^

UID: 5724dce4946da 
    ^

END:VCALENDAR 
      ^

Nun, technisch gesehen der zweiter ist wahrscheinlich nicht ungültig, da UID einen Wert von TEXT definiert hat, aber Sie sollten darauf vorbereitet sein, damit in Schwierigkeiten zu geraten. Einige Implementierungen können dies möglicherweise nicht lesen, andere können den Speicherbereich entfernen, andere enthalten ihn möglicherweise.

Überprüfen Sie die ABNF in RFC 5545 für die richtige Syntax. Im Allgemeinen gibt es in iCalendar keine optionalen Leerzeichen.

Ausgabe 2 - falsche

Die DESCRIPTION Eigenschaft enthält Runden neue Linie Sequenzen zu entkommen, aber es ist nicht richtig übersetzt wird. Die neuen Zeilenzeichen am Ende der Inhaltszeilen sollten als \n maskiert werden (siehe RFC 5545, Section 3.3.11). So ist die Beschreibung Eigenschaft sollte wie folgt (alle in einer Zeile mit entkam neuen Zeilen Zeichen) zu lesen:

DESCRIPTION:The Urban Playground Team are the original performance-parkour (2PK) company combining urban & contemporary dance with authentic French Free-Running. The Team have toured their performances and teaching across five continents for clients including the British Council. Since 2006 the team has included co-creator of Parkour Malik Diouf. In 2009 the Team designed and opened the UK’s first permanent parkour site\, and have since launched two more. In 2013 they founded the international performance-parkour network to support the development of 2PK globally. They have appeared on BBC1’s Blue Peter and Sky1’s Got To Dance. <br />\nSteam is a touring performance\, in which a group of urban explorers discover\, beneath canvas tarps\, the skeletal remains of a machine that changed the world. Inspired\, they shovel coal on the fires of the past. Engineers and drivers hurry to work at the sounds of a whistle’s blast\, and the passengers begin to dance. Inspired by classic movie genre Steam takes the UPG Team on a whistle stop tour through silent movies\, the Wild West\, James Bond\, WWI and the dark future of inner city commuting…<br />\nTry out your own skills after the show - and you could even become part of the next performance!<br />\nSee also Weds June 1st. 

Noch besser wäre es, falten Sie die Linien wie so

DESCRIPTION:The Urban Playground Team are the original performance-park 
our (2PK) company combining urban & contemporary dance with authentic 
French Free-Running. The Team have toured their performances and teach 
ing across five continents for clients including the British Council. 
Since 2006 the team has included co-creator of Parkour Malik Diouf. In 
    2009 the Team designed and opened the UK’s first permanent parkour 
site\, and have since launched two more. In 2013 they founded 
the international performance-parkour network to support the development 
of 2PK globally. They have appeared on BBC1’s Blue Peter and Sky1’s 
Got To Dance. <br />\nSteam is a touring performance\, in which a group 
of urban explorers discover\, beneath canvas tarps\, the skeletal 
remains of a machine that changed the world. Inspired\, they shovel coal 
on the fires of the past. Engineers and drivers hurry to work at the 
sounds of a whistle’s blast\, and the passengers begin to dance. 
Inspired by classic movie genre Steam takes the UPG Team on a whistle 
stop tour through silent movies\, the Wild West\, James Bond\, WWI and 
the dark future of inner city commuting…<br />\nTry out your own 
skills after the show - and you could even become part of the next 
performance!<br />\nSee also Weds June 1st. 

Hinweis Leeraums zu Beginn jeder Zeile. Falten ist in Section 3.1 of RFC 5545 erklärt.

Beachten Sie auch, dass HTML-Tags von iCalendar nicht unterstützt werden. Kunden können dies so interpretieren oder nicht, wie Sie es beabsichtigt haben. Einige Clients zeigen nur die <br /> Tags im Plantext an. Allerdings sollte sich kein iCalendar-Prüfer beschweren.

die Header In Bezug auf die korrekte Inhaltstyp für iCalendar ist text/calendar, also wenn Sie diese über das Rück HTTP Sie folgende Header senden:

Content-type: text/calendar 

Wenn Sie dies als einen Kalender veröffentlichen möchten, dass eine Kalenderanwendung Sie können ein METHOD:PUBLISH Feld zum VCALENDAR Objekt hinzufügen, wie in RFC 5546 erläutert.

Zuletzt: Erwägen Sie, eine vorhandene iCalendar-Bibliothek zu verwenden, die all das für Sie erledigen kann (das Entkommen, das Falten ...). Schauen Sie sich Sabre-VObject an.

+0

Danke! Noch einmal bin ich über meinem Gehalt. Ich habe den weißen Platz geleckt. Die Unachtsamkeit des HTML-Coders fürchte ich. Kämpfen mit der BESCHREIBUNG; So wird es mir als Variable geliefert. Ich werde jetzt gehen und lesen, um es zu entkommen (derzeit durch eine Regex aber offensichtlich nicht richtig). –

+0

Obwohl ich die Faltung im RFC 5546 nicht wirklich befolge, habe ich festgestellt, dass 'strip_tags ($ description') gefolgt von' json_encode ($ description) 'das gewünschte Ergebnis liefert. –

+0

Beachten Sie, dass JSON-Escaping und iCalendar-Escaping nicht identisch sind, sodass Sie für bestimmte Zeichen falsche Ergebnisse erhalten. In JSON Strings müssen Sie '' 'entkommen, da es ein reservierter Char ist, aber nicht in iCalendar, daher sollte es nicht maskiert werden. Andererseits sind', 'und'; 'spezielle Zeichen in iCalendar und müssen mit Escapezeichen versehen werden in normalen Texten, was in JSON nicht der Fall ist – Marten

0

$ EOL = "\ r \ n";

$contents = 

'BEGIN:VCALENDAR'.$eol.' 
VERSION:2.0'.$eol.' 
PRODID:-//hacksw/handcal//NONSGML v1.0//EN'.$eol.' 
CALSCALE:GREGORIAN'.$eol.' 
BEGIN:VEVENT'.$eol.' 
DTEND: '.dateToCal($dateend) .$eol.' 
UID: '. uniqid() .$eol.' 
DTSTAMP:'. dateToCal(time()) .$eol.' 
LOCATION:'. escapeString($address) .$eol.' 
DESCRIPTION:'. escapeString($description) .$eol.' 
URL;VALUE=URI:'. escapeString($uri) .$eol.' 
SUMMARY:'. escapeString($summary) .$eol.' 
DTSTART:'.dateToCal($datestart) .$eol.' 
END:VEVENT'.$eol.' 
END:VCALENDAR '.$eol; 

Die Hauptsache ist, dass Sie $ eol nach jedem Link Break hinzufügen müssen.

+0

Es wirft immer noch einen Fehler in iCal. "Kalender kann diese Kalenderdatei nicht lesen." –