Index: stockapi.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/stockapi/stockapi.module,v
retrieving revision 1.9.2.1
diff -a -u -u -p -r1.9.2.1 stockapi.module
--- stockapi.module	3 Feb 2009 17:25:31 -0000	1.9.2.1
+++ stockapi.module	12 Jun 2010 01:39:33 -0000
@@ -108,27 +108,48 @@ function stockapi_fetch($symbol) {
     return FALSE;
   }
 
-  $data = explode(',', $result->data);
-
-  for ($i=0; $i < count($data); $i++) {
-    $value = trim($data[$i]);
-    if ((substr($value, 0, 1) == '"') && (substr($value, strlen($value) - 1, 1)) != '"') {
-      $data[$i] = str_replace('"', '', ($value .','. $data[$i+1]));
-      unset($data[$i+1]);
-      $i++;
+  // If we have fetched multiple stocks we need to parse them individually.
+  $symbols = explode('+', $symbol);
+  $stocks = explode("\r\n", $result->data);
+  
+  foreach ($stocks as $symbol_key => $stock) {  
+    $data = explode(',', $stock);
+  
+    // The last element of $stocks will have only one empty element. Let's weed it out.
+    if (count($data) == 1) {
+      continue;
+    }
+    
+    for ($i=0; $i < count($data); $i++) {
+      $value = trim($data[$i]);
+      if ((substr($value, 0, 1) == '"') && (substr($value, strlen($value) - 1, 1)) != '"') {
+        $data[$i] = str_replace('"', '', ($value .','. $data[$i+1]));
+        unset($data[$i+1]);
+        $i++;
+      }
+      else {
+        $data[$i] = str_replace('"', '', $value);
+      }
+    }
+    
+    if (!$data) { 
+      // This assumes that the order of the data returned by Yahoo! is the same as
+      // the one in which the symbols have been passed
+      watchdog('stockapi', t('StockAPI: no data for symbol(s): @symbol', array('@symbol' => $symbols[$symbol_key])));
+      return FALSE;
     }
     else {
-      $data[$i] = str_replace('"', '', $value);
+      // This assumes that the order of the data returned by Yahoo! is the same as
+      // the one in which the symbols have been passed
+      $output[$symbols[$symbol_key]] = $data;
     }
   }
-
-  if (!$data) {
-    watchdog('stockapi', t('StockAPI: no data for symbol(s): @symbol', array('@symbol' => $symbol)));
-    return FALSE;
+  // Maintain backward compatibility
+  if (count($output) == 1) {
+    $output = array_values(current($output));
   }
   
-  $data = array_values($data);
-  return $data;
+  return $output;
 }
 
 function stockapi_load($symbol) {
