1) { foreach($keywords_expanded as $keyword_expanded) { $node_found = get_node_by_name($nodes, $keyword_expanded); if(0 < count($node_found)) { $subnodestring .= NODE_TOKEN_PREFIX . $node_found['ref']; } } if($subnodestring != "") { $search = str_ireplace($keyword, $subnodestring, $search); } } } # create a display_fields array with information needed for detailed field highlighting $df=array(); $all_field_info=get_fields_for_search_display(array_unique(array_merge($sort_fields,$thumbs_display_fields,$list_display_fields))); # get display and normalize display specific variables $display=getval("display",$default_display);rs_setcookie('display', $display,0,"","",false,false); switch ($display) { case "list": $display_fields = $list_display_fields; $results_title_trim = $list_search_results_title_trim; break; case "xlthumbs": case "thumbs": case "strip": case 'map': default: $display_fields = $thumbs_display_fields; if (isset($search_result_title_height)) { $result_title_height = $search_result_title_height; } $results_title_trim = $search_results_title_trim; $results_title_wordwrap = $search_results_title_wordwrap; break; } $n=0; foreach ($display_fields as $display_field) { # Find field in selected list $all_field_info_count = count($all_field_info); for ($m=0;$m<$all_field_info_count;$m++) { if ($all_field_info[$m]["ref"]==$display_field && $all_field_info[$m]['active'] == 1) { $field_info=$all_field_info[$m]; $df[$n]['ref']=$display_field; $df[$n]['type']=$field_info['type']; $df[$n]['indexed']=$field_info['keywords_index']; $df[$n]['partial_index']=$field_info['partial_index']; $df[$n]['name']=$field_info['name']; $df[$n]['title']=$field_info['title']; $df[$n]['value_filter']=$field_info['value_filter']; ++$n; } } } $n=0; $df_add=hook("displayfieldsadd"); # create a sort_fields array with information for sort fields $n=0; $sf=array(); foreach ($sort_fields as $sort_field) { # Find field in selected list $all_field_info_count = count($all_field_info); for ($m=0;$m<$all_field_info_count;$m++) { if ($all_field_info[$m]["ref"]==$sort_field) { $field_info=$all_field_info[$m]; $sf[$n]['ref']=$sort_field; $sf[$n]['title']=$field_info['title']; ++$n; } } } $n=0; $saved_search=$search; # Append extra search parameters from the quick search. if (!$config_search_for_number || !is_numeric($search)) # Don't do this when the search query is numeric, as users typically expect numeric searches to return the resource with that ID and ignore country/date filters. { // For the simple search fields, collect from the GET and POST requests and assemble into the search string. $search = update_search_from_request($search); } $searchresourceid = ""; if (is_numeric(trim(getval("searchresourceid","")))){ $searchresourceid = trim(getval("searchresourceid","")); $search = "!resource$searchresourceid"; } // Is this a collection search? $collection_search_strpos = strpos($search, "!collection"); $collectionsearch = $collection_search_strpos !== false && $collection_search_strpos === 0; // We want the default collection order to be applied if($collectionsearch) { // Collection search may also have extra search keywords passed to search within a collection $search_trimmed = substr($search,11); // The collection search must always be the first part of the search string $search_elements = split_keywords($search_trimmed, false, false, false, false, true); $collection = (int)array_shift($search_elements); if(count($search_elements) > 0) { $search = "!collection" . $collection . " " . implode(", ",$search_elements); } } hook("searchstringprocessing"); # Fetch and set the values $offset=getval("offset",0,true);if (strpos($search,"!")===false) {rs_setcookie('saved_offset', $offset,0,"","",false,false);} $offset = intval($offset); if ($offset<0) {$offset=0;} $order_by=getval("order_by",""); if (strpos($search,"!")===false || strpos($search,"!properties")!==false) { rs_setcookie('saved_order_by', $order_by,0,"","",false,false); } if ($order_by=="") { if ($collectionsearch) // We want the default collection order to be applied { $order_by=$default_collection_sort; } elseif (substr($search,0,14)=="!contributions") { // As Added is the initial sort sequence to be used for contribution searches $order_by="resourceid"; } else { $order_by=$default_sort; } } if (substr($order_by,0,5)=="field") { $order_by_field = substr($order_by,5); { if(!metadata_field_view_access($order_by_field)) { $order_by = 'relevance'; } } } $per_page=getval("per_page",$default_perpage, true); $per_page= (!in_array($per_page,$results_display_array)) ? $default_perpage : $per_page; rs_setcookie('per_page', $per_page,0,"","",false,false); // Clear special selection collection if user runs a new search. Paging is not a new search. Also we allow for users that // want to see what they've selected so far. Client side we can POST clear_selection_collection=no to prevent it from clearing // (e.g when batch editing) $clear_selection_collection = (getval("clear_selection_collection", "") != "no"); $paging_request = in_array(getval("go", ""), array("next", "prev", "page")); // After a batch edit, check if search has been instructed to check for resources in the selection collection that have // fallen out of the results so should no longer be selected $check_selection_collection = getval("check_selection_collection", "no") == "yes"; // Preserve selection on display layout change (not available for map view). $displaytypes = array('xlthumbs', 'thumbs', 'strip', 'list'); if (isset($_POST['display'])) { $thumbtypechange = in_array($_POST['display'], $displaytypes); } elseif (!isset($_POST['display']) && isset($_GET['display'])) { $thumbtypechange = in_array($_GET['display'], $displaytypes); } else { $thumbtypechange = false; } $view_selected_request = ($use_selection_collection && mb_strpos($search, "!collection{$USER_SELECTION_COLLECTION}") !== false); if($use_selection_collection && $clear_selection_collection && !$paging_request && !$thumbtypechange && !$view_selected_request && !is_null($USER_SELECTION_COLLECTION)) { remove_all_resources_from_collection($USER_SELECTION_COLLECTION); } // Construct archive string and array $archive_choices=getval("archive",""); $archive_standard = $archive_choices==""; $selected_archive_states = array(); if(!is_array($archive_choices)){$archive_choices=explode(",",$archive_choices);} foreach($archive_choices as $archive_choice) { if(is_numeric($archive_choice)) {$selected_archive_states[] = $archive_choice;} } $archive = implode(",",$selected_archive_states); $archivesearched = in_array(2,$selected_archive_states); // Disable search through all workflow states when an archive state is specifically requested // This prevents links like 'View deleted resources' showing resources in all states if($search_all_workflow_states && !$archive_standard) { $search_all_workflow_states = false; } if(false === strpos($search, '!')) { rs_setcookie('saved_archive', $archive,0,"","",false,false); } if($resetlockedfields) { // Reset locked metadata fields cookie after editing resources in upload_review_mode rs_setcookie('lockedfields', '',0,"","",false,false); } $jumpcount=0; if (getval('recentdaylimit', '', true)!="") //set for recent search, don't set cookie { $daylimit=getval('recentdaylimit', '', true); } else {$daylimit="";} // clear cookie for new search if ($order_by=="field{$date_field}") { $default_sort_direction="DESC"; } elseif ($order_by=="collection") { $default_sort_direction="ASC"; } $sort=getval("sort",$default_sort_direction);rs_setcookie('saved_sort', $sort,0,"","",false,false); $revsort = ($sort=="ASC") ? "DESC" : "ASC"; ## If displaying a collection # Enable/disable the reordering feature. Just for collections for now. $allow_reorder=false; # get current collection resources to pre-fill checkboxes if($use_selection_collection) { if(is_null($USER_SELECTION_COLLECTION)) { $selection_collection_resources = array(); $selection_collection_resources_count = 0; } else { $selection_collection_resources = get_collection_resources($USER_SELECTION_COLLECTION); $selection_collection_resources_count = count($selection_collection_resources); } } $hiddenfields=getval("hiddenfields",""); # fetch resource types from query string and generate a resource types cookie if (getval("resetrestypes","")=="") { $restypes=getval("restypes",""); } else { $restypes=""; reset($_POST);reset($_GET);foreach (array_merge($_GET, $_POST) as $key=>$value) { $hiddenfields = array(); if ($key=="rttickall" && $value=="on"){$restypes="";break;} if ((substr($key,0,8)=="resource")&&!in_array($key, $hiddenfields)) {if ($restypes!="") {$restypes.=",";} $restypes.=substr($key,8);} } rs_setcookie('restypes', $restypes,0,"","",false,false); # This is a new search, log this activity if ($archivesearched) {daily_stat("Archive search",0);} else {daily_stat("Search",0);} } $modified_restypes=hook("modifyrestypes_aftercookieset"); if($modified_restypes){$restypes=$modified_restypes;} # If returning to an old search, restore the page/order by and other non search string parameters $old_search = (!array_key_exists('search', $_GET) && !array_key_exists('search', $_POST)); if ($old_search) { $offset=getval("saved_offset",0,true);rs_setcookie('saved_offset', $offset,0,"","",false,false); $order_by=getval("saved_order_by","relevance"); if ($collectionsearch) // We want the default collection order to be applied { $order_by=$default_collection_sort; } else { $order_by=$default_sort; } rs_setcookie('saved_order_by', $order_by,0,"","",false,false); $sort=getval("saved_sort","");rs_setcookie('saved_sort', $sort,0,"","",false,false); $archivechoices=getval("saved_archive",0);rs_setcookie('saved_archive', $archivechoices,0,"","",false,false); if(!is_array($archivechoices)){$archivechoices=explode(",",$archivechoices);} foreach($archivechoices as $archivechoice) { if(is_numeric($archivechoice)) {$selected_archive_states[] = $archivechoice;} } $archive=implode(",",$selected_archive_states); } hook("searchparameterhandler"); # If requested, refresh the collection frame (for redirects from saves) if (getval("refreshcollectionframe","")!="") { refresh_collection_frame(); } # Initialise the results references array (used later for search suggestions) $refs=array(); # Special query? Ignore restypes if( mb_strpos($search, '!') !== false && !$special_search_honors_restypes // Except for these special searches && substr($search, 0, 11) !== '!properties' && substr($search, 0, 7) !== '!report' ) { $restypes = ''; } # Do the search! $search=refine_searchstring($search); $editable_only = getval("foredit","")=="true"; $get_post_array = array_merge($_GET, $_POST); $search_access = null; # admins can search for resources with a specific access from advanced search if(array_key_exists("access", $get_post_array)) { $search_access = $get_post_array["access"]; } rs_setcookie("access", $search_access, 0, "{$baseurl_short}pages/", "", false, false); $searchparams= array( 'search' => $search, 'k' => $k, 'modal' => $modal, 'display' => $display, 'order_by' => $order_by, 'offset' => $offset, 'per_page' => $per_page, 'archive' => $archive, 'sort' => $sort, 'restypes' => $restypes, 'recentdaylimit' => getval('recentdaylimit', '', true), 'foredit' => ($editable_only?"true":""), 'noreload' => "true", 'access' => $search_access, ); if (!empty($selected_archive_states)) { // This is an advanced search. $searchparams['advsearch'] = "true"; } $checkparams = array(); $checkparams[] = "order_by"; $checkparams[] = "sort"; $checkparams[] = "display"; $checkparams[] = "k"; foreach($checkparams as $checkparam) { if(preg_match('/[^a-z:_\-0-9]/i', $$checkparam)) { exit($lang['error_invalid_input'] . ":-
" . $checkparam . " : " . escape($$checkparam) . ""); } } check_order_by_in_table_joins($order_by); if (preg_match("/@{2}!/", $search) || false === strpos($search, '!') || '!properties' == substr($search, 0, 11) ) { rs_setcookie('search', $search,0,"","",false,false); } else { rs_setcookie('search', "",0,"","",false,false); } # set cookie when search form has been submitted - controls display of search results link in header_links.php if( isset($_REQUEST["search"]) && $_REQUEST["search"] == "" ) { rs_setcookie('search_form_submit', true,0,"","",false,false); } hook('searchaftersearchcookie'); $rowstoretrieve = (!$disable_geocoding && $display == "map") ? $search_map_max_results : $per_page; // Do collections search first as this will determine the rows to fetch for do_search() - not for external shares if(($k=="" || $internal_share_access) && strpos($search,"!")===false && ($archive_standard || in_array(0,$selected_archive_states)) && $display !== "map" ) { $collections=do_collections_search($search,$restypes,0,$order_by,$sort,$rowstoretrieve); if(is_array($collections)) { $colcount = count($collections); } else { $colcount = 0; } // Get the number of resources required after collections have been displayed $cols_this_page = max($colcount-$offset,0); $resourcestoretrieve = $per_page - $cols_this_page; } else { $colcount = 0; $resourcestoretrieve = $rowstoretrieve; } if ($search_includes_resources || substr($search,0,1)==="!") { $search_includes_resources=true; // Always enable resource display for special searches. if (!hook("replacesearch")) { if ($use_selection_collection && $check_selection_collection) { $full_search_results = do_search($search,$restypes,$order_by,$archive,-1,$sort,false,DEPRECATED_STARSEARCH,false,false,$daylimit, getval("go",""), true, true, $editable_only, false, $search_access,false,true); } $result=do_search($search,$restypes,$order_by,$archive,[max($offset-$colcount,0),$resourcestoretrieve],$sort,false,DEPRECATED_STARSEARCH,false,false,$daylimit, getval("go",""), true, false, $editable_only, false, $search_access,false,true); } } else { $result=["total"=>0,"data"=>[]]; # Do not return resources (e.g. for collection searching only) } // Convert structured results back to a simple array for display if(isset($result["total"])) { $result_count = $result["total"]; $result = $result["data"]; } else { $result_count = 0; } // Log the search and attempt to reduce log spam by only recording initial searches. Basically, if either of the search // string or resource types or archive states changed. Changing, for example, display or paging don't count as different // searches. $same_search_param = (trim(strip_leading_comma($search)) === $initial_search_cookie); $same_restypes_param = (trim($restypes) === $initial_restypes_cookie); $same_archive_param = (trim($archive) === $initial_saved_archive_cookie); if(!$old_search && (!$same_search_param || !$same_restypes_param || !$same_archive_param)) { log_search_event(trim(strip_leading_comma($search)), explode(',', $restypes), explode(',', $archive), $result_count); } if ($collectionsearch) { $collectiondata = get_collection($collection); if ($k!="" && !$internal_share_access) {$usercollection=$collection;} # External access - set current collection. if (!$collectiondata) { error_alert($lang["error-collectionnotfound"],true); exit; } # Check to see if this user can edit (and therefore reorder) this resource if (($userref==$collectiondata["user"]) || ($collectiondata["allow_changes"]==1) || (checkperm("h"))) { $allow_reorder=true; } } # Include function for reordering if ($allow_reorder && $display!="list") { # Also check for the parameter and reorder as necessary. $reorder=getval("reorder",false); if ($reorder) { $neworder=json_decode(getval("order",false)); update_collection_order($neworder,$collection,$offset); exit("SUCCESS"); } } include "../include/search_title_processing.php"; # Special case: numeric searches (resource ID) and one result: redirect immediately to the resource view. if ((($config_search_for_number && is_numeric($search)) || $searchresourceid > 0) && is_array($result) && count($result)==1) { redirect(generateURL($baseurl_short."pages/view.php",$searchparams,array("ref"=>$result[0]["ref"]))); } # Include the page header to and render the search results include "../include/header.php"; if($k=="" || $internal_share_access) { ?> 0) { collection_remove_resources($USER_SELECTION_COLLECTION, $resource_not_in_search); } } ?>
"field" . $df[$x]['ref'], "sort"=>$revsort)
); ?>"
onclick="return CentralSpaceLoad(this);">
|
"field" . $df[$x]['ref']) ); ?>" onClick="return CentralSpaceLoad(this);"> |
"resourceid","sort"=>$revsort)
); ?>"
onClick="return CentralSpaceLoad(this);">
|
"resourceid") ); ?>" onClick="return CentralSpaceLoad(this);"> |
"resourcetype","sort" => $revsort)
); ?>"
onClick="return CentralSpaceLoad(this);">
|
"resourcetype","sort" => "ASC") ); ?>" onClick="return CentralSpaceLoad(this);"> |
"extension","sort" => $revsort)
); ?>"
onClick="return CentralSpaceLoad(this);">
|
"extension","sort" => "ASC") ); ?>" onClick="return CentralSpaceLoad(this);"> |
"status","sort" => $revsort)
); ?>"
onClick="return CentralSpaceLoad(this);">
|
"status") ); ?>" onClick="return CentralSpaceLoad(this);"> |
"date","sort" => $revsort)
); ?>"
onClick="return CentralSpaceLoad(this);">
|
"date") ); ?>" onClick="return CentralSpaceLoad(this,true);"> |
---|