Collections functions
General functions
Render functions
Theme permission functions
Resource functions

get_resource_data()

Parameters

ColumnTypeDefaultDescription
$ref
$cache true

Location

include/resource_functions.php lines 371 to 424

Definition

 
function get_resource_data($ref,$cache=true)
    {
    if ((string)(int)
$ref != (string)$ref)
        {
        return 
false;
        }
    
# Returns basic resource data (from the resource table alone) for resource $ref.
    # For 'dynamic' field data, see get_resource_field_data
    
global $default_resource_type$get_resource_data_cache,$always_record_resource_creator;
    if (
$cache && isset($get_resource_data_cache[$ref])) {return $get_resource_data_cache[$ref];}
    
truncate_cache_arrays();

    
# Build a string that will return the 'join' columns (not actually joins but cached truncated metadata stored at the resource level)
    
$joins=get_resource_table_joins();
    
$join_fields="";foreach ($joins as $j) {$join_fields.=",field" $j;}

    
$resource=ps_query("select ref,title,resource_type,has_image,is_transcoding,hit_count,new_hit_count,creation_date,rating,user_rating,user_rating_count,user_rating_total,country,file_extension,preview_extension,image_red,image_green,image_blue,thumb_width,thumb_height,archive,access,colour_key,created_by,file_path,file_modified,file_checksum,request_count,expiry_notification_sent,preview_tweaks,geo_lat,geo_long,mapzoom,disk_usage,disk_usage_last_updated,file_size,preview_attempts,modified,last_verified,integrity_fail,lock_user" $join_fields " from resource where ref=?",array("i",$ref));
    if (
count($resource)==0)
        {
        if (
$ref>=0)
            {
            return 
false;
            }
        else
            {
            
# For upload templates (negative reference numbers), generate a new resource if upload permission.
            
if (!(checkperm("c") || checkperm("d"))) {return false;}
            elseif(!
hook('replace_upload_template_creation''', array($ref)))
                {
                if (isset(
$always_record_resource_creator) && $always_record_resource_creator)
                    {
                    global 
$userref;
                    
$user $userref;
                    }
                else {
$user = -1;}

                
$default_archive_state get_default_archive_state();
                
$wait ps_query("insert into resource (ref,resource_type,created_by, archive) values (?,?,?,?)",array("i",$ref,"i",$default_resource_type,"i",$user,"i",$default_archive_state));

                
$resource ps_query("select ref,title,resource_type,has_image,is_transcoding,hit_count,new_hit_count,creation_date,rating,user_rating,user_rating_count,user_rating_total,country,file_extension,preview_extension,image_red,image_green,image_blue,thumb_width,thumb_height,archive,access,colour_key,created_by,file_path,file_modified,file_checksum,request_count,expiry_notification_sent,preview_tweaks,geo_lat,geo_long,mapzoom,disk_usage,disk_usage_last_updated,file_size,preview_attempts,modified,last_verified,integrity_fail,lock_user" $join_fields " from resource where ref=?",array("i",$ref));
                }
            }
        }

    if (isset(
$resource[0]))
        {
        
$get_resource_data_cache[$ref]=$resource[0];
        return 
$resource[0];
        }
    else
        {
        return 
false;
        }
    }

This article was last updated 3rd October 2022 11:35 Europe/London time based on the source file dated 30th September 2022 14:20 Europe/London time.