Example #1
0
function get_dirs($startdir, $prefix = '/')
{
    $res = array();
    if (!is_dir($startdir)) {
        return;
    }
    global $showhiddenfiles;
    $dh = opendir($startdir);
    while (false !== ($entry = readdir($dh))) {
        if ($entry == '.') {
            continue;
        }
        $full = filemanager_utils::join_path($startdir, $entry);
        if (!is_dir($full)) {
            continue;
        }
        if (!$showhiddenfiles && ($entry[0] == '.' || $entry[0] == '_')) {
            continue;
        }
        if ($entry == '.svn' || $entry == '.git') {
            continue;
        }
        $res[$prefix . $entry] = $prefix . $entry;
        $tmp = get_dirs($full, $prefix . $entry . '/');
        if (is_array($tmp) && count($tmp)) {
            $res = array_merge($res, $tmp);
        }
    }
    closedir($dh);
    return $res;
}
Example #2
0
 protected function after_uploaded_file($fileobject)
 {
     // here we may do image handling, and other cruft.
     if (is_object($fileobject) && $fileobject->name != '') {
         $mod = cms_utils::get_module('FileManager');
         $parms = array();
         $parms['file'] = filemanager_utils::join_path(filemanager_utils::get_full_cwd(), $fileobject->name);
         if ($mod->GetPreference('create_thumbnails')) {
             $thumb = cms_utils::generate_thumbnail($parms['file']);
             if ($thumb) {
                 $params['thumb'] = $thumb;
             }
         }
         $str = $fileobject->name . ' uploaded to ' . filemanager_utils::get_full_cwd();
         if (isset($params['thumb'])) {
             $str .= ' and a thumbnail was generated';
         }
         audit('', $mod->GetName(), $str);
         $mod->SendEvent('OnFileUploaded', $parms);
     }
 }
Example #3
0
 }
 if (!is_readable($src)) {
     $errors[] = $this->Lang('insufficientpermission', $file);
     continue;
 }
 if (file_exists($dest)) {
     $errors[] = $this->Lang('fileexistsdest', $file);
     continue;
 }
 $thumb = '';
 $src_thumb = '';
 $dest_thumb = '';
 if (filemanager_utils::is_image_file($file)) {
     $tmp = 'thumb_' . $file;
     $src_thumb = filemanager_utils::join_path($basedir, $cwd, $tmp);
     $dest_thumb = filemanager_utils::join_path($basedir, $destdir, $tmp);
     if (file_exists($src_thumb)) {
         // have a thumbnail
         $thumb = $tmp;
         if (!is_readable($src_thumb)) {
             $errors[] = $this->Lang('insufficientpermission', $thumb);
             continue;
         }
         if (file_exists($dest_thumb)) {
             $errors[] = $this->Lang('fileexistsdest', $thumb);
             continue;
         }
     }
 }
 // here we can move the file/dir
 $res = rename($src, $dest);
Example #4
0
    $selall = unserialize($selall);
}
if (count($selall) == 0) {
    $params["fmerror"] = "nofilesselected";
    $this->Redirect($id, "defaultadmin", $returnid, $params);
}
if (count($selall) > 1) {
    $params["fmerror"] = "morethanonefiledirselected";
    $this->Redirect($id, "defaultadmin", $returnid, $params);
}
$config = cmsms()->GetConfig();
$filename = $this->decodefilename($selall[0]);
$src = filemanager_utils::join_path($config['root_path'], filemanager_utils::get_cwd(), $filename);
if (!file_exists($src)) {
    $params["fmerror"] = "filenotfound";
    $this->Redirect($id, "defaultadmin", $returnid, $params);
}
include_once dirname(__FILE__) . '/easyarchives/EasyArchive.class.php';
$archive = new EasyArchive();
$destdir = filemanager_utils::join_path($config['root_path'], filemanager_utils::get_cwd());
if (!endswith($destdir, '/')) {
    $destdir .= '/';
}
$res = $archive->extract($src, $destdir);
$paramsnofiles["fmmessage"] = "unpacksuccess";
//strips the file data
$this->Audit('', "File Manager", "Unpacked file: " . $src);
$this->Redirect($id, "defaultadmin", $returnid, $paramsnofiles);
#
# EOF
#
Example #5
0
if (!function_exists("cmsms")) {
    exit;
}
if (!$this->CheckPermission("Modify Files") && !$this->AdvancedAccessAllowed()) {
    exit;
}
if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['showtemplate']) && $_GET['showtemplate'] == 'false') {
    echo filemanager_utils::get_cwd();
    exit;
}
if (!isset($params["newdir"]) || !isset($params["path"])) {
    $this->Redirect($id, 'defaultadmin');
}
$newdir = $params["newdir"];
$path = filemanager_utils::join_path(filemanager_utils::get_cwd(), $newdir);
try {
    if (isset($params['ajax'])) {
        filemanager_utils::set_cwd(trim($newdir));
    } else {
        filemanager_utils::set_cwd($path);
        $this->Redirect($id, 'defaultadmin');
    }
} catch (Exception $e) {
    audit('', 'FileManager', 'Attempt to set working directory to an invalid location: ' . $newdir);
    if (isset($params['ajax'])) {
        exit('ERROR');
    }
}
//echo $params["path"];
if (isset($params['ajax'])) {
Example #6
0
$smarty->assign("rooturl", $config->smart_root_url());
$smarty->assign("filepickertitle", $this->Lang("filepickertitle"));
$smarty->assign("youareintext", $this->Lang("youareintext"));
$tmp = filemanager_utils::get_cwd();
if (isset($_GET['subdir'])) {
    $tmp .= '/' . trim($_GET['subdir']);
    filemanager_utils::set_cwd($tmp);
}
$startpath = filemanager_utils::get_cwd();
if ($type == "image") {
    $smarty->assign("isimage", "1");
} else {
    $smarty->assign("isimage", "0");
}
$starturl = $config['root_url'] . '/' . $startpath;
$startdir = filemanager_utils::join_path($config['root_path'], $startpath);
function sortfiles($file1, $file2)
{
    if ($file1["isdir"] && !$file2["isdir"]) {
        return -1;
    }
    if (!$file1["isdir"] && $file2["isdir"]) {
        return 1;
    }
    return strnatcasecmp($file1["name"], $file2["name"]);
}
$fmmodule = cms_utils::get_module("FileManager");
$files = array();
$d = dir($startdir);
while ($entry = $d->read()) {
    if ($entry == '.') {
Example #7
0
//for initial input box
if (isset($params["newname"])) {
    $newname = $params["newname"];
    if (!filemanager_utils::is_valid_filename($newname)) {
        echo $this->ShowErrors($this->Lang("invaliddestname"));
    } else {
        $cwd = filemanager_utils::get_cwd();
        $fullnewname = filemanager_utils::join_path(filemanager_utils::get_full_cwd(), trim($params['newname']));
        if (file_exists($fullnewname)) {
            echo $this->ShowErrors($this->Lang("namealreadyexists"));
            //fallthrough
        } else {
            $fulloldname = filemanager_utils::join_path(filemanager_utils::get_full_cwd(), $oldname);
            if (@rename($fulloldname, $fullnewname)) {
                $thumboldname = filemanager_utils::join_path(filemanager_utils::get_full_cwd(), 'thumb_' . $oldname);
                $thumbnewname = filemanager_utils::join_path(filemanager_utils::get_full_cwd(), 'thumb_' . trim($params['newname']));
                if (file_exists($thumboldname)) {
                    @rename($thumboldname, $thumbnewname);
                }
                $this->SetMessage($this->Lang('renamesuccess'));
                $this->Audit('', "File Manager", "Renamed file: " . $fullnewname);
                $this->Redirect($id, "defaultadmin", $returnid, $paramsnofiles);
            } else {
                $this->SetError($this->Lang('renameerror'));
                $this->Redirect($id, "defaultadmin", $returnid, $params);
            }
        }
    }
}
if (is_array($params['selall'])) {
    $params['selall'] = serialize($params['selall']);
Example #8
0
if (count($selall) > 1) {
    $params["fmerror"] = "morethanonefiledirselected";
    $this->Redirect($id, "defaultadmin", $returnid, $params);
}
$advancedmode = filemanager_utils::check_advanced_mode();
$basedir = $config['root_path'];
$config = cmsms()->GetConfig();
$filename = $this->decodefilename($selall[0]);
$src = filemanager_utils::join_path($basedir, filemanager_utils::get_cwd(), $filename);
if (!file_exists($src)) {
    $params["fmerror"] = "filenotfound";
    $this->Redirect($id, "defaultadmin", $returnid, $params);
}
$thumb = filemanager_utils::join_path($basedir, filemanager_utils::get_cwd(), 'thumb_' . $filename);
if (isset($params['submit'])) {
    $thumb = filemanager_utils::join_path($basedir, filemanager_utils::get_cwd(), 'thumb_' . $filename);
    $thumb = cms_utils::generate_thumbnail($src);
    if (!$thumb) {
        $params["fmerror"] = "thumberror";
    } else {
        $params["fmmessage"] = "thumbsuccess";
    }
    $this->Redirect($id, "defaultadmin", $returnid, $params);
}
//
// build the form
//
$smarty->assign('filename', $filename);
$smarty->assign('filespec', $src);
$smarty->assign('thumb', $thumb);
$smarty->assign('thumbexists', file_exists($thumb));
Example #9
0
     $errors[] = $this->Lang('insufficientpermission', $file);
     continue;
 }
 if (file_exists($dest)) {
     $errors[] = $this->Lang('fileexistsdest', basename($dest));
     continue;
 }
 $thumb = '';
 $src_thumb = '';
 $dest_thumb = '';
 if (filemanager_utils::is_image_file($file)) {
     $tmp = 'thumb_' . $file;
     $src_thumb = filemanager_utils::join_path($basedir, $cwd, $tmp);
     $dest_thumb = filemanager_utils::join_path($basedir, $destdir, $tmp);
     if ($destname) {
         $dest_thumb = filemanager_utils::join_path($basedir, $destdir, 'thumb_' . $destname);
     }
     if (file_exists($src_thumb)) {
         $thumb = $tmp;
         // have a thumbnail
         if (!is_readable($src_thumb)) {
             $errors[] = $this->Lang('insufficientpermission', $thumb);
             continue;
         }
         if (file_exists($dest_thumb)) {
             $errors[] = $this->Lang('fileexistsdest', $thumb);
             continue;
         }
     }
 }
 // here we can move the file/dir