NOTE: Ignore the opening and closing PHP tags in here. They are just for display and should not be added to your file.

Advanced Forum for D5 needs you to add to the _phptemplate_variables function in template.php. The problem is that this function varies from theme to theme so there's no easy way to simply say "replace X with Y". In 5.x, there's simply no way around this if you need variables sent to templates. Thank the devs, this is fixed in 6.x.

Rather than trying to provide template.php files for every conceivable theme, I'm going to attempt to explain this in terms that even non programmers can understand.

The first step is to find template.php in your theme. It's possible your theme doesn't have one as it's not a required file. If there isn't one there already, create one with a text editor.

If there was an existing template.php, we need to see if there is an existing _phptemplate_variables function. If there isn't, then we need to add the whole thing. If there is, though, we need to merge into it.

Look for a line that reads:

function _phptemplate_variables($hook, $vars) {

This is the start of the function. A function basically a bit of code that takes in values, runs some code, and returns a value to the code that calls it. In this case, what is being passed in is $hook and $vars. These are variables and they hold a value. Every time the function runs, they get their value from the function that calls it. $hook will usually be "page", "node", or "comment" depending on what Drupal is trying to show on the page. $vars is what is called an "array" and it holds many values. It comes in with some values already set and then this function will add more to it. $vars is what needs to be sent back out to the calling function.

Inside this function, you'll find code that checks to see what the value of $hook is. There are two ways of doing that: IF and SWITCH. So you may see code like:

if ($hook == 'node') { DO SOMETHING }

Or you may see something more complex like:

switch ($hook) {
  case 'node':
    DO SOMETHING;
  case 'comment':
    DO ANOTHER THING;
}

In both of these, it's saying, if $hook holds the value "node" then we run this code. If it holds the value "comment" then run this code. In this way you can add different variables depending on what Drupal is showing.

Somewhere in the function should be a line that says "return $vars". This is where we run into trouble. Some themes put that line into the IF/SWITCH above. What that means is that the function will only send back $vars if the hook matches a particular thing, such as "node". Let's say they put it in at the end of "case 'node';". Then the function only returns a value when displaying nodes. If we need to add variables to comments, then it won't work. We need to have it at the end, outside of the IF/SWITCH so it returns the value no matter what.

Now that you understand this function at least a little bit, this is the code we need to add to make advanced forum work:

  if (module_exists('advanced_forum')) {
    $vars = advanced_forum_addvars($hook, $vars);
  }

What this is saying is "If the module advanced_forum is enabled, then call a function in it to add more values into the $vars variable. By calling a function, you don't need to try and merge in code for both node and comment. You just need to add these three lines to the very top of the function, right after the line function _phptemplate_variables($hook, $vars) { and before any other code. Then you need to make sure there is a return $vars at the very end, after all the other code, and right before the } that closes the function. If you see a return array() there, replace it. Otherwise just add the line.

In the end, you should have a function that looks like this:

function _phptemplate_variables($hook, $vars) {
   if (module_exists('advanced_forum')) {
    $vars = advanced_forum_addvars($hook, $vars);
  }

/***EXISTING CODE IN THE FUNCTION, IF ANY***/

  return $vars;
}