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

render_actions()

Description

Renders search actions functionality as a dropdown box

Parameters

ColumnTypeDefaultDescription
$collection_data array Collection data
$top_actions boolean true Set to true if actions are to be rendered in the search filter bar (above results)
$two_line boolean true Display on two lines
$id string '' Selector HTML ID
$resource_data array array Resource data
$optionsonly boolean false Render only options
$forpage string "" Specifically target for which page actions apply

Return

void

Location

include/render_functions.php lines 849 to 1260

Definition

 
function render_actions(array $collection_data$top_actions true$two_line true$id '',$resource_data=array(),$optionsonly=false$forpage="")
    {
    if(
hook('prevent_running_render_actions'))
        {
        return;
        }

    global 
$baseurl$lang$k$pagename$order_by$sort$chosen_dropdowns$allow_resource_deletion;
    
    
// globals that could also be passed as a reference
    
global $result /*search result*/;

    
$action_selection_id = ($forpage!=""?$forpage:$pagename) . '_action_selection' $id;
    if(!
$top_actions)
        {
        
$action_selection_id .= '_bottom';
        }
    if(isset(
$collection_data['ref']))
        {
        
$action_selection_id .= '_' str_replace("-","_",$collection_data['ref']);
        }
        
        
    if(!
$optionsonly)
            {
?>
    
            <div class="ActionsContainer   if($top_actions) { echo 'InpageNavLeftBlock'; } ?>">
                
        
                
if($two_line)
                    {
                    
?>
                    <br />
                    
                    
}
                    
?>
                <select onchange="action_onchange_ echo $action_selection_id?>(this.value);" id=" echo $action_selection_id?> if(!$top_actions) { echo 'class="SearchWidth"'; } ?>>
             ?>
            <option class="SelectAction" selected disabled hidden value=""> echo $lang["actions-select"]?></option>
            

            
// Collection Actions
            
$collection_actions_array compile_collection_actions($collection_data$top_actions$resource_data);

            
// Usual search actions
            
$search_actions_array compile_search_actions($top_actions);

            
// Remove certain actions that apply only to searches
            
if(!$top_actions)
                {
                
$action_index_to_remove array_search('search_items_disk_usage'array_column($search_actions_array'value'));
                unset(
$search_actions_array[$action_index_to_remove]);
                
$search_actions_array array_values($search_actions_array);
                
                
$action_index_to_remove array_search('save_search_items_to_collection'array_column($search_actions_array'value'));
                unset(
$search_actions_array[$action_index_to_remove]);
                
$search_actions_array array_values($search_actions_array);

                if(
$forpage === "themes")
                    {
                    
$action_index_to_remove array_search('remove_collection'array_column($collection_actions_array'value'));
                    unset(
$collection_actions_array[$action_index_to_remove]);
                    
$collection_actions_array array_values($collection_actions_array);
                    }
                }
    
            
/**
            * @var A global variable that allows other parts in ResourceSpace to append extra options to the actions 
            * unified dropdown (plugins can use existing hooks).
            */
            
$render_actions_extra_options = array();
            if(
                isset(
$GLOBALS["render_actions_extra_options"])
                && 
is_array($GLOBALS["render_actions_extra_options"])
                && !empty(
$GLOBALS["render_actions_extra_options"]))
                {
                
$render_actions_extra_options $GLOBALS["render_actions_extra_options"];
                }

            
$actions_array array_merge($collection_actions_array$search_actions_array$render_actions_extra_options);
            unset(
$render_actions_extra_options);

            
$modify_actions_array hook('modify_unified_dropdown_actions_options''', array($actions_array,$top_actions));

            if(!empty(
$modify_actions_array))
                {
                
$actions_array $modify_actions_array;
                }

            
/**
            * @var A global variable that allows other parts in ResourceSpace to filter actions options (plugins can use 
            * existing hooks).
            */
            
if(isset($GLOBALS["render_actions_filter"]) && is_callable($GLOBALS["render_actions_filter"]))
                {
                
$actions_array array_filter($actions_array$GLOBALS["render_actions_filter"]);
                unset(
$GLOBALS["render_actions_filter"]);
                }

            
// Sort array into category groups
            
usort($actions_array, function($a$b){
               if(isset(
$a['category']) && isset($b['category']))
                    {
                    if(
$a['category'] == $b['category'])
                        {
                        
// Same category, check for order_by. If no order_by add to end of category
                        
if(isset($a['order_by']) && (!isset($b['order_by']) || ($b['order_by'] > $a['order_by'])))
                            {
                            return -
1;
                            }
                        return 
1;
                        }
                    else
                        {
                        return  
$a['category'] - $b['category'];
                        }
                    }
                else
                    {
                    return isset(
$a['category']) ? -1;
                    }
                });
                                    
            
// loop and display
            
$options='';
            
$lastcategory 0;
            for(
$a 0$a count($actions_array); $a++)
                {
                
// Is this a new category?
                
if(!isset($actions_array[$a]['category']))
                    {
                    
$actions_array[$a]['category'] = 999;  
                    }
                if(
$lastcategory != $actions_array[$a]['category'])
                    {
                    if(
$a 0)
                        {
                        
$options .= "</optgroup>\n";
                        }
                    
$options .= "<optgroup label='" htmlspecialchars($lang["collection_actiontype_" $actions_array[$a]['category']]) . "'>\n";
                    }

                if(!isset(
$actions_array[$a]['data_attr']))
                    {
                    
$actions_array[$a]['data_attr'] = array();
                    }

                if(!isset(
$actions_array[$a]['extra_tag_attributes']))
                    {
                    
$actions_array[$a]['extra_tag_attributes'] = '';
                    }

                
$options .= render_dropdown_option($actions_array[$a]['value'], $actions_array[$a]['label'], $actions_array[$a]['data_attr'], $actions_array[$a]['extra_tag_attributes']);

                
$add_to_options hook('after_render_dropdown_option''', array($actions_array$a));
                if(
$add_to_options != '')
                    {
                    
$options .= $add_to_options;
                    }
                if(
$a == count($actions_array))
                    {
                    
$options .= "\n</optgroup>\n";
                    }
                
$lastcategory $actions_array[$a]['category'];
                }

            echo 
$options;
            
            if(!
$optionsonly)
                { 
?>
                </select>
                 ?>
        <script>
        function action_onchange_ echo $action_selection_id?>(v)
            {
            if(v == '')
                {
                return false;
                }
            switch(v)
                {
            
            
if(!== count($collection_data) && collection_readable($collection_data['ref']))
                {
                
?>
                case 'select_collection':
                    ChangeCollection( echo $collection_data['ref']; ?>, '');
                    break;

                case 'remove_collection':
                    if(confirm(" echo $lang['removecollectionareyousure']; ?>")) {
                        // most likely will need to be done the same way as delete_collection
                        document.getElementById('collectionremove').value = ' echo urlencode($collection_data["ref"]); ?>';
                        document.getElementById('collectionform').submit();
                    }
                    break;

                case 'purge_collection':
                    if(confirm(' echo $lang["purgecollectionareyousure"]; ?>'))
                        {
                        document.getElementById('collectionpurge').value='".urlencode($collections[$n]["ref"])."';
                        document.getElementById('collectionform').submit();
                        }
                    break;

                case 'relate_all':
                    var collection =  echo urlencode($collection_data['ref']);?>;
                    jQuery.ajax({
                        type: 'POST',
                        url: baseurl_short + 'pages/ajax/relate_resources.php?collection=' + collection,
                        data: { echo generateAjaxToken("relate_resources"); ?>},
                        success: function(data) {
                            if (data.trim() == "SUCCESS") {
                                styledalert(' echo $lang["complete"]?>', ' echo $lang['relateallresources_confirmation']?>');
                            }
                        },
                        error: function (err) {
                            console.log("AJAX error : " + JSON.stringify(err, null, 2));
                        }
                    }); 
                    break;
                
                
}

            if(!
$top_actions || !empty($collection_data))
                {
                global 
$search;
                
$search_collection='';
                if(
substr($search,0,11)=='!collection')
                    {
                    
$search_trimmed substr($search,11); // The collection search must always be the first part of the search string
                    
$search_elements split_keywords($search_trimmedfalsefalsefalsefalsetrue);
                    
$search_collection = (int)$search_elements[0];
                    }
                
?>
                case 'delete_collection':
                    if(confirm(' echo $lang["collectiondeleteconfirm"]; ?>')) {
                        var post_data = {
                            ajax: true,
                            dropdown_actions: true,
                            delete:  echo urlencode($collection_data['ref']); ?>,
                             echo generateAjaxToken("delete_collection"); ?>
                        };

                        jQuery.post(' echo $baseurl?>/pages/collection_manage.php', post_data, function(response) {
                            if(response.success === 'Yes')
                                {
                                CollectionDivLoad(' echo $baseurl?>/pages/collections.php?collection=' + response.redirect_to_collection + '&k=' + response.k + '&nc=' + response.nc);

                                if(basename(document.URL).substr(0, 17) === 'collection_manage')
                                    {
                                    CentralSpaceLoad(document.URL);
                                    }
                                else if(basename(document.URL).substr(0, 6) === 'search' && ' echo $search_collection?>'==' echo $collection_data["ref"]?>')
                                    {
                                    CentralSpaceLoad(' echo $baseurl?>/pages/search.php?search=!collection' + response.redirect_to_collection, true);
                                    }
                                }
                        }, 'json');    
                    }
                    break;
                
                
}

            
// Add extra collection actions javascript case through plugins
            // Note: if you are just going to a different page, it should be easily picked&n