/** * Returns the list of items corresponding to the advanced search array. * * @param array $search * @param string $images_where optional additional restriction on images table * @return array */ function get_regular_search_results($search, $images_where = '') { global $conf; $forbidden = get_sql_condition_FandF(array('forbidden_categories' => 'category_id', 'visible_categories' => 'category_id', 'visible_images' => 'id'), "\n AND"); $items = array(); $tag_items = array(); if (isset($search['fields']['tags'])) { $tag_items = get_image_ids_for_tags($search['fields']['tags']['words'], $search['fields']['tags']['mode']); } $search_clause = get_sql_search_clause($search); if (!empty($search_clause)) { $query = ' SELECT DISTINCT(id) FROM ' . IMAGES_TABLE . ' i INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS ic ON id = ic.image_id WHERE ' . $search_clause; if (!empty($images_where)) { $query .= "\n AND " . $images_where; } $query .= $forbidden . ' ' . $conf['order_by']; $items = array_from_query($query, 'id'); } if (!empty($tag_items)) { switch ($search['mode']) { case 'AND': if (empty($search_clause)) { $items = $tag_items; } else { $items = array_values(array_intersect($items, $tag_items)); } break; case 'OR': $before_count = count($items); $items = array_unique(array_merge($items, $tag_items)); break; } } return $items; }
/** * API method * Returns a list of images for tags * @param mixed[] $params * @option int[] tag_id (optional) * @option string[] tag_url_name (optional) * @option string[] tag_name (optional) * @option bool tag_mode_and * @option int per_page * @option int page * @option string order */ function ws_tags_getImages($params, &$service) { // first build all the tag_ids we are interested in $tags = find_tags($params['tag_id'], $params['tag_url_name'], $params['tag_name']); $tags_by_id = array(); foreach ($tags as $tag) { $tags['id'] = (int) $tag['id']; $tags_by_id[$tag['id']] = $tag; } unset($tags); $tag_ids = array_keys($tags_by_id); $where_clauses = ws_std_image_sql_filter($params); if (!empty($where_clauses)) { $where_clauses = implode(' AND ', $where_clauses); } $order_by = ws_std_image_sql_order($params, 'i.'); if (!empty($order_by)) { $order_by = 'ORDER BY ' . $order_by; } $image_ids = get_image_ids_for_tags($tag_ids, $params['tag_mode_and'] ? 'AND' : 'OR', $where_clauses, $order_by); $count_set = count($image_ids); $image_ids = array_slice($image_ids, $params['per_page'] * $params['page'], $params['per_page']); $image_tag_map = array(); // build list of image ids with associated tags per image if (!empty($image_ids) and !$params['tag_mode_and']) { $query = ' SELECT image_id, GROUP_CONCAT(tag_id) AS tag_ids FROM ' . IMAGE_TAG_TABLE . ' WHERE tag_id IN (' . implode(',', $tag_ids) . ') AND image_id IN (' . implode(',', $image_ids) . ') GROUP BY image_id ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $row['image_id'] = (int) $row['image_id']; $image_tag_map[$row['image_id']] = explode(',', $row['tag_ids']); } } $images = array(); if (!empty($image_ids)) { $rank_of = array_flip($image_ids); $query = ' SELECT * FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $image_ids) . ') ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $image = array(); $image['rank'] = $rank_of[$row['id']]; foreach (array('id', 'width', 'height', 'hit') as $k) { if (isset($row[$k])) { $image[$k] = (int) $row[$k]; } } foreach (array('file', 'name', 'comment', 'date_creation', 'date_available') as $k) { $image[$k] = $row[$k]; } $image = array_merge($image, ws_std_get_urls($row)); $image_tag_ids = $params['tag_mode_and'] ? $tag_ids : $image_tag_map[$image['id']]; $image_tags = array(); foreach ($image_tag_ids as $tag_id) { $url = make_index_url(array('section' => 'tags', 'tags' => array($tags_by_id[$tag_id]))); $page_url = make_picture_url(array('section' => 'tags', 'tags' => array($tags_by_id[$tag_id]), 'image_id' => $row['id'], 'image_file' => $row['file'])); $image_tags[] = array('id' => (int) $tag_id, 'url' => $url, 'page_url' => $page_url); } $image['tags'] = new PwgNamedArray($image_tags, 'tag', ws_std_get_tag_xml_attributes()); $images[] = $image; } usort($images, 'rank_compare'); unset($rank_of); } return array('paging' => new PwgNamedStruct(array('page' => $params['page'], 'per_page' => $params['per_page'], 'count' => count($images), 'total_count' => $count_set)), 'images' => new PwgNamedArray($images, 'image', ws_std_get_image_xml_attributes())); }
$page['items'] = query2array($query, null, 'image_id'); if (isset($cache_key)) { $persistent_cache->set($cache_key, $page['items']); } } } } else { // +-----------------------------------------------------------------------+ // | tags section | // +-----------------------------------------------------------------------+ if ($page['section'] == 'tags') { $page['tag_ids'] = array(); foreach ($page['tags'] as $tag) { $page['tag_ids'][] = $tag['id']; } $items = get_image_ids_for_tags($page['tag_ids']); $page = array_merge($page, array('title' => get_tags_content_title(), 'items' => $items)); } else { if ($page['section'] == 'search') { include_once PHPWG_ROOT_PATH . 'include/functions_search.inc.php'; $search_result = get_search_results($page['search'], @$page['super_order_by']); //save the details of the query search if (isset($search_result['qs'])) { $page['qsearch_details'] = $search_result['qs']; } $page = array_merge($page, array('items' => $search_result['items'], 'title' => '<a href="' . duplicate_index_url(array('start' => 0)) . '">' . l10n('Search results') . '</a>')); } else { if ($page['section'] == 'favorites') { check_user_favorites(); $page = array_merge($page, array('title' => l10n('Favorites'))); if (!empty($_GET['action']) && $_GET['action'] == 'remove_all_from_favorites') {
$filter_sets[] = query2array($query, null, 'image_id'); } if (isset($_SESSION['bulk_manager_filter']['level'])) { $operator = '='; if (isset($_SESSION['bulk_manager_filter']['level_include_lower'])) { $operator = '<='; } $query = ' SELECT id FROM ' . IMAGES_TABLE . ' WHERE level ' . $operator . ' ' . $_SESSION['bulk_manager_filter']['level'] . ' ' . $conf['order_by']; $filter_sets[] = query2array($query, null, 'id'); } if (!empty($_SESSION['bulk_manager_filter']['tags'])) { $filter_sets[] = get_image_ids_for_tags($_SESSION['bulk_manager_filter']['tags'], $_SESSION['bulk_manager_filter']['tag_mode'], null, null, false); } if (isset($_SESSION['bulk_manager_filter']['dimension'])) { $where_clauses = array(); if (isset($_SESSION['bulk_manager_filter']['dimension']['min_width'])) { $where_clause[] = 'width >= ' . $_SESSION['bulk_manager_filter']['dimension']['min_width']; } if (isset($_SESSION['bulk_manager_filter']['dimension']['max_width'])) { $where_clause[] = 'width <= ' . $_SESSION['bulk_manager_filter']['dimension']['max_width']; } if (isset($_SESSION['bulk_manager_filter']['dimension']['min_height'])) { $where_clause[] = 'height >= ' . $_SESSION['bulk_manager_filter']['dimension']['min_height']; } if (isset($_SESSION['bulk_manager_filter']['dimension']['max_height'])) { $where_clause[] = 'height <= ' . $_SESSION['bulk_manager_filter']['dimension']['max_height']; }
function osm_get_items($page) { // Limit search by category, by tag, by smartalbum $LIMIT_SEARCH = ""; $INNER_JOIN = ""; if (isset($page['section'])) { if ($page['section'] === 'categories' and isset($page['category']) and isset($page['category']['id'])) { $LIMIT_SEARCH = "FIND_IN_SET(" . $page['category']['id'] . ", c.uppercats) AND "; $INNER_JOIN = "INNER JOIN " . CATEGORIES_TABLE . " AS c ON ic.category_id = c.id"; } if ($page['section'] === 'tags' and isset($page['tags']) and isset($page['tags'][0]['id'])) { $items = get_image_ids_for_tags(array($page['tags'][0]['id'])); if (!empty($items)) { $LIMIT_SEARCH = "ic.image_id IN (" . implode(',', $items) . ") AND "; } } if ($page['section'] === 'tags' and isset($page['category']) and isset($page['category']['id'])) { $LIMIT_SEARCH = "FIND_IN_SET(" . $page['category']['id'] . ", c.uppercats) AND "; $INNER_JOIN = "INNER JOIN " . CATEGORIES_TABLE . " AS c ON ic.category_id = c.id"; } } $forbidden = get_sql_condition_FandF(array('forbidden_categories' => 'ic.category_id', 'visible_categories' => 'ic.category_id', 'visible_images' => 'i.id'), "\n AND"); /* We have lat and lng coordonate for virtual album */ if (isset($_GET['min_lat']) and isset($_GET['max_lat']) and isset($_GET['min_lng']) and isset($_GET['max_lng'])) { $LIMIT_SEARCH = ""; $INNER_JOIN = ""; /* Delete all previous album */ $query = "SELECT `id` FROM " . CATEGORIES_TABLE . " WHERE `name` = 'Locations' AND `comment` LIKE '%OSM plugin%';"; $ids = array_from_query($query, 'id'); /* Unlink items for the previous album */ delete_categories($ids, $photo_deletion_mode = 'no_delete'); /* Create an album */ $options = array('comment' => 'Generated by OSM plugin'); $osm_album = create_virtual_category('Locations', NULL, $options); /* Create a sub album */ $options = array('comment' => "OSM virtual album\nlat:" . $_GET['min_lat'] . " " . $_GET['max_lat'] . "\nlng:" . $_GET['min_lng'] . " " . $_GET['max_lng']); $osm_sub_album = create_virtual_category("OSM" . $_GET['min_lat'] . "", $osm_album['id'], $options); /* Get all items inside the lat and lng */ $query = "SELECT `id`, `latitude`, `longitude` \n FROM " . IMAGES_TABLE . " AS i\n INNER JOIN " . IMAGE_CATEGORY_TABLE . " AS ic ON id = ic.image_id\n WHERE " . $LIMIT_SEARCH . " `latitude` IS NOT NULL AND `longitude` IS NOT NULL \n AND `latitude` > " . $_GET['min_lat'] . " AND `latitude` < " . $_GET['max_lat'] . "\n AND `longitude` > " . $_GET['min_lng'] . " AND `longitude` < " . $_GET['max_lng'] . "\n " . $forbidden . ";"; $items = hash_from_query($query, 'id'); /* Add items to the new sub album */ foreach ($items as $item) { $query = "INSERT INTO " . IMAGE_CATEGORY_TABLE . " ( `image_id` ,`category_id` ,`rank` ) VALUES ( '" . $item['id'] . "', '" . $osm_sub_album['id'] . "', NULL );"; pwg_query($query); } /* Redirect to the new album */ header('Location: ' . get_absolute_root_url() . 'index.php?/category/' . $osm_sub_album['id']); exit; } // Fetch data with latitude and longitude //$query="SELECT `latitude`, `longitude`, `name`, `path` FROM ".IMAGES_TABLE." WHERE `latitude` IS NOT NULL AND `longitude` IS NOT NULL;"; // SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', 1) full path without filename extension // SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', -1) full path with only filename extension if (isset($page['image_id'])) { $LIMIT_SEARCH .= 'i.id = ' . $page['image_id'] . ' AND '; } $query = "SELECT i.latitude, i.longitude,\n IFNULL(i.name, '') AS `name`,\n IF(i.representative_ext IS NULL,\n CONCAT(SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', 1 ), '-sq.', SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', -1 )),\n TRIM(LEADING '.' FROM\n REPLACE(i.path, TRIM(TRAILING '.' FROM SUBSTRING_INDEX(i.path, '/', -1 )),\n CONCAT('pwg_representative/',\n CONCAT(\n TRIM(TRAILING '.' FROM SUBSTRING_INDEX( SUBSTRING_INDEX(i.path, '/', -1 ) , '.', 1 )),\n CONCAT('-sq.', i.representative_ext)\n )\n )\n )\n )\n ) AS `pathurl`,\n TRIM(TRAILING '/' FROM CONCAT( i.id, '/category/', IFNULL(i.storage_category_id, '') ) ) AS `imgurl`,\n IFNULL(i.comment, '') AS `comment`,\n IFNULL(i.author, '') AS `author`,\n i.width\n FROM " . IMAGES_TABLE . " AS i\n INNER JOIN (" . IMAGE_CATEGORY_TABLE . " AS ic " . $INNER_JOIN . ") ON i.id = ic.image_id\n WHERE " . $LIMIT_SEARCH . " i.latitude IS NOT NULL AND i.longitude IS NOT NULL " . $forbidden . " GROUP BY i.id;"; //echo $query; $php_data = array_from_query($query); //print_r($php_data); $js_data = array(); foreach ($php_data as $array) { // MySQL did all the job //print_r($array); $js_data[] = array((double) $array['latitude'], (double) $array['longitude'], $array['name'], get_absolute_root_url() . "i.php?" . $array['pathurl'], get_absolute_root_url() . "picture.php?/" . $array['imgurl'], $array['comment'], $array['author'], (int) $array['width']); } /* START Debug generate dummy data $js_data = array(); $str = 'abcdef'; $minLat = -90.00; $maxLat = 90.00; $minLon = -180.00; $maxLon = 180.00; for ($i = 1; $i <= 5000; $i++) { $js_data[] = array( (double)$minLat + (double)((float)rand()/(float)getrandmax() * (($maxLat - $minLat) + 1)), (double)$minLon + (double)((float)rand()/(float)getrandmax() * (($maxLon - $minLon) + 1)), str_shuffle($str), "http://placehold.it/120x120", "http://placehold.it/200x200", "Comment", "Author", (int)120 ); } END Debug generate dummy data */ return $js_data; }