diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/comment/helpers/comment_rss.php | 84 | ||||
-rw-r--r-- | modules/comment/views/comment.mrss.php | 34 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_menu.php | 3 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_rss.php | 63 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_theme.php | 8 | ||||
-rw-r--r-- | modules/gallery/libraries/Theme_View.php | 17 | ||||
-rw-r--r-- | modules/rss/controllers/rss.php | 49 | ||||
-rw-r--r-- | modules/rss/helpers/rss.php | 36 | ||||
-rw-r--r-- | modules/rss/helpers/rss_theme.php | 19 | ||||
-rw-r--r-- | modules/rss/views/feed.mrss.php | 18 | ||||
-rw-r--r-- | modules/rss/views/rss_block.html.php | 4 | ||||
-rw-r--r-- | modules/slideshow/helpers/slideshow_menu.php | 11 | ||||
-rw-r--r-- | modules/tag/helpers/tag_rss.php | 36 | ||||
-rw-r--r-- | modules/tag/helpers/tag_theme.php | 6 |
14 files changed, 215 insertions, 173 deletions
diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php index 56de4284..afcc275c 100644 --- a/modules/comment/helpers/comment_rss.php +++ b/modules/comment/helpers/comment_rss.php @@ -19,46 +19,60 @@ */ 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 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) { - $orm = ORM::factory("comment") - ->where("state", "published") - ->orderby("created", "DESC"); - if (!empty($id)) { - $orm->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 = $orm->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 - ); + 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); } - $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"); + 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); + } - return $feed; + $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; + } } }
\ No newline at end of file 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_menu.php b/modules/gallery/helpers/gallery_menu.php index fd4ec241..4499e50a 100644 --- a/modules/gallery/helpers/gallery_menu.php +++ b/modules/gallery/helpers/gallery_menu.php @@ -91,6 +91,9 @@ class gallery_menu_Core { static function album($menu, $theme) { } + static function tag($menu, $theme) { + } + static function photo($menu, $theme) { if (access::can("view_full", $theme->item())) { $menu diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index 6535d29d..6e966bdb 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -19,41 +19,44 @@ */ 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 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); - $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"); + 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); - return $feed; - } + $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); + 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; + $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; + return $feed; + } } } diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index 290434ed..c28c9040 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -42,8 +42,12 @@ class gallery_theme_Core { $buf .= html::script("modules/gallery/js/fullsize.js"); } - if ($theme->item()) { - $buf .= rss::feed_link("albums/{$theme->item()->id}"); + 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/{$tag->id}"); + } } if ($session->get("l10n_mode", false)) { diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 15baaeef..ebf0792c 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -124,6 +124,23 @@ class Theme_View_Core extends View { print $menu; } + public function tag_menu() { + $menu = Menu::factory("root"); + gallery_menu::tag($menu, $this); + + foreach (module::active() as $module) { + if ($module->name == "gallery") { + continue; + } + $class = "{$module->name}_menu"; + if (method_exists($class, "tag")) { + call_user_func_array(array($class, "tag"), array(&$menu, $this)); + } + } + + print $menu; + } + public function photo_menu() { $menu = Menu::factory("root"); gallery_menu::photo($menu, $this); diff --git a/modules/rss/controllers/rss.php b/modules/rss/controllers/rss.php index 80803dfd..e9dd9fff 100644 --- a/modules/rss/controllers/rss.php +++ b/modules/rss/controllers/rss.php @@ -18,42 +18,45 @@ * 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) { + 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); + } } - unset($feed["max_pages"]); - - $view = new View(empty($feed["view"]) ? "feed.mrss" : $feed["view"]); - unset($feed["view"]); - - foreach ($feed as $field => $value) { - $view->$field = $value; + if (empty($feed)) { + Kohana::show_404(); } - $view->feed_link = url::abs_site($feed_uri); - if ($page > 1) { - $previous_page = $page - 1; - $view->previous_page_link = url::site("$feed_uri?page={$previous_page}"); + if ($feed->max_pages && $page > $feed->max_pages) { + url::redirect(url::merge(array("page" => $feed->max_pages))); } - if ($page < $max_pages) { - $next_page = $page + 1; - $view->next_page_link = url::site("$feed_uri?page={$next_page}"); - } + $view = new View(empty($feed->view) ? "feed.mrss" : $feed->view); + unset($feed->view); + $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) { + $feed->previous_page_uri = url::abs_site(url::merge(array("page" => $page - 1))); + } + if ($page < $feed->max_pages) { + $feed->next_page_uri = url::abs_site(url::merge(array("page" => $page + 1))); + } + rest::http_content_type(rest::RSS); print $view; } diff --git a/modules/rss/helpers/rss.php b/modules/rss/helpers/rss.php index 403ee225..81ff175f 100644 --- a/modules/rss/helpers/rss.php +++ b/modules/rss/helpers/rss.php @@ -19,36 +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) { - if ($feed["type"] == "block") { - $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($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); - } - } + /** + * 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/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/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_menu.php b/modules/slideshow/helpers/slideshow_menu.php index 799c9a76..ee975d88 100644 --- a/modules/slideshow/helpers/slideshow_menu.php +++ b/modules/slideshow/helpers/slideshow_menu.php @@ -37,4 +37,15 @@ class slideshow_menu_Core { "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") ->css_id("gSlideshowLink")); } + + static function tag($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("slideshow") + ->label(t("View slideshow")) + ->url("javascript:PicLensLite.start(" . + "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") + ->css_id("gSlideshowLink")); + } + } diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php index 3d6399ca..f94508cf 100644 --- a/modules/tag/helpers/tag_rss.php +++ b/modules/tag/helpers/tag_rss.php @@ -19,24 +19,28 @@ */ class tag_rss_Core { - static function available_feeds($item) { - return array(array("description" => t("Tag Album feed"), - "type" => "head", - "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; + } } } diff --git a/modules/tag/helpers/tag_theme.php b/modules/tag/helpers/tag_theme.php index 45f55986..a32d71b6 100644 --- a/modules/tag/helpers/tag_theme.php +++ b/modules/tag/helpers/tag_theme.php @@ -20,11 +20,7 @@ class tag_theme_Core { static function head($theme) { $url = url::file("modules/tag/js/tag.js"); - $head[] = "<script src=\"$url\" type=\"text/javascript\"></script>"; - if ($theme->tag() && module::is_active("rss")) { - $head[] = rss::feed_link("tags/{$theme->tag()->id}"); - } - return implode("\n", $head); + return "<script src=\"$url\" type=\"text/javascript\"></script>"; } static function sidebar_blocks($theme) { |