Skip to content

Commit

Permalink
Merge branch '2.x' of github.com:Studio-42/elFinder into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
troex committed Nov 9, 2011
2 parents f6bd434 + 0a77ce5 commit 1cfd899
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 58 deletions.
6 changes: 3 additions & 3 deletions elfinder.src.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@
// url : 'php/connector.php',
url : 'php/connector.php',
// transport : new elFinderSupportVer1(),
getFileCallback : function(files, fm) {
console.log(files);
},
// getFileCallback : function(files, fm) {
// console.log(files);
// },
handlers : {
load : function(e, fm) {
// fm.error('All your base belongs to us >_<')
Expand Down
2 changes: 1 addition & 1 deletion js/commands/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ elFinder.prototype.commands.open = function() {
return dfrd.reject(['errOpen', file.name, 'errPerm']);
}

if (!(url = fm.url(file.thash || file.hash))) {
if (!(url = fm.url(/*file.thash || */file.hash))) {
url = fm.options.url;
url = url + (url.indexOf('?') === -1 ? '?' : '&')
+ (fm.oldAPI ? 'cmd=open&current='+file.phash : 'cmd=file')
Expand Down
14 changes: 1 addition & 13 deletions js/elFinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ window.elFinder = function(node, opts) {
f = data[l];
if (f.name && f.hash && f.mime) {
files[f.hash] = f;
}
}
}
},

Expand Down Expand Up @@ -632,19 +632,7 @@ window.elFinder = function(node, opts) {
if (cwdOptions.url) {
return cwdOptions.url + $.map(this.path2array(hash), function(n) { return encodeURIComponent(n); }).slice(1).join('/')
}

var file = files[hash],
path = '';

if (file.url) {
return file.url;
}

if (cwdOptions.url && (path = this.path(hash))) {
path = path.split(cwdOptions.separator).join('/');
this.log(path)
return cwdOptions.url + path.substr(path.indexOf('/')+1);
}
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion js/elFinder.options.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ elFinder.prototype._options = {
* @type Object
* @default {}
*/
customData : {token : '42', test : 'test'},
customData : {},

/**
* Event listeners to bind on elFinder init
Expand Down
1 change: 1 addition & 0 deletions js/i18n/elfinder.en.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ if (elFinder && elFinder.prototype && typeof(elFinder.prototype.i18) == 'object'
'errArcMaxSize' : 'Archive files exceeds maximum allowed size.',
'errResize' : 'Unable to resize "$1".',
'errUsupportType' : 'Unsupported file type.',
'errNotUTF8Content' : 'File "$1" is not in UTF-8 and cannot be edited.', // added 9.11.2011

/******************************* commands names ********************************/
'cmdarchive' : 'Create archive',
Expand Down
17 changes: 9 additions & 8 deletions php/connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ function validName($name) {

array(
'driver' => 'FTP',
'host' => '192.168.1.36',
'host' => '192.168.1.38',
'user' => 'dio',
'pass' => 'hane',
'path' => '/Users/dio/Documents',
Expand All @@ -322,13 +322,14 @@ function validName($name) {

)
),
// array(
// 'driver' => 'FTP',
// 'host' => 'work.std42.ru',
// 'user' => 'dio',
// 'pass' => '123456',
// 'path' => '/'
// ),
array(
'driver' => 'FTP',
'host' => 'work.std42.ru',
'user' => 'dio',
'pass' => '123456',
'path' => '/',
'tmpPath' => '../files/ftp',
),
// array(
// 'driver' => 'FTP',
// 'host' => '192.168.1.35',
Expand Down
15 changes: 12 additions & 3 deletions php/elFinder.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class elFinder {
const ERROR_ARC_MAXSIZE = 'errArcMaxSize';
const ERROR_RESIZE = 'errResize';
const ERROR_UNSUPPORT_TYPE = 'errUsupportType';
const ERROR_NOT_UTF8_CONTENT = 'errNotUTF8Content';

/**
* Constructor
Expand Down Expand Up @@ -885,9 +886,17 @@ protected function get($args) {
return array('error' => $this->error(self::ERROR_OPEN, '#'.$target, self::ERROR_FILE_NOT_FOUND));
}

return ($content = $volume->getContents($target)) === false
? array('error' => $this->error(self::ERROR_OPEN, $volume->path($target), $volume->error()))
: array('content' => $content);
if (($content = $volume->getContents($target)) === false) {
return array('error' => $this->error(self::ERROR_OPEN, $volume->path($target), $volume->error()));
}

$json = json_encode($content);

if ($json == 'null' && strlen($json) < strlen($content)) {
return array('error' => $this->error(self::ERROR_NOT_UTF8_CONTENT, $volume->path($target)));
}

return array('content' => $content);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion php/elFinderConnector.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function run() {
protected function output(array $data) {
$header = isset($data['header']) ? $data['header'] : $this->header;
unset($data['header']);
ob_end_clean();
// ob_end_clean();
if ($header) {
if (is_array($header)) {
foreach ($header as $h) {
Expand Down
4 changes: 2 additions & 2 deletions php/elFinderVolumeDriver.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ public function upload($fp, $dst, $name, $tmpname) {
$w = $s[0];
$h = $s[1];
}

// $this->clearcache();
if (($path = $this->_save($fp, $dstpath, $name, $mime, $w, $h)) == false) {
return false;
}
Expand All @@ -1373,7 +1373,7 @@ public function upload($fp, $dst, $name, $tmpname) {
if (isset($removed)) {
$this->removed[] = $removed;
}

return $this->stat($path);
}

Expand Down
56 changes: 30 additions & 26 deletions php/elFinderVolumeFTP.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,16 +660,13 @@ protected function _fopen($path, $mode='rb') {

if ($this->tmp) {
$local = $this->tmp.DIRECTORY_SEPARATOR.md5($path);
// $local = $this->tmp.DIRECTORY_SEPARATOR.basename($path);
// $mime = $this->mimetype(basename($path));

if (ftp_get($this->connect, $local, $path, FTP_BINARY)) {
return @fopen($local, 'r');
return @fopen($local, $mode);
}
}

return false;

return @fopen($path, $mode);
}

/**
Expand Down Expand Up @@ -834,20 +831,10 @@ protected function _rmdir($path) {
* @author Dmitry (dio) Levashov
**/
protected function _save($fp, $dir, $name, $mime, $w, $h) {
die('Not yet implemented. (_save)');
$path = $dir.DIRECTORY_SEPARATOR.$name;

if (!($target = @fopen($path, 'wb'))) {
return false;
}

while (!feof($fp)) {
fwrite($target, fread($fp, 8192));
}
fclose($target);
@chmod($path, $this->options['fileMode']);
clearstatcache();
return $path;
$path = $dir.'/'.$name;
return ftp_fput($this->connect, $path, $fp, strpos($this->mimetype($path), 'text/') === 0 ? FTP_ASCII : FTP_BINARY)
? $path
: false;
}

/**
Expand All @@ -858,8 +845,15 @@ protected function _save($fp, $dir, $name, $mime, $w, $h) {
* @author Dmitry (dio) Levashov
**/
protected function _getContents($path) {
ie('Not yet implemented. (_getContents)');
return file_get_contents($path);
$contents = '';
if (($fp = $this->_fopen($path))) {
while (!feof($fp)) {
$contents .= fread($fp, 8192);
}
$this->_fclose($fp, $path);
return $contents;
}
return false;
}

/**
Expand All @@ -871,12 +865,22 @@ protected function _getContents($path) {
* @author Dmitry (dio) Levashov
**/
protected function _filePutContents($path, $content) {
die('Not yet implemented. (_filePutContents)');
if (@file_put_contents($path, $content, LOCK_EX) !== false) {
clearstatcache();
return true;
$res = false;

if ($this->tmp) {
$local = $this->tmp.DIRECTORY_SEPARATOR.md5($path).'.txt';

if (@file_put_contents($local, $content, LOCK_EX) !== false
&& ($fp = @fopen($local, 'rb'))) {
clearstatcache();
$mode = strpos($this->mimetype($path), 'text/') === 0 ? FTP_ASCII : FTP_BINARY;
$res = ftp_fput($this->connect, $path, $fp, $mode);
@fclose($fp);
}
file_exists($local) && @unlink($local);
}
return false;

return $res;
}

/**
Expand Down

0 comments on commit 1cfd899

Please sign in to comment.