diff --git a/includes/DateiCalFeedsParser.inc b/includes/DateiCalFeedsParser.inc index 8048fd9efa1f9548556c30b6d272246f4a0b7f01..991bb29490baafae8f9afa490f5f2fced5824db8 100644 --- a/includes/DateiCalFeedsParser.inc +++ b/includes/DateiCalFeedsParser.inc @@ -75,6 +75,7 @@ class DateiCalFeedsParser extends FeedsParser { return array( 'indefinite_count' => $this->config['indefinite_count'], 'until_not_utc' => $this->config['until_not_utc'], + 'skip_days' => $this->config['skip_days'], ); } @@ -85,6 +86,7 @@ class DateiCalFeedsParser extends FeedsParser { return array( 'indefinite_count' => '52', 'until_not_utc' => FALSE, + 'skip_days' => NULL, ); } @@ -108,14 +110,35 @@ class DateiCalFeedsParser extends FeedsParser { $form['until_not_utc'] = array( '#title' => t('RRULE UNTILs are not in UTC'), '#type' => 'checkbox', - '#description' => t('Enable this setting if you\'re seeing reccuring events lose or gain repeat(s) at the end. ' . + '#description' => t('Enable this setting if your reccuring events are not repeating the correct number of times. ' . 'The iCal spec requires that the UNTIL value in an RRULE be specified in UTC, but some iCal feed creators fail to do this ' . - '(the UNTIL values in the feed\'s RRULEs don\'t end is "Z"). This causes the UNTIL value to be off by several hours.'), + '(the UNTIL values in those feeds\' RRULEs don\'t end is "Z"). This causes the UNTIL value to be off by several hours, ' . + 'which can cause the repeat calculator to miss or add repeats.'), '#default_value' => $this->config['until_not_utc'], ); + $form['skip_days'] = array( + '#title' => t('Skip events more than X days old'), + '#type' => 'textfield', + '#size' => 5, + '#description' => t('Set this value to any positive integer (or 0) to skip events which ended more than that many days before the import. ' . + 'Leave it blank to import all events.'), + '#default_value' => $this->config['skip_days'], + ); return $form; } + /** + * Validation handler for configForm. + */ + public function configFormValidate(&$source_config) { + if (!preg_match('/^\d+$/', $source_config['skip_days']) && $source_config['skip_days'] !== '') { + form_set_error('skip_days', 'You must enter a positive integer.'); + } + if ($source_config['skip_days'] === '') { + $source_config['skip_days'] = NULL; + } + } + /** * Creates the list of mapping sources offered by DateiCalFeedsParser. */ diff --git a/libraries/ParserVcalendar.inc b/libraries/ParserVcalendar.inc index 1ef953f556cf03c94587a6b55f5523d53f2e93b1..b0bb3ae2d00bf3f592bb0e9c0b15065719aac40e 100644 --- a/libraries/ParserVcalendar.inc +++ b/libraries/ParserVcalendar.inc @@ -153,7 +153,10 @@ class ParserVcalendar { // Feeds processor. drupal_alter('date_ical_import_post_parse', $this->parsed_data, $context2); - $events[] = $this->parsed_data; + // Skip this event if it's earlier than the user's specified skip time. + if (!$this->_skip_current_event()) { + $events[] = $this->parsed_data; + } // The indices of the original $raw_components array are preserved in // $batch, so using the $ndx value here lets us communicate our progress // through the full collection of components. @@ -474,4 +477,18 @@ class ParserVcalendar { } return $datetimezone; } + + /** + * Internal helper function for skipping old events. + */ + protected function _skip_current_event() { + // Must use !isset() here, because 0 and NULL mean different things. + if (!isset($this->config['skip_days'])) { + return FALSE; + } + $compare_date = isset($this->parsed_data['DTEND']) ? $this->parsed_data['DTEND'] : $this->parsed_data['DTSTART']; + $skip_date = new FeedsDateTime("today -{$this->config['skip_days']} days", $compare_date->getTimezone()); + $skip = ($skip_date > $compare_date); + return $skip; + } }