Ignore:
Timestamp:
Nov 20, 2004, 6:23:42 PM (19 years ago)
Author:
plg
Message:
  • optimization : representative picture becomes mandatory for a non empty category. So, at each insertion in images table for a category, a new representative element is elected (by rand). This must be improved by not reelcting a random picture admin set an element as representative manually.
  • optimization : recent cats page only needs 2 queries instead of 3*N (N categories to display). The bad point is that it shows representative element of recent cat and not a random element among recently added.
  • optimization : empty cats page only needs 1 query per non empty sub category instead of... a lot. For each sub category, PhpWebGallery shows the representative element of a category chosen randomly in sub cats. Thus, get_non_empty_subcat_ids and get_first_non_empty_cat_id becomes obsolete.
  • new function get_cat_display_name_cache to show category names with a caching for all gallery categories names. This function, to the contrary of get_cat_display_name shows names in the correct order...
File:
1 edited

Legend:

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

    r593 r610  
    198198
    199199/**
     200 * returns the list of categories as a HTML string, with cache of names
     201 *
     202 * categories string returned contains categories as given in the input
     203 * array $cat_informations. $uppercats is the list of category ids to
     204 * display in the right order. If url input parameter is empty, returns only
     205 * the categories name without links.
     206 *
     207 * @param string uppercats
     208 * @param string separator
     209 * @param string url
     210 * @param boolean replace_space
     211 * @return string
     212 */
     213function get_cat_display_name_cache($uppercats,
     214                                    $separator,
     215                                    $url = 'category.php?cat=',
     216                                    $replace_space = true)
     217{
     218  global $cat_names;
     219
     220  if (!isset($cat_names))
     221  {
     222    $query = '
     223SELECT id,name
     224  FROM '.CATEGORIES_TABLE.'
     225;';
     226    $result = pwg_query($query);
     227    while ($row = mysql_fetch_array($result))
     228    {
     229      $cat_names[$row['id']] = $row['name'];
     230    }
     231  }
     232 
     233  $output = '';
     234  $is_first = true;
     235  foreach (explode(',', $uppercats) as $category_id)
     236  {
     237    $name = $cat_names[$category_id];
     238   
     239    if ($is_first)
     240    {
     241      $is_first = false;
     242    }
     243    else
     244    {
     245      $output.= $separator;
     246    }
     247
     248    if ($url == '')
     249    {
     250      $output.= $name;
     251    }
     252    else
     253    {
     254      $output.= '
     255<a class=""
     256   href="'.add_session_id(PHPWG_ROOT_PATH.$url.$category_id).'">'.$name.'</a>';
     257    }
     258  }
     259  if ($replace_space)
     260  {
     261    return replace_space($output);
     262  }
     263  else
     264  {
     265    return $output;
     266  }
     267}
     268
     269/**
    200270 * returns the HTML code for a category item in the menu (for category.php)
    201271 *
Note: See TracChangeset for help on using the changeset viewer.