Ignore:
Timestamp:
Mar 23, 2006, 2:49:04 AM (18 years ago)
Author:
rvelices
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions.inc.php

    r1092 r1094  
    10261026/**
    10271027 * adds one or more _GET style parameters to an url
    1028  * example: add_url_param('/x', 'a=b') returns /x?a=b
    1029  * add_url_param('/x?cat_id=10', 'a=b') returns /x?cat_id=10&a=b
     1028 * example: add_url_params('/x', array('a'=>'b')) returns /x?a=b
     1029 * add_url_params('/x?cat_id=10', array('a'=>'b')) returns /x?cat_id=10&a=b
    10301030 * @param string url
    1031  * @param string param
     1031 * @param array params
    10321032 * @return string
    10331033 */
    1034 function add_url_param($url, $param)
    1035 {
    1036   $url .= ( strstr($url, '?')===false ) ? '?' :'&';
    1037   $url .= $param;
     1034function add_url_params($url, $params)
     1035{
     1036  if ( !empty($params) )
     1037  {
     1038    assert( is_array($params) );
     1039    $is_first = true;
     1040    foreach($params as $param=>$val)
     1041    {
     1042      if ($is_first)
     1043      {
     1044        $is_first = false;
     1045        $url .= ( strstr($url, '?')===false ) ? '?' :'&';
     1046      }
     1047      else
     1048      {
     1049        $url .= '&';
     1050      }
     1051      $url .= $param;
     1052      if (isset($val))
     1053      {
     1054        $url .= '='.$val;
     1055      }
     1056    }
     1057  }
    10381058  return $url;
    10391059}
     
    10471067function make_index_URL($params = array())
    10481068{
    1049   $url =
    1050     get_root_url().'category.php?'
    1051     .'/'.make_section_in_URL($params)
    1052     ;
    1053 
     1069  global $conf;
     1070  $url = get_root_url().'category';
     1071  if ($conf['question_mark_in_urls'])
     1072  {
     1073  }
     1074  if ($conf['php_extension_in_urls'])
     1075  {
     1076    $url .= '.php';
     1077  }
     1078  $url.= make_section_in_URL($params);
    10541079  $url = add_well_known_params_in_url($url, $params);
    1055 
    10561080  return $url;
    10571081}
     
    11351159function make_picture_URL($params)
    11361160{
     1161  global $conf;
    11371162  if (!isset($params['image_id']))
    11381163  {
     
    11401165  }
    11411166
    1142   $url =
    1143     get_root_url().'picture.php?'
    1144     .'/'.make_section_in_URL($params)
    1145     ;
     1167  $url = get_root_url().'picture';
     1168  if ($conf['php_extension_in_urls'])
     1169  {
     1170    $url .= '.php';
     1171  }
     1172  if ($conf['question_mark_in_urls'])
     1173  {
     1174    $url .= '?';
     1175  }
     1176  $url .= make_section_in_URL($params);
    11461177  $url = add_well_known_params_in_url($url, $params);
    1147   $url.= '/'.
    1148          $params['image_id']//.'-'.
    1149          //get_filename_wo_extension($params['image_file']).'.htm'
    1150        ;
     1178  $url.= '/';
     1179  switch ( $conf['picture_url_style'] )
     1180  {
     1181    case 'id-file':
     1182      $url .= $params['image_id'].'-';
     1183    case 'file':
     1184      $url .= get_filename_wo_extension($params['image_file']).'.htm';
     1185      break;
     1186    default:
     1187      $url .= $params['image_id'];
     1188  }
    11511189  return $url;
    11521190}
     
    12221260      if (!isset($params['category']))
    12231261      {
    1224         $section_string.= 'categories';
     1262        //$section_string.= '/categories';
    12251263      }
    12261264      else
    12271265      {
    1228         $section_string.= 'category/'.$params['category'];
     1266        $section_string.= '/category/'.$params['category'];
    12291267      }
    12301268
     
    12381276      }
    12391277
    1240       $section_string.= 'tags';
     1278      $section_string.= '/tags';
    12411279
    12421280      foreach ($params['tags'] as $tag)
     
    12541292      }
    12551293
    1256       $section_string.= 'search/'.$params['search'];
     1294      $section_string.= '/search/'.$params['search'];
    12571295
    12581296      break;
     
    12651303      }
    12661304
    1267       $section_string.= 'list/'.implode(',', $params['list']);
     1305      $section_string.= '/list/'.implode(',', $params['list']);
    12681306
    12691307      break;
     
    12711309    default :
    12721310    {
    1273       $section_string.= $params['section'];
     1311      $section_string.= '/'.$params['section'];
    12741312    }
    12751313  }
Note: See TracChangeset for help on using the changeset viewer.