Ignore:
Timestamp:
Jun 7, 2013, 2:41:14 PM (11 years ago)
Author:
plg
Message:

New feature: user album. Only for registered users, no recursivity. Piwigo
will automatically create an upload album for each user with appropriate
community permissions, at first connection.

Bug fixed: on activation, do not create a new "Community" album if it already
exists.

Bug fixed: remove debug for quota

Bug fixed: round corners for number of pending pictures in admin menu.

Location:
extensions/community/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/community/include/functions_community.inc.php

    r23037 r23085  
    2424function community_get_user_permissions($user_id)
    2525{
     26  // echo __FUNCTION__.' => call for user '.$user_id.'<br>';
     27 
    2628  global $conf, $user;
    2729
     
    4951    'upload_whole_gallery' => false,
    5052    'create_whole_gallery' => false,
     53    'user_album' => false,
    5154    'create_categories' => array(),
    5255    'upload_categories' => array(),
     
    6871SELECT
    6972    id,
     73    type,
    7074    category_id,
     75    user_album,
    7176    recursive,
    7277    create_subcategories,
     
    98103  {
    99104    array_push($return['permission_ids'], $row['id']);
    100    
    101     if (empty($row['category_id']))
    102     {
    103       $return ['upload_whole_gallery'] = true;
    104     }
    105     else
    106     {
    107       array_push($return['upload_categories'], $row['category_id']);
    108 
    109       if ('true' == $row['recursive'])
    110       {
    111         array_push($recursive_categories, $row['category_id']);
     105
     106    if ('false' == $row['user_album'])
     107    {
     108      if (empty($row['category_id']))
     109      {
     110        $return['upload_whole_gallery'] = true;
     111      }
     112      else
     113      {
     114        array_push($return['upload_categories'], $row['category_id']);
     115
     116        if ('true' == $row['recursive'])
     117        {
     118          array_push($recursive_categories, $row['category_id']);
     119        }
    112120      }
    113121    }
     
    149157        $return['storage'] = $row['storage'];
    150158      }
     159    }
     160
     161    if ($conf['community']['user_albums'] and 'any_visitor' != $row['type'])
     162    {
     163      $return['user_album'] = true;
    151164    }
    152165  }
     
    237250  }
    238251
     252  if ($return['user_album'])
     253  {
     254    $user_album_category_id = community_get_user_album($user_id);
     255
     256    if (!empty($user_album_category_id) and !in_array($user_album_category_id, $return['upload_categories']))
     257    {
     258      array_push($return['upload_categories'], $user_album_category_id);
     259    }
     260  }
     261
     262  // is the user allowed to use community upload?
     263  if (count($return['upload_categories']) > 0 or $return['create_whole_gallery'] or $return['user_album'])
     264  {
     265    $return['community_enabled'] = true;
     266  }
     267  else
     268  {
     269    $return['community_enabled'] = false;
     270  }
     271
    239272  $_SESSION['community_user_permissions'] = $return;
    240273  $_SESSION['community_cache_key'] = $cache_key;
    241274  $_SESSION['community_user_id'] = $user_id;
    242275
     276  // echo __FUNCTION__.' => cache reset for user '.$user_id.'<br>';
     277 
    243278  return $_SESSION['community_user_permissions'];
     279}
     280
     281/**
     282 * return the user album category_id. The album is automatically created if
     283 * it does not exist (or has been deleted)
     284 */
     285function community_get_user_album($user_id)
     286{
     287  global $conf;
     288 
     289  $user_album_category_id = null;
     290 
     291  $query = '
     292SELECT *
     293  FROM '.CATEGORIES_TABLE.'
     294  WHERE community_user = '.$user_id.'
     295;';
     296  $result = pwg_query($query);
     297  while ($row = pwg_db_fetch_assoc($result))
     298  {
     299    $user_album_category_id = $row['id'];
     300    break;
     301  }
     302
     303  if (!isset($user_album_category_id))
     304  {
     305    $user_infos = getuserdata($user_id, false);
     306
     307    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     308    $category_info = create_virtual_category($user_infos['username'], $conf['community']['user_albums_parent']);
     309
     310    single_update(
     311      CATEGORIES_TABLE,
     312      array('community_user' => $user_id),
     313      array('id' => $category_info['id'])
     314      );
     315
     316    $user_album_category_id = $category_info['id'];
     317
     318    // in functions_html::get_cat_display_name_cache we use a cache and this
     319    // cache must be reset so that new album is included inside it.
     320    global $cache;
     321    unset($cache['cat_names']);
     322  }
     323
     324  return $user_album_category_id;
    244325}
    245326
  • extensions/community/include/install.inc.php

    r23037 r23085  
    3333  user_id smallint(5) DEFAULT NULL,
    3434  category_id smallint(5) unsigned DEFAULT NULL,
     35  user_album enum(\'true\',\'false\') NOT NULL DEFAULT \'false\',
    3536  recursive enum(\'true\',\'false\') NOT NULL DEFAULT \'true\',
    3637  create_subcategories enum(\'true\',\'false\') NOT NULL DEFAULT \'false\',
     
    6667    pwg_query('ALTER TABLE `'.$prefixeTable .'community_permissions` ADD `storage` INT DEFAULT NULL;');
    6768  }
     69
     70  // column community_permissions.user_album added for version 2.5.d
     71  $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'community_permissions` LIKE "user_album";');
     72  if (!pwg_db_num_rows($result))
     73  {     
     74    pwg_query('ALTER TABLE `'.$prefixeTable .'community_permissions` ADD `user_album` enum(\'true\',\'false\') NOT NULL DEFAULT \'false\' after `category_id`;');
     75  }
     76
     77  // column categories.community_user added for version 2.5.d
     78  $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'categories` LIKE "community_user";');
     79  if (!pwg_db_num_rows($result))
     80  {     
     81    pwg_query('ALTER TABLE `'.$prefixeTable .'categories` ADD `community_user`  smallint(5) DEFAULT NULL;');
     82  }
     83
     84  if (!isset($conf['community']))
     85  {
     86    $community_default_config = serialize(
     87      array(
     88        'user_albums' => false,
     89        )
     90      );
     91   
     92    conf_update_param('community', $community_default_config);
     93    $conf['community'] = $community_default_config;
     94  }
    6895}
    6996?>
Note: See TracChangeset for help on using the changeset viewer.