示例#1
0
function translate($txt)
{
    if (is_array($txt)) {
        $args = $txt;
    } else {
        $args = func_get_args();
    }
    $txt = array_shift($args);
    // Test if constant exists (constant without space)
    if (!defined($txt) && find($txt, " ") == 0) {
        if (!($key = getConstantName($txt))) {
            // auto create constant in translation files
            create_label_translation($txt);
        }
    }
    // Encode data
    $array_lang_convert_html = array('ru');
    if ($GLOBALS['__AJAX_LOAD_PAGE__'] == true && !in_array($_GET['l'], $array_lang_convert_html) && (find($_GET['mime'], "xml") > 0 || find($_GET['mime'], "rss") > 0)) {
        $txt = utf8decode($txt);
    } else {
        $txt = utf8encode($txt);
    }
    // convert %s by args
    for ($i = 0; $i < sizeof($args); $i++) {
        if ($GLOBALS['__AJAX_LOAD_PAGE__'] == true && !in_array($_GET['l'], $array_lang_convert_html) && (find($_GET['mime'], "xml") > 0 || find($_GET['mime'], "rss") > 0)) {
            $txt = preg_replace('/%s/', utf8decode($args[$i]), $txt, 1);
        } else {
            $txt = preg_replace('/%s/', utf8encode($args[$i]), $txt, 1);
        }
    }
    if ($GLOBALS['__AJAX_LOAD_PAGE__'] == true && in_array($_GET['l'], $array_lang_convert_html) && (find($_GET['mime'], "xml") > 0 || find($_GET['mime'], "rss") > 0)) {
        $txt = convert_utf8_to_html($txt);
    }
    return $txt;
}
示例#2
0
/**
 * Decodifica os valores de um array ou objeto de UTF-8
 * @param	mixed	$data	dados a serem decodificados
 * @return	mixed			retorna um objeto ou array sem a codificação UTF-8
 */
function utf8decode($data)
{
    if (is_string($data)) {
        return utf8_decode($data);
    }
    if (is_array($data)) {
        $encoded = array();
        foreach ($data as $k => $d) {
            $encoded[$k] = utf8decode($d);
        }
        return $encoded;
    }
    if (is_object($data)) {
        $encoded = new stdClass();
        foreach ($data as $k => $d) {
            $encoded->{$k} = utf8decode($d);
        }
        return $encoded;
    }
    return $data;
}
示例#3
0
 /**
  * Método de descriptografia
  * @param	string	$value		valor criptografado
  * @param	string	$key		chave utilizada para criptogradar
  * @return	mixed				retorna o valor descriptogradado
  */
 public static function decrypt($value, $key)
 {
     return utf8decode(json_decode(self::crypt(base64_decode($value), $key)));
 }