Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/Code)
 Job to grab X number recent posts and put in UL

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!
Before posting, make sure you have read this topic!

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
garyrobar Posted - 24 January 2007 : 11:29:18
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
%>
15   L A T E S T    R E P L I E S    (Newest First)
runsh Posted - 30 January 2007 : 00:29:36
great mod.
thanks<
garyrobar Posted - 29 January 2007 : 21:17:38
Yes, it is. We just need to do two things:

1 - Add a variable called "displayCat" and set it equal to the category ID of the category you want to display.
2 - Find the "WHERE" clause:


if displayforum <> 111111 then
strSql = strSql & " WHERE T.T_STATUS < 2"
strSql = strSql & " AND F.FORUM_ID = " & displayForum & " ORDER BY T.T_LAST_POST DESC"
else
strSql = strSql & " WHERE T.T_STATUS < 2 ORDER BY T.T_LAST_POST DESC"
end if


...and change it to


if displayforum <> 111111 then
strSql = strSql & " WHERE T.T_STATUS < 2"
strSql = strSql & " AND F.CAT_ID = " & displayCat & " ORDER BY T.T_LAST_POST DESC"
else
strSql = strSql & " WHERE T.T_STATUS < 2 ORDER BY T.T_LAST_POST DESC"
end if


SQL is actually quite logical. The "WHERE" clause just helps you narrow down the chink of records you are grabbing from the database. SO, if you only want records from say, category ID 7, the SQL essentially says:

"get me (select) all records from the certain tables that have the data I need, and only get me records WHERE some condition is true. (cat_id = 7)"

Hope this helps.<
runsh Posted - 29 January 2007 : 19:13:56
thanks for changing it. works great. I was wondering if is possible to change it bit more so to allow category (all forums in cat. to display).
<
garyrobar Posted - 29 January 2007 : 11:03:23
okay so make these adjustments to display only posts from ONE forum...

Change this...

intResults = 10
intAge = 30
lastDate = DateToStr(DateAdd("d",-(intAge),Now()))
strMethod = "last_post"
subjectlength = 122
subjectlengthe = 60
intPage = 1


to this...

intResults = 10
intAge = 30
lastDate = DateToStr(DateAdd("d",-(intAge),Now()))
strMethod = "last_post"
subjectlength = 122
subjectlengthe = 60
intPage = 1
displayForum = 26 'enter the FORUM_ID, put 111111 for display all.


and then change the SQL statements from this...


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"


to this...


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"

if displayforum <> 111111 then
strSql = strSql & " WHERE T.T_STATUS < 2"
strSql = strSql & " AND F.FORUM_ID = " & displayForum & " ORDER BY T.T_LAST_POST DESC"
else
strSql = strSql & " WHERE T.T_STATUS < 2 ORDER BY T.T_LAST_POST DESC"
end if
<
JJenson Posted - 27 January 2007 : 21:18:06
Not really no I am just now starting to expand my knowledge in these areas. Maybe give me an example and I should be able to take it from there? Thanks<
garyrobar Posted - 27 January 2007 : 21:15:15
actuallly, you should change the SQL statement to only grab from records of a certain forum id- are you familliar with SQL?<
JJenson Posted - 27 January 2007 : 19:44:15
Yeah figured it was something like that. Now I know you didn't make it this way but h ow hard would it be to convert to only topics from a certain forum get posted? I was trying to do this and changed the url and that didn't work and figured it owuld be a little more difficult than with my knowledge. But I will take a stab at it.<
garyrobar Posted - 27 January 2007 : 14:21:51
Glad you like!

Option Explicit isn't really needed.

It just forces you to code properly. if you have any undeclared variables anywehre on the page you are executing, you'll get errors with option explicit.<
JJenson Posted - 27 January 2007 : 11:47:53
Looks good gary, One thing to make it work on my site I had to remove the option explicit on the top. Now everything works just as it should. I don't think its needed but i could be wrong.

<
garyrobar Posted - 26 January 2007 : 22:02:44
the file you just downloaded is a separate version. The folks who posted earlier wanted one that you didn't have to update manually. So, just download that most recent one a few posts up, and make the changes. Then use a server side include wehreever you wanted the list to appear. no need to do anything else.<
MrsJJenson Posted - 26 January 2007 : 18:21:21
k, so i downloaded the file from above and created the blank
inc_forumrecentpost.asp. Then i changed the files paths in line
5&6 and changed the url path on line 76. then I uploaded the two
files to my site and where I want the recent posts to show on my homepage they are not showing.
<!-- INCLUDE FILE=forum/inc_forumrecentpost.asp --> this needs to be
where I want the recent posts to show, correct? What else do I need to do to fix this?<
garyrobar Posted - 26 January 2007 : 18:09:53
quote:
Originally posted by MrsJJenson

Is any coding suppose to go in the inc_forumrecentpost.asp? I don't see any new posts on my homepage where I would like it to show. What did i do wrong or need to do?





Just download the file from my recent post (3 posts above) and use that one instead. Its dynamic, and you just include it where you want to show the list.<
runsh Posted - 26 January 2007 : 11:00:33
looks good.
thanks<
AnonJr Posted - 26 January 2007 : 06:14:47
Cool.<
garyrobar Posted - 26 January 2007 : 05:31:33
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.<

Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000 Version 3.4.07