aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--admin/notification_by_mail.php16
-rw-r--r--category.php6
-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
-rw-r--r--index.php2
-rw-r--r--install/phpwebgallery_structure.sql2
-rw-r--r--picture.php30
12 files changed, 159 insertions, 65 deletions
diff --git a/admin/notification_by_mail.php b/admin/notification_by_mail.php
index ee31ef077..db92b8e72 100644
--- a/admin/notification_by_mail.php
+++ b/admin/notification_by_mail.php
@@ -7,9 +7,9 @@
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
-// | last update : $Date: 2005-09-21 00:04:57 +0200 (mer, 21 sep 2005) $
-// | last modifier : $Author: plg $
-// | revision : $Revision: 870 $
+// | 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 |
@@ -86,7 +86,7 @@ function update_data_user_mail_notification()
// Set null mail_address empty
$query = '
-update
+update
'.USERS_TABLE.'
set
mail_address = null
@@ -281,10 +281,10 @@ $base_url = get_root_url().'admin.php';
$template->assign_vars(
array(
'U_TABSHEET_TITLE' => l10n('nbm_'.$page['mode'].'_mode'),
- 'U_HELP' => add_url_param(get_root_url().'/popuphelp.php', 'page=notification_by_mail'),
- 'U_PARAM_MODE' => add_url_param($base_url.get_query_string_diff(array('mode')), 'mode=param'),
- 'U_SUBSCRIBE_MODE' => add_url_param($base_url.get_query_string_diff(array('mode')), 'mode=subscribe'),
- 'U_SEND_MODE' => add_url_param($base_url.get_query_string_diff(array('mode')), 'mode=send'),
+ 'U_HELP' => add_url_params(get_root_url().'/popuphelp.php', array('page'=>'notification_by_mail') ),
+ 'U_PARAM_MODE' => add_url_params($base_url.get_query_string_diff(array('mode')), array('mode'=>'param') ),
+ 'U_SUBSCRIBE_MODE' => add_url_params($base_url.get_query_string_diff(array('mode')), array('mode'=>'subscribe') ),
+ 'U_SEND_MODE' => add_url_params($base_url.get_query_string_diff(array('mode')), array('mode'=>'send') ),
'F_ACTION'=> $base_url.get_query_string_diff(array())
));
diff --git a/category.php b/category.php
index 58ae4e247..36e039bed 100644
--- a/category.php
+++ b/category.php
@@ -190,7 +190,7 @@ $template->assign_vars(
'U_HOME' => make_index_URL(),
'U_REGISTER' => get_root_url().'register.php',
'U_LOST_PASSWORD' => get_root_url().'password.php',
- 'U_LOGOUT' => add_url_param(make_index_URL(), 'act=logout'),
+ 'U_LOGOUT' => add_url_params(make_index_URL(), array('act'=>'logout') ),
'U_ADMIN'=> get_root_url().'admin.php',
'U_PROFILE'=> get_root_url().'profile.php',
)
@@ -396,7 +396,7 @@ if (is_admin() and !empty($page['items']) )
'caddie',
array(
'URL' =>
- add_url_param(duplicate_index_url(),'caddie=1')
+ add_url_params(duplicate_index_url(), array('caddie'=>1) )
)
);
}
@@ -446,7 +446,7 @@ if (isset($page['cat_nb_images']) and $page['cat_nb_images'] > 0
'preferred_image_order.order',
array(
'DISPLAY' => $orders[$i][0],
- 'URL' => add_url_param( duplicate_index_URL(), 'image_order='.$i ),
+ 'URL' => add_url_params( duplicate_index_URL(), array('image_order'=>$i) ),
'SELECTED_OPTION' => ($order_idx==$i ? 'SELECTED' : ''),
)
);
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
diff --git a/index.php b/index.php
index d79497cee..9f0b7eb4c 100644
--- a/index.php
+++ b/index.php
@@ -27,5 +27,5 @@
define('PHPWG_ROOT_PATH','./');
include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
-redirect('category.php');
+redirect( make_index_url() );
?>
diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql
index cf3068775..f46babd5c 100644
--- a/install/phpwebgallery_structure.sql
+++ b/install/phpwebgallery_structure.sql
@@ -260,7 +260,7 @@ CREATE TABLE `phpwebgallery_user_cache` (
`user_id` smallint(5) NOT NULL default '0',
`need_update` enum('true','false') NOT NULL default 'true',
`forbidden_categories` text,
- `nb_total_images` mediumint(8),
+ `nb_total_images` mediumint(8) unsigned,
PRIMARY KEY (`user_id`)
) TYPE=MyISAM;
diff --git a/picture.php b/picture.php
index 09353aa39..ac1b2efbe 100644
--- a/picture.php
+++ b/picture.php
@@ -357,16 +357,20 @@ $url_admin =
.'&amp;image_id='.$page['image_id']
;
-$url_slide = add_url_param(
+$url_slide = add_url_params(
$picture['current']['url'],
- 'slideshow='.$conf['slideshow_period'] );
+ array( 'slideshow'=>$conf['slideshow_period'] )
+ );
$title = $picture['current']['name'];
$refresh = 0;
if ( isset( $_GET['slideshow'] ) and isset($page['next_item']) )
{
$refresh= $_GET['slideshow'];
- $url_link = add_url_param($picture['next']['url'], 'slideshow='.$refresh);
+ $url_link = add_url_params(
+ $picture['next']['url'],
+ array('slideshow'=>$refresh)
+ );
}
$title_img = $picture['current']['name'];
@@ -410,7 +414,7 @@ if ($conf['show_exif'] or $conf['show_iptc'])
$metadata_showable = true;
if ( !isset($_GET['metadata']) )
{
- $url_metadata = add_url_param( $url_metadata, 'metadata' );
+ $url_metadata = add_url_params( $url_metadata, array('metadata'=>null) );
}
}
else
@@ -526,7 +530,9 @@ if (is_admin() and isset($page['category']))
$template->assign_block_vars(
'representative',
array(
- 'URL' => add_url_param($url_self, 'action=set_as_representative')
+ 'URL' => add_url_params($url_self,
+ array('action'=>'set_as_representative')
+ )
)
);
}
@@ -537,7 +543,9 @@ if (is_admin())
$template->assign_block_vars(
'caddie',
array(
- 'URL' => add_url_param($url_self, 'action=add_to_caddie')
+ 'URL' => add_url_params($url_self,
+ array('action'=>'add_to_caddie')
+ )
)
);
}
@@ -563,7 +571,10 @@ SELECT COUNT(*) AS nb_fav
'FAVORITE_IMG' => get_root_url().get_themeconf('icon_dir').'/favorite.png',
'FAVORITE_HINT' => $lang['add_favorites_hint'],
'FAVORITE_ALT' => $lang['add_favorites_alt'],
- 'U_FAVORITE' => add_url_param($url_self, 'action=add_to_favorites'),
+ 'U_FAVORITE' => add_url_params(
+ $url_self,
+ array('action'=>'add_to_favorites')
+ ),
)
);
}
@@ -575,7 +586,10 @@ SELECT COUNT(*) AS nb_fav
'FAVORITE_IMG' => get_root_url().get_themeconf('icon_dir').'/del_favorite.png',
'FAVORITE_HINT' => $lang['del_favorites_hint'],
'FAVORITE_ALT' => $lang['del_favorites_alt'],
- 'U_FAVORITE' => add_url_param($url_self, 'action=remove_from_favorites'),
+ 'U_FAVORITE' => add_url_params(
+ $url_self,
+ array('action'=>'remove_from_favorites')
+ )
)
);
}