public function ingestZipData($data, $opspath = null)
 {
     // used when pulling an epub from a zipped archive
     // first writes it to disk, then ingests it whole
     if ($opspath) {
         if (!is_dir($opspath)) {
             throw new Exception('ops path passed is not a directory!');
         }
     }
     $tmpfile = Util::getTempDir() . '/epubimport' . time() . '.epub';
     if (file_put_contents($tmpfile, $data)) {
         if ($this->loadZip($tmpfile)) {
             if ($opspath) {
                 // TODO eliminate need for ZipArchive memory bloat. For now, it's a shortcut
                 // idea here is to dump to a path if needing OPS, if not,
                 // we should one day offer the option to store structure and/or zipdata
                 // in memory or on disk
                 if ($puts = $this->writeFiles($opspath)) {
                     parent::loadOPS($opspath);
                 } else {
                     $this->log("no files were written.");
                 }
                 /*
                 				$this->_za = new ZipArchive();
                 				
                 				// TODO we dont have to store OPS in disk, could use memory
                 				
                 				if ($this->_za->open($tmpfile) === TRUE) {
                 					echo "opened\n";
                 					if($this->_za->extractTo($opspath)) {
                 						echo "extracted\n";
                 						$this->_za->close();
                 						echo "closed\n";
                 						if(!file_exists($opspath.'/META-INF/container.xml')) {
                 							echo "throwing up\n";
                 							throw new Exception('no container found in package!');
                 						} else {
                 							echo file_get_contents($opspath.'/META-INF/container.xml');
                 						}
                 						echo "calling parent\n";
                 						parent::loadOPS($opspath);
                 						echo "loaded OPS\n";
                 					} else {
                 						echo "could not extract this bitch\n";
                 					}
                 				} else {
                 					echo "throwing up again\n";
                 					throw new Exception('could not open zip archive!');
                 				}
                 */
             }
             // TODO we dont have to get rid of the zip data
             $data = null;
             // TODO we dont have to get rid of the stored zip data either
             unlink($tmpfile);
         }
     } else {
         throw new Exception('EPUB file could not be stored locally for import');
     }
 }
Ejemplo n.º 2
0
<?php

require_once './BookGluttonEpub.php';
require_once './BookGluttonZipEpub.php';
$file = './H. G. Wells - The War of the Worlds.epub';
echo "Opening {$file} as OPS in temp dir:\n";
$epub = new BookGluttonEpub();
$epub->setLogVerbose(true);
$epub->setLogLevel(2);
$epub->open($file);
print_r($epub->getMetaPairs());
echo "Now opening {$file} as virtual zip (no filesystem on disk):\n";
$epub = new BookGluttonZipEpub();
$epub->enableLogging();
$epub->loadZip($file);
print_r($epub->getMetaPairs());
echo "There are " . $epub->getFlatNav()->length . " navPoints here.\n";
echo "NCX:\n";
foreach ($epub->getFlatNav() as $np) {
    echo $np->nodeValue . "\n";
}