Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
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
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
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
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
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
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.
Offline
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
Re: Outputting a valid .ics file from an Event for download
jakob wrote #313704:
There’s no inter-article dependency there, just one or more articles.
Then why wouldn’t you directly use comma-separated event=12,34,56,78?
<txp:smd_wrap_all>
<txp:variable name="event" value='<txp:page_url type="event" />' />
<txp:if_variable name="event" value>
<txp:article_custom id='<txp:variable name="event" />' section="naechste-fuehrungen" form="ics-item" />
</txp:if_variable>
</txp:smd_wrap_all>
Note that <txp:page_url /> and <txp:article_custom /> sanitize their attributes enough for this case.
Edit: or even more 4.7-ish
<txp:page_url type="event" wraptag="<txp:article_custom id='<+>' section='naechste-fuehrungen' form='ics-item' />" />
Offline
Re: Outputting a valid .ics file from an Event for download
Lovely how you’ve reduced it successively to a one-liner. Always learn something new from you.
Then why wouldn’t you directly use comma-separated
event=12,34,56,78?
I agree, that was my first thought too. It would certainly be simplest but I read somewhere that commas are a reserved character in URL parameters and that, while they often work in practice, there can be encoding problems when they get retrieved as %2C. I haven’t tested that, though.
Note that
<txp:page_url />and<txp:article_custom />sanitize their attributes enough for this case.
That’s good to know too. While that might prevent illegal stuff in the parameters from getting to the tag, will that also eradicate anything that’s not a comma or a number? Could some wrong entry still cause article_custom to fail?
@lythande: Thinking about that, it would be advisable to add a conditional in ics-form that skips any article that is not an event article and does not have the date custom field. Otherwise, a manually-input URL could be used to output content from any article ID number in your installation.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Outputting a valid .ics file from an Event for download
Ah, perhaps, though event=12%2C34 in URL seems to work for me.
Offline
Re: Outputting a valid .ics file from an Event for download
jakob wrote #313710:
While that might prevent illegal stuff in the parameters from getting to the tag, will that also eradicate anything that’s not a comma or a number?
No, it just encodes '"<> characters to prevent attributes injections. But we could enhance the global escape attribute in such a way that, say, escape="list, integer, filter" removes all invalid values from comma-separated lists.
Could some wrong entry still cause article_custom to fail?
No, anything that’s not an integer is removed from id list.
Offline
Re: Outputting a valid .ics file from an Event for download
Hi,
much thanks for your discussions. Its for me too hard for following it. ^^
I have now try the code from Jacob what he posted first, but I am not sure, what exactly I should write in the body of my article.
At moment I have there written in this: <a class="ics" href="/?rah_external_output=generate-ics-event=83-86-91-92">Termine speichern</a> but on the webpage this link is a normal link and outputting an 404 error: http://mydomain.de/?rah_external_output=generate-ics-event=83-86-91-92 instead a linked .ics-file
In my form for event I written follow:
<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 />
(code for vcalendar is here)
<txp:article_custom id='<txp:variable name="event" />' section="naechste-fuehrungen" time="any" form="ics-item" sortdir="asc" limit="10000" expired="0" break="
" />
END:VCALENDAR
</txp:if_variable>
</txp:smd_wrap_all>
Maybe I have misinterpreted something? :-)
Last edited by lythande (2018-08-31 09:12:24)
Offline