Ejemplo n.º 1
0
/**
 * Call this function only after we have successfully logged in.
 * Updates user status etc.
 */
function handle_post_login()
{
    global $messages;
    if (!isset($messages)) {
        // we might be in auto-login, create a temporary message field anyway
        $messages = array();
    }
    $user = get_user(user_id());
    // display warning if account was disabled
    if ($user['is_disabled']) {
        $messages[] = t("Your account was disabled :ago due to inactivity; your account is now re-enabled, and account data will be updated again soon.", array(':ago' => recent_format($user['disabled_at'])));
        $q = db()->prepare("UPDATE user_properties SET is_disabled=0,logins_after_disabled=logins_after_disabled+1 WHERE id=?");
        $q->execute(array($user['id']));
    }
    // keep track of users that logged in after receiving a warning
    if ($user['is_disable_warned']) {
        $q = db()->prepare("UPDATE user_properties SET is_disable_warned=0,logins_after_disable_warned=logins_after_disable_warned+1 WHERE id=?");
        $q->execute(array($user['id']));
    }
    // update locale
    if ($user['locale']) {
        I18n::setLocale($user['locale']);
    }
    // update login time
    $query = db()->prepare("UPDATE user_properties SET last_login=NOW(),is_disabled=0 WHERE id=?");
    $query->execute(array($user["id"]));
    // if we don't have an IP set, update it now
    if (!$user["user_ip"]) {
        $q = db()->prepare("UPDATE user_properties SET user_ip=? WHERE id=?");
        $q->execute(array(user_ip(), $user['id']));
    }
}
Ejemplo n.º 2
0
<?php

/**
 * Set the current session, cookie or user language.
 */
use Openclerk\I18n;
$locale = require_post("locale");
$redirect = require_post("redirect");
$available = I18n::getAvailableLocales();
if (!isset($available[$locale])) {
    throw new LocaleException("Locale '{$locale}' does not exist for user selection");
}
I18n::setLocale($locale);
// update cookies
setcookie('locale', $locale, time() + 60 * 60 * 24 * 365 * 10);
// update users
if (user_logged_in()) {
    $user = get_user(user_id());
    $q = db()->prepare("UPDATE user_properties SET locale=? WHERE id=?");
    $q->execute(array($locale, user_id()));
}
// go back to their previous page
redirect($redirect);
Ejemplo n.º 3
0
    {
        return $this->title;
    }
    function load()
    {
        require __DIR__ . "/../locale/" . $this->key . ".php";
        return $result;
    }
}
$locales = array('de' => 'German', 'fr' => 'French', 'jp' => 'Japanese', 'ru' => 'Russian', 'zh' => 'Chinese');
foreach ($locales as $locale => $title) {
    I18n::addAvailableLocale(new GenericLocale($locale, $title));
}
I18n::addDefaultKeys(array(':site_name' => get_site_config('site_name')));
// set locale as necessary
if (isset($_COOKIE["locale"]) && in_array($_COOKIE["locale"], array_keys(I18n::getAvailableLocales()))) {
    I18n::setLocale($_COOKIE["locale"]);
}
\Openclerk\Events::on('i18n_missing_string', function ($data) {
    $locale = $data['locale'];
    $key = $data['key'];
    log_uncaught_exception(new LocaleException("Locale '{$locale}': Missing key '{$key}'"));
});
/**
 * Helper function to mark strings that need to be translated on the client-side.
 */
function ct($s)
{
    // do not do any translation here - we have to do it on the client side!
    return $s;
}
Ejemplo n.º 4
0
 function tearDown()
 {
     I18n::setLocale(null);
     I18n::resetAvailableLocales();
 }