Tjorriemorrie Posted June 11, 2009 Share Posted June 11, 2009 Hey, I'm trying to build my own feed after the user has created or edited a post. However, even though I set the pubDate in the entries, Zend still goes and overwrite it with the current timestamp, even worse the timestamp is in the wrong timezone Can anyone help me figure out how to set the pubDate of the entries as per the date of the data? private function setXml() { function cmpEntries($a , $b) { $a_time = strtotime($a['pubDate']); $b_time = strtotime($b['pubDate']); if ($a_time == $b_time) { return 0; } return ($a_time > $b_time) ? -1 : 1; } $entries = array(); $blogDb = new Model_Blog(); $blogs = $blogDb->getAllBlogs(); foreach ($blogs as $blog) { $entry = array( 'title' => $blog->title, 'link' => 'http://www.aviyacrest.com/index/blog/entry/' . $blog->id, 'description' => htmlentities(nl2br($blog->description)), 'pubDate' => date('r', $blog->date) ); array_push($entries, $entry); } $poemsDb = new Model_Poem(); $poems = $poemsDb->getAllPoems(); foreach ($poems as $poem) { $entry = array( 'title' => $poem->title, 'link' => 'http://www.aviyacrest.com/index/poems/entry/' . $poem->id, 'description' => 'New poem from Aviya.', 'pubDate' => date('r', $poem->date) ); array_push($entries, $entry); } usort($entries, 'cmpEntries'); $feed = array( 'title' => 'Aviya', 'link' => 'http://www.aviyacrest.com', 'charset' => 'UTF-8', 'entries' => $entries ); $rss = Zend_Feed::importArray($feed, 'rss'); $rssFeed = $rss->saveXML(); try { $fh = fopen(PUBLIC_PATH . '/blog.xml', 'w'); fwrite($fh, $rssFeed); fclose($fh); return true; } catch (Zend_Exception $e) { $this->message = $e->getMessage(); return false; } } Here's an extract of the xml file: <item> <title><![CDATA[Fragile]]></title> <link>http://www.aviyacrest.com/index/blog/entry/21</link> <description><![CDATA[understand others by understanding yourself]]></description> <pubDate>Thu, 11 Jun 2009 13:15:31 +0000</pubDate> </item> <item> <title><![CDATA[We have done the same]]></title> <link>http://www.aviyacrest.com/index/poems/entry/17</link> <description><![CDATA[New poem from Aviya.]]></description> <pubDate>Thu, 11 Jun 2009 13:15:31 +0000</pubDate> </item> Quote Link to comment https://forums.phpfreaks.com/topic/161815-problem-setting-pubdate-with-zend_feed/ Share on other sites More sharing options...
ArneR Posted June 23, 2009 Share Posted June 23, 2009 Hi, works as designed :-) You have to change your feed-entry array to foreach ($blogs as $blog) { $entry = array( 'title' => $blog->title, 'link' => 'http://www.aviyacrest.com/index/blog/entry/' . $blog->id, 'description' => htmlentities(nl2br($blog->description)), 'published' => date('r', $blog->date) ); array_push($entries, $entry); } The class checking for the "published" key not "pubDate" Greetings, Arne Quote Link to comment https://forums.phpfreaks.com/topic/161815-problem-setting-pubdate-with-zend_feed/#findComment-861707 Share on other sites More sharing options...
Tjorriemorrie Posted June 23, 2009 Author Share Posted June 23, 2009 foreach ($blogs as $blog) { $entry = array( 'title' => $blog->title, 'link' => 'http://www.aviyacrest.com/index/blog/entry/' . $blog->id, 'description' => htmlentities(nl2br($blog->description)), 'published' => date('r', $blog->date) ); array_push($entries, $entry); } Thanks Arne, I'll have to check that. I got it working as 'lastUpdate'. Weird. Also, the value should be long, therefore it should not be date('r', $blog->date) but just $blog->date. Thanks for the reply. Tjorriemorrie Quote Link to comment https://forums.phpfreaks.com/topic/161815-problem-setting-pubdate-with-zend_feed/#findComment-861735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.