You are here

function _htmlpurifier_settings in HTML Purifier 7

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

Generates a settings form for configuring HTML Purifier.

Parameters

array $form: The prepopulated form array.

array $form_state: The form state of the (entire) configuration form.

object $filter: The filter object containing settings for the given format. $filter->name can be either 'htmlpurifier_basic' or 'htmlpurifier_advanced' (the two filters defined by this module).

object $format: The format object being configured.

array $defaults: The default settings for the filter, as defined in 'default settings' in hook_filter_info().

Return value

Form API array.

1 string reference to '_htmlpurifier_settings'
htmlpurifier_filter_info in ./htmlpurifier.module
Implements hook_filter_info().

File

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

Code

function _htmlpurifier_settings($form, &$form_state, $filter, $format, $defaults) {
  _htmlpurifier_load();

  // Dry run, testing for errors:
  _htmlpurifier_process_text('', $filter, $format, LANGUAGE_NONE, FALSE);
  $module_path = drupal_get_path('module', 'htmlpurifier');
  $settings = array();
  $settings['#attached']['css'][] = "{$module_path}/config-form.css";
  $settings['#attached']['js'][] = "{$module_path}/config-form.js";
  $settings['#attached']['js'][] = array(
    'data' => HTMLPurifier_Printer_ConfigForm::getJavaScript(),
    'type' => 'inline',
  );
  $settings['htmlpurifier_help'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display help text'),
    '#default_value' => isset($filter->settings['htmlpurifier_help']) ? $filter->settings['htmlpurifier_help'] : $defaults['htmlpurifier_help'],
    '#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->format)) {
    $settings['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->format,
      )),
    );
  }
  else {
    if ($filter->name == 'htmlpurifier_basic') {
      $title = t('Configure HTML Purifier');
      $allowed = array(
        'URI.DisableExternalResources',
        'URI.DisableResources',
        'URI.Munge',
        'Attr.EnableID',
        'HTML.Allowed',
        'HTML.ForbiddenElements',
        'HTML.ForbiddenAttributes',
        'HTML.SafeObject',
        'Output.FlashCompat',
        'AutoFormat.RemoveEmpty',
        'AutoFormat.Linkify',
        'AutoFormat.AutoParagraph',
      );
    }
    else {
      $title = t('Advanced configuration options');
      $allowed = TRUE;
    }
    $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!  Changes will not apply to old entries until you clear the cache (see the <a href="@url">settings page</a>).', array(
      '@url' => url('admin/config/content/htmlpurifier'),
    )) . '</div></div>';
    $config = _htmlpurifier_get_config($format->format);
    $config_form = new HTMLPurifier_Printer_ConfigForm($filter->name . '_config', 'http://htmlpurifier.org/live/configdoc/plain.html#%s');
    $settings[$filter->name . '_config'] = array(
      '#markup' => $intro . $config_form
        ->render($config, $allowed, FALSE),
      '#after_build' => array(
        '_htmlpurifier_config_hack',
      ),
    );
  }
  return $settings;
}