Merge pull request #928 from dawnbreak/docu
Some documentation, fix chatroom service class lookup.
This commit is contained in:
commit
f823e2e2ed
@ -559,7 +559,7 @@ function downgrade_accounts() {
|
|||||||
// or what the subscriber is not allowed to do.
|
// 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();
|
$a = get_app();
|
||||||
if($uid == local_channel()) {
|
if($uid == local_channel()) {
|
||||||
$service_class = $a->account['account_service_class'];
|
$service_class = $a->account['account_service_class'];
|
||||||
@ -586,13 +586,26 @@ function service_class_allows($uid,$property,$usage = false) {
|
|||||||
else {
|
else {
|
||||||
if(! array_key_exists($property,$arr))
|
if(! array_key_exists($property,$arr))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return (((intval($usage)) < intval($arr[$property])) ? true : false);
|
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) {
|
* @brief Checks service class restrictions by account_id.
|
||||||
$a = get_app();
|
*
|
||||||
|
* 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",
|
$r = q("select account_service_class as service_class from account where account_id = %d limit 1",
|
||||||
intval($aid)
|
intval($aid)
|
||||||
);
|
);
|
||||||
@ -603,21 +616,33 @@ function account_service_class_allows($aid,$property,$usage = false) {
|
|||||||
if(! x($service_class))
|
if(! x($service_class))
|
||||||
return true; // everything is allowed
|
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)))
|
if(! is_array($arr) || (! count($arr)))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if($usage === false)
|
if($usage === false)
|
||||||
return ((x($arr[$property])) ? (bool) $arr[$property] : true);
|
return ((x($arr[$property])) ? (bool) $arr[$property] : true);
|
||||||
else {
|
else {
|
||||||
if(! array_key_exists($property,$arr))
|
if(! array_key_exists($property, $arr))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return (((intval($usage)) < intval($arr[$property])) ? true : false);
|
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();
|
$a = get_app();
|
||||||
if($uid == local_channel()) {
|
if($uid == local_channel()) {
|
||||||
$service_class = $a->account['account_service_class'];
|
$service_class = $a->account['account_service_class'];
|
||||||
@ -635,17 +660,17 @@ function service_class_fetch($uid,$property) {
|
|||||||
if(! x($service_class))
|
if(! x($service_class))
|
||||||
return false; // everything is allowed
|
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)))
|
if(! is_array($arr) || (! count($arr)))
|
||||||
return false;
|
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
|
// 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",
|
$r = q("select account_service_class as service_class from account where account_id = %d limit 1",
|
||||||
intval($aid)
|
intval($aid)
|
||||||
@ -657,12 +682,12 @@ function account_service_class_fetch($aid,$property) {
|
|||||||
if(! x($service_class))
|
if(! x($service_class))
|
||||||
return false; // everything is allowed
|
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)))
|
if(! is_array($arr) || (! count($arr)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return((array_key_exists($property,$arr)) ? $arr[$property] : false);
|
return((array_key_exists($property, $arr)) ? $arr[$property] : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,20 @@
|
|||||||
<?php /** @file */
|
<?php
|
||||||
|
/**
|
||||||
|
* @file include/chat.php
|
||||||
|
* @brief Chat related functions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
function chatroom_create($channel,$arr) {
|
/**
|
||||||
|
* @brief Creates a chatroom.
|
||||||
|
*
|
||||||
|
* @param array $channel
|
||||||
|
* @param array $arr
|
||||||
|
* @return An associative array containing:
|
||||||
|
* - success: A boolean
|
||||||
|
* - message: (optional) A string
|
||||||
|
*/
|
||||||
|
function chatroom_create($channel, $arr) {
|
||||||
|
|
||||||
$ret = array('success' => false);
|
$ret = array('success' => false);
|
||||||
|
|
||||||
@ -24,14 +37,14 @@ function chatroom_create($channel,$arr) {
|
|||||||
intval($channel['channel_account_id'])
|
intval($channel['channel_account_id'])
|
||||||
);
|
);
|
||||||
if($r)
|
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)) {
|
if(($r) && ($limit !== false) && ($r[0]['total'] >= $limit)) {
|
||||||
$ret['message'] = upgrade_message();
|
$ret['message'] = upgrade_message();
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! array_key_exists('expire',$arr))
|
if(! array_key_exists('expire', $arr))
|
||||||
$arr['expire'] = 120; // minutes, e.g. 2 hours
|
$arr['expire'] = 120; // minutes, e.g. 2 hours
|
||||||
|
|
||||||
$created = datetime_convert();
|
$created = datetime_convert();
|
||||||
@ -60,6 +73,7 @@ function chatroom_create($channel,$arr) {
|
|||||||
function chatroom_destroy($channel,$arr) {
|
function chatroom_destroy($channel,$arr) {
|
||||||
|
|
||||||
$ret = array('success' => false);
|
$ret = array('success' => false);
|
||||||
|
|
||||||
if(intval($arr['cr_id']))
|
if(intval($arr['cr_id']))
|
||||||
$sql_extra = " and cr_id = " . intval($arr['cr_id']) . " ";
|
$sql_extra = " and cr_id = " . intval($arr['cr_id']) . " ";
|
||||||
elseif(trim($arr['cr_name']))
|
elseif(trim($arr['cr_name']))
|
||||||
@ -88,12 +102,13 @@ function chatroom_destroy($channel,$arr) {
|
|||||||
intval($r[0]['cr_id'])
|
intval($r[0]['cr_id'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret['success'] = true;
|
$ret['success'] = true;
|
||||||
return $ret;
|
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)
|
if(! $room_id || ! $observer_xchan)
|
||||||
return;
|
return;
|
||||||
@ -117,7 +132,7 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) {
|
|||||||
return false;
|
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) {
|
if($limit !== false) {
|
||||||
$y = q("select count(*) as total from chatpresence where cp_room = %d",
|
$y = q("select count(*) as total from chatpresence where cp_room = %d",
|
||||||
intval($room_id)
|
intval($room_id)
|
||||||
@ -162,7 +177,7 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function chatroom_leave($observer_xchan,$room_id,$client) {
|
function chatroom_leave($observer_xchan, $room_id, $client) {
|
||||||
if(! $room_id || ! $observer_xchan)
|
if(! $room_id || ! $observer_xchan)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -208,7 +223,7 @@ function chatroom_list_count($uid) {
|
|||||||
* It is the caller's responsibility to enter the room.
|
* 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);
|
$ret = array('success' => false);
|
||||||
|
|
||||||
@ -230,7 +245,7 @@ function chat_message($uid,$room_id,$xchan,$text) {
|
|||||||
'chat_text' => $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 )
|
$x = q("insert into chat ( chat_room, chat_xchan, created, chat_text )
|
||||||
values( %d, '%s', '%s', '%s' )",
|
values( %d, '%s', '%s', '%s' )",
|
||||||
|
Reference in New Issue
Block a user