extract( $extractdir ); break ; default : $adapter = & extArchive::getAdapter( $ext ) ; if( $adapter ) { $result = $adapter->extract( $archivename, $extractdir ) ; } else { return PEAR::raiseError('Unknown Archive Type: '.$ext ); } break ; } return $result; } function &getAdapter( $type ) { static $adapters ; if( ! isset( $adapters ) ) { $adapters = array( ) ; } if( ! isset( $adapters[$type] ) ) { // Try to load the adapter object $class = 'extArchive' . ucfirst( $type ) ; if( ! class_exists( $class ) ) { $path = dirname( __FILE__ ) . '/adapter/' . strtolower( $type ) . '.php' ; if( file_exists( $path ) ) { require_once ($path) ; } else { echo 'Unknown Archive Type: '.$class; ext_Result::sendResult('archive', false, 'Unable to load archive' ) ; } } $adapters[$type] = new $class( ) ; } return $adapters[$type] ; } /** * @param string The name of the archive * @param mixed The name of a single file or an array of files * @param string The compression for the archive * @param string Path to add within the archive * @param string Path to remove within the archive * @param boolean Automatically append the extension for the archive * @param boolean Remove for source files */ function create( $archive, $files, $compress = 'tar', $addPath = '', $removePath = '', $autoExt = false ) { $compress = strtolower( $compress ); if( $compress == 'tgz' || $compress == 'tbz' || $compress == 'tar') { require_once( _EXT_PATH.'/libraries/Tar.php' ) ; if( is_string( $files ) ) { $files = array( $files ) ; } if( $autoExt ) { $archive .= '.' . $compress ; } if( $compress == 'tgz' ) $compress = 'gz'; if( $compress == 'tbz' ) $compress = 'bz2'; $tar = new Archive_Tar( $archive, $compress ) ; $tar->setErrorHandling( PEAR_ERROR_PRINT ) ; $result = $tar->addModify( $files, $addPath, $removePath ) ; return $result; } elseif( $compress == 'zip' ) { $adapter = & extArchive::getAdapter( 'zip' ) ; if( $adapter ) { $result = $adapter->create( $archive, $files, array('remove_path' => $removePath ) ) ; } if($result == false ) { return PEAR::raiseError( 'Unrecoverable ZIP Error' ); } } } }