function date_ical_sanitize_text in Date iCal 7.2
Same name and namespace in other branches
- 7.3 date_ical.module \date_ical_sanitize_text()
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.
Parameters
$text: The text to be sanitized.
2 calls to date_ical_sanitize_text()
- date_ical_plugin_row_ical_entity::render in includes/
date_ical_plugin_row_ical_entity.inc - Render a row object. This usually passes through to a theme template of some form, but not always.
- date_ical_plugin_row_ical_fields::render in includes/
date_ical_plugin_row_ical_fields.inc - Returns an Event array based on the query result from the view whose index is specified in the (hidden) second parameter of this function.
File
- ./
date_ical.module, line 205 - Adds ical functionality to Views, and an iCal parser to Feeds.
Code
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.
$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().
$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
// single \n's lying around, because iCalcreator will properly "fold" long
// text fields for us. So, we need to remove all instances of \n which
// are neither immediately preceeded, nor followed, by another \n.
$text = preg_replace("/(?<!\n)\n(?!\n)/", " ", $text);
return $text;
}