Hello all,

First off, I tried searching through this forum to find a simple solution to my question but alas, I found nothing that I was able to understand. Please excuse my ignorance, but I am a brand newbie to the Drupal community, and not very much of a programmer. However, I do have a limited knowledge of PHP coming from the PostNuke world.

I am trying to follow this tutorial located here:

http://www.drupalart.org/phpbb

I've gotten everything setup as far as the php-template theme, and I have template.php already. But where I get stuck is when it says, "If you already have a template.php file, simply merge this code with the other php code you might have in the file."

For the past few hours, this has not been a simple task for me. I really don't know how to begin with merging these two files.

I just try to keep putting the code in places I think it might fit and I receive error messages such as this one:

Fatal error: Cannot redeclare _phptemplate_variables() (previously declared in /home/threeone/public_html/d/themes/civicspace/template.php:250) in /home/threeone/public_html/d/themes/civicspace/template.php on line 893

I don't want to give up on Drupal because I think it looks very promising in the things it can do and I am trying my best to learn it.

So if anyone knows how to at least, point me in the right direction that would be greatly appreciated.

Thanks much!

txcrew

Comments

potential’s picture

When you add code to the template.php file, you just paste the code AFTER the code thats in there. You don't need to insert it within the existing code.

<?php 
//EXISTING CODE 
?>
<?php 
//NEW CODE 
?>

I do remember reading something about reseting a variable or something at the begining of each php code snippit when you have more than one. I think it was posted by Dublin Drupaler. Maybe someone else can comment on this.

Anonymous’s picture

Just tried that and the result was this:

edit:removed live url

Please let me know what you think

Anonymous’s picture

So, perhaps my question should be...

How can you merge the flatforum into Civicspace theme.

Thanks.

zirafa’s picture

Just to follow up, I answered txcrew's question through email (I also wrote that phpbb tutorial).

Basically you just need to merge the code as follows:

BEFORE:

//code from template.php #1
//code from template.php #2

AFTER:

//code from #1
//code from #2

Also, please note that the tutorial linked above was tested on the phptemplate box_grey theme. The CivicSpace theme may try and override the CSS used in the tutorial. So if you follow the tutorial and it doesn't work with your theme check it with box grey to see if that is the cause. Good luck!

-zirafa

ethang’s picture

I can't figure out how to combine flatforum's template.php and multiflex's template.php. I've thoroughly searched on this topic, and can't find a usable document.

Any chance somebody could provide a usable template.php that integrates the flatforum _phptemplate_variables ?

I'm using drupal 4.7.3 and flatforum for 4.7 and the multiflex theme. I tried to join them myself (listed below) - I don't get any errors but flatforum still not working... I get the same old regular forum. What am I doing wrong?

Here's my template.php:


function phptemplate_block_list($region) {
  //  This is the list function from the block module.  We have to comment
  // out the throttle test, which for some reason breaks node previews.
  // As a result, if blocks are throttled, we may get the wrong layout.
  global $user, $theme_key;

  static $blocks = array();

  if (!count($blocks)) {
    $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s' AND status = 1 ORDER BY region, weight, module", $theme_key);
    while ($block = db_fetch_object($result)) {
      if (!isset($blocks[$block->region])) {
        $blocks[$block->region] = array();
      }
      // Use the user's block visibility setting, if necessary
      if ($block->custom != 0) {
        if ($user->uid && isset($user->block[$block->module][$block->delta])) {
          $enabled = $user->block[$block->module][$block->delta];
        }
        else {
          $enabled = ($block->custom == 1);
        }
      }
      else {
        $enabled = TRUE;
      }

      // Match path if necessary
      if ($block->pages) {
        if ($block->visibility < 2) {
          $path = drupal_get_path_alias($_GET['q']);
          $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/';
          $page_match = !($block->visibility xor preg_match($regexp, $path));
        }
        else {
          $page_match = drupal_eval($block->pages);
        }
      }
      else {
         $page_match = TRUE;
      }

      if ($enabled && $page_match) {
        // Check the current throttle status and see if block should be displayed
        // based on server load.
//         if (!($block->throttle && (module_invoke('throttle', 'status') > 0))) {
//           $array = module_invoke($block->module, 'block', 'view', $block->delta);
//           if (isset($array) && is_array($array)) {
//             foreach ($array as $k => $v) {
//               $block->$k = $v;
//             }
//           }
//         }
        if (isset($block->content) && $block->content) {
          $blocks[$block->region]["{$block->module}_{$block->delta}"] = $block;
        }
      }
    }
  }
  // Create an empty array if there were no entries
  if (!isset($blocks[$region])) {
    //    $blocks[$region] = array();
    return 0;
  }

  return 1;//$blocks[$region];
}

function _phptemplate_variables($hook, $vars) {
  // Detect whether left and right sidebars are used, and
  // set layoutcode accordingly
  $vars['layoutcode'] = '3';  // default - right
  if ($left=phptemplate_block_list("left")) {
    $vars['layoutcode'] = '2'; }   // left
  if ($left && phptemplate_block_list("right")) {
    $vars['layoutcode'] = '1'; } //both
  return $vars;

  // Flatforum Module Added within _phptemplate_variables() function 
  // by ethang - Aug 2005

  // $Id: template.php,v 1.7 2006/05/11 18:17:29 ayman Exp $

  
    static $is_forum;
  $variables = array();
  if (!isset($is_forum)) {
    if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
      $nid = arg(1);
    }
    if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) {
      $nid = arg(2);
    }
    if ($nid) {
      $node = node_load(array('nid' => $nid));
    }
    $is_forum = ($node && $node->type == 'forum');
    _is_forum($is_forum);
  }
  if ($is_forum) {
    switch ($hook) {
      case 'comment' :
        $variables['template_file'] = 'node-forum';
        $variables['row_class'] = _row_class();
        $variables['name'] = $vars['author'];
        $variables['userid'] = $vars['comment']->uid;
        $joined = module_invoke('flatforum', 'get_created', $vars['comment']->uid);
        $variables['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
        $posts = module_invoke('flatforum', 'get', $vars['comment']->uid);
        $variables['posts'] = $posts ? $posts : 0;
        $variables['submitted'] = format_date($vars['comment']->timestamp);
        $subject = $vars['comment']->subject;
        $variables['title'] = empty($subject) ? '&nbsp' : $subject;
        $variables['content'] = $vars['comment']->comment;
        $variables['links'] = empty($vars['links']) ? '&nbsp' : $vars['links'];
        break;
      case 'node' :
        $variables['row_class'] = _row_class();
        $variables['userid']=$vars['node']->uid;
        $joined = module_invoke('flatforum', 'get_created', $vars['node']->uid);
        $variables['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
        $posts = module_invoke('flatforum', 'get', $vars['node']->uid);
        $variables['posts'] = $posts ? $posts : 0;
        $variables['title'] = empty($vars['title']) ? '&nbsp' : $vars['title'];
        $variables['content'] = $vars['node']->body;
        $variables['links'] = empty($vars['links']) ? '&nbsp' : $vars['links'];
        break;
    }
  }
  return $variables;
}
function _row_class() {
  static $forum_row = TRUE;
  $forum_row = !$forum_row;
  return $forum_row ? 'odd' : 'even';
}
function _is_forum($arg = NULL) {
  static $is_forum = FALSE;
  if ($arg) {
    $is_forum = $arg;
  }
  return $is_forum;
  
}

function phptemplate_menu_tree($pid=1) {
  // Code adapted from the nice_menus module
  // generates nested <ul> <li> lists
  $menu = menu_get_menu($pid); 
  $output = ''; 
  if ($menu['visible'][$pid]['children']) {
    foreach ($menu['visible'][$pid]['children'] as $mid) {
      if (count($menu['visible'][$mid]['children']) > 0) {
	$output.= "<li>".menu_item_link($mid);
	if (menu_in_active_trail($mid)) { // only output children if they should be seen
	  $output.= "<ul>";
	  $tmp = phptemplate_menu_tree($mid);
	  $output.= $tmp;
	  $output.= "</ul>";
	}
	$output.= "</li>";
      } 
      else {
	$output.= "<li>".menu_item_link($mid)."</li>";
      }
    }
  }
  return $output;
}
Jofaba’s picture

I don't know an awful lot about php but I've tried everything that I've read so far and it kills my entire site. IF anyone can figure out how to merge the templates.php for the Multiflex theme that'd be awesome.

arifjinha’s picture

I pasted the new code to merge with the template.php file it follows the suggested format

php.template #1
php.template #2 

Any idea why it doesn't work, I still get

Fatal error: Cannot redeclare _phptemplate_variables() (previously declared in /home/uottawag/public_html/globe/themes/mollio/template.php:4) in /home/uottawag/public_html/globe/themes/mollio/template.php on line 393

line 393 is where the new code starts at //$Id. This is a clip of what the transition looks like.

...

'footer' => t('footer'),
    'storyimage' => t('story image'),
	'articleblocks' => t('article blocks')
  );
}

// $Id: template.php,v 1.7 2006/05/11 18:17:29 ayman Exp $

function _phptemplate_variables($hook, $vars) {
  static $is_forum;

...
--
Arif Jinha
CIHAD uottawa
www.uottawaglobe.ca

arifjinha’s picture

What ended up working is removing the "function_phptemplate_variables ..." of the code that will be merged, and just started with "static_$is forum" in the variables section.

I'm no programmer, but what this seems to do is avoid the line which 'redeclares' variables and includes the variables in that section of code (the next section in my template.php is 'custom navigable links'.)

Looks like this.

<?php
/* $Id: template.php,v 1.1.4.2 2006/05/17 20:27:17 rkerr Exp $ */

function  _phptemplate_variables($hook, $vars) {
    /* in this case, a hook refers to the beginning of tpl.php file
    Thus, case 'page' affects page.tpl.php. 'node' affects node.tpl.php, and case 'block' would affect
    block.tpl.php  */
    switch($hook) {
        case 'node' :
            /* $vars['article_blocks'] is $article blocks in node.tpl.php */
            $vars['articleblocks']= theme_blocks('articleblocks');
        break;
    }
    return $vars;
}
 {
   static $is_forum;
  $variables = array();
  if (!isset($is_forum)) {
    if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
      $nid = arg(1);
    }
    if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) {
      $nid = arg(2);
    }
    if ($nid) {
      $node = node_load(array('nid' => $nid));
    }
    $is_forum = ($node && $node->type == 'forum');
    _is_forum($is_forum);
  }
  if ($is_forum) {
    switch ($hook) {
      case 'comment' :
        $variables['template_file'] = 'node-forum';
        $variables['row_class'] = _row_class();
        $variables['name'] = $vars['author'];
        $variables['userid'] = $vars['comment']->uid;
        $joined = module_invoke('flatforum', 'get_created', $vars['comment']->uid);
        $variables['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
        $posts = module_invoke('flatforum', 'get', $vars['comment']->uid);
        $variables['posts'] = $posts ? $posts : 0;
        $variables['submitted'] = format_date($vars['comment']->timestamp);
        $subject = $vars['comment']->subject;
        $variables['title'] = empty($subject) ? '&nbsp' : $subject;
        $variables['content'] = $vars['comment']->comment;
        $variables['links'] = empty($vars['links']) ? '&nbsp' : $vars['links'];
        break;
      case 'node' :
        $variables['row_class'] = _row_class();
        $variables['userid']=$vars['node']->uid;
        $joined = module_invoke('flatforum', 'get_created', $vars['node']->uid);
        $variables['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
        $posts = module_invoke('flatforum', 'get', $vars['node']->uid);
        $variables['posts'] = $posts ? $posts : 0;
        $variables['title'] = empty($vars['title']) ? '&nbsp' : $vars['title'];
        $variables['content'] = $vars['node']->body;
        $variables['links'] = empty($vars['links']) ? '&nbsp' : $vars['links'];
        break;
    }
  }
  return $variables;
}
function _row_class() {
  static $forum_row = TRUE;
  $forum_row = !$forum_row;
  return $forum_row ? 'odd' : 'even';
}
function _is_forum($arg = NULL) {
  static $is_forum = FALSE;
  if ($arg) {
    $is_forum = $arg;
  }
  return $is_forum;
}

The next section of the orginal template.php begins with

// custom navigation links
function mollio_nav($parent, $items = array(), $main_class = '') {
  $i = 0;

It seems to be working!
--
Arif Jinha
CIHAD uottawa
www.uottawaglobe.ca