diff options
Diffstat (limited to 'include/category_cats.inc.php')
-rw-r--r-- | include/category_cats.inc.php | 91 |
1 files changed, 41 insertions, 50 deletions
diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php index 414bc24ca..bb048297f 100644 --- a/include/category_cats.inc.php +++ b/include/category_cats.inc.php @@ -2,7 +2,7 @@ // +-----------------------------------------------------------------------+ // | Piwigo - a PHP based photo gallery | // +-----------------------------------------------------------------------+ -// | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org | +// | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | // +-----------------------------------------------------------------------+ @@ -37,6 +37,7 @@ SELECT date_last, max_date_last, count_images, + nb_categories, count_categories FROM '.CATEGORIES_TABLE.' c INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ucc @@ -46,7 +47,7 @@ SELECT if ('recent_cats' == $page['section']) { $query.= ' - WHERE date_last >= '.pwg_db_get_recent_period_expression($user['recent_period']); + WHERE '.get_recent_photos_sql('date_last'); } else { @@ -66,9 +67,6 @@ if ('recent_cats' != $page['section']) ORDER BY rank'; } -$query.= ' -;'; - $result = pwg_query($query); $categories = array(); $category_ids = array(); @@ -83,55 +81,52 @@ while ($row = pwg_db_fetch_assoc($result)) { $image_id = $row['user_representative_picture_id']; } - else if (!empty($row['representative_picture_id'])) + elseif (!empty($row['representative_picture_id'])) { // if a representative picture is set, it has priority $image_id = $row['representative_picture_id']; } - else if ($conf['allow_random_representative']) - { - // searching a random representant among elements in sub-categories + elseif ($conf['allow_random_representative']) + { // searching a random representant among elements in sub-categories $image_id = get_random_image_in_category($row); } - else + elseif ($row['count_categories']>0 and $row['count_images']>0) { // searching a random representant among representant of sub-categories - if ($row['count_categories']>0 and $row['count_images']>0) + $query = ' +SELECT representative_picture_id + FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' + ON id = cat_id and user_id = '.$user['id'].' + WHERE uppercats LIKE \''.$row['uppercats'].',%\' + AND representative_picture_id IS NOT NULL' + .get_sql_condition_FandF + ( + array + ( + 'visible_categories' => 'id', + ), + "\n AND" + ).' + ORDER BY '.DB_RANDOM_FUNCTION.'() + LIMIT 1 +;'; + $subresult = pwg_query($query); + if (pwg_db_num_rows($subresult) > 0) { - $query = ' - SELECT representative_picture_id - FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' - ON id = cat_id and user_id = '.$user['id'].' - WHERE uppercats LIKE \''.$row['uppercats'].',%\' - AND representative_picture_id IS NOT NULL' - .get_sql_condition_FandF - ( - array - ( - 'visible_categories' => 'id', - ), - "\n AND" - ).' - ORDER BY '.DB_RANDOM_FUNCTION.'() - LIMIT 1 - ;'; - $subresult = pwg_query($query); - if (pwg_db_num_rows($subresult) > 0) - { - list($image_id) = pwg_db_fetch_row($subresult); - } + list($image_id) = pwg_db_fetch_row($subresult); } } + if (isset($image_id)) { if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id) { - $user_representative_updates_for[ $user['id'].'#'.$row['id'] ] = $image_id; + $user_representative_updates_for[ $row['id'] ] = $image_id; } $row['representative_picture_id'] = $image_id; - array_push($image_ids, $image_id); - array_push($categories, $row); - array_push($category_ids, $row['id']); + $image_ids[] = $image_id; + $categories[] = $row; + $category_ids[] = $row['id']; } unset($image_id); } @@ -212,12 +207,12 @@ SELECT * if (isset($image_id) and !in_array($image_id, $image_ids)) { - array_push($new_image_ids, $image_id); + $new_image_ids[] = $image_id; } if ($conf['representative_cache_on_level']) { - $user_representative_updates_for[ $user['id'].'#'.$category['id'] ] = $image_id; + $user_representative_updates_for[ $category['id'] ] = $image_id; } $category['representative_picture_id'] = $image_id; @@ -252,18 +247,14 @@ if (count($user_representative_updates_for)) { $updates = array(); - foreach ($user_representative_updates_for as $user_cat => $image_id) + foreach ($user_representative_updates_for as $cat_id => $image_id) { - list($user_id, $cat_id) = explode('#', $user_cat); - - array_push( - $updates, + $updates[] = array( - 'user_id' => $user_id, + 'user_id' => $user['id'], 'cat_id' => $cat_id, 'user_representative_picture_id' => $image_id, - ) - ); + ); } mass_updates( @@ -305,7 +296,7 @@ if (count($categories) > 0) if ($page['section']=='recent_cats') { - $name = get_cat_display_name_cache($category['uppercats'], null, false); + $name = get_cat_display_name_cache($category['uppercats'], null); } else { @@ -361,8 +352,8 @@ if (count($categories) > 0) } else { - $info = sprintf( - l10n('from %s to %s'), + $info = l10n( + 'from %s to %s', format_date($from), format_date($to) ); |