Ejemplo n.º 1
0
function getFiles($path, $filter, $recursive_max, $recursive_count)
{
    $files = array();
    if (@is_dir($path) && @is_readable($path)) {
        $dh = opendir($path);
        while (false !== ($item = readdir($dh))) {
            if ($item[0] != ".") {
                $path = fixPathSlash($path);
                $msg_path = appendPath($path, $item);
                $fileCount++;
                if ($fileCount > 3000) {
                    $_SESSION['ari_error'] .= _("To many files in {$msg_path} Not all files processed") . "<br>";
                    return;
                }
                if ($recursive_count < $recursive_max && is_dir($msg_path)) {
                    $dirCount++;
                    if ($dirCount > 10) {
                        $_SESSION['ari_error'] .= sprintf(_("To many directories in %s Not all files processed"), $msg_path) . "<br>";
                        return;
                    }
                    $count = $recursive_count + 1;
                    $path_files = getFiles($msg_path, $filter, $recursive_max, $count);
                    $files = array_merge($files, $path_files);
                } else {
                    $found = 0;
                    if ($filter) {
                        if (strpos($msg_path, $filter)) {
                            $found = 1;
                        }
                    } else {
                        $found = 1;
                    }
                    if ($found) {
                        $files[count($files) + 1] = $msg_path;
                    }
                }
            }
        }
    }
    return $files;
}
 protected function loadFileList($prefix, $path_parts, $group_parts)
 {
     // collect all the fixed path parts
     // variable, read directory and sub dirs
     for (;;) {
         if (array_key_exists($prefix, $this->processed_dirs) || !file_exists($prefix) || !is_dir($prefix)) {
             // already handled this one or it does not exist
             return;
         }
         // check if this one needs inclusion
         $config = $this->config_paths[$this->config_path];
         // the last path part is not removed and will be scanned for files.
         // if it is {group} then it will also be scanned for directories.
         if (count($path_parts) > 1) {
             $part = array_shift($path_parts);
             if (mb_substr($part, 0, 1) === '{' && mb_substr($part, -1, 1) === '}') {
                 $this->processed_dirs[$prefix] = $path_parts;
                 $dirs = $this->files->directories($prefix);
                 foreach ($dirs as $dir) {
                     $this->path_vars[$part] = basename($dir);
                     if ($part === '{vendor}' || $part === '{package}') {
                         // we can test it here
                         if (!static::isPathIncluded($config, $this->path_vars)) {
                             continue;
                         }
                     }
                     $this->loadFileList($dir, $path_parts, $group_parts);
                     unset($this->path_vars[$part]);
                 }
                 break;
             } else {
                 // fixed string, append it and keep going
                 $prefix = appendPath($prefix, $part);
             }
         } else {
             // we can scan for language files here and in subdirectories, we have no more dirs parts to
             // search
             if ($path_parts[0] === '{group}') {
                 $this->processed_dirs[$prefix] = $path_parts;
                 $dirs = $this->files->directories($prefix);
                 foreach ($dirs as $dir) {
                     $dir_name = substr($dir, strlen($prefix) + 1);
                     $subgroup_parts = $group_parts;
                     $subgroup_parts[] = $dir_name;
                     $this->loadFileList($dir, $path_parts, $subgroup_parts);
                 }
             }
             $files = $this->files->files($prefix);
             $files = array_filter($files, function ($file) {
                 $ext = pathinfo($file, PATHINFO_EXTENSION);
                 return $ext === 'php';
             });
             // now we add all these files to the list as keys with the resolved db_group as the value
             //if (!array_key_exists('db_group', $this->config_paths[$this->config_path]))
             //{
             //    $tmp = 0;
             //    break;
             //}
             //else
             $db_group = static::expandVars($this->config_paths[$this->config_path]['db_group'], $this->path_vars);
             foreach ($files as $file) {
                 if (!array_key_exists($file, $this->lang_files)) {
                     $pieces = $group_parts;
                     $pieces[] = pathinfo($file, PATHINFO_FILENAME);
                     $last_part = implode($this->group_sep, $pieces);
                     $this->path_vars[$path_parts[0]] = $last_part;
                     $this->lang_files[$file] = $this->path_vars + ['{db_group}' => static::expandVars($db_group, $this->path_vars)];
                 } else {
                     assert(false, "Language file was found twice: {$file} => " . $this->lang_files[$file]);
                 }
                 unset($this->path_vars[$path_parts[0]]);
             }
             break;
         }
     }
 }
 /**
  * Text appendPath() functionality
  *
  * @dataProvider getAppendPathProvider
  * @var string $path
  * @var string $part
  * @var string $expectedResult
  * @return void
  */
 public function testAppendPath($path, $part, $expectedResult)
 {
     //echo $url . "\n";
     try {
         self::timeIt('appendPath', function () use(&$result, $path, $part) {
             $result = appendPath($path, $part);
         });
         if ($result !== $expectedResult) {
             $result = appendPath($path, $part);
         }
         $this->assertSame($expectedResult, $result, "Mismatch in result on: '{$path}', '{$part}'");
     } catch (Exception $e) {
         echo "Exception " . $e->getMessage() . " on: '{$path}', '{$part}'\n";
         // rethrow it
         throw $e;
     }
 }