You are here

function _htmlpurifier_get_config in HTML Purifier 7.2

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

Returns the HTMLPurifier_Config object corresponding to a text format.

Parameters

string $filter_name: Text format ID

string $config_name: Configuration name

Return value

Instance of HTMLPurifier_Config.

2 calls to _htmlpurifier_get_config()
_htmlpurifier_process_text 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 499
Implements HTML Purifier as a Drupal filter.

Code

function _htmlpurifier_get_config($format_name, $config_name, $reset = FALSE) {
  $infos = htmlpurifier_get_info();
  $filters = filter_list_format($format_name);
  $config = HTMLPurifier_Config::createDefault();
  $settings = $infos[$config_name]['settings'];
  foreach ($settings as $key => $value) {
    $config
      ->set($key, $value);
  }
  $config_data = isset($filters['htmlpurifier']->settings['htmlpurifier_config']) && !$reset ? $filters['htmlpurifier']->settings['htmlpurifier_config'] : array();

  // Need to do a little more if Filter.ExtractStyleBlocks is set
  if (!empty($config_data['Filter.ExtractStyleBlocks'])) {
    $library = libraries_detect('csstidy');
    if (!$library['installed']) {
      $config_data['Filter.ExtractStyleBlocks'] = '0';
      $error = t('Could not enable ExtractStyleBlocks because CSSTidy library was not found, detected or the version is unsupported.  Please download a supported version from %url.', array(
        '%url' => $library['download url'],
      ));
      drupal_set_message($error, 'error', FALSE);
    }
  }

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

  // Allow other modules to alter the HTML definition.
  $html_definition = $config
    ->getHTMLDefinition(TRUE);
  drupal_alter('htmlpurifier_html_definition', $html_definition);
  return $config;
}