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

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

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


Revision 1.8 - (show annotations) (download) (as text)
Sun Jul 12 15:00:28 2009 UTC (4 months, 2 weeks ago) by soxofaan
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +7 -4 lines
File MIME type: text/x-php
various i18 fixes and typos (part of #351185 by hass)
1 <?php
2 // $Id: geshifilter.filtertips.inc,v 1.7 2009/07/04 11:05:56 soxofaan Exp $
3
4 /**
5 * @file
6 * Implementation of the filter tips.
7 */
8
9 require_once drupal_get_path('module', 'geshifilter') .'/geshifilter.inc';
10
11 /**
12 * Implementation for geshifilter_filter_tips()
13 */
14 function _geshifilter_filter_tips($delta, $format, $long = FALSE) {
15
16 // Get the supported tag styles.
17 $tag_styles = array_filter(_geshifilter_tag_styles($format));
18 $tag_style_examples = array();
19 $bracket_open = NULL;
20 if (in_array(GESHIFILTER_BRACKETS_ANGLE, $tag_styles)) {
21 if (!$bracket_open) {
22 $bracket_open = check_plain('<');
23 $bracket_close = check_plain('>');
24 }
25 $tag_style_examples[] = '<code>'. check_plain('<foo>') .'</code>';
26 }
27 if (in_array(GESHIFILTER_BRACKETS_SQUARE, $tag_styles)) {
28 if (!$bracket_open) {
29 $bracket_open = check_plain('[');
30 $bracket_close = check_plain(']');
31 }
32 $tag_style_examples[] = '<code>'. check_plain('[foo]') .'</code>';
33 }
34 if (in_array(GESHIFILTER_BRACKETS_DOUBLESQUARE, $tag_styles)) {
35 if (!$bracket_open) {
36 $bracket_open = check_plain('[[');
37 $bracket_close = check_plain(']]');
38 }
39 $tag_style_examples[] = '<code>'. check_plain('[[foo]]') .'</code>';
40 }
41 if (!$bracket_open) {
42 drupal_set_message(t('Could not determine a valid tag style for GeSHi filtering.'), 'error');
43 $bracket_open = check_plain('<');
44 $bracket_close = check_plain('>');
45 }
46
47 if ($long) {
48 // get the available tags
49 list($generic_code_tags, $language_tags, $tag_to_lang) = _geshifilter_get_tags($format);
50 // get the available languages
51 $languages = _geshifilter_get_enabled_languages();
52 $lang_attributes = _geshifilter_whitespace_explode(GESHIFILTER_ATTRIBUTES_LANGUAGE);
53
54 // syntax highlighting tags
55 $output = '<p>'. t('Syntax highlighting of source code can be enabled with the following tags:') .'</p>';
56 $items = array();
57 // generic tags
58 $tags = array();
59 foreach ($generic_code_tags as $tag) {
60 $tags[] = '"<code>'. $bracket_open . $tag . $bracket_close .'</code>"';
61 }
62 $items[] = t('Generic syntax highlighting tags: !tags.', array('!tags' => implode(', ', $tags)));
63 // language tags
64 $tags = array();
65 foreach ($language_tags as $tag) {
66 $tags[] = t('"<code>!tag</code>" for @lang source code', array(
67 '!tag' => $bracket_open . $tag . $bracket_close,
68 '@lang' => $languages[$tag_to_lang[$tag]])
69 );
70 }
71 $items[] = t('Language specific syntax highlighting tags: !tags.', array('!tags' => implode(', ', $tags)));
72 // PHP specific delimiters
73 if (in_array(GESHIFILTER_BRACKETS_PHPBLOCK, $tag_styles)) {
74 $items[] = t('PHP source code can also be enclosed in &lt;?php ... ?&gt; or &lt;% ... %&gt;, but additional options like line numbering are not possible here.');
75 }
76
77 $output .= theme('item_list', $items);
78
79 // Options and tips
80 $output .= '<p>'. t('Options and tips:') .'</p>';
81 $items = array();
82
83 // info about language attribute to language mapping
84 $att_to_full = array();
85 foreach ($languages as $langcode => $fullname) {
86 $att_to_full[$langcode] = $fullname;
87 }
88 foreach ($tag_to_lang as $tag => $lang) {
89 $att_to_full[$tag] = $languages[$lang];
90 }
91 ksort($att_to_full);
92 $att_for_full = array();
93 foreach ($att_to_full as $att => $fullname) {
94 $att_for_full[] = t('"<code>@langcode</code>" (for @fullname)', array('@langcode' => $att, '@fullname' => $fullname));
95 }
96 $items[] = t('The language for the generic syntax highlighting tags can be specified with one of the attribute(s): %attributes. The possible values are: !languages.', array('%attributes' => implode(', ', $lang_attributes), '!languages' => implode(', ', $att_for_full)));
97
98 // Tag style options.
99 if (count($tag_style_examples) > 1) {
100 $items[] = t('The supported tag styles are: !tag_styles.' , array('!tag_styles' => implode(', ', $tag_style_examples)));
101 }
102
103 // line numbering options
104 $items[] = t('<em>Line numbering</em> can be enabled/disabled with the attribute "%linenumbers". Possible values are: "%off" for no line numbers, "%normal" for normal line numbers and "%fancy" for fancy line numbers (every n<sup>th</sup> line number highlighted). The start line number can be specified with the attribute "%start", which implicitly enables normal line numbering. For fancy line numbering the interval for the highlighted line numbers can be specified with the attribute "%fancy", which implicitly enables fancy line numbering.', array('%linenumbers' => GESHIFILTER_ATTRIBUTE_LINE_NUMBERING, '%off' => 'off', '%normal' => 'normal', '%fancy' => 'fancy', '%start' => GESHIFILTER_ATTRIBUTE_LINE_NUMBERING_START, '%fancy' => GESHIFILTER_ATTRIBUTE_FANCY_N));
105
106 // block versus inline
107 $items[] = t('If the source code between the tags contains a newline (e.g. immediatly after the opening tag), the highlighted source code will be displayed as a code block. Otherwise it will be displayed inline.');
108
109
110 $output .= theme('item_list', $items);
111
112 // Defaults
113 $output .= '<p>'. t('Defaults:') .'</p>';
114 $items = array();
115 $default_highlighting = variable_get('geshifilter_default_highlighting', GESHIFILTER_DEFAULT_PLAINTEXT);
116 switch ($default_highlighting) {
117 case GESHIFILTER_DEFAULT_DONOTHING:
118 $description = t('when no language attribute is specified the code block won\'t be processed by the GeSHi filter');
119 break;
120 case GESHIFILTER_DEFAULT_PLAINTEXT:
121 $description = t('when no language attribute is specified, no syntax highlighting will be done');
122 break;
123 default:
124 $description = t('the default language used for syntax highlighting is "%default_lang"', array('%default_lang' => $default_highlighting));
125 break;
126 }
127 $items[] = t('Default highlighting mode for generic syntax highlighting tags: !description.', array('!description' => $description));
128 $default_line_numbering = variable_get('geshifilter_default_line_numbering', GESHIFILTER_LINE_NUMBERS_DEFAULT_NONE);
129 switch ($default_line_numbering) {
130 case GESHIFILTER_LINE_NUMBERS_DEFAULT_NONE:
131 $description = t('no line numbers');
132 break;
133 case GESHIFILTER_LINE_NUMBERS_DEFAULT_NORMAL:
134 $description = t('normal line numbers');
135 break;
136 default:
137 $description = t('fancy line numbers (every @n lines)', array('@n' => $default_line_numbering));
138 break;
139 }
140 $items[] = t('Default line numbering: !description.', array('!description' => $description));
141 $output .= theme('item_list', $items);
142
143 // Examples
144 $output .= '<p>'. t('Examples:') .'</p>';
145 $header = array(t('You type'), t('You get'));
146 $rows = array();
147 if (count($generic_code_tags)) {
148 $generic_code_tag = $generic_code_tags[0];
149 $lang = array_rand($languages);
150 $generic_code_tag_open = $bracket_open . $generic_code_tag;
151 $generic_code_tag_close = $bracket_open .'/'. $generic_code_tag . $bracket_close;
152 $rows[] = array(
153 '<code>'. $generic_code_tag_open . $bracket_close .'foo = "bar";'. $generic_code_tag_close .'</code>',
154 t('Inline code with the default syntax highlighting mode.'),
155 );
156 $rows[] = array(
157 '<code>'. $generic_code_tag_open . $bracket_close .'<br />foo = "bar";<br />baz = "foz";<br />'. $generic_code_tag_close .'</code>',
158 t('Code block with the default syntax highlighting mode.'),
159 );
160 $rows[] = array(
161 '<code>'. $generic_code_tag_open .' '. $lang_attributes[1 % count($lang_attributes)] .'="'. $lang .'" '. GESHIFILTER_ATTRIBUTE_LINE_NUMBERING .'="normal"'. $bracket_close .'<br />foo = "bar";<br />baz = "foz";<br />'. $generic_code_tag_close .'</code>',
162 t('Code block with syntax highlighting for @lang source code<br /> and normal line numbers.', array('@lang' => $languages[$lang])),
163 );
164 $rows[] = array(
165 '<code>'. $generic_code_tag_open .' '. $lang_attributes[2 % count($lang_attributes)] .'="'. $lang .'" '. GESHIFILTER_ATTRIBUTE_LINE_NUMBERING_START .'="23" '. GESHIFILTER_ATTRIBUTE_FANCY_N .'="7"'. $bracket_close .'<br />foo = "bar";<br />baz = "foz";<br />'. $generic_code_tag_close .'</code>',
166 t('Code block with syntax highlighting for @lang source code,<br />line numbers starting from 23<br /> and highlighted line numbers every 7<sup>th</sup> line.', array('@lang' => $languages[$lang])),
167 );
168 }
169 if (count($language_tags)) {
170 $language_tag = $language_tags[0];
171 $rows[] = array(
172 '<code>'. $bracket_open . $language_tag . $bracket_close .'<br />foo = "bar";<br />baz = "foz";<br />'. $bracket_open .'/'. $language_tag . $bracket_close .'</code>',
173 t('Code block with syntax highlighting for @lang source code.', array('@lang' => $languages[$tag_to_lang[$language_tag]])),
174 );
175 $rows[] = array(
176 '<code>'. $bracket_open . $language_tag .' '. GESHIFILTER_ATTRIBUTE_LINE_NUMBERING_START .'="23" '. GESHIFILTER_ATTRIBUTE_FANCY_N .'="7"'. $bracket_close .'<br />foo = "bar";<br />baz = "foz";<br />'. $bracket_open . $language_tag . $bracket_close .'</code>',
177 t('Code block with syntax highlighting for @lang source code,<br />line numbers starting from 23<br /> and highlighted line numbers every 7<sup>th</sup> line.', array('@lang' => $languages[$tag_to_lang[$language_tag]])),
178 );
179 }
180 $output .= theme('table', $header, $rows);
181 return $output;
182 }
183 else {
184 // get the available tags
185 list($generic_code_tags, $language_tags, $tag_to_lang) = _geshifilter_get_tags($format);
186 $tags = array();
187 foreach ($generic_code_tags as $tag) {
188 $tags[] = '<code>'. $bracket_open . $tag . $bracket_close .'</code>';
189 }
190 foreach ($language_tags as $tag) {
191 $tags[] = '<code>'. $bracket_open . $tag . $bracket_close .'</code>';
192 }
193 $output = t('You can enable syntax highlighting of source code with the following tags: !tags.', array('!tags' => implode(', ', $tags)));
194 // Tag style options.
195 if (count($tag_style_examples) > 1) {
196 $output .= ' '. t('The supported tag styles are: !tag_styles.' , array('!tag_styles' => implode(', ', $tag_style_examples)));
197 }
198 if (in_array(GESHIFILTER_BRACKETS_PHPBLOCK, $tag_styles)) {
199 $output .= ' '. t('PHP source code can also be enclosed in &lt;?php ... ?&gt; or &lt;% ... %&gt;.');
200 }
201 return $output;
202 }
203 }

  ViewVC Help
Powered by ViewVC 1.1.2