Urgent - Change the date on RSS (exported feed)

Author Message

Greg Sanderson

Thursday 24 April 2008 4:40:36 am

Hi

I have kind of an urgent problem which I hope someone can help with. I have created an RSS feed to publish the latest news from my eZ site. This works however the items are sorted by their node publish date, rather than the publish date the user enters in a date field when they are creating the node.

Can anyone tell me where the XML that is the RSS feed is generated, and how to change it so that instead of using the eZ date it instead uses the date and time field from the node's data map to sort and display?

Thank you

Carlos Revillo

Thursday 24 April 2008 5:00:44 am

Hi.

My reply is for eZ4, but i don't think it would be much different in previous versions

you will find it at kernel/classes/ezrssexportitem.php

There you can search for this function

static function fetchNodeList( $rssSources, $objectListFilter )

In that function you'll find

$listParams = array( 'Limit' => $objectListFilter['number_of_objects'],
                                 'SortBy' => array( 'published', false )
                                );

You can change "SortBy" there.

Anyway, this is only a hack. I prefer not to hack ezpublish kernel clasess. Maybe i would do an extensions (Basically copying this classes) and so, you will no have problems if you want to upgrade ez in the future.

Hope it helps.

Greg Sanderson

Thursday 24 April 2008 5:23:11 am

Thanks - that should change the sort method but the published date and time will still appear on the RSS feed, even if they are in a different order. Is there a way to access the data_map like you would do $node.object.data_map or something in normal templates? That way the date could be shown instead of the attribute called published..

Carlos Revillo

Thursday 24 April 2008 5:34:27 am

For this you will have to look at kernel/classes/ezrssexport.php

I suppose you're working with RSS 2.0 and not with RSS 1.0

So, you will have to look for fetchRSS2_0 function

there you will find

unset( $itemPubDate );
            $itemPubDate = $doc->createElement( 'pubDate', gmdate( 'D, d M Y H:i:s', $object->attribute( 'published' ) ) .' GMT' );

$object->attribute('published') is the date "printed" in the rss content.
you can change it to

 $dataMap = $object->dataMap();
  

and get the content of that field.

Greg Sanderson

Thursday 24 April 2008 5:57:13 am

Awesome - it is almost working. Thank you for your help so far. The items are now being sorted correctly but now there is a blank space where the date and time should be on the RSS feed (it is v2).

I have added this code:

$datamap = $object->dataMap();
// get the data_map of the object in order to access its publish date attribute

$publishdate = $datamap.publish_date.content.timestamp;
// the publish date the user entered as a timestamp

$itemPubDate = $doc->createElement( 'pubDate', gmdate( 'D, d M Y H:i', $publishdate|datetime ) .' GMT' );

... and commented out the $itemPubDate line that was there before. The items are now sorted correctly but the date and time is not shown. Am I accessing the time correctly? It is called publish_date.

Carlos Revillo

Thursday 24 April 2008 6:49:27 am

remember you're working now with php code. you cannot think the thinks you do in templates to get content work the same.
i mean, you'll get nothing in php if you use $dataMap.publish_date...

$dataMap is an array, so, for the fields you will have to ask for $dataMap["field"]

So, your code should be like

$dataMap = $object->dataMap(); // this is an array
$publish_date = $dataMap["publish_date"]->content() // this will result a ezdate object
$timestamp = $publish_date->timeStamp();
//and finally
$itemPubDate = $doc->createElement( 'pubDate', gmdate( 'D, d M Y H:i:s', $timestamp ) .' GMT' );

Greg Sanderson

Thursday 24 April 2008 7:05:19 am

Oh of course!

A very, very big thank you. That code works and the RSS now works perfectly.

Thank you!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.