Skip to content

Commit

Permalink
feature 2557 recent photos/albums should never be empty
Browse files Browse the repository at this point in the history
git-svn-id: http://piwigo.org/svn/trunk@21802 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rvelices committed Mar 23, 2013
1 parent 19d831b commit 55275ef
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 48 deletions.
64 changes: 29 additions & 35 deletions include/category_cats.inc.php
Expand Up @@ -46,7 +46,7 @@
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
{
Expand All @@ -66,9 +66,6 @@
ORDER BY rank';
}

$query.= '
;';

$result = pwg_query($query);
$categories = array();
$category_ids = array();
Expand All @@ -83,44 +80,41 @@
{
$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)
Expand All @@ -129,9 +123,9 @@
}

$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);
}
Expand Down
31 changes: 22 additions & 9 deletions include/functions_user.inc.php
Expand Up @@ -826,7 +826,7 @@ function get_default_user_info($convert_str = true)
if (pwg_db_num_rows($result) > 0)
{
$cache['default_user'] = pwg_db_fetch_assoc($result);

unset($cache['default_user']['user_id']);
unset($cache['default_user']['status']);
unset($cache['default_user']['registration_date']);
Expand Down Expand Up @@ -1125,13 +1125,13 @@ function pwg_password_hash($password)
if (empty($pwg_hasher))
{
require_once(PHPWG_ROOT_PATH.'include/passwordhash.class.php');

// We use the portable hash feature from phpass because we can't be sure
// Piwigo runs on PHP 5.3+ (and won't run on an older version in the
// future)
$pwg_hasher = new PasswordHash(13, true);
}

return $pwg_hasher->HashPassword($password);
}

Expand Down Expand Up @@ -1160,7 +1160,7 @@ function pwg_password_verify($password, $hash, $user_id=null)
{
$check = ($hash == md5($password));
}

if ($check and isset($user_id) and !$conf['external_authentification'])
{
// Rehash using new hash.
Expand All @@ -1179,7 +1179,7 @@ function pwg_password_verify($password, $hash, $user_id=null)
if (empty($pwg_hasher))
{
require_once(PHPWG_ROOT_PATH.'include/passwordhash.class.php');

// We use the portable hash feature
$pwg_hasher = new PasswordHash(13, true);
}
Expand All @@ -1200,11 +1200,11 @@ function try_log_user($username, $password, $remember_me)

function pwg_login($success, $username, $password, $remember_me)
{
if ($success===true)
if ($success===true)
{
return true;
}

// we force the session table to be clean
pwg_session_gc();

Expand All @@ -1231,9 +1231,9 @@ function pwg_login($success, $username, $password, $remember_me)
function logout_user()
{
global $conf;

trigger_action('user_logout', @$_SESSION['pwg_uid']);

$_SESSION = array();
session_unset();
session_destroy();
Expand Down Expand Up @@ -1554,6 +1554,19 @@ function get_sql_condition_FandF(
return $sql;
}

/** @return the sql condition to show recent photos/albums based on user preferences and latest available photo.*/
function get_recent_photos_sql($db_field)
{
global $user;
if (!isset($user['last_photo_date']))
{
return '0=1';
}
return $db_field.'>=LEAST('
.pwg_db_get_recent_period_expression($user['recent_period'])
.','.pwg_db_get_recent_period_expression(1,$user['last_photo_date']).')';
}

/**
* search an available activation_key
*
Expand Down
8 changes: 4 additions & 4 deletions include/section_init.inc.php
Expand Up @@ -452,10 +452,10 @@
SELECT DISTINCT(id)
FROM '.IMAGES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
WHERE
date_available >= '.pwg_db_get_recent_period_expression($user['recent_period']).'
'.$forbidden.'
'.$conf['order_by'].'
WHERE '
.get_recent_photos_sql('date_available').'
'.$forbidden
.$conf['order_by'].'
;';

$page = array_merge(
Expand Down

0 comments on commit 55275ef

Please sign in to comment.