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

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/Code)
 Job to grab X number recent posts and put in UL
 New Topic  Reply to Topic
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

garyrobar
New Member

Canada
90 Posts

Posted - 24 January 2007 :  11:29:18  Show Profile  Visit garyrobar's Homepage  Reply with Quote
Description: Use this to show recent forum topics in a list on other non-forum areas of your website. This helps "grab" users from other areas of your site and bring them to the forum.

I made this code to grab a specified number of the most recent active posts. It puts the info in to a file as an unordered list. It creates and writes an html file with the info, so that every pagevew isn't grabbing information from the db. You could set this as a job to run every X hours/minutes/days whatever.

It also scrubs all formatting out of the post, so that it displays normally. It converts all tags back to html, then uses a regular expression to get rid of all tags.

You can specify the length of the subject and description.

I'm sorry I don't have time to make it more easy to implement, but thought i'd share what i have so far.

You may just need to adjust the pathway to some of the included files, and you'll also have to adjust the path and filename of where you'll want to write the list to. Remember, you'll need write permissions on the directory that you choose to write the file to.

Any improvements or changes are welcomed, and I hope this helps someone out.

<b>FYI - Since some of the code isn't showing properly here because of formatting rules, i've zipped up the file for download:</b>

generate_recent_posts.rar
recent-post-dynamic.rar (Dynamic Version)

<!--#INCLUDE FILE="../../forum/config.asp"-->
<!--#INCLUDE FILE="../../forum/inc_func_common.asp"-->
<%
set my_Conn = Server.CreateObject("ADODB.Connection")
my_Conn.Open strConnString

intResults = 10 '#of results to show
intAge = 30 'age in days of topics to look through
lastDate = DateToStr(DateAdd("d",-(intAge),Now())) 'leave this alone
strMethod = "last_post"
subjectlength = 122 'length in characters of the subject line
subjectlengthe = 60 'length in characters of the description line
intPage = 1 'leave alone


strSql = "SELECT F.F_SUBJECT, T.TOPIC_ID, T.T_AUTHOR, T.T_SUBJECT, T.T_MESSAGE"
strSql = strSql & ", T.T_LAST_POST, T.T_LAST_POST_REPLY_ID, T.T_REPLIES, T.T_DATE, M.M_NAME"
strSql = strSql & ", MEMBERS_1.M_NAME AS LAST_POST_AUTHOR_NAME"
strSql = strSql & " FROM ((" & strTablePrefix & "FORUM F LEFT JOIN " & strTablePrefix & "TOPICS T"
strSql = strSql & " ON F.FORUM_ID = T.FORUM_ID) LEFT JOIN " & strMemberTablePrefix & "MEMBERS M"
strSql = strSql & " ON T.T_AUTHOR = M.MEMBER_ID) LEFT JOIN " & strMemberTablePrefix & "MEMBERS MEMBERS_1"
strSql = strSql & " ON T.T_LAST_POST_AUTHOR = MEMBERS_1.MEMBER_ID"
strSql = strSql & " WHERE T.T_STATUS < 2 ORDER BY T.T_LAST_POST DESC"



'-----------------------------------------end the getting of the data------------------


Set getForumRecentPostsFSO = Server.CreateObject("Scripting.FileSystemObject")
getForumRecentPostsFSO.DeleteFile "E:\path\path\path\path\path\dev\bfadmin\write\inc_forumrecentposts.asp" 'delete old one
Set getForumRecentPostsFile = getForumRecentPostsFSO.CreateTextFile("E:\path\path\path\path\path\dev\bfadmin\write\inc_forumrecentposts.asp", True) 'create new one
getForumRecentPostsFile.WriteLine("<ul class=""ulnav"">")


set objRs = my_Conn.execute(TopSQL(strSql,intResults))

do until objRs.eof

 intID = objRs("TOPIC_ID")
 strSubject = ChkString(objRs("T_SUBJECT"),"display")

 if Len(strSubject) > (subjectlength - 1) then
  strSubject = mid(strSubject,1,subjectlength) & "..."
 end if
 
 strTopicPart = ChkString(objRs("T_MESSAGE"),"display")
 strFSubject = ChkString(objRs("F_SUBJECT"),"display")


 strTopicPart = replace(strTopicPart, "<b>", "<b>") 'replace <b> open
 strTopicPart = replace(strTopicPart, "</b>", "</b>") 'replace </b> close
 strTopicPart = replace(strTopicPart, "<u>", "<u>") 'replace <u> open
 strTopicPart = replace(strTopicPart, "</u>", "</u>") 'replace </u> close
 strTopicPart = replace(strTopicPart, "<i>", "<i>") 'replace <i> open
 strTopicPart = replace(strTopicPart, "</i>", "</i>") 'replace </i> close 
 strTopicPart = replace(strTopicPart, " ,     />     replace close of img tag br /  strTopicPart = replace strTopicPart,  " target="_blank"> ,  < a href=      replace url open br /  strTopicPart = replace strTopicPart,  [/url] ,  < /a>     replace close of /a tag br /  strTopicPart = replace strTopicPart,   ,     />     replace close of img tag br /  strTopicPart = replace strTopicPart,  ", """>") 'replace url end enclosure
 strTopicPart = replace(strTopicPart, "<font", "<font ") 'replace font tag and comment out
 strTopicPart = replace(strTopicPart, "</font", "</font>< ") 'replace font tag and comment out
 strTopicPart = replace(strTopicPart, "">", " "">") 'replace font tag and comment out
 strTopicPart = replace(strTopicPart, "<ul>", "<ul>") 'replace font tag and comment out
 strTopicPart = replace(strTopicPart, "</ul>", "</ul>") 'replace font tag and comment out
 strTopicPart = replace(strTopicPart, "<li>", "<li>") 'replace font tag and comment out
 strTopicPart = replace(strTopicPart, "</li>", "</li>") 'replace font tag and comment out

'bust out the rgex here, and get rid of all tags.

 strTopicPart = removeHTML(strTopicPart)

'end regex bust out.

 strTopicPart = replace(strTopicPart, """, """") 'replace ascii quote with straight quote.

 'pear down the length of the description now that code has been cleaned.
 if Len(strTopicPart) > (subjectlengthe - 1) then
  strTopicPart = mid(strTopicPart,1,subjectlengthe) & "..."
 end if 
 
getForumRecentPostsFile.WriteLine("<li>")
getForumRecentPostsFile.WriteLine("<a href=""http://www.site.com/forum/topic.asp?TOPIC_ID=" & intID & "&whichpage=" & intPage & """ title=""" & strSubject & """>" & strSubject & "</a> - " & strTopicPart  & "") 
getForumRecentPostsFile.WriteLine("</li>")
 
 objRs.MoveNext
loop
  
getForumRecentPostsFile.WriteLine("</ul>")
  
'this is the function that removes the html from the post 
Function RemoveHTML( strText )
 Dim RegEx

 Set RegEx = New RegExp

 RegEx.Pattern = "<[^>]*>"
 RegEx.Global = True

 RemoveHTML = RegEx.Replace(strText, "")
End Function  

objRs.close
set objRs = nothing
my_conn.close
set my_Conn = nothing
getForumRecentPostsFile.close
set getForumRecentPostsFSO = nothing
set getForumRecentPostsFile = nothing
%>

SEO For Snitz Forum

Edited by - garyrobar on 26 January 2007 05:33:28

JJenson
Advanced Member

USA
2121 Posts

Posted - 24 January 2007 :  11:33:58  Show Profile  Visit JJenson's Homepage  Reply with Quote
Will try and implement this later looks like a nice add on though. <
Go to Top of Page

garyrobar
New Member

Canada
90 Posts

Posted - 24 January 2007 :  12:09:16  Show Profile  Visit garyrobar's Homepage  Reply with Quote
Thanks. I've added a zip of the file, since the post seems to be alterning some of the code due to formatting rules.<

SEO For Snitz Forum
Go to Top of Page

runsh
Starting Member

34 Posts

Posted - 24 January 2007 :  15:58:40  Show Profile  Visit runsh's Homepage  Reply with Quote
Thanks for the mod
I am getting this error

Microsoft VBScript runtime error '800a0035'
File not found

/generate_recent_posts.asp, line 31


line 31 getForumRecentPostsFSO.DeleteFile "E:\path\path\path\path\path\dev\bfadmin\write\inc_forumrecentposts.asp" 'delete old one
<
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 24 January 2007 :  16:23:40  Show Profile  Visit JJenson's Homepage  Reply with Quote
Just to make sure did you edit that line to point to where you are trying to generate recent post. Or where you put this file?<
Go to Top of Page

runsh
Starting Member

34 Posts

Posted - 24 January 2007 :  17:05:43  Show Profile  Visit runsh's Homepage  Reply with Quote
I did change it but was not sure if I was doing it right. should the path be same as path to database?
do we have to make inc_forumrecentposts.asp? where should be placed? etc...
little confusing!
some instruction would be nice on what needs to be done to make it work.
thanks<
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 24 January 2007 :  18:12:08  Show Profile  Visit JJenson's Homepage  Reply with Quote
Not sure I cannot get to download the file. He said there is some code missing from the text. So I will see when I can get the code what needs to be done.<
Go to Top of Page

garyrobar
New Member

Canada
90 Posts

Posted - 25 January 2007 :  10:45:18  Show Profile  Visit garyrobar's Homepage  Reply with Quote
you have to create an empty (inc_forumrecentposts.asp) file for the first execution.

Sorry, i forgot to mention that :)<

SEO For Snitz Forum
Go to Top of Page

runsh
Starting Member

34 Posts

Posted - 25 January 2007 :  10:50:05  Show Profile  Visit runsh's Homepage  Reply with Quote
Well I got it to work. is very nice (so far).
to install:
1. download the page form link above.
2. make changes t line 31 and 32 according to your path.
3. make a page called inc_forumrecentposts.asp
4. upload both pages and you can included in almost anypage.
again thanks for the mod is pretty good<
Go to Top of Page

runsh
Starting Member

34 Posts

Posted - 25 January 2007 :  10:52:25  Show Profile  Visit runsh's Homepage  Reply with Quote
also change this line to your website and at end of page redirect line.
getForumRecentPostsFile.WriteLine("<a href=""http://www.site.com/forum/topic.asp?TOPIC_ID=" & intID & "&whichpage=" & intPage & """ title=""" & strSubject & """>" & strSubject & "</a> - " & strTopicPart & "")
<
Go to Top of Page

runsh
Starting Member

34 Posts

Posted - 25 January 2007 :  13:24:28  Show Profile  Visit runsh's Homepage  Reply with Quote
Is there a way to have one for each forum?<
Go to Top of Page

runsh
Starting Member

34 Posts

Posted - 25 January 2007 :  16:47:23  Show Profile  Visit runsh's Homepage  Reply with Quote
list is not updating new post<
Go to Top of Page

AnonJr
Moderator

United States
5768 Posts

Posted - 25 January 2007 :  17:38:08  Show Profile  Visit AnonJr's Homepage  Reply with Quote
Has the set interval passed? Based on the initial post, it looks like this script doesn't update the list immediately upon a new post, only when the interval you set passes.<
Go to Top of Page

runsh
Starting Member

34 Posts

Posted - 25 January 2007 :  21:07:18  Show Profile  Visit runsh's Homepage  Reply with Quote
do you know which part set the interval. is it possible to be set every hour or so?<
Go to Top of Page

AnonJr
Moderator

United States
5768 Posts

Posted - 25 January 2007 :  23:14:24  Show Profile  Visit AnonJr's Homepage  Reply with Quote
I couldn't tell you what part, but according to the first post its possible to set the interval for every hour.

Edit: after going back and re-reading the initial post one more time (seems to be taking my sleep-deprived mind a few times to finally sink in) - it seems that this script would be something you would have to set up as a regular job on the server.

Now, if you were really feeling froggy, you could probably code a check in inc_header to see if its been re-built within the time-frame and run this if it hasn't. I might be able to sketch out something a little more detailed tomorrow, but I make no promises.

For the record, while I am always in favor of cutting unnecessary database calls, I think this is going just a little too far in the other direction.<

Edited by - AnonJr on 25 January 2007 23:28:22
Go to Top of Page

garyrobar
New Member

Canada
90 Posts

Posted - 26 January 2007 :  05:31:33  Show Profile  Visit garyrobar's Homepage  Reply with Quote
Hello everyone,

Here is a version, exactly the same in every way, except that it is dynamic, and updates automatically. You simply use it as an include file whereever you want the list to be displayed.

recent-post-dynamic.rar

Just include it in the page,
make sure you edit lines 5 and 6 depending on where your files are in the directory.
Then edit line 76 to your own domain name

With this one, your forum's most recent posts will display always, without any manual updating.

The OTHER option is to use the original code, and include the file at the end of post.asp. That way anyone updating, posting new, or replying to a topic will cause the file to be regenerated.<

SEO For Snitz Forum

Edited by - garyrobar on 26 January 2007 05:58:48
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000 Version 3.4.07