function tableofcontents_nodeapi in Table of Contents 5.2
Same name and namespace in other branches
- 6.3 tableofcontents.module \tableofcontents_nodeapi()
- 6.2 tableofcontents.module \tableofcontents_nodeapi()
Implementation of hook_nodeapi
We need to clear the cache to cover the case where file attachments have changed, but the body hasn't. This might be a little aggressive, in that we clear the cache for any node with attachments, but since this only occurs during editing or creating the load should be pretty minimal.
File
- ./
tableofcontents.module, line 324 - This is a filter module to generate a collapsible jquery enabled mediawiki style table of contents based on <h[1-6]> tags. Transforms header tags into named anchors.
Code
function tableofcontents_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'prepare':
if (isset($node->files)) {
// Remove the cached version if there attachments on this node
$cid = $node->format . ':' . md5($node->body);
cache_clear_all($cid, 'cache_filter');
}
break;
case 'submit':
if (variable_get("tableofcontents_remove_teaser_{$node->format}", TRUE)) {
$filters = filter_list_format($node->format);
if (isset($filters['tableofcontents/0'])) {
if ($node->teaser && $node->teaser != ($new_teaser = preg_replace('!<\\!-- ?tableofcontents(.*)-->!', '', $node->teaser))) {
// Remove toc from teasers.
$node->teaser = $new_teaser;
}
}
}
break;
}
}