Changeset 2047 for trunk/include/functions_category.inc.php
- Timestamp:
- Jun 28, 2007, 4:16:03 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.