summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2003-12-16 21:06:34 +0000
committerDries Buytaert <dries@buytaert.net>2003-12-16 21:06:34 +0000
commit670a292277682351c373780746aedd5c110b3b08 (patch)
treef6122c8d99f90f001e0d5e0d84f2dde8f99e0214
parent595c790a9c488b16875e4a0f8eb5a35e0df2845c (diff)
downloadbrdo-670a292277682351c373780746aedd5c110b3b08.tar.gz
brdo-670a292277682351c373780746aedd5c110b3b08.tar.bz2
- Reworked 404 (page not found) handling. Patch by walkah. You can specify a
custom 404 page in the administration page. As a result, error.php could be removed.
-rw-r--r--.htaccess7
-rw-r--r--CHANGELOG1
-rw-r--r--error.php21
-rw-r--r--includes/bootstrap.inc4
-rw-r--r--includes/common.inc18
-rw-r--r--includes/menu.inc18
-rw-r--r--includes/theme.inc12
-rw-r--r--index.php2
-rw-r--r--modules/forum.module2
-rw-r--r--modules/forum/forum.module2
-rw-r--r--modules/system.module1
-rw-r--r--modules/system/system.module1
12 files changed, 47 insertions, 42 deletions
diff --git a/.htaccess b/.htaccess
index d1cde27a9..98eec8fe4 100644
--- a/.htaccess
+++ b/.htaccess
@@ -15,13 +15,6 @@ Options FollowSymLinks
# Set the default handler to index.php:
DirectoryIndex index.php
-# Customized server error messages:
-ErrorDocument 400 /error.php
-ErrorDocument 402 /error.php
-ErrorDocument 403 /error.php
-ErrorDocument 404 /error.php
-ErrorDocument 500 /error.php
-
# Overload PHP variables:
<IfModule mod_php4.c>
# If you are using Apache 2, you have to use <IfModule sapi_apache2.c>
diff --git a/CHANGELOG b/CHANGELOG
index 6713c4780..01d7afdf0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -23,6 +23,7 @@ Drupal x.x.x, xxxx-xx-xx
* made themes degrade gracefully in absence of CSS.
* grouped form elements using '<fieldset>' and '<legend>' tags.
* added '<label>' tags to form elements.
+- refactored 404 (file not found) handling.
- documentation:
* added PHPDoc/Doxygen comments.
diff --git a/error.php b/error.php
deleted file mode 100644
index 072f7b126..000000000
--- a/error.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-// $Id$
-
-include_once "includes/bootstrap.inc";
-include_once "includes/common.inc";
-
-$errors = array(
- 500 => "500 error: internal server error",
- 404 => "404 error: '". $_SERVER["REDIRECT_URL"] ."' not found",
- 403 => "403 error: access denied - forbidden",
- 401 => "401 error: authorization required",
- 400 => "400 error: bad request"
-);
-
-if ($errors[$_SERVER["REDIRECT_STATUS"]]) {
- watchdog("httpd", $errors[$_SERVER["REDIRECT_STATUS"]]);
- header("HTTP/1.0 ". $errors[$_SERVER["REDIRECT_STATUS"]]);
-}
-
-include_once("$base_url/index.php");
-?>
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 53289fed5..53932807d 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -168,9 +168,9 @@ function referer_uri() {
}
function arg($index) {
- static $arguments;
+ static $arguments, $q;
- if (empty($arguments)) {
+ if (empty($arguments) || $q != $_GET["q"]) {
$arguments = explode("/", $_GET["q"]);
}
diff --git a/includes/common.inc b/includes/common.inc
index 3b086f736..4376fa685 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -103,6 +103,24 @@ function drupal_rebuild_path_map() {
drupal_get_path_map("rebuild");
}
+function drupal_not_found() {
+ header("HTTP/1.0 404 Not Found");
+ watchdog("httpd", "404 error: ". $_GET['q'] ." not found");
+
+ $path = drupal_get_normal_path(variable_get('site_404', ''));
+
+ if ($path) {
+ menu_set_active_item($path);
+ }
+
+ if ($path && menu_active_handler_exists()) {
+ menu_execute_active_handler();
+ }
+ else {
+ print theme("page", '<h1>'. t('Page not found') .'</h1>');
+ }
+}
+
function error_handler($errno, $message, $filename, $line, $variables) {
$types = array(1 => "error", 2 => "warning", 4 => "parse error", 8 => "notice", 16 => "core error", 32 => "core warning", 64 => "compile error", 128 => "compile warning", 256 => "user error", 512 => "user warning", 1024 => "user notice");
$entry = $types[$errno] .": $message in $filename on line $line.";
diff --git a/includes/menu.inc b/includes/menu.inc
index 3274fdea4..e3e617e02 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -34,18 +34,28 @@ function menu_get_trail($path) {
* Returns the path of the active menu item.
*/
function menu_get_active_item() {
+ return menu_set_active_item();
+}
+
+function menu_set_active_item($path = NULL) {
global $_list;
- static $path;
+ static $stored_path;
- if (empty($path)) {
- $path = $_GET["q"];
+ if (is_null($stored_path) || !empty($path)) {
+ if (empty($path)) {
+ $path = $_GET["q"];
+ }
+ else {
+ $_GET['q'] = $path;
+ }
while ($path && !$_list[$path]) {
$path = substr($path, 0, strrpos($path, "/"));
}
+ $stored_path = $path;
}
- return $path;
+ return $stored_path;
}
/**
diff --git a/includes/theme.inc b/includes/theme.inc
index 0df0e2fba..7bb62b82d 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -131,13 +131,11 @@ function path_to_theme() {
* @return a string containing the @a header output.
*/
function theme_header() {
- global $base_url;
-
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$output .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
$output .= "<head>";
$output .= " <title>". drupal_get_title() ? drupal_get_title() : variable_get(site_name, "drupal") ."</title>";
- $output .= theme_head($main);
+ $output .= theme_head();
$output .= " <style type=\"text/css\" media=\"all\">";
$output .= " @import url(misc/drupal.css);";
$output .= " </style>";
@@ -366,10 +364,10 @@ function theme_box($title, $content, $region = "main") {
* @return a string containing the @a box output.
*/
function theme_block($block) {
- $output = "<div class=\"block block-$block->module\" id=\"block-$block->module-$block->delta\">";
- $output .= " <h2 class=\"title\">$block->subject</h2>";
- $output .= " <div class=\"content\">$block->content</div>";
- $output .= "</div>";
+ $output = "<div class=\"block block-$block->module\" id=\"block-$block->module-$block->delta\">\n";
+ $output .= " <h2 class=\"title\">$block->subject</h2>\n";
+ $output .= " <div class=\"content\">$block->content</div>\n";
+ $output .= "</div>\n";
return $output;
}
diff --git a/index.php b/index.php
index 76fdd98ff..4062ce5bb 100644
--- a/index.php
+++ b/index.php
@@ -13,7 +13,7 @@ if (menu_active_handler_exists()) {
menu_execute_active_handler();
}
else {
- print theme("page", "");
+ drupal_not_found();
}
drupal_page_footer();
diff --git a/modules/forum.module b/modules/forum.module
index b227d3a5a..a41ab0479 100644
--- a/modules/forum.module
+++ b/modules/forum.module
@@ -162,8 +162,10 @@ function forum_view($node, $main = 0, $page = 0) {
// print the breadcrumb
drupal_set_breadcrumb($breadcrumb);
}
+
// prepare the node content
$node = forum_content($node);
+
// print the node
$output .= theme("node", $node, $main, $page);
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index b227d3a5a..a41ab0479 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -162,8 +162,10 @@ function forum_view($node, $main = 0, $page = 0) {
// print the breadcrumb
drupal_set_breadcrumb($breadcrumb);
}
+
// prepare the node content
$node = forum_content($node);
+
// print the node
$output .= theme("node", $node, $main, $page);
diff --git a/modules/system.module b/modules/system.module
index d821ec530..5ac19cc54 100644
--- a/modules/system.module
+++ b/modules/system.module
@@ -116,6 +116,7 @@ function system_view_general() {
$group .= form_textarea(t("Footer message"), "site_footer", variable_get("site_footer", ""), 70, 5, t("This text will be displayed at the bottom of each page. Useful for adding a copyright notice to your pages."));
$group .= form_textfield(t("Anonymous user"), "anonymous", variable_get("anonymous", "Anonymous"), 70, 70, t("The name used to indicate anonymous users."));
$group .= form_textfield(t("Default front page"), "site_frontpage", variable_get("site_frontpage", "node"), 70, 70, t("The home page displays content from this relative URL. If you are not using clean URLs, specify the part after '?q='. If unsure, specify 'node'."));
+ $group .= form_textfield(t("Default 404 (not found) page"), "site_404", variable_get("site_404", ""), 70, 70, t("This page is displayed when no other content matches the requested document. If you are not using clean URLs, specify the part after '?q='. If unsure, specify 'node'."));
$group .= form_radios(t("Clean URLs"), "clean_url", variable_get("clean_url", 0), array(t("Disabled"), t("Enabled")), t("Enable or disable clean URLs. If enabled, you'll need <code>ModRewrite</code> support. See also the <code>.htaccess</code> file in Drupal's top-level directory."));
$output = form_group(t("General settings"), $group);
diff --git a/modules/system/system.module b/modules/system/system.module
index d821ec530..5ac19cc54 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -116,6 +116,7 @@ function system_view_general() {
$group .= form_textarea(t("Footer message"), "site_footer", variable_get("site_footer", ""), 70, 5, t("This text will be displayed at the bottom of each page. Useful for adding a copyright notice to your pages."));
$group .= form_textfield(t("Anonymous user"), "anonymous", variable_get("anonymous", "Anonymous"), 70, 70, t("The name used to indicate anonymous users."));
$group .= form_textfield(t("Default front page"), "site_frontpage", variable_get("site_frontpage", "node"), 70, 70, t("The home page displays content from this relative URL. If you are not using clean URLs, specify the part after '?q='. If unsure, specify 'node'."));
+ $group .= form_textfield(t("Default 404 (not found) page"), "site_404", variable_get("site_404", ""), 70, 70, t("This page is displayed when no other content matches the requested document. If you are not using clean URLs, specify the part after '?q='. If unsure, specify 'node'."));
$group .= form_radios(t("Clean URLs"), "clean_url", variable_get("clean_url", 0), array(t("Disabled"), t("Enabled")), t("Enable or disable clean URLs. If enabled, you'll need <code>ModRewrite</code> support. See also the <code>.htaccess</code> file in Drupal's top-level directory."));
$output = form_group(t("General settings"), $group);