function check_markup2 in Quick Edit 7
Identical to check_markup() with the exception of the new ability to *skip* filters that match any filter type in a list of filter types
Parameters
array $filter_types_to_skip: (optional) An array of filter types to skip, or an empty array (default) to skip no filter types. All of the format's filters will be applied, except for filters of the types that are marked to be skipped. FILTER_TYPE_HTML_RESTRICTOR is the only type that cannot be skipped.
See also
1 call to check_markup2()
- quickedit_field_attach_view_alter in ./
quickedit.module - Implements hook_field_attach_view_alter().
File
- includes/
filter.inc, line 125 - Backport of Drupal 8 filter module improvements.
Code
function check_markup2($text, $format_id = NULL, $langcode = '', $cache = FALSE, $filter_types_to_skip = array()) {
if (!isset($format_id)) {
$format_id = filter_fallback_format();
}
// If the requested text format does not exist, the text cannot be filtered.
if (!($format = filter_format_load($format_id))) {
watchdog('filter', 'Missing text format: %format.', array(
'%format' => $format_id,
), WATCHDOG_ALERT);
return '';
}
// Prevent FILTER_TYPE_HTML_RESTRICTOR from being skipped.
if (in_array(FILTER_TYPE_HTML_RESTRICTOR, $filter_types_to_skip)) {
$filter_types_to_skip = array_diff($filter_types_to_skip, array(
FILTER_TYPE_HTML_RESTRICTOR,
));
}
// When certain filters should be skipped, don't perform caching.
if ($filter_types_to_skip) {
$cache = FALSE;
}
// Check for a cached version of this piece of text.
$cache = $cache && !empty($format->cache);
$cache_id = '';
if ($cache) {
$cache_id = $format->format . ':' . $langcode . ':' . hash('sha256', $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 necessary, skip filters of a certain type.
if (isset($filter_info[$name]['type']) && in_array($filter_info[$name]['type'], $filter_types_to_skip)) {
continue;
}
if (!empty($filter->status) && isset($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 necessary, skip filters of a certain type.
if (isset($filter_info[$name]['type']) && in_array($filter_info[$name]['type'], $filter_types_to_skip)) {
continue;
}
if (!empty($filter->status) && isset($filter_info[$name]['process callback'])) {
$function = $filter_info[$name]['process callback'];
$text = $function($text, $filter, $format, $langcode, $cache, $cache_id);
}
}
// Cache the filtered text. This cache is infinitely valid. It becomes
// obsolete when $text changes (which leads to a new $cache_id). It is
// automatically flushed when the text format is updated.
// @see filter_format_save()
if ($cache) {
cache_set($cache_id, $text, 'cache_filter');
}
return $text;
}