Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 2055 to 2124

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 4th December 2024 08:35 Europe/London time based on the source file dated 27th November 2024 09:40 Europe/London time.