<%@LANGUAGE="VBSCRIPT" %> <% Response.CacheControl = "no-cache" pagetitle = "Welcome to CGT411/490" toplogotextimage = "youhavearrived.jpg" %> <% query = "SELECT * FROM static_content" set ors = oconn.execute(query) %>
RSS Management
<% '///////////////////////////////////////////////// '// Copyright 2005 Ronald J. Glotzbach '///////////////////////////////////////////////// 'Constants Const XMLFile = "../411_RSS.xml" Const author = "Terry Burton" Const LogFile = "DeesRdaLogs/courseRssLogFilexyz.txt" '///////////////////////////////////////////////// '// Open Log File '///////////////////////////////////////////////// Dim myFileSystem Dim myTextStream set myFileSystem=Server.CreateObject("Scripting.FileSystemObject") 'set myTextStream=myFileSystem.OpenTextFile(server.MapPath("\zyxabc.txt"),8) set myTextStream=myFileSystem.OpenTextFile(Server.MapPath(LogFile),8) '///////////////////////////////////////////////// '// End Open Log File '///////////////////////////////////////////////// If Request.QueryString("manage")="edit" Then 'Check for session If Session("guid") = "" Then Response.Redirect("manageRss.asp") End If 'Instantiate the XML parser Set oXml = Server.CreateObject("Msxml2.DOMDocument") 'Load the XML Document oXML.Load(Server.MapPath(XMLFile)) Set oRoot = oXML.documentElement 'Copy beginning elements inside of Set objNode = oRoot.SelectSingleNode("channel/item[guid='" & Request.QueryString("id") & "']") %>
Edit Existing RSS Item
 
Title:
Description:
Link:
Author:
" /> " />
<% ElseIf Request.QueryString("manage")="doEdit" Then 'Check for session If Session("guid") = "" Then Response.Redirect("manageRss.asp") End If Call doEdit() Response.Redirect("manageRss.asp") ElseIf Request.QueryString("manage")="delete" Then 'Check for session If Session("guid") = "" Then Response.Redirect("manageRss.asp") End If Call doDelete() Response.Redirect("manageRss.asp") ElseIf Request.QueryString("manage")="add" Then 'Check for session If Session("guid") = "" Then Response.Redirect("manageRss.asp") End If %>
Add New RSS Item
 
Title:
Description:
Link:
Author:
" /> " />
<% ElseIf Request.QueryString("manage")="doAdd" Then 'Check for session If Session("guid") = "" Then Response.Redirect("manageRss.asp") End If Call doAdd() Response.Redirect("manageRss.asp") Else Set objXML = Server.CreateObject("Microsoft.XMLDOM") Set objLst = Server.CreateObject("Microsoft.XMLDOM") Set objAnn = Server.CreateObject("Microsoft.XMLDOM") objXML.async = False objXML.Load (Server.MapPath(XMLFile)) If objXML.parseError.errorCode <> 0 Then 'handle the error End If %> <% Set objLst = objXML.getElementsByTagName("item") noOfItems = objLst.length For i = 0 To ( noOfItems - 1 ) Set objAnn = objLst.item(i) 'Get the max int iGuid iGuid = int(objAnn.childNodes(3).text) If Session("guid") = "" Then Session("guid") = iGuid ElseIf int(iGuid) > int(Session("guid")) Then Session("guid") = iGuid End If 'End get max 'write the XML title followed by description Response.Write("") Else Response.Write("") End If Next %>
Manage RSS Feed
 
add new
 
edit delete " & objAnn.childNodes(0).text & ": " & objAnn.childNodes(1).text) 'determine current page URL currentPage = "http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL") 'if XML link is not the same URL as current page, don't show a link '(showing the link would create a circular scenario If objAnn.childNodes(2).text <> currentPage Then Response.Write(" [ Link ]
<% End If 'Functions 'This function adds a contact to the xml file Function doAdd() Dim title, description, pubDate, link, author, guid 'Get data submitted from form title = Request.Form("title") description = Request.Form("description") pubDate = Request.Form("pubDate") link = Request.Form("link") author = Request.Form("author") guid = int(Request.Form("guid")) + 1 'Instantiate the XML parser Set oXml = Server.CreateObject("Msxml2.DOMDocument") 'Load the XML Document oXML.Load(Server.MapPath(XMLFile)) 'It is not as easy as appending a new node. the xml dom does not allow a new node 'to be added that deep in the hierarchy. A new channel node could easily be appended, 'but not a new item node. So, we must copy everything out of the old channel node, 're-build it in memory, add the new item node in the process, and then remove the 'old channel node and append the new channel node. strChannel = chr(9) & "" & chr(13) & chr(9) & "" & chr(13) oXML.LoadXML(strChannel) Set oChannel = oXML.documentElement oXML.Load(Server.MapPath(XMLFile)) Set oRoot = oXML.documentElement 'Copy beginning elements inside of Set objNode = oRoot.SelectSingleNode("channel/title") oChannel.appendChild(objNode) Response.Write(objNode.text & "

") Set objNode = oRoot.SelectSingleNode("channel/link") oChannel.appendChild(objNode) Response.Write(objNode.text & "

") Set objNode = oRoot.SelectSingleNode("channel/description") oChannel.appendChild(objNode) Response.Write(objNode.text & "

") Set objNode = oRoot.SelectSingleNode("channel/language") oChannel.appendChild(objNode) Response.Write(objNode.text & "

") Set objNode = oRoot.SelectSingleNode("channel/copyright") oChannel.appendChild(objNode) Response.Write(objNode.text & "

") Set objNode = oRoot.SelectSingleNode("channel/docs") oChannel.appendChild(objNode) Response.Write(objNode.text & "

") Set objNode = oRoot.SelectSingleNode("channel/lastBuildDate") objNode.text = pubdate oChannel.appendChild(objNode) Response.Write(objNode.text & "

") Set objNode = oRoot.SelectSingleNode("channel/image") oChannel.appendChild(objNode) Response.Write(objNode.text & "

") 'Add the new strNewItem = chr(13) & chr(13) & chr(9) & chr(9) & chr(9) & "" & chr(13) strNewItem = strNewItem & chr(9) & chr(9) & chr(9) & chr(9) & "" & title & "" & chr(13) strNewItem = strNewItem & chr(9) & chr(9) & chr(9) & chr(9) & "" & description & "" & chr(13) strNewItem = strNewItem & chr(9) & chr(9) & chr(9) & chr(9) & "" & link & "" & chr(13) strNewItem = strNewItem & chr(9) & chr(9) & chr(9) & chr(9) & "" & guid & "" & chr(13) strNewItem = strNewItem & chr(9) & chr(9) & chr(9) & chr(9) & "" & author & "" & chr(13) strNewItem = strNewItem & chr(9) & chr(9) & chr(9) & chr(9) & "" & pubDate & "" & chr(13) strNewItem = strNewItem & chr(9) & chr(9) & chr(9) & "" & chr(13) Set oXML2 = Server.CreateObject("Microsoft.XMLDOM") oXML2.LoadXML(strNewItem) oChannel.appendChild(oXML2.documentElement) 'Add the rest of the elements Set objXML = Server.CreateObject("Microsoft.XMLDOM") Set objLst = Server.CreateObject("Microsoft.XMLDOM") Set objAnn = Server.CreateObject("Microsoft.XMLDOM") objXML.async = False objXML.Load (Server.MapPath(XMLFile)) Set objLst = objXML.getElementsByTagName("item") noOfItems = objLst.length For i=0 To (noOfItems - 1) Set oAnn = objLst.item(i) Set objNode = oRoot.SelectSingleNode("channel/item[guid='" & oAnn.childNodes(3).text & "']") oChannel.appendChild(objNode) Response.Write(objNode.text & "

") Next 'Remove old channel node Set objNode = oRoot.SelectSingleNode("channel") oRoot.removeChild(objNode) 'Add new channel node oXML.save(Server.MapPath(XMLFile)) oRoot.appendChild(oChannel) 'After the XML file has been edited, is must be saved. oXML.save(Server.MapPath(XMLFile)) End Function 'This functions updates an existing item Function doEdit() 'Instantiate the XML parser Set oXML = Server.CreateObject("Msxml2.DOMDocument") 'Load the XML Document oXML.Load(Server.MapPath(XMLFile)) Set oRoot = oXML.documentElement 'Get the corresponding to the guid passed in Set objNode = oRoot.SelectSingleNode("channel/item[guid='" & Request.Form("guid") & "']") '///////////////////////////////////////////////// '// Write Log File '///////////////////////////////////////////////// 'write REMOTE_ADDR information myTextStream.Write(Request.ServerVariables("REMOTE_ADDR")) myTextStream.Write(chr(9)) 'write HTTP_HOST information myTextStream.Write(Request.ServerVariables("HTTP_HOST")) myTextStream.Write(chr(9)) 'write date myTextStream.Write(Date()) myTextStream.Write(chr(9)) 'write time myTextStream.Write(Time()) myTextStream.Write(chr(9)) 'write userID myTextStream.Write("**EDIT**") myTextStream.Write(chr(9)) 'write newline and original 'write HTTP_USER_AGENT information myTextStream.Write(Request.ServerVariables("HTTP_USER_AGENT")) myTextStream.WriteLine() myTextStream.WriteLine(chr(9) & "Was: ") myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(0).text) myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(1).text) myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(2).text) myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(4).text) '///////////////////////////////////////////////// '// End Write Log File '///////////////////////////////////////////////// objNode.childNodes(0).text = Request.Form("title") objNode.childNodes(1).text = Request.Form("description") objNode.childNodes(2).text = Request.Form("link") objNode.childNodes(4).text = Request.Form("author") '///////////////////////////////////////////////// '// Write Log File '///////////////////////////////////////////////// 'write newline and original myTextStream.WriteLine() myTextStream.WriteLine(chr(9) & "Changed To: ") myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(0).text) myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(1).text) myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(2).text) myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(4).text) myTextStream.WriteLine() myTextStream.close Set myFileSystem = nothing '///////////////////////////////////////////////// '// End Write Log File '///////////////////////////////////////////////// 'After the XML file has been edited, is must be saved. oXML.save(Server.MapPath(XMLFile)) End Function 'This functions deletes an existing item Function doDelete() 'Instantiate the XML parser Set oXML = Server.CreateObject("Microsoft.XMLDOM") 'Turn off asyncronous file loading. oXML.async = false 'Load the XML Document oXML.Load(Server.MapPath(XMLFile)) Set oRoot = oXML.documentElement 'Get the corresponding to the guid passed in Set objNode = oRoot.SelectSingleNode("channel/item[guid='" & Request.QueryString("id") & "']") '///////////////////////////////////////////////// '// Write Log File '///////////////////////////////////////////////// 'write REMOTE_ADDR information myTextStream.Write(Request.ServerVariables("REMOTE_ADDR")) myTextStream.Write(chr(9)) 'write HTTP_HOST information myTextStream.Write(Request.ServerVariables("HTTP_HOST")) myTextStream.Write(chr(9)) 'write date myTextStream.Write(Date()) myTextStream.Write(chr(9)) 'write time myTextStream.Write(Time()) myTextStream.Write(chr(9)) 'write userID myTextStream.Write("**DELETE**") myTextStream.Write(chr(9)) 'write newline and original 'write HTTP_USER_AGENT information myTextStream.Write(Request.ServerVariables("HTTP_USER_AGENT")) myTextStream.WriteLine() myTextStream.WriteLine(chr(9) & "DELETING: ") myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(0).text) myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(1).text) myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(2).text) myTextStream.WriteLine(chr(9) & chr(9) & objNode.childNodes(4).text) '///////////////////////////////////////////////// '// End Write Log File '///////////////////////////////////////////////// oRoot.childNodes(0).removeChild(objNode) '///////////////////////////////////////////////// '// Write Log File '///////////////////////////////////////////////// 'write newline and original myTextStream.WriteLine() myTextStream.close Set myFileSystem = nothing '///////////////////////////////////////////////// '// End Write Log File '///////////////////////////////////////////////// 'After the XML file has been edited, is must be saved. oXML.save(Server.MapPath(XMLFile)) End Function %>