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

Commit

Permalink
Move ContentFilter filterings to AJXP_MetaStreamWrapper instead of Us…
Browse files Browse the repository at this point in the history
…erSelection and fsAccessDriver.
  • Loading branch information
cdujeu committed Feb 22, 2016
1 parent 81a6a4c commit 76c5349
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 21 deletions.
54 changes: 50 additions & 4 deletions core/src/core/classes/class.AJXP_MetaStreamWrapper.php
Expand Up @@ -50,6 +50,8 @@ class AJXP_MetaStreamWrapper implements AjxpWrapper

protected static $cachedRepositoriesWrappers = array();

protected $currentUniquePath;

/**
* Register the stack of protocols/wrappers.
* @param null $registered_wrappers
Expand Down Expand Up @@ -89,9 +91,31 @@ protected static function getNextScheme($url){
}
}

protected static function translateScheme($url){
/**
* @param string $url
* @param AJXP_MetaStreamWrapper $crtInstance
* @return string
* @throws Exception
*/
protected static function translateScheme($url, $crtInstance = null){
$currentScheme = parse_url($url, PHP_URL_SCHEME);
$newScheme = self::getNextScheme($url);
$repository = ConfService::getRepositoryById(parse_url($url, PHP_URL_HOST));
if($currentScheme == "pydio" && $repository->hasContentFilter()){
$baseDir = $repository->getContentFilter()->getBaseDir();
if($crtInstance != null){
$crtInstance->currentUniquePath = $repository->getContentFilter()->getUniquePath();
}
if(!empty($baseDir) || $baseDir != "/"){
$crtPath = parse_url($url, PHP_URL_PATH);
$crtBase = basename($crtPath);
if(!empty($crtPath) && $crtPath != "/" && $crtBase != $repository->getContentFilter()->getUniquePath() && $crtBase != ".ajxp_meta"){
throw new Exception("Cannot find file ".$crtBase);
}
// Prepend baseDir in path
$url = str_replace($currentScheme."://".$repository->getId().$crtPath, $currentScheme."://".$repository->getId().rtrim($baseDir.$crtPath, "/"), $url);
}
}
return str_replace($currentScheme."://", $newScheme."://", $url);
}

Expand Down Expand Up @@ -242,7 +266,7 @@ public function dir_closedir()
*/
public function dir_opendir($path, $options)
{
$newPath = self::translateScheme($path);
$newPath = self::translateScheme($path, $this);
$this->handle = opendir($newPath);
if($this->handle !== false){
$this->currentDirPath = parse_url($path, PHP_URL_PATH);
Expand All @@ -253,18 +277,40 @@ public function dir_opendir($path, $options)
}

/**
* Enter description here...
* Standard readdir() implementation
*
* @return string
*/
public function dir_readdir()
{
if(isSet($this->handle) && is_resource($this->handle)){
return readdir($this->handle);
if($this->currentUniquePath != null){
return $this->innerReadDirFiltered($this->handle);
}else{
return readdir($this->handle);
}
}
return false;
}

/**
* Skip values until correct one is found
* @param Resource $resource
* @return string
*/
protected function innerReadDirFiltered($resource){
$test = readdir($resource);
if($test === false || $test == "." || $test == ".."){
return $test;
}
if($this->currentUniquePath == $test) {
return $test;
}
// Return next one
return $this->innerReadDirFiltered($resource);
}


/**
* Enter description here...
*
Expand Down
11 changes: 10 additions & 1 deletion core/src/core/classes/class.ContentFilter.php
Expand Up @@ -68,7 +68,11 @@ function filterUserSelection( &$userSelection ){
}

function getBaseDir(){
return dirname($this->filters[0]);
return dirname(array_keys($this->filters)[0]);
}

function getUniquePath(){
return basename(array_keys($this->filters)[0]);
}

/**
Expand Down Expand Up @@ -121,4 +125,9 @@ public function toArray(){
return $data;
}

public function fromFilterArray($filters){
$this->filters = $filters;
$this->virtualPaths = array_flip($this->filters);
}

}
3 changes: 0 additions & 3 deletions core/src/core/classes/class.UserSelection.php
Expand Up @@ -77,9 +77,6 @@ public function initFromHttpVars($passedArray=null)
$this->initFromArray($_GET);
$this->initFromArray($_POST);
}
if(isSet($this->repository) && $this->repository->hasContentFilter()){
$this->repository->getContentFilter()->filterUserSelection($this);
}
}

/**
Expand Down
15 changes: 2 additions & 13 deletions core/src/plugins/access.fs/class.fsAccessDriver.php
Expand Up @@ -936,11 +936,6 @@ public function switchAction($action, $httpVars, $fileVars)
$node->mergeMetadata(array("page_position" => floor($index / $limitPerPage) +1));
}
}
if($this->repository->hasContentFilter()){
$externalPath = $this->repository->getContentFilter()->externalPath($node);
$node->setUrl($this->urlBase.$externalPath);
}

AJXP_XMLWriter::renderAjxpNode($node);
}
AJXP_XMLWriter::close();
Expand Down Expand Up @@ -1025,7 +1020,7 @@ public function switchAction($action, $httpVars, $fileVars)
throw new AJXP_Exception("Cannot open dir ".$nonPatchedPath);
}
$nodes = array();
while(strlen($file = readdir($handle))>0){
while(false !== ($file = readdir($handle))){
$nodes[] = $file;
}
closedir($handle);
Expand Down Expand Up @@ -1087,12 +1082,6 @@ public function switchAction($action, $httpVars, $fileVars)
if(isSet($orderField) && $orderField != "ajxp_label" && !(isSet($httpVars["recursive"]) && $httpVars["recursive"] == "true" )) {
$nodeType = "f";
}

if($this->repository->hasContentFilter()){
$externalPath = $this->repository->getContentFilter()->externalPath($node);
$node->setUrl($this->urlBase.$externalPath);
}

$fullList[$nodeType][$nodeName] = $node;
$cursor ++;
}
Expand Down Expand Up @@ -1573,7 +1562,7 @@ public function countFiles($dirName, $foldersOnly = false, $nonEmptyCheckOnly =
}
$count = 0;
$showHiddenFiles = $this->getFilteredOption("SHOW_HIDDEN_FILES", $this->repository);
while (strlen($file = readdir($handle)) > 0) {
while (false !== ($file = readdir($handle))) {
if($file != "." && $file !=".."
&& !(AJXP_Utils::isHidden($file) && !$showHiddenFiles)){
if($foldersOnly && is_file($dirName."/".$file)) continue;
Expand Down

0 comments on commit 76c5349

Please sign in to comment.