Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-11-08 00:51:57

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

Outputting a valid .ics file from an Event for download

Hi,

i wish, my Events could be downloadable as a file for an iCalendar or vCalendar to get the Event-Informations in the own digital calendar.

Is there any plugins or “how to” to make this with a valid .ics file?
I have try http://de-online.co.uk/2006/05/05/textpattern-and-ical, but its not outputting a link from the .ics file – i can only see the content, cant downloadable the event-informations.
What I do wrong or could do others?

Best would be, if the .ics-file-link would be inside the event-article or as button.

Best regards
Lythande

Offline

#2 2017-11-08 08:52:20

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,159
Website

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

I’m no expert on this, but I think you need the correct download headers to make the ics file download rather than display.

One way you can do that is to put your code to generate the ics file in a form for using with rah_external_output form (github link as gocom’s homepage seems to be down at the moment) and prefixing that form with:

; Content-Type: text/calendar
; Content-Disposition: attachment; filename=invite.ics

See the instructions with rah_external_output. The Content-Type infos I’ve given are from this page.

If, for example, you name your form rah_eo_generate-ics, you can then call it as a link in your page template as:

<a href="http://example.com/?rah_external_output=generate-ics&event=<txp:article_id />">Download ics</a>

You then use adi_gps, rah_gps or similar in your form to grab the article id and plug that into your article_custom tag as a tag in tag, e.g.

<txp:rah_gps name="event" />
<!-- OR: <txp:adi_gps name="event" quiet="1" /> if using adi_gps -->
<txp:article_custom id='<txp:variable name="event" />' section="events">
…
</txp:article_custom>

PS: You should also put some checks in place to ensure the ics generator can’t be misused: for example, check that the event attribute you get is a valid integer and end the ics generator if not, restrict your article_custom tag to the section with your events so that other article ids from your site cannot be processed, and prevent it from doing anything if no event is specified.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2017-11-08 09:16:46

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,159
Website

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

I think you can do the integer safety check like this:

<txp:rah_gps name="event" />
<!-- OR: <txp:adi_gps name="event" quiet="1" /> if using adi_gps -->
<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="events">
    …
  </txp:article_custom>
</txp:if_variable>

That should check if the event string is comprised just of digits (see ctype_digit) and set it to nothing if not. The if_variable-is-empty-else bit then only outputs the code if the variable event is actually a digit.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2017-11-08 09:49:20

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,911
Website

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

this would be an excellent howto for txptips. Julian, would you mind very much if you submitted it there?


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Offline

#5 2017-11-08 10:00:16

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,159
Website

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

In principle, that’s fine, but let’s see how Lythande gets on with it.


TXP Builders – finely-crafted code, design and txp

Offline

#6 2017-11-08 10:02:17

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

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

Much thanks jakob! :)
I try it now…

Offline

#7 2017-11-08 10:27:06

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

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

From rah_gps – is there any a .txt-File with the Plugin? On GitHub I dont find it… (only a .php)
I think, I try with ads_gps, because I there find a .txt-plugin.

Offline

#8 2017-11-08 11:18:28

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,159
Website

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

adi_gps is just fine but requires the extra attribute. Here’s a compile of jukka’s rah_gps:

# Name: rah_gps v0.1
# Extract HTTP POST/GET values as Textpattern variables
# Author: Jukka Svahn
# URL: http://rahforum.biz
# Recommended load order: 5
# .....................................................................
# This is a plugin for Textpattern - http://textpattern.com/
# To install: textpattern > admin > plugins
# Paste the following text into the "Install plugin" box:
# .....................................................................

YToxNDp7czo0OiJuYW1lIjtzOjc6InJhaF9ncH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YXImcGlkPWJhcmZvb0AsIGFib3Zl
IHdvdWxkIGNyZWF0ZSBhbmQgcG9wdWxhdGUgdHdvIHZhcmlhYmxlcywKQDx0eHA6dmFyaWFi
bGUgbmFtZT0ibG9jYXRpb24iIC8+QCBhbmQgQDx0eHA6dmFyaWFibGUgbmFtZT0icGlkIiAv
PkAuCgpoMy4gRXhhbXBsZSAjMjogRXh0cmFjdCBvbmx5IHNwZWNpZmljIHZhbHVlcwoKYmMu
IDx0eHA6cmFoX2dwcyBuYW1lPSJmb28sIGJhciIgLz4KCnAuIEFib3ZlIHdvdWxkIGV4cG9y
dCBHRVQvUE9TVCB2YWx1ZXMgdmFsdWVzIEBmb29AIGFuZCBAYmFyQCwgYW5kIGNyZWF0ZSB0
d28gbmV3ICJ2YXJpYWJsZXMiOmh0dHA6Ly90ZXh0cGF0dGVybi5uZXQvd2lraS9pbmRleC5w
aHA/dGl0bGU9dmFyaWFibGUgbmFtZWQgQGZvb0AgYW5kIEBiYXJALiI7czozOiJtZDUiO3M6
MzI6IjFlYmZhN2E4ZGFiOWJmYThmNzQ4OWNhYzUyMjgyY2QzIjt9

And here as files:


TXP Builders – finely-crafted code, design and txp

Offline

#9 2017-11-08 11:29:55

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

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

colak wrote #307686:

this would be an excellent howto for txptips. Julian, would you mind very much if you submitted it there?

You might wait for txp4.7 before submitting, since it can be done in core now (note to myself: update history).


etc_[ query | search | pagination | date | tree | cache ]

Offline

#10 2017-11-08 11:37:58

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

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

at moment I try it out:

inside the form rah_eo_generate-ics (set as “diverse” – was this right?) is now follow:

Content-Type: text/calendar
Content-Disposition: attachment; filename=invite.ics

BEGIN:VCALENDAR
VERSION:2.0
X-WR-CALNAME:Führungstermine
PRODID:-//Apple Computer, Inc//iCal 1.5//EN
X-WR-TIMEZONE:Europe/London
<txp:article_custom form=“icsitem” time=“any” section=“naechste-fuehrungen” sortdir=“asc” limit=“10000”/>
END:VCALENDAR

the form icsitem (set as “article”) has follow text:

BEGIN:VEVENT
DTSTART:<txp:custom_field name=“DTSTART” />
DTEND:<txp:custom_field name=“DTEND” />
SUMMARY:<txp:body />
END:VEVENT

I have created two custom-fields with both names. Inside the custom-fields are follow texts in this form of the time-stamps with the true numbers:

YYYYMMDD HH:MM

Now I dont sure understanding for adi_gps-form (where should i do this line?).
Inside a new form get-article-id i have:

<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”> … </txp:article_custom>
</txp:if_variable>

the form ics-download-link

<a href=”/?rah_external_output=generate-ics&event=<txp:article_id />”>Download ics</a>

should be inside from an article, because is for every event-article. My events is named “naechste-fuehrungen” – the section is named too. I am dont sure, leave “events” in php-lines.
So I have get the form kommende-fuehrungen for my event-article writing follow:

<div class=“artcolumn”>
<h1><txp:title /></h1>
<h2 class=“category”><txp:category1 title=“1” /></h2><txp:if_article_image>
<txp:images form=“image-grid-thumb” wraptag=“section” class=“thumbgrid” break=“figure” />
</txp:if_article_image>
<txp:output_form form=“artikel-body” />
<txp:output_form form=“ics-download-link” />
</div>

and on my site-template is this my forms for the event-articles:

<txp:article_custom section=“naechste-fuehrungen” category=”[true categories names inside…]” limit=“8” form=“kommende-fuehrungen” sort=“expires asc” offset=“0” status=“live” />

The ics-download-link has work – but the ics-event is empty, my calendar couldnt read that.

The ics-download-link outputting the article-id:
http://mydomain.de/?rah_external_output=generate-ics&event=5

Why is the content empty?

Edit the adi_gps to rah_gps-line.

Last edited by lythande (2017-11-08 11:53:43)

Offline

Board footer

Powered by FluxBB