Ejemplo n.º 1
0
function smarty_block_t($params, $text, &$smarty)
{
    $text = stripslashes($text);
    if (isset($params['escape'])) {
        $escape = $params['escape'];
        unset($params['escape']);
    }
    if (isset($params['plural'])) {
        $plural = $params['plural'];
        unset($params['plural']);
        if (isset($params['count'])) {
            $count = $params['count'];
            unset($params['count']);
        }
    }
    if (isset($count) && isset($plural)) {
        $text = CoreLoader::locale(CoreLoader::$system['language'])->ngettext($text, $plural, $count);
    } else {
        $text = CoreLoader::locale(CoreLoader::$system['language'])->gettext($text);
    }
    if (count($params)) {
        $text = strarg($text, $params);
    }
    if (!isset($escape) || $escape == 'html') {
        $text = nl2br(htmlspecialchars($text));
    } elseif (isset($escape) && ($escape == 'javascript' || $escape == 'js')) {
        $text = str_replace('\'', '\\\'', stripslashes($text));
    }
    return $text;
}
Ejemplo n.º 2
0
/**
 * Smarty block function, provides gettext support for smarty.
 *
 * The block content is the text that should be translated.
 *
 * Any parameter that is sent to the function will be represented as %n in the translation text,
 * where n is 1 for the first parameter. The following parameters are reserved:
 *       - escape - sets escape mode:
 *           - 'html' for HTML escaping, this is the default.
 *           - 'js' for javascript escaping.
 *           - 'no'/'off'/0 - turns off escaping
 *       - plural - The plural version of the text (2nd parameter of ngettext())
 *       - count - The item count for plural mode (3rd parameter of ngettext())
 */
function smarty_block_t($params, $text, &$smarty)
{
    $text = stripslashes($text);
    // set escape mode
    if (isset($params['escape'])) {
        $escape = $params['escape'];
        unset($params['escape']);
    }
    // set plural version
    if (isset($params['plural'])) {
        $plural = $params['plural'];
        unset($params['plural']);
        // set count
        if (isset($params['count'])) {
            $count = $params['count'];
            unset($params['count']);
        }
    }
    // use plural if required parameters are set
    if (isset($count) && isset($plural)) {
        $text = CoreLoader::locale(CoreLoader::$system['language'])->ngettext($text, $plural, $count);
    } else {
        // use normal
        $text = CoreLoader::locale(CoreLoader::$system['language'])->gettext($text);
    }
    // run strarg if there are parameters
    if (count($params)) {
        $text = strarg($text, $params);
    }
    if (!isset($escape) || $escape == 'html') {
        // html escape, default
        $text = nl2br(htmlspecialchars($text));
    } elseif (isset($escape) && ($escape == 'javascript' || $escape == 'js')) {
        // javascript escape
        $text = str_replace('\'', '\\\'', stripslashes($text));
    }
    return $text;
}