Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

collection_readable()

Description

Returns true if the current user has read access to the given collection.

Parameters

ColumnTypeDefaultDescription
$collection integer

Return

boolean

Location

include/collections_functions.php lines 511 to 560

Definition

 
function collection_readable($collection)
    {
    global 
$userref$usergroup$ignore_collection_access$collection_commenting;

    
# Precautionary check to see if user has featured collection access or collection is their own
    
if(getval("k","") == "" && !in_array($collectionarray_column(get_user_collections($userref,"","name","ASC",-1,false), "ref")) && !featured_collection_check_access_control($collection)) {return false;}

    
# Fetch collection details.
    
if (!is_numeric($collection)) {return false;}
    
$collectiondata=get_collection($collection);
    if(
$collectiondata === false)
        {
        return 
false;
        }

    
# Load a list of attached users
    
$attached=sql_array("select user value from user_collection where collection='$collection'");
    
$attached_groups=sql_array("select usergroup value from usergroup_collection where collection='$collection'");

    
# Access if collection_commenting is enabled and request feedback checked
    # Access if it's a public collection (or theme)
    # Access if k is not empty or option to ignore collection access is enabled and k is empty
    
if (($collection_commenting && $collectiondata['request_feedback'] == 1)
         ||
        
$collectiondata["public"]==
         
||
        
getval("k","")!=""
         
||
        (
getval("k","")=="" && $ignore_collection_access))
        {
        return 
true;
        }

    
# Perform these checks only if a user is logged in
    
if (is_numeric($userref))
        {
        
# Access if:
        #    - It's their collection
        #     - It's a public collection (or theme)
        #    - They have the 'access and edit all collections' admin permission
        #     - They are attached to this collection
        #   - Option to ignore collection access is enabled and k is empty
        
if($userref==$collectiondata["user"] || $collectiondata["public"]==|| checkperm("h") || in_array($userref,$attached)  || in_array($usergroup,$attached_groups) || checkperm("R") || getval("k","")!="" || (getval("k","")=="" && $ignore_collection_access))
            {
            return 
true;
            }
        }

    return 
false;
    }

This article was last updated 3rd March 2021 13:35 Europe/London time based on the source file dated 2nd March 2021 17:50 Europe/London time.