diff --git a/advanced_forum.module b/advanced_forum.module index 1b469b3..2d989b6 100644 --- a/advanced_forum.module +++ b/advanced_forum.module @@ -1387,3 +1387,63 @@ function advanced_forum_post_position($node, $comment) { return $post_position; } + +/** + * Implements hook_expire_cache_alter(). + * + * When a comment or forum node are cleared. Make sure that the parent + * term form pages are also cleared. + * If the forum post has a language prefix also clears all of the same + * paths with the langage prefix. + */ +function advanced_forum_expire_cache_alter(&$urls, $object_type, $object, $absolute_urls_passed = FALSE) { + // For nodes use the object as node. + if ($object_type == 'node') { + $node = $object; + } + // Or for comments use the comments node as the node. + elseif ($object_type == 'comment') { + $node = node_load($object->nid); + // Make sure we wildcard the node when clearing so pagination is cleared. + if (!isset($urls['node-' . $object->nid])) { + $urls['node-' . $node->nid] = 'node/' . $node->nid; + } + $urls['node-' . $node->nid] = $urls['node-' . $node->nid] . '|wildcard'; + } + else { + // Do nothing if not node or comment. + return; + } + + // Only do actions on nodes which have a forum-tid object. + if (isset($node->forum_tid)) { + $urls['forum'] = 'forum'; + $urls['forum_id'] = 'forum/' . $node->forum_tid . '|wildcard'; + + // Get every parent term and clear, but not wildcard. + $parents = taxonomy_get_parents_all($node->forum_tid); + foreach ($parents as $parent) { + // Clear the forum path. + if ($parent->tid != $node->forum_tid) { + $urls['forum_parent_' . $parent->tid] = 'forum/' . $parent->tid; + } + } + } + // If the object has a language with a prefix remove the same urls + prefix. + $lang = $node->language; + $languages = language_list(); + if (isset($languages[$lang]) && $languages[$lang]->prefix != '') { + $new_urls = array(); + foreach ($urls as $key => $value) { + $new_path = preg_replace("/\|wildcard$/", "", $value, 1, $wildcard); + $new_path = ltrim(url($new_path, array('language' => $languages[$lang])), '/'); + if ($wildcard) { + $new_path = $new_path . "|wildcard"; + } + $new_urls[$key . '_' . $lang] = $new_path; + } + $urls = array_merge($urls, $new_urls); + } + return $urls; +} +