/** * 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. * * @param $page_def mixed an array whose elements are generated by calls to config_add_xxxx functions * each of which describes how one of the plugin's configuration variables. * @param $plugin_name string 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. */ function config_gen_setup_post($page_def,$plugin_name) { if (getval('upload','')!='') { return handle_rsc_upload($plugin_name); } elseif ((getval('submit','')!='') || (getval('save','')!='')) { $config=array(); foreach ($page_def as $def) { $omit = false; switch ($def[0]) { case 'section_header': $omit = true; break; case 'text_list': $GLOBALS[$def[1]] = explode(',', getval($def[1], '')); break; case 'hidden_param': break; default: $GLOBALS[$def[1]] = getval($def[1], is_array($GLOBALS[$def[1]])?array():''); break; } if (!$omit) { $config[$def[1]]=$GLOBALS[$def[1]]; } } set_plugin_config($plugin_name,$config); if (getval('submit','')!=''){redirect('pages/team/team_plugins.php');} } }
/** * 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 * * * @param $page_def mixed an array whose elements are generated by calls to config_add_xxxx functions * each of which describes how one of the plugin's configuration variables. * @param $plugin_name string 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. */ function config_gen_setup_post($page_def, $plugin_name) { if (getval('upload', '') != '') { return handle_rsc_upload($plugin_name); } elseif (getval('submit', '') != '' || getval('save', '') != '') { $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 { switch ($def[0]) { case 'html': $omit = true; break; case 'section_header': $omit = true; break; case 'text_list': $GLOBALS[$def[1]] = explode(',', getval($def[1], '')); break; case 'hidden_param': break; default: $GLOBALS[$def[1]] = getval($def[1], is_array($GLOBALS[$def[1]]) ? array() : ''); break; } } if (!$omit) { $config[$def[1]] = $GLOBALS[$def[1]]; } } set_plugin_config($plugin_name, $config); if (getval('submit', '') != '') { redirect('pages/team/team_plugins.php'); } } }