public function date_ical_plugin_style_ical_feed::attach_to in Date iCal 7.3
Same name and namespace in other branches
- 7 date_ical_plugin_style_ical_feed.inc \date_ical_plugin_style_ical_feed::attach_to()
- 7.2 includes/date_ical_plugin_style_ical_feed.inc \date_ical_plugin_style_ical_feed::attach_to()
Sets up the iCal feed icon on calendar pages.
File
- includes/
date_ical_plugin_style_ical_feed.inc, line 22 - Views style plugin for the Date iCal module.
Class
- date_ical_plugin_style_ical_feed
- Defines a Views style plugin that renders iCal feeds.
Code
public function attach_to($display_id, $path, $title) {
$url_options = array();
$input = $this->view
->get_exposed_input();
if ($input) {
$url_options['query'] = $input;
}
$url_options['absolute'] = TRUE;
// Only add arguments to ical path for the contextual filters in the feed display.
// Clone view to prevent affecting the page view where this is attached.
$clone = $this->view
->clone_view();
$clone
->set_display($this->display->id);
$contextual_filters = $clone
->get_items('argument');
$arg_number = count($contextual_filters);
// Only include as many arguments as the feed display supports.
foreach ($clone->args as $key => $arg) {
if ($key >= $arg_number) {
unset($clone->args[$key]);
}
}
$url = url($clone
->get_url(NULL, $path), $url_options);
// If the user didn't disable the option, change the scheme to webcal://
// so calendar clients can automatically subscribe via the iCal link.
if (!$this
->_get_option('disable_webcal')) {
$url = str_replace(array(
'http://',
'https://',
), 'webcal://', $url);
}
// Render the feed icon and header tag (except during a View Preview and
// if the display is disabled).
if (empty($this->view->live_preview) && (!isset($this->display->display_options['enabled']) || $this->display->display_options['enabled'])) {
$tooltip = t('Add to My Calendar');
if (!isset($this->view->feed_icon)) {
// In PHP 5.5, you're not allowed to concatinate onto an unset
// property. But we need to do a concat, because there may be
// other attachments.
$this->view->feed_icon = '';
}
$variables = array(
'url' => check_url($url),
'tooltip' => $tooltip,
'view' => $this->view,
);
$this->view->feed_icon .= theme('date_ical_icon', $variables);
drupal_add_html_head_link(array(
'rel' => 'alternate',
'type' => 'text/calendar',
'title' => $tooltip,
'href' => $url,
));
}
}