Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-09-24 09:04:53

sgw
Member
Registered: 2012-12-18
Posts: 59

embed caldav data?

For my job and personal needs I run a nextcloud instance and calendars in it.
I track my job appointements and vacations etc … and I’d like to somehow display the “blocked” or “away” times in a page on my txp-website.

Any suggestions how to achieve that?

Or at least some kind of calendar “widget” showing “I am not available at Oct 1-6th, Oct 10th … etc “ … where I can maintain that list via editing some article.
And the URL of that page would go into my email sig or vacation responder.

Understandable? ;-) I’d appreciate any ideas.

Offline

#2 2019-09-24 16:23:09

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: embed caldav data?

Are the Nextcloud calendars shared as .ics iCalendar files, or something else?

Offline

#3 2019-09-24 16:35:50

sgw
Member
Registered: 2012-12-18
Posts: 59

Re: embed caldav data?

I can download an ics file, yes. And access the calendars via CalDAV links.

Offline

#4 2019-09-24 19:03:04

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: embed caldav data?

I’m not familiar with CalDAV, but I have a vague memory of PHP iCalendar being a thing some years ago. I think it parsed .ics files into HTML, but it was never very…pretty. If this was me, I’d have a deep dive on GitHub and GitLab, see what people are doing with iCalendar / CalDAV these days, a PHP library might do just that.

Another route, and your mileage may vary: investigate Google Calendar, subscribe that to your .ics URL, and then use an embed code to insert the Googly stuff.

Offline

#5 2019-09-24 20:55:26

planeth
Plugin Author
From: Nantes, France
Registered: 2009-03-19
Posts: 215
Website

Re: embed caldav data?

The PHP library to handle CalDav / iCal is Sabre.

Offline

#6 2019-09-25 06:33:17

sgw
Member
Registered: 2012-12-18
Posts: 59

Re: embed caldav data?

sounds more complicated than needed ;-) I’ll do some more research maybe, on the other hand it might be less work to simply maintain an article listing my available times. thanks.

Offline

#7 2019-09-25 12:52:44

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: embed caldav data?

This is interesting and could perhaps be solved by a plugin or two, but I’d like to sit and figure out exactly how people might use third-party calendar tools to manage bookings or schedules.

See, with com_connect being able to act as an intermediary between APIs, we’re no longer confined to simply emailing stuff. A contact form could be transformed into a booking form, for instance, in a similar way it can be used for subscribing to mailing lists. That would require two elements:

  1. A way to ‘read’ or import (live or on a schedule or soft-cached?) current calendar information so that the booking form could block out the unavailable dates/times.
  2. A way to validate and write back the requested dates in response to a com_connect message being posted by someone on the website (the validation side of things is tricky to prevent bots or those with malicious intent posting bookings, so perhaps some form of confirmation via email might be prudent before the booking is made live).

The first part of that plugin sounds like something you could utilise here for your application to read the external calendar info and do something with it on a Textpattern page – populate an article, populate many articles so they can be used with smd_calendar, display the dates as a list via a container tag, blah blah.

To do this effectively, we need to query the third-party API (presumably there are many of these and they all speak a different language) and request a timeframe over which to retrieve the calendar info, and the sort of detail we expect in return. After all, we may not want client names and appointments being returned, only the fact that the slot is “unavailable” but if you’re logged into some front-end system, we may wish to permit more detail to be retrieved so someone could manage their own bookings.

Either way, we’d need to enable the possibility to iterate over this information and do something with it via <txp: /> tags – insert into DB, show on page, whatever.

If such information is available as XML or some other standardised format, this could probably be done already with etc_query. No need to reinvent that wheel.

The other half – posting booking information back – is outside the scope of this thread, but may be worth considering if this is a useful feature for Textpattern to gain. That said, many services such as book-a-table will probably offer a JavaScript widget that enables bookings to be made directly with their system, so this may not even be viable or worthwhile to merely cover those services that do not already offer such a feature.

Just thinking out loud really and wondering if it’s worth collecting together some use cases and trying to boil down if stuff like this can be done easily with a bunch of knitted-together plugins or if there’s a gap we could fill with something new, or if we just ignore it and point people elsewhere at existing third-party solutions in future.

Last edited by Bloke (2019-09-25 12:56:39)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#8 2019-09-25 18:41:10

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

Re: embed caldav data?

You can use the plugin mka_ical (this is an updated version that should work with txp 4.7.x) to output data from an ics file. You can control the output, so you could simply not output the {description} of the date “event” and mark that as “unavailable”.

If you need to test for certain output, you can use txp:evaluate with the output placeholder. Two cases I found useful were:

Check if a multi-day event longer than exactly one day:

<txp:evaluate query="('{end_date}' != '{start_date}') and ('{duration}' != '1:00:00:00')">... your output ...</txp:evaluate>

Check if an event has a specific start time (i.e. not a whole day):

<txp:evaluate query="'{start_time}' != '00:00'">... your output ...</txp:evaluate>

Full details on the plugin parameters are in the help and the plugin can cache the requested ical file to avoid having to request it anew every time the page is requested.


TXP Builders – finely-crafted code, design and txp

Offline

#9 2019-09-26 10:01:53

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: embed caldav data?

Not seen mka_ical before. Like it, thanks for the tip. And using <txp:evaluate> to test for what’s returned is neat too. I’ll step away from this as it seems to be covered already.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB