Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

search_get_previews()

Parameters

ColumnTypeDefaultDescription
$search
$restypes ""
$order_by "relevance"
$archive 0
$fetchrows -1
$sort "DESC"
$access_override false
$ignore_filters false
$return_disk_usage false
$recent_search_daylimit ""
$go false
$stats_logging true
$return_refs_only false
$editable_only false
$returnsql false
$getsizes array
$previewextension "jpg"

Location

include/search_functions.php lines 1920 to 1989

Definition

 
function search_get_previews($search,$restypes="",$order_by="relevance",$archive=0,$fetchrows=-1,$sort="DESC",$access_override=false,$ignore_filters=false,$return_disk_usage=false,$recent_search_daylimit=""$go=false$stats_logging=true$return_refs_only=false$editable_only=false,$returnsql=false,$getsizes=array(),$previewextension="jpg")
    {
    global 
$access;

    
$structured false;
    if(
is_array($fetchrows))
        {
        
$structured true;
        }
    elseif(!
is_array($fetchrows) && strpos((string)$fetchrows,",") !== false)
        {
        
$fetchrows explode(",",$fetchrows);
        if(
count($fetchrows) == 2)
            {
            
$structured true;
            }
        else
            {
            
$fetchrows 0;
            }
        }

    if(
$structured)
        {
        
array_map(function($val){return $val>$val 0;},$fetchrows);
        }

    
# Note the subset of the available parameters. We definitely don't want to allow override of permissions or filters.
    
$resultsdo_search($search,$restypes,$order_by,$archive,$fetchrows,$sort,$access_override,DEPRECATED_STARSEARCH,$ignore_filters,$return_disk_usage,$recent_search_daylimit,$go,$stats_logging,$return_refs_only,$editable_only,$returnsql);
    if(
is_string($getsizes)){$getsizes=explode(",",$getsizes);}
    
$getsizes array_map('trim'$getsizes);

    if (!
is_array($results))
        {
        return 
$results;
        }

    
$total $results["total"] ?? count($results);
    
$resultset $results["data"] ?? $results;

    if(
is_array($resultset) && is_array($getsizes) && count($getsizes)>0)
        {
        
$available=get_all_image_sizes(true,($access==1));
        for(
$n=0;$n<$total;$n++)
            {
            
// if using fetchrows some results may just be == 0 - remove from results array
            
if (!isset($resultset[$n]) || $resultset[$n]==0
                {
                continue;
                }

            
$access=get_resource_access($resultset[$n]);
            
$use_watermark=check_use_watermark();

            if(
$resultset[$n]["access"]==2){continue;} // No images for confidential resources
            
foreach ($getsizes as $getsize)
                {
                if(!(
in_array($getsize,array_column($available,"id")))){continue;}
                if(
                    !
resource_has_access_denied_by_RT_size($resultset[$n]['resource_type'], $getsize)
                    && 
file_exists(get_resource_path($resultset[$n]["ref"],true,$getsize,false,$previewextension,-1,1,$use_watermark))
                )
                    {
                    
$resultset[$n]["url_" $getsize]=get_resource_path($resultset[$n]["ref"],false,$getsize,false,$previewextension,-1,1,$use_watermark);
                    }
                }
            }
        }
    return 
$structured ? ["total"=> $total"data" => $resultset] : $resultset;
    }

This article was last updated 21st May 2024 11:05 Europe/London time based on the source file dated 13th May 2024 14:40 Europe/London time.