From 4c289394889dc5f69a0c20ecd56806ea691e7f64 Mon Sep 17 00:00:00 2001 From: toclimb Date: Wed, 29 Jan 2014 23:56:05 +0100 Subject: Don't look for emoticons inside the matching angle brackets of HTML tags (seriously) --- include/text.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index a459296cb..cf68ee121 100755 --- a/include/text.php +++ b/include/text.php @@ -871,8 +871,8 @@ function get_mood_verbs() { * Returns string * * It is expected that this function will be called using HTML text. - * We will escape text between HTML pre and code blocks from being - * processed. + * We will escape text between HTML pre and code blocks, and HTML attributes + * (such as urls) from being processed. * * At a higher level, the bbcode [nosmile] tag can be used to prevent this * function from being executed by the prepare_text() routine when preparing @@ -889,9 +889,8 @@ function smilies($s, $sample = false) { || (local_user() && intval(get_pconfig(local_user(),'system','no_smilies')))) return $s; - $s = preg_replace_callback('/
(.*?)<\/pre>/ism','smile_encode',$s);
-	$s = preg_replace_callback('/(.*?)<\/code>/ism','smile_encode',$s);
-//	$s = preg_replace_callback('/<(.*?)>/ism','smile_encode',$s);
+	$s = preg_replace_callback('{<(pre|code)>(?.*?)}ism','smile_encode',$s);
+	$s = preg_replace_callback('/<[a-z]+ (?.*?)>/ism','smile_encode',$s);
 
 	$texts =  array( 
 		'<3', 
@@ -982,20 +981,20 @@ function smilies($s, $sample = false) {
 		$s = str_replace($params['texts'],$params['icons'],$params['string']);
 	}
 
-	$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(
+		'//ism',
+		function ($m) { return base64url_decode($m[1]); },
+		$s
+	);
 
 	return $s;
 
 }
 
-function smile_encode($m) {
-	return(str_replace($m[1],base64url_encode($m[1]),$m[0]));
-}
 
-function smile_decode($m) {
-	return(str_replace($m[1],base64url_decode($m[1]),$m[0]));
+function smile_encode($m) {
+	$cleartext = $m['target'];
+	return str_replace($cleartext,'',$m[0]);
 }
 
 // expand <3333 to the correct number of hearts
-- 
cgit v1.2.3


From fe2b6f3dfb4a9473905dde49b7741a6c03699c23 Mon Sep 17 00:00:00 2001
From: marijus 
Date: Thu, 30 Jan 2014 00:01:19 +0100
Subject: add image floating to bbcode

---
 include/bbcode.php | 50 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 10 deletions(-)

(limited to 'include')

diff --git a/include/bbcode.php b/include/bbcode.php
index fec8750e9..57494bd7a 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -439,6 +439,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
 	if (strpos($Text,'[/center]') !== false) {	
 	$Text = preg_replace("(\[center\](.*?)\[\/center\])ism","
$1
",$Text); } + // Check for list text $Text = str_replace("[*]", "
  • ", $Text); @@ -531,23 +532,52 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { "
    " . $t_wrote . "
    $2
    ", $Text); - // [img=widthxheight]image source[/img] - //$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); - if (strpos($Text,'[/img]') !== false) { - $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); - } - if (strpos($Text,'[/zmg]') !== false) { - $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '', $Text); - } // Images // [img]pathtoimage[/img] - if (strpos($Text,'[/img]') !== false) { + if (strpos($Text,'[/img]') !== false) { $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); } - if (strpos($Text,'[/zmg]') !== false) { + if (strpos($Text,'[/zmg]') !== false) { $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); } + // [img float={left, right}]pathtoimage[/img] + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img float=left\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img float=right\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg float=left\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg float=right\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + } + + // [img=widthxheight]pathtoimage[/img] + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + } + + // [img=widthxheight float={left, right}]pathtoimage[/img] + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*) float=left\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/img]') !== false) { + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*) float=right\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*) float=left\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + } + if (strpos($Text,'[/zmg]') !== false) { + $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*) float=right\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); + } + + // crypt if (strpos($Text,'[/crypt]') !== false) { $x = random_string(); $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); -- cgit v1.2.3 From 75022367e5c3ecec24ec66acff162d6dd534486c Mon Sep 17 00:00:00 2001 From: marijus Date: Thu, 30 Jan 2014 00:15:13 +0100 Subject: minor whitespace cleanup --- include/bbcode.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 57494bd7a..2e2faddd6 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -439,7 +439,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { if (strpos($Text,'[/center]') !== false) { $Text = preg_replace("(\[center\](.*?)\[\/center\])ism","
    $1
    ",$Text); } - // Check for list text $Text = str_replace("[*]", "
  • ", $Text); -- cgit v1.2.3 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 +++ 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'include') 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 -- 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 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'include') 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", -- 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(+) (limited to 'include') 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 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 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') 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 +} + -- cgit v1.2.3 From 6c6a9b963a925d33b2cc436d877a4edc5f0d59b1 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 30 Jan 2014 01:00:46 -0800 Subject: a bit more ajax work on chat and chatsvc and some fiddling with layouts --- include/chat.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/chat.php b/include/chat.php index aef154fe6..b88c63fc3 100644 --- a/include/chat.php +++ b/include/chat.php @@ -155,7 +155,7 @@ function chatroom_leave($observer_xchan,$room_id,$client) { 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 group by cp_id order by cr_name", + $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 cr_name order by cr_name", intval($uid) ); -- cgit v1.2.3