summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/atom/helpers/atom.php52
-rw-r--r--modules/atom/libraries/Atom_Author.php1
-rw-r--r--modules/atom/libraries/Atom_Base.php1
-rw-r--r--modules/atom/libraries/Atom_Entry.php1
-rw-r--r--modules/atom/libraries/Atom_Feed.php1
-rw-r--r--modules/atom/libraries/Atom_Link.php1
-rw-r--r--modules/comment/controllers/comments.php6
-rw-r--r--modules/comment/helpers/comment.php50
8 files changed, 98 insertions, 15 deletions
diff --git a/modules/atom/helpers/atom.php b/modules/atom/helpers/atom.php
new file mode 100644
index 00000000..fed15eb7
--- /dev/null
+++ b/modules/atom/helpers/atom.php
@@ -0,0 +1,52 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+class atom_Core {
+
+ /**
+ * Converts a Unix timestamp to an Internet timestamp as defined in RFC3339.
+ * http://www.ietf.org/rfc/rfc3339.txt
+ *
+ * @todo Check if time zone is correct.
+ * @todo Write test.
+ *
+ * @param int Unix timestamp
+ * @return string Internet timestamp
+ */
+ public static function unix_to_internet_timestamp($timestamp) {
+ return sprintf("%sZ", date("Y-m-d\TH:i:s", $timestamp));
+ }
+
+ /**
+ *
+ */
+ public static function get_absolute_url() {
+ $base_url = atom::get_base_url();
+ $absolute_url = html::specialchars($base_url . url::current(true));
+ return $absolute_url;
+ }
+
+ /**
+ *
+ */
+ public static function get_base_url() {
+ return sprintf("http://%s%s", $_SERVER["HTTP_HOST"], url::base(true));
+ }
+}
diff --git a/modules/atom/libraries/Atom_Author.php b/modules/atom/libraries/Atom_Author.php
index ec3c61aa..3ee4df41 100644
--- a/modules/atom/libraries/Atom_Author.php
+++ b/modules/atom/libraries/Atom_Author.php
@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
class Atom_Author_Core extends Atom_Base {
public function name($name) {
$this->element->appendChild($this->dom->createElement("name", $name));
diff --git a/modules/atom/libraries/Atom_Base.php b/modules/atom/libraries/Atom_Base.php
index bf115033..0cb33b0b 100644
--- a/modules/atom/libraries/Atom_Base.php
+++ b/modules/atom/libraries/Atom_Base.php
@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
class Atom_Base_Core {
protected $dom;
protected $element;
diff --git a/modules/atom/libraries/Atom_Entry.php b/modules/atom/libraries/Atom_Entry.php
index d566f49b..345755c2 100644
--- a/modules/atom/libraries/Atom_Entry.php
+++ b/modules/atom/libraries/Atom_Entry.php
@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
class Atom_Entry_Core extends Atom_Base {
public function id($id) {
$this->element->appendChild($this->dom->createElement("id", $id));
diff --git a/modules/atom/libraries/Atom_Feed.php b/modules/atom/libraries/Atom_Feed.php
index 0b667e88..8efeb4f2 100644
--- a/modules/atom/libraries/Atom_Feed.php
+++ b/modules/atom/libraries/Atom_Feed.php
@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
class Atom_Feed_Core extends Atom_Base {
public function id($id) {
$this->element->appendChild($this->dom->createElement("id", $id));
diff --git a/modules/atom/libraries/Atom_Link.php b/modules/atom/libraries/Atom_Link.php
index 5fff30f2..723675c1 100644
--- a/modules/atom/libraries/Atom_Link.php
+++ b/modules/atom/libraries/Atom_Link.php
@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
class Atom_Link_Core extends Atom_Base {
public function rel($rel) {
$this->element->setAttribute("rel", $rel);
diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php
index 3838f7f0..989ad177 100644
--- a/modules/comment/controllers/comments.php
+++ b/modules/comment/controllers/comments.php
@@ -62,8 +62,7 @@ class Comments_Controller extends REST_Controller {
* @see Rest_Controller::_show($resource)
*/
public function _show($comment) {
- $output_format = rest::output_format();
- switch ($output_format) {
+ switch (rest::output_format()) {
case "xml":
rest::http_content_type(rest::XML);
print xml::to_xml($comment->as_array(), array("comment"));
@@ -75,7 +74,8 @@ class Comments_Controller extends REST_Controller {
break;
case "atom":
- rest::http_content_type(rest::ATOM);
+ rest::http_content_type(rest::XML);
+ print comment::get_atom_entry($comment);
break;
default:
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php
index e987456a..2e4b732a 100644
--- a/modules/comment/helpers/comment.php
+++ b/modules/comment/helpers/comment.php
@@ -118,7 +118,7 @@ class comment_Core {
switch (rest::output_format()) {
case "atom":
- rest::http_content_type(rest::ATOM);
+ rest::http_content_type(rest::XML);
print comment::get_atom_feed($comments);
break;
@@ -147,26 +147,52 @@ class comment_Core {
}
public static function get_atom_entry($comment) {
+ $base_url = atom::get_base_url();
+ $absolute_url = atom::get_absolute_url();
+ $feed = new Atom_Entry("entry");
+ $feed->id($absolute_url)
+ ->updated(atom::unix_to_internet_timestamp($comment->datetime))
+ ->title(sprintf(_("Comment #%d"), $comment->id))
+ ->content($comment->text, "html")
+ ->author()
+ ->name($comment->author)
+ ->email($comment->email)
+ ->uri(sprintf("%susers/%s", $base_url, $comment->id));
+ $feed->link()
+ ->rel("self")
+ ->href($absolute_url);
+ $feed->link()
+ ->rel("related")
+ ->type("application/atom+xml")
+ ->title(_("Get photo meta data"))
+ ->href(sprintf("%sphotos/%s", $base_url, $comment->item_id));
+ $feed->link()
+ ->rel("related")
+ ->type("image/jpeg")
+ ->title("Download photo")
+ ->href(sprintf("%sphotos/%s", $base_url, $comment->item_id));
+
+ return $feed->as_xml();
}
/*
* 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.
+ * @todo Put proper user ID into author URI.
*/
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));
+ $base_url = atom::get_base_url();
+ $absolute_url = atom::get_absolute_url();
$feed = new Atom_Feed("feed");
$feed->link()
->rel("self")
- ->href($absoluteUrl);
+ ->href($absolute_url);
foreach ($comments as $comment) {
if ($comment->datetime > $latest_comment) {
@@ -174,30 +200,30 @@ class comment_Core {
}
$feed->entry()
- ->id(sprintf("%s%scomments/%s", $base_url, url::site(), $comment->id))
- ->updated(date("Y-m-d\TH:i:s", $comment->datetime) . "Z")
+ ->id(sprintf("%scomments/%s", atom::get_base_url(), $comment->id))
+ ->updated(atom::unix_to_internet_timestamp($comment->datetime))
->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));
+ ->uri(sprintf("%susers/%s", atom::get_base_url(), $comment->id));
}
$item_id = $comment->item_id;
- $feed->id($absoluteUrl)
+ $feed->id($absolute_url)
->title(sprintf(_("Comments on photo %d"), $item_id), "text")
- ->updated(date("Y-m-d\TH:i:s", $latest_comment) . "Z");
+ ->updated(atom::unix_to_internet_timestamp($latest_comment));
$feed->link()
->rel("related")
->type("application/atom+xml")
->title(_("Get photo meta data"))
- ->href(sprintf("%s%sphotos/%s", $base_url, url::site(), $item_id));
+ ->href(sprintf("%sphotos/%s", atom::get_base_url(), $item_id));
$feed->link()
->rel("related")
->type("image/jpeg")
->title("Download photo")
- ->href(sprintf("%s%sphotos/%s", $base_url, url::site(), $item_id));
+ ->href(sprintf("%sphotos/%s", atom::get_base_url(), $item_id));
return $feed->as_xml();
}