1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-04 13:35:13 +02:00

Added the redirect() function for nice and clean redirection.

git-svn-id: file:///svn/phpbb/trunk@2948 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Ludovic Arnaud 2002-10-09 19:50:48 +00:00
parent ac4b54ff4d
commit 369189806b
6 changed files with 44 additions and 62 deletions

View File

@ -111,7 +111,19 @@ foreach ($forum_rows as $row)
if (isset($subforums[$forum_id]))
{
$subforums_list = format_subforums_list($subforums[$forum_id]);
foreach ($subforums as $row)
{
$alist[$row['forum_id']] = $row['forum_name'];
}
asort($alist);
$links = array();
foreach ($alist as $forum_id => $forum_name)
{
$links[] = '<a href="viewforum.' . $phpEx . $SID . '&f=' . $forum_id . '">' . htmlspecialchars($forum_name) . '</a>';
}
$subforums_list = implode(', ', $links);
$l_subforums = (count($subforums[$forum_id]) == 1) ? $lang['Subforum'] . ': ' : $lang['Subforums'] . ': ';
}
else

View File

@ -70,7 +70,7 @@ function get_db_stat($mode)
function sql_quote($msg)
{
return str_replace('\'', '\'\'', $msg);
return str_replace("'", "''", $msg);
}
function get_userdata($user)
@ -403,9 +403,7 @@ function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $mat
{
if ( $_GET['unwatch'] == $mode )
{
$header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
header($header_location . "login.$phpEx$SID&redirect=view$mode.$phpEx&" . $u_url . "=$match_id&unwatch=forum");
exit;
redirect("login.$phpEx$SID&redirect=view$mode.$phpEx&" . $u_url . "=$match_id&unwatch=forum");
}
}
else
@ -527,29 +525,6 @@ function on_page($num_items, $per_page, $start)
return sprintf($lang['Page_of'], floor( $start / $per_page ) + 1, max(ceil( $num_items / $per_page ), 1) );
}
function format_subforums_list($subforums)
{
if (empty($subforums))
{
return '';
}
global $phpEx, $SID;
foreach ($subforums as $row)
{
$alist[$row['forum_id']] = $row['forum_name'];
}
asort($alist);
$links = array();
foreach ($alist as $forum_id => $forum_name)
{
$links[] = '<a href="viewforum.' . $phpEx . $SID . '&f=' . $forum_id . '">' . htmlspecialchars($forum_name) . '</a>';
}
return implode(', ', $links);
}
// Obtain list of naughty words and build preg style replacement arrays for use by the
// calling script, note that the vars are passed as references this just makes it easier
// to return both sets of arrays
@ -574,6 +549,19 @@ function obtain_word_list(&$orig_word, &$replacement_word)
return true;
}
//
// Redirects the user to another page then exits the script nicely
//
function redirect($location)
{
global $db;
$db->sql_close();
$header_location = (@preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE'))) ? 'Refresh: 0; URL=' : 'Location: ';
header($header_location . $location);
exit;
}
//
// This is general replacement for die(), allows templated output in users (or default)
// language, etc. $msg_code can be one of these constants:

View File

@ -442,9 +442,9 @@ class auth
{
global $db;
if ( !($this->founder = $userdata['user_founder']) )
if (!$this->founder = $userdata['user_founder'])
{
$in_sql = '\'a_\', \'f_list\'';
$in_sql = "'a_', 'f_list'";
if ( $options )
{
@ -452,7 +452,7 @@ class auth
{
foreach ( $options as $option )
{
$in_sql .= ', \'' . $option . '\'';
$in_sql .= ", '$option'";
}
}
else
@ -468,8 +468,8 @@ class auth
// The possible alternative here is to store the options in a file
// (perhaps with the other config data) and do away with this query.
$sql = "SELECT auth_option_id, auth_value
FROM " . ACL_OPTIONS_TABLE . "
$sql = 'SELECT auth_option_id, auth_value
FROM ' . ACL_OPTIONS_TABLE . "
WHERE auth_value IN ($in_sql) $or_sql";
$result = $db->sql_query($sql);
@ -527,7 +527,7 @@ class auth
}
*/
}
$this->acl_cache($userdata);
return;
}

View File

@ -32,16 +32,10 @@ $auth = new auth($userdata);
$user = new user($userdata);
// End session management
//
// This appears to work for IIS5 CGI under Win2K. Uses getenv since this doesn't exist for
// ISAPI mode and therefore the normal Location redirector is used in preference
//
$header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
extract($_GET);
extract($_POST);
$redirect = ( !empty($redirect) ) ? $_SERVER['QUERY_STRING'] : '';
$redirect = (!empty($redirect)) ? $_SERVER['QUERY_STRING'] : '';
// Do the login/logout/form/whatever
if ( isset($login) || isset($logout) )
@ -55,8 +49,7 @@ if ( isset($login) || isset($logout) )
//
if ( $board_config['board_disable'] && !$auth->acl_get('a_') )
{
header($header_location . "index.$phpEx$SID");
exit;
redirect("index.$phpEx$SID");
}
if ( !$auth->login($username, $password, $autologin) )
@ -78,8 +71,7 @@ if ( isset($login) || isset($logout) )
// Redirect to wherever we're supposed to go ...
//
$redirect_url = ( $redirect ) ? preg_replace('/^.*?redirect=(.*?)&(.*?)$/', '\\1' . $SID . '&\\2', $redirect) : 'index.'.$phpEx;
header($header_location . $redirect_url);
exit;
redirect($redirect_url);
}
if ( !$userdata['user_id'] )
@ -105,8 +97,7 @@ if ( !$userdata['user_id'] )
}
else
{
header($header_location . "index.$phpEx$SID");
exit;
redirect("index.$phpEx$SID");
}
?>

View File

@ -76,10 +76,7 @@ if (!$auth->acl_get('f_read', $forum_id))
{
if ( !$userdata['user_id'] )
{
$redirect = "f=$forum_id" . ( ( isset($start) ) ? "&start=$start" : '' );
$header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
header($header_location . "login.$phpEx$SID&redirect=viewforum.$phpEx&$redirect");
exit;
redirect("login.$phpEx$SID&redirect=viewforum.$phpEx&f=$forum_id" . ((isset($start)) ? "&start=$start" : ''));
}
// The user is not authed to read this forum ...
@ -87,7 +84,7 @@ if (!$auth->acl_get('f_read', $forum_id))
}
// End of auth check
// Build subforum if applicable
// Build subforums list if applicable
$type = 'parent';
$forum_rows = array();

View File

@ -41,12 +41,10 @@ if ( empty($topic_id) && empty($post_id) )
// Find topic id if user requested a newer
// or older topic
//
if ( isset($_GET['view']) && empty($post_id) )
if (isset($_GET['view']) && empty($post_id))
{
if ( $_GET['view'] == 'newest' )
{
$header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) )
{
$session_id = $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'];
@ -70,13 +68,11 @@ if ( isset($_GET['view']) && empty($post_id) )
}
$post_id = $row['post_id'];
header($header_location . 'viewtopic.' . $phpEx . '?sid=' . $session_id . '&p=' . $post_id . '#' . $post_id);
exit;
redirect("viewtopic.$phpEx$SID&p=$post_id#$post_id");
}
}
header($header_location . 'index.' . $phpEx);
exit;
redirect("index.$phpEx$SID");
}
else if ( $_GET['view'] == 'next' || $_GET['view'] == 'previous' )
{
@ -169,9 +165,7 @@ if ( !$auth->acl_get('f_read', $forum_id) )
{
$redirect = ( isset($post_id) ) ? "p=$post_id" : "t=$topic_id";
$redirect .= ( isset($start) ) ? "&start=$start" : '';
$header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
header($header_location . 'login.' . $phpEx . $SID . '&redirect=viewtopic.' . $phpEx . '&' . $redirect);
exit;
redirect('login.' . $phpEx . $SID . '&redirect=viewtopic.' . $phpEx . '&' . $redirect);
}
message_die(MESSAGE, $lang['Sorry_auth_read']);