@@ -14,48 +14,58 @@ discard block |
||
| 14 | 14 | public $name; |
| 15 | 15 | public $customId; |
| 16 | 16 | |
| 17 | - public function __construct($pid, $pname, $pcustomId) { |
|
| 17 | + public function __construct($pid, $pname, $pcustomId) |
|
| 18 | + { |
|
| 18 | 19 | $this->id = $pid; |
| 19 | 20 | $this->name = $pname; |
| 20 | 21 | $this->customId = $pcustomId; |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | - public function getUri () { |
|
| 24 | + public function getUri () |
|
| 25 | + { |
|
| 24 | 26 | return "?page=".parent::PAGE_CUSTOM_DETAIL."&custom={$this->customId}&id={$this->id}"; |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | - public function getEntryId () { |
|
| 29 | + public function getEntryId () |
|
| 30 | + { |
|
| 28 | 31 | return self::ALL_CUSTOMS_ID.":".$this->customId.":".$this->id; |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | - public static function getTableName ($customId) { |
|
| 34 | + public static function getTableName ($customId) |
|
| 35 | + { |
|
| 32 | 36 | return "custom_column_{$customId}"; |
| 33 | 37 | } |
| 34 | 38 | |
| 35 | - public static function getTableLinkName ($customId) { |
|
| 39 | + public static function getTableLinkName ($customId) |
|
| 40 | + { |
|
| 36 | 41 | return "books_custom_column_{$customId}_link"; |
| 37 | 42 | } |
| 38 | 43 | |
| 39 | - public static function getTableLinkColumn ($customId) { |
|
| 44 | + public static function getTableLinkColumn ($customId) |
|
| 45 | + { |
|
| 40 | 46 | return "value"; |
| 41 | 47 | } |
| 42 | 48 | |
| 43 | - public static function getAllCustomsId ($customId) { |
|
| 49 | + public static function getAllCustomsId ($customId) |
|
| 50 | + { |
|
| 44 | 51 | return self::ALL_CUSTOMS_ID . ":" . $customId; |
| 45 | 52 | } |
| 46 | 53 | |
| 47 | - public static function getUriAllCustoms ($customId) { |
|
| 54 | + public static function getUriAllCustoms ($customId) |
|
| 55 | + { |
|
| 48 | 56 | return "?page=" . parent::PAGE_ALL_CUSTOMS . "&custom={$customId}"; |
| 49 | 57 | } |
| 50 | 58 | |
| 51 | - public static function getAllTitle ($customId) { |
|
| 59 | + public static function getAllTitle ($customId) |
|
| 60 | + { |
|
| 52 | 61 | $result = parent::getDb ()->prepare('select name from custom_columns where id = ?'); |
| 53 | 62 | $result->execute (array ($customId)); |
| 54 | 63 | $post = $result->fetchObject (); |
| 55 | 64 | return $post->name; |
| 56 | 65 | } |
| 57 | 66 | |
| 58 | - public static function getCustomId ($lookup) { |
|
| 67 | + public static function getCustomId ($lookup) |
|
| 68 | + { |
|
| 59 | 69 | $result = parent::getDb ()->prepare('select id from custom_columns where label = ?'); |
| 60 | 70 | $result->execute (array ($lookup)); |
| 61 | 71 | if ($post = $result->fetchObject ()) { |
@@ -64,7 +74,8 @@ discard block |
||
| 64 | 74 | return NULL; |
| 65 | 75 | } |
| 66 | 76 | |
| 67 | - public static function getCount($customId) { |
|
| 77 | + public static function getCount($customId) |
|
| 78 | + { |
|
| 68 | 79 | $nCustoms = parent::executeQuerySingle ('select count(*) from ' . self::getTableName ($customId)); |
| 69 | 80 | $entry = new Entry (self::getAllTitle ($customId), self::getAllCustomsId ($customId), |
| 70 | 81 | str_format (localize("tags.alphabetical", $nCustoms), $nCustoms), "text", |
@@ -72,7 +83,8 @@ discard block |
||
| 72 | 83 | return $entry; |
| 73 | 84 | } |
| 74 | 85 | |
| 75 | - public static function getCustomById ($customId, $id) { |
|
| 86 | + public static function getCustomById ($customId, $id) |
|
| 87 | + { |
|
| 76 | 88 | $result = parent::getDb ()->prepare('select id, value as name from ' . self::getTableName ($customId) . ' where id = ?'); |
| 77 | 89 | $result->execute (array ($id)); |
| 78 | 90 | if ($post = $result->fetchObject ()) { |
@@ -81,15 +93,15 @@ discard block |
||
| 81 | 93 | return NULL; |
| 82 | 94 | } |
| 83 | 95 | |
| 84 | - public static function getAllCustoms($customId) { |
|
| 96 | + public static function getAllCustoms($customId) |
|
| 97 | + { |
|
| 85 | 98 | $result = parent::getDb ()->query(str_format ('select {0}.id as id, {0}.value as name, count(*) as count |
| 86 | 99 | from {0}, {1} |
| 87 | 100 | where {0}.id = {1}.{2} |
| 88 | 101 | group by {0}.id, {0}.value |
| 89 | 102 | order by {0}.value', self::getTableName ($customId), self::getTableLinkName ($customId), self::getTableLinkColumn ($customId))); |
| 90 | 103 | $entryArray = array(); |
| 91 | - while ($post = $result->fetchObject ()) |
|
| 92 | - { |
|
| 104 | + while ($post = $result->fetchObject ()) { |
|
| 93 | 105 | $customColumn = new CustomColumn ($post->id, $post->name, $customId); |
| 94 | 106 | array_push ($entryArray, new Entry ($customColumn->name, $customColumn->getEntryId (), |
| 95 | 107 | str_format (localize("bookword", $post->count), $post->count), "text", |
@@ -76,7 +76,8 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - public function __construct($pid, $pquery, $pn) { |
|
| 79 | + public function __construct($pid, $pquery, $pn) |
|
| 80 | + { |
|
| 80 | 81 | global $config; |
| 81 | 82 | |
| 82 | 83 | $this->idGet = $pid; |
@@ -109,23 +110,33 @@ discard block |
||
| 109 | 110 | } |
| 110 | 111 | if (!in_array (PageQueryResult::SCOPE_SERIES, getCurrentOption ('ignored_categories'))) { |
| 111 | 112 | $series = Serie::getCount(); |
| 112 | - if (!is_null ($series)) array_push ($this->entryArray, $series); |
|
| 113 | + if (!is_null ($series)) { |
|
| 114 | + array_push ($this->entryArray, $series); |
|
| 115 | + } |
|
| 113 | 116 | } |
| 114 | 117 | if (!in_array (PageQueryResult::SCOPE_PUBLISHER, getCurrentOption ('ignored_categories'))) { |
| 115 | 118 | $publisher = Publisher::getCount(); |
| 116 | - if (!is_null ($publisher)) array_push ($this->entryArray, $publisher); |
|
| 119 | + if (!is_null ($publisher)) { |
|
| 120 | + array_push ($this->entryArray, $publisher); |
|
| 121 | + } |
|
| 117 | 122 | } |
| 118 | 123 | if (!in_array (PageQueryResult::SCOPE_TAG, getCurrentOption ('ignored_categories'))) { |
| 119 | 124 | $tags = Tag::getCount(); |
| 120 | - if (!is_null ($tags)) array_push ($this->entryArray, $tags); |
|
| 125 | + if (!is_null ($tags)) { |
|
| 126 | + array_push ($this->entryArray, $tags); |
|
| 127 | + } |
|
| 121 | 128 | } |
| 122 | 129 | if (!in_array (PageQueryResult::SCOPE_RATING, getCurrentOption ('ignored_categories'))) { |
| 123 | 130 | $rating = Rating::getCount(); |
| 124 | - if (!is_null ($rating)) array_push ($this->entryArray, $rating); |
|
| 131 | + if (!is_null ($rating)) { |
|
| 132 | + array_push ($this->entryArray, $rating); |
|
| 133 | + } |
|
| 125 | 134 | } |
| 126 | 135 | if (!in_array ("language", getCurrentOption ('ignored_categories'))) { |
| 127 | 136 | $languages = Language::getCount(); |
| 128 | - if (!is_null ($languages)) array_push ($this->entryArray, $languages); |
|
| 137 | + if (!is_null ($languages)) { |
|
| 138 | + array_push ($this->entryArray, $languages); |
|
| 139 | + } |
|
| 129 | 140 | } |
| 130 | 141 | foreach ($config['cops_calibre_custom_column'] as $lookup) { |
| 131 | 142 | $customId = CustomColumn::getCustomId ($lookup); |
@@ -135,7 +146,9 @@ discard block |
||
| 135 | 146 | } |
| 136 | 147 | $this->entryArray = array_merge ($this->entryArray, Book::getCount()); |
| 137 | 148 | |
| 138 | - if (Base::isMultipleDatabaseEnabled ()) $this->title = Base::getDbName (); |
|
| 149 | + if (Base::isMultipleDatabaseEnabled ()) { |
|
| 150 | + $this->title = Base::getDbName (); |
|
| 151 | + } |
|
| 139 | 152 | } |
| 140 | 153 | } |
| 141 | 154 | |
@@ -171,8 +184,12 @@ discard block |
||
| 171 | 184 | |
| 172 | 185 | public function containsBook () |
| 173 | 186 | { |
| 174 | - if (count ($this->entryArray) == 0) return false; |
|
| 175 | - if (get_class ($this->entryArray [0]) == "EntryBook") return true; |
|
| 187 | + if (count ($this->entryArray) == 0) { |
|
| 188 | + return false; |
|
| 189 | + } |
|
| 190 | + if (get_class ($this->entryArray [0]) == "EntryBook") { |
|
| 191 | + return true; |
|
| 192 | + } |
|
| 176 | 193 | return false; |
| 177 | 194 | } |
| 178 | 195 | } |
@@ -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,27 +88,33 @@ 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 | return $this->getUpdatedFilename () . ".kepub.epub"; |
| 107 | 114 | } |
| 108 | 115 | |
| 109 | - public function getDataLink ($rel, $title = NULL) { |
|
| 116 | + public function getDataLink ($rel, $title = NULL) |
|
| 117 | + { |
|
| 110 | 118 | global $config; |
| 111 | 119 | |
| 112 | 120 | if ($rel == Link::OPDS_ACQUISITION_TYPE && $config['cops_use_url_rewriting'] == "1") { |
@@ -116,19 +124,24 @@ discard block |
||
| 116 | 124 | return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title); |
| 117 | 125 | } |
| 118 | 126 | |
| 119 | - public function getHtmlLink () { |
|
| 127 | + public function getHtmlLink () |
|
| 128 | + { |
|
| 120 | 129 | return $this->getDataLink(Link::OPDS_ACQUISITION_TYPE)->href; |
| 121 | 130 | } |
| 122 | 131 | |
| 123 | - public function getLocalPath () { |
|
| 132 | + public function getLocalPath () |
|
| 133 | + { |
|
| 124 | 134 | return $this->book->path . "/" . $this->getFilename (); |
| 125 | 135 | } |
| 126 | 136 | |
| 127 | - public function getHtmlLinkWithRewriting ($title = NULL) { |
|
| 137 | + public function getHtmlLinkWithRewriting ($title = NULL) |
|
| 138 | + { |
|
| 128 | 139 | global $config; |
| 129 | 140 | |
| 130 | 141 | $database = ""; |
| 131 | - if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/"; |
|
| 142 | + if (!is_null (GetUrlParam (DB))) { |
|
| 143 | + $database = GetUrlParam (DB) . "/"; |
|
| 144 | + } |
|
| 132 | 145 | |
| 133 | 146 | $href = "download/" . $this->id . "/" . $database; |
| 134 | 147 | |
@@ -142,28 +155,27 @@ discard block |
||
| 142 | 155 | return new Link ($href, $this->getMimeType (), Link::OPDS_ACQUISITION_TYPE, $title); |
| 143 | 156 | } |
| 144 | 157 | |
| 145 | - public static function getDataByBook ($book) { |
|
| 158 | + public static function getDataByBook ($book) |
|
| 159 | + { |
|
| 146 | 160 | $out = array (); |
| 147 | 161 | $result = parent::getDb ()->prepare('select id, format, name |
| 148 | 162 | from data where book = ?'); |
| 149 | 163 | $result->execute (array ($book->id)); |
| 150 | 164 | |
| 151 | - while ($post = $result->fetchObject ()) |
|
| 152 | - { |
|
| 165 | + while ($post = $result->fetchObject ()) { |
|
| 153 | 166 | array_push ($out, new Data ($post, $book)); |
| 154 | 167 | } |
| 155 | 168 | return $out; |
| 156 | 169 | } |
| 157 | 170 | |
| 158 | - public static function handleThumbnailLink ($urlParam, $height) { |
|
| 171 | + public static function handleThumbnailLink ($urlParam, $height) |
|
| 172 | + { |
|
| 159 | 173 | global $config; |
| 160 | 174 | |
| 161 | 175 | if (is_null ($height)) { |
| 162 | 176 | if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) { |
| 163 | 177 | $height = $config['cops_opds_thumbnail_height']; |
| 164 | - } |
|
| 165 | - else |
|
| 166 | - { |
|
| 178 | + } else { |
|
| 167 | 179 | $height = $config['cops_html_thumbnail_height']; |
| 168 | 180 | } |
| 169 | 181 | } |
@@ -182,14 +194,17 @@ discard block |
||
| 182 | 194 | |
| 183 | 195 | if (Base::useAbsolutePath () || |
| 184 | 196 | $rel == Link::OPDS_THUMBNAIL_TYPE || |
| 185 | - ($type == "epub" && $config['cops_update_epub-metadata'])) |
|
| 186 | - { |
|
| 187 | - if ($type != "jpg") $urlParam = addURLParameter($urlParam, "type", $type); |
|
| 197 | + ($type == "epub" && $config['cops_update_epub-metadata'])) { |
|
| 198 | + if ($type != "jpg") { |
|
| 199 | + $urlParam = addURLParameter($urlParam, "type", $type); |
|
| 200 | + } |
|
| 188 | 201 | if ($rel == Link::OPDS_THUMBNAIL_TYPE) { |
| 189 | 202 | $urlParam = self::handleThumbnailLink($urlParam, $height); |
| 190 | 203 | } |
| 191 | 204 | $urlParam = addURLParameter($urlParam, "id", $book->id); |
| 192 | - if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
| 205 | + if (!is_null (GetUrlParam (DB))) { |
|
| 206 | + $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
| 207 | + } |
|
| 193 | 208 | if ($config['cops_thumbnail_handling'] != "1" && |
| 194 | 209 | !empty ($config['cops_thumbnail_handling']) && |
| 195 | 210 | $rel == Link::OPDS_THUMBNAIL_TYPE) { |
@@ -197,9 +212,7 @@ discard block |
||
| 197 | 212 | } else { |
| 198 | 213 | return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title); |
| 199 | 214 | } |
| 200 | - } |
|
| 201 | - else |
|
| 202 | - { |
|
| 215 | + } else { |
|
| 203 | 216 | return new Link (str_replace('%2F','/',rawurlencode ($book->path."/".$filename)), $mime, $rel, $title); |
| 204 | 217 | } |
| 205 | 218 | } |
@@ -14,8 +14,9 @@ |
||
| 14 | 14 | $this->idPage = Book::getEntryIdByLetter ($this->idGet); |
| 15 | 15 | |
| 16 | 16 | $count = $this->totalNumber; |
| 17 | - if ($count == -1) |
|
| 18 | - $count = count ($this->entryArray); |
|
| 17 | + if ($count == -1) { |
|
| 18 | + $count = count ($this->entryArray); |
|
| 19 | + } |
|
| 19 | 20 | |
| 20 | 21 | $this->title = str_format (localize ("splitByLetter.letter"), str_format (localize ("bookword", $count), $count), $this->idGet); |
| 21 | 22 | } |
@@ -10,24 +10,29 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public $book; |
| 12 | 12 | |
| 13 | - public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pbook) { |
|
| 13 | + public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pbook) |
|
| 14 | + { |
|
| 14 | 15 | parent::__construct ($ptitle, $pid, $pcontent, $pcontentType, $plinkArray); |
| 15 | 16 | $this->book = $pbook; |
| 16 | 17 | $this->localUpdated = $pbook->timestamp; |
| 17 | 18 | } |
| 18 | 19 | |
| 19 | - public function getCoverThumbnail () { |
|
| 20 | + public function getCoverThumbnail () |
|
| 21 | + { |
|
| 20 | 22 | foreach ($this->linkArray as $link) { |
| 21 | - if ($link->rel == Link::OPDS_THUMBNAIL_TYPE) |
|
| 22 | - return $link->hrefXhtml (); |
|
| 23 | + if ($link->rel == Link::OPDS_THUMBNAIL_TYPE) { |
|
| 24 | + return $link->hrefXhtml (); |
|
| 25 | + } |
|
| 23 | 26 | } |
| 24 | 27 | return null; |
| 25 | 28 | } |
| 26 | 29 | |
| 27 | - public function getCover () { |
|
| 30 | + public function getCover () |
|
| 31 | + { |
|
| 28 | 32 | foreach ($this->linkArray as $link) { |
| 29 | - if ($link->rel == Link::OPDS_IMAGE_TYPE) |
|
| 30 | - return $link->hrefXhtml (); |
|
| 33 | + if ($link->rel == Link::OPDS_IMAGE_TYPE) { |
|
| 34 | + return $link->hrefXhtml (); |
|
| 35 | + } |
|
| 31 | 36 | } |
| 32 | 37 | return null; |
| 33 | 38 | } |
@@ -8,10 +8,15 @@ |
||
| 8 | 8 | |
| 9 | 9 | class LinkNavigation extends Link |
| 10 | 10 | { |
| 11 | - public function __construct($phref, $prel = NULL, $ptitle = NULL) { |
|
| 11 | + public function __construct($phref, $prel = NULL, $ptitle = NULL) |
|
| 12 | + { |
|
| 12 | 13 | parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); |
| 13 | - if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 14 | - if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href; |
|
| 14 | + if (!is_null (GetUrlParam (DB))) { |
|
| 15 | + $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 16 | + } |
|
| 17 | + if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) { |
|
| 18 | + $this->href = "?" . $this->href; |
|
| 19 | + } |
|
| 15 | 20 | if (preg_match ("/(bookdetail|getJSON).php/", parent::getScriptName())) { |
| 16 | 21 | $this->href = "index.php" . $this->href; |
| 17 | 22 | } else { |
@@ -80,7 +80,8 @@ discard block |
||
| 80 | 80 | public $format = array (); |
| 81 | 81 | |
| 82 | 82 | |
| 83 | - public function __construct($line) { |
|
| 83 | + public function __construct($line) |
|
| 84 | + { |
|
| 84 | 85 | $this->id = $line->id; |
| 85 | 86 | $this->title = $line->title; |
| 86 | 87 | $this->timestamp = strtotime ($line->timestamp); |
@@ -98,60 +99,73 @@ discard block |
||
| 98 | 99 | $this->rating = $line->rating; |
| 99 | 100 | } |
| 100 | 101 | |
| 101 | - public function getEntryId () { |
|
| 102 | + public function getEntryId () |
|
| 103 | + { |
|
| 102 | 104 | return self::ALL_BOOKS_UUID.":".$this->uuid; |
| 103 | 105 | } |
| 104 | 106 | |
| 105 | - public static function getEntryIdByLetter ($startingLetter) { |
|
| 107 | + public static function getEntryIdByLetter ($startingLetter) |
|
| 108 | + { |
|
| 106 | 109 | return self::ALL_BOOKS_ID.":letter:".$startingLetter; |
| 107 | 110 | } |
| 108 | 111 | |
| 109 | - public function getUri () { |
|
| 112 | + public function getUri () |
|
| 113 | + { |
|
| 110 | 114 | return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id"; |
| 111 | 115 | } |
| 112 | 116 | |
| 113 | - public function getDetailUrl () { |
|
| 117 | + public function getDetailUrl () |
|
| 118 | + { |
|
| 114 | 119 | $urlParam = $this->getUri (); |
| 115 | - if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
| 120 | + if (!is_null (GetUrlParam (DB))) { |
|
| 121 | + $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
| 122 | + } |
|
| 116 | 123 | return 'index.php' . $urlParam; |
| 117 | 124 | } |
| 118 | 125 | |
| 119 | - public function getTitle () { |
|
| 126 | + public function getTitle () |
|
| 127 | + { |
|
| 120 | 128 | return $this->title; |
| 121 | 129 | } |
| 122 | 130 | |
| 123 | 131 | /* Other class (author, series, tag, ...) initialization and accessors */ |
| 124 | 132 | |
| 125 | - public function getAuthors () { |
|
| 133 | + public function getAuthors () |
|
| 134 | + { |
|
| 126 | 135 | if (is_null ($this->authors)) { |
| 127 | 136 | $this->authors = Author::getAuthorByBookId ($this->id); |
| 128 | 137 | } |
| 129 | 138 | return $this->authors; |
| 130 | 139 | } |
| 131 | 140 | |
| 132 | - public function getAuthorsName () { |
|
| 141 | + public function getAuthorsName () |
|
| 142 | + { |
|
| 133 | 143 | return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ())); |
| 134 | 144 | } |
| 135 | 145 | |
| 136 | - public function getAuthorsSort () { |
|
| 146 | + public function getAuthorsSort () |
|
| 147 | + { |
|
| 137 | 148 | return implode (", ", array_map (function ($author) { return $author->sort; }, $this->getAuthors ())); |
| 138 | 149 | } |
| 139 | 150 | |
| 140 | - public function getPublisher () { |
|
| 151 | + public function getPublisher () |
|
| 152 | + { |
|
| 141 | 153 | if (is_null ($this->publisher)) { |
| 142 | 154 | $this->publisher = Publisher::getPublisherByBookId ($this->id); |
| 143 | 155 | } |
| 144 | 156 | return $this->publisher; |
| 145 | 157 | } |
| 146 | 158 | |
| 147 | - public function getSerie () { |
|
| 159 | + public function getSerie () |
|
| 160 | + { |
|
| 148 | 161 | if (is_null ($this->serie)) { |
| 149 | 162 | $this->serie = Serie::getSerieByBookId ($this->id); |
| 150 | 163 | } |
| 151 | 164 | return $this->serie; |
| 152 | 165 | } |
| 153 | 166 | |
| 154 | - public function getLanguages () { |
|
| 167 | + public function getLanguages () |
|
| 168 | + { |
|
| 155 | 169 | $lang = array (); |
| 156 | 170 | $result = parent::getDb ()->prepare('select languages.lang_code |
| 157 | 171 | from books_languages_link, languages |
@@ -159,14 +173,14 @@ discard block |
||
| 159 | 173 | and book = ? |
| 160 | 174 | order by item_order'); |
| 161 | 175 | $result->execute (array ($this->id)); |
| 162 | - while ($post = $result->fetchObject ()) |
|
| 163 | - { |
|
| 176 | + while ($post = $result->fetchObject ()) { |
|
| 164 | 177 | array_push ($lang, Language::getLanguageString($post->lang_code)); |
| 165 | 178 | } |
| 166 | 179 | return implode (", ", $lang); |
| 167 | 180 | } |
| 168 | 181 | |
| 169 | - public function getTags () { |
|
| 182 | + public function getTags () |
|
| 183 | + { |
|
| 170 | 184 | if (is_null ($this->tags)) { |
| 171 | 185 | $this->tags = array (); |
| 172 | 186 | |
@@ -176,15 +190,15 @@ discard block |
||
| 176 | 190 | and book = ? |
| 177 | 191 | order by name'); |
| 178 | 192 | $result->execute (array ($this->id)); |
| 179 | - while ($post = $result->fetchObject ()) |
|
| 180 | - { |
|
| 193 | + while ($post = $result->fetchObject ()) { |
|
| 181 | 194 | array_push ($this->tags, new Tag ($post)); |
| 182 | 195 | } |
| 183 | 196 | } |
| 184 | 197 | return $this->tags; |
| 185 | 198 | } |
| 186 | 199 | |
| 187 | - public function getTagsName () { |
|
| 200 | + public function getTagsName () |
|
| 201 | + { |
|
| 188 | 202 | return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ())); |
| 189 | 203 | } |
| 190 | 204 | |
@@ -198,9 +212,12 @@ discard block |
||
| 198 | 212 | |
| 199 | 213 | /* End of other class (author, series, tag, ...) initialization and accessors */ |
| 200 | 214 | |
| 201 | - public static function getFilterString () { |
|
| 215 | + public static function getFilterString () |
|
| 216 | + { |
|
| 202 | 217 | $filter = getURLParam ("tag", NULL); |
| 203 | - if (empty ($filter)) return ""; |
|
| 218 | + if (empty ($filter)) { |
|
| 219 | + return ""; |
|
| 220 | + } |
|
| 204 | 221 | |
| 205 | 222 | $exists = true; |
| 206 | 223 | if (preg_match ("/^!(.*)$/", $filter, $matches)) { |
@@ -240,7 +257,8 @@ discard block |
||
| 240 | 257 | return reset ($reduced); |
| 241 | 258 | } |
| 242 | 259 | |
| 243 | - public function getRating () { |
|
| 260 | + public function getRating () |
|
| 261 | + { |
|
| 244 | 262 | if (is_null ($this->rating) || $this->rating == 0) { |
| 245 | 263 | return ""; |
| 246 | 264 | } |
@@ -254,7 +272,8 @@ discard block |
||
| 254 | 272 | return $retour; |
| 255 | 273 | } |
| 256 | 274 | |
| 257 | - public function getPubDate () { |
|
| 275 | + public function getPubDate () |
|
| 276 | + { |
|
| 258 | 277 | if (empty ($this->pubdate)) { |
| 259 | 278 | return ""; |
| 260 | 279 | } |
@@ -265,23 +284,22 @@ discard block |
||
| 265 | 284 | return ""; |
| 266 | 285 | } |
| 267 | 286 | |
| 268 | - public function getComment ($withSerie = true) { |
|
| 287 | + public function getComment ($withSerie = true) |
|
| 288 | + { |
|
| 269 | 289 | $addition = ""; |
| 270 | 290 | $se = $this->getSerie (); |
| 271 | 291 | if (!is_null ($se) && $withSerie) { |
| 272 | 292 | $addition = $addition . "<strong>" . localize("content.series") . "</strong>" . str_format (localize ("content.series.data"), $this->seriesIndex, htmlspecialchars ($se->name)) . "<br />\n"; |
| 273 | 293 | } |
| 274 | - if (preg_match ("/<\/(div|p|a|span)>/", $this->comment)) |
|
| 275 | - { |
|
| 294 | + if (preg_match ("/<\/(div|p|a|span)>/", $this->comment)) { |
|
| 276 | 295 | return $addition . html2xhtml ($this->comment); |
| 277 | - } |
|
| 278 | - else |
|
| 279 | - { |
|
| 296 | + } else { |
|
| 280 | 297 | return $addition . htmlspecialchars ($this->comment); |
| 281 | 298 | } |
| 282 | 299 | } |
| 283 | 300 | |
| 284 | - public function getDataFormat ($format) { |
|
| 301 | + public function getDataFormat ($format) |
|
| 302 | + { |
|
| 285 | 303 | $reduced = array_filter ($this->getDatas (), function ($data) use ($format) { |
| 286 | 304 | return $data->format == $format; |
| 287 | 305 | }); |
@@ -290,23 +308,19 @@ discard block |
||
| 290 | 308 | |
| 291 | 309 | public function getFilePath ($extension, $idData = NULL, $relative = false) |
| 292 | 310 | { |
| 293 | - if ($extension == "jpg") |
|
| 294 | - { |
|
| 311 | + if ($extension == "jpg") { |
|
| 295 | 312 | $file = "cover.jpg"; |
| 296 | - } |
|
| 297 | - else |
|
| 298 | - { |
|
| 313 | + } else { |
|
| 299 | 314 | $data = $this->getDataById ($idData); |
| 300 | - if (!$data) return NULL; |
|
| 315 | + if (!$data) { |
|
| 316 | + return NULL; |
|
| 317 | + } |
|
| 301 | 318 | $file = $data->name . "." . strtolower ($data->format); |
| 302 | 319 | } |
| 303 | 320 | |
| 304 | - if ($relative) |
|
| 305 | - { |
|
| 321 | + if ($relative) { |
|
| 306 | 322 | return $this->relativePath."/".$file; |
| 307 | - } |
|
| 308 | - else |
|
| 309 | - { |
|
| 323 | + } else { |
|
| 310 | 324 | return $this->path."/".$file; |
| 311 | 325 | } |
| 312 | 326 | } |
@@ -316,8 +330,7 @@ discard block |
||
| 316 | 330 | global $config; |
| 317 | 331 | $data = $this->getDataById ($idData); |
| 318 | 332 | |
| 319 | - try |
|
| 320 | - { |
|
| 333 | + try { |
|
| 321 | 334 | $epub = new EPub ($data->getLocalPath ()); |
| 322 | 335 | |
| 323 | 336 | $epub->Title ($this->title); |
@@ -340,14 +353,13 @@ discard block |
||
| 340 | 353 | $epub->updateForKepub (); |
| 341 | 354 | } |
| 342 | 355 | $epub->download ($data->getUpdatedFilenameEpub ()); |
| 343 | - } |
|
| 344 | - catch (Exception $e) |
|
| 345 | - { |
|
| 356 | + } catch (Exception $e) { |
|
| 346 | 357 | echo "Exception : " . $e->getMessage(); |
| 347 | 358 | } |
| 348 | 359 | } |
| 349 | 360 | |
| 350 | - public function getThumbnail ($width, $height, $outputfile = NULL) { |
|
| 361 | + public function getThumbnail ($width, $height, $outputfile = NULL) |
|
| 362 | + { |
|
| 351 | 363 | if (is_null ($width) && is_null ($height)) { |
| 352 | 364 | return false; |
| 353 | 365 | } |
@@ -386,17 +398,14 @@ discard block |
||
| 386 | 398 | { |
| 387 | 399 | $linkArray = array(); |
| 388 | 400 | |
| 389 | - if ($this->hasCover) |
|
| 390 | - { |
|
| 401 | + if ($this->hasCover) { |
|
| 391 | 402 | array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)); |
| 392 | 403 | |
| 393 | 404 | array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL)); |
| 394 | 405 | } |
| 395 | 406 | |
| 396 | - foreach ($this->getDatas () as $data) |
|
| 397 | - { |
|
| 398 | - if ($data->isKnownType ()) |
|
| 399 | - { |
|
| 407 | + foreach ($this->getDatas () as $data) { |
|
| 408 | + if ($data->isKnownType ()) { |
|
| 400 | 409 | array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format)); |
| 401 | 410 | } |
| 402 | 411 | } |
@@ -414,17 +423,20 @@ discard block |
||
| 414 | 423 | } |
| 415 | 424 | |
| 416 | 425 | |
| 417 | - public function getEntry () { |
|
| 426 | + public function getEntry () |
|
| 427 | + { |
|
| 418 | 428 | return new EntryBook ($this->getTitle (), $this->getEntryId (), |
| 419 | 429 | $this->getComment (), "text/html", |
| 420 | 430 | $this->getLinkArray (), $this); |
| 421 | 431 | } |
| 422 | 432 | |
| 423 | - public static function getBookCount($database = NULL) { |
|
| 433 | + public static function getBookCount($database = NULL) |
|
| 434 | + { |
|
| 424 | 435 | return parent::executeQuerySingle ('select count(*) from books', $database); |
| 425 | 436 | } |
| 426 | 437 | |
| 427 | - public static function getCount() { |
|
| 438 | + public static function getCount() |
|
| 439 | + { |
|
| 428 | 440 | global $config; |
| 429 | 441 | $nBooks = parent::executeQuerySingle ('select count(*) from books'); |
| 430 | 442 | $result = array(); |
@@ -443,55 +455,62 @@ discard block |
||
| 443 | 455 | return $result; |
| 444 | 456 | } |
| 445 | 457 | |
| 446 | - public static function getBooksByAuthor($authorId, $n) { |
|
| 458 | + public static function getBooksByAuthor($authorId, $n) |
|
| 459 | + { |
|
| 447 | 460 | return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n); |
| 448 | 461 | } |
| 449 | 462 | |
| 450 | - public static function getBooksByRating($ratingId, $n) { |
|
| 463 | + public static function getBooksByRating($ratingId, $n) |
|
| 464 | + { |
|
| 451 | 465 | return self::getEntryArray (self::SQL_BOOKS_BY_RATING, array ($ratingId), $n); |
| 452 | 466 | } |
| 453 | 467 | |
| 454 | - public static function getBooksByPublisher($publisherId, $n) { |
|
| 468 | + public static function getBooksByPublisher($publisherId, $n) |
|
| 469 | + { |
|
| 455 | 470 | return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n); |
| 456 | 471 | } |
| 457 | 472 | |
| 458 | - public static function getBooksBySeries($serieId, $n) { |
|
| 473 | + public static function getBooksBySeries($serieId, $n) |
|
| 474 | + { |
|
| 459 | 475 | return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n); |
| 460 | 476 | } |
| 461 | 477 | |
| 462 | - public static function getBooksByTag($tagId, $n) { |
|
| 478 | + public static function getBooksByTag($tagId, $n) |
|
| 479 | + { |
|
| 463 | 480 | return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n); |
| 464 | 481 | } |
| 465 | 482 | |
| 466 | - public static function getBooksByLanguage($languageId, $n) { |
|
| 483 | + public static function getBooksByLanguage($languageId, $n) |
|
| 484 | + { |
|
| 467 | 485 | return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n); |
| 468 | 486 | } |
| 469 | 487 | |
| 470 | - public static function getBooksByCustom($customId, $id, $n) { |
|
| 488 | + public static function getBooksByCustom($customId, $id, $n) |
|
| 489 | + { |
|
| 471 | 490 | $query = str_format (self::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", CustomColumn::getTableLinkName ($customId), CustomColumn::getTableLinkColumn ($customId)); |
| 472 | 491 | return self::getEntryArray ($query, array ($id), $n); |
| 473 | 492 | } |
| 474 | 493 | |
| 475 | - public static function getBookById($bookId) { |
|
| 494 | + public static function getBookById($bookId) |
|
| 495 | + { |
|
| 476 | 496 | $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' |
| 477 | 497 | from books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
| 478 | 498 | where books.id = ?'); |
| 479 | 499 | $result->execute (array ($bookId)); |
| 480 | - while ($post = $result->fetchObject ()) |
|
| 481 | - { |
|
| 500 | + while ($post = $result->fetchObject ()) { |
|
| 482 | 501 | $book = new Book ($post); |
| 483 | 502 | return $book; |
| 484 | 503 | } |
| 485 | 504 | return NULL; |
| 486 | 505 | } |
| 487 | 506 | |
| 488 | - public static function getBookByDataId($dataId) { |
|
| 507 | + public static function getBookByDataId($dataId) |
|
| 508 | + { |
|
| 489 | 509 | $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format |
| 490 | 510 | from data, books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
| 491 | 511 | where data.book = books.id and data.id = ?'); |
| 492 | 512 | $result->execute (array ($dataId)); |
| 493 | - while ($post = $result->fetchObject ()) |
|
| 494 | - { |
|
| 513 | + while ($post = $result->fetchObject ()) { |
|
| 495 | 514 | $book = new Book ($post); |
| 496 | 515 | $data = new Data ($post, $book); |
| 497 | 516 | $data->id = $dataId; |
@@ -501,7 +520,8 @@ discard block |
||
| 501 | 520 | return NULL; |
| 502 | 521 | } |
| 503 | 522 | |
| 504 | - public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 523 | + public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) |
|
| 524 | + { |
|
| 505 | 525 | $i = 0; |
| 506 | 526 | $critArray = array (); |
| 507 | 527 | foreach (array (PageQueryResult::SCOPE_AUTHOR, |
@@ -512,8 +532,7 @@ discard block |
||
| 512 | 532 | if (in_array($key, getCurrentOption ('ignored_categories')) || |
| 513 | 533 | (!array_key_exists ($key, $query) && !array_key_exists ("all", $query))) { |
| 514 | 534 | $critArray [$i] = self::BAD_SEARCH; |
| 515 | - } |
|
| 516 | - else { |
|
| 535 | + } else { |
|
| 517 | 536 | if (array_key_exists ($key, $query)) { |
| 518 | 537 | $critArray [$i] = $query [$key]; |
| 519 | 538 | } else { |
@@ -525,19 +544,20 @@ discard block |
||
| 525 | 544 | return self::getEntryArray (self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage); |
| 526 | 545 | } |
| 527 | 546 | |
| 528 | - public static function getBooks($n) { |
|
| 547 | + public static function getBooks($n) |
|
| 548 | + { |
|
| 529 | 549 | list ($entryArray, $totalNumber) = self::getEntryArray (self::SQL_BOOKS_ALL , array (), $n); |
| 530 | 550 | return array ($entryArray, $totalNumber); |
| 531 | 551 | } |
| 532 | 552 | |
| 533 | - public static function getAllBooks() { |
|
| 553 | + public static function getAllBooks() |
|
| 554 | + { |
|
| 534 | 555 | list (, $result) = parent::executeQuery ("select {0} |
| 535 | 556 | from books |
| 536 | 557 | group by substr (upper (sort), 1, 1) |
| 537 | 558 | order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", self::getFilterString (), array (), -1); |
| 538 | 559 | $entryArray = array(); |
| 539 | - while ($post = $result->fetchObject ()) |
|
| 540 | - { |
|
| 560 | + while ($post = $result->fetchObject ()) { |
|
| 541 | 561 | array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title), |
| 542 | 562 | str_format (localize("bookword", $post->count), $post->count), "text", |
| 543 | 563 | array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))), "", $post->count)); |
@@ -545,15 +565,16 @@ discard block |
||
| 545 | 565 | return $entryArray; |
| 546 | 566 | } |
| 547 | 567 | |
| 548 | - public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 568 | + public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) |
|
| 569 | + { |
|
| 549 | 570 | return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage); |
| 550 | 571 | } |
| 551 | 572 | |
| 552 | - public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 573 | + public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) |
|
| 574 | + { |
|
| 553 | 575 | list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage); |
| 554 | 576 | $entryArray = array(); |
| 555 | - while ($post = $result->fetchObject ()) |
|
| 556 | - { |
|
| 577 | + while ($post = $result->fetchObject ()) { |
|
| 557 | 578 | $book = new Book ($post); |
| 558 | 579 | array_push ($entryArray, $book->getEntry ()); |
| 559 | 580 | } |
@@ -561,7 +582,8 @@ discard block |
||
| 561 | 582 | } |
| 562 | 583 | |
| 563 | 584 | |
| 564 | - public static function getAllRecentBooks() { |
|
| 585 | + public static function getAllRecentBooks() |
|
| 586 | + { |
|
| 565 | 587 | global $config; |
| 566 | 588 | list ($entryArray, ) = self::getEntryArray (self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array (), -1); |
| 567 | 589 | return $entryArray; |
@@ -15,33 +15,38 @@ discard block |
||
| 15 | 15 | public $id; |
| 16 | 16 | public $name; |
| 17 | 17 | |
| 18 | - public function __construct($pid, $pname) { |
|
| 18 | + public function __construct($pid, $pname) |
|
| 19 | + { |
|
| 19 | 20 | $this->id = $pid; |
| 20 | 21 | $this->name = $pname; |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | - public function getUri () { |
|
| 24 | + public function getUri () |
|
| 25 | + { |
|
| 24 | 26 | return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id"; |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | - public function getEntryId () { |
|
| 29 | + public function getEntryId () |
|
| 30 | + { |
|
| 28 | 31 | return self::ALL_RATING_ID.":".$this->id; |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | - public static function getCount() { |
|
| 34 | + public static function getCount() |
|
| 35 | + { |
|
| 32 | 36 | // str_format (localize("ratings", count(array)) |
| 33 | 37 | return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings"); |
| 34 | 38 | } |
| 35 | 39 | |
| 36 | - public static function getAllRatings() { |
|
| 40 | + public static function getAllRatings() |
|
| 41 | + { |
|
| 37 | 42 | return self::getEntryArray (self::SQL_ALL_RATINGS, array ()); |
| 38 | 43 | } |
| 39 | 44 | |
| 40 | - public static function getEntryArray ($query, $params) { |
|
| 45 | + public static function getEntryArray ($query, $params) |
|
| 46 | + { |
|
| 41 | 47 | list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1); |
| 42 | 48 | $entryArray = array(); |
| 43 | - while ($post = $result->fetchObject ()) |
|
| 44 | - { |
|
| 49 | + while ($post = $result->fetchObject ()) { |
|
| 45 | 50 | $ratingObj = new Rating ($post->id, $post->rating); |
| 46 | 51 | $rating=$post->rating/2; |
| 47 | 52 | $rating = str_format (localize("ratingword", $rating), $rating); |
@@ -52,7 +57,8 @@ discard block |
||
| 52 | 57 | return $entryArray; |
| 53 | 58 | } |
| 54 | 59 | |
| 55 | - public static function getRatingById ($ratingId) { |
|
| 60 | + public static function getRatingById ($ratingId) |
|
| 61 | + { |
|
| 56 | 62 | $result = parent::getDb ()->prepare('select rating from ratings where id = ?'); |
| 57 | 63 | $result->execute (array ($ratingId)); |
| 58 | 64 | return new Rating ($ratingId, $result->fetchColumn ()); |
@@ -37,23 +37,27 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | private static $db = NULL; |
| 39 | 39 | |
| 40 | - public static function isMultipleDatabaseEnabled () { |
|
| 40 | + public static function isMultipleDatabaseEnabled () |
|
| 41 | + { |
|
| 41 | 42 | global $config; |
| 42 | 43 | return is_array ($config['calibre_directory']); |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | - public static function useAbsolutePath () { |
|
| 46 | + public static function useAbsolutePath () |
|
| 47 | + { |
|
| 46 | 48 | global $config; |
| 47 | 49 | $path = self::getDbDirectory(); |
| 48 | 50 | return preg_match ('/^\//', $path) || // Linux / |
| 49 | 51 | preg_match ('/^\w\:/', $path); // Windows X: |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | - public static function noDatabaseSelected () { |
|
| 54 | + public static function noDatabaseSelected () |
|
| 55 | + { |
|
| 53 | 56 | return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB)); |
| 54 | 57 | } |
| 55 | 58 | |
| 56 | - public static function getDbList () { |
|
| 59 | + public static function getDbList () |
|
| 60 | + { |
|
| 57 | 61 | global $config; |
| 58 | 62 | if (self::isMultipleDatabaseEnabled ()) { |
| 59 | 63 | return $config['calibre_directory']; |
@@ -62,7 +66,8 @@ discard block |
||
| 62 | 66 | } |
| 63 | 67 | } |
| 64 | 68 | |
| 65 | - public static function getDbNameList () { |
|
| 69 | + public static function getDbNameList () |
|
| 70 | + { |
|
| 66 | 71 | global $config; |
| 67 | 72 | if (self::isMultipleDatabaseEnabled ()) { |
| 68 | 73 | return array_keys ($config['calibre_directory']); |
@@ -71,10 +76,13 @@ discard block |
||
| 71 | 76 | } |
| 72 | 77 | } |
| 73 | 78 | |
| 74 | - public static function getDbName ($database = NULL) { |
|
| 79 | + public static function getDbName ($database = NULL) |
|
| 80 | + { |
|
| 75 | 81 | global $config; |
| 76 | 82 | if (self::isMultipleDatabaseEnabled ()) { |
| 77 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 83 | + if (is_null ($database)) { |
|
| 84 | + $database = GetUrlParam (DB, 0); |
|
| 85 | + } |
|
| 78 | 86 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 79 | 87 | return self::error ($database); |
| 80 | 88 | } |
@@ -84,10 +92,13 @@ discard block |
||
| 84 | 92 | return ""; |
| 85 | 93 | } |
| 86 | 94 | |
| 87 | - public static function getDbDirectory ($database = NULL) { |
|
| 95 | + public static function getDbDirectory ($database = NULL) |
|
| 96 | + { |
|
| 88 | 97 | global $config; |
| 89 | 98 | if (self::isMultipleDatabaseEnabled ()) { |
| 90 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 99 | + if (is_null ($database)) { |
|
| 100 | + $database = GetUrlParam (DB, 0); |
|
| 101 | + } |
|
| 91 | 102 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 92 | 103 | return self::error ($database); |
| 93 | 104 | } |
@@ -98,18 +109,21 @@ discard block |
||
| 98 | 109 | } |
| 99 | 110 | |
| 100 | 111 | |
| 101 | - public static function getDbFileName ($database = NULL) { |
|
| 112 | + public static function getDbFileName ($database = NULL) |
|
| 113 | + { |
|
| 102 | 114 | return self::getDbDirectory ($database) .'metadata.db'; |
| 103 | 115 | } |
| 104 | 116 | |
| 105 | - private static function error ($database) { |
|
| 117 | + private static function error ($database) |
|
| 118 | + { |
|
| 106 | 119 | if (php_sapi_name() != "cli") { |
| 107 | 120 | header("location: checkconfig.php?err=1"); |
| 108 | 121 | } |
| 109 | 122 | throw new Exception("Database <{$database}> not found."); |
| 110 | 123 | } |
| 111 | 124 | |
| 112 | - public static function getDb ($database = NULL) { |
|
| 125 | + public static function getDb ($database = NULL) |
|
| 126 | + { |
|
| 113 | 127 | if (is_null (self::$db)) { |
| 114 | 128 | try { |
| 115 | 129 | if (is_readable (self::getDbFileName ($database))) { |
@@ -127,7 +141,8 @@ discard block |
||
| 127 | 141 | return self::$db; |
| 128 | 142 | } |
| 129 | 143 | |
| 130 | - public static function checkDatabaseAvailability () { |
|
| 144 | + public static function checkDatabaseAvailability () |
|
| 145 | + { |
|
| 131 | 146 | if (self::noDatabaseSelected ()) { |
| 132 | 147 | for ($i = 0; $i < count (self::getDbList ()); $i++) { |
| 133 | 148 | self::getDb ($i); |
@@ -139,31 +154,36 @@ discard block |
||
| 139 | 154 | return true; |
| 140 | 155 | } |
| 141 | 156 | |
| 142 | - public static function clearDb () { |
|
| 157 | + public static function clearDb () |
|
| 158 | + { |
|
| 143 | 159 | self::$db = NULL; |
| 144 | 160 | } |
| 145 | 161 | |
| 146 | - public static function executeQuerySingle ($query, $database = NULL) { |
|
| 162 | + public static function executeQuerySingle ($query, $database = NULL) |
|
| 163 | + { |
|
| 147 | 164 | return self::getDb ($database)->query($query)->fetchColumn(); |
| 148 | 165 | } |
| 149 | 166 | |
| 150 | - public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) { |
|
| 167 | + public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) |
|
| 168 | + { |
|
| 151 | 169 | if (!$numberOfString) { |
| 152 | 170 | $numberOfString = $table . ".alphabetical"; |
| 153 | 171 | } |
| 154 | 172 | $count = self::executeQuerySingle ('select count(*) from ' . $table); |
| 155 | - if ($count == 0) return NULL; |
|
| 173 | + if ($count == 0) { |
|
| 174 | + return NULL; |
|
| 175 | + } |
|
| 156 | 176 | $entry = new Entry (localize($table . ".title"), $id, |
| 157 | 177 | str_format (localize($numberOfString, $count), $count), "text", |
| 158 | 178 | array ( new LinkNavigation ("?page=".$pageId)), "", $count); |
| 159 | 179 | return $entry; |
| 160 | 180 | } |
| 161 | 181 | |
| 162 | - public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) { |
|
| 182 | + public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) |
|
| 183 | + { |
|
| 163 | 184 | list (, $result) = self::executeQuery ($query, $columns, "", $params, -1); |
| 164 | 185 | $entryArray = array(); |
| 165 | - while ($post = $result->fetchObject ()) |
|
| 166 | - { |
|
| 186 | + while ($post = $result->fetchObject ()) { |
|
| 167 | 187 | $instance = new $category ($post); |
| 168 | 188 | if (property_exists($post, "sort")) { |
| 169 | 189 | $title = $post->sort; |
@@ -177,7 +197,8 @@ discard block |
||
| 177 | 197 | return $entryArray; |
| 178 | 198 | } |
| 179 | 199 | |
| 180 | - public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 200 | + public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) |
|
| 201 | + { |
|
| 181 | 202 | $totalResult = -1; |
| 182 | 203 | |
| 183 | 204 | if (useNormAndUp ()) { |
@@ -189,8 +210,7 @@ discard block |
||
| 189 | 210 | $numberPerPage = getCurrentOption ("max_item_per_page"); |
| 190 | 211 | } |
| 191 | 212 | |
| 192 | - if ($numberPerPage != -1 && $n != -1) |
|
| 193 | - { |
|
| 213 | + if ($numberPerPage != -1 && $n != -1) { |
|
| 194 | 214 | // First check total number of results |
| 195 | 215 | $result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter)); |
| 196 | 216 | $result->execute ($params); |