private function createBook($title, $language, $format) { $creator = BookCreator::forLanguage($language, $format, ['credits' => false]); list($book, $file) = $creator->create($title); $this->assertFileExists($file); $this->assertNotNull($book); return $file; }
$options['fonts'] = isset($_GET['fonts']) ? strtolower(htmlspecialchars(urldecode($_GET['fonts']))) : 'freeserif'; if (filter_var($options['fonts'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === false) { $options['fonts'] = ''; } } try { if (isset($_GET['refresh'])) { $refresh = new Refresh($api); $refresh->refresh(); $success = 'The cache is updated for ' . $api->lang . ' language.'; include 'templates/book.php'; } if ($title === '') { include 'templates/book.php'; } else { $creator = BookCreator::forApi($api, $format, $options); try { list($book, $file) = $creator->create($title); } catch (WSExportInvalidArgumentException $exception) { throw new HttpException('Unsupported Media Type', 415); } header('X-Robots-Tag: none'); header('Content-Description: File Transfer'); header('Content-Type: ' . $creator->getMimeType()); header('Content-Disposition: attachment; filename="' . $title . '.' . $creator->getExtension() . '"'); header('Content-length: ' . filesize($file)); readfile($file); unlink($file); flush(); CreationLog::singleton()->add($book, $format); }
case 'd': $wsexportConfig['debug'] = true; error_reporting(E_STRICT | E_ALL); break; case 'nocredits': $options['credits'] = false; break; } } if (!$lang or !$title) { throw new WSExportInvalidArgumentException(); } return ['title' => $title, 'lang' => $lang, 'format' => $format, 'path' => $path, 'options' => $options]; } if (isset($argc)) { try { $arguments = parseCommandLine(); $creator = BookCreator::forLanguage($arguments['lang'], $arguments['format'], $arguments['options']); list($book, $file) = $creator->create($arguments['title'], $arguments['path']); echo "The ebook has been created: {$file}\n"; } catch (WSExportInvalidArgumentException $exception) { if (!empty($exception->getMessage())) { fwrite(STDERR, $exception->getMessage() . "\n\n"); } fwrite(STDERR, file_get_contents($basePath . '/cli/help/book.txt')); exit(1); } catch (Exception $exception) { fwrite(STDERR, "Error: {$exception}\n"); exit(1); } }