You are here

function htmlpurifier_filter in HTML Purifier 5

Same name and namespace in other branches
  1. 6.2 htmlpurifier.module \htmlpurifier_filter()
  2. 6 htmlpurifier.module \htmlpurifier_filter()

Implementation of hook_filter().

File

./htmlpurifier.module, line 20

Code

function htmlpurifier_filter($op, $delta = 0, $format = -1, $text = '') {
  switch ($op) {
    case 'list':
      return array(
        0 => t('HTML Purifier'),
      );
    case 'no cache':

      // since HTML Purifier implements its own caching layer, having filter
      // cache it again is wasteful. MAYBE make this configurable.
      return TRUE;
    case 'description':

      // TODO: Include description of what tags and properties are active
      return t('Removes malicious HTML code and ensures that the output is standards compliant. Note: For performance reasons, please ensure there are no dynamic filters before this filter.');
    case 'prepare':
      return $text;
    case 'process':
      $cid = md5($text);
      $cache = cache_get($cid, 'cache_htmlpurifier');
      if ($cache) {
        return $cache->data;
      }
      _htmlpurifier_load();
      $purifier = new HTMLPurifier(_htmlpurifier_get_config($format));
      _htmlpurifier_add_filters($format, $purifier);
      $ret = $purifier
        ->purify($text);
      cache_set($cid, 'cache_htmlpurifier', $ret, CACHE_PERMANENT);
      return $ret;
    case 'settings':
      _htmlpurifier_load();
      return _htmlpurifier_settings($format);
    default:
      return NULL;
  }
}