summaryrefslogtreecommitdiff
path: root/modules/rss
diff options
context:
space:
mode:
Diffstat (limited to 'modules/rss')
-rw-r--r--modules/rss/controllers/rss.php66
-rw-r--r--modules/rss/helpers/rss.php36
-rw-r--r--modules/rss/helpers/rss_block.php49
-rw-r--r--modules/rss/module.info7
-rw-r--r--modules/rss/views/feed.mrss.php79
-rw-r--r--modules/rss/views/rss_block.html.php13
6 files changed, 250 insertions, 0 deletions
diff --git a/modules/rss/controllers/rss.php b/modules/rss/controllers/rss.php
new file mode 100644
index 0000000..571995b
--- /dev/null
+++ b/modules/rss/controllers/rss.php
@@ -0,0 +1,66 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2013 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 = 20;
+
+ public function feed($module_id, $feed_id, $id=null) {
+ $page = (int) Input::instance()->get("page", 1);
+ if ($page < 1) {
+ url::redirect(url::merge(array("page" => 1)));
+ }
+
+ // Configurable page size between 1 and 100, default 20
+ $page_size = max(1, min(100, (int) Input::instance()->get("page_size", self::$page_size)));
+
+ // Run the appropriate feed callback
+ if (module::is_active($module_id)) {
+ $class_name = "{$module_id}_rss";
+ if (class_exists($class_name) && method_exists($class_name, "feed")) {
+ $feed = call_user_func(
+ array($class_name, "feed"), $feed_id,
+ ($page - 1) * $page_size, $page_size, $id);
+ }
+ }
+ if (empty($feed)) {
+ throw new Kohana_404_Exception();
+ }
+
+ 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);
+
+ $view->feed = $feed;
+ $view->pub_date = date("D, d M Y H:i:s O");
+
+ $feed->uri = url::abs_site(url::merge($_GET));
+ 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)));
+ }
+
+ header("Content-Type: application/rss+xml");
+ 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 0000000..d6e60f1
--- /dev/null
+++ b/modules/rss/helpers/rss.php
@@ -0,0 +1,36 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2013 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 {
+ /**
+ * Convert a rss feed id into a rss feed url.
+ */
+ static function url($uri) {
+ return url::site("rss/feed/$uri");
+ }
+
+ /**
+ * 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=\"application/rss+xml\" href=\"$url\" />";
+ }
+} \ No newline at end of file
diff --git a/modules/rss/helpers/rss_block.php b/modules/rss/helpers/rss_block.php
new file mode 100644
index 0000000..9a77b05
--- /dev/null
+++ b/modules/rss/helpers/rss_block.php
@@ -0,0 +1,49 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2013 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_block_Core {
+ static function get_site_list() {
+ return array("rss_feeds" => t("Available RSS feeds"));
+ }
+
+ static function get($block_id, $theme) {
+ $block = "";
+ switch ($block_id) {
+ case "rss_feeds":
+ $feeds = array();
+ foreach (module::active() as $module) {
+ $class_name = "{$module->name}_rss";
+ if (class_exists($class_name) && method_exists($class_name, "available_feeds")) {
+ $feeds = array_merge($feeds,
+ call_user_func(array($class_name, "available_feeds"), $theme->item(), $theme->tag()));
+ }
+ }
+ if (!empty($feeds)) {
+ $block = new Block();
+ $block->css_id = "g-rss";
+ $block->title = t("Available RSS feeds");
+ $block->content = new View("rss_block.html");
+ $block->content->feeds = $feeds;
+ }
+ break;
+ }
+
+ return $block;
+ }
+}
diff --git a/modules/rss/module.info b/modules/rss/module.info
new file mode 100644
index 0000000..5f32387
--- /dev/null
+++ b/modules/rss/module.info
@@ -0,0 +1,7 @@
+name = "RSS"
+description = "Provides RSS feeds"
+version = 1
+author_name = "Gallery Team"
+author_url = "http://codex.galleryproject.org/Gallery:Team"
+info_url = "http://codex.galleryproject.org/Gallery3:Modules:rss"
+discuss_url = "http://galleryproject.org/forum_module_rss"
diff --git a/modules/rss/views/feed.mrss.php b/modules/rss/views/feed.mrss.php
new file mode 100644
index 0000000..b609a54
--- /dev/null
+++ b/modules/rss/views/feed.mrss.php
@@ -0,0 +1,79 @@
+<?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><?= html::clean($feed->title) ?></title>
+ <link><?= $feed->uri ?></link>
+ <description><?= html::clean($feed->description) ?></description>
+ <language>en-us</language>
+ <atom:link rel="self" href="<?= $feed->uri ?>" type="application/rss+xml" />
+ <fh:complete/>
+ <? if (!empty($feed->previous_page_uri)): ?>
+ <atom:link rel="previous" href="<?= $feed->previous_page_uri ?>" type="application/rss+xml" />
+ <? endif ?>
+ <? 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 ($feed->items as $item): ?>
+ <item>
+ <title><?= html::purify($item->title) ?></title>
+ <link><?= url::abs_site("{$item->type}s/{$item->id}") ?></link>
+ <guid isPermaLink="true"><?= url::abs_site("{$item->type}s/{$item->id}") ?></guid>
+ <pubDate><?= date("D, d M Y H:i:s O", $item->created); ?></pubDate>
+ <description><?= html::purify($item->description) ?></description>
+ <content:encoded>
+ <![CDATA[
+ <span><?= html::purify($item->description) ?></span>
+ <p>
+ <? if ($item->type == "photo"): ?>
+ <img alt="" src="<?= $item->resize_url(true) ?>"
+ title="<?= html::purify($item->title)->for_html_attr() ?>"
+ height="<?= $item->resize_height ?>" width="<?= $item->resize_width ?>" /><br />
+ <? else: ?>
+ <a href="<?= url::abs_site("{$item->type}s/{$item->id}") ?>">
+ <img alt="" src="<?= $item->thumb_url(true) ?>"
+ title="<?= html::purify($item->title)->for_html_attr() ?>"
+ height="<?= $item->thumb_height ?>" width="<?= $item->thumb_width ?>" /></a><br />
+ <? endif ?>
+ <?= html::purify($item->description) ?>
+ </p>
+ ]]>
+ </content:encoded>
+ <media:thumbnail url="<?= $item->thumb_url(true) ?>"
+ height="<?= $item->thumb_height ?>"
+ width="<?= $item->thumb_width ?>"
+ />
+ <? $view_full = access::can("view_full", $item); ?>
+ <? if ($item->type == "photo" && $view_full): ?>
+ <media:group>
+ <? endif ?>
+ <? if ($item->type == "photo"): ?>
+ <media:content url="<?= $item->resize_url(true) ?>"
+ fileSize="<?= @filesize($item->resize_path()) ?>"
+ type="<?= $item->mime_type ?>"
+ height="<?= $item->resize_height ?>"
+ width="<?= $item->resize_width ?>"
+ />
+ <? endif ?>
+ <? if ($view_full): ?>
+ <media:content url="<?= $item->file_url(true) ?>"
+ fileSize="<?= @filesize($item->file_path()) ?>"
+ type="<?= $item->mime_type ?>"
+ height="<?= $item->height ?>"
+ width="<?= $item->width ?>"
+ isDefault="true"
+ />
+ <? endif ?>
+ <? if ($item->type == "photo" && $view_full): ?>
+ </media:group>
+ <? endif ?>
+ </item>
+ <? endforeach ?>
+ </channel>
+</rss>
diff --git a/modules/rss/views/rss_block.html.php b/modules/rss/views/rss_block.html.php
new file mode 100644
index 0000000..210c72a
--- /dev/null
+++ b/modules/rss/views/rss_block.html.php
@@ -0,0 +1,13 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<ul id="g-feeds">
+<? foreach($feeds as $url => $title): ?>
+ <li style="clear: both;">
+ <span class="ui-icon-left">
+ <a href="<?= rss::url($url) ?>">
+ <span class="ui-icon ui-icon-signal-diag"></span>
+ <?= html::purify($title) ?>
+ </a>
+ </span>
+ </li>
+<? endforeach ?>
+</ul>