/**
 * Gets the currently selected language. Either from the browser, or the personal configuration, or the global configuration.
 *
 * This function also sets HTTP Headers and cookies to contain the language for follow-up requests
 * TODO:
 * This previously was handled inside a plugin with an event hook, but caching
 * the event plugins that early in sequence created trouble with plugins not
 * having loaded the right language.
 * Find a way to let plugins hook into that sequence :-)
 *
 * @access public
 * @return  string      Returns the name of the selected language.
 */
function serendipity_getSessionLanguage()
{
    global $serendipity;
    // DISABLE THIS!
    /*
        if ($_SESSION['serendipityAuthedUser']) {
            serendipity_header('X-Serendipity-InterfaceLangSource: Database');
            return $serendipity['lang'];
        }
    */
    if (isset($serendipity['lang']) && !isset($serendipity['languages'][$serendipity['lang']])) {
        $serendipity['lang'] = $serendipity['autolang'];
    }
    if (isset($_REQUEST['user_language']) && !empty($serendipity['languages'][$_REQUEST['user_language']]) && !headers_sent()) {
        serendipity_setCookie('serendipityLanguage', $_REQUEST['user_language'], false);
    }
    if (isset($serendipity['COOKIE']['serendipityLanguage'])) {
        if ($serendipity['expose_s9y']) {
            serendipity_header('X-Serendipity-InterfaceLangSource: Cookie');
        }
        $lang = $serendipity['COOKIE']['serendipityLanguage'];
    } elseif (isset($serendipity['GET']['lang_selected']) && !empty($serendipity['languages'][$serendipity['GET']['lang_selected']])) {
        if ($serendipity['expose_s9y']) {
            serendipity_header('X-Serendipity-InterfaceLangSource: GET');
        }
        $lang = $serendipity['GET']['lang_selected'];
    } elseif (serendipity_db_bool($serendipity['lang_content_negotiation'])) {
        if ($serendipity['expose_s9y']) {
            serendipity_header('X-Serendipity-InterfaceLangSource: Content-Negotiation');
        }
        $lang = serendipity_detectLang();
    }
    if (isset($lang)) {
        $serendipity['detected_lang'] = $lang;
    } else {
        if (!empty($_SESSION['serendipityLanguage'])) {
            $lang = $_SESSION['serendipityLanguage'];
        } else {
            if (isset($serendipity['COOKIE']['userDefLang']) && !empty($serendipity['COOKIE']['userDefLang'])) {
                $lang = $serendipity['COOKIE']['userDefLang'];
            } else {
                $lang = $serendipity['lang'];
            }
        }
        $serendipity['detected_lang'] = null;
    }
    if (!isset($serendipity['languages'][$lang])) {
        $serendipity['detected_lang'] = null;
        return $serendipity['lang'];
    } else {
        $_SESSION['serendipityLanguage'] = $lang;
        if (!is_null($serendipity['detected_lang'])) {
            if ($serendipity['expose_s9y']) {
                serendipity_header('X-Serendipity-InterfaceLang: ' . $lang);
            }
        }
    }
    return $lang;
}
Beispiel #2
0
            @(include S9Y_INCLUDE_PATH . 'templates/' . $serendipity['template'] . '/' . $charset . 'lang_' . $serendipity['lang'] . '.inc.php');
            @(include S9Y_INCLUDE_PATH . 'templates/' . $serendipity['template'] . '/lang_en.inc.php');
        }
    }
    // Try and include preferred language from the configurated setting
    if (@(include S9Y_INCLUDE_PATH . 'lang/' . $charset . 'serendipity_lang_' . $serendipity['lang'] . '.inc.php')) {
        // Only here can we truely say the language is loaded
        define('serendipity_LANG_LOADED', true);
        if (function_exists('serendipity_db_reconnect')) {
            serendipity_db_reconnect();
        }
    } elseif (IS_installed === false || defined('IS_up2date') && IS_up2date === false) {
        /* -- Auto-Guess -- */
        // If no config file is loaded, language includes are not available.
        // Now include one. Try to auto-guess the language by looking up the HTTP_ACCEPT_LANGUAGE.
        serendipity_detectLang(true);
    }
    //endif
    // Do fallback to english
    if (IS_installed === false || defined('IS_up2date') && IS_up2date === false) {
        @(include S9Y_INCLUDE_PATH . 'lang/' . $charset . 'serendipity_lang_en.inc.php');
    }
}
if (!defined('serendipity_MB_LOADED') && defined('serendipity_LANG_LOADED')) {
    // Needs to be included here because we need access to constant LANG_CHARSET definied in languages (not available for compat.inc.php)
    if (function_exists('mb_language')) {
        @mb_language($serendipity['lang']);
    }
    if (function_exists('mb_internal_encoding')) {
        @mb_internal_encoding(LANG_CHARSET);
    }