You are here

function _potx_explore_dir in Translation template extractor 7.2

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

Collect a list of file names relevant for extraction, starting from the given path.

Parameters

$path: Where to start searching for files recursively. Provide non-empty path values with a trailing slash.

$basename: Allows the restriction of search to a specific basename (ie. to collect files for a specific module).

$api_version: Drupal API version to work with.

$skip_self: Skip potx related files. To be used when command line type of extraction is used and the potx files at in the webroot, and their strings should not end up in the generated template. Set to TRUE if skiping is needed.

3 calls to _potx_explore_dir()
PotxTestCase::testDrupal8ShippedConfiguration in tests/potx.test
Test parsing of Drupal 8 shipped configuration files.
potx_drush_extract in ./potx.drush.inc
Drush command callback.
potx_select_component_form_submit in ./potx.admin.inc
Generate translation template or translation file for the requested component.

File

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

Code

function _potx_explore_dir($path = '', $basename = '*', $api_version = POTX_API_CURRENT, $skip_self = FALSE) {

  // It would be so nice to just use GLOB_BRACE, but it is not available on all
  // operarting systems, so we are working around the missing functionality.
  $extensions = array(
    'php',
    'inc',
    'module',
    'engine',
    'theme',
    'install',
    'info',
    'profile',
  );
  if ($api_version > POTX_API_5) {
    $extensions[] = 'js';
  }
  if ($api_version > POTX_API_7) {
    $extensions[] = 'twig';
    $extensions[] = 'yml';
    _potx_init_yaml_translation_patterns($path);
  }
  $files = array();
  foreach ($extensions as $extension) {
    $files_here = glob($path . $basename . '.' . $extension);
    if (is_array($files_here)) {
      $files = array_merge($files, $files_here);
    }
    if ($basename != '*') {

      // Basename was specific, so look for things like basename.admin.inc as well.
      // If the basnename was *, the above glob() already covered this case.
      $files_here = glob($path . $basename . '.*.' . $extension);
      if (is_array($files_here)) {
        $files = array_merge($files, $files_here);
      }
    }
  }

  // Grab subdirectories.
  $dirs = glob($path . '*', GLOB_ONLYDIR);
  if (is_array($dirs)) {
    foreach ($dirs as $dir) {
      if (!preg_match("!(^|.+/)(CVS|\\.svn|\\.git|tests|vendor)\$!", $dir)) {
        $files = array_merge($files, _potx_explore_dir("{$dir}/", $basename, $api_version, $skip_self));
      }
    }
  }

  // Skip API and test files. Also skip our own files, if that was requested.
  $skip_pattern = $skip_self ? '!(potx-cli\\.php|potx\\.inc|\\.api\\.php|\\.test)$!' : '!(\\.api\\.php|\\.test)$!';
  foreach ($files as $id => $file_name) {
    if (preg_match($skip_pattern, $file_name)) {
      unset($files[$id]);
    }
  }
  return $files;
}