⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 func-aspcode.asp

📁 简介:一个程序小巧而功能强大
💻 ASP
字号:
<%
function bbcode(content_in, allow_img)
	'Converts bbCode into html before insertion to the database.
	images = allow_img
	content = content_in
	
	content = replace_format(content)
	content = replace_url(content)
	if images = 1 then
		content = replace_img(content)
	end if
	content = replace_quote(content)
	if request.form("smilies") = 1 then
		content = replace_smilies(content)
	end if
	
	bbcode = content
	
end function

function tagcount(content_in, first_tag, last_tag)
	
	'Count instances of start tags and end tags, if they match return passed.
	content = content_in
	start_tag = first_tag
	end_tag = last_tag 
	open_tag_count = 0
	close_tag_count = 0
	
	open_tag_count = ubound(split(content, start_tag))
	close_tag_count = ubound(split(content, end_tag))
			
	if open_tag_count = close_tag_count and open_tag_count > 0 then
		message = "passed"
	else
		message = "failed"
	end if

	tagcount = message

end function

function replace_format(content_in)

	'Replace all text formatting tags with the appropriate html tags
	content = content_in
	
	if instr(content, "[B]") > 0 then
		start_tag = "[B]"
		end_tag = "[/B]"	
		if tagcount(content, start_tag, end_tag) = "passed" then
			content = replace(content, "[B]", "<b>")
			content = replace(content, "[/B]", "</b>")
		end if
	end if
	
	if instr(content, "[I]") > 0 then
		start_tag = "[I]"
		end_tag = "[/I]"	
		if tagcount(content, start_tag, end_tag) = "passed" then
			content = replace(content, "[I]", "<i>")
			content = replace(content, "[/I]", "</i>")
		end if
	end if
	
	if instr(content, "[U]") > 0 then
		start_tag = "[U]"
		end_tag = "[/U]"	
		if tagcount(content, start_tag, end_tag) = "passed" then
			content = replace(content, "[U]", "<u>")
			content = replace(content, "[/U]", "</u>")
		end if
	end if
	
	if instr(content, "[S]") > 0 then
		start_tag = "[S]"
		end_tag = "[/S]"	
		if tagcount(content, start_tag, end_tag) = "passed" then
			content = replace(content, "[S]", "<s>")
			content = replace(content, "[/S]", "</s>")
		end if
	end if
	
	if instr(content, "[LIST]") > 0 then
		start_tag = "[LIST]"
		end_tag = "[/LIST]"	
		if tagcount(content, start_tag, end_tag) = "passed" then
			content = replace(content, "[LIST]", "<UL>")
			content = replace(content, "[*]", "<li>")
			content = replace(content, "[/LIST]", "</UL>")
		end if
	end if
	
	if instr(content, "[LIST=1]") > 0 then
		start_tag = "[LIST=1]"
		end_tag = "[/LIST=1]"	
		if tagcount(content, start_tag, end_tag) = "passed" then
			content = replace(content, "[LIST=1]", "<OL>")
			content = replace(content, "[*]", "<li>")
			content = replace(content, "[/LIST=1]", "</OL>")
		end if
	end if
	
	if instr(content, "[LIST=A]") > 0 then
		start_tag = "[LIST=A]"
		end_tag = "[/LIST=A]"	
		if tagcount(content, start_tag, end_tag) = "passed" then
			content = replace(content, "[LIST=A]", "<OL TYPE=A>")
			content = replace(content, "[*]", "<li>")
			content = replace(content, "[/LIST=A]", "</OL TYPE=A>")
		end if
	end if
	
	if instr(content, "[SPOILER]") > 0 then
		start_tag = "[SPOILER]"
		end_tag = "[/SPOILER]"	
		if tagcount(content, start_tag, end_tag) = "passed" then
			content = replace(content, "[SPOILER]", "<table bgcolor=black><tr><td bgcolor=black><font size=1 color=white>Spoiler: (highlight to view)</font></td></tr><tr><td><font size=2 color=black>")
			content = replace(content, "[/SPOILER]", "</font></td></tr></table>")
		end if
	end if

	content = replace(content, "[COLOR=BLACK]", "<font color=""black"">")
	content = replace(content, "[COLOR=WHITE]", "<font color=""white"">")
	content = replace(content, "[COLOR=BLUE]", "<font color=""blue"">")
	content = replace(content, "[COLOR=RED]", "<font color=""red"">")
	content = replace(content, "[COLOR=GREEN]", "<font color=""green"">")
	content = replace(content, "[COLOR=YELLOW]", "<font color=""yellow"">")
	content = replace(content, "[COLOR=ORANGE]", "<font color=""orange"">")
	content = replace(content, "[COLOR=BROWN]", "<font color=""brown"">")
	content = replace(content, "[COLOR=MAGENTA]", "<font color=""magenta"">")
	content = replace(content, "[COLOR=CYAN]", "<font color=""cyan"">")
	content = replace(content, "[/COLOR]", "</font c>")
	
	content = replace(content, "[SIZE=1]", "<font size=""1"">")
	content = replace(content, "[SIZE=2]", "<font size=""2"">")
	content = replace(content, "[SIZE=3]", "<font size=""3"">")
	content = replace(content, "[SIZE=4]", "<font size=""4"">")
	content = replace(content, "[SIZE=5]", "<font size=""5"">")
	content = replace(content, "[SIZE=6]", "<font size=""6"">")
	content = replace(content, "[/SIZE]", "</font s>")
		
	replace_format = content

end function

function replace_img(content_in)

	'Replace all [IMG]image location[/IMG] tags within the specified text
	content = content_in
	
	do while instr(1, content, "[IMG]", 0) > 0  and InStr(1, content, "[/IMG]", 0) > 0
		'Locate complete [IMG] code
		open_tag = instr(1, content, "[IMG]", 0)
		close_tag = instr(open_tag, content, "[/IMG]", 0) + 6
		original_image = trim(mid(content, open_tag, (close_tag - open_tag)))
		
		'Isolate the image URL
		new_image = original_image
		new_image = replace(new_image, "[IMG]", "", 1, -1, 1)
		new_image = replace(new_image, "[/IMG]", "", 1, -1, 1)
		
		'Filter the image location for any potentially harmful characters
		new_image = replace(new_image, """", " ")
		new_image = replace(new_image, "&", " ", 1, -1, 1)
		new_image = replace(new_image, "#", " ", 1, -1, 1)
		new_image = replace(new_image, ";", " ", 1, -1, 1)
		new_image = replace(new_image, "+", " ", 1, -1, 1)
		new_image = replace(new_image, "(", " ", 1, -1, 1)
		new_image = replace(new_image, ")", " ", 1, -1, 1)
		new_image = replace(new_image, "[", " ", 1, -1, 1)
		new_image = replace(new_image, "]", " ", 1, -1, 1)
		new_image = replace(new_image, "=", " ", 1, -1, 1)
		new_image = replace(new_image, "*", " ", 1, -1, 1)
		new_image = replace(new_image, "'", " ", 1, -1, 1)
		new_image = replace(new_image, "javascript", " ", 1, -1, 1)
		new_image = replace(new_image, "jscript", " ", 1, -1, 1)
		new_image = replace(new_image, "vbscript", " ", 1, -1, 1)
		new_image = replace(new_image, "mailto", " ", 1, -1, 1)
 		new_image = replace(new_image, "<", " ")
 		new_image = replace(new_image, ">", " ")
		
		'Replace [IMG] code with HTML tags
		new_image = "<img src=""" & new_image & """ border=""0"">"
		
		'Insert HTML into text
		content = replace(content, original_image, new_image, 1, -1, 1)	
	loop
	
	'Output the final altered text
	replace_img = content
	
end function

function replace_url(content_in)
	
	'Replace all [URL] related tags were applicable
	content = content_in
	
	'Replace all [URL=link location]link text[/URL] tags
	do while instr(1, content, "[URL=", 0) > 0 AND instr(1, content, "[/URL]", 0) > 0

		'Locate the complete [URL= code within the message
		open_tag = instr(1, content, "[URL=", 1)
		close_tag = instr(open_tag, content, "[/URL]", 0) + 6
		if close_tag - open_tag =< 5 then
			close_tag = open_tag + 5
		end if

		'Isolate the URL and link text from the message
		original_url = trim(mid(content, open_tag, (close_tag - open_tag)))
		new_url = original_url
		new_url = replace(new_url, "[URL=", "", 1, -1, 1)
		new_url = replace(new_url, "[/URL]", "", 1, -1, 1)
		
		url = left(new_url, instr(1, new_url, "]"))
		link = new_url
		link = replace(link, url, "")
		
		'Filter url for any potentially harmful characters 
		url = replace(url, """", " ")
		url = replace(url, "#", " ", 1, -1, 1)
		url = replace(url, ";", " ", 1, -1, 1)
		url = replace(url, "+", " ", 1, -1, 1)
		url = replace(url, "(", " ", 1, -1, 1)
		url = replace(url, ")", " ", 1, -1, 1)
		url = replace(url, "[", " ", 1, -1, 1)
		url = replace(url, "]", " ", 1, -1, 1)
		url = replace(url, "*", " ", 1, -1, 1)
		url = replace(url, "'", " ", 1, -1, 1)
		url = replace(url, "javascript", " ", 1, -1, 1)
		url = replace(url, "jscript", " ", 1, -1, 1)
		url = replace(url, "vbscript", " ", 1, -1, 1)
 		url = replace(url, "<", " ")
 		url = replace(url, ">", " ")
		
		'Build HTML code with filtered url
		new_url = "<a href=""" & url & """ target=""_blank"">" & link & "</a>"

		'Insert HTML back in to text
		content = Replace(content, original_url, new_url, 1, -1, 1)
	loop
	
	'Replace all [URL]link location[/URL] tags
	do while instr(1, content, "[URL]", 0) > 0  and InStr(1, content, "[/URL]", 0) > 0
		'Locate complete [URL] code
		open_tag = instr(1, content, "[URL]", 0)
		close_tag = instr(open_tag, content, "[/URL]", 0) + 6
		original_url = trim(mid(content, open_tag, (close_tag - open_tag)))
		
		'Isolate the URL
		new_url = original_url
		new_url = replace(new_url, "[URL]", "", 1, -1, 1)
		new_url = replace(new_url, "[/URL]", "", 1, -1, 1)
		
		'Filter the image location for any potentially harmful characters
		new_url = replace(new_url, """", " ")
		new_url = replace(new_url, "#", " ", 1, -1, 1)
		new_url = replace(new_url, ";", " ", 1, -1, 1)
		new_url = replace(new_url, "+", " ", 1, -1, 1)
		new_url = replace(new_url, "(", " ", 1, -1, 1)
		new_url = replace(new_url, ")", " ", 1, -1, 1)
		new_url = replace(new_url, "[", " ", 1, -1, 1)
		new_url = replace(new_url, "]", " ", 1, -1, 1)
		new_url = replace(new_url, "*", " ", 1, -1, 1)
		new_url = replace(new_url, "'", " ", 1, -1, 1)
		new_url = replace(new_url, "javascript", " ", 1, -1, 1)
		new_url = replace(new_url, "jscript", " ", 1, -1, 1)
		new_url = replace(new_url, "vbscript", " ", 1, -1, 1)
 		new_url = replace(new_url, "<", " ")
 		new_url = replace(new_url, ">", " ")
		
		'Build HTML code with filtered URL
		new_url = "<a href=""" & new_url & """ target=""_blank"">" & new_url & "</a>"
		
		'Insert HTML into text
		content = replace(content, original_url, new_url, 1, -1, 1)	
	loop

	'Output altered text
	replace_url = content

end function

function replace_quote(content_in)

	'Replace all [QUOTE] tags where applicable
	content = content_in
	
	do while instr(1, content, "[QUOTE]", 1) > 0  and InStr(1, content, "[/QUOTE]", 1) > 0
		'Locate complete [QUOTE] code
		open_tag = instr(1, content, "[QUOTE]", 1)
		close_tag = instr(open_tag, content, "[/QUOTE]", 1) + 8
		original_quote = trim(mid(content, open_tag, (close_tag - open_tag)))
		
		'Build the new Quote html
		new_quote = original_quote
		new_quote = replace(new_quote, "[QUOTE]", "<blockquote><hr>", 1, -1, 1)
		new_quote = replace(new_quote, "[/QUOTE]", "<hr></blockquote>", 1, -1, 1)
		
		'Insert HTML into text
		content = replace(content, original_quote, new_quote, 1, -1, 1)
	loop
	
	replace_quote = content

end function

function replace_smilies(content_in)
	
	'Replace all smilies in the specified text
	content = content_in
	set rsSmilies = server.createobject("adodb.recordset")
	sqlSmilies = "SELECT Smiley_Code, Smiley_Image FROM Forum_Smilies;"
	rsSmilies.open sqlSmilies, adoConn, CMDText
	if rsSmilies.eof or rsSmilies.bof then
	else
		SmileyCnt = rsSmilies.recordcount
		SmileyData = rsSmilies.getrows()
	end if
	rsSmilies.close
	set rsSmilies = nothing
	
	tempCnt = 0
	
	do while tempCnt < SmileyCnt
		smiley = "<img src='Images/Smilies/"& SmileyData(1, tempCnt) &"' border='0'>"
		content = replace(content, SmileyData(0, tempCnt), smiley)
		tempCnt = tempCnt + 1
	loop
	
	replace_smilies = content
	
end function
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -