示例#1
0
/**
 * Helper function to recursively process complex types
 * We support the following kind of variables here:
 * 1. constant values (like the ON/OFF switches): they are defined as constants mapping to numeric values
 * 2. simple arrays with the form: array( a, b, c, d )
 * 3. associative arrays with the form: array( a=>1, b=>2, c=>3, d=>4 )
 * 4. multi-dimensional arrays
 * commas and '=>' within strings are handled
 *
 * @param string  $p_value      Complex value to process.
 * @param boolean $p_trim_quotes Whether to trim quotes.
 * @return parsed variable
 */
function process_complex_value($p_value, $p_trim_quotes = false)
{
    static $s_regex_array = null;
    static $s_regex_string = null;
    static $s_regex_element = null;
    $t_value = trim($p_value);
    # Parsing regex initialization
    if (is_null($s_regex_array)) {
        $s_regex_array = '^array[\\s]*\\((.*)\\)[;]*$';
        $s_regex_string = '[\\w]+' . '|' . "'(?:[^'\\\\]|\\\\.)*'" . '|' . '"(?:[^"\\\\]|\\\\.)*"';
        # The following complex regex will parse individual array elements,
        # taking into consideration sub-arrays, associative arrays and single,
        # double and un-quoted strings
        # @TODO dregad reverse pattern logic for sub-array to avoid match on array(xxx)=>array(xxx)
        $s_regex_element = '(' . '(' . '(?:(?iU:array\\s*(?:\\((?:(?>[^()]+)|(?1))*\\))))' . '|' . $s_regex_string . ')' . '(?:\\s*=>\\s*(?2))?' . ')';
    }
    if (preg_match('/' . $s_regex_array . '/s', $t_value, $t_match) === 1) {
        # It's an array - process each element
        $t_processed = array();
        if (preg_match_all('/' . $s_regex_element . '/', $t_match[1], $t_elements)) {
            foreach ($t_elements[0] as $t_key => $t_element) {
                if (!trim($t_element)) {
                    # Empty element - skip it
                    continue;
                }
                # Check if element is associative array
                preg_match_all('/(' . $s_regex_string . ')\\s*=>\\s*(.*)/', $t_element, $t_split);
                if (!empty($t_split[0])) {
                    # associative array
                    $t_new_key = constant_replace(trim($t_split[1][0], " \t\n\r\v\"'"));
                    $t_new_value = process_complex_value($t_split[2][0], true);
                    $t_processed[$t_new_key] = $t_new_value;
                } else {
                    # regular array
                    $t_new_value = process_complex_value($t_element);
                    $t_processed[$t_key] = $t_new_value;
                }
            }
        }
        return $t_processed;
    } else {
        # Scalar value
        $t_value = trim($t_value, " \t\n\r\v");
        if (is_numeric($t_value)) {
            return (int) $t_value;
        }
        # if has quotation marks
        if (strpos($t_value, "'") !== false || strpos($t_value, '"') !== false) {
            if ($p_trim_quotes) {
                $t_value = trim($t_value, "\"'");
            }
        } else {
            # Only replace constants when no quotation marks exist
            $t_value = constant_replace($t_value);
        }
        return $t_value;
    }
}
<?php

auth_reauthenticate();
access_ensure_global_level(config_get('manage_plugin_threshold'));
plugin_require_api('core/config_api.php');
$f_gpc = array('mail_add_bug_reports' => gpc_get_int('mail_add_bug_reports'), 'mail_add_bugnotes' => gpc_get_int('mail_add_bugnotes'), 'mail_add_complete_email' => gpc_get_int('mail_add_complete_email'), 'mail_add_users_from_cc_to' => gpc_get_int('mail_add_users_from_cc_to'), 'mail_auto_signup' => gpc_get_int('mail_auto_signup'), 'mail_block_attachments_md5' => array_map('strtolower', array_filter(array_map('trim', explode("\n", str_replace(array("\r\n", "\r"), "\n", gpc_get_string('mail_block_attachments_md5')))))), 'mail_block_attachments_logging' => gpc_get_int('mail_block_attachments_logging'), 'mail_debug' => gpc_get_int('mail_debug'), 'mail_debug_directory' => ERP_prepare_directory_string(gpc_get_string('mail_debug_directory')), 'mail_debug_show_memory_usage' => gpc_get_int('mail_debug_show_memory_usage'), 'mail_delete' => gpc_get_int('mail_delete'), 'mail_disposable_email_checker' => gpc_get_int('mail_disposable_email_checker'), 'mail_email_receive_own' => gpc_get_int('mail_email_receive_own'), 'mail_fallback_mail_reporter' => gpc_get_int('mail_fallback_mail_reporter'), 'mail_nodescription' => gpc_get_string('mail_nodescription'), 'mail_nosubject' => gpc_get_string('mail_nosubject'), 'mail_parse_html' => gpc_get_int('mail_parse_html'), 'mail_preferred_username' => gpc_get_string('mail_preferred_username'), 'mail_preferred_realname' => gpc_get_string('mail_preferred_realname'), 'mail_remove_mantis_email' => gpc_get_int('mail_remove_mantis_email'), 'mail_remove_replies' => gpc_get_int('mail_remove_replies'), 'mail_strip_gmail_style_replies' => gpc_get_int('mail_strip_gmail_style_replies'), 'mail_remove_replies_after' => gpc_get_string('mail_remove_replies_after'), 'mail_removed_reply_text' => gpc_get_string('mail_removed_reply_text'), 'mail_reporter_id' => gpc_get_int('mail_reporter_id'), 'mail_rule_system' => gpc_get_int('mail_rule_system'), 'mail_save_from' => gpc_get_int('mail_save_from'), 'mail_save_subject_in_note' => gpc_get_int('mail_save_subject_in_note'), 'mail_secured_script' => gpc_get_int('mail_secured_script'), 'mail_strip_signature' => gpc_get_int('mail_strip_signature'), 'mail_strip_signature_delim' => gpc_get_string('mail_strip_signature_delim'), 'mail_subject_id_regex' => gpc_get_string('mail_subject_id_regex'), 'mail_use_bug_priority' => gpc_get_int('mail_use_bug_priority'), 'mail_use_message_id' => gpc_get_int('mail_use_message_id'), 'mail_use_reporter' => gpc_get_int('mail_use_reporter'));
$f_mail_bug_priority = 'array (' . "\n" . gpc_get_string('mail_bug_priority') . "\n" . ')';
foreach ($f_gpc as $t_key => $t_value) {
    if (plugin_config_get($t_key) !== $t_value) {
        plugin_config_set($t_key, $t_value);
    }
}
$t_mail_bug_priority = process_complex_value($f_mail_bug_priority);
if (is_array($t_mail_bug_priority)) {
    if (plugin_config_get('mail_bug_priority') !== $t_mail_bug_priority) {
        plugin_config_set('mail_bug_priority', $t_mail_bug_priority);
    }
} else {
    html_page_top(plugin_lang_get('plugin_title'));
    echo '<br /><div class="center">';
    echo plugin_lang_get('mail_bug_priority_array_failure') . ' ';
    print_bracket_link(plugin_page('manage_config', TRUE), lang_get('proceed'));
    echo '</div>';
    $t_notsuccesfull = TRUE;
    html_page_bottom(__FILE__);
}
if (!isset($t_notsuccesfull)) {
    print_successful_redirect(plugin_page('manage_config', TRUE));
}