Esempio n. 1
0
 public static function removeDir($directory)
 {
     foreach (glob("{$directory}/*") as $file) {
         if (is_dir($file)) {
             PtFile::removeDir($file);
         } else {
             unlink($file);
         }
     }
     rmdir($directory);
 }
Esempio n. 2
0
 public function downloadEBook($bookId, $page = 0, $limit = 0)
 {
     $dbBooks = $this->db->getBookById((int) $bookId);
     if (count($dbBooks) == 0) {
         // TODO: error msg
         return;
     }
     $dbBook = array_shift($dbBooks);
     $download_times = @$dbBook["download_times"] + 1;
     $this->db->editBook(array("id" => $dbBook["id"], "download_times" => $download_times));
     $page = max(1, $page);
     $limit = $limit == 0 ? $dbBook["pages"] : $limit;
     header('Content-type:application/force-download');
     header('Content-Transfer-Encoding: Binary');
     header('Content-Disposition: attachment; filename*=UTF-8\'\'' . urlencode($dbBook["name"] . ".epub"));
     include_once "TPEpubCreator.php";
     $epub = new TPEpubCreator();
     $epub->temp_folder = 'tmp/';
     $epub->epub_file = "tmp/{$bookId}.epub";
     $epub->title = $dbBook["name"];
     $epub->creator = 'Andy.ck101';
     $epub->language = 'zh';
     $epub->rights = 'ck101';
     $epub->publisher = 'http://novel.elggum.com';
     for ($i = $page; $i <= $limit; $i++) {
         $bookPath = PtFile::getBookPath($bookId, $i);
         if (file_exists($bookPath)) {
             $c = file_get_contents($bookPath);
             $c = iconv("UTF-16", "UTF-8", $c);
             $epub->AddPage($c, false, "{$i} page");
         }
     }
     if (!$epub->error) {
         $epub->CreateEPUB();
         echo file_get_contents($epub->epub_file);
     } else {
         echo $epub->error;
     }
 }
Esempio n. 3
0
 public function updateBook(Book &$dbBook)
 {
     $html = PtHttpCk101::getBookContentPage($dbBook->id, 1);
     $book = PtParserCk101::parseBookFromThread($html);
     if ($book == null) {
         $dbBook->update_time = time();
         $this->db->editBook(Book::toArray($dbBook));
         $this->d("Error! The Book not exists. {$dbBook->id} {$dbBook->name}");
         return;
     }
     $book->current_pages = max($dbBook->current_pages, 1);
     if ($book->posts == 0) {
         $this->d("Error! Can not parse pages! {$book->id}, {$book->current_pages}/{$book->pages}, {$book->name}");
         return;
     }
     do {
         $this->d("Start to update book {$book->id}, {$book->current_pages}/{$book->pages}, {$book->name}");
         if ($book->current_pages != 1) {
             // page 1 is already downloaded
             $html = PtHttpCk101::getBookContentPage($dbBook->id, $book->current_pages);
         }
         if ($html == null) {
             $this->d("Get content text error! Ignore this book");
             break;
         }
         $text = PtParserCk101::parseContentFromThread($html);
         PtFile::saveBook($book->id, $book->current_pages, $text);
         $this->db->editBook(Book::toArray($book));
         sleep(self::QUERY_SLEEP);
     } while (++$book->current_pages <= $book->pages);
 }