diff options
Diffstat (limited to 'modules/comment')
-rw-r--r-- | modules/comment/controllers/comments.php | 4 | ||||
-rw-r--r-- | modules/comment/helpers/comment.php | 61 |
2 files changed, 65 insertions, 0 deletions
diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index e4825a78..3838f7f0 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -74,6 +74,10 @@ class Comments_Controller extends REST_Controller { print json_encode($comment->as_array()); break; + case "atom": + rest::http_content_type(rest::ATOM); + break; + default: $v = new View("comment.$output_format"); $v->comment = $comment; diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php index 462300b8..e987456a 100644 --- a/modules/comment/helpers/comment.php +++ b/modules/comment/helpers/comment.php @@ -117,6 +117,11 @@ class comment_Core { } switch (rest::output_format()) { + case "atom": + rest::http_content_type(rest::ATOM); + print comment::get_atom_feed($comments); + break; + case "xml": rest::http_content_type(rest::XML); return xml::to_xml($comments, array("comments", "comment")); @@ -141,6 +146,62 @@ class comment_Core { } } + public static function get_atom_entry($comment) { + + } + + /* + * This is way too complicated and needs lots of cleanup, but it provides a valid feed. + * @todo Fix double slashes in some URIs. + * @todo Write Unix -> RFC3339 datetime conversion helper. + * @todo Abstract away as much code as possible. + * @todo Show photo title instead of photo ID. + * @todo Show comment numbers relative to current item, not its database ID. + */ + public static function get_atom_feed($comments) { + $latest_comment = 0; + $base_url = sprintf("http://%s%s", $_SERVER["HTTP_HOST"], url::base(true)); + $absoluteUrl = html::specialchars($base_url . url::current(true)); + + $feed = new Atom_Feed("feed"); + $feed->link() + ->rel("self") + ->href($absoluteUrl); + + foreach ($comments as $comment) { + if ($comment->datetime > $latest_comment) { + $latest_comment = $comment->datetime; + } + + $feed->entry() + ->id(sprintf("%s%scomments/%s", $base_url, url::site(), $comment->id)) + ->updated(date("Y-m-d\TH:i:s", $comment->datetime) . "Z") + ->title(sprintf(_("Comment #%d"), $comment->id)) + ->content($comment->text, "html") + ->author() + ->name($comment->author) + ->email($comment->email) + ->uri(sprintf("%s%susers/%s", $base_url, url::site(), $comment->id)); + } + $item_id = $comment->item_id; + + $feed->id($absoluteUrl) + ->title(sprintf(_("Comments on photo %d"), $item_id), "text") + ->updated(date("Y-m-d\TH:i:s", $latest_comment) . "Z"); + $feed->link() + ->rel("related") + ->type("application/atom+xml") + ->title(_("Get photo meta data")) + ->href(sprintf("%s%sphotos/%s", $base_url, url::site(), $item_id)); + $feed->link() + ->rel("related") + ->type("image/jpeg") + ->title("Download photo") + ->href(sprintf("%s%sphotos/%s", $base_url, url::site(), $item_id)); + + return $feed->as_xml(); + } + /** * Format a human-friendly message showing the amount of time elapsed since the specified * timestamp (e.g. 'said today', 'said yesterday', 'said 13 days ago', 'said 5 months ago'). |