diff options
author | Klaus Weidenbach <Klaus.Weidenbach@gmx.net> | 2015-03-16 00:20:14 +0100 |
---|---|---|
committer | Klaus Weidenbach <Klaus.Weidenbach@gmx.net> | 2015-03-16 00:20:14 +0100 |
commit | 864116805b7adf8e82be582c2df8524c44a829fd (patch) | |
tree | 4dafc508962ed625ebf8a7f462cf15d59c8e2f4c | |
parent | 792e475a78ffb1f1facd615b00511c9107d0ac5a (diff) | |
download | volse-hubzilla-864116805b7adf8e82be582c2df8524c44a829fd.tar.gz volse-hubzilla-864116805b7adf8e82be582c2df8524c44a829fd.tar.bz2 volse-hubzilla-864116805b7adf8e82be582c2df8524c44a829fd.zip |
Documentation and remove duplicate code.
Add a bit Doxygen documentation and remove some duplicate code from
account.php.
-rw-r--r-- | include/account.php | 151 |
1 files changed, 79 insertions, 72 deletions
diff --git a/include/account.php b/include/account.php index 5793c2724..caac0b178 100644 --- a/include/account.php +++ b/include/account.php @@ -523,9 +523,7 @@ function downgrade_accounts() { $basic = get_config('system','default_service_class'); - foreach($r as $rr) { - if(($basic) && ($rr['account_service_class']) && ($rr['account_service_class'] != $basic)) { $x = q("UPDATE account set account_service_class = '%s', account_expires = '%s' where account_id = %d", @@ -550,97 +548,96 @@ function downgrade_accounts() { } - -// check service_class restrictions. If there are no service_classes defined, everything is allowed. -// if $usage is supplied, we check against a maximum count and return true if the current usage is -// less than the subscriber plan allows. Otherwise we return boolean true or false if the property -// is allowed (or not) in this subscriber plan. An unset property for this service plan means -// the property is allowed, so it is only necessary to provide negative properties for each plan, -// or what the subscriber is not allowed to do. - - +/** + * @brief Check service_class restrictions. + * + * If there are no service_classes defined, everything is allowed. + * If $usage is supplied, we check against a maximum count and return true if + * the current usage is less than the subscriber plan allows. Otherwise we + * return boolean true or false if the property is allowed (or not) in this + * subscriber plan. An unset property for this service plan means the property + * is allowed, so it is only necessary to provide negative properties for each + * plan, or what the subscriber is not allowed to do. + * + * Like account_service_class_allows() but queries directly by account rather + * than channel. Service classes are set for accounts, so we look up the + * account for the channel and fetch the service class restrictions of the + * account. + * + * @see account_service_class_allows() if you have a channel_id already + * @see service_class_fetch() + * + * @param int $uid The channel_id to check + * @param string $property The service class property to check for + * @param string|boolean $usage (optional) The value to check against + * @return boolean + */ function service_class_allows($uid, $property, $usage = false) { - $a = get_app(); - if($uid == local_channel()) { - $service_class = $a->account['account_service_class']; - } - else { - $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']; - } - } - if(! x($service_class)) - return true; // everything is allowed - - $arr = get_config('service_class',$service_class); - if(! is_array($arr) || (! count($arr))) - return true; + $limit = service_class_fetch($uid, $property); - if($usage === false) - return ((x($arr[$property])) ? (bool) $arr[$property] : true); - else { - if(! array_key_exists($property,$arr)) - return true; + if($limit === false) + return true; // No service class set => everything is allowed - return (((intval($usage)) < intval($arr[$property])) ? true : false); + if($usage === false) { + // We use negative values for not allowed properties in a subscriber plan + return ((x($limit)) ? (bool) $limit : true); + } else { + return (((intval($usage)) < intval($limit)) ? true : false); } } /** - * @brief Checks service class restrictions by account_id. + * @brief Check service class restrictions by account. * - * Like service_class_allows() but queries by account rather than channel. + * If there are no service_classes defined, everything is allowed. + * If $usage is supplied, we check against a maximum count and return true if + * the current usage is less than the subscriber plan allows. Otherwise we + * return boolean true or false if the property is allowed (or not) in this + * subscriber plan. An unset property for this service plan means the property + * is allowed, so it is only necessary to provide negative properties for each + * plan, or what the subscriber is not allowed to do. * - * @see service_class_allows() + * Like service_class_allows() but queries directly by account rather than channel. * - * @param int $aid account_id - * @param string $property - * @param int|boolean $usage, default false - * @return boolean + * @see service_class_allows() if you have a channel_id instead of an account_id + * @see account_service_class_fetch() * - * @todo Can't we use here internally account_service_class_fetch() to reduce duplicate code? + * @param int $aid The account_id to check + * @param string $property The service class property to check for + * @param int|boolean $usage, (optional) The value to check against + * @return boolean */ function account_service_class_allows($aid, $property, $usage = false) { - $r = q("select account_service_class as service_class from account where account_id = %d limit 1", - intval($aid) - ); - if($r !== false and count($r)) { - $service_class = $r[0]['service_class']; - } - if(! x($service_class)) - return true; // everything is allowed + $limit = account_service_class_fetch($aid, $property); - $arr = get_config('service_class', $service_class); - if(! is_array($arr) || (! count($arr))) - return true; + if($limit === false) + return true; // No service class is set => everything is allowed - if($usage === false) - return ((x($arr[$property])) ? (bool) $arr[$property] : true); - else { - if(! array_key_exists($property, $arr)) - return true; - - return (((intval($usage)) < intval($arr[$property])) ? true : false); + if($usage === false) { + // We use negative values for not allowed properties in a subscriber plan + return ((x($limit)) ? (bool) $limit : true); + } else { + return (((intval($usage)) < intval($limit)) ? true : false); } } /** - * @brief Fetches a service class for a channel_id and property. + * @brief Queries a service class value for a channel and property. + * + * Service classes are set for accounts, so look up the account for this channel + * and fetch the service classe of the account. * - * This method not just checks if a service class is allowed like service_class_allows(), - * but also returns the service class value. * If no service class is available it returns false and everything should be * allowed. * - * @param int $uid channel_id - * @param string $property + * @see account_service_class_fetch() + * + * @param int $uid The channel_id to query + * @param string $property The service property name to check for * @return boolean|int + * + * @todo Should we merge this with account_service_class_fetch()? */ function service_class_fetch($uid, $property) { $a = get_app(); @@ -668,8 +665,18 @@ function service_class_fetch($uid, $property) { return((array_key_exists($property, $arr)) ? $arr[$property] : false); } -// like service_class_fetch but queries by account rather than channel - +/** + * @brief Queries a service class value for an account and property. + * + * Like service_class_fetch() but queries by account rather than channel. + * + * @see service_class_fetch() if you have channel_id. + * @see account_service_class_allows() + * + * @param int $aid The account_id to query + * @param string $property The service property name to check for + * @return boolean|int + */ function account_service_class_fetch($aid, $property) { $r = q("select account_service_class as service_class from account where account_id = %d limit 1", @@ -692,7 +699,7 @@ function account_service_class_fetch($aid, $property) { function upgrade_link($bbcode = false) { - $l = get_config('service_class','upgrade_link'); + $l = get_config('service_class', 'upgrade_link'); if(! $l) return ''; if($bbcode) @@ -710,4 +717,4 @@ function upgrade_message($bbcode = false) { function upgrade_bool_message($bbcode = false) { $x = upgrade_link($bbcode); return t('This action is not available under your subscription plan.') . (($x) ? ' ' . $x : '') ; -} +}
\ No newline at end of file |