aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2009-07-18 10:34:39 +0000
committerrvelices <rv-github@modusoptimus.com>2009-07-18 10:34:39 +0000
commit17087ea61572d4fbc3bf4fc3c2d58270dcfde75e (patch)
treed8552960290f65fe197f6b591e49e50a876ccc76 /include
parentcd10ccec6fc27b2f1c74226613a8b79bae2ce4f7 (diff)
merge r3622 from trunk to branch 2.0
- feature 1053: hide categories that contain no photo due to privacy level git-svn-id: http://piwigo.org/svn/branches/2.0@3623 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/functions_user.inc.php92
1 files changed, 51 insertions, 41 deletions
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index d7ef88992..fac372852 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -247,8 +247,7 @@ SELECT ';
}
$query.= '
FROM '.USERS_TABLE.'
- WHERE '.$conf['user_fields']['id'].' = \''.$user_id.'\'
-;';
+ WHERE '.$conf['user_fields']['id'].' = \''.$user_id.'\'';
$row = mysql_fetch_array(pwg_query($query));
@@ -258,8 +257,7 @@ SELECT ';
SELECT ui.*, uc.*
FROM '.USER_INFOS_TABLE.' AS ui LEFT JOIN '.USER_CACHE_TABLE.' AS uc
ON ui.user_id = uc.user_id
- WHERE ui.user_id = \''.$user_id.'\'
-;';
+ WHERE ui.user_id = \''.$user_id.'\'';
$result = pwg_query($query);
if (mysql_num_rows($result) > 0)
{
@@ -320,21 +318,64 @@ SELECT DISTINCT(id)
$userdata['image_access_type'] = 'NOT IN'; //TODO maybe later
$userdata['image_access_list'] = implode(',',$forbidden_ids);
- update_user_cache_categories($userdata);
$query = '
SELECT COUNT(DISTINCT(image_id)) as total
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id NOT IN ('.$userdata['forbidden_categories'].')
- AND image_id '.$userdata['image_access_type'].' ('.$userdata['image_access_list'].')
-;';
+ AND image_id '.$userdata['image_access_type'].' ('.$userdata['image_access_list'].')';
list($userdata['nb_total_images']) = mysql_fetch_array(pwg_query($query));
+
+ // now we update user cache categories
+ $user_cache_cats = get_computed_categories($userdata, null);
+ if ( !is_admin($userdata['status']) )
+ { // for non admins we forbid categories with no image (feature 1053)
+ $forbidden_ids = array();
+ foreach ($user_cache_cats as $cat_id => $cat)
+ {
+ if ($cat['count_images']==0)
+ {
+ array_push($forbidden_ids, $cat_id);
+ unset( $user_cache_cats[$cat_id] );
+ }
+ }
+ if ( !empty($forbidden_ids) )
+ {
+ if ( empty($userdata['forbidden_categories']) )
+ {
+ $userdata['forbidden_categories'] = implode(',', $forbidden_ids);
+ }
+ else
+ {
+ $userdata['forbidden_categories'] .= ','.implode(',', $forbidden_ids);
+ }
+ }
+ }
+
+ // delete user cache
+ $query = '
+DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
+ WHERE user_id = '.$userdata['id'];
+ pwg_query($query);
+
+ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+ mass_inserts
+ (
+ USER_CACHE_CATEGORIES_TABLE,
+ array
+ (
+ 'user_id', 'cat_id',
+ 'date_last', 'max_date_last', 'nb_images', 'count_images', 'count_categories'
+ ),
+ $user_cache_cats
+ );
+
+
// update user cache
$query = '
DELETE FROM '.USER_CACHE_TABLE.'
- WHERE user_id = '.$userdata['id'].'
-;';
+ WHERE user_id = '.$userdata['id'];
pwg_query($query);
$query = '
@@ -345,8 +386,7 @@ INSERT INTO '.USER_CACHE_TABLE.'
('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\','
.$userdata['cache_update_time'].',\''
.$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].',"'
- .$userdata['image_access_type'].'","'.$userdata['image_access_list'].'")
-;';
+ .$userdata['image_access_type'].'","'.$userdata['image_access_list'].'")';
pwg_query($query);
}
}
@@ -643,36 +683,6 @@ FROM '.CATEGORIES_TABLE.' as c
}
/**
- * update data of user_cache_categories
- *
- * @param array userdata
- * @return null
- */
-function update_user_cache_categories($userdata)
-{
- // delete user cache
- $query = '
-DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
- WHERE user_id = '.$userdata['id'].'
-;';
- pwg_query($query);
-
- $cats = get_computed_categories($userdata, null);
-
- include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
- mass_inserts
- (
- USER_CACHE_CATEGORIES_TABLE,
- array
- (
- 'user_id', 'cat_id',
- 'date_last', 'max_date_last', 'nb_images', 'count_images', 'count_categories'
- ),
- $cats
- );
-}
-
-/**
* returns user identifier thanks to his name, false if not found
*
* @param string username