← Back to team overview

brainstorm-dev team mailing list archive

Re: Patch: RSS feed for idea pages

 

Dean Sas wrote:
> I've attached a bzr bundle that generates an rss feed for an idea and
> its comments.
> 
> It also makes the dates in the other rss feeds valid RFC 822 which
> feedvalidator was complaining about.
> 
> Feedback welcome :)

Updated the bundle (attached) after feedback on IRC. Thanks Nicolas :)

Dean


# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: dean@xxxxxxxxxxx-20080621182650-w2r0z2te4eqat32n
# target_branch: file:///home/dean/code/ubuntu-qa.main/
# testament_sha1: 2a2444e3f7d77cc1bffa66a6b67a1d7df5caa648
# timestamp: 2008-06-21 19:30:51 +0100
# base_revision_id: ndeschildre@xxxxxxxxx-20080619184503-\
#   2hik8r7g453mow94
# 
# Begin patch
=== modified file 'code/modules/qapoll/controller.php'
--- code/modules/qapoll/controller.php	2008-06-16 17:33:36 +0000
+++ code/modules/qapoll/controller.php	2008-06-21 15:24:40 +0000
@@ -49,6 +49,7 @@
 require_once "views/view.php";
 require_once "views/pagination.php";
 require_once "views/choice/choice.html.php";
+require_once "views/choice/choice.rss2.php";
 require_once "views/choicelist/choicelist.html.php";
 require_once "views/choicelist/choicelist.rss2.php";
 require_once "views/choicelist/choicelist.json.php";
@@ -912,6 +913,14 @@
 					drupal_set_message("You need to login first!", 'error_msg');
 					drupal_set_header("Location: " . $GLOBALS['basemodule_url'] . "/item/" . $this->_param1 . "/");
 				}
+				else if($this->_param2 == "rss2")
+				{
+					// Display RSS feed of choice and comments
+					$model = new ChoiceModel();
+					$model->setId($this->_param1);
+					$view = new ChoiceRSS2View();
+					$template ="rss2";
+				}
 				else if($this->_param2 == null)
 				{
 					//A comment was submitted. Save it.

=== modified file 'code/modules/qapoll/models/choice.php'
--- code/modules/qapoll/models/choice.php	2008-06-17 20:48:41 +0000
+++ code/modules/qapoll/models/choice.php	2008-06-21 18:26:50 +0000
@@ -88,6 +88,7 @@
 				"qapoll_choice.userid as userid, qapoll_choice.date, qapoll_choice.status, qapoll_choice.description, qapoll_choice.pollid, " . 
 				"qapoll_choice.whiteboard, qapoll_choice.categoryid, qapoll_choice.choicetype, qapoll_choice.duplicatenumber, " .
 				"qapoll_choice.totalvotes as votes, qapoll_choice.last_status_change, qapoll_choice.release_target, " .
+				"qapoll_choice.last_comment_date, ".
 				//Get the user vote only if logged.
 				(($user->uid != null)?"qapoll_vote.value as myvote, ":"") .
 				//Get the user bookmark only if logged.

=== modified file 'code/modules/qapoll/views/choice/choice.html.php'
--- code/modules/qapoll/views/choice/choice.html.php	2008-05-25 16:17:45 +0000
+++ code/modules/qapoll/views/choice/choice.html.php	2008-06-21 15:24:40 +0000
@@ -43,6 +43,11 @@
 		if($template == "default")
 			drupal_add_js('modules/qapoll/js/qapoll_choice_page.js');
 
+		//Add RSS feed
+		$basemodulepath = $GLOBALS['basemodule_path'];
+		drupal_add_feed($GLOBALS['basemodule_url'] . "/" . $basemodulepath .'/'. $this->_data->id."/rss2" ,
+		 "RSS feed for this choice");
+		
 		//Load the category list corresponding to this poll.
 		$this->_categoryList = $this->_model->_pollModel->getCategoryList();
 

=== added file 'code/modules/qapoll/views/choice/choice.rss2.php'
--- code/modules/qapoll/views/choice/choice.rss2.php	1970-01-01 00:00:00 +0000
+++ code/modules/qapoll/views/choice/choice.rss2.php	2008-06-21 18:26:50 +0000
@@ -0,0 +1,46 @@
+<?php
+
+/*
+Copyright (C) 2008 Dean Sas <dean@xxxxxxxxxxx>
+
+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 ChoiceRSS2View extends View
+{
+
+
+	/**
+	 * Prepare and display the page.
+	 */
+	function display($template = "rss2")
+	{
+		global $site;
+		//Indicate the content type.
+		drupal_set_header("Content-type: text/rss");
+		//Execute default template
+		$content .= $this->loadTemplate("choice/", $template);
+		//Don't return the content, otherwise drupal will add some HTML in the way.
+		echo $content;
+
+		return null;
+	}
+
+
+}
+
+?>

=== added file 'code/modules/qapoll/views/choice/tmpl/rss2.php'
--- code/modules/qapoll/views/choice/tmpl/rss2.php	1970-01-01 00:00:00 +0000
+++ code/modules/qapoll/views/choice/tmpl/rss2.php	2008-06-21 18:26:50 +0000
@@ -0,0 +1,41 @@
+<?php
+
+/*
+Copyright (C) 2008 Dean Sas <dean@xxxxxxxxxxx>
+
+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.
+*/
+
+echo "<?xml version=\"1.0\"?>"; ?>
+
+<rss version="2.0">
+  <channel>
+    <title><![CDATA[<?php echo strip_tags_and_evil_attributes($this->_data->title); ?>]]></title>
+    <link><?php echo $GLOBALS['basemodule_url'] . "/item/" . $this->_data->id . "/"; ?></link>
+    <description><![CDATA[<?php echo str_replace("\n", "<br />", strip_tags_and_evil_attributes($this->_data->description, $GLOBALS['site']->getSetting("item_description_auth_tags"))) ?>]]></description>
+
+    <language>en-us</language>
+    <pubDate><?php echo date("r", strtotime($this->_data->date))?></pubDate>
+    <lastBuildDate><?php echo date("r", strtotime($this->_data->last_comment_date))?></lastBuildDate>
+    <generator>QAPoll module</generator>
+    <guid isPermaLink="true"><?php echo $GLOBALS['basemodule_url'] . "/item/" . $this->_data->id . "/"; ?></guid>
+    <?php foreach($this->_data->comment_items as $comment): ?>
+    <?php 
+     $this->comment =& $comment;
+     echo $this->loadTemplate("choice/", "rss2", "comment");
+    ?>
+    <?php endforeach; ?>
+  </channel>
+</rss>

=== added file 'code/modules/qapoll/views/choice/tmpl/rss2_comment.php'
--- code/modules/qapoll/views/choice/tmpl/rss2_comment.php	1970-01-01 00:00:00 +0000
+++ code/modules/qapoll/views/choice/tmpl/rss2_comment.php	2008-06-21 15:24:40 +0000
@@ -0,0 +1,25 @@
+<?php
+
+/*
+ * Copyright (C) 2008 Dean Sas <dean@xxxxxxxxxxx>
+ *
+ * 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.
+ * */
+?>
+<item>
+  <title>Comment from <?php echo $this->comment->username ?></title>
+  <description><![CDATA[<?php echo str_replace("\n", "<br />", strip_tags_and_evil_attributes($this->comment->comment, $GLOBALS['site']->getSetting("item_description_auth_tags"))) ?>]]></description>
+  <pubDate><?php echo date("r", strtotime($this->comment->date))?></pubDate>
+</item>

=== modified file 'code/modules/qapoll/views/choicelist/tmpl/rss2.php'
--- code/modules/qapoll/views/choicelist/tmpl/rss2.php	2008-03-01 13:28:19 +0000
+++ code/modules/qapoll/views/choicelist/tmpl/rss2.php	2008-06-21 15:37:23 +0000
@@ -35,8 +35,8 @@
     <link><?php echo $GLOBALS['basemodule_url']; ?></link>
     <description><![CDATA[<?php if($GLOBALS['entrypoint']->getData()->description != null) echo str_replace("\n", "<br />",$GLOBALS['entrypoint']->getData()->description); else echo str_replace("\n", "<br />", $this->_data->description); ?>]]></description>
     <language>en-us</language>
-    <pubDate><?php echo date("D, d-M-Y"); ?> 00:00:00 UTC</pubDate>
-    <lastBuildDate><?php echo date("D, d-M-Y"); ?> 00:00:00 UTC</lastBuildDate>
+    <pubDate><?php echo date("r"); ?></pubDate>
+    <lastBuildDate><?php echo date("r"); ?></lastBuildDate>
     <generator>QAPoll module</generator>
  
 <?php for ($i = 0; $i < count($this->_data->items); $i++) : ?>

=== modified file 'code/modules/qapoll/views/choicelist/tmpl/rss2_item.php'
--- code/modules/qapoll/views/choicelist/tmpl/rss2_item.php	2008-05-10 18:04:49 +0000
+++ code/modules/qapoll/views/choicelist/tmpl/rss2_item.php	2008-06-21 18:26:50 +0000
@@ -51,6 +51,6 @@
 <?php endif; ?>
 ]]>
 </description>
-      <pubDate><?php echo date("D, d-M-Y"); ?> 00:00:00 UTC</pubDate>
+      <pubDate><?php echo date("r", strtotime($this->item->date)); ?></pubDate>
       <guid><?php echo $GLOBALS['basemodule_url'] . "/item/" . $this->item->id . "/"; ?></guid>
     </item>

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWehoGDUAC+PfgHAwdff////n
/66////6YBN9R9fTsHXNUhQ0AKqgAFiXY6ctFQ2zW0O5pKgCu2lRs2wMJThiiT1J4p6gbKMjaTT1
Gho0ZA0AANqMgeoNA5hNGRoaGQwjQyGmjQAYjJkAwgGA5hNGRoaGQwjQyGmjQAYjJkAwgGASEiEJ
kmDVPJmmlMRtR6RtRgmjI0ANBpkGQRSJkJiTTTCp+mJT1PFT9U3hRtIZI9RieUNPUyfqIPRARSCB
NMII0CMp4jFKflM0yQHqj1P1I9R6gNHqNP1SrpK8FGNNIUEhjGNpNjXB2dWz1Ne18H3d8rwFUOh0
GsrQuakHPf1r3NizpvUkYQghZE1MRiRwJ17sWWb1fri83qpucUnuNVVvu5qvXDpE2YumauV2KRut
nvcZ6Yocvsz4GhZbKxoRu9O5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