You are here

function _htmlpurifier_get_config in HTML Purifier 6

Same name and namespace in other branches
  1. 5 htmlpurifier.module \_htmlpurifier_get_config()
  2. 6.2 htmlpurifier.module \_htmlpurifier_get_config()
  3. 7.2 htmlpurifier.module \_htmlpurifier_get_config()
  4. 7 htmlpurifier.module \_htmlpurifier_get_config()

Returns the HTMLPurifier_Config object corresponding to an input format.

Parameters

int $format: Input format.

Return value

Instance of HTMLPurifier_Config.

2 calls to _htmlpurifier_get_config()
_htmlpurifier_process in ./htmlpurifier.module
Processes HTML according to a format and returns purified HTML. Makes a cache pass if possible.
_htmlpurifier_settings in ./htmlpurifier.module
Generates a settings form for configuring HTML Purifier.

File

./htmlpurifier.module, line 181
Implements HTML Purifier as a Drupal filter.

Code

function _htmlpurifier_get_config($format) {
  $config = HTMLPurifier_Config::createDefault();
  $config
    ->set('AutoFormat', 'AutoParagraph', TRUE);
  $config
    ->set('AutoFormat', 'Linkify', TRUE);
  $config
    ->set('HTML', 'Doctype', 'XHTML 1.0 Transitional');

  // Probably
  $config
    ->set('Core', 'AggressivelyFixLt', TRUE);
  $config
    ->set('Cache', 'DefinitionImpl', 'Drupal');

  // Filter HTML doesn't allow external images, so neither will we...
  // for now. This can be configured off.
  $config
    ->set('URI', 'DisableExternalResources', TRUE);
  if (!empty($_SERVER['SERVER_NAME'])) {

    // SERVER_NAME is more reliable than HTTP_HOST
    $config
      ->set('URI', 'Host', $_SERVER['SERVER_NAME']);
  }
  if (defined('LANGUAGE_RTL') && $GLOBALS['language']->direction === LANGUAGE_RTL) {
    $config
      ->set('Attr', 'DefaultTextDir', 'rtl');
  }
  if ($config_function = _htmlpurifier_config_load($format)) {
    $config_function($config);
  }
  else {
    $config_data = variable_get("htmlpurifier_config_{$format}", FALSE);

    // {FALSE, TRUE, FALSE} = {no index, everything is allowed, don't do mq fix}
    $config
      ->mergeArrayFromForm($config_data, FALSE, TRUE, FALSE);
  }
  return $config;
}