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

StackOverflow https://stackoverflow.com/questions/15302989

  •  18-03-2022
  •  | 
  •  

Domanda

I am trying to figure out why the code posted on the SimplePie website for displaying multiple feeds doesn't work. Specifically, this code example:

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

Here is specifically what I am using:

<?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>

And this is the HTML output I get:

<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 />

I've tried tinkering around with the code (for instance, I can do without favicons), but I always get fatal error messages saying "Call to a member function [fill in the blank] on a non-object in [SimplePie file]".

Is there more up-to-date code that I should be using as a template for constructing pages that process multiple feeds? What's breaking that's preventing SimplePie from working?

È stato utile?

Soluzione

I'm not sure what version of SimplePie you're using but apparently

Favicon handling has been removed, please use your own handling in /home/user/domain/library/SimplePie.php on line 2946

Assuming you don't want to debug SimplePie itself, you should not call this:

$feed->get_favicon()

For starters. I don't know why favicon support was removed, because I use it, but then again I might have written a work around or I'm using an older (inferior) version of SimplePie. Yank out the favicon stuff and try again.

Altri suggerimenti

I didn't like looking at the sample code the way it was, with an instance of $feed in one scope and another instance of $feed in the scope of the foreach() construct. So, I renamed the first instance of $feed to $the_feed, while leaving the $feed variables within the foreach as they were.

The complaints of calls to methods on non-objects went away on the public (iPage) server.

I got here looking for the answer to a similar problem. In my case, what worked fine on my home server would not work on a public server (iPage). Home server runs PHP Version 5.3.3-7 while public server runs 5.2.17. Another difference is that home server has Server API=Apache 2.0 Handler, while public one has Server API=CGI. Not sure if those points are important.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top