Index: includes/bootstrap.inc =================================================================== RCS file: /var/cvs/CookingTheNet/includes/bootstrap.inc,v retrieving revision 1.4 diff -u -r1.4 bootstrap.inc --- includes/bootstrap.inc 13 Jan 2005 12:41:20 -0000 1.4 +++ includes/bootstrap.inc 23 Jan 2005 13:08:17 -0000 @@ -626,6 +632,134 @@ $_SESSION['messages'] = array(); return $messages; +} + +/** + * 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. + * + * 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". + * + * This function ends the request; use it rather than a print theme('page') + * statement in your menu callback. + * + * @param $path + * A Drupal path. + * @param $query + * The query string component, if any. + * @param $fragment + * The destination fragment identifier (named anchor). + */ +function drupal_goto($path = '', $query = NULL, $fragment = NULL) { + // Translate & to simply & in the absolute URL. + $url = str_replace('&', '&', url($path, $query, $fragment, TRUE)); + + if (ini_get('session.use_trans_sid') && session_id() && !strstr($url, session_id())) { + $sid = session_name() . '=' . session_id(); + + if (strstr($url, '?') && !strstr($url, $sid)) { + $url = $url .'&'. $sid; + } + else { + $url = $url .'?'. $sid; + } + } + + // Before the redirect, allow modules to react to the end of the page request. + module_invoke_all('exit', $url); + + header('Location: '. $url); + + // The "Location" header sends a REDIRECT status code to the http + // daemon. In some cases this can go wrong, so we make sure none + // of the code below the drupal_goto() call gets executed when we redirect. + exit(); +} + +/** + * Generate an internal Drupal URL. + * + * @param $path + * The Drupal path being linked to, such as "admin/node". + * @param $query + * A query string to append to the link. + * @param $fragment + * A fragment identifier (named anchor) to append to the link. + * @param $absolute + * Whether to force the output to be an absolute link (beginning with http:). + * Useful for links that will be displayed outside the site, such as in an RSS feed. + * @return + * an HTML string containing a link to the given path. + * + * When creating links in modules, consider whether l() could be a better + * alternative than url(). + */ +function url($path = NULL, $query = NULL, $fragment = NULL, $absolute = FALSE) { + global $base_url; + + static $script; + + if (empty($script)) { + // On some web servers, such as IIS, we can't omit "index.php". So, we + // generate "index.php?q=foo" instead of "?q=foo" on anything that is not + // Apache. + $script = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === false) ? 'index.php' : ''; + } + + if (function_exists('drupal_get_path_alias')) { + $path = drupal_get_path_alias($path); + } + + if (function_exists('i18n_url_rewrite')) { + $path = i18n_url_rewrite($path); + } + + if (isset($fragment)) { + $fragment = '#'. $fragment; + } + + $base = ($absolute ? $base_url . '/' : ''); + + if (variable_get('clean_url', '0') == '0') { + if (isset($path)) { + if (isset($query)) { + return $base . $script .'?q='. $path .'&'. $query . $fragment; + } + else { + return $base . $script .'?q='. $path . $fragment; + } + } + else { + if (isset($query)) { + return $base . $script .'?'. $query . $fragment; + } + else { + return $base . $fragment; + } + } + } + else { + if (isset($path)) { + if (isset($query)) { + return $base . $path .'?'. $query . $fragment; + } + else { + return $base . $path . $fragment; + } + } + else { + if (isset($query)) { + return $base . $script .'?'. $query . $fragment; + } + else { + return $base . $fragment; + } + } + } } unset($conf); Index: includes/common.inc =================================================================== RCS file: /var/cvs/CookingTheNet/includes/common.inc,v retrieving revision 1.6 diff -u -r1.6 common.inc --- includes/common.inc 22 Jan 2005 16:20:31 -0000 1.6 +++ includes/common.inc 23 Jan 2005 13:08:17 -0000 @@ -116,52 +116,6 @@ */ /** - * 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. - * - * 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". - * - * This function ends the request; use it rather than a print theme('page') - * statement in your menu callback. - * - * @param $path - * A Drupal path. - * @param $query - * The query string component, if any. - * @param $fragment - * The destination fragment identifier (named anchor). - */ -function drupal_goto($path = '', $query = NULL, $fragment = NULL) { - // Translate & to simply & in the absolute URL. - $url = str_replace('&', '&', url($path, $query, $fragment, TRUE)); - - if (ini_get('session.use_trans_sid') && session_id() && !strstr($url, session_id())) { - $sid = session_name() . '=' . session_id(); - - if (strstr($url, '?') && !strstr($url, $sid)) { - $url = $url .'&'. $sid; - } - else { - $url = $url .'?'. $sid; - } - } - - // Before the redirect, allow modules to react to the end of the page request. - module_invoke_all('exit', $url); - - header('Location: '. $url); - - // The "Location" header sends a REDIRECT status code to the http - // daemon. In some cases this can go wrong, so we make sure none - // of the code below the drupal_goto() call gets executed when we redirect. - exit(); -} - -/** * Generates a 404 error if the request can not be handled. */ function drupal_not_found() { @@ -1385,81 +1339,6 @@ * @} End of "defgroup form". */ -/** - * Generate an internal Drupal URL. - * - * @param $path - * The Drupal path being linked to, such as "admin/node". - * @param $query - * A query string to append to the link. - * @param $fragment - * A fragment identifier (named anchor) to append to the link. - * @param $absolute - * Whether to force the output to be an absolute link (beginning with http:). - * Useful for links that will be displayed outside the site, such as in an RSS feed. - * @return - * an HTML string containing a link to the given path. - * - * When creating links in modules, consider whether l() could be a better - * alternative than url(). - */ -function url($path = NULL, $query = NULL, $fragment = NULL, $absolute = FALSE) { - global $base_url; - - static $script; - - if (empty($script)) { - // On some web servers, such as IIS, we can't omit "index.php". So, we - // generate "index.php?q=foo" instead of "?q=foo" on anything that is not - // Apache. - $script = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === false) ? 'index.php' : ''; - } - - $path = drupal_get_path_alias($path); - - if (isset($fragment)) { - $fragment = '#'. $fragment; - } - - $base = ($absolute ? $base_url . '/' : ''); - - if (variable_get('clean_url', '0') == '0') { - if (isset($path)) { - if (isset($query)) { - return $base . $script .'?q='. $path .'&'. $query . $fragment; - } - else { - return $base . $script .'?q='. $path . $fragment; - } - } - else { - if (isset($query)) { - return $base . $script .'?'. $query . $fragment; - } - else { - return $base . $fragment; - } - } - } - else { - if (isset($path)) { - if (isset($query)) { - return $base . $path .'?'. $query . $fragment; - } - else { - return $base . $path . $fragment; - } - } - else { - if (isset($query)) { - return $base . $script .'?'. $query . $fragment; - } - else { - return $base . $fragment; - } - } - } -} /** * Format an attribute string to insert in a tag.