function _linkchecker_check_markup in Link checker 7
Same name and namespace in other branches
- 5.2 linkchecker.module \_linkchecker_check_markup()
- 6.2 linkchecker.module \_linkchecker_check_markup()
Customized clone of core check_markup() with additional filter blacklist.
See https://api.drupal.org/api/function/check_markup/7 for API documentation.
2 calls to _linkchecker_check_markup()
- _linkchecker_add_block_custom_links in ./
linkchecker.module - Add custom block links to database.
- _linkchecker_parse_fields in ./
linkchecker.module - Parse the urls from entity.
File
- ./
linkchecker.module, line 2327 - This module periodically check links in given node types, blocks etc.
Code
function _linkchecker_check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE) {
if (!isset($text)) {
return '';
}
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))) {
linkchecker_watchdog_log('filter', 'Missing text format: %format.', array(
'%format' => $format_id,
), WATCHDOG_ALERT);
return '';
}
// Check for a cached version of this piece of text.
$cache = $cache && !empty($format->cache);
$cache_id = '';
if ($cache) {
$cache_id = 'linkchecker:' . $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();
// Do not run placeholder or special tag filters used as references to nodes
// like 'weblink' or 'weblinks' node types. If the original link node is
// updated, all links are automatically up-to-date and there is no need to
// notify about the broken link on all nodes having a link reference in
// content. This would only confuse the authors as they may also not be able
// to fix the source node of the reference.
$filters_blacklist = array_keys(array_filter(variable_get('linkchecker_filter_blacklist', explode('|', LINKCHECKER_DEFAULT_FILTER_BLACKLIST))));
// Give filters the chance to escape HTML-like data such as code or formulas.
foreach ($filters as $name => $filter) {
if (!in_array($name, $filters_blacklist)) {
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 (!in_array($name, $filters_blacklist)) {
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;
}