Commit c301939d authored by Robert Rollins's avatar Robert Rollins

Applied changes inspired by contributors on the issue queue.

parent 709fdda7
......@@ -35,7 +35,8 @@ function theme_date_ical_icon($variables) {
$url = $variables['url'];
$variables = array(
'path' => drupal_get_path('module', 'date_ical') . '/images/ical-feed-icon-34x14.png',
'title' => t('Add to calendar'), t('Add to calendar'),
'title' => t('Add to my calendar'),
'alt' => t('Add to my calendar'),
);
if ($image = theme('image', $variables)) {
return '<a href="' . check_url($url) . '" class="ical-icon" title="ical">' . $image . '</a>';
......
......@@ -149,17 +149,19 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$field_name = 'revision_timestamp';
}
// Identify the field value that matched our query.
$date_field = $entity->$field_name;
// Pull the date value from the specified field of the entity.
$entity->date_id = array();
$start = NULL;
$end = NULL;
$lang = $entity->language;
$delta = isset($row->$delta_field) ? $row->$delta_field : 0;
if ($is_field) {
$date_field = array_key_exists($lang, $date_field) ? $date_field[$lang][$delta] : $date_field['und'][$delta];
$entity->date_id[] = 'calendar.' . $entity->nid . '.' . $field_name . '.' . $delta;
$items = field_get_items($this->entity_type, $entity, $field_name);
$date_field = $items[$delta];
$domain = check_plain($_SERVER['SERVER_NAME']);
$entity->date_id[] = "calendar.$id.$field_name.$delta@$domain";
//$entity->date_id[] = 'calendar.' . $id . '.' . $field_name . '.' . $delta;
if (!empty($date_field['value'])) {
$start = new DateObject($date_field['value'], $date_field['timezone_db']);
......@@ -181,7 +183,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
return;
}
// Set the item date to the proper display timezone;
// Set the item date to the proper display timezone.
$start->setTimezone(new dateTimezone($date_field['timezone']));
$end->setTimezone(new dateTimezone($date_field['timezone']));
......@@ -208,19 +210,19 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$location_field_name = $location_info['real_field_name'];
// Only attempt this is the entity actually has this field.
if (isset($entity->$location_field_name)) {
$location_field = $entity->$location_field_name;
$location_lang = array_key_exists($lang, $location_field) ? $lang : 'und';
$items = field_get_items($this->entity_type, $entity, $location_field_name);
if ($items) {
$location_field = $items[$delta];
if ($location_info['type'] == 'node_reference') {
$location_nid = $location_field[$location_lang][$delta]['nid'];
if ($location_nid) {
$node = node_load($location_nid);
$location = $node->title;
// Make sure this Node Reference actually references a node.
if ($location_field['nid']) {
$node = node_load($location_field['nid']);
$location = check_plain($node->title);
}
}
else {
$location = $location_field[$location_lang][$delta]['value'];
$location = check_plain($location_field['value']);
}
}
}
......
......@@ -13,9 +13,6 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
function _default_calendar_name() {
$view_title = $this->view->get_title();
$calendar_name = variable_get('site_name', 'Drupal');
if ($slogan = variable_get('site_slogan', '')) {
$calendar_name .= ' - ' . $slogan;
}
$calendar_name .= !empty($view_title) ? ': ' . $view_title : '';
return $calendar_name;
}
......@@ -31,7 +28,7 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
$url_options['absolute'] = TRUE;
$url = url($this->view->get_url(NULL, $path), $url_options);
if (empty($this->preview)) {
$this->view->feed_icon = theme('date_ical_icon', array('url' => $url, 'title' => $title));
$this->view->feed_icon .= theme('date_ical_icon', array('url' => $url, 'title' => $title));
drupal_add_html_head_link(array(
'rel' => 'alternate',
'type' => 'application/calendar',
......@@ -43,21 +40,21 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$cal_name = $this->_default_calendar_name();
// Allow users to override the default Calendar name (X-WR-CALNAME).
$form['cal_name'] = array(
'#type' => 'textfield',
'#title' => t('iCal Calendar Name'),
'#default_value' => $this->options['cal_name'],
'#description' => t("By default, the title of this calendar is constructed from the name and slogan of your site,
and the title of this view (\"$cal_name\") when imported into an iCal client. You may override that here."),
'#description' => t('This will appear as the title of the iCal feed. If ' .
'left blank, the View Title will be used. If that is also blank, the site ' .
'name will be inserted as the iCal feed title.'),
);
}
function render() {
if (empty($this->row_plugin) || $this->row_plugin->plugin_name != 'date_ical') {
debug('views_plugin_style_ical_feed: This style plugin supports only the Date iCal Entity row plugin.');
return 'To enable iCal output, this view\'s Format must be configured to Show: Date iCal Entity.';
debug('views_plugin_style_ical_feed: This style plugin supports only the iCal Entity row plugin.');
return 'To enable iCal output, this view\'s Format must be configured to Show: iCal Entity.';
}
$rows = array();
foreach ($this->view->result as $row_index => $row) {
......@@ -70,16 +67,24 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
$library = libraries_load('iCalcreator');
if (!empty($library['loaded'])) {
// Create a vcalendar object using the iCalcreator library.
$config = array('unique_id' => 'Drupal iCal API');
$config = array('unique_id' => 'Drupal: Date iCal');
$vcalendar = new vcalendar($config);
$vcalendar->setMethod('PUBLISH');
// Use the default calendar name, unless the user has overriden it.
$calendar_name = $this->_default_calendar_name();
if (!empty($this->options['cal_name'])) {
$calendar_name = $this->options['cal_name'];
// If the iCal Calendar Name has been set in the Feed Style options, it's used as the
// title in the iCal feed. If not, the View Title is used. If that is blank, then the
// Site Name is used.
$cal_name = $this->options['cal_name'];
if (empty($cal_name)) {
$view_title = $this->view->get_title();
if (!empty($view_title)) {
$cal_name = $view_title;
}
else {
$cal_name = variable_get('site_name', 'Drupal');
}
}
$vcalendar->setProperty('x-wr-calname', $calendar_name, array('VALUE' => 'TEXT'));
$vcalendar->setProperty('x-wr-calname', $cal_name, array('VALUE' => 'TEXT'));
// Now add the vevents.
$timezones = array();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment