Example #1
0
function landing_page()
{
    $subpages = false;
    // kui page muutuja on tühi, siis avalehele
    if (!$_GET["page"]) {
        define("PAGE", LANDING_PAGE);
    } else {
        // keera sisend väikesteks tähtedeks ja eemalda võimalik slash muutuja lõpust
        evaluate_url();
        // kas on alamlehti?
        if (substr_count($_GET["page"], SLASH) > 0) {
            $subpages = explode(SLASH, $_GET["page"]);
            // kas esimesel kohal on põhilehe asemel hoopis keelevahetus?
            if (switch_language($subpages[0])) {
                define("FORCED_LANG", $subpages[0]);
                array_shift($subpages);
            }
            // esimesel kohal on alati põhileht
            define("PAGE", $subpages[0]);
        } else {
            // vaheta keel, kui see on ainuke parameeter
            switch_language($_GET["page"]);
            define("PAGE", $_GET["page"]);
        }
    }
    // kui url'is polnud keelt
    if (!defined("FORCED_LANG")) {
        define("FORCED_LANG", false);
    }
    return $subpages;
}
Example #2
0
// if not allowed, just ignore and return
if ($_CONF['allow_user_language'] == 1) {
    COM_setArgNames(array('lang'));
    $lang = strtolower(COM_applyFilter(COM_getArgument('lang')));
    $lang = preg_replace('/[^a-z0-9\\-_]/', '', $lang);
    $oldlang = COM_getLanguageId();
    // do we really have a new language to switch to?
    if (!empty($lang) && array_key_exists($lang, $_CONF['language_files'])) {
        // does such a language file exist?
        $langfile = $_CONF['language_files'][$lang];
        if (is_file($_CONF['path_language'] . $langfile . '.php')) {
            // Set the language cookie.
            // Mainly used for anonymous users so the rest of their session
            // will remain in the selected language
            setcookie($_CONF['cookie_language'], $langfile, time() + 31536000, $_CONF['cookie_path'], $_CONF['cookiedomain'], $_CONF['cookiesecure']);
            // if user is not anonymous, store the preference in the database
            if (!COM_isAnonUser()) {
                DB_query("UPDATE {$_TABLES['users']} SET language = '{$langfile}' WHERE uid = {$_USER['uid']}");
            }
        }
    }
    // Change the language ID if needed
    if (!empty($ret_url) && !empty($lang) && !empty($oldlang)) {
        $ret_url = switch_language($ret_url, $lang, $oldlang);
    }
}
// if the user didn't come from our site, send them to our index page
if (empty($ret_url)) {
    $ret_url = $_CONF['site_url'] . '/';
}
header("Location: {$ret_url}");