Changeset 3622 for trunk/include


Ignore:
Timestamp:
Jul 18, 2009, 12:30:42 PM (15 years ago)
Author:
rvelices
Message:

feature 1053: hide categories that contain no photo due to privacy level

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_user.inc.php

    r3450 r3622  
    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));
     
    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)
     
    321319      $userdata['image_access_list'] = implode(',',$forbidden_ids);
    322320
    323       update_user_cache_categories($userdata);
    324321
    325322      $query = '
     
    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));
     328
     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 = '
     358DELETE 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
    332374
    333375      // update user cache
    334376      $query = '
    335377DELETE FROM '.USER_CACHE_TABLE.'
    336   WHERE user_id = '.$userdata['id'].'
    337 ;';
     378  WHERE user_id = '.$userdata['id'];
    338379      pwg_query($query);
    339380
     
    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    }
     
    644684
    645685/**
    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 
    675 /**
    676686 * returns user identifier thanks to his name, false if not found
    677687 *
     
    12031213 * @return bool
    12041214 */
    1205 function can_manage_comment($action, $comment_author_id) 
     1215function 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)]));
Note: See TracChangeset for help on using the changeset viewer.