【问题标题】:CFFEED component/custom tag for ColdFusion MX 7?ColdFusion MX 7 的 CFFEED 组件/自定义标签?
【发布时间】:2010-11-18 11:40:12
【问题描述】:

我在一个客户的网站上工作,更新到 ColdFusion 8 不是一个选项。我正在寻找的是通过自定义标签或组件类似于 CF8 的 CFFEED 功能的东西,如果已经存在的话,我并不是特别热衷于编写自己的阅读器/解析器。

我需要从博客中读取 RSS2 提要并显示标题、描述和链接。最好我能够设置大约 5-10 分钟的缓存,这样我就不会敲击提要(我从提要中提取的信息将显示在高流量网站上)。

【问题讨论】:

    标签: coldfusion rss feed cffeed


    【解决方案1】:

    如果您正在寻找开箱即用的东西,RIAForge 上有几个项目,快速搜索一下就找到了这两个,但我猜您可以找到更多:

    http://cfrss.riaforge.org/

    http://rssville.riaforge.org/

    如果您准备推出自己的(我知道您说过您不喜欢),您就不能像这样请求提要吗:

    <cfhttp 
      url = "http://example.com" 
      resolveurl="no"
      throwOnError = "yes"
      timeout = "10" >
    </cfhttp>
    

    并解析结果:

    <cfset feedData = CFHTTP.FileContent>
    <cfset xmlData = XMLParse(feedData)>
    

    循环:

    <cfset result = queryNew("title,description")>  
    <cfset items = xmlSearch(xmlData,"//*[local-name() = 'item']")>
    
    <cfloop index="x" from="1" to="#arrayLen(items)#">
    
        <cfif structKeyExists(items[x],"title")>
            <cfset node.title = items[x].title.XmlText>
        <cfelse>
            <cfset node.title = "">
        </cfif>
    
        <cfif structKeyExists(items[x],"description")>
            <cfset node.description = items[x].description.XmlText>
        <cfelse>
            <cfset node.description = "">
        </cfif>
    
        <cfset queryAddRow(result)>
        <cfset querySetCell(result,"title",node.title)>
        <cfset querySetCell(result,"description",node.description)>
    
    </cfloop>
    

    输出:

    <cfoutput query="result">
        <ul>
            <li><strong>#title#</strong> - #description#</li>
        </ul>
    </cfoutput>
    

    显然未经测试,但仍然是一个想法。使用类似的东西来获取我最新的美味书签。就缓存而言,有几种不同的方法来处理它。我可能会运行一个计划任务来点击这个文件并将输出写入一个包含的单独文件。我敢肯定有更好的方法,但那是快速和肮脏的,imo。

    【讨论】:

      【解决方案2】:

      我知道这有点晚了,但是在我的工作中遇到了这种情况(Coldfuison 7 并且不会升级)。但还需要从它在我们网站上的嵌入位置链接回原始帖子。

      只是为了在上面的好答案中添加更多内容,您可以将其添加到文章的链接(在我们的例子中是在不倒翁上) 在循环中:

      <cfif structKeyExists(items[x],"guid")>
          <cfset node.guid = items[x].guid.XmlText>
      <cfelse>
          <cfset node.guid = "">
      </cfif>
      
      <cfset querySetCell(result,"guid",node.guid)>
      

      在输出中:

      <a href="#guid#">#title#</a>
      

      我相信您也可以使用“link”代替“guid”,但这对我有用。 我希望这可以帮助其他需要链接的人。我对 ColdFusion 很陌生, 并且可能有更好的方法来做到这一点(在旧版本的 CF 上)。

      【讨论】:

        猜你喜欢
        • 2012-07-13
        • 1970-01-01
        • 2016-05-30
        • 2014-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-17
        • 1970-01-01
        相关资源
        最近更新 更多