Changeset 16 for trunk/include/functions_category.inc.php
- Timestamp:
- May 21, 2003, 11:45:46 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_category.inc.php
r13 r16 378 378 $page['cat_site_id'] = $result['site_id']; 379 379 $page['title'] = get_cat_display_name( $page['cat_name'], ' - ', '' ); 380 $page['where'] = ' wherecat_id = '.$page['cat'];380 $page['where'] = ' WHERE cat_id = '.$page['cat']; 381 381 } 382 382 else … … 392 392 $page['title'].= $_GET['search']."</span>"; 393 393 } 394 $page['where'] = " where ( file like'%".$_GET['search']."%'";395 $page['where'].= " or name like'%".$_GET['search']."%'";396 $page['where'].= " or comment like'%".$_GET['search']."%' )";397 398 $query = ' select count(*) asnb_total_images';399 $query.= ' from'.PREFIX_TABLE.'images';394 $page['where'] = " WHERE ( file LIKE '%".$_GET['search']."%'"; 395 $page['where'].= " OR name LIKE '%".$_GET['search']."%'"; 396 $page['where'].= " OR comment LIKE '%".$_GET['search']."%' )"; 397 398 $query = 'SELECT COUNT(*) AS nb_total_images'; 399 $query.= ' FROM '.PREFIX_TABLE.'images'; 400 400 $query.= $page['where']; 401 401 $query.= ';'; … … 409 409 410 410 $page['where'] = ', '.PREFIX_TABLE.'favorites'; 411 $page['where'].= ' whereuser_id = '.$user['id'];412 $page['where'].= ' andimage_id = id';411 $page['where'].= ' WHERE user_id = '.$user['id']; 412 $page['where'].= ' AND image_id = id'; 413 413 414 $query = ' select count(*) asnb_total_images';415 $query.= ' from'.PREFIX_TABLE.'favorites';416 $query.= ' whereuser_id = '.$user['id'];414 $query = 'SELECT COUNT(*) AS nb_total_images'; 415 $query.= ' FROM '.PREFIX_TABLE.'favorites'; 416 $query.= ' WHERE user_id = '.$user['id']; 417 417 $query.= ';'; 418 418 } … … 424 424 // today - $conf['periode_courte'] 425 425 $date = time() - 60*60*24*$user['short_period']; 426 $page['where'] = " wheredate_available > '";426 $page['where'] = " WHERE date_available > '"; 427 427 $page['where'].= date( 'Y-m-d', $date )."'"; 428 428 429 $query = ' select count(*) asnb_total_images';430 $query.= ' from'.PREFIX_TABLE.'images';429 $query = 'SELECT COUNT(*) AS nb_total_images'; 430 $query.= ' FROM '.PREFIX_TABLE.'images'; 431 431 $query.= $page['where']; 432 432 $query.= ';'; … … 436 436 { 437 437 $page['title'] = $conf['top_number'].' '.$lang['most_visited_cat']; 438 $page['where'] = ' wherecat_id != -1';439 $conf['order_by'] = ' order by hit desc, file asc';438 $page['where'] = ' WHERE cat_id != -1'; 439 $conf['order_by'] = ' ORDER BY hit DESC, file ASC'; 440 440 $page['cat_nb_images'] = $conf['top_number']; 441 441 if ( $page['start'] + $user['nb_image_page'] >= $conf['top_number'] ) … … 456 456 { 457 457 // we must not show pictures of a forbidden category 458 $restricted_cat = get_all_restrictions( $user['id'], $user['status'] ); 459 if ( sizeof( $restricted_cat ) > 0 ) 460 { 461 for ( $i = 0; $i < sizeof( $restricted_cat ); $i++ ) 462 { 463 $page['where'].= ' and cat_id != '.$restricted_cat[$i]; 464 } 458 $restricted_cats = get_all_restrictions( $user['id'],$user['status'] ); 459 foreach ( $restricted_cats as $restricted_cat ) { 460 $page['where'].= ' AND cat_id != '.$restricted_cat; 465 461 } 466 462 } … … 478 474 } 479 475 } 476 477 // get_non_empty_sub_cat_ids returns an array composing of the infos of the 478 // direct sub-categories of the given uppercat id. Each of these infos is 479 // associated to the first found non empty category id. eg : 480 // 481 // - catname [cat_id] 482 // - cat1 [1] -> given uppercat 483 // - cat1.1 [2] (empty) 484 // - cat1.1.1 [5] (empty) 485 // - cat1.1.2 [6] 486 // - cat1.2 [3] 487 // - cat1.3 [4] 488 // 489 // get_non_empty_sub_cat_ids will return : 490 // $cats[0]['id'] = 2; 491 // $cats[0]['name'] = ''; 492 // $cats[0]['dir'] = 'cat1'; 493 // $cats[0]['date_dernier'] = '2003-05-17'; 494 // $cats[0]['non_empty_cat'] = 6; 495 // 496 // $cats[1]['id'] = 3; 497 // $cats[1]['non_empty_cat'] = 3; 498 // 499 // $cats[1]['id'] = 4; 500 // $cats[1]['non_empty_cat'] = 4; 501 function get_non_empty_sub_cat_ids( $id_uppercat ) 502 { 503 global $user; 504 505 $cats = array(); 506 507 $query = 'SELECT id,name,dir,date_dernier,nb_images'; 508 $query.= ' FROM '.PREFIX_TABLE.'categories'; 509 $query.= ' WHERE id_uppercat = '.$id_uppercat; 510 // we must not show pictures of a forbidden category 511 $restricted_cats = get_all_restrictions( $user['id'],$user['status'] ); 512 foreach ( $restricted_cats as $restricted_cat ) { 513 $query.= ' AND id != '.$restricted_cat; 514 } 515 $query.= ' ORDER BY rank'; 516 $query.= ';'; 517 518 $result = mysql_query( $query ); 519 while ( $row = mysql_fetch_array( $result ) ) 520 { 521 if ( $row['nb_images'] == 0 ) 522 { 523 $non_empty_cat = get_first_non_empty_cat_id( $row['id'] ); 524 } 525 else 526 { 527 $non_empty_cat = $row['id']; 528 } 529 // only categories with findable picture in any of its subcats is 530 // represented. 531 if ( $non_empty_cat != false ) 532 { 533 $temp_cat = array( 534 'id' => $row['id'], 535 'name' => $row['name'], 536 'dir' => $row['dir'], 537 'date_dernier' => $row['date_dernier'], 538 'non_empty_cat' => $non_empty_cat ); 539 array_push( $cats, $temp_cat ); 540 } 541 } 542 return $cats; 543 } 544 545 // get_first_non_empty_cat_id returns the id of the first non empty 546 // sub-category to the given uppercat. If no picture is found in any 547 // subcategory, false is returned. 548 function get_first_non_empty_cat_id( $id_uppercat ) 549 { 550 global $user; 551 552 $query = 'SELECT id,nb_images'; 553 $query.= ' FROM '.PREFIX_TABLE.'categories'; 554 $query.= ' WHERE id_uppercat = '.$id_uppercat; 555 // we must not show pictures of a forbidden category 556 $restricted_cats = get_all_restrictions( $user['id'],$user['status'] ); 557 foreach ( $restricted_cats as $restricted_cat ) { 558 $query.= ' AND id != '.$restricted_cat; 559 } 560 $query.= ' ORDER BY RAND()'; 561 $query.= ';'; 562 $result = mysql_query( $query ); 563 while ( $row = mysql_fetch_array( $result ) ) 564 { 565 if ( $row['nb_images'] > 0 ) 566 { 567 return $row['id']; 568 } 569 } 570 $result = mysql_query( $query ); 571 while ( $row = mysql_fetch_array( $result ) ) 572 { 573 // recursive call 574 if ( $subcat = get_first_non_empty_cat_id( $row['id'] ) ) 575 { 576 return $subcat; 577 } 578 } 579 return false; 580 } 480 581 ?>
Note: See TracChangeset
for help on using the changeset viewer.