cvs: phpweb /error index.php

From: Date: Wed, 03 Jul 2002 09:07:13 +0000
Subject: cvs: phpweb /error index.php
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-11124@lists.php.net to get a copy of this message
goba Wed Jul 3 05:07:13 2002 EDT Modified files: /phpweb/error index.php Log: Adding heading comments to different error handlers Adding "BC:" to all backward compatibility parts Correcting "html" directory handling (the extension there was .html), and so it needs to be transformed Index: phpweb/error/index.php diff -u phpweb/error/index.php:1.62 phpweb/error/index.php:1.63 --- phpweb/error/index.php:1.62 Tue Jul 2 21:03:45 2002 +++ phpweb/error/index.php Wed Jul 3 05:07:13 2002 @@ -2,36 +2,36 @@ require_once 'prepend.inc'; // A 'good looking' 404 error message page -function make404() { +function make404() +{ global $REQUEST_URI; header('Status: 404 Not Found'); header("Cache-Control: public, max-age=600"); commonHeader('404 Not Found'); echo "<h1>Not Found</h1>\n"; - echo "<p>the page <b>" . htmlspecialchars($REQUEST_URI) . "</b> could not be found.</p>\n"; + echo "<p>The page <b>" . htmlspecialchars($REQUEST_URI) . "</b> could not be found.</p>\n"; commonFooter(); } - -// Mirror specific configuration (for search support) -if (file_exists("../configuration.inc")) { - include_once "../configuration.inc"; -} - -// For images, we automatically display a 404 +// ============================================================================ +// For images, display a 404 automatically (no redirect) if (preg_match('/\.(pdf|gif|jpg)$/', $REQUEST_URI)) { make404(); exit; } -// Get preferred language, and check for -// existing manual in that language +// ============================================================================ +// Get mirror specific configuration, and check for manual language existance +if (file_exists("../configuration.inc")) { + include_once "../configuration.inc"; +} $lang = default_language(); if (!@is_dir("$DOCUMENT_ROOT/manual/$lang")) { $lang = "en"; // fall back to English } -// handle .php3 files that were renamed to .php +// ============================================================================ +// BC: handle .php3 files that were renamed to .php if (preg_match("/(.*\.php)3$/", $REQUEST_URI, $array)) { if($SERVER_PORT!=80) { $url = "http://".$SERVER_NAME.":".$SERVER_PORT.$array[1]; @@ -47,7 +47,9 @@ exit; } -// handle moving english manual down into its own directory +// ============================================================================ +// BC: handle moving english manual down into its own directory (also supports +// default language manual accessibilty on mirror sites through /manual/filename) if (eregi("^(.*)/manual/((html/)?[^/]+)$", $REQUEST_URI, $array)) { if ($SERVER_PORT != 80) { $url = "http://".$SERVER_NAME.":".$SERVER_PORT."$array[1]/manual/$lang/".$array[2]; @@ -63,7 +65,8 @@ exit; } -// prepare URI for manual page and PHP page shortcuts +// ============================================================================ +// Prepare URI for further manipulation, dropping out leading slash $error_notes = $REDIRECT_REDIRECT_ERROR_NOTES ? $REDIRECT_REDIRECT_ERROR_NOTES : $REDIRECT_ERROR_NOTES; @@ -71,25 +74,34 @@ $error_notes, strpos($error_notes,$DOCUMENT_ROOT)+strlen($DOCUMENT_ROOT)+1 ); +if ($uri[0] == "/") { $uri = substr($uri,1); } -// drop out leading slash -if ($uri[0] == "/") $uri = substr($uri,1); +// ============================================================================ +// Printer friendly manual page handling. It's important that this is included, +// and not redirected, as this way all relative URL's will retain their meaning +// and point to pages relative to the print dir (which is nonexistent) +if (preg_match("!^manual/(\\w+)/print/(.+\\.php)$!", $uri, $parts)) { + $PRINT_PAGE = TRUE; + include "../manual/$parts[1]/$parts[2]"; + exit; +} -// Printer friendly manual page handling. It's important -// that this is included, and not redirected, as this way -// all relative URL's will retain their meaning and point -// to pages relative to the print dir (which is nonexistent) -if (preg_match("!^manual/(\\w+)/(print|html)/(.+\\.php)$!", $uri, $parts)) { +// BC: for old HTML directory (.html extension was used in that) +elseif (preg_match("!^manual/(\\w+)/html/(.+)\\.html$!", $uri, $parts)) { $PRINT_PAGE = TRUE; - include "../manual/$parts[1]/$parts[3]"; + include "../manual/$parts[1]/$parts[2].php"; exit; -} elseif (preg_match("!^manual/(\\w+)/(print|html)(/)?$!", $uri, $parts)) { +} + +// The index file needs to be handled in a special way +elseif (preg_match("!^manual/(\\w+)/(print|html)(/)?$!", $uri, $parts)) { $PRINT_PAGE = TRUE; include "../manual/$parts[1]/index.php"; exit; } -// shortcuts for PHP and manual pages +// ============================================================================ +// Define shortcuts for PHP and manual pages $uri_aliases = array ( # PHP page shortcuts @@ -116,33 +128,41 @@ ); -// if the user typed an aliased URL, transform it +// ============================================================================ +// "Rewrite" the URL, if it was a shortcut if (isset($uri_aliases[strtolower($uri)])) { $uri = $uri_aliases[strtolower($uri)]; } -// handle common page shortcuts, like docs, links, support, etc. +// ============================================================================ +// Redirect if the entered URI was a PHP page name if (file_exists("$DOCUMENT_ROOT/$uri.php")) { header("Location: http://$SERVER_NAME/$uri.php"); exit; } -// try to find the uri as a manual entry +// ============================================================================ +// Try to find the URI as a manual entry require "manual-lookup.inc"; if (strchr($uri,'/')) { - list($lang,$function) = explode('/',$uri,2); + + // Find language and function name part (eg. hu/ini) + list($lang,$function) = explode('/',$uri,2); + $function = strtolower($function); + $lang = strtolower($lang); - if (isset($uri_aliases[$function])) { + // Transform function name, so it can be a shortcut + if (isset($uri_aliases[$function])) { $function = $uri_aliases[$function]; } - $lang = strtolower($lang); } else { $function = strtolower($uri); } -// Quick access to revcheck output and build logs for manual writers +// ============================================================================ +// Quick access to revcheck output, build logs and howto for manual writers if ($function == "rev") { header("Location: http://$SERVER_NAME/manual/$lang/revcheck.html.gz"); exit; @@ -154,12 +174,17 @@ exit; } +// ============================================================================ +// Try to find the page using this language as a manual page (lang is the language +// from the URI, or the default language if it was not there in the URI $try = find_manual_page($lang, $function); if ($try) { header("Location: $try"); exit; } -// redirect to the search page with the pattern set to $REQUEST_URI +// ============================================================================ +// If no match was found till this point, the last action is to start a +// search with the URI the user typed in header('Location: http://'.$SERVER_NAME.'/search.php?show=nosource&auto=1&pattern='.urlencode(substr($REQUEST_URI,1)) ); ?>

« previous php.mirrors (#11124) next »