Index: workspace.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/workspace/workspace.module,v
retrieving revision 1.35
diff -u -p -r1.35 workspace.module
--- workspace.module	7 Aug 2008 02:49:45 -0000	1.35
+++ workspace.module	30 Jul 2009 23:08:22 -0000
@@ -4,12 +4,12 @@
 /**
  * @file
  * Presents a user-centric view of content.
- * 
- * Provides a "My workspace" link in the navigation block. When 
+ *
+ * Provides a "My workspace" link in the navigation block. When
  * clicked it brings the user to a table showing the content
  * they have created, with handy links to edit or delete the
  * content, or to create new content.
- * 
+ *
  * Optionally provides a link to a user's content on their
  * profile page (viewable if the current user has 'view all
  * workspace' permission.
@@ -31,6 +31,12 @@ function workspace_help($path) {
 * Implementation of hook_menu().
 */
 function workspace_menu() {
+  $items['workspace/go'] = array(
+    'title' => 'Go to my workspace',
+    'page callback' => 'workspace_user_redirect',
+    'access callback' => 'workspace_redirect_access',
+  'weight' => -12,
+  );
   $items['workspace/%user_uid_optional'] = array(
     'title' => 'My workspace',
     'page callback' => 'workspace_list_content',
@@ -180,7 +186,7 @@ function workspace_configure_form_valida
 
 /**
  * Submit handler for per-user configuration form.
- * 
+ *
  * @see workspace_configure_form()
  */
 function workspace_configure_form_submit($form, &$form_state) {
@@ -216,10 +222,10 @@ function workspace_list_content($account
     $count_sql = 'SELECT COUNT(n.nid)
             FROM {node} n
             LEFT JOIN {node_comment_statistics} s ON n.nid = s.nid
-            WHERE n.uid = %d';   
+            WHERE n.uid = %d';
   }
   else {
-    // Otherwise we use a simpler query.    
+    // Otherwise we use a simpler query.
     $sql = 'SELECT n.nid, n.uid, n.type, 0 as cid, n.title, n.status, n.changed, 1 as node
             FROM {node} n
             WHERE n.uid = %d';
@@ -244,7 +250,7 @@ function workspace_list_content($account
   if ($user->uid == $account->uid) {
     $output = drupal_get_form('workspace_add_form');
   }
-  
+
   $output .= theme_workspace_list($header, $rows, $max);
   return $output;
 }
@@ -259,12 +265,12 @@ function workspace_list_comments($accoun
   drupal_set_title(t('Workspace: @name', array('@name' => $account->name)));
   $max = isset($account->workspaces) ? $account->workspaces['default']['maxcomments'] : 50;
 
-  $sql =       'SELECT c.nid, c.uid, c.cid, c.subject, c.status, c.timestamp, c.pid, 0 
-                FROM {comments} c 
+  $sql =       'SELECT c.nid, c.uid, c.cid, c.subject, c.status, c.timestamp, c.pid, 0
+                FROM {comments} c
                 WHERE c.uid = %d';
 
   $count_sql = 'SELECT COUNT(cid) FROM {comments} WHERE uid = %d';
-  
+
   // Build the comment listing.
   $header = array(
     array('data' => t('Title'), 'field' => 'title'),
@@ -304,7 +310,7 @@ function workspace_build_rows($result, $
       $function = $row->type .'_access';
       if ($cck_enabled && strstr($function, 'content_')) {
         $function = 'content_access';
-      } 
+      }
       else {
         $function = 'node_access';
       }
@@ -351,10 +357,10 @@ function workspace_build_rows($result, $
 
       $rows[] = array(
         l($row->subject, "node/$row->nid", array(), NULL, "comment-$row->cid", FALSE, TRUE),
-        $row->status ? $no : $yes, 
-        format_date($row->timestamp, 'small'), 
-        array('data' => $num_replies, 'align' => 'right'), 
-        $edit_link, 
+        $row->status ? $no : $yes,
+        format_date($row->timestamp, 'small'),
+        array('data' => $num_replies, 'align' => 'right'),
+        $edit_link,
         $delete_link,
       );
     }
@@ -389,9 +395,9 @@ function workspace_list_files($account) 
 
   while ($row = db_fetch_object($result)) {
     $rows[] = array(
-      l($row->filename, "node/$row->nid"), 
-      $row->filemime, 
-      format_date($row->timestamp, 'small'), 
+      l($row->filename, "node/$row->nid"),
+      $row->filemime,
+      format_date($row->timestamp, 'small'),
       format_size($row->filesize),
       l($download, file_create_url($row->filepath)),
     );
@@ -408,7 +414,7 @@ function workspace_theme() {
     'workspace_list' => array(
       'arguments' => array('header' => array(), 'rows' => array(), $max = 50),
     ),
-  );  
+  );
 }
 
 /**
@@ -473,7 +479,7 @@ function workspace_add_form() {
 
 /**
  * Submit handler for content addition form.
- * 
+ *
  * Simply redirects to appropriate node/add/* page.
  *
  * @see workspace_add_form()
@@ -500,7 +506,7 @@ function workspace_add_form_submit($form
 function workspace_settings() {
   $roles = user_roles();
   // The anonymous user does not have a profile.
-  unset($roles[DRUPAL_ANONYMOUS_RID]); 
+  unset($roles[DRUPAL_ANONYMOUS_RID]);
   $form['info'] = array(
     '#value' => "Select each role for which you want the link to a user's workspace to show up in their user profile."
   );
@@ -518,13 +524,13 @@ function workspace_settings() {
     '#description' => t("This will be used to display the link to a user's workspace on his or her profile page. The %username token will be replaced by the username of the user whose profile is being shown."),
     '#default_value' => variable_get('workspace_user_profile_link', 'View recent content created by %username'),
   );
-  
+
   return system_settings_form($form);
 }
 
 /**
  * Implementation of hook_user().
- * 
+ *
  * Place link to user's workspace on user's profile page.
  */
 function workspace_user($op, &$edit, &$account) {
@@ -540,7 +546,7 @@ function workspace_user($op, &$edit, &$a
     if ($allowed) {
       $variables['%username'] = $account->name;
       $link_title = variable_get('workspace_user_profile_link', t('View recent content'));
-      
+
       $account->content['summary']['workspace'] = array(
         '#type' => 'user_profile_item',
         '#title' => variable_get('workspace_user_profile_title', t('Content')),
@@ -548,4 +554,27 @@ function workspace_user($op, &$edit, &$a
       );
     }
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Menu access callback.
+ */
+function workspace_redirect_access() {
+  return true;
+}
+
+/**
+ * Attempt at http://drupal.org/node/536078
+ */
+function workspace_user_redirect() {
+  global $user;
+
+  if ($user->uid == 0) {
+    // TODO present a view explaining that they need to log in
+    // for now just redirect to the login
+    drupal_goto('user', 'destination=workspace/go');
+  } else {
+    // redirect to their own workspace
+    drupal_goto('workspace/'. $user->uid);
+  }
+}
