Changeset 1837 for trunk/include
- Timestamp:
- Feb 19, 2007, 5:25:47 PM (17 years ago)
- Location:
- trunk/include
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/calendar_monthly.class.php
r1597 r1837 2 2 // +-----------------------------------------------------------------------+ 3 3 // | PhpWebGallery - a PHP based picture gallery | 4 // | Copyright (C) 2003-200 6PhpWebGallery Team - http://phpwebgallery.net |4 // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | 5 5 // +-----------------------------------------------------------------------+ 6 6 // | file : $Id$ … … 439 439 else 440 440 { 441 // first try to guess thumbnail size441 /* // first try to guess thumbnail size 442 442 if ( !empty($items[$day]['width']) ) 443 443 { … … 446 446 $conf['tn_width'], $conf['tn_height'] ); 447 447 } 448 else 448 else*/ 449 449 {// item not an image (tn is either mime type or an image) 450 450 $thumb = get_thumbnail_path($items[$day]); -
trunk/include/config_default.inc.php
r1790 r1837 116 116 // given month. a value of 0 means that the pretty view is not shown. 117 117 // a good suggestion would be to have the width and the height equal 118 // and smaller than tn_width and tn_height. NOTE THAT tn_width AND tn_height 119 // MUST CORRESPOND APPROXIMATIVELY TO YOUR REAL THUMBNAIL SIZE, OTHERWISE 120 // THE IMAGES WILL NOT SHOW CORRECTLY 118 // and smaller than tn_width and tn_height. 121 119 $conf['calendar_month_cell_width'] =80; 122 120 $conf['calendar_month_cell_height']=80; -
trunk/include/functions_search.inc.php
r1744 r1837 3 3 // | PhpWebGallery - a PHP based picture gallery | 4 4 // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | 5 // | Copyright (C) 2003-200 6PhpWebGallery Team - http://phpwebgallery.net |5 // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | 6 6 // +-----------------------------------------------------------------------+ 7 // | branch : BSF (Best So Far)8 7 // | file : $Id$ 9 8 // | last update : $Date$ … … 302 301 function get_quick_search_results($q) 303 302 { 304 global $ user, $page, $filter;303 global $page; 305 304 $search_results = array(); 306 307 // first search tag names corresponding to the query $q. we could also search 308 // tags later during the big join, but for the sake of the performance and 309 // because tags have only a simple name we do it separately 310 $q_like_clause = get_qsearch_like_clause($q, 'CONVERT(name, CHAR)' ); 311 $by_tag_weights=array(); 312 if (!empty($q_like_clause)) 313 { 314 $query = ' 315 SELECT id 316 FROM '.TAGS_TABLE.' 317 WHERE '.$q_like_clause; 318 $tag_ids = array_from_query( $query, 'id'); 319 if (!empty($tag_ids)) 320 { // we got some tags 321 $query = ' 322 SELECT image_id, COUNT(tag_id) AS q 323 FROM '.IMAGE_TAG_TABLE.' 324 WHERE tag_id IN ('.implode(',',$tag_ids).') 325 GROUP BY image_id'; 326 $result = pwg_query($query); 327 while ($row = mysql_fetch_assoc($result)) 328 { // weight is important when sorting images by relevance 329 $by_tag_weights[(int)$row['image_id']] = $row['q']; 330 } 331 } 332 } 333 305 $q = trim($q); 306 if (empty($q)) 307 { 308 $search_results['items'] = array(); 309 return $search_results; 310 } 334 311 // prepare the big join on images, comments and categories 335 312 $query = ' 336 313 SELECT 337 i.id, i.file,CAST( CONCAT_WS(" ",314 i.id, CAST( CONCAT_WS(" ", 338 315 IFNULL(i.name,""), 339 316 IFNULL(i.comment,""), … … 357 334 'forbidden_categories' => 'category_id', 358 335 'visible_categories' => 'category_id', 359 'visible_images' => 'i c.image_id'336 'visible_images' => 'i.id' 360 337 ), 361 338 'WHERE' … … 366 343 WHERE MATCH(ft) AGAINST( "'.$q.'" IN BOOLEAN MODE)'; 367 344 368 //also inlcude the file name (but avoid full text which is slower because369 //the filename in pwg doesn't have spaces so full text is meaningless anyway)370 $q_like_clause = get_qsearch_like_clause($q, 'file' );371 if (! empty($q_like_clause) )372 {373 $query .= ' OR '.$q_like_clause;374 }375 376 345 $by_weights=array(); 377 346 $result = pwg_query($query); 378 347 while ($row = mysql_fetch_array($result)) 379 { 380 $by_weights[(int)$row['id']] = $row['q'] ? $row['q'] : 0; 381 } 382 383 // finally merge the results (tags and big join) sorted by "relevance" 384 foreach ( $by_weights as $image=>$w ) 385 { 386 $by_tag_weights[$image] = 2*$w+ (isset($by_tag_weights[$image])?$by_tag_weights[$image]:0); 348 { // weight is important when sorting images by relevance 349 if ($row['q']) 350 { 351 $by_weights[(int)$row['id']] = 2*$row['q']; 352 } 353 } 354 355 $permissions_checked = true; 356 // now search the file name separately (not done in full text because slower 357 // and the filename in pwg doesn't have spaces so full text is meaningless ) 358 $q_like_clause = get_qsearch_like_clause($q, 'file' ); 359 if (!empty($q_like_clause)) 360 { 361 $query = ' 362 SELECT id 363 FROM '.IMAGES_TABLE.' 364 WHERE '.$q_like_clause. 365 get_sql_condition_FandF 366 ( 367 array 368 ( 369 'visible_images' => 'id' 370 ), 371 'AND' 372 ); 373 $result = pwg_query($query); 374 while ($row = mysql_fetch_assoc($result)) 375 { // weight is important when sorting images by relevance 376 $id=(int)$row['id']; 377 @$by_weights[$id] += 2; 378 $permissions_checked = false; 379 } 380 } 381 382 // now search tag names corresponding to the query $q. we could have searched 383 // tags earlier during the big join, but for the sake of the performance and 384 // because tags have only a simple name we do it separately 385 $q_like_clause = get_qsearch_like_clause($q, 'CONVERT(name, CHAR)' ); 386 if (!empty($q_like_clause)) 387 { 388 $query = ' 389 SELECT id 390 FROM '.TAGS_TABLE.' 391 WHERE '.$q_like_clause; 392 $tag_ids = array_from_query( $query, 'id'); 393 if (!empty($tag_ids)) 394 { // we got some tags 395 $query = ' 396 SELECT image_id, COUNT(tag_id) AS q 397 FROM '.IMAGE_TAG_TABLE.' 398 WHERE tag_id IN ('.implode(',',$tag_ids).') 399 GROUP BY image_id'; 400 $result = pwg_query($query); 401 while ($row = mysql_fetch_assoc($result)) 402 { // weight is important when sorting images by relevance 403 $image_id=(int)$row['image_id']; 404 @$by_weights[$image_id] += $row['q']; 405 $permissions_checked = false; 406 } 407 } 387 408 } 388 409 389 410 //at this point, found images might contain images not allowed for the user 390 if ( empty($by_tag_weights) or isset($page['super_order_by']) ) 391 { 392 // no aditionnal query here for permissions (will be done by section_init 393 // while sorting items as the user requested it) 394 $search_results['items'] = array_keys($by_tag_weights); 395 } 396 else 411 if ( !$permissions_checked 412 and !empty($by_weights) 413 and !isset($page['super_order_by']) ) 397 414 { 398 415 // before returning the result "as is", make sure the user has the … … 402 419 FROM '.IMAGES_TABLE.' 403 420 INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id 404 WHERE id IN ('.implode(',', array_keys($by_ tag_weights) ).')421 WHERE id IN ('.implode(',', array_keys($by_weights) ).') 405 422 '.get_sql_condition_FandF 406 423 ( … … 409 426 'forbidden_categories' => 'category_id', 410 427 'visible_categories' => 'category_id', 411 'visible_images' => 'i c.image_id'428 'visible_images' => 'id' 412 429 ), 413 430 'AND' 414 431 ); 415 432 $allowed_image_ids = array_from_query( $query, 'id'); 416 $by_tag_weights = array_intersect_key($by_tag_weights, array_flip($allowed_image_ids)); 417 arsort($by_tag_weights, SORT_NUMERIC); 418 $search_results = array( 419 'items'=>array_keys($by_tag_weights), 420 'as_is'=>1 421 ); 422 } 433 $by_weights = array_intersect_key($by_weights, array_flip($allowed_image_ids)); 434 $permissions_checked = true; 435 } 436 arsort($by_weights, SORT_NUMERIC); 437 if ( $permissions_checked ) 438 { 439 $search_results['as_is']=1; 440 } 441 442 $search_results['items'] = array_keys($by_weights); 423 443 return $search_results; 424 444 } -
trunk/include/ws_functions.inc.php
r1820 r1837 604 604 } 605 605 606 /** 607 * returns a list of elements corresponding to a query search 608 */ 609 function ws_images_search($params, &$service) 610 { 611 global $page; 612 $images = array(); 613 include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' ); 614 include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); 615 616 $where_clauses = ws_std_image_sql_filter( $params ); 617 $order_by = ws_std_image_sql_order($params); 618 619 if ( !empty($where_clauses) and !empty($order_by) ) 620 { 621 $page['super_order_by']=1; // quick_search_result might be faster 622 } 623 $search_result = get_quick_search_results($params['query']); 624 625 global $image_ids; //needed for sorting by rank (usort) 626 if ( ( !isset($search_result['as_is']) 627 or !empty($where_clauses) 628 or !empty($order_by) ) 629 and !empty($search_result['items']) ) 630 { 631 $where_clauses[] = 'id IN (' 632 .wordwrap(implode(', ', $search_result['items']), 80, "\n") 633 .')'; 634 $where_clauses[] = get_sql_condition_FandF( 635 array 636 ( 637 'forbidden_categories' => 'category_id', 638 'visible_categories' => 'category_id', 639 'visible_images' => 'id' 640 ), 641 '', true 642 ); 643 $query = ' 644 SELECT DISTINCT id FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id 645 WHERE '.implode(' 646 AND ', $where_clauses); 647 if (!empty($order_by)) 648 { 649 $query .= ' 650 ORDER BY '.$order_by; 651 } 652 $image_ids = array_from_query($query, 'id'); 653 global $ranks; 654 $ranks = array_flip( $search_result['items'] ); 655 usort( 656 $image_ids, 657 create_function('$i1,$i2', 'global $ranks; return $ranks[$i1]-$ranks[$i2];') 658 ); 659 unset ($ranks); 660 } 661 else 662 { 663 $image_ids = $search_result['items']; 664 } 665 666 $image_ids = array_slice($image_ids, 667 $params['page']*$params['per_page'], 668 $params['per_page'] ); 669 670 if ( count($image_ids) ) 671 { 672 $query = ' 673 SELECT * FROM '.IMAGES_TABLE.' 674 WHERE id IN (' 675 .wordwrap(implode(', ', $image_ids), 80, "\n") 676 .')'; 677 678 $result = pwg_query($query); 679 while ($row = mysql_fetch_assoc($result)) 680 { 681 $image = array(); 682 foreach ( array('id', 'width', 'height', 'hit') as $k ) 683 { 684 if (isset($row[$k])) 685 { 686 $image[$k] = (int)$row[$k]; 687 } 688 } 689 foreach ( array('name', 'file') as $k ) 690 { 691 $image[$k] = $row[$k]; 692 } 693 $image = array_merge( $image, ws_std_get_urls($row) ); 694 array_push($images, $image); 695 } 696 697 $image_ids = array_flip($image_ids); 698 usort( 699 $images, 700 create_function('$i1,$i2', 'global $image_ids; return $image_ids[$i1["id"]]-$image_ids[$i2["id"]];') 701 ); 702 } 703 704 705 return array( 'images' => 706 array ( 707 WS_XML_ATTRIBUTES => 708 array( 709 'page' => $params['page'], 710 'per_page' => $params['per_page'], 711 'count' => count($images) 712 ), 713 WS_XML_CONTENT => new PwgNamedArray($images, 'image', 714 array('id', 'tn_url', 'element_url', 'file','width','height','hit') ) 715 ) 716 ); 717 } 606 718 607 719 /**
Note: See TracChangeset
for help on using the changeset viewer.