diff --git a/js/commands/open.js b/js/commands/open.js
index bb6596968..cf07d7e3a 100644
--- a/js/commands/open.js
+++ b/js/commands/open.js
@@ -42,7 +42,7 @@ elFinder.prototype.commands.open = function() {
return file && !file.read
? dfrd.reject(['errOpen', file.name, 'errPerm'])
: fm.request({
- data : {cmd : 'open', target : file.hash},
+ data : {cmd : 'open', target : file.thash || file.hash},
notify : {type : 'open', cnt : 1, hideCnt : true},
syncOnFail : true
});
@@ -64,7 +64,7 @@ elFinder.prototype.commands.open = function() {
return dfrd.reject(['errOpen', file.name, 'errPerm']);
}
- if (!(url = fm.url(file.hash))) {
+ if (!(url = fm.url(file.thash || file.hash))) {
url = fm.options.url;
url = url + (url.indexOf('?') === -1 ? '?' : '&')
+ (fm.oldAPI ? 'cmd=open¤t='+file.phash : 'cmd=file')
diff --git a/js/ui/tree.js b/js/ui/tree.js
index e28a0ff04..e99fd1fb3 100644
--- a/js/ui/tree.js
+++ b/js/ui/tree.js
@@ -349,10 +349,11 @@ $.fn.elfindertree = function(fm, opts) {
// open dir or open subfolders in tree
.delegate('.'+navdir, 'click', function(e) {
var link = $(this),
- hash = fm.navId2Hash(link.attr('id'));
+ hash = fm.navId2Hash(link.attr('id')),
+ file = fm.file(hash);
if (hash != fm.cwd().hash && !link.is('.'+disabled)) {
- fm.exec('open', hash);
+ fm.exec('open', file.thash || hash);
} else if (link.is('.'+collapsed)) {
link.children('.'+arrow).click();
}
@@ -371,7 +372,7 @@ $.fn.elfindertree = function(fm, opts) {
} else {
spinner.insertBefore(arrow);
link.removeClass(collapsed);
-
+
fm.request({cmd : 'tree', target : fm.navId2Hash(link.attr('id'))})
.done(function(data) {
updateTree(filter(data.tree));
diff --git a/php/connector.php b/php/connector.php
index 20a73a0a1..ef4d5274d 100644
--- a/php/connector.php
+++ b/php/connector.php
@@ -321,13 +321,13 @@ $opts = array(
)
),
- array(
- 'driver' => 'FTP',
- 'host' => 'work.std42.ru',
- 'user' => 'dio',
- 'pass' => '123456',
- 'path' => '/'
- ),
+ // array(
+ // 'driver' => 'FTP',
+ // 'host' => 'work.std42.ru',
+ // 'user' => 'dio',
+ // 'pass' => '123456',
+ // 'path' => '/'
+ // ),
// array(
// 'driver' => 'FTP',
// 'host' => '192.168.1.35',
diff --git a/php/elFinder.class.php b/php/elFinder.class.php
index 0f9f0c535..891057d63 100644
--- a/php/elFinder.class.php
+++ b/php/elFinder.class.php
@@ -110,7 +110,7 @@ class elFinder {
*
* @var array
**/
- protected $mountErrors = array();
+ public $mountErrors = array();
// Errors messages
const ERROR_UNKNOWN = 'errUnknown';
diff --git a/php/elFinderConnector.class.php b/php/elFinderConnector.class.php
index 7e5fadd97..81fbde8d2 100644
--- a/php/elFinderConnector.class.php
+++ b/php/elFinderConnector.class.php
@@ -61,7 +61,7 @@ class elFinderConnector {
}
if (!$this->elFinder->loaded()) {
- $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL)));
+ $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL), 'debug' => $this->elFinder->mountErrors));
}
// telepat_mode: on
@@ -104,7 +104,7 @@ class elFinderConnector {
protected function output(array $data) {
$header = isset($data['header']) ? $data['header'] : $this->header;
unset($data['header']);
- // debug($data);
+
if ($header) {
if (is_array($header)) {
foreach ($header as $h) {
diff --git a/php/elFinderVolumeDriver.class.php b/php/elFinderVolumeDriver.class.php
index a1504363e..9a98ea34d 100644
--- a/php/elFinderVolumeDriver.class.php
+++ b/php/elFinderVolumeDriver.class.php
@@ -995,8 +995,9 @@ abstract class elFinderVolumeDriver {
if (($dir = $this->file($hash)) == false) {
return $this->setError(elFinder::ERROR_DIR_NOT_FOUND);
}
-
+ // debug($dir);
if ($resolveLink && !empty($dir['thash'])) {
+ echo 'here';
$dir = $this->file($dir['thash']);
}
@@ -1920,10 +1921,12 @@ abstract class elFinderVolumeDriver {
}
/**
- * undocumented function
+ * Put file stat in cache and return it
*
- * @return void
- * @author Dmitry Levashov
+ * @param string $path file path
+ * @param array $stat file stat
+ * @return array
+ * @author Dmitry (dio) Levashov
**/
protected function updateCache($path, $stat) {
if (empty($stat) || !is_array($stat)) {
@@ -2006,10 +2009,27 @@ abstract class elFinderVolumeDriver {
}
/**
- * undocumented function
+ * Get stat for folder content and put in cache
+ *
+ * @param string $path
+ * @return void
+ * @author Dmitry (dio) Levashov
+ **/
+ protected function cacheDir($path) {
+ $this->dirsCache[$path] = array();
+
+ foreach ($this->_scandir($path) as $p) {
+ if (($stat = $this->stat($p)) && empty($stat['hidden'])) {
+ $this->dirsCache[$path][] = $p;
+ }
+ }
+ }
+
+ /**
+ * Clean cache
*
* @return void
- * @author Dmitry Levashov
+ * @author Dmitry (dio) Levashov
**/
protected function clearcache() {
$this->cache = $this->dirsCache = array();
@@ -2179,21 +2199,6 @@ abstract class elFinderVolumeDriver {
return $files;
}
- /**
- * undocumented function
- *
- * @return void
- * @author Dmitry Levashov
- **/
- protected function cacheDir($path) {
- $this->dirsCache[$path] = array();
-
- foreach ($this->_scandir($path) as $p) {
- if (($stat = $this->stat($p)) && empty($stat['hidden'])) {
- $this->dirsCache[$path][] = $p;
- }
- }
- }
/**
* Return subdirs tree
diff --git a/php/elFinderVolumeFTP.class.php b/php/elFinderVolumeFTP.class.php
index d767d2881..2e62a3eb0 100644
--- a/php/elFinderVolumeFTP.class.php
+++ b/php/elFinderVolumeFTP.class.php
@@ -85,7 +85,8 @@ class elFinderVolumeFTP extends elFinderVolumeDriver {
'port' => 21,
'mode' => 'passive',
'path' => '/',
- 'timeout' => 10
+ 'timeout' => 10,
+ 'owner' => true
);
$this->options = array_merge($this->options, $opts);
$this->options['mimeDetect'] = 'internal';
@@ -125,15 +126,18 @@ class elFinderVolumeFTP extends elFinderVolumeDriver {
}
$this->rootName = $this->options['alias'];
- return $this->connect();
+ $this->options['separator'] = '/';
+ return
+ $this->connect();
- // debug($this->stat($this->root));
- $this->stat($this->root);
+ debug($this->stat($this->root));
+ // $this->stat($this->root);
- $this->gettree($this->root, 0);
- // $this->getScandir($this->root);
- debug($this->getScandir($this->root));
+ // $this->gettree($this->root, 0);
// $this->getScandir($this->root);
+ // debug($this->_scandir($this->root));
+ // debug($this->getScandir($this->root));
+ $this->getScandir($this->root);
return false;
}
@@ -216,33 +220,62 @@ class elFinderVolumeFTP extends elFinderVolumeDriver {
protected function parseRaw($raw) {
$info = preg_split("/\s+/", $raw, 9);
$stat = array();
-
+
if (count($info) < 9 || $info[8] == '.' || $info[8] == '..') {
return false;
}
- // debug($info);
+
if (!isset($this->ftpOsUnix)) {
$this->ftpOsUnix = !preg_match('/\d/', substr($info[0], 0, 1));
}
if ($this->ftpOsUnix) {
- $perm = $this->parsePermissions($info[0]);
- $stat['name'] = $info[8];
- $stat['mime'] = substr(strtolower($info[0]), 0, 1) == 'd' ? 'directory' : $this->mimetype($stat['name']);
- $stat['size'] = $stat['mime'] == 'directory' ? 0 : $info[4];
- $stat['read'] = $perm['read'];
- $stat['write'] = $perm['write'];
$stat['ts'] = strtotime($info[5].' '.$info[6].' '.$info[7]);
if (empty($stat['ts'])) {
$stat['ts'] = strtotime($info[6].' '.$info[5].' '.$info[7]);
}
- // $stat['d'] = date('d.m.Y H:i', $stat['ts']);
+ $name = $info[8];
+
+ if (preg_match('|(.+)\-\>(.+)|', $name, $m)) {
+ $name = trim($m[1]);
+ $target = trim($m[2]);
+ if (substr($target, 0, 1) != '/') {
+ $target = $this->root.'/'.$target;
+ }
+ $target = $this->_normpath($target);
+ $stat['name'] = $name;
+ if ($this->_inpath($target, $this->root)
+ && ($tstat = $this->stat($target))) {
+ $stat['size'] = $tstat['mime'] == 'directory' ? 0 : $info[4];
+ $stat['alias'] = $this->_relpath($target);
+ $stat['thash'] = $tstat['hash'];
+ $stat['mime'] = $tstat['mime'];
+ $stat['read'] = $tstat['read'];
+ $stat['write'] = $tstat['write'];
+ } else {
+
+ $stat['mime'] = 'symlink-broken';
+ $stat['read'] = false;
+ $stat['write'] = false;
+ $stat['size'] = 0;
+
+ }
+ return $stat;
+ }
+
+ $perm = $this->parsePermissions($info[0]);
+ $stat['name'] = $name;
+ $stat['mime'] = substr(strtolower($info[0]), 0, 1) == 'd' ? 'directory' : $this->mimetype($stat['name']);
+ $stat['size'] = $stat['mime'] == 'directory' ? 0 : $info[4];
+ $stat['read'] = $perm['read'];
+ $stat['write'] = $perm['write'];
+ $stat['perm'] = substr($info[0], 1);
} else {
}
- // echo $stat['name'].' '.$stat['mime'].'
';
+
return $stat;
}
@@ -253,17 +286,18 @@ class elFinderVolumeFTP extends elFinderVolumeDriver {
* @author Dmitry Levashov
**/
protected function parsePermissions($perm) {
- $res = array();
+ $res = array();
$parts = array();
+ $owner = $this->options['owner'];
for ($i = 0, $l = strlen($perm); $i < $l; $i++) {
$parts[] = substr($perm, $i, 1);
}
-
- $read = $parts[0] == 'r' || $parts[4] == 'r' || $parts[7] == 'r';
+
+ $read = ($owner && $parts[0] == 'r') || $parts[4] == 'r' || $parts[7] == 'r';
return array(
- 'read' => $parts[0] == 'd' ? $read && ($parts[3] == 'x' || $parts[6] == 'x' || $parts[9] == 'x') : $read,
- 'write' => $parts[2] == 'w' || $parts[5] == 'w' || $parts[8] == 'w'
+ 'read' => $parts[0] == 'd' ? $read && (($owner && $parts[3] == 'x') || $parts[6] == 'x' || $parts[9] == 'x') : $read,
+ 'write' => ($owner && $parts[2] == 'w') || $parts[5] == 'w' || $parts[8] == 'w'
);
}
@@ -275,7 +309,7 @@ class elFinderVolumeFTP extends elFinderVolumeDriver {
**/
protected function cacheDir($path) {
$this->dirsCache[$path] = array();
- // echo "cacheDir $path
";
+
foreach (ftp_rawlist($this->connect, $path) as $raw) {
if (($stat = $this->parseRaw($raw))) {
$p = $path.'/'.$stat['name'];
@@ -419,10 +453,9 @@ class elFinderVolumeFTP extends elFinderVolumeDriver {
* @author Dmitry (dio) Levashov
**/
protected function _inpath($path, $parent) {
- return $path == $parent || strpos($path, $parent.$this->separator) === 0;
+ return $path == $parent || strpos($path, $parent.'/') === 0;
}
-
/***************** file stat ********************/
/**
* Return stat for given path.
@@ -451,7 +484,7 @@ class elFinderVolumeFTP extends elFinderVolumeDriver {
array_pop($parts);
$parts = array_map('strtolower', $parts);
$stat = array();
-
+ // debug($parts);
foreach ($parts as $part) {
list($key, $val) = explode('=', $part);
@@ -472,8 +505,7 @@ class elFinderVolumeFTP extends elFinderVolumeDriver {
break;
case 'unix.mode':
- $stat['read'] = 1;
- $stat['write'] = 1;
+ $stat['chmod'] = $val;
break;
case 'perm':
@@ -492,6 +524,54 @@ class elFinderVolumeFTP extends elFinderVolumeDriver {
if ($stat['mime'] == 'directory') {
$stat['size'] = 0;
}
+
+ if (isset($stat['chmod'])) {
+ $stat['perm'] = '';
+ if ($stat['chmod'][0] == 0) {
+ $stat['chmod'] = substr($stat['chmod'], 1);
+ }
+
+ for ($i = 0; $i <= 2; $i++) {
+ $perm[$i] = array(false, false, false);
+ $n = $stat['chmod'][$i];
+
+ if ($n - 4 >= 0) {
+ $perm[$i][0] = true;
+ $n = $n - 4;
+ $stat['perm'] .= 'r';
+ } else {
+ $stat['perm'] .= '-';
+ }
+
+ if ($n - 2 >= 0) {
+ $perm[$i][1] = true;
+ $n = $n - 2;
+ $stat['perm'] .= 'w';
+ } else {
+ $stat['perm'] .= '-';
+ }
+
+ if ($n - 1 == 0) {
+ $perm[$i][2] = true;
+ $stat['perm'] .= 'x';
+ } else {
+ $stat['perm'] .= '-';
+ }
+
+ $stat['perm'] .= ' ';
+ }
+
+ $stat['perm'] = trim($stat['perm']);
+
+ $owner = $this->options['owner'];
+ $read = ($owner && $perm[0][0]) || $perm[1][0] || $perm[2][0];
+
+ $stat['read'] = $stat['mime'] == 'directory' ? $read && (($owner && $perm[0][2]) || $perm[1][2] || $perm[2][2]) : $read;
+ $stat['write'] = ($owner && $perm[0][1]) || $perm[1][1] || $perm[2][1];
+ unset($stat['chmod']);
+
+ }
+
return $stat;
}