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

featured_collection_check_access_control()

Description

Access control function used to determine if a featured collection should be accessed by the user

Parameters

ColumnTypeDefaultDescription
$c_ref integer Collection ref to be tested

Return

boolean Returns TRUE if user should have access to the featured collection (no parent category prevents this), FALSE otherwise

Location

include/collections_functions.php lines 4764 to 4833

Definition

 
function featured_collection_check_access_control(int $c_ref)
    {
    if(
checkperm("-j" $c_ref))
        {
        return 
false;
        }
    elseif(
checkperm("j*") || checkperm("j" $c_ref))
        {
        return 
true;
        }
    else
        {        
        
// Get all parents. Query varies according to MySQL cte support
        
$mysql_version sql_query('SELECT LEFT(VERSION(), 3) AS ver');
        if(
version_compare($mysql_version[0]['ver'], '8.0''>=')) 
            {
            
$allparents sql_query("
                WITH RECURSIVE cte(ref,parent, level) AS
                        (
                        SELECT  ref,
                                parent,
                                1 AS level
                          FROM  collection
                         WHERE  ref= '" 
$c_ref "'
                     UNION ALL
                        SELECT  c.ref,
                                c.parent,
                                level+1 AS LEVEL
                          FROM  collection c
                    INNER JOIN  cte
                            ON  c.ref = cte.parent
                        )
                SELECT ref,
                       parent,
                       level
                  FROM cte
              ORDER BY level DESC;"
,
            
"featured_collections");
            }
        else
            {
            
$allparents sql_query("
                    SELECT  C2.ref, C2.parent
                    FROM  (SELECT @r AS p_ref,
                            (SELECT @r := parent FROM collection WHERE ref = p_ref) AS parent,
                            @l := @l + 1 AS lvl
                    FROM  (SELECT @r := '" 
$c_ref "', @l := 0) vars,
                            collection c
                    WHERE  @r <> 0) C1
                    JOIN  collection C2
                        ON  C1.p_ref = C2.ref
                ORDER BY  C1.lvl DESC"

                    
"featured_collections");
            }

          foreach(
$allparents as $parent)
                {
                if(
checkperm("-j" $parent["ref"]))
                    {
                    
// Denied access to parent
                    
return false;
                    }
                elseif(
checkperm("j" $parent["ref"]))
                    {
                    return 
true;
                    }
                }
        return 
false// No explicit permission given and user doesn't have f*
        
}
    }

This article was last updated 22nd April 2021 23:35 Europe/London time based on the source file dated 22nd April 2021 13:10 Europe/London time.