Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Help Groups for Snitz Forums 2000 Users
 Help: General / Classic ASP versions(v3.4.XX)
 Need Help with ReplaceURLs( )
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

garyrobar
New Member

Canada
90 Posts

Posted - 15 June 2007 :  00:18:13  Show Profile  Visit garyrobar's Homepage
Hello,

I am hoping someone can help me sort out a little of the code in the function
ReplaceURLs(ByVal strToFormat)
(in inc_func_common.asp)

My goal is to have url's posted by admin (mlev=4) post as normal, then any urls posted by mlev < 4 have the rel="nofollow" ONLY if they are external.

I've been able to work through the logic...its actually quite simple...

I actually do the work on the delcarations for:

roTag = "<a href="""
roTag = "<a href="""	
rc1Tag = """ target=""_blank"">"
rc2Tag = "</a>"


Basically, here is the logic for the first issue...am I an admin?...


if mlev = 4 then
	roTag = "<a href="""
else
	roTag = "<a rel=""nofollow"" href="""	
end if
rc1Tag = """ target=""_blank"">"
rc2Tag = "</a>"


Now THIS i have been able to successfully implement.

NEXT, I tried to implement the next if statement down further...


if instr(0,strArray2(0),"mydomain.com",0) = 0 then
	roTag = "<a rel=""nofollow"" href="""	
else
	roTag = "<a href="""	
end if


THis, however, causes problems...and causes the function not to work at all... The hard bb code just posts as-is. When I remove this if stmt, the prob goes away.

Anyone see the issue? Am I testing the correct statement here?

SEO For Snitz Forum

garyrobar
New Member

Canada
90 Posts

Posted - 15 June 2007 :  00:50:27  Show Profile  Visit garyrobar's Homepage
Alright, so i've finally figured it out. I've actually done it correctly, but there was a syntax error in my instr() function. Here is the completed function that will insert a rel="nofollow" if the user is less than admin, and the link is outside of the forum domain...


Function ReplaceURLs(ByVal strToFormat)
	Dim oTag, c1Tag, oTag2, c2Tag
	Dim roTag, rc1Tag, rc2Tag
	Dim oTagPos, c1TagPos, oTagPos2, c1TagPos2
	Dim Counter
	Dim strArray, strArray2
	Dim strFirstPart, strSecondPart
	dim ourUrl
	
	ourUrl = "billiardsforum.info"

	oTag = "[url="""
	c1Tag = """]"
	oTag2 = "[url]"
	c2Tag = "[/url]"
	
	if mlev = 4 then
		roTag = "<a href="""
	else
		roTag = "<a rel=""nofollow"" href="""	
		roTagInternal = "<a href="""	
	end if
	rc1Tag = """ target=""_blank"">"
	rc2Tag = "</a>"

	oTagPos = InStr(1, strToFormat, oTag, 1) 'Position of opening tag
	c1TagPos = InStr(1, strToFormat, c1Tag, 1) 'Position of closing tag

	'if opening tag and closing tag is found...
	If (oTagpos > 0) And (c1TagPos > 0) Then
		'Split string at the opening tag
		strArray = Split(strToFormat, oTag, -1, 1)
		
		'Loop through array
		For Counter = 0 To UBound(strArray)
			'if the closing tag is found in the string then...
			If (InStr(1, strArray(Counter), c1Tag, 1) > 0) Then
				'split string at the closing tag...
				strArray2 = Split(strArray(Counter), c1Tag, -1, 1)

				strArray2(0) = replace(strArray2(0), """", " ") ' ## filter out "
				strArray2(0) = replace(strArray2(0), ";", " ", 1, -1, 1) ' ## filter out ;
				strArray2(0) = replace(strArray2(0), "+", " ", 1, -1, 1) ' ## filter out +
				strArray2(0) = replace(strArray2(0), "(", " ", 1, -1, 1) ' ## filter out (
				strArray2(0) = replace(strArray2(0), ")", " ", 1, -1, 1) ' ## filter out )
				strArray2(0) = replace(strArray2(0), "*", " ", 1, -1, 1) ' ## filter out *
				strArray2(0) = replace(strArray2(0), "'", " ", 1, -1, 1) ' ## filter out '
				strArray2(0) = replace(strArray2(0), ">", " ", 1, -1, 1) ' ## filter out >
				strArray2(0) = replace(strArray2(0), "<", " ", 1, -1, 1) ' ## filter out <
				strArray2(0) = replace(strArray2(0), vbTab, " ", 1, -1, 1) ' ## filter out Tabs
				strArray2(0) = replace(strArray2(0), "view-source", " ", 1, -1, 1) ' ## filter out view-source
				strArray2(0) = replace(strArray2(0), "javascript", " ", 1, -1, 1) ' ## filter out javascript
				strArray2(0) = replace(strArray2(0), "jscript", " ", 1, -1, 1) ' ## filter out jscript
				strArray2(0) = replace(strArray2(0), "vbscript", " ", 1, -1, 1) ' ## filter out vbscript

				'if the closing url tag is found in the string and [URL] is not found in the string then...
				If InStr(1, strArray2(1), c2Tag, 1) And _
					Not InStr(1, UCase(strArray2(1)), "[URL]", 1) Then

					strFirstPart = Left(strArray2(1), InStr(1, strArray2(1), c2Tag, 1)-1)
					strSecondPart = Right(strArray2(1), (Len(strArray2(1)) - Instr(1, strArray2(1), c2Tag,1) - len(c2Tag)+1))
					
					If strFirstPart <> "" Then
						if mlev < 4 then
							if inStr(1,strArray2(0),ourUrl,1) = 0 then
								roTag = "<a rel=""nofollow"" href="""	
							else
								roTag = "<a href="""
							end if
						end if					
						If UCase(Left(strFirstPart, 5)) = "[IMG]" Then
							ReplaceURLs = ReplaceURLs & "<a href=""" & strArray2(0) & """ target=""_blank"">" & strFirstPart & "</a>" & strSecondPart
						ElseIf UCase(Left(strArray2(0), 7)) = "http://" Then
							ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf UCase(Left(strArray2(0), 8)) = "https://" Then
							ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf UCase(Left(strArray2(0), 4)) = "WWW." Then
							ReplaceURLs = ReplaceURLs & roTag & "http://" & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf UCase(Left(strArray2(0), 7)) = "MAILTO:" Then
							ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf UCase(Left(strArray2(0), 6)) = "ftp://" Then
							ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf InStr(strArray2(0), "@") > 0 Then
							ReplaceURLs = ReplaceURLs & roTag & "mailto:" & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf UCase(Left(strArray2(0), 6)) = "file:///" Then
							ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						Else
							ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						End If
					Else
						if mlev < 4 then
							if inStr(1,strArray2(0),ourUrl,1) = 0 then
								roTag = "<a rel=""nofollow"" href="""	
							else
								roTag = "<a href="""
							end if
						end if					
						If UCase(Left(strArray2(0), 7)) = "http://" Then
							ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 1) & strSecondPart
							'ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf UCase(Left(strArray2(0), 8)) = "https://" Then
							ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 2) & strSecondPart
							'ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf UCase(Left(strArray2(0), 4)) = "WWW." Then
							ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 3) & strSecondPart
							'ReplaceURLs = ReplaceURLs & roTag & "http://" & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf UCase(Left(strArray2(0), 7)) = "MAILTO:" Then
							ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 4) & strSecondPart
							'ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf UCase(Left(strArray2(0), 6)) = "ftp://" Then
							ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 5) & strSecondPart
							'ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf InStr(strArray2(0), "@") > 0 Then
							ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 4) & strSecondPart
							'ReplaceURLs = ReplaceURLs & roTag & "mailto:" & strArray2(0) & rc1Tag & strFirstPart & rc2Tag & strSecondPart
						ElseIf UCase(Left(strArray2(0), 6)) = "file:///" Then
							ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strArray2(0) & rc2Tag & strSecondPart
						Else
							ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strArray2(0) & rc2Tag & strSecondPart
						End If
					End If
				Else
					ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strArray2(0) & rc2Tag & strArray2(1)
				End If
			Else
				ReplaceURLs = ReplaceURLs & strArray(Counter)
			End If
		Next
	Else
		ReplaceURLs = strToFormat
	End If
	
	oTagPos2 = InStr(1, ReplaceURLs, oTag2, 1)
	c1TagPos2 = InStr(1, ReplaceURLs, c2Tag, 1)

	'if opening tag and closing tag is found then...
	If (oTagpos2 > 0) And (c1TagPos2 > 0) Then
		'split string at opening tag
		strArray = Split(ReplaceURLs, oTag2, -1, 1)

		ReplaceURLs = ""
		For Counter = 0 To Ubound(strArray)
			'if closing url tag is found in string then...
			If InStr(1, strArray(Counter), c2Tag, 1) > 0 Then
				'split string at closing url tag
				strArray2 = Split(strArray(Counter), c2Tag, -1, 1)
				
				strArray2(0) = replace(strArray2(0), """", " ") ' ## filter out "
				strArray2(0) = replace(strArray2(0), ";", " ", 1, -1, 1) ' ## filter out ;
				strArray2(0) = replace(strArray2(0), "+", " ", 1, -1, 1) ' ## filter out +
				strArray2(0) = replace(strArray2(0), "(", " ", 1, -1, 1) ' ## filter out (
				strArray2(0) = replace(strArray2(0), ")", " ", 1, -1, 1) ' ## filter out )
				strArray2(0) = replace(strArray2(0), "*", " ", 1, -1, 1) ' ## filter out *
				strArray2(0) = replace(strArray2(0), "'", " ", 1, -1, 1) ' ## filter out '
				strArray2(0) = replace(strArray2(0), ">", " ", 1, -1, 1) ' ## filter out >
				strArray2(0) = replace(strArray2(0), "<", " ", 1, -1, 1) ' ## filter out <
				strArray2(0) = replace(strArray2(0), vbTab, " ", 1, -1, 1) ' ## filter out Tabs
				strArray2(0) = replace(strArray2(0), "view-source", " ", 1, -1, 1) ' ## filter out view-source
				strArray2(0) = replace(strArray2(0), "javascript", " ", 1, -1, 1) ' ## filter out javascript
				strArray2(0) = replace(strArray2(0), "jscript", " ", 1, -1, 1) ' ## filter out jscript
				strArray2(0) = replace(strArray2(0), "vbscript", " ", 1, -1, 1) ' ## filter out vbscript
				
				if mlev < 4 then
					if inStr(1,strArray2(0),ourUrl,1) = 0 then
						roTag = "<a rel=""nofollow"" href="""	
					else
						roTag = "<a href="""
					end if
				end if
				
				If UCase(Left(strArray2(0), 7)) = "http://" Then
					ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 1) & strArray2(1)
				ElseIf UCase(Left(strArray2(0), 8)) = "https://" Then
					ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 2) & strArray2(1)
				ElseIf UCase(Left(strArray2(0), 4)) = "WWW." Then
					ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 3) & strArray2(1)
				ElseIf UCase(Left(strArray2(0), 7)) = "MAILTO:" Then
					'ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 4) & strArray2(1)
					ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strArray2(0) & rc2Tag & strArray2(1)
				ElseIf UCase(Left(strArray2(0), 6)) = "ftp://" Then
					ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 5) & strArray2(1)
				ElseIf InStr(strArray2(0), "@") > 0 Then
					ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 4) & strArray2(1)
				ElseIf UCase(Left(strArray2(0), 6)) = "file:///" Then
					ReplaceURLs = ReplaceURLs & edit_hrefs(strArray2(0), 7) & strArray2(1)
				Else
					ReplaceURLs = ReplaceURLs & roTag & strArray2(0) & rc1Tag & strArray2(0) & rc2Tag & strArray2(1)
				End If
			Else
				ReplaceURLs = ReplaceURLs & strArray(Counter)
			End If
		Next
	End If
End Function
<edited by="Shaggy" to="prevent forum code from parsing" />

SEO For Snitz Forum

Edited by - Shaggy on 15 June 2007 03:56:44
Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 15 June 2007 :  03:58:34  Show Profile
That will only insert the rel attribute if the person viewing the post is not an admin not if the person who posted the link is not an admin.


Search is your friend
“I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Go to Top of Page

garyrobar
New Member

Canada
90 Posts

Posted - 15 June 2007 :  09:19:01  Show Profile  Visit garyrobar's Homepage
ahhh, back to the drawing board...don't know how I could have missed that. Does anyone have any ideas for this?

SEO For Snitz Forum

Edited by - garyrobar on 15 June 2007 09:27:03
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.3 seconds. Powered By: Snitz Forums 2000 Version 3.4.07