You are here

function dirtree in TinyBrowser 7

4 calls to dirtree()
edit.php in tinybrowser/edit.php
folders.php in tinybrowser/folders.php
tinybrowser.php in tinybrowser/tinybrowser.php
upload.php in tinybrowser/upload.php

File

tinybrowser/fns_tinybrowser.php, line 418

Code

function dirtree(&$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++;
  $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));
      }
      $indent = '';
      for ($i = 0; $i < $level; $i++) {
        $indent .= ' &nbsp; ';
      }
      if (strlen($indent) > 0) {
        $indent .= '&rarr; ';
      }
      $alldirs[] = array(
        urlencode($branch . $dirname . '/'),
        $indent . $dirname . ' (' . $filenum . ')',
        $indent . $dirname,
        $dirname,
        $filenum,
        filemtime($root . $tree . $branch . $dirname),
      );
      dirtree($alldirs, $types, $root, $tree, $branch . $dirname . '/', $level);
    }
  }
  closedir($dh);
  $level--;
}