diff options
author | rvelices <rv-github@modusoptimus.com> | 2006-03-23 01:49:04 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2006-03-23 01:49:04 +0000 |
commit | 5c7d65500573ed52ea2fb1aff8a3218b524ea982 (patch) | |
tree | 1a658831f2a515a3e4210d7c9c9ff6ddfcad7f1e /include/functions.inc.php | |
parent | 4cb765e78362f36073bd490248b1f870095b5c40 (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/functions.inc.php | 90 |
1 files changed, 64 insertions, 26 deletions
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&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']; } } |