1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 06:07:32 +02:00

get_files() fix.

This commit is contained in:
Cameron
2020-12-26 12:02:52 -08:00
parent c9ce6e1bd0
commit 30ac723fa2
3 changed files with 46 additions and 49 deletions

View File

@@ -229,7 +229,7 @@
{ {
$ret = array(); $ret = array();
$invert = false; $invert = false;
if(strpos($fmask,'~') === 0) if(substr($fmask, 0, 1) == '~')
{ {
$invert = true; // Invert selection - exclude files which match selection $invert = true; // Invert selection - exclude files which match selection
$fmask = substr($fmask, 1); $fmask = substr($fmask, 1);
@@ -270,17 +270,19 @@
continue; continue;
} }
if(($recurse_level > 0) && !in_array($file, $this->dirFilter) && !in_array($file, $omit) && is_dir($path . '/' . $file)) if(is_dir($path . '/' . $file))
{ // Its a directory - recurse into it unless a filtered directory or required depth achieved
// Must always check for '.' and '..'
if(($recurse_level > 0) && !in_array($file, $this->dirFilter) && !in_array($file, $omit))
{ {
// Its a directory - recurse into it unless a filtered directory or required depth achieved
$xx = $this->get_files($path . '/' . $file, $fmask, $omit, $recurse_level - 1); $xx = $this->get_files($path . '/' . $file, $fmask, $omit, $recurse_level - 1);
$ret = array_merge($ret, $xx); $ret = array_merge($ret, $xx);
}
} }
else else
{ {
// Now check against standard reject list and caller-specified list // Now check against standard reject list and caller-specified list
if(empty($fmask) || ($invert != preg_match("#" . $fmask . "#", $file))) if(($fmask == '') || ($invert != preg_match("#" . $fmask . "#", $file)))
{ // File passes caller's filter here { // File passes caller's filter here
$rejected = false; $rejected = false;
@@ -430,8 +432,6 @@
*/ */
public function get_file_info($path_to_file, $imgcheck = true, $auto_fix_ext = true) public function get_file_info($path_to_file, $imgcheck = true, $auto_fix_ext = true)
{ {
trigger_error('<b>'.__METHOD__.' is deprecated.</b> Use getFileInfo() instead.', E_USER_DEPRECATED); // NO LAN
return $this->getFileInfo($path_to_file, $imgcheck, $auto_fix_ext); return $this->getFileInfo($path_to_file, $imgcheck, $auto_fix_ext);
} }
@@ -538,7 +538,7 @@
{ {
if(E107_DEBUG_LEVEL > 0) if(E107_DEBUG_LEVEL > 0)
{ {
e107::getLog()->addDebug('getRemoteFile() requires cURL to be installed in file_class.php'); e107::getAdminLog()->addDebug('getRemoteFile() requires cURL to be installed in file_class.php');
} }
return false; // May not be installed return false; // May not be installed
@@ -811,12 +811,7 @@
while(false !== ($file = readdir($handle))) while(false !== ($file = readdir($handle)))
{ {
if($file === '.' || $file === '..' || in_array($file, $this->dirFilter) || in_array($file, $omit)) if(($file != '.') && ($file != '..') && !in_array($file, $this->dirFilter) && !in_array($file, $omit) && is_dir($path . '/' . $file) && ($fmask == '' || preg_match("#" . $fmask . "#", $file)))
{
continue;
}
if(is_dir($path . '/' . $file) && ($fmask == '' || preg_match("#" . $fmask . "#", $file)))
{ {
$ret[] = $file; $ret[] = $file;
} }
@@ -834,7 +829,7 @@
function rmtree($dir) function rmtree($dir)
{ {
if(substr($dir, -1) !== '/') if(substr($dir, -1) != '/')
{ {
$dir .= '/'; $dir .= '/';
} }
@@ -842,11 +837,8 @@
{ {
while($obj = readdir($handle)) while($obj = readdir($handle))
{ {
if($obj === '.' || $obj === '..') if($obj != '.' && $obj != '..')
{ {
continue;
}
if(is_dir($dir . $obj)) if(is_dir($dir . $obj))
{ {
if(!$this->rmtree($dir . $obj)) if(!$this->rmtree($dir . $obj))
@@ -861,7 +853,7 @@
return false; return false;
} }
} }
}
} }
closedir($handle); closedir($handle);
@@ -958,39 +950,34 @@
{ {
$size = filesize($size); $size = filesize($size);
} }
$kb = 1024; $kb = 1024;
$mb = 1024 * $kb; $mb = 1024 * $kb;
$gb = 1024 * $mb; $gb = 1024 * $mb;
$tb = 1024 * $gb; $tb = 1024 * $gb;
if(!$size) if(!$size)
{ {
return '0&nbsp;' . CORE_LAN_B; return '0&nbsp;' . CORE_LAN_B;
} }
if($size < $kb) if($size < $kb)
{ {
$ret = $size . "&nbsp;" . CORE_LAN_B; return $size . "&nbsp;" . CORE_LAN_B;
} }
elseif($size < $mb) elseif($size < $mb)
{ {
$ret = round($size / $kb, $decimal) . "&nbsp;" . CORE_LAN_KB; return round($size / $kb, $decimal) . "&nbsp;" . CORE_LAN_KB;
} }
elseif($size < $gb) elseif($size < $gb)
{ {
$ret = round($size / $mb, $decimal) . "&nbsp;" . CORE_LAN_MB; return round($size / $mb, $decimal) . "&nbsp;" . CORE_LAN_MB;
} }
elseif($size < $tb) elseif($size < $tb)
{ {
$ret = round($size / $gb, $decimal) . "&nbsp;" . CORE_LAN_GB; return round($size / $gb, $decimal) . "&nbsp;" . CORE_LAN_GB;
} }
else else
{ {
$ret = round($size / $tb, 2) . "&nbsp;" . CORE_LAN_TB; return round($size / $tb, 2) . "&nbsp;" . CORE_LAN_TB;
} }
return $ret;
} }
@@ -1141,7 +1128,7 @@
} }
else else
{ {
e107::redirect(); // ("location: {$e107->base_path}"); header("location: {$e107->base_path}");
exit(); exit();
} }
} }
@@ -1202,7 +1189,7 @@
} }
else else
{ {
e107::redirect(); header("location: " . e_BASE . "index.php");
exit(); exit();
} }
} }
@@ -1314,7 +1301,7 @@
if($archive->create($filePaths, PCLZIP_OPT_REMOVE_PATH, $removePath) == 0) if($archive->create($filePaths, PCLZIP_OPT_REMOVE_PATH, $removePath) == 0)
{ {
$error = $archive->errorInfo(true); $error = $archive->errorInfo(true);
e107::getLog()->addError($error)->save('FILE', E_LOG_NOTICE); e107::getAdminLog()->addError($error)->save('FILE', E_LOG_NOTICE);
return false; return false;
} }
@@ -1584,7 +1571,7 @@
// print_a($headers); // print_a($headers);
return (stripos($headers[0], "200 OK") || strpos($headers[0], "302")); return (stripos($headers[0], "200 OK") || strpos($headers[0], "302")) ? true : false;
} }
@@ -1867,7 +1854,7 @@
} }
return compact('success', 'error', 'skipped'); return array('success' => $success, 'error' => $error, 'skipped' => $skipped);
} }

View File

@@ -346,6 +346,9 @@
$result = $this->dta->get_current_table('core'); $result = $this->dta->get_current_table('core');
$this->assertSame($result,$expected); $this->assertSame($result,$expected);
} }

View File

@@ -421,6 +421,13 @@ class e_fileTest extends \Codeception\Test\Unit
$this->assertNotContains('style.css', $files); $this->assertNotContains('style.css', $files);
// test folder with ony a folder inside. (no files)
$publicFilter = array('_FT', '^thumbs\.db$','^Thumbs\.db$','.*\._$','^\.htaccess$','^\.cvsignore$','^\.ftpquota$','^index\.html$','^null\.txt$','\.bak$','^.tmp'); // Default file filter (regex format)
$result = $this->fl->get_files(e_DOCS,'',$publicFilter);
$expected = array();
$this->assertSame($expected, $result);
} }
/* /*
public function testGetUserDir() public function testGetUserDir()