function advanced_forum_treat_as_forum_post in Advanced Forum 5
Same name and namespace in other branches
- 6 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 - Preprocesses template variables for the comment wrapper template.
- advanced_forum_preprocess_node in ./
advanced_forum.module - Preprocesses template variables for the node template.
File
- ./
advanced_forum.module, line 1274 - 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 page
// as long as we haven't hit a non forum node on the page
static $forum_node_id;
// Start out assuming it's not one of ours.
$decision = FALSE;
if ($hook == 'node') {
// Make sure this is a forum node type and that it's not being
// shown on some other page (like a view or promoted to front page)
if ($variables['node']->type == 'forum' && (arg(0) == 'node' && is_numeric(arg(1)) && arg(1) == $variables['node']->nid || arg(0) == 'comment')) {
$forum_node_id = $variables['node']->nid;
$decision = TRUE;
}
else {
// In D5, only forum types allowed in the forums so
// we know this isn't a forum thread (or that it's not in the forums).
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 ($decision) {
_advanced_forum_add_files();
}
return $decision;
}