Ignore:
Timestamp:
Jan 20, 2011, 2:32:34 PM (13 years ago)
Author:
plg
Message:

bug 937 fixed: makes sure a user won't see the thumbnail of a photo that has a
higher privacy level than user privacy level.

For an acceptable solution at performance level, I have implemented a cache:
for a given user, each album has a representative_picture_id. This cache also
avoids to perform numerous "order by rand()" SQL queries which is the case
when $confallow_random_representative = true;

File:
1 edited

Legend:

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

    r8728 r8802  
    496496}
    497497
     498/**
     499 * Find a random photo among all photos below a given album in the tree (not
     500 * only photo directly associated to the album but also to sub-albums)
     501 *
     502 * we need $category['uppercats'], $category['id'], $category['count_images']
     503 */
     504function get_random_image_in_category($category)
     505{
     506  $image_id = null;
     507  if ($category['count_images']>0)
     508  {
     509    $query = '
     510SELECT image_id
     511  FROM '.CATEGORIES_TABLE.' AS c
     512    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id
     513  WHERE (c.id='.$category['id'].' OR uppercats LIKE \''.$category['uppercats'].',%\')'
     514    .get_sql_condition_FandF
     515    (
     516      array
     517        (
     518          'forbidden_categories' => 'c.id',
     519          'visible_categories' => 'c.id',
     520          'visible_images' => 'image_id',
     521        ),
     522      "\n  AND"
     523    ).'
     524  ORDER BY '.DB_RANDOM_FUNCTION.'()
     525  LIMIT 1
     526;';
     527    $result = pwg_query($query);
     528    if (pwg_db_num_rows($result) > 0)
     529    {
     530      list($image_id) = pwg_db_fetch_row($result);
     531    }
     532  }
     533
     534  return $image_id;
     535}
    498536?>
Note: See TracChangeset for help on using the changeset viewer.