From 484796e7cc54c3690462ee061850b563c4d5da16 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 14 Jun 2009 11:39:53 -0700 Subject: Remove rss:item_feed, rss::tag_fead and rss_theme::head and move that functionality in the _theme::head function. Created rss::feed_link to wrap the module supplied uri in the html link element. --- modules/tag/helpers/tag_theme.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag_theme.php b/modules/tag/helpers/tag_theme.php index a32d71b6..45f55986 100644 --- a/modules/tag/helpers/tag_theme.php +++ b/modules/tag/helpers/tag_theme.php @@ -20,7 +20,11 @@ class tag_theme_Core { static function head($theme) { $url = url::file("modules/tag/js/tag.js"); - return ""; + $head[] = ""; + if ($theme->tag() && module::is_active("rss")) { + $head[] = rss::feed_link("tags/{$theme->tag()->id}"); + } + return implode("\n", $head); } static function sidebar_blocks($theme) { -- cgit v1.2.3 From 76b89556fc138dce694178fab9140a8242ea40ec Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 14 Jun 2009 12:09:47 -0700 Subject: Remove the sidebar flag from the feed definition returned by available_feeds and replace with a type field with one of two values (head and block). We need to do this to determine what fields go in the rss block so we can ignore the definitions that are related to the page head when creating the rss block that goes into the sidebar. --- modules/comment/helpers/comment_rss.php | 4 ++-- modules/gallery/helpers/gallery_rss.php | 4 ++-- modules/rss/helpers/rss.php | 7 +++---- modules/tag/helpers/tag_rss.php | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php index b191c326..2e958eef 100644 --- a/modules/comment/helpers/comment_rss.php +++ b/modules/comment/helpers/comment_rss.php @@ -21,10 +21,10 @@ class comment_rss_Core { static function available_feeds($item) { return array(array("description" => t("All new comments"), - "sidebar" => true, + "type" => "block", "uri" => "comments"), array("description" => sprintf(t("Comments on %s"), $item->title), - "sidebar" => true, + "type" => "block", "uri" => "comments/{$item->id}")); } diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index 6e722ff6..455e210f 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -21,10 +21,10 @@ class gallery_rss_Core { static function available_feeds($item) { return array(array("description" => t("New photos or movies"), - "sidebar" => true, + "type" => "block", "uri" => "updates"), array("description" => t("Album feed"), - "sidebar" => false, + "type" => "head", "uri" => "albums")); } diff --git a/modules/rss/helpers/rss.php b/modules/rss/helpers/rss.php index e4d6f5e9..403ee225 100644 --- a/modules/rss/helpers/rss.php +++ b/modules/rss/helpers/rss.php @@ -27,16 +27,15 @@ class rss_Core { /** * Get all available rss feeds */ - static function available_feeds($item, $sidebar_only=true) { + static function available_feeds($item) { $feeds = array(); foreach (module::active() as $module) { $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 ($sidebar_only && !$feed["sidebar"]) { - continue; + if ($feed["type"] == "block") { + $feeds[$feed["description"]] = url::site("rss/feed/{$feed['uri']}"); } - $feeds[$feed["description"]] = url::site("rss/feed/{$feed['uri']}"); } } } diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php index ace7fd6a..7846edf6 100644 --- a/modules/tag/helpers/tag_rss.php +++ b/modules/tag/helpers/tag_rss.php @@ -21,7 +21,7 @@ class tag_rss_Core { static function available_feeds($item) { return array(array("description" => t("Tag Album feed"), - "sidebar" => false, + "type" => "head", "uri" => "tags")); } -- cgit v1.2.3 From 8b7f7a2fbe30c8e17f60177db7f371e1d1f2152c Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 14 Jun 2009 12:38:57 -0700 Subject: Don't use stdClass to return the feed data. Just use an array. --- modules/comment/helpers/comment_rss.php | 15 +++++++-------- modules/gallery/helpers/gallery_rss.php | 22 ++++++++++------------ modules/rss/controllers/rss.php | 14 +++++++++----- modules/tag/helpers/tag_rss.php | 11 +++++------ 4 files changed, 31 insertions(+), 31 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php index 2e958eef..56de4284 100644 --- a/modules/comment/helpers/comment_rss.php +++ b/modules/comment/helpers/comment_rss.php @@ -29,7 +29,6 @@ class comment_rss_Core { } static function comments($offset, $limit, $id) { - $feed = new stdClass(); $orm = ORM::factory("comment") ->where("state", "published") ->orderby("created", "DESC"); @@ -37,12 +36,12 @@ class comment_rss_Core { $orm->where("item_id", $id); } - $feed->view = "comment.mrss"; + $feed["view"] = "comment.mrss"; $comments = $orm->find_all($limit, $offset); - $feed->data["children"] = array(); + $feed["children"] = array(); foreach ($comments as $comment) { $item = $comment->item(); - $feed->data["children"][] = array( + $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(), @@ -55,10 +54,10 @@ class comment_rss_Core { ); } - $feed->max_pages = ceil($comments->count() / $limit); - $feed->data["title"] = htmlspecialchars(t("Recent Comments")); - $feed->data["link"] = url::abs_site("albums/" . (empty($id) ? "1" : $id)); - $feed->data["description"] = t("Recent Comments"); + $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"); return $feed; } diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index 455e210f..6535d29d 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -29,16 +29,15 @@ class gallery_rss_Core { } static function updates($offset, $limit) { - $feed = new stdClass(); - $feed->data["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->data["children"]->count() / $limit); - $feed->data["title"] = t("Recent Updates"); - $feed->data["link"] = url::abs_site("albums/1"); - $feed->data["description"] = t("Recent Updates"); + $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"); return $feed; } @@ -47,14 +46,13 @@ class gallery_rss_Core { $item = ORM::factory("item", $id); access::required("view", $item); - $feed = new stdClass(); - $feed->data["children"] = $item + $feed["children"] = $item ->viewable() ->descendants($limit, $offset, "photo"); - $feed->max_pages = ceil($item->viewable()->descendants_count("photo") / $limit); - $feed->data["title"] = $item->title; - $feed->data["link"] = url::abs_site("albums/{$item->id}"); - $feed->data["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 8c3544e4..80803dfd 100644 --- a/modules/rss/controllers/rss.php +++ b/modules/rss/controllers/rss.php @@ -28,12 +28,16 @@ class Rss_Controller extends Controller { } $feed = rss::feed_data($method, ($page - 1) * self::$page_size, self::$page_size, $id); - if ($feed->max_pages && $page > $feed->max_pages) { - url::redirect("$feed_uri?page={$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); - foreach ($feed->data as $field => $value) { + $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); @@ -43,7 +47,7 @@ class Rss_Controller extends Controller { $view->previous_page_link = url::site("$feed_uri?page={$previous_page}"); } - if ($page < $feed->max_pages) { + if ($page < $max_pages) { $next_page = $page + 1; $view->next_page_link = url::site("$feed_uri?page={$next_page}"); } diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php index 7846edf6..3d6399ca 100644 --- a/modules/tag/helpers/tag_rss.php +++ b/modules/tag/helpers/tag_rss.php @@ -31,12 +31,11 @@ class tag_rss_Core { return Kohana::show_404(); } - $feed = new stdClass(); - $feed->data["children"] = $tag->items($limit, $offset, "photo"); - $feed->max_pages = ceil($tag->count / $limit); - $feed->data["title"] = $tag->name; - $feed->data["link"] = url::abs_site("tags/{$tag->id}"); - $feed->data["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