Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

render_upload_here_button()

Description

Render "Upload here" button.

This applies to search results that are either a special search "!collection" and/or consist of purely the following:
- Nodes
- Resource type
- Workflow (archive) state

For free text searches this SHOULD NOT work!

Parameters

ColumnTypeDefaultDescription
$search_params array
$return_params_only boolean false Exception to the rule! Rather than render, return the upload here params

Return

void|array

Location

include/render_functions.php lines 3098 to 3213

Definition

 
function render_upload_here_button(array $search_params$return_params_only false)
    {
    if(!(
checkperm('c') || checkperm('d')))
        {
        return;
        }

    if(!isset(
$search_params['search']) || !isset($search_params['restypes']) || !isset($search_params['archive']))
        {
        return;
        }

    if(
        isset(
$search_params['search'])
        && (
            
mb_substr($search_params['search'], 011) != '!collection'
            
&& empty(resolve_nodes_from_string($search_params['search']))
        )
    )
        {
        return;
        }

    
$upload_here_params = array();

    
$upload_endpoint 'pages/upload_batch.php';
    if(!
$GLOBALS['upload_then_edit'])
        {
        
$upload_endpoint 'pages/edit.php';
        
$upload_here_params['ref'] = $GLOBALS['userref'];
        
$upload_here_params['uploader'] = $GLOBALS['top_nav_upload_type'];
        }

    
$upload_here_params['upload_here'] = true;
    
$upload_here_params['search'] = $search_params['search'];

    
// Special search !collection
    
if(mb_substr($search_params['search'], 011) == '!collection')
        {
        
$collection explode(' '$search_params['search']);
        
$collection str_replace('!collection'''$collection[0]);
        
$collection explode(','$collection);
        
$collection = (int) $collection[0];

        
//Check the user is able to upload to this collection before continuing
        
if(!collection_writeable($collection)) {return;}

        
$upload_here_params['collection_add'] = $collection;
        }

    if (isset(
$search_params['advsearch']) && $search_params['advsearch'] == 'true')
        {
        
$upload_here_params['advsearch'] = 'true';
        }

    
// If resource types is a list then always select the first resource type the user has access to
    
$resource_types explode(','$search_params['restypes']);
    foreach(
$resource_types as $resource_type)
        {
        if(!
checkperm("XU{$resource_type}"))
            {
            
$upload_here_params['resource_type'] = $resource_type;
            break;
            }
        }

    
// Archive can be a list (e.g from advanced search) so always select the first archive state user access to, 
    // favouring the Active one
    
$search_archive explode(','$search_params['archive']);
    
$use_default false;

    if (
count($search_archive) == && $search_archive[0] == "")
        {
        
$search_archive = array();
        
$use_default true;
        }

    
// Check access to Active state
    
if(in_array(0$search_archive) && checkperm("e0"))
        {
        
$upload_here_params['status'] = 0;
        
$search_archive = array();
        }
    
// Check remaining states
    
foreach($search_archive as $archive)
        {
        if(
$archive == '' || !is_numeric($archive))
            {
            continue;
            }

        if(
checkperm("e{$archive}"))
            {
            
$upload_here_params['status'] = $archive;
            
$search_archive = array();
            break;
            }
        }

    if (
count($search_archive) != || $use_default)
        {
        
// None of the supplied archive states were accessible with e permission so use default.
        
$upload_here_params['status'] = get_default_archive_state();
        }

    
// Option to return out just the upload params
    
if ($return_params_only)
        {
        return 
$upload_here_params;
        }
        
    
$upload_here_url generateURL("{$GLOBALS['baseurl']}/{$upload_endpoint}"$upload_here_params);
    
$attributes "onclick=\"CentralSpaceLoad('{$upload_here_url}');\"";

    
render_filter_bar_button($GLOBALS['lang']['upload_here'], $attributesUPLOAD_ICON);
    }

This article was last updated 22nd May 2024 15:35 Europe/London time based on the source file dated 17th May 2024 16:45 Europe/London time.