Changeset 569


Ignore:
Timestamp:
Oct 21, 2004, 11:17:46 PM (20 years ago)
Author:
z0rglub
Message:

code refactoring for function get_cat_display_name

File:
1 edited

Legend:

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

    r528 r569  
    151151//   - $style : the style of the span tag for the lowest category,
    152152//     "font-style:italic;" for example
    153 function get_cat_display_name( $cat_informations, $separator,
    154   $url = 'category.php?cat=', $replace_space = true)
     153function get_cat_display_name($cat_informations,
     154                              $separator,
     155                              $url = 'category.php?cat=',
     156                              $replace_space = true)
    155157{
    156158  $output = '';
    157   $i=0;
    158   while ( list ($id, $name) = each($cat_informations))
    159   {
    160     if ( $i )  $output.= $separator;
    161         $i++;
    162         if (empty($style) && empty($url) || ($i == count( $cat_informations)))
    163           $output.= $name;
    164     elseif (!empty($url))
    165       $output.= '<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.$url.$id).'">'.$name."</a>";
    166         else
    167       $output.= '<span style="'.$style.'">'.$name.'</span>';
    168   }
    169   if ( $replace_space ) return replace_space( $output );
    170   else                  return $output;
     159  $is_first = true;
     160  foreach ($cat_informations as $id => $name)
     161  {
     162    if ($is_first)
     163    {
     164      $is_first = false;
     165    }
     166    else
     167    {
     168      $output.= $separator;
     169    }
     170
     171    if ($url == '')
     172    {
     173      $output.= $name;
     174    }
     175    else
     176    {
     177      $output.= '
     178<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.$url.$id).'">'.$name.'</a>';
     179    }
     180  }
     181  if ($replace_space)
     182  {
     183    return replace_space($output);
     184  }
     185  else
     186  {
     187    return $output;
     188  }
    171189}
    172190
Note: See TracChangeset for help on using the changeset viewer.