Changeset 1094


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

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/notification_by_mail.php

    • Property svn:eol-style set to native
    • Property svn:keywords set to Author Date Id Revision
    r1091 r1094  
    88// | branch        : BSF (Best So Far)
    99// | file          : $RCSfile$
    10 // | last update   : $Date: 2005-09-21 00:04:57 +0200 (mer, 21 sep 2005) $
    11 // | last modifier : $Author: plg $
    12 // | revision      : $Revision: 870 $
     10// | last update   : $Date$
     11// | last modifier : $Author$
     12// | revision      : $Revision$
    1313// +-----------------------------------------------------------------------+
    1414// | This program is free software; you can redistribute it and/or modify  |
     
    8787  // Set null mail_address empty
    8888  $query = '
    89 update 
     89update
    9090  '.USERS_TABLE.'
    9191set
     
    282282  array(
    283283    'U_TABSHEET_TITLE' => l10n('nbm_'.$page['mode'].'_mode'),
    284     'U_HELP' => add_url_param(get_root_url().'/popuphelp.php', 'page=notification_by_mail'),
    285     'U_PARAM_MODE' => add_url_param($base_url.get_query_string_diff(array('mode')), 'mode=param'),
    286     'U_SUBSCRIBE_MODE' => add_url_param($base_url.get_query_string_diff(array('mode')), 'mode=subscribe'),
    287     'U_SEND_MODE' => add_url_param($base_url.get_query_string_diff(array('mode')), 'mode=send'),
     284    'U_HELP' => add_url_params(get_root_url().'/popuphelp.php', array('page'=>'notification_by_mail') ),
     285    'U_PARAM_MODE' => add_url_params($base_url.get_query_string_diff(array('mode')), array('mode'=>'param') ),
     286    'U_SUBSCRIBE_MODE' => add_url_params($base_url.get_query_string_diff(array('mode')), array('mode'=>'subscribe') ),
     287    'U_SEND_MODE' => add_url_params($base_url.get_query_string_diff(array('mode')), array('mode'=>'send') ),
    288288    'F_ACTION'=> $base_url.get_query_string_diff(array())
    289289    ));
  • trunk/category.php

    r1092 r1094  
    191191    'U_REGISTER' => get_root_url().'register.php',
    192192    'U_LOST_PASSWORD' => get_root_url().'password.php',
    193     'U_LOGOUT' => add_url_param(make_index_URL(), 'act=logout'),
     193    'U_LOGOUT' => add_url_params(make_index_URL(), array('act'=>'logout') ),
    194194    'U_ADMIN'=> get_root_url().'admin.php',
    195195    'U_PROFILE'=> get_root_url().'profile.php',
     
    397397      array(
    398398        'URL' =>
    399           add_url_param(duplicate_index_url(),'caddie=1')
     399          add_url_params(duplicate_index_url(), array('caddie'=>1) )
    400400        )
    401401      );
     
    447447        array(
    448448          'DISPLAY' => $orders[$i][0],
    449           'URL' => add_url_param( duplicate_index_URL(), 'image_order='.$i ),
     449          'URL' => add_url_params( duplicate_index_URL(), array('image_order'=>$i) ),
    450450          'SELECTED_OPTION' => ($order_idx==$i ? 'SELECTED' : ''),
    451451          )
  • trunk/include/category_default.inc.php

    r1092 r1094  
    8686          'image_id' => $row['id'],
    8787          'image_file' => $row['file']
    88         )
     88        ),
     89        array('start')
    8990      );
    9091
  • trunk/include/config_default.inc.php

    r1087 r1094  
    416416$conf['history_admin'] = false;
    417417
     418// +-----------------------------------------------------------------------+
     419// |                                 urls                                  |
     420// +-----------------------------------------------------------------------+
     421
     422// question_mark_in_urls : the generated urls contain a ? sign. This can be
     423// changed to false only if the server translates PATH_INFO variable
     424// (depends on the server AcceptPathInfo directive configuration)
     425$conf['question_mark_in_urls'] = true;
     426
     427// picture_url_style : one of 'id' 'id-file' or 'file'. 'id-file' or 'file'
     428// mean that the file name (without extension will appear in the url).
     429// Note that one aditionnal sql query will occur if 'file' is choosen.
     430// Note that you might experience navigation issues if you choose 'file'
     431// and your file names are not unique
     432$conf['picture_url_style'] = 'id';
     433
     434
     435// php_extension_in_urls : if true, the urls generated for picture and
     436// category will not contain the .php extension. This will work only if
     437// .htaccess defines Options +MultiViews parameter or url rewriting rules
     438// are active.
     439$conf['php_extension_in_urls'] = true;
     440
    418441?>
  • 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  }
  • trunk/include/functions_calendar.inc.php

    • Property svn:keywords set to Author Date Id Revision
    r1090 r1094  
    66// | branch        : BSF (Best So Far)
    77// | file          : $RCSfile$
    8 // | last update   : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $
    9 // | last modifier : $Author: rvelices $
    10 // | revision      : $Revision: 1014 $
     8// | last update   : $Date$
     9// | last modifier : $Author$
     10// | revision      : $Revision$
    1111// +-----------------------------------------------------------------------+
    1212// | This program is free software; you can redistribute it and/or modify  |
     
    179179
    180180  $must_show_list = true; // true until calendar generates its own display
    181   if (basename($_SERVER['SCRIPT_NAME']) == 'category.php')
     181  if (basename($_SERVER['SCRIPT_FILENAME']) == 'category.php')
    182182  {
    183183    $template->assign_block_vars('calendar', array());
  • trunk/include/picture_comment.inc.php

    • Property svn:eol-style set to native
    • Property svn:keywords set to Author Date Id Revision
    r1090 r1094  
    77// | branch        : BSF (Best So Far)
    88// | file          : $RCSfile$
    9 // | last update   : $Date: 2006-03-09 00:14:53 +0100 (jeu, 09 mar 2006) $
    10 // | last modifier : $Author: rub $
    11 // | revision      : $Revision: 1070 $
     9// | last update   : $Date$
     10// | last modifier : $Author$
     11// | revision      : $Revision$
    1212// +-----------------------------------------------------------------------+
    1313// | This program is free software; you can redistribute it and/or modify  |
     
    187187          array(
    188188            'U_COMMENT_DELETE' =>
    189               add_url_param( $url_self,
    190                   'action=delete_comment&comment_to_delete='.$row['id']
     189              add_url_params(
     190                    $url_self,
     191                    array(
     192                      'action'=>'delete_comment',
     193                      'comment_to_delete'=>$row['id']
     194                    )
    191195                )
    192196            )
  • trunk/include/picture_rate.inc.php

    r1092 r1094  
    114114        array(
    115115          'OPTION'    => $mark,
    116           'URL'       => add_url_param($url_self,'action=rate&rate='.$mark),
     116          'URL'       => add_url_params(
     117                          $url_self,
     118                          array(
     119                            'action'=>'rate',
     120                            'rate'=>$mark
     121                          )
     122                        ),
    117123          'SEPARATOR' => ($num > 0 ? '|' : ''),
    118124          )
  • trunk/include/section_init.inc.php

    r1092 r1094  
    8484
    8585$next_token = 0;
    86 if (basename($_SERVER['SCRIPT_NAME']) == 'picture.php')
     86if (basename($_SERVER['SCRIPT_FILENAME']) == 'picture.php')
    8787{ // the last token must be the identifier for the picture
    8888  $token = array_pop($tokens);
     
    9494  {
    9595    preg_match('/^(\d+-)?((.*)[_\.]html?)?$/', $token, $matches);
    96     if ( isset($matches[1]) and is_numeric($matches[1]) )
     96    if (isset($matches[1]) and is_numeric($matches[1]=rtrim($matches[1],'-')) )
    9797    {
    9898      $page['image_id'] = $matches[1];
     
    101101        $page['image_file'] = $matches[3];
    102102      }
     103
    103104    }
    104105    else
     
    508509}
    509510
    510 if (basename($_SERVER['SCRIPT_NAME']) == 'picture.php'
     511if (basename($_SERVER['SCRIPT_FILENAME']) == 'picture.php'
    511512    and !isset($page['image_id']) )
    512513{
    513   $query = '
     514  if ( !empty($page['items']) )
     515  {
     516    $query = '
    514517SELECT id,file
    515518  FROM '.IMAGES_TABLE .'
     
    517520  AND file LIKE "' . $page['image_file'] . '.%" ESCAPE "|"'
    518521;
    519   $result = pwg_query($query);
    520   if (mysql_num_rows($result)>0)
    521   {
    522     list($page['image_id'], $page['image_file']) = mysql_fetch_row($result);
     522    $result = pwg_query($query);
     523    if (mysql_num_rows($result)>0)
     524    {
     525      list($page['image_id'], $page['image_file']) = mysql_fetch_row($result);
     526    }
     527  }
     528  if ( !isset($page['image_id']) )
     529  {
     530    $page['image_id'] = -1; // will fail in picture.php
    523531  }
    524532}
  • trunk/index.php

    r675 r1094  
    2828define('PHPWG_ROOT_PATH','./');
    2929include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
    30 redirect('category.php');
     30redirect( make_index_url() );
    3131?>
  • trunk/install/phpwebgallery_structure.sql

    r1085 r1094  
    261261  `need_update` enum('true','false') NOT NULL default 'true',
    262262  `forbidden_categories` text,
    263   `nb_total_images` mediumint(8),
     263  `nb_total_images` mediumint(8) unsigned,
    264264  PRIMARY KEY  (`user_id`)
    265265) TYPE=MyISAM;
  • trunk/picture.php

    r1092 r1094  
    358358;
    359359
    360 $url_slide = add_url_param(
     360$url_slide = add_url_params(
    361361  $picture['current']['url'],
    362   'slideshow='.$conf['slideshow_period'] );
     362  array( 'slideshow'=>$conf['slideshow_period'] )
     363  );
    363364
    364365$title =  $picture['current']['name'];
     
    367368{
    368369  $refresh= $_GET['slideshow'];
    369   $url_link = add_url_param($picture['next']['url'], 'slideshow='.$refresh);
     370  $url_link = add_url_params(
     371      $picture['next']['url'],
     372      array('slideshow'=>$refresh)
     373    );
    370374}
    371375
     
    411415  if ( !isset($_GET['metadata']) )
    412416  {
    413     $url_metadata = add_url_param( $url_metadata, 'metadata' );
     417    $url_metadata = add_url_params( $url_metadata, array('metadata'=>null) );
    414418  }
    415419}
     
    527531    'representative',
    528532    array(
    529       'URL' => add_url_param($url_self, 'action=set_as_representative')
     533      'URL' => add_url_params($url_self,
     534                  array('action'=>'set_as_representative')
     535               )
    530536      )
    531537    );
     
    538544    'caddie',
    539545    array(
    540       'URL' => add_url_param($url_self, 'action=add_to_caddie')
     546      'URL' => add_url_params($url_self,
     547                  array('action'=>'add_to_caddie')
     548               )
    541549      )
    542550    );
     
    564572        'FAVORITE_HINT' => $lang['add_favorites_hint'],
    565573        'FAVORITE_ALT'  => $lang['add_favorites_alt'],
    566         'U_FAVORITE'    => add_url_param($url_self, 'action=add_to_favorites'),
     574        'U_FAVORITE'    => add_url_params(
     575                              $url_self,
     576                              array('action'=>'add_to_favorites')
     577                           ),
    567578        )
    568579      );
     
    576587        'FAVORITE_HINT' => $lang['del_favorites_hint'],
    577588        'FAVORITE_ALT'  => $lang['del_favorites_alt'],
    578         'U_FAVORITE'    => add_url_param($url_self, 'action=remove_from_favorites'),
     589        'U_FAVORITE'    => add_url_params(
     590                              $url_self,
     591                              array('action'=>'remove_from_favorites')
     592                           )
    579593        )
    580594      );
Note: See TracChangeset for help on using the changeset viewer.