function get_comments($params = array())
{
$comments = null;
$comments_count = null;
// Assign self link.
$self = '';
// Assign alternate link.
$alternate = '';
$updated = DateTime::create();
// Check if this is a feed for a single post
if (isset($params['slug']) || isset($params['id'])) {
if (isset($params['slug'])) {
$post = Post::get(array('slug' => $params['slug']));
} elseif (isset($params['id'])) {
$post = Post::get(array('id' => $params['id']));
}
// If the post doesn't exist, send a 404
if (!$post instanceof Post) {
header('HTTP/1.1 404 Not Found', true, 404);
die('The post could not be found');
}
$comments = $post->comments->approved;
$comments_count = count($comments);
$content_type = Post::type_name($post->content_type);
$self = URL::get("atom_feed_{$content_type}_comments", $post, false);
$alternate = URL::get("display_{$content_type}", $post, false);
if ($comments_count) {
$updated = $comments[$comments_count - 1]->date;
}
} else {
$self = URL::get('atom_feed_comments');
$alternate = URL::get('display_home');
$params['status'] = 'approved';
$comments = Comments::get($params);
$comments_count = Comments::count_total(Comment::status('approved'));
if ($comments_count) {
$updated = $comments[0]->date;
}
}
$id = isset($params['slug']) ? $params['slug'] : 'atom_comments';
$xml = $this->create_atom_wrapper($alternate, $self, $id, $updated);
$xml = $this->add_pagination_links($xml, $comments_count);
$xml = $this->add_comments($xml, $comments);
Plugins::act('atom_get_comments', $xml, $params, $this->handler_vars);
$xml = $xml->asXML();
ob_clean();
header('Content-Type: application/atom+xml');
print $xml;
}