Skip to content
Snippets Groups Projects
Commit 93004831 authored by Ghazi Triki's avatar Ghazi Triki
Browse files

Chat messages can contain XML code and all links starting with http, https,...

Chat messages can contain XML code and all links starting with http, https, ftp and www are parsed and sent correctly to chat service.
parent bc8f22ff
No related branches found
No related tags found
No related merge requests found
File added
......@@ -18,6 +18,7 @@
*/
package org.bigbluebutton.modules.chat
{
import org.as3commons.lang.StringUtils;
import org.bigbluebutton.util.i18n.ResourceUtil;
public class ChatUtil
......@@ -46,27 +47,48 @@ package org.bigbluebutton.modules.chat
}
public static function cleanup(message:String):String{
var parsedString:String = message.replace('<', '&#60;')
parsedString = parsedString.replace('>', '&#62;')
var parsedString:String = StringUtils.replace(message, '<', '&#60;'),
parsedString = StringUtils.replace(parsedString, '>', '&#62;')
return parsedString;
}
public static function parseURLs(message:String):String{
var indexOfHTTP:Number = message.indexOf("http://");
var indexOfWWW:Number = message.indexOf("www.");
var indexOfHTTPS:Number = message.indexOf("https://");
if (indexOfHTTP == -1 && indexOfWWW == -1 && indexOfHTTPS == -1) return message;
var words:Array = message.split(" ");
var parsedString:String = "";
for (var n:Number = 0; n < words.length; n++){
var word:String = words[n] as String;
if (word.indexOf("http://") != -1) parsedString += '<a href="event:' + word + '"> <u>' + word + '</u></a> ';
else if (word.indexOf("https://") != -1) parsedString += '<a href="event:' + word + '"> <u>' + word + '</u></a> ';
else if (word.indexOf("www.") != -1) parsedString += '<a href="event:http://' + word + '"> <u>' + word + '</u></a> ';
else parsedString += word + ' ';
public static function parseURLs( message : String ) : String{
var urlPattern : RegExp = /(http|ftp|https|www)(:\/\/[\w\-_]+)?(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/g;
var matches : Array = message.match(urlPattern);
var resultArray : Array = [];
var result : Object = urlPattern.exec(message);
while (result != null)
{
var item : Object = new Object();
item.foundValue = result[0];
item.index = result.index;
item.length = item.foundValue.length;
// We push the last result into resultArray
resultArray.push(item);
// We try to find the next match
urlPattern.lastIndex = item.index + item.length;
result = urlPattern.exec(message);
}
// Replacing matched patterns with HTML links
var parsedString : String = message;
for (var i : uint = matches.length; i > 0; i--)
{
var value : String = resultArray[i - 1].foundValue;
var newValue : String;
if ( !StringUtils.startsWith(value, 'www' ){
newValue = '<a href="event:' + value + '"> <u>' + value + '</u></a> ';
}
else{
newValue = '<a href="event:' + value + '"> <u>' + value + '</u></a> ';
}
parsedString = StringUtils.replaceAt(parsedString, newValue, resultArray[i - 1].index, resultArray[i - 1].index + resultArray[i - 1].length)
}
return parsedString;
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment