1 |
85ad3d82
|
Assos Assos
|
Date iCal
|
2 |
|
|
|
3 |
8a7e43dd
|
Florent Torregrosa
|
This module allows users to export iCal feeds using Views, and import iCal feeds
|
4 |
|
|
from other sites using Feeds. Any entity that contains a Date field can act as
|
5 |
55670b15
|
Assos Assos
|
the source/target to export/import an iCal feed.
|
6 |
|
|
|
7 |
85ad3d82
|
Assos Assos
|
|
8 |
8a7e43dd
|
Florent Torregrosa
|
===============================================================================
|
9 |
85ad3d82
|
Assos Assos
|
INSTALLATION
|
10 |
8a7e43dd
|
Florent Torregrosa
|
===============================================================================
|
11 |
|
|
Date iCal has several required dependencies, and an optional one:
|
12 |
|
|
- The Views (version 3.5+), Entity API, Libraries API (version 2.0+), and Date
|
13 |
|
|
modules are required.
|
14 |
7e072189
|
Assos Assos
|
- The iCalcreator library v2.20.2 is required.
|
15 |
8a7e43dd
|
Florent Torregrosa
|
- PHP 5.3 is required for the iCalcreator library to properly handle timezones.
|
16 |
|
|
- The Feeds module is optional. It's needed only if you you wish to import iCal
|
17 |
|
|
feeds from other sites.
|
18 |
|
|
|
19 |
7e072189
|
Assos Assos
|
To install the iCalcreator library, download the project's v2.20.2 zip file:
|
20 |
|
|
https://github.com/iCalcreator/iCalcreator/archive/e3dbec2cb3bb91a8bde989e467567ae8831a4026.zip
|
21 |
|
|
Extract it, and copy iCalcreator.class.php to a folder in your Drupal site
|
22 |
|
|
named sites/all/libraries/iCalcreator (you'll need to create that folder).
|
23 |
8a7e43dd
|
Florent Torregrosa
|
|
24 |
55670b15
|
Assos Assos
|
Or, if you have drush, you can install iCalcreator by running this command from
|
25 |
|
|
your site's root directory:
|
26 |
85ad3d82
|
Assos Assos
|
drush make sites/all/modules/date_ical/date_ical.make --no-core
|
27 |
|
|
|
28 |
8a7e43dd
|
Florent Torregrosa
|
Then, clear the cache on your site by using either "drush cc all" or logging in
|
29 |
|
|
to your site and going to Configuration -> Development -> Performance and click
|
30 |
|
|
the "Clear all caches" button. This is necessary because libraries are cached,
|
31 |
|
|
and you may see confusing behavior from Date iCal if the iCalcreator library
|
32 |
|
|
gets cached at a bad time.
|
33 |
85ad3d82
|
Assos Assos
|
|
34 |
|
|
To confirm that iCalcreator is installed correctly, log in to your Drupal site
|
35 |
|
|
and navigate to the admin/reports/status page. If the row titled "Date iCal" is
|
36 |
|
|
green, Date iCal is ready to go. If it's red, the iCalcreator library is not
|
37 |
8a7e43dd
|
Florent Torregrosa
|
properly installed. If it's missing, you'll need to enable Date iCal.
|
38 |
|
|
|
39 |
85ad3d82
|
Assos Assos
|
|
40 |
8a7e43dd
|
Florent Torregrosa
|
===============================================================================
|
41 |
|
|
EXPORTING AN ICAL FEED USING Views
|
42 |
|
|
===============================================================================
|
43 |
|
|
There are two plugins that export iCal feeds. You can use either one, though
|
44 |
|
|
the iCal Fields plugin (described later) is a bit more versatile.
|
45 |
85ad3d82
|
Assos Assos
|
|
46 |
8a7e43dd
|
Florent Torregrosa
|
HOW TO EXPORT AN ICAL FEED USING THE iCal Entities PLUGIN
|
47 |
85ad3d82
|
Assos Assos
|
|
48 |
8a7e43dd
|
Florent Torregrosa
|
1. Go to the Manage Display page for the content type you want to export in an
|
49 |
|
|
iCal feed. On the "Default" tab, check the box for "iCal" in the section
|
50 |
|
|
titled "Use custom display settings for the following view modes", then
|
51 |
|
|
click Save.
|
52 |
85ad3d82
|
Assos Assos
|
2. Click the new "iCal" tab that now appears in the upper-right corner of the
|
53 |
|
|
Manage Display page for this content type.
|
54 |
|
|
3. Set up the iCal view mode to contain whatever should be exported as the
|
55 |
|
|
'Description' field for the iCal feed. You can trim the text to the desired
|
56 |
|
|
size, include additional information from other fields, etc.
|
57 |
8a7e43dd
|
Florent Torregrosa
|
4. Do this for each of the content types that you wish to include in your
|
58 |
85ad3d82
|
Assos Assos
|
site's iCal feeds.
|
59 |
55670b15
|
Assos Assos
|
5. Create a new View that displays the entities that you want to include in
|
60 |
|
|
the iCal feed.
|
61 |
|
|
6. Add a "Feed" display to the same View. Change the Format to "iCal Feed".
|
62 |
|
|
When you click "Apply" from that dialog, you'll be given the option to name
|
63 |
|
|
the calendar, which will appear in your users' calendar clients as the
|
64 |
|
|
calendar's title.
|
65 |
8a7e43dd
|
Florent Torregrosa
|
7. Change the Show setting to "iCal Entity".
|
66 |
|
|
8. In the settings for iCal Entity, select the date field that should be used
|
67 |
85ad3d82
|
Assos Assos
|
as the event date for the iCal feed. Make sure that you choose a field that
|
68 |
|
|
is a part of every entity that your View displays. Otherwise, the entities
|
69 |
|
|
which don't have that field will be left out of the iCal feed.
|
70 |
204e4d33
|
Assos Assos
|
9. You may optionally choose a field that will be used to populate the
|
71 |
55670b15
|
Assos Assos
|
Location property of events in your iCal feed. This field can be a text
|
72 |
|
|
field, a Node Reference field, an Addressfield, or a Location field.
|
73 |
|
|
10. Give the Feed a path like 'calendar/%/export.ics', including a '/%/' for
|
74 |
8a7e43dd
|
Florent Torregrosa
|
every contextual filter in the view.
|
75 |
85ad3d82
|
Assos Assos
|
11. Make sure the Pager options are set to "Display all items".
|
76 |
|
|
12. Add date filters or arguments that will constrain the view to the items you
|
77 |
|
|
want to be included in the iCal feed.
|
78 |
55670b15
|
Assos Assos
|
13. Using the "Attach to:" setting in the Feed Settings panel, attach the feed
|
79 |
|
|
to a another display in the same view (usually a Page display). Be aware,
|
80 |
|
|
though, that the Feed will display exactly what its settings tell it to,
|
81 |
|
|
regardless of how the Page display is set up. Thus, it's best to ensure
|
82 |
|
|
that both displays are configured to include the same content.
|
83 |
85ad3d82
|
Assos Assos
|
14. Save the View.
|
84 |
55670b15
|
Assos Assos
|
15. Navigate to a page which displays the view (usually the Page display's
|
85 |
|
|
"path" setting). You should see the iCal icon at the bottom of the view's
|
86 |
|
|
output. Clicking on the icon will subscribe your calendar app to the iCal
|
87 |
|
|
feed.
|
88 |
|
|
16. If you don't have a calendar app set up on your computer, or you want your
|
89 |
|
|
users to download the ical feed rather than subscribe to it, you'll want to
|
90 |
|
|
go back to the View settings page, click the Settings link next to
|
91 |
|
|
"Format: iCal Feed", and check "Disable webcal://". Then save your View.
|
92 |
|
|
This will make the iCal icon download a .ics file with the events, instead
|
93 |
|
|
of loading the events directly into the user's calendar app.
|
94 |
c7b88c87
|
Assos Assos
|
17. If events that you expect your feed to include are not appearing when it
|
95 |
|
|
gets consumed by a calendar app, check the Drupal permissions for your
|
96 |
|
|
event content type. If anonymous users can't view the event nodes, they
|
97 |
|
|
won't appear in your feed when it gets loaded by a calendar app.
|
98 |
85ad3d82
|
Assos Assos
|
|
99 |
8a7e43dd
|
Florent Torregrosa
|
HOW TO EXPORT AN ICAL FEED USING THE iCal Fields PLUGIN
|
100 |
85ad3d82
|
Assos Assos
|
1-6.These steps are the same as above.
|
101 |
8a7e43dd
|
Florent Torregrosa
|
7. Add views fields for each piece of information that you want to populate
|
102 |
|
|
your iCal feed with. A Date field is required, and fields that will act as
|
103 |
7e072189
|
Assos Assos
|
the Title and Description of the events are recommended. You can also
|
104 |
8a7e43dd
|
Florent Torregrosa
|
include a Location field.
|
105 |
55670b15
|
Assos Assos
|
8. Back in the FORMAT section, change the "Show" setting to 'iCal Fields'.
|
106 |
85ad3d82
|
Assos Assos
|
9. In the settings for iCal Fields, choose which views fields you want to use
|
107 |
|
|
for the Date, Title, Description, and Location.
|
108 |
8a7e43dd
|
Florent Torregrosa
|
10+ These steps are the same as above.
|
109 |
85ad3d82
|
Assos Assos
|
|
110 |
|
|
|
111 |
8a7e43dd
|
Florent Torregrosa
|
===============================================================================
|
112 |
|
|
IMPORTING AN ICAL FEED FROM ANOTHER SITE USING Feeds
|
113 |
|
|
===============================================================================
|
114 |
|
|
- Install the Feeds module, which is the framework upon which Date iCal's
|
115 |
|
|
import functionality is built.
|
116 |
85ad3d82
|
Assos Assos
|
- Login to your Drupal site and navigate to the admin/structure/feeds page.
|
117 |
|
|
- Click the "Add importer" link, and give it a name and description.
|
118 |
|
|
- Clicking "Create" will bring you to the general Feeds importer settings page.
|
119 |
8a7e43dd
|
Florent Torregrosa
|
This page displays some general information about making Feeds importers,
|
120 |
85ad3d82
|
Assos Assos
|
which you should familiarize yourself with.
|
121 |
|
|
- In the left sidebar, you'll see "Basic settings", "Fetcher", "Parser", and
|
122 |
|
|
"Processor". The Parser and Processor settings are what we're interested in.
|
123 |
8a7e43dd
|
Florent Torregrosa
|
- In the Parser section, click "change". This will bring up the Parser
|
124 |
85ad3d82
|
Assos Assos
|
selection page, on which you should select the radio button for "iCal Parser"
|
125 |
|
|
and then click Save.
|
126 |
8a7e43dd
|
Florent Torregrosa
|
- Now, under Processor, click the "Settings" link. Most of the time, you'll
|
127 |
85ad3d82
|
Assos Assos
|
want to use the "Update existing nodes (slower than replacing them)" setting.
|
128 |
|
|
Then select the Content type of the nodes you'd like to create from iCal
|
129 |
7e072189
|
Assos Assos
|
events. You can leave the other settings as their defaults, or change them
|
130 |
85ad3d82
|
Assos Assos
|
as you need. Click Save.
|
131 |
|
|
- Now click the "Mapping" link at the bottom of the left sidebar. This page is
|
132 |
|
|
where you'll define how iCal event properties get mapped into your nodes'
|
133 |
|
|
fields. Expand the "Legend" for a detailed description of each source and
|
134 |
8a7e43dd
|
Florent Torregrosa
|
target field. Sources are the attributes available in iCal event objects,
|
135 |
|
|
and Targets are the fields in your nodes.
|
136 |
7e072189
|
Assos Assos
|
- Most of this setup is going to be dependent upon how your content type's
|
137 |
85ad3d82
|
Assos Assos
|
fields are configured, but there are some universal requirements:
|
138 |
8a7e43dd
|
Florent Torregrosa
|
1) You MUST map the "UID" source to the "GUID" target. Then, after clicking
|
139 |
|
|
"Add", click the gear-shaped button that appears in the new table row,
|
140 |
85ad3d82
|
Assos Assos
|
and check the "Unique" checkbox. Then click "Update", and then before
|
141 |
|
|
you add any more mappings, click "Save" at the bottom of the page.
|
142 |
8a7e43dd
|
Florent Torregrosa
|
2) It's a good idea to map the "Summary/Title" source to the "Title" target,
|
143 |
|
|
and the "Description" source to whatever field is the "body" of the node.
|
144 |
55670b15
|
Assos Assos
|
3) AS OF 2014/04/10 THERE IS A MAJOR BUG IN Feeds WHICH LEAVES THE DATE
|
145 |
|
|
VALUES ON ALL IMPORTED EVENTS BLACNK. YOU MUST APPLY A PATCH TO Feeds
|
146 |
|
|
TO FIX THIS PROBLEM. IT IS AVAILABLE HERE: http://drupal.org/node/2237177.
|
147 |
8a7e43dd
|
Florent Torregrosa
|
- Once you've completed all the mappings, click the "Save" button on the
|
148 |
85ad3d82
|
Assos Assos
|
bottom left side of the page.
|
149 |
|
|
- Now you can import the iCal feed into nodes by going to the /import page of
|
150 |
8a7e43dd
|
Florent Torregrosa
|
your site (e.g. http://www.exmaple.com/import). Click the link for the
|
151 |
55670b15
|
Assos Assos
|
importer you just created, and enter the URL of the feed into the "URL"
|
152 |
|
|
field. Click the "Import" button, and observe the progress.
|
153 |
85ad3d82
|
Assos Assos
|
- Once it's done, you should see a green message saying "Created X nodes." If
|
154 |
|
|
you do, you've successfully set up your iCal importer. If you get some other
|
155 |
8a7e43dd
|
Florent Torregrosa
|
message, you'll need to tweak the importer's settings.
|
156 |
|
|
|
157 |
|
|
Remember, you have to map the UID source to the GUID target, and make it
|
158 |
|
|
unique, or your imports won't work!
|
159 |
|
|
|
160 |
55670b15
|
Assos Assos
|
|
161 |
|
|
===============================================================================
|
162 |
|
|
IMPORTANT NOTE ABOUT THE DATE FIELD TIMEZONE SETTING
|
163 |
|
|
===============================================================================
|
164 |
|
|
Date fields have a setting called "Time zone handling" which determines how
|
165 |
|
|
dates are stored in the database, and how they are displayed to users.
|
166 |
|
|
- "Site's time zone" converts the date to UTC as it stores it to the DB. Upon
|
167 |
|
|
display, it converts the date to the "Default time zone" that's set on your
|
168 |
|
|
site's Regional Settings configuration page (/admin/config/regional/settings).
|
169 |
|
|
- "Date's time zone" stores the date as it is entered, along with the timezone
|
170 |
|
|
name. Upon display, it converts the date from the stored timezone into the
|
171 |
|
|
site's default timezone. Well, I'm pretty sure it's *supposed* to do that, but
|
172 |
|
|
the code behind this setting is very buggy. DO NOT USE THIS SETTING.
|
173 |
|
|
- "User's time zone" converts the date to UTC as it stores it to the DB. Upon
|
174 |
|
|
display, it converts the date to the current user's timezone setting.
|
175 |
|
|
- "UTC" converts the date to UTC as it stores it to the DB. Upon display, it
|
176 |
|
|
performs no conversion, showing the UTC date directly to the user.
|
177 |
|
|
- "No time zone conversion" performs no conversion as it stores the date in
|
178 |
|
|
the DB. It also performs no conversion upon display.
|
179 |
|
|
|
180 |
|
|
The appropriate setting to choose here will depend upon how you want times to
|
181 |
|
|
be displayed on your site. The best setting *would* be "Date's time zone",
|
182 |
|
|
but since that setting is so buggy, I must recommend against it. Instead,
|
183 |
|
|
I'd suggest using "Site's time zone" for sites which host events that are
|
184 |
|
|
mostly in the same timezone (set the site's default timezone appropriately).
|
185 |
|
|
This works just right for local users of your site, and will be the least
|
186 |
|
|
confusing for users who live in a different timezone.
|
187 |
|
|
|
188 |
|
|
For sites which store events that take place in multiple different timezones,
|
189 |
|
|
the "User's time zone" setting is probably the most appropriate. Most users will
|
190 |
|
|
presumably be tuning in to your events online or on TV (since many take place
|
191 |
|
|
far away from them), which means they'll want to know what time the event occurs
|
192 |
|
|
in their local timezone, so they don't miss the broadcast.
|
193 |
|
|
|
194 |
|
|
If your Date field is already set to "Date's time zone", you won't be able to
|
195 |
|
|
change it, because that setting uses a different table schema than the others.
|
196 |
7e072189
|
Assos Assos
|
Since "Date's time zone" is very buggy, I'd strongly recommend deleting the
|
197 |
55670b15
|
Assos Assos
|
field and recreating it with a different setting. This will delete all the
|
198 |
|
|
dates in existing event nodes which use this field.
|
199 |
|
|
|
200 |
8a7e43dd
|
Florent Torregrosa
|
|
201 |
|
|
===============================================================================
|
202 |
|
|
HOW TO FIX THE "not a valid timezone" ERROR
|
203 |
|
|
===============================================================================
|
204 |
|
|
If you are seeing a warning about invalid timezones when you import an iCal
|
205 |
|
|
feed, you'll need to implement hook_date_ical_import_timezone_alter() in a
|
206 |
|
|
custom module to fix it. To do so, either edit an existing custom module, or
|
207 |
|
|
make a new module and add this function to it:
|
208 |
|
|
|
209 |
|
|
<?php
|
210 |
|
|
/**
|
211 |
|
|
* Implements hook_date_ical_import_timezone_alter().
|
212 |
|
|
*/
|
213 |
|
|
function <module>_date_ical_import_timezone_alter(&$tzid, $context) {
|
214 |
|
|
if (!empty($tzid)) {
|
215 |
|
|
// Do something to fix your invalid timezone.
|
216 |
|
|
// For instance, if all your events take place in one timezone, find your
|
217 |
|
|
// region's official TZID, and replace $tzid with it. Like this:
|
218 |
|
|
// $tzid = 'America/Los_Angeles';
|
219 |
|
|
}
|
220 |
|
|
}
|
221 |
|
|
?>
|
222 |
|
|
|
223 |
|
|
Replace <module> with the name of your module, change the code to do whatever
|
224 |
|
|
needs to be done to fix your timezones, and clear your Drupal cache.
|
225 |
|
|
|
226 |
55670b15
|
Assos Assos
|
|
227 |
8a7e43dd
|
Florent Torregrosa
|
===============================================================================
|
228 |
|
|
ADDITIONAL NOTES
|
229 |
|
|
===============================================================================
|
230 |
55670b15
|
Assos Assos
|
Date iCal only supports exporting iCal calendars by using Views.
|
231 |
8a7e43dd
|
Florent Torregrosa
|
To put an "Add to calendar" button on individual event nodes, try the
|
232 |
|
|
Add to Cal module (http://drupal.org/project/addtocal), or follow the
|
233 |
|
|
instructions created by the estimable nmc at:
|
234 |
85ad3d82
|
Assos Assos
|
http://nmc-codes.blogspot.ca/2012/11/creating-ical-feed-for-single-node-in.html
|
235 |
|
|
|
236 |
8a7e43dd
|
Florent Torregrosa
|
The Feeds Tamper module is useful for altering the data in imported iCal feeds.
|
237 |
|
|
|
238 |
85ad3d82
|
Assos Assos
|
Developers who wish to implement more powerful manipulation of event data can
|
239 |
8a7e43dd
|
Florent Torregrosa
|
read the date_ical.api.php file to learn about the various alter hooks that
|
240 |
85ad3d82
|
Assos Assos
|
date_ical exposes.
|
241 |
8a7e43dd
|
Florent Torregrosa
|
|
242 |
|
|
The libraries/windowsZones.json file, which Date iCal uses to map Windows-style
|
243 |
|
|
timezone names to real timezone IDs, is from Version24 of the Unicode CLDR:
|
244 |
|
|
http://cldr.unicode.org/.
|
245 |
c7b88c87
|
Assos Assos
|
|
246 |
7e072189
|
Assos Assos
|
The author of iCalcreator made extenside backwards incompatible changes to the
|
247 |
|
|
library in the v2.22 release. Thus Date iCal does not support any version of
|
248 |
|
|
iCalcreator after v2.20.2. |