Collections functions
General functions
Render functions
Theme permission functions
Resource functions

get_dash_search_data()

Description

Get images and resource count for search dash tile.
This has to work on a string because the dash tile does not yet exist when on dash creation page
For performance this function will return a maximum of 4 images

Parameters

ColumnTypeDefaultDescription
$link string '' Tile link URL
$promimg int 0 Promoted image ref

Return

array $searchdata Array containing the count of resources and details of preview images.

Location

include/dash_functions.php lines 2138 to 2189

Definition

 
function get_dash_search_data($link=''$promimg=0)
    {    
    
$searchdata = [];
    
$searchdata["count"] = 0;
    
$searchdata["images"] = [];
    
    
$search_string explode('?',$link);
    
parse_str(str_replace("&","&",$search_string[1]),$search_string);
    
$search = isset($search_string["search"]) ? $search_string["search"] :"";
    
$restypes = isset($search_string["restypes"]) ? $search_string["restypes"] : "";
    
$order_by= isset($search_string["order_by"]) ? $search_string["order_by"] : "";
    
$archive = isset($search_string["archive"]) ? $search_string["archive"] : "";
    
$sort = isset($search_string["sort"]) ? $search_string["sort"] : "";

    
$resultsdo_search($search,$restypes,$order_by,$archive,-1,$sort);    
    
$imagecount 0;
    if(
is_array($results))
        {
        
$resultcount count($results);
        
$searchdata["count"] = $resultcount;
        
$n 0;
        
// First see if we can get the promoted image by adding it to the front of the array
        
if($promimg != 0)
            {
            
$add get_resource_data($promimg);
            if(
is_array($add))
                {
                
array_unshift($results,$add);
                }
            }
        while(
$imagecount && $n $resultcount)
            {
            global 
$access// Needed by check_use_watermark()
            
$access=get_resource_access($results[$n]);
            if(
in_array($access,[RESOURCE_ACCESS_RESTRICTED,RESOURCE_ACCESS_FULL]))
                {
                
$use_watermark=check_use_watermark();
                
$resfile=get_resource_path($results[$n]["ref"],true,"pre",false,"jpg",-1,1,$use_watermark);
                if(
file_exists($resfile))
                    {
                    
$searchdata["images"][$imagecount]["ref"] = $results[$n]["ref"];
                    
$searchdata["images"][$imagecount]["thumb_width"] = $results[$n]["thumb_width"];
                    
$searchdata["images"][$imagecount]["thumb_height"] = $results[$n]["thumb_height"];
                    
$searchdata["images"][$imagecount]["url"] = get_resource_path($results[$n]["ref"],false,"pre",false,"jpg",-1,1,$use_watermark);
                    
$imagecount++;
                    }
                }
            
$n++;
            }
        }
    return 
$searchdata;
    }

This article was last updated 4th October 2022 17:05 Europe/London time based on the source file dated 27th September 2022 15:05 Europe/London time.