Changeset 1866 for trunk/include
- Timestamp:
- Feb 28, 2007, 4:07:12 AM (17 years ago)
- Location:
- trunk/include
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/category_cats.inc.php
r1861 r1866 36 36 $query = ' 37 37 SELECT 38 id, name, representative_picture_id, comment, nb_images, uppercats,38 id, name, permalink, representative_picture_id, comment, nb_images, uppercats, 39 39 date_last, max_date_last, count_images, count_categories, global_rank 40 40 FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' … … 58 58 $query = ' 59 59 SELECT 60 id, name, representative_picture_id, comment, nb_images,60 id, name, permalink, representative_picture_id, comment, nb_images, 61 61 date_last, max_date_last, count_images, count_categories 62 62 FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' -
trunk/include/constants.php
r1727 r1866 5 5 // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | 6 6 // +-----------------------------------------------------------------------+ 7 // | branch : BSF (Best So Far) 8 // | file : $RCSfile$ 7 // | file : $Id$ 9 8 // | last update : $Date$ 10 9 // | last modifier : $Author$ … … 76 75 define('PLUGINS_TABLE', $prefixeTable.'plugins'); 77 76 define('WEB_SERVICES_ACCESS_TABLE', $prefixeTable.'ws_access'); 77 define('OLD_PERMALINKS_TABLE', $prefixeTable.'old_permalinks'); 78 78 ?> -
trunk/include/functions.inc.php
r1864 r1866 1176 1176 1177 1177 /** 1178 * creates an hashed based on a query, this function is a very common 1179 * pattern used here. The key is given as parameter, the value is an associative 1180 * array. 1181 * 1182 * @param string $query 1183 * @param string $keyname 1184 * @return array 1185 */ 1186 function hash_from_query($query, $keyname) 1187 { 1188 $array = array(); 1189 $result = pwg_query($query); 1190 while ($row = mysql_fetch_assoc($result)) 1191 { 1192 $array[ $row[$keyname] ] = $row; 1193 } 1194 return $array; 1195 } 1196 1197 /** 1178 1198 * Return basename of the current script 1179 1199 * Lower case convertion is applied on return value -
trunk/include/functions_category.inc.php
r1861 r1866 60 60 // From CATEGORIES_TABLE 61 61 $query.= ' 62 name, id, nb_images, global_rank,';62 id, name, permalink, nb_images, global_rank,'; 63 63 // From USER_CACHE_CATEGORIES_TABLE 64 64 $query.= ' … … 160 160 } 161 161 162 $names = array(); 163 $query = ' 164 SELECT id, name 165 FROM '.CATEGORIES_TABLE.' 166 WHERE id IN ('.$cat['uppercats'].') 167 ;'; 168 $result = pwg_query($query); 169 while($row = mysql_fetch_assoc($result)) 170 { 171 $names[$row['id']] = $row; 172 } 173 174 // category names must be in the same order than uppercats list 175 $cat['upper_names'] = array(); 176 foreach (explode(',', $cat['uppercats']) as $cat_id) 177 { 178 $cat['upper_names'][$cat_id] = $names[$cat_id]; 179 } 180 162 $upper_ids = explode(',', $cat['uppercats']); 163 if ( count($upper_ids)==1 ) 164 {// no need to make a query for level 1 165 $cat['upper_names'] = array( 166 array( 167 'id' => $cat['id'], 168 'name' => $cat['name'], 169 'permalink' => $cat['permalink'], 170 ) 171 ); 172 } 173 else 174 { 175 $names = array(); 176 $query = ' 177 SELECT id, name, permalink 178 FROM '.CATEGORIES_TABLE.' 179 WHERE id IN ('.$cat['uppercats'].') 180 ;'; 181 $names = hash_from_query($query, 'id'); 182 183 // category names must be in the same order than uppercats list 184 $cat['upper_names'] = array(); 185 foreach ($upper_ids as $cat_id) 186 { 187 array_push( $cat['upper_names'], $names[$cat_id]); 188 } 189 } 181 190 return $cat; 182 191 } … … 309 318 if (!empty($result)) 310 319 { 311 while ($row = mysql_fetch_a rray($result))320 while ($row = mysql_fetch_assoc($result)) 312 321 { 313 322 array_push($categories, $row); … … 356 365 } 357 366 367 /** returns a category id that corresponds to the given permalink (or null) 368 * @param string permalink 369 */ 370 function get_cat_id_from_permalink( $permalink ) 371 { 372 $query =' 373 SELECT id FROM '.CATEGORIES_TABLE.' 374 WHERE permalink="'.$permalink.'"'; 375 $ids = array_from_query($query, 'id'); 376 if (!empty($ids)) 377 { 378 return $ids[0]; 379 } 380 return null; 381 } 382 383 /** returns a category id that has used before this permalink (or null) 384 * @param string permalink 385 * @param boolean is_hit if true update the usage counters on the old permalinks 386 */ 387 function get_cat_id_from_old_permalink($permalink, $is_hit) 388 { 389 $query=' 390 SELECT c.id 391 FROM '.OLD_PERMALINKS_TABLE.' op INNER JOIN '.CATEGORIES_TABLE.' c 392 ON op.cat_id=c.id 393 WHERE op.permalink="'.$permalink.'" 394 LIMIT 1'; 395 $result = pwg_query($query); 396 $cat_id = null; 397 if ( mysql_num_rows($result) ) 398 list( $cat_id ) = mysql_fetch_array($result); 399 400 if ( isset($cat_id) and $is_hit ) 401 { 402 $query=' 403 UPDATE '.OLD_PERMALINKS_TABLE.' SET last_hit=NOW(), hit=hit+1 404 WHERE permalink="'.$permalink.'" AND cat_id='.$cat_id.' 405 LIMIT 1'; 406 pwg_query($query); 407 } 408 return $cat_id; 409 } 410 358 411 function global_rank_compare($a, $b) 359 412 { -
trunk/include/functions_html.inc.php
r1861 r1866 235 235 * 236 236 * categories string returned contains categories as given in the input 237 * array $cat_informations. $cat_informations array must be an a ssociation238 * of {category_id => array( id, name) }. If url input parameter is null,237 * array $cat_informations. $cat_informations array must be an array 238 * of array( id=>?, name=>?, permalink=>?). If url input parameter is null, 239 239 * returns only the categories name without links. 240 240 * … … 252 252 $output = ''; 253 253 $is_first = true; 254 foreach ($cat_informations as $ id => $cat)254 foreach ($cat_informations as $cat) 255 255 { 256 256 is_array($cat) or trigger_error( 257 'get_cat_display_name wrong type for cat '.$id, E_USER_WARNING257 'get_cat_display_name wrong type for category ', E_USER_WARNING 258 258 ); 259 259 if ($is_first) … … 283 283 else 284 284 { 285 $output.= '<a href="'.PHPWG_ROOT_PATH.$url.$ id.'">';285 $output.= '<a href="'.PHPWG_ROOT_PATH.$url.$cat['id'].'">'; 286 286 $output.= $cat['name'].'</a>'; 287 287 } … … 319 319 { 320 320 $query = ' 321 SELECT id, name 321 SELECT id, name, permalink 322 322 FROM '.CATEGORIES_TABLE.' 323 323 ;'; 324 $result = pwg_query($query); 325 while ($row = mysql_fetch_assoc($result)) 326 { 327 $cache['cat_names'][$row['id']] = $row; 328 } 324 $cache['cat_names'] = hash_from_query($query, 'id'); 329 325 } 330 326 -
trunk/include/functions_url.inc.php
r1861 r1866 337 337 ); 338 338 339 $section_string.= '/category/'.$params['category']['id']; 340 if ( $conf['category_url_style']=='id-name' ) 339 array_key_exists('permalink', $params['category']) or trigger_error( 340 'make_section_in_url category permalink not set', E_USER_WARNING 341 ); 342 343 $section_string.= '/category/'; 344 if ( empty($params['category']['permalink']) ) 341 345 { 342 $section_string.= '-'.str2url($params['category']['name']); 346 $section_string.= $params['category']['id']; 347 if ( $conf['category_url_style']=='id-name' ) 348 { 349 $section_string.= '-'.str2url($params['category']['name']); 350 } 351 } 352 else 353 { 354 $section_string.= $params['category']['permalink']; 343 355 } 344 356 } -
trunk/include/section_init.inc.php
r1861 r1866 108 108 $page['image_file'] = $matches[2]; 109 109 } 110 111 110 } 112 111 else … … 129 128 $next_token++; 130 129 131 if (isset($tokens[$next_token]) 132 and preg_match('/^(\d+)/', $tokens[$next_token], $matches)) 133 { 134 $page['category'] = $matches[1]; 135 $next_token++; 130 if (isset($tokens[$next_token]) ) 131 { 132 if (preg_match('/^(\d+)(?:-(.+))?$/', $tokens[$next_token], $matches)) 133 { 134 if ( isset($matches[2]) ) 135 $page['hit_by']['cat_url_name'] = $matches[2]; 136 $page['category'] = $matches[1]; 137 $next_token++; 138 } 139 else 140 { 141 if ( strpos($tokens[$next_token], 'created-')!==0 142 and strpos($tokens[$next_token], 'posted-')!==0 143 and $tokens[$next_token] != 'flat') 144 {// try a permalink 145 $cat_id = get_cat_id_from_permalink($tokens[$next_token]); 146 if ( !isset($cat_id) ) 147 {//try old permalink 148 $cat_id = get_cat_id_from_old_permalink($tokens[$next_token], true); 149 } 150 if ( isset($cat_id) ) 151 { 152 $page['category'] = $cat_id; 153 $page['hit_by']['cat_permalink'] = $tokens[$next_token]; 154 } 155 else 156 { 157 page_not_found('Permalink for album not found'); 158 } 159 unset($cat_id); 160 $next_token++; 161 } 162 } 136 163 } 137 164 } … … 691 718 } 692 719 720 // see if we need a redirect because of a permalink 721 if ( 'categories'==$page['section'] and isset($page['category']) ) 722 { 723 $need_redirect=false; 724 if ( empty($page['category']['permalink']) ) 725 { 726 if ( $conf['category_url_style'] == 'id-name' and 727 @$page['hit_by']['cat_url_name'] !== str2url($page['category']['name']) ) 728 { 729 $need_redirect=true; 730 } 731 } 732 else 733 { 734 if ( $page['category']['permalink'] !== @$page['hit_by']['cat_permalink'] ) 735 { 736 $need_redirect=true; 737 } 738 } 739 740 if ($need_redirect) 741 { 742 $redirect_url = ( script_basename()=='picture' 743 ? duplicate_picture_url() 744 : duplicate_index_url() 745 ); 746 if (!headers_sent()) 747 { // this is a permanent redirection 748 set_status_header(302); 749 redirect_http( $redirect_url ); 750 } 751 redirect( $redirect_url ); 752 } 753 unset( $need_redirect, $page['hit_by'] ); 754 } 755 693 756 trigger_action('loc_end_section_init'); 694 757 ?> -
trunk/include/ws_functions.inc.php
r1861 r1866 320 320 321 321 $query = ' 322 SELECT id, name, image_order322 SELECT id, name, permalink, image_order 323 323 FROM '.CATEGORIES_TABLE.' 324 324 WHERE '. implode(' … … 466 466 467 467 $query = ' 468 SELECT id, name, uppercats, global_rank,468 SELECT id, name, permalink, uppercats, global_rank, 469 469 nb_images, count_images AS total_nb_images, 470 470 date_last, max_date_last, count_categories AS nb_categories … … 597 597 //-------------------------------------------------------- related categories 598 598 $query = ' 599 SELECT id, name, uppercats, global_rank, commentable599 SELECT id, name, permalink, uppercats, global_rank, commentable 600 600 FROM '.IMAGE_CATEGORY_TABLE.' 601 601 INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
Note: See TracChangeset
for help on using the changeset viewer.