Ejemplo n.º 1
0
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php 
require_once 'fbparser.php';
$fb = new FBParser();
if (!$fb->parse("test.fb2")) {
    die("error parsing fb2");
}
print "<br>Title = " . $fb->getTitle();
print "<br>Name = " . $fb->getAuthor();
?>
</body>
</html>
Ejemplo n.º 2
0
 private function convert($filePath, $fileName, $format)
 {
     $this->zipFile = null;
     $this->fbFile = null;
     // Extract fb2 from zip
     $zipArr = $this->unzip($filePath);
     if ($zipArr === false) {
         $this->zipFile = null;
         $this->fbFile = $filePath;
     } else {
         $this->zipFile = $filePath;
         $this->fbFile = $zipArr["filePath"];
         $fileName = $zipArr["fileName"];
     }
     // Parse fb2
     $parser = new FBParser();
     $this->book = $parser->parse($this->fbFile);
     if ($this->book === false) {
         throw new Exception("{$fileName} is not a fb2 or zip file", self::ERR_FORMAT);
     }
     // genarate unique book key
     $this->bookKey = md5(uniqid(""));
     // get md5 of the file content (
     // NOTE! Here is a BUG. We should calculate md5 based on full book content (md5file), but we can do it only after reconverting all books.
     $md5 = md5($fileName);
     // get the filename without extension
     $this->fileName = $this->getBaseFileName($fileName);
     if (!$this->fileName) {
         $this->fileName = $this->bookKey . ".zip";
     }
     // Process book
     if (!self::TEST_MODE) {
         if (!$this->checkBook($md5)) {
             $this->insertBook($md5);
         }
         $status = $this->checkFormat($format);
         if ($status == self::DB_BOOK_CONVERTED) {
             $this->notifyUserByEmail($this->email, $this->bookKey, "r");
             return;
         }
         if ($status == self::DB_BOOK_NOT_FOUND) {
             $this->insertFormat($format);
         } else {
             if ($status == self::DB_BOOK_RECONVERT) {
                 // Prepare book for reconverting
                 $this->updateFormat($format);
             }
         }
         // Send request to convert book
         $this->requestConvert($format);
     }
 }