/**
* Processes links and smileys in "body"
*/
function processReplacements(body)
{
//make links clickable
body = linkify(body);
//add smileys
body = smilify(body);
return body;
}
/**
* Finds and replaces all links in the links in "body"
* with their
*/
function linkify(inputText)
{
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with http://, https://, or ftp://
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
replacedText = inputText.replace(replacePattern1, '$1');
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
replacedText = replacedText.replace(replacePattern2, '$1$2');
//Change email addresses to mailto:: links.
replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;
replacedText = replacedText.replace(replacePattern3, '$1');
return replacedText;
}
/**
* Replaces common smiley strings with images
*/
function smilify(body)
{
if(!body)
return body;
body = body.replace(/(:\(|:\(\(|:-\(\(|:-\(|\(sad\))/gi, "");
body = body.replace(/(\(angry\))/gi, "");
body = body.replace(/(\(n\))/gi, "");
body = body.replace(/(:-\)\)|:\)\)|;-\)\)|;\)\)|\(lol\)|:-D|:D|;-D|;D)/gi, "");
body = body.replace(/(;-\(\(|;\(\(|;-\(|;\(|:'\(|:'-\(|:~-\(|:~\(|\(upset\))/gi, "");
body = body.replace(/(<3|<3|\(L\)|\(l\)|\(H\)|\(h\))/gi, "");
body = body.replace(/(\(angel\))/gi, "");
body = body.replace(/(\(bomb\))/gi, "");
body = body.replace(/(\(chuckle\))/gi, "");
body = body.replace(/(\(y\)|\(Y\)|\(ok\))/gi, "");
body = body.replace(/(;-\)|;\)|:-\)|:\))/gi, "");
body = body.replace(/(\(blush\))/gi, "");
body = body.replace(/(:-\*|:\*|\(kiss\))/gi, "");
body = body.replace(/(\(search\))/gi, "");
body = body.replace(/(\(wave\))/gi, "");
body = body.replace(/(\(clap\))/gi, "");
body = body.replace(/(\(sick\))/gi, "");
body = body.replace(/(:-P|:P|:-p|:p)/gi, "");
body = body.replace(/(:-\0|\(shocked\))/gi, "");
body = body.replace(/(\(oops\))/gi, "");
return body
};