Seeing as you're using phpTemplate, you get passed a whole load of variables when you load a page (or anything?).

Instead of having a separate _is_forum() function or doing a node load, simply do something like this:

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
      if(arg(0) == 'forum' || $vars['type'] == 'forum' || $vars['node']->type == 'forum') {
        $vars['template_file'] = 'page-forum';
      }
      break;
  }

There are, as far as I can see, 3 situation (or at least there are on our site at the time of writing).
1) You're looking at the forum overview - check arg(0) as this page has no type per-se.
2) You're viewing a list of forums - this seems to have the forum type in $vars.
3) You're viewing a forum node - simply take a peek at the node object in the $vars array.

I hope this helps in some way!

PS: This wont work for comments...

Comments

nicholasthompson’s picture

Correction - it will work for comments - this is an adaptation (work in progress) of the template that comes with the current 4.7 download...

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
      if(arg(0) == 'forum' || $vars['type'] == 'forum' || $vars['node']->type == 'forum') {
        $vars['template_file'] = 'page-forum';
      }
      
    case 'node':
      if($vars['type'] == 'forum') {
        $vars['row_class'] = _row_class();
        $vars['userid']=$vars['node']->uid;
        $joined = module_invoke('flatforum', 'get_created', $vars['node']->uid);
        $vars['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
        $posts = module_invoke('flatforum', 'get', $vars['node']->uid);
        $vars['posts'] = $posts ? $posts : 0;
        $vars['title'] = empty($vars['title']) ? '&nbsp' : $vars['title'];
        $vars['content'] = $vars['node']->body;
        $vars['links'] = empty($vars['links']) ? '&nbsp' : $vars['links'];
      }
      break;

    case 'comment' :
      $cnode = node_load($vars['comment']->nid);

      if($cnode->type == 'forum') {
        $vars['template_file'] = 'node-forum';
        $vars['row_class'] = _row_class();
        $vars['name'] = $vars['author'];
        $vars['userid'] = $vars['comment']->uid;
        $joined = module_invoke('flatforum', 'get_created', $vars['comment']->uid);
        $vars['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
        $posts = module_invoke('flatforum', 'get', $vars['comment']->uid);
        $vars['posts'] = $posts ? $posts : 0;
        $vars['submitted'] = format_date($vars['comment']->timestamp);
        $subject = $vars['comment']->subject;
        $vars['title'] = empty($subject) ? '&nbsp' : $subject;
        $vars['content'] = $vars['comment']->comment;
        $vars['links'] = empty($vars['links']) ? '&nbsp' : $vars['links'];
      }
      
      break;
  }


  return $vars;
}

I looked up the code for node_load and, once the overhead of loading a node is done once, its all stored in a static array. Therefore its not too bad loading a nid for a set of comments as they should all share the same node.

airblaster’s picture

Somehow I don't understand how to use this function.
Is there any case where node-forum.tpl is loaded outside a forum?

nicholasthompson’s picture

Somehow I don't understand how to use this function.

That code either needs to be pasted into template.php or amalgamated with an existing variables function.

Is there any case where node-forum.tpl is loaded outside a forum?

In theory - no... Also, in theory, node-form.tpl.php wont ever be loaded without the code above or the code in the readme for flatforum. Drupal wont know what it is.

azote’s picture

Hi nicholasThompson, I tested your code with 5.1 and doing it like that it will use the node-forum.tpl.php even when the node is promoted been loaded from the front page.
So looks kind of weird having a forum like post embedded in the front of your website ...

airblaster’s picture

I guess you can fix this by using drupal_is_front_page().
Untested Code with added front_page checks :

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
      if((arg(0) == 'forum' || $vars['type'] == 'forum' || $vars['node']->type == 'forum') && !drupal_is_front_page()) {
        $vars['template_file'] = 'page-forum';
      }
      
    case 'node':
      if($vars['type'] == 'forum' && !drupal_is_front_page()) {
        $vars['row_class'] = _row_class();
        $vars['userid']=$vars['node']->uid;
        $joined = module_invoke('flatforum', 'get_created', $vars['node']->uid);
        $vars['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
        $posts = module_invoke('flatforum', 'get', $vars['node']->uid);
        $vars['posts'] = $posts ? $posts : 0;
        $vars['title'] = empty($vars['title']) ? '&nbsp' : $vars['title'];
        $vars['content'] = $vars['node']->body;
        $vars['links'] = empty($vars['links']) ? '&nbsp' : $vars['links'];
      }
      break;

    case 'comment' :
      $cnode = node_load($vars['comment']->nid);

      if($cnode->type == 'forum' &&  !drupal_is_front_page()) {
        $vars['template_file'] = 'node-forum';
        $vars['row_class'] = _row_class();
        $vars['name'] = $vars['author'];
        $vars['userid'] = $vars['comment']->uid;
        $joined = module_invoke('flatforum', 'get_created', $vars['comment']->uid);
        $vars['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
        $posts = module_invoke('flatforum', 'get', $vars['comment']->uid);
        $vars['posts'] = $posts ? $posts : 0;
        $vars['submitted'] = format_date($vars['comment']->timestamp);
        $subject = $vars['comment']->subject;
        $vars['title'] = empty($subject) ? '&nbsp' : $subject;
        $vars['content'] = $vars['comment']->comment;
        $vars['links'] = empty($vars['links']) ? '&nbsp' : $vars['links'];
      }
      
      break;
  }


  return $vars;
}
azote’s picture

yeah nic that works ...
but I had to comment out:
>$vars['content'] = $vars['node']->body;
on the node case because the content of the node on the front page was null..
any ideas why is this?

azote’s picture

ops sorry for the previous post nic... I forgot to add the check for frontpage at the case for the node.

any ideas how to only remove the navigation for the forums only?
I tried this but it was just a 20secs guest...

/* removes the next and previous links */
function phptemplate_forum_topic_navigation($node){
        if($node->type == 'forum'){
        return _phptemplate_callback('forum_topic_navigation', array('node' => $node));
}else{
        return theme_forum_topic_navigation($node);
} }
michelle’s picture

Status: Active » Closed (fixed)

Just tidying up.

Michelle