aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2006-03-23 01:49:04 +0000
committerrvelices <rv-github@modusoptimus.com>2006-03-23 01:49:04 +0000
commit5c7d65500573ed52ea2fb1aff8a3218b524ea982 (patch)
tree1a658831f2a515a3e4210d7c9c9ff6ddfcad7f1e /include
parent4cb765e78362f36073bd490248b1f870095b5c40 (diff)
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
Diffstat (limited to '')
-rw-r--r--include/category_default.inc.php3
-rw-r--r--include/config_default.inc.php23
-rw-r--r--include/functions.inc.php90
-rw-r--r--include/functions_calendar.inc.php8
-rw-r--r--include/picture_comment.inc.php14
-rw-r--r--include/picture_rate.inc.php8
-rw-r--r--include/section_init.inc.php22
7 files changed, 124 insertions, 44 deletions
diff --git a/include/category_default.inc.php b/include/category_default.inc.php
index 47f8fcd27..7201c7bb8 100644
--- a/include/category_default.inc.php
+++ b/include/category_default.inc.php
@@ -85,7 +85,8 @@ foreach ($pictures as $row)
array(
'image_id' => $row['id'],
'image_file' => $row['file']
- )
+ ),
+ array('start')
);
$template->assign_block_vars(
diff --git a/include/config_default.inc.php b/include/config_default.inc.php
index cbb74ad83..b6427772e 100644
--- a/include/config_default.inc.php
+++ b/include/config_default.inc.php
@@ -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;
+
?>
diff --git a/include/functions.inc.php b/include/functions.inc.php
index eb27ce51d..da7991855 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -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&amp;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&amp;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 ) ? '?' :'&amp;';
- $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 ) ? '?' :'&amp;';
+ }
+ else
+ {
+ $url .= '&amp;';
+ }
+ $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'];
}
}
diff --git a/include/functions_calendar.inc.php b/include/functions_calendar.inc.php
index 6dc178d10..962086bce 100644
--- a/include/functions_calendar.inc.php
+++ b/include/functions_calendar.inc.php
@@ -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());
diff --git a/include/picture_comment.inc.php b/include/picture_comment.inc.php
index 6572705dc..79177839d 100644
--- a/include/picture_comment.inc.php
+++ b/include/picture_comment.inc.php
@@ -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']
+ )
)
)
);
diff --git a/include/picture_rate.inc.php b/include/picture_rate.inc.php
index 86c2486ac..46263d968 100644
--- a/include/picture_rate.inc.php
+++ b/include/picture_rate.inc.php
@@ -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 ? '|' : ''),
)
);
diff --git a/include/section_init.inc.php b/include/section_init.inc.php
index 80f853d17..73f11105d 100644
--- a/include/section_init.inc.php
+++ b/include/section_init.inc.php
@@ -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
}
}
?> \ No newline at end of file