Skip to content
Permalink
Browse files

Many fixes

  • Loading branch information
cdujeu committed May 24, 2016
1 parent 0060f35 commit 5015584c61f8708f035c46c0da945628b6da0fda
@@ -105,7 +105,8 @@
function AjaXplorer_autoload($className)
{
// Temp : super dummy autoloader, take only class name
$className = array_pop(explode("\\", $className));
$parts = explode("\\", $className);
$className = array_pop($parts);

if($className == "dibi"){
require_once(AJXP_BIN_FOLDER."/lib/dibi/dibi.php");
@@ -23,8 +23,6 @@
use DOMNode;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Model\Repository;
use Pydio\Access\Driver\StreamProvider\FS\fsAccessDriver;
use Pydio\Core\Utils\Utils;

@@ -177,10 +175,14 @@ public function filterNodeName($nodePath, $nodeName, &$isLeaf, $lsOptions)
public function countFiles($dirName, $foldersOnly = false, $nonEmptyCheckOnly = false, $dirHandle = null)
{
if($foldersOnly) return 0;
// WILL USE IMAP FUNCTIONS TO COUNT;
$tmpHandle = opendir($dirName);
$this->logDebug("COUNT : ".imapAccessWrapper::getCurrentDirCount());
return imapAccessWrapper::getCurrentDirCount();
$count = 0;
if($tmpHandle = opendir($dirName)){
// WILL USE IMAP FUNCTIONS TO COUNT;
$this->logDebug("COUNT : ".imapAccessWrapper::getCurrentDirCount());
$count = imapAccessWrapper::getCurrentDirCount();
closedir($tmpHandle);
}
return $count;
}

}
@@ -210,9 +210,8 @@ public static function copyFileInStream($path, $stream)
* @param string $path
* @param number $chmodValue
*/
public static function changeMode($path, $chmodValue)
{
// TODO: Implement changeMode() method.
public static function changeMode($path, $chmodValue){

}

/**
@@ -116,7 +116,7 @@ protected function filecopy($srcFile, $destFile)
* @param $dest
* @param $basedir
* @throws \Exception
* @return zipfile
* @return PclZip Zip Archive
*/
public function makeZip ($src, $dest, $basedir)
{
@@ -147,7 +147,7 @@ protected static function getSftpResource($repoObject)
* @param String $mode
* @param array $options
* @param array $context
* @return unknown
* @return resource
*/
public function stream_open($path, $mode, $options, &$context)
{
@@ -24,7 +24,6 @@

use DOMNode;
use PclZip;
use Pydio\Access\Core\Model\Repository;
use Pydio\Access\Driver\StreamProvider\FS\fsAccessDriver;
use Pydio\Core\Services\ConfService;

@@ -93,10 +92,11 @@ protected function parseSpecificContributions(&$contribNode)
}

/**
* @param $src
* @param $dest
* @param $basedir
* @return zipfile
* @param array $src
* @param string $dest
* @param string $basedir
* @return PclZip zipfile
* @throws \Exception
*/
public function makeZip ($src, $dest, $basedir)
{
@@ -113,14 +113,7 @@ public static function getRealFSReference($path, $persistent = false)
}

/**
* Opens the stream
* Diff with parent class : do not "securePath", as it removes double slash
*
* @param String $path Maybe in the form "ajxp.fs://repositoryId/pathToFile"
* @param String $mode
* @param unknown_type $options
* @param unknown_type $opened_path
* @return unknown
* @inheritdoc
*/
public function stream_open($path, $mode, $options, &$context)
{
@@ -212,12 +205,10 @@ public function detectRemoteUserId($repoObject)
$ssh2->disconnect();

if (trim($output != "")) {
$res = sscanf($output, "uid=%i(%s) gid=%i(%s) groups=%i(%s)");
preg_match_all("/(\w*)=(\w*)\((\w*)\)/", $output, $matches);
if (count($matches[0]) == 3) {
$uid = $matches[2][0];
$gid = $matches[2][1];

return array($uid, $gid);
}
}
@@ -64,7 +64,7 @@ public function initRepository()

require_once($this->getBaseDir()."/smb.php");

$create = $this->repository->getOption("CREATE");
//$create = $this->repository->getOption("CREATE");
$recycle = $this->repository->getOption("RECYCLE_BIN");

$this->detectStreamWrapper(true);
@@ -103,45 +103,6 @@ protected function parseSpecificContributions(&$contribNode)
$this->disableArchiveBrowsingContributions($contribNode);
}

public function makeZip ($src, $dest, $basedir)
{
@set_time_limit(0);
require_once(AJXP_BIN_FOLDER."/lib/pclzip.lib.php");
$zipEncoding = ConfService::getCoreConf("ZIP_ENCODING");

$filePaths = array();
foreach ($src as $item) {
$url = $this->urlBase.(($item[0] == "/")? "" : "/").Utils::securePath($item);
$realFile = AJXP_MetaStreamWrapper::getRealFSReference($url);
//$basedir = trim(dirname($realFile))."/";
if (basename($item) == "") {
$filePaths[] = array(PCLZIP_ATT_FILE_NAME => $realFile);
} else {
$shortName = basename($item);
if(!empty($zipEncoding)){
$test = iconv(TextEncoder::getEncoding(), $zipEncoding, $shortName);
if($test !== false) $shortName = $test;
}
$filePaths[] = array(PCLZIP_ATT_FILE_NAME => $realFile,
PCLZIP_ATT_FILE_NEW_SHORT_NAME => $shortName);
}
}
self::$filteringDriverInstance = $this;
$archive = new PclZip($dest);
if($basedir == "__AJXP_ZIP_FLAT__/"){
$vList = $archive->create($filePaths, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_ADD_TEMP_FILE_ON, PCLZIP_CB_PRE_ADD, 'zipPreAddCallback');
}else{
$basedir = AJXP_MetaStreamWrapper::getRealFSReference($this->urlBase).trim($basedir);
$this->logDebug("Basedir", array($basedir));
$vList = $archive->create($filePaths, PCLZIP_OPT_REMOVE_PATH, $basedir, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_ADD_TEMP_FILE_ON, PCLZIP_CB_PRE_ADD, 'zipPreAddCallback');
}
if (!$vList) {
throw new \Exception("Zip creation error : ($dest) ".$archive->errorInfo(true));
}
self::$filteringDriverInstance = null;
return $vList;
}

public function isWriteable($dir, $type="dir")
{
if(substr_count($dir, '/') <= 3) $rc = true;
@@ -89,13 +89,7 @@ protected static function initPath($path, $streamType, $storeOpenContext = false
}

/**
* Opens the stream
* Diff with parent class : do not "securePath", as it removes double slash
*
* @param String $path Maybe in the form "ajxp.fs://repositoryId/pathToFile"
* @param String $mode
* @param mixed $options
* @return resource|bool
* @inheritdoc
*/
public function stream_open($path, $mode, $options, &$context)
{
@@ -189,9 +183,6 @@ public static function copyFileInStream($path, $stream)
fclose($fp);
}

public static function changeMode($path, $chmodValue)
{
//$realPath = self::initPath($path, "file");
//chmod($realPath, $chmodValue);
public static function changeMode($path, $chmodValue){
}
}
@@ -22,8 +22,12 @@

use DOMDocument;
use DOMXPath;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\AbstractAccessDriver;
use Pydio\Core\Controller\XMLWriter;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Model\NodesList;
use Pydio\Core\Http\Response\SerializableResponseStream;

defined('AJXP_EXEC') or die( 'Access not allowed');

@@ -34,66 +38,81 @@
*/
class WmsBrowser extends AbstractAccessDriver
{
public function switchAction($action, $httpVars, $fileVars)
public function switchAction(ServerRequestInterface $requestInterface, ResponseInterface &$responseInterface)
{
parent::accessPreprocess($action, $httpVars, $fileVars);

switch ($action) {
case "ls":
$doc = DOMDocument::load($this->repository->getOption("HOST") . "?request=GetCapabilities");
$xPath = new DOMXPath($doc);
$dir = $httpVars["dir"];
XMLWriter::header();
XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist"><column messageId="wms.1" attributeName="ajxp_label" sortType="String"/><column messageId="wms.6" attributeName="srs" sortType="String"/><column messageId="wms.4" attributeName="style" sortType="String"/><column messageId="wms.5" attributeName="keywords" sortType="String"/></columns>');

$layers = $xPath->query("Capability/Layer/Layer");
// Detect "levels"
$levels = array();
$leafs = array();
$styleLevels = $prefixLevels = false;
foreach ($layers as $layer) {
$name = $xPath->evaluate("Name", $layer)->item(0)->nodeValue;
$stylesList = $xPath->query("Style/Name", $layer);
if (strstr($name, ":")!==false) {
$exp = explode(":", $name);
if(!isSet($levels[$exp[0]]))$levels[$exp[0]] = array();
$levels[$exp[0]][] = $layer;
$prefixLevels = true;
} else if ($stylesList->length > 1) {
if(!isSet($levels[$name])) $levels[$name] = array();
foreach ($stylesList as $style) {
$levels[$name][$style->nodeValue] = $layer;
}
$styleLevels = true;
} else {
$leafs[] = $layer;
}
}
if ($dir == "/" || $dir == "") {
$this->listLevels($levels);
$this->listLayers($leafs, $xPath);
} else if (isSet($levels[basename($dir)])) {
$this->listLayers($levels[basename($dir)], $xPath, ($styleLevels?array($this,"replaceStyle"):null));
}
XMLWriter::close();
break;
parent::accessPreprocess($requestInterface);

if($requestInterface->getAttribute("action")){
return ;
}

$doc = new DOMDocument();
$doc->load($this->repository->getOption("HOST") . "?request=GetCapabilities");
$xPath = new DOMXPath($doc);

$httpVars = $requestInterface->getParsedBody();
$dir = $httpVars["dir"];

default:
break;
$x = new SerializableResponseStream();
$responseInterface = $responseInterface->withBody($x);
$nodesList = new NodesList();
$nodesList->initColumnsData("filelist");
$nodesList->appendColumn("wms.1", "ajxp_label");
$nodesList->appendColumn("wms.6", "srs");
$nodesList->appendColumn("wms.4", "style");
$nodesList->appendColumn("wms.5", "keyword");

$layers = $xPath->query("Capability/Layer/Layer");
// Detect "levels"
$levels = array();
$leafs = array();
$styleLevels = $prefixLevels = false;
foreach ($layers as $layer) {
$name = $xPath->evaluate("Name", $layer)->item(0)->nodeValue;
$stylesList = $xPath->query("Style/Name", $layer);
if (strstr($name, ":")!==false) {
$exp = explode(":", $name);
if(!isSet($levels[$exp[0]]))$levels[$exp[0]] = array();
$levels[$exp[0]][] = $layer;
$prefixLevels = true;
} else if ($stylesList->length > 1) {
if(!isSet($levels[$name])) $levels[$name] = array();
foreach ($stylesList as $style) {
$levels[$name][$style->nodeValue] = $layer;
}
$styleLevels = true;
} else {
$leafs[] = $layer;
}
}
if ($dir == "/" || $dir == "") {
$this->listLevels($nodesList, $levels);
$this->listLayers($nodesList, $leafs, $xPath);
} else if (isSet($levels[basename($dir)])) {
$this->listLayers($nodesList, $levels[basename($dir)], $xPath, ($styleLevels?array($this,"replaceStyle"):null));
}

$x->addChunk($nodesList);

}

public function listLevels($levels)
/**
* @param NodesList $NodesList
* @param $levels
*/
public function listLevels(&$NodesList, $levels)
{
foreach ($levels as $key => $layers) {
XMLWriter::renderNode("/$key", $key, false, array(
$node = new AJXP_Node("/$key", array(
"icon" => "folder.png",
"openicon" => "openfolder.png",
"parentname" => "/",
"srs" => "-",
"keywords" => "-",
"style" => "-"
));
$node->setLeaf(false);
$NodesList->addBranch($node);
}

}
@@ -107,7 +126,14 @@ public function replaceStyle($key, $metaData)
return $metaData;
}

public function listLayers($nodeList, $xPath, $replaceCallback = null)
/**
* @param NodesList $NodesList
* @param array $nodeList
* @param DOMXPath $xPath
* @param callable|null $replaceCallback
* @throws \Exception
*/
public function listLayers(&$NodesList, $nodeList, $xPath, $replaceCallback = null)
{
foreach ($nodeList as $key => $node) {
$name = $xPath->evaluate("Name", $node)->item(0)->nodeValue;
@@ -149,7 +175,9 @@ public function listLayers($nodeList, $xPath, $replaceCallback = null)
$metaData = call_user_func($replaceCallback, $key, $metaData);
}

XMLWriter::renderNode("/".$metaData["name"], $title, true, $metaData);
$newNode = new AJXP_Node("/".$metaData["name"], $metaData);
$newNode->setLeaf(true);
$NodesList->addBranch($newNode);
}
}

@@ -152,7 +152,7 @@ private function callSet($nodeObject)

/**
* This function initializes the file path
* @param $nodeObject
* @param AJXP_Node $nodeObject
*/
public function setPath($nodeObject)
{
@@ -164,7 +164,7 @@ public function setPath($nodeObject)

/**
* This function initializes the file extension
* @param $nodeObject
* @param AJXP_Node $nodeObject
*/
public function setFileExtension ($nodeObject)
{

0 comments on commit 5015584

Please sign in to comment.
You can’t perform that action at this time.