Example #1
0
 /**
  * Uncompresses a known archive identified by $file.
  * Returns the path to the folder it created.
  * If $show_errors is true, it outputs errors in html.
  */
 public static function uncompress($file, $show_errors)
 {
     // Tar (.tar) archives, including those compressed with gzip (.tar.gz, .tgz), bzip (.tar.bz, .tbz), bzip2 (.tar.bz2, .tbz2), compress (.tar.Z, .taz), lzop (.tar.lzo, .tzo) and lzma (.tar.lzma)
     // Zip archives (.zip)
     // Jar archives (.jar, .ear, .war)
     // 7z archives (.7z)
     // iso9660 CD images (.iso)
     // Lha archives (.lzh)
     // Single files compressed with gzip (.gz), bzip (.bz), bzip2 (.bz2), compress (.Z), lzop (.lzo) and lzma (.lzma)
     $suffix = pathinfo($file, PATHINFO_EXTENSION);
     switch ($suffix) {
         case "tar.gz":
             // Never called because pathinfo would give the 'gz' suffix only.
         // Never called because pathinfo would give the 'gz' suffix only.
         case "gz":
         case "tgz":
             return Filter_Archive::untargz($file, $show_errors);
         case "zip":
             return Filter_Archive::unzip($file, $show_errors);
         case "tar.bz":
         case "tbz":
         case "tar.bz2":
         case "tbz2":
     }
     return NULL;
 }
Example #2
0
<?php

/*
Copyright (©) 2003-2014 Teus Benschop.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once "../bootstrap/bootstrap.php";
page_access_level(Filter_Roles::MANAGER_LEVEL);
Assets_Page::header(Locale_Translate::_("Import"));
$file = $_GET['file'];
$folder = Filter_Archive::uncompress($file, true);
$view = new Assets_View(__FILE__);
$view->view->folder = $folder;
$view->render("import3.php");
Assets_Page::footer();
Example #3
0
 public function testFilterArchiveUntargz()
 {
     $tarball = Filter_Archive::tarGzipFile($this->file1, false);
     // Test decompression.
     $folder = Filter_Archive::untargz($tarball, false);
     $this->assertTrue(file_exists($folder));
     Filter_Rmdir::rmdir($folder);
     $folder = Filter_Archive::uncompress($tarball, 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));
     }
     Filter_Rmdir::rmdir($folder);
     unlink($tarball);
     // Test that unzipping garbage returns NULL.
     $folder = Filter_Archive::untargz("xxxxx", false);
     $this->assertEquals(NULL, $folder);
 }
Example #4
0
 /**
  * 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);
 }
Example #5
0
        $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}");
        }
    }
Example #6
0
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once "../bootstrap/bootstrap.php";
page_access_level(Filter_Roles::MANAGER_LEVEL);
Assets_Page::header(Locale_Translate::_("Import"));
// Move the uploaded file to a temporary name.
$notesfile = tempnam(sys_get_temp_dir(), '');
unlink($notesfile);
@($notesfile .= $_FILES['notes']['name']);
@($tmpfile = $_FILES['notes']['tmp_name']);
$view = new Assets_View(__FILE__);
if (move_uploaded_file($tmpfile, $notesfile)) {
    $view->view->filename = $notesfile;
    $notesfolder = Filter_Archive::uncompress($notesfile, true);
    $view->view->folder = $notesfolder;
    $view->render("import2.php");
} else {
    $view->render("import2error.php");
}
Assets_Page::footer();
Example #7
0
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once "../bootstrap/bootstrap.php";
// Security: Page only runs from the cli SAPI.
Filter_Cli::assert();
$database_logs = Database_Logs::getInstance();
$database_logs->log(Locale_Translate::_("Import Bible data has started"), true);
ignore_user_abort(true);
set_time_limit(0);
$location = Filter_Cli::argument(@$argv, 1);
$bible = Filter_Cli::argument(@$argv, 2);
$database_logs->log("Importing from location {$location} into Bible {$bible}", true);
$folder = Filter_Archive::uncompress($location, true);
if ($folder != NULL) {
    $location = $folder;
}
unset($folder);
$files = array();
if (is_dir($location)) {
    $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($location));
    foreach ($objects as $name => $object) {
        if (is_file($name)) {
            $files[] = $name;
        }
    }
} else {
    $files[] = $location;
}