function geshifilter_filter in GeSHi Filter for syntax highlighting 5
Same name and namespace in other branches
- 5.2 geshifilter.module \geshifilter_filter()
- 6 geshifilter.module \geshifilter_filter()
Implementation of hook_filter()
File
- ./
geshifilter.module, line 281
Code
function geshifilter_filter($op, $delta = 0, $format = -1, $text = '') {
//disable cache for developpement cause nocache doesn't work
switch ($op) {
case 'list':
return array(
0 => t('GeSHi filter'),
);
case 'description':
return t('Allows users to post hightlighted code verbatim using <blockcode type="<em>language</em>"> tag.');
case 'settings':
$lang_dir = variable_get('geshifilter_lang_dir', drupal_get_path('module', 'geshifilter') . '/geshi/geshi');
// Find languages in the directory, we get a table where key == value
$files = file_scan_directory($lang_dir, '\\.php$', array(
'.',
'..',
'CVS',
'geshi.php',
), 0, FALSE, 'name');
//produce an associative array whit keys equal to values
$languages = drupal_map_assoc(array_keys($files));
uasort($languages, 'strnatcasecmp');
$languages_select = $languages;
$languages_select[0] = t('- DO NOT HIGHLIGHT -');
$form['geshifilter'] = array(
'#type' => 'fieldset',
'#title' => t('GeSHi filter'),
);
$form['geshifilter']['geshifilter_inline_code_' . $format] = array(
'#type' => 'checkbox',
'#title' => t('Highlight inline code'),
'#default_value' => variable_get('geshifilter_inline_code_' . $format, FALSE),
'#description' => t('Enable highligthing for code surrounded by <code>...</code> tags.'),
);
$form['geshifilter']['geshifilter_default_type_' . $format] = array(
'#type' => 'select',
'#title' => t('Default language'),
'#default_value' => variable_get('geshifilter_default_type_' . $format, 0),
'#options' => $languages_select,
'#description' => t('Default language pattern used to highlight posted code where type="<em>language</em>" param is omitted.'),
);
$form['geshifilter']['geshifilter_types_' . $format] = array(
'#type' => 'checkboxes',
'#title' => t('Allowed Languages'),
'#default_value' => variable_get('geshifilter_types_' . $format, array()),
'#options' => $languages,
'#description' => t('Check every languages you want to be allowed for highlighting (i.e. usable in <em>lang</em> param).'),
);
//pass the format value, so filter_admin_configure_validate can know which format is being processed
$form['geshifilter']['format'] = array(
'#type' => 'hidden',
'#default_value' => $format,
);
return $form;
case 'prepare':
return $text;
case 'process':
return _geshifilter_process_code($format, $text);
default:
return $text;
}
}