From 677f5f641e6c37244ee67459b6fa2c7e5aea119b Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 16:02:02 -0800 Subject: more testing of chatroom interfaces, also corrected a function call that should have been a class instantiation in reddav --- include/chat.php | 4 ++-- include/reddav.php | 2 +- include/widgets.php | 3 +++ view/tpl/chatroomlist.tpl | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/chat.php b/include/chat.php index 6bcb003ff..f682fe6fe 100644 --- a/include/chat.php +++ b/include/chat.php @@ -88,8 +88,8 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) { require_once('include/security.php'); $sql_extra = permissions_sql($r[0]['cr_uid']); - $x = q("select * from chatroom where cr_id = %d and uid = %d $sql_extra limit 1", - intval($room_id) + $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1", + intval($room_id), intval($r[0]['cr_uid']) ); if(! $x) { diff --git a/include/reddav.php b/include/reddav.php index c5ef39097..e6e066770 100644 --- a/include/reddav.php +++ b/include/reddav.php @@ -628,7 +628,7 @@ function RedFileData($file, &$auth,$test = false) { } if((! $file) || ($file === '/')) { - return RedDirectory('/',$auth); + return new RedDirectory('/',$auth); } diff --git a/include/widgets.php b/include/widgets.php index 8b22515b1..400660d11 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -580,8 +580,11 @@ function widget_menu_preview($arr) { function widget_chatroom_list($arr) { require_once("include/chat.php"); $r = chatroom_list(local_user()); + $channel = get_app()->get_channel(); return replace_macros(get_markup_template('chatroomlist.tpl'),array( '$header' => t('Chat Rooms'), + '$baseurl' => z_root(), + '$nickname' => $channel['channel_address'], '$items' => $r, )); } \ No newline at end of file diff --git a/view/tpl/chatroomlist.tpl b/view/tpl/chatroomlist.tpl index d2cf4d7b0..c26ba0c33 100644 --- a/view/tpl/chatroomlist.tpl +++ b/view/tpl/chatroomlist.tpl @@ -3,7 +3,7 @@ {{if $items}} {{foreach $items as $item}} - + {{/foreach}}
{{$item.cr_name}}{{$item.cr_inroom}}
{{$item.cr_name}}{{$item.cr_inroom}}
{{/if}} -- cgit v1.2.3 From b8fb6a437335ce16e658f8acda632916bb28e574 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 17:09:20 -0800 Subject: more chat infrastructure --- include/chat.php | 15 ++++++++------ mod/chat.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ view/tpl/chat.tpl | 18 ++++++++++++++++ 3 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 mod/chat.php create mode 100644 view/tpl/chat.tpl diff --git a/include/chat.php b/include/chat.php index f682fe6fe..a8c3db429 100644 --- a/include/chat.php +++ b/include/chat.php @@ -83,8 +83,10 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) { $r = q("select * from chatroom where cr_id = %d limit 1", intval($room_id) ); - if(! $r) - return; + if(! $r) { + notice( t('Room not found.') . EOL); + return false; + } require_once('include/security.php'); $sql_extra = permissions_sql($r[0]['cr_uid']); @@ -94,7 +96,7 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) { ); if(! $x) { notice( t('Permission denied.') . EOL); - return; + return false; } $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1", @@ -122,12 +124,13 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) { } -function chatroom_leave($observer_xchan,$room_id,$status) { +function chatroom_leave($observer_xchan,$room_id,$client) { if(! $room_id || ! $observer_xchan) return; - $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1", + $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d and cp_client = '%s' limit 1", dbesc($observer_xchan), - intval($room_id) + intval($room_id), + dbesc($client) ); if($r) { q("delete from chatpresence where cp_id = %d limit 1", diff --git a/mod/chat.php b/mod/chat.php new file mode 100644 index 000000000..bc981b76b --- /dev/null +++ b/mod/chat.php @@ -0,0 +1,62 @@ + 1) + $which = argv(1); + if(! $which) { + if(local_user()) { + $channel = $a->get_channel(); + if($channel && $channel['channel_address']) + $which = $channel['channel_address']; + } + } + if(! $which) { + notice( t('You must be logged in to see this page.') . EOL ); + return; + } + + $profile = 0; + $channel = $a->get_channel(); + + if((local_user()) && (argc() > 2) && (argv(2) === 'view')) { + $which = $channel['channel_address']; + $profile = argv(1); + } + + $a->page['htmlhead'] .= '' . "\r\n" ; + + // Run profile_load() here to make sure the theme is set before + // we start loading content + + profile_load($a,$which,$profile); + +} + + +function chat_content(&$a) { + + if(! perm_is_allowed($a->profile['profile_uid'],get_observer_hash(),'chat')) { + notice( t('Permission denied.') . EOL); + return; + } + + if((argc() > 3) && intval(argv(2)) && (argv(3) === 'leave')) { + chatroom_leave(get_observer_hash(),$room_id,$_SERVER['REMOTE_ADDR']); + goaway(z_root() . '/channel/' . argv(1)); + } + + + if(argc() > 2 && intval(argv(2))) { + $room_id = intval(argv(2)); + $x = chatroom_enter(get_observer_hash(),$room_id,'online',$_SERVER['REMOTE_ADDR']); + if(! $x) + return; + $o = replace_macros(get_markup_template('chat.tpl'),array()); + return $o; + } + +} \ No newline at end of file diff --git a/view/tpl/chat.tpl b/view/tpl/chat.tpl new file mode 100644 index 000000000..6378b8776 --- /dev/null +++ b/view/tpl/chat.tpl @@ -0,0 +1,18 @@ +
+ +
+
+ +
+ +
+
+ +
+ + +
+ +
+ +
\ No newline at end of file -- cgit v1.2.3 From 0d326dfb45734950159030ea02b02dec4fba55b7 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 18:02:51 -0800 Subject: mod/chatsvc - ajax backend for chat --- mod/chatsvc.php | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 mod/chatsvc.php diff --git a/mod/chatsvc.php b/mod/chatsvc.php new file mode 100644 index 000000000..b8d2a9f69 --- /dev/null +++ b/mod/chatsvc.php @@ -0,0 +1,104 @@ + false); + + $a->data['chat']['room_id'] = intval($_REQUEST['room_id']); + $x = q("select cr_uid from chatroom where cr_id = %d and cr_id != 0 limit 1", + intval($a->data['chat']['room_id']) + ); + if(! $x) + json_return_and_die($ret); + + $a->data['chat']['uid'] = $x[0]['cr_uid']; + + if(! perm_is_allowed($a->data['chat']['uid'],get_observer_hash(),'chat')) { + json_return_and_die($ret); + } + +} + +function chatsvc_post(&$a) { + + $ret = array('success' => false); + + $room_id = $a->data['chat']['room_id']; + $text = escape_tags($_REQUEST['chat_text']); + + + $sql_extra = permissions_sql($a->data['chat']['uid']); + + $r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra", + intval($a->data['chat']['uid']), + intval($a->data['chat']['room_id']) + ); + if(! $r) + json_return_and_die($ret); + + $x = q("insert into chat ( chat_room, chat_xchan, created, chat_text ) + values( %d, '%s', '%s', '%s' )", + intval($a->data['chat']['room_id']), + dbesc(get_observer_hash()), + dbesc(datetime_convert()), + dbesc($text) + ); + +} + +function chatsvc_content(&$a) { + + $lastseen = intval($_REQUEST['last']); + + $ret = array('success' => false); + + $sql_extra = permissions_sql($a->data['chat']['uid']); + + $r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra", + intval($a->data['chat']['uid']), + intval($a->data['chat']['room_id']) + ); + if(! $r) + json_return_and_die($ret); + + $inroom = array(); + + $r = q("select * from chatpresence left join xchan on xchan_hash = cp_xchan where cp_room = %d order by xchan_name", + intval($a->data['chat']['room_id']) + ); + if($r) { + foreach($r as $rr) { + $inroom[] = array('img' => zid($rr['xchan_photo_m']), 'img_type' => $rr['xchan_photo_mimetype'],'name' => $rr['xchan_name']); + } + } + + $chats = array(); + + $r = q("select * from chat left join xchan on chat_xchan = xchan_hash where chat_room = %d and chat_id > %d", + intval($a->data['chat']['room_id']), + intval($lastseen) + ); + if($r) { + foreach($r as $rr) { + $chats[] = array( + 'id' => $rr['chat_id'], + 'img' => zid($rr['xchan_photo_m']), + 'img_type' => $rr['xchan_photo_mimetype'], + 'name' => $rr['xchan_name'], + 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $rr['created'], 'c'), + 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $rr['created'], 'r'), + 'text' => smilies(bbcode($rr['chat_text'])) + ); + } + } + + $ret['success'] = true; + $ret['inroom'] = $inroom; + $ret['chats'] = $chats; + + json_return_and_die($ret); + +} + \ No newline at end of file -- cgit v1.2.3 From c24aa824fe49d6dc803fb58c577d2238db416f2f Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 18:19:19 -0800 Subject: chat is a members only feature, there is no "guest" access. --- mod/chat.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mod/chat.php b/mod/chat.php index bc981b76b..42a7808d9 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -39,20 +39,26 @@ function chat_init(&$a) { function chat_content(&$a) { - if(! perm_is_allowed($a->profile['profile_uid'],get_observer_hash(),'chat')) { + $observer = get_observer_hash(); + if(! $observer) { + notice( t('Permission denied.') . EOL); + return; + } + + if(! perm_is_allowed($a->profile['profile_uid'],$observer,'chat')) { notice( t('Permission denied.') . EOL); return; } if((argc() > 3) && intval(argv(2)) && (argv(3) === 'leave')) { - chatroom_leave(get_observer_hash(),$room_id,$_SERVER['REMOTE_ADDR']); + chatroom_leave($observer,$room_id,$_SERVER['REMOTE_ADDR']); goaway(z_root() . '/channel/' . argv(1)); } if(argc() > 2 && intval(argv(2))) { $room_id = intval(argv(2)); - $x = chatroom_enter(get_observer_hash(),$room_id,'online',$_SERVER['REMOTE_ADDR']); + $x = chatroom_enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); if(! $x) return; $o = replace_macros(get_markup_template('chat.tpl'),array()); -- cgit v1.2.3 From 838ebbcb62aaaca8f19e338fe89c484f9d4ececd Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 18:29:03 -0800 Subject: apply service class limits (at the account level) to chatroom creation as chat has the potential to adversely affect system performance. In the future we may also want to service_class restrict the number of participants in a room. --- include/chat.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/chat.php b/include/chat.php index a8c3db429..aef154fe6 100644 --- a/include/chat.php +++ b/include/chat.php @@ -20,6 +20,18 @@ function chatroom_create($channel,$arr) { return $ret; } + $r = q("select count(cr_id) as total from chatroom where cr_aid = %d", + intval($channel['channel_account_id']) + ); + if($r) + $limit = service_class_fetch($channel_id,'chatrooms'); + + if(($r) && ($limit !== false) && ($r[0]['total'] >= $limit)) { + $ret['message'] = upgrade_message(); + return $ret; + } + + $created = datetime_convert(); $x = q("insert into chatroom ( cr_aid, cr_uid, cr_name, cr_created, cr_edited, allow_cid, allow_gid, deny_cid, deny_gid ) -- cgit v1.2.3 From 9fdee53c9a35d584de8cacd071c6608de88a18b6 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 20:14:18 -0800 Subject: start on the ajax bits --- mod/chat.php | 5 ++++- mod/chatsvc.php | 2 ++ view/tpl/chat.tpl | 33 +++++++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/mod/chat.php b/mod/chat.php index 42a7808d9..b8af4c1a6 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -61,7 +61,10 @@ function chat_content(&$a) { $x = chatroom_enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); if(! $x) return; - $o = replace_macros(get_markup_template('chat.tpl'),array()); + $o = replace_macros(get_markup_template('chat.tpl'),array( + '$room_id' => $room_id, + '$submit' => t('Submit') + )); return $o; } diff --git a/mod/chatsvc.php b/mod/chatsvc.php index b8d2a9f69..23b95cd1c 100644 --- a/mod/chatsvc.php +++ b/mod/chatsvc.php @@ -4,6 +4,8 @@ require_once('include/security.php'); function chatsvc_init(&$a) { +//logger('chatsvc'); + $ret = array('success' => false); $a->data['chat']['room_id'] = intval($_REQUEST['room_id']); diff --git a/view/tpl/chat.tpl b/view/tpl/chat.tpl index 6378b8776..d0f9418a0 100644 --- a/view/tpl/chat.tpl +++ b/view/tpl/chat.tpl @@ -8,11 +8,36 @@
-
- - + + +
+
- \ No newline at end of file + + + -- cgit v1.2.3 From 7b609782623d91c2bdf81c04cd801aaae927e9fa Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 20:40:37 -0800 Subject: back-end for changing online status and keeping presence refreshed --- mod/chat.php | 3 +++ mod/chatsvc.php | 21 ++++++++++++++++++++- view/pdl/mod_chat.pdl | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 view/pdl/mod_chat.pdl diff --git a/mod/chat.php b/mod/chat.php index b8af4c1a6..fa3d05364 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -67,5 +67,8 @@ function chat_content(&$a) { )); return $o; } + require_once('include/widgets.php'); + + return widget_chatroom_list(array()); } \ No newline at end of file diff --git a/mod/chatsvc.php b/mod/chatsvc.php index 23b95cd1c..39161b5a7 100644 --- a/mod/chatsvc.php +++ b/mod/chatsvc.php @@ -29,7 +29,19 @@ function chatsvc_post(&$a) { $room_id = $a->data['chat']['room_id']; $text = escape_tags($_REQUEST['chat_text']); - + $status = strip_tags($_REQUEST['status']); + + if($status && $room_id) { + $r = q("update chatpresence set cp_status = '%s', cp_last = '%s' where cp_room = %d and cp_xchan = '%s' and cp_client = '%s' limit 1", + dbesc($status), + dbesc(datetime_convert()), + intval($room_id), + dbesc(get_observer_hash()), + dbesc($_SERVER['REMOTE_ADDR']) + ); + } + if(! $text) + return; $sql_extra = permissions_sql($a->data['chat']['uid']); @@ -96,6 +108,13 @@ function chatsvc_content(&$a) { } } + $r = q("update chatpresence set cp_last = '%s' where cp_room = %d and cp_xchan = '%s' and cp_client = '%s' limit 1", + dbesc(datetime_convert()), + intval($room_id), + dbesc(get_observer_hash()), + dbesc($_SERVER['REMOTE_ADDR']) + ); + $ret['success'] = true; $ret['inroom'] = $inroom; $ret['chats'] = $chats; diff --git a/view/pdl/mod_chat.pdl b/view/pdl/mod_chat.pdl new file mode 100644 index 000000000..6b1d2a15e --- /dev/null +++ b/view/pdl/mod_chat.pdl @@ -0,0 +1,3 @@ +[region=aside] +[widget=profile][/widget] +[/region] -- cgit v1.2.3 From 080928f214c9f83879f1578e05baa6032fa2b7b8 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 21:29:48 -0800 Subject: chatroom management front-end stuff --- include/widgets.php | 3 +- mod/chat.php | 73 +++++++++++++++++++++++++++++++++++++++++++++ view/js/mod_chat.js | 16 ++++++++++ view/js/mod_filestorage.php | 16 ++++++++++ view/tpl/chatroom_new.tpl | 12 ++++++++ 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 view/js/mod_chat.js create mode 100644 view/js/mod_filestorage.php create mode 100644 view/tpl/chatroom_new.tpl diff --git a/include/widgets.php b/include/widgets.php index 400660d11..0151f7c27 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -587,4 +587,5 @@ function widget_chatroom_list($arr) { '$nickname' => $channel['channel_address'], '$items' => $r, )); -} \ No newline at end of file +} + diff --git a/mod/chat.php b/mod/chat.php index fa3d05364..54fa58092 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -36,6 +36,46 @@ function chat_init(&$a) { } +function chat_post(&$a) { + + if($_POST['room_name']) + $room = strip_tags(trim($_POST['room_name'])); + + if((! $room) || (! local_user())) + return; + + $channel = $a->get_channel(); + + + if($_POST['action'] === 'drop') { + chatroom_destroy($channel,array('cr_name' => $room)); + goaway(z_root() . '/chat/' . $channel['channel_address']); + } + + + $arr = array('name' => $room); + $arr['allow_gid'] = perms2str($_REQUEST['group_allow']); + $arr['allow_cid'] = perms2str($_REQUEST['contact_allow']); + $arr['deny_gid'] = perms2str($_REQUEST['group_deny']); + $arr['deny_cid'] = perms2str($_REQUEST['contact_deny']); + + chatroom_create($channel,$arr); + + $x = q("select cr_id from chatroom where cr_name = '%s' and cr_uid = %d limit 1", + dbesc($room), + intval(local_user()) + ); + + if($x) + goaway(z_root() . '/chat/' . $channel['channel_address'] . '/' . $x[0]['cr_id']); + + // that failed. Try again perhaps? + + goaway(z_root() . '/chat/' . $channel['channel_address'] . '/new'); + + +} + function chat_content(&$a) { @@ -62,11 +102,44 @@ function chat_content(&$a) { if(! $x) return; $o = replace_macros(get_markup_template('chat.tpl'),array( + '$room_name' => '', // should we get this from the API? '$room_id' => $room_id, '$submit' => t('Submit') )); return $o; } + + + + + + if(local_user() && argc() > 2 && argv(2) === 'new') { + + + $channel = $a->get_channel(); + $channel_acl = array( + 'allow_cid' => $channel['channel_allow_cid'], + 'allow_gid' => $channel['channel_allow_gid'], + 'deny_cid' => $channel['channel_deny_cid'], + 'deny_gid' => $channel['channel_deny_gid'] + ); + + require_once('include/acl_selectors.php'); + + $o = replace_macros(get_markup_template('chatroom_new.tpl'),array( + '$header' => t('New Chatroom'), + '$name' => array('room_name',t('Chatroom Name'),'', ''), + '$acl' => populate_acl($channel_acl), + '$submit' => t('Submit') + )); + return $o; + } + + + + + + require_once('include/widgets.php'); return widget_chatroom_list(array()); diff --git a/view/js/mod_chat.js b/view/js/mod_chat.js new file mode 100644 index 000000000..82957ae44 --- /dev/null +++ b/view/js/mod_chat.js @@ -0,0 +1,16 @@ +$(document).ready(function() { + + $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() { + var selstr; + $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() { + selstr = $(this).text(); + $('#jot-perms-icon').removeClass('unlock').addClass('lock'); + $('#jot-public').hide(); + }); + if(selstr == null) { + $('#jot-perms-icon').removeClass('lock').addClass('unlock'); + $('#jot-public').show(); + } + + }).trigger('change'); +}); diff --git a/view/js/mod_filestorage.php b/view/js/mod_filestorage.php new file mode 100644 index 000000000..82957ae44 --- /dev/null +++ b/view/js/mod_filestorage.php @@ -0,0 +1,16 @@ +$(document).ready(function() { + + $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() { + var selstr; + $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() { + selstr = $(this).text(); + $('#jot-perms-icon').removeClass('unlock').addClass('lock'); + $('#jot-public').hide(); + }); + if(selstr == null) { + $('#jot-perms-icon').removeClass('lock').addClass('unlock'); + $('#jot-public').show(); + } + + }).trigger('change'); +}); diff --git a/view/tpl/chatroom_new.tpl b/view/tpl/chatroom_new.tpl new file mode 100644 index 000000000..86eadb132 --- /dev/null +++ b/view/tpl/chatroom_new.tpl @@ -0,0 +1,12 @@ +

{{$header}}

+ +
+{{include file="field_input.tpl" field=$name}} +
+
+{{$acl}} +
+ +
+ + -- cgit v1.2.3