This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcover.php
61 lines (46 loc) · 1.91 KB
/
cover.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
//
// Returns the cover of a given epub file
//
require_once("include/ebookRead.php"); // parses .epub
$rootpath = "books";
# if the rootpath doesn't end in a slash, add it
if ('/' != $rootpath[strlen($rootpath)]) {
$rootpath .= '/';
}
// get the name of the file we want the cover of
// er, and what's to stop us going up a directory, eh?
$filename = $_GET["filename"];
if(!$filename) {
$filename = "Jules Verne - From the Earth to the Moon.epub";
}
$filename = str_replace(".", "", $filename);
$filename = str_replace("epub", ".epub", $filename); // horrible hack, but stops people having filename=../../
$epubfile = $rootpath.$filename;
#echo $epubfile;
$ebook = new ebookRead($epubfile);
# in theory the cover is referenced in the <metadata> section by something like:
# <meta name="cover" content="cover-image"/>
# and then in the manifest something like:
# <item id="cover-image" href="the_cover.jpg" media-type="image/jpeg"/>
# but in reality it all seems to be a bit hit and miss.
# try the <meta> route first, and then make some informed guesses
#$coverReference = $this->getTag($this->ebookData->metadata, 'dclanguage');
$cover = $ebook->getManifestById('cover');
# if the type doesn't start with 'image', look elsewhere
if(stripos($cover->type, 'image') === false) {
#echo "cover is not an image, trying book-cover<br>";
$cover = $ebook->getManifestById('book-cover');
# if the type *still* doesn't start with 'image', look elsewhere
if(stripos($cover->type, 'image') === false) {
#echo "book-cover is not an image, trying cover-image<br>";
$cover = $ebook->getManifestById('cover-image');
if(stripos($cover->type, 'image') === false) {
#echo "cover-image is not an image. giving up.<br>";
}
}
}
header("X-EPUBSERVER-DEBUG: $cover->type".", $cover->href");
header("Content-Type: $cover->type");
echo $ebook->getContentFile($cover->href);
?>