views:

755

answers:

1

I have successfully created a simple RSS feed, but entries keep coming back as unread and updated, and entries deleted from the client reappear everytime I ask mail to update the feed.

What am I doing wrong?

I use this simple function to create an rss feed:

public static function getFeed($db)
{
    $title = 'Latest feeds';
    $feedUri = '/rss/';

    //link from which feed is available
    $link = 'http://' . $_SERVER['HTTP_HOST'] . $feedUri;

    //create array according to structure defined in Zend_Feed documentation
    $feedArr = array('title' => $title,
                     'link'  => $link,
                     'description' => $title,
                     'language' => 'en-us',
                     'charset' => 'utf-8',
                   //'published' => 1237281011,
                     'generator' => 'Zend Framework Zend_Feed',
                     'entries' => array()
              );
    $itemObjs = array();
    $select = $db->select('id')->from('things')
                               ->order('createddate desc')
                               ->limit(10);
    $results = $db->fetchAll($select->__toString());
    $count = count($results);
    for($i=0;$i<$count;$i++) {
        $itemObjs[] = SiteUtil::getItemObjectInstance($db, $results[$i]['id']);
    }
    $count = count($itemObjs);
    for($i=0;$i<$count;$i++) {
        $obj = & $itemObjs[$i];
        $feedArr['entries'][] = array('title' => $obj->getSummary(),
                                      'link'    => 'http://' . $_SERVER['HTTP_HOST'] . $obj->getDetailUri(),
                                      'description' => $obj->description,
                                      'publishdate' => $obj->publishedDate,
                                      'guid' => 'http://' . $_SERVER['HTTP_HOST'] . $obj->getDetailUri()
                                      );
    }
    $feed = Zend_Feed::importArray($feedArr, 'rss');
    return $feed;
}

The action in the controller class is:

public function rssAction()
{
    $feed = FeedUtil::getFeed($this->db);
    $feed->send();
}

So to access the feed, I point the client to: http://mysite.com/rss

I am using mac mail's rss client to test. The feed downloads just fine, showing all 5 items I have in the database for testing purposes. The problems are as follows:

1) If I mark one or more items as 'read' and then tell mail to update the feed, it pulls all items again as if I never downloaded them in the first place.

2) If I delete one or more items they come back again, unread, again as if it were the first time I subscribed to the feed.

3) Feeds are always marked as updated. Is that supposed to be the case?

Is is something to do with the parameters I'm setting, am I omitting something, or could the solution be something more subtle like setting HTTP content headers (e.g. '304 Not Modified')?

My understanding of rss is that once an item has been marked as read or deleted from the client, it should never come back, which is the behaviour I'm after.

Just to note, the 'link' and 'guid' parameters are always unique, and I have tried experimenting with 'published' and 'publishdate' (both optional) attributes only get the same result. The above code is a simplified version of what I have, showing only the relevant bits, and finally, yes, I have read the rss specification.

Thanks in advance for any help offered here, I'll be happy to clarify any point.

+3  A: 

According to the Zend Framework Doc, you must use the lastUpdate parameter to set the last modification date of an entry.

 'entries'     => array(
                         array(
                               [...]
                               'lastUpdate'   => 'timestamp of the publication date', // optional
                               [...]

So published for the feed, and lastUpdate for the entries.

altermativ
thanks allterrnativ, I am giving this a go.
karim79
Indeed, it worked like a charm. How wishy-washy of me to skip over that detail. Thanks again!
karim79