Changeset 21802


Ignore:
Timestamp:
Mar 23, 2013, 11:50:57 AM (11 years ago)
Author:
rvelices
Message:

feature 2557 recent photos/albums should never be empty

Location:
trunk/include
Files:
3 edited

Legend:

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

    r20177 r21802  
    4747{
    4848  $query.= '
    49   WHERE date_last >= '.pwg_db_get_recent_period_expression($user['recent_period']);
     49  WHERE '.get_recent_photos_sql('date_last');
    5050}
    5151else
     
    6767}
    6868
    69 $query.= '
    70 ;';
    71 
    7269$result = pwg_query($query);
    7370$categories = array();
     
    8481    $image_id = $row['user_representative_picture_id'];
    8582  }
    86   else if (!empty($row['representative_picture_id']))
     83  elseif (!empty($row['representative_picture_id']))
    8784  { // if a representative picture is set, it has priority
    8885    $image_id = $row['representative_picture_id'];
    8986  }
    90   else if ($conf['allow_random_representative'])
    91   {
    92     // searching a random representant among elements in sub-categories
     87  elseif ($conf['allow_random_representative'])
     88  { // searching a random representant among elements in sub-categories
    9389    $image_id = get_random_image_in_category($row);
    9490  }
    95   else
     91  elseif ($row['count_categories']>0 and $row['count_images']>0)
    9692  { // searching a random representant among representant of sub-categories
    97     if ($row['count_categories']>0 and $row['count_images']>0)
    98     {
    99       $query = '
    100   SELECT representative_picture_id
    101     FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
    102     ON id = cat_id and user_id = '.$user['id'].'
    103     WHERE uppercats LIKE \''.$row['uppercats'].',%\'
    104       AND representative_picture_id IS NOT NULL'
    105     .get_sql_condition_FandF
    106     (
    107       array
    108         (
    109           'visible_categories' => 'id',
    110         ),
    111       "\n  AND"
    112     ).'
    113     ORDER BY '.DB_RANDOM_FUNCTION.'()
    114     LIMIT 1
    115   ;';
    116       $subresult = pwg_query($query);
    117       if (pwg_db_num_rows($subresult) > 0)
    118       {
    119         list($image_id) = pwg_db_fetch_row($subresult);
    120       }
    121     }
    122   }
     93    $query = '
     94SELECT representative_picture_id
     95  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
     96  ON id = cat_id and user_id = '.$user['id'].'
     97  WHERE uppercats LIKE \''.$row['uppercats'].',%\'
     98    AND representative_picture_id IS NOT NULL'
     99  .get_sql_condition_FandF
     100  (
     101    array
     102      (
     103        'visible_categories' => 'id',
     104      ),
     105    "\n  AND"
     106  ).'
     107  ORDER BY '.DB_RANDOM_FUNCTION.'()
     108  LIMIT 1
     109;';
     110    $subresult = pwg_query($query);
     111    if (pwg_db_num_rows($subresult) > 0)
     112    {
     113      list($image_id) = pwg_db_fetch_row($subresult);
     114    }
     115  }
     116
    123117
    124118  if (isset($image_id))
     
    130124
    131125    $row['representative_picture_id'] = $image_id;
    132     array_push($image_ids, $image_id);
    133     array_push($categories, $row);
    134     array_push($category_ids, $row['id']);
     126    $image_ids[] = $image_id;
     127    $categories[] = $row;
     128    $category_ids[] = $row['id'];
    135129  }
    136130  unset($image_id);
  • trunk/include/functions_user.inc.php

    r21801 r21802  
    827827    {
    828828      $cache['default_user'] = pwg_db_fetch_assoc($result);
    829      
     829
    830830      unset($cache['default_user']['user_id']);
    831831      unset($cache['default_user']['status']);
     
    11261126  {
    11271127    require_once(PHPWG_ROOT_PATH.'include/passwordhash.class.php');
    1128    
     1128
    11291129    // We use the portable hash feature from phpass because we can't be sure
    11301130    // Piwigo runs on PHP 5.3+ (and won't run on an older version in the
     
    11321132    $pwg_hasher = new PasswordHash(13, true);
    11331133  }
    1134  
     1134
    11351135  return $pwg_hasher->HashPassword($password);
    11361136}
     
    11611161      $check = ($hash == md5($password));
    11621162    }
    1163    
     1163
    11641164    if ($check and isset($user_id) and !$conf['external_authentification'])
    11651165    {
     
    11801180  {
    11811181    require_once(PHPWG_ROOT_PATH.'include/passwordhash.class.php');
    1182    
     1182
    11831183    // We use the portable hash feature
    11841184    $pwg_hasher = new PasswordHash(13, true);
     
    12011201function pwg_login($success, $username, $password, $remember_me)
    12021202{
    1203   if ($success===true) 
     1203  if ($success===true)
    12041204  {
    12051205    return true;
    12061206  }
    1207  
     1207
    12081208  // we force the session table to be clean
    12091209  pwg_session_gc();
     
    12321232{
    12331233  global $conf;
    1234  
     1234
    12351235  trigger_action('user_logout', @$_SESSION['pwg_uid']);
    1236  
     1236
    12371237  $_SESSION = array();
    12381238  session_unset();
     
    15551555}
    15561556
     1557/** @return the sql condition to show recent photos/albums based on user preferences and latest available photo.*/
     1558function get_recent_photos_sql($db_field)
     1559{
     1560  global $user;
     1561  if (!isset($user['last_photo_date']))
     1562  {
     1563    return '0=1';
     1564  }
     1565  return $db_field.'>=LEAST('
     1566    .pwg_db_get_recent_period_expression($user['recent_period'])
     1567    .','.pwg_db_get_recent_period_expression(1,$user['last_photo_date']).')';
     1568}
     1569
    15571570/**
    15581571 * search an available activation_key
  • trunk/include/section_init.inc.php

    r20453 r21802  
    453453  FROM '.IMAGES_TABLE.'
    454454    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
    455   WHERE
    456     date_available >= '.pwg_db_get_recent_period_expression($user['recent_period']).'
    457     '.$forbidden.'
    458   '.$conf['order_by'].'
     455  WHERE '
     456  .get_recent_photos_sql('date_available').'
     457  '.$forbidden
     458  .$conf['order_by'].'
    459459;';
    460460
Note: See TracChangeset for help on using the changeset viewer.