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