function _potx_find_log_calls in Translation template extractor 8
Same name and namespace in other branches
- 6.3 potx.inc \_potx_find_log_calls()
- 7.3 potx.inc \_potx_find_log_calls()
- 7.2 potx.inc \_potx_find_log_calls()
Detect all occurances of log() calls.
These sequences are searched for: log + "(" + ..anything (might be more tokens).. + "," + T_CONSTANT_ENCAPSED_STRING + whatever.
Parameters
string $file: Name of file parsed.
string $save_callback: Callback function used to save strings.
1 call to _potx_find_log_calls()
- _potx_parse_php_file in ./
potx.inc - Parse a PHP file for translatables.
File
- ./
potx.inc, line 1172 - Extraction API used by the web and command line interface.
Code
function _potx_find_log_calls($file, $save_callback) {
global $_potx_tokens, $_potx_lookup;
if (isset($_potx_lookup['log'])) {
foreach ($_potx_lookup['log'] as $ti) {
list($prev, $ctok, $par1) = [
$_potx_tokens[$ti - 1],
$_potx_tokens[$ti],
$_potx_tokens[$ti + 1],
];
list($type, $string, $line) = $ctok;
if (is_array($prev) && $prev[0] == T_FUNCTION) {
continue;
}
if ($par1 == "(") {
// Eat up everything that is used as the first parameter.
$tn = $ti + 2;
$depth = 0;
while (!($_potx_tokens[$tn] == "," && $depth == 0)) {
if ($_potx_tokens[$tn] == "(") {
$depth++;
}
elseif ($_potx_tokens[$tn] == ")") {
$depth--;
}
$tn++;
if ($depth < 0) {
// There is no second argument. This log() call was a false
// positive, continue with the next one.
continue 2;
}
}
// Get further parameters.
list($comma, $message, $par2) = [
$_potx_tokens[$tn],
$_potx_tokens[$tn + 1],
$_potx_tokens[$tn + 2],
];
if ($comma == ',' && in_array($par2, [
')',
',',
]) && (is_array($message) && $message[0] == T_CONSTANT_ENCAPSED_STRING)) {
// Context is not supported on watchdog().
$save_callback(_potx_format_quoted_string($message[1]), POTX_CONTEXT_NONE, $file, $line);
}
else {
// log() found, but the parameters are not correct.
_potx_marker_error($file, $line, 'log', $ti, t('In log(), the log level should be followed by a literal string. There should be no variables, concatenation, constants or even a t() call there.'), 'http://drupal.org/node/323101');
}
}
}
}
}