[geeklog-hg] geeklog: Added COM_handle404 function to generate a 404 error wh...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Tue Apr 2 17:39:50 EDT 2013
changeset 9023:6dee451f5010
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/6dee451f5010
user: Tom <websitemaster at cogeco.net>
date: Tue Apr 02 17:32:55 2013 -0400
description:
Added COM_handle404 function to generate a 404 error when needed. Topics, Articles and Comments now use function instead of displaying not found message or redirecting to homepage (feature request #0001548)
diffstat:
language/english.php | 11 ++++---
language/english_utf-8.php | 11 ++++---
public_html/404.php | 19 +------------
public_html/article.php | 7 ++--
public_html/index.php | 65 +++++++++++----------------------------------
public_html/lib-common.php | 49 ++++++++++++++++++++++++++++++++++
system/lib-comment.php | 18 ++++++++++--
7 files changed, 96 insertions(+), 84 deletions(-)
diffs (truncated from 307 to 300 lines):
diff -r 58cad0780cfa -r 6dee451f5010 language/english.php
--- a/language/english.php Sun Mar 31 09:16:22 2013 -0400
+++ b/language/english.php Tue Apr 02 17:32:55 2013 -0400
@@ -423,9 +423,9 @@
# index.php
$LANG05 = array(
- 1 => 'No News to Display',
- 2 => 'There are no news stories to display. There may be no news for this topic or your user preferences may be too restrictive',
- 3 => ' for topic %s',
+ 1 => 'No Articles to Display',
+ 2 => 'There are no articles to display for this topic.',
+ 3 => '', // Not Used
4 => 'Today\'s Featured Article',
5 => 'Next',
6 => 'Previous',
@@ -1468,8 +1468,9 @@
$LANG_404 = array(
1 => '404 Error',
- 2 => 'Gee, I\'ve looked everywhere but I can not find <b>%s</b>.',
- 3 => "<p>We're sorry, but the file you have requested does not exist. Please feel free to check the <a href=\"{$_CONF['site_url']}\">main page</a> or the <a href=\"{$_CONF['site_url']}/search.php\">search page</a> to see if you can find what you lost."
+ 2 => '<p>Gee, I\'ve looked everywhere but I can not find:</p><p><b>%s</b></p>',
+ 3 => "<p>We're sorry, but the page you have requested does not exist. Please feel free to check the <a href=\"{$_CONF['site_url']}/\">main page</a> or the <a href=\"{$_CONF['site_url']}/search.php\">search page</a> to see if you can find what you lost.",
+ 4 => "<p>We're sorry, but the page you have requested does not exist. We recommend going back to this <a href=\"%s\">related page</a>, or you may want to check the <a href=\"{$_CONF['site_url']}/\">home page</a>, or the <a href=\"{$_CONF['site_url']}/search.php\">search page</a> to see if you can find what you lost.",
);
###############################################################################
diff -r 58cad0780cfa -r 6dee451f5010 language/english_utf-8.php
--- a/language/english_utf-8.php Sun Mar 31 09:16:22 2013 -0400
+++ b/language/english_utf-8.php Tue Apr 02 17:32:55 2013 -0400
@@ -423,9 +423,9 @@
# index.php
$LANG05 = array(
- 1 => 'No News to Display',
- 2 => 'There are no news stories to display. There may be no news for this topic or your user preferences may be too restrictive',
- 3 => ' for topic %s',
+ 1 => 'No Articles to Display',
+ 2 => 'There are no articles to display for this topic.',
+ 3 => '', // Not Used
4 => 'Today\'s Featured Article',
5 => 'Next',
6 => 'Previous',
@@ -1468,8 +1468,9 @@
$LANG_404 = array(
1 => '404 Error',
- 2 => 'Gee, I\'ve looked everywhere but I can not find <b>%s</b>.',
- 3 => "<p>We're sorry, but the file you have requested does not exist. Please feel free to check the <a href=\"{$_CONF['site_url']}\">main page</a> or the <a href=\"{$_CONF['site_url']}/search.php\">search page</a> to see if you can find what you lost."
+ 2 => '<p>Gee, I\'ve looked everywhere but I can not find:</p><p><b>%s</b></p>',
+ 3 => "<p>We're sorry, but the page you have requested does not exist. Please feel free to check the <a href=\"{$_CONF['site_url']}/\">main page</a> or the <a href=\"{$_CONF['site_url']}/search.php\">search page</a> to see if you can find what you lost.",
+ 4 => "<p>We're sorry, but the page you have requested does not exist. We recommend going back to this <a href=\"%s\">related page</a>, or you may want to check the <a href=\"{$_CONF['site_url']}/\">home page</a>, or the <a href=\"{$_CONF['site_url']}/search.php\">search page</a> to see if you can find what you lost.",
);
###############################################################################
diff -r 58cad0780cfa -r 6dee451f5010 public_html/404.php
--- a/public_html/404.php Sun Mar 31 09:16:22 2013 -0400
+++ b/public_html/404.php Tue Apr 02 17:32:55 2013 -0400
@@ -33,23 +33,6 @@
require_once 'lib-common.php';
-$display = COM_startBlock($LANG_404[1]);
-if (isset($_SERVER['SCRIPT_URI'])) {
- $url = strip_tags($_SERVER['SCRIPT_URI']);
-} else {
- $pos = strpos($_SERVER['REQUEST_URI'], '?');
- if ($pos === false) {
- $request = $_SERVER['REQUEST_URI'];
- } else {
- $request = substr($_SERVER['REQUEST_URI'], 0, $pos);
- }
- $url = 'http://' . $_SERVER['HTTP_HOST'] . strip_tags($request);
-}
-$display .= sprintf($LANG_404[2], $url);
-$display .= $LANG_404[3];
-$display .= COM_endBlock();
-$display = COM_createHTMLDocument($display, array('pagetitle' => $LANG_404[1]));
-
-COM_output($display);
+COM_handle404();
?>
diff -r 58cad0780cfa -r 6dee451f5010 public_html/article.php
--- a/public_html/article.php Sun Mar 31 09:16:22 2013 -0400
+++ b/public_html/article.php Tue Apr 02 17:32:55 2013 -0400
@@ -110,8 +110,7 @@
$sid = COM_applyFilter ($_POST['cmt_sid']);
}
if (empty ($sid)) {
- echo COM_refresh ($_CONF['site_url'] . '/index.php');
- exit();
+ COM_handle404();
}
// Get topic
@@ -157,7 +156,7 @@
. COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
$display = COM_createHTMLDocument($display, array('pagetitle' => $LANG_ACCESS['accessdenied']));
} elseif ( $output == STORY_INVALID_SID ) {
- $display .= COM_refresh($_CONF['site_url'] . '/index.php');
+ COM_handle404();
} elseif (($mode == 'print') && ($_CONF['hideprintericon'] == 0)) {
$story_template = COM_newTemplate($_CONF['path_layout'] . 'article');
$story_template->set_file('article', 'printable.thtml');
@@ -450,7 +449,7 @@
$display = COM_createHTMLDocument($display, array('pagetitle' => $pagetitle, 'breadcrumbs' => $breadcrumbs, 'headercode' => $headercode));
}
} else {
- $display .= COM_refresh($_CONF['site_url'] . '/index.php');
+ COM_handle404();
}
COM_output($display);
diff -r 58cad0780cfa -r 6dee451f5010 public_html/index.php
--- a/public_html/index.php Sun Mar 31 09:16:22 2013 -0400
+++ b/public_html/index.php Tue Apr 02 17:32:55 2013 -0400
@@ -85,7 +85,7 @@
// See if user has access to view topic else display message.
// This check has already been done in lib-common so re check to figure out if
-// message needs to be displayed.
+// 404 message needs to be displayed.
$topic_check = '';
if (isset($_GET['topic'])) {
$topic_check = COM_applyFilter($_GET['topic']);
@@ -94,43 +94,7 @@
}
if ($topic_check != '') {
if ($topic_check != DB_getItem($_TABLES['topics'], 'tid', "tid = '$topic_check' " . COM_getPermSQL('AND'))) {
- // This will eventually be a 404 error. Copied code from below this time
- // just to keep the same user exerience
- $display = '';
- if (!isset ($_CONF['hide_no_news_msg']) ||
- ($_CONF['hide_no_news_msg'] == 0)) {
- $display .= COM_startBlock ($LANG05[1], '',
- COM_getBlockTemplate ('_msg_block', 'header')) . $LANG05[2];
- if (!empty ($topic_check)) {
- $topicname = DB_getItem ($_TABLES['topics'], 'topic',
- "tid = '$topic_check'");
- $display .= sprintf ($LANG05[3], $topicname);
- }
- $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
- }
-
- $display .= PLG_showCenterblock (3, $page, $topic_check); // bottom blocks
-
- $header = '';
-
- if ($topic)
- {
- // Meta Tags
- if ($_CONF['meta_tags'] > 0) {
- $result = DB_query ("SELECT meta_description, meta_keywords FROM {$_TABLES['topics']} WHERE tid = '{$topic}'");
- $A = DB_fetchArray ($result);
-
- $meta_description = stripslashes($A['meta_description']);
- $meta_keywords = stripslashes($A['meta_keywords']);
- $header .= COM_createMetaTags($meta_description, $meta_keywords);
- }
- }
-
- $display = COM_createHTMLDocument($display, array('breadcrumbs' => $breadcrumbs, 'headercode' => $header, 'rightblock' => true));
-
- // Output page
- COM_output($display);
- exit();
+ COM_handle404();
}
}
@@ -418,19 +382,22 @@
$display .= COM_printPageNavigation ($base_url, $page, $num_pages);
}
} else { // no stories to display
- if (!isset ($_CONF['hide_no_news_msg']) ||
- ($_CONF['hide_no_news_msg'] == 0)) {
- $display .= COM_startBlock ($LANG05[1], '',
- COM_getBlockTemplate ('_msg_block', 'header')) . $LANG05[2];
- if (!empty ($topic)) {
- $topicname = DB_getItem ($_TABLES['topics'], 'topic',
- "tid = '$topic'");
- $display .= sprintf ($LANG05[3], $topicname);
+ if ($page == 1) {
+ if (!isset ($_CONF['hide_no_news_msg']) ||
+ ($_CONF['hide_no_news_msg'] == 0)) {
+ $display .= COM_startBlock ($LANG05[1], '',
+ COM_getBlockTemplate ('_msg_block', 'header')) . $LANG05[2];
+ $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
}
- $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
+
+ $display .= PLG_showCenterblock (3, $page, $topic); // bottom blocks
+ } else {
+ $topic_url = '';
+ if (!empty($topic)) {
+ $topic_url = $_CONF['site_url'] . '/index.php?topic=' . $topic;
+ }
+ COM_handle404($topic_url);
}
-
- $display .= PLG_showCenterblock (3, $page, $topic); // bottom blocks
}
$header = '';
diff -r 58cad0780cfa -r 6dee451f5010 public_html/lib-common.php
--- a/public_html/lib-common.php Sun Mar 31 09:16:22 2013 -0400
+++ b/public_html/lib-common.php Tue Apr 02 17:32:55 2013 -0400
@@ -7831,6 +7831,55 @@
}
/**
+ * Display a 404 not found error message
+ *
+ * @param string $alternate_url Point the user to another location
+ */
+function COM_handle404($alternate_url = '')
+{
+ global $_USER, $LANG_404;
+
+
+ if (function_exists('CUSTOM_handle404')) {
+ CUSTOM_handle404($alternate_url);
+ exit;
+ }
+
+ // send 404 in any case
+ header('HTTP/1.1 404 Not Found');
+ header('Status: 404 Not Found');
+
+ $display .= COM_startBlock($LANG_404[1]);
+ if (isset($_SERVER['SCRIPT_URI'])) {
+ $url = strip_tags($_SERVER['SCRIPT_URI']);
+ } else {
+ $request = $_SERVER['REQUEST_URI'];
+ $url = 'http://' . $_SERVER['HTTP_HOST'] . strip_tags($request);
+ }
+
+ // Add log stuff
+ if (isset($_USER['uid'])) {
+ $byuser = $_USER['uid'] . '@' . $_SERVER['REMOTE_ADDR'];
+ } else {
+ $byuser = 'anon@' . $_SERVER['REMOTE_ADDR'];
+ }
+ $refurl = $_SERVER['HTTP_REFERER'];
+ COM_errorLog("404 Error generated by $byuser for url: $url - Referring url: $refurl", 1);
+
+ $display .= sprintf($LANG_404[2], $url);
+ if ($alternate_url != '') {
+ $display .= sprintf($LANG_404[4], $alternate_url);
+ } else {
+ $display .= $LANG_404[3];
+ }
+ $display .= COM_endBlock();
+ $display = COM_createHTMLDocument($display, array('pagetitle' => $LANG_404[1]));
+
+ COM_output($display);
+ exit; // Do not want to go any further
+}
+
+/**
* Handle errors.
*
* This function will handle all PHP errors thrown at it, without exposing
diff -r 58cad0780cfa -r 6dee451f5010 system/lib-comment.php
--- a/system/lib-comment.php Sun Mar 31 09:16:22 2013 -0400
+++ b/system/lib-comment.php Tue Apr 02 17:32:55 2013 -0400
@@ -766,7 +766,19 @@
$thecomments = '';
$result = DB_query( $q );
-
+
+ if (DB_numRows($result) == 0) {
+ if ($page > 1) {
+ list($plgurl, $plgid) = CMT_getCommentUrlId($type);
+ $plglink = '';
+ if (!empty($plgurl)) {
+ $plglink = "$plgurl?$plgid=$sid";
+ }
+ // Requested invalid page
+ COM_handle404($plglink);
+ }
+ }
+
$thecomments .= CMT_getComment( $result, $mode, $type, $order,
$delete_option, false, $ccode, $page );
@@ -2143,7 +2155,7 @@
}
}
if ($cid <= 0) {
- return COM_refresh($_CONF['site_url'] . '/index.php');
+ COM_handle404();
}
$sql = "SELECT sid, title, type FROM {$_TABLES['comments']} WHERE cid = $cid";
@@ -2155,7 +2167,7 @@
$display = PLG_displayComment($type, $sid, $cid, $title,
More information about the geeklog-cvs
mailing list