Exemplo n.º 1
0
function lang_init()
{
    if (!lang_detect()) {
        throw new Exception('Could not initialise language.');
    }
    bindtextdomain('messages', BH_INCLUDE_PATH . 'locale/');
    textdomain('messages');
    bind_textdomain_codeset('messages', 'UTF-8');
}
Exemplo n.º 2
0
}
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
    $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
} else {
    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
        $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
    }
}
/**
 * Do the work!
 */
$lang = '';
// 1. try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE
// variable
if (empty($lang) && !empty($HTTP_ACCEPT_LANGUAGE)) {
    $accepted = explode(',', $HTTP_ACCEPT_LANGUAGE);
    $acceptedCnt = count($accepted);
    reset($accepted);
    for ($i = 0; $i < $acceptedCnt && empty($lang); $i++) {
        lang_detect($accepted[$i], 1);
    }
}
// 2. try to findout user's language by checking its HTTP_USER_AGENT variable
if (empty($lang) && !empty($HTTP_USER_AGENT)) {
    lang_detect($HTTP_USER_AGENT, 2);
}
// 3. If we catch a valid language, configure it
if (!empty($lang)) {
    $USER['lang'] = $available_languages[$lang][1];
}
// $__PMA_SELECT_LANG_LIB__
Exemplo n.º 3
0
/**
 *	function sends missed calls of user to given email address
 *	
 *	@param	string	$uid			
 *	@param	string	$email_address	
 *	@return	bool					TRUE on success, FALSE on error
 */
function send_mail_with_missed_calls($uid, $email_address, $mail_from)
{
    global $config, $data, $lang_set;
    /* get missed calls */
    if (false === ($missed_calls = $data->get_missed_calls_of_yesterday($uid, null))) {
        return false;
    }
    if (!count($missed_calls)) {
        return true;
    }
    //there are no missed calls - nothing to do
    /* check if imap extension is loaded */
    if (!function_exists('imap_mail_compose')) {
        ErrorHandler::add_errors("Can not send mail. IMAP extension for PHP is not installed.");
        return false;
    }
    /*
     *	Create table of missed calls
     */
    $table = '<html><body><table border="1" cellspacing="0" cellpadding="1">' . "\n";
    $table .= '<tr>';
    $table .= '<th>calling subscriber</th>';
    $table .= '<th>time</th>';
    $table .= '<th>reply status</th>';
    $table .= '</tr>' . "\n";
    foreach ($missed_calls as $row) {
        $table .= '<tr>';
        $table .= '<td>' . $row->from_uri . '&nbsp;</td>';
        $table .= '<td>' . $row->request_timestamp . '&nbsp;</td>';
        $table .= '<td>' . $row->sip_status . '&nbsp;</td>';
        $table .= '</tr>' . "\n";
    }
    $table .= '</table></body></html>' . "\n";
    /*
     *	Get language of user
     */
    if (false === ($lang = Attributes::get_attribute($config->attr_names['lang'], array("uid" => $uid)))) {
        return false;
    }
    $lang = lang_detect($lang, 3);
    //translate $lang to be a index into $available_languages array
    if (!$lang) {
        $lang = $config->default_lang;
    }
    /*
     *	Read file containing the mail body
     */
    $mail_file = multidomain_get_lang_file("mail_missed_calls.txt", "txt", $lang);
    $m = read_txt_file($mail_file, array());
    if ($m === false) {
        ErrorHandler::add_error("Can't read file with mail body.");
        return false;
    }
    /* get charset */
    $charset = null;
    if (isset($m['headers']['content-type']) and eregi("charset=([-a-z0-9]+)", $m['headers']['content-type'], $regs)) {
        $charset = $regs[1];
    }
    /* add information about charset to the header */
    if ($charset) {
        $m['headers']['subject'] = "=?" . $charset . "?Q?" . imap_8bit($m['headers']['subject']) . "?=";
    }
    /*
     *	Compose the mail message
     */
    if ($mail_from) {
        $envelope["from"] = $mail_from;
    } else {
        $envelope["from"] = $config->mail_header_from;
    }
    $envelope["to"] = $email_address;
    $part1["type"] = TYPEMULTIPART;
    $part1["subtype"] = "mixed";
    $part2["type"] = TYPETEXT;
    $part2["subtype"] = "plain";
    $part2["contents.data"] = $m['body'];
    if ($charset) {
        $part2["charset"] = $charset;
    }
    $part3["type"] = TYPETEXT;
    $part3["subtype"] = "html";
    $part3["contents.data"] = $table;
    $part3["charset"] = $lang_set['charset'];
    $body[1] = $part1;
    $body[2] = $part2;
    $body[3] = $part3;
    $mail = imap_mail_compose($envelope, $body);
    list($m_header, $m_body) = split("\r\n\r\n", $mail, 2);
    /*
     *	Send mail
     */
    if (!mail($email_address, $m['headers']['subject'], $m_body, $m_header)) {
        $errors[] = "can't send missed calls to " . $email_address;
    }
    return true;
}
Exemplo n.º 4
0
function determine_lang(){
    global $config, $data, $available_languages;
    $an = &$config->attr_names;
    $did = null;


    // Lang forced
    if (!empty($config->force_lang) && isset($available_languages[$config->force_lang])) {
        $_SESSION['lang'] = $config->force_lang;
    }

    
    // If session variable is set, obtain language from it
    if (isset($_SESSION['lang'])){
        if (isset($available_languages[$_SESSION['lang']])) return $_SESSION['lang'];
        else unset($_SESSION['lang']);
    }

    // Lang is not know yet
    // try to findout user's language by checking user attribute

    if (isset($_SESSION['auth']) and 
        is_a($_SESSION['auth'], 'Auth') and
        $_SESSION['auth']->is_authenticated()){

        $uid = $_SESSION['auth']->get_uid();
        $did = $_SESSION['auth']->get_did(); //for checking domain attribute later

        $attrs = &User_Attrs::singleton($uid);
        $lang = lang_detect($attrs->get_attribute($an['lang']), 3);
        if (false != $lang) return $lang;

    }
    

    // try to findout user's language by checking cookie

    if (!empty($_COOKIE['serweb_lang']) and isset($available_languages[$_COOKIE['serweb_lang']])){
        return $_COOKIE['serweb_lang'];
    }

    // try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE variable
    
    if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $accepted    = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
        $acceptedCnt = count($accepted);
        for ($i = 0; $i < $acceptedCnt; $i++) {
            $lang = lang_detect($accepted[$i], 1);
            if (false != $lang) return $lang;
        }
    }
    
    // try to findout user's language by checking its HTTP_USER_AGENT variable

    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
        $lang = lang_detect($_SERVER['HTTP_USER_AGENT'], 2);
        if (false != $lang) return $lang;
    }

    // try to findout user's language by checking domain or global attribute

    if (empty($config->do_not_set_lang_by_domain)){
        if (is_null($did)){ // if user is not authenticated yet
                            // get did of domain from http request
            $data->add_method('get_did_by_realm');
            $did = $data->get_did_by_realm($config->domain, null);
            if (false === $did) $did = null;
        }
    }
    else{
        $did = null;
    }

    $o = array();
    if (!is_null($did)) $o['did'] = $did;
    $lang = lang_detect(Attributes::get_attribute($an['lang'], $o), 3);
    if (false != $lang) return $lang;


    if (!is_null($lang) and isset($available_languages[$lang])) return $lang;


    // Didn't catch any valid lang : we use the default settings
    
    return $config->default_lang;

}
Exemplo n.º 5
0
if ($superCage->server->keyExists('HTTP_ACCEPT_LANGUAGE')) {
    //We can use the getRaw method here because the data will be sanitized in the lang_detect function
    $HTTP_ACCEPT_LANGUAGE = $superCage->server->getRaw('HTTP_ACCEPT_LANGUAGE');
}
if ($superCage->server->keyExists('HTTP_USER_AGENT')) {
    //We can use the getRaw method here because the data will be sanitized in the lang_detect function
    $HTTP_USER_AGENT = $superCage->server->getRaw('HTTP_USER_AGENT');
}
/**
 * Do the work!
 */
$lang = '';
// 1. try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE
// variable
if (empty($lang) && !empty($HTTP_ACCEPT_LANGUAGE)) {
    $accepted = explode(',', $HTTP_ACCEPT_LANGUAGE);
    $acceptedCnt = count($accepted);
    reset($accepted);
    for ($i = 0; $i < $acceptedCnt && empty($lang); $i++) {
        lang_detect($lang, $available_languages, $accepted[$i], 1);
    }
}
// 2. try to findout user's language by checking its HTTP_USER_AGENT variable
if (empty($lang) && !empty($HTTP_USER_AGENT)) {
    lang_detect($lang, $available_languages, $HTTP_USER_AGENT, 2);
}
// 3. If we catch a valid language, configure it
if (!empty($lang)) {
    $USER['lang'] = $available_languages[$lang][1];
}
// $__PMA_SELECT_LANG_LIB__