1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-26 09:20:28 +02:00

Issue #5208 - Start of PCLZip removal.

This commit is contained in:
camer0n
2024-04-17 14:17:04 -07:00
parent 15e717b66e
commit bdbda018d2
2 changed files with 2320 additions and 2278 deletions

View File

@@ -244,6 +244,7 @@ class e_file
*/
function get_files($path, $fmask = '', $omit = 'standard', $recurse_level = 0)
{
$ret = array();
$invert = false;
if(!empty($fmask) && strpos($fmask, '~') === 0)
@@ -441,14 +442,16 @@ class e_file
/**
* Return information about a file, including mime-type
* @deprecated - use getFileInfo() instead.
*
* @param string $path_to_file
* @param bool $imgcheck
* @param bool $auto_fix_ext
* @return array|bool
* @deprecated - use getFileInfo() instead.
*/
public function get_file_info($path_to_file, $imgcheck = true, $auto_fix_ext = true)
{
return $this->getFileInfo($path_to_file, $imgcheck, $auto_fix_ext);
}
@@ -560,6 +563,7 @@ class e_file
}
error_log($msg);
return false; // May not be installed
}
@@ -1321,6 +1325,37 @@ class e_file
}
private function addToZip(ZipArchive $zip, $src, $localname)
{
if(is_dir($src))
{
$dir = opendir($src);
// add empty directories
$zip->addEmptyDir($localname);
while(false !== ($file = readdir($dir)))
{
if(($file != '.') && ($file != '..'))
{
$this->addToZip($zip, $src . '/' . $file, $localname . '/' . $file);
}
}
closedir($dir);
}
elseif(is_file($src))
{
if(!$zip->addFile($src, $localname))
{
$this->error = "Could not add file: $src";
e107::getLog()->addError($this->error)->save('FILE', E_LOG_NOTICE);
}
}
}
/**
* Zip up folders and files
*
@@ -1331,7 +1366,6 @@ class e_file
*/
public function zip($filePaths = null, $newFile = '', $options = array())
{
if(empty($newFile))
{
$newFile = e_BACKUP . eHelper::title2sef(SITENAME) . "_" . date("Y-m-d-H-i-s") . ".zip";
@@ -1342,22 +1376,27 @@ class e_file
return "No file-paths set!";
}
require_once(e_HANDLER . 'pclzip.lib.php');
$archive = new PclZip($newFile);
$zip = new ZipArchive();
$removePath = (!empty($options['remove_path'])) ? $options['remove_path'] : e_BASE;
if($archive->create($filePaths, PCLZIP_OPT_REMOVE_PATH, $removePath) == 0)
if($zip->open($newFile, ZipArchive::CREATE) !== true)
{
$error = $archive->errorInfo(true);
e107::getLog()->addError($error)->save('FILE', E_LOG_NOTICE);
$this->error = "Cannot open <$newFile>\n";
e107::getLog()->addError($this->error)->save('FILE', E_LOG_NOTICE);
return false;
}
else
$removePath = (!empty($options['remove_path'])) ? $options['remove_path'] : e_BASE;
foreach($filePaths as $file)
{
return $newFile;
$localname = str_replace($removePath, '', $file);
$this->addToZip($zip, $file, rtrim($localname, '/'));
}
$zip->close();
return $newFile;
}
@@ -1684,14 +1723,14 @@ class e_file
}
else // Legacy Method.
/* else // Legacy Method.
{
require_once(e_HANDLER . "pclzip.lib.php");
$archive = new PclZip(e_TEMP . $localfile);
$unarc = ($fileList = $archive->extract(PCLZIP_OPT_PATH, e_TEMP, PCLZIP_OPT_SET_CHMOD, 0755)); // Store in TEMP first.
$dir = $this->getRootFolder($unarc);
}
}*/
$destpath = ($type == 'theme') ? e_THEME : e_PLUGIN;
@@ -1761,14 +1800,14 @@ class e_file
/**
* @deprecated Use getAllowedFileTypes()
* Get an array of permitted filetypes according to a set hierarchy.
* If a specific file name given, that's used. Otherwise the default hierarchy is used
*
* @param string|boolean $file_mask - comma-separated list of allowed file types
* @param string $filename - optional override file name - defaults ignored
*
* @return array of filetypes
* @deprecated Use getAllowedFileTypes()
* Get an array of permitted filetypes according to a set hierarchy.
* If a specific file name given, that's used. Otherwise the default hierarchy is used
*
*/
function getFiletypeLimits($file_mask = false, $filename = '') // Wrapper only for now.
{
@@ -1877,8 +1916,10 @@ class e_file
foreach($unarc as $k => $v)
{
if($this->matchFound($v['stored_filename'], $excludeMatch) ||
in_array($v['stored_filename'], $excludes))
if(
$this->matchFound($v['stored_filename'], $excludeMatch) ||
in_array($v['stored_filename'], $excludes)
)
{
$skipped[] = $v['stored_filename'];
continue;
@@ -2278,6 +2319,7 @@ class e_file
*/
private function getMimeTypes()
{
return array(
'asc' => 'text/plain',
'css' => 'text/css',
@@ -2413,15 +2455,15 @@ class e_file
}
/**
* Return the mime-type based on the file's extension.
*
* @param string $filename
* @return string
*/
public function getMime($filename)
{
$filename = basename($filename);
$tmp = explode('.', $filename);

View File

@@ -436,7 +436,7 @@ class e_jsmanagerTest extends \Codeception\Test\Unit
}
$tp->setStaticUrl(null);
e107::getParser()->setStaticUrl(null);
}
/*