Commit 8f7f6326 authored by Tim Plunkett's avatar Tim Plunkett

Issue #1447104 by tim.plunkett: Fixed code clean-up and undefined notices.

parent 00a13265
......@@ -2,18 +2,19 @@ Date iCal Module
Roadmap and Background:
This module contains code to create an iCal feed in Views. It has been pulled out
of the Calendar iCal module because it has no dependency on Calendar and it could
be used on any view. The code has also been generalized so that it will work for
any entity, not just nodes. It creates an 'iCal' view mode for every entity type
that can be used to to configure the description used in the iCal feed, and adds
theme suggestions to tell Drupal to look for an iCal version of the entity template.
This module contains code to create an iCal feed in Views. It has been pulled
out of the Calendar iCal module because it has no dependency on Calendar and it
could be used on any view. The code has also been generalized so that it will
work for any entity, not just nodes. It creates an 'iCal' view mode for every
entity type that can be used to to configure the description used in the iCal
feed, and adds theme suggestions to tell Drupal to look for an iCal version of
the entity template.
The Calendar iCal module will be deprecated in favor of this module.
Future plans for this module:
- Add in an iCal parser for the Feeds module that can parse an iCal feed
from another site so it is possible to import as well as export iCal information.
- Add in an iCal parser for the Feeds module that can parse an iCal feed from
another site so it is possible to import as well as export iCal information.
- Add in ways to take advantage of other parts of the iCal specification,
like LOCATION or VALARM.
- Add some pre-configured features that illustrate how to set up a site
......@@ -22,24 +23,28 @@ Future plans for this module:
To use this module to create an iCal feed:
- Enable Date API, Views, and Date iCal.
- Go to the Display Fields screen for the entity you want to export in an iCal field.
You will see that there is a new view mode for all entities, called 'iCal'.
- Set up the iCal view mode to contain whatever should be exported as the 'Description'
field for the iCal field. You can trim the text to the desired size, include other fields, etc.
- Go to the Display Fields screen for the entity you want to export in an iCal
field. You will see that there is a new view mode for all entities, called
'iCal'.
- Set up the iCal view mode to contain whatever should be exported as the
'Description' field for the iCal field. You can trim the text to the desired
size, include other fields, etc.
- Optional, but recommended, create a new node.tpl file for the iCal view mode,
using the name ENTITYTYPE--ical.tpl.php or ENTITYTYPE--BUNDLE--ical.tpl.php. Make this a very
simple template that omits the title, submitted by information, links, and comments.
Place that file in the theme folder.
using the name ENTITYTYPE--ical.tpl.php or ENTITYTYPE--BUNDLE--ical.tpl.php.
Make this a very simple template that omits the title, submitted by
information, links, and comments. Place that file in the theme folder.
- Clear the cache so the new template can be discovered by Drupal.
- Create a new view that contains the items you want to display in the iCal feed.
- Create a new view containing the items you want to display in the iCal feed.
- Add a feed to the view, using the feed type 'Date iCal'.
- Choose to 'Show' the feed as 'Date iCal Entities' (rather than 'Content' or 'Fields').
- Choose to 'Show' the feed as 'Date iCal Entities' (rather than 'Content' or
'Fields').
- In the settings for Date iCal Entities, select the specific date field
that should be used as the event date for the iCal feed.
- Give the feed a path like 'calendar/ical/%/calendar.ics', where you have a '/%/' for every
contextual filter in the view.
- Add date filters or arguments that will constrain the view to the items you want to display in the feed.
- Give the feed a path like 'calendar/ical/%/calendar.ics', where you have a
'/%/' for every contextual filter in the view.
- Add date filters or arguments that will constrain the view to the items you
want to display in the feed.
- Attach the feed to a page view.
- Navigate to the page view. You should see the iCal icon at the bottom of the view.
If you click on the icon it will download an .ics file with the events that matched
the view criteria.
\ No newline at end of file
- Navigate to the page view. You should see the iCal icon at the bottom of the
view. If you click on the icon it will download an .ics file with the events
that matched the view criteria.
......@@ -13,8 +13,8 @@
* be compliant with the iCal spec.
*
* @see http://tools.ietf.org/html/rfc5545#section-3.1
* @see date-vevent.tpl.php.
* @see date-valarm.tpl.php.
* @see date-vevent.tpl.php
* @see date-valarm.tpl.php
*
* @ingroup themeable
*/
......
......@@ -24,7 +24,7 @@
* be compliant with the iCal spec.
*
* @see http://tools.ietf.org/html/rfc5545#section-3.1
* @see date-valarm.tpl.php.
* @see date-valarm.tpl.php
*
* @ingroup themeable
*/
......
<?php
/**
* @file
* Adds ical functionality to Views.
*/
/**
* Implementation of hook_views_api().
*
* Implements hook_views_api().
*/
function date_ical_views_api() {
return array(
......@@ -18,38 +18,37 @@ function date_ical_views_api() {
/**
* Implements hook_theme().
*/
function date_ical_theme() {
function date_ical_theme($existing, $type, $theme, $path) {
return array(
'date_ical_icon' => array(
'variables' => array('url'),
),
);
'variables' => array('url' => NULL),
),
);
}
/**
* The theme for the ical icon.
*/
function theme_date_ical_icon($vars) {
$url = $vars['url'];
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'),
);
if ($image = theme('image', $variables)) {
return '<div style="text-align:right"><a href="' . check_url($url) . '" class="ical-icon" title="ical">' . $image . '</a></div>';
return '<div style="text-align: right;"><a href="' . check_url($url) . '" class="ical-icon" title="ical">' . $image . '</a></div>';
}
}
/**
* Implementation of hook_preprocess_node().
*
* Hide extraneous information when printing an ical view.
* The same thing can be done in the theme for other entities,
* and this function can be overridden in the theme to produce
* different results for nodes.
* Implements hook_preprocess_HOOK() for nodes.
*
* Hide extraneous information when printing an ical view. The same thing can be
* done in the theme for other entities, and this function can be overridden in
* the theme to produce different results for nodes.
*/
function date_ical_preprocess_node(&$variables){
if ($variables['view_mode'] == 'ical') {
function date_ical_preprocess_node(&$variables) {
if (isset($variables['view_mode']) && $variables['view_mode'] == 'ical') {
// We hide the page elements we won't want to see.
// The display of the body and other fields will be controlled
// by the Display Fields settings for the ical view mode.
......@@ -67,20 +66,19 @@ function date_ical_preprocess_node(&$variables){
*
* Add an 'iCal' view mode for all entities, similar to RSS view mode.
*/
function date_ical_entity_info_alter(&$info) {
$data = entity_get_info();
foreach ($data as $entity_type => $entity_info) {
$info[$entity_type]['view modes'] += array(
function date_ical_entity_info_alter(&$entity_info) {
foreach ($entity_info as $entity_type => $info) {
$entity_info[$entity_type]['view modes'] += array(
'ical' => array(
'label' => t('iCal'),
'custom settings' => FALSE,
'custom settings' => TRUE,
),
);
}
}
/**
* Implementation of hook_views_plugins
* Implements hook_views_plugins().
*/
function date_ical_views_plugins() {
$module_path = drupal_get_path('module', 'date_ical');
......@@ -93,10 +91,10 @@ function date_ical_views_plugins() {
'title' => t('Date iCal Feed'),
'help' => t('Generates an iCal VCALENDAR feed from a view.'),
'handler' => 'date_ical_plugin_style_ical_feed',
'path' => "$module_path",
'theme' => 'date_vcalendar',
'path' => $module_path,
'theme' => 'date_ical_vcalendar',
'theme file' => 'theme.inc',
'theme path' => "$module_path",
'theme path' => $module_path,
'uses fields' => TRUE,
'uses grouping' => FALSE,
'uses row plugin' => TRUE,
......@@ -110,10 +108,10 @@ function date_ical_views_plugins() {
'title' => t('Date iCal Entities'),
'help' => t('Display each entity as an iCal VEVENT item.'),
'handler' => 'date_ical_plugin_row_ical_feed',
'path' => "$module_path",
'theme' => 'date_vevent',
'path' => $module_path,
'theme' => 'date_ical_vevent',
'theme file' => 'theme.inc',
'theme path' => "$module_path",
'theme path' => $module_path,
'uses options' => TRUE,
'uses fields' => FALSE,
'type' => 'feed',
......@@ -124,7 +122,8 @@ function date_ical_views_plugins() {
}
/**
* Implemention of hook_theme_registry_alter().
* Implements hook_theme_registry_alter().
*
* Technique borrowed from Display Suite module.
* Add a custom preprocess hook that will work for all types of entities
*/
......@@ -133,7 +132,9 @@ function date_ical_theme_registry_alter(&$theme_registry) {
$entity_info = entity_get_info();
foreach ($entity_info as $entity => $info) {
// User uses user_profile for theming.
if ($entity == 'user') $entity = 'user_profile';
if ($entity == 'user') {
$entity = 'user_profile';
}
// Only add preprocess functions if entity exposes theme function.
if (isset($theme_registry[$entity])) {
......@@ -156,8 +157,8 @@ function date_ical_theme_registry_alter(&$theme_registry) {
* Technique borrowed from Display Suite module.
* Add ical template suggestions to all types of entities.
*/
function date_ical_preprocess(&$vars) {
if (isset($vars['elements']) && isset($vars['elements']['#entity_type']) && isset($vars['elements']['#bundle']) && $vars['view_mode'] == 'ical') {
function date_ical_preprocess(&$vars, $hook) {
if (isset($vars['elements']) && isset($vars['elements']['#entity_type']) && isset($vars['elements']['#bundle']) && isset($vars['view_mode']) && $vars['view_mode'] == 'ical') {
$vars['theme_hook_suggestions'][] = $vars['elements']['#entity_type'] . '__ical';
$vars['theme_hook_suggestions'][] = $vars['elements']['#entity_type'] . '__' . $vars['elements']['#bundle'] . '__ical';
}
......
<?php
/**
* @file
* Contains the iCal row style plugin.
......@@ -54,7 +55,6 @@ class date_ical_plugin_row_ical_feed extends views_plugin_row {
}
function pre_render($values) {
// @TODO When the date is coming in through a relationship, the nid
// of the view is not the right node to use, then we need the related node.
// Need to sort out how that should be handled.
......@@ -91,11 +91,9 @@ class date_ical_plugin_row_ical_feed extends views_plugin_row {
if (array_key_exists($this->language, $substitutions)) {
$this->language = $substitutions[$this->language];
}
}
function render($row) {
global $base_url;
$id = $row->{$this->field_alias};
if (!is_numeric($id)) {
......@@ -183,7 +181,9 @@ class date_ical_plugin_row_ical_feed extends views_plugin_row {
$event['start'] = $start->format($all_day ? DATE_FORMAT_ICAL_DATE : DATE_FORMAT_ICAL);
$event['end'] = $end->format($all_day ? DATE_FORMAT_ICAL_DATE : DATE_FORMAT_ICAL);
$event['description'] = date_ical_escape_text(($item_text));
$event['url'] = url(entity_uri($this->entity_type, $entity), array('absolute' => TRUE));
$uri = entity_uri($this->entity_type, $entity);
$uri['options']['absolute'] = TRUE;
$event['url'] = url($uri['path'], $uri['options']);
$event['uid'] = !empty($entity->date_id) ? $entity->date_id[0] : $event['url'];
$event['rrule'] = $is_field && array_key_exists('rrule', $item) ? $item['rrule'] : '';
......@@ -195,4 +195,3 @@ class date_ical_plugin_row_ical_feed extends views_plugin_row {
));
}
}
......@@ -61,5 +61,4 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style_rss {
unset($this->view->row_index);
return $output;
}
}
\ No newline at end of file
}
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