开发者社区> 问答> 正文

来自Gallery2的RSS feed

在与Gallery2 RSS模块进行了几个小时的争吵之后,我只收到消息“尚未定义提要”,我放弃了。根据Google搜索“尚未定义供稿”,这是一个非常普遍的问题。您是否有任何提示和/或技巧来使Gallery2 RSS模块正常工作?还是对那些不太了解PHP的开发人员尝试调试此PHP应用程序问题的任何提示?

展开
收起
游客ufivfoddcd53c 2020-01-03 16:58:05 1009 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()
    
    2020-01-03 16:58:38
    赞同 展开评论 打赏
问答分类:
PHP
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载