Completed
Push — development ( 1b87d2...43bb99 )
by Thomas
06:02
created

htdocs/src/OcLegacy/SmartyPlugins/block.t.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/***************************************************************************
3
 * You can find the license in the docs directory *
4
 *
5
 *  For more information about this smarty-extension see
6
 *  prefilter.t.php
7
 *
8
 *  This extension probably is OBSOLETE: {t} blocks are handled by
9
 *  prefilter.t.php when precompiling the templates via clear-webcache.php.
10
 *  smarty_block_t() probably never gets called.
11
 ***************************************************************************
12
 * Replaces arguments in a string with their values.
13
 * Arguments are represented by % followed by their number.
14
 *
15
 * @param    string    Source string
16
 * @param    mixed    Arguments, can be passed in an array or through single variables.
17
 *
18
 * @returns    string    Modified string
19
 */
20
/**
21
 * @param $str
22
 * @return string
23
 */
24
function smarty_gettext_strarg($str)
25
{
26
    $tr = [];
27
    $p = 0;
28
    $funcNumArgs = func_num_args();
29
    for ($i = 1; $i < $funcNumArgs; $i++) {
30
        $arg = func_get_arg($i);
31
32
        if (is_array($arg)) {
33
            foreach ($arg as $aarg) {
34
                $tr['%' . ++ $p] = $aarg;
35
            }
36
        } else {
37
            $tr['%' . ++ $p] = $arg;
38
        }
39
    }
40
41
    return strtr($str, $tr);
42
}
43
44
/**
45
 * Smarty block function, provides gettext support for smarty.
46
 *
47
 * The block content is the text that should be translated.
48
 *
49
 * Any parameter that is sent to the function will be represented as %n in the translation text,
50
 * where n is 1 for the first parameter. The following parameters are reserved:
51
 *   - escape - Valid is "js" to escape a string for usage inside JS string
52
 *   - plural - The plural version of the text (2nd parameter of ngettext())
53
 *   - count - The item count for plural mode (3rd parameter of ngettext())
54
 * @param mixed $params
55
 * @param mixed $text
56
 * @param & $smarty
0 ignored issues
show
The doc-type & could not be parsed: Unknown type name "&" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
57
 * @param & $repeat
0 ignored issues
show
The doc-type & could not be parsed: Unknown type name "&" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
58
 */
59
function smarty_block_t($params, $text, &$smarty, &$repeat)
60
{
61
    if ($repeat) {
62
        return;
63
    }
64
65
    $escape = isset($params['escape']) ? $params['escape'] : '';
66
    unset($params['escape']);
67
68
    // use plural if required parameters are set
69
    if (isset($params['count']) && isset($params['plural']) && $params['count'] != 1) {
70
        $text = $params['plural'];
71
    }
72
    unset($params['plural']);
73
    unset($params['count']);
74
75
    // run strarg if there are parameters
76
    if (count($params)) {
77
        $text = smarty_gettext_strarg($text, $params);
78
    }
79
80
    // escape the string, now
81
    // see also modifier.escpapejs.php
82
    if ($escape == 'js') {
83
        $text = str_replace('\\', '\\\\', $text);
84
        $text = str_replace('\'', '\\\'', $text);
85
        $text = str_replace('"', '&quot;', $text);
86
    }
87
88
    return $text;
89
}
90