View source
<?php
require_once 'geshifilter.inc';
function _geshifilter_admin_filter_conflicts($check_only = FALSE) {
$output = '';
$geshi_library = _geshifilter_check_geshi_library();
if (!$geshi_library['success']) {
if (!$check_only) {
drupal_set_message($geshi_library['message'], 'error');
}
return $output;
}
$alerts = array();
$conflict_detectors = array(
'filter/0' => '_geshifilter_htmlfilter_conflicts',
'codefilter/0' => '_geshifilter_codefilter_conflicts',
);
foreach (filter_formats() as $format => $input_format) {
$filters = filter_list_format($format);
if (isset($filters['geshifilter/0'])) {
$geshifilter = $filters['geshifilter/0'];
foreach ($conflict_detectors as $filter_key => $conflict_detector) {
if (array_key_exists($filter_key, $filters)) {
$cfilter = $filters[$filter_key];
$conflicts = $conflict_detector($format, $cfilter, $geshifilter);
foreach ($conflicts as $conflict) {
$alerts[] = array(
l(t($input_format->name), "admin/settings/filters/{$format}"),
$cfilter->name,
$conflict['description'],
$conflict['solution'],
);
}
}
}
}
}
if ($check_only) {
return count($alerts);
}
else {
if (count($alerts) == 0) {
$alerts[] = array(
array(
'data' => t('No known filter conflicts were detected.'),
'colspan' => 4,
),
);
}
$header = array(
t('Input format'),
t('Filter'),
t('Description'),
t('Possible solutions'),
);
$output .= theme('table', $header, $alerts);
return $output;
}
}
function _geshifilter_htmlfilter_conflicts($format, $cfilter, $geshifilter) {
$conflicts = array();
if ($cfilter->weight >= $geshifilter->weight) {
$conflicts[] = array(
'description' => t('%cfilter should not come after %geshifilter to prevent loss of layout and highlighting.', array(
'%cfilter' => $cfilter->name,
'%geshifilter' => $geshifilter->name,
)),
'solution' => l(t('Rearrange filters'), "admin/settings/filters/{$format}/order"),
);
}
if (variable_get("filter_html_{$format}", FILTER_HTML_STRIP) == FILTER_HTML_ESCAPE) {
$conflicts[] = array(
'description' => t('%cfilter is configured to "Escape all tags", which is likely to cause propblems with %geshifilter.', array(
'%cfilter' => $cfilter->name,
'%geshifilter' => $geshifilter->name,
)),
'solution' => l(t('Configure HTML filtering to "Strip disallowed tags"'), "admin/settings/filters/{$format}/configure", array(), NULL, NULL, FALSE, TRUE),
);
}
return $conflicts;
}
function _geshifilter_codefilter_conflicts($format, $cfilter, $geshifilter) {
$conflicts = array();
if (_geshifilter_brackets($format) != GESHIFILTER_BRACKETS_SQUARE) {
list($generic_code_tags, $language_tags, $tag_to_lang) = _geshifilter_get_tags($format);
if (in_array('code', $generic_code_tags) || in_array('code', $language_tags)) {
$conflicts[] = array(
'description' => t('%cfilter and %geshifilter trigger on the same tag "<code>".', array(
'%cfilter' => $cfilter->name,
'%geshifilter' => $geshifilter->name,
)),
'solution' => t('Remove "code" as generic syntax highlighting tag for %geshifilter, limit %geshifilter to tag style "[foo]" only or disable %cfilter', array(
'%cfilter' => $cfilter->name,
'%geshifilter' => $geshifilter->name,
)),
);
}
}
return $conflicts;
}