From 00fad54c0babfb0643c2ab9da98b4b74af84d466 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Sun, 14 Jun 2009 16:40:57 -0700
Subject: Refactor feed code to use stdClass everywhere. Fix bugs in the
max-pages calculation code. Move feed related data into the $feed variable
and only pass that to the view.
---
modules/comment/helpers/comment_rss.php | 48 +++++++++++++++++----------------
modules/comment/views/comment.mrss.php | 34 +++++++++++------------
modules/gallery/helpers/gallery_rss.php | 28 ++++++++++---------
modules/rss/controllers/rss.php | 19 ++++++-------
modules/rss/helpers/rss.php | 6 ++---
modules/rss/views/feed.mrss.php | 18 ++++++-------
modules/tag/helpers/tag_rss.php | 11 ++++----
7 files changed, 82 insertions(+), 82 deletions(-)
(limited to 'modules')
diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php
index 56de4284..c3eb7b2b 100644
--- a/modules/comment/helpers/comment_rss.php
+++ b/modules/comment/helpers/comment_rss.php
@@ -21,43 +21,45 @@
class comment_rss_Core {
static function available_feeds($item) {
return array(array("description" => t("All new comments"),
- "type" => "block",
"uri" => "comments"),
array("description" => sprintf(t("Comments on %s"), $item->title),
- "type" => "block",
"uri" => "comments/{$item->id}"));
}
static function comments($offset, $limit, $id) {
- $orm = ORM::factory("comment")
+ $comments = ORM::factory("comment")
->where("state", "published")
->orderby("created", "DESC");
- if (!empty($id)) {
- $orm->where("item_id", $id);
+ if ($id) {
+ $comments->where("item_id", $id);
}
- $feed["view"] = "comment.mrss";
- $comments = $orm->find_all($limit, $offset);
- $feed["children"] = array();
+ $feed->view = "comment.mrss";
+ $comments = $comments->find_all($limit, $offset);
+ $feed->children = array();
foreach ($comments as $comment) {
$item = $comment->item();
- $feed["children"][] = array(
- "pub_date" => date("D, d M Y H:i:s T", $comment->created),
- "text" => htmlspecialchars($comment->text),
- "thumb_url" => $item->thumb_url(),
- "thumb_height" => $item->thumb_height,
- "thumb_width" => $item->thumb_width,
- "item_link" => htmlspecialchars(url::abs_site("{$item->type}s/$item->id")),
- "title" =>htmlspecialchars($item->title),
- "author" =>
- empty($comment->guest_name) ? $comment->author()->full_name : $comment->guest_name
- );
+ $feed->children[] = new ArrayObject(
+ array("pub_date" => date("D, d M Y H:i:s T", $comment->created),
+ "text" => $comment->text,
+ "thumb_url" => $item->thumb_url(),
+ "thumb_height" => $item->thumb_height,
+ "thumb_width" => $item->thumb_width,
+ "item_uri" => url::abs_site("{$item->type}s/$item->id"),
+ "title" => $item->title,
+ "author" => $comment->author_name()),
+ ArrayObject::ARRAY_AS_PROPS);
}
- $feed["max_pages"] = ceil($comments->count() / $limit);
- $feed["title"] = htmlspecialchars(t("Recent Comments"));
- $feed["link"] = url::abs_site("albums/" . (empty($id) ? "1" : $id));
- $feed["description"] = t("Recent Comments");
+ $all_comments = ORM::factory("comment")->where("state", "published");
+ if ($id) {
+ $all_comments->where("item_id", $id);
+ }
+
+ $feed->max_pages = ceil($all_comments->find_all()->count() / $limit);
+ $feed->title = htmlspecialchars(t("Recent Comments"));
+ $feed->uri = url::abs_site("albums/" . (empty($id) ? "1" : $id));
+ $feed->description = t("Recent Comments");
return $feed;
}
diff --git a/modules/comment/views/comment.mrss.php b/modules/comment/views/comment.mrss.php
index d2177026..4f520144 100644
--- a/modules/comment/views/comment.mrss.php
+++ b/modules/comment/views/comment.mrss.php
@@ -6,33 +6,33 @@
xmlns:fh="http://purl.org/syndication/history/1.0">
gallery3
- = p::clean($title) ?>
- = $link ?>
- = p::clean($description) ?>
+ = p::clean($feed->title) ?>
+ = $feed->uri ?>
+ = p::clean($feed->description) ?>
en-us
-
+
- if (!empty($previous_page_link)): ?>
-
+ if (!empty($feed->previous_page_uri)): ?>
+
endif ?>
- if (!empty($next_page_link)): ?>
-
+ if (!empty($feed->next_page_uri)): ?>
+
endif ?>
= $pub_date ?>
= $pub_date ?>
- foreach ($children as $child): ?>
+ foreach ($feed->children as $child): ?>
-
- = p::clean($child["title"]) ?>
- = p::clean($child["item_link"]) ?>
- = p::clean($child["author"]) ?>
- = $child["item_link"] ?>
- = $child["pub_date"] ?>
+ = p::clean($child->title) ?>
+ = p::clean($child->item_uri) ?>
+ = p::clean($child->author) ?>
+ = $child->item_uri ?>
+ = $child->pub_date ?>
= p::clean($child["text"]) ?>
+ = p::clean($child->text) ?>
-
"
- height="= $child["thumb_height"] ?>" width="= $child["thumb_width"] ?>" />
+
]]>
diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php
index 6535d29d..413d12a4 100644
--- a/modules/gallery/helpers/gallery_rss.php
+++ b/modules/gallery/helpers/gallery_rss.php
@@ -21,23 +21,27 @@
class gallery_rss_Core {
static function available_feeds($item) {
return array(array("description" => t("New photos or movies"),
- "type" => "block",
"uri" => "updates"),
array("description" => t("Album feed"),
- "type" => "head",
"uri" => "albums"));
}
static function updates($offset, $limit) {
- $feed["children"] = ORM::factory("item")
+ $feed->children = ORM::factory("item")
->viewable()
->where("type !=", "album")
->orderby("created", "DESC")
->find_all($limit, $offset);
- $feed["max_pages"] = ceil($feed["children"]->count() / $limit);
- $feed["title"] = t("Recent Updates");
- $feed["link"] = url::abs_site("albums/1");
- $feed["description"] = t("Recent Updates");
+
+ $all_children = ORM::factory("item")
+ ->viewable()
+ ->where("type !=", "album")
+ ->orderby("created", "DESC");
+
+ $feed->max_pages = ceil($all_children->find_all()->count() / $limit);
+ $feed->title = t("Recent Updates");
+ $feed->link = url::abs_site("albums/1");
+ $feed->description = t("Recent Updates");
return $feed;
}
@@ -46,13 +50,13 @@ class gallery_rss_Core {
$item = ORM::factory("item", $id);
access::required("view", $item);
- $feed["children"] = $item
+ $feed->children = $item
->viewable()
->descendants($limit, $offset, "photo");
- $feed["max_pages"] = ceil($item->viewable()->descendants_count("photo") / $limit);
- $feed["title"] = $item->title;
- $feed["link"] = url::abs_site("albums/{$item->id}");
- $feed["description"] = $item->description;
+ $feed->max_pages = ceil($item->viewable()->descendants_count("photo") / $limit);
+ $feed->title = $item->title;
+ $feed->link = url::abs_site("albums/{$item->id}");
+ $feed->description = $item->description;
return $feed;
}
diff --git a/modules/rss/controllers/rss.php b/modules/rss/controllers/rss.php
index 80803dfd..29300d58 100644
--- a/modules/rss/controllers/rss.php
+++ b/modules/rss/controllers/rss.php
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Rss_Controller extends Controller {
- public static $page_size = 30;
+ public static $page_size = 20;
public function feed($method, $id=null) {
$page = $this->input->get("page", 1);
@@ -28,28 +28,25 @@ class Rss_Controller extends Controller {
}
$feed = rss::feed_data($method, ($page - 1) * self::$page_size, self::$page_size, $id);
- $max_pages = $feed["max_pages"];
+ $max_pages = $feed->max_pages;
if ($max_pages && $page > $max_pages) {
url::redirect("$feed_uri?page={$max_pages}");
}
- unset($feed["max_pages"]);
- $view = new View(empty($feed["view"]) ? "feed.mrss" : $feed["view"]);
- unset($feed["view"]);
+ $view = new View(empty($feed->view) ? "feed.mrss" : $feed->view);
+ unset($feed->view);
- foreach ($feed as $field => $value) {
- $view->$field = $value;
- }
- $view->feed_link = url::abs_site($feed_uri);
+ $feed->uri = url::abs_site($feed_uri);
+ $view->feed = $feed;
if ($page > 1) {
$previous_page = $page - 1;
- $view->previous_page_link = url::site("$feed_uri?page={$previous_page}");
+ $feed->previous_page_uri = url::site("$feed_uri?page={$previous_page}");
}
if ($page < $max_pages) {
$next_page = $page + 1;
- $view->next_page_link = url::site("$feed_uri?page={$next_page}");
+ $feed->next_page_uri = url::site("$feed_uri?page={$next_page}");
}
$view->pub_date = date("D, d M Y H:i:s T");
diff --git a/modules/rss/helpers/rss.php b/modules/rss/helpers/rss.php
index 403ee225..8a7d0c97 100644
--- a/modules/rss/helpers/rss.php
+++ b/modules/rss/helpers/rss.php
@@ -33,9 +33,7 @@ class rss_Core {
$class_name = "{$module->name}_rss";
if (method_exists($class_name, "available_feeds")) {
foreach (call_user_func(array($class_name, "available_feeds"), $item) as $feed) {
- if ($feed["type"] == "block") {
- $feeds[$feed["description"]] = url::site("rss/feed/{$feed['uri']}");
- }
+ $feeds[$feed["description"]] = url::site("rss/feed/{$feed['uri']}");
}
}
}
@@ -43,7 +41,7 @@ class rss_Core {
return $feeds;
}
- static function feed_data($feed, $offset, $limit, $id) {
+ static function feed_data($method, $offset, $limit, $id) {
foreach (module::active() as $module) {
$class_name = "{$module->name}_rss";
if (method_exists($class_name, $feed)) {
diff --git a/modules/rss/views/feed.mrss.php b/modules/rss/views/feed.mrss.php
index 0beebbcf..447179a5 100644
--- a/modules/rss/views/feed.mrss.php
+++ b/modules/rss/views/feed.mrss.php
@@ -6,21 +6,21 @@
xmlns:fh="http://purl.org/syndication/history/1.0">
gallery3
- = p::clean($title) ?>
- = $link ?>
- = p::clean($description) ?>
+ = p::clean($feed->title) ?>
+ = $feed->uri ?>
+ = p::clean($feed->description) ?>
en-us
-
+
- if (!empty($previous_page_link)): ?>
-
+ if (!empty($feed->previous_page_uri)): ?>
+
endif ?>
- if (!empty($next_page_link)): ?>
-
+ if (!empty($feed->next_page_uri)): ?>
+
endif ?>
= $pub_date ?>
= $pub_date ?>
- foreach ($children as $child): ?>
+ foreach ($feed->children as $child): ?>
-
= p::clean($child->title) ?>
= url::abs_site("{$child->type}s/{$child->id}") ?>
diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php
index 3d6399ca..dbef3914 100644
--- a/modules/tag/helpers/tag_rss.php
+++ b/modules/tag/helpers/tag_rss.php
@@ -21,7 +21,6 @@
class tag_rss_Core {
static function available_feeds($item) {
return array(array("description" => t("Tag Album feed"),
- "type" => "head",
"uri" => "tags"));
}
@@ -31,11 +30,11 @@ class tag_rss_Core {
return Kohana::show_404();
}
- $feed["children"] = $tag->items($limit, $offset, "photo");
- $feed["max_pages"] = ceil($tag->count / $limit);
- $feed["title"] = $tag->name;
- $feed["link"] = url::abs_site("tags/{$tag->id}");
- $feed["description"] = t("Photos related to %tag_name", array("tag_name" => $tag->name));
+ $feed->children = $tag->items($limit, $offset, "photo");
+ $feed->max_pages = ceil($tag->count / $limit);
+ $feed->title = $tag->name;
+ $feed->link = url::abs_site("tags/{$tag->id}");
+ $feed->description = t("Photos related to %tag_name", array("tag_name" => $tag->name));
return $feed;
}
--
cgit v1.2.3