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_category.inc.php

    r1854 r1861  
    7878    if (isset($page['category']))
    7979    {
    80       $query.= ' OR id_uppercat IN ('.$page['uppercats'].')';
     80      $query.= ' OR id_uppercat IN ('.$page['category']['uppercats'].')';
    8181    }
    8282    $query.= ')';
     
    112112  }
    113113
    114   return get_html_menu_category($cats);
     114  return get_html_menu_category($cats, @$page['category'] );
    115115}
    116116
     
    135135function get_cat_info( $id )
    136136{
    137   $infos = array('nb_images','id_uppercat','comment','site_id'
    138                  ,'dir','date_last','uploadable','status','visible'
    139                  ,'representative_picture_id','uppercats','commentable'
    140                  ,'image_order');
    141 
    142137  $query = '
    143 SELECT '.implode(',', $infos).'
     138SELECT *
    144139  FROM '.CATEGORIES_TABLE.'
    145140  WHERE id = '.$id.'
    146141;';
    147   $row = mysql_fetch_array(pwg_query($query));
    148   if (empty($row))
     142  $cat = mysql_fetch_assoc(pwg_query($query));
     143  if (empty($cat))
    149144    return null;
    150145
    151   $cat = array();
    152   foreach ($infos as $info)
    153   {
    154     if (isset($row[$info]))
    155     {
    156       $cat[$info] = $row[$info];
    157     }
    158     else
    159     {
    160       $cat[$info] = '';
    161     }
     146  foreach ($cat as $k => $v)
     147  {
    162148    // If the field is true or false, the variable is transformed into a
    163149    // boolean value.
    164     if ($cat[$info] == 'true' or $cat[$info] == 'false')
    165     {
    166       $cat[$info] = get_boolean( $cat[$info] );
     150    if ($cat[$k] == 'true' or $cat[$k] == 'false')
     151    {
     152      $cat[$k] = get_boolean( $cat[$k] );
    167153    }
    168154  }
     
    171157          preg_match('/<(div|br|img|script).*>/i', $cat['comment']) ) )
    172158  {
    173     $cat['comment'] = nl2br($cat['comment']);
     159    $cat['comment'] = nl2br(@$cat['comment']);
    174160  }
    175161
    176162  $names = array();
    177163  $query = '
    178 SELECT name,id
     164SELECT id, name
    179165  FROM '.CATEGORIES_TABLE.'
    180166  WHERE id IN ('.$cat['uppercats'].')
    181167;';
    182168  $result = pwg_query($query);
    183   while($row = mysql_fetch_array($result))
    184   {
    185     $names[$row['id']] = $row['name'];
     169  while($row = mysql_fetch_assoc($result))
     170  {
     171    $names[$row['id']] = $row;
    186172  }
    187173
    188174  // category names must be in the same order than uppercats list
    189   $cat['name'] = array();
     175  $cat['upper_names'] = array();
    190176  foreach (explode(',', $cat['uppercats']) as $cat_id)
    191177  {
    192     $cat['name'][$cat_id] = $names[$cat_id];
     178    $cat['upper_names'][$cat_id] = $names[$cat_id];
    193179  }
    194180
     
    346332  foreach ($ids as $num => $category_id)
    347333  {
     334    is_numeric($category_id)
     335      or trigger_error(
     336        'get_subcat_ids expecting numeric, not '.gettype($category_id),
     337        E_USER_WARNING
     338      );
    348339    if ($num > 0)
    349340    {
Note: See TracChangeset for help on using the changeset viewer.