function date_ical_sanitize_text in Date iCal 7.3
Same name and namespace in other branches
- 7.2 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. Paragraph, heading, and div tags will be replaced with newlines.
Parameters
string $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 - Renders the entities returned by the view into event arrays.
- date_ical_plugin_row_ical_fields::render in includes/
date_ical_plugin_row_ical_fields.inc - Returns an Event array row in the query with index: $row->index.
File
- ./
date_ical.module, line 224 - Adds ical functionality to Views, and an iCal parser to Feeds.
Code
function date_ical_sanitize_text($text = '') {
// HTML tags may get converted to < and such by the View code, so we need
// to convert them back to HTML so we can remove them with strip_tags().
$text = decode_entities($text);
// Convert <p> tags to double newlines.
$text = trim(preg_replace("/<p.*?>/i", "\n\n", $text));
// Separate heading tags from the text around them in both directions.
$text = trim(preg_replace("/<\\?h\\d.*?>/i", "\n\n", $text));
// Add a newline for each <div>.
$text = trim(preg_replace("/<div.*?>/i", "\n", $text));
// Strip the remaining HTML.
$text = strip_tags($text);
// Remove newlines added at the beginning.
return trim($text);
}