Changeset 456 for trunk/include/functions_category.inc.php
- Timestamp:
- Jul 26, 2004, 10:45:12 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_category.inc.php
r442 r456 95 95 } 96 96 if ( $cat == 'fav' 97 or $cat == 'search'98 97 or $cat == 'most_visited' 99 98 or $cat == 'best_rated' … … 101 100 or $cat == 'recent_cats' 102 101 or $cat == 'calendar' ) 102 { 103 $page['cat'] = $cat; 104 } 105 if ($cat == 'search' and isset($_GET['search'])) 103 106 { 104 107 $page['cat'] = $cat; … … 449 452 if ( $page['cat'] == 'search' ) 450 453 { 454 // analyze search string given in URL (created in search.php) 455 $tokens = explode('|', $_GET['search']); 456 457 if (isset($tokens[1]) and $tokens[1] == 'AND') 458 { 459 $search['mode'] = 'AND'; 460 } 461 else 462 { 463 $search['mode'] = 'OR'; 464 } 465 466 $search_tokens = explode(';', $tokens[0]); 467 foreach ($search_tokens as $search_token) 468 { 469 $tokens = explode(':', $search_token); 470 $field_name = $tokens[0]; 471 $field_content = $tokens[1]; 472 473 $tokens = explode('~', $tokens[1]); 474 if (isset($tokens[1])) 475 { 476 $search['fields'][$field_name]['mode'] = $tokens[1]; 477 } 478 else 479 { 480 $search['fields'][$field_name]['mode'] = ''; 481 } 482 483 $search['fields'][$field_name]['words'] = array(); 484 $tokens = explode(',', $tokens[0]); 485 foreach ($tokens as $token) 486 { 487 array_push($search['fields'][$field_name]['words'], $token); 488 } 489 } 490 451 491 $page['title'] = $lang['search_result']; 452 492 if ( $calling_page == 'picture' ) … … 456 496 } 457 497 458 $page['where'] = ' WHERE ('; 459 $fields = array( 'file', 'name', 'comment', 'keywords' ); 460 $words = explode( ',', $_GET['search'] ); 461 $sql_search = array(); 462 foreach ( $words as $i => $word ) { 463 // if the user searchs any of the words, the where statement must 464 // be : 465 // field1 LIKE '%$word1%' OR field2 LIKE '%$word1%' ... 466 // OR field1 LIKE '%$word2%' OR field2 LIKE '%$word2%' ... 467 if ( $_GET['mode'] == 'OR' ) 498 // SQL where clauses are stored in $clauses array during query 499 // construction 500 $clauses = array(); 501 502 $textfields = array('file', 'name', 'comment', 'keywords', 'author'); 503 foreach ($textfields as $textfield) 504 { 505 if (isset($search['fields'][$textfield])) 468 506 { 469 if ( $i != 0 ) $page['where'].= ' OR'; 470 foreach ( $fields as $j => $field ) { 471 if ( $j != 0 ) $page['where'].= ' OR'; 472 $page['where'].= ' '.$field." LIKE '%".$word."%'"; 507 $local_clauses = array(); 508 foreach ($search['fields'][$textfield]['words'] as $word) 509 { 510 array_push($local_clauses, $textfield." LIKE '%".$word."%'"); 511 } 512 // adds brackets around where clauses 513 array_walk($local_clauses,create_function('&$s','$s="(".$s.")";')); 514 array_push($clauses, 515 implode(' '.$search['fields'][$textfield]['mode'].' ', 516 $local_clauses)); 517 } 518 } 519 520 $datefields = array('date_available', 'date_creation'); 521 foreach ($datefields as $datefield) 522 { 523 $key = $datefield; 524 if (isset($search['fields'][$key])) 525 { 526 $local_clause = $datefield." = '"; 527 $local_clause.= str_replace('.', '-', 528 $search['fields'][$key]['words'][0]); 529 $local_clause.= "'"; 530 array_push($clauses, $local_clause); 531 } 532 533 foreach (array('after','before') as $suffix) 534 { 535 $key = $datefield.'-'.$suffix; 536 if (isset($search['fields'][$key])) 537 { 538 $local_clause = $datefield; 539 if ($suffix == 'after') 540 { 541 $local_clause.= ' >'; 542 } 543 else 544 { 545 $local_clause.= ' <'; 546 } 547 if (isset($search['fields'][$key]['mode']) 548 and $search['fields'][$key]['mode'] == 'inc') 549 { 550 $local_clause.= '='; 551 } 552 $local_clause.= " '"; 553 $local_clause.= str_replace('.', '-', 554 $search['fields'][$key]['words'][0]); 555 $local_clause.= "'"; 556 array_push($clauses, $local_clause); 473 557 } 474 558 } 475 // if the user searchs all the words : 476 // ( field1 LIKE '%$word1%' OR field2 LIKE '%$word1%' ) 477 // AND ( field1 LIKE '%$word2%' OR field2 LIKE '%$word2%' ) 478 else if ( $_GET['mode'] == 'AND' ) 479 { 480 if ( $i != 0 ) $page['where'].= ' AND'; 481 $page['where'].= ' ('; 482 foreach ( $fields as $j => $field ) { 483 if ( $j != 0 ) $page['where'].= ' OR'; 484 $page['where'].= ' '.$field." LIKE '%".$word."%'"; 485 } 486 $page['where'].= ' )'; 487 } 488 } 489 $page['where'].= ' )'; 559 } 560 561 if (isset($search['fields']['cat'])) 562 { 563 $local_clause = 'category_id IN ('; 564 $local_clause.= implode(',',$search['fields']['cat']['words']); 565 $local_clause.= ')'; 566 array_push($clauses, $local_clause); 567 } 568 569 // adds brackets around where clauses 570 array_walk($clauses, create_function('&$s', '$s = "(".$s.")";')); 571 $page['where'] = 'WHERE '.implode(' '.$search['mode'].' ', $clauses); 490 572 if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden; 491 573 492 $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images'; 493 $query.= ' FROM '.IMAGES_TABLE; 494 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; 495 $query.= ' ON id = ic.image_id'; 496 $query.= $page['where']; 497 $query.= ';'; 498 499 $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; 574 $query = ' 575 SELECT COUNT(DISTINCT(id)) AS nb_total_images 576 FROM '.IMAGES_TABLE.' 577 INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id 578 '.$page['where'].' 579 ;'; 580 $url.= '&search='.$_GET['search']; 500 581 } 501 582 // favorites displaying
Note: See TracChangeset
for help on using the changeset viewer.