function _imagepicker_quota_check in Image Picker 7
Same name and namespace in other branches
- 6.2 imagepicker.functions.inc \_imagepicker_quota_check()
1 call to _imagepicker_quota_check()
- imagepicker_quota_ok in ./
imagepicker.functions.inc - Checks quotas
File
- ./
imagepicker.functions.inc, line 2277 - @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL
Code
function _imagepicker_quota_check($src, $account = FALSE) {
if ($account) {
$user = $account;
}
else {
global $user;
}
$usedbytes = imagepicker_get_all_bytes($user) + 1;
$usedbytesprint = _imagepicker_bkmg($usedbytes);
$quota = 0;
$quota_enabled = imagepicker_variable_get('imagepicker_quota_enable', 1);
if ($quota_enabled) {
if (imagepicker_variable_get('imagepicker_quota_byrole', 0)) {
$roleid = imagepicker_variable_get('imagepicker_quota_role', 2);
if (imagepicker_user_has_role($roleid, $user) && $user->uid > 1) {
$quota = imagepicker_variable_get('imagepicker_quota_default', 0);
}
}
else {
$quota = imagepicker_variable_get('imagepicker_quota_default', imagepicker_variable_get('imagepicker_quota_default', 0), $user->uid);
}
if ($quota > 0) {
$quota_ok = $quota * 1000000 > $usedbytes ? TRUE : FALSE;
}
else {
$quota_ok = TRUE;
}
}
else {
$quota_ok = TRUE;
}
$imgtot = _imagepicker_user_has_img($user);
$pl = format_plural($imgtot, '1 image', '@count images');
$message1 = '';
$message2 = '';
if ($quota_enabled) {
if ($quota > 0) {
$pused = round($usedbytes / ($quota * 1000000) * 100, 2);
$quotaprint = imagepicker_get_quota_list($quota + 1);
if ($src == 'admin') {
$message1 = t('The quota for %name is %quotaprint and has used %pused percent, or %usedbytesprint in %pl', array(
'%name' => $user->name,
'%quotaprint' => $quotaprint,
'%pused' => $pused,
'%usedbytesprint' => $usedbytesprint,
'%pl' => $pl,
));
}
else {
$message1 = t('Your quota is %quotaprint and you have used %pused percent, or %usedbytesprint in %pl', array(
'%quotaprint' => $quotaprint,
'%pused' => $pused,
'%usedbytesprint' => $usedbytesprint,
'%pl' => $pl,
));
}
}
else {
$quotaprint = imagepicker_get_quota_list($quota + 1);
if ($src == 'admin') {
$message1 = t('The quota for %name is %quotaprint and has used %usedbytesprint in %pl', array(
'%name' => $user->name,
'%quotaprint' => $quotaprint,
'%usedbytesprint' => $usedbytesprint,
'%pl' => $pl,
));
}
else {
$message1 = t('Your quota is %quotaprint and you have used %usedbytesprint in %pl', array(
'%quotaprint' => $quotaprint,
'%usedbytesprint' => $usedbytesprint,
'%pl' => $pl,
));
}
}
}
else {
if ($src == 'admin') {
$message1 = t('%name has used %usedbytesprint in %pl', array(
'%name' => $user->name,
'%usedbytesprint' => $usedbytesprint,
'%pl' => $pl,
));
}
else {
$message1 = t('You have used %usedbytesprint in %pl', array(
'%usedbytesprint' => $usedbytesprint,
'%pl' => $pl,
));
}
}
if (!$quota_ok) {
if ($src == 'admin') {
$message2 = t('%name has used all of quota, please delete some files to make some room.', array(
'%name' => $user->name,
));
}
else {
$message2 = t('You have used all of your quota, please delete some files to make some room.');
}
}
return array(
$quota_ok,
$message1,
$message2,
);
}