Skip to content

Commit 4cbf56f

Browse files
author
rvelices
committed
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
1 parent 9c00b3e commit 4cbf56f

File tree

1 file changed

+54
-44
lines changed

1 file changed

+54
-44
lines changed

include/functions_user.inc.php

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ function getuserdata($user_id, $use_cache)
247247
}
248248
$query.= '
249249
FROM '.USERS_TABLE.'
250-
WHERE '.$conf['user_fields']['id'].' = \''.$user_id.'\'
251-
;';
250+
WHERE '.$conf['user_fields']['id'].' = \''.$user_id.'\'';
252251

253252
$row = mysql_fetch_array(pwg_query($query));
254253

@@ -258,8 +257,7 @@ function getuserdata($user_id, $use_cache)
258257
SELECT ui.*, uc.*
259258
FROM '.USER_INFOS_TABLE.' AS ui LEFT JOIN '.USER_CACHE_TABLE.' AS uc
260259
ON ui.user_id = uc.user_id
261-
WHERE ui.user_id = \''.$user_id.'\'
262-
;';
260+
WHERE ui.user_id = \''.$user_id.'\'';
263261
$result = pwg_query($query);
264262
if (mysql_num_rows($result) > 0)
265263
{
@@ -320,21 +318,64 @@ function getuserdata($user_id, $use_cache)
320318
$userdata['image_access_type'] = 'NOT IN'; //TODO maybe later
321319
$userdata['image_access_list'] = implode(',',$forbidden_ids);
322320

323-
update_user_cache_categories($userdata);
324321

325322
$query = '
326323
SELECT COUNT(DISTINCT(image_id)) as total
327324
FROM '.IMAGE_CATEGORY_TABLE.'
328325
WHERE category_id NOT IN ('.$userdata['forbidden_categories'].')
329-
AND image_id '.$userdata['image_access_type'].' ('.$userdata['image_access_list'].')
330-
;';
326+
AND image_id '.$userdata['image_access_type'].' ('.$userdata['image_access_list'].')';
331327
list($userdata['nb_total_images']) = mysql_fetch_array(pwg_query($query));
332328

329+
330+
// now we update user cache categories
331+
$user_cache_cats = get_computed_categories($userdata, null);
332+
if ( !is_admin($userdata['status']) )
333+
{ // for non admins we forbid categories with no image (feature 1053)
334+
$forbidden_ids = array();
335+
foreach ($user_cache_cats as $cat_id => $cat)
336+
{
337+
if ($cat['count_images']==0)
338+
{
339+
array_push($forbidden_ids, $cat_id);
340+
unset( $user_cache_cats[$cat_id] );
341+
}
342+
}
343+
if ( !empty($forbidden_ids) )
344+
{
345+
if ( empty($userdata['forbidden_categories']) )
346+
{
347+
$userdata['forbidden_categories'] = implode(',', $forbidden_ids);
348+
}
349+
else
350+
{
351+
$userdata['forbidden_categories'] .= ','.implode(',', $forbidden_ids);
352+
}
353+
}
354+
}
355+
356+
// delete user cache
357+
$query = '
358+
DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
359+
WHERE user_id = '.$userdata['id'];
360+
pwg_query($query);
361+
362+
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
363+
mass_inserts
364+
(
365+
USER_CACHE_CATEGORIES_TABLE,
366+
array
367+
(
368+
'user_id', 'cat_id',
369+
'date_last', 'max_date_last', 'nb_images', 'count_images', 'count_categories'
370+
),
371+
$user_cache_cats
372+
);
373+
374+
333375
// update user cache
334376
$query = '
335377
DELETE FROM '.USER_CACHE_TABLE.'
336-
WHERE user_id = '.$userdata['id'].'
337-
;';
378+
WHERE user_id = '.$userdata['id'];
338379
pwg_query($query);
339380

340381
$query = '
@@ -345,8 +386,7 @@ function getuserdata($user_id, $use_cache)
345386
('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\','
346387
.$userdata['cache_update_time'].',\''
347388
.$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].',"'
348-
.$userdata['image_access_type'].'","'.$userdata['image_access_list'].'")
349-
;';
389+
.$userdata['image_access_type'].'","'.$userdata['image_access_list'].'")';
350390
pwg_query($query);
351391
}
352392
}
@@ -642,36 +682,6 @@ function get_computed_categories($userdata, $filter_days=null)
642682
return $cats;
643683
}
644684

645-
/**
646-
* update data of user_cache_categories
647-
*
648-
* @param array userdata
649-
* @return null
650-
*/
651-
function update_user_cache_categories($userdata)
652-
{
653-
// delete user cache
654-
$query = '
655-
DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
656-
WHERE user_id = '.$userdata['id'].'
657-
;';
658-
pwg_query($query);
659-
660-
$cats = get_computed_categories($userdata, null);
661-
662-
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
663-
mass_inserts
664-
(
665-
USER_CACHE_CATEGORIES_TABLE,
666-
array
667-
(
668-
'user_id', 'cat_id',
669-
'date_last', 'max_date_last', 'nb_images', 'count_images', 'count_categories'
670-
),
671-
$cats
672-
);
673-
}
674-
675685
/**
676686
* returns user identifier thanks to his name, false if not found
677687
*
@@ -1202,13 +1212,13 @@ function is_adviser()
12021212
* @param action edit/delete
12031213
* @return bool
12041214
*/
1205-
function can_manage_comment($action, $comment_author_id)
1215+
function can_manage_comment($action, $comment_author_id)
12061216
{
12071217
if (!in_array($action, array('delete','edit'))) {
12081218
return false;
12091219
}
1210-
return (is_admin() ||
1211-
(($GLOBALS['user']['id'] == $comment_author_id)
1220+
return (is_admin() ||
1221+
(($GLOBALS['user']['id'] == $comment_author_id)
12121222
&& !is_a_guest()
12131223
&& $GLOBALS['conf'][sprintf('user_can_%s_comment', $action)]));
12141224
}

0 commit comments

Comments
 (0)