function _potx_find_watchdog_calls in Translation template extractor 8
Same name and namespace in other branches
- 5.2 potx.inc \_potx_find_watchdog_calls()
- 5 potx.inc \_potx_find_watchdog_calls()
- 6.3 potx.inc \_potx_find_watchdog_calls()
- 6 potx.inc \_potx_find_watchdog_calls()
- 6.2 potx.inc \_potx_find_watchdog_calls()
- 7.3 potx.inc \_potx_find_watchdog_calls()
- 7 potx.inc \_potx_find_watchdog_calls()
- 7.2 potx.inc \_potx_find_watchdog_calls()
Detect all occurances of watchdog() calls. Only in Drupal 6 and Drupal 7.
These sequences are searched for: watchdog + "(" + T_CONSTANT_ENCAPSED_STRING + "," + T_CONSTANT_ENCAPSED_STRING + something.
Parameters
string $file: Name of file parsed.
string $save_callback: Callback function used to save strings.
1 call to _potx_find_watchdog_calls()
- _potx_parse_php_file in ./
potx.inc - Parse a PHP file for translatables.
File
- ./
potx.inc, line 1120 - Extraction API used by the web and command line interface.
Code
function _potx_find_watchdog_calls($file, $save_callback) {
global $_potx_tokens, $_potx_lookup;
// Lookup tokens by function name.
if (isset($_potx_lookup['watchdog'])) {
foreach ($_potx_lookup['watchdog'] as $ti) {
list($prev, $ctok, $par, $mtype, $comma, $message, $rig) = [
$_potx_tokens[$ti - 1],
$_potx_tokens[$ti],
$_potx_tokens[$ti + 1],
$_potx_tokens[$ti + 2],
$_potx_tokens[$ti + 3],
$_potx_tokens[$ti + 4],
$_potx_tokens[$ti + 5],
];
list($type, $string, $line) = $ctok;
if (is_array($prev) && $prev[0] == T_FUNCTION) {
continue;
}
if ($par == '(') {
// Both type and message should be a string literal.
if (in_array($rig, [
')',
',',
]) && $comma == ',' && (is_array($mtype) && $mtype[0] == T_CONSTANT_ENCAPSED_STRING) && (is_array($message) && $message[0] == T_CONSTANT_ENCAPSED_STRING)) {
// Context is not supported on watchdog().
$save_callback(_potx_format_quoted_string($mtype[1]), POTX_CONTEXT_NONE, $file, $line);
$save_callback(_potx_format_quoted_string($message[1]), POTX_CONTEXT_NONE, $file, $line);
}
else {
// watchdog() found, but inside is something which is not a string
// literal.
_potx_marker_error($file, $line, 'watchdog', $ti, t('The first two watchdog() parameters should be literal strings. There should be no variables, concatenation, constants or even a t() call there.'), 'http://drupal.org/node/323101');
}
}
}
}
}