Changeset 1109


Ignore:
Timestamp:
Mar 28, 2006, 4:16:34 AM (18 years ago)
Author:
rvelices
Message:

moved category.php to index.php

split url functions from functions.inc.php to functions_url.inc.php

Location:
trunk
Files:
1 added
4 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/include/calendar_monthly.class.php

    r1092 r1109  
    1   <?php
     1<?php
    22// +-----------------------------------------------------------------------+
    33// | PhpWebGallery - a PHP based picture gallery                           |
  • trunk/include/functions.inc.php

    r1102 r1109  
    33// | PhpWebGallery - a PHP based picture gallery                           |
    44// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
    5 // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
     5// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
    66// +-----------------------------------------------------------------------+
    77// | branch        : BSF (Best So Far)
     
    3232include_once( PHPWG_ROOT_PATH .'include/functions_group.inc.php' );
    3333include_once( PHPWG_ROOT_PATH .'include/functions_html.inc.php' );
     34include_once( PHPWG_ROOT_PATH .'include/functions_url.inc.php' );
    3435
    3536//----------------------------------------------------------- generic functions
     
    10201021}
    10211022
    1022 /**
    1023  * returns a prefix for each url link on displayed page
    1024  * @return string
    1025  */
    1026 function get_root_url()
    1027 {
    1028   global $page;
    1029   if ( isset($page['root_path']) )
    1030   {
    1031     return $page['root_path'];
    1032   }
    1033   return PHPWG_ROOT_PATH;
    1034 }
    1035 
    1036 /**
    1037  * adds one or more _GET style parameters to an url
    1038  * example: add_url_params('/x', array('a'=>'b')) returns /x?a=b
    1039  * add_url_params('/x?cat_id=10', array('a'=>'b')) returns /x?cat_id=10&amp;a=b
    1040  * @param string url
    1041  * @param array params
    1042  * @return string
    1043  */
    1044 function add_url_params($url, $params)
    1045 {
    1046   if ( !empty($params) )
    1047   {
    1048     assert( is_array($params) );
    1049     $is_first = true;
    1050     foreach($params as $param=>$val)
    1051     {
    1052       if ($is_first)
    1053       {
    1054         $is_first = false;
    1055         $url .= ( strstr($url, '?')===false ) ? '?' :'&amp;';
    1056       }
    1057       else
    1058       {
    1059         $url .= '&amp;';
    1060       }
    1061       $url .= $param;
    1062       if (isset($val))
    1063       {
    1064         $url .= '='.$val;
    1065       }
    1066     }
    1067   }
    1068   return $url;
    1069 }
    1070 
    1071 /**
    1072  * build an index URL for a specific section
    1073  *
    1074  * @param array
    1075  * @return string
    1076  */
    1077 function make_index_URL($params = array())
    1078 {
    1079   global $conf;
    1080   $url = get_root_url().'category';
    1081   if ($conf['php_extension_in_urls'])
    1082   {
    1083     $url .= '.php';
    1084   }
    1085   if ($conf['question_mark_in_urls'])
    1086   {
    1087     $url .= '?';
    1088   }
    1089   $url.= make_section_in_URL($params);
    1090   $url = add_well_known_params_in_url($url, $params);
    1091   return $url;
    1092 }
    1093 
    1094 /**
    1095  * build an index URL with current page parameters, but with redefinitions
    1096  * and removes.
    1097  *
    1098  * duplicate_index_URL(array('category' => 12), array('start')) will create
    1099  * an index URL on the current section (categories), but on a redefined
    1100  * category and without the start URL parameter.
    1101  *
    1102  * @param array redefined keys
    1103  * @param array removed keys
    1104  * @return string
    1105  */
    1106 function duplicate_index_URL($redefined = array(), $removed = array())
    1107 {
    1108   return make_index_URL(
    1109     params_for_duplication($redefined, $removed)
    1110     );
    1111 }
    1112 
    1113 /**
    1114  * returns $page global array with key redefined and key removed
    1115  *
    1116  * @param array redefined keys
    1117  * @param array removed keys
    1118  * @return array
    1119  */
    1120 function params_for_duplication($redefined, $removed)
    1121 {
    1122   global $page;
    1123 
    1124   if (count($removed) > 0)
    1125   {
    1126     $params = array();
    1127 
    1128     foreach ($page as $page_item_key => $page_item_value)
    1129     {
    1130       if (!in_array($page_item_key, $removed))
    1131       {
    1132         $params[$page_item_key] = $page_item_value;
    1133       }
    1134     }
    1135   }
    1136   else
    1137   {
    1138     $params = $page;
    1139   }
    1140 
    1141   foreach ($redefined as $redefined_param => $redefined_value)
    1142   {
    1143     $params[$redefined_param] = $redefined_value;
    1144   }
    1145 
    1146   return $params;
    1147 }
    1148 
    1149 /**
    1150  * create a picture URL with current page parameters, but with redefinitions
    1151  * and removes. See duplicate_index_URL.
    1152  *
    1153  * @param array redefined keys
    1154  * @param array removed keys
    1155  * @return string
    1156  */
    1157 function duplicate_picture_URL($redefined = array(), $removed = array())
    1158 {
    1159   return make_picture_URL(
    1160     params_for_duplication($redefined, $removed)
    1161     );
    1162 }
    1163 
    1164 /**
    1165  * create a picture URL on a specific section for a specific picture
    1166  *
    1167  * @param array
    1168  * @return string
    1169  */
    1170 function make_picture_URL($params)
    1171 {
    1172   global $conf;
    1173   if (!isset($params['image_id']))
    1174   {
    1175     die('make_picture_URL: image_id is a required parameter');
    1176   }
    1177 
    1178   $url = get_root_url().'picture';
    1179   if ($conf['php_extension_in_urls'])
    1180   {
    1181     $url .= '.php';
    1182   }
    1183   if ($conf['question_mark_in_urls'])
    1184   {
    1185     $url .= '?';
    1186   }
    1187   $url .= make_section_in_URL($params);
    1188   $url = add_well_known_params_in_url($url, $params);
    1189   $url.= '/';
    1190   switch ( $conf['picture_url_style'] )
    1191   {
    1192     case 'id-file':
    1193       $url .= $params['image_id'].'-';
    1194     case 'file':
    1195       $url .= get_filename_wo_extension($params['image_file']).'.htm';
    1196       break;
    1197     default:
    1198       $url .= $params['image_id'];
    1199   }
    1200   return $url;
    1201 }
    1202 
    1203 /**
    1204  *adds to the url the chronology and start parameters
    1205 */
    1206 function add_well_known_params_in_url($url, $params)
    1207 {
    1208   if ( isset($params['chronology_field']) )
    1209   {
    1210     $url .= '/'. $params['chronology_field'];
    1211     $url .= '-'. $params['chronology_style'];
    1212     if ( isset($params['chronology_view']) )
    1213     {
    1214       $url .= '-'. $params['chronology_view'];
    1215     }
    1216     if ( !empty($params['chronology_date']) )
    1217     {
    1218       $url .= '-'. implode('-', $params['chronology_date'] );
    1219     }
    1220   }
    1221 
    1222   if (isset($params['start']) and $params['start'] > 0)
    1223   {
    1224     $url.= '/start-'.$params['start'];
    1225   }
    1226   return $url;
    1227 }
    1228 
    1229 /**
    1230  * return the section token of an index or picture URL.
    1231  *
    1232  * Depending on section, other parameters are required (see function code
    1233  * for details)
    1234  *
    1235  * @param array
    1236  * @return string
    1237  */
    1238 function make_section_in_URL($params)
    1239 {
    1240   $section_string = '';
    1241 
    1242   if (!isset($params['section']))
    1243   {
    1244     if (isset($params['category']))
    1245     {
    1246       $params['section'] = 'categories';
    1247     }
    1248     else if (isset($params['tags']))
    1249     {
    1250       $params['section'] = 'tags';
    1251     }
    1252     else if (isset($params['list']))
    1253     {
    1254       $params['section'] = 'list';
    1255     }
    1256     else if (isset($params['search']))
    1257     {
    1258       $params['section'] = 'search';
    1259     }
    1260   }
    1261 
    1262   if (!isset($params['section']))
    1263   {
    1264     $params['section'] = 'categories';
    1265   }
    1266 
    1267   switch($params['section'])
    1268   {
    1269     case 'categories' :
    1270     {
    1271       if (!isset($params['category']))
    1272       {
    1273         //$section_string.= '/categories';
    1274       }
    1275       else
    1276       {
    1277         $section_string.= '/category/'.$params['category'];
    1278       }
    1279 
    1280       break;
    1281     }
    1282     case 'tags' :
    1283     {
    1284       if (!isset($params['tags']) or count($params['tags']) == 0)
    1285       {
    1286         die('make_section_in_URL: require at least one tag');
    1287       }
    1288 
    1289       $section_string.= '/tags';
    1290 
    1291       foreach ($params['tags'] as $tag)
    1292       {
    1293         $section_string.= '/'.$tag;
    1294       }
    1295 
    1296       break;
    1297     }
    1298     case 'search' :
    1299     {
    1300       if (!isset($params['search']))
    1301       {
    1302         die('make_section_in_URL: require a search identifier');
    1303       }
    1304 
    1305       $section_string.= '/search/'.$params['search'];
    1306 
    1307       break;
    1308     }
    1309     case 'list' :
    1310     {
    1311       if (!isset($params['list']))
    1312       {
    1313         die('make_section_in_URL: require a list of items');
    1314       }
    1315 
    1316       $section_string.= '/list/'.implode(',', $params['list']);
    1317 
    1318       break;
    1319     }
    1320     default :
    1321     {
    1322       $section_string.= '/'.$params['section'];
    1323     }
    1324   }
    1325 
    1326   return $section_string;
    1327 }
    13281023?>
  • trunk/include/functions_calendar.inc.php

    r1094 r1109  
    179179
    180180  $must_show_list = true; // true until calendar generates its own display
    181   if (basename($_SERVER['SCRIPT_FILENAME']) == 'category.php')
     181  if (basename($_SERVER['SCRIPT_FILENAME']) != 'picture.php')
    182182  {
    183183    $template->assign_block_vars('calendar', array());
  • trunk/include/section_init.inc.php

    r1094 r1109  
    8585$next_token = 0;
    8686if (basename($_SERVER['SCRIPT_FILENAME']) == 'picture.php')
    87 { // the last token must be the identifier for the picture
    88   $token = array_pop($tokens);
     87{ // the first token must be the identifier for the picture
     88  if ( isset($_GET['image_id'])
     89       and isset($_GET['cat']) and is_numeric($_GET['cat']) )
     90  {// url compatibility with versions below 1.6
     91    $url = make_picture_url( array(
     92        'section' => 'categories',
     93        'category' => $_GET['cat'],
     94        'image_id' => $_GET['image_id']
     95      ) );
     96    redirect($url);
     97  }
     98  $token = $tokens[$next_token];
     99  $next_token++;
    89100  if ( is_numeric($token) )
    90101  {
     
    93104  else
    94105  {
    95     preg_match('/^(\d+-)?((.*)[_\.]html?)?$/', $token, $matches);
     106    preg_match('/^(\d+-)?(.*)?$/', $token, $matches);
    96107    if (isset($matches[1]) and is_numeric($matches[1]=rtrim($matches[1],'-')) )
    97108    {
    98109      $page['image_id'] = $matches[1];
    99       if ( !empty($matches[3]) )
     110      if ( !empty($matches[2]) )
    100111      {
    101         $page['image_file'] = $matches[3];
     112        $page['image_file'] = $matches[2];
    102113      }
    103114
     
    105116    else
    106117    {
    107       if ( !empty($matches[3]) )
     118      if ( !empty($matches[2]) )
    108119      {
    109         $page['image_file'] = $matches[3];
     120        $page['image_file'] = $matches[2];
    110121      }
    111122      else
     
    117128}
    118129
    119 if (0 === strpos($tokens[$next_token], 'cat'))
     130if (0 === strpos($tokens[$next_token], 'categor'))
    120131{
    121132  $page['section'] = 'categories';
     
    214225  $next_token++;
    215226}
    216 else
    217 {
    218   $page['section'] = 'categories';
    219   $next_token++;
    220 }
    221227
    222228for ($i = $next_token; ; $i++)
  • trunk/index.php

    r1106 r1109  
    109109include(PHPWG_ROOT_PATH.'include/page_header.php');
    110110
    111 $template->set_filenames( array('category'=>'category.tpl') );
     111$template->set_filenames( array('index'=>'index.tpl') );
    112112//-------------------------------------------------------------- category title
    113113if (isset($page['category']))
     
    483483pwg_log('category', $page['title']);
    484484
    485 $template->parse('category');
     485$template->parse('index');
    486486include(PHPWG_ROOT_PATH.'include/page_tail.php');
    487487?>
Note: See TracChangeset for help on using the changeset viewer.