function _tableofcontents_hide_in_teaser in Table of Contents 6.3
Same name and namespace in other branches
- 7.2 tableofcontents.admin.inc \_tableofcontents_hide_in_teaser()
- 7 tableofcontents.admin.inc \_tableofcontents_hide_in_teaser()
This function makes sure that the table of content is hidden in the teaser if so requested by the user.
@param[in] $node The node which teaser will be tweaked
1 call to _tableofcontents_hide_in_teaser()
- tableofcontents_nodeapi in ./
tableofcontents.module - Implementation of hook_nodeapi
File
- ./
tableofcontents.admin.inc, line 393 - Include the different setup (administration forms) for the table of contents module.
Code
function _tableofcontents_hide_in_teaser(&$node) {
// node got a teaser?
if (!$node->teaser) {
return;
}
// node uses our filter?
$filters = filter_list_format($node->format);
if (!isset($filters['tableofcontents/0'])) {
return;
}
// any [toc ...] tag in the teaser?
$new_teaser = preg_replace('%(<!--\\s*tableofcontents([^>]*)-->|\\[\\[TOC.*?\\]\\]|(<(div|p)(\\s+[^>]*)?' . '>\\s*)?\\[toc.*?\\](\\s*</(div|p)>)?)%', '', $node->teaser);
if ($node->teaser == $new_teaser) {
// okay, no [toc ...], but maybe we need to hide the table of content?
if (!variable_get('tableofcontents_automatic_' . $node->format, 0)) {
return;
}
}
if (strpos($node->body, '<!--break-->') !== FALSE) {
// We've specified the split, but the teaser is shown in full
// view. So, we now have to convert it so that the table of
// content is hidden in the teaser.
$body = '<!--break-->' . str_replace('<!--break-->', '', $node->body);
if ($body != $node->body) {
$node->body = $body;
drupal_set_message(t("The content you saved contains a table of contents. A separate summary (teaser) has been automatically created without the table of contents at the top. If you make any further changes, be sure to check the summary field to see if your changes apply there as well."));
}
}
else {
// This is the case where no teaser was specified by the user.
// We add an explicit split teaser.
$node->body = '<!--break-->' . $node->body;
drupal_set_message(t("The summary (teaser) was automatically split from the body as site settings does not allow table of contents in summaries. If you make any further changes, be sure to check the summary field to see if your changes apply there as well."));
}
// Remove toc from teasers.
$node->teaser = $new_teaser . '<div>[toc hidden:1]</div>';
}