cvs: pearweb /include pear-prepend.php /public_html/error 404.php
| From: | Richard Heyes | Date: | Mon, 03 Jun 2002 00:40:57 +0000 |
| Subject: | cvs: pearweb /include pear-prepend.php /public_html/error 404.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4383@lists.php.net to get a copy of this message | ||
richard Sun Jun 2 20:40:57 2002 EDT
Modified files:
/pearweb/include pear-prepend.php
/pearweb/public_html/error 404.php
Log:
* Added auto redirection for urls like: http://pear.php.net/Mail_Mime
to package info page. If multiple results shows three results and a
link to the search page if more than three.
Index: pearweb/include/pear-prepend.php
diff -u pearweb/include/pear-prepend.php:1.29 pearweb/include/pear-prepend.php:1.30
--- pearweb/include/pear-prepend.php:1.29 Mon May 13 20:04:21 2002
+++ pearweb/include/pear-prepend.php Sun Jun 2 20:40:57 2002
@@ -90,4 +90,30 @@
}
}
+/**
+* Returns an absolute URL using Net_URL
+*
+* @param string $url All/part of a url
+* @return string Full url
+*/
+function getURL($url)
+{
+ include_once('Net/URL.php');
+ $obj = new Net_URL($url);
+ return $obj->getURL();
+}
+
+/**
+* Redirects to the given full or partial URL.
+* will turn the given url into an absolute url
+* using the above getURL() function. This function
+* does not return.
+*
+* @param string $url Full/partial url to redirect to
+*/
+function redirect($url)
+{
+ header('Location: ' . getURL($url));
+ exit;
+}
?>
Index: pearweb/public_html/error/404.php
diff -u pearweb/public_html/error/404.php:1.1 pearweb/public_html/error/404.php:1.2
--- pearweb/public_html/error/404.php:1.1 Fri Dec 28 06:55:53 2001
+++ pearweb/public_html/error/404.php Sun Jun 2 20:40:57 2002
@@ -1,9 +1,56 @@
-<?php response_header("Error 404"); ?>
+<?php
+/**
+* Filename.......: 404.php
+* Project........: Pearweb
+* Last Modified..: $Date: 2002/06/03 00:40:57 $
+* CVS Revision...: $Revision: 1.2 $
+*
+* On 404 error this will search for a package with the same
+* name as the requested document. Thus enabling urls such as:
+*
+* http://pear.php.net/Mail_Mime
+*/
+
+$pinfo_url = '/package-info.php?pacid=';
+$packages = $dbh->getAll($sql = sprintf("SELECT p.id, p.name, p.summary
+ FROM packages p
+ WHERE name LIKE '%%%s%%'
+ ORDER BY p.name",
basename($_SERVER['REDIRECT_URL'])), DB_FETCHMODE_ASSOC);
+
+if (count($packages) == 1) {
+ redirect($pinfo_url . $packages[0]['id']);
+
+} elseif (count($packages) > 3) {
+ $packages = array($packages[0], $packages[1], $packages[2]);
+ $show_search_link = true;
+}
+
+response_header("Error 404");
+?>
<h2>Error 404 - document not found</h2>
-<p>The requested document <i><?php echo $REQUEST_URI; ?></i> was not
+<p>The requested document <i><?php echo $_SERVER['REQUEST_URI'];
?></i> was not
found on this server.</p>
+
+<?if($packages):?>
+ Searching the current list of packages for
<i><?=basename($_SERVER['REQUEST_URI'])?></i> included the following
results:
+
+ <ul>
+ <?foreach($packages as $p):?>
+ <li>
+ <?=make_link(getURL($pinfo_url . $p['id']), $p['name'])?><br />
+ <i><?=$p['summary']?></i><br /><br />
+ </li>
+ <?endforeach?>
+ </ul>
+
+ <?if($show_search_link):?>
+ <p align="center">
+ <?=make_link(getURL('/package-search.php?pkg_name=' .
basename($_SERVER['REQUEST_URI']) . '&bool=AND&submit=Search'),
'View full search results...')?>
+ </p>
+ <?endif?>
+<?endif?>
<p>If you think that this error message is caused by an error in the
configuration of the server, please contact