Hello,

I would like to use Advanced Forum module (http://groups.drupal.org/node/7123). I have been reading instructions of how to install it and I have to modify "function _phptemplate_variable" as it's said here: http://drupal.org/node/227108
The problem is that I haven't been able to find such a variable and I don't quite understand how it works. What should I do? which file should I edit? how?

thank you

PS: I'm completely new in Drupal's world (I come from phpnuke) and I don't know if that's the correct place to post a question, if not, accept my apologize and tell me where should I address. Thank you.

CommentFileSizeAuthor
#19 template.php_.txt15.93 KBtrevortwining
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yoroy’s picture

Project: Zen » Advanced Forum
Version: 5.x-1.0 »
Component: Code » Theming

Hi. you should at least post your question to the right issue queue, that of Advanced Forum, not Zen theme.

I can't help you with your actual question but you might have more luck now.

Michelle’s picture

Version: » 5.x-1.0-alpha2

Did you read the explanation at http://drupal.org/node/207841 ?

Michelle

c-c-m’s picture

Sure! I red it (in fact I posted a link that I had to follow from that node), but if I follow step #5 and I paste the following code:

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

at the begining of template.php I get the following errror:

Fatal error: Call to undefined function advanced_profile_forum() in /home/.../template.php on line 3

I paste the content of lines 1-4 here:

<?php
if (module_exists('advanced_forum')) {
    $vars = advanced_profile_forum($hook, $vars);
  } 

I also read the readme file, which is slightly different from that node, but wasn't able to make it work.

The problem is that there's no function "_phptemplate_variables" in Zen's theme, if I make a search, the only instance of _phptemplate_variables is the following one:

* For a sub-theme to add its own variables, instead of _phptemplate_variables,
* use these functions:
* STARTERKIT_preprocess_page(&$vars) to add variables to the page.tpl.php
* STARTERKIT_preprocess_node(&$vars) to add variables to the node.tpl.php
* STARTERKIT_preprocess_comment(&$vars) to add variables to the comment.tpl.php
* STARTERKIT_preprocess_block(&$vars) to add variables to the block.tpl.php
*/

Which I don't understand, since I am new at Drupal's world and I don't understand how does it work. It seems that Zen's theme is slightly different from others' that's why asked about it here instead of asking at Advanced Forum's (answering to yoroy's response)

Any help, please?

Michelle’s picture

Project: Advanced Forum » Zen
Version: 5.x-1.0-alpha2 » 5.x-1.x-dev
Component: Theming » Code

Well, I can see why you got an error. Why did you change the code to "advanced_profile_forum"? There's no such thing. Paste the code on that page I linked you to as is.

As for where to paste it to make it work with subthemes, no idea. For that you'll need to go back to their issue queue so they can explain how to add _phptemplate_variables() to it. Either that or add the call to both the node and comment preprocess functions.

Michelle

c-c-m’s picture

Michelle,

I don't understand what am I supposed to do:

as I said, if I make a search on template.php looking for "function _phptemplate_variables($hook, $vars) {" I don't get anything as a result. The post you provided says I should get a result. All the text is assuming that I have such a function, which, as I have said, it doesn't exist. (it does exist something close to it, but it's commented).

I have pasted the following code (whithout understanding what am I doing):

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

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


  return $vars;
}

and I get the following error:

Fatal error: Cannot redeclare _phptemplate_variables() (previously declared in /home/.../sites/all/themes/zen/template.php:143) in /home/.../sites/all/themes/zen/name/template.php on line 14

It seems that as my theme is a Zen's subtheme, theres another function declared before, so I make a search at Zen's root template.php. That's what I get:

function _phptemplate_variables($hook, $vars = array()) {
  // Get the currently logged in user
  global $user, $theme_key;

  // Set a new $is_admin variable. This is determined by looking at the
  // currently logged in user and seeing if they are in the role 'admin'. The
  // 'admin' role will need to have been created manually for this to work this
  // variable is available to all templates.
  $vars['is_admin'] = in_array('admin', $user->roles);

  // Send a new variable, $logged_in, to tell us if the current user is
  // logged in or out. An anonymous user has a user id of 0.
  $vars['logged_in'] = ($user->uid > 0) ? TRUE : FALSE;

  switch ($hook) {
    case 'page':
      global $theme;

      // These next lines add additional CSS files and redefine
      // the $css and $styles variables available to your page template
      if ($theme == $theme_key) { // If we're in the main theme
        // Load the stylesheet for a liquid layout
        if (theme_get_setting('zen_layout') == 'border-politics-liquid') {
          drupal_add_css($vars['directory'] .'/layout-liquid.css', 'theme', 'all');
        }
        // Or load the stylesheet for a fixed width layout
        else {
          drupal_add_css($vars['directory'] .'/layout-fixed.css', 'theme', 'all');
        }
        drupal_add_css($vars['directory'] .'/html-elements.css', 'theme', 'all');
        drupal_add_css($vars['directory'] .'/tabs.css', 'theme', 'all');
        drupal_add_css($vars['directory'] .'/zen.css', 'theme', 'all');
        // Avoid IE5 bug that always loads @import print stylesheets
        $vars['head'] = zen_add_print_css($vars['directory'] .'/print.css');
      }
      // Optionally add the block editing styles.
      if (theme_get_setting('zen_block_editing')) {
        drupal_add_css($vars['directory'] .'/block-editing.css');
      }
      // Optionally add the wireframes style.
      if (theme_get_setting('zen_wireframes')) {
        drupal_add_css($vars['directory'] .'/wireframes.css', 'theme', 'all');
      }
      $vars['css'] = drupal_add_css();
      $vars['styles'] = drupal_get_css();

      // Allow sub-themes to have an ie.css file
      $vars['subtheme_directory'] = path_to_subtheme();

      // Don't display empty help from node_help().
      if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
        $vars['help'] = '';
      }

      // Classes for body element. Allows advanced theming based on context
      // (home page, node of certain type, etc.)
      $body_classes = array();
      $body_classes[] = ($vars['is_front']) ? 'front' : 'not-front';
      $body_classes[] = ($vars['logged_in']) ? 'logged-in' : 'not-logged-in';
      if ($vars['node']->type) {
        // If on an individual node page, put the node type in the body classes
        $body_classes[] = 'node-type-'. $vars['node']->type;
      }
      if ($vars['sidebar_left'] && $vars['sidebar_right']) {
        $body_classes[] = 'two-sidebars';
      }
      elseif ($vars['sidebar_left']) {
        $body_classes[] = 'one-sidebar sidebar-left';
      }
      elseif ($vars['sidebar_right']) {
        $body_classes[] = 'one-sidebar sidebar-right';
      }
      else {
        $body_classes[] = 'no-sidebars';
      }
	  
	  
	  
      if (!$vars['is_front']) {
        // Add unique classes for each page and website section
        $path = drupal_get_path_alias($_GET['q']);
        list($section,) = explode('/', $path, 2);
        $body_classes[] = zen_id_safe('page-'. $path);
        $body_classes[] = zen_id_safe('section-'. $section);
        if (arg(0) == 'node') {
          if (arg(1) == 'add') {
            if ($section == 'node') {
              array_pop($body_classes); // Remove 'section-node'
            }
            $body_classes[] = 'section-node-add'; // Add 'section-node-add'
          }
          elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
            if ($section == 'node') {
              array_pop($body_classes); // Remove 'section-node'
            }
            $body_classes[] = 'section-node-'. arg(2); // Add 'section-node-edit' or 'section-node-delete'
          }
        }
      }
      $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces

      break;

    case 'node':
      // Special classes for nodes
      $node_classes = array();
      if ($vars['sticky']) {
        $node_classes[] = 'sticky';
      }
      if (!$vars['node']->status) {
        $node_classes[] = 'node-unpublished';
        $vars['unpublished'] = TRUE;
      }
      else {
        $vars['unpublished'] = FALSE;
      }
      if ($vars['node']->uid && $vars['node']->uid == $user->uid) {
        // Node is authored by current user
        $node_classes[] = 'node-mine';
      }
      if ($vars['teaser']) {
        // Node is displayed as teaser
        $node_classes[] = 'node-teaser';
      }
      // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
      $node_classes[] = 'node-type-'. $vars['node']->type;
      $vars['node_classes'] = implode(' ', $node_classes); // Concatenate with spaces

      break;

    case 'comment':
      // We load the node object that the current comment is attached to
      $node = node_load($vars['comment']->nid);
      // If the author of this comment is equal to the author of the node, we
      // set a variable so we can theme this comment uniquely.
      $vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;

      $comment_classes = array();

      // Odd/even handling
      static $comment_odd = TRUE;
      $comment_classes[] = $comment_odd ? 'odd' : 'even';
      $comment_odd = !$comment_odd;

      if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) {
        $comment_classes[] = 'comment-unpublished';
        $vars['unpublished'] = TRUE;
      }
      else {
        $vars['unpublished'] = FALSE;
      }
      if ($vars['author_comment']) {
        // Comment is by the node author
        $comment_classes[] = 'comment-by-author';
      }
      if ($vars['comment']->uid == 0) {
        // Comment is by an anonymous user
        $comment_classes[] = 'comment-by-anon';
      }
      if ($user->uid && $vars['comment']->uid == $user->uid) {
        // Comment was posted by current user
        $comment_classes[] = 'comment-mine';
      }
      $vars['comment_classes'] = implode(' ', $comment_classes);

      // If comment subjects are disabled, don't display 'em
      if (variable_get('comment_subject_field', 1) == 0) {
        $vars['title'] = '';
      }

      break;

    case 'block':
      $block = $vars['block'];

      // Special classes for blocks
      $block_classes = array();
      $block_classes[] = 'block-'. $block->module;
      $block_classes[] = 'region-'. $vars['block_zebra'];
      $block_classes[] = $vars['zebra'];
      $block_classes[] = 'region-count-'. $vars['block_id'];
      $block_classes[] = 'count-'. $vars['id'];
      $vars['block_classes'] = implode(' ', $block_classes);

      if (theme_get_setting('zen_block_editing') && user_access('administer blocks')) {
        // Display 'edit block' for custom blocks
        if ($block->module == 'block') {
          $edit_links[] = l('<span>'. t('edit block') .'</span>', 'admin/build/block/configure/'. $block->module .'/'. $block->delta, array('title' => t('edit the content of this block'), 'class' => 'block-edit'), drupal_get_destination(), NULL, FALSE, TRUE);
        }
        // Display 'configure' for other blocks
        else {
          $edit_links[] = l('<span>'. t('configure') .'</span>', 'admin/build/block/configure/'. $block->module .'/'. $block->delta, array('title' => t('configure this block'), 'class' => 'block-config'), drupal_get_destination(), NULL, FALSE, TRUE);
        }

        // Display 'administer views' for views blocks
        if ($block->module == 'views' && user_access('administer views')) {
          $edit_links[] = l('<span>'. t('edit view') .'</span>', 'admin/build/views/'. $block->delta .'/edit', array('title' => t('edit the view that defines this block'), 'class' => 'block-edit-view'), drupal_get_destination(), 'edit-block', FALSE, TRUE);
        }
        // Display 'edit menu' for menu blocks
        elseif (($block->module == 'menu' || ($block->module == 'user' && $block->delta == 1)) && user_access('administer menu')) {
          $edit_links[] = l('<span>'. t('edit menu') .'</span>', 'admin/build/menu', array('title' => t('edit the menu that defines this block'), 'class' => 'block-edit-menu'), drupal_get_destination(), NULL, FALSE, TRUE);
        }
        $vars['edit_links_array'] = $edit_links;
        $vars['edit_links'] = '<div class="edit">'. implode(' ', $edit_links) .'</div>';
      }

      break;
  }

As you see I'm not sure where does it end, so I don't know what to put and where. In addition there's no "function _phptemplate_variables($hook, $vars) {" but function _phptemplate_variables($hook, $vars = array()) { which is close, but not the same.

Could you please help me?

Thank you!

Michelle’s picture

The docs you pasted say " For a sub-theme to add its own variables, instead of _phptemplate_variables, use these functions:". Which means you either need to paste it in both the node and comment preprocess functions listed there or you need to find out how you can add _phptemplate_variables to Zen. Beyond that, I don't know. The version of Zen I use is 1.5 years old and doesn't have all this stuff. You need someone familiar with the theme to help you. This isn't specific to advforum. It's a matter of knowing how to add variables to your theme.

Michelle

c-c-m’s picture

Thanks for trying to help, Michelle, but I don't understand what should I do. I don't feel confident with Drupal's nor Zen's nor php, but thanks anyway. By the way, isn't this the right place to ask for help about Zen's theme? Is there any official support? a better place to ask for help? (sorry, I don't quite understand how does a so huge website works)

JohnAlbin’s picture

ccm & Michelle, it looks like these modules just need to add some variables to the node.tpl.php and comment.tpl.php files.

So, in your sub-themes template.php file, just before the STARTERKIT_preprocess_node() function and just before the STARTERKIT_preprocess_comment(), you need to delete this line:

/* -- Delete this line if you want to use this function

You should also delete the example code: $vars['sample_variable'] = t('Lorem ipsum.'); and replace it with the code that advanced_forum and advanced_profile recommend.

And, obviously, “STARTERKIT” needs to be replaced with whatever the name of your sub-theme is (as the Zen installation instructions say.)

Let me know if you need me to spell it out more, ccm.

JohnAlbin’s picture

Status: Active » Postponed (maintainer needs more info)
Michelle’s picture

Yeah, that should do it. I don't have any plans to use anything but the node and comment hooks in D5 and in D6 this issue totally goes away, thank the devs.

Michelle

c-c-m’s picture

Thanks for your reply, JohnAlbin,

I think I found the commented lines, I deleted that line and replaced

/* -- Delete this line if you want to use this function
function themename_preprocess_page(&$vars) {
  $vars['sample_variable'] = t('Lorem ipsum.');
}

with:

function themename_preprocess_page(&$vars) {
  if (module_exists('advanced_forum')) {
    $vars = advanced_profile_forum($hook, $vars);
  }
}

wich corresponds to lines 131-135,

but I get the following error:

Fatal error: Call to undefined function advanced_profile_forum() in /home/.../sites/all/themes/zen/themename/template.php on line 133

What did I do wrong?

JohnAlbin’s picture

Project: Zen » Advanced Forum
Component: Code » Documentation
Status: Postponed (maintainer needs more info) » Active

No clue. Michelle?

c-c-m’s picture

Don't say that, JohnAlbin! :(

Isn't there any way to implement advanced forums with Zen's theme? Is there any way to contact (and get a response) from their creators: Jeff Robbins with Lullabot?

What should be the process to implement it? maybe I forgot to do something or I did something wrong...

Hope someone can help me with the issue.

Thanks

Michelle’s picture

See comment #4.

Michelle

c-c-m’s picture

Michelle, I saw it and I replied it at #5. I wasn't able to follow instructions and I provided details about the problems I encountered. Could you be more clear, please?

Thanks

Michelle’s picture

Yes, you corrected it in #5 but then you went and changed it back to "advanced_profile_forum" again. You need to paste exactly what I have there and don't change the function name otherwise you're trying to call a function that doesn't exist.

Michelle

Michelle’s picture

Status: Active » Fixed

Ok, I need to apologize. I had looked at the explanation page to make sure it was accurate but the mis-copy was actually on the main page and I totally missed it. I just got bit by it when I copied it without looking onto my own site. LOL

I fixed the documentation so you should be all set.

Michelle

c-c-m’s picture

Michelle, I got lost. I didn't understand what did you change (sorry, I'm not English speaker, and I have difficulties in understanding English and php ;) )

I re-red the node http://drupal.org/node/207841 again.

I seached for:

function _phptemplate_variables($hook, $vars) {

Since I didn't get any result, I copied:

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

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


  return $vars;
}

at the begining of the file
but I got the same error:

Fatal error: Cannot redeclare _phptemplate_variables() (previously declared in /home/.../sites/all/themes/zen/template.php:143) in /home/.../sites/all/themes/zen/plusarquitectura/template.php on line 14

What am I doing wrong?

thanks

trevortwining’s picture

FileSize
15.93 KB

c-c-m,

Here is a replacement file for zen/template.php. I tested it locally and it should work on your system. If you've made any other changes to this file, they will be overwritten by this version.

you can find the specific changes on lines 375-381 so you can see what was done/changed.

c-c-m’s picture

Thank you.

it now works!

c-c-m’s picture

Well, it doesn't work completely... Forums are displayed propperly, but when I watch a node and comments, those are displayed as regular forum, not in advanced forum way. What would be the problem? I'm pretty sure of having followed instructions at readme.txt file

Michelle’s picture

Status: Fixed » Postponed (maintainer needs more info)

That's because the call to advforum isn't right. He put it in the 'block' hook so it's not getting called in the right place.

Take that code he added and move it just above this line:

// The following is a deprecated function included for backwards compatibility

That should hopefully fix it.

Michelle

c-c-m’s picture

Perfect, Michelle! Now it works.

Michelle’s picture

Status: Postponed (maintainer needs more info) » Fixed

Thank goodness! :)

Michelle

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.