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

compile_collection_actions()

Description

Helper function for render_actions(). Compiles actions that are normally valid for collections

Parameters

ColumnTypeDefaultDescription
$collection_data array Collection data
$top_actions boolean Set to true if actions are to be rendered in the search filter bar (above results)
$resource_data array array Resource data

Return

array

Location

include/collections_functions.php lines 4000 to 4555

Definition

 
function compile_collection_actions(array $collection_data$top_actions$resource_data=array())
    {
    global 
$baseurl_short$lang$k$userrequestmode$zipcommand$collection_download$use_zip_extension$archiver_path,
           
$manage_collections_share_link$allow_share$enable_collection_copy,
           
$manage_collections_remove_link$userref$collection_purge$result,
           
$order_by$sort$archive$contact_sheet_link_on_collection_bar,
           
$show_searchitemsdiskusage$emptycollection$count_result,
           
$download_usage$home_dash$top_nav_upload_type$pagename$offset$col_order_by$find$default_sort,
           
$default_collection_sort$restricted_share$hidden_collections$internal_share_access$search,
           
$usercollection$disable_geocoding$collection_download_settings$contact_sheet$pagename,$upload_then_edit$enable_related_resources,$list$enable_themes,
           
$system_read_only;
               
    
#This is to properly render the actions drop down in the themes page    
    
if ( isset($collection_data['ref']) && $pagename!="collections" )
        {
        if(!
is_array($result))
            {
            
$result get_collection_resources_with_data($collection_data['ref']);
            }

        if((
'' == $k || $internal_share_access) && is_null($list))
            {
            
$list get_user_collections($userref);
            }

        
$count_result count($result);
        }
    
    if(isset(
$search) && substr($search011) == '!collection' && ($k == '' || $internal_share_access))
        { 
        
# Extract the collection number - this bit of code might be useful as a function
        
$search_collection explode(' '$search);
        
$search_collection str_replace('!collection'''$search_collection[0]);
        
$search_collection explode(','$search_collection); // just get the number
        
$search_collection $search_collection[0];
        }

    
// Collection bar actions should always be a special search !collection[ID] (exceptions might arise but most of the 
    // time it should be handled using the special search). If top actions then search may include additional refinement inside the collection

    
if(isset($collection_data['ref']) && !$top_actions)
        {
        
$search "!collection{$collection_data['ref']}";
        }

    
$urlparams = array(
        
"search"      =>  $search,
        
"collection"  =>  (isset($collection_data['ref']) ? $collection_data['ref'] : ""),
        
"ref"         =>  (isset($collection_data['ref']) ? $collection_data['ref'] : ""),
        
"restypes"    =>  isset($_COOKIE['restypes']) ? $_COOKIE['restypes'] : "",
        
"order_by"    =>  $order_by,
        
"col_order_by"=>  $col_order_by,
        
"sort"        =>  $sort,
        
"offset"      =>  $offset,
        
"find"        =>  $find,
        
"k"           =>  $k);
    
    
$options = array();
    
$o=0;

    if(empty(
$collection_data))
        {
        return 
$options;
        }
    
    if(empty(
$order_by))
        {
        
$order_by $default_collection_sort;
        }

    
// Check minimum access if we have all the data (i.e. not padded for search display), if not then render anyway and access will be checked on target page
    
$lastresource end($resource_data);
    if(
$pagename == 'collection_manage'
        {
        
$min_access collection_min_access($collection_data['ref']);
        }
    elseif(isset(
$lastresource["ref"]))
        {
        
$min_access collection_min_access($resource_data);
        }
    else
        {
        
$min_access 0;
        }

    
// View all resources
    
if(
        !
$top_actions // View all resources makes sense only from collection bar context
        
&& (
            (
$k=="" || $internal_share_access)
            && (isset(
$collection_data["c"]) && $collection_data["c"] > 0)
            || (
is_array($result) && count($result) > 0)
        )
    )
        {
        
$tempurlparams = array(
            
'sort' => 'ASC',
            
'search' => (isset($collection_data['ref']) ? "!collection{$collection_data['ref']}$search),
        );

        
$data_attribute['url'] = generateURL($baseurl_short "pages/search.php",$urlparams,$tempurlparams);
        
$options[$o]['value']='view_all_resources_in_collection';
        
$options[$o]['label']=$lang['view_all_resources'];
        
$options[$o]['data_attr']=$data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_RESOURCE;
        
$options[$o]['order_by'] = 10;
        
$o++;
        }
    
    
// Download option
    
if($min_access == )
        {
        if( 
$download_usage && ( isset($zipcommand) || $use_zip_extension || ( isset($archiver_path) && isset($collection_download_settings) ) ) && $collection_download && $count_result 0)
            {
            
$download_url generateURL($baseurl_short "pages/download_usage.php",$urlparams);
            
$data_attribute['url'] = generateURL($baseurl_short "pages/terms.php",$urlparams,array("url"=>$download_url));
            
$options[$o]['value']='download_collection';
            
$options[$o]['label']=$lang['action-download'];
            
$options[$o]['data_attr']=$data_attribute;
            
$options[$o]['category'] = ACTIONGROUP_RESOURCE;
            
$options[$o]['order_by'] = 20;
            
$o++;
            }
        elseif( (isset(
$zipcommand) || $use_zip_extension || ( isset($archiver_path) && isset($collection_download_settings) ) ) && $collection_download && $count_result 0)
            {
            
$download_url generateURL($baseurl_short "pages/collection_download.php",$urlparams);
            
$data_attribute['url'] = generateURL($baseurl_short "pages/terms.php",$urlparams,array("url"=>$download_url));
            
$options[$o]['value']='download_collection';
            
$options[$o]['label']=$lang['action-download'];
            
$options[$o]['data_attr']=$data_attribute;
            
$options[$o]['category'] = ACTIONGROUP_RESOURCE;
            
$options[$o]['order_by'] = 20;
            
$o++;
            }
        }

    
// Upload to collection
    
if(allow_upload_to_collection($collection_data))
        {
        if(
$upload_then_edit)
            {
            
$data_attribute['url'] = generateURL($baseurl_short "pages/upload_batch.php",array(),array("collection_add"=>$collection_data['ref']));
            }
        else
            {
            
$data_attribute['url'] = generateURL($baseurl_short "pages/edit.php",array(),array("uploader"=>$top_nav_upload_type,"ref"=>-$userref"collection_add"=>$collection_data['ref']));
            }

        
$options[$o]['value']='upload_collection';
        
$options[$o]['label']=$lang['action-upload-to-collection'];
        
$options[$o]['data_attr']=$data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_RESOURCE;
        
$options[$o]['order_by'] = 30;
        
$o++;
        }
    
     
// Remove all resources from collection
     
if(!checkperm("b") && $count_result && ($k=="" || $internal_share_access) && isset($emptycollection) && !$system_read_only && collection_writeable($collection_data['ref']))
     {
     
$data_attribute['url'] = generateURL($baseurl_short "pages/collections.php",$urlparams,array("emptycollection"=>$collection_data['ref'],"removeall"=>"true","ajax"=>"true","submitted"=>"removeall"));
     
$options[$o]['value']     = 'empty_collection';
     
$options[$o]['label']     = $lang['emptycollection'];
     
$options[$o]['data_attr'] = $data_attribute;
    
$options[$o]['category']  = ACTIONGROUP_RESOURCE;
    
$options[$o]['order_by'] = 50;
     
$o++;
     }
 
    if(!
collection_is_research_request($collection_data['ref']) || !checkperm('r'))
        {
        if (
            !
$top_actions && checkperm('s'
            && 
$pagename === 'collections'
            
&& isset($collection_data['request_feedback']) 
            && 
$collection_data['request_feedback']
            ) {
            
// Collection feedback
                
$data_attribute['url'] = sprintf('%spages/collection_feedback.php?collection=%s&k=%s',
                    
$baseurl_short,
                    
urlencode($collection_data['ref']),
                    
urlencode($k)
                );
                
$options[$o]['value']='collection_feedback';
                
$options[$o]['label']=$lang['sendfeedback'];
                
$options[$o]['data_attr']=$data_attribute;
                
$options[$o]['category'] = ACTIONGROUP_RESOURCE;
                
$options[$o]['order_by'] = 70;
                
$o++;
            }
        }
    else
        {
        
$research ps_value('SELECT ref value FROM research_request WHERE collection=?', array("i",$collection_data['ref']),0);

        
// Manage research requests
        
$data_attribute['url'] = generateURL($baseurl_short "pages/team/team_research.php",$urlparams);
        
$options[$o]['value']='manage_research_requests';
        
$options[$o]['label']=$lang['manageresearchrequests'];
        
$options[$o]['data_attr']=$data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_RESEARCH;
        
$options[$o]['order_by'] = 80;
        
$o++;

        
// Edit research requests
        
$data_attribute['url'] = generateURL($baseurl_short "pages/team/team_research_edit.php",$urlparams,array("ref"=>$research));
        
$options[$o]['value']='edit_research_requests';
        
$options[$o]['label']=$lang['editresearchrequests'];
        
$options[$o]['data_attr']=$data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_RESEARCH;
        
$options[$o]['order_by'] = 90;
        
$o++;
        }

    
// Select collection option - not for collection bar
    
if($pagename != 'collections' && ($k == '' || $internal_share_access) && !checkperm('b')
        && (
$pagename == 'load_actions' || $pagename == 'themes' || $pagename === 'collection_manage' || $pagename === 'resource_collection_list' || $top_actions)
        && ((isset(
$search_collection) && isset($usercollection) && $search_collection != $usercollection) || !isset($search_collection))
        && 
collection_readable($collection_data['ref'])
    )
        {
        
$options[$o]['value'] = 'select_collection';
        
$options[$o]['label'] = $lang['selectcollection'];
        
$options[$o]['category'] = ACTIONGROUP_COLLECTION;
        
$options[$o]['order_by'] = 100;
        
$o++;
        }

    
// Copy resources from another collection. Must be in top actions or have more than one collection available if on collections.php
    
if(
        !
checkperm('b')
        && (
$k == '' || $internal_share_access)
        && 
collection_readable($collection_data['ref'])
        && (
$top_actions || (is_array($list) && count($list) > 1))
        && 
$enable_collection_copy
    
)
        {
        
$data_attribute['url'] = generateURL($baseurl_short "pages/collection_copy_resources.php",array("ref"=>$collection_data['ref']));
        
$options[$o]['data_attr'] = $data_attribute;
        
$options[$o]['value'] = 'copy_collection';
        
$options[$o]['label'] = $lang['copyfromcollection'];
        
$options[$o]['category'] = ACTIONGROUP_RESOURCE;
        
$options[$o]['order_by'] = 105;
        
$o++;
        }

    
// Edit Collection
    
if((($userref == $collection_data['user'] && !in_array($collection_data['type'],[COLLECTION_TYPE_REQUEST,COLLECTION_TYPE_SELECTION])) || (checkperm('h')))  && ($k == '' || $internal_share_access) && !$system_read_only
        {
        
$data_attribute['url'] = generateURL($baseurl_short "pages/collection_edit.php",$urlparams);
        
$options[$o]['value']='edit_collection';
        
$options[$o]['label']=$lang['editcollection'];
        
$options[$o]['data_attr'] = $data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_EDIT;
        
$options[$o]['order_by'] = 110;
        
$o++;
        }
    
    if(isset(
$lastresource["ref"]))
        {
        
// Work this out based on resource data
        
$allow_multi_edit=allow_multi_edit($resource_data$collection_data['ref']);
        }
    else
        {
        
// Padded result set. It is too expensive to work this out every time for large result sets,
        // Show edit actions for logged in users and access will be checked once action has been selected.
        
$allow_multi_edit $k == "";
        }

    
// Edit all
    # If this collection is (fully) editable, then display an edit all link
    
if (
        ( 
$k=="" || $internal_share_access 
        && 
$count_result>0
        
&& $allow_multi_edit
        
) {
            
$extra_params = array(
                
'editsearchresults' => 'true',
            );

            
$data_attribute['url'] = generateURL($baseurl_short "pages/edit.php"$urlparams$extra_params);
            
$options[$o]['value']='edit_all_in_collection';
            
$options[$o]['label']=$lang['edit_all_resources'];
            
$options[$o]['data_attr']=$data_attribute;
            
$options[$o]['category'] = ACTIONGROUP_EDIT;
            
$options[$o]['order_by'] = 120;
            
$o++;
        }
    
    
    
// Edit Previews
    
if (($k=="" || $internal_share_access) && $count_result && !(checkperm('F*')) && ($userref == $collection_data['user'] || $collection_data['allow_changes'] == || checkperm('h')) && $allow_multi_edit)
        {
        
$main_pages   = array('search''collection_manage''collection_public''themes');
        
$back_to_page = (in_array($pagename$main_pages) ? escape($pagename) : '');
        
$data_attribute['url'] = generateURL($baseurl_short "pages/collection_edit_previews.php",$urlparams,array("backto"=>$back_to_page));
        
$options[$o]['value']     = 'edit_previews';
        
$options[$o]['label']     = $lang['editcollectionresources'];
        
$options[$o]['data_attr'] = $data_attribute;
        
$options[$o]['category']  = ACTIONGROUP_EDIT;
        
$options[$o]['order_by']  = 130;
        
$o++;
        }

    
// Share
    
if(allow_collection_share($collection_data))
        {
        
$data_attribute['url'] = generateURL($baseurl_short "pages/collection_share.php",$urlparams);
        
$options[$o]['value']='share_collection';
        
$options[$o]['label']=$lang['share'];
        
$options[$o]['data_attr']=$data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_SHARE;
        
$options[$o]['order_by']  = 140;
        
$o++;
        }

    
// Share external link to upload to collection, not permitted if already externally shared for view access
    
$eakeys get_external_shares(array("share_collection"=>$collection_data['ref'],"share_type"=>0));
    if(
can_share_upload_link($collection_data) && count($eakeys) == 0)
        {
        
$data_attribute['url'] = generateURL($baseurl_short "pages/share_upload.php",array(),array("share_collection"=>$collection_data['ref']));
        
$options[$o]['value']='share_upload';
        
$options[$o]['label']=$lang['action-share-upload-link'];
        
$options[$o]['data_attr']=$data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_SHARE;
        
$options[$o]['order_by'] = 30;
        
$o++;
        }
        
    
// Home_dash is on, AND NOT Anonymous use, AND (Dash tile user (NOT with a managed dash) || Dash Tile Admin)
    
if(!$top_actions && $home_dash && ($k == '' || $internal_share_access) && checkPermission_dashcreate() && !$system_read_only && !in_array($collection_data['type'],[COLLECTION_TYPE_REQUEST,COLLECTION_TYPE_SELECTION]))
        {
        
$is_smart_featured_collection = (isset($collection_data["smart"]) ? (bool) $collection_data["smart"] : false);
        
$is_featured_collection_category = (is_featured_collection_category($collection_data) || is_featured_collection_category_by_children($collection_data["ref"]));
        
$is_featured_collection = (!$is_featured_collection_category && !$is_smart_featured_collection);

        
$tileparams = array(
                
'create'            => 'true',
                
'tltype'            => 'srch',
                
'tlstyle'           => 'thmbs',
                
'promoted_resource' => 'true',
                
'freetext'          => 'true',
                
'all_users'         => '1',
                
'title'             => $collection_data["name"],
        );

        if(
$is_featured_collection)
            {
            
$tileparams['tltype'] = 'srch';
            
$tileparams['link']   = generateURL($baseurl_short 'pages/search.php',array('search' => '!collection' $collection_data['ref']));
            }
        else
            {
            
$tileparams['tltype'] = 'fcthm';
            
$tileparams['link']   = generateURL($baseurl_short 'pages/collections_featured.php',array('parent' => $collection_data['ref']));
            }
        
        
$data_attribute['url'] = generateURL($baseurl_short "pages/dash_tile.php",$urlparams,$tileparams);

        
$options[$o]['value']='save_collection_to_dash';
        
$options[$o]['label']=$lang['createnewdashtile'];
        
$options[$o]['data_attr']=$data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_SHARE;
        
$options[$o]['order_by']  = 150;
        
$o++;
        }

    
// Add option to publish as featured collection
    
if($enable_themes && ($k == '' || $internal_share_access) && checkperm("h") && !in_array($collection_data['type'],[COLLECTION_TYPE_REQUEST,COLLECTION_TYPE_SELECTION]))
        {
        
$data_attribute['url'] = generateURL($baseurl_short "pages/collection_set_category.php"$urlparams);
        
$options[$o]['value'] = 'collection_set_category';
        
$options[$o]['label'] = $lang['collection_set_theme_category'];
        
$options[$o]['data_attr'] = $data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_SHARE;
        
$options[$o]['order_by'] = 160;
        
$o++;
        }

    
// Request all
    
if($count_result && ($k == '' || $internal_share_access) && checkperm("q"))
        {
        
# Ability to request a whole collection 

        # This option should only be rendered if at least one of the resources is not downloadable

        
$data_attribute['url'] = generateURL($baseurl_short "pages/collection_request.php",$urlparams);
        
$options[$o]['value']='request_all';
        
$options[$o]['label']=$lang['requestall'];
        
$options[$o]['data_attr']=$data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_RESOURCE;
        
$options[$o]['order_by']  = 170;
        
$o++;
        }

    
// Contact Sheet
    
if($count_result && ($k=="" || $internal_share_access) && $contact_sheet == true && ($contact_sheet_link_on_collection_bar))
        {
        
$data_attribute['url'] = generateURL($baseurl_short "pages/contactsheet_settings.php",$urlparams);
        
$options[$o]['value']='contact_sheet';
        
$options[$o]['label']=$lang['contactsheet'];
        
$options[$o]['data_attr']=$data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_ADVANCED;
        
$options[$o]['order_by']  = 190;
        
$o++;
        }

    
// Remove
    
if(($k=="" || $internal_share_access)
        && 
$manage_collections_remove_link
        
&& $userref != $collection_data['user']
        && !
checkperm('b')
        && 
collection_readable($collection_data['ref'])
    )
        {
        
$options[$o]['value']='remove_collection';
        
$options[$o]['label']=$lang['action-remove'];
        
$options[$o]['category'] = ACTIONGROUP_COLLECTION;
        
$options[$o]['order_by']  = 200;
        
$o++;
        }

    
// Delete
    
if(($k=="" || $internal_share_access) && (($userref == $collection_data['user']) || checkperm('h')) && ($collection_data['cant_delete'] == 0) && $collection_data['type'] != COLLECTION_TYPE_REQUEST
        {
        
$options[$o]['value']='delete_collection';
        
$options[$o]['label']=$lang['action-deletecollection'];
        
$options[$o]['category'] = ACTIONGROUP_EDIT;
        
$options[$o]['order_by']  = 210;
        
$o++;
        }

    
// Collection Purge
    
if(($k=="" || $internal_share_access) && $collection_purge && isset($collections) && checkperm('e0') && $collection_data['cant_delete'] == 0)
        {
        
$options[$o]['value']='purge_collection';
        
$options[$o]['label']=$lang['purgeanddelete'];
        
$options[$o]['category'] = ACTIONGROUP_EDIT;
        
$options[$o]['order_by']  = 220;
        
$o++;
        }

    
// Collection log
    
if(($k=="" || $internal_share_access) && ($userref== $collection_data['user'] || (checkperm('h'))))
        {
        
$data_attribute['url'] = generateURL($baseurl_short "pages/collection_log.php",$urlparams);
        
$options[$o]['value']='collection_log';
        
$options[$o]['label']=$lang['action-log'];
        
$options[$o]['data_attr']=$data_attribute;
        
$options[$o]['category'] = ACTIONGROUP_ADVANCED;
        
$options[$o]['order_by']  = 230;
        
$o++;
        }
          
    
// Delete all
    // Note: functionality moved from edit collection page
    
if(($k=="" || $internal_share_access
        && !
$top_actions
        
&& ((is_array($result) && count($result) != 0) || $count_result != 0)
        && 
collection_writeable($collection_data['ref'])
        && 
$allow_multi_edit
        
&& !checkperm('D'))
        {
        
$options[$o]['value']='delete_all_in_collection';
        
$options[$o]['label']=$lang['deleteallresourcesfromcollection'];
        
$options[$o]['category'] = ACTIONGROUP_EDIT;
        
$options[$o]['order_by']  = 240;
        
$o++;
        }

    
// Show disk usage
    
if(($k=="" || $internal_share_access) && (checkperm('a') || checkperm('v')) && !$top_actions && $show_searchitemsdiskusage && $count_result
        {
        
$data_attribute['url'] = generateURL($baseurl_short "pages/search_disk_usage.php",$urlparams);
        
$options[$o]['value']='search_items_disk_usage';
        
$options[$o]['label']=$lang['collection_disk_usage'];
        
$options[$o]['data_attr'] = $data_attribute;
        
$options[$o]['category']  = ACTIONGROUP_ADVANCED;
        
$options[$o]['order_by']  = 250;
        
$o++;
        }

    
// CSV export of collection metadata
    
if($count_result 
        
&& !$top_actions
        
&& ($k =='' || $internal_share_access)
        && 
collection_readable($collection_data['ref'])
    )
        {
        
$options[$o]['value']            = 'csv_export_results_metadata';
        
$options[$o]['label']            = $lang['csvExportResultsMetadata'];
        
$data_attribute['url'] = generateURL($baseurl_short "pages/csv_export_results_metadata.php",$urlparams);
        
$options[$o]['data_attr'] = $data_attribute;
        
$options[$o]['category']  = ACTIONGROUP_ADVANCED;
        
$options[$o]['order_by']  = 260;
        
$o++;

        if(!
checkperm('b') && !$system_read_only)
            {
            
// Hide Collection
            
$user_mycollection=ps_value("select ref value from collection where user=? and name='Default Collection' order by ref limit 1",array("i",$userref),"");
            
// check that this collection is not hidden. use first in alphabetical order otherwise
            
if(in_array($user_mycollection,$hidden_collections)){
                
$sql="select ref value from collection where user=?";
                
$params=array("i",$userref);
                if (
count($hidden_collections)>0)
                    {
                    
$sql.=" and ref not in(" ps_param_insert(count($hidden_collections)) . ")";
                    
$params=array_merge($params,ps_param_fill($hidden_collections,"i"));
                    }
                
$user_mycollection=ps_value($sql " order by ref limit 1",$params,"");
            }
            
$extra_tag_attributes sprintf('
                    data-mycol="%s"
                '
,
                
urlencode($user_mycollection)
            );
            
            if (
$pagename != "load_actions")
                {
                
$options[$o]['value'] = 'hide_collection';
                
$options[$o]['label'] = $lang['hide_collection'];
                
$options[$o]['extra_tag_attributes']=$extra_tag_attributes
                
$options[$o]['category']  = ACTIONGROUP_ADVANCED;
                
$options[$o]['order_by']  = 270;
                
$o++;
                }
        }
        }
        
    
    
// Relate / Unrelate all resources
    
if($enable_related_resources && $allow_multi_edit && $count_result)
        {
        
$options[$o]['value'] = 'relate_all';
        
$options[$o]['label'] = $lang['relateallresources'];
        
$options[$o]['category']  = ACTIONGROUP_ADVANCED;
        
$options[$o]['order_by']  = 280;
        
$o++;

        
$options[$o]['value'] = 'unrelate_all';
        
$options[$o]['label'] = $lang['unrelateallresources'];
        
$options[$o]['category']  = ACTIONGROUP_ADVANCED;
        
$options[$o]['order_by']  = 290;
        
$o++;
        }

    
// Add extra collection actions and manipulate existing actions through plugins
    
$modified_options hook('render_actions_add_collection_option''', array($top_actions,$options,$collection_data$urlparams));
    if(
is_array($modified_options) && !empty($modified_options))
        {
        
$options=$modified_options;
        }

    return 
$options;
    }

This article was last updated 19th March 2024 03:05 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.