diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-06-12 12:00:20 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-06-12 12:00:20 -0700 |
commit | 1406cb7c0fc401b530c10286aa26434a92a2b113 (patch) | |
tree | fd12da0853060f134bdaa5cb4be87a6b3879ffb4 | |
parent | 6749a835e71826d4f8cffb0d859edc0e2b4e6b96 (diff) | |
parent | 30bdaa81233fc2904367cd39017597b33f05efa9 (diff) |
Merge branch 'master' of git@github.com:gallery/gallery3
-rw-r--r-- | modules/comment/helpers/comment_rss.php | 65 | ||||
-rw-r--r-- | modules/comment/views/comment.mrss.php (renamed from modules/rss/views/comment.mrss.php) | 0 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_rss.php | 61 | ||||
-rw-r--r-- | modules/rss/controllers/rss.php | 175 | ||||
-rw-r--r-- | modules/rss/helpers/rss.php | 29 | ||||
-rw-r--r-- | modules/rss/helpers/rss_theme.php | 12 | ||||
-rw-r--r-- | modules/tag/helpers/tag_rss.php | 43 |
7 files changed, 214 insertions, 171 deletions
diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php new file mode 100644 index 00000000..b191c326 --- /dev/null +++ b/modules/comment/helpers/comment_rss.php @@ -0,0 +1,65 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 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 comment_rss_Core { + static function available_feeds($item) { + return array(array("description" => t("All new comments"), + "sidebar" => true, + "uri" => "comments"), + array("description" => sprintf(t("Comments on %s"), $item->title), + "sidebar" => true, + "uri" => "comments/{$item->id}")); + } + + static function comments($offset, $limit, $id) { + $feed = new stdClass(); + $orm = ORM::factory("comment") + ->where("state", "published") + ->orderby("created", "DESC"); + if (!empty($id)) { + $orm->where("item_id", $id); + } + + $feed->view = "comment.mrss"; + $comments = $orm->find_all($limit, $offset); + $feed->data["children"] = array(); + foreach ($comments as $comment) { + $item = $comment->item(); + $feed->data["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->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"); + + return $feed; + } +}
\ No newline at end of file diff --git a/modules/rss/views/comment.mrss.php b/modules/comment/views/comment.mrss.php index d2177026..d2177026 100644 --- a/modules/rss/views/comment.mrss.php +++ b/modules/comment/views/comment.mrss.php diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php new file mode 100644 index 00000000..6e722ff6 --- /dev/null +++ b/modules/gallery/helpers/gallery_rss.php @@ -0,0 +1,61 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 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 gallery_rss_Core { + static function available_feeds($item) { + return array(array("description" => t("New photos or movies"), + "sidebar" => true, + "uri" => "updates"), + array("description" => t("Album feed"), + "sidebar" => false, + "uri" => "albums")); + } + + static function updates($offset, $limit) { + $feed = new stdClass(); + $feed->data["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"); + + return $feed; + } + + static function albums($offset, $limit, $id) { + $item = ORM::factory("item", $id); + access::required("view", $item); + + $feed = new stdClass(); + $feed->data["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; + + return $feed; + } +} diff --git a/modules/rss/controllers/rss.php b/modules/rss/controllers/rss.php index 1f8b8a4e..164803cb 100644 --- a/modules/rss/controllers/rss.php +++ b/modules/rss/controllers/rss.php @@ -20,185 +20,38 @@ class Rss_Controller extends Controller { public static $page_size = 30; - public function albums($id) { - $item = ORM::factory("item", $id); - access::required("view", $item); - + public function __call($method, $arguments) { + $id = empty($arguments) ? null : $arguments[0]; $page = $this->input->get("page", 1); + $feed_uri = "rss/$method" . (empty($id) ? "" : "/$id"); if ($page < 1) { - url::redirect("rss/albums/{$item->id}"); - } - - $children = $item - ->viewable() - ->descendants(self::$page_size, ($page - 1) * self::$page_size, "photo"); - $max_pages = ceil($item->viewable()->descendants_count("photo") / self::$page_size); - - if ($max_pages && $page > $max_pages) { - url::redirect("rss/albums/{$item->id}?page=$max_pages"); - } - - $view = new View("feed.mrss"); - $view->title = $item->title; - $view->link = url::abs_site("albums/{$item->id}"); - $view->description = $item->description; - $view->feed_link = url::abs_site("rss/albums/{$item->id}"); - $view->children = $children; - - if ($page > 1) { - $previous_page = $page - 1; - $view->previous_page_link = url::site("rss/albums/{$item->id}?page={$previous_page}"); + url::redirect($feed_uri); } - if ($page < $max_pages) { - $next_page = $page + 1; - $view->next_page_link = url::site("rss/albums/{$item->id}?page={$next_page}"); + $feed = rss::process_feed($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}"); } - // @todo do we want to add an upload date to the items table? - $view->pub_date = date("D, d M Y H:i:s T"); - - rest::http_content_type(rest::RSS); - print $view; - } - - public function updates() { - $page = $this->input->get("page", 1); - if ($page < 1) { - url::redirect("rss/updates"); + $view = new View(empty($feed->view) ? "feed.mrss" : $feed->view); + foreach ($feed->data as $field => $value) { + $view->$field = $value; } - - $items = ORM::factory("item") - ->viewable() - ->where("type !=", "album") - ->orderby("created", "DESC") - ->find_all(self::$page_size, ($page - 1) * self::$page_size); - $max_pages = ceil($items->count() / self::$page_size); - - if ($max_pages && $page > $max_pages) { - url::redirect("rss/updates?page=$max_pages"); - } - - $view = new View("feed.mrss"); - $view->title = t("Recent Updates"); - $view->link = url::abs_site("albums/1"); - $view->description = t("Recent Updates"); - $view->feed_link = url::abs_site("rss/updates"); - $view->children = $items; + $view->feed_link = url::abs_site($feed_uri); if ($page > 1) { $previous_page = $page - 1; - $view->previous_page_link = url::site("rss/updates?page={$previous_page}"); + $view->previous_page_link = url::site("$feed_uri?page={$previous_page}"); } - if ($page < $max_pages) { + if ($page < $feed->max_pages) { $next_page = $page + 1; - $view->next_page_link = url::site("rss/updates?page={$next_page}"); + $view->next_page_link = url::site("$feed_uri?page={$next_page}"); } - // @todo do we want to add an upload date to the items table? $view->pub_date = date("D, d M Y H:i:s T"); rest::http_content_type(rest::RSS); print $view; } - - public function tags($id) { - $tag = ORM::factory("tag", $id); - if (!$tag->loaded) { - return Kohana::show_404(); - } - - $page = $this->input->get("page", 1); - if ($page < 1) { - url::redirect("rss/tags/{$tag->id}"); - } - - $children = $tag->items(self::$page_size, ($page - 1) * self::$page_size, "photo"); - $max_pages = ceil($tag->count / self::$page_size); - - if ($max_pages && $page > $max_pages) { - url::redirect("rss/tags/{$tag->id}?page=$max_pages"); - } - - $view = new View("feed.mrss"); - $view->title = $tag->name; - $view->link = url::abs_site("tags/{$tag->id}"); - $view->description = t("Photos related to %tag_name", array("tag_name" => $tag->name)); - $view->feed_link = url::abs_site("rss/tags/{$tag->id}"); - $view->children = $children; - - if ($page > 1) { - $previous_page = $page - 1; - $view->previous_page_link = url::site("rss/tags/{$tag->id}?page={$previous_page}"); - } - - if ($page < $max_pages) { - $next_page = $page + 1; - $view->next_page_link = url::site("rss/tags/{$tag->id}?page={$next_page}"); - } - - // @todo do we want to add an upload date to the items table? - $view->pub_date = date("D, d M Y H:i:s T"); - - rest::http_content_type(rest::RSS); - print $view; - } - - public function comments($id=null) { - $page = $this->input->get("page", 1); - if ($page < 1) { - url::redirect("rss/comments/$id"); - } - - $orm = ORM::factory("comment") - ->where("state", "published") - ->orderby("created", "DESC"); - if (!empty($id)) { - $orm->where("item_id", $id); - } - - $comments = $orm->find_all(self::$page_size, ($page - 1) * self::$page_size); - $max_pages = ceil($orm->count_last_query() / self::$page_size); - - if ($max_pages && $page > $max_pages) { - url::redirect("rss/comments/{$item->id}?page=$max_pages"); - } - - $view = new View("comment.mrss"); - $view->title = htmlspecialchars(t("Recent Comments")); - $view->link = url::abs_site("albums/1"); - $view->description = t("Recent Comments"); - $view->feed_link = url::abs_site("rss/comments"); - $view->pub_date = date("D, d M Y H:i:s T"); - - $view->children = array(); - foreach ($comments as $comment) { - $item = $comment->item(); - $view->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 - ); - } - - if ($page > 1) { - $previous_page = $page - 1; - $view->previous_page_link = url::site("rss/comments/{$item->id}?page={$previous_page}"); - } - - if ($page < $max_pages) { - $next_page = $page + 1; - $view->next_page_link = url::site("rss/comments/{$item->id}?page={$next_page}"); - } - - rest::http_content_type(rest::RSS); - print $view; - } }
\ No newline at end of file diff --git a/modules/rss/helpers/rss.php b/modules/rss/helpers/rss.php index b320aeae..1d30425f 100644 --- a/modules/rss/helpers/rss.php +++ b/modules/rss/helpers/rss.php @@ -27,4 +27,33 @@ class rss_Core { static function tag_feed($tag) { return url::site("rss/tags/$tag->id}"); } + + /** + * Get all available rss feeds + */ + static function get_feeds($item, $sidebar_only=true) { + $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; + } + $feeds[$feed["description"]] = url::site("rss/{$feed['uri']}"); + } + } + } + + return $feeds; + } + + static function process_feed($feed, $offset, $limit, $id) { + foreach (module::active() as $module) { + $class_name = "{$module->name}_rss"; + if (method_exists($class_name, $feed)) { + return call_user_func(array($class_name, $feed), $offset, $limit, $id); + } + } + } }
\ No newline at end of file diff --git a/modules/rss/helpers/rss_theme.php b/modules/rss/helpers/rss_theme.php index 54bba210..b82133bd 100644 --- a/modules/rss/helpers/rss_theme.php +++ b/modules/rss/helpers/rss_theme.php @@ -40,16 +40,8 @@ class rss_theme_Core { $block->css_id = "gRss"; $block->title = t("Available RSS Feeds"); $block->content = new View("rss_block.html"); - // @todo consider pushing the code for the feeds back to the associated modules - // and create an event 'generate_rss_feeds' that modules can respond to create - // the list of feeds. - $feeds = array(t("New photos or movies") => url::site("rss/updates")); - if (module::is_active("comment")) { - $feeds[t("All new comments")] = url::site("rss/comments"); - $feeds[sprintf(t("Comments on %s"), $theme->item()->title)] = - url::site("rss/comments/{$theme->item()->id}"); - } - $block->content->feeds = $feeds; + $block->content->feeds = rss::get_feeds($theme->item()); + return $block; } } diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php new file mode 100644 index 00000000..ace7fd6a --- /dev/null +++ b/modules/tag/helpers/tag_rss.php @@ -0,0 +1,43 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 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 tag_rss_Core { + static function available_feeds($item) { + return array(array("description" => t("Tag Album feed"), + "sidebar" => false, + "uri" => "tags")); + } + + static function tags($offset, $limit, $id) { + $tag = ORM::factory("tag", $id); + if (!$tag->loaded) { + 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)); + + return $feed; + } +} |