From 80816a71955b8959bd9f1e24ee39d52aac3158eb Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 14 Mar 2015 00:10:06 +0100 Subject: Some documentation, fix chatroom service class lookup. Add some Doxygen documentation and fixing a service class lookup for chatroom_create(). --- include/account.php | 51 ++++++++++++++++++++++++++++++++++++++------------- include/chat.php | 47 +++++++++++++++++++++++++++++++---------------- 2 files changed, 69 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/account.php b/include/account.php index 19c13d5bd..5793c2724 100644 --- a/include/account.php +++ b/include/account.php @@ -559,7 +559,7 @@ function downgrade_accounts() { // or what the subscriber is not allowed to do. -function service_class_allows($uid,$property,$usage = false) { +function service_class_allows($uid, $property, $usage = false) { $a = get_app(); if($uid == local_channel()) { $service_class = $a->account['account_service_class']; @@ -586,13 +586,26 @@ function service_class_allows($uid,$property,$usage = false) { else { if(! array_key_exists($property,$arr)) return true; + return (((intval($usage)) < intval($arr[$property])) ? true : false); } } -// like service_class_allows but queries by account rather than channel -function account_service_class_allows($aid,$property,$usage = false) { - $a = get_app(); +/** + * @brief Checks service class restrictions by account_id. + * + * Like service_class_allows() but queries by account rather than channel. + * + * @see service_class_allows() + * + * @param int $aid account_id + * @param string $property + * @param int|boolean $usage, default false + * @return boolean + * + * @todo Can't we use here internally account_service_class_fetch() to reduce duplicate code? + */ +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) ); @@ -603,21 +616,33 @@ function account_service_class_allows($aid,$property,$usage = false) { if(! x($service_class)) return true; // everything is allowed - $arr = get_config('service_class',$service_class); + $arr = get_config('service_class', $service_class); if(! is_array($arr) || (! count($arr))) return true; if($usage === false) return ((x($arr[$property])) ? (bool) $arr[$property] : true); else { - if(! array_key_exists($property,$arr)) + if(! array_key_exists($property, $arr)) return true; + return (((intval($usage)) < intval($arr[$property])) ? true : false); } } - -function service_class_fetch($uid,$property) { +/** + * @brief Fetches a service class for a channel_id and property. + * + * 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 + * @return boolean|int + */ +function service_class_fetch($uid, $property) { $a = get_app(); if($uid == local_channel()) { $service_class = $a->account['account_service_class']; @@ -635,17 +660,17 @@ function service_class_fetch($uid,$property) { if(! x($service_class)) return false; // everything is allowed - $arr = get_config('service_class',$service_class); + $arr = get_config('service_class', $service_class); if(! is_array($arr) || (! count($arr))) return false; - return((array_key_exists($property,$arr)) ? $arr[$property] : false); + return((array_key_exists($property, $arr)) ? $arr[$property] : false); } // like service_class_fetch but queries by account rather than channel -function account_service_class_fetch($aid,$property) { +function account_service_class_fetch($aid, $property) { $r = q("select account_service_class as service_class from account where account_id = %d limit 1", intval($aid) @@ -657,12 +682,12 @@ function account_service_class_fetch($aid,$property) { if(! x($service_class)) return false; // everything is allowed - $arr = get_config('service_class',$service_class); + $arr = get_config('service_class', $service_class); if(! is_array($arr) || (! count($arr))) return false; - return((array_key_exists($property,$arr)) ? $arr[$property] : false); + return((array_key_exists($property, $arr)) ? $arr[$property] : false); } diff --git a/include/chat.php b/include/chat.php index b19d495bb..05bb02bb9 100644 --- a/include/chat.php +++ b/include/chat.php @@ -1,7 +1,20 @@ - false); @@ -24,14 +37,14 @@ function chatroom_create($channel,$arr) { intval($channel['channel_account_id']) ); if($r) - $limit = service_class_fetch($channel_id,'chatrooms'); + $limit = service_class_fetch($channel['channel_id'], 'chatrooms'); - if(($r) && ($limit !== false) && ($r[0]['total'] >= $limit)) { - $ret['message'] = upgrade_message(); - return $ret; - } + if(($r) && ($limit !== false) && ($r[0]['total'] >= $limit)) { + $ret['message'] = upgrade_message(); + return $ret; + } - if(! array_key_exists('expire',$arr)) + if(! array_key_exists('expire', $arr)) $arr['expire'] = 120; // minutes, e.g. 2 hours $created = datetime_convert(); @@ -60,6 +73,7 @@ function chatroom_create($channel,$arr) { function chatroom_destroy($channel,$arr) { $ret = array('success' => false); + if(intval($arr['cr_id'])) $sql_extra = " and cr_id = " . intval($arr['cr_id']) . " "; elseif(trim($arr['cr_name'])) @@ -72,7 +86,7 @@ function chatroom_destroy($channel,$arr) { $r = q("select * from chatroom where cr_uid = %d $sql_extra limit 1", intval($channel['channel_id']) ); - if(! $r) { + if(! $r) { $ret['message'] = t('Invalid room specifier.'); return $ret; } @@ -88,12 +102,13 @@ function chatroom_destroy($channel,$arr) { intval($r[0]['cr_id']) ); } + $ret['success'] = true; return $ret; } -function chatroom_enter($observer_xchan,$room_id,$status,$client) { +function chatroom_enter($observer_xchan, $room_id, $status, $client) { if(! $room_id || ! $observer_xchan) return; @@ -117,7 +132,7 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) { return false; } - $limit = service_class_fetch($r[0]['cr_uid'],'chatters_inroom'); + $limit = service_class_fetch($r[0]['cr_uid'], 'chatters_inroom'); if($limit !== false) { $y = q("select count(*) as total from chatpresence where cp_room = %d", intval($room_id) @@ -157,12 +172,12 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) { dbesc($status), dbesc($client) ); - + return $r; } -function chatroom_leave($observer_xchan,$room_id,$client) { +function chatroom_leave($observer_xchan, $room_id, $client) { if(! $room_id || ! $observer_xchan) return; @@ -208,7 +223,7 @@ function chatroom_list_count($uid) { * It is the caller's responsibility to enter the room. */ -function chat_message($uid,$room_id,$xchan,$text) { +function chat_message($uid, $room_id, $xchan, $text) { $ret = array('success' => false); @@ -230,14 +245,14 @@ function chat_message($uid,$room_id,$xchan,$text) { 'chat_text' => $text ); - call_hooks('chat_message',$arr); + call_hooks('chat_message', $arr); $x = q("insert into chat ( chat_room, chat_xchan, created, chat_text ) values( %d, '%s', '%s', '%s' )", intval($room_id), dbesc($xchan), dbesc(datetime_convert()), - dbesc($arr['chat_text']) + dbesc($arr['chat_text']) ); $ret['success'] = true; -- cgit v1.2.3