-
Notifications
You must be signed in to change notification settings - Fork 30
/
book.php
44 lines (42 loc) · 1.72 KB
/
book.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$wsexportConfig = array(
'basePath' => '..',
'tempPath' => '../temp'
);
include('../book/init.php');
try {
if(isset($_GET['refresh'])) {
include $wsexportConfig['basePath'].'/book/Refresh.php';
$refresh = new Refresh();
$refresh->refresh();
exit();
}
if(!isset($_GET['page']) || $_GET['page'] == '')
include 'help/book.php';
$title = htmlspecialchars(urldecode($_GET['page']));
$format = isset($_GET['format']) ? htmlspecialchars(urldecode($_GET['format'])) : 'epub';
$withPictures = isset($_GET['pictures']) ? (bool) $_GET['pictures'] : true;
$api = new Api();
$provider = new BookProvider($api, $withPictures);
$data = $provider->get($title);
if($format == 'epub-2' | $format == 'epub') {
include($basePath . '/book/formats/Epub2Generator.php');
$generator = new Epub2Generator();
} else if($format == 'odt') {
include($basePath . '/book/formats/OdtGenerator.php');
$generator = new OdtGenerator();
} else if($format == 'xhtml') {
include($basePath . '/book/formats/XhtmlGenerator.php');
$generator = new XhtmlGenerator();
} else {
include 'help/book.php';
}
$file = $generator->create($data);
header('Content-Type: ' . $generator->getMimeType());
header('Content-Disposition: attachment; filename="'. $title . '.' . $generator->getExtension() . '"');
header('Content-length: ' . strlen($file));
echo $file;
flush();
} catch(HttpException $exception) {
$exception->show();
}