? 663108_yr_blocks.patch
Index: yr_verdata.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/yr_verdata/yr_verdata.module,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 yr_verdata.module
--- yr_verdata.module	10 Jan 2010 16:13:31 -0000	1.1.2.3
+++ yr_verdata.module	1 Feb 2010 09:43:25 -0000
@@ -111,26 +111,46 @@ function yr_verdata_page($yid = 0) {
  * Implementation of hook_block().
  */
 function yr_verdata_block($op = 'list', $delta = 0, $edit = array()) {
+  $rows = yr_verdata_locations();
   switch ($op) {
     case 'list' :
+      foreach ($rows AS $row) {
+        $blocks['y-'.$row->yid]['info'] = $row->subregion . ', ' . $row->region . ', ' . $row->country;
+      }
       $blocks[0]['info'] = t('Yr.no Weather Forecast');
       $blocks[0]['cache'] = BLOCK_NO_CACHE;
       return $blocks;
     case 'view' :
-      $sql = "SELECT * FROM {yr_verdata} ORDER BY '%s', location ASC";
-      $order = variable_get('yr_verdata_order', 'subregion');
-      $result = db_query($sql, $order);
-      $rows = array();
-      while ($row = db_fetch_object($result)) {
-        $rows[] = $row;
+      if ($delta == 0) {
+        $block['subject'] = t('Weather Forecast');
+        $block['content'] = theme('yr_verdata_location_block', $rows);
+      }
+      foreach ($rows AS $row) {
+        if ($delta == 'y-' . $row->yid) {
+          $block['subject'] = t('Weather Forecast');
+          $block['content'] = theme('yr_verdata_location_block', $row);
+        }
       }
-      $block['subject'] = t('Weather Forecast');
-      $block['content'] = theme('yr_verdata_location_block', $rows);
       return $block;
   }
 }
 
 /**
+ * Helper function to return all locations.
+ */
+function yr_verdata_locations() {
+  $sql = "SELECT * FROM {yr_verdata} ORDER BY '%s', location ASC";
+  $order = variable_get('yr_verdata_order', 'subregion');
+  $result = db_query($sql, $order);
+  $rows = array();
+  while ($row = db_fetch_object($result)) {
+    $rows[] = $row;
+  }
+
+  return (!empty($rows) ? $rows : array());
+}
+
+/**
  * Implementation of hook_theme().
  */
 function yr_verdata_theme() {
@@ -344,6 +364,12 @@ function theme_yr_verdata_location_block
   $modpath = drupal_get_path('module', 'yr_verdata');
   drupal_add_css($modpath .'/yr_verdata.css');
   $output = '';
+
+  // check if we're just getting a single location.
+  if (!is_array($rows)) {
+    $rows = array($rows);
+  }
+
   foreach ($rows as $row) {
     // Make sure there are no punctuation in the url, as this could possibly lead to a malicious user
     // navigating elsewhere in the filesystem?
@@ -377,7 +403,10 @@ function theme_yr_verdata_location_block
     $output .= theme('yr_verdata_block_location', $location);
   }
 
-  $output .= '<div class="yr-credit"><p>'. t('<a href="!yrl" title="Go to yr.no to view forecasts for more than 7 million locations across the globe">Forecast from yr.no</a>', array('!yrl' => 'http://yr.no')) .'</p></div>';
+  // check if ooutput is empty, don't add credit. Stops the blocks from showing just the credit.
+  if ($output != '') {
+    $output .= '<div class="yr-credit"><p>'. t('<a href="!yrl" title="Go to yr.no to view forecasts for more than 7 million locations across the globe">Forecast from yr.no</a>', array('!yrl' => 'http://yr.no')) .'</p></div>';
+  }
   return $output;
 }
 
