From 8c8be2a05e7646595b2c811dd4ab2ac7d7a98b69 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 28 Jan 2014 15:05:44 -0800 Subject: add client field to chatpresence - which will give us a place to put IP addresses for webRTC. Might as well allow for that since we'll (soon) have presence. Then we wouldn't need SIP and folks can "just" p2p each other using any mechanism they wish if they have permission to do so. --- boot.php | 2 +- doc/To-Do-Code.md | 4 ++-- install/database.sql | 1 + install/update.php | 8 +++++++- version.inc | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/boot.php b/boot.php index 73525b4b5..7be74e64a 100755 --- a/boot.php +++ b/boot.php @@ -46,7 +46,7 @@ define ( 'RED_PLATFORM', 'Red Matrix' ); define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R'); define ( 'ZOT_REVISION', 1 ); -define ( 'DB_UPDATE_VERSION', 1093 ); +define ( 'DB_UPDATE_VERSION', 1094 ); define ( 'EOL', '
' . "\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/doc/To-Do-Code.md b/doc/To-Do-Code.md index 3baf08d40..5804801b4 100644 --- a/doc/To-Do-Code.md +++ b/doc/To-Do-Code.md @@ -17,7 +17,7 @@ We need much more than this, but here are areas where developers can help. Pleas * (Advanced) create a UI for building Comanche pages -* Help with WebDAV and file storage implementation, especially replacing the fugly Sabre web UI. +* templatise and translate the Web interface to webDAV * Extend WebDAV to provide desktop access to photo albums @@ -25,7 +25,7 @@ We need much more than this, but here are areas where developers can help. Pleas * service classes - account overview page showing resources consumed by channel. With special consideration this page can also be accessed at a meta level by the site admin to drill down on problematic accounts/channels. -* Events module - bring back birthday reminders for friends, fix permissions on events, and provide JS translation support for the calendar overview +* Events module - bring back birthday reminders for friends, fix permissions on events, and provide JS translation support for the calendar overview; integrate with calDAV * Events module - event followups and RSVP diff --git a/install/database.sql b/install/database.sql index 1c87b725b..dba03da65 100644 --- a/install/database.sql +++ b/install/database.sql @@ -232,6 +232,7 @@ CREATE TABLE IF NOT EXISTS `chatpresence` ( `cp_xchan` char(255) NOT NULL DEFAULT '', `cp_last` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `cp_status` char(255) NOT NULL, + `cp_client` char(128) NOT NULL DEFAULT '', PRIMARY KEY (`cp_id`), KEY `cp_room` (`cp_room`), KEY `cp_xchan` (`cp_xchan`), diff --git a/install/update.php b/install/update.php index 9ab5db8c6..180b8d5a0 100644 --- a/install/update.php +++ b/install/update.php @@ -1,6 +1,6 @@ Date: Wed, 29 Jan 2014 00:43:54 +0100 Subject: Don't look for text emoticons inside the matching angle brackets of a HTML tag --- include/text.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/text.php b/include/text.php index f5c440e4a..4cb7a1d5e 100755 --- a/include/text.php +++ b/include/text.php @@ -891,6 +891,7 @@ function smilies($s, $sample = false) { $s = preg_replace_callback('/
(.*?)<\/pre>/ism','smile_encode',$s);
 	$s = preg_replace_callback('/(.*?)<\/code>/ism','smile_encode',$s);
+	$s = preg_replace_callback('/<(.*?)>/s','smile_encode',$s);
 
 	$texts =  array( 
 		'<3', 
@@ -983,6 +984,7 @@ function smilies($s, $sample = false) {
 
 	$s = preg_replace_callback('/
(.*?)<\/pre>/ism','smile_decode',$s);
 	$s = preg_replace_callback('/(.*?)<\/code>/ism','smile_decode',$s);
+	$s = preg_replace_callback('/<(.*?)>/s','smile_decode',$s);
 
 	return $s;
 
-- 
cgit v1.2.3


From 6e22aa25cc941f542a192ef32a2e8ee4f23bb1c1 Mon Sep 17 00:00:00 2001
From: friendica 
Date: Tue, 28 Jan 2014 15:52:54 -0800
Subject: basic presence indication

---
 mod/ping.php | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/mod/ping.php b/mod/ping.php
index dda87dec2..b9ecf9b41 100644
--- a/mod/ping.php
+++ b/mod/ping.php
@@ -43,6 +43,31 @@ function ping_init(&$a) {
 		unset($_SESSION['sysmsg_info']);
 	}
 
+	if(get_observer_hash() && (! $result['invalid'])) {
+		$r = q("select cp_id from chatpresence where cp_xchan = '%s'",
+			dbesc(get_observer_hash())
+		);
+		if($r) {
+			foreach($r as $rr) {
+				q("update chatpresence set cp_last = '%s' where cp_id = %d limit 1",
+					intval($rr['cp_id'])
+				);
+			}
+		}
+		else {
+			q("insert into chatpresence ( cp_xchan, cp_last, cp_status, cp_client)
+				values( '%s', '%s', '%s', '%s' ) ",
+				dbesc(get_observer_hash()),
+				dbesc(datetime_convert()),
+				dbesc('online'),
+				dbesc($_SERVER['REMOTE_ADDR'])
+			);
+		}
+	}
+
+	q("delete from chatpresence where cp_last < UTC_TIMESTAMP() - INTERVAL 2 MINUTE"); 
+
+
 	if((! local_user()) || ($result['invalid'])) {
 		echo json_encode($result);
 		killme();
-- 
cgit v1.2.3


From 8efac0cfd6db063a469ada1db4e5767a5fd975c6 Mon Sep 17 00:00:00 2001
From: friendica 
Date: Tue, 28 Jan 2014 16:16:55 -0800
Subject: fix sql query and provide setting to hide online status

---
 mod/ping.php          | 2 +-
 mod/settings.php      | 7 +++++++
 view/tpl/settings.tpl | 3 +++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/mod/ping.php b/mod/ping.php
index b9ecf9b41..f067091da 100644
--- a/mod/ping.php
+++ b/mod/ping.php
@@ -50,6 +50,7 @@ function ping_init(&$a) {
 		if($r) {
 			foreach($r as $rr) {
 				q("update chatpresence set cp_last = '%s' where cp_id = %d limit 1",
+					dbesc(datetime_convert()),
 					intval($rr['cp_id'])
 				);
 			}
@@ -67,7 +68,6 @@ function ping_init(&$a) {
 
 	q("delete from chatpresence where cp_last < UTC_TIMESTAMP() - INTERVAL 2 MINUTE"); 
 
-
 	if((! local_user()) || ($result['invalid'])) {
 		echo json_encode($result);
 		killme();
diff --git a/mod/settings.php b/mod/settings.php
index ee6ef45de..7ff76cd3e 100644
--- a/mod/settings.php
+++ b/mod/settings.php
@@ -266,6 +266,7 @@ function settings_post(&$a) {
 	$expire_network_only    = ((x($_POST,'expire_network_only'))? intval($_POST['expire_network_only'])	 : 0);
 
 	$allow_location   = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
+	$hide_presence    = (((x($_POST,'hide_presence')) && (intval($_POST['hide_presence']) == 1)) ? 1: 0);
 
 	$publish          = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
 	$page_flags       = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
@@ -395,6 +396,7 @@ function settings_post(&$a) {
 	set_pconfig(local_user(),'system','post_joingroup', $post_joingroup);
 	set_pconfig(local_user(),'system','post_profilechange', $post_profilechange);
 	set_pconfig(local_user(),'system','blocktags',$blocktags);
+	set_pconfig(local_user(),'system','hide_online_status',$hide_presence);
 
 
 	$r = q("update channel set channel_name = '%s', channel_pageflags = %d, channel_timezone = '%s', channel_location = '%s', channel_notifyflags = %d, channel_max_anon_mail = %d, channel_max_friend_req = %d, channel_expire_days = %d, channel_default_group = '%s', channel_r_stream = %d, channel_r_profile = %d, channel_r_photos = %d, channel_r_abook = %d, channel_w_stream = %d, channel_w_wall = %d, channel_w_tagwall = %d, channel_w_comment = %d, channel_w_mail = %d, channel_w_photos = %d, channel_w_chat = %d, channel_a_delegate = %d, channel_r_storage = %d, channel_w_storage = %d, channel_r_pages = %d, channel_w_pages = %d, channel_a_republish = %d, channel_allow_cid = '%s', channel_allow_gid = '%s', channel_deny_cid = '%s', channel_deny_gid = '%s'  where channel_id = %d limit 1",
@@ -821,6 +823,9 @@ function settings_content(&$a) {
 		$unkmail    = $a->user['unkmail'];
 		$cntunkmail = $a->user['cntunkmail'];
 
+		$hide_presence = intval(get_pconfig(local_user(), 'system','hide_online_status'));
+
+
 		$expire_items = get_pconfig(local_user(), 'expire','items');
 		$expire_items = (($expire_items===false)? '1' : $expire_items); // default if not set: 1
 	
@@ -918,6 +923,8 @@ function settings_content(&$a) {
 
 			'$h_prv' 	=> t('Security and Privacy Settings'),
 
+			'$hide_presence' => array('hide_presence', t('Hide my online presence'),$hide_presence, t('Prevents showing if you are available for chat')),
+
 			'$lbl_pmacro' => t('Quick Privacy Settings:'),
 			'$pmacro3'    => t('Very Public - extremely permissive'),
 			'$pmacro2'    => t('Typical - default public, privacy when desired'),
diff --git a/view/tpl/settings.tpl b/view/tpl/settings.tpl
index 7b6add231..b1a4f956d 100755
--- a/view/tpl/settings.tpl
+++ b/view/tpl/settings.tpl
@@ -22,6 +22,9 @@
 
 

{{$h_prv}}

+{{include file="field_checkbox.tpl" field=$hide_presence}} + +
{{$lbl_pmacro}}
  • {{$pmacro3}}
  • -- cgit v1.2.3 From d79a2e3b55c7cf6c775b8ecf7fbf708248aa16c8 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 28 Jan 2014 16:32:47 -0800 Subject: undo pull request #287 --- include/text.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/text.php b/include/text.php index 4cb7a1d5e..a459296cb 100755 --- a/include/text.php +++ b/include/text.php @@ -891,7 +891,7 @@ function smilies($s, $sample = false) { $s = preg_replace_callback('/
    (.*?)<\/pre>/ism','smile_encode',$s);
     	$s = preg_replace_callback('/(.*?)<\/code>/ism','smile_encode',$s);
    -	$s = preg_replace_callback('/<(.*?)>/s','smile_encode',$s);
    +//	$s = preg_replace_callback('/<(.*?)>/ism','smile_encode',$s);
     
     	$texts =  array( 
     		'<3', 
    @@ -984,7 +984,7 @@ function smilies($s, $sample = false) {
     
     	$s = preg_replace_callback('/
    (.*?)<\/pre>/ism','smile_decode',$s);
     	$s = preg_replace_callback('/(.*?)<\/code>/ism','smile_decode',$s);
    -	$s = preg_replace_callback('/<(.*?)>/s','smile_decode',$s);
    +//	$s = preg_replace_callback('/<(.*?)>/s','smile_decode',$s);
     
     	return $s;
     
    -- 
    cgit v1.2.3
    
    
    From 3dfd38021f193d16d3c6ed4824fa24e42a62238f Mon Sep 17 00:00:00 2001
    From: friendica 
    Date: Tue, 28 Jan 2014 16:35:10 -0800
    Subject: SECURITY: remove style and class bbcodes
    
    ---
     include/bbcode.php | 8 --------
     1 file changed, 8 deletions(-)
    
    diff --git a/include/bbcode.php b/include/bbcode.php
    index 084c02125..fec8750e9 100644
    --- a/include/bbcode.php
    +++ b/include/bbcode.php
    @@ -442,14 +442,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
     	// Check for list text
     	$Text = str_replace("[*]", "
  • ", $Text); - // Check for style sheet commands - if (strpos($Text,'[/style]') !== false) { - $Text = preg_replace("(\[style=(.*?)\](.*?)\[\/style\])ism","$2",$Text); - } - // Check for CSS classes - if (strpos($Text,'[/class]') !== false) { - $Text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism","$2",$Text); - } // handle nested lists $endlessloop = 0; -- cgit v1.2.3 From cc11535e34f1cc91251d7ca3f38ef38997774857 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 28 Jan 2014 17:07:25 -0800 Subject: online indication on profile sidebar --- include/identity.php | 28 +++++++++++++++++++++++++++- view/js/icon_translate.js | 1 + view/theme/redbasic/css/style.css | 4 ++++ view/tpl/profile_vcard.tpl | 2 +- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/identity.php b/include/identity.php index a99474d42..ee289495d 100644 --- a/include/identity.php +++ b/include/identity.php @@ -544,6 +544,9 @@ function profile_load(&$a, $nickname, $profile = '') { } $a->profile = $r[0]; + $online = get_online_status($nickname); + $a->profile['online_status'] = $online['result']; + $a->profile_uid = $r[0]['profile_uid']; $a->page['title'] = $a->profile['channel_name'] . " - " . $a->profile['channel_address'] . "@" . $a->get_hostname(); @@ -678,13 +681,15 @@ function profile_sidebar($profile, $block = 0, $show_connect = true) { $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False); $marital = ((x($profile,'marital') == 1) ? t('Status:') : False); $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False); + $profile['online'] = (($profile['online_status'] === 'online') ? t('Online Now') : False); +logger('online: ' . $profile['online']); if(! perm_is_allowed($profile['uid'],((is_array($observer)) ? $observer['xchan_hash'] : ''),'view_profile')) { $block = true; } if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) { - $location = $pdesc = $gender = $marital = $homepage = False; + $location = $pdesc = $gender = $marital = $homepage = $online = False; } $firstname = ((strpos($profile['name'],' ')) @@ -1144,3 +1149,24 @@ function is_foreigner($s) { function is_member($s) { return((is_foreigner($s)) ? false : true); } + +function get_online_status($nick) { + + $ret = array('result' => false); + + $r = q("select channel_id, channel_hash from channel where channel_address = '%s' limit 1", + dbesc(argv(1)) + ); + if($r) { + $hide = get_pconfig($r[0]['channel_id'],'system','hide_online_status'); + if($hide) + return $ret; + $x = q("select cp_status from chatpresence where cp_xchan = '%s' and cp_room = 0 limit 1", + dbesc($r[0]['channel_hash']) + ); + if($x) + $ret['result'] = $x[0]['cp_status']; + } + + return $ret; +} diff --git a/view/js/icon_translate.js b/view/js/icon_translate.js index 9e69e0b7d..838ff899f 100644 --- a/view/js/icon_translate.js +++ b/view/js/icon_translate.js @@ -50,4 +50,5 @@ $(document).ready(function() { $('.icon-check').addClass(''); $('.icon-globe').addClass(''); $('.icon-circle-blank').addClass(''); + $('.icon-circle').addClass(''); }); \ No newline at end of file diff --git a/view/theme/redbasic/css/style.css b/view/theme/redbasic/css/style.css index b2f90cbc1..02832b5f0 100644 --- a/view/theme/redbasic/css/style.css +++ b/view/theme/redbasic/css/style.css @@ -2445,4 +2445,8 @@ img.mail-list-sender-photo { .abook-self { background-color: #ffdddd; +} +.online-now { + color: red; + cursor: pointer; } \ No newline at end of file diff --git a/view/tpl/profile_vcard.tpl b/view/tpl/profile_vcard.tpl index aaee02ab5..7a857fd67 100755 --- a/view/tpl/profile_vcard.tpl +++ b/view/tpl/profile_vcard.tpl @@ -16,7 +16,7 @@ {{/if}} -
    {{$profile.name}}
    +
    {{$profile.name}}{{if $profile.online}} {{/if}}
    {{if $pdesc}}
    {{$profile.pdesc}}
    {{/if}}
    {{$profile.name}}
    -- cgit v1.2.3 From d970c69f91b96b3ef40752a95ecec8ca8b11b62a Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 28 Jan 2014 19:49:56 -0800 Subject: online indication to the directory popup --- include/identity.php | 22 ++++++++++++++++++++++ mod/dirprofile.php | 4 ++++ view/tpl/direntry_large.tpl | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/identity.php b/include/identity.php index ee289495d..2db5d8ece 100644 --- a/include/identity.php +++ b/include/identity.php @@ -1170,3 +1170,25 @@ function get_online_status($nick) { return $ret; } + + +function remote_online_status($webbie) { + + $result = false; + $r = q("select * from hubloc where hubloc_addr = '%s' limit 1", + dbesc($webbie) + ); + if(! $r) + return $result; + + $url = $r[0]['hubloc_url'] . '/online/' . substr($webbie,0,strpos($webbie,'@')); + + $x = z_fetch_url($url); + if($x['success']) { + $j = json_decode($x['body'],true); + if($j) + $result = (($j['result']) ? $j['result'] : false); + } + return $result; + +} diff --git a/mod/dirprofile.php b/mod/dirprofile.php index 1593b014a..d88144f52 100644 --- a/mod/dirprofile.php +++ b/mod/dirprofile.php @@ -74,6 +74,9 @@ function dirprofile_init(&$a) { $qrlink = zid($rr['url']); $connect_link = ((local_user()) ? z_root() . '/follow?f=&url=' . urlencode($rr['address']) : ''); + $online = remote_online_status($rr['address']); + + if(in_array($rr['hash'],$contacts)) $connect_link = ''; @@ -151,6 +154,7 @@ function dirprofile_init(&$a) { '$photo' => $rr['photo_l'], '$alttext' => $rr['name'] . ' ' . $rr['address'], '$name' => $rr['name'], + '$online' => (($online) ? t('Online Now') : ''), '$details' => $pdesc . $details, '$profile' => $profile, '$address' => $rr['address'], diff --git a/view/tpl/direntry_large.tpl b/view/tpl/direntry_large.tpl index a3fa7e4c3..f00448175 100755 --- a/view/tpl/direntry_large.tpl +++ b/view/tpl/direntry_large.tpl @@ -13,7 +13,7 @@
    -
    {{$name}}
    +
    {{$name}}{{if $online}} {{/if}}
    {{if $connect}} {{/if}} -- cgit v1.2.3 From 2822e6e70a15508e0626d5fe2eace87b5013b9b6 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 28 Jan 2014 20:15:57 -0800 Subject: missing file in checkin --- mod/online.php | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 mod/online.php diff --git a/mod/online.php b/mod/online.php new file mode 100644 index 000000000..c6500347a --- /dev/null +++ b/mod/online.php @@ -0,0 +1,11 @@ + false); + if(argc() != 2) + json_return_and_die($ret); + + $ret = get_online_status(argv(1)); + json_return_and_die($ret); +} -- cgit v1.2.3 From 0013e59086080963737d6c864eca7ff852a1e9da Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 28 Jan 2014 20:19:16 -0800 Subject: chatpresence timing out too quickly --- mod/ping.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/ping.php b/mod/ping.php index f067091da..e205dbea7 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -66,7 +66,7 @@ function ping_init(&$a) { } } - q("delete from chatpresence where cp_last < UTC_TIMESTAMP() - INTERVAL 2 MINUTE"); + q("delete from chatpresence where cp_last < UTC_TIMESTAMP() - INTERVAL 3 MINUTE"); if((! local_user()) || ($result['invalid'])) { echo json_encode($result); -- cgit v1.2.3 From 9261a170eb45f0b189afb4c1a30603d0cbb8f31c Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 00:08:29 -0800 Subject: basic chatroom management backend --- include/chat.php | 117 ++++++++++++++++++++++++++++++++++++++++++++ install/htconfig.sample.php | 2 +- version.inc | 2 +- 3 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 include/chat.php diff --git a/include/chat.php b/include/chat.php new file mode 100644 index 000000000..4df419294 --- /dev/null +++ b/include/chat.php @@ -0,0 +1,117 @@ + false); + + $name = trim($arr['name']); + if(! $name) { + $ret['message'] = t('Missing room name'); + return $ret; + } + + $r = q("select cr_id from chatroom where cr_uid = %d and cr_name = '%s' limit 1", + intval($channel['channel_id']), + dbesc($name) + ); + if($r) { + $ret['message'] = t('Duplicate room name'); + 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 ) + values ( %d, %d , '%s' '%s', '%s', '%s', '%s', '%s', '%s' ) ", + intval($channel['account_id']), + intval($channel['channel_id']), + dbesc($name), + dbesc($created), + dbesc($created), + dbesc($arr['allow_cid']), + dbesc($arr['allow_gid']), + dbesc($arr['deny_cid']), + dbesc($arr['deny_gid']) + ); + if($x) + $ret['success'] = true; + + return $ret; +} + + +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'])) + $sql_extra = " and cr_name = '" . protect_sprintf(dbesc(trim($arr['cr_name']))) . "' "; + else { + $ret['message'] = t('Invalid room specifier.'); + return $ret; + } + + $r = q("select * from chatroom where cr_uid = %d $sql_extra limit 1", + intval($channel['channel_id']) + ); + if(! $r) { + $ret['message'] = t('Invalid room specifier.'); + return $ret; + } + + q("delete from chatroom where cr_id = %d limit 1", + intval($r[0]['cr_id']) + ); + if($r[0]['cr_id']) { + q("delete from chatpresence where cp_room = %d", + intval($r[0]['cr_id']) + ); + } + $ret['success'] = true; + return $ret; +} + + +function chatroom_enter($observer_xchan,$room_id,$status) { + if(! $room_id || ! $observer) + return; + $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1", + dbesc($observer_xchan), + intval($room_id) + ); + if($r) { + q("update chatpresence set cp_status = %d and cp_last = '%s' where cp_id = %d limit 1", + dbesc($status), + dbesc(datetime_convert()), + intval($r[0]['cp_id']) + ); + return true; + } + + $r = q("insert into chatpresence ( cp_room, cp_xchan, cp_last, cp_status ) + values ( %d, '%s', '%s', '%s' )", + intval($room_id), + dbesc($observer_xchan), + dbesc(datetime_convert()), + dbesc($status) + ); + return $r; +} + + +function chatroom_leave($observer_xchan,$room_id,$status) { + if(! $room_id || ! $observer) + return; + $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1", + dbesc($observer_xchan), + intval($room_id) + ); + if($r) { + q("delete from chatpresence where cp_id = %d limit 1", + intval($r[0]['cp_id']) + ); + } + return true; +} \ No newline at end of file diff --git a/install/htconfig.sample.php b/install/htconfig.sample.php index 33258cf41..b23dfe3b6 100755 --- a/install/htconfig.sample.php +++ b/install/htconfig.sample.php @@ -3,7 +3,7 @@ // If automatic system installation fails: // Copy or rename this file to .htconfig.php in the top level -// Friendica directory +// Red Matrix directory // Why .htconfig.php? Because it contains sensitive information which could // give somebody complete control of your database. Apache's default diff --git a/version.inc b/version.inc index 3c79f0c43..36c8c7342 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2014-01-28.571 +2014-01-29.572 -- cgit v1.2.3 From 9f546757021305b6cfe924f38ca1af5fd5d3e69b Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 01:52:23 -0800 Subject: chatroom list widget backend --- include/chat.php | 9 +++++++++ include/widgets.php | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/include/chat.php b/include/chat.php index 4df419294..cb910bd62 100644 --- a/include/chat.php +++ b/include/chat.php @@ -114,4 +114,13 @@ function chatroom_leave($observer_xchan,$room_id,$status) { ); } return true; +} + + +function chatroom_list($uid) { + + $r = q("select cr_name, cr_id, count(cp_id) as cr_inroom from chatroom left join chatpresence on cr_id = cp_room where cr_uid = %d order by cr_name group by cp_id", + intval($uid) + ); + return $r; } \ No newline at end of file diff --git a/include/widgets.php b/include/widgets.php index efa350785..8b22515b1 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -576,3 +576,12 @@ function widget_menu_preview($arr) { require_once('include/menu.php'); return menu_render(get_app()->data['menu_item']); } + +function widget_chatroom_list($arr) { + require_once("include/chat.php"); + $r = chatroom_list(local_user()); + return replace_macros(get_markup_template('chatroomlist.tpl'),array( + '$header' => t('Chat Rooms'), + '$items' => $r, + )); +} \ No newline at end of file -- cgit v1.2.3 From f84ba95e870ce5b63e5af4cc7be43b516d4c163d Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 01:53:15 -0800 Subject: add template for chatroomlist widget --- view/tpl/chatroomlist.tpl | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 view/tpl/chatroomlist.tpl diff --git a/view/tpl/chatroomlist.tpl b/view/tpl/chatroomlist.tpl new file mode 100644 index 000000000..34050eef3 --- /dev/null +++ b/view/tpl/chatroomlist.tpl @@ -0,0 +1,11 @@ +
    +

    {{$header}}

    +{{$if $items}} + +{{for $items as $item}} + +{{/for}} +
    {{$item.cr_name}}{{$item.cr_inroom}}
    +{{/if}} +
    + -- cgit v1.2.3 From 10b51a9471bba2a1b058eee2d362d3d2189627be Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 02:25:21 -0800 Subject: issues uncovered whilst testing the chatroom API --- include/chat.php | 18 ++++++++++-------- mod/ping.php | 10 +++++++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/chat.php b/include/chat.php index cb910bd62..8011fdb5b 100644 --- a/include/chat.php +++ b/include/chat.php @@ -23,8 +23,8 @@ function chatroom_create($channel,$arr) { $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 ) - values ( %d, %d , '%s' '%s', '%s', '%s', '%s', '%s', '%s' ) ", - intval($channel['account_id']), + values ( %d, %d , '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ", + intval($channel['channel_account_id']), intval($channel['channel_id']), dbesc($name), dbesc($created), @@ -34,6 +34,7 @@ function chatroom_create($channel,$arr) { dbesc($arr['deny_cid']), dbesc($arr['deny_gid']) ); + if($x) $ret['success'] = true; @@ -74,8 +75,8 @@ function chatroom_destroy($channel,$arr) { } -function chatroom_enter($observer_xchan,$room_id,$status) { - if(! $room_id || ! $observer) +function chatroom_enter($observer_xchan,$room_id,$status,$client) { + if(! $room_id || ! $observer_xchan) return; $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1", dbesc($observer_xchan), @@ -90,19 +91,20 @@ function chatroom_enter($observer_xchan,$room_id,$status) { return true; } - $r = q("insert into chatpresence ( cp_room, cp_xchan, cp_last, cp_status ) - values ( %d, '%s', '%s', '%s' )", + $r = q("insert into chatpresence ( cp_room, cp_xchan, cp_last, cp_status, cp_client ) + values ( %d, '%s', '%s', '%s', '%s' )", intval($room_id), dbesc($observer_xchan), dbesc(datetime_convert()), - dbesc($status) + dbesc($status), + dbesc($client) ); return $r; } function chatroom_leave($observer_xchan,$room_id,$status) { - if(! $room_id || ! $observer) + if(! $room_id || ! $observer_xchan) return; $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1", dbesc($observer_xchan), diff --git a/mod/ping.php b/mod/ping.php index e205dbea7..c3c81992f 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -44,18 +44,22 @@ function ping_init(&$a) { } if(get_observer_hash() && (! $result['invalid'])) { - $r = q("select cp_id from chatpresence where cp_xchan = '%s'", - dbesc(get_observer_hash()) + $r = q("select cp_id from chatpresence where cp_xchan = '%s' and cp_client = '%s'", + dbesc(get_observer_hash()), + dbesc($_SERVER['REMOTE_ADDR']) ); + $basic_presence = false; if($r) { foreach($r as $rr) { + if($rr['cp_id'] == 0) + $basic_presence = true; q("update chatpresence set cp_last = '%s' where cp_id = %d limit 1", dbesc(datetime_convert()), intval($rr['cp_id']) ); } } - else { + if(! $basic_presence) { q("insert into chatpresence ( cp_xchan, cp_last, cp_status, cp_client) values( '%s', '%s', '%s', '%s' ) ", dbesc(get_observer_hash()), -- cgit v1.2.3 From c95f65e092e3ea3e4d312976789597ef91037b25 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 02:36:01 -0800 Subject: prevent runaway presence indication --- mod/ping.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/ping.php b/mod/ping.php index c3c81992f..2d5deb9ad 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -44,14 +44,14 @@ function ping_init(&$a) { } if(get_observer_hash() && (! $result['invalid'])) { - $r = q("select cp_id from chatpresence where cp_xchan = '%s' and cp_client = '%s'", + $r = q("select cp_id, cp_room from chatpresence where cp_xchan = '%s' and cp_client = '%s'", dbesc(get_observer_hash()), dbesc($_SERVER['REMOTE_ADDR']) ); $basic_presence = false; if($r) { foreach($r as $rr) { - if($rr['cp_id'] == 0) + if($rr['cp_room'] == 0) $basic_presence = true; q("update chatpresence set cp_last = '%s' where cp_id = %d limit 1", dbesc(datetime_convert()), -- cgit v1.2.3 From 6a9d43bcbe167ff3a8f9bd8a2ce93d9fc298fcdf Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 03:16:07 -0800 Subject: debug chatroom_list widget --- include/chat.php | 3 ++- view/tpl/chatroomlist.tpl | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/chat.php b/include/chat.php index 8011fdb5b..9d90f7970 100644 --- a/include/chat.php +++ b/include/chat.php @@ -121,8 +121,9 @@ function chatroom_leave($observer_xchan,$room_id,$status) { function chatroom_list($uid) { - $r = q("select cr_name, cr_id, count(cp_id) as cr_inroom from chatroom left join chatpresence on cr_id = cp_room where cr_uid = %d order by cr_name group by cp_id", + $r = q("select cr_name, cr_id, count(cp_id) as cr_inroom from chatroom left join chatpresence on cr_id = cp_room where cr_uid = %d group by cp_id order by cr_name", intval($uid) ); + return $r; } \ No newline at end of file diff --git a/view/tpl/chatroomlist.tpl b/view/tpl/chatroomlist.tpl index 34050eef3..d2cf4d7b0 100644 --- a/view/tpl/chatroomlist.tpl +++ b/view/tpl/chatroomlist.tpl @@ -1,10 +1,10 @@

    {{$header}}

    -{{$if $items}} +{{if $items}} -{{for $items as $item}} +{{foreach $items as $item}} -{{/for}} +{{/foreach}}
    {{$item.cr_name}}{{$item.cr_inroom}}
    {{/if}}
    -- cgit v1.2.3 From a1e7c65d51a6472cf7fe95686883f77953d7dfd7 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 03:39:32 -0800 Subject: chatroom permissions enforcement --- include/chat.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/chat.php b/include/chat.php index 9d90f7970..6bcb003ff 100644 --- a/include/chat.php +++ b/include/chat.php @@ -76,8 +76,27 @@ function chatroom_destroy($channel,$arr) { function chatroom_enter($observer_xchan,$room_id,$status,$client) { + if(! $room_id || ! $observer_xchan) return; + + $r = q("select * from chatroom where cr_id = %d limit 1", + intval($room_id) + ); + if(! $r) + return; + 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) + intval($r[0]['cr_uid']) + ); + if(! $x) { + notice( t('Permission denied.') . EOL); + return; + } + $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1", dbesc($observer_xchan), intval($room_id) -- cgit v1.2.3