/** * Zip the temp folder */ function createZipFile($bEchoStatus = FALSE) { if (empty($this->aPaths)) { return PEAR::raiseError(_kt("No folders or documents found to compress")); } $sZipFile = sprintf("%s/%s." . $this->extension, $this->sTmpPath, $this->sZipFileName); $sZipFile = str_replace('<', '', str_replace('</', '', str_replace('>', '', $sZipFile))); $archive = new KTPclZip($sZipFile); $archive->createZipFile($this->sTmpPath . '/Root Folder'); /* $config = KTConfig::getSingleton(); $useBinary = true; //$config->get('export/useBinary', false); // Set environment language to output character encoding $loc = $this->sOutputEncoding; putenv("LANG=$loc"); putenv("LANGUAGE=$loc"); $loc = setlocale(LC_ALL, $loc); if($useBinary){ $sManifest = sprintf("%s/%s", $this->sTmpPath, "MANIFEST"); file_put_contents($sManifest, join("\n", $this->aPaths)); } $sZipFile = sprintf("%s/%s.".$this->extension, $this->sTmpPath, $this->sZipFileName); $sZipFile = str_replace('<', '', str_replace('</', '', str_replace('>', '', $sZipFile))); if($useBinary){ $sZipCommand = KTUtil::findCommand("export/zip", "zip"); $aCmd = array($sZipCommand, "-r", $sZipFile, ".", "-i@MANIFEST"); $sOldPath = getcwd(); chdir($this->sTmpPath); // Note that the popen means that pexec will return a file descriptor $aOptions = array('popen' => 'r'); $fh = KTUtil::pexec($aCmd, $aOptions); if($bEchoStatus){ $last_beat = time(); while(!feof($fh)) { if ($i % 1000 == 0) { $this_beat = time(); if ($last_beat + 1 < $this_beat) { $last_beat = $this_beat; print " "; } } $contents = fread($fh, 4096); if ($contents) { print nl2br($this->_convertEncoding($contents, false)); } $i++; } } pclose($fh); }else{ // Create the zip archive using the PEAR File_Archive File_Archive::extract( File_Archive::read($this->sTmpPath.'/Root Folder'), File_Archive::toArchive($this->sZipFileName.'.'.$this->extension, File_Archive::toFiles($this->sTmpPath), $this->extension) ); } */ // Save the zip file and path into session $_SESSION['zipcompression'] = KTUtil::arrayGet($_SESSION, 'zipcompression', array()); $sExportCode = $this->exportCode; $_SESSION['zipcompression'][$sExportCode] = array('file' => $sZipFile, 'dir' => $this->sTmpPath); $_SESSION['zipcompression']['exportcode'] = $sExportCode; $this->sZipFile = $sZipFile; return $sExportCode; }
function init() { $oKTConfig =& KTConfig::getSingleton(); $sBasedir = $oKTConfig->get("urls/tmpDirectory"); $sTmpPath = tempnam($sBasedir, 'archiveimportstorage'); if ($sTmpPath === false) { return PEAR::raiseError(_kt("Could not create temporary directory for archive storage")); } if (!file_exists($this->sZipPath)) { return PEAR::raiseError(_kt("Archive file given does not exist")); } unlink($sTmpPath); mkdir($sTmpPath, 0777); $this->sBasePath = $sTmpPath; // Set environment language to output character encoding $sOutputEncoding = $oKTConfig->get('export/encoding', 'UTF-8'); $loc = $sOutputEncoding; putenv("LANG={$loc}"); putenv("LANGUAGE={$loc}"); $loc = setlocale(LC_ALL, $loc); // File Archive doesn't unzip properly - using peclzip for zip files // todo: replace file archive for tar, etc if ($this->sExtension == 'zip') { $archive = new KTPclZip($this->sZipPath); $archive->extractZipFile($sTmpPath); /* ** Original zip functionality using the unzip binary ** * $sUnzipCommand = KTUtil::findCommand("import/unzip", "unzip"); if (empty($sUnzipCommand)) { return PEAR::raiseError(_kt("unzip command not found on system")); } $aArgs = array( $sUnzipCommand, "-q", "-n", "-d", $sTmpPath, $this->sZipPath, ); $aRes = KTUtil::pexec($aArgs); if ($aRes['ret'] !== 0) { return PEAR::raiseError(_kt("Could not retrieve contents from zip storage")); } /* ** End original zip functionality ** */ } else { File_Archive::extract(File_Archive::readArchive($this->sExtension, File_Archive::readUploadedFile($this->sFileName)), $dst = $sTmpPath); } }