Index: modules/content_retriever/content_retriever.module
===================================================================
--- modules/content_retriever/content_retriever.module	(revision 1)
+++ modules/content_retriever/content_retriever.module	(working copy)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @author Greg Harvey - http://www.drupaler.co.uk 
+ * @author Greg Harvey - http://www.drupaler.co.uk
  */
 
 /**
@@ -16,14 +16,14 @@
  */
 function content_retriever_form_alter(&$form, $form_state, $form_id) {
   if($form_id === 'node_type_form' && $_GET['type']){
-  	$form['identity']['type']['#default_value'] = $_GET['type'];
+    $form['identity']['type']['#default_value'] = $_GET['type'];
   }
 }
 /**
  * Implementation of hook_menu().
  */
 function content_retriever_menu() {
-  
+
   //the admin page
   $items['admin/settings/retriever'] = array(
     'title' => 'Content Retriever Settings',
@@ -35,7 +35,7 @@
     'type' => MENU_NORMAL_ITEM,
     'file' => 'content_retriever.admin.inc',
   );
-  
+
   $items['admin/settings/retriever/settings'] = array(
     'title' => 'Settings',
     'description' => t('Settings for content retrieval over web services from a central distribution server.'),
@@ -46,7 +46,7 @@
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'file' => 'content_retriever.admin.inc',
   );
-  
+
   $items['admin/settings/retriever/types'] = array(
     'title' => 'Content Types',
     'description' => t('Settings for content retrieval over web services from a central distribution server.'),
@@ -56,7 +56,7 @@
     'type' => MENU_LOCAL_TASK,
     'file' => 'content_retriever.admin.inc',
   );
-  
+
   $items['admin/settings/retriever/queues'] = array(
     'title' => 'Nodequeues',
     'description' => t('Nodequeues to interrogate on remote server to retrieve distributed content.'),
@@ -66,7 +66,7 @@
     'type' => MENU_LOCAL_TASK,
     'file' => 'content_retriever.admin.inc',
   );
-  
+
   //visual output for debug purposes
   $last_run = variable_get('content_retriever_last_run', (time() - (24 * 60 * 60)) );
   $items['admin/settings/retriever/output'] = array(
@@ -87,7 +87,7 @@
 function content_retriever_theme() {
   return array(
     'content_retriever_admin_page' => array(
-      'arguments' => array(),  
+      'arguments' => array(),
     ),
     'content_retriever_admin_types_page' => array(
       'arguments' => array(),
@@ -101,10 +101,10 @@
 
 /**
  * parses and saves nodes sent back from the web service
- * 
+ *
  * @param $last_run
  * timestamp - Unix time of last time process executed
- * 
+ *
  * @return
  * string of HTML for debug purposes only
  */
@@ -116,7 +116,7 @@
   $api_key = variable_get('content_retriever_api_key', '');
   //check if screen reporting messages for debug are on or off
   $screen_reports = variable_get('content_retriever_screen_messages', 0);
-  
+
   //fetch node data
   $nodes = _content_retriever_fetch_nodes($last_run);
   if ($nodes) {
@@ -124,33 +124,33 @@
       drupal_set_message('_content_retriever_fetch_nodes ran! No. of nodes: '.count($nodes));
     }
   }else{
-  	if($screen_reports != 0){
-  	  drupal_set_message(t('There are no new nodes to retrieve. Process complete.'));
-  	}
-  	return;
+    if($screen_reports != 0){
+      drupal_set_message(t('There are no new nodes to retrieve. Process complete.'));
+    }
+    return;
   }
 
   if ($nodes) {
     foreach ($nodes as $node) {
 
-      // get a handle on the original_nid stored in the local database 
+      // get a handle on the original_nid stored in the local database
       // to check if we already have a version of the incoming node
       $result = db_query("SELECT nid FROM {content_retriever} WHERE original_nid = %d",$node->nid);
       $nid = (int)db_result($result);
-       
+
       //we need to be a superuser to do this next stuff
       $temp_user = $user;
       $user = user_load(array('uid' => 1));
-            
+
       //store remote nid
       $remote_nid = $node->nid;
 
       //unset the CMS node ID
       unset($node->nid);
-      
+
       //if we have nodes carrying this CMS nid already, use that local ID so we update them as the NID
       if(!empty($nid)){
-        $node->nid = $nid;  
+        $node->nid = $nid;
         //need to get the latest revision id
         $result = db_query("SELECT MAX(vid) FROM {node_revisions} WHERE nid = %d",$node->nid);
         $vid = (int)db_result($result);
@@ -158,35 +158,35 @@
         // is a new revision
         $node->vid = $vid;
         $node->revision = 1;
-        
+
         if($screen_reports != 0){
           drupal_set_message(t('Updating node with nid: '. $nid));
         }
         watchdog(t('integration'), t('Updating node with nid: %nid.'), array('%nid' => $nid), WATCHDOG_NOTICE);
       }else{
-      	unset($node->vid);
-      }        
-      
+        unset($node->vid);
+      }
+
       //unset anything unique to each instance of Drupal and save the node
       unset($node->created);
       unset($node->changed);
-      
+
       unset($node->promote);
       unset($node->sticky);
-      
+
       unset($node->revision_uid);
       unset($node->revision_timestamp);
       unset($node->field_related_items);
-      
+
       unset($node->path);
-      
+
       unset($node->comment_count);
       unset($node->last_comment_timestamp);
       unset($node->last_comment_name);
-      
+
       //reset the teaser so a new, safe, teaser is created
       $node->teaser = node_teaser($node->body, $node->format);
-      
+
       unset($node->queues);
 
       //taxonomy parsing - rewrites the taxonomy object
@@ -194,94 +194,121 @@
         if ($node->taxonomy) {
           // construct array of term names from the $node->taxonomy
           $term_categories = array();
-          foreach($node->taxonomy as $term){         
+          foreach($node->taxonomy as $term){
             $term_categories[$term['name']]['vocab'] = $node->vocab_names[$term['tid']];
           }
           // parse the taxonomy and return taxonomy array to be attached to the node object
-          $node->taxonomy = taxonomy_parser_import_taxonomy($term_categories, $node->type);   
+          $node->taxonomy = taxonomy_parser_import_taxonomy($term_categories, $node->type);
         }
       }else{
-      	// module is not installed so capture the issue
-  		watchdog('integration', 'Failed to call taxonomy_parser_import_taxonomy(). The taxonomy_parser module is not available.', WATCHDOG_WARNING);
-      	unset($node->taxonomy);
+        // module is not installed so capture the issue
+      watchdog('integration', 'Failed to call taxonomy_parser_import_taxonomy(). The taxonomy_parser module is not available.', WATCHDOG_WARNING);
+        unset($node->taxonomy);
       }
-          
+
+      // nodereference
+      if (module_exists('nodereference')) {
+        $fields = content_fields();
+        if (!empty($fields)) {
+          foreach($fields as $content_type_field){
+            if ($content_type_field['type_name'] == $node->type && $content_type_field['module'] == 'nodereference') {
+              if(!empty($node->$content_type_field['field_name'])){
+                $nr_data = $node->$content_type_field['field_name'];
+                if (isset($nr_data[0]['nid']) && $nr_data[0]['nid'] != '') {
+                  $nr_newids = array();
+                  // Loop all values
+                  foreach ($nr_data as $nr_key => $nr_item) {
+                    // Try to find the new node id
+                    $result = db_query("select nid, original_nid FROM {content_retriever} as c WHERE c.original_nid = %d", $nr_item['nid']);
+                    $nr_new = (int)db_result($result);
+                    if ($nr_new && $nr_new != 0) {
+                      $nr_newids[] = array (nid => $nr_new);
+                    }
+                  }
+                  $node->$content_type_field['field_name'] = $nr_newids;
+                }
+              }
+            }
+          }
+        }
+      }
+
       //fetch imagefield / filefield files
       if((module_exists('imagefield')) || (module_exists('filefield'))){
-      	$fields = content_fields();
+        $fields = content_fields();
         $files_array = array();
         //check the cck field exists on the local content type
-        
+
         if (!empty($fields)) {
           foreach($fields as $content_type_field){
             if(($content_type_field['type_name'] == $node->type) && (($content_type_field['module'] == 'imagefield')) || ($content_type_field['module'] == 'filefield')){
-  	  	      if(!empty($node->$content_type_field['field_name'])){
+              if(!empty($node->$content_type_field['field_name'])){
                 $files_array[$content_type_field['field_name']] = $node->$content_type_field['field_name'];
-  		      }
-  	        }
+            }
+            }
           }
         }
-        
+
         $file_count = count($files_array);
         if ($file_count > 0) {
           // get a session id from system.service module
           $connect = content_retriever_xmlrpc($endpoint, 'system.connect', $api_key);
-		  $session_id = $connect['sessid'];
-          
-          foreach($files_array as $field => $file_type){  
+          $session_id = $connect['sessid'];
+
+          foreach($files_array as $field => $file_type){
             $field_array = $node->$field;
             foreach($file_type as $key => $incoming_file){
               $file = content_retriever_xmlrpc($endpoint, 'file.get', $api_key, $session_id, (int)$incoming_file['fid']);
               $file_details = _content_retriever_save_file($file, $node->nid, 'cck', null, $field, $node->type);
-           
+
               $field_array[$key]['fid'] = $file_details->fid;
-              $field_array[$key]['filepath'] = $file_details->filepath;                             
+              $field_array[$key]['filepath'] = $file_details->filepath;
             }
             $node->$field = $field_array;
           }
         }
-      }     
-	  
-	  //grab files array and unset files on the node before save
+      }
+
+    //grab files array and unset files on the node before save
       $files_array = array();
       $files_array = $node->files;
       unset($node->files);
-      
-      // save the node     
+
+      // save the node
       node_save($node);
-      
+
       //format node->published_date to unix timestamp for DB entry.
       $published_date = $node->published_date;
       $published_date = date_convert($published_date, DATE_DATETIME, DATE_UNIX);
-              
+
       // check whether we are inserting a new node or updating an existing one
       if(!empty($nid)){
-      	db_query("UPDATE {content_retriever} SET published_date = %d WHERE nid = %d", $published_date, $node->nid);
+        db_query("UPDATE {content_retriever} SET published_date = %d WHERE nid = %d", $published_date, $node->nid);
       }else{
-	    db_query("INSERT INTO {content_retriever} (nid, original_nid, published_date) VALUES (%d, %d, %d)", $node->nid, $remote_nid, $published_date);
+      db_query("INSERT INTO {content_retriever} (nid, original_nid, published_date) VALUES (%d, %d, %d)", $node->nid, $remote_nid, $published_date);
       }
-            	              
+
       //fetch ordinary upload module attached files
       if (module_exists('upload')) {
         $file_count = count($files_array);
         if ($file_count > 0) {
           // get a session id from system.service module
           $connect = content_retriever_xmlrpc($endpoint, 'system.connect', $api_key);
-		  $session_id = $connect['sessid'];
+      $session_id = $connect['sessid'];
           $files = content_retriever_xmlrpc($endpoint, 'file.getNodeFiles', $api_key, $session_id, $remote_nid);
           if(!empty($files)){
             foreach ($files as $file) {
               _content_retriever_save_file($file, $node->nid, 'file', $node->vid);
             }
           }else{
-          	watchdog(t('integration'), t('Content retriever ran but could not retrieve files on node with node ID %node'), array('%node' => $node->nid), WATCHDOG_NOTICE);
+            watchdog(t('integration'), t('Content retriever ran but could not retrieve files on node with node ID %node'), array('%node' => $node->nid), WATCHDOG_NOTICE);
           }
         }
       }
-    
+
       //now stop being the superuser
       $user = $temp_user;
-      
+
       //tell watchdog the process has completed with content
       $output .= '<pre>'. htmlspecialchars(print_r($node, true)) .'</pre>';
     }
@@ -299,10 +326,10 @@
 /**
  * retrieves and builds an array of nodes from the remote resource,
  * ready to be saved to the database
- * 
+ *
  * @param $last_run
  * timestamp - Unix time of last time process executed
- * 
+ *
  * @return
  *  array containing retrieved node objects
  */
@@ -316,68 +343,68 @@
   $api_key = variable_get('content_retriever_api_key', '');
   $username = variable_get('content_retriever_webservice_username', '');
   $password = variable_get('content_retriever_webservice_pass', '');
-  
+
   //warn sysadm via watchdog if no safe content types are found
   if (count($content_types) == 0) {
     watchdog('integration', t('Content Retriever found no valid content types - doing nothing.'), array(), WATCHDOG_WARNING);
     drupal_set_message(t('There are no available content types installed on this instance - cannot retrieve content'), 'error');
     return false;
   } else {
-  	$nodes = array();
-  	$processed_nids = array();
-  	
-  	//we need to be logged in as webservice user with 
+    $nodes = array();
+    $processed_nids = array();
+
+    //we need to be logged in as webservice user with
     //'administer nodes' permissions to be able to
     //retrieve unpublished nodes via views.get service call
     $connect = content_retriever_xmlrpc($endpoint, 'system.connect', $api_key);
     $session_id = $connect['sessid'];
-  
-	//login as webservice user
+
+  //login as webservice user
     $login = content_retriever_xmlrpc($endpoint, 'user.login', $api_key, $session_id, $username, $password);
     $session_id = $login['sessid'];
-  		
+
     foreach ($content_types as $contenttype) {
-      
+
       foreach ($queues as $qid => $queue) {
-      	if ($queue != '0') {
-  	      //make the call
+        if ($queue != '0') {
+          //make the call
           $result = content_retriever_xmlrpc($endpoint, 'views.get', $api_key, $session_id, $viewname, array((int)$qid, $contenttype, format_date($last_run, 'custom', 'YmdHi')));
 
           if($result) {
             foreach ($result as $node_info) {
               //load the remote node
               $node = _content_retriever_fetch_node($node_info['nid'], $session_id);
-              //check we haven't already got this node in the $nodes array from another queue             
+              //check we haven't already got this node in the $nodes array from another queue
               foreach($nodes as $processed_node) {
                 $processed_nids[$processed_node->nid] = $processed_node->nid;
-              }            
-  	          if (array_search($node->nid, $processed_nids) === false) {
+              }
+              if (array_search($node->nid, $processed_nids) === false) {
                 $nodes[] = $node;
-  	          }
-  	          $processed_nids = array();
+              }
+              $processed_nids = array();
             }
           }
         }
-  	  }
+      }
     }
     // logout as webservice user from remote site
     content_retriever_xmlrpc($endpoint, 'user.logout', $api_key, $session_id);
     return $nodes;
   }
-  
+
 }
 
 
 /**
  * retrieves a specific node from the remote resource,
  * ready to be saved to the database
- * 
+ *
  * @param $nid
  * integer node id
- * 
+ *
  * @param $fields
  * optional array of CCK field names
- * 
+ *
  * @return
  *  node object
  */
@@ -386,9 +413,9 @@
   //variables are set in the admin form submit function
   $endpoint = variable_get('content_retriever_endpoint', 'http://cms.defaqto.com/services/xmlrpc');
   $api_key = variable_get('content_retriever_api_key', '');
-  
+
   $result = content_retriever_xmlrpc($endpoint, 'node.get', $api_key, $session_id, (int)$nid, $fields);
-  
+
   //convert returned array in to a proper object
   if ($result) {
     $node = new stdClass();
@@ -399,21 +426,21 @@
   } else {
     return false;
   }
-  
+
 }
 
 
 /**
  * @param $file
  * array of file data
- * 
+ *
  * @param $nid
  * integer: the NEW node id on the local instance
- * 
+ *
  * @param $type
  * string denoting type of file, possible values:
- * 		- image
- * 		- file
+ *     - image
+ *     - file
  */
 function _content_retriever_save_file($file, $nid, $type, $vid = null, $field = '', $node_type = '') {
   $file_data = base64_decode($file['file']);
@@ -421,18 +448,18 @@
     case 'file':
       //set filepath to save to
       $file['filepath'] = file_directory_path().'/'.$file['filename'];
-               
+
       //check if the file is already on the system, if it is no need to save it again
       $result = db_query("SELECT fid FROM {files} WHERE filename = '%s' AND timestamp = %d", $file['filename'], $file['timestamp']);
       $fid_int = (int)db_result($result);
-      
+
       if(!$fid_int){
         //save file
         //note, safe to REPLACE because we can be certain we will not have duplicates
         //we wish to keep - distirbution site will be handling duplicate file names
         //so we will only ever receive unique ones here
         file_save_data($file_data, $file['filepath'], FILE_EXISTS_REPLACE);
-      
+
         //write record in files table
         drupal_write_record('files', $file);
 
@@ -440,7 +467,7 @@
         $result = db_query("SELECT fid FROM {files} WHERE filename = '%s'", $file['filename']);
         $fid_int = (int)db_result($result);
       }
-      
+
       //build array for upload table insertion
       $upload = array(
         'fid' => $fid_int,
@@ -453,63 +480,63 @@
 
       //write record in upload table
       drupal_write_record('upload', $upload);
-      
+
       return true;
     break;
-    
+
     case 'cck':
        //set filepath to save to
       $file['filepath'] = file_directory_path().'/'.$file['filename'];
-      
+
       //set content type db table, and field to search on.
       $content_table = 'content_type_'.$node_type;
       $fid_field = $field.'_fid';
-      
+
       $file_details = array();
       //get timestamp and fid if there is a file on this node
       $result = db_query("SELECT f.timestamp, f.fid, f.filepath FROM {files} as f
-				RIGHT JOIN {%s} as ctype
-				ON f.fid=ctype.%s
-				WHERE ctype.vid = (SELECT MAX({%s}.vid)
-				FROM {%s}) AND ctype.nid = %d", $content_table, $fid_field, $content_table, $content_table, $nid);
-          
-  
+        RIGHT JOIN {%s} as ctype
+        ON f.fid=ctype.%s
+        WHERE ctype.vid = (SELECT MAX({%s}.vid)
+        FROM {%s}) AND ctype.nid = %d", $content_table, $fid_field, $content_table, $content_table, $nid);
+
+
       $file_details = db_fetch_object($result);
-      
+
       //check if it's the same file coming over
-   	  if($file_details->timestamp == $file['timestamp']){
-   	  	//if it is it dont write another record in the files table.
-   	  	return $file_details;
-   	  }else{ 
+       if($file_details->timestamp == $file['timestamp']){
+         //if it is it dont write another record in the files table.
+         return $file_details;
+       }else{
         //save file
         //note, safe to REPLACE because we can be certain we will not have duplicates
         //we wish to keep - distribution site will be handling duplicate file names
         //so we will only ever receive unique ones here
         file_save_data($file_data, $file['filepath'], FILE_EXISTS_REPLACE);
-      
+
         //write record in files table
         drupal_write_record('files', $file);
-	  
-	    $result = db_query("SELECT fid,filepath FROM {files} WHERE filename = '%s'", $file['filename']);
+
+      $result = db_query("SELECT fid,filepath FROM {files} WHERE filename = '%s'", $file['filename']);
         $file_details = db_fetch_object($result);
-      
+
         return $file_details;
-   	  }
+       }
     break;
   }
-  
+
 }
 
 /**
  * abstraction of the service calling code needed to retrieve nodes
- * 
+ *
  * makes and xml-rpc call to the Services module of another Drupal
  * installation, calling the views.get method, and returns the
  * resulting array
- * 
+ *
  * @param $endpoint
  * string representing the valid URI for the web service endpoint
- * 
+ *
  * @param $method
  * string telling us what method to call, examples:
  *     - views.get
@@ -517,17 +544,17 @@
  *     - nodequeue.getQueues
  *     - node.get
  *     - image.getNodeImages
- * 
+ *
  * @param $api_key
  * string containing a valid API key for this service
- * 
+ *
  * @param $param1 thru $param3
  * various: placeholder vars for passing parameters to the web
  * service methods - can be anything valid for the method call being
- * invoked - empty strings by default 
- * 
+ * invoked - empty strings by default
+ *
  * @return
- * array containing results of the call 
+ * array containing results of the call
  */
 function content_retriever_xmlrpc($endpoint, $method, $api_key, $session_id = '',$param1 = '', $param2 = '', $param3 = '') {
   //check if HTTP requests are enabled and report error if not
@@ -535,10 +562,10 @@
     drupal_set_message(t('Drupal is unable to make HTTP requests. Please reset the HTTP request status.'), 'error', FALSE);
     watchdog('integration', t('Drupal is unable to make HTTP requests. Please reset the HTTP request status.'), array(), WATCHDOG_CRITICAL);
   } else {
-  	
-  	if($api_key != ''){
-  	  //use api key to get a hash code for the service.
-  	  $timestamp = (string) strtotime("now");
+
+    if($api_key != ''){
+      //use api key to get a hash code for the service.
+      $timestamp = (string) strtotime("now");
       $domain = $_SERVER['SERVER_NAME'];
       $nonce = content_retriever_get_unique_code('10');
       $hash_parameters = array(
@@ -548,104 +575,104 @@
         $method,
       );
       $hash = hash_hmac("sha256", implode(';', $hash_parameters), $api_key);
-  	}  
-  		
-  	switch ($method) {
-  	  case 'system.connect': 	              
+    }
+
+    switch ($method) {
+      case 'system.connect':
           $result = xmlrpc($endpoint, $method);
-  	  break;
-  	  case 'user.login':
-  	    //check for an API key - if not supplied, presume not required
-        if ($api_key == '') {          
+      break;
+      case 'user.login':
+        //check for an API key - if not supplied, presume not required
+        if ($api_key == '') {
           $result = xmlrpc($endpoint, $method, $session_id, (string) $param1, (string) $param2);
         } else {
           $result = xmlrpc($endpoint, $method, $hash, $domain, $timestamp, $nonce, $session_id, (string) $param1, (string) $param2);
         }
-  	  break;
-  	  case 'user.logout':
-  	    //check for an API key - if not supplied, presume not required
-        if ($api_key == '') {          
+      break;
+      case 'user.logout':
+        //check for an API key - if not supplied, presume not required
+        if ($api_key == '') {
           $result = xmlrpc($endpoint, $method, $session_id);
         } else {
           $result = xmlrpc($endpoint, $method, $hash, $domain, $timestamp, $nonce, $session_id);
         }
-  	  break;
-  	  case 'views.get':
-  	    //check for an API key - if not supplied, presume not required
+      break;
+      case 'views.get':
+        //check for an API key - if not supplied, presume not required
         if ($api_key == '') {
-          //$param1 is view name, $param2 is array of view arguments 
-          //'default' is display_id parameter hardcoded to default.         
+          //$param1 is view name, $param2 is array of view arguments
+          //'default' is display_id parameter hardcoded to default.
           $result = xmlrpc($endpoint, $method, $session_id, (string) $param1, 'default', array(), (array) $param2, 0, 0);
         } else {
           //var_dump($endpoint, $method, $hash, $domain, $timestamp, $nonce, $session_id, $param1, $param2);
           $result = xmlrpc($endpoint, $method, $hash, $domain, $timestamp, $nonce, $session_id, (string) $param1, 'default', array(), (array) $param2, 0, 0);
         }
-  	  break;
-  	  
-  	  case 'file.getNodeFiles':
-  	    //check for an API key - if not supplied, presume not required
+      break;
+
+      case 'file.getNodeFiles':
+        //check for an API key - if not supplied, presume not required
         if ($api_key == '') {
           //$param1 is nid
           $result = xmlrpc($endpoint, $method, $session_id, (int) $param1);
         } else {
           $result = xmlrpc($endpoint, $method, $hash, $domain, $timestamp, $nonce, $session_id, (int) $param1);
         }
-  	  break;
-  	  
-  	  case 'file.get':
-  	    //check for an API key - if not supplied, presume not required
+      break;
+
+      case 'file.get':
+        //check for an API key - if not supplied, presume not required
         if ($api_key == '') {
           //$param1 is fid
           $result = xmlrpc($endpoint, $method, $session_id, (int) $param1);
         } else {
           $result = xmlrpc($endpoint, $method, $hash, $domain, $timestamp, $nonce, $session_id, (int) $param1);
         }
-  	  break;
-  	  
-  	  case 'nodequeue.getQueues':
-  	    //check for an API key - if not supplied, presume not required
+      break;
+
+      case 'nodequeue.getQueues':
+        //check for an API key - if not supplied, presume not required
         if ($api_key == '') {
           $result = xmlrpc($endpoint, $method, $session_id);
         } else {
           $result = xmlrpc($endpoint, $method, $hash, $domain, $timestamp, $nonce, $session_id);
         }
-  	  break;
-  	  
-  	  case 'node.get':
-  	    //check for an API key - if not supplied, presume not required
+      break;
+
+      case 'node.get':
+        //check for an API key - if not supplied, presume not required
         if ($api_key == '') {
           //$param1 is nid, $param2 is array of cck field names
           $result = xmlrpc($endpoint, $method, $session_id, (int) $param1, (array) $param2);
         } else {
           $result = xmlrpc($endpoint, $method, $hash, $domain, $timestamp, $nonce, $session_id, (int) $param1, (array) $param2);
         }
-  	  break;
-  	  
-  	  case 'image.getNodeImages':
-  	    //check for an API key - if not supplied, presume not required
+      break;
+
+      case 'image.getNodeImages':
+        //check for an API key - if not supplied, presume not required
         if ($api_key == '') {
           //$param1 is nid
           $result = xmlrpc($endpoint, $method, $session_id, (int) $param1);
         } else {
           $result = xmlrpc($endpoint, $method, $hash, $domain, $timestamp, $nonce, $session_id, (int) $param1);
         }
-  	  break;
-  	  
-  	  case 'node.getAllTypes':
-  	    //check for an API key - if not supplied, presume not required
+      break;
+
+      case 'node.getAllTypes':
+        //check for an API key - if not supplied, presume not required
         if ($api_key == '') {
           //$param1 is nid
           $result = xmlrpc($endpoint, $method, $session_id);
         } else {
           $result = xmlrpc($endpoint, $method, $hash, $domain, $timestamp, $nonce, $session_id);
         }
-  	  break;
-  	  
-  	  default:
-  	    $result = array();
-  	    watchdog('integration', t('Unknown method call attempted.'), array(), WATCHDOG_NOTICE);
-  	  break;
-  	}
+      break;
+
+      default:
+        $result = array();
+        watchdog('integration', t('Unknown method call attempted.'), array(), WATCHDOG_NOTICE);
+      break;
+    }
     return $result;
   }
 }
@@ -666,7 +693,7 @@
 
 /**
  * Function extending the available page variables
- * 
+ *
  * This has been implemented to expose the last time the content
  * retriever has ran to page.tpl. This is purely for admin purposes,
  * so they can simply visit the homepage of any site retrieving content
@@ -680,8 +707,8 @@
 
 /**
  * Implementation of hook_nodeapi().
- * 
- * delete the record from the content_retriever table when a node 
+ *
+ * delete the record from the content_retriever table when a node
  * is deleted.
  */
 function content_retriever_nodeapi(&$node, $op, $teaser, $page) {
@@ -696,6 +723,6 @@
 function content_retriever_get_unique_code($length = ''){
   $code = md5(uniqid(rand(), true));
   if ($length != "") return substr($code, 0, $length);
-  else return $code;	
+  else return $code;
 }
 
