Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2017-11-08 16:13:58

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

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

I sent you a couple of further ideas to try out in reply to your email.


TXP Builders – finely-crafted code, design and txp

Offline

#32 2017-11-08 17:45:31

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

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

Much thanks for supporting by Email!
Now works!!! :-)

How I solve it:

1. Create an Event in my own Calendar with all Information, what I do have wish inside. (URL, Description…)

2. Drop this Event to Desktop or in a File. Open it with a Texteditor.

3. Compare the calendar-Event with the forms icsitem and rah_eo_generate-ics.

I have compare both and have seen, that my text was in wrong order. After I corrected the order, it works! :-)

I have made two new custom_fields, because one for the url to the long article and another with the right Title for the calendar (and not the title from article).

Here is my .ics-file:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//Mac OS X 10.8.5//EN
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3
DTSTART:19700329T020000
TZNAME:MEZ
TZOFFSETTO:+0200
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10
DTSTART:19701025T030000
TZNAME:MEZ
TZOFFSETTO:+0100
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20171108T002911Z
UID:2017-11-07T23:29:11Z@http://mydomain.de/
DTEND;TZID=Europe/Berlin:20180217T163000
TRANSP:OPAQUE
SUMMARY:(Title for Calendar)
DTSTART;TZID=Europe/Berlin:20180217T150000
DTSTAMP:20171108T002911Z
LOCATION:Bundeskunsthalle Bonn
DESCRIPTION:Teilnahme nur nach Anmeldung bis 3 Tage vorher möglich!
URL;VALUE=URI:http://mydomain.de/url...
END:VEVENT
END:VCALENDAR

Offline

#33 2017-11-08 18:29:38

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

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

Hm, it works with more Event-Articles too. But: the .ics-file contains all events and not the one from the one article. So the download is for all articles.
How I can create, that both article have two different .ics-files, one .ics for a single article?

Sure, I wish to have a .ics-File with all events too, thats no problem! :-)
But maybe the .ics-file is different between two languages in the event, so that one .ics is with english-events and the other .ics with german-events.
I think, I must work with a 3rd category for say, in which language is the event. I using the category2 to choose the language.

Last edited by lythande (2017-11-08 20:15:58)

Offline

#34 2017-11-10 19:53:21

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

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

Much thanks Jakob! Now I can output in a .ics: single event, all event, and all events from each language!
Now works, thanks a lot! :-)

Offline

#35 2017-11-15 09:54:58

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

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

colak wrote #307686:

this would be an excellent howto for txptips …

I’ve written this up now as a txptip, and tried to generalise the situation a little:

» Outputting an .ics calendar file from a Textpattern article

Thanks to lythande for her help and for providing me with her setup to test it. We’ve not yet tried how it works with different calendar apps and OSes, so any feedback for improving the .ics output would be helpful. Finally, I hope the tutorial is useful :-)


TXP Builders – finely-crafted code, design and txp

Offline

#36 2017-11-15 14:37:14

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,392
Website

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

Thanks to jakob for the excellent tutorial, and hope it benefits some members of the community! Textpattern Tips is always open for new and exciting content, keep it coming :)

Offline

#37 2018-08-29 11:52:13

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

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

Hi! :-)

a lot of months was ago, since I have implemented the ICS-Calendars. This works good.

I try to make my workaround for new events better and ask me, is there possible to make the ics for more <txp:article_id />? The generates an .ics file for a single event and more single events works good. Now I wish to make it for more single events – without categories (because the categories from event was using for another site and can’t using for this site on the same website). So I can only work with article_id's.

I try it in form for 4 events, form name=“generate-ics-single-4”:

<txp:smd_wrap_all><txp:rah_gps name="event, event2, event3, event4" />
<txp:php>
  global $variable;
  if( !ctype_digit($variable['event']) ){
    $variable['event'] = '';
  }
  if( !ctype_digit($variable['event2']) ){
    $variable['event2'] = '';
  }
  if( !ctype_digit($variable['event3']) ){
    $variable['event3'] = '';
  }
  if( !ctype_digit($variable['event4']) ){
    $variable['event4'] = '';
  }
</txp:php>
<txp:if_variable name="event" value=""><txp:else />
<txp:if_variable name="event2" value=""><txp:else />
<txp:if_variable name="event3" value=""><txp:else />
<txp:if_variable name="event4" value=""><txp:else />
BEGIN:VCALENDAR...
<txp:article_custom id='<txp:variable name="event" />, <txp:variable name="event2" />, <txp:variable name="event3" />, <txp:variable name="event4" />' section="naechste-fuehrungen" form="ics-item" sortdir="asc" limit="4" expired="0" break="
" />
END:VCALENDAR
</txp:if_variable>
</txp:if_variable>
</txp:if_variable>
</txp:if_variable>
</txp:smd_wrap_all>

and in the article-body is this link:

<a class=“ics” href=”/?rah_external_output=generate-ics-single-4&event=83&event2=86&event3=91&event4=92”>Termine speichern</a>

How I can make this workaround better, shorter – then If I deleting e.g. &event4=92 so the .ics outputting empty, nothings. Mostly I have maximum 4 Events for one exhibition.
Some way for making this better or txp-like how <txp:article_custom id=" 83, 86, 91, 92"?
So that I can work with the same code for 2, 3 or 4 (or more) events with article_id, without to change the "/?rah_external_output=generate-ics-single-4&..." code for 1, 2, 3 or more events. Only to leave empty the follow events.
e.g.: for 3 events: <a href="/?rah_external_output=generate-ics-single-4&event=83&event2=86&event3=91">

Last edited by lythande (2018-08-29 11:55:09)

Offline

#38 2018-08-29 18:31:18

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

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

Hi lythande,

I replied to your email with a similar but more flexible approach to dealing with multiple events that should cater for one or more events using just one url parameter.


TXP Builders – finely-crafted code, design and txp

Offline

#39 2018-08-29 20:49:30

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

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

I guess jakob approach will suffice, but if there is a hierarchical dependency between the events (i.e. event3 should be ignored if event2 is not set), you can use the recursive forms parsing of txp 4.7.

Create a misc type form called events:

<txp:variable name="level"><txp:evaluate query='<txp:variable name="level" escape="integer" />+1' /></txp:variable>
<txp:variable name="label" value='event<txp:if_variable name="level" not value="1"><txp:variable name="level" /></txp:if_variable>' />

<txp:evaluate test="page_url">
    <txp:page_url type='<txp:variable name="label" />' /><txp::events escape="trim" wraptag=",<+>" />
</txp:evaluate>

Now, if you call <txp::events escape="trim" />, you will get 1,3,2 on ?event=1&event3=2&event2=3 page, but only 1 on ?event=1&event3=2 page.


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

Offline

#40 2018-08-29 21:27:37

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

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

Oleg, that’s also an interesting approach. My suggestion was to go back a step and just allow any number of events using an url variable ?event=12-34-56-78 with 12, 34, 56, 78 being the article ID#s:

<txp:smd_wrap_all>
    <txp:rah_gps name="event" />
    <txp:php>
        global $variable;
        // remove anything that's not a number or dash
        $tmp = preg_replace("/[^0-9-]/", "", $variable['event']);
        // change every "-" into a "," and remove any preceding or trailing commas
        $variable['event'] = trim(str_replace("-", ",", $tmp), ",");
    </txp:php>
    <txp:if_variable name="event" value=""><txp:else />
        <txp:article_custom id='<txp:variable name="event" />' section="naechste-fuehrungen" form="ics-item" />
    </txp:if_variable>
</txp:smd_wrap_all>

The limit attribute must also be removed (or made a high number if expecting more than 10 dates) from article_custom and the form ics-item has to use if_first_article and if_last_article for the ICS header and footer infos. There’s no inter-article dependency there, just one or more articles.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB