You are here

class webfm_build_dir_list in Web File Manager 5.2

Same name and namespace in other branches
  1. 5 webfm.module \webfm_build_dir_list

Class to build the directory, file and breadcrumb listings ..for the directory at $path for javascript Load_dirlist()

Hierarchy

Expanded class hierarchy of webfm_build_dir_list

File

./webfm.module, line 1460

View source
class webfm_build_dir_list {
  var $dirs = array();
  var $files = array();
  var $breadcrumb = array();

  //Constructor
  function webfm_build_dir_list($root, $path, $perm) {
    global $user;
    $bl = array(
      '.',
      '..',
      '.htaccess',
    );
    $_dirs = array();
    $_files = array();
    $full_path = $root . $path;
    if (is_dir($full_path)) {
      chdir($full_path);
      if ($handle = opendir('.')) {
        if (variable_get('webfm_root_dir', '')) {

          // breadcrumb keeps file-sys root hidden
          $non_root_arr = explode('/', trim($path, '/'));
          foreach ($non_root_arr as $piece) {
            $this->breadcrumb[] = $piece;
          }
        }
        while (($readdir = readdir($handle)) !== false) {

          // check that directory element is readable and not in black list
          if (!in_array(strtolower($readdir), $bl)) {
            if (is_dir($readdir)) {
              $_dirs[] = $readdir;
            }
            if (is_file($readdir)) {
              $_files[] = $readdir;
            }
          }
        }
        closedir($handle);
      }
      if (is_array($_dirs)) {
        foreach ($_dirs as $dir) {
          $dd = new stdClass();
          $dd->n = $dir;
          $dd->p = $path . "/" . $dir;
          $dd->m = filemtime($dir) ? date('d/m/y g:i a', @filemtime($dir)) : "";
          $this->dirs[] = $dd;
        }
      }
      if (is_array($_files)) {
        foreach ($_files as $file) {
          if ($_file = webfm_get_file_record('', $full_path . '/' . $file)) {
            $fd = new stdClass();
            $fd->id = $_file->fid;
            $fd->u = $_file->uid;
            $fd->m = $_file->fcreatedate ? date('d/m/y g:i a', $_file->fcreatedate) : date('d/m/y g:i a', @filemtime($file));
            $fd->s = $_file->fsize ? $_file->fsize : @filesize($file);
          }
          else {
            if ($perm == WEBFM_ADMIN) {
              $fd = new stdClass();
              $fd->id = 0;

              //invalid fid signals no db entry
              $fd->u = 0;

              //file has no owner(anon user)
              $fd->m = filemtime($file) ? date('d/m/y g:i a', @filemtime($file)) : "";
              $fd->s = @filesize($file);
            }
            else {

              // Only WEBFM_ADMIN can see files not in db
              continue;
            }
          }
          $fd->n = $file;
          $fd->p = $path;

          //if file is an image...
          if ($i = @getimagesize($file)) {

            //if valid width/height...
            if ($i[0] != 0 && $i[1] != 0) {

              //return type
              $fd->i = $i[2];
            }
          }
          else {
            $fd->i = 0;
          }
          if (strpos($file, ".") === false) {
            $fd->e = "";
          }
          else {
            $fd->e = strtolower(substr($file, strrpos($file, ".") + 1));
          }
          $this->files[] = $fd;
        }
      }
    }
  }
  function get_dir_listing() {
    return $this->dirs;
  }
  function get_file_listing() {
    return $this->files;
  }
  function get_breadcrumb() {
    return $this->breadcrumb;
  }

}

Members