Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2017-11-08 13:41:23

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,311

Re: Outputting a valid .ics file from an Event for download

RE-POSTING OF LYTHANDE’S POST THAT WAS SENT OFF AS REPORT:
_______________________________________________

I recherching for Property [UID]:

https://blog.emeidi.com/2016/06/29/einen-outlook-2010-kompatiblen-icalendar-ics-generieren/

There is inside form from an event:

BEGIN:VEVENT
UID:5772a5d6498eef051c12ed37@domain.tld
DTSTART;TZID=Mad:20160628T182910
DTEND;TZID=Mad:20160628T183410
DTSTAMP:20160629T190304Z
SUMMARY:Bahnhof Bern
LOCATION:Bahnhof Bern
COMMENT:
END:VEVENT

Hm, could do be that UID? How I could generate an UID?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#14 2017-11-08 13:49:23

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,752
Website

Re: Outputting a valid .ics file from an Event for download

Hi, you two are quicker than me. This is what I’ve got so far:

I think you need to do it like this:

First of all, each guided tour should be an article of its own (which I think you have).

Your page template looks fine, your form kommende-fuehrungen is okay too.

Inside your rah_eo_generate-ics form (misc/diverse type should be fine), you need to have this:

; Content-Type: text/calendar
; Content-Disposition: attachment; filename=invite.ics
<txp:rah_gps name="event" />
<txp:php>
  global $variable;
  if( !ctype_digit($variable['event']) ) {
    $variable['event'] = '';
  }
</txp:php>
<txp:if_variable name="event" value=""><txp:else />
  <txp:article_custom id='<txp:variable name="event" />' section="naechste-fuehrungen">
BEGIN:VCALENDAR
VERSION:2.0
X-WR-CALNAME:Fuehrungstermine
PRODID:-//Apple Computer, Inc//iCal 1.5//EN
X-WR-TIMEZONE:Europe/London
BEGIN:VEVENT
UID:<txp:posted format="iso8601"/>-<txp:article-id />@karinmuellerschmied.de
DTSTAMP:<txp:posted format="iso8601"/>
DTSTART;TZID=Europe/Berlin:<txp:custom_field name="DTSTART" />
DTEND;TZID=Europe/Berlin:<txp:custom_field name="DTEND" />
SUMMARY:<txp:body />
END:VEVENT
END:VCALENDAR
  </txp:article_custom>
</txp:if_variable>

This should give one ics link per event.

Note:
  • Your DTSTART and DTEND fields need to be in the form YYYYMMDDTHHMMSS, i.e. with a T between the date and time and the additional values for seconds. You’ve seen this by now.
  • I added an UID field and a DTSTAMP (creation date) as the ical validator suggests you need them.
  • I’m guessing txp:body needs to be without the HTML, or else escaped to prevent illegal characters. Maybe you want to try with txp:title first.

It may be necessary to clean some of the output to avoid things like umlauts or empty lines at the beginning and end. smd_wrap is good for both of those.

To test, you could comment out or temporarily remove the content-type and attachment lines at the beginning and just see what it outputs, then run that through the validator.

Finally, you may need to play around a little with the correct timezone information, but we can get to that once the basic principle is working.


TXP Builders – finely-crafted code, design and txp

Offline

#15 2017-11-08 13:53:59

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,752
Website

Re: Outputting a valid .ics file from an Event for download

In the example above I generated UID as a combination of the datestamp article id and domain

lythande wrote #307696:

Hm, could do be that UID? How I could generate an UID?

In the example above I generated UID as a combination of the datestamp article id and domain. I’m guessing the numbers in your example are an md5 hash generated from something like that, i.e. not random but unique to that article, date and source.


TXP Builders – finely-crafted code, design and txp

Offline

#16 2017-11-08 13:56:41

lythande
Member
Registered: 2009-09-08
Posts: 202
Website

Re: Outputting a valid .ics file from an Event for download

I have recherching for the [UID] and fount an explain here: https://blog.emeidi.com/2016/06/29/einen-outlook-2010-kompatiblen-icalendar-ics-generieren/

here code snippet is:

BEGIN:VEVENT
UID:5772a5d6498eef051c12ed37@domain.tld
DTSTART;TZID=Mad:20160628T182910
DTEND;TZID=Mad:20160628T183410
DTSTAMP:20160629T190304Z
SUMMARY:Bahnhof Bern
LOCATION:Bahnhof Bern
COMMENT:
END:VEVENT

So I have in my form icsitem

BEGIN:VEVENT
UID:<txp:posted format="w3cdtf" />@<txp:site_url />

now works with UID.

But now the validator means:
Your calendar parsed, but with errors.
Error: Error was: Property [DTSTAMP] must be specified once
Cause: Sorry, I couldn’t get an exact cause.

The DTSTAMP I do now inside:

BEGIN:VEVENT
UID:<txp:posted format="w3cdtf" />@<txp:site_url />
DTSTART:<txp:custom_field name="DTSTART" />
DTEND:<txp:custom_field name="DTEND" />
DTSTAMP:<txp:posted format="%Y%m%dT%H%M%SZ" />
SUMMARY:<txp:title />
END:VEVENT

now my ics-file is for iCalendar validate! :-)

But as I get the .ics-file for my iCalendar say my Calendar still: is emtpy…. arghhhh

Offline

#17 2017-11-08 14:03:04

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,752
Website

Re: Outputting a valid .ics file from an Event for download

lythande wrote #307695:

I understand now, that my timestamp was not correct. I corrected them to “20180217T150000” and End-Date same too.
(would there possible parsing the date “20180217 15:00” to “YYYYMMDDTHHMMSS”, so that I can fill in the custom-field a readable timestamp?)

Sorry for replying in bits and bots. Look at this date rewriting example in smd_wrap, which is probably helpful anyway here. Borrowing from that, I think you could do this:

<txp:smd_wrap delim="@"
     transform="date|%Y%m%dT%H%M%S">
<txp:custom_field name="DTSTART" />
</txp:smd_wrap>

TXP Builders – finely-crafted code, design and txp

Offline

#18 2017-11-08 14:04:37

lythande
Member
Registered: 2009-09-08
Posts: 202
Website

Re: Outputting a valid .ics file from an Event for download

sorry, i was recherching and validating, so I havent read your postings… sorry!

Now I make my rah_eo_generate-ics better how jacob say it.

But the validator has not like the DTSTAMP:<txp:posted format="iso8601"/>, so I have made it with DTSTAMP:<txp:posted format="%Y%m%dT%H%M%SZ" />.

Offline

#19 2017-11-08 14:08:00

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,752
Website

Re: Outputting a valid .ics file from an Event for download

lythande wrote #307699:

now my ics-file is for iCalendar validate! :-)

But as I get the .ics-file for my iCalendar say my Calendar still: is emtpy…. arghhhh

You’re getting there :-)

An ics file is just a text file, so can you open it in a text editor. You may be able to identify what’s missing or if there are extra lines up front or behind. Also, if you have all your events in one calendar file, you might want to try how they work individually first.

You should be able to edit the ics file directly, save it, then import it into/drop it onto your calendar.

lythande wrote #307702:

But the validator has not like the DTSTAMP:<txp:posted format="iso8601"/>, so I have made it with DTSTAMP:<txp:posted format="%Y%m%dT%H%M%SZ" />.

Yes, that works. The validator I linked to above didn’t require the Z at the end, but you may need it to get the right timezone later…


TXP Builders – finely-crafted code, design and txp

Offline

#20 2017-11-08 14:15:30

lythande
Member
Registered: 2009-09-08
Posts: 202
Website

Re: Outputting a valid .ics file from an Event for download

thanks, i think too, we solving it soon ;-)

jakob wrote #307697:

Inside your rah_eo_generate-ics form (misc/diverse type should be fine), you need to have this (code)

Hm, your code-snippet doesnt validate for iCalendar-validator.
he say:

Sorry, your calendar could not be parsed.
Error: Error was: Error at line 4:Expected [BEGIN], read [ ]
Cause: Sorry, I couldn’t get an exact cause.

So i think, he dont like the php-lines between ; Content-Disposition: and BEGIN:?

Offline

#21 2017-11-08 14:18:23

lythande
Member
Registered: 2009-09-08
Posts: 202
Website

Re: Outputting a valid .ics file from an Event for download

the iso8601 output YYYY-MM-DDTHH:MM:SS, but the validator need the timestamp without – and :, so I make the strftime inside.

Offline

#22 2017-11-08 14:19:41

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,752
Website

Re: Outputting a valid .ics file from an Event for download

What does the .ics file itself contain? Maybe there are some blank lines at the beginning.

If you’ve installed smd_wrap, you can put

<txp:smd_wrap_all>
…
</txp:smd_wrap_all>

around everything (below the ; … lines) and it should trim any preceding and trailing blank lines.


TXP Builders – finely-crafted code, design and txp

Offline

#23 2017-11-08 14:32:45

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,752
Website

Re: Outputting a valid .ics file from an Event for download

For the correct timezone, I believe you need to add after the initial opening calendar block:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Computer, Inc//iCal 1.5//EN
X-WR-TIMEZONE:Europe/Berlin

this VTIMEZONE block:

BEGIN:VTIMEZONE
TZID:Europe/Berlin
X-LIC-LOCATION:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE

And then in your actual event infos, you need to add ;TZID=Europe/Berlin to DTSTAMP, DTSTART, and DTEND, so you have something like this:

BEGIN:VEVENT
UID:20171088T232500-123@karinmuellerschmied.de
DTSTAMP;TZID=Europe/Berlin:20171088T232500
DTSTART;TZID=Europe/Berlin:20171108T122500
DTEND;TZID=Europe/Berlin:20171108T142500
SUMMARY:Text Description
END:VEVENT

and then the closing calendar entry:

END:VCALENDAR

Hope that helps…


TXP Builders – finely-crafted code, design and txp

Offline

#24 2017-11-08 14:32:56

lythande
Member
Registered: 2009-09-08
Posts: 202
Website

Re: Outputting a valid .ics file from an Event for download

the .ics file contains:


BEGIN:VCALENDAR
VERSION:2.0
X-WR-CALNAME:Führungstermine
PRODID:-//Apple Computer, Inc//iCal 1.5//EN
X-WR-TIMEZONE:Europe/London
BEGIN:VEVENT
UID:2017-11-07T23:29:11Z@http://mydomain.de/
DTSTART:20180217T150000
DTEND:20180217T163000
DTSTAMP:20171108T002911Z
SUMMARY:Sa, 17.02.2018
END:VEVENT
END:VCALENDAR

I have make my (validated) code inside again, because the form rah_eo_generate-ics need to have inside the BEGIN:VCALENDAR the <txp:article_custom ... />-snipped to get the custom-fields inside the article-form icsitem.

At moment I dont have parsing the readable custom-field with smd_wrap, because I think its important first to solve the ics-file itself. :-)

Offline

Board footer

Powered by FluxBB