check_markup

Versions
mediamosa-21
check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE)

Run all the enabled filters on a piece of text.

Note: Because filters can inject JavaScript or execute PHP code, security is vital here. When a user supplies a text format, you should validate it using filter_access() before accepting/using it. This is normally done in the validation stage of the Form API. You should for example never make a preview of content in a disallowed format.

Parameters

$text The text to be filtered.

$format_id The format id of the text to be filtered. If no format is assigned, the fallback format will be used.

$langcode Optional: the language code of the text to be filtered, e.g. 'en' for English. This allows filters to be language aware so language specific text replacement can be implemented.

$cache Boolean whether to cache the filtered output in the {cache_filter} table. The caller may set this to FALSE when the output is already cached elsewhere to avoid duplicate cache lookups and storage.

▾ 10 functions call check_markup()

block_block_view in modules/block/block.module
Implements hook_block_view().
comment_submit in modules/comment/comment.module
Prepare a comment for submission.
comment_tokens in modules/comment/comment.tokens.inc
Implements hook_tokens().
hook_node_update_index in modules/node/node.api.php
Act on a node being indexed for searching.
profile_view_field in modules/profile/profile.module
taxonomy_term_feed in modules/taxonomy/taxonomy.pages.inc
Generate the content feed for a taxonomy term.
taxonomy_term_view in modules/taxonomy/taxonomy.module
Generate an array for rendering the given term.
taxonomy_tokens in modules/taxonomy/taxonomy.tokens.inc
Implements hook_tokens().
user_comment_view in modules/user/user.module
Implements hook_comment_view().
_text_sanitize in modules/field/modules/text/text.module
Sanitizes the 'value' or 'summary' data of a text value.

Code

modules/filter/filter.module, line 671

<?php
function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE) {
  if (empty($format_id)) {
    $format_id = filter_fallback_format();
  }
  $format = filter_format_load($format_id);

  // Check for a cached version of this piece of text.
  $cache = $cache && !empty($format->cache);
  $cache_id = '';
  if ($cache) {
    $cache_id = $format->format . ':' . $langcode . ':' . md5($text);
    if ($cached = cache_get($cache_id, 'cache_filter')) {
      return $cached->data;
    }
  }

  // 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->format);
  $filter_info = filter_get_filters();

  // Give filters the chance to escape HTML-like data such as code or formulas.
  foreach ($filters as $name => $filter) {
    if ($filter->status && isset($filter_info[$name]['prepare callback']) && function_exists($filter_info[$name]['prepare callback'])) {
      $function = $filter_info[$name]['prepare callback'];
      $text = $function($text, $filter, $format, $langcode, $cache, $cache_id);
    }
  }

  // Perform filtering.
  foreach ($filters as $name => $filter) {
    if ($filter->status && isset($filter_info[$name]['process callback']) && function_exists($filter_info[$name]['process callback'])) {
      $function = $filter_info[$name]['process callback'];
      $text = $function($text, $filter, $format, $langcode, $cache, $cache_id);
    }
  }

  // Store in cache with a minimum expiration time of 1 day.
  if ($cache) {
    cache_set($cache_id, $text, 'cache_filter', REQUEST_TIME + (60 * 60 * 24));
  }

  return $text;
}
?>