1) - key 'user' and int representing user ref to check user preferences
* array('usergroup' => 2) - key 'usergroup' and int representing usergroup ref to check user group preferences
* @param string $find Value from getval("find", "")
* @param string $only_modified Value from getval("only_modified", "no")
*/
function config_filter_by_search(array $page_def, array $config_type, string $find, string $only_modified): array
{
$only_modified = $only_modified == 'yes';
$searching = $find != "" || $only_modified;
if ($searching) {
// Check for search phrase in config. description.
if ($find !== '') {
$search_matches = array();
foreach ($page_def as $config_to_check) {
if (isset($config_to_check[2]) && stripos($config_to_check[2], $find) !== false) {
$search_matches[] = $config_to_check;
}
}
$page_def = $search_matches;
}
// Filter results to only config which has been changed previously i.e. exists in user_preferences with null in user column.
if ($only_modified) {
$search_matches = array();
$returned_options = array();
get_config_options($config_type, $returned_options);
$returned_options = array_column($returned_options, 'parameter');
foreach ($page_def as $config_to_check) {
if (isset($config_to_check[1]) && in_array($config_to_check[1], $returned_options)) {
$search_matches[] = $config_to_check;
}
}
$page_def = $search_matches;
}
}
return $page_def;
}
/**
* Remove user preferences by resetting to system preferences. Used to display system config or user group config
* without the current user's preferences changing the values.
*
* @param array $page_def Array containing page definition, from functions config_add_ ...
*/
function config_remove_user_preferences(array $page_def): void
{
global $system_wide_config_options;
// loop through every field about to be created
foreach ($page_def as $page_item) {
if (
$page_item[0] !== 'html'
&& isset($system_wide_config_options[$page_item[1]])
&& $GLOBALS[$page_item[1]] !== $system_wide_config_options[$page_item[1]]
) {
// Set the global variable back to the system value if it is different
$GLOBALS[$page_item[1]] = $system_wide_config_options[$page_item[1]];
}
}
}
/**
* Generate a percentage range input
*
* @param string $name The name of the configuration variable to be added.
* @param string $label The user text displayed to label the text block. Usually a $lang string.
* @param string $current The current value of the config variable being set.
* @param int $width The width of the input field in pixels. Default: 420.
* @param string $title The title attribute of the element
* @param string $help_link Help link to be displayed alongside the label.
*/
function config_percent_range($name, $label, $current, $width = 420, $title = null, $help_link = "")
{
global $lang;
if (is_null($title)) {
$title = str_replace('%cvn', $name, $lang['plugins-configvar']);
}
// Convert stored 0–1 value to percentage for display
$percent = round($current * 100);
$escaped_name = escape($name);
?>