Index: aggregation_block.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/aggregation_block/aggregation_block.module,v
retrieving revision 1.2
diff -u -p -r1.2 aggregation_block.module
--- aggregation_block.module	13 Aug 2010 15:26:19 -0000	1.2
+++ aggregation_block.module	5 Nov 2010 19:29:55 -0000
@@ -50,73 +49,42 @@ function aggregation_block_init() {
 */
 function aggregation_block_block($op = 'list', $delta = 0, $edit = array()) {
   if ($op == 'list') {
-    $sql = <<<EOT
-SELECT n.title, n.nid AS fid, ab.usefeed
-FROM node {n}
-LEFT JOIN {aggregation_block} ab ON ab.fid = n.nid
-WHERE n.type='aggregation_feed'
-AND ab.usefeed=1
-ORDER BY n.title
-EOT;
-
-      $res = db_query($sql);
-      while ($row = db_fetch_object($res)) {
-        $blocks[$row->fid]['info'] = t('Aggregation Feed: '. $row->title);
-        $item_node = node_load($row->nid);
-      }
+    $res = db_query("SELECT n.title, n.nid AS fid, ab.usefeed FROM {node} LEFT JOIN {aggregation_block} ab ON ab.fid = n.nid WHERE n.type = 'aggregation_feed' AND ab.usefeed = 1 ORDER BY n.title");
+    while ($row = db_fetch_object($res)) {
+      $blocks[$row->fid]['info'] = t('Aggregation Feed: '. $row->title);
+      $item_node = node_load($row->nid);
+    }
     return $blocks;
   }
   elseif ($op == 'view') {
     if (user_access('access content')) {
       // get agg block settings
-      $sql = <<<EOT
-SELECT ab.feedtitle AS feedtitle, ab.showfeed AS feedlimit, ab.fid as feednid
-FROM {node} n
-LEFT JOIN {aggregation_block} ab ON ab.fid=n.nid
-LEFT JOIN {aggregation_feed} af ON af.nid=n.nid
-WHERE n.type='aggregation_feed'
-AND ab.fid=%d
-AND ab.usefeed=1
-EOT;
-      $res = db_query($sql, $delta);
-      $row = db_fetch_object($res);
+      $row = db_fetch_object(db_query("SELECT ab.feedtitle AS feedtitle, ab.showfeed AS feedlimit, ab.fid as feednid FROM {node} n LEFT JOIN {aggregation_block} ab ON ab.fid = n.nid LEFT JOIN {aggregation_feed} af ON af.nid = n.nid WHERE n.type='aggregation_feed' AND ab.fid= %d AND ab.usefeed = 1", $delta));
       $feedtitle = $row->feedtitle;
       $feedlimit = $row->feedlimit;
       $feednid = $row->feednid;
       
       // get feed items and build block
-      $sql = <<<EOT
-SELECT n.title AS itemtitle, ai.url
-FROM {aggregation_item} ai
-INNER JOIN {node} n ON n.nid=ai.nid
-WHERE ai.fid=%d
-ORDER BY n.created DESC
-LIMIT %d
-EOT;
-
-      $res = db_query($sql, $delta, $feedlimit);
-      $list = '<ul>';
+      $res = db_query("SELECT n.title AS itemtitle, ai.url FROM {aggregation_item} ai INNER JOIN {node} n ON n.nid = ai.nid WHERE ai.fid = %d ORDER BY n.created DESC LIMIT %d", $delta, $feedlimit);
+      $items = array();
       while ($row = db_fetch_object($res)) {
-        $list .= '<li>'. l($row->itemtitle, $row->url, array('absolute' => TRUE)) .'</li>';
+        $items[] = l($row->itemtitle, $row->url, array('absolute' => TRUE));
       }
-      $list .= '</ul>';
+      $block['content'] = theme('item_list', $items);
       if (variable_get('aggregation_block_showmore', TRUE)) {
         // add "more" link
-        $footer = '<div class="aggblock-footer">'. l('show all...', 'node/'. $feednid, array('absolute' => TRUE)) .'</div>';
-        $list = $list . $footer;
+        $block['content'] .= '<div class="aggblock-footer">'. l('show all...', 'node/'. $feednid, array('absolute' => TRUE)) .'</div>';
       }
       $block['subject'] = $feedtitle;
-      $block['content'] = $list;
     }
-  return $block;
+    return $block;
   }
 }
 
-
-/***
-* implementation of hook_theme()
-* 
-*/
+/**
+ * Implements hook_theme().
+ */
 function aggregation_block_theme() {
   return array(
     'aggregation_block_form' => array(
@@ -125,8 +93,6 @@ function aggregation_block_theme() {
   );
 }
 
-
-
 /**
  * Theme function for the image import form.
  */
@@ -172,17 +138,8 @@ EOT;
  */
 function aggregation_block_form() {
   // get list of available feeds, loop through them to build the form
-  $sql = <<<EOT
-SELECT n.title, af.url, ai.fid, COUNT(ai.fid) AS items, ab.showfeed, ab.usefeed, ab.feedtitle
-FROM node n 
-INNER JOIN aggregation_feed af ON n.nid = af.nid
-INNER JOIN aggregation_item ai ON af.nid = ai.fid 
-LEFT JOIN aggregation_block ab ON ab.fid = ai.fid 
-GROUP BY ai.fid
-ORDER BY n.title
-EOT;
+  $res = db_query("SELECT n.title, af.url, ai.fid, COUNT(ai.fid) AS items, ab.showfeed, ab.usefeed, ab.feedtitle FROM {node} n INNER JOIN {aggregation_feed} af ON n.nid = af.nid INNER JOIN {aggregation_item} ai ON af.nid = ai.fid LEFT JOIN {aggregation_block} ab ON ab.fid = ai.fid GROUP BY ai.fid ORDER BY n.title");
 
-  $res = db_query($sql);
   $index = 0;
   while ($row = db_fetch_object($res)) {
     $index++;   // ensure 1-based index because a checkbox with a zero value is seen as
@@ -230,8 +187,6 @@ EOT;
   return $form;
 }
 
-
-
 /**
  * Submit handler for the aggregation block form.
  */
@@ -245,16 +200,14 @@ function aggregation_block_form_submit($
   );
 
   for ($i=1; $i <= count($form_state['values']['fid']); $i++) {
-    $res = db_query("SELECT COUNT(*) FROM {aggregation_block} WHERE fid='%d'", $form_state['values']['fid'][$i]);
+    $res = db_query("SELECT COUNT(*) FROM {aggregation_block} WHERE fid = %d", $form_state['values']['fid'][$i]);
     if (db_result($res) == 0) {
       // no entry for this feed; insert it
       db_query("INSERT INTO {aggregation_block} (fid, usefeed, showfeed, feedtitle) VALUES (%d, %d, %d, '%s')", $form_state['values']['fid'][$i], $form_state['values']['usefeed'][$i], $form_state['values']['showfeed'][$i], $form_state['values']['feedtitle'][$i]);
     }
     else {
       // has feed, update values
-      db_query("UPDATE {aggregation_block} SET usefeed=%d, showfeed=%d, feedtitle='%s' WHERE fid=%d", $form_state['values']['usefeed'][$i], $form_state['values']['showfeed'][$i], $form_state['values']['feedtitle'][$i], $form_state['values']['fid'][$i]);
+      db_query("UPDATE {aggregation_block} SET usefeed = %d, showfeed = %d, feedtitle = '%s' WHERE fid = %d", $form_state['values']['usefeed'][$i], $form_state['values']['showfeed'][$i], $form_state['values']['feedtitle'][$i], $form_state['values']['fid'][$i]);
     }
   }
 }
-
-
