View source
<?php
define('FILTER_TYPE_MARKUP_LANGUAGE', 0);
define('FILTER_TYPE_HTML_RESTRICTOR', 1);
define('FILTER_TYPE_TRANSFORM_REVERSIBLE', 2);
define('FILTER_TYPE_TRANSFORM_IRREVERSIBLE', 3);
function quickedit_filter_info_alter(&$info) {
if (module_exists('php')) {
$info['php_code']['type'] = FILTER_TYPE_MARKUP_LANGUAGE;
}
$info['filter_autop']['type'] = FILTER_TYPE_MARKUP_LANGUAGE;
$info['filter_url']['type'] = FILTER_TYPE_MARKUP_LANGUAGE;
$info['filter_html_escape']['type'] = FILTER_TYPE_MARKUP_LANGUAGE;
$info['filter_html']['type'] = FILTER_TYPE_HTML_RESTRICTOR;
$info['filter_htmlcorrector']['type'] = FILTER_TYPE_HTML_RESTRICTOR;
$contrib_filter_type = array(
'biblio_filter_reference' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'biblio_filter_inline_reference' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'caption_filter' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'ckeditor_link_filter' => FILTER_TYPE_TRANSFORM_REVERSIBLE,
'editor_align' => FILTER_TYPE_TRANSFORM_REVERSIBLE,
'editor_caption' => FILTER_TYPE_TRANSFORM_REVERSIBLE,
'emptyparagraphkiller' => FILTER_TYPE_HTML_RESTRICTOR,
'entity_embed' => FILTER_TYPE_TRANSFORM_REVERSIBLE,
'filter_footnotes' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'filter_hashtags' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'filter_html_image_secure' => FILTER_TYPE_HTML_RESTRICTOR,
'htmlpurifier_basic' => FILTER_TYPE_HTML_RESTRICTOR,
'htmlpurifier_advanced' => FILTER_TYPE_HTML_RESTRICTOR,
'image_resize_filter' => FILTER_TYPE_TRANSFORM_REVERSIBLE,
'filter_align' => FILTER_TYPE_TRANSFORM_REVERSIBLE,
'filter_markdown' => FILTER_TYPE_MARKUP_LANGUAGE,
'insert_view' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'media_filter' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'node_embed' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'oembed' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'pathologic' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'smart_paging_filter' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'smart_paging_filter_autop' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'spamspan' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'transliteration' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'typogrify' => FILTER_TYPE_TRANSFORM_IRREVERSIBLE,
'wysiwyg' => FILTER_TYPE_HTML_RESTRICTOR,
);
foreach ($contrib_filter_type as $filter => $type) {
if (empty($info[$filter])) {
continue;
}
$info[$filter]['type'] = $type;
}
}
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 (!($format = filter_format_load($format_id))) {
watchdog('filter', 'Missing text format: %format.', array(
'%format' => $format_id,
), WATCHDOG_ALERT);
return '';
}
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,
));
}
if ($filter_types_to_skip) {
$cache = FALSE;
}
$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;
}
}
$text = str_replace(array(
"\r\n",
"\r",
), "\n", $text);
$filters = filter_list_format($format->format);
$filter_info = filter_get_filters();
foreach ($filters as $name => $filter) {
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);
}
}
foreach ($filters as $name => $filter) {
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);
}
}
if ($cache) {
cache_set($cache_id, $text, 'cache_filter');
}
return $text;
}
function filter_get_filter_types_by_format($format_id) {
$filter_types = array();
$filters = filter_list_format($format_id);
$filters_info = filter_get_filters();
foreach ($filters as $filter) {
if (empty($filter->status)) {
continue;
}
if (!isset($filters_info[$filter->name]['type'])) {
drupal_set_message(t('The filter "!filter" has no type specified! This is required for the Quick Edit module. Please consult Quick Edit module\'s README.', array(
'!filter' => $filter->name,
)), 'error');
continue;
}
$filter_types[] = $filters_info[$filter->name]['type'];
}
return array_unique($filter_types);
}