SimplePie多提要演示代码不起作用.我应该用什么来代替呢?


SimplePie multiple feed demonstration code doesn't work. What should I use instead?

我想弄清楚为什么SimplePie网站上发布的用于显示多个提要的代码不起作用。具体来说,这个代码示例:

http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date

下面是我具体使用的:

<?php
// Include the SimplePie library
// For 1.0-1.2:
#require_once('simplepie.inc');
require_once($_SERVER['DOCUMENT_ROOT']."/path/to/simplepie/autoloader.php");
// For 1.3+:
// Create a new SimplePie object
$feed = new SimplePie();
// Instead of only passing in one feed url, we'll pass in an array of three
$feed->set_feed_url(array(
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=1891&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=1313&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=5811&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=1044&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=1804&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=5512&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=5127&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=5128&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=1440&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=1085&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=1095&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=5395&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=5429&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=5482&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=1812&year=2013',
'http://apps.leg.wa.gov/billinfo/SummaryRss.aspx?bill=1457&year=2013'
));
// Initialize the feed object
$feed->init();
// This will work if all of the feeds accept the same settings.
$feed->handle_content_type();
// Begin our HTML markup
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head>
    <title>Awesome feeds</title>
    <style type="text/css">
    h4.title {
        /* We're going to add some space next to the titles so we can fit the 16x16 favicon image. */
        background-color:transparent;
        background-repeat:no-repeat;
        background-position:0 1px;
        padding-left:20px;
    }
    </style>
</head>
<body>
    <div id="site">
        <?php if ($feed->error): ?>
        <p><?php echo $feed->error; ?></p>
        <?php endif; ?>
        <h1>Awesome feeds</h1>
        <?php foreach ($feed->get_items() as $item): ?>
        <div class="chunk">
            <?php /* Here, we'll use the $item->get_feed() method to gain access to the parent feed-level data for the specified item. */ ?>
            <h4 class="title" style="background-image:url(<?php $feed = $item->get_feed(); echo $feed->get_favicon(); ?>);"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h4>
            <?php echo $item->get_content(); ?>
            <p class="footnote">Source: <a href="<?php $feed = $item->get_feed(); echo $feed->get_permalink(); ?>"><?php $feed = $item->get_feed(); echo $feed->get_title(); ?></a> | <?php echo $item->get_date('j M Y | g:i a T'); ?></p>
        </div>
        <?php endforeach; ?>
    </div>
</body>
</html>

这是我得到的HTML输出:

<body>
    <div id="site">
        <h1>Awesome feeds</h1>
        <div class="chunk">
 <h4 class="title" style="background-image:url(<br />
<b>Warning</b>:  Favicon handling has been removed, please use your own handling in <b>/home/user/domain/library/SimplePie.php</b> on line <b>2946</b><br />
http://g.etfv.co/http%3A%2F%2Fapps.leg.wa.gov%2Fbillinfo%2Fsummary.aspx%3Fbill%3D1044%26amp%3Byear%3D2013);"><a href="<br />
<b>Fatal error</b>:  Call to a member function get_base() on a non-object in <b>/home/user/domain/folder/subfolder/simplepie/library/SimplePie/Item.php</b> on line <b>167</b><br />

我尝试过修改代码(例如,我可以不使用favicons),但是我总是得到致命的错误消息,说"调用成员函数[填充空白]在[SimplePie文件]中的非对象"。

是否有更多的最新代码,我应该使用作为构建处理多个提要的页面的模板?是什么破坏了SimplePie的工作?

我不知道你使用的是什么版本的SimplePie,但显然

Favicon处理已被删除,请使用您自己的处理/home/user/domain/library/SimplePie.php 2946

假设你不想调试SimplePie本身,你不应该调用这个:

$ feed -> get_favicon ()

开始。我不知道为什么favicon支持被删除了,因为我使用它,但我可能已经写了一个工作,或者我使用的是旧(劣质)版本的SimplePie。拉出图标的东西,再试一次。

我不喜欢看样例代码的方式,在一个作用域中有一个$feed实例,在foreach()结构的作用域中有另一个$feed实例。因此,我将$feed的第一个实例重命名为$the_feed,同时保留foreach中的$feed变量。

在公共(iPage)服务器上调用非对象上的方法的抱怨消失了。

我来这里寻找类似问题的答案。在我的情况下,在我的主服务器上工作良好的东西在公共服务器(iPage)上就不能工作了。主服务器运行PHP 5.3.3-7版本,公共服务器运行PHP 5.2.17版本。另一个区别是主服务器有服务器API=Apache 2.0 Handler,而公共服务器有服务器API=CGI。不确定这些要点是否重要