|
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
|
|
|
function smarty_gettext_strarg($str) |
|
21
|
|
|
{ |
|
22
|
|
|
$tr = []; |
|
23
|
|
|
$p = 0; |
|
24
|
|
|
$funcNumArgs = func_num_args(); |
|
25
|
|
|
for ($i = 1; $i < $funcNumArgs; $i++) { |
|
26
|
|
|
$arg = func_get_arg($i); |
|
27
|
|
|
|
|
28
|
|
|
if (is_array($arg)) { |
|
29
|
|
|
foreach ($arg as $aarg) { |
|
30
|
|
|
$tr['%' . ++ $p] = $aarg; |
|
31
|
|
|
} |
|
32
|
|
|
} else { |
|
33
|
|
|
$tr['%' . ++ $p] = $arg; |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return strtr($str, $tr); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Smarty block function, provides gettext support for smarty. |
|
42
|
|
|
* |
|
43
|
|
|
* The block content is the text that should be translated. |
|
44
|
|
|
* |
|
45
|
|
|
* Any parameter that is sent to the function will be represented as %n in the translation text, |
|
46
|
|
|
* where n is 1 for the first parameter. The following parameters are reserved: |
|
47
|
|
|
* - escape - Valid is "js" to escape a string for usage inside JS string |
|
48
|
|
|
* - plural - The plural version of the text (2nd parameter of ngettext()) |
|
49
|
|
|
* - count - The item count for plural mode (3rd parameter of ngettext()) |
|
50
|
|
|
*/ |
|
51
|
|
|
function smarty_block_t($params, $text, &$smarty, &$repeat) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
if ($repeat) { |
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$escape = isset($params['escape']) ? $params['escape'] : ''; |
|
58
|
|
|
unset($params['escape']); |
|
59
|
|
|
|
|
60
|
|
|
// use plural if required parameters are set |
|
61
|
|
|
if (isset($params['count']) && isset($params['plural']) && $params['count'] != 1) { |
|
62
|
|
|
$text = $params['plural']; |
|
63
|
|
|
} |
|
64
|
|
|
unset($params['plural']); |
|
65
|
|
|
unset($params['count']); |
|
66
|
|
|
|
|
67
|
|
|
// run strarg if there are parameters |
|
68
|
|
|
if (count($params)) { |
|
69
|
|
|
$text = smarty_gettext_strarg($text, $params); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
// escape the string, now |
|
73
|
|
|
// see also modifier.escpapejs.php |
|
74
|
|
|
if ($escape == 'js') { |
|
75
|
|
|
$text = str_replace('\\', '\\\\', $text); |
|
76
|
|
|
$text = str_replace('\'', '\\\'', $text); |
|
77
|
|
|
$text = str_replace('"', '"', $text); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $text; |
|
81
|
|
|
} |
|
82
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.