URL rewrite: 3 options in the config file define behaviour (question mark

removal, file name for picture and .php extension removal)

fix: added unsigned for column in install sql - for the sake of uniformization

change: add_url_param is now add_url_params and takes an array as parameter 
instead of a string

git-svn-id: http://piwigo.org/svn/trunk@1094 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices
2006-03-23 01:49:04 +00:00
parent 4cb765e783
commit 5c7d655005
12 changed files with 159 additions and 65 deletions
+2 -1
View File
@@ -85,7 +85,8 @@ foreach ($pictures as $row)
array(
'image_id' => $row['id'],
'image_file' => $row['file']
)
),
array('start')
);
$template->assign_block_vars(
+23
View File
@@ -415,4 +415,27 @@ $conf['nb_logs_page'] = 300;
// history_admin : history admin visits ?
$conf['history_admin'] = false;
// +-----------------------------------------------------------------------+
// | urls |
// +-----------------------------------------------------------------------+
// question_mark_in_urls : the generated urls contain a ? sign. This can be
// changed to false only if the server translates PATH_INFO variable
// (depends on the server AcceptPathInfo directive configuration)
$conf['question_mark_in_urls'] = true;
// picture_url_style : one of 'id' 'id-file' or 'file'. 'id-file' or 'file'
// mean that the file name (without extension will appear in the url).
// Note that one aditionnal sql query will occur if 'file' is choosen.
// Note that you might experience navigation issues if you choose 'file'
// and your file names are not unique
$conf['picture_url_style'] = 'id';
// php_extension_in_urls : if true, the urls generated for picture and
// category will not contain the .php extension. This will work only if
// .htaccess defines Options +MultiViews parameter or url rewriting rules
// are active.
$conf['php_extension_in_urls'] = true;
?>
+64 -26
View File
@@ -1025,16 +1025,36 @@ function get_root_url()
/**
* adds one or more _GET style parameters to an url
* example: add_url_param('/x', 'a=b') returns /x?a=b
* add_url_param('/x?cat_id=10', 'a=b') returns /x?cat_id=10&a=b
* example: add_url_params('/x', array('a'=>'b')) returns /x?a=b
* add_url_params('/x?cat_id=10', array('a'=>'b')) returns /x?cat_id=10&a=b
* @param string url
* @param string param
* @param array params
* @return string
*/
function add_url_param($url, $param)
function add_url_params($url, $params)
{
$url .= ( strstr($url, '?')===false ) ? '?' :'&';
$url .= $param;
if ( !empty($params) )
{
assert( is_array($params) );
$is_first = true;
foreach($params as $param=>$val)
{
if ($is_first)
{
$is_first = false;
$url .= ( strstr($url, '?')===false ) ? '?' :'&';
}
else
{
$url .= '&';
}
$url .= $param;
if (isset($val))
{
$url .= '='.$val;
}
}
}
return $url;
}
@@ -1046,13 +1066,17 @@ function add_url_param($url, $param)
*/
function make_index_URL($params = array())
{
$url =
get_root_url().'category.php?'
.'/'.make_section_in_URL($params)
;
global $conf;
$url = get_root_url().'category';
if ($conf['question_mark_in_urls'])
{
}
if ($conf['php_extension_in_urls'])
{
$url .= '.php';
}
$url.= make_section_in_URL($params);
$url = add_well_known_params_in_url($url, $params);
return $url;
}
@@ -1134,20 +1158,34 @@ function duplicate_picture_URL($redefined = array(), $removed = array())
*/
function make_picture_URL($params)
{
global $conf;
if (!isset($params['image_id']))
{
die('make_picture_URL: image_id is a required parameter');
}
$url =
get_root_url().'picture.php?'
.'/'.make_section_in_URL($params)
;
$url = get_root_url().'picture';
if ($conf['php_extension_in_urls'])
{
$url .= '.php';
}
if ($conf['question_mark_in_urls'])
{
$url .= '?';
}
$url .= make_section_in_URL($params);
$url = add_well_known_params_in_url($url, $params);
$url.= '/'.
$params['image_id']//.'-'.
//get_filename_wo_extension($params['image_file']).'.htm'
;
$url.= '/';
switch ( $conf['picture_url_style'] )
{
case 'id-file':
$url .= $params['image_id'].'-';
case 'file':
$url .= get_filename_wo_extension($params['image_file']).'.htm';
break;
default:
$url .= $params['image_id'];
}
return $url;
}
@@ -1221,11 +1259,11 @@ function make_section_in_URL($params)
{
if (!isset($params['category']))
{
$section_string.= 'categories';
//$section_string.= '/categories';
}
else
{
$section_string.= 'category/'.$params['category'];
$section_string.= '/category/'.$params['category'];
}
break;
@@ -1237,7 +1275,7 @@ function make_section_in_URL($params)
die('make_section_in_URL: require at least one tag');
}
$section_string.= 'tags';
$section_string.= '/tags';
foreach ($params['tags'] as $tag)
{
@@ -1253,7 +1291,7 @@ function make_section_in_URL($params)
die('make_section_in_URL: require a search identifier');
}
$section_string.= 'search/'.$params['search'];
$section_string.= '/search/'.$params['search'];
break;
}
@@ -1264,13 +1302,13 @@ function make_section_in_URL($params)
die('make_section_in_URL: require a list of items');
}
$section_string.= 'list/'.implode(',', $params['list']);
$section_string.= '/list/'.implode(',', $params['list']);
break;
}
default :
{
$section_string.= $params['section'];
$section_string.= '/'.$params['section'];
}
}
+4 -4
View File
@@ -5,9 +5,9 @@
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $
// | last modifier : $Author: rvelices $
// | revision : $Revision: 1014 $
// | last update : $Date$
// | last modifier : $Author$
// | revision : $Revision$
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
@@ -178,7 +178,7 @@ WHERE id IN (' . implode(',',$page['items']) .')';
//echo ('<pre>'. var_export($calendar, true) . '</pre>');
$must_show_list = true; // true until calendar generates its own display
if (basename($_SERVER['SCRIPT_NAME']) == 'category.php')
if (basename($_SERVER['SCRIPT_FILENAME']) == 'category.php')
{
$template->assign_block_vars('calendar', array());
+9 -5
View File
@@ -6,9 +6,9 @@
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2006-03-09 00:14:53 +0100 (jeu, 09 mar 2006) $
// | last modifier : $Author: rub $
// | revision : $Revision: 1070 $
// | last update : $Date$
// | last modifier : $Author$
// | revision : $Revision$
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
@@ -186,8 +186,12 @@ SELECT id,author,date,image_id,content
'comments.comment.delete',
array(
'U_COMMENT_DELETE' =>
add_url_param( $url_self,
'action=delete_comment&amp;comment_to_delete='.$row['id']
add_url_params(
$url_self,
array(
'action'=>'delete_comment',
'comment_to_delete'=>$row['id']
)
)
)
);
+7 -1
View File
@@ -113,7 +113,13 @@ SELECT COUNT(rate) AS count
'rate.rate_option',
array(
'OPTION' => $mark,
'URL' => add_url_param($url_self,'action=rate&amp;rate='.$mark),
'URL' => add_url_params(
$url_self,
array(
'action'=>'rate',
'rate'=>$mark
)
),
'SEPARATOR' => ($num > 0 ? '|' : ''),
)
);
+15 -7
View File
@@ -83,7 +83,7 @@ $tokens = explode(
// );
$next_token = 0;
if (basename($_SERVER['SCRIPT_NAME']) == 'picture.php')
if (basename($_SERVER['SCRIPT_FILENAME']) == 'picture.php')
{ // the last token must be the identifier for the picture
$token = array_pop($tokens);
if ( is_numeric($token) )
@@ -93,13 +93,14 @@ if (basename($_SERVER['SCRIPT_NAME']) == 'picture.php')
else
{
preg_match('/^(\d+-)?((.*)[_\.]html?)?$/', $token, $matches);
if ( isset($matches[1]) and is_numeric($matches[1]) )
if (isset($matches[1]) and is_numeric($matches[1]=rtrim($matches[1],'-')) )
{
$page['image_id'] = $matches[1];
if ( !empty($matches[3]) )
{
$page['image_file'] = $matches[3];
}
}
else
{
@@ -507,19 +508,26 @@ if (isset($page['chronology_field']))
initialize_calendar();
}
if (basename($_SERVER['SCRIPT_NAME']) == 'picture.php'
if (basename($_SERVER['SCRIPT_FILENAME']) == 'picture.php'
and !isset($page['image_id']) )
{
$query = '
if ( !empty($page['items']) )
{
$query = '
SELECT id,file
FROM '.IMAGES_TABLE .'
WHERE id IN ('.implode(',',$page['items']).')
AND file LIKE "' . $page['image_file'] . '.%" ESCAPE "|"'
;
$result = pwg_query($query);
if (mysql_num_rows($result)>0)
$result = pwg_query($query);
if (mysql_num_rows($result)>0)
{
list($page['image_id'], $page['image_file']) = mysql_fetch_row($result);
}
}
if ( !isset($page['image_id']) )
{
list($page['image_id'], $page['image_file']) = mysql_fetch_row($result);
$page['image_id'] = -1; // will fail in picture.php
}
}
?>