<% ' Copyright (c) 2003 on-the-ocean-train@agresticism.org ' Licensed under the MIT license: ' http://www.opensource.org/licenses/mit-license.php ' CachedPath: ' relative path for the local (transformed) copy. Make sure the directory exists and has write permissions. ' Service: ' BlogRolling or blo.gs. ' UniqueID: ' your (blogroll's) unique ID. For blo.gs it'll probably be just a number, for BlogRolling a longer string. ' HTTPComponent: ' AspTear or MSXML. ' Stylesheet: ' relative path to the XSL stylesheet. Public Function Blogroll(CachedPath, Service, UniqueID, HTTPComponent, Stylesheet) Dim FSO, CachedFile, TextStream Dim XML, XSL Dim LastModified Dim BlogrollData Set FSO = Server.CreateObject("Scripting.FileSystemObject") If FSO.FileExists(Server.MapPath(CachedPath)) Then Set CachedFile = FSO.GetFile(Server.MapPath(CachedPath)) Set TextStream = CachedFile.OpenAsTextStream(1) LastModified = CachedFile.DateLastModified ' End of stream errors otherwise. If CachedFile.Size > 0 Then BlogrollData = TextStream.ReadAll Else BlogrollData = "" TextStream.Close Set CachedFile = Nothing Set TextStream = Nothing Else ' A week ago. Doesn't have to be this, really, just anything that's definitely longer ago than an hour. LastModified = Now - 7 End If If LastModified > (Now - 1/24) And Len(BlogrollData) > 0 Then ' No need to do anything at all but return the cached copy. Blogroll = BlogrollData ' Clean up. Set FSO = Nothing Set CachedFile = Nothing Set XML = Nothing Set XSL = Nothing Exit Function End If Set XML = Server.CreateObject("Microsoft.XMLDOM") Set XSL = Server.CreateObject("Microsoft.XMLDOM") ' Choose your HTTP component. "MSXML" or "AspTear". Select Case LCase(Service) Case "blogrolling": BlogrollData = ReadURL("http://rpc.blogrolling.com/rss.php", "r=" & UniqueID, HTTPComponent) Case "blo.gs": BlogrollData = ReadURL("http://blo.gs/" & UniqueID & "/favorites.rss", "", HTTPComponent) End Select XML.LoadXML BlogrollData ' Load the stylesheet. XSL.ASync = False XSL.Load Server.MapPath(Stylesheet) ' Apply the stylesheet to the document. BlogrollData = XML.TransformNode(XSL) ' If the directory doesn't exist, this will most likely not work. Set CachedFile = FSO.OpenTextFile(Server.MapPath(CachedPath), 2, True) ' Cache the data for next time. CachedFile.Write(BlogrollData) CachedFile.Close ' Return what we need. Blogroll = BlogrollData ' Clean up. Set FSO = Nothing Set CachedFile = Nothing Set XML = Nothing Set XSL = Nothing End Function Private Function ReadURL(URL, Parameters, HTTPComponent) ' A handy function to compliment the other. You might find this useful in general. Dim HTTP Select Case LCase(HTTPComponent) Case "asptear": Set HTTP = Server.CreateObject("SOFTWING.AspTear") ReadURL = HTTP.Retrieve(URL, 2, Parameters, "", "") Case "msxml": If Len(Parameters) > 0 Then URL = URL & "?" & Parameters Set HTTP = Server.CreateObject("MSXML2.ServerXMLHTTP") HTTP.Open "GET", URL, False ReadURL = HTTP.ResponseText End Select Set HTTP = Nothing End Function %>