diff options
Diffstat (limited to 'modules/rss')
-rw-r--r-- | modules/rss/controllers/rss.php | 108 | ||||
-rw-r--r-- | modules/rss/helpers/rss.php | 30 | ||||
-rw-r--r-- | modules/rss/helpers/rss_installer.php | 33 | ||||
-rw-r--r-- | modules/rss/helpers/rss_theme.php | 32 | ||||
-rw-r--r-- | modules/rss/module.info | 3 | ||||
-rw-r--r-- | modules/rss/views/feed.mrss.php | 68 |
6 files changed, 274 insertions, 0 deletions
diff --git a/modules/rss/controllers/rss.php b/modules/rss/controllers/rss.php new file mode 100644 index 00000000..24ba7249 --- /dev/null +++ b/modules/rss/controllers/rss.php @@ -0,0 +1,108 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 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 Rss_Controller extends Controller { + public static $page_size = 30; + + public function albums($id) { + $item = ORM::factory("item", $id); + if (!access::can("view", $item)) { + return Kohana::show_404(); + } + + $page = $this->input->get("page", 1); + 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 ($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}"); + } + + if ($page < $max_pages) { + $next_page = $page + 1; + $view->next_page_link = url::site("rss/albums/{$item->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 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 ($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; + } +}
\ No newline at end of file diff --git a/modules/rss/helpers/rss.php b/modules/rss/helpers/rss.php new file mode 100644 index 00000000..728c2847 --- /dev/null +++ b/modules/rss/helpers/rss.php @@ -0,0 +1,30 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 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 rss_Core { + static function item_feed($item) { + $id = $item->is_album() ? $item->id : $item->parent_id; + return url::site("rss/albums/$id"); + } + + static function tag_feed($tag) { + return url::site("rss/tags/$tag->id}"); + } +}
\ No newline at end of file diff --git a/modules/rss/helpers/rss_installer.php b/modules/rss/helpers/rss_installer.php new file mode 100644 index 00000000..aabd5664 --- /dev/null +++ b/modules/rss/helpers/rss_installer.php @@ -0,0 +1,33 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 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 rss_installer { + static function install() { + $version = module::get_version("rss"); + if ($version == 0) { + module::set_version("rss", 1); + // @todo remove this before the final or after the next intermin release + module::delete("media_rss"); + } + } + + static function uninstall() { + module::delete("rss"); + } +} diff --git a/modules/rss/helpers/rss_theme.php b/modules/rss/helpers/rss_theme.php new file mode 100644 index 00000000..2880baa5 --- /dev/null +++ b/modules/rss/helpers/rss_theme.php @@ -0,0 +1,32 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 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 rss_theme_Core { + static function head($theme) { + if ($theme->item()) { + $url = rss::item_feed($theme->item()); + } else if ($theme->tag()) { + $url = rss::tag_feed($theme->tag()); + } + + if (!empty($url)) { + return "<link rel=\"alternate\" type=\"" . rest::RSS . "\" href=\"$url\" />"; + } + } +} diff --git a/modules/rss/module.info b/modules/rss/module.info new file mode 100644 index 00000000..ffd26192 --- /dev/null +++ b/modules/rss/module.info @@ -0,0 +1,3 @@ +name = RSS +description = Provide a RSS feeds +version = 1 diff --git a/modules/rss/views/feed.mrss.php b/modules/rss/views/feed.mrss.php new file mode 100644 index 00000000..6015f471 --- /dev/null +++ b/modules/rss/views/feed.mrss.php @@ -0,0 +1,68 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<? echo "<?xml version=\"1.0\" ?>" ?> +<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" + xmlns:atom="http://www.w3.org/2005/Atom" + xmlns:content="http://purl.org/rss/1.0/modules/content" + xmlns:fh="http://purl.org/syndication/history/1.0"> + <channel> + <generator>gallery3</generator> + <title><?= htmlspecialchars($title) ?></title> + <link><?= $link ?></link> + <description><?= htmlspecialchars($description) ?></description> + <language>en-us</language> + <atom:link rel="self" href="<?= $feed_link ?>" type="application/rss+xml" /> + <fh:complete/> + <? if (!empty($previous_page_link)): ?> + <atom:link rel="previous" href="<?= $previous_page_link ?>" type="application/rss+xml" /> + <? endif ?> + <? if (!empty($next_page_link)): ?> + <atom:link rel="next" href="<?= $next_page_link ?>" type="application/rss+xml" /> + <? endif ?> + <pubDate><?= $pub_date ?></pubDate> + <lastBuildDate><?= $pub_date ?></lastBuildDate> + <? foreach ($children as $child): ?> + <item> + <title><?= htmlspecialchars($child->title) ?></title> + <link><?= url::abs_site("photos/$child->id") ?></link> + <guid isPermaLink="true"><?= url::abs_site("photos/$child->id") ?></guid> + <description><?= htmlspecialchars($child->description) ?></description> + <enclosure url="<?= $child->file_url(true) ?>" + type="<?= $child->mime_type ?>" + height="<?= $child->height ?>" + width="<?= $child->width ?>"/> + <media:thumbnail url="<?= $child->thumb_url(true) ?>" + fileSize="<?= filesize($child->thumb_path()) ?>" + height="<?= $child->thumb_height ?>" + width="<?= $child->thumb_width ?>" + /> + <content:encoded> + <![CDATA[ + <p> + <img alt="" src="<?= $child->resize_url(true) ?>" + title="<?= htmlspecialchars($child->title) ?>" + height="<?= $child->resize_height ?>" width="<?= $child->resize_width ?>" /><br /> + <?= $child->description ?> + </p> + ]]> + </content:encoded> + <media:group> + <media:content url="<?= $child->resize_url(true) ?>" + fileSize="<?= filesize($child->resize_path()) ?>" + type="<?= $child->mime_type ?>" + height="<?= $child->resize_height ?>" + width="<?= $child->resize_width ?>" + isDefault="true" + /> + <? if (access::can("view_full", $child)): ?> + <media:content url="<?= $child->file_url(true) ?>" + fileSize="<?= filesize($child->file_path()) ?>" + type="<?= $child->mime_type ?>" + height="<?= $child->height ?>" + width="<?= $child->width ?>" + /> + <? endif ?> + </media:group> + </item> + <? endforeach ?> + </channel> +</rss> |