Changeset 2047
- Timestamp:
- Jun 28, 2007, 4:16:03 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions_permalinks.php
r1900 r2047 24 24 // +-----------------------------------------------------------------------+ 25 25 26 /** returns a category id that corresponds to the given permalink (or null) 27 * @param string permalink 28 */ 29 function get_cat_id_from_permalink( $permalink ) 30 { 31 $query =' 32 SELECT id FROM '.CATEGORIES_TABLE.' 33 WHERE permalink="'.$permalink.'"'; 34 $ids = array_from_query($query, 'id'); 35 if (!empty($ids)) 36 { 37 return $ids[0]; 38 } 39 return null; 40 } 41 42 /** returns a category id that has used before this permalink (or null) 43 * @param string permalink 44 * @param boolean is_hit if true update the usage counters on the old permalinks 45 */ 46 function get_cat_id_from_old_permalink($permalink) 47 { 48 $query=' 49 SELECT c.id 50 FROM '.OLD_PERMALINKS_TABLE.' op INNER JOIN '.CATEGORIES_TABLE.' c 51 ON op.cat_id=c.id 52 WHERE op.permalink="'.$permalink.'" 53 LIMIT 1'; 54 $result = pwg_query($query); 55 $cat_id = null; 56 if ( mysql_num_rows($result) ) 57 list( $cat_id ) = mysql_fetch_array($result); 58 return $cat_id; 59 } 60 61 26 62 /** deletes the permalink associated with a category 27 63 * returns true on success … … 49 85 if ($save) 50 86 { 51 $old_cat_id = get_cat_id_from_old_permalink($permalink , false);87 $old_cat_id = get_cat_id_from_old_permalink($permalink); 52 88 if ( isset($old_cat_id) and $old_cat_id!=$cat_id ) 53 89 { … … 101 137 global $page, $cache; 102 138 103 $sanitized_permalink = preg_replace( '#[^a-zA-Z0-9_-]#', '' ,$permalink); 139 $sanitized_permalink = preg_replace( '#[^a-zA-Z0-9_/-]#', '' ,$permalink); 140 $sanitized_permalink = trim($sanitized_permalink, '/'); 141 $sanitized_permalink = str_replace('//', '/', $sanitized_permalink); 104 142 if ( $sanitized_permalink != $permalink 105 143 or preg_match( '#^(\d)+(-.*)?$#', $permalink) ) … … 129 167 130 168 // check if the new permalink was historically used 131 $old_cat_id = get_cat_id_from_old_permalink($permalink , false);169 $old_cat_id = get_cat_id_from_old_permalink($permalink); 132 170 if ( isset($old_cat_id) and $old_cat_id!=$cat_id ) 133 171 { -
trunk/include/functions_category.inc.php
r1900 r2047 365 365 } 366 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 { 367 /** finds a matching category id from a potential list of permalinks 368 * @param array permalinks example: holiday holiday/france holiday/france/paris 369 * @param int idx - output of the index in $permalinks that matches 370 * return category id or null if no match 371 */ 372 function get_cat_id_from_permalinks( $permalinks, &$idx ) 373 { 374 $in = ''; 375 foreach($permalinks as $permalink) 376 { 377 if ( !empty($in) ) $in.=', '; 378 $in .= '"'.$permalink.'"'; 379 } 372 380 $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 381 SELECT c.id, op.permalink, 1 AS is_old 391 382 FROM '.OLD_PERMALINKS_TABLE.' op INNER JOIN '.CATEGORIES_TABLE.' c 392 383 ON op.cat_id=c.id 393 WHERE op.permalink="'.$permalink.'" 384 WHERE op.permalink IN ('.$in.') 385 UNION 386 SELECT id, permalink, 0 AS is_old 387 FROM '.CATEGORIES_TABLE.' 388 WHERE permalink IN ('.$in.') 389 ;'; 390 $perma_hash = hash_from_query($query, 'permalink'); 391 392 if ( empty($perma_hash) ) 393 return null; 394 for ($i=count($permalinks)-1; $i>=0; $i--) 395 { 396 if ( isset( $perma_hash[ $permalinks[$i] ] ) ) 397 { 398 $idx = $i; 399 $cat_id = $perma_hash[ $permalinks[$i] ]['id']; 400 if ($perma_hash[ $permalinks[$i] ]['is_old']) 401 { 402 $query=' 403 UPDATE '.OLD_PERMALINKS_TABLE.' SET last_hit=NOW(), hit=hit+1 404 WHERE permalink="'.$permalinks[$i].'" AND cat_id='.$cat_id.' 394 405 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; 406 pwg_query($query); 407 } 408 return $cat_id; 409 } 410 } 411 return null; 409 412 } 410 413 -
trunk/include/functions_url.inc.php
r2026 r2047 458 458 } 459 459 else 460 { 461 if ( strpos($tokens[$next_token], 'created-')!==0 462 and strpos($tokens[$next_token], 'posted-')!==0 460 {// try a permalink 461 $maybe_permalinks = array(); 462 $current_token = $next_token; 463 while ( isset($tokens[$current_token]) 464 and strpos($tokens[$current_token], 'created-')!==0 465 and strpos($tokens[$current_token], 'posted-')!==0 463 466 and strpos($tokens[$next_token], 'start-')!==0 464 and $tokens[$next_token] != 'flat') 465 {// try a permalink 466 $cat_id = get_cat_id_from_permalink($tokens[$next_token]); 467 if ( !isset($cat_id) ) 468 {//try old permalink 469 $cat_id = get_cat_id_from_old_permalink($tokens[$next_token], true); 467 and $tokens[$current_token] != 'flat') 468 { 469 if (empty($maybe_permalinks)) 470 { 471 array_push($maybe_permalinks, $tokens[$current_token]); 470 472 } 473 else 474 { 475 array_push($maybe_permalinks, 476 $maybe_permalinks[count($maybe_permalinks)-1] 477 . '/' . $tokens[$current_token] 478 ); 479 } 480 $current_token++; 481 } 482 483 if ( count($maybe_permalinks) ) 484 { 485 $cat_id = get_cat_id_from_permalinks($maybe_permalinks, $perma_index); 471 486 if ( isset($cat_id) ) 472 487 { 488 $next_token += $perma_index+1; 473 489 $page['category'] = $cat_id; 474 $page['hit_by']['cat_permalink'] = $ tokens[$next_token];490 $page['hit_by']['cat_permalink'] = $maybe_permalinks[$perma_index]; 475 491 } 476 492 else … … 478 494 page_not_found('Permalink for album not found'); 479 495 } 480 $next_token++;481 496 } 482 497 } 483 498 } 484 499 -
trunk/language/en_UK.iso-8859-1/admin.lang.php
r2032 r2047 149 149 $lang['Permalink'] = 'Permalink'; 150 150 $lang['Permalink_%s_histo_used_by_%s'] = 'Permalink %s has been previously used by category %s. Delete from the permalink history first'; 151 $lang['Permalink_name_rule'] = 'The permalink name must be composed of a-z, A-Z, 0-9, "-" or "_". It must not be numeric or start with number followed by "-"';151 $lang['Permalink_name_rule'] = 'The permalink name must be composed of a-z, A-Z, 0-9, "-", "_" or "/". It must not be numeric or start with number followed by "-"'; 152 152 $lang['Permalink %s is already used by category %s'] = 'Permalink %s is already used by category %s'; 153 153 $lang['Permalink history'] = 'Permalink history'; -
trunk/language/fr_FR.iso-8859-1/admin.lang.php
r2032 r2047 149 149 $lang['Permalink'] = 'Lien permanent'; 150 150 $lang['Permalink_%s_histo_used_by_%s'] = 'Le lien permanent %s a été utilisé précédemment par la catégorie %s. Veuillez l\'effacer de l\'historique des liens permanents'; 151 $lang['Permalink_name_rule'] = 'Le lien permanent ne doit contenir des caractères que parmi "a-zA-Z0-9", "-" ou "_". Il ne doit pas être numérique ou commencer par un nombre suivi par "-"';151 $lang['Permalink_name_rule'] = 'Le lien permanent ne doit contenir des caractères que parmi "a-zA-Z0-9", "-", "_" ou "/". Il ne doit pas être numérique ou commencer par un nombre suivi par "-"'; 152 152 $lang['Permalink %s is already used by category %s'] = 'Le lien permanent %s est dèja utilisé par la catégorie %s'; 153 153 $lang['Permalink history'] = 'Historique des liens permanents';
Note: See TracChangeset
for help on using the changeset viewer.