summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/comment/helpers/comment_rss.php84
-rw-r--r--modules/gallery/helpers/gallery_rss.php75
-rw-r--r--modules/gallery/helpers/gallery_theme.php4
-rw-r--r--modules/rss/controllers/rss.php38
-rw-r--r--modules/rss/helpers/rss.php34
-rw-r--r--modules/rss/helpers/rss_theme.php19
-rw-r--r--modules/rss/views/rss_block.html.php4
-rw-r--r--modules/slideshow/helpers/slideshow_theme.php12
-rw-r--r--modules/tag/helpers/tag_rss.php35
9 files changed, 161 insertions, 144 deletions
diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php
index c3eb7b2b..afcc275c 100644
--- a/modules/comment/helpers/comment_rss.php
+++ b/modules/comment/helpers/comment_rss.php
@@ -19,48 +19,60 @@
*/
class comment_rss_Core {
- static function available_feeds($item) {
- return array(array("description" => t("All new comments"),
- "uri" => "comments"),
- array("description" => sprintf(t("Comments on %s"), $item->title),
- "uri" => "comments/{$item->id}"));
+ static function available_feeds($item, $tag) {
+ $feeds["comment/newest"] = t("All new comments");
+ if ($item) {
+ $feeds["comment/item/$item->id"] =
+ t("Comments on %title", array("title" => p::clean($item->title)));
+ }
+ return $feeds;
}
- static function comments($offset, $limit, $id) {
- $comments = ORM::factory("comment")
- ->where("state", "published")
- ->orderby("created", "DESC");
- if ($id) {
- $comments->where("item_id", $id);
- }
+ static function feed($feed_id, $offset, $limit, $id) {
+ switch ($feed_id) {
+ case "newest":
+ $comments = ORM::factory("comment")
+ ->where("state", "published")
+ ->orderby("created", "DESC");
+ $all_comments = ORM::factory("comment")
+ ->where("state", "published")
+ ->orderby("created", "DESC");
+ break;
- $feed->view = "comment.mrss";
- $comments = $comments->find_all($limit, $offset);
- $feed->children = array();
- foreach ($comments as $comment) {
- $item = $comment->item();
- $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);
+ case "item":
+ $comments = ORM::factory("comment")
+ ->where("state", "published")
+ ->orderby("created", "DESC")
+ ->where("item_id", $id);
+ $all_comments = ORM::factory("comment")
+ ->where("state", "published")
+ ->where("item_id", $id);
}
- $all_comments = ORM::factory("comment")->where("state", "published");
- if ($id) {
- $all_comments->where("item_id", $id);
- }
+ if (!empty($comments)) {
+ $feed->view = "comment.mrss";
+ $comments = $comments->find_all($limit, $offset);
+ $feed->children = array();
+ foreach ($comments as $comment) {
+ $item = $comment->item();
+ $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($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");
+ $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;
+ return $feed;
+ }
}
} \ No newline at end of file
diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php
index 413d12a4..6e966bdb 100644
--- a/modules/gallery/helpers/gallery_rss.php
+++ b/modules/gallery/helpers/gallery_rss.php
@@ -19,45 +19,44 @@
*/
class gallery_rss_Core {
- static function available_feeds($item) {
- return array(array("description" => t("New photos or movies"),
- "uri" => "updates"),
- array("description" => t("Album feed"),
- "uri" => "albums"));
+ static function available_feeds($item, $tag) {
+ $feeds["gallery/latest"] = t("Latest photos and movies");
+ return $feeds;
}
- static function updates($offset, $limit) {
- $feed->children = ORM::factory("item")
- ->viewable()
- ->where("type !=", "album")
- ->orderby("created", "DESC")
- ->find_all($limit, $offset);
-
- $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;
- }
-
- static function albums($offset, $limit, $id) {
- $item = ORM::factory("item", $id);
- access::required("view", $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;
-
- return $feed;
+ static function feed($feed_id, $offset, $limit, $id) {
+ switch ($feed_id) {
+ case "latest":
+ $feed->children = ORM::factory("item")
+ ->viewable()
+ ->where("type !=", "album")
+ ->orderby("created", "DESC")
+ ->find_all($limit, $offset);
+
+ $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;
+
+ case "album":
+ $item = ORM::factory("item", $id);
+ access::required("view", $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;
+
+ return $feed;
+ }
}
}
diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php
index 290434ed..f955e8f7 100644
--- a/modules/gallery/helpers/gallery_theme.php
+++ b/modules/gallery/helpers/gallery_theme.php
@@ -42,10 +42,6 @@ class gallery_theme_Core {
$buf .= html::script("modules/gallery/js/fullsize.js");
}
- if ($theme->item()) {
- $buf .= rss::feed_link("albums/{$theme->item()->id}");
- }
-
if ($session->get("l10n_mode", false)) {
$buf .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" .
url::file("modules/gallery/css/l10n_client.css") . "\" />";
diff --git a/modules/rss/controllers/rss.php b/modules/rss/controllers/rss.php
index 29300d58..e9dd9fff 100644
--- a/modules/rss/controllers/rss.php
+++ b/modules/rss/controllers/rss.php
@@ -20,37 +20,43 @@
class Rss_Controller extends Controller {
public static $page_size = 20;
- public function feed($method, $id=null) {
+ public function feed($module_id, $feed_id, $id=null) {
$page = $this->input->get("page", 1);
- $feed_uri = "rss/feed/$method" . (empty($id) ? "" : "/$id");
if ($page < 1) {
- url::redirect($feed_uri);
+ url::redirect(url::merge(array("page" => 1)));
}
- $feed = rss::feed_data($method, ($page - 1) * self::$page_size, self::$page_size, $id);
- $max_pages = $feed->max_pages;
- if ($max_pages && $page > $max_pages) {
- url::redirect("$feed_uri?page={$max_pages}");
+ // Run the appropriate feed callback
+ if (module::is_active($module_id)) {
+ $class_name = "{$module_id}_rss";
+ if (method_exists($class_name, "feed")) {
+ $feed = call_user_func(
+ array($class_name, "feed"), $feed_id,
+ ($page - 1) * self::$page_size, self::$page_size, $id);
+ }
+ }
+ if (empty($feed)) {
+ Kohana::show_404();
+ }
+
+ if ($feed->max_pages && $page > $feed->max_pages) {
+ url::redirect(url::merge(array("page" => $feed->max_pages)));
}
$view = new View(empty($feed->view) ? "feed.mrss" : $feed->view);
unset($feed->view);
- $feed->uri = url::abs_site($feed_uri);
$view->feed = $feed;
+ $view->pub_date = date("D, d M Y H:i:s T");
+ $feed->uri = url::abs_site(Router::$current_uri);
if ($page > 1) {
- $previous_page = $page - 1;
- $feed->previous_page_uri = url::site("$feed_uri?page={$previous_page}");
+ $feed->previous_page_uri = url::abs_site(url::merge(array("page" => $page - 1)));
}
-
- if ($page < $max_pages) {
- $next_page = $page + 1;
- $feed->next_page_uri = url::site("$feed_uri?page={$next_page}");
+ if ($page < $feed->max_pages) {
+ $feed->next_page_uri = url::abs_site(url::merge(array("page" => $page + 1)));
}
- $view->pub_date = date("D, d M Y H:i:s T");
-
rest::http_content_type(rest::RSS);
print $view;
}
diff --git a/modules/rss/helpers/rss.php b/modules/rss/helpers/rss.php
index 8a7d0c97..81ff175f 100644
--- a/modules/rss/helpers/rss.php
+++ b/modules/rss/helpers/rss.php
@@ -19,34 +19,18 @@
*/
class rss_Core {
- static function feed_link($uri) {
- $url = url::site("rss/feed/$uri");
- return "<link rel=\"alternate\" type=\"" . rest::RSS . "\" href=\"$url\" />";
- }
-
/**
- * Get all available rss feeds
+ * Convert a rss feed id into a rss feed url.
*/
- 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) {
- $feeds[$feed["description"]] = url::site("rss/feed/{$feed['uri']}");
- }
- }
- }
-
- return $feeds;
+ static function url($uri) {
+ return url::site("rss/feed/$uri");
}
- static function feed_data($method, $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);
- }
- }
+ /**
+ * Return a <link> element for a given rss feed id.
+ */
+ static function feed_link($uri) {
+ $url = url::site("rss/feed/$uri");
+ return "<link rel=\"alternate\" type=\"" . rest::RSS . "\" href=\"$url\" />";
}
} \ No newline at end of file
diff --git a/modules/rss/helpers/rss_theme.php b/modules/rss/helpers/rss_theme.php
index 52d988bf..3d1b9a29 100644
--- a/modules/rss/helpers/rss_theme.php
+++ b/modules/rss/helpers/rss_theme.php
@@ -19,17 +19,22 @@
*/
class rss_theme_Core {
static function sidebar_blocks($theme) {
- // @todo this needs to be data driven
- if (!$theme->item()) {
- return;
- }
-
$block = new Block();
$block->css_id = "gRss";
$block->title = t("Available RSS Feeds");
$block->content = new View("rss_block.html");
- $block->content->feeds = rss::available_feeds($theme->item());
+ $block->content->feeds = array();
+ foreach (module::active() as $module) {
+ $class_name = "{$module->name}_rss";
+ if (method_exists($class_name, "available_feeds")) {
+ $block->content->feeds = array_merge(
+ $block->content->feeds,
+ call_user_func(array($class_name, "available_feeds"), $theme->item(), $theme->tag()));
+ }
+ }
- return $block;
+ if ($block->content->feeds) {
+ return $block;
+ }
}
}
diff --git a/modules/rss/views/rss_block.html.php b/modules/rss/views/rss_block.html.php
index f964329c..39921d7d 100644
--- a/modules/rss/views/rss_block.html.php
+++ b/modules/rss/views/rss_block.html.php
@@ -1,9 +1,9 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<ul id="gFeeds">
-<? foreach($feeds as $title => $url): ?>
+<? foreach($feeds as $url => $title): ?>
<li style="clear: both;">
<span class="ui-icon-left">
- <a href="<?= $url ?>">
+ <a href="<?= rss::url($url) ?>">
<span class="ui-icon ui-icon-signal-diag"></span>
<?= $title ?>
</a>
diff --git a/modules/slideshow/helpers/slideshow_theme.php b/modules/slideshow/helpers/slideshow_theme.php
index 125d175c..69acb113 100644
--- a/modules/slideshow/helpers/slideshow_theme.php
+++ b/modules/slideshow/helpers/slideshow_theme.php
@@ -20,7 +20,17 @@
class slideshow_theme_Core {
static function head($theme) {
$proto = (empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] === "off") ? "http" : "https";
- return "<script src=\"$proto://lite.piclens.com/current/piclens_optimized.js\"" .
+
+ if (module::is_active("rss")) {
+ if ($item = $theme->item()) {
+ $buf = rss::feed_link("gallery/album/{$item->id}");
+ } else if ($tag = $theme->tag()) {
+ $buf = rss::feed_link("tag/{$tag->id}");
+ }
+ }
+
+ $buf .= "<script src=\"$proto://lite.piclens.com/current/piclens_optimized.js\"" .
"type=\"text/javascript\"></script>";
+ return $buf;
}
}
diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php
index dbef3914..f94508cf 100644
--- a/modules/tag/helpers/tag_rss.php
+++ b/modules/tag/helpers/tag_rss.php
@@ -19,23 +19,28 @@
*/
class tag_rss_Core {
- static function available_feeds($item) {
- return array(array("description" => t("Tag Album feed"),
- "uri" => "tags"));
- }
-
- static function tags($offset, $limit, $id) {
- $tag = ORM::factory("tag", $id);
- if (!$tag->loaded) {
- return Kohana::show_404();
+ static function available_feeds($item, $tag) {
+ if ($tag) {
+ $feeds["tag/tag/{$tag->id}"] =
+ t("Tag feed for %tag_name", array("tag_name" => p::clean($tag->name)));
+ return $feeds;
}
+ return array();
+ }
- $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));
+ static function feed($feed_id, $offset, $limit, $id) {
+ if ($feed_id == "tag") {
+ $tag = ORM::factory("tag", $id);
+ if (!$tag->loaded) {
+ 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));
- return $feed;
+ return $feed;
+ }
}
}