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

config_gen_setup_post()

Description

Generate the first half of the "guts" of a plugin setup page from a page definition array. This
function deals with processing the POST that comes (usually) as a result of clicking on the Save
Configuration button.

The page definition array is typically constructed by a series of calls to config_add_xxxx
functions (see below). See the setup page for the sample plugin for information on how to use
this and the associated functions.

If wishing to store array of values in one config option, in your setup page have something like the
following which adds a single definition for each key of your config option:
foreach($usergroups as $k => $group)
{
global $usergroupemails;
if(!isset($usergroupemails[$group["ref"]])){$usergroupemails[$group["ref"]]=array();} // Define any missing keys
$page_def[] = config_add_text_list_input("usergroupemails[".$group["ref"]."]",$group["name"]); //need to pass a string that looks like: "$configoption["key"]"
}
The key can consist of numbers, letters or an underscore contained within "" or ''. If using numbers you don't need the quote marks


each of which describes how one of the plugin's configuration variables.

Parameters

ColumnTypeDefaultDescription
$page_def
$plugin_name
mixed $page_def an array whose elements are generated by calls to config_add_xxxx functions
string $plugin_name the name of the plugin for which the function is being invoked.

Return

void|string Returns NULL

Location

include/plugin_functions.php lines 419 to 485

Definition

 
function config_gen_setup_post($page_def,$plugin_name)
    {
    if((
getval('submit''') != '' || getval('save','') != '') && enforcePostRequest(false))
        {
        
$config=array();
        foreach (
$page_def as $def)
            {
            
$array_offset="";
            if(
preg_match("/\[[\"|']?\w+[\"|']?\]/",$def[1],$array_offset))
                {
                
$array=preg_replace("/\[[\"|']?\w+[\"|']?\]/","",$def[1]);
                
preg_match("/[\"|']?\w+[\"|']?/",$array_offset[0],$array_offset);
                }
            
$omit false;
            if(!empty(
$array_offset))
                {
                
$curr_post=getval($array,"");
                if(
$curr_post==""){continue;} //Ignore if Array already handled or blank
                
foreach($curr_post as $key => $val)
                    {
                    
$config[$array][$key] = explode(','$val);
                    
$GLOBALS[$array][$key] = explode(','$val);
                    }
                unset(
$_POST[$array]); //Unset once array has been handled to prevent duplicate changes
                
$omit=true;
                }
            else
                {
                
$config_global=(isset($GLOBALS[$def[1]]) ? $GLOBALS[$def[1]] :false);
                switch (
$def[0])
                    {
                    case 
'html':
                    case 
'fixed_input':
                        
$omit true;
                        break;
                    case 
'section_header':
                        
$omit true;
                        break;
                    case 
'text_list':
                        
$pval getval($def[1],'');
                        
$GLOBALS[$def[1]] = (trim($pval) != '') ? explode(',',$pval) : array();
                        break;
                    case 
'hidden_param':
                        break;
                    default:
                        
$def1_is_array is_array($GLOBALS[$def[1]]);
                        
$GLOBALS[$def[1]] = getval(
                            
$def[1],
                            
$def1_is_array ? [] : '',
                            
false,
                            
$def1_is_array 'is_array' null
                        
);
                        break;
                    }

                
hook('custom_config_post''', array($def$config$omit$config_global));

                }
            if (!
$omit)
                {
                
$config[$def[1]]=$GLOBALS[$def[1]];
                }
            }
        
set_plugin_config($plugin_name,$config);
        if (
getval('submit','')!=''){redirect('pages/team/team_plugins.php');}
        }
    }

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 8th November 2024 11:50 Europe/London time.