Index: modules/content_retriever/content_retriever.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/content_distribution/modules/content_retriever/content_retriever.admin.inc,v
retrieving revision 1.1.2.6.2.8
diff -u -p -r1.1.2.6.2.8 content_retriever.admin.inc
--- modules/content_retriever/content_retriever.admin.inc	11 Feb 2010 19:28:57 -0000	1.1.2.6.2.8
+++ modules/content_retriever/content_retriever.admin.inc	14 Feb 2010 22:15:45 -0000
@@ -90,7 +90,7 @@ function content_retriever_admin_setting
  */
 function content_retriever_admin_retrieve_now_form_submit($form, &$form_state) {
   $last_run = variable_get('content_retriever_last_run', (time() - (24 * 60 * 60)) );
-  if (_content_retriever_save_nodes($last_run)) {
+  if (_content_retriever_retrieve_nodes($last_run)) {
     drupal_set_message(t('Process complete.'));
     variable_set('content_retriever_last_run', time());
   }
@@ -357,16 +357,18 @@ function content_retriever_manual_form($
   $form['notice'] = array(
     '#type' => 'markup', 
     '#value' => t('<p>Use this page to test your connection is set up correctly, and to manually retrieve nodes from the remote site.</p>'),
+      '#weight' => -10,  
   );
-
+  
+  // Buttons. These are themed into a vertical list with the description text alongside each one
   $form['buttons'] = array(
     '#theme' => 'content_retriever_manual_form_button', 
     '#tree' => TRUE,
   );
-  $form['buttons']['connection'] = array(
+  $form['buttons']['connect'] = array(
     '#value' => 'Test connection',
     '#type' => 'submit',
-    '#name' => 'connection',
+    '#name' => 'connect',
     '#submit' => array('content_retriever_admin_manual_form_connection_submit'),
     '#description' => t('Test the connection settings by calling system.connect on the remote server.'),
   );
@@ -377,21 +379,67 @@ function content_retriever_manual_form($
     '#submit' => array('content_retriever_admin_manual_form_login_submit'),
     '#description' => t('Test the remote user settings and by calling user.login on the remote server.'),
   );
+  $form['buttons']['view_result'] = array(
+    '#value' => 'Test view result',
+    '#type' => 'submit',
+    '#name' => 'view_result',
+    '#submit' => array('content_retriever_admin_manual_form_view_result_submit'),
+    '#description' => t('Query the view on the remote server, but do not retrieve nodes or change last run time.'),
+  );
+  $form['buttons']['nodes'] = array(
+    '#value' => 'Test nodes result',
+    '#type' => 'submit',
+    '#name' => 'view_result',
+    '#submit' => array('content_retriever_admin_manual_form_nodes_submit'),
+    '#description' => t('Query the view on the remote server and retrieve nodes, but do not save them locally or change last run time.'),
+  );
   $form['buttons']['retrieve'] = array(
     '#value' => 'Retrieve content now',
     '#type' => 'submit',
     '#name' => 'retrieve',
     '#submit' => array('content_retriever_admin_retrieve_now_form_submit'),
+    '#description' => t('Perform a full retrieval of content. This saves nodes locally and updates the last run time.'),
   );
   
-  //dsm($form_state);
-  if (count($form_state['post'])) {
+  
+  // Display the results from the buttons in a fieldset above them.
+  // Add this after the buttons but above them so we can grab their human-readable
+  // titles from the form array already built.
+  if (count($form_state['storage'])) {
     $form['results'] = array(
-      '#type' => 'markup', 
-      '#value' => t('<p>Results</p>'),
+      '#type' => 'fieldset', 
+      '#title' => t('Results'),
+      '#collapsible' => TRUE,
+      '#collapsed' => FALSE,
+      '#weight' => -5,  
     );
+    
+    foreach (array_keys($form['buttons']) as $button_id) {
+      // If there is a key in the form storage with the same ID as a button, 
+      // the it is the result of a previous manual test.  
+      if (isset($form_state['storage'][$button_id])) {
+        $title = $form['buttons'][$button_id]['#value'];
+        $form['results'][$button_id] = array(
+          '#type' => 'markup', 
+          '#value' => "<h3>$title</h3>" . 
+            '<pre>' . print_r($form_state['storage'][$button_id], TRUE) . '</pre>',
+        );
+      }
+    }
+    
+    // Some operations have more results.
+    if (isset($form_state['storage']['view_arguments'])) {
+      $form['results']['view_arguments'] = array(
+        '#type' => 'markup', 
+        '#value' => "<h3>View arguments</h3>" . 
+          '<pre>' . print_r($form_state['storage']['view_arguments'], TRUE) . '</pre>',
+      );
+    }
   }
   
+  // Empty the form storage so the next test has clean results.
+  $form_state['storage'] = array();
+
   return $form;
 }
 
@@ -414,8 +462,10 @@ function theme_content_retriever_manual_
  */
 function content_retriever_admin_manual_form_connection_submit($form, &$form_state) {
   $connect = content_retriever_xmlrpc('system.connect');
-  
+ 
   if (is_array($connect) && isset($connect['user'])) {
+    $form_state['storage']['connect'] = $connect;
+
     drupal_set_message(t('Sucessfully connected to the remote site.'));
   }
   else {
@@ -424,12 +474,14 @@ function content_retriever_admin_manual_
 }
 
 /**
- * Submit handler for the connect button.
+ * Submit handler for the login button.
  */
 function content_retriever_admin_manual_form_login_submit($form, &$form_state) {
   $login = content_retriever_xmlrpc('user.login');
   
   if (is_array($login) && isset($login['user'])) {
+    $form_state['storage']['login'] = $login;
+    
     drupal_set_message(t('Sucessfully logged in to the remote site; got back details for user %user (uid @uid).', array(
       '%user' => $login['user']['name'],
       '@uid'  => $login['user']['uid'],
@@ -440,3 +492,50 @@ function content_retriever_admin_manual_
   }
 }
 
+/**
+ * Submit handler for the view results button.
+ */
+function content_retriever_admin_manual_form_view_result_submit($form, &$form_state) {
+  $last_run     = variable_get('content_retriever_last_run', (time() - (24 * 60 * 60)) );
+  $view_args    = array();
+  $view_result  = _content_retriever_get_view($last_run, $view_args);
+  
+  //dsm($form_state);
+  if (is_array($view_result)) {
+    //dsm($view_result);
+    $form_state['storage']['view_result']     = $view_result;
+    $form_state['storage']['view_arguments']  = $view_args;
+    
+    drupal_set_message(t('Sucessfully retrieved view results from the remote site; got back @count rows.', array(
+      '@count' => count($view_result),
+      )));
+  }
+  else {
+    drupal_set_message(t('Could not retrieve results from the view on the remote site.'), 'warning');
+  }
+}
+
+/**
+ * Submit handler for the node results button.
+ */
+function content_retriever_admin_manual_form_nodes_submit($form, &$form_state) {
+  content_retriever_admin_manual_form_view_result_submit($form, $form_state);
+  $view_result = $form_state['storage']['view_result'];
+  
+  if (count($view_result)) {
+    $nodes = _content_retriever_get_nodes($view_result);
+    if (is_array($nodes)) {
+      $form_state['storage']['nodes'] = $nodes;
+      
+      drupal_set_message(t('Sucessfully retrieved nodes from the remote site; got back @count nodes. No changes have been made to the local site.', array(
+        '@count' => count($nodes),
+        )));
+    }
+    else {
+      drupal_set_message(t('Could not retrieve nodes on the remote site.'), 'warning');
+    }
+  }
+  else {
+    drupal_set_message(t('No nodes to retrieve.'));
+  }
+}
Index: modules/content_retriever/content_retriever.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/content_distribution/modules/content_retriever/content_retriever.module,v
retrieving revision 1.1.2.8.2.17
diff -u -p -r1.1.2.8.2.17 content_retriever.module
--- modules/content_retriever/content_retriever.module	11 Feb 2010 22:13:27 -0000	1.1.2.8.2.17
+++ modules/content_retriever/content_retriever.module	14 Feb 2010 22:15:46 -0000
@@ -105,7 +105,7 @@ function content_retriever_menu() {
   $items['admin/settings/retriever/output'] = array(
     'title' => 'Content Retriever visual output',
     'description' => t('If you need to physically see the retrieved content for debug purposes, touching this page runs the processes and outputs the resulting nodes to screen.'),
-    'page callback' => '_content_retriever_save_nodes',
+    'page callback' => '_content_retriever_retrieve_nodes',
     'page arguments' => array((string) $last_run),
     'access arguments' => array('administer content retrieval'),
     'weight' => 5,
@@ -123,15 +123,19 @@ function content_retriever_menu() {
  * @return
  * string of HTML for debug purposes only
  */
-function _content_retriever_save_nodes($last_run) {
+function _content_retriever_retrieve_nodes($last_run) {
   //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);
+  //fetch node data  
+  $view_result  = _content_retriever_get_view($last_run);
+  $nodes        = _content_retriever_get_nodes($view_result);
+  // logout as webservice user from remote site
+  content_retriever_xmlrpc('user.logout');
+  
   if ($nodes) {
     if ($screen_reports != 0) {
-      drupal_set_message('_content_retriever_fetch_nodes ran! No. of nodes: '.count($nodes));
+      drupal_set_message(t('Content retrieval ran successfully and retrieved @count nodes.', array('@count' => count($nodes))));
     }
   }
   else {
@@ -176,6 +180,86 @@ function _content_retriever_save_nodes($
   return $output;
 }
 
+
+/**
+ * Build the arguments and query the view on the remote resource.
+ * 
+ * @param $last_run
+ *  timestamp - Unix time of last time process executed
+ * @param $return_arguments
+ *  If an empty array is passed in, it will be filled with the arguments passed
+ *  to the remote view. Used for testing and debugging.
+ * 
+ * @return
+ *  The Views return array. Irrespective of whether the remote view's display
+ *  style is set to nodes or fields, each item of this array will have a 'nid'
+ *  key.
+ */
+function _content_retriever_get_view($last_run, &$return_arguments = NULL) { 
+  // Get view name, display, and arguments
+  $viewname = variable_get('content_retriever_viewname', 'content_distribution');
+  $view_display = variable_get('content_retriever_view_displayname', 'default');
+  foreach (variable_get('content_retriever_view_arguments', array()) as $arg) {
+    if (is_array($arg)) {
+      $arg = implode(',', $arg);
+    }
+    $view_args[] = $arg;
+  }
+  // Add the date as the final argument.
+  $view_args[]  = format_date($last_run, 'custom', 'YmdHi');
+  
+  $view_result = content_retriever_xmlrpc('views.get', 
+    $viewname,
+    $view_display,
+    $view_args
+  );
+  
+  if (is_array($return_arguments)) {
+    $return_arguments = $view_args;
+  }
+
+  return $view_result;
+}
+
+
+/**
+ * Retrieves an array of nodes from the remote resource.
+ * 
+ * @param $view_result
+ *  An array of View results, as returned by _content_retriever_get_view()
+ *  (or more generally, a call to views.get).
+ * 
+ * @return
+ *  array containing retrieved node objects, ready to be saved to the local
+ *  database
+ */
+function _content_retriever_get_nodes($view_result) { 
+	$nodes = array();
+
+  // Retrieve the nodes.
+  if ($view_result) {
+    foreach ($view_result as $node_info) {
+      $remote_nid = $node_info['nid'];
+      // load the remote node
+      $node = _content_retriever_fetch_node($remote_nid, $session_id);
+      if (!is_null($node)) {
+        $nodes[$remote_nid] = $node;   
+      }
+      else {
+        // There was a problem.
+        //check if screen reporting messages for debug are on or off
+        $screen_reports = variable_get('content_retriever_screen_messages', 0);
+        if ($screen_reports != 0) {
+          drupal_set_message(t('There was a problem retrieving node %nid.', array('%nid' => $remote_nid)));
+        }
+      }
+    }
+  }
+  
+  return $nodes;
+}
+
+
 /**
  * Save a single retrieved node.
  *
@@ -301,62 +385,6 @@ function _content_retriever_save_node(&$
   }
 }
 
-/**
- * Retrieves an array of nodes from the remote resource.
- * 
- * @param $last_run
- *  timestamp - Unix time of last time process executed
- * 
- * @return
- *  array containing retrieved node objects, ready to be saved to the local
- *  database
- */
-function _content_retriever_fetch_nodes($last_run) { 
-	$nodes = array();
-	
-  // Get view name, display, and arguments
-  $viewname = variable_get('content_retriever_viewname', 'content_distribution');
-  $view_display = variable_get('content_retriever_view_displayname', 'default');
-  foreach (variable_get('content_retriever_view_arguments', array()) as $arg) {
-    if (is_array($arg)) {
-      $arg = implode(',', $arg);
-    }
-    $view_args[] = $arg;
-  }
-  // Add the date as the final argument.
-  $view_args[]  = format_date($last_run, 'custom', 'YmdHi');
-
-  $result = content_retriever_xmlrpc('views.get', 
-    $viewname,
-    $view_display,
-    $view_args
-  ); 
-  
-  // Retrieve the nodes.
-  if ($result) {
-    foreach ($result as $node_info) {
-      $remote_nid = $node_info['nid'];
-      // load the remote node
-      $node = _content_retriever_fetch_node($remote_nid, $session_id);
-      if (!is_null($node)) {
-        $nodes[$remote_nid] = $node;   
-      }
-      else {
-        // There was a problem.
-        //check if screen reporting messages for debug are on or off
-        $screen_reports = variable_get('content_retriever_screen_messages', 0);
-        if ($screen_reports != 0) {
-          drupal_set_message(t('There was a problem retrieving node %nid.', array('%nid' => $remote_nid)));
-        }
-      }
-    }
-  }
-  
-  // logout as webservice user from remote site
-  content_retriever_xmlrpc('user.logout');
-  return $nodes;
-}
-
 
 /**
  * retrieves a specific node from the remote resource,
@@ -598,7 +626,7 @@ function content_retriever_cron() {
   //set time to now for next run to use as the last run time
   variable_set('content_retriever_last_run', time());
   //run
-  _content_retriever_save_nodes((string) $last_run);
+  _content_retriever_retrieve_nodes((string) $last_run);
 }
 
 
