class webfm_build_dir_list in Web File Manager 5
Same name and namespace in other branches
- 5.2 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
- class \webfm_build_dir_list
Expanded class hierarchy of webfm_build_dir_list
File
- ./
webfm.module, line 2074
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('.')) {
// 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) ? @filemtime($dir) : "";
$this->dirs[] = $dd;
}
}
if (is_array($_files)) {
foreach ($_files as $file) {
if ($_file = webfm_get_file_record('', $full_path . '/' . $file)) {
if ($perm == WEBFM_ADMIN || $_file->uid == $user->uid || (int) $_file->perm & WEBFM_FILE_ACCESS_ROLE_FULL || (int) $_file->perm & WEBFM_FILE_ACCESS_ROLE_VIEW) {
$fd = new stdClass();
$fd->id = $_file->fid;
if ((int) $_file->perm & WEBFM_FILE_ACCESS_ROLE_FULL) {
// A bit of a hack for js functionality but safe since this is
// always validated on server side
$fd->u = $user->uid;
}
else {
$fd->u = $_file->uid;
}
$_query = 'SELECT name FROM {users} WHERE uid = %d';
$fd->un = db_result(db_query($_query, $_file->uid));
$fd->m = @filemtime($file);
$fd->s = @filesize($file);
}
else {
// permission denied to view this file
continue;
}
}
else {
if ($perm == WEBFM_ADMIN) {
$fd = new stdClass();
$fd->id = 0;
//invalid fid signals no db entry
$fd->u = 0;
//file has no owner
$_query = 'SELECT name FROM {users} WHERE uid = %d';
$fd->un = db_result(db_query($_query, $fd->u));
$fd->m = @filemtime($file);
$fd->s = @filesize($file);
}
else {
// permission denied to view this file
continue;
}
}
if (variable_get('webfm_display_title', '') && $_file->ftitle) {
$fd->ftitle = urldecode($_file->ftitle);
}
$fd->n = $file;
$fd->p = $path;
$fd->i = 0;
if (strpos($file, ".") === FALSE) {
$fd->e = "";
}
else {
$fd->e = array_pop(explode('.', $file));
$mime_type = webfm_mime_type($file);
if (preg_match('/^image/', $mime_type)) {
if (!function_exists('exif_imagetype')) {
if ($i = @getimagesize($file)) {
//if valid width/height...
if ($i[0] != 0 && $i[1] != 0) {
//return type
$fd->i = $i[2];
}
}
}
else {
if ($i = @exif_imagetype($file)) {
$fd->i = $i;
}
}
}
}
$this->files[] = $fd;
}
}
}
}
function get_dir_listing() {
return $this->dirs;
}
function get_file_listing() {
return $this->files;
}
function get_breadcrumb() {
return $this->breadcrumb;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
webfm_build_dir_list:: |
property | |||
webfm_build_dir_list:: |
property | |||
webfm_build_dir_list:: |
property | |||
webfm_build_dir_list:: |
function | |||
webfm_build_dir_list:: |
function | |||
webfm_build_dir_list:: |
function | |||
webfm_build_dir_list:: |
function |