来自Gallery2的RSS源

时间:2008-08-11 01:32:16

标签: php web-applications

Gallery2 RSS module进行了几个小时的战斗,并且只获得了消息,“尚未定义任何Feed”,我放弃了。基于a Google search for "no feeds have yet been defined",这是一个非常常见的问题。您是否有任何使Gallery2 RSS模块工作的提示和/或技巧?或者是一个相对PHP无知的开发人员试图调试这个PHP应用程序的问题的任何提示?

2 个答案:

答案 0 :(得分:1)

我对此问题的最终(并且希望是临时的)解决方案是Python CGI脚本。我的脚本适用于任何可能发现它有用的人(尽管事实上这是一个彻底的黑客行为)。

#!/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()

答案 1 :(得分:-2)

嗯,我不确定这可以帮到你,但这是一个非常简单的RSS,作为另一个主题的解决方案呈现:

PHP RSS Builder