Commit fda25132 authored by byrond's avatar byrond Committed by Robert Rollins

Issue #2289981: Changed the way exported fields get converted to plaintext.

parent 2fa55376
...@@ -222,29 +222,28 @@ function date_ical_feeds_processor_targets_alter(&$targets, $entity_type, $bundl ...@@ -222,29 +222,28 @@ function date_ical_feeds_processor_targets_alter(&$targets, $entity_type, $bundl
/** /**
* Reformats the provided text to be compliant with the iCal spec. * 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 * If the text contains HTML tags, those tags will be stripped. Paragraph,
* converted to "\n\n" and link tags converted to footnotes), and uneeded * heading, and div tags will be replaced with newlines.
* whitespace will be cleaned up.
* *
* @param string $text * @param string $text
* The text to be sanitized. * The text to be sanitized.
*/ */
function date_ical_sanitize_text($text = '') { function date_ical_sanitize_text($text = '') {
// Use Drupal's built-in HTML to Text converter, which does a mostly // HTML tags may get converted to &lt; and such by the View code, so we need
// adequate job of making the text iCal-compliant. // to convert them back to HTML so we can remove them with strip_tags().
$text = trim(drupal_html_to_text($text)); $text = decode_entities($text);
// Replace instances of more than one space with exactly one space. This
// cleans up the whitespace mess that drupal_html_to_text() leaves behind. // Convert <p> tags to double newlines.
$text = preg_replace("/ +/", " ", $text); $text = trim(preg_replace("/<p.*?>/i", "\n\n", $text));
// The call to drupal_html_to_text() above converted <p> to \n\n, and also // Separate heading tags from the text around them in both directions.
// shoved a \n into the string every 80 characters. We don't want those $text = trim(preg_replace("/<\\?h\d.*?>/i", "\n\n", $text));
// single \n's lying around, because iCalcreator will properly "fold" long // Add a newline for each <div>.
// text fields for us. So, we need to remove all instances of \n which $text = trim(preg_replace("/<div.*?>/i", "\n", $text));
// are neither immediately preceeded, nor followed, by another \n.
// However, \n's which are followed immediately by a > character should // Strip the remaining HTML.
// remain, because of how drupal_html_to_text() converts <blockquote>. $text = strip_tags($text);
$text = preg_replace("/(?<!\n)\n(?![\n\>])/", " ", $text); // Remove newlines added at the beginning.
return $text; return trim($text);
} }
/** /**
......
...@@ -248,7 +248,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -248,7 +248,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
// Make sure this Node Reference actually references a node. // Make sure this Node Reference actually references a node.
if ($location_field['nid']) { if ($location_field['nid']) {
$node = node_load($location_field['nid']); $node = node_load($location_field['nid']);
$location = check_plain($node->title); $location = $node->title;
} }
} }
elseif ($location_info['type'] == 'addressfield') { elseif ($location_info['type'] == 'addressfield') {
...@@ -276,10 +276,10 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -276,10 +276,10 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$location_data[] = $location_field[$included_field]; $location_data[] = $location_field[$included_field];
} }
} }
$location = check_plain(implode(', ', $location_data)); $location = implode(', ', $location_data);
} }
else { else {
$location = check_plain($location_field['value']); $location = $location_field['value'];
} }
} }
} }
...@@ -345,7 +345,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -345,7 +345,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$event['url'] = url($uri['path'], $uri['options']); $event['url'] = url($uri['path'], $uri['options']);
$event['rrule'] = $is_field && array_key_exists('rrule', $date_field) ? $date_field['rrule'] : ''; $event['rrule'] = $is_field && array_key_exists('rrule', $date_field) ? $date_field['rrule'] : '';
if ($location) { if ($location) {
$event['location'] = $location; $event['location'] = date_ical_sanitize_text($location);
} }
// For this event's UID, use either the date_id generated by the Date // For this event's UID, use either the date_id generated by the Date
......
...@@ -226,13 +226,11 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row { ...@@ -226,13 +226,11 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
drupal_alter('date_ical_export_html', $text_fields, $this->view, $context); drupal_alter('date_ical_export_html', $text_fields, $this->view, $context);
// Sanitize the text fields for iCal compliance, and add them to the event. // Sanitize the text fields for iCal compliance, and add them to the event.
// Also strip all HTML from the summary and location fields, since they $event['summary'] = date_ical_sanitize_text($text_fields['summary']);
// must be plaintext, and may have been set as links by the view. $event['location'] = date_ical_sanitize_text($text_fields['location']);
$event['summary'] = date_ical_sanitize_text(strip_tags($text_fields['summary']));
$event['location'] = date_ical_sanitize_text(strip_tags($text_fields['location']));
$event['description'] = date_ical_sanitize_text($text_fields['description']); $event['description'] = date_ical_sanitize_text($text_fields['description']);
// Allow other modules to alter the event object, before it gets passed to // Allow other modules to alter the event object before it gets passed to
// the style plugin to be converted into an iCal VEVENT. // the style plugin to be converted into an iCal VEVENT.
drupal_alter('date_ical_export_raw_event', $event, $this->view, $context); drupal_alter('date_ical_export_raw_event', $event, $this->view, $context);
......
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