check_output

Definition

check_output($text, $format = FILTER_FORMAT_DEFAULT, $check = FALSE)
modules/filter.module, line 666

Description

Run all the enabled filters on a piece of text.

You can do a filter_access() check on $format automatically by passing $check = TRUE. Note that this will check the permissions of the current user, so you should specify $check = FALSE when viewing other people's content.

Parameters

$text The text to be filtered.

$format The format of the text to be filtered. Specify FILTER_FORMAT_DEFAULT for the default format.

$check Whether to check the $format with filter_access() first. If set to false, make sure the check has performed at some point earlier.

Code

<?php
function check_output($text, $format = FILTER_FORMAT_DEFAULT, $check = FALSE) {
  // When $check = true, do an access check on $format.
  if (isset($text) && (!$check || filter_access($format))) {
    if ($format == FILTER_FORMAT_DEFAULT) {
      $format = variable_get('filter_default_format', 1);
    }

    // Check for a cached version of this piece of text.
    $id = 'filter:'. $format .':'. md5($text);
    if ($cached = cache_get($id)) {
      return $cached->data;
    }

    // See if caching is allowed for this format.
    $cache = filter_format_allowcache($format);

    // Convert all Windows and Mac newlines to a single newline,
    // so filters only need to deal with one possibility.
    $text = str_replace(array("\r\n", "\r"), "\n", $text);

    // Get a complete list of filters, ordered properly.
    $filters = filter_list_format($format);

    // Give filters the chance to escape HTML-like data such as code or formulas.
    foreach ($filters as $filter) {
      $text = module_invoke($filter->module, 'filter', 'prepare', $filter->delta, $format, $text);
    }

    // Perform filtering.
    foreach ($filters as $filter) {
      $text = module_invoke($filter->module, 'filter', 'process', $filter->delta, $format, $text);
    }

    // Store in cache with a minimum expiration time of 1 day.
    if ($cache) {
      cache_set($id, $text, time() + (60 * 60 * 24));
    }
  }
  else {
    $text = message_na();
  }

  return $text;
}
?>
 
 

Drupal is a registered trademark of Dries Buytaert.