? modules/commentrss/commentrss.install
Index: modules/commentrss/commentrss.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/commentrss/commentrss.info,v
retrieving revision 1.2
diff -U3 -r1.2 commentrss.info
--- modules/commentrss/commentrss.info	18 Jun 2007 22:53:34 -0000	1.2
+++ modules/commentrss/commentrss.info	4 Jul 2007 07:02:04 -0000
@@ -1,3 +1,4 @@
 ; $Id: commentrss.info,v 1.2 2007/06/18 22:53:34 dww Exp $
 name = Comment RSS
 description = Provides RSS feeds for comments
+dependencies = comment
Index: modules/commentrss/commentrss.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/commentrss/commentrss.module,v
retrieving revision 1.12
diff -U3 -r1.12 commentrss.module
--- modules/commentrss/commentrss.module	18 Dec 2006 11:42:56 -0000	1.12
+++ modules/commentrss/commentrss.module	4 Jul 2007 07:02:04 -0000
@@ -1,64 +1,68 @@
 <?php
 // $Id: commentrss.module,v 1.12 2006/12/18 11:42:56 goba Exp $
 
-function commentrss_help($section = "admin/modules#description") {
-  if ($section == "admin/modules#description") {
-    return t('Provides RSS feeds for comments');
+function commentrss_help($section) {
+  $output = '';
+  switch ($section) {
+    case 'admin/modules#description':
+      $output = t('Provides RSS feeds for comments');
+      break;
+    case 'admin/content/commentrss':
+      $output = '<p>' . t('Select the types of comment feeds to be enabled.') . '</p>';
+      break;
   }
+  return $output;
 }
 
 function commentrss_menu($may_cache) {
+  $items = array();
   if ($may_cache) {
+    $items[] = array(
+      'path' => 'admin/content/commentrss',
+      'title' => t('Comment RSS publishing'),
+      'description' => t('Configure RSS feeds for comments.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'commentrss_admin_settings',
+      'access' => user_access('administer site configuration'),
+      'type' => MENU_NORMAL_ITEM);
     $items[] = array('path' => 'crss', 'title' => '',
       'callback' => 'commentrss_handler',
       'access' => user_access('access content'),
       'type' => MENU_CALLBACK);
   }
   else {
-    drupal_add_link(array('rel' => 'alternate',
-                          'type' => 'application/rss+xml',
-                          'title' => t('All comments'),
-                          'href' => url('crss', NULL, NULL, TRUE)));
-    if (arg(0) == 'taxonomy' && arg(1) == 'vocabulary') {
-      // vocabulary_list module is serving this page - http://drupal.org/project/vocabulary_list
-      drupal_add_link(array('rel' => 'alternate',
-                          'type' => 'application/rss+xml',
-                          'title' => t('Comments on this vocabulary'),
-                          'href' => url('crss/vocab/'. arg(2), NULL, NULL, TRUE)));
-    }
-    elseif (arg(0) == 'taxonomy' && arg(1) == 'term') {
-      drupal_add_link(array('rel' => 'alternate',
-                          'type' => 'application/rss+xml',
-                          'title' => t('Comments on this taxonomy term'),
-                          'href' => url('crss/term/'. arg(2), NULL, NULL, TRUE)));
-    }
-    elseif (arg(0) == 'node' && is_numeric(arg(1))) {
+    if (arg(0) == 'node' && is_numeric(arg(1)) && variable_get('commentrss_node', TRUE)) {
       $node = node_load(arg(1));
       if ($node->nid) {
-        $typename = node_get_types('name', $node);
-        drupal_add_link(array('rel' => 'alternate',
-                              'type' => 'application/rss+xml',
-                              'title' => t('Comments for @title', array('@title' => $node->title)),
-                              'href' => url('crss/node/'. arg(1), NULL, NULL, TRUE)));
-        drupal_add_link(array('rel' => 'alternate',
-                              'type' => 'application/rss+xml',
-                              'title' => t('Comments for all @type content', array('@type' => $typename)),
-                              'href' => url('crss/nodetype/'. $node->type, NULL, NULL, TRUE)));
+        drupal_add_feed(url('crss/node/'. arg(1)),
+          t('Comments for @title', array('@title' => $node->title)));
       }
     }
+    elseif (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) && variable_get('commentrss_term', FALSE)) {
+      $term = taxonomy_get_term(arg(2));
+      drupal_add_feed(url('crss/term/'. arg(2)), t('Comments for category @title', array('@title' => $term->name)));
+    }
+    elseif (arg(0) == 'taxonomy' && arg(1) == 'vocabulary' && is_numeric(arg(2)) && variable_get('commentrss_vocab', FALSE)) {
+      // vocabulary_list module is serving this page - http://drupal.org/project/vocabulary_list
+      drupal_add_feed(url('crss/vocab/'. arg(2)), t('Comments for this vocabulary'));
+    }
+    // If currently viewing a node add a feed for all comments
+    elseif (arg(0) == 'node' && variable_get('commentrss_site', TRUE)) {
+      drupal_add_feed(url('crss'), variable_get('site_name', 'Drupal') .' '. t('All comments'));
+    }
   }
   return $items;
 }
 
 function commentrss_handler($type = NULL) {
-  if ($type) {
-    if (in_array($type, array('node', 'term', 'vocab', 'nodetype'))) {
+  if ($type && variable_get('commentrss_'.$type, FALSE)) {
+    if (in_array($type, array('node', 'term', 'vocab'))) {
       if (call_user_func('commentrss_feed_' . $type)) {
         return;
       }
     }
   }
-  else {
+  elseif (variable_get('commentrss_site', TRUE)) {
     if (commentrss_feed_site()) {
       return;
     }
@@ -74,25 +78,25 @@
 }
 
 // Provides a comment feed for nodes in a vocabulary
-// For the master link in the RSS feed to work, you need vocabulary_list.module!
+// Requires vocabulary_list.module because there is no way to discover
+//   this feed without a vocabulary list page.
 function commentrss_feed_vocab() {
   global $base_url;
-  
-  $vid = arg(2);
-  if (is_numeric($vid)) {
-    
-    $items = commentrss_format_items('DISTINCT(n.nid)', 'INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {term_data} d ON r.tid = d.tid', 'd.vid = %d AND', $vid);
-    $vocab = taxonomy_get_vocabulary($vid);
-    
-    // We can link to a specific page if vocabulary listing is present
-    $link = (module_exist('vocabulary_list') ? url("taxonomy/vocabulary/$vid", NULL, NULL, TRUE) : $base_url);
-    
+
+  if (is_numeric(arg(2)) && module_exists('vocabulary_list')) {
+    $vocab = taxonomy_get_vocabulary(arg(2));
+    if (!$vocab->vid) {
+      return FALSE;
+    }
+
+    $items = commentrss_format_items('DISTINCT(n.nid)', 'INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {term_data} d ON r.tid = d.tid', 'd.vid = %d AND', $vocab->vid);
+
     $channel = array(
-      'title'       => check_plain(variable_get('site_name', 'drupal') .' - '. $vocab->name) .' - '. t('Comments'),
-      'link'        => $link,
-      'description' => t('Comments for "@title"', array("@title" => $vocab->name)),
+      'title' => check_plain(variable_get('site_name', 'drupal')) .' - '. t('Comments for "@vocab"', array('@vocab' => $vocab->name)),
+      'link' => url("taxonomy/vocabulary/$vocab->vid", NULL, NULL, TRUE),
+      'description' => t('Comments for articles with this vocabulary'),
     );
-    
+
     commentrss_format_feed($items, $channel);
     return TRUE;
   }
@@ -101,104 +105,61 @@
 
 // Provides a comment feed for nodes associated with a term
 function commentrss_feed_term() {
-  $tid = arg(2);
-  if (is_numeric($tid)) {
-    
-    $items = commentrss_format_items('DISTINCT(n.nid)', 'INNER JOIN {term_node} r ON n.nid = r.nid', 'r.tid = %d AND', $tid);
-    $term = taxonomy_get_term($tid);
-    
+  if (is_numeric(arg(2))) {
+    $term = taxonomy_get_term(arg(2));
+    if (!$term->tid) {
+      return FALSE;
+    }
+
+    $items = commentrss_format_items('DISTINCT(n.nid)', 'INNER JOIN {term_node} r ON n.nid = r.nid', 'r.tid = %d AND', $term->tid);
+
     $channel = array(
-      'title'       => check_plain(variable_get('site_name', 'drupal') .' - '. $term->name) .' - '. t('Comments'),
-      'link'        => url("taxonomy/term/$tid", NULL, NULL, TRUE),
-      'description' => t('Comments for "@title"', array("@title" => $term->name)),
+      'title' => check_plain(variable_get('site_name', 'drupal')) .' - '. t('Comments for "@title"', array('@title' => $term->name)),
+      'link' => url("taxonomy/term/$tid", NULL, NULL, TRUE),
+      'description' => t('Comments for articles with this term')
     );
-    
+
     commentrss_format_feed($items, $channel);
     return TRUE;
   }
   return FALSE;
 }
 
-// Provides a comment feed for a single node (also includes the node teaser
-// as the last item, even if there are too many comments which are not
-// included in the resulting RSS output)
+// Provides a comment feed for a single node
 function commentrss_feed_node() {
   global $base_url;
 
-  $nid = arg(2);
-  if (is_numeric($nid)) {
-    if (!($item = node_load($nid))) {
+  if (is_numeric(arg(2))) {
+    $node = node_load(arg(2));
+    if (!$node->nid) {
       return FALSE;
     }
 
-    $items = commentrss_format_items('n.nid', '', 'n.nid = %d AND', $nid);
-    $link = url("node/$nid", NULL, NULL, TRUE);
+    $items = commentrss_format_items('n.nid', '', 'n.nid = %d AND', $node->nid);
+    $link = url("node/$node->nid", NULL, NULL, TRUE);
 
-    // COPIED from node_feed() start
-    $item_length = variable_get('feed_item_length', 'teaser');
-    if ($item_length != 'title') {
-      $teaser = ($item_length == 'teaser') ? TRUE : FALSE;
-      if (node_hook($item, 'view')) {
-        node_invoke($item, 'view', $teaser, FALSE);
-      }
-      else {
-        $item = node_prepare($item, $teaser);
-      }
-      node_invoke_nodeapi($item, 'view', $teaser, FALSE);
-    }
-    switch ($item_length) {
-      case 'fulltext':
-        $item_text = $item->body;
-        break;
-      case 'teaser':
-        $item_text = $item->teaser;
-        if ($item->readmore) {
-          $item_text .= '<p>'. l(t('read more'), 'node/'. $item->nid, NULL, NULL, NULL, TRUE) .'</p>';
-        }
-        break;
-      case 'title':
-        $item_text = '';
-        break;
-    }
-    $extra = node_invoke_nodeapi($item, 'rss item');
-    $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' =>  date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name), array('key' => 'guid', 'value' => $item->nid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'false'))));
+    $extra_defaults = array(
+      array('key' => 'pubDate', 'value' =>  date('r', $node->created)),
+      array('key' => 'dc:creator', 'value' => $node->name),
+      array('key' => 'guid', 'attributes' => array('isPermaLink' => 'false'),
+            'value' => $base_url . '/node/' . $node->nid)
+    );
+    $extra = node_invoke_nodeapi($node, 'rss item');
+    $extra = array_merge($extra, $extra_defaults);
     $namespaces = array();
     foreach ($extra as $element) {
       if ($element['namespace']) {
         $namespaces[] = $element['namespace'];
       }
     }
-    $items .= format_rss_item($item->title, $link, $item_text, $extra);
-    // COPIED from node_feed() end
-    
-    $channel = array(
-      'title'       => check_plain(variable_get('site_name', 'drupal') .' - '. $item->title) .' - '. t('Comments'),
-      'link'        => $link,
-      'description' => t('Comments for "@title"', array("@title" => $item->title)),
-    );
-    
-    commentrss_format_feed($items, $channel, $namespaces);
-    return TRUE;
-  }
-  return FALSE;
-}
 
-// Provides a comment feed for nodes of a certain type
-function commentrss_feed_nodetype() {
-  $type = arg(2);
-  if (preg_match("!^[a-z0-9-]+$!", $type)) {
-    
-    $items = commentrss_format_items('n.nid', '', "n.type = '%s' AND", $type);
-    
-    $typename = node_get_types('name', $type);
     $channel = array(
-      'title'       => check_plain(variable_get('site_name', 'drupal') .' - '. $typename) .' - '. t('Comments'),
-      // no module provides a page for this type of listing
-      //'link'        => url("nodesbytype/$type", NULL, NULL, TRUE),
-      'description' => t('Comments for "@type"', array("@type" => $typename)),
+      'title' => check_plain(variable_get('site_name', 'drupal')) . ' - ' . t('Comments for "@title"', array('@title' => $node->title)),
+      'link' => $link,
+      'description' => t('Comments for this article'),
     );
-    
-    commentrss_format_feed($items, $channel);
+
+    commentrss_format_feed($items, $channel, $namespaces);
     return TRUE;
   }
   return FALSE;
@@ -208,7 +169,7 @@
 // This is a customized version of the core node_feed()
 function commentrss_format_feed($items, $channel = array(), $namespaces = array()) {
   global $base_url, $locale;
-  
+
   $channel_defaults = array(
     'version'     => '2.0',
     'title'       => check_plain(variable_get('site_name', 'drupal')) . ' - ' . t('Comments'),
@@ -218,13 +179,13 @@
   );
   $channel = array_merge($channel_defaults, $channel);
   $namespaces = array_merge(array('xmlns:dc="http://purl.org/dc/elements/1.1/"'), $namespaces);
-  
+
   $output = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
   $output .= '<rss version="'. $channel["version"] . '" xml:base="'. $base_url .'" ' . implode(' ', $namespaces) . ">\n";
   $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']);
   $output .= "</rss>\n";
 
-  drupal_set_header('Content-Type: text/xml; charset=utf-8');
+  drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
   print $output;
 }
 
@@ -257,3 +218,26 @@
   }
   return $items;
 }
+
+/**
+ * Menu callback; displays the commentrss module settings page.
+ */
+function commentrss_admin_settings() {
+  $form['commentrss_site'] = array('#type' => 'checkbox',
+    '#title' => t('Node comments for entire site'),
+    '#default_value' => variable_get('commentrss_site', FALSE));
+  $form['commentrss_node'] = array('#type' => 'checkbox',
+    '#title' => t('Node comments for individual nodes'),
+    '#default_value' => variable_get('commentrss_node', FALSE));
+  $form['commentrss_term'] = array('#type' => 'checkbox',
+    '#title' => t('Node comments for a term'),
+    '#default_value' => variable_get('commentrss_term', FALSE));
+  if (module_exists('vocabulary_list')) {
+    $form['commentrss_vocab'] = array('#type' => 'checkbox',
+      '#title' => t('Node comments for a vocabulary'),
+      '#default_value' => variable_get('commentrss_vocab', FALSE));
+  }
+
+  return system_settings_form($form);
+}
+
