Changeset 23085


Ignore:
Timestamp:
06/07/13 14:41:14 (7 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
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • extensions/community/add_photos.php

    r23037 r23085  
    3232define('PHOTOS_ADD_BASE_URL', make_index_url(array('section' => 'add_photos'))); 
    3333 
    34 $user_permissions = community_get_user_permissions($user['id']); 
    35  
    36 if (count($user_permissions['upload_categories']) == 0 and !$user_permissions ['create_whole_gallery']) 
     34$user_permissions = $user['community_permissions']; 
     35 
     36if (!$user_permissions['community_enabled']) 
    3737{ 
    3838  redirect(make_index_url()); 
     
    393393  if ($remaining_storage <= 0) 
    394394  { 
    395     echo 'limit storage reached<br>'; 
    396395    // limit reached 
    397396    $setup_errors[] = sprintf( 
     
    426425  if ($remaining_nb_photos <= 0) 
    427426  { 
    428     echo 'limit nb_photos reached<br>'; 
    429427    // limit reached 
    430428    $setup_errors[] = sprintf( 
  • extensions/community/admin.php

    r9516 r23085  
    5757    'label' => $pendings_label, 
    5858    ), 
     59  array( 
     60    'code' => 'config', 
     61    'label' => l10n('Configuration'), 
     62    ), 
    5963  ); 
    6064 
  • extensions/community/admin_permissions.php

    r23037 r23085  
    5151if (isset($_POST['submit_add'])) 
    5252{ 
     53  // echo '<pre>'; print_r($_POST); echo '</pre>'; 
    5354  if (!in_array($_POST['who'], array_keys($who_options))) 
    5455  { 
     
    8182  { 
    8283    check_input_parameter('storage', $_POST, false, PATTERN_ID); 
     84  } 
     85 
     86  // it is already blocked by Javascript, but an extra check is usefull 
     87  if ('any_visitor' == $_POST['who'] and -1 == $_POST['category']) 
     88  { 
     89    die('hacking attempt: invalid "where" option for this user'); 
     90  } 
     91 
     92  if (-1 == $_POST['category']) 
     93  { 
     94    unset($_POST['recursive']); 
     95    unset($_POST['create_subcategories']); 
    8396  } 
    8497 
     
    89102    'user_id' => ('user' == $_POST['who']) ? $_POST['who_user'] : null, 
    90103    'category_id' => ($_POST['category'] > 0) ? $_POST['category'] : null, 
     104    'user_album' => boolean_to_string(-1 == $_POST['category']), 
    91105    'recursive' => isset($_POST['recursive']) ? 'true' : 'false', 
    92106    'create_subcategories' => isset($_POST['create_subcategories']) ? 'true' : 'false', 
     
    107121    AND group_id '.(isset($insert['group_id']) ? '= '.$insert['group_id'] : 'is null').' 
    108122    AND category_id '.(isset($insert['category_id']) ? '= '.$insert['category_id'] : 'is null').' 
     123    AND user_album = \''.$insert['user_album'].'\' 
    109124;'; 
    110125  $result = pwg_query($query); 
     
    231246        'user_options_selected' => $row['user_id'], 
    232247        'group_options_selected' => $row['group_id'], 
     248        'whole_gallery_selected' => empty($row['category_id']) and !get_boolean($row['user_album']), 
     249        'user_album_selected' => get_boolean($row['user_album']), 
    233250        'recursive' => get_boolean($row['recursive']), 
    234251        'create_subcategories' => get_boolean($row['create_subcategories']), 
     
    244261  $template->assign( 
    245262    array( 
     263      'whole_gallery_selected' => !$conf['community']['user_albums'], 
     264      'user_album_selected' => $conf['community']['user_albums'], 
    246265      'moderated' => true, 
    247266      'nb_photos' => -1, 
     
    310329  array( 
    311330    'F_ADD_ACTION' => COMMUNITY_BASE_URL.'-'.$page['tab'], 
     331    'community_conf' => $conf['community'], 
    312332    ) 
    313333  ); 
     
    418438foreach ($permissions as $permission) 
    419439{ 
    420   $where = l10n('The whole gallery'); 
    421   if (isset($permission['category_id'])) 
    422   { 
    423     $where = $name_of_category[ $permission['category_id'] ]; 
     440  $where = l10n('User album only'); 
     441  if (!get_boolean($permission['user_album'])) 
     442  { 
     443    $where = l10n('The whole gallery'); 
     444    if (isset($permission['category_id'])) 
     445    { 
     446      $where = $name_of_category[ $permission['category_id'] ]; 
     447    } 
    424448  } 
    425449 
  • extensions/community/admin_permissions.tpl

    r23037 r23085  
    6060    $("[name^=who_]").hide(); 
    6161    $("[name=who_"+$(this).attr("value")+"]").show(); 
    62   }); 
     62    checkWhoOptions(); 
     63  }); 
     64 
     65  function checkWhoOptions() { 
     66    if ('any_visitor' == $("select[name=who] option:selected").val()) { 
     67      $("#userAlbumOption").attr("disabled", true); 
     68      $("#userAlbumInfo").hide(); 
     69 
     70      if (-1 == $("select[name=category] option:selected").val()) { 
     71        $("select[name=category]").val("0"); 
     72        checkWhereOptions(); 
     73      } 
     74    } 
     75    else { 
     76      $("#userAlbumOption").attr("disabled", false); 
     77      $("#userAlbumInfo").show(); 
     78    } 
     79  } 
     80  checkWhoOptions(); 
    6381 
    6482  function checkWhereOptions() { 
     
    6987      $(recursive).attr("disabled", true); 
    7088      $(recursive).attr('checked', true); 
     89    } 
     90    else if ($("select[name=category] option:selected").val() == -1) { 
     91      /* user upload only */ 
     92      $(recursive).attr("disabled", true).attr('checked', false); 
     93      $(create).attr("disabled", true).attr('checked', false); 
    7194    } 
    7295    else { 
     
    207230 
    208231    <p> 
    209       <strong>{'Where?'|@translate}</strong> 
     232      <strong>{'Where?'|@translate}</strong> {if $community_conf.user_albums}<em id="userAlbumInfo">{'(in addition to user album)'|@translate}</em>{/if} 
    210233      <br> 
    211234      <select class="categoryDropDown" name="category"> 
    212         <option value="0" {if not isset($category_options_selected)}selected="selected"{/if}>{'The whole gallery'|@translate}</option> 
     235{if $community_conf.user_albums} 
     236        <option value="-1"{if $user_album_selected} selected="selected"{/if} id="userAlbumOption">{'User album only'|@translate}</option> 
     237{/if} 
     238        <option value="0"{if $whole_gallery_selected} selected="selected"{/if}>{'The whole gallery'|@translate}</option> 
    213239        <option disabled="disabled">------------</option> 
    214240        {html_options options=$category_options selected=$category_options_selected} 
  • 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?> 
  • extensions/community/language/en_UK/plugin.lang.php

    r23037 r23085  
    7575$lang['How much disk space?'] = 'How much disk space?'; 
    7676$lang['How many photos?'] = 'How many photos?'; 
     77$lang['User albums'] = 'User albums'; 
     78$lang['Piwigo automatically creates an album for each user, on first connection'] = 'Piwigo automatically creates an album for each user, on first connection'; 
     79$lang['Where should Piwigo create user albums?'] = 'Where should Piwigo create user albums?'; 
     80$lang['Gallery root'] = 'Gallery root'; 
     81$lang['(in addition to user album)'] = '(in addition to user album)'; 
     82$lang['User album only'] = 'User album only'; 
    7783?> 
  • extensions/community/language/fr_FR/plugin.lang.php

    r23037 r23085  
    7777$lang['How much disk space?'] = 'Combien d\'espace disque ?'; 
    7878$lang['How many photos?'] = 'Combien de photos ?'; 
     79$lang['User albums'] = 'Albums utilisateur'; 
     80$lang['Piwigo automatically creates an album for each user, on first connection'] = 'Piwigo créée automatiquement un album pour chaque utilisateur, lors de sa première connexion'; 
     81$lang['Where should Piwigo create user albums?'] = 'Où Piwigo doit-il créer les albums utilisateur ?'; 
     82$lang['Gallery root'] = 'Racine de la galerie'; 
     83$lang['(in addition to user album)'] = '(en plus de l\'album utilisateur)'; 
     84$lang['User album only'] = 'Uniquement l\'album utilisateur'; 
    7985?> 
  • extensions/community/main.inc.php

    r23037 r23085  
    3838function community_init() 
    3939{ 
    40   global $conf, $pwg_loaded_plugins; 
     40  global $conf, $user, $pwg_loaded_plugins; 
    4141 
    4242  // apply upgrade if needed 
     
    6363    } 
    6464  } 
     65 
     66  // prepare plugin configuration 
     67  $conf['community'] = unserialize($conf['community']); 
     68 
     69  // TODO: generate permissions in $user['community_permissions'] if ws.php 
     70  // + remove all calls of community_get_user_permissions related to webservices 
     71  if (!defined('IN_ADMIN') or !IN_ADMIN) 
     72  { 
     73    $user['community_permissions'] = community_get_user_permissions($user['id']); 
     74  } 
    6575} 
    6676 
     
    8898    $style.= '-moz-border-radius:10px;'; 
    8999    $style.= '-webkit-border-radius:10px;'; 
    90     $style.= '-border-radius:10px;'; 
     100    $style.= 'border-radius:10px;'; 
    91101    $style.= 'margin-left:5px;'; 
    92102     
     
    169179  // conditional : depending on community permissions, display the "Add 
    170180  // photos" link in the gallery menu 
    171   $user_permissions = community_get_user_permissions($user['id']); 
    172  
    173   if (count($user_permissions['upload_categories']) == 0 and !$user_permissions ['create_whole_gallery']) 
     181  $user_permissions = $user['community_permissions']; 
     182 
     183  if (!$user_permissions['community_enabled']) 
    174184  { 
    175185    return; 
  • extensions/community/maintain.inc.php

    r23037 r23085  
    2424  $query = 'DROP TABLE '.$prefixeTable.'community_pendings;'; 
    2525  pwg_query($query); 
     26 
     27  $query = 'ALTER TABLE '.$prefixeTable.'categories drop column community_user;'; 
     28  pwg_query($query); 
     29 
     30  // delete configuration 
     31  pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param IN ("community", "community_cache_key");'); 
    2632} 
    2733 
     
    241247{ 
    242248  global $prefixeTable; 
    243    
    244   // create an album "Community" 
    245   $category_info = create_virtual_category('Community'); 
     249 
     250  // is there a "Community" album? 
     251  $query = ' 
     252SELECT 
     253    id 
     254  FROM '.CATEGORIES_TABLE.' 
     255  WHERE name = \'Community\' 
     256;'; 
     257  $result = pwg_query($query); 
     258  while ($row = pwg_db_fetch_assoc($result)) 
     259  { 
     260    $category_id = $row['id']; 
     261    break; 
     262  } 
     263 
     264  if (!isset($category_id)) 
     265  { 
     266    // create an album "Community" 
     267    $category_info = create_virtual_category('Community'); 
     268    $category_id = $category_info['id']; 
     269  } 
    246270 
    247271  $insert = array( 
    248272    'type' => 'any_registered_user', 
    249     'category_id' => $category_info['id'], 
     273    'category_id' => $category_id, 
    250274    'recursive' => 'true', 
    251275    'create_subcategories' => 'true', 
Note: See TracChangeset for help on using the changeset viewer.