Click here to Skip to main content
15,878,814 members
Articles / Programming Languages / ASP

StP Forum

Rate me:
Please Sign up or sign in to vote.
4.13/5 (8 votes)
17 Mar 20028 min read 89.7K   1.9K   51  
ASP-based forum for your website.
<%
'Blockquote identifies a quotations
'class SmartLink is used to show visited/new forums and topics
%>
<STYLE>
BLOCKQUOTE{
	font-size: xx-small;
	margin: 20px;
}
A.SmartLink{
	font-weight: bold;
}
A.SmartLink:visited{
	font-weight: normal;
}
</STYLE>
<%
	'database connection string
	Const ConnString = "DSN=MyDB"
	
	'colors for columns headers
	Const HeadCellColor = "#333333"'"#6666cc"
	Const HeadFontColor = "wheat"'"#99ccff"
	
	'color for category and table background
	Const CategoryCellColor = "#666666"'"#333399"
	Const CategoryFontColor = "wheat"
	
	'colors for rest of forum
	Const ForumCellColor = "white"
	Const ForumCellAltColor = "#dcdcdc"
	Const ForumFontColor = "black"
	
	'check for bad words? And what they are?
	Const BadWordsFilter = True
	Const BadWords = "fuck|suck|shit|wank"
	
	'smilies settings
	Const UseSmiles = True
	'smilies images, code and descriptions. "|" is used as a delimiter, 
	'so be sure not to use itself
	Const SmiliesImages = "smile.gif|biggrin.gif|confused.gif|cool.gif|frown.gif|mad.gif|ooo.gif|rolleyes.gif|tongue.gif|wink.gif"
	Const SmiliesTypes = ":)|:-D|:confused:|:cool:|:(|:mad:|:-o|:rolleyes:|:-p|;)"
	Const SmiliesDescriptions = "Smile|Big Grin|Confused|Cool|Frown|Mad|Ooo|Rolleyes|Tongue|Wink"
	
	
	Const AllowAnonymous = True			'allow anonymous posts?
'	Const AnonymousUserName = "Unregistered User"	'default name for anonymous posters
	Const HighlightRows = True			'use mouse over for forums names?
	Const AllowHTMLLevel = 0			'0 - No HTML, 1 - Restrict some tags, 2 - Allow ALL html code
	Const RestrictedTags = "SCRIPT|IFRAME|EMBED|FRAME"	'in case AllowHTMLLevel = 1, restricted tags will be taken from here
	Const AllowPseudoCode = True		'Use pseudo-code?
	
	Const ForumName = "StP Forums"		'Forum names
	
	'******************************
	'* Files and directories
	Const ImagesDir = "../images/"		'images directory, relative to forums dir
	Const ForumFile = "default.asp"		'main forum page
	Const MembersFile = "members.asp"	'members page
	Const AdminFile = "admin.asp"		'administration page
	Const EmailFile = "mail.asp"		'send e-mail page
	Const PostFile = "post.asp"			'new post/topic page
	Const LoginFile = "login.asp"		'login page
	Const ProfileFile = "profile.asp"	'profile/register page
	Const SearchFile = "search.asp"		'search form and results
	
	'buttons-images. Leave blank if you want to use text links.
	Const NewTopicImage = ""
	Const ReplyImage = ""
	Const LoginImage = ""
	Const RegisterImage = ""
	Const ProfileImage = ""
	Const SearchImage = ""
	
	'images for messages and topics
	Const MessageImages = "icon1.gif|icon2.gif|icon3.gif|icon4.gif|icon5.gif|icon6.gif"
	
	'Session variables
	Const USER_LEVEL = "STPLevel"	'User level is stored here. 0 - Regular User, 2 - Moderator, 3 - Administrator
	Const USER_NAME = "STPName"		'User name (not e-mail)
	
	'*************************************
	'* fields definitions
	' In case you are adding fields in database BETWEEN existing fields, you need to edit this
	'definition. All fields in recordset accessed by ordinal number and not by name, to increase
	'database processing speed. But this is NOT says that u can change the names of fields
	'in tables. Names also used in SQL queries, so don't change them
	
	'#ForumT table
	Const FORUM_ID = 0
	Const F_NAME = 1
	Const F_DESCRIPTION = 2
	Const F_CAT = 3
	Const F_POSTS = 4
	Const F_TOPICS = 5
	Const F_LASTPOST = 6
	Const F_LASTPOSTER = 7
	Const F_MODERATOR = 8
	Const F_DATE = 9
	Const F_STATUS = 10
	
	'#CategoryT table
	Const CAT_ID = 0
	Const CAT_NAME = 1
	Const CAT_DATE = 2
	
	'#TopicsT Table
	Const TOPIC_ID = 0
	Const T_FORUM_ID = 1
	Const T_SUBJECT = 2
	Const T_MESSAGE = 3
	Const T_ORIGINATOR = 4
	Const T_REPLIES = 5
	Const T_LASTPOST = 6
	Const T_STATUS = 7
	Const T_DATE = 8
	Const T_MAIL = 9
	Const T_VIEWS = 10
	Const T_LASTPOSTER = 11
	Const T_IMAGE = 12
	
	'#ReplyT table
	Const REPLY_ID = 0
	Const R_TOPIC_ID= 1
	Const R_POSTED_BY = 2
	Const R_MESSAGE = 3
	Const R_DATE = 4
	Const R_SUBJECT = 5
	Const R_IMAGE = 6
	
	'#UsersT Table
	Const USER_ID = 0
	Const U_EMAIL = 1
	Const U_NAME = 2
	Const U_PASSWORD = 3
	Const U_SIGNATURE = 4
	Const U_LEVEL = 5
	Const U_ICQ = 6
	Const U_COUNTRY = 7
	Const U_HOMEPAGE = 8
	Const U_POSTS = 9
	Const U_DATE_REGISTERED = 10
	Const U_LAST_VISIT = 11
	
%>
<SCRIPT language=VBScript RUNAT=Server>	
	'************************Classes and Functions******************'
	'Formats a message before displaying it
	Function FormatText(Text)
		dim retval, regEx, oMatches, oMatch, iEnd, strBuf, iStart, sTemp, i
		retval = Text
		Set regEx = new RegExp
		regEx.IgnoreCase = True
		regEx.Global = True
		
		'replace HTML code
		Select Case AllowHTMLLevel
		Case 0
			retval = Replace(retval, "<", "&lt;")
			retval = Replace(retval, ">", "&gt;")
		Case 1
			regEx.Pattern = "<\s*(" & RestrictedTags & ")\b>"
			retval = regEx.Replace(retval, " ")
		End Select
		
		'replace bad words
		if BadWordsFilter then
			regEx.Pattern = "(" & BadWords & ")"
			retval = regEx.Replace(retval, "****")
		end if
		
		'replace pseudo-code
		'simple PCode should be replaced first!
		if AllowPseudoCode then
			retval = ReplacePCode(retval, "[b]", "[/b]", "<B>$1</B>")
			retval = ReplacePCode(retval, "[u]", "[/u]", "<U>$1</U>")
			retval = ReplacePCode(retval, "[i]", "[/i]", "<I>$1</I>")
			retval = ReplacePCode(retval, "[s]", "[/s]", "<S>$1</S>")
			retval = ReplacePCode(retval, "[center]", "[/center]", "<P align=center>$1</P>")
			retval = ReplacePCode(retval, "[right]", "[/right]", "<P align=right>$1</P>")
			retval = ReplacePCode(retval, "[quote]", "[/quote]", "<BLOCKQUOTE>$1</BLOCKQUOTE>")

			retval = ReplacePCode(retval, "[color=(.+)]", "[/color]", "<FONT color=$1>$2</FONT>")
			retval = ReplacePCode(retval, "[url=(.+)]", "[/url]", "<A href=""$1"">$2</A>")
			retval = ReplacePCode(retval, "[size=(.+)]", "[/size]", "<FONT size=$1>$2</FONT>")
			retval = ReplacePCode(retval, "[mail=(.+)]", "[/mail]", "<A href=""mailto:$1"">$2</A>")
		end if
		
		'replace carriage returns
		retval = Replace(retval, vbCrLf, "<BR>")
		
		'replace smilies
		if UseSmiles then
			dim ar1, ar2
			ar1 = Split(SmiliesTypes, "|", -1, 0)
			ar2 = Split(SmiliesImages, "|", -1, 0)
			for i=0 to UBound(ar1)
				retval = Replace(retval, ar1(i), "<IMG src=""" & ImagesDir & ar2(i) & """ border=0>")
			Next
		End If
		
		FormatText = retval
		set regEx = nothing
	End Function
	
	Function ReplacePCode(sText, sPOpen, sPClose, sHCode)
		dim regEx
		set regEx = new RegExp
		regEx.IgnoreCase = True
		regEx.Global = True	'(.*|\n*)
		regEx.Pattern = Replace(Replace(sPOpen, "[", "\["), "]", "\]") & "(.*|\n*)" &_
						Replace(Replace(sPClose, "[", "\["), "]", "\]")
		ReplacePCode = regEx.Replace(sText, sHCode)
		set regEx = nothing
	End Function
	
	Function Date2Number(d)
		On Error Resume Next
		d = CDate(d)
		if Err then d = Now
		On Error Goto 0
		Date2Number = Day(d) & Month(d) & Year(d) & Hour(d) & Minute(d) & Second(d)
	End Function
	
	'Mail client class. E-mail sends using CDO.Message, if you want to use another component,
	'you should edit this class
	Class MailClient
	
		Private	oMail
		Public Recipient, From, HTMLBody, Subject
		
		Private Sub Class_Initialize()
			set oMail = Server.CreateObject("CDO.Message")
		End Sub
		Private Sub Class_Terminate
			set oMail = nothing
		End Sub
		
		Public Sub Send
			oMail.To = Recipient
			oMail.Subject = Subject
			oMail.From = "noreply@saintopatrick.com"
			oMail.HTMLBody = HTMLBody
			oMail.ReplyTo = From
			oMail.Send 
		End Sub
	End Class
</SCRIPT>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Team Leader Varonis
Israel Israel
I was born in small town Penza, Russia, in October 13th, 1975 yr. So my mother tongue is Russian. I finished the school there and learned in University, then I came to Israel and since then, I live there (or here *s*)
My profession is a C++ programmer under MS Windows platforms, but my hobby is Web development and ASP programming.

I started interesting in computers and programming somewere in 1990-1991 yrs., when my father brought home our first computer - Sinclair ZX Spectrum (he made it by himself). So I learned Basic and joined the Basic programmers club at my school (me and my friend were the only 2 guys from all school there, lol). After I finished the school (1992yr) I decided to continue my study at University and got specialization Operation Systems and Software Engineer. Although I still like my profession, but I always wanted something new, thus I learned HTML, Javascript and ASP which turned to be my hobby Smile | :)

Comments and Discussions