mirror of
https://github.com/misterunknown/ifm.git
synced 2025-08-10 10:04:01 +02:00
consolidate zip class, remove unzip function from main class
This commit is contained in:
34
ifm.php
34
ifm.php
@@ -108,6 +108,9 @@ class IFMConfig {
|
||||
*/
|
||||
|
||||
class IFMZip {
|
||||
/**
|
||||
* Add a folder to the zip file
|
||||
*/
|
||||
private static function folderToZip($folder, &$zipFile, $exclusiveLength) {
|
||||
$handle = opendir( $folder );
|
||||
while( false !== $f = readdir( $handle ) ) {
|
||||
@@ -129,7 +132,10 @@ class IFMZip {
|
||||
closedir( $handle );
|
||||
}
|
||||
|
||||
public static function create_zip( $src, $out, $root=false )
|
||||
/**
|
||||
* Create a zip file
|
||||
*/
|
||||
public static function create( $src, $out, $root=false )
|
||||
{
|
||||
$z = new ZipArchive();
|
||||
$z->open( $out, ZIPARCHIVE::CREATE);
|
||||
@@ -148,11 +154,14 @@ class IFMZip {
|
||||
}
|
||||
}
|
||||
|
||||
public static function unzip_file( $file ) {
|
||||
$zip = new ZipArchive();
|
||||
/**
|
||||
* Unzip a zip file
|
||||
*/
|
||||
public function extract( $file, $destination="./" ) {
|
||||
$zip = new ZipArchive;
|
||||
$res = $zip->open( $file );
|
||||
if( $res === true ) {
|
||||
$zip->extractTo( './' );
|
||||
$zip->extractTo( $destination );
|
||||
$zip->close();
|
||||
return true;
|
||||
} else {
|
||||
@@ -1779,7 +1788,7 @@ ifm.init();
|
||||
echo json_encode( array( "status" => "ERROR","message" => "Could not create target directory." ) );
|
||||
exit( 1 );
|
||||
}
|
||||
if( ! $this->unzip( $d['filename'], $d['targetdir'] ) ) {
|
||||
if( ! IFMZip::extract( $d['filename'], $d['targetdir'] ) ) {
|
||||
echo json_encode( array( "status" => "ERROR","message" => "File could not be extracted" ) );
|
||||
} else {
|
||||
echo json_encode( array( "status" => "OK","message" => "File successfully extracted." ) );
|
||||
@@ -1871,7 +1880,7 @@ ifm.init();
|
||||
unset( $zip );
|
||||
$dfile = $this->pathCombine( IFMConfig::tmp_dir, uniqid( "ifm-tmp-" ) . ".zip" ); // temporary filename
|
||||
try {
|
||||
IFMZip::create_zip( realpath( $d['filename'] ), $dfile, ( $d['filename'] == "." ) );
|
||||
IFMZip::create( realpath( $d['filename'] ), $dfile, ( $d['filename'] == "." ) );
|
||||
if( $d['filename'] == "." ) {
|
||||
if( getcwd() == $this->getScriptRoot() )
|
||||
$d['filename'] = "root";
|
||||
@@ -2219,19 +2228,6 @@ ifm.init();
|
||||
return ( strtolower( $a['name'] ) < strtolower( $b['name'] ) ) ? -1 : 1;
|
||||
}
|
||||
|
||||
// unzip an archive
|
||||
private function unzip( $file, $destination="./" ) {
|
||||
$zip = new ZipArchive;
|
||||
$res = $zip->open( $file );
|
||||
if( $res === true ) {
|
||||
$zip->extractTo( $destination );
|
||||
$zip->close();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// is cURL extention avaliable?
|
||||
private function checkCurl() {
|
||||
if( !function_exists( "curl_init" ) ||
|
||||
|
@@ -13,6 +13,9 @@
|
||||
*/
|
||||
|
||||
class IFMZip {
|
||||
/**
|
||||
* Add a folder to the zip file
|
||||
*/
|
||||
private static function folderToZip($folder, &$zipFile, $exclusiveLength) {
|
||||
$handle = opendir( $folder );
|
||||
while( false !== $f = readdir( $handle ) ) {
|
||||
@@ -34,7 +37,10 @@ class IFMZip {
|
||||
closedir( $handle );
|
||||
}
|
||||
|
||||
public static function create_zip( $src, $out, $root=false )
|
||||
/**
|
||||
* Create a zip file
|
||||
*/
|
||||
public static function create( $src, $out, $root=false )
|
||||
{
|
||||
$z = new ZipArchive();
|
||||
$z->open( $out, ZIPARCHIVE::CREATE);
|
||||
@@ -53,11 +59,14 @@ class IFMZip {
|
||||
}
|
||||
}
|
||||
|
||||
public static function unzip_file( $file ) {
|
||||
$zip = new ZipArchive();
|
||||
/**
|
||||
* Unzip a zip file
|
||||
*/
|
||||
public function extract( $file, $destination="./" ) {
|
||||
$zip = new ZipArchive;
|
||||
$res = $zip->open( $file );
|
||||
if( $res === true ) {
|
||||
$zip->extractTo( './' );
|
||||
$zip->extractTo( $destination );
|
||||
$zip->close();
|
||||
return true;
|
||||
} else {
|
||||
|
17
src/main.php
17
src/main.php
@@ -482,7 +482,7 @@ class IFM {
|
||||
echo json_encode( array( "status" => "ERROR","message" => "Could not create target directory." ) );
|
||||
exit( 1 );
|
||||
}
|
||||
if( ! $this->unzip( $d['filename'], $d['targetdir'] ) ) {
|
||||
if( ! IFMZip::extract( $d['filename'], $d['targetdir'] ) ) {
|
||||
echo json_encode( array( "status" => "ERROR","message" => "File could not be extracted" ) );
|
||||
} else {
|
||||
echo json_encode( array( "status" => "OK","message" => "File successfully extracted." ) );
|
||||
@@ -574,7 +574,7 @@ class IFM {
|
||||
unset( $zip );
|
||||
$dfile = $this->pathCombine( IFMConfig::tmp_dir, uniqid( "ifm-tmp-" ) . ".zip" ); // temporary filename
|
||||
try {
|
||||
IFMZip::create_zip( realpath( $d['filename'] ), $dfile, ( $d['filename'] == "." ) );
|
||||
IFMZip::create( realpath( $d['filename'] ), $dfile, ( $d['filename'] == "." ) );
|
||||
if( $d['filename'] == "." ) {
|
||||
if( getcwd() == $this->getScriptRoot() )
|
||||
$d['filename'] = "root";
|
||||
@@ -922,19 +922,6 @@ class IFM {
|
||||
return ( strtolower( $a['name'] ) < strtolower( $b['name'] ) ) ? -1 : 1;
|
||||
}
|
||||
|
||||
// unzip an archive
|
||||
private function unzip( $file, $destination="./" ) {
|
||||
$zip = new ZipArchive;
|
||||
$res = $zip->open( $file );
|
||||
if( $res === true ) {
|
||||
$zip->extractTo( $destination );
|
||||
$zip->close();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// is cURL extention avaliable?
|
||||
private function checkCurl() {
|
||||
if( !function_exists( "curl_init" ) ||
|
||||
|
Reference in New Issue
Block a user