You are here

wysiwyg_filter.module in WYSIWYG Filter 6

Same filename and directory in other branches
  1. 7 wysiwyg_filter.module

Provides an input filter that allows site administrators configure which HTML elements, attributes and style properties are allowed.

File

wysiwyg_filter.module
View source
<?php

/**
 * @file
 * Provides an input filter that allows site administrators configure which
 * HTML elements, attributes and style properties are allowed.
 */

/**
 * Implementation of hook_filter().
 */
function wysiwyg_filter_filter($op, $delta = 0, $format = -1, $text = '') {
  if ($op == 'list') {
    return array(
      0 => t('WYSIWYG Filter'),
    );
  }
  else {
    if ($op == 'description') {
      if ($delta == 0) {
        return t('Allows you to restrict whether users can post HTML and which tags and attributes per HTML tag to filter out.');
      }
    }
    else {
      if ($op == 'settings') {
        if ($delta == 0) {
          module_load_include('inc', 'wysiwyg_filter', 'wysiwyg_filter.admin');
          return wysiwyg_filter_settings_filter($format);
        }
      }
      else {
        if ($op == 'process') {
          if ($delta == 0) {
            module_load_include('inc', 'wysiwyg_filter', 'wysiwyg_filter.pages');
            return wysiwyg_filter_process($text, $format);
          }
        }
        else {
          return $text;
        }
      }
    }
  }
}

/**
 * Implementation of hook_filter_tips().
 */
function wysiwyg_filter_filter_tips($delta, $format, $long = FALSE) {
  if ($delta == 0) {

    // Load common functions.
    module_load_include('inc', 'wysiwyg_filter');
    $filter_options = wysiwyg_filter_get_filter_options($format);
    $tips = array();
    if (!empty($filter_options['valid_elements'])) {
      $tags = array();
      foreach (array_keys($filter_options['valid_elements']) as $tag) {
        $tags[] = '<' . $tag . '>';
      }
      $tips[] = t('Allowed HTML tags: @tags', array(
        '@tags' => implode(' ', $tags),
      ));
    }
    if (!empty($filter_options['style_properties'])) {
      $tips[] = t('Allowed Style properties: @properties', array(
        '@properties' => implode(', ', array_keys($filter_options['style_properties'])),
      ));
    }
    if (!empty($tips)) {
      return implode('<br />', $tips);
    }
  }
}

/**
 * Implementation of wysiwyg_editor_settings_alter().
 */
function wysiwyg_filter_wysiwyg_editor_settings_alter(&$settings, $context) {

  // Provide the valid_elements option to TinyMCE editors, only if the WYSIWYG
  // Filter is enabled in the input format related to the current given context.
  if ($context['profile']->editor == 'tinymce' && ($valid_elements = variable_get('wysiwyg_filter_valid_elements_raw_' . $context['profile']->format, ''))) {
    if (isset($context['profile']->format) && ($filters = filter_list_format($context['profile']->format)) && !empty($filters['wysiwyg_filter/0'])) {
      $settings['valid_elements'] = preg_replace('#\\s+#', '', $valid_elements);
    }
  }
}

/**
 * Implementation of hook_input_formats_variables().
 */
function wysiwyg_filter_input_formats_variables($delta) {
  $variables = array();
  switch ($delta) {
    case 0:
      $variables['wysiwyg_filter_valid_elements_parsed'] = t('Valid elements parsed');
      break;
  }
  return $variables;
}

Functions

Namesort descending Description
wysiwyg_filter_filter Implementation of hook_filter().
wysiwyg_filter_filter_tips Implementation of hook_filter_tips().
wysiwyg_filter_input_formats_variables Implementation of hook_input_formats_variables().
wysiwyg_filter_wysiwyg_editor_settings_alter Implementation of wysiwyg_editor_settings_alter().