We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39184
    • 24 Posts
    @desgincouch - I'm using mxcalendar and was curious if you have every formatted the output to iCal? I'd be interested in any insight you may have as I begin this endeavor. I'm looking to create a nice feed that visitors can add to their calendar but also to share the feeds between related sites.

    Thanks
      • 37984
      • 215 Posts
      Quote from: breynolds13 at Mar 11, 2013, 03:41 PM
      @desgincouch - I'm using mxcalendar and was curious if you have every formatted the output to iCal? I'd be interested in any insight you may have as I begin this endeavor. I'm looking to create a nice feed that visitors can add to their calendar but also to share the feeds between related sites.

      Thanks

      BReynolds,

      I have actually done this with a client site recently. It's still in the last stages of development or I'd share the link, but the basic process is as simple as creating an XML feed using the mxCalendar list view as a starting point. iCal is notoriously finicky for getting the details of your items right, so here is the basic code that I'm using.

      The wrapper—goes in the content area of your main Resource. This resource should NOT use Rich Text as the tags will screw with the XML, and you should create a custom content type of "iCal" and assign it to this resource (instead of the default HTML). Also be sure your timezone settings in the XML header are set correctly (you may have to change the code below to do this).

      Wrapper Code & mxCalendar call:
      BEGIN:VCALENDAR
      PRODID:-//YourWebsite//SiteCalendar//EN
      VERSION:2.0
      METHOD:PUBLISH
      BEGIN:VTIMEZONE
      TZID:America/New_York
      X-LIC-LOCATION:America/New_York
      BEGIN:DAYLIGHT
      TZOFFSETFROM:+0000
      TZOFFSETTO:+0100
      TZNAME:IST
      DTSTART:19700329T010000
      RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
      END:DAYLIGHT
      BEGIN:STANDARD
      TZOFFSETFROM:+0100
      TZOFFSETTO:+0000
      TZNAME:GMT
      DTSTART:19701025T020000
      RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
      END:STANDARD
      END:VTIMEZONE
      [[!mxCalendar? &addJQ=`0` &displayType=`list` &eventListlimit=`1000` &elEndDate=`+1 year` &tplListItem=`tplListItemICAL` &tplListHeading=`tplListHeadingICAL` &tplListWrap=`tplListWrapICAL` &tplDetail=`tplDetailICAL` &debug=`0` &sort=`startdate` &dir=`ASC`]]
      END:VCALENDAR


      It is important to note the custom TPLs listed in the mxCalendar call. This call is tailored to my needs, and includes a tplDetailICAL chunk that is used when the user wants to add a specific event to their calendar instead of the whole feed. This chunk is exactly the same as the tplListItemICAL chunk (see below). This call also references a BLANK chunk (tplListHeadingICAL). You create it and leave it completely blank. This keeps the XML formatting all in one place (the main Resource) so that you can view it all together and make changes easier. The tplListWrapICAL chunk contains only the mxCalendar event list placeholder ( [[+eventList]] ).

      tplListItemICAL & tplDetailICAL chunks:
      BEGIN:VEVENT
      UID:[[+id]][[+startdate]]@example.com
      DTSTAMP:[[!ical_datestamp]]T[[!ical_timestamp]]
      DESCRIPTION:[[+description:replace=`<br />==\n`:replace=`http://http://==http://`]]
      DTSTART:[[+startdate:date=`%Y%m%dT%H%M%S`]]
      DTEND:[[+enddate:date=`%Y%m%dT%H%M%S`]]
      LOCATION:[[+location_name]]
      SUMMARY:[[+title]]
      END:VEVENT
      


      A few important things about the code above. First, it uses some output modifiers to edit the content flowing into it. In the Description, it strips out any
      and replaces them with a newline XML character ( /n ). It also eliminates an error with double http:// prefixes that I was noticing. Also, this chunk references two tiny custom snippets ( ical_datestamp & ical_timestamp ) that are necessary to make sure that the date and time stamps are correct when a user downloads the feed/event for the first time. These snippets are below.

      ical_datestamp snippet:
      <?php
      echo date("Ymd");
      


      ical_timestamp snippet:
      <?php
      echo date("His");
      


      This is a massive amount of info, and may be more than you were looking for, but I figure it will help others who are trying to do the same thing! Good luck, and let me know if I can help further.
        Jesse Couch
        MODX Aficionado, Front-End Designer & Developer
        http://www.designcouch.com
        • 37984
        • 215 Posts
        If anyone needs it, there's a slightly more in depth version of the above that I decided to post on my site. http://www.designcouch.com/home/why/2013/03/11/creating-an-ical-feed-in-modx-with-mxcalendar/
          Jesse Couch
          MODX Aficionado, Front-End Designer & Developer
          http://www.designcouch.com