/*
[Discuz!] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: bbcode.js 35331 2015-06-15 07:03:11Z nemohou $
*/
var re, DISCUZCODE = [];
DISCUZCODE['num'] = '-1';
DISCUZCODE['html'] = [];
EXTRAFUNC['bbcode2html'] = [];
EXTRAFUNC['html2bbcode'] = [];
function addslashes(str) {
return preg_replace(['\\\\', '\\\'', '\\\/', '\\\(', '\\\)', '\\\[', '\\\]', '\\\{', '\\\}', '\\\^', '\\\$', '\\\?', '\\\.', '\\\*', '\\\+', '\\\|'], ['\\\\', '\\\'', '\\/', '\\(', '\\)', '\\[', '\\]', '\\{', '\\}', '\\^', '\\$', '\\?', '\\.', '\\*', '\\+', '\\|'], str);
}
function atag(aoptions, text) {
if(trim(text) == '') {
return '';
}
var pend = parsestyle(aoptions, '', '');
href = getoptionvalue('href', aoptions);
if(href.substr(0, 11) == 'javascript:') {
return trim(recursion('a', text, 'atag'));
}
return pend['prepend'] + '[url=' + href + ']' + trim(recursion('a', text, 'atag')) + '[/url]' + pend['append'];
}
function bbcode2html(str) {
if(str == '') {
return '';
}
if(typeof(parsetype) == 'undefined') {
parsetype = 0;
}
if(!fetchCheckbox('bbcodeoff') && allowbbcode && parsetype != 1) {
str = str.replace(/\[code\]([\s\S]+?)\[\/code\]/ig, function($1, $2) {return parsecode($2);});
}
if(fetchCheckbox('allowimgurl')) {
str = str.replace(/([^>=\]"'\/]|^)((((https?|ftp):\/\/)|www\.)([\w\-]+\.)*[\w\-\u4e00-\u9fa5]+\.([\.a-zA-Z0-9]+|\u4E2D\u56FD|\u7F51\u7EDC|\u516C\u53F8)((\?|\/|:)+[\w\.\/=\?%\-&~`@':+!]*)+\.(jpg|gif|png|bmp))/ig, '$1[img]$2[/img]');
}
if(!allowhtml || !fetchCheckbox('htmlon')) {
str = str.replace(//g, '>');
if(!fetchCheckbox('parseurloff')) {
str = parseurl(str, 'html', false);
}
}
for(i in EXTRAFUNC['bbcode2html']) {
EXTRASTR = str;
try {
eval('str = ' + EXTRAFUNC['bbcode2html'][i] + '()');
} catch(e) {}
}
if(!fetchCheckbox('smileyoff') && allowsmilies) {
if(typeof smilies_type == 'object') {
for(var typeid in smilies_array) {
for(var page in smilies_array[typeid]) {
for(var i in smilies_array[typeid][page]) {
re = new RegExp(preg_quote(smilies_array[typeid][page][i][1]), "g");
str = str.replace(re, '');
}
}
}
}
}
if(!fetchCheckbox('bbcodeoff') && allowbbcode) {
str = clearcode(str);
str = str.replace(/\[url\]\s*((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)([^\[\"']+?)\s*\[\/url\]/ig, function($1, $2, $3, $4) {return cuturl($2 + $4);});
str = str.replace(/\[url=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.|mailto:)?([^\r\n\[\"']+?)\]([\s\S]+?)\[\/url\]/ig, '$4');
str = str.replace(/\[email\](.[^\\=[]*)\[\/email\]/ig, '$1');
str = str.replace(/\[email=(.[^\\=[]*)\](.*?)\[\/email\]/ig, '$2');
str = str.replace(/\[postbg\]\s*([^\[\<\r\n;'\"\?\(\)]+?)\s*\[\/postbg\]/ig, function($1, $2) {
addCSS = '';
if(in_array($2, postimg_type["postbg"])) {
addCSS = '';
}
return addCSS;
});
str = str.replace(/\[color=([\w#\(\),\s]+?)\]/ig, '');
str = str.replace(/\[backcolor=([\w#\(\),\s]+?)\]/ig, '');
str = str.replace(/\[size=(\d+?)\]/ig, '');
str = str.replace(/\[size=(\d+(\.\d+)?(px|pt)+?)\]/ig, '');
str = str.replace(/\[font=([^\[\<\=]+?)\]/ig, '');
str = str.replace(/\[align=([^\[\<\=]+?)\]/ig, ' ');
str = str.replace(/\[float=left\]/ig, '
');
str = str.replace(/\[float=right\]/ig, '
');
if(parsetype != 1) {
str = str.replace(/\[quote]([\s\S]*?)\[\/quote\]\s?\s?/ig, '$1
', '', '' ], str, 'g'); } if(!fetchCheckbox('bbcodeoff')) { if(allowimgcode) { str = str.replace(/\[img\]\s*([^\[\"\<\r\n]+?)\s*\[\/img\]/ig, ''); str = str.replace(/\[attachimg\](\d+)\[\/attachimg\]/ig, function ($1, $2) { if(!$('image_' + $2)) { return ''; } width = $('image_' + $2).getAttribute('cwidth'); if(!width) { re = /cwidth=(["']?)(\d+)(\1)/i; var matches = re.exec($('image_' + $2).outerHTML); if(matches != null) { width = matches[2]; } } return ''; }); str = str.replace(/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\"\<\r\n]+?)\s*\[\/img\]/ig, function ($1, $2, $3, $4) {return ' 0 ? ' width="' + $2 + '"' : '') + ($3 > 0 ? ' _height="' + $3 + '"' : '') + ' src="' + $4 + '" border="0" alt="" />'}); } else { str = str.replace(/\[img\]\s*([^\[\"\<\r\n]+?)\s*\[\/img\]/ig, '$1'); str = str.replace(/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\"\<\r\n]+?)\s*\[\/img\]/ig, '$3'); } } for(var i = 0; i <= DISCUZCODE['num']; i++) { str = str.replace("[\tDISCUZ_CODE_" + i + "\t]", DISCUZCODE['html'][i]); } if(!allowhtml || !fetchCheckbox('htmlon')) { str = str.replace(/(^|>)([^<]+)(?=<|$)/ig, function($1, $2, $3) { return $2 + preg_replace(['\t', ' ', ' ', '(\r\n|\n|\r)'], [' ', ' ', ' ', '