function _htmlpurifier_process in HTML Purifier 6.2
Same name and namespace in other branches
- 6 htmlpurifier.module \_htmlpurifier_process()
- 7.2 htmlpurifier.module \_htmlpurifier_process()
- 7 htmlpurifier.module \_htmlpurifier_process()
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
int $format: Input format corresponding to HTML Purifier's configuration.
boolean $cache: Whether or not to check the cache.
2 calls to _htmlpurifier_process()
- htmlpurifier_filter in ./
htmlpurifier.module - Implementation of hook_filter().
- _htmlpurifier_settings in ./
htmlpurifier.module - Generates a settings form for configuring HTML Purifier.
File
- ./
htmlpurifier.module, line 217 - Implements HTML Purifier as a Drupal filter.
Code
function _htmlpurifier_process($text, $format, $cache = TRUE) {
if ($cache) {
$cid = $format . ':' . md5($text);
$old = cache_get($cid, 'cache_htmlpurifier');
if ($old) {
return $old->data;
}
}
_htmlpurifier_load();
$config = _htmlpurifier_get_config($format);
// If ExtractStyleBlocks is enabled, we'll need to do a bit more for CSSTidy
$config_extractstyleblocks = $config
->get('Filter.ExtractStyleBlocks');
// Maybe this works if CSSTidy is at root? CSSTidy could be other places though
if ($config_extractstyleblocks == true) {
_htmlpurifier_load_csstidy();
}
$purifier = new HTMLPurifier($config);
$ret = $purifier
->purify($text);
// If using Filter.ExtractStyleBlocks we need to handle the CSSTidy output
if ($config_extractstyleblocks == true) {
// 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);
$ret = '<!-- HTML Purifier Cache #' . $cid . ' -->' . $ret;
}
}
if ($cache) {
cache_set($cid, $ret, 'cache_htmlpurifier', CACHE_PERMANENT);
}
return $ret;
}