You are here

function addtocal_download_ics in Add to Cal 7

Outputs an ICS file containing event information for the selected entity. Called by hook_menu.

Parameters

$entity:

$field_name:

$view_mode:

1 string reference to 'addtocal_download_ics'
addtocal_menu in ./addtocal.module
Implements hook_menu().

File

./addtocal.module, line 583
addtocal.module General functions and hook implementations.

Code

function addtocal_download_ics($entity, $field_name, $view_mode) {
  drupal_add_http_header('Content-Type', 'application/calendar; charset=utf-8');

  // Set the filename.
  $filename = preg_replace('/[\\x00-\\x1F]/u', '_', strip_tags($entity->title));
  drupal_add_http_header('Content-Disposition', 'attachment; filename="' . $filename . '.ics"');

  // Get entity type from the current path
  $entity_type = arg(0);

  // Get the entity_id.
  list($entity_id) = entity_extract_ids($entity_type, $entity);

  // Get query.
  $query = drupal_get_query_parameters();

  // Get display and info.
  $display = addtocal_get_display($entity, $entity_type, $field_name, $view_mode);
  $info = addtocal_extract_event_info($entity_type, $entity, $entity_id, $field_name, $display);
  $url = isset($query['url']) ? $query['url'] : '';
  $description = $info['description'];
  $location = $info['location'];
  $title = $info['title'];
  $dates = field_get_items($entity_type, $entity, $field_name);
  $start_date = $dates[0]['value'];
  if (array_key_exists('value2', $dates[0])) {
    $end_date = $dates[0]['value2'];
  }
  else {
    $end_date = $start_date;
  }
  $rfc_dates = addtocal_rfc_3339_date($start_date, $end_date, $info['timezone']);
  echo 'BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:' . $entity_type . '-' . $entity_id . '@' . $_SERVER['HTTP_HOST'] . '
DTSTAMP:' . $rfc_dates['start'] . '
DTSTART:' . $rfc_dates['start'] . '
DTEND:' . $rfc_dates['end'] . '
SUMMARY:' . check_plain($title) . '
DESCRIPTION:' . $description . '
LOCATION:' . $location . '
END:VEVENT
END:VCALENDAR';
  drupal_exit();
}