[VD:LocalFileSystem] fix nao-pon/elFinder#15 doSearch of non UTF-8

This commit is contained in:
nao-pon
2015-12-16 20:36:30 +09:00
parent deb001d060
commit d0a4ee8c35
2 changed files with 21 additions and 11 deletions
+20 -10
View File
@@ -453,6 +453,7 @@ class elFinderVolumeLocalFileSystem extends elFinderVolumeDriver {
protected function _subdirs($path) {
if (is_dir($path)) {
$path = strtr($path, array('[' => '\\[', ']' => '\\]', '*' => '\\*', '?' => '\\?'));
return (bool)glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR);
}
return false;
@@ -1014,15 +1015,27 @@ class elFinderVolumeLocalFileSystem extends elFinderVolumeDriver {
* @author Naoki Sawada
**/
protected function doSearch($path, $q, $mimes) {
if ($this->encoding) {
// non UTF-8 has problem of glob() results
return parent::doSearch($path, $q, $mimes);
}
static $escaper;
if (!$escaper) {
$escaper = array(
'[' => '\\[',
']' => '\\]',
'*' => '\\*',
'?' => '\\?'
);
}
$result = array();
$path = $this->convEncIn($path);
$path = strtr($path, $escaper);
$_q = strtr($q, $escaper);
$dirs = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR);
$match = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*'.$q.'*', GLOB_NOSORT);
if ($dirs) {
$dirs = $this->convEncOut($dirs, false);
}
$match = $this->convEncOut($match);
$match = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*'.$_q.'*', GLOB_NOSORT);
if ($match) {
foreach($match as $p) {
$stat = $this->stat($p);
@@ -1041,9 +1054,6 @@ class elFinderVolumeLocalFileSystem extends elFinderVolumeDriver {
$stat['path'] = $this->path($stat['hash']);
if ($this->URL && !isset($stat['url'])) {
$path = str_replace(DIRECTORY_SEPARATOR, '/', substr($p, strlen($this->root) + 1));
if ($this->encoding) {
$path = str_replace('%2F', '/', rawurlencode($this->convEncIn($path, true)));
}
$stat['url'] = $this->URL . $path;
}