Index: modules/syndication/syndication.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/syndication/syndication.module,v
retrieving revision 1.40.2.5
diff -u -r1.40.2.5 syndication.module
--- modules/syndication/syndication.module	24 Dec 2006 05:08:08 -0000	1.40.2.5
+++ modules/syndication/syndication.module	16 Mar 2007 02:03:58 -0000
@@ -12,6 +12,13 @@
     'access' => user_access('access content'),
     'callback' => 'syndication_page',
     'weight' => 6);
+
+    $items[] = array('path' => 'admin/content/syndication',
+                     'title' => t('RSS feed syndication'),
+                     'access' => user_access('access administration pages'),
+                     'callback' => 'drupal_get_form',
+                     'callback arguments' => array('syndication_admin_settings'),
+                     'type' => MENU_NORMAL_ITEM);
   }
   return $items;
 }
@@ -40,19 +47,24 @@
 
 function syndication_page () {
   $output = '';
-  if (module_exist('atom')) {
+  if (module_exists('atom')) {
     $output .= theme('box', t('Atom feed'), l(t('Atom front page feed'), 'atom/feed'));
   }
   if (function_exists('blog_feed_user')) {
     $output .= theme('box', t('Blogs'), syndication_blogs());
   }
-  if (module_exist('aggregator') && user_access('access news feeds')) {
+  if (module_exists('aggregator') && user_access('access news feeds')) {
     $output .= theme('box', t('External feeds'), syndication_opml());
   }
-  if (module_exist('taxonomy') && user_access('access content')) {
+  if (module_exists('taxonomy') && user_access('access content')) {
     $output .= theme('box', t('Categories'), syndication_vocabularies());
   }
-  
+  if (module_exists('views') && module_exists('views_rss') && user_access('access content')){
+    if ($views = syndication_views_rss()){ //only bother generating the box if there are enabled views feeds
+      $output .= theme('box', t('Views'), $views);
+    }
+  }
+
   // modules may add their own syndication boxes
   $result = array();
   foreach (module_list() as $name) {
@@ -70,7 +82,7 @@
 }
 
 function syndication_blogs() {
-  if(module_exist('atom')) {
+  if(module_exists('atom')) {
     $prefix = '<p>'. t("At <i>%sn</i>, all users have a %rss and %atom feed for their blog, as well as each individual user.", array ('%sn' => variable_get('site_name', 'Drupal'), '%rss' => l(t('RSS'), 'blog/feed'), '%atom' => l(t('Atom'), 'blog/atom/feed'))). '</p>';
   } else {
     $prefix = '<p>'. t('At <i>%sn</i>, %all and each user, have an RSS feed for their blog.', array ('%sn' => variable_get('site_name', 'Drupal'), '%all' => l(t('all users'), 'blog/feed'))). '</p>';
@@ -78,11 +90,11 @@
   $result = db_query_range("SELECT DISTINCT(u.uid), u.name FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.type = 'blog' AND n.status = 1", 0, 16);
   while ($account = db_fetch_object($result)) {
     $author = $account->name .': '. l(t('RSS feed'), "blog/$account->uid/feed");
-    $author .= module_exist('atom') ? ', '. l(t('Atom feed'), "blog/$account->uid/atom/feed") : '';
+    $author .= module_exists('atom') ? ', '. l(t('Atom feed'), "blog/$account->uid/atom/feed") : '';
     $authors[] = $author;
   }
   if ($authors) {
-    $output =  theme('item_list', $authors, t('Recent Blog Authors'));  
+    $output =  theme('item_list', $authors, t('Recent Blog Authors'));
   }
 
   $form['name'] = array('#type' => 'textfield',
@@ -99,7 +111,7 @@
     while ($account = db_fetch_object($result)) {;
    	  $rows[$i][] = theme('username', $account). ':';
    	  $rows[$i][] = l(t("RSS feed"), "blog/$account->uid/feed");
-      if (module_exist('atom')) {
+      if (module_exists('atom')) {
         $rows[$i][] = l(t("Atom feed"), "blog/$account->uid/atom/feed");
       }
       $rows[$i][] = l(t("blog"), "blog/$account->uid");
@@ -119,10 +131,10 @@
   foreach (variable_get('syndication_vocabularies', array()) as $vid) {
     $vocab = taxonomy_get_vocabulary($vid);
     $tree = taxonomy_get_tree($vid);
-    // only show first 30 terms. wary of huge vocabs. not ideal. 
+    // only show first 30 terms. wary of huge vocabs. not ideal.
     $tree = array_slice($tree, 0, 30);
     $items = syndication_taxonomy_build_list_items($index = 0, $tree);
-    if ($items) {  
+    if ($items) {
       $output .= theme('item_list', $items, $vocab->name);
     }
   }
@@ -170,17 +182,78 @@
   return $output;
 }
 
-function syndication_settings() {
+function syndication_views_rss() {
+  $vids = variable_get('syndication_views', array());
+  foreach ($vids as $key => $value){
+    if (!$value) unset($vids[$key]); //throw away the vids that aren't enabled
+  }
+  if ($vids) { //only bother getting results if at least one vid is enabled
+    $result = _syndication_return_views_rss_feeds($vids);
+    while ($view = db_fetch_object($result)) {
+      $rows[] = l($view->page_title, $view->url . '/feed', array('class' => 'syndication_view_rss'));
+    }
+    $output = theme('syndication_views_rss', $rows);
+  }
+  return $output;
+}
+
+/**
+ * Helper function to get all views that generate rss feeds from the database
+ * Accepts an array of views ids (vids) to limit the results
+ *
+ * @param  $args - an array of views ids
+ * @return  $result - database result object or null if no feeds exist
+ */
+function _syndication_return_views_rss_feeds($args = array()){
+  if (count($args) > 0) {
+    for($i == 1; $i <= count($args); $i++){
+      $where[] =  '%d';
+    }
+  }
+  if ($where){
+    $where_clause = ' AND arg.vid IN ('. implode(', ', $where) .')';
+  }
+  array_unshift($args, 'rss_feed'); //first query argument is always rss_feed
+  $query = "SELECT v.vid, v.page_title, v.url FROM {view_view} v LEFT JOIN {view_argument} arg ON arg.vid = v.vid WHERE arg.type = '%s'" . $where_clause;
+  $result = db_query($query, $args);
+
+  if (db_num_rows($result) > 0){
+    return $result;
+  }
+}
+
+function theme_syndication_views_rss($rows){
+  if (is_array($rows)){
+    $output = theme('item_list', $rows, '', 'ul');
+  }
+  return $output;
+}
+
+function syndication_admin_settings() {
   foreach (taxonomy_get_vocabularies() as $vid => $vocab) {
     $options[$vid] = $vocab->name;
   }
   $description = t('Select the vocabularies which should appear in the <em>Categories</em> block on the %page', array('%page' => l(t('syndication page'), 'syndication')));
-  $form['syndication_vocabularies'] = array('#type' => 'checkboxes', 
-                                      '#title' => t('Vocabularies'), 
-                                      '#options' => $options, 
-                                      '#default_value' => variable_get('syndication_vocabularies', array()), 
+  $form['syndication_vocabularies'] = array('#type' => 'checkboxes',
+                                      '#title' => t('Vocabularies'),
+                                      '#options' => $options,
+                                      '#default_value' => variable_get('syndication_vocabularies', array()),
                                       '#description' => $description);
-  return $form;
+
+  $options = array();
+  $result = _syndication_return_views_rss_feeds();
+  while ($view = db_fetch_object($result)){
+    $options[$view->vid] = $view->page_title;
+  }
+
+  $description = t('Select the views which should appear in the <em>Views</em> block on the %page', array('%page' => l(t('syndication page'), 'syndication')));
+  $form['syndication_views'] = array('#type' => 'checkboxes',
+                               '#title' => t('Views'),
+                               '#options' => $options,
+                               '#default_value' => variable_get('syndication_views', array()),
+                               '#description' => $description);
+  $form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
+  return system_settings_form($form);
 }
 
 function syndication_help($section) {
