From ad6c82bdea11e4c35284e18608f78ad4c355405d Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 24 Jun 2012 22:23:17 -0700 Subject: [PATCH] implement "follow" service limits --- include/follow.php | 36 ++++++++++++++++++++++++++++++++++++ include/plugin.php | 15 ++++++++++++++- view/en/update_fail_eml.tpl | 2 +- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/include/follow.php b/include/follow.php index 22288a0daf..b4d1732b88 100644 --- a/include/follow.php +++ b/include/follow.php @@ -62,6 +62,11 @@ function new_contact($uid,$url,$interactive = false) { } } + + + + + // This extra param just confuses things, remove it if($ret['network'] === NETWORK_DIASPORA) $ret['url'] = str_replace('?absolute=true','',$ret['url']); @@ -89,6 +94,11 @@ function new_contact($uid,$url,$interactive = false) { $ret['notify'] = ''; } + + + + + if(! $ret['notify']) { $result['message'] .= t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL; } @@ -129,6 +139,32 @@ function new_contact($uid,$url,$interactive = false) { } else { + + // check service class limits + + $r = q("select count(*) as total from contact where uid = %d and pending = 0 and self = 0", + intval($uid) + ); + if(count($r)) + $total_contacts = $r[0]['total']; + + if(! service_class_allows($uid,'total_contacts',$total_contacts)) { + $result['message'] .= upgrade_message(); + return $result; + } + + $r = q("select count(network) as total from contact where uid = %d and network = '%s' and pending = 0 and self = 0", + intval($uid), + dbesc($network) + ); + if(count($r)) + $total_network = $r[0]['total']; + + if(! service_class_allows($uid,'total_contacts_' . $network,$total_network)) { + $result['message'] .= upgrade_message(); + return $result; + } + $new_relation = (($ret['network'] === NETWORK_MAIL) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING); if($ret['network'] === NETWORK_DIASPORA) $new_relation = CONTACT_IS_FOLLOWER; diff --git a/include/plugin.php b/include/plugin.php index 3b6faa072a..89715485ee 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -353,4 +353,17 @@ function service_class_allows($uid,$property,$usage = false) { return true; return (((intval($usage)) < intval($arr[$property])) ? true : false); } -} \ No newline at end of file +} + +function upgrade_link() { + $l = get_config('service_class','upgrade_link'); + $t = sprintf('' . t('Click here to upgrade.') . '', $l); + if($l) + return $t; + return ''; +} + +function upgrade_message() { + $x = upgrade_link(); + return t('This action exceeds the limits set by your subscription plan.') . (($x) ? ' ' . $x : '') ; +} diff --git a/view/en/update_fail_eml.tpl b/view/en/update_fail_eml.tpl index f68a3dece1..548e1a0df1 100644 --- a/view/en/update_fail_eml.tpl +++ b/view/en/update_fail_eml.tpl @@ -1,5 +1,5 @@ Hey, -I'm $sitename. +I'm $sitename; The friendica developers released update $update recently, but when I tried to install it, something went terribly wrong. This needs to be fixed soon and I can't do it alone. Please contact a