0

複数のフィードを表示するために SimplePie Web サイトに投稿されたコードが機能しない理由を理解しようとしています。具体的には、このコード例:

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

コードをいじってみましたが (たとえば、ファビコンなしで実行できます)、「[SimplePie ファイル] の非オブジェクトでメンバー関数 [空白を埋める] を呼び出します」という致命的なエラー メッセージが常に表示されます。 "。

複数のフィードを処理するページを作成するためのテンプレートとして使用すべき最新のコードはありますか? SimplePie が機能しない原因は何ですか?

4

2 に答える 2

1

使用しているSimplePieのバージョンはわかりませんが、どうやら

ファビコンの処理は削除されました。/home/user/domain/library/SimplePie.phpの 2946 行で独自の処理を使用してください。

SimplePie 自体をデバッグしたくない場合は、これを呼び出すべきではありません。

$feed->get_favicon()

初心者向け。ファビコンのサポートを使用しているため、なぜ削除されたのかわかりませんが、回避策を書いたか、SimplePie の古い (劣った) バージョンを使用している可能性があります。ファビコンのものを取り出して、もう一度やり直してください。

于 2013-03-12T02:09:04.203 に答える