Changeset 1109 for trunk/include/functions.inc.php
- Timestamp:
- Mar 28, 2006, 4:16:34 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions.inc.php
r1102 r1109 3 3 // | PhpWebGallery - a PHP based picture gallery | 4 4 // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | 5 // | Copyright (C) 2003-200 5PhpWebGallery Team - http://phpwebgallery.net |5 // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | 6 6 // +-----------------------------------------------------------------------+ 7 7 // | branch : BSF (Best So Far) … … 32 32 include_once( PHPWG_ROOT_PATH .'include/functions_group.inc.php' ); 33 33 include_once( PHPWG_ROOT_PATH .'include/functions_html.inc.php' ); 34 include_once( PHPWG_ROOT_PATH .'include/functions_url.inc.php' ); 34 35 35 36 //----------------------------------------------------------- generic functions … … 1020 1021 } 1021 1022 1022 /**1023 * returns a prefix for each url link on displayed page1024 * @return string1025 */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 url1038 * example: add_url_params('/x', array('a'=>'b')) returns /x?a=b1039 * add_url_params('/x?cat_id=10', array('a'=>'b')) returns /x?cat_id=10&a=b1040 * @param string url1041 * @param array params1042 * @return string1043 */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 ) ? '?' :'&';1056 }1057 else1058 {1059 $url .= '&';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 section1073 *1074 * @param array1075 * @return string1076 */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 redefinitions1096 * and removes.1097 *1098 * duplicate_index_URL(array('category' => 12), array('start')) will create1099 * an index URL on the current section (categories), but on a redefined1100 * category and without the start URL parameter.1101 *1102 * @param array redefined keys1103 * @param array removed keys1104 * @return string1105 */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 removed1115 *1116 * @param array redefined keys1117 * @param array removed keys1118 * @return array1119 */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 else1137 {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 redefinitions1151 * and removes. See duplicate_index_URL.1152 *1153 * @param array redefined keys1154 * @param array removed keys1155 * @return string1156 */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 picture1166 *1167 * @param array1168 * @return string1169 */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 parameters1205 */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 code1233 * for details)1234 *1235 * @param array1236 * @return string1237 */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 else1276 {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 }1328 1023 ?>
Note: See TracChangeset
for help on using the changeset viewer.