Skip to content
Snippets Groups Projects
Commit 670a2922 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- 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.
parent 595c790a
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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>
......
......@@ -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.
......
<?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");
?>
......@@ -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"]);
}
......
......@@ -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.";
......
......@@ -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;
}
/**
......
......@@ -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;
}
......
......@@ -13,7 +13,7 @@
menu_execute_active_handler();
}
else {
print theme("page", "");
drupal_not_found();
}
drupal_page_footer();
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment