@@ -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 | 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 | self::error ($database); |
| 93 | 104 | } |
@@ -98,28 +109,34 @@ discard block |
||
| 98 | 109 | } |
| 99 | 110 | |
| 100 | 111 | // -DC- Add image directory |
| 101 | - public static function getImgDirectory ($database = NULL) { |
|
| 112 | + public static function getImgDirectory ($database = NULL) |
|
| 113 | + { |
|
| 102 | 114 | global $config; |
| 103 | 115 | if (self::isMultipleDatabaseEnabled ()) { |
| 104 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 116 | + if (is_null ($database)) { |
|
| 117 | + $database = GetUrlParam (DB, 0); |
|
| 118 | + } |
|
| 105 | 119 | $array = array_values ($config['image_directory']); |
| 106 | 120 | return $array[$database]; |
| 107 | 121 | } |
| 108 | 122 | return $config['image_directory']; |
| 109 | 123 | } |
| 110 | 124 | |
| 111 | - public static function getDbFileName ($database = NULL) { |
|
| 125 | + public static function getDbFileName ($database = NULL) |
|
| 126 | + { |
|
| 112 | 127 | return self::getDbDirectory ($database) .'metadata.db'; |
| 113 | 128 | } |
| 114 | 129 | |
| 115 | - private static function error ($database) { |
|
| 130 | + private static function error ($database) |
|
| 131 | + { |
|
| 116 | 132 | if (php_sapi_name() != "cli") { |
| 117 | 133 | header("location: checkconfig.php?err=1"); |
| 118 | 134 | } |
| 119 | 135 | throw new Exception("Database <{$database}> not found."); |
| 120 | 136 | } |
| 121 | 137 | |
| 122 | - public static function getDb ($database = NULL) { |
|
| 138 | + public static function getDb ($database = NULL) |
|
| 139 | + { |
|
| 123 | 140 | if (is_null (self::$db)) { |
| 124 | 141 | try { |
| 125 | 142 | if (is_readable (self::getDbFileName ($database))) { |
@@ -137,7 +154,8 @@ discard block |
||
| 137 | 154 | return self::$db; |
| 138 | 155 | } |
| 139 | 156 | |
| 140 | - public static function checkDatabaseAvailability () { |
|
| 157 | + public static function checkDatabaseAvailability () |
|
| 158 | + { |
|
| 141 | 159 | if (self::noDatabaseSelected ()) { |
| 142 | 160 | for ($i = 0; $i < count (self::getDbList ()); $i++) { |
| 143 | 161 | self::getDb ($i); |
@@ -149,33 +167,38 @@ discard block |
||
| 149 | 167 | return true; |
| 150 | 168 | } |
| 151 | 169 | |
| 152 | - public static function clearDb () { |
|
| 170 | + public static function clearDb () |
|
| 171 | + { |
|
| 153 | 172 | self::$db = NULL; |
| 154 | 173 | } |
| 155 | 174 | |
| 156 | - public static function executeQuerySingle ($query, $database = NULL) { |
|
| 175 | + public static function executeQuerySingle ($query, $database = NULL) |
|
| 176 | + { |
|
| 157 | 177 | return self::getDb ($database)->query($query)->fetchColumn(); |
| 158 | 178 | } |
| 159 | 179 | |
| 160 | - public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) { |
|
| 180 | + public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) |
|
| 181 | + { |
|
| 161 | 182 | if (!$numberOfString) { |
| 162 | 183 | $numberOfString = $table . ".alphabetical"; |
| 163 | 184 | } |
| 164 | 185 | $count = self::executeQuerySingle ('select count(*) from ' . $table); |
| 165 | - if ($count == 0) return NULL; |
|
| 186 | + if ($count == 0) { |
|
| 187 | + return NULL; |
|
| 188 | + } |
|
| 166 | 189 | $entry = new Entry (localize($table . ".title"), $id, |
| 167 | 190 | str_format (localize($numberOfString, $count), $count), "text", |
| 168 | 191 | array ( new LinkNavigation ("?page=".$pageId)), "", $count); |
| 169 | 192 | return $entry; |
| 170 | 193 | } |
| 171 | 194 | |
| 172 | - public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) { |
|
| 195 | + public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) |
|
| 196 | + { |
|
| 173 | 197 | /* @var $result PDOStatement */ |
| 174 | 198 | |
| 175 | 199 | list (, $result) = self::executeQuery ($query, $columns, "", $params, -1); |
| 176 | 200 | $entryArray = array(); |
| 177 | - while ($post = $result->fetchObject ()) |
|
| 178 | - { |
|
| 201 | + while ($post = $result->fetchObject ()) { |
|
| 179 | 202 | /* @var $instance Author|Tag|Serie|Publisher */ |
| 180 | 203 | |
| 181 | 204 | $instance = new $category ($post); |
@@ -191,7 +214,8 @@ discard block |
||
| 191 | 214 | return $entryArray; |
| 192 | 215 | } |
| 193 | 216 | |
| 194 | - public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 217 | + public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) |
|
| 218 | + { |
|
| 195 | 219 | $totalResult = -1; |
| 196 | 220 | |
| 197 | 221 | if (useNormAndUp ()) { |
@@ -203,8 +227,7 @@ discard block |
||
| 203 | 227 | $numberPerPage = getCurrentOption ("max_item_per_page"); |
| 204 | 228 | } |
| 205 | 229 | |
| 206 | - if ($numberPerPage != -1 && $n != -1) |
|
| 207 | - { |
|
| 230 | + if ($numberPerPage != -1 && $n != -1) { |
|
| 208 | 231 | // First check total number of results |
| 209 | 232 | $result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter)); |
| 210 | 233 | $result->execute ($params); |
@@ -108,7 +108,8 @@ discard block |
||
| 108 | 108 | public $format = array (); |
| 109 | 109 | private $coverFileName = NULL; |
| 110 | 110 | |
| 111 | - public function __construct($line) { |
|
| 111 | + public function __construct($line) |
|
| 112 | + { |
|
| 112 | 113 | global $config; |
| 113 | 114 | |
| 114 | 115 | $this->id = $line->id; |
@@ -168,8 +169,7 @@ discard block |
||
| 168 | 169 | } |
| 169 | 170 | if ($cover === false || !file_exists($cover)) { |
| 170 | 171 | $this->hasCover = 0; |
| 171 | - } |
|
| 172 | - else { |
|
| 172 | + } else { |
|
| 173 | 173 | $this->coverFileName = $cover; |
| 174 | 174 | } |
| 175 | 175 | } |
@@ -190,25 +190,32 @@ discard block |
||
| 190 | 190 | return $res; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - public function getEntryId() { |
|
| 193 | + public function getEntryId() |
|
| 194 | + { |
|
| 194 | 195 | return self::ALL_BOOKS_UUID.':'.$this->uuid; |
| 195 | 196 | } |
| 196 | 197 | |
| 197 | - public static function getEntryIdByLetter ($startingLetter) { |
|
| 198 | + public static function getEntryIdByLetter ($startingLetter) |
|
| 199 | + { |
|
| 198 | 200 | return self::ALL_BOOKS_ID.':letter:'.$startingLetter; |
| 199 | 201 | } |
| 200 | 202 | |
| 201 | - public function getUri () { |
|
| 203 | + public function getUri () |
|
| 204 | + { |
|
| 202 | 205 | return '?page='.parent::PAGE_BOOK_DETAIL.'&id=' . $this->id; |
| 203 | 206 | } |
| 204 | 207 | |
| 205 | - public function getDetailUrl () { |
|
| 208 | + public function getDetailUrl () |
|
| 209 | + { |
|
| 206 | 210 | $urlParam = $this->getUri(); |
| 207 | - if (!is_null(GetUrlParam(DB))) $urlParam = addURLParameter($urlParam, DB, GetUrlParam (DB)); |
|
| 211 | + if (!is_null(GetUrlParam(DB))) { |
|
| 212 | + $urlParam = addURLParameter($urlParam, DB, GetUrlParam (DB)); |
|
| 213 | + } |
|
| 208 | 214 | return 'index.php' . $urlParam; |
| 209 | 215 | } |
| 210 | 216 | |
| 211 | - public function getTitle () { |
|
| 217 | + public function getTitle () |
|
| 218 | + { |
|
| 212 | 219 | return $this->title; |
| 213 | 220 | } |
| 214 | 221 | |
@@ -217,22 +224,26 @@ discard block |
||
| 217 | 224 | /** |
| 218 | 225 | * @return Author[] |
| 219 | 226 | */ |
| 220 | - public function getAuthors () { |
|
| 227 | + public function getAuthors () |
|
| 228 | + { |
|
| 221 | 229 | if (is_null($this->authors)) { |
| 222 | 230 | $this->authors = Author::getAuthorByBookId($this->id); |
| 223 | 231 | } |
| 224 | 232 | return $this->authors; |
| 225 | 233 | } |
| 226 | 234 | |
| 227 | - public function getAuthorsName () { |
|
| 235 | + public function getAuthorsName () |
|
| 236 | + { |
|
| 228 | 237 | return implode(', ', array_map(function ($author) { return $author->name; }, $this->getAuthors())); |
| 229 | 238 | } |
| 230 | 239 | |
| 231 | - public function getAuthorsSort () { |
|
| 240 | + public function getAuthorsSort () |
|
| 241 | + { |
|
| 232 | 242 | return implode(', ', array_map(function ($author) { return $author->sort; }, $this->getAuthors())); |
| 233 | 243 | } |
| 234 | 244 | |
| 235 | - public function getPublisher () { |
|
| 245 | + public function getPublisher () |
|
| 246 | + { |
|
| 236 | 247 | if (is_null($this->publisher)) { |
| 237 | 248 | $this->publisher = Publisher::getPublisherByBookId($this->id); |
| 238 | 249 | } |
@@ -242,7 +253,8 @@ discard block |
||
| 242 | 253 | /** |
| 243 | 254 | * @return Serie |
| 244 | 255 | */ |
| 245 | - public function getSerie() { |
|
| 256 | + public function getSerie() |
|
| 257 | + { |
|
| 246 | 258 | if (is_null($this->serie)) { |
| 247 | 259 | $this->serie = Serie::getSerieByBookId($this->id); |
| 248 | 260 | } |
@@ -252,7 +264,8 @@ discard block |
||
| 252 | 264 | /** |
| 253 | 265 | * @return string |
| 254 | 266 | */ |
| 255 | - public function getLanguages() { |
|
| 267 | + public function getLanguages() |
|
| 268 | + { |
|
| 256 | 269 | $lang = array(); |
| 257 | 270 | $result = parent::getDb()->prepare('select languages.lang_code |
| 258 | 271 | from books_languages_link, languages |
@@ -260,8 +273,7 @@ discard block |
||
| 260 | 273 | and book = ? |
| 261 | 274 | order by item_order'); |
| 262 | 275 | $result->execute(array($this->id)); |
| 263 | - while ($post = $result->fetchObject()) |
|
| 264 | - { |
|
| 276 | + while ($post = $result->fetchObject()) { |
|
| 265 | 277 | array_push($lang, Language::getLanguageString($post->lang_code)); |
| 266 | 278 | } |
| 267 | 279 | return implode(', ', $lang); |
@@ -270,7 +282,8 @@ discard block |
||
| 270 | 282 | /** |
| 271 | 283 | * @return Tag[] |
| 272 | 284 | */ |
| 273 | - public function getTags() { |
|
| 285 | + public function getTags() |
|
| 286 | + { |
|
| 274 | 287 | if (is_null ($this->tags)) { |
| 275 | 288 | $this->tags = array(); |
| 276 | 289 | |
@@ -280,15 +293,15 @@ discard block |
||
| 280 | 293 | and book = ? |
| 281 | 294 | order by name'); |
| 282 | 295 | $result->execute(array($this->id)); |
| 283 | - while ($post = $result->fetchObject()) |
|
| 284 | - { |
|
| 296 | + while ($post = $result->fetchObject()) { |
|
| 285 | 297 | array_push($this->tags, new Tag($post)); |
| 286 | 298 | } |
| 287 | 299 | } |
| 288 | 300 | return $this->tags; |
| 289 | 301 | } |
| 290 | 302 | |
| 291 | - public function getTagsName() { |
|
| 303 | + public function getTagsName() |
|
| 304 | + { |
|
| 292 | 305 | return implode(', ', array_map(function ($tag) { return $tag->name; }, $this->getTags())); |
| 293 | 306 | } |
| 294 | 307 | |
@@ -305,9 +318,12 @@ discard block |
||
| 305 | 318 | |
| 306 | 319 | /* End of other class (author, series, tag, ...) initialization and accessors */ |
| 307 | 320 | |
| 308 | - public static function getFilterString() { |
|
| 321 | + public static function getFilterString() |
|
| 322 | + { |
|
| 309 | 323 | $filter = getURLParam('tag', NULL); |
| 310 | - if (empty($filter)) return ''; |
|
| 324 | + if (empty($filter)) { |
|
| 325 | + return ''; |
|
| 326 | + } |
|
| 311 | 327 | |
| 312 | 328 | $exists = true; |
| 313 | 329 | if (preg_match("/^!(.*)$/", $filter, $matches)) { |
@@ -347,7 +363,8 @@ discard block |
||
| 347 | 363 | return reset($reduced); |
| 348 | 364 | } |
| 349 | 365 | |
| 350 | - public function getRating() { |
|
| 366 | + public function getRating() |
|
| 367 | + { |
|
| 351 | 368 | if (is_null($this->rating) || $this->rating == 0) { |
| 352 | 369 | return ''; |
| 353 | 370 | } |
@@ -361,7 +378,8 @@ discard block |
||
| 361 | 378 | return $retour; |
| 362 | 379 | } |
| 363 | 380 | |
| 364 | - public function getPubDate() { |
|
| 381 | + public function getPubDate() |
|
| 382 | + { |
|
| 365 | 383 | if (empty ($this->pubdate)) { |
| 366 | 384 | return ''; |
| 367 | 385 | } |
@@ -372,23 +390,22 @@ discard block |
||
| 372 | 390 | return ''; |
| 373 | 391 | } |
| 374 | 392 | |
| 375 | - public function getComment($withSerie = true) { |
|
| 393 | + public function getComment($withSerie = true) |
|
| 394 | + { |
|
| 376 | 395 | $addition = ''; |
| 377 | 396 | $se = $this->getSerie (); |
| 378 | 397 | if (!is_null ($se) && $withSerie) { |
| 379 | 398 | $addition = $addition . '<strong>' . localize('content.series') . '</strong>' . str_format(localize('content.series.data'), $this->seriesIndex, htmlspecialchars($se->name)) . "<br />\n"; |
| 380 | 399 | } |
| 381 | - if (preg_match('/<\/(div|p|a|span)>/', $this->comment)) |
|
| 382 | - { |
|
| 400 | + if (preg_match('/<\/(div|p|a|span)>/', $this->comment)) { |
|
| 383 | 401 | return $addition . html2xhtml($this->comment); |
| 384 | - } |
|
| 385 | - else |
|
| 386 | - { |
|
| 402 | + } else { |
|
| 387 | 403 | return $addition . htmlspecialchars($this->comment); |
| 388 | 404 | } |
| 389 | 405 | } |
| 390 | 406 | |
| 391 | - public function getDataFormat($format) { |
|
| 407 | + public function getDataFormat($format) |
|
| 408 | + { |
|
| 392 | 409 | $reduced = array_filter($this->getDatas(), function ($data) use ($format) { |
| 393 | 410 | return $data->format == $format; |
| 394 | 411 | }); |
@@ -419,16 +436,14 @@ discard block |
||
| 419 | 436 | if ($extension == "jpg" || $extension == "png") { |
| 420 | 437 | if (empty($this->coverFileName)) { |
| 421 | 438 | return $this->path . '/cover.' . $extension; |
| 422 | - } |
|
| 423 | - else { |
|
| 439 | + } else { |
|
| 424 | 440 | $ext = strtolower(pathinfo($this->coverFileName, PATHINFO_EXTENSION)); |
| 425 | 441 | if ($ext == $extension) { |
| 426 | 442 | return $this->coverFileName; |
| 427 | 443 | } |
| 428 | 444 | } |
| 429 | 445 | return false; |
| 430 | - } |
|
| 431 | - else { |
|
| 446 | + } else { |
|
| 432 | 447 | $data = $this->getDataById($idData); |
| 433 | 448 | if (!$data) { |
| 434 | 449 | return NULL; |
@@ -443,8 +458,7 @@ discard block |
||
| 443 | 458 | global $config; |
| 444 | 459 | $data = $this->getDataById($idData); |
| 445 | 460 | |
| 446 | - try |
|
| 447 | - { |
|
| 461 | + try { |
|
| 448 | 462 | $epub = new EPub($data->getLocalPath()); |
| 449 | 463 | |
| 450 | 464 | $epub->Title($this->title); |
@@ -471,14 +485,13 @@ discard block |
||
| 471 | 485 | $filename = $data->getUpdatedFilenameKepub(); |
| 472 | 486 | } |
| 473 | 487 | $epub->download($filename); |
| 474 | - } |
|
| 475 | - catch (Exception $e) |
|
| 476 | - { |
|
| 488 | + } catch (Exception $e) { |
|
| 477 | 489 | echo 'Exception : ' . $e->getMessage(); |
| 478 | 490 | } |
| 479 | 491 | } |
| 480 | 492 | |
| 481 | - public function getThumbnail($width, $height, $outputfile = NULL) { |
|
| 493 | + public function getThumbnail($width, $height, $outputfile = NULL) |
|
| 494 | + { |
|
| 482 | 495 | if (is_null($width) && is_null($height)) { |
| 483 | 496 | return false; |
| 484 | 497 | } |
@@ -527,17 +540,14 @@ discard block |
||
| 527 | 540 | if ($ext == 'png') { |
| 528 | 541 | array_push($linkArray, Data::getLink($this, "png", "image/png", Link::OPDS_IMAGE_TYPE, "cover.png", NULL)); |
| 529 | 542 | array_push($linkArray, Data::getLink($this, "png", "image/png", Link::OPDS_THUMBNAIL_TYPE, "cover.png", NULL)); |
| 530 | - } |
|
| 531 | - else { |
|
| 543 | + } else { |
|
| 532 | 544 | array_push($linkArray, Data::getLink($this, 'jpg', 'image/jpeg', Link::OPDS_IMAGE_TYPE, 'cover.jpg', NULL)); |
| 533 | 545 | array_push($linkArray, Data::getLink($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL)); |
| 534 | 546 | } |
| 535 | 547 | } |
| 536 | 548 | |
| 537 | - foreach ($this->getDatas() as $data) |
|
| 538 | - { |
|
| 539 | - if ($data->isKnownType()) |
|
| 540 | - { |
|
| 549 | + foreach ($this->getDatas() as $data) { |
|
| 550 | + if ($data->isKnownType()) { |
|
| 541 | 551 | array_push($linkArray, $data->getDataLink(Link::OPDS_ACQUISITION_TYPE, $data->format)); |
| 542 | 552 | } |
| 543 | 553 | } |
@@ -556,17 +566,20 @@ discard block |
||
| 556 | 566 | } |
| 557 | 567 | |
| 558 | 568 | |
| 559 | - public function getEntry() { |
|
| 569 | + public function getEntry() |
|
| 570 | + { |
|
| 560 | 571 | return new EntryBook($this->getTitle(), $this->getEntryId(), |
| 561 | 572 | $this->getComment(), 'text/html', |
| 562 | 573 | $this->getLinkArray(), $this); |
| 563 | 574 | } |
| 564 | 575 | |
| 565 | - public static function getBookCount($database = NULL) { |
|
| 576 | + public static function getBookCount($database = NULL) |
|
| 577 | + { |
|
| 566 | 578 | return parent::executeQuerySingle('select count(*) from books', $database); |
| 567 | 579 | } |
| 568 | 580 | |
| 569 | - public static function getCount() { |
|
| 581 | + public static function getCount() |
|
| 582 | + { |
|
| 570 | 583 | global $config; |
| 571 | 584 | $nBooks = parent::executeQuerySingle('select count(*) from books'); |
| 572 | 585 | $result = array(); |
@@ -585,27 +598,33 @@ discard block |
||
| 585 | 598 | return $result; |
| 586 | 599 | } |
| 587 | 600 | |
| 588 | - public static function getBooksByAuthor($authorId, $n) { |
|
| 601 | + public static function getBooksByAuthor($authorId, $n) |
|
| 602 | + { |
|
| 589 | 603 | return self::getEntryArray(self::SQL_BOOKS_BY_AUTHOR, array($authorId), $n); |
| 590 | 604 | } |
| 591 | 605 | |
| 592 | - public static function getBooksByRating($ratingId, $n) { |
|
| 606 | + public static function getBooksByRating($ratingId, $n) |
|
| 607 | + { |
|
| 593 | 608 | return self::getEntryArray(self::SQL_BOOKS_BY_RATING, array($ratingId), $n); |
| 594 | 609 | } |
| 595 | 610 | |
| 596 | - public static function getBooksByPublisher($publisherId, $n) { |
|
| 611 | + public static function getBooksByPublisher($publisherId, $n) |
|
| 612 | + { |
|
| 597 | 613 | return self::getEntryArray(self::SQL_BOOKS_BY_PUBLISHER, array($publisherId), $n); |
| 598 | 614 | } |
| 599 | 615 | |
| 600 | - public static function getBooksBySeries($serieId, $n) { |
|
| 616 | + public static function getBooksBySeries($serieId, $n) |
|
| 617 | + { |
|
| 601 | 618 | return self::getEntryArray(self::SQL_BOOKS_BY_SERIE, array($serieId), $n); |
| 602 | 619 | } |
| 603 | 620 | |
| 604 | - public static function getBooksByTag($tagId, $n) { |
|
| 621 | + public static function getBooksByTag($tagId, $n) |
|
| 622 | + { |
|
| 605 | 623 | return self::getEntryArray(self::SQL_BOOKS_BY_TAG, array($tagId), $n); |
| 606 | 624 | } |
| 607 | 625 | |
| 608 | - public static function getBooksByLanguage($languageId, $n) { |
|
| 626 | + public static function getBooksByLanguage($languageId, $n) |
|
| 627 | + { |
|
| 609 | 628 | return self::getEntryArray(self::SQL_BOOKS_BY_LANGUAGE, array($languageId), $n); |
| 610 | 629 | } |
| 611 | 630 | |
@@ -615,32 +634,33 @@ discard block |
||
| 615 | 634 | * @param $n integer |
| 616 | 635 | * @return array |
| 617 | 636 | */ |
| 618 | - public static function getBooksByCustom($customColumn, $id, $n) { |
|
| 637 | + public static function getBooksByCustom($customColumn, $id, $n) |
|
| 638 | + { |
|
| 619 | 639 | list($query, $params) = $customColumn->getQuery($id); |
| 620 | 640 | |
| 621 | 641 | return self::getEntryArray($query, $params, $n); |
| 622 | 642 | } |
| 623 | 643 | |
| 624 | - public static function getBookById($bookId) { |
|
| 644 | + public static function getBookById($bookId) |
|
| 645 | + { |
|
| 625 | 646 | $result = parent::getDb()->prepare('select ' . self::getBookColumns() . ' |
| 626 | 647 | from books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
| 627 | 648 | where books.id = ?'); |
| 628 | 649 | $result->execute(array($bookId)); |
| 629 | - while ($post = $result->fetchObject()) |
|
| 630 | - { |
|
| 650 | + while ($post = $result->fetchObject()) { |
|
| 631 | 651 | $book = new Book($post); |
| 632 | 652 | return $book; |
| 633 | 653 | } |
| 634 | 654 | return NULL; |
| 635 | 655 | } |
| 636 | 656 | |
| 637 | - public static function getBookByDataId($dataId) { |
|
| 657 | + public static function getBookByDataId($dataId) |
|
| 658 | + { |
|
| 638 | 659 | $result = parent::getDb()->prepare('select ' . self::getBookColumns() . ', data.name, data.format |
| 639 | 660 | from data, books ' . self::SQL_BOOKS_LEFT_JOIN . ' |
| 640 | 661 | where data.book = books.id and data.id = ?'); |
| 641 | 662 | $result->execute(array($dataId)); |
| 642 | - while ($post = $result->fetchObject()) |
|
| 643 | - { |
|
| 663 | + while ($post = $result->fetchObject()) { |
|
| 644 | 664 | $book = new Book($post); |
| 645 | 665 | $data = new Data($post, $book); |
| 646 | 666 | $data->id = $dataId; |
@@ -650,7 +670,8 @@ discard block |
||
| 650 | 670 | return NULL; |
| 651 | 671 | } |
| 652 | 672 | |
| 653 | - public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 673 | + public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) |
|
| 674 | + { |
|
| 654 | 675 | $i = 0; |
| 655 | 676 | $critArray = array(); |
| 656 | 677 | foreach (array(PageQueryResult::SCOPE_AUTHOR, |
@@ -661,8 +682,7 @@ discard block |
||
| 661 | 682 | if (in_array($key, getCurrentOption('ignored_categories')) || |
| 662 | 683 | (!array_key_exists($key, $query) && !array_key_exists('all', $query))) { |
| 663 | 684 | $critArray[$i] = self::BAD_SEARCH; |
| 664 | - } |
|
| 665 | - else { |
|
| 685 | + } else { |
|
| 666 | 686 | if (array_key_exists($key, $query)) { |
| 667 | 687 | $critArray[$i] = $query[$key]; |
| 668 | 688 | } else { |
@@ -674,12 +694,14 @@ discard block |
||
| 674 | 694 | return self::getEntryArray(self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage); |
| 675 | 695 | } |
| 676 | 696 | |
| 677 | - public static function getBooks($n) { |
|
| 697 | + public static function getBooks($n) |
|
| 698 | + { |
|
| 678 | 699 | list ($entryArray, $totalNumber) = self::getEntryArray(self::SQL_BOOKS_ALL , array (), $n); |
| 679 | 700 | return array($entryArray, $totalNumber); |
| 680 | 701 | } |
| 681 | 702 | |
| 682 | - public static function getAllBooks() { |
|
| 703 | + public static function getAllBooks() |
|
| 704 | + { |
|
| 683 | 705 | /* @var $result PDOStatement */ |
| 684 | 706 | |
| 685 | 707 | list (, $result) = parent::executeQuery('select {0} |
@@ -688,8 +710,7 @@ discard block |
||
| 688 | 710 | order by substr (upper (sort), 1, 1)', 'substr (upper (sort), 1, 1) as title, count(*) as count', self::getFilterString(), array(), -1); |
| 689 | 711 | |
| 690 | 712 | $entryArray = array(); |
| 691 | - while ($post = $result->fetchObject()) |
|
| 692 | - { |
|
| 713 | + while ($post = $result->fetchObject()) { |
|
| 693 | 714 | array_push($entryArray, new Entry($post->title, Book::getEntryIdByLetter($post->title), |
| 694 | 715 | str_format(localize('bookword', $post->count), $post->count), 'text', |
| 695 | 716 | array(new LinkNavigation('?page='.parent::PAGE_ALL_BOOKS_LETTER.'&id='. rawurlencode($post->title))), '', $post->count)); |
@@ -697,25 +718,27 @@ discard block |
||
| 697 | 718 | return $entryArray; |
| 698 | 719 | } |
| 699 | 720 | |
| 700 | - public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 721 | + public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) |
|
| 722 | + { |
|
| 701 | 723 | return self::getEntryArray(self::SQL_BOOKS_BY_FIRST_LETTER, array($letter . '%'), $n, $database, $numberPerPage); |
| 702 | 724 | } |
| 703 | 725 | |
| 704 | - public static function getEntryArray($query, $params, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 726 | + public static function getEntryArray($query, $params, $n, $database = NULL, $numberPerPage = NULL) |
|
| 727 | + { |
|
| 705 | 728 | /* @var $totalNumber integer */ |
| 706 | 729 | /* @var $result PDOStatement */ |
| 707 | 730 | list($totalNumber, $result) = parent::executeQuery($query, self::getBookColumns(), self::getFilterString(), $params, $n, $database, $numberPerPage); |
| 708 | 731 | |
| 709 | 732 | $entryArray = array(); |
| 710 | - while ($post = $result->fetchObject()) |
|
| 711 | - { |
|
| 733 | + while ($post = $result->fetchObject()) { |
|
| 712 | 734 | $book = new Book($post); |
| 713 | 735 | array_push($entryArray, $book->getEntry()); |
| 714 | 736 | } |
| 715 | 737 | return array($entryArray, $totalNumber); |
| 716 | 738 | } |
| 717 | 739 | |
| 718 | - public static function getAllRecentBooks() { |
|
| 740 | + public static function getAllRecentBooks() |
|
| 741 | + { |
|
| 719 | 742 | global $config; |
| 720 | 743 | list ($entryArray, ) = self::getEntryArray(self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array(), -1); |
| 721 | 744 | return $entryArray; |
@@ -727,7 +750,8 @@ discard block |
||
| 727 | 750 | * @param string[] $columns |
| 728 | 751 | * @return CustomColumn[] |
| 729 | 752 | */ |
| 730 | - public function getCustomColumnValues($columns, $asArray = false) { |
|
| 753 | + public function getCustomColumnValues($columns, $asArray = false) |
|
| 754 | + { |
|
| 731 | 755 | $result = array(); |
| 732 | 756 | |
| 733 | 757 | foreach ($columns as $lookup) { |
@@ -52,15 +52,13 @@ |
||
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - switch ($type) |
|
| 56 | - { |
|
| 55 | + switch ($type) { |
|
| 57 | 56 | // -DC- Add png type |
| 58 | 57 | case 'jpg': |
| 59 | 58 | case 'png': |
| 60 | 59 | if ($type == 'jpg') { |
| 61 | 60 | header('Content-Type: image/jpeg'); |
| 62 | - } |
|
| 63 | - else { |
|
| 61 | + } else { |
|
| 64 | 62 | header('Content-Type: image/png'); |
| 65 | 63 | } |
| 66 | 64 | //by default, we don't cache |
@@ -15,25 +15,30 @@ discard block |
||
| 15 | 15 | public $id; |
| 16 | 16 | public $name; |
| 17 | 17 | |
| 18 | - public function __construct($post) { |
|
| 18 | + public function __construct($post) |
|
| 19 | + { |
|
| 19 | 20 | $this->id = $post->id; |
| 20 | 21 | $this->name = $post->name; |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | - public function getUri () { |
|
| 24 | + public function getUri () |
|
| 25 | + { |
|
| 24 | 26 | return "?page=".parent::PAGE_TAG_DETAIL."&id=$this->id"; |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | - public function getEntryId () { |
|
| 29 | + public function getEntryId () |
|
| 30 | + { |
|
| 28 | 31 | return self::ALL_TAGS_ID.":".$this->id; |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | - public static function getCount() { |
|
| 34 | + public static function getCount() |
|
| 35 | + { |
|
| 32 | 36 | // str_format (localize("tags.alphabetical", count(array)) |
| 33 | 37 | return parent::getCountGeneric ("tags", self::ALL_TAGS_ID, parent::PAGE_ALL_TAGS); |
| 34 | 38 | } |
| 35 | 39 | |
| 36 | - public static function getTagById ($tagId) { |
|
| 40 | + public static function getTagById ($tagId) |
|
| 41 | + { |
|
| 37 | 42 | $result = parent::getDb ()->prepare('select id, name from tags where id = ?'); |
| 38 | 43 | $result->execute (array ($tagId)); |
| 39 | 44 | if ($post = $result->fetchObject ()) { |
@@ -42,7 +47,8 @@ discard block |
||
| 42 | 47 | return NULL; |
| 43 | 48 | } |
| 44 | 49 | |
| 45 | - public static function getAllTags() { |
|
| 50 | + public static function getAllTags() |
|
| 51 | + { |
|
| 46 | 52 | global $config; |
| 47 | 53 | |
| 48 | 54 | $sql = self::SQL_ALL_TAGS; |
@@ -54,13 +60,13 @@ discard block |
||
| 54 | 60 | return Base::getEntryArrayWithBookNumber ($sql, self::TAG_COLUMNS, array (), "Tag"); |
| 55 | 61 | } |
| 56 | 62 | |
| 57 | - public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { |
|
| 63 | + public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) |
|
| 64 | + { |
|
| 58 | 65 | $columns = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count"; |
| 59 | 66 | $sql = 'select {0} from tags where upper (tags.name) like ? {1} order by tags.name'; |
| 60 | 67 | list ($totalNumber, $result) = parent::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), $n, $database, $numberPerPage); |
| 61 | 68 | $entryArray = array(); |
| 62 | - while ($post = $result->fetchObject ()) |
|
| 63 | - { |
|
| 69 | + while ($post = $result->fetchObject ()) { |
|
| 64 | 70 | $tag = new Tag ($post); |
| 65 | 71 | array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (), |
| 66 | 72 | str_format (localize("bookword", $post->count), $post->count), "text", |