/[drupal]/contributions/modules/geshifilter/geshifilter.conflicts.inc
ViewVC logotype

Contents of /contributions/modules/geshifilter/geshifilter.conflicts.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (show annotations) (download) (as text)
Sun Jul 12 23:24:48 2009 UTC (4 months, 2 weeks ago) by soxofaan
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +4 -4 lines
File MIME type: text/x-php
#351185 by hass: i18n fixes
1 <?php
2 // $Id: geshifilter.conflicts.inc,v 1.6 2009/07/12 15:00:28 soxofaan Exp $
3
4 /**
5 * @file
6 * Implementation of the conflict detection feature of the GeSHi filter.
7 */
8
9 require_once drupal_get_path('module', 'geshifilter') .'/geshifilter.inc';
10
11 /**
12 * Menu callback for filter conflicts page
13 */
14 function geshifilter_admin_filter_conflicts($check_only=FALSE) {
15 // start
16 $output = '';
17 // check if GeSHi library is available
18 $geshi_library = _geshifilter_check_geshi_library();
19 if (!$geshi_library['success']) {
20 if (!$check_only) {
21 drupal_set_message($geshi_library['message'], 'error');
22 }
23 return $output;
24 }
25 $alerts = array();
26 $conflict_detectors = array(
27 'filter/0' => '_geshifilter_htmlfilter_conflicts',
28 'codefilter/0' => '_geshifilter_codefilter_conflicts',
29 );
30 foreach (filter_formats() as $format => $input_format) {
31 // Get the filters in this input format
32 $filters = filter_list_format($format);
33 // look if GeSHi is enabled in this input format
34 if (isset($filters['geshifilter/0'])) {
35 $geshifilter = $filters['geshifilter/0'];
36 // Check if possibly conflicting filters are also present in input format
37 foreach ($conflict_detectors as $filter_key => $conflict_detector) {
38 // does this filter exist in the input format?
39 if (array_key_exists($filter_key, $filters)) {
40 $cfilter = $filters[$filter_key];
41 $conflicts = $conflict_detector($format, $cfilter, $geshifilter);
42 foreach ($conflicts as $conflict) {
43 $alerts[] = array(
44 l(t($input_format->name), "admin/settings/filters/$format"),
45 $cfilter->name,
46 $conflict['description'],
47 $conflict['solution'],
48 );
49 }
50 }
51 }
52 }
53 }
54 if ($check_only) {
55 return count($alerts);
56 }
57 else {
58 // show alerts
59 if (count($alerts) == 0) {
60 $alerts[] = array(array('data' => t('No known filter conflicts were detected.'), 'colspan' => 4));
61 }
62 $header = array(t('Input format'), t('Filter'), t('Description'), t('Possible solutions'));
63 $output .= theme('table', $header, $alerts);
64 return $output;
65 }
66 }
67
68 /**
69 * conflict detection for html filter
70 */
71 function _geshifilter_htmlfilter_conflicts($format, $cfilter, $geshifilter) {
72 $conflicts = array();
73 // check order
74 if ($cfilter->weight >= $geshifilter->weight) {
75 $conflicts[] = array(
76 'description' => t('%cfilter should not come after %geshifilter to prevent loss of layout and highlighting.',
77 array('%cfilter' => $cfilter->name, '%geshifilter' => $geshifilter->name)),
78 'solution' => l(t('Rearrange filters'), "admin/settings/filters/$format/order"),
79 );
80 }
81 // check tag escaping of html filter
82 if (variable_get("filter_html_$format", FILTER_HTML_STRIP) == FILTER_HTML_ESCAPE) {
83 $conflicts[] = array(
84 'description' => t('%cfilter is configured to "Escape all tags", which is likely to cause problems with %geshifilter.',
85 array('%cfilter' => $cfilter->name, '%geshifilter' => $geshifilter->name)),
86 'solution' => l(t('Configure HTML filtering to "Strip disallowed tags"'), "admin/settings/filters/$format/configure", array('html' => TRUE)),
87 );
88 }
89 return $conflicts;
90 }
91
92 /**
93 * Conflict detection for codefilter.
94 */
95 function _geshifilter_codefilter_conflicts($format, $cfilter, $geshifilter) {
96 $conflicts = array();
97 if (in_array(GESHIFILTER_BRACKETS_ANGLE, array_filter(_geshifilter_tag_styles($format)))) {
98 list($generic_code_tags, $language_tags, $tag_to_lang) = _geshifilter_get_tags($format);
99 if (in_array('code', $generic_code_tags) || in_array('code', $language_tags)) {
100 $conflicts[] = array(
101 'description' => t('%cfilter and %geshifilter trigger on the same tag "&lt;code&gt;".',
102 array('%cfilter' => $cfilter->name, '%geshifilter' => $geshifilter->name)),
103 'solution' => t('Remove "code" as generic syntax highlighting tag for %geshifilter, limit %geshifilter to tag style "[foo]" only or disable %cfilter',
104 array('%cfilter' => $cfilter->name, '%geshifilter' => $geshifilter->name)),
105 );
106 }
107 }
108 return $conflicts;
109 }

  ViewVC Help
Powered by ViewVC 1.1.2