3 Jappix - An open social platform
4 These are the filtering JS script for Jappix
6 -------------------------------------------------
9 Authors: Vanaryon, Maranda
10 Last revision: 04/08/11
14 // Generates a given emoticon HTML code
15 function emoteImage(image, text, after) {
16 return ' <img class="emoticon emoticon-' + image + ' smileys-images" alt="' + encodeQuotes(text) + '" src="' + './img/others/blank.gif' + '" /> ' + after;
19 // Filters a given message
20 function filterThisMessage(neutralMessage, nick, html_encode) {
21 var filteredMessage = neutralMessage;
23 // We encode the HTML special chars
25 filteredMessage = filteredMessage.htmlEnc();
28 filteredMessage = filteredMessage.replace(/((^)|((.+)(>)))(\/me )([^<]+)/, nick + ' $7')
30 // We replace the smilies text into images
31 .replace(/(:-?@)($|\s|<)/gi, emoteImage('angry', '$1', '$2'))
32 .replace(/(:-?\[)($|\s|<)/gi, emoteImage('bat', '$1', '$2'))
33 .replace(/(\(B\))($|\s|<)/g, emoteImage('beer', '$1', '$2'))
34 .replace(/((:-?D)|(XD))($|\s|<)/gi, emoteImage('biggrin', '$1', '$4'))
35 .replace(/(:-?\$)($|\s|<)/gi, emoteImage('blush', '$1', '$2'))
36 .replace(/(\(Z\))($|\s|<)/g, emoteImage('boy', '$1', '$2'))
37 .replace(/(\(W\))($|\s|<)/g, emoteImage('brflower', '$1', '$2'))
38 .replace(/((<\/3)|(\(U\)))($|\s|<)/g, emoteImage('brheart', '$1', '$4'))
39 .replace(/(\(C\))($|\s|<)/g, emoteImage('coffee', '$1', '$2'))
40 .replace(/((8-\))|(\(H\)))($|\s|<)/g, emoteImage('coolglasses', '$1', '$4'))
41 .replace(/(:'-?\()($|\s|<)/gi, emoteImage('cry', '$1', '$2'))
42 .replace(/(\(%\))($|\s|<)/g, emoteImage('cuffs', '$1', '$2'))
43 .replace(/(\]:-?>)($|\s|<)/gi, emoteImage('devil', '$1', '$2'))
44 .replace(/(\(D\))($|\s|<)/g, emoteImage('drink', '$1', '$2'))
45 .replace(/(@}->--)($|\s|<)/gi, emoteImage('flower', '$1', '$2'))
46 .replace(/((:-?\/)|(:-?S))($|\s|<)/gi, emoteImage('frowning', '$1', '$4'))
47 .replace(/(\(X\))($|\s|<)/g, emoteImage('girl', '$1', '$2'))
48 .replace(/((<3)|(\(L\)))($|\s|<)/g, emoteImage('heart', '$1', '$4'))
49 .replace(/(\(}\))($|\s|<)/g, emoteImage('hugleft', '$1', '$2'))
50 .replace(/(\({\))($|\s|<)/g, emoteImage('hugright', '$1', '$2'))
51 .replace(/(:-?{})($|\s|<)/gi, emoteImage('kiss', '$1', '$2'))
52 .replace(/(\(I\))($|\s|<)/g, emoteImage('lamp', '$1', '$2'))
53 .replace(/(:-?3)($|\s|<)/gi, emoteImage('lion', '$1', '$2'))
54 .replace(/(\(E\))($|\s|<)/g, emoteImage('mail', '$1', '$2'))
55 .replace(/(\(S\))($|\s|<)/g, emoteImage('moon', '$1', '$2'))
56 .replace(/(\(8\))($|\s|<)/g, emoteImage('music', '$1', '$2'))
57 .replace(/((=-?O)|(:-?O))($|\s|<)/gi, emoteImage('oh', '$1', '$4'))
58 .replace(/(\(T\))($|\s|<)/g, emoteImage('phone', '$1', '$2'))
59 .replace(/(\(P\))($|\s|<)/g, emoteImage('photo', '$1', '$2'))
60 .replace(/(:-?!)($|\s|<)/gi, emoteImage('puke', '$1', '$2'))
61 .replace(/(\(@\))($|\s|<)/g, emoteImage('pussy', '$1', '$2'))
62 .replace(/(\(R\))($|\s|<)/g, emoteImage('rainbow', '$1', '$2'))
63 .replace(/(:-?\))($|\s|<)/gi, emoteImage('smile', '$1', '$2'))
64 .replace(/(\(\*\))($|\s|<)/g, emoteImage('star', '$1', '$2'))
65 .replace(/(:-?\|)($|\s|<)/gi, emoteImage('stare', '$1', '$2'))
66 .replace(/(\(N\))($|\s|<)/g, emoteImage('thumbdown', '$1', '$2'))
67 .replace(/(\(Y\))($|\s|<)/g, emoteImage('thumbup', '$1', '$2'))
68 .replace(/(:-?P)($|\s|<)/gi, emoteImage('tongue', '$1', '$2'))
69 .replace(/(:-?\()($|\s|<)/gi, emoteImage('unhappy', '$1', '$2'))
70 .replace(/(;-?\))($|\s|<)/gi, emoteImage('wink', '$1', '$2'))
73 .replace(/(^|\s|>)((\*)([^<>'"]+)(\*))($|\s|<)/gi, '$1<b>$2</b>$6')
76 .replace(/(^|\s|>)((\/)([^<>'"]+)(\/))($|\s|<)/gi, '$1<i>$2</i>$6')
79 .replace(/(^|\s|>)((_)([^<>'"]+)(_))($|\s|<)/gi, '$1<span style="text-decoration: underline;">$2</span>$6');
83 filteredMessage = applyLinks(filteredMessage, 'desktop');
85 // Filter integratebox links
86 filteredMessage = filterIntegrateBox(filteredMessage);
88 return filteredMessage;
91 // Filters a xHTML message to be displayed in Jappix
92 function filterThisXHTML(code) {
93 // Allowed elements array
94 var elements = new Array(
132 // Allowed attributes array
133 var attributes = new Array(
159 // Remove forbidden elements
160 $(code).find('html body *').each(function() {
161 // This element is not authorized
162 if(!existArrayValue(elements, (this).nodeName.toLowerCase()))
166 // Remove forbidden attributes
167 $(code).find('html body *').each(function() {
168 // Put a pointer on this element (jQuery way & normal way)
169 var cSelector = $(this);
170 var cElement = (this);
172 // Loop the attributes of the current element
173 $(cElement.attributes).each(function(index) {
174 // Read the current attribute
175 var cAttr = cElement.attributes[index];
176 var cName = cAttr.name;
177 var cVal = cAttr.value;
179 // This attribute is not authorized, or contains JS code
180 if(!existArrayValue(attributes, cName.toLowerCase()) || ((cVal.toLowerCase()).match(/(^|"|')javascript:/)))
181 cSelector.removeAttr(cName);
185 // Filter some other elements
186 $(code).find('a').attr('target', '_blank');
188 return $(code).find('html body').html();