Index: contributions/modules/hidden/hidden.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hidden/hidden.module,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 hidden.module
--- contributions/modules/hidden/hidden.module	18 Oct 2007 12:17:15 -0000	1.2.2.1
+++ contributions/modules/hidden/hidden.module	2 Jan 2008 13:33:59 -0000
@@ -692,30 +692,54 @@ function hidden_link($type, $item = NULL
   if ($hidden == false) {
     // not hidden
     if (user_access('mark as hidden')) {
-      $links['hidden-hide'] = array('title' => t('hide'), 'href' => "hidden/$type/$target/hide", );
+      $links['hidden-hide'] = array(
+        'title' => t('hide'), 
+        'href' => "hidden/$type/$target/hide", 
+        'query' => drupal_get_destination(), 
+      );
     }
     // not hidden and is published
     if (user_access('report for hiding') && (
          ($type == 'comment' && $item->status != COMMENT_NOT_PUBLISHED) || 
          ($type == 'node' && $item->status)
        )) {
-       $links['hidden-report'] = array('title' => t('report'), 'href' => "hidden/$type/$target/report", );
+       $links['hidden-report'] = array(
+         'title' => t('report'), 
+         'href' => "hidden/$type/$target/report",
+         'query' => drupal_get_destination(),
+       );
     }
   }
   elseif ($hidden->delay!=0) {
     // marked to be hidden by a cron job
     if (user_access('mark as hidden')) {
-      $links['hidden-hide'] = array('title' => t('hide now'), 'href' => "hidden/$type/$target/hide", );
-      $links['hidden-unhide'] = array( 'title' => t("don't hide"), 'href' => "hidden/$type/$target/unhide", );
+      $links['hidden-hide'] = array(
+        'title' => t('hide now'), 
+        'href' => "hidden/$type/$target/hide",
+        'query' => drupal_get_destination(),
+      );
+      $links['hidden-unhide'] = array( 
+        'title' => t("don't hide"), 
+        'href' => "hidden/$type/$target/unhide", 
+        'query' => drupal_get_destination(),
+      );
     }
     if (user_access('report for hiding')) {
-      $links['hidden-report'] = array('title' => t('report'), 'href' => "hidden/$type/$target/report", );
+      $links['hidden-report'] = array(
+        'title' => t('report'), 
+        'href' => "hidden/$type/$target/report",
+        'query' => drupal_get_destination(),
+      );
     }
   }
   else {
     // hidden
     if (user_access('mark as hidden')) {
-      $links['hidden-unhide'] = array( 'title' => t('unhide'), 'href' => "hidden/$type/$target/unhide", );
+      $links['hidden-unhide'] = array( 
+        'title' => t('unhide'), 
+        'href' => "hidden/$type/$target/unhide", 
+        'query' => drupal_get_destination(),
+      );
     }
   }
 
@@ -1663,7 +1687,7 @@ function hidden_hide($op, $type, $id) {
     if ($hidden->delay==0) {
       // already fully hidden
       drupal_set_message('Item is already hidden!', 'error');
-      _hidden_goto_hidden($type, $id);
+      _hidden_goto_hidden($hidden->nid, $hidden->cid);
     }
   }
 
@@ -1681,7 +1705,7 @@ function hidden_hide($op, $type, $id) {
   }
   if (!$result) {
     drupal_set_message(t('Database error occurred when retrieving item\'s title.'), 'error');
-    drupal_goto($type, $id);
+    drupal_goto();
   }
 
   if ($op=='hide') {
@@ -1829,6 +1853,7 @@ function hidden_hide_submit($form_id, $f
       _hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id, $rid, $public, $private);
       drupal_set_message($msg, 'error');
     }
+    _hidden_goto_hidden($nid, $cid);
   }
   else {
     if (_hidden_reported_hide($type, $nid, $cid, $uid, $rid, $public, $private)) {
@@ -1841,9 +1866,8 @@ function hidden_hide_submit($form_id, $f
       _hidden_log(HIDDEN_LOG_ERROR, $msg, $type, $id, $rid, $public, $private);
       drupal_set_message($msg, 'error');
     }
+    drupal_goto();
   }
-
-  _hidden_goto_hidden($type, $nid, $cid);
 }
 
 /**
@@ -3152,59 +3176,65 @@ function _hidden_mail($subject, $content
  * If user can see unpublished content it will goto normal view
  * if not will goto the hidden page
  *
- * @param $type
- *   string 'node' or 'comment'
+ * NOTE: nid is actually redundant for comments at the moment. The fn could be $type, $id.
+ * nid is already available at all calling points and may be required for future views.module
+ * based redirects.
+ *
  * @param $id
- *   nid or cid (if not third parameter)
+ *   nid 
  * @param $cid
- *   cid (optional)
+ *   cid (if comment)
  */
-function _hidden_goto_hidden($type, $id, $cid=null) {
-  if ($cid!==null) {
-    $nid = $id;
-    if ($cid!=0) {
-      $id = $cid;
-    }
-  }
-  elseif ($type == 'node') {
-    $nid = $id;
-    $cid = 0;
-  }
-  else {
-    $query = 'SELECT nid FROM {comments} WHERE cid=%d';
-    $nid = db_result(db_query($query, $id));
-    $cid = $id;
-  }
-
+function _hidden_goto_hidden($nid, $cid = 0) {
   if ($cid == 0) {
-    $access = user_access('administer nodes');
+    $access = user_access('administer nodes');          // it's a node can the user see unpublished nodes?
   }
   else {
-    $access = user_access('administer comments');
+    $access = user_access('administer comments');       // it's a comment can the user see unpublished comments
   }
 
-  if ($access) {
-    $url = 'node/'. $nid;
-    if ($cid != 0) {
-      $fragment = 'comment-'. $cid;
+  if (isset($_REQUEST['destination'])) { // **assumption** this was set by this module
+    if ($access == TRUE) { // if the user can see it return there
+      drupal_goto();
+    } 
+    else { // user can see now hidden item there unset it and continue to hidden view
+      unset($_REQUEST['destination']);
     }
   }
-  else {
-    $url = "hidden/$type/$id";
+
+  if ($cid == 0) {     // the type is node
+    $type = 'node';
+    $id = $nid;              // make the id the nid
+  }
+  else {                     // the type is comment
+    $type = 'comment';
+    $id = $cid;              // the id is the cid
   }
 
-  drupal_goto($url, null, $fragment);
+  $url = "hidden/$type/$id";
+
+  drupal_goto($url);
 }
 
 /**
- * drupal_goto() wrapper for redirecting to not hidden content
+ * drupal_goto() wrapper for redirecting to just unhidden content
  *
  * @param $nid
  *   int nid
  * @param $cid
- *   int cid (0 if content is a node)
+ *   int cid (if comment)
  */
-function _hidden_goto_unhidden($nid, $cid) {
+function _hidden_goto_unhidden($nid, $cid = 0) {
+  if (isset($_REQUEST['destination'])) { 
+    // this is pre-empting the probability that views.module displays may return to same location
+    // some other switch may be required as well
+    if (substr($_REQUEST['destination'],0,6) == 'hidden') {
+      unset($_REQUEST['destination']);
+    }
+    else {
+      drupal_goto();
+    }
+  }
   $url = 'node/'. $nid;
   if ($cid != 0) {
     $fragment = 'comment-'. $cid;
