Skip to content

Commit

Permalink
connector - abstract driver fixed. FTP driver - open dir works
Browse files Browse the repository at this point in the history
  • Loading branch information
dio-el-claire committed Nov 4, 2011
1 parent 989e213 commit 56d08a5
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 227 deletions.
141 changes: 76 additions & 65 deletions php/connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,83 +240,94 @@ function validName($name) {

'roots' => array(

// array(
// 'driver' => 'LocalFileSystem',
// 'path' => '../files/',
// 'URL' => dirname($_SERVER['PHP_SELF']) . '/../files/',
// // 'alias' => 'File system',
// 'mimeDetect' => 'internal',
// 'tmbPath' => '.tmb',
// 'utf8fix' => true,
// 'tmbCrop' => false,
// 'startPath' => '../files/test',
// // 'deep' => 3,
// // 'separator' => ':',
// 'attributes' => array(
// array(
// 'pattern' => '~/\.~',
// // 'pattern' => '/^\/\./',
// 'read' => false,
// 'write' => false,
// 'hidden' => true,
// 'locked' => false
// ),
// array(
// 'pattern' => '~/replace/.+png$~',
// // 'pattern' => '/^\/\./',
// 'read' => false,
// 'write' => false,
// // 'hidden' => true,
// 'locked' => true
// )
// ),
// // 'defaults' => array('read' => false, 'write' => true)
// ),
// array(
// 'driver' => 'LocalFileSystem',
// 'path' => '../files2/',
// 'URL' => dirname($_SERVER['PHP_SELF']) . '/../files2/',
// 'alias' => 'File system',
// 'mimeDetect' => 'internal',
// 'tmbPath' => '.tmb',
// 'utf8fix' => true,
// 'tmbCrop' => false,
// 'startPath' => '../files/test',
// // 'separator' => ':',
// 'attributes' => array(
// array(
// 'pattern' => '~/\.~',
// // 'pattern' => '/^\/\./',
// 'read' => false,
// 'write' => false,
// 'hidden' => true,
// 'locked' => false
// ),
// array(
// 'pattern' => '~/replace/.+png$~',
// // 'pattern' => '/^\/\./',
// 'read' => false,
// 'write' => false,
// // 'hidden' => true,
// 'locked' => true
// )
// ),
// // 'defaults' => array('read' => false, 'write' => true)
// ),

array(
'driver' => 'LocalFileSystem',
'path' => '../files/',
'URL' => dirname($_SERVER['PHP_SELF']) . '/../files/',
// 'alias' => 'File system',
'mimeDetect' => 'internal',
'tmbPath' => '.tmb',
'utf8fix' => true,
'tmbCrop' => false,
'startPath' => '../files/test',
// 'separator' => ':',
'driver' => 'FTP',
'host' => '192.168.1.36',
'user' => 'dio',
'pass' => 'hane',
'path' => '/Users/dio/Documents',
'attributes' => array(
array(
'pattern' => '~/\.~',
// 'pattern' => '/^\/\./',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
array(
'pattern' => '~/replace/.+png$~',
// 'pattern' => '/^\/\./',
'read' => false,
'write' => false,
// 'hidden' => true,
'locked' => true
)
),
// 'defaults' => array('read' => false, 'write' => true)

)
),
array(
'driver' => 'LocalFileSystem',
'path' => '../files2/',
'URL' => dirname($_SERVER['PHP_SELF']) . '/../files2/',
'alias' => 'File system',
'mimeDetect' => 'internal',
'tmbPath' => '.tmb',
'utf8fix' => true,
'tmbCrop' => false,
'startPath' => '../files/test',
// 'separator' => ':',
'attributes' => array(
array(
'pattern' => '~/\.~',
// 'pattern' => '/^\/\./',
'read' => false,
'write' => false,
'hidden' => true,
'locked' => false
),
array(
'pattern' => '~/replace/.+png$~',
// 'pattern' => '/^\/\./',
'read' => false,
'write' => false,
// 'hidden' => true,
'locked' => true
)
),
// 'defaults' => array('read' => false, 'write' => true)
'driver' => 'FTP',
'host' => 'work.std42.ru',
'user' => 'dio',
'pass' => '123456',
'path' => '/'
),

// array(
// 'driver' => 'FTP',
// 'host' => '192.168.1.37',
// 'user' => 'dio',
// 'pass' => 'hane',
// 'path' => '/Users/dio/Sites'
// ),
// array(
// 'driver' => 'FTP',
// 'host' => 'work.std42.ru',
// 'user' => 'dio',
// 'pass' => '123456',
// 'path' => '/'
// ),
// array(
// 'driver' => 'FTP',
// 'host' => '192.168.1.35',
Expand Down
2 changes: 1 addition & 1 deletion php/elFinderConnector.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function run() {
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) {
Expand Down
74 changes: 38 additions & 36 deletions php/elFinderVolumeDriver.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,15 @@ public function mount(array $opts) {
$this->access = array($this->options['accessControl'][0], $this->options['accessControl'][1]);
}
}

$this->today = mktime(0,0,0, date('m'), date('d'), date('Y'));
$this->yesterday = $this->today-86400;

// debug($this->attributes);
if (!$this->init()) {
return false;
}

$this->today = mktime(0,0,0, date('m'), date('d'), date('Y'));
$this->yesterday = $this->today-86400;

// check some options is arrays
$this->uploadAllow = isset($this->options['uploadAllow']) && is_array($this->options['uploadAllow'])
? $this->options['uploadAllow']
Expand Down Expand Up @@ -1913,7 +1914,6 @@ protected function attr($path, $name, $val=false) {
* @author Dmitry (dio) Levashov
**/
protected function stat($path) {
// echo 'stat '.$path.'<br>';
return isset($this->cache[$path])
? $this->cache[$path]
: $this->updateCache($path, $this->_stat($path));
Expand All @@ -1929,7 +1929,7 @@ protected function updateCache($path, $stat) {
if (empty($stat) || !is_array($stat)) {
return $this->cache[$path] = array();
}
// echo 'updateCache '.$path.'<br>';

$root = $path == $this->root;

$stat['name'] = $root ? $this->rootName : $this->_basename($path);
Expand All @@ -1950,8 +1950,6 @@ protected function updateCache($path, $stat) {
$stat['mime'] = $this->mimetype($stat['name']);
}



// @todo move dateformat to client
$stat['date'] = isset($stat['ts'])
? $this->formatDate($stat['ts'])
Expand All @@ -1973,7 +1971,7 @@ protected function updateCache($path, $stat) {

if ($stat['read'] && empty($stat['hidden'])) {

if ($stat['mime'] == 'directory') {
if ($stat['mime'] == 'directory' && $stat['read']) {
// for dir - check for subdirs
if ($this->options['checkSubfolders']) {
if (!empty($stat['alias']) && !empty($stat['target'])) {
Expand All @@ -1988,11 +1986,13 @@ protected function updateCache($path, $stat) {
}
} else {
// for files - check for thumbnails
$p = isset($stat['target']) ? $stat['target'] : $path;
if (($tmb = $this->gettmb($p)) != false) {
$stat['tmb'] = $tmb;
} elseif ($this->canCreateTmb($p, $stat['mime'])) {
$stat['tmb'] = 1;
if ($this->tmbURL) {
$p = isset($stat['target']) ? $stat['target'] : $path;
if (($tmb = $this->gettmb($p)) != false) {
$stat['tmb'] = $tmb;
} elseif ($this->canCreateTmb($p, $stat['mime'])) {
$stat['tmb'] = 1;
}
}
}
}
Expand Down Expand Up @@ -2167,27 +2167,34 @@ protected function childsByAttr($path, $attr, $val) {
**/
protected function getScandir($path) {
$files = array();
$paths = isset($this->dirsCache[$path])
? $this->dirsCache[$path]
: $this->_scandir($path);

// if (isset($this->dirsCache[$path])) {
// echo 'scandir from cache '.$path.'<br>';
// } else {
// echo 'scandir '.$path.'<br>';
// }

foreach ($paths as $p) {
$stat = $this->stat($p);
if ($stat && empty($stat['hidden'])) {
!isset($this->dirsCache[$path]) && $this->cacheDir($path);

foreach ($this->dirsCache[$path] as $p) {
if (($stat = $this->stat($p)) && empty($stat['hidden'])) {
$files[] = $stat;
}
}
// debug($files);

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
*
Expand All @@ -2198,18 +2205,13 @@ protected function getScandir($path) {
**/
protected function gettree($path, $deep, $exclude='') {
$dirs = array();

!isset($this->dirsCache[$path]) && $this->cacheDir($path);

$paths = isset($this->dirsCache[$path])
? $this->dirsCache[$path]
: $this->_scandir($path);

foreach ($paths as $p) {
foreach ($this->dirsCache[$path] as $p) {
$stat = $this->stat($p);

if ($path != $exclude
&& $stat
&& empty($stat['hidden'])
&& $stat['mime'] == 'directory') {
if ($stat && empty($stat['hidden']) && $path != $exclude && $stat['mime'] == 'directory') {
$dirs[] = $stat;
if ($deep > 0 && !empty($stat['dirs'])) {
$dirs = array_merge($dirs, $this->gettree($p, $deep-1));
Expand Down
Loading

0 comments on commit 56d08a5

Please sign in to comment.