RSS Feed to get indexed

Discussion in 'General Programming Chat' started by youtalk, Aug 9, 2012.

  1. youtalk

    youtalk Regular Member

    Joined:
    Jul 5, 2012
    Messages:
    351
    Likes Received:
    6
    Occupation:
    Owner
    Location:
    I don't even know anymore
    Maybe I'll get more responses on this here.


    A little while back someone posted this code, and now I cannot find the original thread.

    My question is, how can I translate this code to php?

    > Make sure you use an embed script that will make the RSS feed content as part
    > of the page HTML, not some kind of javascript rendering script (less readable
    > by SE's)
    > Here is a asp script for doing that very thing, you could easily convert to
    > php if needed.
    > I didn't write this, I even left the copyright in, but I use it myself in
    > various forms. I modified the links it produces to be nofollow so as not to
    > dilute my existing outbound links
    > If there are no feed items to display it will tell you on the webpage. It
    > will say "This feed is empty"
    >
    >
    Code:
    > < %
    > 'Response.Expires = -1
    > dim URLToRSS
    > dim MaxNumberOfItems
    > dim MainTemplateHeader
    > dim MainTemplateFooter
    > dim Keyword1
    > dim Keyword2
    > dim ItemTemplate
    > dim ErrorMessage
    > dim xmlHttp
    > dim RSSXML
    > dim xmlDOM
    > dim RSSItems
    > dim RSSItemsCount
    > dim j
    > dim i
    > dim RSSItem
    > dim RSSdescription
    > dim RSSCommentsLink
    > dim child
    > dim RSStitle
    > dim RSSLink
    > dim RSSDate
    > dim CategoryItems
    > dim RSSCategory
    > dim categoryitem
    > dim ItemContent
    > 
    > dim testchildtext
    > 
    > 
    > ' =========== RSS2HTML.ASP for ASP/ASP.NET ==========
    > ' copyright 2005-2008 (c)[URL="http://www.Bytescout.com"]www.Bytescout.com[/URL]
    > ' version 1.27, 16 August 2008
    > ' =========== configuration =====================
    > ' ##### URL to RSS Feed to display #########
    > 'URLToRSS = "http://feeds2.feedburner.com/Bytescout"
    > 
    > ' Search Engine Land Rss Feed
    > URLToRSS = "http://feeds.searchengineland.com/searchengineland?format=xml"
    > '##### max number of displayed items #####
    > MaxNumberOfItems = 10
    > 
    > ' ##### Main template constants
    > MainTemplateHeader = ""
    > MainTemplateFooter = "
    "
    > ' #####
    > 
    > ' ######################################
    > Keyword1 = "" ' Keyword1 = "tech" - set non-empty keyword value to filter by 
    > this keyword
    > Keyword2 = "" ' Keyword1 = "win" - set non-empty keyword value to filter by 
    > this 2nd keyword too
    > ' #################################
    > 
    > ' ##### Item template.
    > ' ##### {LINK} will be replaced with item link
    > ' ##### {TITLE} will be replaced with item title
    > ' ##### {DESCRIPTION} will be replaced with item description
    > ' ##### {DATE} will be replaced with item date and time
    > ' ##### {COMMENTSLINK} will be replaced with link to comments (if you use RSS 
    > feed from blog)
    > ' ##### {CATEGORY} will be replaced with item category
    > '
    > 'ItemTemplate = 
    > "{DATE}
    {CATEGORY}
    > href=" & """{LINK}""" & " 
    > target='_blank'>{TITLE}
    {DESCRIPTION}"
    > 'ItemTemplate = "> target='_blank'>{TITLE}
    > size=-2>{DESCRIPTION}"
    > ItemTemplate = "{DATE}
    
    > target='_blank'>{TITLE}
    {DESCRIPTION}
    "
    > 
    > ' ##### Error message that will be displayed if not items etc
    > ErrorMessage = "Error has occured while trying to process " & URLToRSS & 
    > "
    Please contact web-master"
    > 
    > ' ================================================
    > 
    > Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
    > xmlHttp.Open "GET", URLToRSS, false
    > xmlHttp.Send()
    > RSSXML = xmlHttp.ResponseText
    > 
    > Set xmlDOM = Server.CreateObject("MSXML2.DomDocument.3.0")
    > xmlDOM.async = False
    > xmlDOM.validateOnParse = False
    > xmlDom.resolveExternals = False
    > 
    > If not xmlDOM.LoadXml(RSSXML) Then
    > ErrorMessage = "Can not load XML:" & vbCRLF & xmlDOM.parseError.reason & 
    > vbCRLF & ErrorMessage
    > End If
    > 
    > Set xmlHttp = Nothing ' clear HTTP object
    > 
    > Set RSSItems = xmlDOM.getElementsByTagName("item") ' collect all "items" from 
    > downloaded RSS
    > 
    > RSSItemsCount = RSSItems.Length-1
    > 
    > ' if not .. entries, then try to get ..
    > if RSSItemsCount = -1 Then
    > Set RSSItems = xmlDOM.getElementsByTagName("entry") ' collect all "entry" 
    > (atom format) from downloaded RSS
    > RSSItemsCount = RSSItems.Length-1
    > 
    > End If
    > 
    > Set xmlDOM = Nothing ' clear XML
    > 
    > 
    > ' writing Header
    > Response.write("
    ")
    > if RSSItemsCount > 0 then
    > Response.Write MainTemplateHeader
    > End If
    > 
    > j = -1
    > 
    > 
    > For i = 0 To RSSItemsCount
    > Set RSSItem = RSSItems.Item(i)
    > 
    > ' fix for the issue when a description from a previous item
    > ' is used if current item description is empty provided by George Sexton
    > RSSdescription=" "
    > RSSCommentsLink=" "
    > 
    > for each child in RSSItem.childNodes
    > 
    > Select case lcase(child.nodeName)
    > case "title"
    > RSStitle = child.text
    > case "link"
    > If child.Attributes.length>0 Then
    > RSSLink = child.GetAttribute("href")
    > if (RSSLink <> "") Then
    > if child.GetAttribute("rel") <> "alternate" Then
    > RSSLink = ""
    > End If
    > End If
    > End If ' if has attributes
    > If RSSLink = "" Then
    > RSSlink = child.text
    > End If
    > case "description"
    > RSSdescription = child.text
    > case "content" ' atom format
    > RSSdescription = child.text
    > case "published"' atom format
    > RSSDate = child.text
    > case "pubdate"
    > RSSDate = child.text
    > case "comments"
    > RSSCommentsLink = child.text
    > case "category"
    > Set CategoryItems = RSSItem.getElementsByTagName("category")
    > RSSCategory = ""
    > for each categoryitem in CategoryItems
    > if RSSCategory <> "" Then
    > RSSCategory = RSSCategory & ", "
    > End If
    > 
    > RSSCategory = RSSCategory & categoryitem.text
    > Next
    > End Select
    > next
    > 
    > ' now check filter
    > If (InStr(RSSTitle,Keyword1)>0) or (InStr(RSSTitle,Keyword2)>0) or 
    > (InStr(RSSDescription,Keyword1)>0) or (InStr(RSSDescription,Keyword2)>0) then
    > 
    > j = J+1
    > 
    > if J> ' Make no follow links for feed
    > ItemContent = Replace(ItemTemplate,"{LINK}",RSSlink)
    > ItemContent = Replace(ItemContent,"{TITLE}",RSSTitle)
    > ItemContent = Replace(ItemContent,"{DATE}",RSSDate)
    > ItemContent = Replace(ItemContent,"{COMMENTSLINK}",RSSCommentsLi nk)
    > ItemContent = Replace(ItemContent,"{CATEGORY}",RSSCategory)
    > 
    > Response.Write Replace(ItemContent,"{DESCRIPTION}",RSSDescription )
    > ItemContent = ""
    > RSSLink = ""
    > End if
    > End If
    > 
    > Next
    > 
    > ' writing Footer
    > if RSSItemsCount > 0 then
    > Response.Write MainTemplateFooter
    > Response.write("")
    > else
    > Response.Write("This feed is empty")
    > > Response.Write("This feed is empty")
    > Response.write("")
    > End If
    > 
    > 'Response.End ' uncomment this for use in on-the-fly output
    > Response.write(testchildtext)
    
     
    Last edited by a moderator: Aug 9, 2012