|
@@ -0,0 +1,69 @@
|
|
1
|
+/**
|
|
2
|
+ * Processes links and smileys in "body"
|
|
3
|
+ */
|
|
4
|
+function processReplacements(body)
|
|
5
|
+{
|
|
6
|
+ //make links clickable
|
|
7
|
+ body = linkify(body);
|
|
8
|
+
|
|
9
|
+ //add smileys
|
|
10
|
+ body = smilify(body);
|
|
11
|
+
|
|
12
|
+ return body;
|
|
13
|
+}
|
|
14
|
+
|
|
15
|
+/**
|
|
16
|
+ * Finds and replaces all links in the links in "body"
|
|
17
|
+ * with their <a href=""></a>
|
|
18
|
+ */
|
|
19
|
+function linkify(inputText)
|
|
20
|
+{
|
|
21
|
+ var replacedText, replacePattern1, replacePattern2, replacePattern3;
|
|
22
|
+
|
|
23
|
+ //URLs starting with http://, https://, or ftp://
|
|
24
|
+ replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
|
|
25
|
+ replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');
|
|
26
|
+
|
|
27
|
+ //URLs starting with "www." (without // before it, or it'd re-link the ones done above).
|
|
28
|
+ replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
|
|
29
|
+ replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');
|
|
30
|
+
|
|
31
|
+ //Change email addresses to mailto:: links.
|
|
32
|
+ replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;
|
|
33
|
+ replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
|
|
34
|
+
|
|
35
|
+ return replacedText;
|
|
36
|
+}
|
|
37
|
+
|
|
38
|
+/**
|
|
39
|
+ * Replaces common smiley strings with images
|
|
40
|
+ */
|
|
41
|
+function smilify(body)
|
|
42
|
+{
|
|
43
|
+ if(!body)
|
|
44
|
+ return body;
|
|
45
|
+
|
|
46
|
+ body = body.replace(/(:\(|:\(\(|:-\(\(|:-\(|\(sad\))/gi, "<img title=$1 alt=$1 src="+smiley1+ ">");
|
|
47
|
+ body = body.replace(/(\(angry\))/gi, "<img title=$1 alt=$1 src="+smiley2+ ">");
|
|
48
|
+ body = body.replace(/(\(n\))/gi, "<img title=$1 alt=$1 src="+smiley3+ ">");
|
|
49
|
+ body = body.replace(/(:-\)\)|:\)\)|;-\)\)|;\)\)|\(lol\)|:-D|:D|;-D|;D)/gi, "<img title=$1 alt=$1 src="+smiley4+ ">");
|
|
50
|
+ body = body.replace(/(;-\(\(|;\(\(|;-\(|;\(|:'\(|:'-\(|:~-\(|:~\(|\(upset\))/gi, "<img title=$1 alt=$1 src="+smiley5+ ">");
|
|
51
|
+ body = body.replace(/(<3|\(L\)|\(l\)|\(H\)|\(h\))/gi, "<img title=$1 alt=$1 src="+smiley6+ ">");
|
|
52
|
+ body = body.replace(/(\(angel\))/gi, "<img title=$1 alt=$1 src="+smiley7+ ">");
|
|
53
|
+ body = body.replace(/(\(bomb\))/gi, "<img title=$1 alt=$1 src="+smiley8+ ">");
|
|
54
|
+ body = body.replace(/(\(chuckle\))/gi, "<img title=$1 alt=$1 src="+smiley9+ ">");
|
|
55
|
+ body = body.replace(/(\(y\)|\(Y\)|\(ok\))/gi, "<img title=$1 alt=$1 src="+smiley10+ ">");
|
|
56
|
+ body = body.replace(/(;-\)|;\)|:-\)|:\))/gi, "<img title=$1 alt=$1 src="+smiley11+ ">");
|
|
57
|
+ body = body.replace(/(\(blush\))/gi, "<img title=$1 alt=$1 src="+smiley12+ ">");
|
|
58
|
+ body = body.replace(/(:-\*|:\*|\(kiss\))/gi, "<img title=$1 alt=$1 src="+smiley13+ ">");
|
|
59
|
+ body = body.replace(/(\(search\))/gi, "<img title=$1 alt=$1 src="+smiley14+ ">");
|
|
60
|
+ body = body.replace(/(\(wave\))/gi, "<img title=$1 alt=$1 src="+smiley15+ ">");
|
|
61
|
+ body = body.replace(/(\(clap\))/gi, "<img title=$1 alt=$1 src="+smiley16+ ">");
|
|
62
|
+ body = body.replace(/(\(sick\))/gi, "<img title=$1 alt=$1 src="+smiley17+ ">");
|
|
63
|
+ body = body.replace(/(:-P|:P|:-p|:p)/gi, "<img title=$1 alt=$1 src="+smiley18+ ">");
|
|
64
|
+ body = body.replace(/(:-\0|\(shocked\))/gi, "<img title=$1 alt=$1 src="+smiley19+ ">");
|
|
65
|
+ body = body.replace(/(\(oops\))/gi, "<img title=$1 alt=$1 src="+smiley20+ ">");
|
|
66
|
+
|
|
67
|
+ return body
|
|
68
|
+};
|
|
69
|
+
|