diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-06-14 16:40:57 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-06-14 16:40:57 -0700 |
commit | 00fad54c0babfb0643c2ab9da98b4b74af84d466 (patch) | |
tree | a9f863c0139c2c2e5b7e4356e780f7aca37423c7 /modules | |
parent | 47bc53eb5c328254d431caebf8acfd2636969bb4 (diff) |
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.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/comment/helpers/comment_rss.php | 48 | ||||
-rw-r--r-- | modules/comment/views/comment.mrss.php | 34 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_rss.php | 28 | ||||
-rw-r--r-- | modules/rss/controllers/rss.php | 19 | ||||
-rw-r--r-- | modules/rss/helpers/rss.php | 6 | ||||
-rw-r--r-- | modules/rss/views/feed.mrss.php | 18 | ||||
-rw-r--r-- | modules/tag/helpers/tag_rss.php | 11 |
7 files changed, 82 insertions, 82 deletions
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"> <channel> <generator>gallery3</generator> - <title><?= p::clean($title) ?></title> - <link><?= $link ?></link> - <description><?= p::clean($description) ?></description> + <title><?= p::clean($feed->title) ?></title> + <link><?= $feed->uri ?></link> + <description><?= p::clean($feed->description) ?></description> <language>en-us</language> - <atom:link rel="self" href="<?= $feed_link ?>" type="application/rss+xml" /> + <atom:link rel="self" href="<?= $feed->uri ?>" type="application/rss+xml" /> <fh:complete/> - <? if (!empty($previous_page_link)): ?> - <atom:link rel="previous" href="<?= $previous_page_link ?>" type="application/rss+xml" /> + <? if (!empty($feed->previous_page_uri)): ?> + <atom:link rel="previous" href="<?= $feed->previous_page_uri ?>" type="application/rss+xml" /> <? endif ?> - <? if (!empty($next_page_link)): ?> - <atom:link rel="next" href="<?= $next_page_link ?>" type="application/rss+xml" /> + <? if (!empty($feed->next_page_uri)): ?> + <atom:link rel="next" href="<?= $feed->next_page_uri ?>" type="application/rss+xml" /> <? endif ?> <pubDate><?= $pub_date ?></pubDate> <lastBuildDate><?= $pub_date ?></lastBuildDate> - <? foreach ($children as $child): ?> + <? foreach ($feed->children as $child): ?> <item> - <title><?= p::clean($child["title"]) ?></title> - <link><?= p::clean($child["item_link"]) ?></link> - <author><?= p::clean($child["author"]) ?></author> - <guid isPermaLink="true"><?= $child["item_link"] ?></guid> - <pubDate><?= $child["pub_date"] ?></pubDate> + <title><?= p::clean($child->title) ?></title> + <link><?= p::clean($child->item_uri) ?></link> + <author><?= p::clean($child->author) ?></author> + <guid isPermaLink="true"><?= $child->item_uri ?></guid> + <pubDate><?= $child->pub_date ?></pubDate> <content:encoded> <![CDATA[ - <p><?= p::clean($child["text"]) ?></p> + <p><?= p::clean($child->text) ?></p> <p> - <img alt="" src="<?= $child["thumb_url"] ?>" - height="<?= $child["thumb_height"] ?>" width="<?= $child["thumb_width"] ?>" /> + <img alt="" src="<?= $child->thumb_url ?>" + height="<?= $child->thumb_height ?>" width="<?= $child->thumb_width ?>" /> <br /> </p> ]]> 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"> <channel> <generator>gallery3</generator> - <title><?= p::clean($title) ?></title> - <link><?= $link ?></link> - <description><?= p::clean($description) ?></description> + <title><?= p::clean($feed->title) ?></title> + <link><?= $feed->uri ?></link> + <description><?= p::clean($feed->description) ?></description> <language>en-us</language> - <atom:link rel="self" href="<?= $feed_link ?>" type="application/rss+xml" /> + <atom:link rel="self" href="<?= $feed->uri ?>" type="application/rss+xml" /> <fh:complete/> - <? if (!empty($previous_page_link)): ?> - <atom:link rel="previous" href="<?= $previous_page_link ?>" type="application/rss+xml" /> + <? if (!empty($feed->previous_page_uri)): ?> + <atom:link rel="previous" href="<?= $feed->previous_page_uri ?>" type="application/rss+xml" /> <? endif ?> - <? if (!empty($next_page_link)): ?> - <atom:link rel="next" href="<?= $next_page_link ?>" type="application/rss+xml" /> + <? if (!empty($feed->next_page_uri)): ?> + <atom:link rel="next" href="<?= $feed->next_page_uri ?>" type="application/rss+xml" /> <? endif ?> <pubDate><?= $pub_date ?></pubDate> <lastBuildDate><?= $pub_date ?></lastBuildDate> - <? foreach ($children as $child): ?> + <? foreach ($feed->children as $child): ?> <item> <title><?= p::clean($child->title) ?></title> <link><?= url::abs_site("{$child->type}s/{$child->id}") ?></link> 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; } |