Changeset 23037


Ignore:
Timestamp:
Jun 4, 2013, 12:55:59 PM (11 years ago)
Author:
plg
Message:

manage quota (number of photos, disk usage)

Location:
extensions/community
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • extensions/community/add_photos.php

    r16637 r23037  
    7373include_once(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_process.inc.php');
    7474
     75// +-----------------------------------------------------------------------+
     76// | limits                                                                |
     77// +-----------------------------------------------------------------------+
     78
     79// has the user reached its limits?
     80$user['community_usage'] = community_get_user_limits($user['id']);
     81// echo '<pre>'; print_r($user['community_usage']); echo '</pre>';
     82
     83// +-----------------------------------------------------------------------+
     84// | set properties, moderate, notify                                      |
     85// +-----------------------------------------------------------------------+
     86
    7587if (isset($image_ids) and count($image_ids) > 0)
    7688{
     89  $query = '
     90SELECT
     91    id,
     92    file,
     93    filesize
     94  FROM '.IMAGES_TABLE.'
     95  WHERE id IN ('.implode(',', $image_ids).')
     96  ORDER BY id DESC
     97;';
     98  $images = array_from_query($query);
     99
     100  $nb_images_deleted = 0;
     101 
     102  // upload has just happened, maybe the user is over quota
     103  if ($user_permissions['storage'] > 0 and $user['community_usage']['storage'] > $user_permissions['storage'])
     104  {
     105    foreach ($images as $image)
     106    {
     107      array_push(
     108        $page['errors'],
     109        sprintf(l10n('Photo %s rejected.'), $image['file'])
     110        .' '.sprintf(l10n('Disk usage quota reached (%uMB)'), $user_permissions['storage'])
     111        );
     112     
     113      delete_elements(array($image['id']), true);
     114      foreach ($page['thumbnails'] as $tn_idx => $thumbnail)
     115      {
     116        if ($thumbnail['file'] == $image['file'])
     117        {
     118          unset($page['thumbnails'][$idx]);
     119        }
     120      }
     121
     122      $user['community_usage'] = community_get_user_limits($user['id']);
     123     
     124      if ($user['community_usage']['storage'] <= $user_permissions['storage'])
     125      {
     126        // we stop the deletions
     127        break;
     128      }
     129    }
     130  }
     131
     132  if ($user_permissions['nb_photos'] > 0 and $user['community_usage']['nb_photos'] > $user_permissions['nb_photos'])
     133  {
     134    foreach ($images as $image)
     135    {
     136      array_push(
     137        $page['errors'],
     138        sprintf(l10n('Photo %s rejected.'), $image['file'])
     139        .' '.sprintf(l10n('Maximum number of photos reached (%u)'), $user_permissions['nb_photos'])
     140        );
     141     
     142      delete_elements(array($image['id']), true);
     143      foreach ($page['thumbnails'] as $tn_idx => $thumbnail)
     144      {
     145        if ($thumbnail['file'] == $image['file'])
     146        {
     147          unset($page['thumbnails'][$idx]);
     148        }
     149      }
     150
     151      $user['community_usage'] = community_get_user_limits($user['id']);
     152     
     153      if ($user['community_usage']['nb_photos'] <= $user_permissions['nb_photos'])
     154      {
     155        // we stop the deletions
     156        break;
     157      }
     158    }
     159  }
     160     
     161 
    77162  // reinitialize the informations to display on the result page
    78163  $page['infos'] = array();
     
    112197      );
    113198  }
    114  
    115   // $category_id is set in the photos_add_direct_process.inc.php included script
    116   $category_infos = get_cat_info($category_id);
    117   $category_name = get_cat_display_name($category_infos['upper_names']);
    118 
    119   array_push(
    120     $page['infos'],
    121     sprintf(
    122       l10n('%d photos uploaded into album "%s"'),
    123       count($page['thumbnails']),
    124       '<em>'.$category_name.'</em>'
    125       )
    126     );
     199
     200  if (count($page['thumbnails']) > 0)
     201  {
     202    // $category_id is set in the photos_add_direct_process.inc.php included script
     203    $category_infos = get_cat_info($category_id);
     204    $category_name = get_cat_display_name($category_infos['upper_names']);
     205
     206    array_push(
     207      $page['infos'],
     208      sprintf(
     209        l10n('%d photos uploaded into album "%s"'),
     210        count($page['thumbnails']),
     211        '<em>'.$category_name.'</em>'
     212        )
     213      );
     214  }
    127215
    128216  // should the photos be moderated?
     
    186274        );
    187275    }
    188    
    189     mass_inserts(
    190       COMMUNITY_PENDINGS_TABLE,
    191       array_keys($inserts[0]),
    192       $inserts
    193       );
    194 
    195     // find the url to the medium size
    196     $page['thumbnails'] = array();
    197 
    198     $query = '
     276
     277    if (count($inserts) > 0)
     278    {
     279      mass_inserts(
     280        COMMUNITY_PENDINGS_TABLE,
     281        array_keys($inserts[0]),
     282        $inserts
     283        );
     284     
     285      // find the url to the medium size
     286      $page['thumbnails'] = array();
     287
     288      $query = '
    199289SELECT *
    200290  FROM '.IMAGES_TABLE.'
    201291  WHERE id IN ('.implode(',', $image_ids).')
    202292;';
    203     $result = pwg_query($query);
    204     while ($row = pwg_db_fetch_assoc($result))
    205     {
    206       $src_image = new SrcImage($row);
    207 
    208       $page['thumbnails'][] = array(
    209         'file' => $row['file'],
    210         'src' => DerivativeImage::url(IMG_THUMB, $src_image),
    211         'title' => $row['name'],
    212         'link' => $image_url = DerivativeImage::url(IMG_MEDIUM, $src_image),
    213         'lightbox' => true,
     293      $result = pwg_query($query);
     294      while ($row = pwg_db_fetch_assoc($result))
     295      {
     296        $src_image = new SrcImage($row);
     297       
     298        $page['thumbnails'][] = array(
     299          'file' => $row['file'],
     300          'src' => DerivativeImage::url(IMG_THUMB, $src_image),
     301          'title' => $row['name'],
     302          'link' => $image_url = DerivativeImage::url(IMG_MEDIUM, $src_image),
     303          'lightbox' => true,
     304          );
     305      }
     306     
     307      array_push(
     308        $page['infos'],
     309        l10n('Your photos are waiting for validation, administrators have been notified')
    214310        );
    215311    }
    216 
    217     array_push(
    218       $page['infos'],
    219       l10n('Your photos are waiting for validation, administrators have been notified')
    220       );
    221312  }
    222313  else
     
    247338
    248339  invalidate_user_cache();
    249 
    250   // let's notify administrators
    251   include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
    252 
    253   $keyargs_content = array(
    254     get_l10n_args('Hi administrators,', ''),
    255     get_l10n_args('', ''),
    256     get_l10n_args('Album: %s', get_cat_display_name($category_infos['upper_names'], null, false)),
    257     get_l10n_args('User: %s', $user['username']),
    258     get_l10n_args('Email: %s', $user['email']),
     340 
     341  if (count($page['thumbnails']))
     342  {
     343    // let's notify administrators
     344    include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
     345
     346    $keyargs_content = array(
     347      get_l10n_args('Hi administrators,', ''),
     348      get_l10n_args('', ''),
     349      get_l10n_args('Album: %s', get_cat_display_name($category_infos['upper_names'], null, false)),
     350      get_l10n_args('User: %s', $user['username']),
     351      get_l10n_args('Email: %s', $user['email']),
     352      );
     353
     354    if ($moderate)
     355    {
     356      $keyargs_content[] = get_l10n_args('', '');
     357     
     358      array_push(
     359        $keyargs_content,
     360        get_l10n_args(
     361          'Validation page: %s',
     362          get_absolute_root_url().'admin.php?page=plugin-community-pendings'
     363          )
     364        );
     365    }
     366
     367    pwg_mail_notification_admins(
     368      get_l10n_args('%d photos uploaded by %s', array(count($image_ids), $user['username'])),
     369      $keyargs_content,
     370      false
     371      );
     372  }
     373}
     374
     375// +-----------------------------------------------------------------------+
     376// |                             prepare form                              |
     377// +-----------------------------------------------------------------------+
     378
     379$template->set_filenames(array('add_photos' => dirname(__FILE__).'/add_photos.tpl'));
     380
     381include_once(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_prepare.inc.php');
     382
     383$quota_available = array(
     384  'summary' => array(),
     385  'details' => array(),
     386  );
     387
     388// there is a limit on storage for this user
     389if ($user_permissions['storage'] > 0)
     390{
     391  $remaining_storage = $user_permissions['storage'] - $user['community_usage']['storage'];
     392 
     393  if ($remaining_storage <= 0)
     394  {
     395    echo 'limit storage reached<br>';
     396    // limit reached
     397    $setup_errors[] = sprintf(
     398      l10n('Disk usage quota reached (%uMB)'),
     399      $user_permissions['storage']
     400      );
     401  }
     402  else
     403  {
     404    $quota_available['summary'][] = $remaining_storage.'MB';
     405   
     406    $quota_available['details'][] = sprintf(
     407      l10n('%s out of %s'),
     408      $remaining_storage.'MB',
     409      $user_permissions['storage']
     410      );
     411   
     412    $template->assign(
     413      array(
     414        'limit_storage' => $remaining_storage*1024*1024,
     415        'limit_storage_total_mb' => $user_permissions['storage'],
     416        )
     417      );
     418  }
     419}
     420
     421// there is a limit on number of photos for this user
     422if ($user_permissions['nb_photos'] > 0)
     423{
     424  $remaining_nb_photos = $user_permissions['nb_photos'] - $user['community_usage']['nb_photos'];
     425 
     426  if ($remaining_nb_photos <= 0)
     427  {
     428    echo 'limit nb_photos reached<br>';
     429    // limit reached
     430    $setup_errors[] = sprintf(
     431      l10n('Maximum number of photos reached (%u)'),
     432      $user_permissions['nb_photos']
     433      );
     434  }
     435  else
     436  {
     437    $quota_available['summary'][] = l10n_dec('%d photo', '%d photos', $remaining_nb_photos);
     438   
     439    $quota_available['details'][] = sprintf(
     440      l10n('%s out of %s'),
     441      l10n_dec('%d photo', '%d photos', $remaining_nb_photos),
     442      $user_permissions['nb_photos']
     443      );
     444   
     445    $template->assign('limit_nb_photos', $remaining_nb_photos);
     446  }
     447}
     448
     449if (count($quota_available['details']) > 0)
     450{
     451  $template->assign(
     452    array(
     453      'quota_summary' => sprintf(
     454        l10n('Available %s.'),
     455        implode(', ', $quota_available['summary'])
     456        ),
     457      'quota_details' => sprintf(
     458        l10n('Available quota %s.'),
     459        implode(', ', $quota_available['details'])
     460        ),
     461      )
    259462    );
    260 
    261   if ($moderate)
    262   {
    263     $keyargs_content[] = get_l10n_args('', '');
    264    
    265     array_push(
    266       $keyargs_content,
    267       get_l10n_args(
    268         'Validation page: %s',
    269         get_absolute_root_url().'admin.php?page=plugin-community-pendings'
    270         )
    271       );
    272   }
    273 
    274   pwg_mail_notification_admins(
    275     get_l10n_args('%d photos uploaded by %s', array(count($image_ids), $user['username'])),
    276     $keyargs_content,
    277     false
    278     );
    279 }
    280 
    281 // +-----------------------------------------------------------------------+
    282 // |                             prepare form                              |
    283 // +-----------------------------------------------------------------------+
    284 
    285 $template->set_filenames(array('add_photos' => dirname(__FILE__).'/add_photos.tpl'));
    286 
    287 include_once(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_prepare.inc.php');
     463}
     464
     465$template->assign(
     466  array(
     467    'setup_errors'=> $setup_errors,
     468    )
     469  );
    288470
    289471// we have to change the list of uploadable albums
  • extensions/community/add_photos.tpl

    r22820 r23037  
    1212{footer_script}{literal}
    1313jQuery(document).ready(function(){
     14function sprintf() {
     15        var i = 0, a, f = arguments[i++], o = [], m, p, c, x, s = '';
     16        while (f) {
     17                if (m = /^[^\x25]+/.exec(f)) {
     18                        o.push(m[0]);
     19                }
     20                else if (m = /^\x25{2}/.exec(f)) {
     21                        o.push('%');
     22                }
     23                else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
     24                        if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) {
     25                                throw('Too few arguments.');
     26                        }
     27                        if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) {
     28                                throw('Expecting number but found ' + typeof(a));
     29                        }
     30                        switch (m[7]) {
     31                                case 'b': a = a.toString(2); break;
     32                                case 'c': a = String.fromCharCode(a); break;
     33                                case 'd': a = parseInt(a); break;
     34                                case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
     35                                case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
     36                                case 'o': a = a.toString(8); break;
     37                                case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
     38                                case 'u': a = Math.abs(a); break;
     39                                case 'x': a = a.toString(16); break;
     40                                case 'X': a = a.toString(16).toUpperCase(); break;
     41                        }
     42                        a = (/[def]/.test(m[7]) && m[2] && a >= 0 ? '+'+ a : a);
     43                        c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
     44                        x = m[5] - String(a).length - s.length;
     45                        p = m[5] ? str_repeat(c, x) : '';
     46                        o.push(s + (m[4] ? a + p : p + a));
     47                }
     48                else {
     49                        throw('Huh ?!');
     50                }
     51                f = f.substring(m[0].length);
     52        }
     53        return o.join('');
     54}
     55
    1456  function checkUploadStart() {
    1557    var nbErrors = 0;
     
    167209{/literal}
    168210{if $upload_mode eq 'html'}
     211  {if isset($limit_nb_photos)}
     212  var limit_nb_photos = {$limit_nb_photos};
     213  {/if}
    169214{literal}
     215
    170216  function addUploadBox() {
    171217    var uploadBox = '<p class="file"><input type="file" size="60" name="image_upload[]"></p>';
    172218    jQuery(uploadBox).appendTo("#uploadBoxes");
     219
     220    if (typeof limit_nb_photos != 'undefined') {
     221      if (jQuery("input[name^=image_upload]").size() >= limit_nb_photos) {
     222        jQuery("#addUploadBox").hide();
     223      }
     224    }
    173225  }
    174226
     
    176228
    177229  jQuery("#addUploadBox A").click(function () {
     230    if (typeof limit_nb_photos != 'undefined') {
     231      if (jQuery("input[name^=image_upload]").size() >= limit_nb_photos) {
     232        alert('tu rigoles mon gaillard !');
     233        return false;
     234      }
     235    }
     236
    178237    addUploadBox();
    179238  });
     
    191250var buttonText = "{'Select files'|@translate}";
    192251var sizeLimit = Math.round({$upload_max_filesize} / 1024); /* in KBytes */
     252var sumQueueFilesize = 0;
     253  {if isset($limit_storage)}
     254var limit_storage = {$limit_storage};
     255  {/if}
    193256
    194257{literal}
     
    209272    'fileSizeLimit'  : sizeLimit,
    210273    'progressData'   : 'percentage',
     274{/literal}
     275  {if isset($limit_nb_photos)}
     276    'queueSizeLimit' : {$limit_nb_photos},
     277  {/if}
     278{literal}
    211279    requeueErrors   : false,
    212     'onSelect'       : function(event,ID,fileObj) {
     280    'onSelect'       : function(file) {
     281      console.log('filesize = '+file.size+'bytes');
     282
     283      if (typeof limit_storage != 'undefined') {
     284        if (sumQueueFilesize + file.size > limit_storage) {
     285          jQuery.jGrowl(
     286            '<p></p>'+sprintf(
     287              '{/literal}{'File %s too big (%uMB), quota of %uMB exceeded'|@translate}{literal}',
     288              file.name,
     289              Math.round(file.size/(1024*1024)),
     290              limit_storage/(1024*1024)
     291            ),
     292            {
     293              theme:  'error',
     294              header: 'ERROR',
     295              life:   4000,
     296              sticky: false
     297            }
     298          );
     299
     300          jQuery('#uploadify').uploadifyCancel(file.id);
     301          return false;
     302        }
     303        else {
     304          sumQueueFilesize += file.size;
     305        }
     306      }
     307
    213308      jQuery("#fileQueue").show();
     309    },
     310    'onCancel' : function(file) {
     311      console.log('The file ' + file.name + ' was cancelled ('+file.size+')');
    214312    },
    215313    'onQueueComplete'  : function(stats) {
     
    432530      <legend>{'Select files'|@translate}</legend>
    433531
    434     <p id="uploadWarningsSummary">{$upload_max_filesize_shorthand}B. {$upload_file_types}. {if isset($max_upload_resolution)}{$max_upload_resolution}Mpx{/if} <a class="showInfo" title="{'Learn more'|@translate}">i</a></p>
     532    <p id="uploadWarningsSummary">{$upload_max_filesize_shorthand}B. {$upload_file_types}. {if isset($max_upload_resolution)}{$max_upload_resolution}Mpx.{/if} {$quota_summary}
     533<a class="showInfo" title="{'Learn more'|@translate}">i</a></p>
    435534
    436535    <p id="uploadWarnings">
     
    440539{'Approximate maximum resolution: %dM pixels (that\'s %dx%d pixels).'|@translate|@sprintf:$max_upload_resolution:$max_upload_width:$max_upload_height}
    441540  {/if}
     541{$quota_details}
    442542    </p>
    443543
  • extensions/community/admin_pendings.php

    r16637 r23037  
    180180    $category_for_image[ $row['image_id'] ] = get_cat_display_name_cache(
    181181      $row['uppercats'],
    182       'admin.php?page=cat_modify&amp;cat_id=',
     182      'admin.php?page=album-',
    183183      false,
    184184      true,
  • extensions/community/admin_permissions.php

    r10772 r23037  
    7373  check_input_parameter('moderated', $_POST, false, '/^(true|false)$/');
    7474
     75  if (-1 != $_POST['nb_photos'])
     76  {
     77    check_input_parameter('nb_photos', $_POST, false, PATTERN_ID);
     78  }
     79
     80  if (-1 != $_POST['storage'])
     81  {
     82    check_input_parameter('storage', $_POST, false, PATTERN_ID);
     83  }
     84
    7585  // creating the permission
    7686  $insert = array(
     
    8292    'create_subcategories' => isset($_POST['create_subcategories']) ? 'true' : 'false',
    8393    'moderated' => $_POST['moderated'],
     94    'nb_photos' => $_POST['nb_photos'],
     95    'storage' => $_POST['storage'],
    8496    );
    8597
     
    222234        'create_subcategories' => get_boolean($row['create_subcategories']),
    223235        'moderated' => get_boolean($row['moderated']),
     236        'nb_photos' => empty($row['nb_photos']) ? -1 : $row['nb_photos'],
     237        'storage' => empty($row['storage']) ? -1 : $row['storage'],
    224238        )
    225239      );
     
    231245    array(
    232246      'moderated' => true,
     247      'nb_photos' => -1,
     248      'storage' => -1,
    233249      )
    234250    );
     
    445461    $highlight = true;
    446462  }
    447  
     463
     464  $nb_photos = false;
     465  $nb_photos_tooltip = null;
     466  if (!empty($permission['nb_photos']) and $permission['nb_photos'] > 0)
     467  {
     468    $nb_photos = $permission['nb_photos'];
     469    $nb_photos_tooltip = sprintf(
     470      l10n('up to %d photos (for each user)'),
     471      $nb_photos
     472      );
     473  }
     474
     475  $storage = false;
     476  $storage_tooltip = null;
     477  if (!empty($permission['storage']) and $permission['storage'] > 0)
     478  {
     479    $storage = $permission['storage'];
     480    $storage_tooltip = sprintf(
     481      l10n('up to %dMB (for each user)'),
     482      $storage
     483      );
     484  }
     485
    448486 
    449487  $template->append(
     
    456494      'RECURSIVE' => get_boolean($permission['recursive']),
    457495      'RECURSIVE_TOOLTIP' => l10n('Apply to sub-albums'),
     496      'NB_PHOTOS' => $nb_photos,
     497      'NB_PHOTOS_TOOLTIP' => $nb_photos_tooltip,
     498      'STORAGE' => $storage,
     499      'STORAGE_TOOLTIP' => $storage_tooltip,
    458500      'CREATE_SUBCATEGORIES' => get_boolean($permission['create_subcategories']),
    459501      'U_DELETE' => $admin_base_url.'&amp;delete='.$permission['id'],
  • extensions/community/admin_permissions.tpl

    r9807 r23037  
     1{combine_script id='jquery.ui.slider' require='jquery.ui' load='footer' path='themes/default/js/ui/minified/jquery.ui.slider.min.js'}
     2{combine_css path="themes/default/js/ui/theme/jquery.ui.slider.css"}
     3
    14{literal}
    25<style>
     
    69.permissionActions img {margin-bottom:-2px}
    710.rowSelected {background-color:#C2F5C2 !important}
     11#community_nb_photos, #community_storage {width:400px; display:inline-block; margin-right:10px;}
    812</style>
    913{/literal}
    1014
    1115{footer_script}{literal}
     16function sprintf() {
     17        var i = 0, a, f = arguments[i++], o = [], m, p, c, x, s = '';
     18        while (f) {
     19                if (m = /^[^\x25]+/.exec(f)) {
     20                        o.push(m[0]);
     21                }
     22                else if (m = /^\x25{2}/.exec(f)) {
     23                        o.push('%');
     24                }
     25                else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
     26                        if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) {
     27                                throw('Too few arguments.');
     28                        }
     29                        if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) {
     30                                throw('Expecting number but found ' + typeof(a));
     31                        }
     32                        switch (m[7]) {
     33                                case 'b': a = a.toString(2); break;
     34                                case 'c': a = String.fromCharCode(a); break;
     35                                case 'd': a = parseInt(a); break;
     36                                case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
     37                                case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
     38                                case 'o': a = a.toString(8); break;
     39                                case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
     40                                case 'u': a = Math.abs(a); break;
     41                                case 'x': a = a.toString(16); break;
     42                                case 'X': a = a.toString(16).toUpperCase(); break;
     43                        }
     44                        a = (/[def]/.test(m[7]) && m[2] && a >= 0 ? '+'+ a : a);
     45                        c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
     46                        x = m[5] - String(a).length - s.length;
     47                        p = m[5] ? str_repeat(c, x) : '';
     48                        o.push(s + (m[4] ? a + p : p + a));
     49                }
     50                else {
     51                        throw('Huh ?!');
     52                }
     53                f = f.substring(m[0].length);
     54        }
     55        return o.join('');
     56}
     57
    1258$(document).ready(function() {
    1359  $("select[name=who]").change(function () {
     
    5298    return false;
    5399  });
     100
     101  /* ∞ */
     102  /**
     103   * find the key from a value in the startStopValues array
     104   */
     105  function getSliderKeyFromValue(value, values) {
     106    for (var key in values) {
     107      if (values[key] == value) {
     108        return key;
     109      }
     110    }
     111    return 0;
     112  }
     113
     114  var nbPhotosValues = [5,10,20,50,100,500,1000,5000,-1];
     115
     116  function getNbPhotosInfoFromIdx(idx) {
     117    if (idx == nbPhotosValues.length - 1) {
     118      return "{/literal}{'no limit'|@translate}{literal}";
     119    }
     120
     121    return sprintf(
     122      "{/literal}{'up to %d photos (for each user)'|@translate}{literal}",
     123      nbPhotosValues[idx]
     124    );
     125  }
     126
     127  /* init nb_photos info span */
     128  var nbPhotos_init = getSliderKeyFromValue(jQuery('input[name=nb_photos]').val(), nbPhotosValues);
     129
     130  jQuery("#community_nb_photos_info").html(getNbPhotosInfoFromIdx(nbPhotos_init));
     131
     132  jQuery("#community_nb_photos").slider({
     133    range: "min",
     134    min: 0,
     135    max: nbPhotosValues.length - 1,
     136    value: nbPhotos_init,
     137    slide: function( event, ui ) {
     138      jQuery("#community_nb_photos_info").html(getNbPhotosInfoFromIdx(ui.value));
     139    },
     140    stop: function( event, ui ) {
     141      jQuery("input[name=nb_photos]").val(nbPhotosValues[ui.value]);
     142    }
     143  });
     144
     145  var storageValues = [10,50,100,200,500,1000,5000,-1];
     146
     147  function getStorageInfoFromIdx(idx) {
     148    if (idx == storageValues.length - 1) {
     149      return "{/literal}{'no limit'|@translate}{literal}";
     150    }
     151
     152    return sprintf(
     153      "{/literal}{'up to %dMB (for each user)'|@translate}{literal}",
     154      storageValues[idx]
     155    );
     156  }
     157
     158  /* init storage info span */
     159  var storage_init = getSliderKeyFromValue(jQuery('input[name=storage]').val(), storageValues);
     160
     161  jQuery("#community_storage_info").html(getStorageInfoFromIdx(storage_init));
     162
     163  jQuery("#community_storage").slider({
     164    range: "min",
     165    min: 0,
     166    max: storageValues.length - 1,
     167    value: storage_init,
     168    slide: function( event, ui ) {
     169      jQuery("#community_storage_info").html(getStorageInfoFromIdx(ui.value));
     170    },
     171    stop: function( event, ui ) {
     172      jQuery("input[name=storage]").val(storageValues[ui.value]);
     173    }
     174  });
     175
    54176});
    55177{/literal}{/footer_script}
     
    104226    </p>
    105227
     228    <p style="margin-bottom:0">
     229      <strong>{'How many photos?'|@translate}</strong>
     230    </p>
     231    <div id="community_nb_photos"></div>
     232    <span id="community_nb_photos_info">{'no limit'|@translate}</span>
     233    <input type="hidden" name="nb_photos" value="{$nb_photos}">
     234
     235    <p style="margin-top:1.5em;margin-bottom:0;">
     236      <strong>{'How much disk space?'|@translate}</strong>
     237    </p>
     238    <div id="community_storage"></div>
     239    <span id="community_storage_info">{'no limit'|@translate}</span>
     240    <input type="hidden" name="storage" value="{$storage}">
     241
    106242    {if isset($edit)}
    107243      <input type="hidden" name="edit" value="{$edit}">
    108244    {/if}
    109245   
    110     <p style="margin:0;">
     246    <p style="margin-top:1.5em;">
    111247      <input class="submit" type="submit" name="submit_add" value="{if isset($edit)}{'Submit'|@translate}{else}{'Add'|@translate}{/if}"/>
    112248      <a href="{$F_ADD_ACTION}">{'Cancel'|@translate}</a>
     
    128264    <td>{$permission.WHERE}</td>
    129265    <td>
    130       <span title="{$permission.TRUST_TOOLTIP}">{$permission.TRUST}</span>
    131     {if $permission.RECURSIVE}
    132 , <span title="{$permission.RECURSIVE_TOOLTIP}">{'sub-albums'|@translate}</span>
    133     {/if}
     266      <span title="{$permission.TRUST_TOOLTIP}">{$permission.TRUST}</span>{if $permission.RECURSIVE},
     267<span title="{$permission.RECURSIVE_TOOLTIP}">{'sub-albums'|@translate}</span>{/if}{if $permission.NB_PHOTOS},
     268<span title="{$permission.NB_PHOTOS_TOOLTIP}">{'%d photos'|@translate|sprintf:$permission.NB_PHOTOS}</span>{/if}{if $permission.STORAGE},
     269<span title="{$permission.STORAGE_TOOLTIP}">{$permission.STORAGE}MB</span>{/if}
    134270    {if $permission.CREATE_SUBCATEGORIES}
    135271, {'sub-albums creation'|@translate}
  • extensions/community/include/functions_community.inc.php

    r10770 r23037  
    5252    'upload_categories' => array(),
    5353    'permission_ids' => array(),
     54    'nb_photos' => 0,
     55    'storage' => 0,
    5456    );
    5557 
     
    6870    category_id,
    6971    recursive,
    70     create_subcategories
     72    create_subcategories,
     73    nb_photos,
     74    storage
    7175  FROM '.COMMUNITY_PERMISSIONS_TABLE.'
    7276  WHERE (type = \'any_visitor\')';
     
    120124      }
    121125    }
     126
     127    if ($return['nb_photos'] != -1)
     128    {
     129      if (empty($row['nb_photos']) or -1 == $row['nb_photos'])
     130      {
     131        // that means "no limit"
     132        $return['nb_photos'] = -1;
     133      }
     134      elseif ($row['nb_photos'] > $return['nb_photos'])
     135      {
     136        $return['nb_photos'] = $row['nb_photos'];
     137      }
     138    }
     139   
     140    if ($return['storage'] != -1)
     141    {
     142      if (empty($row['storage']) or -1 == $row['storage'])
     143      {
     144        // that means "no limit"
     145        $return['storage'] = -1;
     146      }
     147      elseif ($row['storage'] > $return['storage'])
     148      {
     149        $return['storage'] = $row['storage'];
     150      }
     151    }
    122152  }
    123153
     
    126156    $return ['upload_whole_gallery'] = true;
    127157    $return ['create_whole_gallery'] = true;
     158    $return['nb_photos'] = -1;
     159    $return['storage'] = -1;
    128160  }
    129161
     
    270302  }
    271303}
     304
     305function community_get_user_limits($user_id)
     306{
     307  // how many photos and storage for this user?
     308  $query = '
     309SELECT
     310    COUNT(id) AS nb_photos,
     311    IFNULL(FLOOR(SUM(filesize)/1024), 0) AS storage
     312  FROM '.IMAGES_TABLE.'
     313  WHERE added_by = '.$user_id.'
     314;';
     315  return pwg_db_fetch_assoc(pwg_query($query));
     316}
    272317?>
  • extensions/community/language/en_UK/plugin.lang.php

    r12333 r23037  
    6363
    6464$lang['Set Photo Properties'] = 'Set Photo Properties';
     65$lang['Available %s.'] = 'Available %s.';
     66$lang['Available quota %s.'] = 'Available quota %s.';
     67$lang['%s out of %s'] = '%s out of %s';
     68$lang['File %s too big (%uMB), quota of %uMB exceeded'] = 'File %s too big (%uMB), quota of %uMB exceeded';
     69$lang['Disk usage quota reached (%uMB)'] = 'Disk usage quota reached (%uMB)';
     70$lang['Maximum number of photos reached (%u)'] = 'Maximum number of photos reached (%u)';
     71$lang['Photo %s rejected.'] = 'Photo %s rejected.';
     72$lang['no limit'] = 'no limit';
     73$lang['up to %d photos (for each user)'] = 'up to %d photos (for each user)';
     74$lang['up to %dMB (for each user)'] = 'up to %dMB (for each user)';
     75$lang['How much disk space?'] = 'How much disk space?';
     76$lang['How many photos?'] = 'How many photos?';
    6577?>
  • extensions/community/language/fr_FR/plugin.lang.php

    r12508 r23037  
    5050$lang['%d photos uploaded by %s'] = '%d photos ajoutées par %s';
    5151$lang['Validation page: %s'] = 'Page de validation : %s';
    52 $lang['%d photos uploaded into album "%s"'] = '%d photos ajoutée à l\'album "%s"';
     52$lang['%d photos uploaded into album "%s"'] = '%d photos ajoutées à l\'album "%s"';
    5353$lang['Hi administrators,'] = 'Bonjours chers administrateurs,';
    5454
     
    6565
    6666$lang['Set Photo Properties'] = 'Définir les propriétés de la photo';
     67$lang['Available %s.'] = 'Disponible %s.';
     68$lang['Available quota %s.'] = 'Quota disponible %s.';
     69$lang['%s out of %s'] = '%s sur %s';
     70$lang['File %s too big (%uMB), quota of %uMB exceeded'] = 'Fichier %s trop gros (%uMB), quota de %uMB dépassé';
     71$lang['Disk usage quota reached (%uMB)'] = 'Quota d\'utilisation disque atteint (%uMB)';
     72$lang['Maximum number of photos reached (%u)'] = 'Nombre maximum de photos atteint (%u)';
     73$lang['Photo %s rejected.'] = 'Photo %s rejetée.';
     74$lang['no limit'] = 'pas de limite';
     75$lang['up to %d photos (for each user)'] = 'jusqu\'à %d photos (pour chaque utilisateur)';
     76$lang['up to %dMB (for each user)'] = 'jusqu\'à %dMB (pour chaque utilisateur)';
     77$lang['How much disk space?'] = 'Combien d\'espace disque ?';
     78$lang['How many photos?'] = 'Combien de photos ?';
    6779?>
  • extensions/community/main.inc.php

    r21751 r23037  
    1414}
    1515
     16global $prefixeTable;
     17
     18// +-----------------------------------------------------------------------+
     19// | Define plugin constants                                               |
     20// +-----------------------------------------------------------------------+
     21
     22defined('COMMUNITY_ID') or define('COMMUNITY_ID', basename(dirname(__FILE__)));
    1623define('COMMUNITY_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
    17 
    18 global $prefixeTable;
    1924define('COMMUNITY_PERMISSIONS_TABLE', $prefixeTable.'community_permissions');
    2025define('COMMUNITY_PENDINGS_TABLE', $prefixeTable.'community_pendings');
     26define('COMMUNITY_VERSION', 'auto');
    2127
    2228include_once(COMMUNITY_PATH.'include/functions_community.inc.php');
     29
     30// init the plugin
     31add_event_handler('init', 'community_init');
     32/**
     33 * plugin initialization
     34 *   - check for upgrades
     35 *   - unserialize configuration
     36 *   - load language
     37 */
     38function community_init()
     39{
     40  global $conf, $pwg_loaded_plugins;
     41
     42  // apply upgrade if needed
     43  if (
     44    COMMUNITY_VERSION == 'auto' or
     45    $pwg_loaded_plugins[COMMUNITY_ID]['version'] == 'auto' or
     46    version_compare($pwg_loaded_plugins[COMMUNITY_ID]['version'], COMMUNITY_VERSION, '<')
     47  )
     48  {
     49    // call install function
     50    include_once(COMMUNITY_PATH.'include/install.inc.php');
     51    community_install();
     52
     53    // update plugin version in database
     54    if ( $pwg_loaded_plugins[COMMUNITY_ID]['version'] != 'auto' and COMMUNITY_VERSION != 'auto' )
     55    {
     56      $query = '
     57UPDATE '. PLUGINS_TABLE .'
     58SET version = "'. COMMUNITY_VERSION .'"
     59WHERE id = "'. COMMUNITY_ID .'"';
     60      pwg_query($query);
     61
     62      $pwg_loaded_plugins[COMMUNITY_ID]['version'] = COMMUNITY_VERSION;
     63    }
     64  }
     65}
    2366
    2467/* Plugin admin */
  • extensions/community/maintain.inc.php

    r21289 r23037  
    11<?php
     2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    23
    34if (!defined("COMMUNITY_PATH"))
     
    67}
    78
     9include_once(COMMUNITY_PATH.'/include/install.inc.php');
     10
    811function plugin_install()
    912{
    10   global $conf, $prefixeTable;
    11 
    12   $query = '
    13 CREATE TABLE '.$prefixeTable.'community_permissions (
    14   id int(11) NOT NULL AUTO_INCREMENT,
    15   type varchar(255) NOT NULL,
    16   group_id smallint(5) unsigned DEFAULT NULL,
    17   user_id smallint(5) DEFAULT NULL,
    18   category_id smallint(5) unsigned DEFAULT NULL,
    19   recursive enum(\'true\',\'false\') NOT NULL DEFAULT \'true\',
    20   create_subcategories enum(\'true\',\'false\') NOT NULL DEFAULT \'false\',
    21   moderated enum(\'true\',\'false\') NOT NULL DEFAULT \'true\',
    22   PRIMARY KEY (id)
    23 ) ENGINE=MyISAM DEFAULT CHARACTER SET utf8
    24 ;';
    25   pwg_query($query);
    26 
    27   $query = '
    28 CREATE TABLE '.$prefixeTable.'community_pendings (
    29   image_id mediumint(8) unsigned NOT NULL,
    30   state varchar(255) NOT NULL,
    31   added_on datetime NOT NULL,
    32   validated_by smallint(5) DEFAULT NULL
    33 ) ENGINE=MyISAM DEFAULT CHARACTER SET utf8
    34 ;';
    35   pwg_query($query);
     13  community_install();
     14  define('community_installed', true);
    3615}
    3716
     
    5029{
    5130  global $prefixeTable;
    52 
    53   $are_new_tables_installed = false;
    54  
    55   $query = 'SHOW TABLES;';
    56   $result = pwg_query($query);
    57   while ($row = pwg_db_fetch_row($result))
    58   {
    59     if ($prefixeTable.'community_permissions' == $row[0])
    60     {
    61       $are_new_tables_installed = true;
    62     }
    63   }
    64 
    65   if (!$are_new_tables_installed)
    66   {
    67     plugin_install();
     31 
     32  if (!defined('community_installed')) // a plugin is activated just after its installation
     33  {
     34    community_install();
    6835  }
    6936
Note: See TracChangeset for help on using the changeset viewer.