Minor refactoring of "Shared\ZipArchive" class.
This commit is contained in:
parent
e31f080ea6
commit
3d06c77fc1
|
|
@ -158,7 +158,7 @@ class ZipArchive
|
||||||
{
|
{
|
||||||
if (!$this->usePclzip) {
|
if (!$this->usePclzip) {
|
||||||
if ($this->zip->close() === false) {
|
if ($this->zip->close() === false) {
|
||||||
throw new Exception("Could not close zip file $this->filename.");
|
throw new Exception("Could not close zip file {$this->filename}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,7 +233,7 @@ class ZipArchive
|
||||||
$tempFile = false;
|
$tempFile = false;
|
||||||
if ($filenameParts['basename'] != $localnameParts['basename']) {
|
if ($filenameParts['basename'] != $localnameParts['basename']) {
|
||||||
$tempFile = true; // temp file created
|
$tempFile = true; // temp file created
|
||||||
$temppath = $this->tempDir . '/' . $localnameParts['basename'];
|
$temppath = $this->tempDir . DIRECTORY_SEPARATOR . $localnameParts['basename'];
|
||||||
copy($filename, $temppath);
|
copy($filename, $temppath);
|
||||||
$filename = $temppath;
|
$filename = $temppath;
|
||||||
$filenameParts = pathinfo($temppath);
|
$filenameParts = pathinfo($temppath);
|
||||||
|
|
@ -246,7 +246,7 @@ class ZipArchive
|
||||||
|
|
||||||
if ($tempFile) {
|
if ($tempFile) {
|
||||||
// Remove temp file, if created
|
// Remove temp file, if created
|
||||||
@unlink($this->tempDir . '/' . $localnameParts["basename"]);
|
unlink($this->tempDir . DIRECTORY_SEPARATOR . $localnameParts['basename']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($res == 0) ? false : true;
|
return ($res == 0) ? false : true;
|
||||||
|
|
@ -266,19 +266,19 @@ class ZipArchive
|
||||||
$filenameParts = pathinfo($localname);
|
$filenameParts = pathinfo($localname);
|
||||||
|
|
||||||
// Write $contents to a temp file
|
// Write $contents to a temp file
|
||||||
$handle = fopen($this->tempDir . '/' . $filenameParts["basename"], "wb");
|
$handle = fopen($this->tempDir . DIRECTORY_SEPARATOR . $filenameParts['basename'], 'wb');
|
||||||
fwrite($handle, $contents);
|
fwrite($handle, $contents);
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
|
|
||||||
// Add temp file to zip
|
// Add temp file to zip
|
||||||
$filename = $this->tempDir . '/' . $filenameParts["basename"];
|
$filename = $this->tempDir . DIRECTORY_SEPARATOR . $filenameParts['basename'];
|
||||||
$pathRemoved = $this->tempDir;
|
$pathRemoved = $this->tempDir;
|
||||||
$pathAdded = $filenameParts['dirname'];
|
$pathAdded = $filenameParts['dirname'];
|
||||||
|
|
||||||
$res = $zip->add($filename, PCLZIP_OPT_REMOVE_PATH, $pathRemoved, PCLZIP_OPT_ADD_PATH, $pathAdded);
|
$res = $zip->add($filename, PCLZIP_OPT_REMOVE_PATH, $pathRemoved, PCLZIP_OPT_ADD_PATH, $pathAdded);
|
||||||
|
|
||||||
// Remove temp file
|
// Remove temp file
|
||||||
@unlink($this->tempDir . '/' . $filenameParts["basename"]);
|
@unlink($this->tempDir . DIRECTORY_SEPARATOR . $filenameParts['basename']);
|
||||||
|
|
||||||
return ($res == 0) ? false : true;
|
return ($res == 0) ? false : true;
|
||||||
}
|
}
|
||||||
|
|
@ -338,7 +338,7 @@ class ZipArchive
|
||||||
$extracted = $zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING);
|
$extracted = $zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING);
|
||||||
}
|
}
|
||||||
if ((is_array($extracted)) && ($extracted != 0)) {
|
if ((is_array($extracted)) && ($extracted != 0)) {
|
||||||
$contents = $extracted[0]["content"];
|
$contents = $extracted[0]['content'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $contents;
|
return $contents;
|
||||||
|
|
@ -377,8 +377,8 @@ class ZipArchive
|
||||||
$listCount = count($list);
|
$listCount = count($list);
|
||||||
$listIndex = -1;
|
$listIndex = -1;
|
||||||
for ($i = 0; $i < $listCount; ++$i) {
|
for ($i = 0; $i < $listCount; ++$i) {
|
||||||
if (strtolower($list[$i]["filename"]) == strtolower($filename) ||
|
if (strtolower($list[$i]['filename']) == strtolower($filename) ||
|
||||||
strtolower($list[$i]["stored_filename"]) == strtolower($filename)) {
|
strtolower($list[$i]['stored_filename']) == strtolower($filename)) {
|
||||||
$listIndex = $i;
|
$listIndex = $i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue