Jump to Last Post Permalink - Posted (7746 Views)
Support Moderator
Shaggy
Posts: 6780
6780
After some recent discussions about it, I've been working on modifying the jump to last post feature so it does not need to pass the REPLY_ID through the querystring, effectively allowing you to create permanent links that will always take you to the latest post in a topic. Here's what I have so far:
Code:
if mypage=-1 then
strSql1="SELECT REPLY_ID"
strSql2=" FROM "&strActivePrefix&"REPLY "
strSql3=" WHERE TOPIC_ID="&Topic_ID
if AdminAllowed=0 then
strSql3=strSql3&" AND (R_STATUS<"
if Moderation="Y" then strSql3=strSql3&"2" else strSql3=strSql3&"3"
strSql3=strSql3&" OR R_AUTHOR="&MemberID&")"
end if
strSql4=" ORDER BY R_DATE ASC"
set rsReplies=server.createobject("ADODB.Recordset")
if strDBType="mysql" then
rsReplies.open strSql1&strSql2&strSql3&strSql4,my_Conn,adOpenStatic,adLockReadOnly,adCmdText
if rsReplies.eof then
iReplyCount=-1
strwhichpage=""
else
arrReplyData=rsReplies.getrows(adGetRowsRest)
iReplyCount=ubound(arrReplyData,2)
if len(request.querystring("REPLY_ID"))>0 then LastPostReplyID=clng(request.querystring("REPLY_ID")) else LastPostReplyID=cLng(arrReplyData(0,iReplyCount))
end if
if iReplyCount>-1 then
for iReply=0 to iReplyCount
intReplyID=arrReplyData(0,iReply)
if LastPostReplyID=intReplyID then
intPageNumber=((iReply+1)/strPageSize)
if intPageNumber>clng(intPageNumber) then intPageNumber=clng(intPageNumber)+1
strwhichpage="whichpage="&intPageNumber&"&"
exit for
end if
next
end if
else
rsReplies.cachesize=strPageSize
rsReplies.pagesize=strPageSize
rsReplies.open strSql1&strSql2&strSql3&strSql4,my_Conn,adOpenStatic,,adCmdText if len(request.querystring("REPLY_ID"))>0 then
LastPostReplyID=clng(request.querystring("REPLY_ID"))
else
rsReplies.movelast
LastPostReplyID=cLng(rsReplies("REPLY_ID"))
rsReplies.movefirst
end if
rsReplies.find="REPLY_ID="&LastPostReplyID&""
if not (rsReplies.eof or rsReplies.bof) then
if rsReplies.absolutepage>1 then strwhichpage="whichpage="&rsReplies.absolutepage&"&"
else
strwhichpage = ""
end if
end if
rsReplies.close
set rsReplies=nothing
my_Conn.close
set my_Conn=nothing
response.redirect("topic.asp?"&strwhichpage&"TOPIC_ID="&Topic_ID&"#"&LastPostReplyID&"")
response.end
end if
That replaces the if statement beginning on line 202 of a fresh, v3.4.05 topic.asp. Note that I haven't tested this yet mainly because I don't have a clean Snitz that I can test it on but also because I've already encountered a problem in that the code above will always take you to the last actual reply to a topic without taking into account any replies that may have been edited after the last actual reply. I'm about to switch over to me other job for the evening but wanted to post this here first so's ye could see where I'm going with it and maybe offer some insights as to how to get around the problem I mentioned.
<
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.”
 Sort direction, for dates DESC means newest first  
 Page size 
Posted
Senior Member
Astralis
Posts: 1218
1218
Shaggy,

I never did figure out what that green line is for, whether that is the only line that needs changed or something else.
When I looked around line 202 of topic.asp, I found the following code. Are you saying I should replace it entirely with everything you have?
Code:

if mypage = -1 and Request.QueryString("REPLY_ID") <> "" then
strSql1 = "SELECT REPLY_ID "
strSql2 = "FROM " & strActivePrefix & "REPLY "
strSql3 = "WHERE TOPIC_ID = " & Topic_ID & " "
' DEM --> if not a Moderator, all unapproved posts should not be viewed. if AdminAllowed = 0 then
strSql3 = strSql3 & "AND (R_STATUS < "
if Moderation = "Y" then
' Ignore unapproved/rejected posts
strSql3 = strSql3 & "2 "
else
' Ignore any previously rejected topic
strSql3 = strSql3 & "3 "
end if
strSql3 = strSql3 & "OR R_AUTHOR = " & MemberID & ") "
end if
strSql4 = "ORDER BY R_DATE ASC "

if strDBType = "mysql" then
set rsReplies = Server.CreateObject("ADODB.Recordset")

rsReplies.open strSql1 & strSql2 & strSql3 & strSql4, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText

if rsReplies.EOF then
iReplyCount = ""
else
arrReplyData = rsReplies.GetRows(adGetRowsRest)
iReplyCount = UBound(arrReplyData, 2)
rREPLY_ID = 0
end if

LastPostReplyID = cLng(Request.QueryString("REPLY_ID"))

if iReplyCount <> "" then
for iReply = 0 to iReplyCount
intReplyID = arrReplyData(rREPLY_ID,iReply)
if LastPostReplyID = intReplyID then
intPageNumber = ((iReply+1)/strPageSize)
if intPageNumber > cLng(intPageNumber) then
intPageNumber = cLng(intPageNumber) + 1
end if
strwhichpage = "whichpage=" & intPageNumber & "&"
exit for
end if
next
else
strwhichpage = ""
end if

rsReplies.Close
set rsReplies = nothing
else
set rsReplies = Server.CreateObject("ADODB.Recordset")
rsReplies.cachesize = strPageSize
rsReplies.pagesize = strPageSize

rsReplies.open strSql1 & strSql2 & strSql3 & strSql4, my_Conn, adOpenStatic, adLockReadOnly, adCmdText

LastPostReplyID = cLng(Request.QueryString("REPLY_ID"))
rsReplies.Find = "REPLY_ID=" & LastPostReplyID & ""

if not (rsReplies.EOF or rsReplies.BOF) then
if rsReplies.absolutepage > 1 then strwhichpage = "whichpage=" & rsReplies.absolutepage & "&"
else
strwhichpage = ""
end if

rsReplies.Close
set rsReplies = nothing
end if

Response.Redirect("topic.asp?" & strwhichpage & "TOPIC_ID=" & Topic_ID & "#" & LastPostReplyID & "")
Response.End
end if
<
Posted
Support Moderator
Shaggy
Posts: 6780
6780
Me either, but it was a while ago now wink I think Davio added that line in when adding this to the base code. But, yeah, just replace that chunk of code with mine, taking care to back up topic.asp first, just in case.
<
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.”
Posted
Senior Member
Astralis
Posts: 1218
1218
Excellent! It's working great! Thank you for helping me.
I figured that green line was probably a leftover from some other discussion.<
Posted
Support Moderator
Shaggy
Posts: 6780
6780
You're welcome, buddy smile
<
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.”
You Must enter a message