Closed tonylisanti closed 11 years ago
Looks like the date within the feed(s) needs to be a timestamp in order for the sort to work correctly but I'm not 100% sure.
Weird, it should be cast to a timestamp: https://github.com/milesj/cake-utility/blob/master/Model/Datasource/FeedSource.php#L313
I will look into this.
Actually, I think there may be an issue with the sorting on lines 162-166 in FeedSource.php that causing the issue.
I'm a novice but I changed it to the below and it seems to work. Not sure if this is the issue though:
uksort($results, array($this, 'cmp'));
if ($query['feed']['order'] == 'DESC') {
$results = array_reverse($results);
}
/*
if ($query['feed']['order'] == 'ASC') {
krsort($results);
} else {
ksort($results);
}
*/
if ($cache) {
Cache::set(array('duration' => $query['feed']['expires']));
Cache::write($cache, $results, 'feeds');
}
}
return $this->_truncate($results, $query['limit']);
}
return array();
}
function cmp($a, $b) {
$a = strtotime($a);
$b = strtotime($b);
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
Pushed some changes in RC3.
Tested just now with no problems. Release 1.3.0.
I'm not able to get the sort order for the feeds to work. For some reason, maybe i'm doing something wrong, the feeds never order by date. It looks like it orders within the month correctly but the months and years are not.
I have this in my controller:
And this is the result I'm getting:
array( 'Fri, 03 Aug 2012 11:59:24 EDT' => array( 'title' => 'An open letter to texting-mad teenagers', 'guid' => 'http://www.cnn.com/2012/08/01/tech/netiquette-open-letter-teenagers/index.html', 'date' => 'Fri, 03 Aug 2012 11:59:24 EDT', 'link' => 'http://rss.cnn.com/~r/rss/cnn_tech/~3/mFKZeL3oHyM/index.html', 'description' => 'Put your phone down for a second, teen texters -- there are some things you've got to hear.
Any help would be greatly appreciated.
Thanks