You are here

function _potx_find_perm_hook in Translation template extractor 6.3

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

Detect permission names from the hook_perm() implementations. Note that this will get confused with a similar pattern in a comment, and with dynamic permissions, which need to be accounted for.

Parameters

$file: Full path name of file parsed.

$filebase: Filenaname of file parsed.

$save_callback: Callback function used to save strings.

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

File

./potx.inc, line 1160
Extraction API used by the web and command line interface.

Code

function _potx_find_perm_hook($file, $filebase, $save_callback) {
  global $_potx_tokens, $_potx_lookup;
  if (isset($_potx_lookup[$filebase . '_perm'])) {

    // Special case for node module, because it uses dynamic permissions.
    // Include the static permissions by hand. That's about all we can do here.
    if ($filebase == 'node') {
      $line = $_potx_tokens[$_potx_lookup['node_perm'][0]][2];

      // List from node.module 1.763 (checked in on 2006/12/29 at 21:25:36 by drumm)
      $nodeperms = array(
        'administer content types',
        'administer nodes',
        'access content',
        'view revisions',
        'revert revisions',
      );
      foreach ($nodeperms as $item) {

        // hook_perm() is only ever found on a Drupal system which does not
        // support context.
        $save_callback($item, POTX_CONTEXT_NONE, $file, $line);
      }
    }
    else {
      $count = 0;
      foreach ($_potx_lookup[$filebase . '_perm'] as $ti) {
        $tn = $ti;
        while (is_array($_potx_tokens[$tn]) || $_potx_tokens[$tn] != '}') {
          if (is_array($_potx_tokens[$tn]) && $_potx_tokens[$tn][0] == T_CONSTANT_ENCAPSED_STRING) {

            // hook_perm() is only ever found on a Drupal system which does not
            // support context.
            $save_callback(_potx_format_quoted_string($_potx_tokens[$tn][1]), POTX_CONTEXT_NONE, $file, $_potx_tokens[$tn][2]);
            $count++;
          }
          $tn++;
        }
      }
      if (!$count) {
        potx_status('error', t('%hook should have an array of literal string permission names.', array(
          '%hook' => $filebase . '_perm()',
        )), $file, NULL, NULL, 'http://drupal.org/node/323101');
      }
    }
  }
}