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