<%
Dim xobjFile, xRSS, xpp, xppp, endCount, startCount, tpages
xlink_id = "10209"
local_file = "rcxlink_" & xlink_id & ".xml"
xpp = 50
xppp = 10
local_file = Server.MapPath(local_file)
xlink_feed = "http://rcxlink.4u2ges.com/rcxlink.asp?id=" & xlink_id
If isNumeric(Request("page")) and Len(Request("page")) > 0 then
nPage = Request("page")
Else: nPage = 1
End If
Set xobjFile = Server.CreateObject("Scripting.FileSystemObject")
If Not xobjFile.FileExists(local_file) Then
Response.Write "Local XML File does not exist. Please review instructions at RCxLink site. ID=" & xlink_id
Response.End
End If
fileModDate = xobjFile.getFile(local_file).DateLastModified
fileModDate = xConvDate(fileModDate)
CompDate = DateAdd("h", -24, Now)
CompDate = xConvDate(CompDate)
Set xRSS = new xkwRSS_reader
If fileModDate < CompDate Or xobjFile.getFile(local_file).size < 20 Or Len(Request("feed")) > 0 Then
feed_data = xRSS.getFeed(xlink_feed)
If Len(feed_data) > 10 then xwriteFile local_file, feed_data
End If
local_feed_data = xReadFile(local_file)
xRSS.ParseLocation(local_feed_data)
RSS_ChannelTitle = xRSS.ChannelTitle
RSS_ChannelLanguage = xRSS.ChannelLanguage
RSS_ChannelURL = xRSS.ChannelURL
RSS_ChannelDesc = xRSS.ChannelDesc
RSS_ImageURL = xRSS.ImageURL
RSS_ChannelCategory = xRSS.ChannelCategory
RSS_OUT = RSS_OUT & "
"
RSS_OUT = RSS_OUT & "" & RSS_ChannelDesc & "
"
feedsTotal = xRSS.TotalItems
strFeedPaging = buildPaging(CLng(nPage), feedsTotal)
RSS_OUT = RSS_OUT & "" & strFeedPaging & "
"
RSS_OUT = RSS_OUT & "Pages: " & tpages & "
Sites in Exchange: " & feedsTotal & "; displaying " & startCount+1 & " through " & endCount & "
"
RSS_OUT = RSS_OUT & "
" & vbcrLf & ""
Response.Write RSS_OUT
Function UnicodeXL(b)
t = String(LenB(b), " ")
t = ""
For i = 1 To LenB(b)
t = t & Chr(AscB(MidB(b, i, 1)))
Next
UnicodeXL = t
End Function
Const xrssInit = 1
Const xrssError = 2
Const xrssBadRSS= 3
Const xrssOK = 0
class xkwRSS_reader
Private Items()
Public CurrentItem, TotalItems
Public ChannelRSSURI, ChannelURL, ChannelTitle, ChannelDesc, ChannelLanguage, ChannelCategory
Public ImageTitle, ImageLink, ImageURL
Public TextInputURL, TextInputTitle, TextInputDesc, TextInputName
Private Status
Private Sub Class_Initialize
CurrentItem = -1
TotalItems = -1
Redim Items(5, 5000) '1st dimension = item's title/link/desc, 2nd dimension the item number
Status = xrssInit
End Sub
Private Sub Class_Terminate
Erase Items
Set Items = Nothing
End Sub
Public Function getFeed(URL)
reffer = Server.URlEncode(Request.ServerVariables("HTTP_REFERER"))
browser = Server.URlEncode(Request.ServerVariables("HTTP_USER_AGENT"))
ChannelRSSURI = URL & "&ref=" & reffer & "&brz=" & browser
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", ChannelRSSURI, False
xmlhttp.send
rssXML_Data = xmlhttp.responseBody
rssXML_Data = UnicodeXL(rssXML_Data)
rssXML_Data = replace(rssXML_Data, "", "rss-0.91.dtd""-->")
Set xmlhttp = nothing
getFeed = rssXML_Data
End Function
Public Function ParseLocation(rssXML_Data)
Set xmlObj = Server.CreateObject("Msxml2.DOMDocument.3.0")
xmlObj.validateOnParse = false
xmlObj.async = false
xmlObj.preserveWhiteSpace = false
xmlObj.loadXML(rssXML_Data)
If xmlObj.parseError.errorCode = 0 then
ValidLocation = true
Else
ValidLocation = false
End if
If not ValidLocation then
Status = xrssBadRSS
Exit Function
End if
set rootNode = xmlObj.selectSingleNode("rdf:RDF")
If rootNode is nothing then
Set rootNode = xmlObj.selectSingleNode("rss")
If rootNode is nothing then
Status = xrssError
Else
Reader rootNode, 0.91
End if
Else
Reader rootNode, 1.0
End if
set rootNode = nothing
set xmlObj = nothing
Status = xrssOK
End Function
Private Sub Reader(rootNode, ver)
itemNum = -1
set SingleNode = rootNode.selectSingleNode("//channel/title")
if Not SingleNode is nothing then ChannelTitle = SingleNode.text
set SingleNode = rootNode.selectSingleNode("//channel/link")
if Not SingleNode is nothing then ChannelURL = SingleNode.text
set SingleNode = rootNode.selectSingleNode("//channel/description")
if Not SingleNode is nothing then ChannelDesc = SingleNode.text
set SingleNode = rootNode.selectSingleNode("//channel/language")
if Not SingleNode is nothing then ChannelLanguage = SingleNode.text
set SingleNode = rootNode.selectSingleNode("//channel/category")
if Not SingleNode is nothing then ChannelCategory = SingleNode.text
if ver = 1 then
set child = rootNode.selectSingleNode("image")
else
set child = rootNode.selectSingleNode("//channel/image")
end if
if not child is nothing then
set SingleNode = child.selectSingleNode("title")
if Not SingleNode is nothing then ImageTitle = SingleNode.text
set SingleNode = child.selectSingleNode("link")
if Not SingleNode is nothing then ImageLink = SingleNode.text
set SingleNode = child.selectSingleNode("url")
if Not SingleNode is nothing then ImageURL = SingleNode.text
end if
set child = nothing
if ver = 1 then
set child = rootNode.selectSingleNode("textinput")
else
set child = rootNode.selectSingleNode("//channel/textinput")
end if
if not child is nothing then
set SingleNode = child.selectSingleNode("title")
if Not SingleNode is nothing then TextInputTitle = SingleNode.text
set SingleNode = child.selectSingleNode("description")
if Not SingleNode is nothing then TextInputDesc = SingleNode.text
set SingleNode = child.selectSingleNode("name")
if Not SingleNode is nothing then TextInputName = SingleNode.text
set SingleNode = child.selectSingleNode("link")
if Not SingleNode is nothing then TextInputURL = SingleNode.text
end if
set child = nothing
set children = rootNode.selectNodes("//item")
TotalItems = children.length
for each child in children
itemNum = itemNum + 1
if itemNum > ubound(Items, 2) then
Redim Preserve Items(4, ubound(Items, 2) + 5)
end if
for each ItemChild in child.ChildNodes
select case ItemChild.baseName
case "title" Items(0, itemNum) = ItemChild.text
case "link" Items(1, itemNum) = ItemChild.text
case "description" Items(2, itemNum) = ItemChild.text
case "pubDate" Items(3, itemNum) = ItemChild.text
case "enclosure"
encType = ItemChild.getAttribute("type")
If Instr(1, encType, "image", 1) <> 0 then
Items(4, itemNum) = ItemChild.getAttribute("url")
End If
case "category" Items(5, itemNum) = ItemChild.text
end select
next
next
if TotalItems > 0 then CurrentItem = 0
End Sub
Public Function GetTitle()
GetTitle = Items(0, CurrentItem)
End Function
Public Function GetLink()
GetLink = Items(1, CurrentItem)
End Function
Public Function GetDesc()
GetDesc = Items(2, CurrentItem)
End Function
Public Function GetDate()
GetDate = Items(3, CurrentItem)
End Function
Public Function GetEnclosure()
GetEnclosure = Items(4, CurrentItem)
End Function
Public Function GetCategory()
GetCategory = Items(5, CurrentItem)
End Function
Public Function MoveNext
CurrentItem = CurrentItem + 1
End Function
Public Function FirstItem
if TotalItems > 0 then
CurrentItem = 0
else
CurrentItem = -1
end if
End Function
Public Function ValidItem
if CurrentItem > -1 and CurrentItem < TotalItems then
ValidItem = true
else
ValidItem = false
end if
End Function
Public Function EOF
if CurrentItem < TotalItems then
EOF = false
else
EOF = true
end if
End Function
Public Function GetStatus()
GetStatus = Status
end function
end class
Function xreadFile(rFile)
Set riFile = xobjFile.GetFile(rFile)
Set recordGet = xobjFile.OpenTextFile(riFile, 1, False)
rec = recordGet.Read(riFile.Size)
recordGet.Close
rec = xClearCarriageReturn(rec)
xreadFile = rec
End Function
Sub xwriteFile(iFile, iData)
iData = xClearCarriageReturn(iData)
On Error Resume Next
Set recordSet = xobjFile.OpenTextFile(iFile, 2, True)
recordSet.WriteLine iData
recordSet.Close
Set iData = Nothing
If err.number <> 0 Then Response.Write "[Write] permission is not set for [" & iFile & "].": Response.End
On Error Goto 0
End Sub
Function xClearCarriageReturn(recClearRet)
Do Until Not Right(recClearRet, 2) = vbCrLf And Not Left(recClearRet, 2) = vbCrLf
If Right(recClearRet, 2) = vbCrLf Then recClearRet = Left(recClearRet, Len(recClearRet) - 2)
If Left(recClearRet, 2) = vbCrLf Then recClearRet = Right(recClearRet, Len(recClearRet) - 2)
Loop
xClearCarriageReturn = recClearRet
End Function
Function xConvDate(passDate)
date_part = DatePart("yyyy", passDate) & "-" & Right(DatePart("m", passDate) + 100, 2) & "-" & Right(DatePart("d", passDate) + 100, 2)
time_part = " " & Right(DatePart("h", passDate) + 100, 2) & ":" & Right(DatePart("n", passDate) + 100, 2) & ":" & Right(DatePart("s", passDate) + 100, 2)
xConvDate = date_part & time_part
End Function
Function buildPaging(Page, fcount)
tpages = fcount \ xpp
remain = fcount Mod xpp
If (tpages < 2 And remain = 0) Or tpages < 1 Then
records = remain
If remain = 0 Then records = xpp
startCount = 0
endCount = records
pbatches = 1
tpages = 1
Exit Function
Else
If remain > 0 Then tpages = tpages + 1
pbatches = tpages \ xppp
BatchesRemain = tpages Mod xppp
If BatchesRemain > 0 Then pbatches = pbatches + 1
records = xpp
If remain > 0 And Page = tpages Then records = remain
startCount = (Page * xpp) - xpp
endCount = startCount + records
End If
If tpages > 1 Then
pbatch = Page \ xppp
tempRemain = Page Mod xppp
If pbatch = 0 Or tempRemain > 0 Then pbatch = pbatch + 1
batchCount = xppp
If BatchesRemain > 0 And pbatch = pbatches Then batchCount = BatchesRemain
startBatch = ((pbatch - 1) * xppp) + 1
endBatch = startBatch + batchCount - 1
If pbatch > 1 Then
prevRec = xppp * (pbatch - 1)
pages = "<<Prev " & vbcrlf
End If
For J = startBatch To endBatch
If Page = J Then
pages = pages & "[" & J & "] " & vbcrlf
Else
pages = pages & "[" & J & "] " & vbcrlf
End If
Next
If pbatch < pbatches Then
nextRec = (xppp * pbatch) + 1
pages = pages & "Next>> " & vbcrlf
End If
End If
buildPaging = pages
End Function
%>