Hi,

Can someone from the calendar team give his/her blessing. I have written a procedure on how to expose an ical for a single node/event.

Calendar has excellent support for exposing ical *feeds* and I want to leverage that for a single node. I though this would be trivial but it took me a while so I wrote up a procedure that others can use. If this is not the way to do it please let me know (or if there is an easier way..)

The procedure is as follows :

- Clone the calendar view

Why? We want to leave the original view alone and since we cannot add an ical feed through the views UI we need to clone the view (this is expecteded behaviour for this module)
Leave all the display of the cloned view intact.

- Adjust the path of the (cloned) ical display so that it is unique (the original view will otherwise takeover)

- Add an argument the the ical display so that the node is filter on the nodeid (nid)

- Override the template that is used for creating the ical :

Copy
"calendar\calendar_ical\calendar-view-ical.tpl.php"
to
sites\default\themes\YOURTHEME\CustomMade\calendar-view-ical--NAMEOFYOURVIEW.tpl.php (this can be looked up in the theme information with views)

Now remove the line with "X-WR-CALNAME" otherwise Outlook and other email clients will consider it a feed and not a single event.

- You can now link to this ical feed as follows
/calendar-date/downloadical/105 (/calendar-date/downloadical/ is the path I have chose, 105 is a nodid)

- Not related to the procedure but if you want to set the location,title etc of the ical you can you modify the style of the ical view display (click the rotor)

Comments

Rob_Feature’s picture

This totally rocks (and was just what I needed). Thanks for sharing!

leenwebb’s picture

Thanks so much, buckley! This is just what I was looking for.

akalata’s picture

Thank you!

sdsheridan’s picture

For whatever reason, this isn't working for me. I'm using 6.x-2.2 of calendar. When I test in the Views UI and outside, I get an empty iCal feed (no events, just the shell). Yet when I run the query itself against the database (the one the Views UI reports using), I get the result set I would expect. Anyone else experienced this?

Thanks in advance, Shawn

sdsheridan’s picture

OK, I think I figured it out... the other 'missing ingredient' (at least for me) in this was that there has to be a filter on a date with a comparison value (not just saying the date is 'not null'), such as "event date is greater than 2007-01-01 (which in the case of the site I'm working on will always be the case). Then all of a sudden the contents appeared in the per-node iCal feed.

Shawn

koppie’s picture

Thanks Shawn - I needed that extra step too. Also, I couldn't figure out how to get it to work with sites\default\themes\YOURTHEME\CustomMade\calendar-view-ical--NAMEOFYOURVIEW.tpl.php so I just edited the actual module. I know, not recommended because of upgrade problems, but it was the only way I could get it to work.

New question: how do you embed the link in the event?

sdsheridan’s picture

Check out the Dynamic Field CCK module. Install that module (obviously you also need CCK), add a dynamic field to an event content type positioned where you want the iCal icon to appear, and then in the PHP code text area of the field's configuration, use the following (without the opening and closing php tags):

return '';

I used text-align: right because I wanted the icon floated over to the right-hand side of the event.

Shawn

akalata’s picture

You could also use a custom node.tpl.php, but the Dynamic CCK looks like a good option if you don't need to go that far. All you need for the link is <a href="/path/to/view/<?php print $node->nid ;?>">link text</a>, the rest is just gravy.

Edit: The above will work in node.tpl.php; if you want to do something that's already inside php tags, it would be print 'nid . '">link text';

moondancerjen’s picture

I've used this method to add an ical link on individual events on my site, but the ical isn't working on some platforms. In testing this, I put my link in the iCal Validator http://icalvalid.cloudapp.net/Default.aspx and got the following response: We scored 99 out of 100 with this message: "This calendar has minor problems, but will likely work correctly in most major calendar applications." The warning says "Line endings must be a Carriage Return/Line Feed (CRLF) pair."

Has anyone else had this problem? Any idea how to fix it?

hwasem’s picture

I'm having a lot of trouble getting the iCal to show on a node. In my case, it is a custom content type.

I like the idea that Shawn and akalata discuss in #7 and #8. I have a custom node.tpl.php, so I can do either suggestion. If I use these suggestions, do I need to also do everything suggested in the original post (copy the calendar view, etc.)? If so, I'm not sure what this step means, "Add an argument the the ical display so that the node is filter on the nodeid (nid)"

I have all of the modules installed according to http://drupal.org/node/341716, but I don't want the calendar to have iCal. Just the actual event nodes displayed in the calendar.

I could really use some guidance :)

sdsheridan’s picture

In the particular view, when editing it, add an argument (middle column, below 'relationships'). Pick nid (Node, node ID) as your argument. That's it. Save the view.

Shawn

hwasem’s picture

Thank you! I followed your initial steps so far.

* I cloned an existing month calendar view I had working (now called calendar_ical)
* I changed the path (/ical)
* I added the argument from the Node group of Node:NID
* I put a copy of the ical template file in my theme named: calendar-view-ical-calendar_ical.tpl.php and removed the "X-WR-CALNAME" line

I'm not sure that part is working right. When I display the /ical page, it is still a full month view of the calendar. Should it be displaying nodes? How do I know the ical piece is working?

hwasem’s picture

More information. As I've been reading throughout the day, I keep seeing that others have posted pictures on this topic with a calendar tab that says "iCal Feed", including images in the Calendar instruction manual at http://drupal.org/node/797042. I'm completely missing this tab. In my dev environment, I revert to the original calendar and it showed up. Sigh. At least that explains why I was so lost. Thanks for the help so far. I'm off to figure out if I can add that tab back in or if I need to start over :)

sdsheridan’s picture

Just displaying /ical won't give you what you want. Sounds like you need a bit of a better understanding of views, and in particular, view arguments. Once you added NID as an argument, that means you have to supply it to the view via the URL. So, in other words, find a node ID that belongs to an event (say for argument sake it's 5), and then display /ical/5. What you should then get if you've done it right is a dialogue box asking what you'd like to do with the thing you're downloading, which should be the iCal event. Please re-read 7 and 8 above.

Shawn

hwasem’s picture

Thanks for your response, sdsheridan. I have the iCal working on my node now that I reverted my calendar back. I wish I could figure out a way to restore the "iCal Feed" tab on my calendar view without reverting it. At some point, the last web guy here deleted that tab. Once I reverted and saw it, I was able to use the steps mentioned in #7 and 8. Off topic, I know, but any ideas on how to get the "iCal Feed" tab back after it was deleted without reverting?

KarenS’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

I'm going to move this to D7 to work on it there, then we'll backport to D6.

I started by altering the templates to make X-WR-CALNAME optional in the feed. I also added a way to alter the method from PUBLISH to REQUEST (which should make it possible to send it as a calendar invite).

Now I need to decide on the best way to make this an option in the code. This may actually be something that should be done in the Date module. I have to think about that.

benjifisher’s picture

Category: support » bug
Priority: Normal » Major

Apologies if I am the one confused here, but this looks to me like a big goof.

According to this Commit record (Calendar module) and this one (Date module), patches have been committed to fix this problem. I am surprised that there is no reference on this page to the commit, nor any attached patch. But the commit pages link here. (These are commits for the 6.x branch.)

Here is part of the patch that has already been committed. (There are very similar patches in both the Date and Calendar projects.)

 BEGIN:VCALENDAR
 VERSION:2.0
 METHOD:<?php print $method; ?>
+<?php if !empty($calname): ?>
 X-WR-CALNAME;VALUE=TEXT:<?php print $calname . "\r\n"; ?>
+<?php endif; ?>
 PRODID:-//Drupal iCal API//EN

This gives an "Internal Server Error" because we need parentheses after the if.

I also have problems with the METHOD line because there is no "\r\n". I may have messed up my EOL characters, or maybe there is a problem with the file I got from git. I would volunteer a patch, but I am afraid I would mess this up further.

The files involved are calendar/calendar_ical/calendar-view-ical.tpl.php and date/theme/date-vcalendar.tpl.php . I have been testing the first, and I am not sure how to test the second.

The corresponding commits for the 7.x branches are d9948a6 (Calendar) and 4704b7a (Date).

benjifisher’s picture

After more time reviewing the recent commits, I see that the serious part of this problem has already been corrected in the D7 branch by f9c1b73. (That commit applies to the D7 branch of Calendar. I am not sure about Date.)

I think the problem is still there in the D6 branch.

The second problem (missing "\r\n") is one of the minor problems fixed by the patch I just added in #1284170: All-day events missing or wrong in ical feed.

jnettik’s picture

I'm trying to set up this in a Drupal 6 site and the problem I'm getting is when I pass in my argument, the tpl file's $events array is empty. Basically this is what I get:

BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH
PRODID:-//Drupal iCal API//EN
END:VCALENDAR

Any ideas what I'm doing wrong?

benjifisher’s picture

@moondancerjen: The problem you describe in #9 is because the ical spec requires CRLF (DOS-style) line endings and you must have some LF (UNIX-style) endings. First, check that the template files calendar_ical/*.tpl.php have CRLF line endings. Second, look for lines with
<?php print $foo; ?>
at the end, and edit them to look like
<?php print $foo . "\r\n"; ?>

If you are getting this problem after applying a patch, see #1302052: CRLF line endings cause problems with "git apply".

dmgenesys’s picture

Thanks for this procedure - works like a charm... Two notes though... For #7 I've modified it so that it displays a link for importing ics file only if the event is in the future (w/o php opening and closing tags):

$now = time();
$event = strtotime($node->field_event_date[0]['value']);
if ($event > $now)
{
return '';
}

The link is a bit modified for our situation (this is from group calendar integration). So it should be adjusted per your requirements...

And now if anybody made it possible on event node creation/update to send notification with ics file attached?

pbfleetwood’s picture

Has anyone tried this in Drupal 7? Dynamic Field is not available in that version; is there an alternative way of plugging PHP code into a content type?

pbfleetwood’s picture

I tried to use the procedure that @buckley offered when starting this thread, but there is no calendar-view-ical.tpl.php file in Calendar version 7.x-3.x-dev.

I also tried creating a block with a link in it, using the code that @sdsheridan offers in #7, but it doesn't look like embedded PHP gets executed if placed in the text field of a block. The link showed up, but the code that should provide the node id did not get processed, so the link was invalid. I don't know how else to embed PHP on a page. I'm kind of a newb. And I'm kind of stuck now. :/

pbfleetwood’s picture

Project: Date iCal » Calendar
Version: 7.x-1.x-dev » 7.x-3.x-dev
Component: Code » iCal export
Category: feature » bug
Priority: Normal » Major
Status: Needs review » Active

I was able to get this working, and I'll explain what I did, in case it will benefit someone else.

I did some searching and found out that the core module PHP filter had to be enabled. That's why I was unable to test any code placed within a page. But since what I really needed was a way of placing a block with the necessary code on every event page, I did some more research.

I created a block with the code that follows, then I enabled it for my events' content type. I had to experiment a bit, because a block does not know anything about any of the nodes that might be displayed. This code gets the node ID from the url, regardless of whether there has been any aliasing.

<?php
$nid = 0;
if (arg(0) == 'node' && is_numeric(arg(1))) {
    $nid = arg(1);
return '<div class="ical-event-icon"><div style="text-align:right"><a href="/calendar/ical/' . $nid . '/event.ics" class="ical-icon" title="ical"><img src="/sites/all/modules/date/date_api/images/ical16x16.gif" alt="Add to calendar" title="Add to calendar" height=16 width=16></a></div></div>';
}
?>

I placed the block in the Featured Content region, because I needed it at the top of the content area, then did some positioning in CSS to get it to fall into exactly the same place as the link falls on the calendar and upcoming events pages. Woohoo! I've also done some work in CSS to replace the icon with a more visible button, which is related to a different feature request: Changing appearance of ical icon & link.

I'd still love to see this as a feature of the Calendar module, but beggars can't be choosers. ;) I hope this helps others, and would like to thank everyone who contributed useful information to this thread.

I think that this should still be classified as a feature request, as the person who changed it to a major bug report in #17 was referring to something that was not directly related to the original subject of this thread.

bzsim’s picture

This worked great for me! Thanks so much! Should have came with the module though.

bzsim’s picture

I have a calendar event that runs multiple dates. This setup only adds the first date into Outlook. How do you get it to add all of the dates?

KarenS’s picture

Category: bug » feature
Priority: Major » Normal

This is still a feature request, and not major. The previous commits were just to provide some functionality that would be needed for this to work.

pbfleetwood’s picture

I could not duplicate the problem that @bzsim mentions in #26; rather, I found that the Outlook event correctly comes over as a single event spanning the days specified in the event node.

I am, however, experiencing an odd effect, in that repeating events are duplicated. For instance, if one creates an event that occurs on three dates, the iCal file will create an entry with the correct occurrence rule, but it will be duplicated two more times. So instead of having three events, there will be nine -- three identical events on each of the event dates.

EDIT: I find that this is true not only with the custom, single-event iCal format, but with the iCal format that is part of the Calendar module's distribution. I did not see where this had been addressed by any other issue, so I've added Repeating events cause duplicates in iCal feeds.

KarenS’s picture

Project: Calendar » Date iCal
Version: 7.x-3.x-dev »
Component: iCal export » Code

I decided to set Date iCal up as a new project. It can be expanded to include a Feeds parser for importing ical items and add some features to make it easier to import/export ical feeds. Plus it could have another maintainer that is someone interested in doing more work on the iCal standard. I will be deprecating the Calendar iCal module in favor of that one.

Moving this to the new project.

bskohli1’s picture

Version: 7.x-1.x-dev » 7.x-1.0
Category: feature » bug
Status: Needs review » Fixed
FileSize
412 bytes

Patch to implement the calendar functionality in such a way that the events are added to the existing calendar and no new calendar is created.

BrightBold’s picture

Version: » 7.x-1.x-dev
Status: Active » Needs review

@bskohli1 - The "fixed" status is used when a submitted patch has been tested and committed and no one needs to do anything else on the issue. So I think you're looking for "needs review" so that people will test out your patch and report back on how it works for them. I for one will check it out soon.

bskohli1’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Category: bug » feature
Status: Fixed » Needs review

@BrightBold - My bad. I knew it but forgot to select "needs review". I am using it on my websites and it works like charm.

BrightBold’s picture

@bskohli — Yes it worked for me too. I got the impression from @KarenS's comment in #16 that this shouldn't be necessary, but even though the code shows that she made X-WR-CALNAME optional, I couldn't figure out how to get it not to show up, so I removed those lines as you did and that works.

I'd like to figure out how to have both a feed of multiple calendar items (using X-WR-CALNAME) and to have single-node imports without that, but in the meantime I have opted for the single-node version only, since that seems more useful.

Draknek’s picture

Reposting above patch in format that drush make accepts.

nmc’s picture

FileSize
76.55 KB

I've gotten lost in this thread... It seems (as mentioned in #24) that the comments may have gotten away from the original post. Given that the iCal functionality has been changed and extracted into its own module, I believe the originally posted instructions are no longer applicable/accurate.

Here are a new set of instructions that worked for me for creating an iCal Feed for single nodes:

  1. Create a Block View for the content type(s) that you want to create the iCal Feed.  Keep in mind that this block needs to be put on your node page, so make sure that your block contains items that you would like to display on the node page.
  2. Views will force you to display at least one field. If you want an empty block with just the iCal feed, you can use the Global: Custom Text as your Field. Hide the label and leave the text box empty.
  3. Add a Contextual Filter of Content: Nid to your Block view.
  4. Set up the Contextual Filter so that it gets the default value of Content ID from URL. This way, your iCal Feed will only show information for the node that is loaded on the page.
  5. Add a Feed to your View and configure it to display iCal Feeds.
  6. Don't forget to add the fields that you want included in your iCal feed...
  7. ... and add a Path to the Feed view. Make sure it ends in .ics. You will also need to attach the feed view to the Block that you created earlier. EDIT: (As noted by @derekw below) you Feed path should be something like event/%/ical.ics so that Views can insert the NID in place of %
  8. Once you save the view, you can place your empty block with the attached iCal feed on every node page.

Your resulting view and node page might look something like this:

Node view with iCal Feed Block

I created a fully illustrated step-by-step on my blog: http://nmc-codes.blogspot.ca/2012/11/creating-ical-feed-for-single-node-...

Please let me know if you see any issues with these instructions.

BrightBold’s picture

People should also be aware of the Add to Cal module as an alternative to this method. It may still need a little work to get it working equally well with all date formats, but it's easy to implement so some people might prefer it.

derekw’s picture

Project: Calendar » Date iCal
Version: 7.x-3.x-dev » 7.x-1.x-dev
Component: iCal export » Code
Category: bug » feature
Priority: Major » Normal
Status: Active » Needs review

@nmc - followed your instructions but my ics files did not contain the events.

Based on your example, make the feed path /event/%/test-ical.ics, and then add a contextual filter on the feed that Provides the default value from the Raw value from the path, 2nd element (%).

Now it works!

nmc’s picture

@derekw - you're absolutely right! I missed that step. Without it, my view/feed still worked except the URL ended up being something like /test-ical.ics/% where % was the nid that was provided in the contextual filter. Your method is much cleaner. I'll update the instructions. Thanks!

coredumperror’s picture

Status: Needs review » Reviewed & tested by the community

If it's OK with you, nmc, I'd like to link to your blog post from the project documentation. This is a very useful technique.

coredumperror’s picture

Status: Reviewed & tested by the community » Closed (works as designed)

The functionality at the core of this feature request is available from the Add to Cal module. I may or may not attempt to implement something similar for Date iCal, so I'm going to close this ticket.

However, I will #1890736: Make the X-WR-CALNAME property optional.

nmc’s picture

@coredumpererror: Yes, please use my blog post if it's helpful. And thanks!