You are here

function _htmlpurifier_settings in HTML Purifier 6

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

Generates a settings form for configuring HTML Purifier.

Parameters

int $delta: Whether or not to use advanced form (1) or not (0).

int $format: Input format being configured.

Return value

Form API array.

1 call to _htmlpurifier_settings()
htmlpurifier_filter in ./htmlpurifier.module
Implementation of hook_filter().

File

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

Code

function _htmlpurifier_settings($delta, $format) {
  _htmlpurifier_load();

  // Dry run, testing for errors:
  _htmlpurifier_process('', $format, FALSE);
  $module_path = drupal_get_path('module', 'htmlpurifier');
  drupal_add_css("{$module_path}/config-form.css");

  // Makes all configuration links open in new windows; can safe lots of grief!
  drupal_add_js('$(function(){$(".hp-config a").click(function(){window.open(this.href);return false;});});', 'inline');
  drupal_add_js(HTMLPurifier_Printer_ConfigForm::getJavaScript(), 'inline');
  $form = array();
  $form['htmlpurifier'] = array(
    '#type' => 'fieldset',
    '#title' => t('HTML Purifier'),
    '#collapsible' => TRUE,
  );
  $form['htmlpurifier']["htmlpurifier_help_{$format}"] = array(
    '#type' => 'checkbox',
    '#title' => t('Display help text'),
    '#default_value' => variable_get("htmlpurifier_help_{$format}", TRUE),
    '#description' => t('If enabled, a short note will be added to the filter tips explaining that HTML will be transformed to conform with HTML standards. You may want to disable this option when the HTML Purifier is used to check the output of another filter like BBCode.'),
  );
  if ($config_function = _htmlpurifier_config_load($format)) {
    $form['htmlpurifier']['notice'] = array(
      '#type' => 'markup',
      '#value' => t('<div>Configuration function <code>!function()</code> is already defined. To edit HTML Purifier\'s configuration, edit the corresponding configuration file, which is usually <code>htmlpurifier/config/!format.php</code>. To restore the web configuration form, delete or rename this file.</div>', array(
        '!function' => $config_function,
        '!format' => $format,
      )),
    );
  }
  else {
    if ($delta == 0) {
      $title = t('Configure HTML Purifier');
      $allowed = array(
        'URI.DisableExternalResources',
        'URI.DisableResources',
        'URI.Munge',
        'Filter.YouTube',
        'Attr.EnableID',
        'HTML.Allowed',
        'HTML.ForbiddenElements',
        'HTML.ForbiddenAttributes',
        'AutoFormat.Linkify',
        'AutoFormat.AutoParagraph',
      );
    }
    else {
      $title = t('Advanced configuration options');
      $allowed = TRUE;
      $form['htmlpurifier']["htmlpurifier_doublecache_{$format}"] = array(
        '#type' => 'checkbox',
        '#title' => t('Allow double caching'),
        '#default_value' => variable_get("htmlpurifier_doublecache_{$format}", FALSE),
        '#description' => t('If enabled, HTML Purifier will tell filter that its output is cacheable. This is not usually necessary, because HTML Purifier maintains its own cache, but may be helpful if you have later filters that need to be cached.'),
      );
    }
    $intro = '<div class="form-item"><h3>' . $title . '</h3><div class="description">' . t('Please click on a directive name for more information on what it does before enabling or changing anything!') . '</div></div>';
    $config = _htmlpurifier_get_config($format);
    $config_form = new HTMLPurifier_Printer_ConfigForm("htmlpurifier_config_{$format}", 'http://htmlpurifier.org/live/configdoc/plain.html#%s');
    $form['htmlpurifier']["htmlpurifier_config_{$format}"] = array(
      '#value' => $intro . $config_form
        ->render($config, $allowed, FALSE),
      '#after_build' => array(
        '_htmlpurifier_config_hack',
      ),
    );
  }
  return $form;
}