Skip to content
Permalink
Browse files
feature 1053: hide categories that contain no photo due to privacy level
git-svn-id: http://piwigo.org/svn/trunk@3622 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
modus75 committed Jul 18, 2009
1 parent 9c00b3e commit 4cbf56f768d0a73999b7722eac9b447e61967c3c
Showing 1 changed file with 54 additions and 44 deletions.
@@ -247,8 +247,7 @@ function getuserdata($user_id, $use_cache)
}
$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 @@ function getuserdata($user_id, $use_cache)
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 @@ function getuserdata($user_id, $use_cache)
$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 @@ function getuserdata($user_id, $use_cache)
('.$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);
}
}
@@ -642,36 +682,6 @@ function get_computed_categories($userdata, $filter_days=null)
return $cats;
}

/**
* 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
*
@@ -1202,13 +1212,13 @@ function is_adviser()
* @param action edit/delete
* @return bool
*/
function can_manage_comment($action, $comment_author_id)
function can_manage_comment($action, $comment_author_id)
{
if (!in_array($action, array('delete','edit'))) {
return false;
}
return (is_admin() ||
(($GLOBALS['user']['id'] == $comment_author_id)
return (is_admin() ||
(($GLOBALS['user']['id'] == $comment_author_id)
&& !is_a_guest()
&& $GLOBALS['conf'][sprintf('user_can_%s_comment', $action)]));
}

0 comments on commit 4cbf56f

Please sign in to comment.