Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/161815-problem-setting-pubdate-with-zend_feed/
Share on other sites

  • 2 weeks later...

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.