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

compute_featured_collections_access_control()

Description

Compute the featured collections allowed based on current access control

TRUE if user has access to all featured collections. If some access control is in place, then the
return will be an array with all the allowed featured collections

Parameters

This function accepts no parameters.

Return

boolean|array Returns FALSE if user should not see any featured collections (usually means misconfiguration) -or-

Location

include/collections_functions.php lines 5063 to 5152

Definition

 
function compute_featured_collections_access_control()
    {
    global 
$CACHE_FC_ACCESS_CONTROL$userpermissions;
    if(!
is_null($CACHE_FC_ACCESS_CONTROL))
        {
        return 
$CACHE_FC_ACCESS_CONTROL;
        }

    
$all_fcs sql_query(sprintf("SELECT ref, parent FROM collection WHERE `type` = %s"COLLECTION_TYPE_FEATURED), "featured_collections");
    
$all_fcs_rp reshape_array_by_value_keys($all_fcs'ref''parent');
    
// Set up arrays to store permitted/blocked featured collections
    
$includerefs = array();
    
$excluderefs = array();
    if(
checkperm("j*"))
        {
        
// Check for -jX permissions.
        
foreach($userpermissions as $userpermission)
            {
            if(
substr($userpermission,0,2) == "-j")
                {
                
$fcid substr($userpermission,2);
                if(
is_int_loose($fcid))
                    {
                    
// Collection access has been explicitly denied
                    
$excluderefs[] = $fcid;
                    }                
                }
            }
        if(
count($excluderefs) == 0)
            {
            return 
true;
            }
        }
    else
        {
        
// No access to all, check for j{field} permissions that open up access
        
foreach($userpermissions as $userpermission)
            {
            if(
substr($userpermission,0,1) == "j")
                {
                
$fcid substr($userpermission,1);
                if(
is_int_loose($fcid))
                    {
                    
$includerefs[] = $fcid;
                    
// Add children of this collection unless a -j permission has been added below it
                    
$children array_keys($all_fcs_rp,$fcid);
                    
$queue = new SplQueue();
                    
$queue->setIteratorMode(SplQueue::IT_MODE_DELETE);
                    foreach(
$children as $child_fc)
                        {
                        
$queue->enqueue($child_fc);
                        }
                
                    while(!
$queue->isEmpty())
                        {
                        
$checkfc $queue->dequeue();
                        if(!
checkperm("-j" $checkfc))
                            {
                            
$includerefs[] = $checkfc;
                            
// Also add children of this collection to queue to check
                            
$fcs_sub array_keys($all_fcs_rp,$checkfc);
                            foreach(
$fcs_sub as $fc_sub)
                                {
                                
$queue->enqueue($fc_sub);
                                }
                            }
                        }
                    }
                }
            }
        
        if(
count($includerefs) == 0)
            {
            
// Misconfiguration - user can only see specific FCs but none have been selected
            
return false;
            }
        }

    
$return = array();
    foreach(
$all_fcs_rp as $fc => $fcp)
        {
        if(
in_array($fc$includerefs) && !in_array($fc,$excluderefs))
            {
            
$return[] = $fc;
            }
        }
        
    
$CACHE_FC_ACCESS_CONTROL $return;
    return 
$return;
    }

This article was last updated 25th January 2021 10:35 Europe/London time based on the source file dated 19th January 2021 16:15 Europe/London time.