2016-04-30 79 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中引发恐慌。 “日历无法读取此日历文件。” –