Commit 32126161 authored by Robert Rollins's avatar Robert Rollins

Fixed up loads of issues reported by www.PAReview.sh

parent 1e130962
......@@ -23,10 +23,11 @@ Date iCal has several required dependencies, and an optional one:
- The Feeds module is optional, but it's needed to enable import of iCal feeds
from other sites.
To install the iCalcreator library, download it from http://github.com/iCalcreator/iCalcreator
using either git clone or the "Download Zip" button. Inside you'll find the file
iCalcreator.class.php. Copy that file to a folder in your Drupal site named
sites/all/libraries/iCalcreator.
To install the iCalcreator library, download it from the project's github:
http://github.com/iCalcreator/iCalcreator
Using either git clone or the "Download Zip" button, you'll find the file
iCalcreator.class.php inside. Copy that file to a folder in your Drupal site
named sites/all/libraries/iCalcreator.
Or, if you have drush, install iCalcreator by running this command from your
site's root directory:
......@@ -50,10 +51,10 @@ the iCal Fields plugin is a bit more versatile.
HOW TO EXPORT AN ICAL FEED USING THE iCal Entities PLUGIN
1. Go to the Manage Display page for the content type you want to export in an
1. Go to the Manage Display page for the content type you want to export in an
iCal feed. On the "Default" tab, check the box for "iCal" in the section
titled "Use custom display settings for the following view modes", then click
Save.
titled "Use custom display settings for the following view modes", then
click Save.
2. Click the new "iCal" tab that now appears in the upper-right corner of the
Manage Display page for this content type.
3. Set up the iCal view mode to contain whatever should be exported as the
......@@ -63,10 +64,10 @@ HOW TO EXPORT AN ICAL FEED USING THE iCal Entities PLUGIN
site's iCal feeds.
5. Create a new View that displays the entities that you want to include in the
iCal feed.
6. Add a "Feed" to the view. Change the Format to 'iCal Feed'. When you click
Apply from that dialog, you'll be given the option to name the calendar. This
name will appear in your users' calendar clients as the calendar's title.
7. Change the Show setting to 'iCal Entity' (rather than 'Content' or 'Fields').
6. Add a "Feed" to the view. Change the Format to 'iCal Feed'. When you click
Apply from that dialog, you'll be given the option to name the calendar,
which will appear in your users' calendar clients as the calendar's title.
7. Change the Show setting to 'iCal Entity'.
8. In the settings for iCal Entity, select the date field that should be used
as the event date for the iCal feed. Make sure that you choose a field that
is a part of every entity that your View displays. Otherwise, the entities
......@@ -95,10 +96,10 @@ HOW TO EXPORT AN ICAL FEED USING THE iCal Entities PLUGIN
HOW TO EXPORT AN ICAL FEED USING THE iCal Fields PLUGIN
1-6.These steps are the same as above.
7. Add views fields for each piece of information that you want to populate your
iCal feed with. A Date field is required, and fields that will act as the
Title and Description of the events are reccomended. You can also include a
Location field.
7. Add views fields for each piece of information that you want to populate
your iCal feed with. A Date field is required, and fields that will act as
the Title and Description of the events are reccomended. You can also
include a Location field.
8. Back in the FORMAT section, change the Show setting to 'iCal Fields'.
9. In the settings for iCal Fields, choose which views fields you want to use
for the Date, Title, Description, and Location.
......
......@@ -23,7 +23,7 @@
* - 'summary': The title field string
* - 'location': The location field string.
* @param object $view
* The view object that is being executed to render the iCal feed.
* The view object that is being executed to render the iCal feed.
* @param array $context
* Depending on whether this event is being constructed using the Fields or
* Entity plugins, this context array will have different keys and values.
......@@ -96,7 +96,7 @@ function hook_date_ical_export_raw_event_alter(&$event, $view, $context) {
* @param object $vevent
* A reference to an iCalcreator vevent which will be exported in this feed.
* @param object $view
* The view object that is being executed to render the iCal feed.
* The view object that is being executed to render the iCal feed.
* @param object $event_array
* The array representation of the event that's been rendered to the $vevent.
*/
......@@ -113,7 +113,7 @@ function hook_date_ical_export_vevent_alter(&$vevent, $view, $event_array) {
* @param object $vcalendar
* A reference to the iCalcreator vcalendar object representing this feed.
* @param object $view
* The view object that is being executed to render the iCal feed.
* The view object that is being executed to render the iCal feed.
*/
function hook_date_ical_export_vcalendar_alter(&$vcalendar, $view) {
......@@ -128,7 +128,7 @@ function hook_date_ical_export_vcalendar_alter(&$vcalendar, $view) {
* @param string $rendered_calendar
* A reference to the string containing the rendered the iCal feed.
* @param object $view
* The view that is being executed to render this iCal feed.
* The view that is being executed to render this iCal feed.
*/
function hook_date_ical_export_post_render_alter(&$rendered_calendar, $view) {
......@@ -149,7 +149,7 @@ function hook_date_ical_export_post_render_alter(&$rendered_calendar, $view) {
* - 'fetcher_result': The FeedsFetcherResult object for this Feed.
*/
function hook_date_ical_import_vcalendar_alter(&$calendar, $context) {
}
/**
......@@ -165,14 +165,15 @@ function hook_date_ical_import_vcalendar_alter(&$calendar, $context) {
* - 'fetcher_result': The FeedsFetcherResult object for this Feed.
*/
function hook_date_ical_import_component_alter(&$component, $context) {
// Example of what might be done with this alter hook
// Example of what might be done with this alter hook.
if ($component->objName == 'vevent') {
// Do something for vevents ...
// Do something for vevents...
}
else if ($component->objName == 'valarm') {
// Do something different for valarms ...
elseif ($component->objName == 'valarm') {
// Do something different for valarms...
}
}
/**
* Alter the timezone string from an imported iCal Feed.
*
......
......@@ -5,6 +5,7 @@
* Install, update and uninstall functions for the date_ical module.
*
*/
/**
* Implements hook_requirements().
*/
......@@ -41,7 +42,7 @@ function date_ical_requirements($phase) {
}
/**
* Implementation of hook_enable().
* Implements of hook_enable().
*/
function date_ical_enable() {
cache_clear_all('plugins:feeds:plugins', 'cache');
......@@ -53,6 +54,7 @@ function date_ical_enable() {
/**
* Migrates all iCal feed importers for from Date iCal 2.x to 3.0.
*
* <br>
* PLEASE NOTE: If any of your importers are defined by Features, you'll need
* to update their feature(s) to match.
......@@ -96,7 +98,7 @@ function date_ical_update_7300() {
// parser plugin being missing. We corrected that warning above, so we
// should clear it out to avoid potential confusion.
$messages = drupal_get_messages('warning');
foreach($messages['warning'] as $warning) {
foreach ($messages['warning'] as $warning) {
// Calling drupal_get_messages() removed *every* warning from the
// message queue, so we need to re-issue any warnings that aren't
// about missing Feeds plugins.
......
......@@ -18,7 +18,7 @@ define('DATE_ICAL_VERSION', '3.0-dev');
class DateIcalException extends Exception {}
/**
* Exception for when the date field for a row in the ical_fields row plugin is blank.
* Exception used by iCal Fields for when a date field is blank.
*/
class BlankDateFieldException extends DateIcalException {}
......@@ -76,7 +76,8 @@ function date_ical_theme($existing, $type, $theme, $path) {
}
/**
* The theme for the ical icon.
* Theme function for the ical icon used by attached iCal feed.
*
* Available variables are:
* $variables['tooltip'] - The tooltip to be used for the ican feed icon.
* $variables['url'] - The url to the actual iCal feed.
......@@ -98,18 +99,16 @@ function theme_date_ical_icon($variables) {
}
/**
* Implements hook_preprocess_HOOK() for nodes.
* Implements hook_preprocess_HOOK().
*
* Hide extraneous information when rendering the iCal view mode of a node.
* Hides the page elements which don't belong in an iCal DESCRIPTION element.
* The display of the body and other fields is controlled by the Manage
* Display settings for the nodes' iCal view mode.
*/
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 Manage Display settings for the iCal view mode.
// Trick the default node template into not displaying the page title by
// telling it this is a page.
// Trick the default node template into not displaying the page title, by
// telling it that this *is* a page.
$variables['page'] = TRUE;
$variables['title_prefix'] = '';
$variables['title_suffix'] = '';
......@@ -130,7 +129,8 @@ function date_ical_preprocess_node(&$variables) {
/**
* Implements hook_entity_info_alter().
*
* Add an 'iCal' view mode for entities, which will be used by the Views style plugin.
* Adds an 'iCal' view mode for entities, which is used by the iCal Entity
* View plugin.
*/
function date_ical_entity_info_alter(&$entity_info) {
foreach ($entity_info as $entity_type => $info) {
......@@ -181,9 +181,9 @@ function date_ical_ctools_plugin_api($owner, $api) {
/**
* Implements hook_feeds_processor_targets_alter().
*
* Adds the "Field Name: Repeat Rule" target to Date Repeat Fields.
* Adds the "Field Name: Repeat Rule" target to Date Repeat fields.
*
* @see FeedsNodeProcessor::getMappingTargets().
* @see FeedsNodeProcessor::getMappingTargets()
*/
function date_ical_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
......@@ -201,6 +201,7 @@ function date_ical_feeds_processor_targets_alter(&$targets, $entity_type, $bundl
/**
* Reformats the provided text to be compliant with the iCal spec.
*
* If the text contains HTML tags, those tags will be stripped (with <p> tags
* converted to "\n\n" and link tags converted to footnotes), and uneeded
* whitespace will be cleaned up.
......@@ -209,11 +210,11 @@ function date_ical_feeds_processor_targets_alter(&$targets, $entity_type, $bundl
* The text to be sanitized.
*/
function date_ical_sanitize_text($text = '') {
// Use Drupal's built-in HTML to Text converter, which does a mostly adequate
// job of making the text iCal-compliant.
// Use Drupal's built-in HTML to Text converter, which does a mostly
// adequate job of making the text iCal-compliant.
$text = trim(drupal_html_to_text($text));
// Replace instances of more than one space with exactly one space. This
// cleans up the whitespace mess that gets left behind by drupal_html_to_text().
// cleans up the whitespace mess that drupal_html_to_text() leaves behind.
$text = preg_replace("/ +/", " ", $text);
// The call to drupal_html_to_text() above converted <p> to \n\n, and also
// shoved a \n into the string every 80 characters. We don't want those
......@@ -227,14 +228,14 @@ function date_ical_sanitize_text($text = '') {
/**
* Callback specified in date_ical_feeds_processor_targets_alter() for RRULEs.
*
* @param $source
* @param object $source
* The FeedsSource object.
* @param $entity
* @param object $entity
* The node that's being built from the iCal element that's being parsed.
* @param $target
* @param string $target
* The machine name of the field into which this RRULE shall be parsed,
* with ":rrule" appended to the end.
* @param $feed_element
* @param string $feed_element
* The RRULE string (with optional EXDATEs and RDATEs separated by \n).
*/
function date_ical_feeds_set_rrule($source, $entity, $target, $feed_element) {
......@@ -247,7 +248,8 @@ function date_ical_feeds_set_rrule($source, $entity, $target, $feed_element) {
module_load_include('inc', 'date_api', 'date_api_ical');
$info = field_info_field($field_name);
foreach ($entity->{$field_name} as $lang => $field_array) {
// Add the multiple date values that Date Repeat Field uses to represent recurring dates.
// Add the multiple date values that Date Repeat Field uses to represent
// recurring dates.
$values = date_repeat_build_dates($feed_element, NULL, $info, $field_array[0]);
foreach ($values as $key => $value) {
$entity->{$field_name}[$lang][$key] = $value;
......@@ -256,7 +258,7 @@ function date_ical_feeds_set_rrule($source, $entity, $target, $feed_element) {
}
/**
* Identify all potential fields that could populate the optional LOCATION component of iCal output.
* Identify all potential fields which could be used as an iCal LOCATION.
*/
function date_ical_get_location_fields($base = 'node', $reset = FALSE) {
static $fields = array();
......@@ -276,15 +278,15 @@ function date_ical_get_location_fields($base = 'node', $reset = FALSE) {
}
/**
* Identify all potential LOCATION fields.
* This is a cut down version of _date_views_fields() from date_views_fields.inc
* in date_views module.
* Internal helper function for date_ical_get_location_fields().
*
* This is a cut down version of _date_views_fields() from
* date_views_fields.inc in date_views module.
*
* @return
* array with fieldname, type, and table.
*
* @return
* array with fieldname, type, and table.
* @see
* date_views_date_views_fields(), which implements hook_date_views_fields()
* for the core date fields.
* @see date_views_date_views_fields()
*/
function _date_ical_get_location_fields($base = 'node') {
// Make sure $base is never empty.
......@@ -307,7 +309,14 @@ function _date_ical_get_location_fields($base = 'node') {
// Skip unsupported field types and fields that weren't defined through
// the Field module.
$info = field_info_field($field_name);
if (!$info || !in_array($info['type'], array('text', 'text_long', 'text_with_summary', 'node_reference', 'addressfield'))) {
$supported_location_fields = array(
'text',
'text_long',
'text_with_summary',
'node_reference',
'addressfield',
);
if (!$info || !in_array($info['type'], $supported_location_fields)) {
continue;
}
......@@ -333,7 +342,7 @@ function _date_ical_get_location_fields($base = 'node') {
/**
* Identify all potential fields that could populate the custom SUMMARY field
* Identify all potential fields which could be used as an iCal SUMMARY.
*/
function date_ical_get_summary_fields($base = 'node', $reset = FALSE) {
static $fields = array();
......@@ -353,15 +362,15 @@ function date_ical_get_summary_fields($base = 'node', $reset = FALSE) {
}
/**
* Identify all potential SUMMARY fields.
* This is a cut down version of _date_views_fields() from date_views_fields.inc
* in date_views module.
* Internal helper function for date_ical_get_summary_fields().
*
* This is a cut down version of _date_views_fields() from
* date_views_fields.inc in date_views module.
*
* @return
* Array with fieldname, type, and table.
*
* @return
* array with fieldname, type, and table.
* @see
* date_views_date_views_fields(), which implements hook_date_views_fields()
* for the core date fields.
* @see date_views_date_views_fields()
*/
function _date_ical_get_summary_fields($base = 'node') {
// Make sure $base is never empty.
......@@ -384,7 +393,14 @@ function _date_ical_get_summary_fields($base = 'node') {
// Skip unsupported field types and fields that weren't defined through
// the Field module.
$info = field_info_field($field_name);
if (!$info || !in_array($info['type'], array('text', 'text_long', 'text_with_summary', 'node_reference', 'taxonomy_term_reference'))) {
$supported_summary_fields = array(
'text',
'text_long',
'text_with_summary',
'node_reference',
'taxonomy_term_reference',
);
if (!$info || !in_array($info['type'], $supported_summary_fields)) {
continue;
}
......@@ -407,3 +423,38 @@ function _date_ical_get_summary_fields($base = 'node') {
cache_set($cid, $fields, 'cache_views');
return $fields;
}
/**
* Convert an rrule array to the iCalcreator format.
*
* iCalcreator expects the BYDAY element to be an array like this:
* (array) ( [([plus] ordwk / minus ordwk)], "DAY" => weekday )
*
* But the way that the Date API gives it to us is like this:
* (array) ( [([plus] ordwk / minus ordwk)]weekday )
*/
function _date_ical_convert_rrule_for_icalcreator($rrule) {
$new_rrule = array();
foreach ($rrule as $key => $value) {
if (strtoupper($key) == 'DATA') {
// iCalcreator doesn't expect the 'DATA' key that the Date API gives us.
continue;
}
if (strtoupper($key) == 'UNTIL') {
// iCalcreator expects the 'timestamp' to be array key for UNTIL
$value['timestamp'] = strtotime($value['datetime']);
}
if (strtoupper($key) == 'BYDAY') {
$new_byday = array();
foreach ($value as $day) {
// Fortunately, the weekday values are always 2 characters.
$weekday = substr($day, -2);
$ordwk = substr($day, 0, -2);
$new_byday[] = array($ordwk, 'DAY' => $weekday);
}
$value = $new_byday;
}
$new_rrule[$key] = $value;
}
return $new_rrule;
}
<?php
/**
* @file
* DateiCalFeedsParser is Date iCal's Feeds parser plugin.
* DateiCalFeedsParser is Date iCal's Feeds parser plugin.
*/
class DateiCalFeedsParser extends FeedsParser {
......@@ -44,7 +43,7 @@ class DateiCalFeedsParser extends FeedsParser {
// We've got a vcalendar object created from the feed data. Now we need to
// convert that vcalendar into an array of Feeds-compatible data arrays.
// ParserVcalendar->parse() does that.
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'date_ical') . '/libraries/ParserVcalendar.inc');
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'date_ical') . '/libraries/ParserVcalendar.inc';
$parser = new ParserVcalendar($calendar, $source, $fetcher_result, $source->getConfigFor($this));
// Using the stored progress pointer (or 0 if it's not set),
......@@ -103,8 +102,6 @@ class DateiCalFeedsParser extends FeedsParser {
/**
* Creates the list of mapping sources offered by DateiCalFeedsParser.
*
* @return array
*/
public static function getiCalMappingSources() {
$sources = array();
......
......@@ -6,25 +6,30 @@
*/
/**
* Plugin which creates a view on the resulting object
* and formats it as an iCal VEVENT.
* A Views plugin which builds an iCal VEVENT from a single node.
*/
class date_ical_plugin_row_ical_entity extends views_plugin_row {
// Basic properties that let the row style follow relationships.
var $base_table = 'node';
var $base_field = 'nid';
protected $base_table = 'node';
protected $base_field = 'nid';
// Stores the nodes loaded with pre_render.
var $entities = array();
protected $entities = array();
function init(&$view, &$display, $options = NULL) {
/**
* Initialize the row plugin.
*/
public function init(&$view, &$display, $options = NULL) {
parent::init($view, $display, $options);
$this->base_table = $view->base_table;
$this->base_field = $view->base_field;
}
function option_definition() {
/**
* Set up the options for the row plugin.
*/
public function option_definition() {
$options = parent::option_definition();
$options['date_field'] = array('default' => array());
$options['summary_field'] = array('default' => array());
......@@ -33,17 +38,18 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
}
/**
* Provide a form for setting options.
* Build the form for setting the row plugin's options.
*/
function options_form(&$form, &$form_state) {
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// Build the select dropdown for the date field that the user wants to use
// to populate the date fields in VEVENTs.
// Build the select dropdown for the Date field that the user wants to use
// to populate the date properties in VEVENTs.
$data = date_views_fields($this->base_table);
$options = array();
foreach ($data['name'] as $item => $value) {
// We only want to see one value for each field, skip '_value2', and other columns.
// We only want to see one value for each field, so we need to
// skip '_value2' and other columns.
if ($item == $value['fromto'][0]) {
$options[$item] = $value['label'];
}
......@@ -58,7 +64,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
'#required' => TRUE,
);
$form['instructions'] = array(
// The surrounding <div> is necessary to ensure that the settings dialog expands to show everything.
// The surrounding <div> ensures that the settings dialog expands.
'#prefix' => '<div style="font-size: 90%">',
'#suffix' => '</div>',
'#markup' => t("Each item's Title and iCal view mode will be included as the SUMMARY and DESCRIPTION elements (respectively) in the VEVENTs output by this View.
......@@ -101,18 +107,21 @@ class date_ical_plugin_row_ical_entity 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.
/**
* Preload the list of entities which will appear in the view.
*
* @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.
*/
public function pre_render($values) {
// Preload each entity used in this view from the cache.
// Provides all the entity values relatively cheaply, and we don't
// need to do it repeatedly for the same entity if there are
// multiple results for one entity.
$ids = array();
foreach ($values as $row) {
// Use the $id as the key so we don't create more than one value per entity.
// Use the $id as the key so we create only value per entity.
$id = $row->{$this->field_alias};
// Node revisions need special loading.
......@@ -140,8 +149,10 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
}
}
function render($row) {
global $base_url;
/**
* Renders the entities returned by the view into event arrays.
*/
public function render($row) {
$id = $row->{$this->field_alias};
if (!is_numeric($id)) {
return NULL;
......@@ -157,20 +168,17 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$date_fields = date_views_fields($this->base_table);
$date_info = $date_fields['name'][$this->options['date_field']];
$field_name = str_replace(array('_value', '_value2'), '', $date_info['real_field_name']);
$table_name = $date_info['table_name'];
$delta_field = $date_info['delta_field'];
$is_field = $date_info['is_field'];
// This is ugly and hacky but I can't figure out any generic way to
// recognize that the node module is going to give some the revision timestamp
// a different field name on the entity than the actual column name in the database.
// Sometimes the timestamp is actually the revision timestamp.
if ($this->view->base_table == 'node_revision' && $field_name == 'timestamp') {
$field_name = 'revision_timestamp';
}
if (!isset($entity->$field_name)) {
// This entity doesn't have the date property that the user configured
// our view to use. We can't do anything with it
// our view to use. We can't do anything with it.
return NULL;
}
$date_field = $entity->$field_name;
......@@ -193,7 +201,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
if (!empty($date_field['value'])) {
$start = new DateObject($date_field['value'], $date_field['timezone_db']);
if (array_key_exists('value2', $date_field)) {
if (!empty($date_field['value2'])) {
$end = new DateObject($date_field['value2'], $date_field['timezone_db']);
}
else {
......@@ -244,7 +252,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
}
elseif ($location_info['type'] == 'addressfield') {
$locations = array();
foreach($location_field as $key => $loc) {
foreach ($location_field as $key => $loc) {
if ($loc && !in_array($key, array('first_name', 'last_name'))) {
$locations[] = $loc;
}
......@@ -257,11 +265,12 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
}
}
// Create the rendered display using the display settings from the 'iCal' view mode.
// Create the rendered event using the display settings from the
// iCal view mode.
$rendered_array = entity_view($this->entity_type, array($entity), 'ical', $this->language, TRUE);
$data = array(
'description' => drupal_render($rendered_array),
'summary' => entity_label($this->entity_type, $entity)
'summary' => entity_label($this->entity_type, $entity),
);
if (!empty($this->options['summary_field']) && $this->options['summary_field'] != 'default_title') {
$summary_fields = date_ical_get_summary_fields();
......@@ -281,7 +290,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
}
elseif ($summary_info['type'] == 'taxonomy_term_reference') {
$terms = taxonomy_term_load_multiple($items);
// Make sure that there are terms that were loaded
// Make sure that there are terms that were loaded.
if ($terms) {
$term_names = array();
foreach ($terms as $term) {
......@@ -293,7 +302,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
else {
$summary = trim($summary_field['value']);
}
$data['summary'] = $summary ? $summary : $data['summary'];
$data['summary'] = $summary ? $summary : $data['summary'];
}
}
// Allow other modules to alter the HTML of the Summary and Description,
......@@ -320,8 +329,8 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$event['location'] = $location;
}
// For this event's UID, use either the date_id generated by the Date module, or the
// event page's URL, if the date_id isn't available.
// For this event's UID, use either the date_id generated by the Date
// module, or the event page's URL if the date_id isn't available.
$event['uid'] = !empty($entity->date_id) ? $entity->date_id[0] : $event['url'];
// If we are using a repeat rule (and not just multi-day events) we
......@@ -342,7 +351,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
if (isset($entity->changed)) {
$event['last-modified'] = new DateObject($entity->changed, 'UTC');
}
else if (isset($entity->created)) {
elseif (isset($entity->created)) {
// If changed is unset, but created is, use that for last-modified.
$event['last-modified'] = new DateObject($entity->created, 'UTC');
}
......
......@@ -6,12 +6,14 @@
*/
/**
* Plugin which creates a view on the resulting object
* and formats it as an iCal VEVENT.
* A Views plugin which builds an iCal VEVENT from a views row with Fields.
*/
class date_ical_plugin_row_ical_fields extends views_plugin_row {
function option_definition() {
/**
* Set up the options for the row plugin.
*/
public function option_definition() {
$options = parent::option_definition();
$options['date_field'] = array('default' => '');
$options['title_field'] = array('default' => '');
......@@ -21,7 +23,10 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
return $options;
}
function options_form(&$form, &$form_state) {
/**
* Build the form for setting the row plugin's options.
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$all_field_labels = $this->display->handler->get_field_labels();
$date_field_labels = $this->get_date_field_candidates($all_field_labels);
......@@ -29,7 +34,7 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
$text_field_label_options = array_merge(array('' => t('- None -')), $all_field_labels);
$form['instructions'] = array(
// The surrounding <div> is necessary to ensure that the settings dialog expands to show everything.
// The surrounding <div> ensures that the settings dialog expands.
'#prefix' => '<div style="font-size: 90%">',
'#suffix' => '</div>',
'#markup' => t("Once you've finished setting up the fields for this View, you may want to return to this dialog to set the Date field."),
......@@ -84,7 +89,10 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
);
}
function pre_render($result) {
/**
* Set up the environment for the render() function.
*/
public function pre_render($result) {
// Get the language for this view.
$this->language = $this->display->handler->get_option('field_language');
$substitutions = views_views_query_substitutions($this->view);
......@@ -95,10 +103,9 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
}
/**
* Returns an Event array based on the query result from the view whose
* index is $row->index.
* Returns an Event array row in the query with index: $row->index.
*/
function render($row) {
public function render($row) {
$date_field_name = $this->options['date_field'];
// If this view is set to use the first populated date field, check each
......@@ -153,7 +160,7 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
if (isset($entity->changed)) {
$event['last-modified'] = new DateObject($entity->changed, 'UTC');
}
else if (isset($entity->created)) {
elseif (isset($entity->created)) {
// If changed is unset, but created is, use that for last-modified.
$event['last-modified'] = new DateObject($entity->created, 'UTC');
}
......@@ -238,8 +245,8 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
*
* @return array
* The normalized array.
*/
function get_row_date($row, $date_field_name) {
*/
protected function get_row_date($row, $date_field_name) {
$start = NULL;
$end = NULL;
$rrule = NULL;
......@@ -315,24 +322,27 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
}
/**
* Filter the list of views fields down to only those which are supported date-type fields.
* At this time, the supported date-type fields are timestamps and the three Date fields.
* Filter the list of views fields down to only supported date-type fields.
*
* The supported date-type fields are timestamps and the three Date fields.
*
* @param array $view_fields
* An key=>value array @see views_plugin_display::get_field_labels().
* An associative array like views_plugin_display::get_field_labels().
*
* @return array
* An key=>value array (alias => label) of date fields.
* An associative array (alias => label) of date fields.
*/
function get_date_field_candidates($view_fields) {
protected function get_date_field_candidates($view_fields) {
$handlers = $this->display->handler->get_handlers('field');
$field_candidates = array();
// These are Date, Date (ISO format), and Date (Unix timestamp).
$date_fields = array('datetime', 'date', 'datestamp');
foreach ($view_fields as $alias => $label) {
$handler = $handlers[$alias];
if (get_class($handler) == 'views_handler_field_date'
|| (get_class($handler) == 'views_handler_field_field' &&
// These are Date, Date (ISO format), and Date (Unix timestamp).