1 | <?php |
||
11 | class Data extends Base { |
||
12 | public $id; |
||
13 | public $name; |
||
14 | public $format; |
||
15 | public $realFormat; |
||
16 | public $extension; |
||
17 | public $book; |
||
18 | |||
19 | public static $mimetypes = array( |
||
20 | 'aac' => 'audio/aac', |
||
21 | 'azw' => 'application/x-mobipocket-ebook', |
||
22 | 'azw1' => 'application/x-topaz-ebook', |
||
23 | 'azw2' => 'application/x-kindle-application', |
||
24 | 'azw3' => 'application/x-mobi8-ebook', |
||
25 | 'cbz' => 'application/x-cbz', |
||
26 | 'cbr' => 'application/x-cbr', |
||
27 | 'djv' => 'image/vnd.djvu', |
||
28 | 'djvu' => 'image/vnd.djvu', |
||
29 | 'doc' => 'application/msword', |
||
30 | 'epub' => 'application/epub+zip', |
||
31 | 'fb2' => 'text/fb2+xml', |
||
32 | 'ibooks'=> 'application/x-ibooks+zip', |
||
33 | 'kepub' => 'application/epub+zip', |
||
34 | 'kobo' => 'application/x-koboreader-ebook', |
||
35 | 'm4a' => 'audio/mp4', |
||
36 | 'mobi' => 'application/x-mobipocket-ebook', |
||
37 | 'mp3' => 'audio/mpeg', |
||
38 | 'lit' => 'application/x-ms-reader', |
||
39 | 'lrs' => 'text/x-sony-bbeb+xml', |
||
40 | 'lrf' => 'application/x-sony-bbeb', |
||
41 | 'lrx' => 'application/x-sony-bbeb', |
||
42 | 'ncx' => 'application/x-dtbncx+xml', |
||
43 | 'opf' => 'application/oebps-package+xml', |
||
44 | 'otf' => 'application/x-font-opentype', |
||
45 | 'pdb' => 'application/vnd.palm', |
||
46 | 'pdf' => 'application/pdf', |
||
47 | 'prc' => 'application/x-mobipocket-ebook', |
||
48 | 'rtf' => 'application/rtf', |
||
49 | 'svg' => 'image/svg+xml', |
||
50 | 'ttf' => 'application/x-font-truetype', |
||
51 | 'tpz' => 'application/x-topaz-ebook', |
||
52 | 'wav' => 'audio/wav', |
||
53 | 'wmf' => 'image/wmf', |
||
54 | 'xhtml' => 'application/xhtml+xml', |
||
55 | 'xpgt' => 'application/adobe-page-template+xml', |
||
56 | 'zip' => 'application/zip' |
||
57 | ); |
||
58 | |||
59 | 60 | public function __construct($post, $book = null) { |
|
60 | 60 | $this->id = $post->id; |
|
61 | 60 | $this->name = $post->name; |
|
62 | 60 | $this->format = $post->format; |
|
63 | 60 | $this->realFormat = str_replace ("ORIGINAL_", "", $post->format); |
|
64 | 60 | $this->extension = strtolower ($this->realFormat); |
|
65 | 60 | $this->book = $book; |
|
66 | 60 | } |
|
67 | |||
68 | 50 | public function isKnownType () { |
|
69 | 50 | return array_key_exists ($this->extension, self::$mimetypes); |
|
70 | } |
||
71 | |||
72 | 50 | public function getMimeType () { |
|
73 | 50 | $result = "application/octet-stream"; |
|
74 | 50 | if ($this->isKnownType ()) { |
|
75 | 50 | return self::$mimetypes [$this->extension]; |
|
76 | 1 | } elseif (function_exists('finfo_open') === true) { |
|
77 | 1 | $finfo = finfo_open(FILEINFO_MIME_TYPE); |
|
78 | |||
79 | 1 | if (is_resource($finfo) === true) |
|
80 | 1 | { |
|
81 | 1 | $result = finfo_file($finfo, $this->getLocalPath ()); |
|
82 | 1 | } |
|
83 | |||
84 | 1 | finfo_close($finfo); |
|
85 | |||
86 | 1 | } |
|
87 | 1 | return $result; |
|
88 | } |
||
89 | |||
90 | 1 | public function isEpubValidOnKobo () { |
|
91 | 1 | return $this->format == "EPUB" || $this->format == "KEPUB"; |
|
92 | } |
||
93 | |||
94 | 47 | public function getFilename () { |
|
95 | 47 | return $this->name . "." . strtolower ($this->format); |
|
96 | } |
||
97 | |||
98 | 1 | public function getUpdatedFilename () { |
|
99 | 1 | return $this->book->getAuthorsSort () . " - " . $this->book->title; |
|
100 | } |
||
101 | |||
102 | 1 | public function getUpdatedFilenameEpub () { |
|
103 | 1 | return $this->getUpdatedFilename () . ".epub"; |
|
104 | } |
||
105 | |||
106 | 1 | public function getUpdatedFilenameKepub () { |
|
107 | 1 | return $this->getUpdatedFilename () . ".kepub.epub"; |
|
108 | } |
||
109 | |||
110 | 46 | public function getDataLink ($rel, $title = NULL) { |
|
111 | 46 | global $config; |
|
112 | |||
113 | 46 | if ($rel == Link::OPDS_ACQUISITION_TYPE && $config['cops_use_url_rewriting'] == "1") { |
|
114 | 2 | return $this->getHtmlLinkWithRewriting($title); |
|
115 | } |
||
116 | |||
117 | 45 | return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title); |
|
118 | } |
||
119 | |||
120 | 4 | public function getHtmlLink () { |
|
121 | 4 | return $this->getDataLink(Link::OPDS_ACQUISITION_TYPE)->href; |
|
122 | } |
||
123 | |||
124 | 2 | public function getLocalPath () { |
|
125 | 2 | return $this->book->path . "/" . $this->getFilename (); |
|
126 | } |
||
127 | |||
128 | 2 | public function getHtmlLinkWithRewriting ($title = NULL) { |
|
145 | |||
146 | 59 | public static function getDataByBook ($book) { |
|
147 | 59 | $out = array (); |
|
148 | 59 | $result = parent::getDb ()->prepare('select id, format, name |
|
|
|||
149 | 59 | from data where book = ?'); |
|
150 | 59 | $result->execute (array ($book->id)); |
|
151 | |||
152 | 59 | while ($post = $result->fetchObject ()) |
|
153 | { |
||
154 | 59 | array_push ($out, new Data ($post, $book)); |
|
155 | 59 | } |
|
156 | 59 | return $out; |
|
158 | |||
159 | 19 | public static function handleThumbnailLink ($urlParam, $height) { |
|
177 | |||
178 | 46 | public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL) |
|
207 | } |
||
208 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.