<?php
/**
 * This file is a compilation of commonly used phptemplate override files.
 * Nothing in this file should be specific to any particular theme.
 * 
 * All functions in this file should be of the phptemplate_ variety of override.
 * This allows the template.php to still us themename_ overrides to avoid any
 * function name collision.
 * 
 */
 
/**
 * Add frontpage 'active' state handling to menu links
 * and menu-[title] as css id
 */
function phptemplate_menu_item_link($item, $link_item) {
  static $menu;
  if (!isset($menu)) { 
    $menu = menu_get_menu(); 
  }
  $mid = $menu['path index'][$link_item['path']];
  $front = variable_get('site_frontpage','node');
  
  $attribs = isset($item['description']) ? array('title' => $item['description']) : array();
  $attribs['class'] = 'menu-'. str_replace(' ', '-', strtolower($item['title'])); 
  if((($link_item['path']=='<front>') && ($front==$_GET['q'])) ||
     (($item['pid'] == variable_get('menu_primary_menu',0)) && menu_in_active_trail($mid))){
    $attribs['class'] .= ' active';
  }else{
    //$attribs['rel'] = $link_item['path'];
     }
  return l($item['title'], $link_item['path'], $attribs);
} 

function phptemplate_get_section(){
  $trail = _menu_get_active_trail();
  /*
   * $trail[0] == menu 
   * $trail[1] == top level nav item
   * $trail[2] == second level nav item
   */
  if(($trail[0]==variable_get('menu_primary_menu',0)) &&
     isset($trail[1]) && ($trail[1] > 0)){
    $item = menu_get_item($trail[1]);
    return strtolower(str_replace(' ', '_',$item['title']));
  }else{
    return 'none';
  }

}

/**
 * Theme all forms by first trying to call node-{content-type}-form.tpl.php
 * if $form['#node'] isset. Otherwise fall through and let the default 
 * form_render take care of it.  This does require that a node-form.tpl.php
 * template file be placed in the theme directory.  node-form.tpl.php can be
 * empty in which case the default form_render takes place.
 */
function phptemplate_node_form($form) {
  if(isset($form['#node'])){
    return _phptemplate_callback('node-form', array('form' => $form), 
      'node-'.$form['#node']->type.'-form');
  }
}

