1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Views style plugin for the Date iCal module.
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
/**
|
8 |
8a7e43dd
|
Florent Torregrosa
|
* Defines a Views style plugin that renders iCal feeds.
|
9 |
85ad3d82
|
Assos Assos
|
*/
|
10 |
|
|
class date_ical_plugin_style_ical_feed extends views_plugin_style {
|
11 |
|
|
|
12 |
8a7e43dd
|
Florent Torregrosa
|
/**
|
13 |
|
|
* Internal helper function.
|
14 |
|
|
*/
|
15 |
85ad3d82
|
Assos Assos
|
protected function _get_option($option_name) {
|
16 |
|
|
return isset($this->options[$option_name]) ? $this->options[$option_name] : '';
|
17 |
|
|
}
|
18 |
|
|
|
19 |
8a7e43dd
|
Florent Torregrosa
|
/**
|
20 |
|
|
* Sets up the iCal feed icon on calendar pages.
|
21 |
|
|
*/
|
22 |
|
|
public function attach_to($display_id, $path, $title) {
|
23 |
85ad3d82
|
Assos Assos
|
$url_options = array();
|
24 |
|
|
$input = $this->view->get_exposed_input();
|
25 |
|
|
if ($input) {
|
26 |
|
|
$url_options['query'] = $input;
|
27 |
|
|
}
|
28 |
|
|
$url_options['absolute'] = TRUE;
|
29 |
|
|
|
30 |
|
|
$url = url($this->view->get_url(NULL, $path), $url_options);
|
31 |
8a7e43dd
|
Florent Torregrosa
|
// If the user didn't disable the option, change the scheme to webcal://
|
32 |
|
|
// so calendar clients can automatically subscribe via the iCal link.
|
33 |
85ad3d82
|
Assos Assos
|
if (!$this->_get_option('disable_webcal')) {
|
34 |
|
|
$url = str_replace(array('http://', 'https://'), 'webcal://', $url);
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
// Render the feed icon and header tag (except during a View Preview).
|
38 |
|
|
if (empty($this->view->live_preview)) {
|
39 |
|
|
$tooltip = t('Add to My Calendar');
|
40 |
|
|
if (!isset($this->view->feed_icon)) {
|
41 |
8a7e43dd
|
Florent Torregrosa
|
// In PHP 5.5, you're not allowed to concatinate onto an unset
|
42 |
|
|
// property. But we need to do a concat, because there may be
|
43 |
|
|
// other attachments.
|
44 |
85ad3d82
|
Assos Assos
|
$this->view->feed_icon = '';
|
45 |
|
|
}
|
46 |
8a7e43dd
|
Florent Torregrosa
|
$variables = array(
|
47 |
|
|
'url' => check_url($url),
|
48 |
|
|
'tooltip' => $tooltip,
|
49 |
|
|
'view' => $this->view,
|
50 |
|
|
);
|
51 |
|
|
$this->view->feed_icon .= theme('date_ical_icon', $variables);
|
52 |
85ad3d82
|
Assos Assos
|
drupal_add_html_head_link(array(
|
53 |
|
|
'rel' => 'alternate',
|
54 |
|
|
'type' => 'text/calendar',
|
55 |
|
|
'title' => $tooltip,
|
56 |
8a7e43dd
|
Florent Torregrosa
|
'href' => $url,
|
57 |
85ad3d82
|
Assos Assos
|
));
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
|
61 |
8a7e43dd
|
Florent Torregrosa
|
/**
|
62 |
|
|
* Set up the options for the style plugin.
|
63 |
|
|
*/
|
64 |
|
|
public function option_definition() {
|
65 |
|
|
$false_bool = array('default' => FALSE, 'bool' => TRUE);
|
66 |
|
|
|
67 |
85ad3d82
|
Assos Assos
|
$options = parent::option_definition();
|
68 |
|
|
$options['cal_name'] = array('default' => array());
|
69 |
8a7e43dd
|
Florent Torregrosa
|
$options['no_calname'] = $false_bool;
|
70 |
|
|
$options['disable_webcal'] = $false_bool;
|
71 |
|
|
$options['exclude_dtstamp'] = $false_bool;
|
72 |
|
|
$options['unescape_punctuation'] = $false_bool;
|
73 |
85ad3d82
|
Assos Assos
|
return $options;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
8a7e43dd
|
Florent Torregrosa
|
/**
|
77 |
|
|
* Build the form for setting the style plugin's options.
|
78 |
|
|
*/
|
79 |
|
|
public function options_form(&$form, &$form_state) {
|
80 |
85ad3d82
|
Assos Assos
|
parent::options_form($form, $form_state);
|
81 |
|
|
// Allow users to override the default Calendar name (X-WR-CALNAME).
|
82 |
|
|
$form['cal_name'] = array(
|
83 |
|
|
'#type' => 'textfield',
|
84 |
|
|
'#title' => t('iCal Calendar Name'),
|
85 |
|
|
'#default_value' => $this->_get_option('cal_name'),
|
86 |
|
|
'#description' => t('This will appear as the title of the iCal feed. If left blank, the View Title will be used.
|
87 |
|
|
If that is also blank, the site name will be inserted as the iCal feed title.'),
|
88 |
|
|
);
|
89 |
|
|
$form['no_calname'] = array(
|
90 |
|
|
'#type' => 'checkbox',
|
91 |
|
|
'#title' => t('Exclude Calendar Name'),
|
92 |
|
|
'#default_value' => $this->_get_option('no_calname'),
|
93 |
|
|
'#description' => t("Excluding the X-WR-CALNAME value from the iCal Feed causes
|
94 |
|
|
some calendar clients to add the events in the feed to an existing calendar, rather
|
95 |
|
|
than creating a whole new calendar for them."),
|
96 |
|
|
);
|
97 |
|
|
$form['disable_webcal'] = array(
|
98 |
|
|
'#type' => 'checkbox',
|
99 |
|
|
'#title' => t('Disable webcal://'),
|
100 |
|
|
'#default_value' => $this->_get_option('disable_webcal'),
|
101 |
|
|
'#description' => t("By default, the feed URL will use the webcal:// scheme, which allows calendar
|
102 |
|
|
clients to easily subscribe to the feed. If you want your users to instead download this iCal
|
103 |
|
|
feed as a file, activate this option."),
|
104 |
|
|
);
|
105 |
|
|
$form['exclude_dtstamp'] = array(
|
106 |
|
|
'#type' => 'checkbox',
|
107 |
|
|
'#title' => t('Exclude DTSTAMP'),
|
108 |
|
|
'#default_value' => $this->_get_option('exclude_dtstamp'),
|
109 |
|
|
'#description' => t("By default, the feed will set each event's DTSTAMP property to the time at which the feed got downloaded.
|
110 |
|
|
Some feed readers will (incorrectly) look at the DTSTAMP value when they compare different downloads of the same feed, and
|
111 |
|
|
conclcude that the event has been updated (even though it hasn't actually changed). Enable this option to exclude the DTSTAMP
|
112 |
|
|
field from your feeds, so that these buggy feed readers won't mark every event as updated every time they check."),
|
113 |
|
|
);
|
114 |
8a7e43dd
|
Florent Torregrosa
|
$form['unescape_punctuation'] = array(
|
115 |
|
|
'#type' => 'checkbox',
|
116 |
|
|
'#title' => t('Unescape Commas and Semicolons'),
|
117 |
|
|
'#default_value' => $this->_get_option('unescape_punctuation'),
|
118 |
|
|
'#description' => t('In order to comply with the iCal spec, Date iCal will "escape" commas and semicolons (prepend them with backslashes).
|
119 |
|
|
However, many calendar clients are bugged to not unescape these characters, leaving the backslashes littered throughout your events.
|
120 |
|
|
Enable this option to have Date iCal unescape these characters before it exports the iCal feed.'),
|
121 |
|
|
);
|
122 |
85ad3d82
|
Assos Assos
|
}
|
123 |
|
|
|
124 |
8a7e43dd
|
Florent Torregrosa
|
/**
|
125 |
|
|
* Render the event arrays returned by the row plugin into a VCALENDAR.
|
126 |
|
|
*/
|
127 |
|
|
public function render() {
|
128 |
85ad3d82
|
Assos Assos
|
if (empty($this->row_plugin) || !in_array($this->row_plugin->plugin_name, array('date_ical', 'date_ical_fields'))) {
|
129 |
|
|
debug('date_ical_plugin_style_ical_feed: This style plugin supports only the "iCal Entity" and "iCal Fields" row plugins.', NULL, TRUE);
|
130 |
8a7e43dd
|
Florent Torregrosa
|
return t('To enable iCal output, the view Format must be configured to Show: iCal Entity or iCal Fields.');
|
131 |
85ad3d82
|
Assos Assos
|
}
|
132 |
|
|
if ($this->row_plugin->plugin_name == 'date_ical_fields' && empty($this->row_plugin->options['date_field'])) {
|
133 |
8a7e43dd
|
Florent Torregrosa
|
// Because the Date field is required by the form, this error state will
|
134 |
|
|
// rarely occur. But I ran across it during testing, and the error that
|
135 |
|
|
// resulted was totally non-sensical, so I'm adding this just in case.
|
136 |
85ad3d82
|
Assos Assos
|
return t("When using the iCal Fields row plugin, the Date field is required. Please set it up using the Settings link under 'Format -> Show: iCal Fields'.");
|
137 |
|
|
}
|
138 |
|
|
$events = array();
|
139 |
|
|
foreach ($this->view->result as $row_index => $row) {
|
140 |
|
|
$this->view->row_index = $row_index;
|
141 |
8a7e43dd
|
Florent Torregrosa
|
$row->index = $row_index;
|
142 |
85ad3d82
|
Assos Assos
|
try {
|
143 |
8a7e43dd
|
Florent Torregrosa
|
$events[] = $this->row_plugin->render($row);
|
144 |
85ad3d82
|
Assos Assos
|
}
|
145 |
|
|
catch (Exception $e) {
|
146 |
|
|
debug($e->getMessage(), NULL, TRUE);
|
147 |
|
|
return $e->getMessage();
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
unset($this->view->row_index);
|
151 |
|
|
|
152 |
|
|
// Try to load the iCalcreator library.
|
153 |
|
|
$library = libraries_load('iCalcreator');
|
154 |
|
|
if (!$library['loaded']) {
|
155 |
|
|
// The iCalcreator library isn't available, so we can't output anything.
|
156 |
|
|
$output = t('Please install the iCalcreator library to enable iCal output.');
|
157 |
|
|
}
|
158 |
|
|
else {
|
159 |
|
|
// Create a vcalendar object using the iCalcreator library.
|
160 |
|
|
$config = array('unique_id' => 'Date iCal v' . DATE_ICAL_VERSION);
|
161 |
|
|
$vcalendar = new vcalendar($config);
|
162 |
|
|
$vcalendar->setMethod('PUBLISH');
|
163 |
|
|
|
164 |
8a7e43dd
|
Florent Torregrosa
|
// Only include the X-WR-CALNAME property if the user didn't enable
|
165 |
|
|
// the "Exclude Calendar Name" option.
|
166 |
|
|
if (!$this->_get_option('no_calname')) {
|
167 |
|
|
$cal_name = $this->_get_option('cal_name');
|
168 |
|
|
if (empty($cal_name)) {
|
169 |
|
|
$cal_name = $this->view->get_title();
|
170 |
|
|
if (empty($cal_name)) {
|
171 |
|
|
$cal_name = variable_get('site_name', 'Drupal');
|
172 |
|
|
}
|
173 |
85ad3d82
|
Assos Assos
|
}
|
174 |
8a7e43dd
|
Florent Torregrosa
|
if (!empty($cal_name)) {
|
175 |
|
|
$vcalendar->setProperty('X-WR-CALNAME', $cal_name, array('VALUE' => 'TEXT'));
|
176 |
85ad3d82
|
Assos Assos
|
}
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
// Now add the VEVENTs.
|
180 |
|
|
$timezones = array();
|
181 |
|
|
foreach ($events as $event) {
|
182 |
|
|
if (empty($event)) {
|
183 |
|
|
// The row plugin returned NULL for this row, which can happen due to
|
184 |
|
|
// either various error conditions, or because an RRULE is involved.
|
185 |
|
|
// When this happens, just skip it.
|
186 |
|
|
continue;
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
$vevent = $vcalendar->newComponent('vevent');
|
190 |
8a7e43dd
|
Florent Torregrosa
|
$vevent->setUid($event['uid']);
|
191 |
|
|
$vevent->setSummary($event['summary']);
|
192 |
|
|
|
193 |
85ad3d82
|
Assos Assos
|
// Get the start date as an array.
|
194 |
|
|
$start = $event['start']->toArray();
|
195 |
8a7e43dd
|
Florent Torregrosa
|
$start_timezone = $event['start']->getTimezone()->getName();
|
196 |
|
|
$timezones[$start_timezone] = $start_timezone;
|
197 |
85ad3d82
|
Assos Assos
|
|
198 |
|
|
if ($event['all_day']) {
|
199 |
8a7e43dd
|
Florent Torregrosa
|
// All Day events need to be DATEs, rather than DATE-TIMEs.
|
200 |
85ad3d82
|
Assos Assos
|
$vevent->setDtstart($start['year'], $start['month'], $start['day'],
|
201 |
|
|
FALSE, FALSE, FALSE, FALSE, array('VALUE' => 'DATE'));
|
202 |
|
|
}
|
203 |
|
|
else {
|
204 |
|
|
$vevent->setDtstart(
|
205 |
|
|
$start['year'],
|
206 |
|
|
$start['month'],
|
207 |
|
|
$start['day'],
|
208 |
|
|
$start['hour'],
|
209 |
|
|
$start['minute'],
|
210 |
|
|
$start['second'],
|
211 |
8a7e43dd
|
Florent Torregrosa
|
$start_timezone
|
212 |
85ad3d82
|
Assos Assos
|
);
|
213 |
|
|
}
|
214 |
|
|
|
215 |
|
|
// Add the Timezone info to the start date, for use later.
|
216 |
|
|
$start['tz'] = $event['start']->getTimezone();
|
217 |
|
|
|
218 |
|
|
// Only add the end date if there is one.
|
219 |
|
|
if (!empty($event['end'])) {
|
220 |
|
|
$end = $event['end']->toArray();
|
221 |
8a7e43dd
|
Florent Torregrosa
|
$end_timezone = $event['end']->getTimezone()->getName();
|
222 |
|
|
$timezones[$end_timezone] = $end_timezone;
|
223 |
85ad3d82
|
Assos Assos
|
|
224 |
|
|
if ($event['all_day']) {
|
225 |
|
|
$vevent->setDtend($end['year'], $end['month'], $end['day'],
|
226 |
|
|
FALSE, FALSE, FALSE, FALSE, array('VALUE' => 'DATE'));
|
227 |
|
|
}
|
228 |
|
|
else {
|
229 |
|
|
$vevent->setDtend(
|
230 |
|
|
$end['year'],
|
231 |
|
|
$end['month'],
|
232 |
|
|
$end['day'],
|
233 |
|
|
$end['hour'],
|
234 |
|
|
$end['minute'],
|
235 |
|
|
$end['second'],
|
236 |
8a7e43dd
|
Florent Torregrosa
|
$end_timezone
|
237 |
85ad3d82
|
Assos Assos
|
);
|
238 |
|
|
}
|
239 |
|
|
$end['tz'] = $event['end']->getTimezone();
|
240 |
|
|
}
|
241 |
|
|
|
242 |
|
|
// Handle repeating dates from the date_repeat module.
|
243 |
|
|
if (!empty($event['rrule']) && module_exists('date_repeat')) {
|
244 |
|
|
// Split the rrule into an RRULE and any additions and exceptions.
|
245 |
|
|
module_load_include('inc', 'date_api', 'date_api_ical');
|
246 |
|
|
module_load_include('inc', 'date_repeat', 'date_repeat_calc');
|
247 |
|
|
list($rrule, $exceptions, $additions) = date_repeat_split_rrule($event['rrule']);
|
248 |
|
|
|
249 |
|
|
// Add the RRULE itself. We need to massage the data a bit, since
|
250 |
|
|
// iCalcreator expects RRULEs to be in a different format than how
|
251 |
|
|
// Date API gives them to us.
|
252 |
8a7e43dd
|
Florent Torregrosa
|
$vevent->setRrule(_date_ical_convert_rrule_for_icalcreator($rrule));
|
253 |
85ad3d82
|
Assos Assos
|
|
254 |
|
|
// Convert any exceptions to EXDATE properties.
|
255 |
|
|
if (!empty($exceptions)) {
|
256 |
|
|
$exdates = array();
|
257 |
|
|
foreach ($exceptions as $exception) {
|
258 |
|
|
$except = date_ical_date($exception, 'UTC');
|
259 |
|
|
date_timezone_set($except, $start['tz']);
|
260 |
|
|
$exception_array = $except->toArray();
|
261 |
|
|
$exdates[] = array(
|
262 |
|
|
'year' => $exception_array['year'],
|
263 |
|
|
'month' => $exception_array['month'],
|
264 |
|
|
'day' => $exception_array['day'],
|
265 |
|
|
// Use the time information from the start date, since Date
|
266 |
|
|
// doesn't store time info for EXDATEs.
|
267 |
|
|
'hour' => $start['hour'],
|
268 |
|
|
'min' => $start['minute'],
|
269 |
|
|
'second' => $start['second'],
|
270 |
|
|
'tz' => $start['tz']->getName(),
|
271 |
|
|
);
|
272 |
|
|
}
|
273 |
|
|
// Add each exclusion as a separate EXDATE property.
|
274 |
|
|
// The spec supports putting multiple date values into one EXDATE,
|
275 |
|
|
// but several popular calendar clients (*cough* Apple *cough*)
|
276 |
|
|
// are bugged, and do not recognize multi-value EXDATEs.
|
277 |
|
|
foreach ($exdates as $exdate) {
|
278 |
|
|
$vevent->setExdate(array($exdate));
|
279 |
|
|
}
|
280 |
|
|
}
|
281 |
|
|
|
282 |
|
|
// Convert any additions to RDATE properties.
|
283 |
|
|
if (!empty($additions)) {
|
284 |
|
|
$rdates = array();
|
285 |
|
|
foreach ($additions as $addition) {
|
286 |
|
|
$add = date_ical_date($addition, 'UTC');
|
287 |
|
|
date_timezone_set($add, $start['tz']);
|
288 |
|
|
$addition_array = $add->toArray();
|
289 |
|
|
|
290 |
|
|
$rdate = array(
|
291 |
|
|
'year' => $addition_array['year'],
|
292 |
|
|
'month' => $addition_array['month'],
|
293 |
|
|
'day' => $addition_array['day'],
|
294 |
|
|
// Use the time information from the start date, since Date
|
295 |
|
|
// doesn't store time info for RDATEs.
|
296 |
|
|
'hour' => $start['hour'],
|
297 |
|
|
'min' => $start['minute'],
|
298 |
|
|
'second' => $start['second'],
|
299 |
|
|
'tz' => $start['tz']->getName(),
|
300 |
|
|
);
|
301 |
|
|
|
302 |
|
|
// If an end date was was calculated above, use that too.
|
303 |
|
|
// iCalcreator expects RDATEs that have end dates to be
|
304 |
|
|
// specified as array($start_rdate, $end_rdate).
|
305 |
|
|
if (isset($end)) {
|
306 |
|
|
$rdate_with_end = array($rdate);
|
307 |
|
|
$rdate_with_end[] = array(
|
308 |
|
|
'year' => $addition_array['year'],
|
309 |
|
|
'month' => $addition_array['month'],
|
310 |
|
|
'day' => $addition_array['day'],
|
311 |
|
|
// Use the time information from the end date.
|
312 |
|
|
'hour' => $end['hour'],
|
313 |
|
|
'min' => $end['minute'],
|
314 |
|
|
'second' => $end['second'],
|
315 |
|
|
'tz' => $end['tz']->getName(),
|
316 |
|
|
);
|
317 |
|
|
$rdate = $rdate_with_end;
|
318 |
|
|
}
|
319 |
|
|
|
320 |
|
|
$rdates[] = $rdate;
|
321 |
|
|
}
|
322 |
|
|
// Add each addition as a separate RDATE property.
|
323 |
|
|
// The spec supports putting multiple date values into one RDATE,
|
324 |
|
|
// but several popular calendar clients (*cough* Apple *cough*)
|
325 |
|
|
// are bugged, and do not recognize multi-value RDATEs.
|
326 |
|
|
foreach ($rdates as $rdate) {
|
327 |
|
|
$vevent->setRdate(array($rdate));
|
328 |
|
|
}
|
329 |
|
|
}
|
330 |
|
|
}
|
331 |
|
|
if (!empty($event['url'])) {
|
332 |
|
|
$vevent->setUrl($event['url'], array('type' => 'URI'));
|
333 |
|
|
}
|
334 |
|
|
if (!empty($event['location'])) {
|
335 |
8a7e43dd
|
Florent Torregrosa
|
$vevent->setLocation($event['location']);
|
336 |
85ad3d82
|
Assos Assos
|
}
|
337 |
|
|
if (!empty($event['description'])) {
|
338 |
8a7e43dd
|
Florent Torregrosa
|
$vevent->setDescription($event['description']);
|
339 |
85ad3d82
|
Assos Assos
|
}
|
340 |
|
|
if (!empty($event['last-modified'])) {
|
341 |
|
|
$lm = $event['last-modified']->toArray();
|
342 |
|
|
$vevent->setLastModified(
|
343 |
|
|
$lm['year'],
|
344 |
|
|
$lm['month'],
|
345 |
|
|
$lm['day'],
|
346 |
|
|
$lm['hour'],
|
347 |
|
|
$lm['minute'],
|
348 |
|
|
$lm['second'],
|
349 |
|
|
$lm['timezone']
|
350 |
|
|
);
|
351 |
|
|
}
|
352 |
|
|
if (!empty($event['created'])) {
|
353 |
|
|
$created = $event['created']->toArray();
|
354 |
|
|
$vevent->setCreated(
|
355 |
|
|
$created['year'],
|
356 |
|
|
$created['month'],
|
357 |
|
|
$created['day'],
|
358 |
|
|
$created['hour'],
|
359 |
|
|
$created['minute'],
|
360 |
|
|
$created['second'],
|
361 |
|
|
$created['timezone']
|
362 |
|
|
);
|
363 |
|
|
}
|
364 |
|
|
|
365 |
8a7e43dd
|
Florent Torregrosa
|
// Allow other modules to alter the vevent before it's exported.
|
366 |
|
|
drupal_alter('date_ical_export_vevent', $vevent, $this->view, $event);
|
367 |
85ad3d82
|
Assos Assos
|
}
|
368 |
|
|
|
369 |
|
|
// Now add to the calendar all the timezones used by the events.
|
370 |
|
|
foreach ($timezones as $timezone) {
|
371 |
|
|
if (strtoupper($timezone) != 'UTC') {
|
372 |
|
|
iCalUtilityFunctions::createTimezone($vcalendar, $timezone);
|
373 |
|
|
}
|
374 |
|
|
}
|
375 |
|
|
|
376 |
8a7e43dd
|
Florent Torregrosa
|
// Allow other modules to alter the vcalendar before it's exported.
|
377 |
|
|
drupal_alter('date_ical_export_vcalendar', $vcalendar, $this->view);
|
378 |
85ad3d82
|
Assos Assos
|
|
379 |
|
|
$output = $vcalendar->createCalendar();
|
380 |
8a7e43dd
|
Florent Torregrosa
|
// iCalcreator escapes all commas and semicolons in string values, as the
|
381 |
|
|
// spec demands. However, some calendar clients are buggy and fail to
|
382 |
|
|
// unescape these characters. Users may choose to unescape them here to
|
383 |
|
|
// sidestep those clients' bugs.
|
384 |
|
|
// NOTE: This results in a non-compliant iCal feed, but it seems like a
|
385 |
|
|
// LOT of major clients are bugged this way.
|
386 |
|
|
if ($this->_get_option('unescape_punctuation')) {
|
387 |
|
|
$output = str_replace('\,', ',', $output);
|
388 |
|
|
$output = str_replace('\;', ';', $output);
|
389 |
|
|
}
|
390 |
85ad3d82
|
Assos Assos
|
|
391 |
|
|
// In order to respect the Exclude DTSTAMP option, we unfortunately have
|
392 |
|
|
// to parse out the DTSTAMP properties after they get rendered. Simply
|
393 |
|
|
// using deleteProperty('DTSTAMP') doesn't work, because iCalcreator
|
394 |
|
|
// considers the DTSTAMP to be essential, and will re-create it when
|
395 |
|
|
// createCalendar() is called.
|
396 |
|
|
if ($this->_get_option('exclude_dtstamp')) {
|
397 |
|
|
$filtered_lines = array();
|
398 |
|
|
foreach (explode("\r\n", $output) as $line) {
|
399 |
|
|
if (strpos($line, 'DTSTAMP') === 0) {
|
400 |
|
|
continue;
|
401 |
|
|
}
|
402 |
|
|
$filtered_lines[] = $line;
|
403 |
|
|
}
|
404 |
|
|
$output = implode("\r\n", $filtered_lines);
|
405 |
|
|
}
|
406 |
|
|
}
|
407 |
|
|
|
408 |
8a7e43dd
|
Florent Torregrosa
|
// These steps shouldn't be run when during Preview on the View page.
|
409 |
85ad3d82
|
Assos Assos
|
if (empty($this->view->live_preview)) {
|
410 |
|
|
// Prevent devel module from appending queries to ical export.
|
411 |
|
|
$GLOBALS['devel_shutdown'] = FALSE;
|
412 |
|
|
|
413 |
55670b15
|
Assos Assos
|
drupal_add_http_header('Content-Type', 'text/calendar; charset=UTF-8');
|
414 |
|
|
drupal_add_http_header('Cache-Control', 'no-cache, must-revalidate');
|
415 |
|
|
drupal_add_http_header('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT');
|
416 |
85ad3d82
|
Assos Assos
|
|
417 |
8a7e43dd
|
Florent Torregrosa
|
// For sites with Clean URLs disabled, the Display's "path" value ends
|
418 |
|
|
// up only in the query args, meaning the filename won't be set properly
|
419 |
|
|
// when users download the feed. So we need to manually instruct browsers
|
420 |
|
|
// to download a .ics file.
|
421 |
85ad3d82
|
Assos Assos
|
if (!variable_get('clean_url', FALSE)) {
|
422 |
|
|
$path_array = explode('/', $this->display->display_options['path']);
|
423 |
8a7e43dd
|
Florent Torregrosa
|
$filename = end($path_array);
|
424 |
85ad3d82
|
Assos Assos
|
drupal_add_http_header('Content-Disposition', "attachment; filename=\"$filename\"");
|
425 |
|
|
}
|
426 |
|
|
}
|
427 |
|
|
|
428 |
8a7e43dd
|
Florent Torregrosa
|
// Allow other modules to alter the rendered calendar.
|
429 |
|
|
drupal_alter('date_ical_export_post_render', $output, $this->view);
|
430 |
85ad3d82
|
Assos Assos
|
|
431 |
|
|
return $output;
|
432 |
|
|
}
|
433 |
|
|
} |