diff options
-rw-r--r-- | includes/common.inc | 37 | ||||
-rw-r--r-- | modules/comment.module | 15 | ||||
-rw-r--r-- | modules/comment/comment.module | 15 | ||||
-rw-r--r-- | modules/path.module | 3 | ||||
-rw-r--r-- | modules/path/path.module | 3 | ||||
-rw-r--r-- | modules/taxonomy.module | 3 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.module | 3 | ||||
-rw-r--r-- | modules/user.module | 23 | ||||
-rw-r--r-- | modules/user/user.module | 23 |
9 files changed, 73 insertions, 52 deletions
diff --git a/includes/common.inc b/includes/common.inc index 0ace8d84b..3fb7e0207 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -116,11 +116,39 @@ function drupal_get_headers() { */ /** + * Prepare a destination query string for use in combination with + * drupal_goto(). Used to direct the user back to the referring page + * after completing a form. + * + * @see drupal_goto() + */ +function drupal_get_destination() { + $destination[] = $_GET['q']; + $params = array('from', 'sort', 'order'); + foreach ($params as $param) { + if (isset($_GET[$param])) { + $destination[] = "$param=". $_GET[$param]; + } + } + return 'destination='. urlencode(implode('&', $destination)); +} + +/** * Send the user to a different Drupal page. * * This issues an on-site HTTP redirect. The function makes sure the redirected * URL is formatted correctly. * + * Usually the redirected URL is constructed from this function's input + * parameters. However you may override that behavior by setting a + * <em>destination</em> in either the $_REQUEST-array (i.e. by using + * the query string of an URI) or the $_REQUEST['edit']-array (i.e. by + * using a hidden form field). This is used to direct the user back to + * the proper page after completing a form. For example, after editing + * a post on the 'admin/node'-page or after having logged on using the + * 'user login'-block in a sidebar. The function drupal_get_destination() + * can be used to help set the destination URL. + * * It is advised to use drupal_goto() instead of PHP's header(), because * drupal_goto() will append the user's session ID to the URI when PHP is * compiled with "--enable-trans-sid". @@ -134,8 +162,17 @@ function drupal_get_headers() { * The query string component, if any. * @param $fragment * The destination fragment identifier (named anchor). + * + * @see drupal_get_destination() */ function drupal_goto($path = '', $query = NULL, $fragment = NULL) { + if ($_REQUEST['destination']) { + extract(parse_url($_REQUEST['destination'])); + } + else if ($_REQUEST['edit']['destination']) { + extract(parse_url($_REQUEST['edit']['destination'])); + } + // Translate & to simply & in the absolute URL. $url = str_replace('&', '&', url($path, $query, $fragment, TRUE)); diff --git a/modules/comment.module b/modules/comment.module index 8ac68ba7c..90517617a 100644 --- a/modules/comment.module +++ b/modules/comment.module @@ -970,24 +970,24 @@ function comment_delete($cid) { _comment_update_node_statistics($comment->nid); - // Clear the cache so an anonymous user - // can see his comment being added. + // Clear the cache so an anonymous user sees that his comment was deleted. cache_clear_all(); - } + drupal_goto("node/$comment->nid"); - // Print a confirmation. + } else if ($comment->cid) { drupal_set_message(t('Do you want to delete this comment and all its replies?')); $comment->comment = check_output($comment->comment, $comment->format); $output = theme('comment', $comment); $output .= form_submit(t('Delete')); + $output = form($output); } else { drupal_set_message(t('The comment no longer exists.')); } - print theme('page', form($output)); + print theme('page', $output); } function comment_save($id, $edit) { @@ -1009,6 +1009,7 @@ function comment_admin_overview($type = 'new') { array('data' => t('Operations'), 'colspan' => '2') ); + $destination = drupal_get_destination(); $status = ($type == 'approval') ? 1 : 0; $sql = 'SELECT c.subject, c.nid, c.cid, c.comment, c.timestamp, c.status, c.name, c.homepage, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.status = '. db_escape_string($status); $sql .= tablesort_sql($header); @@ -1021,8 +1022,8 @@ function comment_admin_overview($type = 'new') { format_name($comment), ($comment->status == 0 ? t('Published') : t('Not published')), format_date($comment->timestamp, 'small'), - l(t('edit'), "admin/comment/edit/$comment->cid"), - l(t('delete'), "admin/comment/delete/$comment->cid") + l(t('edit'), "admin/comment/edit/$comment->cid", array(), $destination), + l(t('delete'), "admin/comment/delete/$comment->cid", array(), $destination) ); } diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 8ac68ba7c..90517617a 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -970,24 +970,24 @@ function comment_delete($cid) { _comment_update_node_statistics($comment->nid); - // Clear the cache so an anonymous user - // can see his comment being added. + // Clear the cache so an anonymous user sees that his comment was deleted. cache_clear_all(); - } + drupal_goto("node/$comment->nid"); - // Print a confirmation. + } else if ($comment->cid) { drupal_set_message(t('Do you want to delete this comment and all its replies?')); $comment->comment = check_output($comment->comment, $comment->format); $output = theme('comment', $comment); $output .= form_submit(t('Delete')); + $output = form($output); } else { drupal_set_message(t('The comment no longer exists.')); } - print theme('page', form($output)); + print theme('page', $output); } function comment_save($id, $edit) { @@ -1009,6 +1009,7 @@ function comment_admin_overview($type = 'new') { array('data' => t('Operations'), 'colspan' => '2') ); + $destination = drupal_get_destination(); $status = ($type == 'approval') ? 1 : 0; $sql = 'SELECT c.subject, c.nid, c.cid, c.comment, c.timestamp, c.status, c.name, c.homepage, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.status = '. db_escape_string($status); $sql .= tablesort_sql($header); @@ -1021,8 +1022,8 @@ function comment_admin_overview($type = 'new') { format_name($comment), ($comment->status == 0 ? t('Published') : t('Not published')), format_date($comment->timestamp, 'small'), - l(t('edit'), "admin/comment/edit/$comment->cid"), - l(t('delete'), "admin/comment/delete/$comment->cid") + l(t('edit'), "admin/comment/edit/$comment->cid", array(), $destination), + l(t('delete'), "admin/comment/delete/$comment->cid", array(), $destination) ); } diff --git a/modules/path.module b/modules/path.module index 43b2d0ec2..86a9bea07 100644 --- a/modules/path.module +++ b/modules/path.module @@ -264,8 +264,9 @@ function path_overview() { $sql .= tablesort_sql($header); $result = pager_query($sql, 50); + $destination = drupal_get_destination(); while ($data = db_fetch_object($result)) { - $rows[] = array($data->dst, $data->src, l(t('edit'), "admin/path/edit/$data->pid"), l(t('delete'), "admin/path/delete/$data->pid")); + $rows[] = array($data->dst, $data->src, l(t('edit'), "admin/path/edit/$data->pid", array(), $destination), l(t('delete'), "admin/path/delete/$data->pid")); } if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) { diff --git a/modules/path/path.module b/modules/path/path.module index 43b2d0ec2..86a9bea07 100644 --- a/modules/path/path.module +++ b/modules/path/path.module @@ -264,8 +264,9 @@ function path_overview() { $sql .= tablesort_sql($header); $result = pager_query($sql, 50); + $destination = drupal_get_destination(); while ($data = db_fetch_object($result)) { - $rows[] = array($data->dst, $data->src, l(t('edit'), "admin/path/edit/$data->pid"), l(t('delete'), "admin/path/delete/$data->pid")); + $rows[] = array($data->dst, $data->src, l(t('edit'), "admin/path/edit/$data->pid", array(), $destination), l(t('delete'), "admin/path/delete/$data->pid")); } if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) { diff --git a/modules/taxonomy.module b/modules/taxonomy.module index d69f988db..75967f0f8 100644 --- a/modules/taxonomy.module +++ b/modules/taxonomy.module @@ -241,6 +241,9 @@ function taxonomy_form_term($edit = array()) { $form .= form_submit(t('Delete')); $form .= form_hidden('tid', $edit['tid']); } + else { + $form .= form_hidden('destination', $_GET['q']); + } return form($form); } diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index d69f988db..75967f0f8 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -241,6 +241,9 @@ function taxonomy_form_term($edit = array()) { $form .= form_submit(t('Delete')); $form .= form_hidden('tid', $edit['tid']); } + else { + $form .= form_hidden('destination', $_GET['q']); + } return form($form); } diff --git a/modules/user.module b/modules/user.module index 785d72b80..7c2df79cb 100644 --- a/modules/user.module +++ b/modules/user.module @@ -483,23 +483,16 @@ function user_block($op = 'list', $delta = 0, $edit = array()) { $output = "<div class=\"user-login-block\">\n"; - // Save the referer. We record where the user came from such - // that we can redirect him after having completed the login form. - - if (empty($edit)) { - $edit['destination'] = $_GET['q']; - } // NOTE: special care needs to be taken because on pages with forms, // such as node and comment submission pages, the $edit variable // might already be set. - $output .= form_hidden('destination', $edit['destination']); $output .= form_textfield(t('Username'), 'name', $edit['name'], 15, 64); $output .= form_password(t('Password'), 'pass', $pass, 15, 64); $output .= form_submit(t('Log in')); $output .= "</div>\n"; - $output = form($output, 'post', url('user/login')); + $output = form($output, 'post', url('user/login', drupal_get_destination())); if (variable_get('user_register', 1)) { $items[] = l(t('Create new account'), 'user/register', array('title' => t('Create a new user account.'))); @@ -796,7 +789,7 @@ function user_login($edit = array(), $msg = '') { user_module_invoke('login', $edit, $user); // Redirect the user to the page he logged on from. - drupal_goto($edit['destination']); + drupal_goto(); } else { if (!$error) { @@ -811,13 +804,6 @@ function user_login($edit = array(), $msg = '') { drupal_set_message($error, 'error'); } - // Save the referrer. We record where the user came from such that we - // can redirect him after having completed the login form. - if (empty($edit)) { - $edit['destination'] = $_GET['q']; - } - $output .= form_hidden('destination', $edit['destination']); - // Display login form: if ($msg) { $output .= "<p>$msg</p>"; @@ -831,7 +817,7 @@ function user_login($edit = array(), $msg = '') { $output .= form_password(t('Password'), 'pass', $pass, 30, 64, t('Enter the password that accompanies your username.')); $output .= form_submit(t('Log in')); - return form($output, 'post', url('user/login')); + return form($output, 'post', url('user/login', drupal_get_destination())); } function user_authenticate($name, $pass) { @@ -1609,6 +1595,7 @@ function user_admin_account() { $result = pager_query($sql, 50); $status = array(t('blocked'), t('active')); + $destination = drupal_get_destination(); while ($account = db_fetch_object($result)) { $rolesresult = db_query('SELECT r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $account->uid); $roles = array(); @@ -1617,7 +1604,7 @@ function user_admin_account() { $roles[] = $role->name; } - $rows[] = array($account->uid, format_name($account), $status[$account->status], implode(',<br />', $roles), format_date($account->changed, 'small'), l(t('edit'), "user/$account->uid/edit")); + $rows[] = array($account->uid, format_name($account), $status[$account->status], implode(',<br />', $roles), format_date($account->changed, 'small'), l(t('edit'), "user/$account->uid/edit", array(), $destination)); } $pager = theme('pager', NULL, 50, 0, tablesort_pager()); diff --git a/modules/user/user.module b/modules/user/user.module index 785d72b80..7c2df79cb 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -483,23 +483,16 @@ function user_block($op = 'list', $delta = 0, $edit = array()) { $output = "<div class=\"user-login-block\">\n"; - // Save the referer. We record where the user came from such - // that we can redirect him after having completed the login form. - - if (empty($edit)) { - $edit['destination'] = $_GET['q']; - } // NOTE: special care needs to be taken because on pages with forms, // such as node and comment submission pages, the $edit variable // might already be set. - $output .= form_hidden('destination', $edit['destination']); $output .= form_textfield(t('Username'), 'name', $edit['name'], 15, 64); $output .= form_password(t('Password'), 'pass', $pass, 15, 64); $output .= form_submit(t('Log in')); $output .= "</div>\n"; - $output = form($output, 'post', url('user/login')); + $output = form($output, 'post', url('user/login', drupal_get_destination())); if (variable_get('user_register', 1)) { $items[] = l(t('Create new account'), 'user/register', array('title' => t('Create a new user account.'))); @@ -796,7 +789,7 @@ function user_login($edit = array(), $msg = '') { user_module_invoke('login', $edit, $user); // Redirect the user to the page he logged on from. - drupal_goto($edit['destination']); + drupal_goto(); } else { if (!$error) { @@ -811,13 +804,6 @@ function user_login($edit = array(), $msg = '') { drupal_set_message($error, 'error'); } - // Save the referrer. We record where the user came from such that we - // can redirect him after having completed the login form. - if (empty($edit)) { - $edit['destination'] = $_GET['q']; - } - $output .= form_hidden('destination', $edit['destination']); - // Display login form: if ($msg) { $output .= "<p>$msg</p>"; @@ -831,7 +817,7 @@ function user_login($edit = array(), $msg = '') { $output .= form_password(t('Password'), 'pass', $pass, 30, 64, t('Enter the password that accompanies your username.')); $output .= form_submit(t('Log in')); - return form($output, 'post', url('user/login')); + return form($output, 'post', url('user/login', drupal_get_destination())); } function user_authenticate($name, $pass) { @@ -1609,6 +1595,7 @@ function user_admin_account() { $result = pager_query($sql, 50); $status = array(t('blocked'), t('active')); + $destination = drupal_get_destination(); while ($account = db_fetch_object($result)) { $rolesresult = db_query('SELECT r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $account->uid); $roles = array(); @@ -1617,7 +1604,7 @@ function user_admin_account() { $roles[] = $role->name; } - $rows[] = array($account->uid, format_name($account), $status[$account->status], implode(',<br />', $roles), format_date($account->changed, 'small'), l(t('edit'), "user/$account->uid/edit")); + $rows[] = array($account->uid, format_name($account), $status[$account->status], implode(',<br />', $roles), format_date($account->changed, 'small'), l(t('edit'), "user/$account->uid/edit", array(), $destination)); } $pager = theme('pager', NULL, 50, 0, tablesort_pager()); |