Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Move fsAccessDriver functions to its parent AbstractAccessDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Feb 27, 2015
1 parent 6af583c commit dba284a
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 93 deletions.
91 changes: 0 additions & 91 deletions core/src/plugins/access.fs/class.fsAccessDriver.php
Expand Up @@ -1307,97 +1307,6 @@ protected function appendUploadedData($folder, $source, $target){

}

/**
* Test if userSelection is containing a hidden file, which should not be the case!
* @param UserSelection $files
*/
public function filterUserSelectionToHidden($files)
{
$showHiddenFiles = $this->getFilteredOption("SHOW_HIDDEN_FILES", $this->repository->getId());
foreach ($files as $file) {
$file = basename($file);
if (AJXP_Utils::isHidden($file) && !$showHiddenFiles) {
throw new Exception("$file Forbidden", 411);
}
if ($this->filterFile($file) || $this->filterFolder($file)) {
throw new Exception("$file Forbidden", 411);
}
}
}

public function filterNodeName($nodePath, $nodeName, &$isLeaf, $lsOptions)
{
$showHiddenFiles = $this->getFilteredOption("SHOW_HIDDEN_FILES", $this->repository->getId());
$isLeaf = (is_file($nodePath."/".$nodeName) || AJXP_Utils::isBrowsableArchive($nodeName));
if (AJXP_Utils::isHidden($nodeName) && !$showHiddenFiles) {
return false;
}
$nodeType = "d";
if ($isLeaf) {
if(AJXP_Utils::isBrowsableArchive($nodeName)) $nodeType = "z";
else $nodeType = "f";
}
if(!$lsOptions[$nodeType]) return false;
if ($nodeType == "d") {
if(RecycleBinManager::recycleEnabled()
&& $nodePath."/".$nodeName == RecycleBinManager::getRecyclePath()){
return false;
}
return !$this->filterFolder($nodeName);
} else {
if($nodeName == "." || $nodeName == "..") return false;
if(RecycleBinManager::recycleEnabled()
&& $nodePath == RecycleBinManager::getRecyclePath()
&& $nodeName == RecycleBinManager::getCacheFileName()){
return false;
}
return !$this->filterFile($nodeName);
}
}

public function filterFile($fileName, $hiddenTest = false)
{
$pathParts = pathinfo($fileName);
if($hiddenTest){
$showHiddenFiles = $this->getFilteredOption("SHOW_HIDDEN_FILES", $this->repository->getId());
if (AJXP_Utils::isHidden($pathParts["basename"]) && !$showHiddenFiles) return true;
}
$hiddenFileNames = $this->getFilteredOption("HIDE_FILENAMES", $this->repository->getId());
$hiddenExtensions = $this->getFilteredOption("HIDE_EXTENSIONS", $this->repository->getId());
if (!empty($hiddenFileNames)) {
if (!is_array($hiddenFileNames)) {
$hiddenFileNames = explode(",",$hiddenFileNames);
}
foreach ($hiddenFileNames as $search) {
if(strcasecmp($search, $pathParts["basename"]) == 0) return true;
}
}
if (!empty($hiddenExtensions)) {
if (!is_array($hiddenExtensions)) {
$hiddenExtensions = explode(",",$hiddenExtensions);
}
foreach ($hiddenExtensions as $search) {
if(strcasecmp($search, $pathParts["extension"]) == 0) return true;
}
}
return false;
}

public function filterFolder($folderName, $compare = "equals")
{
$hiddenFolders = $this->getFilteredOption("HIDE_FOLDERS", $this->repository->getId());
if (!empty($hiddenFolders)) {
if (!is_array($hiddenFolders)) {
$hiddenFolders = explode(",",$hiddenFolders);
}
foreach ($hiddenFolders as $search) {
if($compare == "equals" && strcasecmp($search, $folderName) == 0) return true;
if($compare == "contains" && strpos($folderName, "/".$search) !== false) return true;
}
}
return false;
}

public function readFile($filePathOrData, $headerType="plain", $localName="", $data=false, $gzip=null, $realfileSystem=false, $byteOffset=-1, $byteLength=-1)
{
if ($gzip === null) {
Expand Down
98 changes: 96 additions & 2 deletions core/src/plugins/core.access/class.AbstractAccessDriver.php
Expand Up @@ -443,9 +443,10 @@ protected function deldir($location, $repoData)
/**
*
* Try to reapply correct permissions
* @param oct $mode
* @param array $stat
* @param Repository $repoObject
* @param Function $remoteDetectionCallback
* @param callable $remoteDetectionCallback
* @internal param \oct $mode
*/
public static function fixPermissions(&$stat, $repoObject, $remoteDetectionCallback = null)
{
Expand Down Expand Up @@ -530,4 +531,97 @@ protected function resetAllPermission($value)
{
}

/**
* Test if userSelection is containing a hidden file, which should not be the case!
* @param Array $files
* @throws Exception
*/
public function filterUserSelectionToHidden($files)
{
$showHiddenFiles = $this->getFilteredOption("SHOW_HIDDEN_FILES", $this->repository->getId());
foreach ($files as $file) {
$file = basename($file);
if (AJXP_Utils::isHidden($file) && !$showHiddenFiles) {
throw new Exception("$file Forbidden", 411);
}
if ($this->filterFile($file) || $this->filterFolder($file)) {
throw new Exception("$file Forbidden", 411);
}
}
}

public function filterNodeName($nodePath, $nodeName, &$isLeaf, $lsOptions)
{
$showHiddenFiles = $this->getFilteredOption("SHOW_HIDDEN_FILES", $this->repository->getId());
$isLeaf = (is_file($nodePath."/".$nodeName) || AJXP_Utils::isBrowsableArchive($nodeName));
if (AJXP_Utils::isHidden($nodeName) && !$showHiddenFiles) {
return false;
}
$nodeType = "d";
if ($isLeaf) {
if(AJXP_Utils::isBrowsableArchive($nodeName)) $nodeType = "z";
else $nodeType = "f";
}
if(!$lsOptions[$nodeType]) return false;
if ($nodeType == "d") {
if(RecycleBinManager::recycleEnabled()
&& $nodePath."/".$nodeName == RecycleBinManager::getRecyclePath()){
return false;
}
return !$this->filterFolder($nodeName);
} else {
if($nodeName == "." || $nodeName == "..") return false;
if(RecycleBinManager::recycleEnabled()
&& $nodePath == RecycleBinManager::getRecyclePath()
&& $nodeName == RecycleBinManager::getCacheFileName()){
return false;
}
return !$this->filterFile($nodeName);
}
}

public function filterFile($fileName, $hiddenTest = false)
{
$pathParts = pathinfo($fileName);
if($hiddenTest){
$showHiddenFiles = $this->getFilteredOption("SHOW_HIDDEN_FILES", $this->repository->getId());
if (AJXP_Utils::isHidden($pathParts["basename"]) && !$showHiddenFiles) return true;
}
$hiddenFileNames = $this->getFilteredOption("HIDE_FILENAMES", $this->repository->getId());
$hiddenExtensions = $this->getFilteredOption("HIDE_EXTENSIONS", $this->repository->getId());
if (!empty($hiddenFileNames)) {
if (!is_array($hiddenFileNames)) {
$hiddenFileNames = explode(",",$hiddenFileNames);
}
foreach ($hiddenFileNames as $search) {
if(strcasecmp($search, $pathParts["basename"]) == 0) return true;
}
}
if (!empty($hiddenExtensions)) {
if (!is_array($hiddenExtensions)) {
$hiddenExtensions = explode(",",$hiddenExtensions);
}
foreach ($hiddenExtensions as $search) {
if(strcasecmp($search, $pathParts["extension"]) == 0) return true;
}
}
return false;
}

public function filterFolder($folderName, $compare = "equals")
{
$hiddenFolders = $this->getFilteredOption("HIDE_FOLDERS", $this->repository->getId());
if (!empty($hiddenFolders)) {
if (!is_array($hiddenFolders)) {
$hiddenFolders = explode(",",$hiddenFolders);
}
foreach ($hiddenFolders as $search) {
if($compare == "equals" && strcasecmp($search, $folderName) == 0) return true;
if($compare == "contains" && strpos($folderName, "/".$search) !== false) return true;
}
}
return false;
}


}

0 comments on commit dba284a

Please sign in to comment.