You are here

function dirtree2 in TinyBrowser 7

1 call to dirtree2()
dirtree3 in tinybrowser/fns_tinybrowser.php

File

tinybrowser/fns_tinybrowser.php, line 468

Code

function dirtree2(&$alldirs, $types, $root = '', $tree = '', $branch = '', $level = 0) {

  // IN(Old): $types = '*.jpg, *.gif, *.png';
  // IN(New): $types = array('jpg', 'gif', 'png');
  // filter file types according to type
  // $filetypes = explode(',',preg_replace('{[ \t]+}', '',$types));
  // OUT(Old): $filetypes = array('*.jpg', '*.gif', '*.png');
  $filetypes = $types;
  for ($i = 0; $i < count($filetypes); $i++) {
    $filetypes[$i] = '*.' . $filetypes[$i];
  }

  // OUT(New): $filetypes = array('*.jpg', '*.gif', '*.png');
  if ($level == 0 && is_dir($root . $tree . $branch)) {
    $filenum = 0;
    foreach ($filetypes as $filetype) {
      $filenum = $filenum + count(glob($root . $tree . $branch . sql_regcase($filetype), GLOB_NOSORT));
    }
    $treeparts = explode('/', rtrim($tree, '/'));
    $topname = end($treeparts);
    $alldirs[] = array(
      $branch,
      rtrim($topname, '/') . ' (' . $filenum . ')',
      rtrim($topname, '/'),
      rtrim($topname, '/'),
      $filenum,
      filemtime($root . $tree . $branch),
      $level,
    );
  }
  $level++;
  $dh = opendir($root . $tree . $branch);
  while (($dirname = readdir($dh)) !== false) {
    if ($dirname != '.' && $dirname != '..' && is_dir($root . $tree . $branch . $dirname) && $dirname != '_thumbs') {
      $filenum = 0;
      foreach ($filetypes as $filetype) {
        $filenum = $filenum + count(glob($root . $tree . $branch . $dirname . '/' . sql_regcase($filetype), GLOB_NOSORT));
      }
      $alldirs[] = array(
        urlencode($branch . $dirname . '/'),
        $dirname . ' (' . $filenum . ')',
        $dirname,
        $dirname,
        $filenum,
        filemtime($root . $tree . $branch . $dirname),
        $level,
      );
      dirtree2($alldirs, $types, $root, $tree, $branch . $dirname . '/', $level);
    }
  }
  closedir($dh);
  $level--;
}