Collections functions
Encryption functions
General functions
Theme permission functions
Resource 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

string containing a status message if the post was of an .rsc file.

Location

include/plugin_functions.php lines 496 to 559

Definition

 
function config_gen_setup_post($page_def,$plugin_name)
    {
    if (
getval('upload','')!='')
        {
        return 
handle_rsc_upload($plugin_name);
        }
    else 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':
                        
$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:
                        
$GLOBALS[$def[1]] = getval($def[1], is_array($GLOBALS[$def[1]])?array():'');
                        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 14th July 2020 05:05 Europe/London time based on the source file dated 2nd July 2020 09:08 Europe/London time.