function check_markup

You are here

7 filter.module check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE)
4.7 filter.module check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE)
5 filter.module check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE)
6 filter.module check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE)
8 filter.module check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE, $filter_types_to_skip = array())

Run all the enabled filters on a piece of text.

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. Defaults to TRUE. Note that this will check the permissions of the current user, so you should specify $check = FALSE when viewing other people's content. When showing content that is not (yet) stored in the database (eg. upon preview), set to TRUE so the user's permissions are checked.

Related topics

8 calls to check_markup()
block_block in modules/block/block.module
Implementation of hook_block().
comment_nodeapi in modules/comment/comment.module
Implementation of hook_nodeapi().
node_prepare in modules/node/node.module
Apply filters and build the node's standard elements.
profile_view_field in modules/profile/profile.module
system_message_action in modules/system/system.module
A configurable Drupal action. Sends a message to the current user's screen.

... See full list

File

modules/filter/filter.module, line 427
Framework for handling filtering of content.

Code

function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
  // When $check = TRUE, do an access check on $format.
  if (isset($text) && (!$check || filter_access($format))) {
    $format = filter_resolve_format($format);

    // Check for a cached version of this piece of text.
    $cache_id = $format . ':' . md5($text);
    if ($cached = cache_get($cache_id, 'cache_filter')) {
      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, $cache_id);
    }

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

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

  return $text;
}

Comments

In Drupal 6, the second argument of check_markup() is the value of the "format" field in the "filter_formats" table; it is a serial field, which means it can contain only numbers.

more info and source:

http://drupal.stackexchange.com/questions/10517/drupal-ignores-check-markup

If you want to disable the filter caching system with memcached, check_markup() will increase the "MISS" rate because filter_format_allowcache() is checked only for the cache_set() and not for the cache_get().
We moved the cache verification before the cache_get() and add a condition :

<?php
function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
  (...)
   
// See if caching is allowed for this format.
   
$cache = filter_format_allowcache($format);

   

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