Index: google_image_sitemap.module
===================================================================
diff --git a/trunk/sites/all/modules/contrib/google_image_sitemap/google_image_sitemap.module b/trunk/sites/all/modules/contrib/google_image_sitemap/google_image_sitemap.module
--- a/trunk/sites/all/modules/contrib/google_image_sitemap/google_image_sitemap.module	(revision 2558)
+++ b/trunk/sites/all/modules/contrib/google_image_sitemap/google_image_sitemap.module	(working copy)
@@ -267,7 +267,7 @@
     // Get records.
     $query = db_select('node', 'n');
     $query->fields('n', array('nid', 'created', 'title'));
-    $query->innerJoin('file_usage', 'fu', "n.nid = fu.id");
+    $query->innerJoin('file_usage', 'fu', "n.nid = fu.id AND fu.type = 'node'");
     $query->innerJoin('file_managed', 'f', "fu.fid = f.fid");
     $query->fields('f', array('uri'));
     // Use a 'node_access' tag with a query to find out how many this user has
@@ -281,6 +281,40 @@
     $query->orderBy('f.timestamp', 'DESC');
     $query->range(($sitemap_obj->range_start - 1), ($sitemap_obj->range_end));
     $nodes = $query->execute()->fetchAll();
+    
+    // If the field collection module exists, we also need to collect the images
+    // in field collections added to these nodes
+    if (module_exists('field_collection')) {
+      $fields_info = field_info_instances('node', $sitemap_obj->node_type);
+      
+      foreach ($fields_info as $field_name => $field_info) {
+        // Is the field a field collection?
+        if ($field_info['widget']['module'] == 'field_collection') {
+          // Get records.
+          $field_collection_query = db_select('node', 'n');
+          $field_collection_query->fields('n', array('nid', 'created', 'title'));
+          
+          // Use a 'node_access' tag with a query to find out how many this user has
+          // access to. This will be the standard way to make lists while respecting
+          // node access restrictions.
+          $field_collection_query->addTag('node_access');
+          $field_collection_query->innerjoin('field_data_' . $field_name, $field_name, 'n.nid = ' . $field_name . '.entity_id');
+          $field_collection_query->innerJoin('file_usage', 'fu', $field_name . "." . $field_name . "_value = fu.id AND fu.type = 'field_collection_item'");
+          $field_collection_query->innerJoin('file_managed', 'f', "fu.fid = f.fid");
+          
+          $field_collection_query->fields('f', array('uri'));
+          $field_collection_query->condition('n.type', $sitemap_obj->node_type);
+          $field_collection_query->condition('n.status', NODE_PUBLISHED);
+          $field_collection_query->condition('f.filemime', array('image/png', 'image/jpg', 'image/gif', 'image/jpeg'), 'IN');
+          $field_collection_query->orderBy('n.created', 'DESC');
+          $field_collection_query->orderBy('f.timestamp', 'DESC');
+          $nodes_field_collection = $field_collection_query->execute()->fetchAll();
+          
+          $nodes = array_merge($nodes, $nodes_field_collection);
+        }
+      }
+    }
+    
     // Create only if images are found.
     if (count($nodes) > 0) {
       $output = '<?xml version="1.0" encoding="UTF-8"?>';
