function _tableofcontents_replace_toc_tags in Table of Contents 7
Same name and namespace in other branches
- 6.3 tableofcontents.pages.inc \_tableofcontents_replace_toc_tags()
This function replaces one [toc ...] tag.
Note that all the toc tags receive the same headers, but each may have a different set of parameters.
@todo Unfortunately, since we use the preg_replace_callback() functions to increase speed we run in the problem of having to use a global variable to hold all the TOC information. This function must make a copy of it to avoid problems later.
Parameters
$toc The TOC object:
$matches The matches of one [toc ...] tag:
Return value
The replacement for that [toc ...] tag
1 string reference to '_tableofcontents_replace_toc_tags'
- _tableofcontents_replace_toc in ./
tableofcontents.pages.inc - This function replaces the table of contents.
File
- ./
tableofcontents.pages.inc, line 459 - Applies the filter functions.
Code
function _tableofcontents_replace_toc_tags($matches) {
global $_tableofcontents_toc;
// we do not want options in this [toc ...] tag to affect the following [toc ...] tags
$save_toc = clone $_tableofcontents_toc;
// we always want to check the options because hidden:1 is always accepted!
$options = isset($matches[1]) ? $matches[1] : '';
_tableofcontents_get_options($_tableofcontents_toc, $options);
if ($_tableofcontents_toc->hidden) {
$_tableofcontents_toc = $save_toc;
// replace that table of contents with nothing (i.e. hiding it!)
return '';
}
// Is user allowed to override options?
if (!$_tableofcontents_toc->allow_override) {
// Nope, then restore!
$_tableofcontents_toc = $save_toc;
}
elseif ($_tableofcontents_toc->safe_title && $_tableofcontents_toc->title != $save_toc->title) {
$_tableofcontents_toc->title = check_plain(strip_tags($_tableofcontents_toc->title));
}
// If attachments are enabled, prepare the $_tableofcontents_toc->files variable
if ($_tableofcontents_toc->attachments && arg(0) == 'node' && is_numeric(arg(1)) && module_exists('upload')) {
$node = node_load(arg(1));
$_tableofcontents_toc->files = $node->files;
}
$result = theme('tableofcontents_toc', array(
'toc' => $_tableofcontents_toc,
));
$_tableofcontents_toc = $save_toc;
if ($result) {
$_tableofcontents_toc->has_toc = TRUE;
}
return $result;
}