function _tableofcontents_hide_in_teaser in Table of Contents 7
Same name and namespace in other branches
- 6.3 tableofcontents.admin.inc \_tableofcontents_hide_in_teaser()
- 7.2 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.
Parameters
$node The node which teaser will be tweaked:
1 call to _tableofcontents_hide_in_teaser()
- tableofcontents_node_presave in ./
tableofcontents.module - Implementation of hook_node_presave
File
- ./
tableofcontents.admin.inc, line 420 - 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->body[$node->language][0]['summary']) {
return;
}
// node uses our filter?
$filters = filter_list_format($node->body[$node->language][0]['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->body[$node->language][0]['summary'] == $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[$node->language][0]['value'], '<!--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[$node->language][0]['value']);
if ($body != $node->body[$node->language][0]['value']) {
$node->body[$node->language][0]['value'] = $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[$node->language][0]['value'] = '<!--break-->' . $node->body[$node->language][0]['value'];
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->body[$node->language][0]['summary'] = $new_teaser . '<div>[toc hidden:1]</div>';
}