Index: syndication.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/syndication/syndication.module,v
retrieving revision 1.47.2.4
diff -u -r1.47.2.4 syndication.module
--- syndication.module	4 Jun 2007 18:23:06 -0000	1.47.2.4
+++ syndication.module	12 Feb 2008 19:46:43 -0000
@@ -8,21 +8,28 @@
   $items = array();
 
   if ($may_cache) {
-    $items[] = array('path' => 'syndication', 'title' => t('RSS feeds'),
-    '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);
+    $items[] = array(
+      'path' => 'syndication', 'title' => t('RSS feeds'),
+      '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;
 }
 
+/**
+ * Implementation of hook_block().
+ */
 function syndication_block($op = 'list', $delta = 0) {
   if($op == 'list') {
     $blocks[0]['info'] = 'Syndicate (more)';
@@ -35,16 +42,20 @@
       if ($pagetype == 'blog') {
         $userid = arg(1);
         $linkurl = is_numeric($userid) ? "blog/$userid/feed" : 'blog/feed';
-      } else {
+      }
+      else {
         $linkurl = 'rss.xml';
       }
       $block['content'] = theme('feed_icon', url($linkurl));
-      $block['content'] .= '<div class="more-link">'. l(t('more'), 'syndication', array ('title' => t("Review all XML feeds exported by %sn", array ("%sn" => variable_get('site_name', 'Drupal'))))). "</div>\n";
+      $block['content'] .= '<div class="more-link">'. l(t('more'), 'syndication', array('title' => t("Review all XML feeds exported by %sn", array("%sn" => variable_get('site_name', 'Drupal'))))) ."</div>\n";
       return $block;
     }
   }
 }
 
+/**
+ * Syndication page.
+ */
 function syndication_page () {
   $output = '';
   if (module_exists('atom')) {
@@ -60,12 +71,13 @@
     $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
+    // Only bother generating the box if there are enabled views feeds.
+    if ($views = syndication_views_rss()){
       $output .= theme('box', t('Views'), $views);
     }
   }
 
-  // modules may add their own syndication boxes
+  // Modules may add their own syndication boxes.
   $result = array();
   foreach (module_list() as $name) {
     $result = module_invoke($name, 'syndication', $edit);
@@ -78,23 +90,34 @@
   if (empty($output)) {
     $output = t('Sorry, there are no feeds available.');
   }
+
   return $output;
 }
 
+/**
+ * Generate a form for searching for user blogs feeds.
+ */
 function syndication_users() {
   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>';
+    $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>';
   }
-  $form['name'] = array('#type' => 'textfield',
+  $form['name'] = array(
+    '#type' => 'textfield',
     '#title' => t('Search users'),
     '#prefix' => $prefix,
-    '#description' => t('Enter a username to view her blog feed, and other details.'));
+    '#description' => t('Enter a username to view her blog feed, and other details.'),
+  );
   $form['submit'] = array('#type' => 'button', '#value' => t('Search'));
+
   return $form;
 }
 
+/**
+ * Generate a list of feeds for personal blogs.
+ */
 function syndication_blogs() {
   $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)) {
@@ -103,18 +126,18 @@
     $authors[] = $author;
   }
   if ($authors) {
-    $output =  theme('item_list', $authors, t('Recent Blog Authors'));
+    $output = theme('item_list', $authors, t('Recent Blog Authors'));
   }
 
   $output .= drupal_get_form('syndication_users');
 
   if ($name = $_POST['name']) {
-    // TODO: this query was already executed in validate hook. if i knew what i was doing, i would not run it again here.
+    // TODO: This query was already executed in validate hook. If I knew what I was doing, I would not run it again here.
     $result = db_query("SELECT uid, name FROM {users} WHERE uid > 0 and name LIKE '%s' ORDER BY access DESC", '%'. $name. '%');
     $i=0;
     while ($account = db_fetch_object($result)) {;
-   	  $rows[$i][] = theme('username', $account). ':';
-   	  $rows[$i][] = l(t("RSS feed"), "blog/$account->uid/feed");
+       $rows[$i][] = theme('username', $account). ':';
+       $rows[$i][] = l(t("RSS feed"), "blog/$account->uid/feed");
       if (module_exists('atom')) {
         $rows[$i][] = l(t("Atom feed"), "blog/$account->uid/atom/feed");
       }
@@ -122,20 +145,23 @@
       $i++;
     }
     if ($rows) {
-  	  $output .= theme('table', array(), $rows);
+      $output .= theme('table', array(), $rows);
     }
   }
   $output .= $frm;
+
   return $output;
 }
 
-// follows a similar pattern from og_vocab.module
-// should ideally be in taxonomy.module
+/**
+ * Follows a similar pattern from og_vocab.module should ideally be in
+ * taxonomy.module.
+ */
 function syndication_vocabularies() {
   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) {
@@ -145,7 +171,9 @@
   return $output;
 }
 
-// helper function for syndication_taxonomy
+/**
+ * Helper function for syndication_taxonomy.
+ */
 function syndication_taxonomy_build_list_items(&$index, $tree) {
   $items = array();
   $current_depth = $tree[$index]->depth;
@@ -156,9 +184,9 @@
       $term_path = "taxonomy/term/$term->tid/0/feed";
       $term_link = l(t($term->name), $term_path, array('title' => t($term->description)));
       if ($term->depth) {
-        $prefix = str_repeat('--', $term->depth). ' ';
+        $prefix = str_repeat('--', $term->depth) .' ';
       }
-      $item = $prefix. $term_link . " ($count)";
+      $item = $prefix . $term_link ." ($count)";
       $items[] = $item;
       $index++;
     }
@@ -169,6 +197,9 @@
   return $items;
 }
 
+/**
+ * Validates user blog feed search form.
+ */
 function syndication_users_validate($form_id, &$form) {
   $result = db_query("SELECT uid, name FROM {users} WHERE name LIKE '%s' AND uid > 0 ORDER BY access DESC", '%'. $form["name"]. '%');
   if (db_num_rows($result)) {
@@ -176,25 +207,35 @@
   }
   else {
     form_set_error('name', t('Username not found.'));
-	  drupal_goto('syndication');
+    drupal_goto('syndication');
   }
 }
 
+/**
+ * Generates a link to aggregator.module OPML file.
+ */
 function syndication_opml() {
   $url = l(t('this OPML file'), 'aggregator/opml');
   $output = t('In addition to displaying RSS feeds, <i>%sn</i> offers %link which lists all RSS feeds that are collected here.', array ('%sn' => variable_get('site_name', 'Drupal'), '%link' => $url));
   return $output;
 }
 
+/**
+ * Generates a list of feeds from views_rss.module.
+ */
 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
+    // Throw away the vids that aren't enabled.
+    if (!$value) {
+      unset($vids[$key]);
+    }
   }
-  if ($vids) { //only bother getting results if at least one vid is enabled
+  // Only bother getting results if at least one vid is enabled.
+  if ($vids) {
     $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'));
+      $rows[] = l($view->page_title, $view->url .'/feed', array('class' => 'syndication_view_rss'));
     }
     $output = theme('syndication_views_rss', $rows);
   }
@@ -202,11 +243,13 @@
 }
 
 /**
- * Helper function to get all views that generate rss feeds from the database
- * Accepts an array of views ids (vids) to limit the results
+ * 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
+ * @param $args
+ *   An array of views ids.
+ * @return
+ *   Database result object or null if no feeds exist.
  */
 function _syndication_return_views_rss_feeds($args = array()){
   if (count($args) > 0) {
@@ -217,7 +260,9 @@
   if ($where){
     $where_clause = ' AND arg.vid IN ('. implode(', ', $where) .')';
   }
-  array_unshift($args, 'rss_feed'); //first query argument is always rss_feed
+
+  // First query argument is always rss_feed.
+  array_unshift($args, '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);
 
@@ -226,6 +271,9 @@
   }
 }
 
+/**
+ * Theme views_rss feeds list.
+ */
 function theme_syndication_views_rss($rows){
   if (is_array($rows)){
     $output = theme('item_list', $rows, '', 'ul');
@@ -233,35 +281,45 @@
   return $output;
 }
 
+/**
+ * Syndication module configuration form.
+ */
 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()),
-                                      '#description' => $description);
+  $form['syndication_vocabularies'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Vocabularies'),
+    '#options' => $options,
+    '#default_value' => variable_get('syndication_vocabularies', array()),
+    '#description' => $description,
+  );
 
-  if(module_exists('views') && module_exists('views_rss')){
+  if(module_exists('views') && module_exists('views_rss')) {
     $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['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);
 }
 
+/**
+ * Implementation of hook_help().
+ */
 function syndication_help($section) {
   $output = '';
   switch ($section) {
@@ -276,6 +334,9 @@
   return $output;
 }
 
+/**
+ * Helper function for syndication_help().
+ */
 function syndication_help_intro() {
   $output = '
 <p>Syndication.module offers a web page which centralizes all of the RSS feeds
@@ -290,10 +351,13 @@
 </p>
 
 <h3>For Module Developers - Syndication hook</h3>';
+
   return $output;
 }
 
-// TODO: move this to Doxygen
+/**
+ * TODO: move this to Doxygen.
+ */
 function syndication_help_api() {
 
   $output = '
@@ -317,5 +381,6 @@
       return  $block;
     }
     </pre>';
+
   return $output;
-}
\ No newline at end of file
+}
