@@ -55,7 +55,8 @@ discard block |
||
55 | 55 | 'zip' => 'application/zip' |
56 | 56 | ); |
57 | 57 | |
58 | - public function __construct($post, $book = null) { |
|
58 | + public function __construct($post, $book = null) |
|
59 | + { |
|
59 | 60 | $this->id = $post->id; |
60 | 61 | $this->name = $post->name; |
61 | 62 | $this->format = $post->format; |
@@ -64,19 +65,20 @@ discard block |
||
64 | 65 | $this->book = $book; |
65 | 66 | } |
66 | 67 | |
67 | - public function isKnownType () { |
|
68 | + public function isKnownType () |
|
69 | + { |
|
68 | 70 | return array_key_exists ($this->extension, self::$mimetypes); |
69 | 71 | } |
70 | 72 | |
71 | - public function getMimeType () { |
|
73 | + public function getMimeType () |
|
74 | + { |
|
72 | 75 | $result = "application/octet-stream"; |
73 | 76 | if ($this->isKnownType ()) { |
74 | 77 | return self::$mimetypes [$this->extension]; |
75 | 78 | } elseif (function_exists('finfo_open') === true) { |
76 | 79 | $finfo = finfo_open(FILEINFO_MIME_TYPE); |
77 | 80 | |
78 | - if (is_resource($finfo) === true) |
|
79 | - { |
|
81 | + if (is_resource($finfo) === true) { |
|
80 | 82 | $result = finfo_file($finfo, $this->getLocalPath ()); |
81 | 83 | } |
82 | 84 | |
@@ -86,29 +88,35 @@ discard block |
||
86 | 88 | return $result; |
87 | 89 | } |
88 | 90 | |
89 | - public function isEpubValidOnKobo () { |
|
91 | + public function isEpubValidOnKobo () |
|
92 | + { |
|
90 | 93 | return $this->format == "EPUB" || $this->format == "KEPUB"; |
91 | 94 | } |
92 | 95 | |
93 | - public function getFilename () { |
|
96 | + public function getFilename () |
|
97 | + { |
|
94 | 98 | return $this->name . "." . strtolower ($this->format); |
95 | 99 | } |
96 | 100 | |
97 | - public function getUpdatedFilename () { |
|
101 | + public function getUpdatedFilename () |
|
102 | + { |
|
98 | 103 | return $this->book->getAuthorsSort () . " - " . $this->book->title; |
99 | 104 | } |
100 | 105 | |
101 | - public function getUpdatedFilenameEpub () { |
|
106 | + public function getUpdatedFilenameEpub () |
|
107 | + { |
|
102 | 108 | return $this->getUpdatedFilename () . ".epub"; |
103 | 109 | } |
104 | 110 | |
105 | - public function getUpdatedFilenameKepub () { |
|
111 | + public function getUpdatedFilenameKepub () |
|
112 | + { |
|
106 | 113 | $str = $this->getUpdatedFilename () . ".kepub.epub"; |
107 | 114 | return str_replace(array(':', '#', '&'), |
108 | 115 | array('-', '-', ' '), $str ); |
109 | 116 | } |
110 | 117 | |
111 | - public function getDataLink ($rel, $title = NULL, $view = false) { |
|
118 | + public function getDataLink ($rel, $title = NULL, $view = false) |
|
119 | + { |
|
112 | 120 | global $config; |
113 | 121 | |
114 | 122 | if ($rel == Link::OPDS_ACQUISITION_TYPE && $config['cops_use_url_rewriting'] == "1") { |
@@ -118,23 +126,29 @@ discard block |
||
118 | 126 | return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title, NULL, $view); |
119 | 127 | } |
120 | 128 | |
121 | - public function getHtmlLink () { |
|
129 | + public function getHtmlLink () |
|
130 | + { |
|
122 | 131 | return $this->getDataLink(Link::OPDS_ACQUISITION_TYPE)->href; |
123 | 132 | } |
124 | 133 | |
125 | - public function getViewHtmlLink () { |
|
134 | + public function getViewHtmlLink () |
|
135 | + { |
|
126 | 136 | return $this->getDataLink(Link::OPDS_ACQUISITION_TYPE, NULL, true)->href; |
127 | 137 | } |
128 | 138 | |
129 | - public function getLocalPath () { |
|
139 | + public function getLocalPath () |
|
140 | + { |
|
130 | 141 | return $this->book->path . "/" . $this->getFilename (); |
131 | 142 | } |
132 | 143 | |
133 | - public function getHtmlLinkWithRewriting ($title = NULL, $view = false) { |
|
144 | + public function getHtmlLinkWithRewriting ($title = NULL, $view = false) |
|
145 | + { |
|
134 | 146 | global $config; |
135 | 147 | |
136 | 148 | $database = ""; |
137 | - if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/"; |
|
149 | + if (!is_null (GetUrlParam (DB))) { |
|
150 | + $database = GetUrlParam (DB) . "/"; |
|
151 | + } |
|
138 | 152 | |
139 | 153 | $prefix = "download"; |
140 | 154 | if ($view) { |
@@ -152,28 +166,27 @@ discard block |
||
152 | 166 | return new Link ($href, $this->getMimeType (), Link::OPDS_ACQUISITION_TYPE, $title); |
153 | 167 | } |
154 | 168 | |
155 | - public static function getDataByBook ($book) { |
|
169 | + public static function getDataByBook ($book) |
|
170 | + { |
|
156 | 171 | $out = array (); |
157 | 172 | $result = parent::getDb ()->prepare('select id, format, name |
158 | 173 | from data where book = ?'); |
159 | 174 | $result->execute (array ($book->id)); |
160 | 175 | |
161 | - while ($post = $result->fetchObject ()) |
|
162 | - { |
|
176 | + while ($post = $result->fetchObject ()) { |
|
163 | 177 | array_push ($out, new Data ($post, $book)); |
164 | 178 | } |
165 | 179 | return $out; |
166 | 180 | } |
167 | 181 | |
168 | - public static function handleThumbnailLink ($urlParam, $height) { |
|
182 | + public static function handleThumbnailLink ($urlParam, $height) |
|
183 | + { |
|
169 | 184 | global $config; |
170 | 185 | |
171 | 186 | if (is_null ($height)) { |
172 | 187 | if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) { |
173 | 188 | $height = $config['cops_opds_thumbnail_height']; |
174 | - } |
|
175 | - else |
|
176 | - { |
|
189 | + } else { |
|
177 | 190 | $height = $config['cops_html_thumbnail_height']; |
178 | 191 | } |
179 | 192 | } |
@@ -189,18 +202,23 @@ discard block |
||
189 | 202 | global $config; |
190 | 203 | |
191 | 204 | $urlParam = addURLParameter("", "data", $idData); |
192 | - if ($view) $urlParam = addURLParameter($urlParam, "view", 1); |
|
205 | + if ($view) { |
|
206 | + $urlParam = addURLParameter($urlParam, "view", 1); |
|
207 | + } |
|
193 | 208 | |
194 | 209 | if (Base::useAbsolutePath () || |
195 | 210 | $rel == Link::OPDS_THUMBNAIL_TYPE || |
196 | - ($type == "epub" && $config['cops_update_epub-metadata'])) |
|
197 | - { |
|
198 | - if ($type != "jpg") $urlParam = addURLParameter($urlParam, "type", $type); |
|
211 | + ($type == "epub" && $config['cops_update_epub-metadata'])) { |
|
212 | + if ($type != "jpg") { |
|
213 | + $urlParam = addURLParameter($urlParam, "type", $type); |
|
214 | + } |
|
199 | 215 | if ($rel == Link::OPDS_THUMBNAIL_TYPE) { |
200 | 216 | $urlParam = self::handleThumbnailLink($urlParam, $height); |
201 | 217 | } |
202 | 218 | $urlParam = addURLParameter($urlParam, "id", $book->id); |
203 | - if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
219 | + if (!is_null (GetUrlParam (DB))) { |
|
220 | + $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
221 | + } |
|
204 | 222 | if ($config['cops_thumbnail_handling'] != "1" && |
205 | 223 | !empty ($config['cops_thumbnail_handling']) && |
206 | 224 | $rel == Link::OPDS_THUMBNAIL_TYPE) { |
@@ -208,9 +226,7 @@ discard block |
||
208 | 226 | } else { |
209 | 227 | return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title); |
210 | 228 | } |
211 | - } |
|
212 | - else |
|
213 | - { |
|
229 | + } else { |
|
214 | 230 | return new Link (str_replace('%2F','/',rawurlencode ($book->path."/".$filename)), $mime, $rel, $title); |
215 | 231 | } |
216 | 232 | } |