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

override_rs_variables_by_eval()

Description

Run PHP code on array of variables. Used for modifying $GLOBALS.

This ensures we only revert config to its original state for the same origin of the override.
For example, if applying resource type specific config, don't revert config changed at the user group level.
This also prevents unexpected changes of config whilst pages are being loaded.

Parameters

ColumnTypeDefaultDescription
$variables array Array of variables to apply override on.
$code string Signed string containing the PHP code to run.
$override_for string Context in which override is being made. Generally this will be 'usergroup' or 'resource_type' config overrides.

Return

void

Location

include/config_functions.php lines 1448 to 1501

Definition

 
function override_rs_variables_by_eval(array $variablesstring $codestring $override_for)
    {
    global 
$configs_overwritten;
    
// Remove all previous overwrides that have been set
    
if(is_array($configs_overwritten) && isset($configs_overwritten[$override_for]) && count($configs_overwritten[$override_for]) != 0)
        {
        
// We're processing config override for the same origin e.g. user group or resource type. Previously these were changed so revert them.
        
foreach($configs_overwritten[$override_for] as $option => $value)
            {
            if (
$value === 'UNSET_override_rs_variables_by_eval')
                {
                unset(
$GLOBALS[$option]);
                unset(
$variables[$option]);
                }
            else
                {
                
$variables[$option] = $value;
                }
            }
        }

    
$temp_variables $variables;

    
// Copy keys to a new array to prevent loss of original values.
    // This is a temporary solution for PHP versions 7.4 and 8.0 where eval() is applied to the keys in both %$temp_variables and $variables;
    
foreach ($variables as $variable => $var_val)
        {
        
$original['copy_' $variable] = $var_val;
        }

    
extract($temp_variablesEXTR_REFS EXTR_SKIP);
    eval(
eval_check_signed($code)); 

    
$temp_array = [];
    foreach(
$temp_variables as $temp_variable_name => $temp_variable_val)
        {
        if(!isset(
$original['copy_' $temp_variable_name]))
            {
            
$original['copy_' $temp_variable_name] = null;
            }

        if(
$original['copy_' $temp_variable_name] !== $temp_variable_val)
            {
            
$temp_array[$temp_variable_name] = $original['copy_' $temp_variable_name];
            if (
$original['copy_' $temp_variable_name] === null)
                {
                
$temp_array[$temp_variable_name] = 'UNSET_override_rs_variables_by_eval';
                }
            }
        
$GLOBALS[$temp_variable_name] = $temp_variable_val;
        }

    
$configs_overwritten[$override_for] = $temp_array;
    }

This article was last updated 11th December 2024 20:35 Europe/London time based on the source file dated 11th December 2024 15:55 Europe/London time.