Merge service class

//service class configure in .htconfig.php:
$a->config['system']['default_service_class']='standard';  // this is
the default service class that is attached to every new account
$a->config['service_class']['standard'] =
array('photo_upload_limit'=>20000000, // total photo storage limit per
channel (here 20MB)
 'total_identities' =>5, // number of channels an account can create
'total_items' =>2000, // number of top level posts a channel can
create. Applies only to top level posts of the user, other posts and
comments are unaffected
'total_pages' =>10, // number of pages a channel can create
 'total_channels' =>500, // number of channels the user can add, other
users can still add this channel, even if the limit is reached
 'attach_upload_limit' =>20000000); // total attachment storage limit
per channel (here 20MB)
This commit is contained in:
Christian Vogeley 2013-09-08 18:03:26 +02:00
commit e70c9b3613
9 changed files with 104 additions and 14 deletions

View File

@ -339,7 +339,7 @@ function attach_store($channel,$observer_hash,$options = '',$arr = null) {
intval($channel_id)
);
if(($r) && (($r[0]['total'] + $filesize) > ($limit - $existing_size))) {
$ret['message'] = upgrade_message(true);
$ret['message'] = upgrade_message(true).sprintf(t("You have reached your limit of %1$.0f Mbytes attachment storage."),$limit / 1024000);
@unlink($src);
return $ret;
}

View File

@ -1,12 +1,27 @@
<?php /** @file */
function follow_widget() {
$a = get_app();
$uid =$a->channel['channel_id'];
$r = q("select count(*) as total from abook where abook_channel = %d and not (abook_flags & %d) ",
intval($uid),
intval(ABOOK_FLAG_SELF)
);
if($r)
$total_channels = $r[0]['total'];
$limit = service_class_fetch($uid,'total_channels');
if($limit !== false) {
$abook_usage_message = sprintf( t("You have %1$.0f of %2$.0f allowed connections."), $total_channels, $limit);
}
else {
$abook_usage_message = '';
}
return replace_macros(get_markup_template('follow.tpl'),array(
'$connect' => t('Add New Connection'),
'$desc' => t('Enter the channel address'),
'$hint' => t('Example: bob@example.com, http://example.com/barbara'),
'$follow' => t('Connect')
'$follow' => t('Connect'),
'$abook_usage_message' => $abook_usage_message
));
}

View File

@ -7,7 +7,7 @@ require_once('include/crypto.php');
function identity_check_service_class($account_id) {
$ret = array('success' => false, $message => '');
$r = q("select count(channel_id) as total from channel were channel_account_id = %d ",
$r = q("select count(channel_id) as total from channel where channel_account_id = %d ",
intval($account_id)
);
if(! ($r && count($r))) {
@ -80,7 +80,10 @@ function create_identity($arr) {
$ret['message'] = t('No account identifier');
return $ret;
}
$ret=identity_check_service_class($arr['account_id']);
if (!$ret['success']) {
return $ret;
}
$nick = mb_strtolower(trim($arr['nickname']));
$name = escape_tags($arr['name']);
$pageflags = ((x($arr,'pageflags')) ? intval($arr['pageflags']) : PAGE_NORMAL);

View File

@ -374,12 +374,14 @@ function get_theme_screenshot($theme) {
function service_class_allows($uid,$property,$usage = false) {
$a = get_app();
if($uid == local_user()) {
$service_class = $a->user['service_class'];
$service_class = $a->account['account_service_class'];
}
else {
$r = q("select service_class from user where uid = %d limit 1",
$r = q("select account_service_class as service_class
from channel c, account a
where c.channel_account_id=a.account_id and c.channel_id= %d limit 1",
intval($uid)
);
if($r !== false and count($r)) {
@ -404,13 +406,15 @@ function service_class_allows($uid,$property,$usage = false) {
function service_class_fetch($uid,$property) {
$a = get_app();
if($uid == local_user()) {
$service_class = $a->user['service_class'];
$service_class = $a->account['account_service_class'];
}
else {
$r = q("select service_class from user where uid = %d limit 1",
intval($uid)
$r = q("select account_service_class as service_class
from channel c, account a
where c.channel_account_id=a.account_id and c.channel_id= %d limit 1",
intval($uid)
);
if($r !== false and count($r)) {
$service_class = $r[0]['service_class'];
@ -420,6 +424,7 @@ function service_class_fetch($uid,$property) {
return false; // everything is allowed
$arr = get_config('service_class',$service_class);
if(! is_array($arr) || (! count($arr)))
return false;

View File

@ -71,7 +71,17 @@ function item_post(&$a) {
$webpage = ((x($_REQUEST,'webpage')) ? intval($_REQUEST['webpage']) : 0);
$pagetitle = ((x($_REQUEST,'pagetitle')) ? escape_tags($_REQUEST['pagetitle']) : '');
$layout_mid = ((x($_REQUEST,'layout_mid')) ? escape_tags($_REQUEST['layout_mid']): '');
/*
Check service class limits
*/
if (local_user() && !(x($_REQUEST,'parent')) && !(x($_REQUEST,'post_id'))) {
$ret=item_check_service_class(local_user(),x($_REQUEST,'webpage'));
if (!$ret['success']) {
notice( t($ret['message']) . EOL) ;
goaway($a->get_baseurl() . "/" . $return_path );
killme();
}
}
if($pagetitle) {
require_once('library/urlify/URLify.php');
$pagetitle = strtolower(URLify::transliterate($pagetitle));
@ -1115,3 +1125,40 @@ function fix_attached_file_permissions($channel,$observer_hash,$body,
}
}
}
function item_check_service_class($channel_id,$iswebpage) {
$ret = array('success' => false, $message => '');
if ($iswebpage) {
$r = q("select count(i.id) as total from item i
right join channel c on (i.author_xchan=c.channel_hash and i.uid=c.channel_id )
and i.parent=i.id and (i.item_restrict & %d) and i.uid= %d ",
intval(ITEM_WEBPAGE),
intval($channel_id)
);
}
else {
$r = q("select count(i.id) as total from item i
right join channel c on (i.author_xchan=c.channel_hash and i.uid=c.channel_id )
and i.parent=i.id and (i.item_restrict=0) and i.uid= %d ",
intval($channel_id)
);
}
if(! ($r && count($r))) {
$ret['message'] = t('Unable to obtain identity information from database');
return $ret;
}
if (!$iswebpage) {
if(! service_class_allows($channel_id,'total_items',$r[0]['total'])) {
$result['message'] .= upgrade_message().sprintf(t("You have reached your limit of %1$.0f top level posts."),$r[0]['total']);
return $result;
}
}
else {
if(! service_class_allows($channel_id,'total_pages',$r[0]['total'])) {
$result['message'] .= upgrade_message().sprintf(t("You have reached your limit of %1$.0f webpages."),$r[0]['total']);
return $result;
}
}
$ret['success'] = true;
return $ret;
}

View File

@ -53,6 +53,17 @@ function manage_content(&$a) {
$channels[$x]['default_links'] = '1';
}
}
$r = q("select count(channel_id) as total from channel where channel_account_id = %d ",
intval($account)
);
$limit = service_class_fetch(local_user(),'total_identities');
if($limit !== false) {
$channel_usage_message = sprintf( t("You have created %1$.0f of %2$.0f allowed channels."), $r[0]['total'], $limit);
}
else {
$channel_usage_message = '';
}
}
$links = array(
@ -69,6 +80,7 @@ function manage_content(&$a) {
'$msg_make_default' => t('Make Default'),
'$links' => $links,
'$all_channels' => $channels,
'$channel_usage_message' => $channel_usage_message,
));

View File

@ -7,6 +7,11 @@
{{/foreach}}
{{/if}}
{{if $channel_usage_message}}
<div id="channel-usage-message" class="usage-message">
{{$channel_usage_message}}
</div>
{{/if}}
{{if $selected}}
<div id="selected-channel">
<div id="channels-selected">{{$msg_selected}}</div>

View File

@ -4,5 +4,8 @@
<form action="follow" method="post" />
<input id="side-follow-url" type="text" name="url" size="24" title="{{$hint}}" /><input id="side-follow-submit" type="submit" name="submit" value="{{$follow}}" />
</form>
{{if $abook_usage_message}}
<div class="usage-message" id="abook-usage-message">{{$abook_usage_message}}</div>
{{/if}}
</div>

View File

@ -1,6 +1,6 @@
<h3>{{$pagename}}</h3>
<div id="photos-usage-message">{{$usage}}</div>
<div id="photos-usage-message" class="usage-message">{{$usage}}</div>
<form action="photos/{{$nickname}}" enctype="multipart/form-data" method="post" name="photos-upload-form" id="photos-upload-form" >
<input type="hidden" id="photos-upload-source" name="source" value="photos" />