View source
<?php
require_once 'geshifilter.inc';
function _geshifilter_filter_tips($delta, $format, $long = false) {
if (_geshifilter_brackets($format) == GESHIFILTER_BRACKETS_SQUARE) {
$bracket_open = '[';
$bracket_close = ']';
}
else {
$bracket_open = '<';
$bracket_close = '>';
}
if ($long) {
list($generic_code_tags, $language_tags, $tag_to_lang) = _geshifilter_get_tags($format);
$languages = _geshifilter_get_enabled_languages();
$lang_attributes = _geshifilter_whitespace_explode(GESHIFILTER_ATTRIBUTES_LANGUAGE);
$output = '<p>' . t('Syntax highlighting of source code can be enabled with the following tags:') . '</p>';
$items = array();
$tags = array();
foreach ($generic_code_tags as $tag) {
$tags[] = '"<code>' . $bracket_open . $tag . $bracket_close . '</code>"';
}
$items[] = t('Generic syntax highlighting tags: !tags.', array(
'!tags' => implode(', ', $tags),
));
$tags = array();
foreach ($language_tags as $tag) {
$tags[] = t('"<code>@tag-code</code>" for @lang source code', array(
'@tag-code' => $bracket_open . $tag . $bracket_close,
'@lang' => $languages[$tag_to_lang[$tag]],
));
}
$items[] = t('Language specific syntax highlighting tags: !tags.', array(
'!tags' => implode(', ', $tags),
));
if (_geshifilter_php_delimeters($format)) {
$items[] = t('PHP source code can also be enclosed in <?php ... ?> or <% ... %>, but additional options like line numbering are not possible here.');
}
$output .= theme('item_list', $items);
$output .= '<p>' . t('Options and tips:') . '</p>';
$items = array();
$att_to_full = array();
foreach ($languages as $langcode => $fullname) {
$att_to_full[$langcode] = $fullname;
}
foreach ($tag_to_lang as $tag => $lang) {
$att_to_full[$tag] = $languages[$lang];
}
ksort($att_to_full);
$att_for_full = array();
foreach ($att_to_full as $att => $fullname) {
$att_for_full[] = t('"<code>@langcode</code>" (for @fullname)', array(
'@langcode' => $att,
'@fullname' => $fullname,
));
}
$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),
));
$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,
));
$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.');
if (_geshifilter_brackets($format) == GESHIFILTER_BRACKETS_BOTH) {
$items[] = t('Beside the tag style "!angle" it is also possible to use "!bracket".', array(
'!angle' => '<code><foo></code>',
'!bracket' => '<code>[foo]</code>',
));
}
$output .= theme('item_list', $items);
$output .= '<p>' . t('Defaults:') . '</p>';
$items = array();
$default_highlighting = variable_get('geshifilter_default_highlighting', GESHIFILTER_DEFAULT_PLAINTEXT);
switch ($default_highlighting) {
case GESHIFILTER_DEFAULT_DONOTHING:
$description = t('when no language attribute is specified the code block won\'t be processed by the GeSHi filter');
break;
case GESHIFILTER_DEFAULT_PLAINTEXT:
$description = t('when no language attribute is specified, no syntax highlighting will be done');
break;
default:
$description = t('the default language used for syntax highlighting is "%default_lang"', array(
'%default_lang' => $default_highlighting,
));
break;
}
$items[] = t('Default highlighting mode for generic syntax highlighting tags: !description.', array(
'!description' => $description,
));
$default_line_numbering = variable_get('geshifilter_default_line_numbering', GESHIFILTER_LINE_NUMBERS_DEFAULT_NONE);
switch ($default_line_numbering) {
case GESHIFILTER_LINE_NUMBERS_DEFAULT_NONE:
$description = t('no line numbers');
break;
case GESHIFILTER_LINE_NUMBERS_DEFAULT_NORMAL:
$description = t('normal line numbers');
break;
default:
$description = t('fancy line numbers (every @n lines)', array(
'@n' => $default_line_numbering,
));
break;
}
$items[] = t('Default line numbering: !description.', array(
'!description' => $description,
));
$output .= theme('item_list', $items);
$output .= '<p>' . t('Examples:') . '</p>';
$header = array(
t('You type'),
t('You get'),
);
$rows = array();
if (count($generic_code_tags)) {
$generic_code_tag = $generic_code_tags[0];
$lang = array_rand($languages);
$generic_code_tag_open = $bracket_open . $generic_code_tag;
$generic_code_tag_close = $bracket_open . '/' . $generic_code_tag . $bracket_close;
$rows[] = array(
'<code>' . $generic_code_tag_open . $bracket_close . 'foo = "bar";' . $generic_code_tag_close . '</code>',
t('Inline code with the default syntax highlighting mode.'),
);
$rows[] = array(
'<code>' . $generic_code_tag_open . $bracket_close . '<br />foo = "bar";<br />baz = "foz";<br />' . $generic_code_tag_close . '</code>',
t('Code block with the default syntax highlighting mode.'),
);
$rows[] = array(
'<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>',
t('Code block with syntax highlighting for @lang source code<br /> and normal line numbers.', array(
'@lang' => $languages[$lang],
)),
);
$rows[] = array(
'<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>',
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],
)),
);
}
if (count($language_tags)) {
$language_tag = $language_tags[0];
$rows[] = array(
'<code>' . $bracket_open . $language_tag . $bracket_close . '<br />foo = "bar";<br />baz = "foz";<br />' . $bracket_open . '/' . $language_tag . $bracket_close . '</code>',
t('Code block with syntax highlighting for @lang source code.', array(
'@lang' => $languages[$tag_to_lang[$language_tag]],
)),
);
$rows[] = array(
'<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>',
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]],
)),
);
}
$output .= theme('table', $header, $rows);
return $output;
}
else {
list($generic_code_tags, $language_tags, $tag_to_lang) = _geshifilter_get_tags($format);
$tags = array();
foreach ($generic_code_tags as $tag) {
$tags[] = '<code>' . $bracket_open . $tag . $bracket_close . '</code>';
}
foreach ($language_tags as $tag) {
$tags[] = '<code>' . $bracket_open . $tag . $bracket_close . '</code>';
}
$output = t('You can enable syntax highlighting of source code with the following tags: !tags.', array(
'!tags' => implode(', ', $tags),
));
if (_geshifilter_brackets($format) == GESHIFILTER_BRACKETS_BOTH) {
$output .= ' ' . t('Beside the tag style "!angle" it is also possible to use "!bracket".', array(
'!angle' => '<code><foo></code>',
'!bracket' => '<code>[foo]</code>',
));
}
if (_geshifilter_php_delimeters($format)) {
$output .= ' ' . t('PHP source code can also be enclosed in <?php ... ?> or <% ... %>.');
}
return $output;
}
}