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

get_external_shares()

Description

Get details of external shares

"share_group" - (int) Usergroup ref 'shared as'
"share_user" - (int) user ID of share creator
"share_order_by" - (string) order by column
"share_sort" - (string) sortorder (ASC or DESC)
"share_type" - (int) 0=view, 1=upload
"share_collection" - (int) Collection ID
"share_resource" - (int) Resource ID
"access_key" - (string) Access key
"ignore_permissions"- (bool) Show all shares, irrespective of permissions

Parameters

ColumnTypeDefaultDescription
$filteropts array Array of options to filter shares returned

Return

array

Location

include/resource_functions.php lines 9031 to 9133

Definition

 
function get_external_shares(array $filteropts)
    {
    global 
$userref;

    
$share_group $filteropts['share_group'] ?? null;
    
$share_user $filteropts['share_user'] ?? null;
    
$share_order_by $filteropts['share_order_by'] ?? null;
    
$share_sort $filteropts['share_sort'] ?? null;
    
$share_type $filteropts['share_type'] ?? null;
    
$share_collection $filteropts['share_collection'] ?? null;
    
$share_resource $filteropts['share_resource'] ?? null;
    
$access_key $filteropts['access_key'] ?? null;
    
$ignore_permissions $filteropts['ignore_permissions'] ?? null;

    
$valid_orderby = array("collection","user""sharedas""expires""date""email""lastused""access_key""upload");
    if(!
in_array($share_order_by$valid_orderby))
        {
        
$share_order_by "expires";
        }
    
$share_sort strtoupper((string) $share_sort) == "ASC" "ASC" "DESC";

    
$conditions = array(); $params = [];
    if((int)
$share_user && ($share_user == $userref || checkperm_user_edit($share_user))
        )
        {
        
$conditions[] = "eak.user = ?";
        
$params = ['i', (int)$share_user];
        }
    elseif(!
checkperm('a') && !$ignore_permissions)
        {
        
$usercondition "eak.user = ?";
        
$params array_merge($params, ['i', (int)$userref]);
        if(
checkperm("ex"))
            {
            
// Can also see shares that never expire
            
$usercondition " (expires IS NULL OR " $usercondition ")";
            }
        
$conditions[] =$usercondition;
        }

    if(!
is_null($share_group) && (int)$share_group 0  && checkperm('a'))
        {
        
$conditions[] = "eak.usergroup = ?";
        
$params array_merge($params, ['i', (int)$share_group]);
        }

    if(!
is_null($access_key))
        {
        
$conditions[] = "eak.access_key = ?";
        
$params array_merge($params, ['s'$access_key]);
        }

    if((int)
$share_type === 0)
        {
        
$conditions[] = "(eak.upload=0 OR eak.upload IS NULL)";
        }
    elseif((int)
$share_type === 1)
        {
        
$conditions[] = "eak.upload=1";
        }
    if(
is_int_loose($share_collection) && $share_collection != 0)
        {
        
$conditions[] = "eak.collection = ?";
        
$params array_merge($params, ['i', (int)$share_collection]);
        }
    if((int)
$share_resource 0)
        {
        
$conditions[] = "eak.resource = ?";
        
$params array_merge($params, ['i', (int)$share_resource]);
        }

    
$conditional_sql="";
    if (
count($conditions)>0){$conditional_sql=" WHERE " implode(" AND ",$conditions);}

    
$external_access_keys_query =
        
"SELECT access_key,
                ifnull(collection,'-') collection,
                CASE
                    WHEN collection IS NULL THEN resource
                    ELSE '-'
                END AS 'resource',
                user,
                eak.email,
                min(date) date,
                MAX(date) maxdate,
                max(lastused) lastused,
                eak.access,
                eak.expires,
                eak.usergroup,
                eak.password_hash,
                eak.upload,
                ug.name sharedas,
                u.fullname,
                u.username
           FROM external_access_keys eak
      LEFT JOIN user u ON u.ref=eak.user
      LEFT JOIN usergroup ug ON ug.ref=eak.usergroup " 
.
                
$conditional_sql .
     
" GROUP BY access_key, collection
       ORDER BY " 
$share_order_by " " $share_sort;

    return 
ps_query($external_access_keys_query$params);
    }

This article was last updated 4th December 2024 08:35 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.