Changeset 8726 for trunk/include/ws_functions.inc.php
- Timestamp:
- Jan 17, 2011, 10:16:42 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/ws_functions.inc.php
r8464 r8726 1559 1559 1560 1560 1561 $image_ids = array(); 1561 $where_clauses = ws_std_image_sql_filter($params); 1562 if (!empty($where_clauses)) 1563 { 1564 $where_clauses = implode( ' AND ', $where_clauses); 1565 } 1566 $image_ids = get_image_ids_for_tags( 1567 $tag_ids, 1568 $params['tag_mode_and'] ? 'AND' : 'OR', 1569 $where_clauses, 1570 ws_std_image_sql_order($params) ); 1571 1572 1573 $image_ids = array_slice($image_ids, (int)($params['per_page']*$params['page']), (int)$params['per_page'] ); 1574 1562 1575 $image_tag_map = array(); 1563 1564 if ( !empty($tag_ids) ) 1576 if ( !empty($image_ids) and !$params['tag_mode_and'] ) 1565 1577 { // build list of image ids with associated tags per image 1566 if ($params['tag_mode_and']) 1567 { 1568 $image_ids = get_image_ids_for_tags( $tag_ids ); 1569 } 1570 else 1571 { 1572 $query = ' 1578 $query = ' 1573 1579 SELECT image_id, GROUP_CONCAT(tag_id) AS tag_ids 1574 1580 FROM '.IMAGE_TAG_TABLE.' 1575 WHERE tag_id IN ('.implode(',',$tag_ids).') 1581 WHERE tag_id IN ('.implode(',',$tag_ids).') AND image_id IN ('.implode(',',$image_ids).') 1576 1582 GROUP BY image_id'; 1577 $result = pwg_query($query); 1578 while ( $row=pwg_db_fetch_assoc($result) ) 1579 { 1580 $row['image_id'] = (int)$row['image_id']; 1581 array_push( $image_ids, $row['image_id'] ); 1582 $image_tag_map[ $row['image_id'] ] = explode(',', $row['tag_ids']); 1583 } 1583 $result = pwg_query($query); 1584 while ( $row=pwg_db_fetch_assoc($result) ) 1585 { 1586 $row['image_id'] = (int)$row['image_id']; 1587 array_push( $image_ids, $row['image_id'] ); 1588 $image_tag_map[ $row['image_id'] ] = explode(',', $row['tag_ids']); 1584 1589 } 1585 1590 } 1586 1591 1587 1592 $images = array(); 1588 if ( !empty($image_ids)) 1589 { 1590 $where_clauses = ws_std_image_sql_filter($params); 1591 $where_clauses[] = get_sql_condition_FandF( 1592 array 1593 ( 1594 'forbidden_categories' => 'category_id', 1595 'visible_categories' => 'category_id', 1596 'visible_images' => 'i.id' 1597 ), 1598 '', true 1599 ); 1600 $where_clauses[] = 'id IN ('.implode(',',$image_ids).')'; 1601 1602 $order_by = ws_std_image_sql_order($params); 1603 if (empty($order_by)) 1604 { 1605 $order_by = $conf['order_by']; 1606 } 1607 else 1608 { 1609 $order_by = 'ORDER BY '.$order_by; 1610 } 1611 1612 $query = ' 1613 SELECT DISTINCT i.* FROM '.IMAGES_TABLE.' i 1614 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON i.id=image_id 1615 WHERE '. implode(' 1616 AND ', $where_clauses).' 1617 '.$order_by.' 1618 LIMIT '.(int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['page']); 1619 1620 $result = pwg_query($query); 1593 if (!empty($image_ids)) 1594 { 1595 $rank_of = array_flip($image_ids); 1596 $result = pwg_query(' 1597 SELECT * FROM '.IMAGES_TABLE.' 1598 WHERE id IN ('.implode(',',$image_ids).')'); 1621 1599 while ($row = pwg_db_fetch_assoc($result)) 1622 1600 { 1623 1601 $image = array(); 1602 $image['rank'] = $rank_of[ $row['id'] ]; 1624 1603 foreach ( array('id', 'width', 'height', 'hit') as $k ) 1625 1604 { … … 1665 1644 array_push($images, $image); 1666 1645 } 1646 usort($images, 'rank_compare'); 1647 unset($rank_of); 1667 1648 } 1668 1649 … … 2545 2526 global $template; 2546 2527 2547 if (!is_admin() || is_adviser())2528 if (!is_admin()) 2548 2529 { 2549 2530 return new PwgError(401, 'Access denied');
Note: See TracChangeset
for help on using the changeset viewer.