cvs: phpweb /error index.php /include site.inc
| From: | Gabor Hojtsy | Date: | Wed, 08 Jan 2003 08:06:07 +0000 |
| Subject: | cvs: phpweb /error index.php /include site.inc | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-14839@lists.php.net to get a copy of this message | ||
goba Wed Jan 8 03:06:07 2003 EDT
Modified files:
/phpweb/include site.inc
/phpweb/error index.php
Log:
Add new mirror_redirect() function to redirect to some local or remote URI.
Use $MYSITE instead of $SERVER_NAME for local redirects. It's always the
"best name" for the mirror, most probably the mirrors real mirror name if
it's found.
Use this new function to greatly simplify redirects in the URL handler script.
Also use a switch instead of multiple IFs to react to some special shortcuts.
Still more to come...
Index: phpweb/include/site.inc
diff -u phpweb/include/site.inc:1.236 phpweb/include/site.inc:1.237
--- phpweb/include/site.inc:1.236 Tue Jan 7 17:15:57 2003
+++ phpweb/include/site.inc Wed Jan 8 03:06:06 2003
@@ -1,6 +1,6 @@
<?php // -*- C++ -*-
-// $Id: site.inc,v 1.236 2003/01/07 22:15:57 goba Exp $
+// $Id: site.inc,v 1.237 2003/01/08 08:06:06 goba Exp $
// Define $MIRRORS array, and some constants
include_once 'mirrors.inc';
@@ -122,6 +122,28 @@
global $MIRRORS, $MYSITE;
if (!$site) { $site = $MYSITE; }
return $MIRRORS[$site][7];
+}
+
+// Redirect to an URI on this mirror
+// site or outside this site
+function mirror_redirect($absoluteURI, $remote = FALSE)
+{
+ global $MYSITE;
+
+ // A local or remote redirect is needed
+ if (!$remote) {
+ $URI = substr($MYSITE, 0, -1) . $absoluteURI;
+ } else {
+ $URI = $absoluteURI;
+ }
+
+ // Do a redirection, if headers are not sent
+ if (!headers_sent()) {
+ header("Location: $URI");
+ }
+
+ // Always exit (the page is not to be displayed)
+ exit;
}
// Guess the current site from what Apache tells us.
Index: phpweb/error/index.php
diff -u phpweb/error/index.php:1.94 phpweb/error/index.php:1.95
--- phpweb/error/index.php:1.94 Tue Jan 7 16:35:19 2003
+++ phpweb/error/index.php Wed Jan 8 03:06:07 2003
@@ -1,24 +1,10 @@
<?php
-require_once 'prepend.inc';
-// A 'good looking' 404 error message page
-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";
- commonFooter();
-}
+include_once 'prepend.inc';
// ============================================================================
// For images, display a 404 automatically (no redirect)
-if (preg_match('/\.(pdf|gif|jpg|png)$/', $REQUEST_URI)) {
- make404();
- exit;
-}
+if (preg_match('/\.(pdf|gif|jpg|png)$/', $REQUEST_URI)) { make404(); }
// ============================================================================
// Check for a manual in the mirror's default language
@@ -30,16 +16,14 @@
// ============================================================================
// BC: handle .php3 files that were renamed to .php
if (preg_match("/(.*\.php)3$/", $REQUEST_URI, $array)) {
- header("Location: http://$SERVER_NAME$array[1]");
- exit;
+ mirror_redirect($array[1]);
}
// ============================================================================
// 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)) {
- header("Location: http://$SERVER_NAME$array[1]/manual/$lang/$array[2]");
- exit;
+ mirror_redirect("$array[1]/manual/$lang/$array[2]");
}
// ============================================================================
@@ -151,15 +135,13 @@
// which we display in the mirror's language or the explicitly specified
// language [see below])
if ($uri != 'books' && file_exists("$DOCUMENT_ROOT/$uri.php")) {
- header("Location: http://$SERVER_NAME/$uri.php");
- exit;
+ mirror_redirect("/$uri.php");
}
// ============================================================================
// Execute external redirect if a rule exists for the URI
if (isset($external_redirects[strtolower($uri)])) {
- header("Location: " . $external_redirects[strtolower($uri)]);
- exit;
+ mirror_redirect($external_redirects[strtolower($uri)], TRUE);
}
// ============================================================================
@@ -187,32 +169,36 @@
// ============================================================================
// Quick access to revcheck output, build logs, books for various languages and
-// the PHP Documentation Howto for backward compatibility
-if ($function == "rev") {
- header("Location: http://$SERVER_NAME/manual/$lang/revcheck.html.gz");
- exit;
-} elseif ($function == "blog") {
- header("Location: http://$SERVER_NAME/manual/$lang/build.log.gz");
- exit;
-} elseif ($function == "books") {
- header("Location: http://$SERVER_NAME/books.php?type_lang=PHP_$lang");
- exit;
-} elseif ($function == "phpdochowto") {
- header("Location: http://$SERVER_NAME/manual/howto/index.html");
- exit;
+// the PHP Documentation Howto for backward compatibility [breaks left out intentionally]
+switch ($function) {
+ case "rev" : mirror_redirect("/manual/$lang/revcheck.html.gz");
+ case "blog" : mirror_redirect("/manual/$lang/build.log.gz");
+ case "books" : mirror_redirect("/books.php?type_lang=PHP_$lang");
+ case "phpdochowto" : mirror_redirect("/manual/howto/index.html");
}
// ============================================================================
// 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;
-}
+if ($try) { mirror_redirect($try); }
// ============================================================================
// 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=manual&lang='.urlencode($lang).'&pattern='.urlencode(substr($REQUEST_URI,1))
);
+mirror_redirect('/search.php?show=manual&lang='.urlencode($lang).'&pattern='.urlencode(substr($REQUEST_URI,1)));
+
+// A 'good looking' 404 error message page
+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";
+ commonFooter();
+ exit;
+}
+
?>