function _htmlpurifier_process_text in HTML Purifier 7.2
Same name and namespace in other branches
- 7 htmlpurifier.module \_htmlpurifier_process_text()
Processes HTML according to a format and returns purified HTML. Makes a cache pass if possible.
@note We ignore $delta because the only difference it makes is in the configuration screen.
Parameters
string $text: Text to purify
object $filter: The filter object containing settings for the given format.
object $format: The format object of the text to be filtered.
string $langcode: The language code of the text to be filtered.
boolean $cache: Whether or not to check the cache.
2 calls to _htmlpurifier_process_text()
- _htmlpurifier_process in ./
htmlpurifier.module - Process callback, used by htmlpurifier_filter_info().
- _htmlpurifier_settings in ./
htmlpurifier.module - Generates a settings form for configuring HTML Purifier.
File
- ./
htmlpurifier.module, line 443 - Implements HTML Purifier as a Drupal filter.
Code
function _htmlpurifier_process_text($text, $filter, $format, $langcode, $cache = TRUE) {
// No need to run the filter if there isn't anything to filter
// See https://drupal.org/node/1821178
if ($text === '') {
return '';
}
$return = $text;
$htmlpurifier_library = libraries_load('htmlpurifier');
if ($htmlpurifier_library['installed']) {
if ($cache) {
$cid = $format->format . ':' . $langcode . ':' . hash('sha256', $text);
$old = cache_get($cid, 'cache_htmlpurifier');
if ($old) {
return $old->data;
}
}
$config_name = isset($filter->settings['htmlpurifier_config_name']) ? $filter->settings['htmlpurifier_config_name'] : 'htmlpurifier_basic';
$config = _htmlpurifier_get_config($format->format, $config_name);
$purifier = new HTMLPurifier($config);
$return = $purifier
->purify($text);
// If using Filter.ExtractStyleBlocks we need to handle the CSSTidy output
if ($config
->get('Filter.ExtractStyleBlocks') == TRUE) {
libraries_load('csstidy');
// We're only going to bother if we're caching! - no caching? no style blocks!
if ($cache) {
// Get style blocks, cache them, and help hook_nodeapi find the cache
$styles = $purifier->context
->get('StyleBlocks');
cache_set('css:' . $cid, $styles, 'cache_htmlpurifier', CACHE_PERMANENT);
$return = '<!-- HTML Purifier Cache #' . $cid . ' -->' . $return;
}
}
if ($cache) {
cache_set($cid, $return, 'cache_htmlpurifier', CACHE_PERMANENT);
static $done = FALSE;
$done = TRUE;
}
}
else {
drupal_set_message($htmlpurifier_library['error message'], 'error', FALSE);
}
return $return;
}