You are here

function _potx_find_watchdog_calls in Translation template extractor 7.2

Same name and namespace in other branches
  1. 8 potx.inc \_potx_find_watchdog_calls()
  2. 5.2 potx.inc \_potx_find_watchdog_calls()
  3. 5 potx.inc \_potx_find_watchdog_calls()
  4. 6.3 potx.inc \_potx_find_watchdog_calls()
  5. 6 potx.inc \_potx_find_watchdog_calls()
  6. 6.2 potx.inc \_potx_find_watchdog_calls()
  7. 7.3 potx.inc \_potx_find_watchdog_calls()
  8. 7 potx.inc \_potx_find_watchdog_calls()

Detect all occurances of watchdog() calls. Only from Drupal 6.

These sequences are searched for: watchdog + "(" + T_CONSTANT_ENCAPSED_STRING + "," + T_CONSTANT_ENCAPSED_STRING + something

Parameters

$file: Name of file parsed.

$save_callback: Callback function used to save strings.

1 call to _potx_find_watchdog_calls()
_potx_process_file in ./potx.inc
Process a file and put extracted information to the given parameters.

File

./potx.inc, line 944
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) = array(
        $_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, array(
          ')',
          ',',
        )) && $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');
        }
      }
    }
  }
}