/**
  * This function renders $content using the ODT-page-renderer.
  * It then unzips the ODT document and reads in the file contents
  * of the files 'content.xml', 'meta.xml' and 'styles.xml' and
  * saves the strings in $files ['content-xml'], $files ['meta-xml']
  * and $files ['styles-xml'].
  *
  * @param array       $files
  * @param string      $content
  * @return boolean
  */
 public static function getRenderedODTDocument(array &$files, $content)
 {
     // Create parser instructions for wiki page $content
     $instructions = p_get_instructions($content);
     // Render the page by looping through the instructions.
     $renderer = new renderer_plugin_odt_page();
     foreach ($instructions as $instruction) {
         // Execute the callback against the Renderer
         if (method_exists($renderer, $instruction[0])) {
             call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1] ? $instruction[1] : array());
         }
     }
     io_savefile(TMP_DIR . '/odt/temp_test_doc.odt', $renderer->doc);
     $ZIP = new ZipLib();
     $ok = $ZIP->Extract(TMP_DIR . '/odt/temp_test_doc.odt', TMP_DIR . '/odt/unpacked');
     if ($ok == -1) {
         // Error unzipping document
         return false;
     }
     $files['content-xml'] = file_get_contents(TMP_DIR . '/odt/unpacked/content.xml');
     $files['meta-xml'] = file_get_contents(TMP_DIR . '/odt/unpacked/meta.xml');
     $files['styles-xml'] = file_get_contents(TMP_DIR . '/odt/unpacked/styles.xml');
     // Success
     return true;
 }
 /**
  * Decompress a given file to the given target directory
  *
  * Determines the compression type from the file extension
  */
 function decompress($file, $target)
 {
     global $conf;
     // decompression library doesn't like target folders ending in "/"
     if (substr($target, -1) == "/") {
         $target = substr($target, 0, -1);
     }
     $ext = $this->guess_archive($file);
     if (in_array($ext, array('tar', 'bz', 'gz'))) {
         switch ($ext) {
             case 'bz':
                 $compress_type = TarLib::COMPRESS_BZIP;
                 break;
             case 'gz':
                 $compress_type = TarLib::COMPRESS_GZIP;
                 break;
             default:
                 $compress_type = TarLib::COMPRESS_NONE;
         }
         $tar = new TarLib($file, $compress_type);
         if ($tar->_initerror < 0) {
             if ($conf['allowdebug']) {
                 msg('TarLib Error: ' . $tar->TarErrorStr($tar->_initerror), -1);
             }
             return false;
         }
         $ok = $tar->Extract(TarLib::FULL_ARCHIVE, $target, '', 0777);
         if ($ok < 1) {
             if ($conf['allowdebug']) {
                 msg('TarLib Error: ' . $tar->TarErrorStr($ok), -1);
             }
             return false;
         }
         return true;
     } else {
         if ($ext == 'zip') {
             $zip = new ZipLib();
             $ok = $zip->Extract($file, $target);
             // FIXME sort something out for handling zip error messages meaningfully
             return $ok == -1 ? false : true;
         }
     }
     // unsupported file type
     return false;
 }
function epub_pack_ZipLib($meta)
{
    chdir($meta);
    echo rawurlencode("Using Dokuwiki's ZipLib Class\n");
    $epub_file = $meta . 'my-book.epub';
    unlink($epub_file);
    $z = new ZipLib();
    $z->add_File('application/epub+zip', 'mimetype', 0);
    $z->Compress('OEBPS', './');
    $z->Compress('META-INF', './');
    $result = $z->get_file();
    file_put_contents($epub_file, $result);
}
Example #4
0
function ap_decompress($file, $target)
{
    global $conf;
    // decompression library doesn't like target folders ending in "/"
    if (substr($target, -1) == "/") {
        $target = substr($target, 0, -1);
    }
    $ext = substr($file, strrpos($file, '.') + 1);
    // .tar, .tar.bz, .tar.gz, .tgz
    if (in_array($ext, array('tar', 'bz', 'bz2', 'gz', 'tgz'))) {
        require_once DOKU_INC . "inc/TarLib.class.php";
        if (strpos($ext, 'bz') !== false) {
            $compress_type = COMPRESS_BZIP;
        } else {
            if (strpos($ext, 'gz') !== false) {
                $compress_type = COMPRESS_GZIP;
            } else {
                $compress_type = COMPRESS_NONE;
            }
        }
        $tar = new TarLib($file, $compress_type);
        if ($tar->_initerror < 0) {
            if ($conf['allowdebug']) {
                msg('TarLib Error: ' . $tar->TarErrorStr($tar->_initerror), -1);
            }
            return false;
        }
        $ok = $tar->Extract(FULL_ARCHIVE, $target, '', 0777);
        if ($ok < 1) {
            if ($conf['allowdebug']) {
                msg('TarLib Error: ' . $tar->TarErrorStr($ok), -1);
            }
            return false;
        }
        return true;
    } else {
        if ($ext == 'zip') {
            require_once DOKU_INC . "inc/ZipLib.class.php";
            $zip = new ZipLib();
            $ok = $zip->Extract($file, $target);
            // FIXME sort something out for handling zip error messages meaningfully
            return $ok == -1 ? false : true;
        } else {
            if ($ext == "rar") {
                // not yet supported -- fix me
                return false;
            }
        }
    }
    // unsupported file type
    return false;
}
Example #5
0
/**
* Decompress an archive
*
* @param    string  $file   soure file
* @param    string  $target destination directory
* @return   bool            true on success, false on fail
*
*/
function COM_decompress($file, $target)
{
    global $_CONF;
    $ok = 0;
    // decompression library doesn't like target folders ending in "/"
    if (substr($target, -1) == "/") {
        $target = substr($target, 0, -1);
    }
    $ext = substr($file, strrpos($file, '.') + 1);
    // .tar, .tar.bz, .tar.gz, .tgz
    if (in_array($ext, array('tar', 'bz', 'bz2', 'gz', 'tgz'))) {
        require_once 'Archive/Tar.php';
        $tar = new Archive_Tar($file);
        $ok = $tar->extract($target);
        if ($ok) {
            $ok = 1;
        }
        return $ok < 1 ? false : true;
    } else {
        if ($ext == 'zip') {
            require_once $_CONF['path'] . '/lib/ZipLib.class.php';
            $zip = new ZipLib();
            $ok = $zip->Extract($file, $target);
            return $ok == -1 ? false : true;
        }
    }
    // unsupported file type
    return false;
}