2016-04-30 81 views
0

我有一個問題,如果有人會如此善良。這個ICS文件有什麼問題?

其實這是兩個相互依賴的問題。

我正在製作一個日曆文件,我不習慣編寫文件,儘管將它寫入.txt文件似乎很簡單。

  1. 我是否需要爲.ics文件編寫頭文件?如果是這樣,它是如何執行的?

  2. 這是什麼問題,無法在iCal(MacOS)中打開?

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 

內容被這樣產生的:

​​
+0

只是一個說明;我認爲這可能是1970年1月1日以前的無效日期,但我用'time()'改變了它,事實並非如此。 –

回答

2

我看到兩個問題:

問題1 - 額外的空格

您的iCal文件包含非法位置的情侶白色空間:

DTEND: 19700101T024640Z 
    ^

UID: 5724dce4946da 
    ^

END:VCALENDAR 
      ^

那麼,在技術上,第二個是可能不是無效的,因爲UID被定義爲具有TEXT的值,但是您應該準備好迎接這個問題。有些實現可能無法閱讀,其他實現可能會剝離空間,其他實現可能會包含它。

查看RFC 5545中的ABNF以獲取正確的語法。一般來說,iCalendar中沒有可選的空白。

第2期 - 不正確逃逸

DESCRIPTION屬性包含serveral的新行序列,但它不是正確轉義。內容行末尾的新行字符應該轉義爲\n(請參閱RFC 5545, Section 3.3.11)。於是Description屬性應該(與轉義的新行字符都在一行中)這樣寫的:

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. 

更重要的是,在開始摺疊線,像這樣

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. 

注意前導空白的每一行。摺疊在Section 3.1 of RFC 5545中解釋。

另請注意,iCalendar不支持HTML標籤。客戶可能會或可能不會以您想要的方式來解釋。有些客戶只會在計劃文本中顯示<br />標籤。但是,沒有iCalendar驗證器應該抱怨這一點。

關於頭,爲的iCalendar正確的內容類型是text/calendar,所以如果你回到這個通過HTTP發送下面的頭:如果您要發佈這是一個日曆,日曆應用程序

Content-type: text/calendar 

可以訂閱你應該考慮添加一個METHOD:PUBLISH字段VCALENDAR對象,如RFC 5546解釋。

最後:考慮使用現有的iCalendar庫,它可以處理所有這些(轉義,摺疊...)。看看Sabre-VObject

+0

謝謝!我再次處於薪酬級別之上。我有空白的舔。我擔心HTML編碼器的粗心大意。與描述搏鬥;這就是它作爲一個變量傳遞給我的方式。我現在要去閱讀它(目前由正則表達式完成,但顯然不正確)。 –

+0

儘管我並沒有真正遵循RFC 5546中的摺疊方法,但我發現'strip_tags($ description')後跟'json_encode($ description)'會產生所需的結果。 –

+0

請注意,JSON轉義和iCalendar轉義是不一樣的,所以你會得到某些字符不正確的結果。在JSON字符串中,你必須轉義''',因爲它是一個保留字符,但它不在iCalendar中,所以它不應該被轉義。另一方面,','和';'是iCalendar中的特殊字符,必須轉義在常規文本中,JSON並非如此 – 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; 

最重要的是你需要在每個鏈接中斷後添加$ eol。

+0

它仍然在iCal中引發恐慌。 「日曆無法讀取此日曆文件。」 –