Example #1
0
function lang_load($p_lang)
{
    global $g_lang_strings, $g_active_language;
    $g_active_language = $p_lang;
    if (isset($g_lang_strings[$p_lang])) {
        return;
    }
    if (!lang_language_exists($p_lang)) {
        return;
    }
    $t_lang_dir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR;
    require_once $t_lang_dir . 'strings_' . $p_lang . '.txt';
    # Allow overriding strings declared in the language file.
    # custom_strings_inc.php can use $g_active_language
    $t_custom_strings = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'custom_strings_inc.php';
    if (file_exists($t_custom_strings)) {
        require $t_custom_strings;
        # this may be loaded multiple times, once per language
    }
    $t_vars = get_defined_vars();
    foreach (array_keys($t_vars) as $t_var) {
        $t_lang_var = ereg_replace('^s_', '', $t_var);
        if ($t_lang_var != $t_var || 'MANTIS_ERROR' == $t_var) {
            $g_lang_strings[$p_lang][$t_lang_var] = ${$t_var};
        }
    }
}
Example #2
0
/**
 * Loads the specified language and stores it in $g_lang_strings, to be used by lang_get
 * @param string $p_lang
 * @param string $p_dir
 * @return null
 */
function lang_load($p_lang, $p_dir = null)
{
    global $g_lang_strings, $g_active_language;
    $g_active_language = $p_lang;
    if (isset($g_lang_strings[$p_lang]) && is_null($p_dir)) {
        return;
    }
    if (!lang_language_exists($p_lang)) {
        return;
    }
    if ($p_dir === null) {
        include_once config_get('language_path') . 'strings_' . $p_lang . '.txt';
    } else {
        if (is_file($p_dir . 'strings_' . $p_lang . '.txt')) {
            include_once $p_dir . 'strings_' . $p_lang . '.txt';
        }
    }
    # Allow overriding strings declared in the language file.
    # custom_strings_inc.php can use $g_active_language
    $t_custom_strings = config_get('absolute_path') . 'custom_strings_inc.php';
    if (file_exists($t_custom_strings)) {
        require $t_custom_strings;
        # this may be loaded multiple times, once per language
    }
    if (isset($s_messages)) {
        if (isset($g_lang_strings[$p_lang])) {
            $g_lang_strings[$p_lang] = array_merge((array) $g_lang_strings[$p_lang], (array) $s_messages);
        } else {
            $g_lang_strings[$p_lang] = $s_messages;
        }
    }
    if (!isset($s_messages) || file_exists($t_custom_strings)) {
        $t_vars = get_defined_vars();
        foreach (array_keys($t_vars) as $t_var) {
            $t_lang_var = preg_replace('/^s_/', '', $t_var);
            if ($t_lang_var != $t_var) {
                $g_lang_strings[$p_lang][$t_lang_var] = ${$t_var};
            } else {
                if ('MANTIS_ERROR' == $t_var) {
                    if (isset($g_lang_strings[$p_lang][$t_lang_var])) {
                        foreach (${$t_var} as $key => $val) {
                            $g_lang_strings[$p_lang][$t_lang_var][$key] = $val;
                        }
                    } else {
                        $g_lang_strings[$p_lang][$t_lang_var] = ${$t_var};
                    }
                }
            }
        }
    }
}
Example #3
0
/**
 * Loads the specified language and stores it in $g_lang_strings, to be used by lang_get
 * @param string $p_lang Name of Language to load.
 * @param string $p_dir  Directory Containing language file.
 * @return void
 */
function lang_load($p_lang, $p_dir = null)
{
    global $g_lang_strings, $g_active_language;
    $g_active_language = $p_lang;
    if (isset($g_lang_strings[$p_lang]) && is_null($p_dir)) {
        return;
    }
    if (!lang_language_exists($p_lang)) {
        return;
    }
    if ($p_dir === null) {
        include_once config_get('language_path') . 'strings_' . $p_lang . '.txt';
    } else {
        if (is_file($p_dir . 'strings_' . $p_lang . '.txt')) {
            include_once $p_dir . 'strings_' . $p_lang . '.txt';
        }
    }
    # Allow overriding strings declared in the language file.
    # custom_strings_inc.php can use $g_active_language.
    # Include file multiple times to allow for overrides per language.
    global $g_config_path;
    if (file_exists($g_config_path . 'custom_strings_inc.php')) {
        include $g_config_path . 'custom_strings_inc.php';
    }
    $t_vars = get_defined_vars();
    foreach (array_keys($t_vars) as $t_var) {
        $t_lang_var = preg_replace('/^s_/', '', $t_var);
        if ($t_lang_var != $t_var) {
            $g_lang_strings[$p_lang][$t_lang_var] = ${$t_var};
        } else {
            if ('MANTIS_ERROR' == $t_var) {
                if (isset($g_lang_strings[$p_lang][$t_lang_var])) {
                    foreach (${$t_var} as $t_key => $t_val) {
                        $g_lang_strings[$p_lang][$t_lang_var][$t_key] = $t_val;
                    }
                } else {
                    $g_lang_strings[$p_lang][$t_lang_var] = ${$t_var};
                }
            }
        }
    }
}
Example #4
0
/**
 * returns user language
 * @param int $p_user_id
 * @param int $p_project_id
 * @return string language name or null if invalid language specified
 */
function user_pref_get_language( $p_user_id, $p_project_id = ALL_PROJECTS ) {
	$t_prefs = user_pref_get( $p_user_id, $p_project_id );

	// ensure the language is a valid one
	$t_lang = $t_prefs->language;
	if( !lang_language_exists( $t_lang ) ) {
		$t_lang = null;
	}
	return $t_lang;
}
# TODO: split this functionality into manage_user_prefs_update.php
if (auth_get_current_user_id() != $f_user_id) {
    access_ensure_global_level(config_get('manage_user_threshold'));
    access_ensure_global_level($t_user['access_level']);
} else {
    # Protected users should not be able to update the preferences of their
    # user account. The anonymous user is always considered a protected
    # user and hence will also not be allowed to update preferences.
    user_ensure_unprotected($f_user_id);
}
$t_prefs = user_pref_get($f_user_id);
$t_prefs->redirect_delay = gpc_get_int('redirect_delay');
$t_prefs->refresh_delay = gpc_get_int('refresh_delay');
$t_prefs->default_project = gpc_get_int('default_project');
$t_lang = gpc_get_string('language');
if (lang_language_exists($t_lang)) {
    $t_prefs->language = $t_lang;
}
$t_prefs->email_on_new = gpc_get_bool('email_on_new');
$t_prefs->email_on_assigned = gpc_get_bool('email_on_assigned');
$t_prefs->email_on_feedback = gpc_get_bool('email_on_feedback');
$t_prefs->email_on_resolved = gpc_get_bool('email_on_resolved');
$t_prefs->email_on_closed = gpc_get_bool('email_on_closed');
$t_prefs->email_on_reopened = gpc_get_bool('email_on_reopened');
$t_prefs->email_on_bugnote = gpc_get_bool('email_on_bugnote');
$t_prefs->email_on_status = gpc_get_bool('email_on_status');
$t_prefs->email_on_priority = gpc_get_bool('email_on_priority');
$t_prefs->email_on_new_min_severity = gpc_get_int('email_on_new_min_severity');
$t_prefs->email_on_assigned_min_severity = gpc_get_int('email_on_assigned_min_severity');
$t_prefs->email_on_feedback_min_severity = gpc_get_int('email_on_feedback_min_severity');
$t_prefs->email_on_resolved_min_severity = gpc_get_int('email_on_resolved_min_severity');
Example #6
0
/**
 * Loads the specified language and stores it in $g_lang_strings, to be used by lang_get
 * @param string $p_lang
 * @param string $p_dir
 * @return null
 */
function lang_load($p_lang, $p_dir = null)
{
    global $g_lang_strings, $g_active_language;
    $g_active_language = $p_lang;
    if (isset($g_lang_strings[$p_lang]) && is_null($p_dir)) {
        return;
    }
    if (!lang_language_exists($p_lang)) {
        return;
    }
    // Step 1 - Load Requested Language file
    // @@ and if file doesn't exist???
    if ($p_dir === null) {
        include_once config_get('language_path') . 'strings_' . $p_lang . '.txt';
    } else {
        if (is_file($p_dir . 'strings_' . $p_lang . '.txt')) {
            include_once $p_dir . 'strings_' . $p_lang . '.txt';
        }
    }
    // Step 2 - Allow overriding strings declared in the language file.
    //          custom_strings_inc.php can use $g_active_language
    // 2 formats:
    // $s_* - old format
    // $s_custom_strings array - new format
    // NOTE: it's not expected that you'd mix/merge old/new formats within this file.
    $t_custom_strings = config_get('custom_strings_file');
    if (file_exists($t_custom_strings)) {
        # this may be loaded multiple times, once per language
        require $t_custom_strings;
    }
    // Step 3  - New Language file format
    // Language file consists of an array
    if (isset($s_messages)) {
        // lang strings array entry can only be set if $p_dir is not null - i.e. in a plugin
        if (isset($g_lang_strings[$p_lang])) {
            if (isset($s_custom_messages[$p_lang])) {
                // Step 4 - handle merging in custom strings:
                // Possible states:
                // 4.a - new string format + new custom string format
                $g_lang_strings[$p_lang] = array_replace((array) $g_lang_strings[$p_lang], (array) $s_messages, (array) $s_custom_messages[$p_lang]);
                return;
            } else {
                $g_lang_strings[$p_lang] = array_replace((array) $g_lang_strings[$p_lang], (array) $s_messages);
            }
        } else {
            // new language loaded
            $g_lang_strings[$p_lang] = $s_messages;
            if (isset($s_custom_messages[$p_lang])) {
                // 4.a - new string format + new custom string format
                $g_lang_strings[$p_lang] = array_replace((array) $g_lang_strings[$p_lang], (array) $s_custom_messages[$p_lang]);
                return;
            }
        }
    }
    // 4.b new string format + old custom string format
    // 4.c - old string format + old custom string format
    if (!isset($s_messages) || file_exists($t_custom_strings)) {
        $t_vars = get_defined_vars();
        foreach (array_keys($t_vars) as $t_var) {
            $t_lang_var = preg_replace('/^s_/', '', $t_var);
            if ($t_lang_var != $t_var) {
                $g_lang_strings[$p_lang][$t_lang_var] = ${$t_var};
            } else {
                if ('MANTIS_ERROR' == $t_var) {
                    if (isset($g_lang_strings[$p_lang][$t_lang_var])) {
                        foreach (${$t_var} as $key => $val) {
                            $g_lang_strings[$p_lang][$t_lang_var][$key] = $val;
                        }
                    } else {
                        $g_lang_strings[$p_lang][$t_lang_var] = ${$t_var};
                    }
                }
            }
        }
        // 4.d old string format + new custom string format
        // merge new custom strings into array in same way we merge in 4.a
        if (isset($s_custom_messages[$p_lang])) {
            $g_lang_strings[$p_lang] = array_replace((array) $g_lang_strings[$p_lang], (array) $s_custom_messages[$p_lang]);
        }
    }
}