【问题标题】:RSS feeds from Gallery2来自 Gallery2 的 RSS 提要
【发布时间】:2010-09-05 16:01:45
【问题描述】:

在与Gallery2 RSS module 斗争了几个小时后,我只收到消息“尚未定义任何提要”,我放弃了。基于a Google search for "no feeds have yet been defined",这是一个很常见的问题。你有什么让 Gallery2 RSS 模块正常工作的提示和/或技巧吗?或者对于尝试调试此 PHP 应用程序问题的相对 PHP 无知的开发人员有什么提示?

【问题讨论】:

    标签: php web-applications


    【解决方案1】:

    好吧,我不确定这对您有帮助,但这里有一个非常简单的 RSS,它在另一个主题中作为解决方案提出:

    PHP RSS Builder

    【讨论】:

      【解决方案2】:

      我对这个问题的最终(希望是暂时的)解决方案是一个 Python CGI 脚本。我的脚本适用于任何可能觉得它有用的人(尽管这完全是一个 hack)。

      #!/usr/bin/python
      """A CGI script to produce an RSS feed of top-level Gallery2 albums."""
      
      #import cgi
      #import cgitb; cgitb.enable()
      from time import gmtime, strftime
      import MySQLdb
      
      ALBUM_QUERY = '''
          select g_id, g_title, g_originationTimestamp
          from g_Item
          where g_canContainChildren = 1 
          order by g_originationTimestamp desc
          limit 0, 20
          '''
      
      RSS_TEMPLATE = '''Content-Type: text/xml
      
      <?xml version="1.0"?>
      <rss version="2.0">
        <channel>
          <title>TITLE</title>
          <link>http://example.com/gallery2/main.php</link>
          <description>DESCRIPTION</description>
          <ttl>1440</ttl>
      %s
        </channel>
      </rss>
      '''
      
      ITEM_TEMPLATE = '''
          <item>
            <title>%s</title>
            <link>http://example.com/gallery2/main.php?g2_itemId=%s</link>
            <description>%s</description>
            <pubDate>%s</pubDate>
          </item>
      '''
      
      def to_item(row):
          item_id = row[0]
          title = row[1]
          date = strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime(row[2]))
          return ITEM_TEMPLATE % (title, item_id, title, date)
      
      conn = MySQLdb.connect(host = "HOST",
                             user = "USER",
                             passwd = "PASSWORD",
                             db = "DATABASE")
      curs = conn.cursor()
      curs.execute(ALBUM_QUERY)
      print RSS_TEMPLATE % ''.join([ to_item(row) for row in curs.fetchall() ])
      curs.close()
      

      【讨论】:

        猜你喜欢
        • 2020-01-25
        • 2017-06-09
        • 1970-01-01
        • 2012-11-07
        • 2012-12-15
        • 2015-12-22
        • 2015-04-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多