aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/category_cats.inc.php64
-rw-r--r--include/functions_user.inc.php31
-rw-r--r--include/section_init.inc.php8
3 files changed, 55 insertions, 48 deletions
diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php
index 414bc24ca..cbdbe47b7 100644
--- a/include/category_cats.inc.php
+++ b/include/category_cats.inc.php
@@ -46,7 +46,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 +66,6 @@ if ('recent_cats' != $page['section'])
ORDER BY rank';
}
-$query.= '
-;';
-
$result = pwg_query($query);
$categories = array();
$category_ids = array();
@@ -83,44 +80,41 @@ 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)
@@ -129,9 +123,9 @@ while ($row = pwg_db_fetch_assoc($result))
}
$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);
}
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index 439c91b3e..db9da568c 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -826,7 +826,7 @@ SELECT *
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']);
@@ -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);
}
@@ -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.
@@ -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);
}
@@ -1200,11 +1200,11 @@ add_event_handler('try_log_user', 'pwg_login', EVENT_HANDLER_PRIORITY_NEUTRAL, 4
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();
@@ -1231,9 +1231,9 @@ SELECT '.$conf['user_fields']['id'].' AS id,
function logout_user()
{
global $conf;
-
+
trigger_action('user_logout', @$_SESSION['pwg_uid']);
-
+
$_SESSION = array();
session_unset();
session_destroy();
@@ -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
*
diff --git a/include/section_init.inc.php b/include/section_init.inc.php
index 9b6e4b088..46f1edde0 100644
--- a/include/section_init.inc.php
+++ b/include/section_init.inc.php
@@ -452,10 +452,10 @@ SELECT image_id
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(