Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
merge -r1287 from branch-1_6 to trunk
bug 349: Nicer display messages instead of "die" when urls cannot be 
solved (also set 404 status code for bots)

git-svn-id: http://piwigo.org/svn/trunk@1288 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rvelices committed Apr 28, 2006
1 parent 0510cfd commit aaea0a1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions category.php
Expand Up @@ -39,6 +39,9 @@
{
$url_params['section'] = 'categories';
$url_params['category'] = $_GET['cat'];
$result = get_cat_info($url_params['category']);
if ( !empty($result) )
$url_params['cat_name'] = $result['name'];
}
elseif ( in_array($_GET['cat'],
array('best_rated','most_visited','recent_pics','recent_cats')
Expand All @@ -47,6 +50,10 @@
{
$url_params['section'] = $_GET['cat'];
}
else
{
page_not_found('');
}
}

redirect ( make_index_url($url_params) );
Expand Down
2 changes: 2 additions & 0 deletions include/functions_category.inc.php
Expand Up @@ -118,6 +118,8 @@ function get_cat_info( $id )
WHERE id = '.$id.'
;';
$row = mysql_fetch_array(pwg_query($query));
if (empty($row))
return null;

$cat = array();
foreach ($infos as $info)
Expand Down
18 changes: 18 additions & 0 deletions include/functions_html.inc.php
Expand Up @@ -591,4 +591,22 @@ function access_denied()
redirect($login_url);
}
}

/**
* exits the current script with 404 code when a page cannot be found
* @param string msg a message to display
* @param string alternate_url redirect to this url
*/
function page_not_found($msg, $alternate_url=null)
{
header('HTTP/1.1 404 Not found');
header('Status: 404 Not found');
if ($alternate_url==null)
$alternate_url = make_index_url();
redirect( $alternate_url,
'<div style="text-align:left; margin-left:5em;margin-bottom:5em;">
<h1 style="text-align:left; font-size:36px;">Page not found</h1><br/>'
.$msg.'</div>',
5 );
}
?>
6 changes: 5 additions & 1 deletion include/section_init.inc.php
Expand Up @@ -197,7 +197,7 @@
}
if ( empty($page['tags']) )
{
die('Fatal: no existing tag');
page_not_found('Requested tag does not exist', get_root_url().'tags.php' );
}
}
else if (0 === strpos($tokens[$next_token], 'fav'))
Expand Down Expand Up @@ -316,6 +316,10 @@
if (isset($page['category']))
{
$result = get_cat_info($page['category']);
if (empty($result))
{
page_not_found('Requested category does not exist' );
}

$page = array_merge(
$page,
Expand Down
3 changes: 2 additions & 1 deletion picture.php
Expand Up @@ -42,7 +42,8 @@
// displayed, and execution is stopped
if (!in_array($page['image_id'], $page['items']))
{
die('Fatal: this picture does not belong to this section');
page_not_found('The requested image does not belong to this image set',
duplicate_index_url() );
}

// +-----------------------------------------------------------------------+
Expand Down

0 comments on commit aaea0a1

Please sign in to comment.