public function testFilterArchiveUnzip() { $zipfile = Filter_Archive::zip($this->file1, false); // Test unzip. $folder = Filter_Archive::unzip($zipfile, false); $this->assertTrue(file_exists($folder)); foreach (new DirectoryIterator($folder) as $fileInfo) { if ($fileInfo->isDot()) { continue; } $path = $fileInfo->getFilename(); $path = "{$folder}/{$path}"; $this->assertEquals(9000, filesize($path)); } unlink($zipfile); Filter_Rmdir::rmdir($folder); // Test that unzipping garbage returns NULL. $folder = Filter_Archive::unzip("xxxxx", false); $this->assertEquals(NULL, $folder); }
/** * This saves the OpenDocument to file * $name: the name of the file to save to. */ public function save($name) { // Create the content.xml file. // No formatting because some white space is processed. $this->contentDom->formatOutput = true; $string = $this->contentDom->save($this->unpackedOdtFolder . "/content.xml"); // Create the styles.xml file. // No formatting because some white space is processed. $this->stylesDom->formatOutput = true; $string = $this->stylesDom->save($this->unpackedOdtFolder . "/styles.xml"); // Save the OpenDocument file. $zippedfile = Filter_Archive::zip($this->unpackedOdtFolder); file_put_contents($name, file_get_contents($zippedfile)); unlink($zippedfile); }
$chapter_data = $database_bibles->getChapter($bible, $book, $chapter); $chapter_data = trim($chapter_data); // Add the chapter USFM code to the book's USFM code. $bookUsfmDataFull .= $chapter_data; $bookUsfmDataFull .= "\n"; } // The filename for the USFM for this book. $filename = Export_Logic::baseBookFileName($book); $path = "{$usfmDirectoryFull}/{$filename}.usfm"; // Save. file_put_contents($path, $bookUsfmDataFull); } // Compress USFM files into one zip file. $zipfile = "{$usfmDirectoryFull}/" . Export_Logic::baseBookFileName(0) . ".zip"; @unlink($zipfile); $archive = Filter_Archive::zip($usfmDirectoryFull); rename($archive, $zipfile); if ($database_config_bible->getSecureUsfmExport($bible)) { // Securing the full USFM export means that there will be one zip file secured with a password. // This zip file contains all exported USFM data. // All other files will be removed. // It uses the external zip binary. // PHP 5.6 supports password protected archives: ZipArchive::setPassword ($password). $files = scandir($usfmDirectoryFull); $files = Filter_Folders::cleanup($files); $basefile = basename($zipfile); foreach ($files as $file) { if ($file != $basefile) { unlink("{$usfmDirectoryFull}/{$file}"); } }