function advanced_forum_treat_as_forum_post in Advanced Forum 6
Same name and namespace in other branches
- 5 advanced_forum.module \advanced_forum_treat_as_forum_post()
This function returns TRUE if the node/comment should be themed and otherwise treated as a forum post.
3 calls to advanced_forum_treat_as_forum_post()
- advanced_forum_preprocess_comment in ./
advanced_forum.module - Preprocesses template variables for the comment template.
- advanced_forum_preprocess_comment_wrapper in ./
advanced_forum.module - advanced_forum_preprocess_node in ./
advanced_forum.module - Preprocesses template variables for the node template.
File
- ./
advanced_forum.module, line 1383 - Enables the look and feel of other popular forum software.
Code
function advanced_forum_treat_as_forum_post($hook, $variables) {
// Setting this static means the check only needs to be done once per thread
static $forum_node_id;
// Start out assuming it's not one of ours.
$decision = FALSE;
if ($hook == 'node') {
$vid = variable_get('forum_nav_vocabulary', '');
$vocabulary = taxonomy_vocabulary_load($vid);
if (empty($vocabulary) || !in_array($variables['node']->type, $vocabulary->nodes)) {
// No forum vocabulary or the node type cannot be used in the forums
unset($forum_node_id);
$decision = FALSE;
}
elseif (arg(1) == 'add' && arg(2) == 'forum') {
// Previewing a new forum post. Checking just for 'forum' is not ideal
// but covers most use cases and will do for now.
unset($forum_node_id);
$decision = TRUE;
}
else {
// Get a list of the terms attached to this node
$terms = taxonomy_node_get_terms_by_vocabulary($variables['node'], $vid);
if (count($terms) > 0 && (arg(0) == 'node' && is_numeric(arg(1)) && arg(1) == $variables['node']->nid || arg(0) == 'comment')) {
// The node has at least one forum term attached to it and is not being
// shown on some other page (like a view or promoted to front page)
$forum_node_id = $variables['node']->nid;
$decision = TRUE;
}
else {
// We've hit a non forum node
unset($forum_node_id);
$decision = FALSE;
}
}
}
if ($hook == 'comment') {
if (isset($forum_node_id) && $variables['comment']->nid == $forum_node_id) {
// We already know this comment is either part of a forum thread
// or that comments on this thread are known exceptions.
$decision = TRUE;
}
else {
// Not part of a forum thread. Check if this site wants all comments to
// use the forum comment template or the comment is being shown alone via
// the comment_page module
if (variable_get("advanced_forum_theme_all_comments", 0) == 1 || arg(0) == 'comment' && is_numeric(arg(1))) {
// This site wants all comments to use the forum comment template
$forum_node_id = $variables['comment']->nid;
$decision = TRUE;
}
else {
// If we are on a comment reply page, check if the node/comment gets styled.
if (arg(0) == 'comment' && arg(1) == 'reply') {
$nid = arg(2);
$variables['node'] = node_load($nid);
$decision = advanced_forum_treat_as_forum_post('node', $variables);
}
}
}
}
if ($hook == 'comment-wrapper') {
if (isset($forum_node_id) && $variables['node']->nid == $forum_node_id) {
// We only want to use our comment wrapper if we are on a node that
// passed the tests.
$decision = TRUE;
}
}
// Call a hook with our decisions and the available information. If it returns
// a number, override our decision and set the static variable to that number.
$override_nids = module_invoke_all('treat_as_forum_post_alter', $decision, $hook, $variables);
if (!empty($override_nids)) {
// At least one module has returned an nid. We are making an assumption here
// that if there was more than one the nids are the same and just grabbing
// the first one.
$forum_node_id = $override_nids[0];
if ($forum_node_id == -1) {
unset($forum_node_id);
$decision = FALSE;
}
else {
$decision = TRUE;
}
}
// If we're claiming this one, there are a few things we need to do...
if ($decision) {
_advanced_forum_add_files();
}
return $decision;
}