function _tableofcontents_filter_process in Table of Contents 7.2
Process the text for the table of content.
This adds the information about the [toc] to the text regardless of whether it will actually be converted to a [toc] in the end.
1 call to _tableofcontents_filter_process()
- tableofcontents_filter_process in ./
tableofcontents.module - Implements hook_filter_FILTER_process(). (sort of)
File
- ./
tableofcontents.filters.inc, line 59 - Table of Contents - Versatile system for generating Tables of Contents for fields - filters.
Code
function _tableofcontents_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) {
if (!$text) {
return $text;
}
$encoded_toc = '';
$toc = $filter->settings['tableofcontents'];
// Does this have [toc] already?
if (strpos($text, '[toc') === FALSE) {
// No it doesn't...
static $default;
if (!isset($default)) {
// Just do this once, in case it's wanted again.
$default = _tableofcontents_toc_encode($toc);
}
// No, just encode the full default settings
$encoded_toc = $default;
// Do we want this at the top or bottom (or nowhere?)
switch ($toc['on_off']['automatic']) {
case 0:
// Actually not required.
break;
case 1:
$text = '[toc]' . $text;
break;
case 2:
$text .= '[toc]';
break;
}
}
else {
// Yes, so extract toc settings from [toc] in text,
// then merge with defaults and encode
$new_toc = _tableofcontents_toc_extract($text);
$toc = merge_arrays($toc, $new_toc);
$encoded_toc = _tableofcontents_toc_encode($toc);
}
// Replace the old [toc] with the new [toc]
# tableofcontents_set()
return preg_replace(TABLEOFCONTENTS_REMOVE_PATTERN, "[toc {$encoded_toc}]", $text);
}