Commit 0b6a73ad authored by Robert Rollins's avatar Robert Rollins

Applied patch #11 from [#1922658] to get around iCalcreator limitation with...

Applied patch #11 from [#1922658] to get around iCalcreator limitation with stream wrappers. Also made the amount of whitespace on blank lines consistent throughout the project.
parent 3fb327ec
......@@ -148,7 +148,7 @@ function hook_date_ical_icalcreator_component_alter(&$component, &$context) {
function hook_date_ical_feeds_object_alter(&$value, &$context) {
// Example of what might be done with this alter hook
if ($context['property_key'] == 'dtstart') {
// Tweak the parsed FeedsDateTime object for the start time.
// Tweak the parsed FeedsDateTime object created from the start time.
// ...
}
}
......@@ -10,10 +10,10 @@
*/
function date_ical_requirements($phase) {
$requirements = array();
// Ensure translations don't break at install time
$t = get_t();
switch ($phase) {
case 'runtime':
if (($library = libraries_detect('iCalcreator')) && !empty($library['installed'])) {
......@@ -33,7 +33,7 @@ function date_ical_requirements($phase) {
}
break;
}
return $requirements;
}
......
......@@ -57,10 +57,10 @@ function date_ical_preprocess_node(&$variables) {
$variables['page'] = TRUE;
$variables['title_prefix'] = '';
$variables['title_suffix'] = '';
// We don't want to see the author information in our feed.
$variables['display_submitted'] = FALSE;
// Comments and links don't belong in an iCal feed.
if (isset($variables['content']['comments'])) {
unset($variables['content']['comments']);
......@@ -107,7 +107,7 @@ function date_ical_libraries_info() {
'php' => array('iCalcreator.class.php'),
),
);
return $libraries;
}
......@@ -209,17 +209,16 @@ function date_ical_feeds_set_rrule($source, $entity, $target, $feed_element) {
* giving up completely.
*/
function date_ical_build_repeating_dates($rrule = NULL, $rrule_values = NULL, $field, $item) {
module_load_include('inc', 'date_api', 'date_api_ical');
$field_name = $field['field_name'];
if (empty($rrule)) {
$rrule = date_api_ical_build_rrule($rrule_values);
}
elseif (empty($rrule_values)) {
$rrule_values = date_ical_parse_rrule(NULL, $rrule);
}
// By the time we get here, the start and end dates have been
// adjusted back to UTC, but we want localtime dates to do
// things like '+1 Tuesday', so adjust back to localtime.
......@@ -240,7 +239,7 @@ function date_ical_build_repeating_dates($rrule = NULL, $rrule_values = NULL, $f
}
$duration = $start->difference($end);
$start_datetime = date_format($start, DATE_FORMAT_DATETIME);
if (!empty($rrule_values['UNTIL']['datetime'])) {
$end = date_ical_date($rrule_values['UNTIL'], $timezone);
$end_datetime = date_format($end, DATE_FORMAT_DATETIME);
......@@ -255,7 +254,7 @@ function date_ical_build_repeating_dates($rrule = NULL, $rrule_values = NULL, $f
$rrule = substr_replace($rrule, 'COUNT=52;', 6, 0);
$end_datetime = NULL;
}
// Split the RRULE into RRULE, EXDATE, and RDATE parts.
$parts = date_repeat_split_rrule($rrule);
$parsed_exceptions = (array) $parts[1];
......@@ -264,14 +263,14 @@ function date_ical_build_repeating_dates($rrule = NULL, $rrule_values = NULL, $f
$date = date_ical_date($exception, $timezone);
$exceptions[] = date_format($date, 'Y-m-d');
}
$parsed_rdates = (array) $parts[2];
$additions = array();
foreach ($parsed_rdates as $rdate) {
$date = date_ical_date($rdate, $timezone);
$additions[] = date_format($date, 'Y-m-d');
}
$dates = date_repeat_calc($rrule, $start_datetime, $end_datetime, $exceptions, $timezone, $additions);
$value = array();
foreach ($dates as $delta => $date) {
......@@ -301,7 +300,7 @@ function date_ical_build_repeating_dates($rrule = NULL, $rrule_values = NULL, $f
function date_ical_get_location_fields($base = 'node', $reset = FALSE) {
static $fields = array();
$empty = array('name' => array(), 'alias' => array());
if (empty($fields[$base]) || $reset) {
$cid = 'date_ical_location_fields_' . $base;
if (!$reset && $cached = cache_get($cid, 'cache_views')) {
......
......@@ -20,7 +20,7 @@ abstract class DateIcalFeedsParser extends FeedsParser {
* );
*/
static protected $sources;
/**
* Implementation of FeedsParser::getMappingSources().
*/
......@@ -39,7 +39,7 @@ abstract class DateIcalFeedsParser extends FeedsParser {
// Call parent::getMappingSources() to trigger additional target creation.
return $sources + parent::getMappingSources();
}
/**
* Override FeedsParser::getSourceElement().
*/
......@@ -48,7 +48,7 @@ abstract class DateIcalFeedsParser extends FeedsParser {
if (substr($property_key, 0, 7) == 'parent:') {
return parent::getSourceElement($source, $result, $property_key);
}
// Otherwise retrieve the current DateIcalComponent from the DateIcalParserResult.
if ($item = $result->currentItem()) {
if ($position = strpos($property_key, ':')) {
......@@ -82,7 +82,7 @@ interface DateIcalComponentInterface {
class DateIcalParserResult extends FeedsParserResult {
// Feed extension timezone (X-WR-TIMEZONE)
public $timezone;
// Feed RFC 5545 timezones; we can't use these at
// present, only PHP timezonedb tz will be actually recognized.
// So this is more here as reminder/explanation.
......
......@@ -70,7 +70,7 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
'date_ical_parse_handler' => 'formatCategories',
),
);
/**
* Load and run parser implementation of FeedsParser::parse().
*
......@@ -78,19 +78,20 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
*/
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
self::loadLibrary();
// Get the path to the temporary file created by the feed download.
$filename = $fetcher_result->getFilePath();
$config = $source->getConfig();
//
// Create the calendar object and parse the file.
//
$config = array(
'unique_id' => '', // do we need one for incoming parsing?
'url' => $filename, // it's a stream wrapper, so url
'filename' => $config['FeedsHTTPFetcher']['source'],
);
$calendar = new vcalendar($config);
if (!$calendar->parse()) {
if (!$calendar->parse($fetcher_result->getRaw())) {
throw new DateIcalParseException(t('Error parsing %source iCal file %file', array('%source' => 'todo', '%file' => $filename)));
}
......@@ -105,14 +106,14 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
// Set a result object.
//
$result = new DateIcalParserResult();
// FeedsResult properties
$xcalname = $calendar->getProperty('X-WR-CALNAME');
$result->title = !empty($xcalname) ? $xcalname[1] : '';
$xcaldesc = $calendar->getProperty('X-WR-CALDESC');
$result->description = !empty($xcaldesc) ? $xcaldesc[1] : '';
$result->link = NULL;
// Additional DateIcalParserResult properties
$xtimezone = $calendar->getProperty('X-WR-TIMEZONE');
if (!empty($xtimezone)) {
......@@ -130,7 +131,7 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
$components[$component->getProperty('tzid')] = new DateIcalIcalcreatorComponent($component);
}
$result->timezones = $components;
// Separate the individual feed items into DateIcalIcalcreatorComponent objects, to be treated as
// separate parsed elements.
$components = array();
......@@ -152,16 +153,16 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
}
}
$result->items = $components;
return $result;
}
/******
* Source output formatters.
*
* Could be in a class of their own?
**/
/**
* Format text fields.
*
......@@ -174,7 +175,7 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
// Allow modules to alter the text before it's mapped to the target.
drupal_alter('date_ical_feeds_object', $text, $context);
return $text;
}
......@@ -192,10 +193,10 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
// Allow modules to alter the param text before it's mapped to the target.
drupal_alter('date_ical_feeds_object', $text, $context);
return $text;
}
/**
* Format date fields.
*
......@@ -209,7 +210,7 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
if (isset($property['params']['TZID'])) {
$date_array['tz'] = $property['params']['TZID'];
}
if (isset($property['params']['VALUE']) && $property['params']['VALUE'] == 'DATE') {
/**
* DATE values are All Day events, with no time-of-day.
......@@ -227,12 +228,12 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
$start_array['tz'] = $start_prop['params']['TZID'];
}
// On single-day All Day events (the start date + 1 = the end date), just ignore the DTEND
// if the Date All Day module is installed. Otherwise it'll be displayed strangely.
if ($start_array['year'] == $date_array['year']
&& $start_array['month'] == $date_array['month']
&& $start_array['day'] + 1 == $date_array['day']
&& module_exists('date_all_day')) {
// On single-day All Day events (the start date + 1 = the end date), just ignore the DTEND
// if the Date All Day module is installed. Otherwise it'll be displayed strangely.
return;
}
}
......@@ -262,10 +263,14 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
else {
// Date with time.
$date_string = iCalUtilityFunctions::_format_date_time($date_array);
$tz = NULL;
if (isset($date_array['tz'])) {
$tz = $date_array['tz'];
// 'Z' == 'Zulu' == 'UTC'. DateTimeZone won't acept Z, so change it to UTC.
if (strtoupper($date_array['tz']) == 'Z') {
$date_array['tz'] = 'UTC';
}
$tz = new DateTimeZone($date_array['tz']);
}
else {
// If there was no timezone in the date array itself, add one if we have one.
......@@ -301,7 +306,7 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
return $parsed_datetime;
}
/**
* Format Categories
*
......@@ -351,7 +356,7 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
$rdate = $item->getRdate();
return trim("$rrule\n$exdate\n$rdate");
}
/**
* Load the iCalcreator library.
*/
......@@ -367,7 +372,7 @@ class DateIcalIcalcreatorParser extends DateIcalFeedsParser {
class DateIcalIcalcreatorComponent implements DateIcalComponentInterface {
protected $component;
private $_serialized_component;
/**
* Constructor.
*
......@@ -377,7 +382,7 @@ class DateIcalIcalcreatorComponent implements DateIcalComponentInterface {
public function __construct(calendarComponent $component) {
$this->component = $component;
}
/**
* Serialization helper.
*/
......@@ -385,7 +390,7 @@ class DateIcalIcalcreatorComponent implements DateIcalComponentInterface {
$this->_serialized_component = serialize($this->component);
return array('_serialized_component');
}
/**
* Unserialization helper.
*/
......@@ -393,15 +398,15 @@ class DateIcalIcalcreatorComponent implements DateIcalComponentInterface {
DateIcalIcalcreatorParser::loadLibrary();
$this->component = unserialize($this->_serialized_component);
}
public function getComponentType() {
return $this->component->objName;
}
public function getProperty($name) {
return $this->component->getProperty($name, FALSE, TRUE);
}
// $args should be an array of arguments to be sent to the set$Name()
// function of calendarComponent. If $args is not an array, it'll be
// wrapped as one. This is necessary because the iCalcreator API has different
......@@ -424,7 +429,7 @@ class DateIcalIcalcreatorComponent implements DateIcalComponentInterface {
public function getRrule() {
return trim($this->component->createRrule());
}
public function setRdate($rdate) {
return $this->component->rdate[0] = $rdate;
}
......
......@@ -10,7 +10,7 @@
*/
function date_ical_views_plugins() {
$includes_path = drupal_get_path('module', 'date_ical') . '/includes';
$data = array(
'module' => 'date_ical', // This just tells our themes are elsewhere.
'style' => array(
......
......@@ -84,7 +84,7 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
$rows[] = $this->row_plugin->render($row);
}
unset($this->view->row_index);
// Try to load the iCalcreator library, and check if that worked.
$library = libraries_load('iCalcreator');
if (!empty($library['loaded'])) {
......@@ -110,7 +110,7 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
if (!$this->_get_option('no_calname')) {
$vcalendar->setProperty('x-wr-calname', $cal_name, array('VALUE' => 'TEXT'));
}
// Now add the VEVENTs.
$timezones = array();
foreach ($rows as $row) {
......@@ -141,10 +141,10 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
$start['second'],
$timezone);
}
// Add the Timezone info to the start date, for use later.
$start['tz'] = $row['start']->getTimezone();
// Only add the end date if there is one.
if (!empty($row['end'])) {
$end = $row['end']->toArray();
......@@ -170,7 +170,7 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
}
$vevent->setProperty('uid', $row['uid']);
$vevent->setProperty('summary', $row['summary']);
// Handle repeating dates from the date_repeat module.
if (!empty($row['rrule']) && module_exists('date_repeat')) {
// Split the rrule into the actual rule, exceptions and additions.
......@@ -207,7 +207,7 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
$add = date_ical_date($addition, 'UTC');
date_timezone_set($add, $start['tz']);
$addition_array = $add->toArray();
$add_date = array(
'year' => $addition_array['year'],
'month' => $addition_array['month'],
......@@ -232,7 +232,7 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
'tz' => $end['tz']->getName(),
);
}
$add_dates[] = $add_date;
}
// Add the additions as 'RDATE's.
......@@ -264,15 +264,15 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
// Allow other modules to alter the VEVENT object.
drupal_alter('date_ical_feed_ical_vevent_render', $vevent, $this->view, $row);
}
// Now add all the timezones we just used to the calendar.
foreach ($timezones as $timezone) {
iCalUtilityFunctions::createTimezone($vcalendar, $timezone);
}
// Allow other modules to alter the calendar as a whole.
drupal_alter('date_ical_feed_ical_vcalendar_render', $vcalendar, $this->view);
$output = $vcalendar->createCalendar();
}
else {
......@@ -327,7 +327,6 @@ class date_ical_plugin_style_ical_feed extends views_plugin_style {
}
$value = $new_byday;
}
$new_rrule[$key] = $value;
}
return $new_rrule;
......
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