Ignore:
Timestamp:
Feb 27, 2007, 2:56:16 AM (17 years ago)
Author:
rvelices
Message:
  • refactoring pagecategory before 1.7 release

pagecategory is not an id anymore, but an associative array of category info
all of pagecat_xxx or pageuppercats merged into one
simplifies calls to make_index_url
give plugins a clean start for page variables for version 1.7

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_html.inc.php

    r1855 r1861  
    236236 * categories string returned contains categories as given in the input
    237237 * array $cat_informations. $cat_informations array must be an association
    238  * of {category_id => category_name}. If url input parameter is null,
     238 * of {category_id => array( id, name) }. If url input parameter is null,
    239239 * returns only the categories name without links.
    240240 *
     
    252252  $output = '';
    253253  $is_first = true;
    254   foreach ($cat_informations as $id => $name)
    255   {
     254  foreach ($cat_informations as $id => $cat)
     255  {
     256    is_array($cat) or trigger_error(
     257        'get_cat_display_name wrong type for cat '.$id, E_USER_WARNING
     258      );
    256259    if ($is_first)
    257260    {
     
    265268    if ( !isset($url) )
    266269    {
    267       $output.= $name;
     270      $output.= $cat['name'];
    268271    }
    269272    elseif ($url == '')
     
    272275            .make_index_url(
    273276                array(
    274                   'category'=>$id,
    275                   'cat_name'=>$name
     277                  'category' => $cat,
    276278                  )
    277279              )
    278280            .'">';
    279       $output.= $name.'</a>';
     281      $output.= $cat['name'].'</a>';
    280282    }
    281283    else
    282284    {
    283285      $output.= '<a href="'.PHPWG_ROOT_PATH.$url.$id.'">';
    284       $output.= $name.'</a>';
     286      $output.= $cat['name'].'</a>';
    285287    }
    286288  }
     
    312314                                    $replace_space = true)
    313315{
    314   global $cat_names, $conf;
    315 
    316   if (!isset($cat_names))
     316  global $cache, $conf;
     317
     318  if (!isset($cache['cat_names']))
    317319  {
    318320    $query = '
    319 SELECT id,name
     321SELECT id, name
    320322  FROM '.CATEGORIES_TABLE.'
    321323;';
    322324    $result = pwg_query($query);
    323     while ($row = mysql_fetch_array($result))
    324     {
    325       $cat_names[$row['id']] = $row['name'];
     325    while ($row = mysql_fetch_assoc($result))
     326    {
     327      $cache['cat_names'][$row['id']] = $row;
    326328    }
    327329  }
     
    331333  foreach (explode(',', $uppercats) as $category_id)
    332334  {
    333     $name = $cat_names[$category_id];
     335    $cat = $cache['cat_names'][$category_id];
    334336
    335337    if ($is_first)
     
    344346    if ( !isset($url) )
    345347    {
    346       $output.= $name;
     348      $output.= $cat['name'];
    347349    }
    348350    elseif ($url == '')
     
    352354      .make_index_url(
    353355          array(
    354             'category'=>$category_id,
    355             'cat_name'=>$name
     356            'category' => $cat,
    356357            )
    357358        )
    358       .'">'.$name.'</a>';
     359      .'">'.$cat['name'].'</a>';
    359360    }
    360361    else
    361362    {
    362363      $output.= '
    363 <a href="'.PHPWG_ROOT_PATH.$url.$category_id.'">'.$name.'</a>';
     364<a href="'.PHPWG_ROOT_PATH.$url.$category_id.'">'.$cat['name'].'</a>';
    364365    }
    365366  }
     
    385386 * @return string
    386387 */
    387 function get_html_menu_category($categories)
    388 {
    389   global $page, $lang;
     388function get_html_menu_category($categories, $selected_category)
     389{
     390  global $lang;
    390391
    391392  $ref_level = 0;
     
    393394  $menu = '';
    394395
    395   // $page_cat value remains 0 for special sections
    396   $page_cat = 0;
    397   if (isset($page['category']))
    398   {
    399     $page_cat = $page['category'];
    400   }
    401 
    402396  foreach ($categories as $category)
    403397  {
     
    420414
    421415    $menu.= "\n\n".'<li';
    422     if ($category['id'] == $page_cat)
     416    if ($category['id'] == @$selected_category['id'])
    423417    {
    424418      $menu.= ' class="selected"';
     
    428422    $url = make_index_url(
    429423            array(
    430               'category'=>$category['id'],
    431               'cat_name'=>$category['name']
     424              'category' => $category
    432425              )
    433426            );
    434427
    435428    $menu.= "\n".'<a href="'.$url.'"';
    436     if ($page_cat != 0
    437         and $category['id'] == $page['cat_id_uppercat'])
     429    if ($selected_category!=null
     430        and $category['id'] == $selected_category['id_uppercat'])
    438431    {
    439432      $menu.= ' rel="up"';
     
    510503{
    511504  $cat_info = get_cat_info($cat_id);
    512   return get_cat_display_name($cat_info['name'], $url, $replace_space);
     505  return get_cat_display_name($cat_info['upper_names'], $url, $replace_space);
    513506}
    514507
Note: See TracChangeset for help on using the changeset viewer.