00001 <?php
00002
00014 lt_include( PLOG_CLASS_PATH."class/file/unpacker/baseunpacker.class.php" );
00015 lt_include( PLOG_CLASS_PATH."class/file/unpacker/targzunpacker.class.php" );
00016 lt_include( PLOG_CLASS_PATH."class/file/unpacker/zipunpacker.class.php" );
00017 lt_include( PLOG_CLASS_PATH."class/file/unpacker/tarbz2unpacker.class.php" );
00018 lt_include( PLOG_CLASS_PATH."class/file/unpacker/rarunpacker.class.php" );
00019
00020 define( "UNPACKER_AUTODETECT", "detect" );
00021 define( "UNPACKER_TAR_GZ", "tar.gz" );
00022 define( "UNPACKER_TAR_BZ2", "tar.bz2" );
00023 define( "UNPACKER_ZIP", "zip" );
00024 define( "UNPACKER_RAR", "rar" );
00025 define( "UNPACKER_UNSUPPORTED", false );
00026
00050 class Unpacker
00051 {
00052
00053 var $_methods = Array( "tar.gz" => "TarGzUnpacker",
00054 "zip" => "ZipUnpacker",
00055 "tar.bz2" => "TarBz2Unpacker",
00056 "rar" => "RarUnpacker"
00057 );
00058
00059 var $_method;
00060
00061 var $_unpackerObj;
00062
00079 function Unpacker( $method = UNPACKER_AUTODETECT )
00080 {
00081
00082
00083 $this->_method = $method;
00084 }
00085
00090 function _findUnpacker()
00091 {
00092 if( $this->_method == UNPACKER_AUTODETECT ) {
00093 $extArray = explode( ".", $this->_file );
00094
00095 $ext = $extArray[count($extArray)-1];
00096 $ext2 = $extArray[count($extArray)-2].".".$ext;
00097
00098 if( isset($this->_methods[$ext]))
00099 $this->_method = $ext;
00100 elseif( isset($this->_methods[$ext2]))
00101 $this->_method = $ext2;
00102 else
00103 $this->_method = UNPACKER_UNSUPPORTED;
00104 }
00105
00106
00107 if( $this->_method != UNPACKER_UNSUPPORTED ) {
00108 $this->_unpacker = new $this->_methods[$this->_method]();
00109 $result = true;
00110 }
00111 else
00112 $result = false;
00113
00114 return $result;
00115 }
00116
00127 function unpack( $file, $destFolder = "./" )
00128 {
00129
00130 $this->_file = $file;
00131
00132 if( !$this->_findUnpacker())
00133 return UNPACKER_UNSUPPORTED;
00134
00135
00136 return $this->_unpacker->unpack( $file, $destFolder );
00137 }
00138 }
00139 ?>